/* === Design Tokens === */

:root {
    /* Core palette */
    --bg: #fafafa;
    --surface: #fff;
    --text: #1a1a1a;
    --text-muted: #666;
    --border: #ddd;
    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --success: #16a34a;
    --error: #dc2626;
    --warning: #d97706;

    /* Verdict semantic colors */
    --verdict-positive-bg: #dcfce7;
    --verdict-positive-text: #166534;
    --verdict-negative-bg: #fee2e2;
    --verdict-negative-text: #991b1b;
    --verdict-caution-bg: #fef3c7;
    --verdict-caution-text: #92400e;
    --verdict-neutral-bg: #e5e7eb;
    --verdict-neutral-text: #374151;

    /* Status colors */
    --status-queued-bg: #e5e7eb;
    --status-queued-text: #4b5563;
    --status-processing-bg: #dbeafe;
    --status-processing-text: #1d4ed8;
    --status-complete-bg: #dcfce7;
    --status-complete-text: #16a34a;
    --status-error-bg: #fee2e2;
    --status-error-text: #dc2626;

    /* UI chrome */
    --chrome-light: #f3f4f6;
    --chrome-lighter: #f9fafb;
    --badge-cached-bg: #e0e7ff;
    --badge-cached-text: #4338ca;
    --overlay-subtle: rgba(0,0,0,0.06);

    /* Spacing scale */
    --space-xs: 0.25rem;
    --space-sm: 0.5rem;
    --space-md: 1rem;
    --space-lg: 1.5rem;
    --space-xl: 2rem;
}

/* === Dark Mode === */

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #111;
        --surface: #1a1a1a;
        --text: #e5e5e5;
        --text-muted: #999;
        --border: #333;
        --accent: #60a5fa;
        --accent-hover: #93bbfd;
        --success: #4ade80;
        --error: #f87171;
        --warning: #fbbf24;

        --verdict-positive-bg: #052e16;
        --verdict-positive-text: #86efac;
        --verdict-negative-bg: #450a0a;
        --verdict-negative-text: #fca5a5;
        --verdict-caution-bg: #451a03;
        --verdict-caution-text: #fde68a;
        --verdict-neutral-bg: #1f2937;
        --verdict-neutral-text: #d1d5db;

        --status-queued-bg: #1f2937;
        --status-queued-text: #d1d5db;
        --status-processing-bg: #172554;
        --status-processing-text: #93c5fd;
        --status-complete-bg: #052e16;
        --status-complete-text: #86efac;
        --status-error-bg: #450a0a;
        --status-error-text: #fca5a5;

        --chrome-light: #222;
        --chrome-lighter: #1a1a1a;
        --badge-cached-bg: #1e1b4b;
        --badge-cached-text: #a5b4fc;
        --overlay-subtle: rgba(255,255,255,0.06);
    }
}

/* === Reset === */

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
}

/* === Navigation === */

nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem var(--space-xl);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 1.25rem; color: var(--text); text-decoration: none; }
.nav-right { display: flex; align-items: center; gap: 1.25rem; font-size: 0.9rem; }
.nav-right a { color: var(--text-muted); text-decoration: none; }
.nav-right a:hover { color: var(--text); }
.user-name { color: var(--text-muted); font-style: italic; }

/* === Layout === */

main {
    max-width: 52rem;
    margin: var(--space-xl) auto;
    padding: 0 var(--space-lg);
}
main.wide { max-width: 80rem; }

h1 { margin-bottom: var(--space-lg); font-size: 1.5rem; }
h2 { margin: var(--space-lg) 0 var(--space-md); font-size: 1.2rem; }

/* === Forms === */

label { display: block; margin-bottom: var(--space-xs); font-weight: 500; font-size: 0.9rem; }

input[type="text"], textarea, select {
    width: 100%;
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.95rem;
    font-family: inherit;
    margin-bottom: var(--space-md);
    background: var(--surface);
    color: var(--text);
}
textarea { resize: vertical; }

