/* Dialog AI — assistant layout, not a messenger: answers read like a document.
   No JavaScript, no web fonts, no heavy effects: it has to work on anything with a browser. */
:root {
    --bg: #f7f7fb;
    --panel: #ffffff;
    --side: #f1f0f7;
    --ink: #121417;
    --muted: #68717c;
    --line: #e3e7eb;
    --hover: #e9ecef;
    --accent: #5b4fe9;
    --accent-ink: #ffffff;
    --accent-soft: #ecebff;
    --ask: #ecebff;
    --code: #f2f4f6;
    --danger: #c62828;
    --danger-soft: #fdecec;
    --warn-soft: #fff6dd;
    --info-soft: #e8f1ff;
    color-scheme: light;
}
@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0c0c11;
        --panel: #15151d;
        --side: #111118;
        --ink: #e8ecf0;
        --muted: #8e98a3;
        --line: #252b32;
        --hover: #1f252c;
        --accent: #8b80ff;
        --accent-ink: #0e0b26;
        --accent-soft: #24204a;
        --ask: #24204a;
        --code: #1b2026;
        --danger: #ff6b6b;
        --danger-soft: #3a1b1d;
        --warn-soft: #3a3115;
        --info-soft: #172739;
        color-scheme: dark;
    }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
    margin: 0; min-height: 100vh;
    background: var(--bg); color: var(--ink);
    font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
