@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@300;400;500;600&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:ital,wght@0,400;0,600;0,700;1,400&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600&display=swap');

:root {
    --bg: #F7F4EE;
    --bg-elevated: #FFFFFF;
    --bg-subtle: #F0ECE4;
    --bg-deep: #0B0B0A;
    --bg-sidebar: #111110;
    --ink: #1A1918;
    --ink-secondary: #4A4744;
    --ink-muted: #8C8884;
    --ink-faint: #B8B4AE;
    --border: rgba(26,25,24,0.08);
    --border-strong: rgba(26,25,24,0.14);
    --accent: #C1121F;
    --accent-hover: #A30E1A;
    --accent-soft: rgba(193,18,31,0.06);
    --green: #1A6B3A;
    --green-bg: rgba(26,107,58,0.07);
    --amber: #B45309;
    --amber-bg: rgba(180,83,9,0.07);
    --red-bg: rgba(193,18,31,0.06);
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.06);
    --shadow-lg: 0 8px 30px rgba(0,0,0,0.08);
    --radius: 10px;
    --radius-sm: 6px;
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'IBM Plex Mono', monospace;
    --font-serif: 'Playfair Display', Georgia, serif;
}

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

body {
    font-family: var(--font-sans);
    background: var(--bg);
    color: var(--ink);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* ═══ Layout ═══ */
.app-container { display: flex; height: 100vh; overflow: hidden; }

/* ═══ Sidebar ═══ */
.sidebar {
    width: 250px;
    background: var(--bg-sidebar);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.sidebar-header {
    padding: 24px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-box {
    width: 34px; height: 34px;
    background: var(--accent);
    color: #fff;
    border-radius: var(--radius-sm);
    display: flex; align-items: center; justify-content: center;
    font-family: var(--font-serif);
    font-weight: 700; font-size: 17px;
}

.logo-text h2 {
    font-family: var(--font-serif);
    font-size: 17px; font-weight: 600;
    color: #E8E4DC; line-height: 1.2;
}

.logo-text span {
    font-family: var(--font-mono);
    font-size: 9px; color: rgba(232,228,220,0.3);
    font-weight: 400; text-transform: uppercase;
    letter-spacing: 1.8px;
}

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

.nav-link {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 14px;
    color: rgba(232,228,220,0.4);
    text-decoration: none;
    font-size: 13px; font-weight: 400;
    border-radius: var(--radius-sm);
    transition: all 150ms ease;
}

.nav-link:hover {
    color: rgba(232,228,220,0.7);
    background: rgba(255,255,255,0.04);
}

.nav-link.active {
    color: #E8E4DC;
    background: rgba(255,255,255,0.07);
    font-weight: 500;
}

.nav-link svg { opacity: 0.6; flex-shrink: 0; }
.nav-link.active svg { opacity: 1; }

.nav-divider { height: 1px; background: rgba(255,255,255,0.06); margin: 8px 14px; }

.sidebar-footer { padding: 16px; border-top: 1px solid rgba(255,255,255,0.06); }

.user-profile { display: flex; align-items: center; gap: 10px; }

.avatar {
    width: 30px; height: 30px;
    background: var(--accent);
    color: #fff; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-weight: 600; font-size: 11px;
}

.user-details { display: flex; flex-direction: column; min-width: 0; }

.user-name {
    font-size: 12px; font-weight: 500;
    color: #E8E4DC;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.user-email { font-size: 10px; color: rgba(232,228,220,0.3); }
.user-email button { color: var(--accent) !important; font-size: 10px !important; border: none; background: transparent; cursor: pointer; font-family: var(--font-sans); }

/* ═══ Main Content ═══ */
.main-content { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--bg); }

/* ═══ Topbar ═══ */
.topbar {
    height: 54px;
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 32px;
    border-bottom: 1px solid var(--border);
    background: var(--bg);
    flex-shrink: 0;
}

.topbar h1 { font-family: var(--font-sans); font-size: 15px; font-weight: 600; color: var(--ink); }
.topbar-actions { display: flex; gap: 6px; align-items: center; }

/* ═══ Views ═══ */
.views-container { flex: 1; overflow-y: auto; padding: 32px; }

.view { display: none; max-width: 1100px; margin: 0 auto; animation: fadeIn 0.3s ease; }
.view.active { display: block; }

@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

.page-intro {
    font-size: 13px; font-weight: 400;
    color: var(--ink-muted); margin-bottom: 28px;
    max-width: 520px; line-height: 1.7;
}

/* ═══ Cards ═══ */
.card {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    margin-bottom: 20px;
    overflow: hidden;
}

.card-header {
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
    background: rgba(247,244,238,0.5);
}

.card-header h2 {
    font-family: var(--font-sans);
    font-size: 12px; font-weight: 600;
    color: var(--ink-muted);
    text-transform: uppercase; letter-spacing: 0.06em;
}

.card-body { padding: 20px; }

.flex-between { display: flex; justify-content: space-between; align-items: center; }

/* ═══ Helpers ═══ */
.text-right { text-align: right; }
.text-sm { font-size: 12px; }
.text-center { text-align: center; }
.w-full { width: 100%; }
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mb-4 { margin-bottom: 16px; }
.h-full { height: 100%; }
.h-full-inner { display: flex; flex-direction: column; min-height: 380px; }
.relative { position: relative; }
.max-w-md { max-width: 400px; }
.font-medium { font-weight: 500; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mt-auto { margin-top: auto; }
.text-slate-500 { color: var(--ink-muted); }

/* ═══ Buttons ═══ */
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    font-family: var(--font-sans);
    font-size: 12px; font-weight: 500;
    padding: 7px 16px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 150ms ease;
    border: 1px solid transparent;
    gap: 6px;
}

.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); transform: translateY(-1px); box-shadow: 0 2px 8px rgba(193,18,31,0.25); }

.btn-secondary { background: var(--bg-elevated); border-color: var(--border-strong); color: var(--ink-secondary); box-shadow: var(--shadow-sm); }
.btn-secondary:hover { background: var(--bg-subtle); border-color: var(--ink-faint); }

.btn-danger { background: transparent; border-color: var(--accent); color: var(--accent); }
.btn-danger:hover { background: var(--accent-soft); }

.btn-sm { padding: 5px 10px; font-size: 11px; }

.btn-icon { background: transparent; border: none; color: var(--ink-muted); cursor: pointer; font-size: 16px; padding: 4px 8px; border-radius: var(--radius-sm); transition: all 150ms; }
.btn-icon:hover { color: var(--ink); background: var(--bg-subtle); }

.btn-text { border: none; background: transparent; }
.btn-text:hover { text-decoration: underline; }

/* ═══ Forms ═══ */
.form-group { margin-bottom: 18px; }

.form-group label {
    display: block; font-size: 12px; font-weight: 500;
    color: var(--ink-secondary); margin-bottom: 6px;
}

.form-input {
    width: 100%; padding: 9px 12px;
    font-family: var(--font-sans); font-size: 13px; color: var(--ink);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--bg-elevated);
    transition: all 150ms ease;
}

