/* TicalChat — self-contained styling (no external deps), light/dark aware. */
:root {
    --bg: #ffffff; --bg-soft: #f7f7f8; --bg-elev: #ffffff;
    --fg: #1f2328; --fg-soft: #656d76; --fg-faint: #8b949e;
    --border: #e5e7eb; --border-soft: #eef0f2;
    --accent: #2563eb; --accent-fg: #ffffff; --accent-soft: #eff4ff;
    --user-bg: #2563eb; --user-fg: #ffffff;
    --ok: #1a7f37; --ok-soft: #e6f4ea; --warn: #9a6700; --warn-soft: #fff8e5; --bad: #cf222e; --bad-soft: #ffebe9;
    --mark: #7c3aed;
    --radius: 14px; --radius-sm: 9px;
    --shadow: 0 1px 2px rgba(0,0,0,.05), 0 8px 24px rgba(0,0,0,.06);
    --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
    --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0d1117; --bg-soft: #161b22; --bg-elev: #161b22;
        --fg: #e6edf3; --fg-soft: #9198a1; --fg-faint: #6e7681;
        --border: #30363d; --border-soft: #21262d;
        --accent: #4c8dff; --accent-fg: #0d1117; --accent-soft: #12233f;
        --user-bg: #234a86; --user-fg: #eaf1ff;
        --ok: #3fb950; --ok-soft: #12261a; --warn: #d29922; --warn-soft: #2a2410; --bad: #f85149; --bad-soft: #2a1615;
        --mark: #a371f7;
        --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.4);
    }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font-family: var(--sans); color: var(--fg); background: var(--bg); font-size: 15px; line-height: 1.55; }
b { font-weight: 650; }
code { font-family: var(--mono); font-size: .85em; background: var(--bg-soft); padding: 1px 5px; border-radius: 5px; }

/* ── buttons ─────────────────────────────────────────── */
.btn { font: inherit; cursor: pointer; border: 1px solid transparent; border-radius: var(--radius-sm);
    padding: 9px 15px; text-decoration: none; display: inline-flex; align-items: center; gap: 7px; transition: .12s; }
.btn-primary { background: var(--accent); color: var(--accent-fg); font-weight: 600; }
.btn-primary:hover { filter: brightness(1.07); }
.btn-ghost { background: transparent; color: var(--fg-soft); border-color: var(--border); }
.btn-ghost:hover { background: var(--bg-soft); color: var(--fg); }
.btn-block { width: 100%; justify-content: center; padding: 13px; font-size: 1.02rem; }

/* ── login ───────────────────────────────────────────── */
.auth-wrap { min-height: 100dvh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; padding: 24px; }
.auth-card { width: 100%; max-width: 440px; background: var(--bg-elev); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow); padding: 34px 30px; }
.brand { display: flex; align-items: center; gap: 9px; font-size: 1.35rem; font-weight: 700; }
.brand-mark { font-size: 1.4rem; }
.auth-lede { color: var(--fg-soft); margin: 16px 0 22px; }
.auth-error { background: var(--bad-soft); color: var(--bad); border: 1px solid var(--bad); border-radius: var(--radius-sm); padding: 10px 12px; margin-bottom: 16px; font-size: .9rem; }
.auth-points { list-style: none; padding: 0; margin: 22px 0 0; color: var(--fg-soft); font-size: .9rem; display: grid; gap: 9px; }
.auth-foot { color: var(--fg-faint); font-size: .8rem; }
.dev-link { display: block; text-align: center; margin-top: 16px; color: var(--fg-faint); font-size: .8rem; }

/* ── app shell: sidebar + main ───────────────────────── */
.app { display: flex; height: 100dvh; overflow: hidden; }
.sidebar { width: 266px; flex: 0 0 266px; background: var(--bg-soft); border-right: 1px solid var(--border);
    display: flex; flex-direction: column; }
