/* ---------- Design tokens ---------- */
:root {
    color-scheme: light dark;

    --font-serif: Georgia, "Iowan Old Style", "Palatino Linotype", "Times New Roman", serif;
    --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

    --bg: #eef0f4;
    --surface: #ffffff;
    --surface-alt: #f7f8fa;
    --border: #e1e4ea;
    --text: #1b2130;
    --text-muted: #5c6472;
    --text-faint: #8a91a0;

    --primary: #1f3a5f;
    --primary-dark: #142943;
    --primary-tint: #e8edf5;
    --accent: #9b2f3a;
    --accent-tint: #f6e9ea;

    --shadow-sm: 0 1px 2px rgba(20, 25, 40, 0.06);
    --shadow-md: 0 4px 16px rgba(20, 25, 40, 0.08);
    --shadow-lg: 0 12px 32px rgba(20, 25, 40, 0.14);

    --radius: 10px;
    --radius-sm: 6px;
}

:root[data-theme="dark"] {
    --bg: #0f131b;
    --surface: #171c26;
    --surface-alt: #1d232f;
    --border: #2a3140;
    --text: #e7e9ee;
    --text-muted: #9aa2b2;
    --text-faint: #6b7383;

    --primary: #6f97c9;
    --primary-dark: #567aa8;
    --primary-tint: #1c2a3d;
    --accent: #dd8a92;
    --accent-tint: #33232a;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.45);
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #0f131b;
        --surface: #171c26;
        --surface-alt: #1d232f;
        --border: #2a3140;
        --text: #e7e9ee;
        --text-muted: #9aa2b2;
        --text-faint: #6b7383;

        --primary: #6f97c9;
        --primary-dark: #567aa8;
        --primary-tint: #1c2a3d;
        --accent: #dd8a92;
        --accent-tint: #33232a;

        --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
        --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.35);
        --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.45);
    }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

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

a { color: var(--primary); }

.container {
    max-width: 1180px;
    margin: 0 auto;
    padding: 2rem 1.75rem 4rem;
}

/* ---------- Top bar ---------- */
.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: 0.7rem 1.75rem;
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--border);
}

.topbar nav { display: flex; align-items: center; gap: 1.75rem; }

.brand {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    font-family: var(--font-serif);
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text) !important;
    text-decoration: none;
    letter-spacing: 0.01em;
}
.brand svg { color: var(--primary); flex-shrink: 0; }

.topbar nav a:not(.brand) {
    position: relative;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.93rem;
    font-weight: 500;
    padding: 0.3rem 0.1rem;
    transition: color 0.15s ease;
}
.topbar nav a:not(.brand)::after {
    content: "";
    position: absolute;
    left: 0; right: 0; bottom: -0.35rem;
    height: 2px;
    background: var(--accent);
    transform: scaleX(0);
    transition: transform 0.18s ease;
}
.topbar nav a:not(.brand):hover { color: var(--text); }
.topbar nav a:not(.brand):hover::after,
.topbar nav a.active::after { transform: scaleX(1); }
.topbar nav a.active { color: var(--text); }

.logout-form { display: flex; align-items: center; gap: 0.65rem; }
.user-chip {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    color: var(--text-muted);
}
.user-avatar {
    width: 26px; height: 26px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-size: 0.75rem;
    font-weight: 700;
    flex-shrink: 0;
}
.logout-form button {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    padding: 0.35rem 0.65rem;
    font-size: 0.82rem;
    cursor: pointer;
    transition: all 0.15s ease;
}
.logout-form button:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- Login page ---------- */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background:
        radial-gradient(ellipse 800px 500px at 15% -10%, color-mix(in srgb, var(--primary) 16%, transparent), transparent),
        radial-gradient(ellipse 700px 500px at 100% 110%, color-mix(in srgb, var(--accent) 10%, transparent), transparent),
        var(--bg);
    padding: 1.5rem;
}

.login-card {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
    width: 360px;
    padding: 2.25rem 2rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
}
.login-brand {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-bottom: 0.35rem;
}
.login-brand svg { color: var(--primary); }
.login-card h1 {
    font-family: var(--font-serif);
    font-size: 1.3rem;
    margin: 0;
}
.login-tagline {
    margin: -0.35rem 0 0.5rem;
    color: var(--text-muted);
    font-size: 0.85rem;
}
.login-card label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: -0.35rem;
}
.login-card input {
    padding: 0.6rem 0.7rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-alt);
    color: var(--text);
    font-size: 0.95rem;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.login-card input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 22%, transparent);
    background: var(--surface);
}
.login-card button {
    margin-top: 0.6rem;
    padding: 0.7rem;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease;
}
.login-card button:hover { background: var(--primary-dark); }
.error {
    background: var(--accent-tint);
    color: var(--accent);
    border-radius: var(--radius-sm);
    padding: 0.55rem 0.7rem;
    font-size: 0.85rem;
}

/* ---------- Page header ---------- */
.page-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 1.25rem;
}
.page-header h1 {
    font-family: var(--font-serif);
    font-size: 1.65rem;
    margin: 0;
}
.stat-badge {
    font-size: 0.8rem;
    color: var(--primary);
    background: var(--primary-tint);
    border-radius: 999px;
    padding: 0.35rem 0.85rem;
    font-weight: 600;
    white-space: nowrap;
}

