/* Chat 9router – giao diện kiểu Claude: nền ấm, chữ serif ở lời chào, màu nhấn cam đất. Sáng / tối theo hệ thống hoặc chọn tay. */

:root {
  --bg: #faf9f5;
  --surface: #ffffff;
  --sidebar: #f2f0e8;
  --text: #1f1e1d;
  --muted: #6e6c64;
  --border: #e4e1d6;
  --accent: #c15f3c;
  --accent-hover: #a94d2d;
  --accent-text: #ffffff;
  --user-bg: #efece2;
  --hover: rgba(31, 30, 29, 0.06);
  --code-bg: #f4f2ea;
  --code-head: #e9e6da;
  --danger: #b3392f;
  --shadow: 0 2px 14px rgba(31, 30, 29, 0.08);
  --tk-c: #8a8678;
  --tk-s: #2f7d4f;
  --tk-n: #b25a1c;
  --tk-k: #a23a76;
  --tk-f: #2a62a8;
  --serif: ui-serif, 'Iowan Old Style', 'Palatino Linotype', Palatino, Georgia, 'Times New Roman', serif;
  --sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans', sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, 'Liberation Mono', monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #262624;
    --surface: #30302e;
    --sidebar: #1f1e1d;
    --text: #ece9e1;
    --muted: #a5a195;
    --border: #3d3c38;
    --accent: #d9774f;
    --accent-hover: #e48a64;
    --accent-text: #1f1e1d;
    --user-bg: #3a3936;
    --hover: rgba(236, 233, 225, 0.08);
    --code-bg: #1c1b1a;
    --code-head: #2b2a28;
    --danger: #f08a7e;
    --shadow: 0 2px 18px rgba(0, 0, 0, 0.4);
    --tk-c: #8d897c;
    --tk-s: #8fd1a4;
    --tk-n: #e8a672;
    --tk-k: #e29bc6;
    --tk-f: #8db8f0;
    color-scheme: dark;
  }
}
:root[data-theme='dark'] {
  --bg: #262624;
  --surface: #30302e;
  --sidebar: #1f1e1d;
  --text: #ece9e1;
  --muted: #a5a195;
  --border: #3d3c38;
  --accent: #d9774f;
  --accent-hover: #e48a64;
  --accent-text: #1f1e1d;
  --user-bg: #3a3936;
  --hover: rgba(236, 233, 225, 0.08);
  --code-bg: #1c1b1a;
  --code-head: #2b2a28;
  --danger: #f08a7e;
  --shadow: 0 2px 18px rgba(0, 0, 0, 0.4);
  --tk-c: #8d897c;
  --tk-s: #8fd1a4;
  --tk-n: #e8a672;
  --tk-k: #e29bc6;
  --tk-f: #8db8f0;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 16px/1.6 var(--sans); -webkit-font-smoothing: antialiased; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.ico { flex: none; display: block; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.icon-btn { display: inline-grid; place-items: center; width: 36px; height: 36px; border: 0; border-radius: 10px; background: transparent; color: var(--muted); }
.icon-btn:hover { background: var(--hover); color: var(--text); }
.link { border: 0; background: none; padding: 0; color: var(--accent); text-decoration: underline; text-underline-offset: 2px; font-size: inherit; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 16px; border-radius: 10px; border: 1px solid transparent; font-weight: 600; font-size: 14.5px; }
.btn-primary { background: var(--accent); color: var(--accent-text); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.55; cursor: default; }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn-ghost:hover { background: var(--hover); }
.btn.danger, .danger { color: var(--danger); }

/* ---------------------------------------------------------------- bố cục */

.app { display: flex; height: 100vh; height: 100dvh; overflow: hidden; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; }

.sidebar { width: 288px; flex: none; display: flex; flex-direction: column; background: var(--sidebar); border-right: 1px solid var(--border); transition: margin-left 0.2s ease; }
.app.sidebar-collapsed .sidebar { margin-left: -288px; }
.side-top { padding: 14px 12px 8px; display: grid; gap: 10px; }
.brand { display: flex; align-items: center; gap: 9px; padding: 2px 6px 6px; font-family: var(--serif); font-size: 19px; font-weight: 600; }
.brand-mark { color: var(--accent); font-size: 22px; line-height: 1; }
.btn-new { display: flex; align-items: center; gap: 9px; width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); font-weight: 600; font-size: 14.5px; }
.btn-new:hover { border-color: var(--accent); }
.btn-new .ico { color: var(--accent); }
.search { display: flex; align-items: center; gap: 8px; padding: 0 10px; border-radius: 10px; background: var(--hover); color: var(--muted); }
.search input { flex: 1; min-width: 0; padding: 8px 0; border: 0; background: transparent; outline: 0; font-size: 14px; color: var(--text); }
.search input::placeholder { color: var(--muted); }

