:root {
    --bg: #f5f6fa;
    --surface: #ffffff;
    --surface-2: #f0f2f7;
    --text: #1d2433;
    --muted: #6b7385;
    --border: #e1e4ec;
    --accent: #be185d;
    --accent-ink: #ffffff;
    --accent-soft: #fce7f3;
    --danger: #b42318;
    --danger-soft: #fee4e2;
    --info-soft: #e8f0fe;
    --radius: 10px;
    --font: "Inter", "Noto Sans Tamil", system-ui, sans-serif;
    --font-tamil: "Noto Sans Tamil", "Inter", system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
    :root {
        --bg: #12141a;
        --surface: #1b1e27;
        --surface-2: #232733;
        --text: #e7e9ef;
        --muted: #9aa1b2;
        --border: #2e3342;
        --accent: #f472b6;
        --accent-ink: #1b1e27;
        --accent-soft: #3b1d2c;
        --danger: #f97066;
        --danger-soft: #3d1d1b;
        --info-soft: #1e2a44;
    }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 15px/1.55 var(--font); }
a { color: var(--accent); }
.muted { color: var(--muted); }
.pad { padding: 12px; }
.tamil { font-family: var(--font-tamil); line-height: 1.8; }
.spacer { flex: 1; }
[hidden] { display: none !important; }