.form-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.form-input::placeholder { color: var(--ink-faint); }

select.form-input { appearance: auto; }
textarea.form-input { resize: vertical; min-height: 100px; line-height: 1.6; overflow-wrap: break-word; word-break: break-word; }

/* ═══ Tables ═══ */
.table-container { width: 100%; overflow-x: auto; }

.data-table { width: 100%; border-collapse: collapse; text-align: left; }

.data-table th {
    font-size: 11px; font-weight: 600;
    color: var(--ink-muted); text-transform: uppercase;
    letter-spacing: 0.05em; padding: 10px 20px;
    border-bottom: 1px solid var(--border);
    background: rgba(247,244,238,0.5);
}

.data-table td {
    font-size: 13px; color: var(--ink-secondary);
    padding: 12px 20px; border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

.data-table tbody tr { transition: background 150ms; }
.data-table tbody tr:hover { background: var(--bg-subtle); }

.code-font { font-family: var(--font-mono); font-size: 12px; }

/* ═══ Stats ═══ */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 28px; }

.stat-card {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow-sm);
}

.stat-title { font-size: 11px; font-weight: 600; color: var(--ink-muted); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 8px; }
.stat-value { font-family: var(--font-serif); font-size: 32px; font-weight: 600; color: var(--ink); line-height: 1; letter-spacing: -0.02em; }

/* ═══ Playground — FIXED GRID ═══ */
.playground-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 20px;
}

.playground-panel { min-width: 0; }

.code-block {
    background: var(--bg-deep);
    color: rgba(232,228,220,0.65);
    padding: 16px;
    border-radius: var(--radius-sm);
    font-family: var(--font-mono); font-size: 12px;
    overflow-x: auto; line-height: 1.6;
    word-break: break-all; overflow-wrap: break-word;
}