.chat-list { flex: 1; overflow-y: auto; padding: 4px 8px 16px; }
.side-group { padding: 14px 10px 5px; font-size: 12px; font-weight: 600; letter-spacing: 0.02em; color: var(--muted); }
.side-empty { padding: 20px 12px; color: var(--muted); font-size: 14px; text-align: center; }
.chat-item { position: relative; display: flex; align-items: center; border-radius: 10px; }
.chat-item:hover, .chat-item.active { background: var(--hover); }
.chat-item.active { background: color-mix(in srgb, var(--accent) 14%, transparent); }
.chat-link { flex: 1; min-width: 0; padding: 8px 10px; border: 0; background: none; text-align: left; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-more { display: none; flex: none; width: 30px; height: 30px; margin-right: 3px; place-items: center; border: 0; border-radius: 8px; background: none; color: var(--muted); }
.chat-more:hover { background: var(--hover); color: var(--text); }
.chat-item:hover .chat-more, .chat-item.active .chat-more { display: grid; }
@media (hover: none) { .chat-more { display: grid; } }
.rename-input { flex: 1; min-width: 0; margin: 3px 6px; padding: 5px 8px; border: 1px solid var(--accent); border-radius: 8px; background: var(--surface); outline: 0; font-size: 14.5px; }

.menu { position: fixed; z-index: 60; min-width: 190px; padding: 5px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); box-shadow: var(--shadow); }
.menu button { display: flex; align-items: center; gap: 9px; width: 100%; padding: 8px 10px; border: 0; border-radius: 8px; background: none; text-align: left; font-size: 14.5px; }
.menu button:hover { background: var(--hover); }