button {
    padding: 0.6rem var(--space-lg);
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 0.95rem;
    cursor: pointer;
}
button:hover { background: var(--accent-hover); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

/* === Tables === */

table { width: 100%; border-collapse: collapse; }
th, td { padding: 0.6rem 0.75rem; text-align: left; border-bottom: 1px solid var(--border); font-size: 0.9rem; }
th { font-weight: 600; color: var(--text-muted); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; }
td a { color: var(--accent); text-decoration: none; }
td a:hover { text-decoration: underline; }

/* === Status badges === */

.status {
    display: inline-block;
    padding: 0.15rem var(--space-sm);
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 500;
}
.status-queued { background: var(--status-queued-bg); color: var(--status-queued-text); }
.status-processing { background: var(--status-processing-bg); color: var(--status-processing-text); }
.status-complete { background: var(--status-complete-bg); color: var(--status-complete-text); }
.status-error { background: var(--status-error-bg); color: var(--status-error-text); }

/* === Login === */

.login-container { max-width: 24rem; margin: 6rem auto; text-align: center; }
.login-container h1 { font-size: 2rem; }
.subtitle { color: var(--text-muted); margin-bottom: var(--space-xl); }
.login-container form { text-align: left; }

/* === Notices === */

.error { background: var(--status-error-bg); color: var(--status-error-text); padding: 0.75rem var(--space-md); border-radius: 6px; margin-bottom: var(--space-md); }
.success { background: var(--status-complete-bg); color: var(--status-complete-text); padding: 0.75rem var(--space-md); border-radius: 6px; margin-bottom: var(--space-md); }
.empty { color: var(--text-muted); }

/* === Claim box === */

.claim-box {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1.25rem;
    margin-bottom: var(--space-lg);
}
.claim-meta { margin-top: 0.75rem; font-size: 0.85rem; color: var(--text-muted); }

.processing-notice {
    background: var(--status-processing-bg);
    color: var(--status-processing-text);
    padding: var(--space-md);
    border-radius: 8px;
    margin-bottom: var(--space-lg);
}

/* === Result header === */

.result-header { display: flex; align-items: center; gap: var(--space-md); margin-bottom: var(--space-lg); }
.result-header h1 { margin-bottom: 0; }

/* === Verdict banner === */

.verdict-banner {
    padding: var(--space-md) 1.25rem;
    border-radius: 8px;
    margin-bottom: var(--space-lg);
    background: var(--chrome-light);
}
.verdict-main {
    display: flex;
    align-items: baseline;
    gap: 0.75rem;
    flex-wrap: wrap;
}
.verdict-icon { font-size: 1.5rem; line-height: 1; }
.verdict-label { font-size: 1.25rem; font-weight: 700; }
.verdict-confidence {
    font-size: 0.95rem;
    color: var(--text-muted);
    padding: 0.15rem 0.6rem;
    background: var(--overlay-subtle);
    border-radius: 999px;
}
.verdict-explanation {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 0.4rem;
    font-style: italic;
}

/* Verdict color variants */
.verdict-true, .verdict-mostly-true { background: var(--verdict-positive-bg); }
.verdict-true .verdict-icon, .verdict-mostly-true .verdict-icon { color: var(--verdict-positive-text); }
.verdict-false, .verdict-mostly-false { background: var(--verdict-negative-bg); }
.verdict-false .verdict-icon, .verdict-mostly-false .verdict-icon { color: var(--verdict-negative-text); }
.verdict-misleading, .verdict-lacks-context { background: var(--verdict-caution-bg); }
.verdict-misleading .verdict-icon, .verdict-lacks-context .verdict-icon { color: var(--verdict-caution-text); }
.verdict-mixed { background: var(--verdict-caution-bg); }
.verdict-mixed .verdict-icon { color: var(--verdict-caution-text); }
.verdict-unverifiable, .verdict-outdated, .verdict-insufficient-evidence { background: var(--verdict-neutral-bg); }
.verdict-unverifiable .verdict-icon, .verdict-outdated .verdict-icon,
.verdict-insufficient-evidence .verdict-icon { color: var(--verdict-neutral-text); }

/* === Full output (raw markdown) === */

.full-output {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: var(--space-lg) var(--space-xl);
    font-size: 0.9rem;
    line-height: 1.7;
    margin-bottom: var(--space-md);
}
.full-output h2, .full-output h3, .full-output h4 {
    margin-top: var(--space-lg);
    margin-bottom: var(--space-sm);
}
.full-output h2:first-child, .full-output h3:first-child, .full-output h4:first-child {
    margin-top: 0;
}
.full-output h2 { font-size: 1.1rem; }
.full-output h3 { font-size: 1rem; }
.full-output h4 { font-size: 0.95rem; }
.full-output p { margin: 0.75rem 0; }
.full-output ul, .full-output ol { margin: 0.75rem 0; padding-left: var(--space-lg); }
.full-output li { margin-bottom: 0.35rem; }
.full-output hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 1.25rem 0;
}
.full-output strong { font-weight: 600; }
.full-output a { color: var(--accent); text-decoration: none; }
.full-output a:hover { text-decoration: underline; }
.full-output table { width: 100%; border-collapse: collapse; margin: 0.75rem 0; }
.full-output table th, .full-output table td {
    padding: 0.4rem 0.75rem;
    border: 1px solid var(--border);
    font-size: 0.85rem;
}
.full-output table th { background: var(--chrome-lighter); }