.side-top { padding: 14px 12px 10px; display: flex; flex-direction: column; gap: 12px; }
.side-top .brand { font-size: 1.15rem; padding: 0 4px; }
.btn-new { justify-content: center; background: var(--bg-elev); border: 1px solid var(--border); color: var(--fg); font-weight: 600; padding: 10px; }
.btn-new:hover { border-color: var(--accent); color: var(--accent); }
.thread-list { flex: 1; overflow-y: auto; padding: 4px 8px; display: flex; flex-direction: column; gap: 2px; }
.thread-item { display: flex; align-items: center; gap: 6px; padding: 9px 10px; border-radius: 8px; color: var(--fg-soft); text-decoration: none; font-size: .88rem; cursor: pointer; }
.thread-item:hover { background: var(--bg-elev); color: var(--fg); }
.thread-item.active { background: var(--accent-soft); color: var(--accent); }
.ti-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ti-del { border: 0; background: transparent; color: var(--fg-faint); cursor: pointer; font-size: 1.1rem; line-height: 1; padding: 0 2px; opacity: 0; border-radius: 4px; }
.thread-item:hover .ti-del, .thread-item.active .ti-del { opacity: 1; }
.ti-del:hover { color: var(--bad); }
.side-foot { padding: 10px 14px; border-top: 1px solid var(--border); }
.main { flex: 1; min-width: 0; display: grid; grid-template-rows: auto 1fr auto; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 11px 18px; border-bottom: 1px solid var(--border); background: var(--bg-elev); }
.topbar-title { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-right { display: flex; align-items: center; gap: 14px; font-size: .9rem; }
.user { color: var(--fg-soft); }
.icon-btn { display: none; border: 0; background: transparent; color: var(--fg-soft); font-size: 1.2rem; cursor: pointer; }
.status { display: inline-flex; align-items: center; gap: 6px; color: var(--fg-soft); font-size: .8rem; }
.status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--fg-faint); flex: 0 0 auto; }
.status.ok .dot { background: var(--ok); } .status.bad .dot { background: var(--bad); }

/* ── messages ────────────────────────────────────────── */
.chat { overflow-y: auto; }
.messages { max-width: 820px; margin: 0 auto; padding: 26px 18px 40px; display: flex; flex-direction: column; gap: 22px; }
.empty { text-align: center; margin: 8vh auto 0; color: var(--fg-soft); max-width: 560px; }
.empty-mark { font-size: 2.6rem; }
.empty h1 { color: var(--fg); font-size: 1.5rem; margin: 12px 0 4px; }
.empty-sub { margin: 0 0 22px; }
.suggestions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.chip { text-align: left; background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius-sm);
    padding: 12px 14px; color: var(--fg); cursor: pointer; font: inherit; font-size: .9rem; transition: .12s; }
.chip:hover { border-color: var(--accent); background: var(--accent-soft); }

.msg { display: flex; gap: 13px; }
.msg .avatar { width: 28px; height: 28px; border-radius: 7px; flex: 0 0 auto; display: grid; place-items: center; font-size: .82rem; font-weight: 700; }
.msg.user .avatar { background: var(--user-bg); color: var(--user-fg); }
.msg.bot .avatar { background: var(--accent-soft); color: var(--accent); }
.msg .body { min-width: 0; flex: 1; }
.msg .who { font-weight: 650; font-size: .82rem; color: var(--fg-soft); margin-bottom: 3px; }
.msg .text { white-space: pre-wrap; word-wrap: break-word; }
.msg.user .text { background: var(--bg-soft); border: 1px solid var(--border-soft); border-radius: var(--radius); padding: 10px 14px; display: inline-block; }
.msg .text.abstain { color: var(--warn); background: var(--warn-soft); border: 1px solid var(--warn); border-radius: var(--radius-sm); padding: 10px 13px; }
.msg .text.creative::after { content: " ✦ creative (non-factual)"; color: var(--mark); font-size: .8em; }
.cursor { display: inline-block; width: 7px; height: 1.05em; background: var(--accent); vertical-align: text-bottom; animation: blink 1s steps(2) infinite; margin-left: 1px; }
@keyframes blink { 50% { opacity: 0; } }
.thinking { color: var(--fg-faint); font-style: italic; display: inline-flex; gap: 4px; align-items: center; }
.thinking .d { width: 5px; height: 5px; border-radius: 50%; background: var(--fg-faint); animation: bounce 1.2s infinite; }
.thinking .d:nth-child(2){animation-delay:.15s} .thinking .d:nth-child(3){animation-delay:.3s}
@keyframes bounce { 0%,60%,100%{transform:translateY(0);opacity:.4} 30%{transform:translateY(-4px);opacity:1} }