.topbar { display: flex; align-items: center; gap: 6px; padding: 10px 14px; min-height: 56px; }
.chat-title { margin: 0 6px; font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.scroller { flex: 1; overflow-y: auto; overflow-x: hidden; scroll-behavior: auto; overscroll-behavior: contain; } /* lớp chặn cuối: không bao giờ có thanh cuộn ngang ở khung chat */
.thread { max-width: 768px; margin: 0 auto; padding: 8px 20px 28px; }
.to-bottom { position: absolute; left: 50%; bottom: 142px; transform: translateX(-50%); display: grid; place-items: center; width: 36px; height: 36px; border: 1px solid var(--border); border-radius: 50%; background: var(--surface); color: var(--muted); box-shadow: var(--shadow); z-index: 5; }

/* ---------------------------------------------------------------- lời chào */

.welcome { padding: 14vh 0 4vh; text-align: center; }
.welcome-mark { color: var(--accent); font-size: 38px; line-height: 1; }
.welcome h2 { margin: 14px 0 26px; font-family: var(--serif); font-weight: 500; font-size: clamp(26px, 4vw, 34px); line-height: 1.25; }
.chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
.chip { max-width: 330px; padding: 10px 14px; border: 1px solid var(--border); border-radius: 14px; background: var(--surface); text-align: left; font-size: 14.5px; line-height: 1.4; color: var(--muted); }
.chip:hover { border-color: var(--accent); color: var(--text); }

/* ---------------------------------------------------------------- tin nhắn */

.messages { display: flex; flex-direction: column; gap: 6px; }
.msg { position: relative; display: flex; flex-direction: column; margin: 10px 0; }

.msg.user { align-items: flex-end; }
.msg.user .bubble { max-width: min(85%, 600px); padding: 10px 16px; border-radius: 18px; background: var(--user-bg); overflow-wrap: anywhere; }
.msg.user .text { white-space: pre-wrap; }
.msg.user .images { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.msg.user .images img { max-width: 220px; max-height: 200px; border-radius: 10px; object-fit: cover; }
.msg.user .actions { margin: 2px 4px 0 0; }

.editor { width: min(100%, 600px); padding: 10px; border: 1px solid var(--border); border-radius: 16px; background: var(--surface); }
.editor textarea { display: block; width: 100%; resize: none; border: 0; outline: 0; background: transparent; line-height: 1.5; }
.editor-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

.msg.assistant { flex-direction: row; gap: 12px; align-items: flex-start; }
.avatar { flex: none; display: grid; place-items: center; width: 28px; height: 28px; margin-top: 2px; border-radius: 50%; background: var(--accent); color: var(--accent-text); }
.msg.assistant .body { flex: 1; min-width: 0; }

.actions { display: inline-flex; gap: 2px; opacity: 0; transition: opacity 0.12s; }
.msg:hover .actions, .msg:focus-within .actions, .msg.assistant:last-child .actions { opacity: 1; }
@media (hover: none) { .actions { opacity: 1; } }
.act { display: grid; place-items: center; width: 30px; height: 30px; border: 0; border-radius: 8px; background: none; color: var(--muted); }
.act:hover { background: var(--hover); color: var(--text); }
.msg.assistant:not(:last-child) .act-regen { display: none; }
.messages.is-generating .act-regen, .messages.is-generating .act-edit { display: none; }
.meta { display: flex; align-items: center; gap: 8px; margin-top: 4px; min-height: 30px; color: var(--muted); font-size: 12.5px; }
.msg.streaming .meta { visibility: hidden; }

.reasoning { margin: 0 0 10px; padding: 8px 12px; border: 1px solid var(--border); border-radius: 12px; color: var(--muted); font-size: 14px; }
.reasoning summary { display: flex; align-items: center; gap: 7px; cursor: pointer; font-weight: 600; list-style: none; }
.reasoning summary::-webkit-details-marker { display: none; }
.reasoning-text { margin-top: 8px; white-space: pre-wrap; max-height: 320px; overflow-y: auto; }

.typing { display: inline-flex; gap: 5px; padding: 10px 2px; }
.typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite ease-in-out both; }
.typing span:nth-child(2) { animation-delay: 0.15s; }
.typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; transform: scale(0.8); } 40% { opacity: 1; transform: scale(1); } }
.msg.streaming .md > :last-child::after { content: '▍'; margin-left: 2px; color: var(--accent); animation: caret 1s steps(2) infinite; }
.msg.streaming .md > .codeblock:last-child::after, .msg.streaming .md > .table-wrap:last-child::after { content: none; }
@keyframes caret { 50% { opacity: 0; } }

.error-note { margin: 6px 0; padding: 8px 12px; border: 1px solid color-mix(in srgb, var(--danger) 45%, transparent); border-radius: 10px; background: color-mix(in srgb, var(--danger) 8%, transparent); color: var(--danger); font-size: 14.5px; overflow-wrap: anywhere; }

/* ---------------------------------------------------------------- công cụ + tệp đính kèm */

.msg.assistant.cont { margin-top: -4px; }
.msg.assistant.cont .avatar { visibility: hidden; }
.msg.assistant.tool-only .meta { display: none; }
.msg.assistant.tool-only .md:empty { display: none; }

.toolcalls { display: grid; grid-template-columns: minmax(0, 1fr); gap: 6px; margin: 6px 0 10px; } /* minmax(0,1fr): cột co theo màn hình, không phình theo độ dài prompt / tiêu đề */
.toolcall { border: 1px solid var(--border); border-radius: 12px; background: var(--surface); font-size: 14px; }
.toolcall > summary { display: flex; align-items: center; gap: 8px; padding: 8px 12px; cursor: pointer; list-style: none; color: var(--muted); }
.toolcall > summary::-webkit-details-marker { display: none; }
.toolcall > summary:hover { color: var(--text); }
.toolcall .tc-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.toolcall .tc-state { flex: none; font-size: 12.5px; }
.toolcall.running .tc-ico { color: var(--accent); animation: pulse 1.1s ease-in-out infinite; }
.toolcall.failed .tc-state { color: var(--danger); }
@keyframes pulse { 50% { opacity: 0.35; } }
.tc-body { padding: 0 12px 12px; }
.tc-label { margin: 8px 0 4px; font-size: 12px; font-weight: 650; letter-spacing: 0.03em; text-transform: uppercase; color: var(--muted); }
.tc-body pre { margin: 0; padding: 9px 11px; max-height: 280px; overflow: auto; border-radius: 8px; background: var(--code-bg); font: 12.5px/1.55 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere; }

