:root {
    --bg: #0f1115;
    --surface: #171a21;
    --surface-2: #1e222b;
    --border: #2a2f3a;
    --text: #e6e8ec;
    --text-dim: #9aa1ad;
    --accent: #c8a45c;
    --accent-strong: #e0bd72;
    --ok: #4caf78;
    --warn: #d9a441;
    --danger: #d9534f;
    --radius: 10px;
    --sidebar-w: 248px;
    --font-sans: "Manrope", system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
    --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-sans);
    font-size: 15px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3 {
    font-weight: 700;
    line-height: 1.2;
    margin: 0 0 0.5em;
}

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

a:hover {
    text-decoration: underline;
}

code {
    font-family: var(--font-mono);
    font-size: 0.9em;
}

/* App shell — sidebar + content */
.app-shell {
    display: flex;
    min-height: 100vh;
}

.app-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.content {
    flex: 1;
    padding: 40px clamp(20px, 5vw, 56px);
    max-width: 1100px;
    width: 100%;
}

.app-footer {
    padding: 18px clamp(20px, 5vw, 56px);
    border-top: 1px solid var(--border);
    color: var(--text-dim);
    font-size: 13px;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-w);
    flex-shrink: 0;
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 24px 18px;
    gap: 24px;
}

.sidebar-brand .brand {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text);
    font-weight: 800;
    font-size: 18px;
}

.sidebar-brand .brand:hover {
    text-decoration: none;
}

.brand-mark {
    display: inline-grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border-radius: 8px;
    background: var(--accent);
    color: #1a1300;
    font-weight: 800;
    letter-spacing: 0.5px;
}

.brand-accent {
    color: var(--accent-strong);
}

.brand-sub {
    margin: 8px 0 0 2px;
    color: var(--text-dim);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
}

.nav-link {
    display: block;
    padding: 10px 12px;
    border-radius: 8px;
    color: var(--text-dim);
    font-weight: 600;
    transition: background 0.12s, color 0.12s;
}

.nav-link:hover {
    background: var(--surface-2);
    color: var(--text);
    text-decoration: none;
}

.nav-link.active {
    background: var(--surface-2);
    color: var(--accent-strong);
    box-shadow: inset 2px 0 0 var(--accent);
}

.sidebar-auth {
    border-top: 1px solid var(--border);
    padding-top: 18px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.auth-user {
    color: var(--text-dim);
    font-size: 13px;
    padding-left: 2px;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 9px 16px;
    border-radius: 8px;
    border: 1px solid transparent;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: filter 0.12s, background 0.12s;
}

.btn:hover {
    text-decoration: none;
    filter: brightness(1.08);
}

.btn-block {
    width: 100%;
}

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

.btn-ghost {
    background: transparent;
    border-color: var(--border);
    color: var(--text);
}

/* Hero + panels */
.hero {
    margin-bottom: 36px;
}

.hero h1 {
    font-size: clamp(26px, 4vw, 36px);
}

.lede {
    color: var(--text-dim);
    font-size: 17px;
    max-width: 60ch;
}

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
}

.panel h2 {
    font-size: 18px;
}

/* Status lines (API connectivity) */
.status-line {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0;
    font-size: 15px;
}

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

.status-pending .dot {
    background: var(--text-dim);
}

.status-ok .dot {
    background: var(--ok);
}

.status-down .dot {
    background: var(--danger);
}

.status-warning .dot {
    background: var(--warn);
}

/* Status / error pages */
.status-stage {
    display: grid;
    place-items: center;
    min-height: 60vh;
}

.status-card {
    text-align: center;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 48px 40px;
    max-width: 480px;
}

.status-card.status-danger {
    border-color: rgba(217, 83, 79, 0.4);
}

.status-card.status-warning {
    border-color: rgba(217, 164, 65, 0.4);
}

.status-code {
    font-family: var(--font-mono);
    font-size: 44px;
    font-weight: 700;
    color: var(--accent-strong);
}

.status-desc {
    color: var(--text-dim);
}

.status-detail {
    margin: 18px 0;
    font-size: 13px;
    color: var(--text-dim);
}

.det-k {
    display: block;
    margin-bottom: 4px;
}

.status-actions {
    margin-top: 24px;
}

/* Inline status message (error boundary) */
.status-message {
    padding: 16px 20px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

.status-message.status-error {
    border-color: rgba(217, 83, 79, 0.4);
    background: rgba(217, 83, 79, 0.08);
}

.status-message.status-warning {
    border-color: rgba(217, 164, 65, 0.4);
    background: rgba(217, 164, 65, 0.08);
}

.status-message p {
    margin: 0;
}

/* Page head */
.page-head {
    margin-bottom: 24px;
}

.page-head h1 {
    font-size: clamp(24px, 3.5vw, 32px);
}

/* Filters */
.filters {
    margin-bottom: 20px;
}

.filter-form {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 14px;
}

.filter-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.filter-search {
    flex: 1 1 280px;
    min-width: 200px;
}

.filter-field label {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-dim);
}

.filter-field input,
.filter-field select {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font: inherit;
    padding: 9px 12px;
}

