:root {
    --bg: #07070c;
    --panel: rgba(22, 22, 30, 0.72);
    --panel-solid: #16161e;
    --text: #ffffff;
    --muted: #9ca3af;
    --accent: #7c5cff;
    --accent2: #fbbf24;
    --border: rgba(255,255,255,0.08);
    --nav-h: 64px;
    --blur: 18px;
    --radius: 18px;
}

/* GLOBAL RESET */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial;
}

body {
    background: radial-gradient(circle at 20% 10%, rgba(124,92,255,0.18), transparent 40%),
                radial-gradient(circle at 80% 80%, rgba(251,191,36,0.10), transparent 45%),
                var(--bg);
    color: var(--text);
    overflow: hidden;
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    background-image: url("https://grainy-gradients.vercel.app/noise.svg");
    opacity: 0.06;
    pointer-events: none;
}

/* APP FRAME */
.app-container {
    height: 100vh;
    max-width: 640px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    position: relative;
}

/* ==========================================
   HEADER
   ========================================== */
.app-header {
    padding: 14px 20px;
    -webkit-backdrop-filter: blur(var(--blur));
    backdrop-filter: blur(var(--blur));
    background: rgba(10,10,14,0.6);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 50;
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-logo {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    flex: 0 0 auto;
    box-shadow: 0 0 14px rgba(124,92,255,0.28);
}

.header-text { display: flex; flex-direction: column; }

.header-title {
    font-size: 1.3rem;
    letter-spacing: 0.22em;
    font-weight: 700;
    line-height: 1.1;
}

.header-subtitle {
    font-size: 0.7rem;
    color: var(--muted);
    letter-spacing: 0.14em;
}

/* ==========================================
   VIEW SYSTEM
   ========================================== */
.view-container {
    flex: 1;
    overflow-y: auto;
    padding: 18px;
    padding-bottom: calc(var(--nav-h) + 90px);
}

.app-view {
    display: none;
    opacity: 0;
    transform: translateY(10px);
}

.app-view.active {
    display: block;
    animation: fadeUp 0.35s ease forwards;
    pointer-events: auto;
}

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

/* TYPOGRAPHY */
h2 { font-size: 1.4rem; margin-bottom: 6px; }
p { color: var(--muted); font-size: 0.92rem; }
.muted { color: var(--muted); }

/* ==========================================
   GLASS CARDS (AI + Source results)
   ========================================== */
.source-card, .ai-card {
    background: var(--panel);
    -webkit-backdrop-filter: blur(var(--blur));
    backdrop-filter: blur(var(--blur));
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-top: 14px;
    position: relative;
    box-shadow: 0 10px 30px rgba(0,0,0,0.25);
    transition: transform 0.2s ease, border-color 0.2s ease;
}

.source-card:hover {
    transform: translateY(-2px);
    border-color: rgba(124,92,255,0.35);
}

.source-card { border-left: 3px solid var(--accent2); }
.source-title { font-weight: 650; margin-bottom: 4px; }
.source-agency { font-size: 0.7rem; color: var(--muted); letter-spacing: 0.12em; }
.source-meta { font-size: 0.75rem; color: var(--muted); }

/* BADGE */
.badge {
    position: absolute;
    top: 14px;
    right: 14px;
    font-size: 0.6rem;
    padding: 4px 8px;
    border-radius: 999px;
    background: rgba(124,92,255,0.15);
    color: var(--accent);
    border: 1px solid rgba(124,92,255,0.3);
}

/* AI CARD */
.ai-card { border: 1px solid rgba(124,92,255,0.4); }
.ai-card.speculative { border-color: rgba(251,191,36,0.5); }
.ai-header { font-size: 0.65rem; letter-spacing: 0.18em; color: var(--accent); margin-bottom: 10px; }
.ai-card.speculative .ai-header { color: var(--accent2); }
.ai-content { font-size: 0.95rem; line-height: 1.55; }

/* ==========================================
   ARCHIVE LIST
   ========================================== */
.archive-status { font-size: 0.72rem; color: var(--muted); letter-spacing: 0.06em; margin: 10px 0 16px; }
.archive-status.error-line { color: #ef4444; }
.archive-list { display: flex; flex-direction: column; gap: 10px; }

.archive-row {
    display: flex;
    align-items: stretch;
    gap: 12px;
    background: var(--panel);
    -webkit-backdrop-filter: blur(var(--blur));
    backdrop-filter: blur(var(--blur));
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 14px 14px 14px 0;
    overflow: hidden;
    position: relative;
    cursor: pointer;
    transition: transform 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}
.archive-row:hover {
    transform: translateY(-1px);
    border-color: rgba(124,92,255,0.35);
    background: rgba(124,92,255,0.06);
}

.archive-accent { width: 3px; border-radius: 3px; flex: 0 0 auto; align-self: stretch; }
.archive-body { flex: 1 1 auto; min-width: 0; padding-left: 2px; }
.archive-title { font-weight: 650; font-size: 0.95rem; line-height: 1.32; margin-bottom: 5px; word-break: break-word; }
.archive-agency { font-size: 0.64rem; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); }
.archive-meta { font-size: 0.72rem; color: var(--muted); margin-top: 4px; }
.archive-badge {
    flex: 0 0 auto; align-self: flex-start; margin-top: 2px; font-size: 0.56rem; letter-spacing: 0.06em;
    padding: 4px 8px; border-radius: 999px; background: rgba(124,92,255,0.15); color: var(--accent);
    border: 1px solid rgba(124,92,255,0.3); white-space: nowrap;
}

/* Repository tag — color injected inline per corpus */
.archive-repo-tag {
    display: inline-flex;
    align-items: center;
    font-size: 0.52rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    padding: 3px 9px;
    border-radius: 999px;
    border: 1px solid;
    margin-bottom: 7px;
    white-space: nowrap;
}

/* Brief corpus description line */
.archive-desc {
    font-size: 0.7rem;
    color: var(--muted);
    margin-top: 5px;
    line-height: 1.4;
    font-style: italic;
}

/* ==========================================
   DOCUMENT VIEWER
   ========================================== */
.doc-back-btn {
    background: rgba(124,92,255,0.12); color: var(--accent); border: 1px solid rgba(124,92,255,0.3);
    border-radius: 999px; padding: 8px 16px; font-size: 0.85rem; cursor: pointer; margin-bottom: 16px; transition: all 0.2s ease;
}
.doc-back-btn:hover { background: rgba(124,92,255,0.2); }

.document-header {
    background: var(--panel);
    -webkit-backdrop-filter: blur(var(--blur));
    backdrop-filter: blur(var(--blur));
    border: 1px solid var(--border); border-left: 3px solid var(--accent2);
    border-radius: var(--radius); padding: 16px; margin-bottom: 16px;
}
.document-title { font-size: 1.15rem; font-weight: 700; line-height: 1.3; }
.document-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.doc-chip {
    font-size: 0.6rem; letter-spacing: 0.08em; text-transform: uppercase; font-weight: 700; padding: 4px 8px;
    border-radius: 999px; background: rgba(124,92,255,0.15); color: var(--accent); border: 1px solid rgba(124,92,255,0.3);
}
.document-sub { font-size: 0.78rem; color: var(--muted); margin-top: 10px; }
.document-pagecount { font-size: 0.72rem; color: var(--muted); margin-top: 6px; letter-spacing: 0.06em; }
.document-pages { display: flex; flex-direction: column; gap: 14px; }
.doc-loading { text-align: center; color: var(--accent2); padding: 24px 0; animation: pulse 1.4s infinite; }

/* page-unit = outer visible card (border, radius, bg, overflow clip for image corners) */
.page-unit {
    background: var(--panel);
    -webkit-backdrop-filter: blur(var(--blur));
    backdrop-filter: blur(var(--blur));
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

/* page-card = inner content area (image + head + transcription); no border/bg of its own */
.page-card {
    background: transparent;
}
.page-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; }
.page-label { font-size: 0.65rem; font-weight: 700; letter-spacing: 0.1em; color: var(--accent); }
.page-count { font-size: 0.62rem; color: var(--muted); }
.page-img-link { display: block; background: #0d0d14; }
.page-img { display: block; width: 100%; height: auto; }
.page-noimg { display: flex; align-items: center; justify-content: center; height: 180px; background: #0d0d14; color: var(--muted); font-size: 0.8rem; }

.page-ocr { border-top: 1px solid var(--border); }
.page-ocr summary {
    cursor: pointer; padding: 10px 12px; font-size: 0.72rem; font-weight: 600;
    letter-spacing: 0.08em; color: var(--accent); list-style: none;
}
.page-ocr summary::-webkit-details-marker { display: none; }
.page-ocr summary::before { content: "▸ "; }
.page-ocr[open] summary::before { content: "▾ "; }
.page-ocr pre {
    margin: 0; padding: 0 12px 14px; white-space: pre-wrap; word-break: break-word;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.78rem; line-height: 1.5; color: var(--muted);
}

/* ==========================================
   INFO / LEGAL PAGES
   ========================================== */
.info-body {
    margin-top: 8px;
    background: var(--panel);
    -webkit-backdrop-filter: blur(var(--blur));
    backdrop-filter: blur(var(--blur));
    border: 1px solid var(--border); border-left: 3px solid var(--accent2);
    border-radius: var(--radius); padding: 18px 18px 22px; line-height: 1.6;
}
.info-body h3 { font-size: 0.95rem; margin: 18px 0 6px; color: var(--text); letter-spacing: 0.02em; }
.info-body h3:first-child { margin-top: 0; }
.info-body p { font-size: 0.88rem; color: var(--muted); margin-bottom: 10px; }
.info-body ul { margin: 4px 0 12px 18px; }
.info-body li { font-size: 0.88rem; color: var(--muted); margin-bottom: 6px; }
.info-body a { color: var(--accent); text-decoration: none; }
.info-updated { font-size: 0.7rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); margin-bottom: 14px; }

/* ==========================================
   SETTINGS / HOME MENU
   ========================================== */
.settings-menu { margin-top: 24px; display: flex; flex-direction: column; gap: 10px; }
.settings-item {
    display: flex; align-items: center; padding: 16px 20px;
    background: var(--panel);
    -webkit-backdrop-filter: blur(var(--blur));
    backdrop-filter: blur(var(--blur));
    border: 1px solid var(--border); border-radius: 12px; color: var(--muted);
    text-decoration: none; font-size: 0.9rem; cursor: pointer; transition: all 0.2s ease;
}
.settings-item:hover {
    color: var(--text); border-color: rgba(124,92,255,0.4);
    background: rgba(124,92,255,0.08); transform: translateY(-1px);
}
.settings-item.support-link { border-left: 3px solid var(--accent2); color: var(--text); font-weight: 600; }

/* ==========================================
   CHIPS
   ========================================== */
.chips-container { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }
.chip {
    border: 1px solid var(--border); background: rgba(255,255,255,0.03);
    padding: 10px 14px; border-radius: 999px; font-size: 0.8rem; color: var(--text);
    transition: all 0.2s ease; cursor: pointer;
}
.chip:hover { transform: translateY(-1px); border-color: rgba(124,92,255,0.4); background: rgba(124,92,255,0.08); }

/* ==========================================
   SEARCH BAR
   ========================================== */
.search-wrapper {
    position: fixed; bottom: var(--nav-h); left: 0; right: 0;
    max-width: 640px; margin: 0 auto; padding: 14px 16px; z-index: 80;
}
.search-box {
    display: flex; align-items: center; background: rgba(22,22,30,0.7);
    -webkit-backdrop-filter: blur(16px);
    backdrop-filter: blur(16px);
    border: 1px solid var(--border); border-radius: 999px;
    padding: 6px 6px 6px 20px; gap: 8px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.4);
    transition: border-color 0.2s ease;
}
.search-box:focus-within { border-color: rgba(124,92,255,0.5); }
#prompt-input {
    flex: 1; background: transparent; border: none; color: var(--text);
    font-size: 1rem; outline: none; min-width: 0;
}
#prompt-input::placeholder { color: var(--muted); }
#search-btn {
    width: 44px; height: 44px; border-radius: 50%; border: none;
    background: linear-gradient(135deg, var(--accent), #5b3fd4);
    color: #fff; display: flex; align-items: center; justify-content: center;
    cursor: pointer; flex: 0 0 auto; transition: transform 0.15s ease, opacity 0.15s ease;
}
#search-btn:hover { transform: scale(1.08); }
#search-btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