/* ---------- Filters ---------- */
.filters {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
    align-items: center;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 1rem;
    margin-bottom: 1.25rem;
}
.filters .search-wrap {
    position: relative;
    flex: 1 1 220px;
}
.filters .search-wrap svg {
    position: absolute;
    left: 0.6rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-faint);
    pointer-events: none;
}
.filters input[type="search"] { padding-left: 2rem; }
.filters input, .filters select {
    padding: 0.5rem 0.65rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-alt);
    color: var(--text);
    font-size: 0.88rem;
    min-width: 0;
}
.filters input:focus, .filters select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 18%, transparent);
}
.filters button {
    padding: 0.5rem 1.1rem;
    border: none;
    border-radius: var(--radius-sm);
    background: var(--primary);
    color: #fff;
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease;
}
.filters button:hover { background: var(--primary-dark); }
.clear-link {
    color: var(--text-muted);
    font-size: 0.85rem;
    text-decoration: none;
    padding: 0.4rem 0.2rem;
}
.clear-link:hover { color: var(--accent); }

.result-summary { color: var(--text-muted); font-size: 0.85rem; margin: 0 0 0.75rem; }

/* ---------- Table ---------- */
.table-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}
.decisions-table {
    width: 100%;
    border-collapse: collapse;
}
.decisions-table thead th {
    text-align: left;
    font-size: 0.72rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-faint);
    font-weight: 600;
    background: var(--surface-alt);
    padding: 0.7rem 1rem;
    border-bottom: 1px solid var(--border);
}
.decisions-table td {
    padding: 0.7rem 1rem;
    border-bottom: 1px solid var(--border);
    font-size: 0.88rem;
    vertical-align: middle;
}
.decisions-table tbody tr:last-child td { border-bottom: none; }
.decisions-table tbody tr { transition: background 0.12s ease; }
.decisions-table tbody tr:hover { background: var(--surface-alt); }
.decisions-table td.mono, .decisions-table td:nth-child(4), .decisions-table td:nth-child(5) {
    font-family: var(--font-mono);
    font-size: 0.82rem;
    color: var(--text-muted);
}
.decisions-table a { text-decoration: none; font-weight: 600; }
.decisions-table a:hover { text-decoration: underline; }
.decisions-table .empty { text-align: center; color: var(--text-muted); padding: 3rem 1rem; font-size: 0.9rem; }

/* ---------- Pagination ---------- */
.pagination {
    display: flex;
    justify-content: space-between;
    margin-top: 1.25rem;
    gap: 0.75rem;
}
.pagination a, .pagination .disabled {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.5rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 500;
    transition: all 0.15s ease;
}
.pagination a:hover { border-color: var(--primary); color: var(--primary); }
.pagination .disabled { color: var(--text-faint); opacity: 0.5; pointer-events: none; }
.pagination .spacer { flex: 1; }

/* ---------- Decision detail ---------- */
.back-link {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    margin-bottom: 1rem;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.87rem;
}
.back-link:hover { color: var(--primary); }

.detail-header h1 {
    font-family: var(--font-serif);
    font-size: 1.5rem;
    line-height: 1.35;
    margin: 0 0 1rem;
}

.meta-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
}
.meta-chip {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.5rem 0.85rem;
}
.meta-chip .label {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-faint);
    font-weight: 600;
}
.meta-chip .value {
    font-size: 0.88rem;
    font-weight: 600;
    font-family: var(--font-mono);
}

.text-card-label {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-faint);
    font-weight: 600;
    margin-bottom: 0.5rem;
}
.decision-text {
    white-space: pre-wrap;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 1.75rem 2rem;
    font-family: var(--font-serif);
    font-size: 1rem;
    line-height: 1.75;
    color: var(--text);
    max-width: 74ch;
}

/* ---------- Empty state (RAG placeholder etc.) ---------- */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 0.85rem;
    background: var(--surface);
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    padding: 4rem 2rem;
    margin-top: 1rem;
    color: var(--text-muted);
}
.empty-state svg { color: var(--text-faint); }
.empty-state h1 {
    font-family: var(--font-serif);
    font-size: 1.4rem;
    color: var(--text);
    margin: 0;
}
.empty-state p { max-width: 46ch; margin: 0; font-size: 0.92rem; }
.badge-soon {
    display: inline-block;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--accent);
    background: var(--accent-tint);
    border-radius: 999px;
    padding: 0.25rem 0.75rem;
}

@media (max-width: 720px) {
    .container { padding: 1.25rem 1rem 3rem; }
    .topbar { padding: 0.6rem 1rem; flex-wrap: wrap; }
    .topbar nav { gap: 1rem; }
    .decisions-table thead { display: none; }
    .decisions-table, .decisions-table tbody, .decisions-table tr, .decisions-table td { display: block; width: 100%; }
    .decisions-table tr { border-bottom: 1px solid var(--border); padding: 0.6rem 0; }
    .decisions-table td { border-bottom: none; padding: 0.15rem 1rem; }
}