.filter-field input:focus,
.filter-field select:focus {
    outline: none;
    border-color: var(--accent);
}

.filter-actions {
    display: flex;
    gap: 8px;
}

/* Results meta */
.results-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 18px;
    margin-bottom: 14px;
    color: var(--text-dim);
    font-size: 14px;
}

.results-meta .count strong {
    color: var(--text);
}

.loading-indicator {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-dim);
}

.li-spin {
    width: 14px;
    height: 14px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: li-spin 0.7s linear infinite;
}

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

/* Dashboard — stat cards + progress */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}

.stat-card {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 18px 20px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.stat-label {
    color: var(--text-dim);
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.stat-value {
    font-size: 30px;
    font-weight: 600;
    color: var(--text);
}

.stat-value-ok {
    color: var(--ok);
}

.progress {
    height: 12px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 999px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    background: var(--ok);
    border-radius: inherit;
    transition: width 0.3s ease;
}

.progress-caption {
    margin: 10px 0 0;
    color: var(--text-dim);
    font-size: 14px;
}

.progress-caption strong {
    color: var(--text);
}

/* Data table */
.table-wrap {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow-x: auto;
    background: var(--surface);
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.data-table th,
.data-table td {
    text-align: left;
    padding: 11px 14px;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}

.data-table thead th {
    background: var(--surface-2);
    color: var(--text-dim);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
    position: sticky;
    top: 0;
}

.data-table tbody tr:last-child td {
    border-bottom: none;
}

.data-table tbody tr:hover {
    background: var(--surface-2);
}

.col-num {
    width: 1%;
    white-space: nowrap;
}

.col-status {
    width: 1%;
    white-space: nowrap;
}

.col-actions {
    width: 1%;
    white-space: nowrap;
    text-align: right;
}

.col-text {
    max-width: 360px;
    word-break: break-word;
}

.mono {
    font-family: var(--font-mono);
    font-size: 0.92em;
    color: var(--text-dim);
}

.text-dim {
    color: var(--text-dim);
}

/* Badges */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 9px;
    border-radius: 999px;
    border: 1px solid var(--border);
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}

.badge .dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: currentColor;
    flex-shrink: 0;
}

.badge-success {
    color: var(--ok);
    border-color: rgba(76, 175, 120, 0.4);
    background: rgba(76, 175, 120, 0.1);
}

.badge-warning {
    color: var(--warn);
    border-color: rgba(217, 164, 65, 0.4);
    background: rgba(217, 164, 65, 0.1);
}

.badge-danger {
    color: var(--danger);
    border-color: rgba(217, 83, 79, 0.4);
    background: rgba(217, 83, 79, 0.1);
}

.badge-neutral {
    color: var(--text-dim);
}

/* Buttons — small + disabled variants */
.btn-sm {
    padding: 6px 12px;
    font-size: 13px;
}

.btn.is-disabled {
    opacity: 0.4;
    pointer-events: none;
    cursor: default;
}

/* Pager */
.pager {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    margin-top: 20px;
}

.pager-status {
    color: var(--text-dim);
    font-size: 14px;
    font-variant-numeric: tabular-nums;
}

/* Empty state */
.empty {
    text-align: center;
    padding: 20px 0;
}

.empty h2 {
    font-size: 18px;
}

.empty p {
    color: var(--text-dim);
    margin: 0;
}

/* Accessibility helper */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Side-by-side editor */
.editor-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    align-items: start;
}

.editor-pane {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.editor-pane-title {
    margin: 0;
    font-size: 15px;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.editor-pane-subtitle {
    margin: 0;
    font-size: 13px;
    color: var(--text-dim);
}

.editor-source {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
    white-space: pre-wrap;
    word-break: break-word;
    line-height: 1.6;
}

.editor-source.is-superseded {
    opacity: 0.75;
}

.editor-superseded {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.editor-textarea {
    width: 100%;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    padding: 14px;
    line-height: 1.6;
    resize: vertical;
}

.editor-textarea:focus {
    outline: none;
    border-color: var(--accent);
}

.editor-actions {
    margin-top: 12px;
    display: flex;
    gap: 10px;
}

.editor-approve {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 12px;
}

.ph-token {
    background: rgba(200, 164, 92, 0.18);
    color: var(--accent-strong);
    border-radius: 4px;
    padding: 0 4px;
    font-family: var(--font-mono);
    font-size: 0.92em;
}

/* Import / Export */
.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    text-transform: none;
    letter-spacing: normal;
    color: var(--text);
}

.checkbox-label input {
    width: auto;
}

.notice-list {
    margin: 0;
    padding: 0;
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* Responsive — stack the sidebar on top on small screens */
@media (max-width: 760px) {
    .editor-grid {
        grid-template-columns: 1fr;
    }

    .app-shell {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        gap: 12px;
        padding: 14px 16px;
    }

    .sidebar-brand {
        flex: 1;
    }

    .brand-sub {
        display: none;
    }

    .sidebar-nav {
        flex-direction: row;
        flex-wrap: wrap;
        flex: 1 0 100%;
    }

    .sidebar-auth {
        border-top: none;
        padding-top: 0;
    }
}