.file-chip { display: inline-flex; align-items: center; gap: 6px; max-width: 100%; padding: 5px 10px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); font-size: 13px; color: var(--text); }
.file-chip .file-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-chip .file-size { flex: none; color: var(--muted); font-size: 12px; }
.file-chip.removable { padding-right: 4px; }
.chip-remove { display: grid; place-items: center; width: 20px; height: 20px; border: 0; border-radius: 50%; background: none; color: var(--muted); }
.chip-remove:hover { background: var(--hover); color: var(--text); }
.msg.user .files { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.msg.user .files .file-chip { background: var(--bg); }
.tools-btn.is-on { color: var(--accent); background: color-mix(in srgb, var(--accent) 13%, transparent); }
.tools-btn:not(.is-on) { opacity: 0.75; }

/* ---------------------------------------------------------------- ảnh do AI tạo */

.toolitem { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; min-width: 0; }
.toolitem > * { min-width: 0; }
.tc-images { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
.gen-image { margin: 0; width: fit-content; max-width: 100%; }
/* width/height auto + object-fit: contain: ảnh luôn giữ đúng tỉ lệ gốc, không bao giờ bị kéo giãn / bóp méo (kể cả khi cột hẹp hay màn hình thấp) */
.gen-image img { display: block; width: auto; height: auto; max-width: min(100%, 520px); max-height: min(560px, 70vh); object-fit: contain; border: 1px solid var(--border); border-radius: 14px; cursor: zoom-in; background: var(--code-bg); }
.img-skeleton { display: flex; align-items: center; gap: 10px; width: min(100%, 360px); aspect-ratio: 1; justify-content: center; border: 1px dashed var(--border); border-radius: 14px; background: linear-gradient(110deg, var(--code-bg) 30%, var(--hover) 50%, var(--code-bg) 70%) 0 0 / 220% 100%; color: var(--muted); font-size: 14px; text-align: center; padding: 20px; animation: shimmer 1.6s linear infinite; }
@keyframes shimmer { to { background-position: -220% 0; } }
.spinner { flex: none; width: 16px; height: 16px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.lightbox { position: fixed; inset: 0; z-index: 90; display: grid; grid-template-rows: 1fr auto; place-items: center; gap: 14px; padding: 20px; background: rgba(0, 0, 0, 0.82); }
.lightbox img { width: auto; height: auto; max-width: 100%; max-height: calc(100dvh - 110px); border-radius: 10px; object-fit: contain; }
.lb-actions { display: flex; gap: 10px; }
.lb-actions .btn-ghost { color: #fff; border-color: rgba(255, 255, 255, 0.4); }
.lb-actions .btn-ghost:hover { background: rgba(255, 255, 255, 0.12); }

/* ---------------------------------------------------------------- nội dung Markdown */

.md { overflow-wrap: anywhere; }
.md > :first-child { margin-top: 0; }
.md p { margin: 0 0 0.9em; }
.md h1, .md h2, .md h3, .md h4 { margin: 1.3em 0 0.5em; line-height: 1.3; font-weight: 650; }
.md h1 { font-size: 1.45em; } .md h2 { font-size: 1.28em; } .md h3 { font-size: 1.12em; } .md h4 { font-size: 1em; }
.md ul, .md ol { margin: 0 0 0.9em; padding-left: 1.5em; }
.md li { margin: 0.25em 0; }
.md li > ul, .md li > ol { margin: 0.25em 0 0.25em; }
.md blockquote { margin: 0 0 0.9em; padding: 2px 0 2px 14px; border-left: 3px solid var(--border); color: var(--muted); }
.md hr { margin: 1.4em 0; border: 0; border-top: 1px solid var(--border); }
.md a { color: var(--accent); text-underline-offset: 2px; }
.md code { padding: 0.12em 0.4em; border-radius: 6px; background: var(--code-bg); font: 0.88em var(--mono); }
.md .table-wrap { margin: 0 0 0.9em; overflow-x: auto; }
.md table { border-collapse: collapse; font-size: 0.94em; }
.md th, .md td { padding: 7px 12px; border: 1px solid var(--border); text-align: left; vertical-align: top; }
.md th { background: var(--code-bg); font-weight: 650; }

.codeblock { margin: 0 0 1em; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; background: var(--code-bg); }
.codehead { display: flex; align-items: center; justify-content: space-between; padding: 6px 8px 6px 14px; background: var(--code-head); color: var(--muted); font: 12.5px var(--mono); }
.copy-code { padding: 4px 9px; border: 0; border-radius: 7px; background: transparent; color: var(--muted); font: 12.5px var(--sans); }
.copy-code:hover { background: var(--hover); color: var(--text); }
.codeblock pre { margin: 0; padding: 12px 14px; overflow-x: auto; }
.codeblock code { padding: 0; background: none; font: 13.5px/1.6 var(--mono); white-space: pre; }
.tk-c { color: var(--tk-c); font-style: italic; }
.tk-s { color: var(--tk-s); }
.tk-n { color: var(--tk-n); }
.tk-k { color: var(--tk-k); }
.tk-f { color: var(--tk-f); }

/* ---------------------------------------------------------------- ô nhập */

.composer-wrap { padding: 0 16px calc(10px + env(safe-area-inset-bottom)); }
.composer { max-width: 768px; margin: 0 auto; padding: 12px 12px 8px 16px; border: 1px solid var(--border); border-radius: 22px; background: var(--surface); box-shadow: var(--shadow); }
.composer { position: relative; }
.composer:focus-within { border-color: color-mix(in srgb, var(--accent) 55%, var(--border)); }
.composer textarea { display: block; width: 100%; max-height: 220px; padding: 2px 0 6px; border: 0; outline: 0; resize: none; background: transparent; line-height: 1.55; }
.composer textarea::placeholder { color: var(--muted); }
.composer-row { display: flex; align-items: center; gap: 6px; }
.send-btn { display: grid; place-items: center; width: 36px; height: 36px; border: 0; border-radius: 10px; background: var(--accent); color: var(--accent-text); }
.send-btn:hover:not(:disabled) { background: var(--accent-hover); }
.send-btn:disabled { opacity: 0.35; cursor: default; }
.disclaimer { margin: 8px 0 0; text-align: center; font-size: 12px; color: var(--muted); }

.attachments { display: flex; flex-wrap: wrap; gap: 8px; padding-bottom: 10px; }
.attachment { position: relative; width: 64px; height: 64px; }
.attachment img { width: 100%; height: 100%; border-radius: 10px; object-fit: cover; border: 1px solid var(--border); }
.attachment-remove { position: absolute; top: -6px; right: -6px; display: grid; place-items: center; width: 20px; height: 20px; border: 0; border-radius: 50%; background: var(--text); color: var(--bg); }

.model-picker { position: relative; }
.model-btn { display: inline-flex; align-items: center; gap: 6px; max-width: 230px; padding: 6px 10px; border: 0; border-radius: 10px; background: transparent; color: var(--muted); font-size: 13.5px; }
.model-btn:hover, .model-btn[aria-expanded='true'] { background: var(--hover); color: var(--text); }
.model-btn #modelLabel { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.popover { position: absolute; right: 0; bottom: calc(100% + 8px); z-index: 40; width: min(360px, calc(100vw - 32px)); border: 1px solid var(--border); border-radius: 14px; background: var(--surface); box-shadow: var(--shadow); overflow: hidden; }
.popover > input { display: block; width: 100%; padding: 12px 14px; border: 0; border-bottom: 1px solid var(--border); outline: 0; background: transparent; font-size: 14.5px; }
.pop-list { max-height: min(340px, max(110px, calc(100dvh - 290px))); overflow-y: auto; padding: 4px; } /* màn hình thấp (xoay ngang): co danh sách lại, không tràn lên trên */
.pop-group { padding: 8px 10px 3px; font-size: 11.5px; font-weight: 650; letter-spacing: 0.03em; text-transform: uppercase; color: var(--muted); }
.model-item { display: flex; align-items: center; justify-content: space-between; gap: 8px; width: 100%; padding: 8px 10px; border: 0; border-radius: 8px; background: none; text-align: left; font-size: 14px; }
.model-item .model-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.model-item.active, .model-item:hover { background: var(--hover); }
.model-item.selected { color: var(--accent); font-weight: 600; }
.pop-note { padding: 12px 14px; font-size: 14px; color: var(--muted); }
.pop-note.is-error { color: var(--danger); }
.pop-foot { padding: 7px 12px; border-top: 1px solid var(--border); font-size: 13px; }
.pop-foot .link { display: inline-flex; align-items: center; gap: 6px; text-decoration: none; color: var(--muted); }
.pop-foot .link:hover { color: var(--text); }

.drop-overlay { position: fixed; inset: 0; z-index: 80; display: grid; place-items: center; background: color-mix(in srgb, var(--bg) 80%, transparent); backdrop-filter: blur(3px); pointer-events: none; }
.drop-overlay > div { padding: 28px 40px; border: 2px dashed var(--accent); border-radius: 20px; background: var(--surface); font-weight: 600; }

.toast { position: fixed; left: 50%; bottom: 24px; z-index: 100; max-width: min(92vw, 520px); padding: 10px 16px; border-radius: 12px; background: var(--text); color: var(--bg); font-size: 14.5px; opacity: 0; pointer-events: none; transform: translate(-50%, 12px); transition: opacity 0.18s, transform 0.18s; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--danger); color: #fff; }

/* ---------------------------------------------------------------- cài đặt */

dialog { width: min(540px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); padding: 0; border: 1px solid var(--border); border-radius: 18px; background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3); }
dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
.settings { display: grid; gap: 14px; padding: 22px; }
.settings h2 { margin: 0; font-family: var(--serif); font-weight: 500; font-size: 24px; }
fieldset { display: grid; gap: 12px; margin: 0; padding: 14px 16px 16px; border: 1px solid var(--border); border-radius: 14px; }
legend { padding: 0 6px; font-size: 13px; font-weight: 650; color: var(--muted); }
.field { display: grid; gap: 5px; font-size: 14px; }
.field > span { color: var(--muted); font-weight: 600; }
.field input, .field textarea, .field select { width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg); outline: 0; }
.field input:focus, .field textarea:focus, .field select:focus { border-color: var(--accent); }
.field textarea { resize: vertical; }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14.5px; }
.hint { margin: 0; font-size: 13px; color: var(--muted); }
.form-status { margin: 0; min-height: 0; font-size: 14px; color: var(--muted); }
.form-status:empty { display: none; }
.form-status.error { color: var(--danger); }
.form-status.warn { padding: 9px 12px; border-radius: 10px; background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--text); }
.dialog-actions { display: flex; align-items: center; gap: 8px; }