/* ── reasoning panel ─────────────────────────────────── */
.reasoning { margin-top: 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg-soft); overflow: hidden; }
.reasoning > summary { cursor: pointer; padding: 9px 13px; font-size: .84rem; color: var(--fg-soft); font-weight: 600; list-style: none; display: flex; align-items: center; gap: 8px; user-select: none; }
.reasoning > summary::-webkit-details-marker { display: none; }
.reasoning > summary::before { content: "▸"; transition: .15s; color: var(--fg-faint); }
.reasoning[open] > summary::before { transform: rotate(90deg); }
.reasoning .r-badge { margin-left: auto; font-weight: 500; }
.pill { font-size: .72rem; padding: 2px 8px; border-radius: 999px; font-weight: 600; }
.pill.ok { background: var(--ok-soft); color: var(--ok); } .pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.info { background: var(--accent-soft); color: var(--accent); } .pill.bad { background: var(--bad-soft); color: var(--bad); }
.r-body { padding: 4px 13px 13px; border-top: 1px solid var(--border-soft); }
.r-meta { font-size: .8rem; color: var(--fg-soft); margin: 9px 0; }
.r-meta code { font-size: .8em; }
.trace { display: flex; flex-direction: column; gap: 6px; margin: 8px 0; }
.step { display: grid; grid-template-columns: auto 1fr; gap: 9px; align-items: baseline; font-size: .83rem; }
.step .op { font-family: var(--mono); font-size: .68rem; font-weight: 700; padding: 1px 6px; border-radius: 5px; background: var(--bg-elev); border: 1px solid var(--border); color: var(--fg-soft); white-space: nowrap; }
.step .op.RECALL, .step .op.PULL { color: var(--accent); } .step .op.ISA, .step .op.CHAIN, .step[data-op^="ISA"] .op { color: var(--mark); } .step .op.EMIT { color: var(--ok); }
.step .detail { color: var(--fg); }
.step .src { display: block; color: var(--fg-faint); font-size: .76rem; margin-top: 1px; }
.cites { margin: 10px 0 2px; }
.cites .c-title { font-size: .78rem; color: var(--fg-soft); font-weight: 600; margin-bottom: 4px; }
.cites .cite { font-size: .78rem; color: var(--fg-soft); padding: 5px 9px; background: var(--bg-elev); border: 1px solid var(--border-soft); border-radius: 6px; margin-bottom: 4px; }

/* ── elaboration (creativity dial) ───────────────────── */
.elab { margin-top: 12px; border: 1px dashed var(--mark); border-radius: var(--radius-sm); padding: 12px 14px; background: color-mix(in srgb, var(--mark) 6%, transparent); }
.elab .e-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: .8rem; color: var(--fg-soft); margin-bottom: 7px; }
.elab .e-title { font-weight: 700; color: var(--mark); }
.elab .e-text { white-space: pre-wrap; }
.bleed-bar { height: 5px; background: var(--border); border-radius: 3px; overflow: hidden; width: 80px; }
.bleed-bar > span { display: block; height: 100%; background: var(--mark); }

/* ── composer ────────────────────────────────────────── */
.composer { border-top: 1px solid var(--border); background: var(--bg-elev); padding: 12px 18px 14px; }
.composer .controls, .input-row, .composer-foot { max-width: 820px; margin-inline: auto; }
.controls { display: flex; gap: 26px; align-items: flex-end; margin-bottom: 10px; flex-wrap: wrap; }
.ctl { display: flex; flex-direction: column; gap: 4px; min-width: 190px; }
.ctl-persona { min-width: 150px; }
.ctl-top { display: flex; justify-content: space-between; align-items: baseline; }
.ctl-label { font-size: .78rem; color: var(--fg-soft); font-weight: 600; }
.ctl-val { font-family: var(--mono); color: var(--accent); }
.ctl-hint { font-size: .72rem; color: var(--fg-faint); }
input[type=range] { accent-color: var(--accent); width: 100%; }
select { font: inherit; padding: 7px 9px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--bg); color: var(--fg); }
.input-row { display: flex; gap: 10px; align-items: flex-end; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 8px 8px 14px; box-shadow: var(--shadow); }
.input-row:focus-within { border-color: var(--accent); }
#input { flex: 1; resize: none; border: 0; outline: 0; background: transparent; color: var(--fg); font: inherit; max-height: 200px; padding: 4px 0; }
.btn-send { background: var(--accent); color: var(--accent-fg); border-radius: 9px; width: 38px; height: 38px; justify-content: center; padding: 0; font-size: 1.05rem; flex: 0 0 auto; }
.btn-send:disabled { opacity: .4; cursor: default; }
.composer-foot { font-size: .74rem; color: var(--fg-faint); text-align: center; margin: 9px auto 0; }

@media (max-width: 800px) {
    .icon-btn { display: block; }
    .sidebar { position: fixed; z-index: 20; left: 0; top: 0; bottom: 0; transform: translateX(-100%); transition: transform .18s; box-shadow: var(--shadow); }
    .sidebar.open { transform: translateX(0); }
    .suggestions { grid-template-columns: 1fr; }
    .controls { gap: 16px; }
    .ctl { min-width: 140px; }
    .topbar-right .user { display: none; }
}