/* ==========================================
   BOTTOM NAV
   ========================================== */
.bottom-nav {
    position: fixed; bottom: 0; left: 0; right: 0; max-width: 640px; margin: 0 auto;
    height: var(--nav-h); display: flex; align-items: center; justify-content: space-around;
    background: rgba(10,10,14,0.85);
    -webkit-backdrop-filter: blur(var(--blur));
    backdrop-filter: blur(var(--blur));
    border-top: 1px solid var(--border); z-index: 100;
}
.nav-item {
    display: flex; flex-direction: column; align-items: center; gap: 4px;
    color: var(--muted); cursor: pointer; transition: color 0.2s ease;
    padding: 8px 20px; border-radius: 12px; font-size: 0.7rem; letter-spacing: 0.06em;
    background: transparent; border: none; font-family: inherit;
}
.nav-item:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.nav-item svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.nav-item.active { color: var(--accent); }
.nav-item.active svg { filter: drop-shadow(0 0 6px rgba(124,92,255,0.5)); }

/* ==========================================
   RESULTS AREA
   ========================================== */
#results-container { display: flex; flex-direction: column; }
#error-container { color: #ef4444; font-size: 0.85rem; padding: 10px 0; text-align: center; }
#loading-indicator {
    display: none; text-align: center; padding: 24px 0;
    color: var(--accent2); font-size: 0.85rem; letter-spacing: 0.1em;
    animation: pulse 1.4s infinite;
}
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:0.4} }