.code-block.no-bg { background: var(--bg-subtle); color: var(--ink); border: 1px solid var(--border); word-break: normal; }
.code-block pre { white-space: pre-wrap; word-break: break-all; }

.code-block span#pg-curl-key, .code-block span#pg-curl-claim { color: var(--accent); }

.bg-slate-50 { background-color: var(--bg); }

.pg-loading {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 14px; height: 100%; min-height: 280px;
    font-size: 12px; color: var(--ink-muted); font-weight: 400;
}

.spinner { width: 22px; height: 22px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.pg-empty {
    display: flex; align-items: center; justify-content: center;
    height: 100%; min-height: 280px;
    color: var(--ink-faint); font-size: 13px; text-align: center;
}

.pg-response { display: flex; flex-direction: column; height: 100%; }

.resp-header {
    display: flex; justify-content: space-between; align-items: flex-start;
    padding-bottom: 16px; border-bottom: 1px solid var(--border); margin-bottom: 16px;
}

.resp-score-label { display: block; font-size: 11px; color: var(--ink-muted); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 4px; font-weight: 500; }
.resp-score-val { font-family: var(--font-mono); font-size: 36px; font-weight: 600; color: var(--accent); line-height: 1; }

.resp-status { padding: 5px 12px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; border-radius: var(--radius-sm); }
.status-verified { background: var(--green-bg); color: var(--green); }
.status-uncertain { background: var(--amber-bg); color: var(--amber); }
.status-false, .status-error { background: var(--red-bg); color: var(--accent); }

.resp-section { margin-bottom: 16px; }
.resp-section h4 { font-size: 11px; font-weight: 600; color: var(--ink-muted); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 8px; }
.resp-section p { font-size: 13px; color: var(--ink-secondary); line-height: 1.65; }

.resp-source-list { list-style: none; display: flex; flex-direction: column; gap: 6px; }
.resp-source-list li { background: var(--bg); border: 1px solid var(--border); padding: 9px 12px; border-radius: var(--radius-sm); font-size: 12px; display: flex; justify-content: space-between; align-items: center; }
.resp-source-list li .name { font-weight: 500; color: var(--ink); }
.resp-source-list li .stance { font-size: 10px; text-transform: uppercase; font-weight: 600; letter-spacing: 0.06em; }

.json-block { max-height: 200px; overflow-y: auto; }

/* ═══ Badges ═══ */
.badge { padding: 3px 8px; border-radius: var(--radius-sm); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.b-green, .badge-success { background: var(--green-bg); color: var(--green); }
.b-red, .badge-error { background: var(--red-bg); color: var(--accent); }
.b-yellow, .badge-neutral { background: var(--amber-bg); color: var(--amber); }

/* ═══ Docs ═══ */
.docs-layout { display: flex; gap: 40px; }
.docs-sidebar { width: 200px; flex-shrink: 0; position: sticky; top: 0; }
.docs-nav { list-style: none; }

.docs-nav li {
    padding: 7px 12px; font-size: 13px; color: var(--ink-muted);
    cursor: pointer; border-radius: var(--radius-sm);
    transition: all 150ms;
}
.docs-nav li:hover { color: var(--ink); background: var(--bg-subtle); }
.docs-nav li.active { color: var(--accent); font-weight: 500; background: var(--accent-soft); }

.docs-nav li strong {
    color: var(--ink-muted); font-size: 10px;
    text-transform: uppercase; letter-spacing: 0.1em;
    display: block; margin-top: 16px; margin-bottom: 2px;
    cursor: default;
    font-weight: 600;
}

.docs-content { flex: 1; max-width: 720px; }
.docs-content h1 { font-family: var(--font-serif); font-size: 32px; font-weight: 600; margin-bottom: 12px; letter-spacing: -0.02em; }
.docs-content h2 { font-family: var(--font-serif); font-size: 22px; font-weight: 600; margin-top: 36px; margin-bottom: 12px; scroll-margin-top: 20px; }
.docs-content h3 { font-size: 12px; font-weight: 600; margin-top: 20px; margin-bottom: 10px; color: var(--ink-muted); text-transform: uppercase; letter-spacing: 0.05em; }
.docs-content p { font-size: 14px; color: var(--ink-secondary); margin-bottom: 14px; line-height: 1.7; }
.docs-lead { font-size: 15px !important; font-style: italic; font-family: var(--font-serif); color: var(--ink-muted) !important; margin-bottom: 28px; }

.docs-hr { border: 0; border-top: 1px solid var(--border); margin: 32px 0; }

.docs-callout { background: var(--accent-soft); border-left: 3px solid var(--accent); padding: 14px 18px; border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.docs-callout strong { display: block; font-size: 12px; margin-bottom: 4px; color: var(--ink); }
.docs-callout p { margin: 0; font-size: 13px !important; }

.docs-table { width: 100%; border-collapse: collapse; }
.docs-table td { padding: 14px; border-bottom: 1px solid var(--border); vertical-align: top; font-size: 13px; color: var(--ink-secondary); }
.docs-table td:first-child { width: 30%; }

.badge-req { font-size: 9px; color: var(--accent); background: var(--red-bg); padding: 2px 6px; border-radius: 3px; text-transform: uppercase; font-weight: 600; }
.badge-opt { font-size: 9px; color: var(--ink-muted); background: var(--bg-subtle); padding: 2px 6px; border-radius: 3px; text-transform: uppercase; font-weight: 600; }

/* ═══ Modal ═══ */
.modal-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(11,11,10,0.5);
    backdrop-filter: blur(6px);
    display: flex; align-items: center; justify-content: center;
    z-index: 1000; opacity: 0; visibility: hidden;
    transition: all 0.2s;
}
.modal-overlay.active { opacity: 1; visibility: visible; }

.modal {
    background: var(--bg-elevated); width: 420px;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    transform: translateY(8px); transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}
.modal-overlay.active .modal { transform: translateY(0); }

.modal-header { padding: 18px 20px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal-header h2 { font-size: 15px; font-weight: 600; }
.modal-body { padding: 20px; }
.modal-footer { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; background: var(--bg); border-radius: 0 0 var(--radius) var(--radius); }

/* ═══ Toast ═══ */
.toast {
    position: fixed; bottom: 24px; right: 24px;
    background: var(--bg-deep); color: #E8E4DC;
    padding: 10px 18px; border-radius: var(--radius-sm);
    font-size: 12px; font-weight: 500;
    box-shadow: var(--shadow-lg);
    transform: translateY(80px); opacity: 0;
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    z-index: 9999;
}
.toast.show { transform: translateY(0); opacity: 1; }
.toast.error { background: var(--accent); }

/* ═══ Auth ═══ */
.auth-view {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: var(--bg-deep);
    z-index: 1000;
    align-items: center; justify-content: center;
}

.auth-card {
    width: 100%; max-width: 400px; margin: 0 auto;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
}

.auth-card .card-header { border-bottom: none; padding: 28px 28px 0; text-align: center; background: transparent; }
.auth-card .card-header h2 { font-family: var(--font-serif); font-size: 24px; font-weight: 600; color: var(--ink); text-transform: none; letter-spacing: -0.01em; }
.auth-card .card-header .text-sm { color: var(--ink-muted); font-size: 13px; display: block; margin-top: 4px; }
.auth-card .card-body { padding: 20px 28px 28px; }
.auth-card .btn-primary { padding: 10px; width: 100%; }

/* ═══ Scrollbar ═══ */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--ink-faint); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--ink-muted); }

.chart-card .card-body { min-height: 80px; }

@media (max-width: 1024px) {
    .playground-layout { grid-template-columns: 1fr; }
    .docs-layout { flex-direction: column; }
    .docs-sidebar { width: 100%; }
}

@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: -250px;
        top: 0;
        bottom: 0;
        z-index: 1000;
        transition: left 0.3s cubic-bezier(0.16, 1, 0.3, 1);
        box-shadow: var(--shadow-lg);
    }
    .sidebar.open {
        left: 0;
    }
    .mobile-overlay {
        position: fixed;
        top: 0; left: 0; right: 0; bottom: 0;
        background: rgba(11,11,10,0.5);
        backdrop-filter: blur(2px);
        z-index: 999;
        opacity: 0;
        visibility: hidden;
        transition: all 0.3s;
    }
    .mobile-overlay.active {
        opacity: 1;
        visibility: visible;
    }
    .topbar {
        padding: 0 16px;
    }
    .mobile-menu-btn {
        display: flex !important;
        margin-right: 12px;
        background: transparent;
        border: none;
        color: var(--ink);
        cursor: pointer;
    }
    .views-container {
        padding: 16px;
    }
    .topbar-actions a span { display: none; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
}

.mobile-menu-btn { display: none; }