.result-meta { font-size: 0.8rem; color: var(--text-muted); margin-bottom: var(--space-lg); }

/* === Badges === */

.badge { display: inline-block; padding: 0.15rem var(--space-sm); border-radius: 999px; font-size: 0.75rem; }
.badge-cached { background: var(--badge-cached-bg); color: var(--badge-cached-text); }

.invite-code {
    display: inline-block;
    margin-top: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    background: var(--chrome-light);
    border-radius: 6px;
    font-size: 1.1rem;
    user-select: all;
}

.inline-form { display: flex; gap: var(--space-sm); align-items: end; margin-bottom: var(--space-xl); }
.inline-form input { margin-bottom: 0; }

/* === Follow-ups === */

.follow-ups { margin-top: var(--space-xl); }
.follow-ups h2 { font-size: 1.15rem; margin-bottom: var(--space-md); }

.follow-up-card { margin-bottom: 1.25rem; }
.follow-up-question {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: var(--space-md) 1.25rem;
    font-weight: 600;
    font-size: 0.9rem;
    margin-bottom: var(--space-sm);
}
.follow-up-answer {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1.25rem var(--space-lg);
    font-size: 0.9rem;
    line-height: 1.7;
}
.follow-up-answer p { margin: 0.75rem 0; }
.follow-up-answer p:first-child { margin-top: 0; }
.follow-up-answer ul, .follow-up-answer ol { margin: 0.75rem 0; padding-left: var(--space-lg); }
.follow-up-answer li { margin-bottom: 0.35rem; }
.follow-up-answer strong { font-weight: 600; }
.follow-up-answer a { color: var(--accent); text-decoration: none; }
.follow-up-answer a:hover { text-decoration: underline; }
.follow-up-answer hr { border: none; border-top: 1px solid var(--border); margin: var(--space-md) 0; }

.follow-up-processing {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: var(--space-md) 1.25rem;
    color: var(--accent);
    font-size: 0.85rem;
    font-style: italic;
}
.follow-up-error {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: var(--space-md) 1.25rem;
    color: var(--error);
    font-size: 0.85rem;
}
.follow-up-meta { font-size: 0.75rem; color: var(--text-muted); margin-top: var(--space-sm); }

.follow-up-form { margin-top: var(--space-lg); padding-top: var(--space-md); border-top: 1px solid var(--border); }
.follow-up-form textarea { min-height: 4rem; margin-bottom: var(--space-sm); }
.follow-up-form button { padding: var(--space-sm) 1.25rem; font-size: 0.9rem; }

/* Follow-up list using dl/dt/dd */
.follow-up-list { margin: 0; }
.follow-up-list dt { font-weight: 600; margin-bottom: var(--space-xs); }
.follow-up-list dd { margin-left: 0; margin-bottom: var(--space-md); }

/* === Structured result sections === */

.section-verified-facts {
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 4px solid var(--success);
    border-radius: 8px;
    padding: var(--space-md) var(--space-lg);
    margin-bottom: var(--space-md);
}
.section-verified-facts h2 {
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--text-muted);
    margin-bottom: var(--space-sm);
}
.section-verified-facts p { margin: 0.4rem 0; }