.section-label {
    font-size: 0.6rem; letter-spacing: 0.18em; text-transform: uppercase;
    color: var(--muted); margin-top: 20px; margin-bottom: 4px;
}

/* ==========================================
   SHARE ROW
   ========================================== */
.page-share-row {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 12px; border-top: 1px solid var(--border);
}
.share-row-label {
    font-size: 0.55rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted);
    margin-right: auto;
}
.share-btn {
    width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--border);
    background: rgba(255,255,255,0.04); color: var(--muted); display: flex;
    align-items: center; justify-content: center; cursor: pointer;
    transition: all 0.18s ease; flex: 0 0 auto;
}
.share-btn:hover { transform: scale(1.12); border-color: rgba(124,92,255,0.4); color: var(--text); }
.share-btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
.share-fb:hover  { border-color: rgba(24,119,242,0.5); color: #1877f2; }
.share-tw:hover  { border-color: rgba(255,255,255,0.3); color: var(--text); }
.share-wa:hover  { border-color: rgba(37,211,102,0.5); color: #25d366; }

#share-toast {
    position: fixed; bottom: calc(var(--nav-h) + 80px); left: 50%; transform: translateX(-50%) translateY(12px);
    background: rgba(22,22,30,0.95); border: 1px solid var(--border); border-radius: 999px;
    padding: 10px 20px; font-size: 0.82rem; color: var(--text); white-space: nowrap;
    opacity: 0; transition: opacity 0.25s ease, transform 0.25s ease; pointer-events: none; z-index: 200;
}
#share-toast.visible { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ==========================================
   QUERIES REMAINING BADGE
   ========================================== */
.queries-badge {
    text-align: center; margin: 18px 0; font-size: 0.72rem;
    color: var(--muted); letter-spacing: 0.08em;
}

/* ==========================================
   CTA / SUPPORT
   ========================================== */
.cta-card {
    background: var(--panel);
    -webkit-backdrop-filter: blur(var(--blur));
    backdrop-filter: blur(var(--blur));
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-top: 14px;
}

.cta-label {
    font-size: 0.6rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    font-weight: 700;
    color: var(--accent2);
    border: 1px solid rgba(251,191,36,0.4);
    background: rgba(251,191,36,0.1);
    border-radius: 999px;
    padding: 3px 10px;
    margin-bottom: 12px;
}

.cta-heading {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text);
    line-height: 1.3;
    margin-bottom: 10px;
}

