:root {
    --bg-primary: #09090b;
    --bg-secondary: #18181b;
    --bg-card: rgba(24, 24, 27, 0.5);
    --bg-card-hover: rgba(39, 39, 42, 0.4);
    --border: #27272a;
    --border-subtle: rgba(39, 39, 42, 0.5);
    --text-primary: #fafafa;
    --text-secondary: #a1a1aa;
    --text-muted: #71717a;
    --accent: #8b5cf6;
    --accent-hover: #a78bfa;
    --accent-gradient: linear-gradient(135deg, #9B30FF 0%, #4169E1 100%);
    --success: #34d399;
    --error: #f87171;
    --warning: #fbbf24;
    --font-stack: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
    --font-mono: 'SF Mono', SFMono-Regular, 'Cascadia Code', 'Fira Code', Menlo, Consolas, 'Liberation Mono', monospace;
    --radius: 8px;
    --radius-lg: 12px;
}

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-stack);
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

/* ─── Scrollbar ──────────────────────────────────────────────────────── */

::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #3f3f46;
}

/* ─── Navbar ─────────────────────────────────────────────────────────── */

.navbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 50;
    background: rgba(9, 9, 11, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border-subtle);
    height: 56px;
}

.navbar-inner {
    max-width: 72rem;
    margin: 0 auto;
    padding: 0 1.5rem;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.navbar-brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    text-decoration: none;
    color: var(--text-primary);
    font-weight: 600;
    font-size: 1.1rem;
}

.navbar-brand svg {
    width: 24px;
    height: 24px;
}

.navbar-nav {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    list-style: none;
}

.nav-link {
    display: inline-flex;
    align-items: center;
    padding: 0.4rem 0.75rem;
    border-radius: var(--radius);
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 500;
    transition: color 0.15s, background 0.15s;
}

.nav-link:hover {
    color: var(--text-primary);
    background: var(--bg-card-hover);
}

.nav-link.active {
    color: var(--text-primary);
    background: var(--bg-card);
}

/* ─── Main Layout ────────────────────────────────────────────────────── */

.main {
    max-width: 72rem;
    margin: 0 auto;
    padding: 5rem 1.5rem 3rem;
}

.page-header {
    margin-bottom: 2rem;
}

.page-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
}

.page-subtitle {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* ─── Cards ──────────────────────────────────────────────────────────── */

.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    transition: border-color 0.15s;
}

.card:hover {
    border-color: #3f3f46;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.card-title {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
}

.card-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
}

.card-unit {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-left: 0.25rem;
    font-weight: 400;
}

/* ─── Grid ───────────────────────────────────────────────────────────── */

.grid-4 {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    margin-bottom: 2rem;
}

.grid-2 {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
    margin-bottom: 2rem;
}

.grid-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    margin-bottom: 2rem;
}

/* ─── Status Indicator ───────────────────────────────────────────────── */

.status-card {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem 1.25rem;
    margin-bottom: 2rem;
}

.status-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
}

.status-dot.online {
    background: var(--success);
    box-shadow: 0 0 8px rgba(52, 211, 153, 0.5);
    animation: pulse 2s ease-in-out infinite;
}

.status-dot.offline {
    background: var(--error);
    box-shadow: 0 0 8px rgba(248, 113, 113, 0.5);
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.status-label {
    font-size: 0.9rem;
    font-weight: 600;
}

.status-label.online {
    color: var(--success);
}

.status-label.offline {
    color: var(--error);
}

.status-url {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-family: var(--font-mono);
    margin-left: auto;
}

/* ─── Section Headers ────────────────────────────────────────────────── */

.section-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
}

/* ─── Config Cards ───────────────────────────────────────────────────── */

.config-card {
    padding: 1.25rem;
    margin-bottom: 1rem;
}

.config-breadcrumb {
    font-family: var(--font-mono);
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--accent);
    margin-bottom: 0.75rem;
}

.config-table {
    width: 100%;
    border-collapse: collapse;
}

.config-table td {
    padding: 0.35rem 0;
    font-size: 0.85rem;
    vertical-align: top;
}