.section-evidence {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: var(--space-md) var(--space-lg);
    margin-bottom: var(--space-md);
}
.section-evidence h2 {
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--text-muted);
    margin-bottom: var(--space-sm);
}
.section-evidence ul, .section-evidence ol { padding-left: 1.25rem; }
.section-evidence li { margin-bottom: var(--space-sm); line-height: 1.5; }
.section-evidence p { margin: 0.4rem 0; }

.section-meta-inline {
    font-size: 0.85rem;
    color: var(--text-muted);
    padding: 0.4rem 0;
    border-bottom: 1px solid var(--border);
    margin-bottom: var(--space-sm);
}

.section-expandable {
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 0.75rem;
}
.section-expandable summary {
    padding: 0.75rem 1.25rem;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.9rem;
    list-style: none;
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}
.section-expandable summary::before {
    content: "\25B6";
    font-size: 0.65rem;
    transition: transform 0.15s;
}
.section-expandable[open] summary::before {
    transform: rotate(90deg);
}
.section-expandable summary::-webkit-details-marker { display: none; }
.section-expandable .section-body {
    padding: 0 1.25rem var(--space-md);
    font-size: 0.9rem;
    line-height: 1.6;
}
.section-expandable .section-body p { margin: var(--space-sm) 0; }

.flag-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.25rem;
    height: 1.25rem;
    padding: 0 0.35rem;
    background: var(--warning);
    color: #fff;
    font-size: 0.7rem;
    font-weight: 700;
    border-radius: 999px;
}

.trust-footer {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-sm);
    padding: 0.75rem 0;
    margin-top: var(--space-md);
    border-top: 1px solid var(--border);
    font-size: 0.8rem;
    color: var(--text-muted);
}
.trust-footer span::after { content: "\00B7"; margin-left: var(--space-sm); }
.trust-footer span:last-child::after { content: ""; }

/* === Accessibility === */

.skip-link {
    position: absolute;
    top: -100%;
    left: var(--space-md);
    padding: var(--space-sm) var(--space-md);
    background: var(--accent);
    color: #fff;
    border-radius: 4px;
    z-index: 1000;
    text-decoration: none;
    font-weight: 600;
}
.skip-link:focus { top: var(--space-sm); }

:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 2px;
}
a:focus-visible { border-radius: 2px; }

nav a[aria-current="page"] {
    font-weight: 700;
    text-decoration: underline;
    text-underline-offset: 4px;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* === Utility === */

.text-muted { color: var(--text-muted); font-size: 0.85rem; }
.user-inactive td { opacity: 0.5; }

.btn-small {
    padding: var(--space-xs) 0.6rem;
    font-size: 0.8rem;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 4px;
    cursor: pointer;
}
.btn-small:hover { background: var(--bg); }

.cost-total-row td { font-weight: 600; border-top: 2px solid var(--text); }

/* Per-claim cost table: prevent soft-breaking on hyphenated dates and
   numeric columns. Claim column (2nd) keeps wrapping behaviour so long
   claim titles don't force unbounded horizontal scroll. */
.cost-claims-table th,
.cost-claims-table td { white-space: nowrap; }
.cost-claims-table th:nth-child(2),
.cost-claims-table td:nth-child(2) {
    white-space: normal;
    max-width: 20rem;
}
.cost-claims-table td:not(:nth-child(2)):not(:nth-child(4)) {
    font-variant-numeric: tabular-nums;
}

/* === Responsive === */

@media (max-width: 640px) {
    nav {
        flex-direction: column;
        gap: var(--space-sm);
        padding: var(--space-sm) var(--space-md);
    }
    .nav-right {
        flex-wrap: wrap;
        justify-content: center;
        gap: 0.75rem;
        font-size: 0.85rem;
    }

    main { padding: 0 var(--space-md); margin: var(--space-md) auto; }

    h1 { font-size: 1.25rem; }

    button { width: 100%; }

    .login-container { margin: var(--space-xl) auto; }

    .inline-form { flex-direction: column; }
    .inline-form input { margin-bottom: var(--space-sm); }
    .inline-form button { width: 100%; }

    .verdict-main { gap: var(--space-sm); }
    .verdict-label { font-size: 1.1rem; }

    .trust-footer { font-size: 0.75rem; }
}

/* === Reduced Motion === */

@media (prefers-reduced-motion: reduce) {
    .section-expandable summary::before {
        transition: none;
    }
}