.cta-body {
    font-size: 0.88rem;
    color: var(--muted);
    line-height: 1.55;
    margin-bottom: 18px;
}

.cta-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 14px 20px;
    background: linear-gradient(135deg, rgba(251,191,36,0.18), rgba(251,191,36,0.08));
    border: 1px solid rgba(251,191,36,0.5);
    border-radius: 12px;
    color: var(--accent2);
    font-weight: 700;
    font-size: 0.95rem;
    text-decoration: none;
    letter-spacing: 0.02em;
    transition: all 0.2s ease;
}

.cta-btn:hover {
    background: linear-gradient(135deg, rgba(251,191,36,0.28), rgba(251,191,36,0.14));
    border-color: rgba(251,191,36,0.75);
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(251,191,36,0.15);
}

/* ==========================================
   ARCHIVE SEARCH BAR
   ========================================== */
.archive-search-wrap {
    display: flex;
    align-items: center;
    background: var(--panel);
    -webkit-backdrop-filter: blur(var(--blur));
    backdrop-filter: blur(var(--blur));
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 4px 12px;
    margin: 14px 0 6px;
    gap: 8px;
    transition: border-color 0.2s ease;
}

.archive-search-wrap:focus-within {
    border-color: rgba(124,92,255,0.45);
    box-shadow: 0 0 0 3px rgba(124,92,255,0.1);
}