/* ---- top bar ---- */
.topbar {
    display: flex; align-items: center; gap: 16px; padding: 10px 16px;
    background: var(--surface); border-bottom: 1px solid var(--border); height: 56px;
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; font-weight: 600; }
.brand small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; }
.brand-mark {
    display: grid; place-items: center; width: 32px; height: 32px; border-radius: 8px;
    background: var(--accent); color: var(--accent-ink); font-weight: 700; font-size: 13px;
}
.topnav { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.topnav form { margin: 0; }
.who { font-weight: 500; }

/* ---- controls ---- */
.btn {
    font: inherit; border: 1px solid var(--border); background: var(--surface); color: var(--text);
    padding: 7px 14px; border-radius: 8px; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn-primary:hover { filter: brightness(1.05); background: var(--accent); }
.btn-ghost { background: transparent; }
.btn-ghost.on { background: var(--accent-soft); border-color: var(--accent); }
.btn-danger { color: var(--danger); background: transparent; }
.btn-danger:hover { background: var(--danger-soft); }
.btn-block { width: 100%; padding: 10px; }
.input, .field input, .field select {
    font: inherit; width: 100%; padding: 8px 10px; border-radius: 8px;
    border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
.input:focus, .field input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.badge {
    display: inline-block; padding: 2px 10px; border-radius: 999px;
    background: var(--accent-soft); color: var(--accent); font-size: 12px; font-weight: 600;
}
.badge.small { font-size: 11px; padding: 1px 8px; }

/* ---- auth ---- */
body.auth { display: flex; flex-direction: column; }
.auth-card {
    width: min(420px, calc(100% - 32px)); margin: 48px auto; background: var(--surface);
    border: 1px solid var(--border); border-radius: 14px; padding: 28px;
}
.auth-card h1 { margin: 0 0 4px; font-size: 22px; }
.field { display: block; margin: 14px 0; }
.field > span { display: block; font-weight: 500; margin-bottom: 4px; }
.field .help { display: block; color: var(--muted); font-size: 12px; margin-top: 4px; }
.field .help ul { margin: 4px 0; padding-left: 18px; }
.field .error, .alert { display: block; color: var(--danger); font-size: 13px; margin-top: 4px; }
.alert { background: var(--danger-soft); padding: 8px 12px; border-radius: 8px; }
.switch { text-align: center; margin-top: 16px; }

/* ---- app layout ---- */
body.app { display: flex; flex-direction: column; height: 100vh; }
.layout { flex: 1; display: flex; min-height: 0; }
.sidebar {
    width: 320px; flex-shrink: 0; display: flex; flex-direction: column;
    background: var(--surface); border-right: 1px solid var(--border);
}
.sidebar-head { padding: 14px; border-bottom: 1px solid var(--border); }
.sidebar-head h2 { font-size: 15px; margin: 0 0 10px; }
.filter { margin-top: 10px; }
.qlist { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.qitem { padding: 10px 14px; border-bottom: 1px solid var(--border); cursor: pointer; }
.qitem:hover { background: var(--surface-2); }
.qitem.active { background: var(--accent-soft); }
.qitem-meta { display: flex; gap: 6px; align-items: center; font-size: 12px; margin-bottom: 4px; flex-wrap: wrap; }
.qitem-text { font-size: 13.5px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.pager { display: flex; align-items: center; justify-content: space-between; padding: 8px 10px; border-top: 1px solid var(--border); }

.main { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.main > section { max-width: 900px; width: 100%; margin: 0 auto; }
#question-view { display: flex; flex-direction: column; gap: 16px; }
.controls { display: flex; align-items: flex-end; gap: 14px; flex-wrap: wrap; }
.control label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.control select { min-width: 190px; }
.category-hint { flex-basis: 100%; font-size: 13px; }
.check { display: flex; align-items: center; gap: 6px; padding-bottom: 8px; }
.status { max-width: 900px; width: 100%; margin: 0 auto; padding: 10px 14px; border-radius: 8px; background: var(--info-soft); }
.status[data-kind="error"] { background: var(--danger-soft); color: var(--danger); }
.empty h3 { margin-top: 0; }
.qhead { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.qhead h3 { margin: 0; font-size: 16px; }
.md { font-size: 16px; overflow-x: auto; }
.md p:first-child { margin-top: 0; }
.md p:last-child { margin-bottom: 0; }
.md table { border-collapse: collapse; margin: 8px 0; }
.md th, .md td { border: 1px solid var(--border); padding: 4px 10px; }
.md pre { background: var(--surface-2); padding: 10px; border-radius: 8px; overflow-x: auto; }
.answers { display: flex; flex-direction: column; gap: 14px; }
.answer { border-top: 1px dashed var(--border); padding-top: 12px; }
.answer:first-child { border-top: 0; padding-top: 0; }
.answer-meta { font-size: 12px; margin-bottom: 6px; }

/* ---- temporary chat ---- */
.chat {
    width: 380px; min-width: 300px; max-width: 70vw; flex-shrink: 0; display: flex; flex-direction: column;
    background: var(--surface); border-left: 1px solid var(--border);
}
.resizer {
    width: 6px; flex-shrink: 0; cursor: col-resize; background: transparent;
    margin-right: -3px; position: relative; z-index: 1; touch-action: none;
}
.resizer::after {
    content: ""; position: absolute; top: 50%; left: 1px; width: 4px; height: 40px;
    transform: translateY(-50%); border-radius: 2px; background: var(--border);
}
.resizer:hover, .resizer.dragging { background: var(--accent-soft); }
.resizer:hover::after, .resizer.dragging::after { background: var(--accent); }
body.resizing { cursor: col-resize; user-select: none; }
.chat-head { display: flex; align-items: center; gap: 6px; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.chat-head h3 { margin: 0; font-size: 15px; }
.chat-head > div { flex: 1; }
.chat-log { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.bubble { padding: 9px 12px; border-radius: 12px; max-width: 92%; font-family: var(--font-tamil); overflow-x: auto; }
.bubble.user { align-self: flex-end; background: var(--accent); color: var(--accent-ink); white-space: pre-wrap; }
.bubble.assistant { align-self: flex-start; background: var(--surface-2); }
.bubble.pending { color: var(--muted); }
.bubble.error { background: var(--danger-soft); color: var(--danger); }
.bubble p { margin: 0 0 6px; }
.bubble p:last-child { margin: 0; }
.chat-suggest { display: flex; gap: 6px; padding: 0 12px 8px; flex-wrap: wrap; }
.chat-suggest button {
    font: inherit; font-size: 12px; border: 1px solid var(--border); background: transparent;
    color: var(--text); border-radius: 999px; padding: 3px 10px; cursor: pointer;
}
.chat-form { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--border); align-items: flex-end; }
.chat-form textarea { resize: none; font-family: var(--font-tamil); }

/* ---- models dialog ---- */
.small { font-size: 13px; }
.model-summary { flex-basis: 100%; font-size: 12px; }
.dialog {
    width: min(560px, calc(100% - 32px)); border: 1px solid var(--border); border-radius: 14px;
    padding: 20px; background: var(--surface); color: var(--text);
}
.dialog::backdrop { background: rgb(0 0 0 / .35); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; }
.dialog-head h3 { margin: 0; }
.model-rows { display: flex; flex-direction: column; gap: 14px; margin: 14px 0; }
.model-row { display: grid; grid-template-columns: 1fr 2fr 1.2fr; gap: 10px; align-items: center; }
.model-row label { font-weight: 500; font-size: 14px; }
.dialog-foot { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
@media (max-width: 560px) { .model-row { grid-template-columns: 1fr; gap: 4px; } }

/* ---- narrow screens ---- */
@media (max-width: 900px) {
    body.app { height: auto; }
    .layout { flex-direction: column; }
    .sidebar { width: 100%; max-height: 50vh; border-right: 0; border-bottom: 1px solid var(--border); }
    .main { padding: 16px; overflow: visible; }
    .chat { width: 100% !important; max-width: none; height: 70vh; border-left: 0; border-top: 1px solid var(--border); }
    .resizer { display: none !important; }
    .brand small { display: none; }
}