.config-table td:first-child {
    color: var(--text-secondary);
    width: 40%;
    padding-right: 1rem;
    font-family: var(--font-mono);
    font-size: 0.8rem;
}

.config-table td:last-child {
    color: var(--text-primary);
    word-break: break-all;
}

/* ─── Raw TOML ───────────────────────────────────────────────────────── */

.raw-toggle-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.4rem 0.75rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-secondary);
    font-size: 0.8rem;
    cursor: pointer;
    transition: border-color 0.15s, color 0.15s;
    margin-bottom: 1rem;
}

.raw-toggle-btn:hover {
    border-color: var(--accent);
    color: var(--text-primary);
}

.raw-toml-block {
    display: none;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    overflow-x: auto;
    margin-bottom: 2rem;
}

.raw-toml-block.visible {
    display: block;
}

.raw-toml-block pre {
    margin: 0;
    font-family: var(--font-mono);
    font-size: 0.8rem;
    line-height: 1.7;
    color: var(--text-secondary);
    white-space: pre-wrap;
    word-break: break-word;
}

.toml-key { color: #c4b5fd; }
.toml-string { color: #6ee7b7; }
.toml-header { color: #93c5fd; font-weight: 600; }
.toml-comment { color: var(--text-muted); font-style: italic; }

/* ─── Table ──────────────────────────────────────────────────────────── */

.table-wrap {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--bg-card);
}

table.log-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

table.log-table thead th {
    padding: 0.65rem 1rem;
    text-align: left;
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

table.log-table tbody tr {
    border-bottom: 1px solid rgba(39, 39, 42, 0.3);
    cursor: pointer;
    transition: background 0.1s;
}

table.log-table tbody tr:hover {
    background: var(--bg-card-hover);
}

table.log-table tbody td {
    padding: 0.6rem 1rem;
    color: var(--text-primary);
    white-space: nowrap;
}

.prompt-cell {
    max-width: 280px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text-secondary) !important;
}

.expand-row {
    display: none;
}

.expand-row.visible {
    display: table-row;
}

.expand-row td {
    padding: 1rem !important;
    background: rgba(9, 9, 11, 0.5);
}

.expand-content {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-all;
    color: var(--text-secondary);
    max-height: 320px;
    overflow-y: auto;
}

/* ─── Badges ─────────────────────────────────────────────────────────── */

.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.15rem 0.5rem;
    border-radius: 9999px;
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.badge-success {
    background: rgba(52, 211, 153, 0.15);
    color: var(--success);
}

.badge-error {
    background: rgba(248, 113, 113, 0.15);
    color: var(--error);
}

.badge-warning {
    background: rgba(251, 191, 36, 0.15);
    color: var(--warning);
}

.badge-neutral {
    background: rgba(161, 161, 170, 0.15);
    color: var(--text-secondary);
}

/* ─── Buttons ────────────────────────────────────────────────────────── */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.55rem 1.1rem;
    border-radius: var(--radius);
    font-size: 0.85rem;
    font-weight: 600;
    font-family: var(--font-stack);
    cursor: pointer;
    border: none;
    transition: background 0.15s, opacity 0.15s, transform 0.1s;
}

.btn:active {
    transform: scale(0.98);
}

.btn-primary {
    background: var(--accent);
    color: #fff;
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-gradient {
    background: var(--accent-gradient);
    color: #fff;
}

.btn-gradient:hover {
    opacity: 0.9;
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
}

.btn-outline:hover {
    border-color: var(--accent);
    color: var(--text-primary);
}

.btn-danger {
    background: rgba(248, 113, 113, 0.15);
    color: var(--error);
    border: 1px solid rgba(248, 113, 113, 0.3);
}

.btn-danger:hover {
    background: rgba(248, 113, 113, 0.25);
}

/* ─── Form Elements ──────────────────────────────────────────────────── */

.form-group {
    margin-bottom: 1rem;
}

.form-label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 0.35rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.form-input,
.form-textarea {
    width: 100%;
    padding: 0.6rem 0.85rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-family: var(--font-stack);
    font-size: 0.875rem;
    transition: border-color 0.15s;
    outline: none;
}

.form-input:focus,
.form-textarea:focus {
    border-color: var(--accent);
}

.form-input[readonly] {
    color: var(--text-secondary);
    cursor: default;
}

.form-textarea {
    resize: vertical;
    min-height: 120px;
    font-family: var(--font-stack);
    line-height: 1.6;
}

/* ─── Response Area ──────────────────────────────────────────────────── */

.response-area {
    margin-top: 1.5rem;
}

.response-card {
    padding: 1.25rem;
}

.response-meta {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.response-meta-item {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.8rem;
}

.response-meta-label {
    color: var(--text-muted);
}

.response-meta-value {
    color: var(--text-primary);
    font-weight: 600;
    font-family: var(--font-mono);
}

.response-text {
    font-size: 0.9rem;
    line-height: 1.7;
    color: var(--text-primary);
    white-space: pre-wrap;
    word-break: break-word;
}

.response-raw {
    margin-top: 1rem;
    display: none;
}

.response-raw.visible {
    display: block;
}

.response-raw pre {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    line-height: 1.6;
    color: var(--text-secondary);
    white-space: pre-wrap;
    word-break: break-all;
    background: rgba(9, 9, 11, 0.6);
    padding: 1rem;
    border-radius: var(--radius);
    max-height: 300px;
    overflow-y: auto;
}

/* ─── Toolbar ────────────────────────────────────────────────────────── */

.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.toolbar-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* ─── Toggle Switch ──────────────────────────────────────────────────── */

.toggle-label {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8rem;
    color: var(--text-secondary);
    cursor: pointer;
}

.toggle-switch {
    position: relative;
    width: 36px;
    height: 20px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    inset: 0;
    background: var(--border);
    border-radius: 10px;
    transition: background 0.2s;
    cursor: pointer;
}

.toggle-slider::before {
    content: '';
    position: absolute;
    width: 14px;
    height: 14px;
    left: 3px;
    top: 3px;
    background: var(--text-secondary);
    border-radius: 50%;
    transition: transform 0.2s, background 0.2s;
}

.toggle-switch input:checked + .toggle-slider {
    background: var(--accent);
}

.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(16px);
    background: #fff;
}

/* ─── Empty State ────────────────────────────────────────────────────── */

.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-muted);
}