.archive-search-icon {
    color: var(--muted);
    flex-shrink: 0;
}

#archive-search {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text);
    font-size: 0.9rem;
    padding: 10px 0;
    outline: none;
}

#archive-search::placeholder { color: var(--muted); }
#archive-search::-webkit-search-cancel-button { display: none; }

.archive-search-clear {
    display: none;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: none;
    background: rgba(255,255,255,0.1);
    color: var(--muted);
    font-size: 1rem;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.15s ease;
}
.archive-search-clear:hover { background: rgba(255,255,255,0.18); color: var(--text); }

/* ==========================================
   TRANSCRIPT SEARCH RESULTS
   ========================================== */
.archive-search-icon-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    color: var(--accent);
    cursor: pointer;
    border-radius: 8px;
    flex-shrink: 0;
    transition: background 0.15s ease;
}
.archive-search-icon-btn:hover { background: rgba(124,92,255,0.12); }

.search-result-card {
    display: flex;
    gap: 12px;
    background: var(--panel);
    -webkit-backdrop-filter: blur(var(--blur));
    backdrop-filter: blur(var(--blur));
    border: 1px solid var(--border);
    border-left: 3px solid var(--accent2);
    border-radius: 14px;
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.15s ease, border-color 0.15s ease;
}
.search-result-card:hover {
    transform: translateY(-1px);
    border-color: rgba(124,92,255,0.4);
}

.search-result-thumb {
    width: 90px;
    min-width: 90px;
    object-fit: cover;
    background: #0d0d14;
}
.search-result-no-thumb {
    width: 90px;
    min-width: 90px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #0d0d14;
    font-size: 0.6rem;
    color: var(--muted);
    letter-spacing: 0.08em;
}

.search-result-body {
    flex: 1;
    min-width: 0;
    padding: 12px 12px 12px 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.search-result-title {
    font-weight: 700;
    font-size: 0.88rem;
    line-height: 1.3;
    color: var(--text);
}
.search-result-meta {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 4px;
    font-size: 0.62rem;
    color: var(--muted);
    letter-spacing: 0.06em;
    text-transform: uppercase;
}
.search-result-page { color: var(--accent2); font-weight: 600; }
.search-result-excerpt {
    font-size: 0.78rem;
    color: var(--muted);
    line-height: 1.5;
    margin-top: 4px;
    word-break: break-word;
}
mark.search-hi {
    background: rgba(251,191,36,0.25);
    color: var(--accent2);
    border-radius: 3px;
    padding: 0 2px;
    font-weight: 600;
}

.search-empty {
    text-align: center;
    padding: 40px 20px;
    color: var(--muted);
    font-size: 0.9rem;
    line-height: 1.6;
}
.search-empty-icon { font-size: 2rem; margin-bottom: 12px; }

/* ==========================================
   TEXT SIZE CONTROL (transcript)
   ========================================== */
.text-size-control {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 14px;
    padding: 8px 12px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 12px;
}
.text-size-label {
    font-size: 0.7rem;
    color: var(--muted);
    letter-spacing: 0.06em;
    margin-right: auto;
}
.text-size-btn {
    min-width: 40px;
    min-height: 40px;
    border-radius: 9px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--muted);
    font-size: 0.85rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.15s ease;
}
.text-size-btn:hover { color: var(--text); border-color: rgba(124,92,255,0.4); }
.text-size-btn.active {
    background: rgba(124,92,255,0.18);
    color: var(--accent);
    border-color: rgba(124,92,255,0.5);
}

/* Transcript size scales — Small is default. Higher specificity than base .page-ocr pre */
.document-pages.ocr-sm .page-ocr pre { font-size: 0.78rem; line-height: 1.5; }
.document-pages.ocr-md .page-ocr pre { font-size: 0.95rem; line-height: 1.6; }
.document-pages.ocr-lg .page-ocr pre { font-size: 1.15rem; line-height: 1.7; }