/* ---------------------------------------------------------------- đăng nhập */

.login-page { display: grid; place-items: center; min-height: 100dvh; padding: 20px; }
.login-card { display: grid; gap: 12px; width: min(380px, 100%); padding: 32px 28px; border: 1px solid var(--border); border-radius: 20px; background: var(--surface); box-shadow: var(--shadow); text-align: center; }
.login-card h1 { margin: 0; font-family: var(--serif); font-weight: 500; font-size: 28px; }
.login-card p { margin: 0; }
.login-card input[type='password'] { padding: 11px 13px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg); outline: 0; }
.login-card input[type='password']:focus { border-color: var(--accent); }
.login-error { color: var(--danger); font-size: 14px; }

/* ---------------------------------------------------------------- điện thoại */

.scrim { display: none; }
@media (max-width: 860px) {
  .sidebar { position: fixed; z-index: 50; inset: 0 auto 0 0; width: min(300px, 86vw); margin-left: 0 !important; transform: translateX(-100%); transition: transform 0.22s ease; box-shadow: var(--shadow); }
  .app.sidebar-open .sidebar { transform: none; }
  .app.sidebar-open .scrim { display: block; position: fixed; inset: 0; z-index: 45; background: rgba(0, 0, 0, 0.4); }
  .thread { padding-inline: 14px; }
  .welcome { padding-top: 9vh; }
  .to-bottom { bottom: 150px; }
  .field-grid { grid-template-columns: 1fr; }
  .model-btn { max-width: 160px; }
  /* điện thoại: danh sách model rộng đúng bằng ô nhập (không lẹm ra ngoài mép màn hình) */
  .model-picker { position: static; }
  .popover { left: 0; right: 0; width: auto; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