h1, h2, h3 { line-height: 1.25; margin: 0 0 10px; }
h1 { font-size: 1.4rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 10px; }
a { color: var(--accent); }
img { max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.lead, .hint, .form-note { color: var(--muted); }
.hint { font-size: .88rem; margin: 0; }

/* ---------- controls ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    min-height: 42px; padding: 0 18px; border: 1px solid transparent; border-radius: 999px;
    background: var(--hover); color: var(--ink); font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn:hover { filter: brightness(.97); }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-ghost { background: transparent; border-color: var(--line); }
.btn-small { min-height: 34px; padding: 0 12px; font-size: .85rem; }
.badge { display: inline-block; padding: 1px 9px; border-radius: 999px; font-size: .75rem; font-weight: 700; background: var(--hover); color: var(--muted); }
.badge-pro { background: var(--accent); color: var(--accent-ink); }
.badge-soon { background: var(--warn-soft); color: var(--ink); }
.field { display: block; margin: 0 0 14px; color: var(--muted); font-size: .9rem; }
input[type=text], input[type=password], input[type=email], input[type=search], select, textarea {
    display: block; width: 100%; margin-top: 4px; min-height: 46px; padding: 11px 14px;
    border: 1px solid var(--line); border-radius: 12px; background: var(--panel); color: var(--ink); outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
.lang-switch { display: inline-flex; gap: 4px; margin: 0; }
.lang-switch button { min-height: 30px; padding: 0 10px; border: 0; border-radius: 999px; background: var(--hover); color: var(--ink); font-size: .8rem; font-weight: 600; cursor: pointer; }
.lang-switch button[aria-current="true"] { background: var(--accent); color: var(--accent-ink); }
.banner { padding: 12px 16px; border-radius: 12px; margin: 10px 0; background: var(--info-soft); }
.banner p { margin: 0; }
.banner-error { background: var(--danger-soft); color: var(--danger); }
.banner-warn { background: var(--warn-soft); }
.banner-links { margin-top: 6px !important; font-size: .9rem; }

/* ---------- regular pages ---------- */
.site-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 12px 20px; border-bottom: 1px solid var(--line); background: var(--panel); }
.brand, .side-brand { display: inline-flex; align-items: center; gap: 10px; color: var(--ink); font-weight: 750; font-size: 1.1rem; text-decoration: none; }
.brand-mark { width: 30px; height: 30px; border-radius: 9px; }
.nav { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; font-size: .92rem; }
.nav a { color: var(--ink); text-decoration: none; }
.nav a:hover { color: var(--accent); }
.nav-user { font-weight: 600; }
.wrap { width: 100%; max-width: 760px; margin: 0 auto; padding: 24px 16px 40px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 22px 20px; margin-bottom: 16px; }
.auth-card { max-width: 420px; margin: 6vh auto 0; }
.auth-card .btn-primary { width: 100%; min-height: 48px; }
.auth-or { text-align: center; color: var(--muted); margin: 14px 0; }
.google-btn { width: 100%; border-color: var(--line); background: transparent; }
.site-footer { text-align: center; color: var(--muted); font-size: .8rem; padding: 24px 16px; }
.facts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin: 0; }
.facts div { background: var(--bg); border-radius: 12px; padding: 12px; }
.facts dt { color: var(--muted); font-size: .8rem; }
.facts dd { margin: 2px 0 0; font-weight: 600; overflow-wrap: anywhere; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin: 12px 0; }
.stat { background: var(--bg); border-radius: 14px; padding: 14px; }
.stat h2, .stat h3 { font-size: .85rem; color: var(--muted); margin: 0 0 4px; }
.stat-value { font-size: 1.6rem; font-weight: 750; margin: 0 0 6px; }
.stat meter { width: 100%; height: 10px; accent-color: var(--accent); }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.plain-list { padding-left: 20px; }
.download { text-align: center; }
.table-wrap { overflow-x: auto; }
.admin-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.admin-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.admin-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.admin-table th, .admin-table td { text-align: left; padding: 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.chart-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-bottom: 18px; }
.chart { border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.chart-caption { color: var(--muted); font-size: 12px; }
.chart-cols { display: flex; align-items: stretch; gap: 6px; height: 150px; }
.chart-col { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; }
.chart-num, .chart-day { font-size: 11px; color: var(--muted); line-height: 1.2; }
.chart-track { flex: 1; width: 100%; display: flex; align-items: flex-end; justify-content: center; }
.chart-bar { display: block; width: 70%; max-width: 28px; min-height: 2px; background: var(--accent); border-radius: 6px 6px 2px 2px; }
.stats-hero { margin-bottom: 16px; }
.missing { text-align: center; }

/* ---------- chat layout ---------- */
body.layout-chat { height: 100vh; height: 100dvh; overflow: hidden; }
.app-shell { display: flex; height: 100vh; height: 100dvh; }
.sidebar {
    width: 280px; flex: 0 0 280px; display: flex; flex-direction: column;
    background: var(--side); border-right: 1px solid var(--line);
    padding: calc(12px + env(safe-area-inset-top, 0)) 10px calc(10px + env(safe-area-inset-bottom, 0));
}
.sidebar-top { display: flex; align-items: center; justify-content: space-between; padding: 4px 6px 12px; }
.side-close { display: none; color: var(--muted); text-decoration: none; font-size: 1.1rem; padding: 4px 10px; border-radius: 8px; }
.new-chat {
    width: 100%; min-height: 44px; margin-bottom: 10px;
    display: flex; align-items: center; justify-content: center; gap: 8px;
    border: 1px solid var(--line); border-radius: 12px; background: var(--panel); color: var(--ink);
    font-weight: 600; cursor: pointer;
}
.new-chat:hover { border-color: var(--accent); }
.sidebar form { margin: 0; }
.chat-list { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 1px; }
.chat-link {
    display: block; padding: 9px 12px; border-radius: 10px; color: var(--ink); text-decoration: none;
    font-size: .92rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-link:hover { background: var(--hover); }
.chat-link.is-active { background: var(--panel); font-weight: 600; box-shadow: inset 3px 0 0 var(--accent); }
.side-empty { color: var(--muted); font-size: .9rem; padding: 8px 12px; }
.sidebar-user { border-top: 1px solid var(--line); padding: 10px 6px 0; display: flex; flex-direction: column; gap: 8px; }
.me-line { display: flex; align-items: center; gap: 8px; min-width: 0; }
.me-face { width: 30px; height: 30px; flex: 0 0 30px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: .85rem; }
.me-line .nav-user { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me-links { display: flex; gap: 12px; flex-wrap: wrap; font-size: .85rem; }
.me-links a { color: var(--muted); text-decoration: none; }
.me-links a:hover { color: var(--accent); }

.thread-pane { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--panel); }
.thread-head {
    display: flex; align-items: center; gap: 10px; min-height: 56px;
    padding: 8px 16px; padding-top: calc(8px + env(safe-area-inset-top, 0));
    border-bottom: 1px solid var(--line);
}
.thread-head h1 { flex: 1; min-width: 0; margin: 0; font-size: 1rem; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread-head form { margin: 0; }
.menu-btn { display: none; color: var(--ink); text-decoration: none; font-size: 1.3rem; padding: 2px 10px; border-radius: 10px; }
.thread-pane > .banner { margin: 10px 16px 0; }

.transcript-scroll { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.transcript { max-width: 760px; margin: 0 auto; padding: 24px 18px 12px; }
.turn { margin: 0 0 22px; }
.turn-user { display: flex; flex-direction: column; align-items: flex-end; }
.ask {
    max-width: 85%; margin: 0; padding: 10px 16px; border-radius: 18px;
    background: var(--ask); white-space: pre-wrap; overflow-wrap: anywhere;
}
.turn-user .attach { max-width: 260px; max-height: 260px; border-radius: 14px; margin-bottom: 6px; object-fit: cover; }
.turn-model { display: flex; gap: 14px; align-items: flex-start; }
.ai-mark {
    width: 30px; height: 30px; flex: 0 0 30px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    background: var(--accent-soft); color: var(--accent); font-size: .95rem; margin-top: 2px;
}
.ai-mark.spin { animation: ai-spin 1.6s linear infinite; }
@keyframes ai-spin { to { transform: rotate(360deg); } }
.answer { flex: 1; min-width: 0; }
.is-demo .answer { opacity: .8; }
.msg-body { overflow-wrap: anywhere; }
.msg-body > :last-child { margin-bottom: 0; }
.msg-body p, .msg-body ul, .msg-body ol, .msg-body blockquote, .msg-body pre, .msg-body .md-table { margin: 0 0 12px; }
.msg-body ul, .msg-body ol { padding-left: 22px; }
.msg-body li { margin: 3px 0; }
.msg-body h1, .msg-body h2, .msg-body h3 { margin: 18px 0 8px; }
.msg-body code { font: .88em/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; background: var(--code); padding: 1px 5px; border-radius: 5px; }
.msg-body pre { background: var(--code); padding: 12px 14px; border-radius: 12px; overflow-x: auto; }
.msg-body pre code { background: none; padding: 0; }
.msg-body blockquote { border-left: 3px solid var(--accent); padding: 2px 12px; color: var(--muted); }
.msg-body hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }
.md-table { overflow-x: auto; }
.md-table table { border-collapse: collapse; font-size: .92rem; min-width: 60%; }
.md-table th, .md-table td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; }
.md-table th { background: var(--code); }
.msg-sources { font-size: .85rem; color: var(--muted); }
.thinking { margin: 4px 0 0; color: var(--muted); }
.thinking-dots { display: inline-flex; gap: 4px; margin-left: 6px; }
.thinking-dots span { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: dots 1.2s infinite ease-in-out; }
.thinking-dots span:nth-child(2) { animation-delay: .2s; }
.thinking-dots span:nth-child(3) { animation-delay: .4s; }
@keyframes dots { 0%, 100% { opacity: .2; } 50% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .ai-mark.spin, .thinking-dots span { animation: none; } }

.empty-state { text-align: center; margin: auto; padding: 48px 20px; max-width: 560px; color: var(--muted); }
.empty-state h2 { color: var(--ink); font-size: 1.6rem; }
.hello-mark { display: block; width: 56px; height: 56px; border-radius: 16px; margin: 0 auto 14px; }
.thread-pane > .empty-state { flex: 1; display: flex; flex-direction: column; justify-content: center; }
.suggest { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-top: 22px; text-align: left; }
.suggest form { margin: 0; }
.suggest button {
    width: 100%; height: 100%; min-height: 64px; padding: 12px 14px;
    border: 1px solid var(--line); border-radius: 14px; background: var(--panel); color: var(--ink);
    text-align: left; font-size: .92rem; cursor: pointer;
}
.suggest button:hover { border-color: var(--accent); background: var(--accent-soft); }

.composer { padding: 10px 16px calc(10px + env(safe-area-inset-bottom, 0)); }
.composer-form {
    max-width: 760px; margin: 0 auto;
    border: 1px solid var(--line); border-radius: 22px; background: var(--panel);
    padding: 6px 8px 8px 8px;
}
.composer-form:focus-within { border-color: var(--accent); }
.composer-field { display: block; margin: 0; }
.composer-field textarea {
    border: 0; margin: 0; min-height: 52px; max-height: 40vh; resize: none;
    background: transparent; padding: 10px 10px 4px; field-sizing: content;
}
.composer-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.composer-file {
    position: relative; display: inline-flex; align-items: center; gap: 6px;
    min-height: 38px; padding: 0 12px; border-radius: 999px; color: var(--muted); font-size: .88rem; cursor: pointer; overflow: hidden;
}
.composer-file:hover { background: var(--hover); color: var(--ink); }
.composer-file input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.composer-file:focus-within { outline: 2px solid var(--accent); }
.send-btn {
    width: 42px; height: 42px; flex: 0 0 42px; border: 0; border-radius: 50%;
    background: var(--accent); color: var(--accent-ink); font-size: 1.05rem; cursor: pointer;
}
.send-btn:hover { filter: brightness(1.06); }
.usage-line { max-width: 760px; margin: 6px auto 0; text-align: center; color: var(--muted); font-size: .76rem; }

/* old markup kept for other pages */
.mobile-bar { display: none; }
.msg-role { color: var(--muted); font-size: .8rem; }

/* ---------- phones ---------- */
@media (max-width: 760px) {
    .sidebar {
        position: fixed; inset: 0 auto 0 0; z-index: 20; width: 86vw; max-width: 320px;
        transform: translateX(-102%); transition: transform .2s ease;
        box-shadow: 0 0 40px rgba(0, 0, 0, .25);
    }
    .sidebar:target { transform: none; }
    .side-close, .menu-btn { display: inline-block; }
    .suggest { grid-template-columns: 1fr; }
    .transcript { padding: 16px 14px 8px; }
    .ask { max-width: 92%; }
    .turn-model { gap: 10px; }
    .ai-mark { width: 26px; height: 26px; flex-basis: 26px; }
    .facts, .chart-grid { grid-template-columns: 1fr; }
    .file-label { display: none; }
    .site-header { padding: 10px 14px; }
}
@media (prefers-reduced-motion: reduce) { .sidebar { transition: none; } }