.empty-state-icon {
    font-size: 2.5rem;
    margin-bottom: 0.75rem;
    opacity: 0.5;
}

.empty-state-text {
    font-size: 0.9rem;
}

.empty-state-sub {
    font-size: 0.8rem;
    margin-top: 0.25rem;
    color: var(--text-muted);
}

/* ─── Gradient Divider ───────────────────────────────────────────────── */

.gradient-divider {
    height: 1px;
    background: linear-gradient(90deg, transparent, #9B30FF, #4169E1, transparent);
    border: none;
    margin: 2rem 0;
    opacity: 0.4;
}

/* ─── Footer ─────────────────────────────────────────────────────────── */

.footer {
    text-align: center;
    padding: 2rem 1rem;
    font-size: 0.8rem;
    color: var(--text-muted);
    border-top: 1px solid var(--border-subtle);
    margin-top: 3rem;
}

.footer a {
    color: var(--accent);
    text-decoration: none;
}

.footer a:hover {
    color: var(--accent-hover);
    text-decoration: underline;
}

/* ─── Spinner ────────────────────────────────────────────────────────── */

.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ─── Responsive ─────────────────────────────────────────────────────── */

@media (max-width: 1024px) {
    .grid-4 {
        grid-template-columns: repeat(2, 1fr);
    }
    .grid-3 {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 640px) {
    .grid-4,
    .grid-3,
    .grid-2 {
        grid-template-columns: 1fr;
    }

    .navbar-inner {
        padding: 0 1rem;
    }

    .main {
        padding: 4.5rem 1rem 2rem;
    }

    .navbar-nav {
        gap: 0;
    }

    .nav-link {
        padding: 0.35rem 0.5rem;
        font-size: 0.8rem;
    }

    .status-url {
        display: none;
    }

    .page-title {
        font-size: 1.25rem;
    }

    table.log-table {
        font-size: 0.78rem;
    }

    table.log-table thead th,
    table.log-table tbody td {
        padding: 0.5rem 0.6rem;
    }
}
