:root {
  --bg: #0b0d12;
  --panel: #12151c;
  --panel-2: #1a1e28;
  --border: #252b37;
  --text: #e8ebf2;
  --muted: #8b93a7;
  --accent: #22d3ee;
  --accent-2: #22d3ee;
  --user: #123038;
  --grad: #22d3ee;
  --on-accent: #041a20;
  --shadow: 0 10px 30px rgba(0,0,0,.35);
  --danger: #da3633;
  --ok: #3fb950;
  --warn: #d29922;
  --radius: 12px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #fafbfe;
  --panel: #ffffff;
  --panel-2: #f0f1f8;
  --border: #e0e3ee;
  --text: #1b1e27;
  --muted: #5d6477;
  --accent: #0e7490;
  --accent-2: #0e7490;
  --user: #dff6fa;
  --grad: #0e7490;
  --on-accent: #ffffff;
  --shadow: 0 10px 30px rgba(40,44,70,.12);
  --ok: #1a7f37;
  --warn: #9a6700;
  color-scheme: light;
}
/* Code blocks stay dark in both themes. */
[data-theme="light"] .code { color: #e6edf3; border-color: #30363d; }
[data-theme="light"] .code-head { background: #161b22; color: #8b949e; }
[data-theme="light"] .code-head .copy, [data-theme="light"] .code-head .run { background: #1f2630; border-color: #30363d; color: #e6edf3; }
[data-theme="light"] .pv-body .hl-k { color: #cf222e; }
[data-theme="light"] .pv-body .hl-s { color: #0a3069; }
[data-theme="light"] .pv-body .hl-c { color: #57606a; }
[data-theme="light"] .pv-body .hl-n { color: #0550ae; }
[data-theme="light"] .note.error, [data-theme="light"] .notice.error, [data-theme="light"] .chip.error .meta, [data-theme="light"] #err { color: #cf222e; }
[data-theme="light"] .timer[data-level="warn"] { color: #9a6700; border-color: #d4a72c; }
[data-theme="light"] .timer[data-level="crit"] { color: #cf222e; border-color: #ff8182; }
[data-theme="light"] #drop { background: rgba(255,255,255,.88); }
[data-theme="light"] .modal { background: rgba(31,35,40,.45); }
[data-theme="light"] aside, [data-theme="light"] .modal-card { box-shadow: 0 8px 30px rgba(31,35,40,.18); }

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); display: flex; flex-direction: column; font-size: 15px; line-height: 1.55; }
[hidden] { display: none !important; }

button { font: inherit; cursor: pointer; border-radius: 8px; border: 1px solid var(--border); background: var(--panel-2); color: var(--text); padding: 7px 14px; }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--accent-2); border-color: var(--accent-2); color: var(--on-accent, #041a20); }
button.primary:hover:not(:disabled) { background: var(--accent); }
button.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
button.ghost { background: transparent; }
button.ghost:hover { background: var(--panel-2); }
button.icon { background: transparent; border: none; font-size: 20px; padding: 6px 8px; }

header { display: flex; align-items: center; justify-content: space-between; padding: 10px 18px; border-bottom: 1px solid var(--border); background: var(--panel); }
.brand { font-weight: 600; display: flex; align-items: center; gap: 8px; }
.model { color: var(--muted); font-weight: 400; font-size: 13px; }
.model-select { font: inherit; font-size: 13px; color: var(--text); background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; cursor: pointer; }
.model-select:hover { background: var(--panel); }
.actions { display: flex; gap: 6px; align-items: center; }
.actions button { white-space: nowrap; }
.timer { font-size: 12px; font-weight: 500; font-variant-numeric: tabular-nums; color: var(--muted); background: var(--panel-2); border: 1px solid var(--border); border-radius: 999px; padding: 2px 8px; white-space: nowrap; }
.timer[data-level="warn"] { color: #f0b429; border-color: #f0b42966; }
.timer[data-level="crit"] { color: #ff6b6b; border-color: #ff6b6b88; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); display: inline-block; }
.dot[data-status="ready"] { background: var(--ok); }
.dot[data-status="connecting"] { background: var(--warn); }
.dot[data-status="busy"] { background: var(--accent); animation: pulse 2.4s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .45; } }

main { flex: 1; overflow-y: auto; padding: 24px max(16px, calc(50% - 400px)); scroll-behavior: auto; }
.empty { text-align: center; color: var(--muted); margin-top: 14vh; }
.empty h1 { color: var(--text); font-weight: 600; font-size: 26px; }
.examples { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; max-width: 620px; margin: 26px auto 0; text-align: start; }
.examples button { display: flex; flex-direction: column; gap: 2px; padding: 12px 14px; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); transition: border-color .15s, background .15s; }
.examples button:hover { border-color: var(--accent); background: var(--panel-2); }
.examples b { font-weight: 600; font-size: 14px; }
.examples span { color: var(--muted); font-size: 13px; }
.msg-actions { display: flex; gap: 4px; margin-top: 4px; opacity: 1; transition: opacity .15s; }
.msg:hover .msg-actions, .msg-actions:focus-within { opacity: 1; }
.msg-meta { font-size: 12px; color: var(--muted); align-self: center; padding: 0 6px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.msg.user .msg-actions { align-items: center; }
.act { background: transparent; border: 1px solid transparent; color: var(--muted); font-size: 12px; padding: 2px 8px; }
.act:hover { background: var(--panel-2); border-color: var(--border); color: var(--text); }
.theme-btn { padding: 6px 9px; line-height: 1; }

/* streaming: blinking caret at the end of the reply, gentle fade-in for new messages */
.msg { animation: msgIn .18s ease-out; }
@keyframes msgIn { from { opacity: 0; transform: translateY(4px); } }
.msg.streaming > .body > .text:last-child > :is(p, h1, h2, h3, h4):last-child::after,
.msg.streaming > .body > .text:last-child > :is(ul, ol):last-child > li:last-child::after {
  content: ''; display: inline-block; width: 7px; height: 1.05em; margin-inline-start: 3px; vertical-align: text-bottom;
  background: var(--accent); border-radius: 1px; animation: caret 1s steps(1) infinite;
}
@keyframes caret { 50% { opacity: 0; } }

/* back to top / jump to latest */
#scrollBtns { position: fixed; right: max(16px, calc(50% - 470px)); bottom: calc(var(--footer-h, 100px) + 14px); display: flex; flex-direction: column; gap: 8px; z-index: 4; }
.fab { width: 38px; height: 38px; padding: 0; border-radius: 50%; font-size: 17px; line-height: 1; background: var(--panel); border: 1px solid var(--border); color: var(--text); box-shadow: 0 4px 14px rgba(0,0,0,.3); }
.fab:hover { border-color: var(--accent); color: var(--accent); }
[data-theme="light"] .fab { box-shadow: 0 4px 14px rgba(31,35,40,.15); }

/* diagrams and math */
.diagram { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 14px; margin: 0 0 6px; overflow-x: auto; text-align: center; }
.diagram svg { max-width: 100%; height: auto; }
.dg-src { margin: 0 0 12px; }
.dg-src summary { color: var(--muted); font-size: 12px; cursor: pointer; width: fit-content; }
.dg-src .code { margin-top: 6px; }
.math-block { overflow-x: auto; overflow-y: hidden; margin: 6px 0 12px; padding: 2px 0; }
.math-block.pending, .math.pending { font-family: ui-monospace, Consolas, monospace; font-size: 13px; color: var(--muted); }
.katex { font-size: 1.08em; }

/* model switch marker, retry-with menu */
.divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; margin: -6px 0 18px; }
.divider::before, .divider::after { content: ''; flex: 1; border-top: 1px solid var(--border); }
.menu { position: fixed; z-index: 30; display: flex; flex-direction: column; min-width: 210px; padding: 4px; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.35); }
.menu button { background: transparent; border: none; text-align: start; padding: 7px 10px; font-size: 13px; border-radius: 6px; }
.menu button:hover { background: var(--panel-2); }
.code-btns { display: flex; gap: 6px; }

.msg { margin: 0 0 22px; display: flex; flex-direction: column; }
.msg.user { align-items: flex-end; }
.msg.user .bubble { background: var(--user); padding: 10px 14px; border-radius: var(--radius) var(--radius) 4px var(--radius); max-width: 85%; white-space: normal; overflow-wrap: anywhere; }
.file-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; justify-content: flex-end; }
.md-img { max-width: 100%; max-height: 460px; height: auto; border-radius: 8px; border: 1px solid var(--border); background: var(--panel); cursor: zoom-in; vertical-align: middle; }
.text p > .md-img:only-child { display: block; }
.user-imgs { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; justify-content: flex-end; }
.user-imgs .md-img { width: 120px; height: 90px; object-fit: cover; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; margin: 8px 0 4px; }
.gallery figure { margin: 0; }
.gallery .md-img { width: 100%; height: 180px; object-fit: contain; display: block; }
.gallery figcaption { font-size: 12px; color: var(--muted); margin-top: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ext-img, .img-missing { display: inline-flex; gap: 6px; align-items: center; font-size: 13px; padding: 6px 10px; border: 1px dashed var(--border); border-radius: 8px; background: var(--panel); color: inherit; }
.ext-img { cursor: pointer; }
.img-missing { color: var(--muted); }
.tag { background: var(--panel-2); border: 1px solid var(--border); border-radius: 6px; padding: 2px 8px; font-size: 13px; }

.msg.assistant .body { overflow-wrap: anywhere; }
.text > :first-child { margin-top: 0; }
.text > :last-child { margin-bottom: 0; }
.text p, .text ul, .text ol, .text blockquote { margin: 0 0 10px; }
.text h1, .text h2, .text h3, .text h4 { margin: 16px 0 8px; line-height: 1.3; }
.text h1 { font-size: 22px; } .text h2 { font-size: 19px; } .text h3 { font-size: 17px; }
.text a { color: var(--accent); }
.text code { background: var(--panel-2); padding: 1px 5px; border-radius: 5px; font-size: 13.5px; font-family: ui-monospace, "Cascadia Code", Consolas, monospace; }
.text blockquote { border-inline-start: 3px solid var(--border); padding-inline-start: 12px; color: var(--muted); }
.text hr { border: none; border-top: 1px solid var(--border); margin: 14px 0; }
.code { background: #010409; border: 1px solid var(--border); border-radius: 8px; margin: 0 0 12px; overflow: hidden; }
.text li > p { margin: 0 0 6px; }
.text li > .code { margin: 6px 0 10px; }
.text li > ul, .text li > ol { margin: 4px 0; }
.code-head { display: flex; justify-content: space-between; align-items: center; padding: 4px 10px; background: var(--panel); color: var(--muted); font-size: 12px; }
.code-head .copy, .code-head .run { padding: 2px 8px; font-size: 12px; }
.code pre { margin: 0; padding: 12px; overflow-x: auto; }
.code pre code { background: none; padding: 0; font-size: 13px; white-space: pre; }
.table { overflow-x: auto; margin: 0 0 12px; }
.table table { border-collapse: collapse; font-size: 14px; }
.table th, .table td { border: 1px solid var(--border); padding: 6px 10px; text-align: start; }
.table th { background: var(--panel); }

.tool { display: flex; gap: 8px; align-items: baseline; color: var(--muted); font-size: 13px; padding: 4px 10px; margin: 6px 0; background: var(--panel); border: 1px solid var(--border); border-radius: 8px; width: fit-content; max-width: 100%; }
.tool .tt { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: ui-monospace, Consolas, monospace; }
.tool[data-status="completed"] .ti { color: var(--ok); }
.tool[data-status="failed"] .ti { color: var(--danger); }
.tool[data-status="pending"] .ti, .tool[data-status="in_progress"] .ti { color: var(--accent); display: inline-block; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.thought { color: var(--muted); font-size: 13px; margin: 6px 0; }
.thought summary { cursor: pointer; }
.thought-body { border-inline-start: 2px solid var(--border); padding-inline-start: 10px; margin-top: 4px; }
.plan { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; margin: 8px 0; font-size: 14px; }
.plan-title { font-weight: 600; margin-bottom: 4px; }
.plan-item[data-status="completed"] { color: var(--muted); text-decoration: line-through; }
.note { color: var(--muted); font-size: 13px; margin-top: 6px; }
.note.error { color: #ff7b72; }

.typing { display: inline-flex; align-items: center; gap: 8px; margin-top: 6px; padding: 5px 12px 5px 10px; width: fit-content; font-size: 13px; color: var(--muted); background: var(--panel); border: 1px solid var(--border); border-radius: 999px; }
.typing .dots { display: inline-flex; gap: 3px; }
.typing .dots span { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); opacity: .35; animation: blink 1.8s ease-in-out infinite; }
.typing .dots span:nth-child(2) { animation-delay: .3s; }
.typing .dots span:nth-child(3) { animation-delay: .6s; }
.typing .st-time { font-variant-numeric: tabular-nums; }
.typing .st-time:empty { display: none; }
.typing.warn { color: #d29922; border-color: #d2992266; }
.typing.warn .dots span { background: #d29922; }
@keyframes blink { 0%, 70%, 100% { opacity: .35; transform: none; } 35% { opacity: .95; transform: translateY(-2px); } }

.notice { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; margin: 0 0 18px; color: var(--muted); }
.notice.error { border-color: var(--danger); color: #ff7b72; }
.notice button { margin-inline-start: 8px; }

footer { padding: 10px max(16px, calc(50% - 400px)) 12px; border-top: 1px solid var(--border); background: var(--panel); }
#composer { display: flex; gap: 8px; align-items: flex-end; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 6px; }
#composer:focus-within { border-color: var(--accent); }
#input { flex: 1; resize: none; background: transparent; border: none; outline: none; color: var(--text); font: inherit; padding: 7px 4px; max-height: 240px; }
.hint { color: var(--muted); font-size: 12px; text-align: center; margin-top: 6px; }
#attachments { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
#attachments:empty { display: none; }
.chip { display: flex; align-items: center; gap: 4px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 3px 4px 3px 10px; font-size: 13px; max-width: 320px; }
.chip .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip .meta { color: var(--muted); white-space: nowrap; }
.chip.error { border-color: var(--danger); }
.chip.error .meta { color: #ff7b72; }
.chip.uploading .meta { color: var(--accent); }
.chip button { border: none; background: none; padding: 0 6px; color: var(--muted); }

aside { position: fixed; top: 52px; right: 12px; width: 340px; max-height: 70vh; overflow-y: auto; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 8px 30px rgba(0,0,0,.5); z-index: 5; }
.panel-head { display: flex; justify-content: space-between; align-items: center; padding: 8px 12px; border-bottom: 1px solid var(--border); font-weight: 600; }
#filesList { list-style: none; margin: 0; padding: 6px 0; }
#filesList li { display: flex; justify-content: space-between; gap: 10px; padding: 5px 12px; font-size: 13px; }
#filesList a { color: var(--accent); overflow-wrap: anywhere; }
.muted { color: var(--muted); }

#drop { position: fixed; inset: 0; background: rgba(13,17,23,.85); border: 3px dashed var(--accent); display: flex; align-items: center; justify-content: center; font-size: 22px; z-index: 10; pointer-events: none; }

body.login { align-items: center; justify-content: center; }
body.login > main { display: contents; }
#login { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 28px; width: 320px; display: flex; flex-direction: column; gap: 12px; }
#login h1 { margin: 0 0 6px; font-size: 22px; text-align: center; }
#login input { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 9px 12px; color: var(--text); font: inherit; }
#err { color: #ff7b72; margin: 0; min-height: 1em; text-align: center; font-size: 14px; }

/* waiting line + warning popup */
.dot[data-status="queued"] { background: var(--warn); animation: pulse 2.4s ease-in-out infinite; }
.queue-pos { font-size: 64px; font-weight: 700; color: var(--text); margin: 8px 0; }
.modal { position: fixed; inset: 0; background: rgba(1,4,9,.75); display: flex; align-items: center; justify-content: center; z-index: 20; padding: 16px; }
.modal-card { background: var(--panel); border: 1px solid var(--warn); border-radius: var(--radius); padding: 22px 24px; max-width: 440px; width: 100%; box-shadow: 0 10px 40px rgba(0,0,0,.5); }
.modal-card h2 { margin: 0 0 10px; font-size: 20px; color: var(--warn); }
.modal-card p { line-height: 1.5; margin: 0 0 12px; }
.modal-card .count { color: var(--warn); font-variant-numeric: tabular-nums; }
.modal-card button { width: 100%; margin-top: 6px; }

/* syntax highlighting */
.hl-k { color: #ff7b72; }
.hl-s { color: #a5d6ff; }
.hl-c { color: #8b949e; font-style: italic; }
.hl-n { color: #79c0ff; }

/* queue extras, files panel, previews */
.queue-eta { margin-top: -4px; }
.notify-btn { margin-top: 6px; }
.small { font-size: 13px; }
#filesList .file-meta { display: flex; gap: 10px; align-items: center; white-space: nowrap; }
#filesList a.dl { text-decoration: none; }
.modal.preview .modal-card { border-color: var(--border); max-width: min(960px, 100%); padding: 0; display: flex; flex-direction: column; max-height: 90vh; }
.modal.preview .modal-card button { width: auto; margin: 0; padding: 3px 10px; }
.pv-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: ui-monospace, Consolas, monospace; font-size: 13px; }
.pv-body { overflow: auto; padding: 12px; min-height: 80px; }
.pv-body pre { margin: 0; font-size: 13px; font-family: ui-monospace, "Cascadia Code", Consolas, monospace; white-space: pre; }
.pv-body img { max-width: 100%; height: auto; display: block; margin: 0 auto; }
.modal.preview .pv-page { max-width: min(1200px, 100%); height: 88vh; max-height: 88vh; overflow: hidden; }
.pv-page iframe { flex: 1; width: 100%; border: 0; background: #fff; border-radius: 0 0 var(--radius) var(--radius); }
.pv-btns { display: flex; gap: 6px; align-items: center; white-space: nowrap; }

/* mobile */
body { height: 100dvh; }
/* mobile breakpoints: see "design refresh" at the end */

/* ---------- code runner */
.code-head .exec { padding: 2px 8px; font-size: 12px; background: #1a7f37; border-color: #2ea043; color: #fff; }
.code-head .exec:hover:not(:disabled) { background: #2ea043; }
.run-out { border-top: 1px solid #30363d; background: #0b0f14; color: #e6edf3; }
.run-out[data-status="err"] .run-head { color: #ff7b72; }
.run-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 4px 10px; font-size: 12px; color: #8b949e; }
.run-head .run-close { padding: 0 6px; font-size: 12px; background: transparent; border: none; color: #8b949e; }
.run-text { margin: 0; padding: 4px 12px 12px; max-height: 360px; overflow: auto; font-size: 13px; white-space: pre-wrap; word-break: break-word; font-family: ui-monospace, "Cascadia Code", Consolas, monospace; }
.run-out .gallery { padding: 0 12px 12px; }

/* ---------- previews: editor, sheets, pdf */
.pv-edit { width: 100%; min-height: 55vh; resize: vertical; box-sizing: border-box; background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 10px; font: 13px/1.5 ui-monospace, "Cascadia Code", Consolas, monospace; tab-size: 2; white-space: pre; direction: ltr; }
.pv-edit-bar { display: flex; justify-content: flex-end; align-items: center; gap: 8px; margin-top: 8px; }
.pv-edit-bar .pv-status { margin-inline-end: auto; font-size: 13px; }
.modal.preview .pv-edit-bar button { padding: 6px 16px; }
.sheet { overflow: auto; max-height: 68vh; border: 1px solid var(--border); border-radius: 8px; }
.sheet table { border-collapse: collapse; font-size: 13px; min-width: 100%; }
.sheet th, .sheet td { border-bottom: 1px solid var(--border); border-inline-end: 1px solid var(--border); padding: 5px 9px; text-align: start; white-space: nowrap; max-width: 360px; overflow: hidden; text-overflow: ellipsis; }
.sheet th { position: sticky; top: 0; background: var(--panel-2); cursor: pointer; user-select: none; font-weight: 600; }
.sheet th:hover { color: var(--accent); }
.sheet th .th-sort { all: unset; display: block; cursor: pointer; overflow: hidden; text-overflow: ellipsis; }
.sheet th .th-sort:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }
.sheet .num { text-align: end; font-variant-numeric: tabular-nums; }
.sheet tbody tr:nth-child(even) { background: color-mix(in srgb, var(--panel-2) 45%, transparent); }
.sheet-tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 8px; }
.modal.preview .sheet-tabs button { padding: 3px 12px; font-size: 13px; }
.sheet-tabs button.on { background: var(--panel-2); border-color: var(--accent); }
.pv-page > iframe { flex: 1; width: 100%; border: 0; background: #525659; border-radius: 0 0 var(--radius) var(--radius); }
.small { font-size: 12px; }

/* ---------- diffs */
details.diff { border: 1px solid var(--border); border-radius: 8px; margin: 4px 0 10px; overflow: hidden; background: var(--panel); }
details.diff summary { cursor: pointer; padding: 6px 10px; font-size: 13px; list-style-position: inside; }
.diff-path { font-family: ui-monospace, Consolas, monospace; }
.diff-add { color: var(--ok); font-weight: 600; }
.diff-del { color: #f85149; font-weight: 600; }
.diff-body { max-height: 420px; overflow: auto; border-top: 1px solid var(--border); font: 12.5px/1.5 ui-monospace, "Cascadia Code", Consolas, monospace; direction: ltr; text-align: left; }
.dl { display: flex; white-space: pre; min-width: max-content; }
.dl .ln { width: 3.2em; flex: none; text-align: right; padding-right: 6px; color: var(--muted); user-select: none; }
.dl .dk { width: 1.4em; flex: none; text-align: center; user-select: none; }
.dl .dc { padding-right: 12px; }
.dl.add { background: rgba(46,160,67,.18); }
.dl.del { background: rgba(248,81,73,.18); }
.dl.add .dk { color: var(--ok); }
.dl.del .dk { color: #f85149; }
.dl.gap { color: var(--muted); padding: 2px 10px; background: var(--panel-2); font-style: italic; }

/* ---------- image editor */
.img-editor .modal-card { max-width: min(1100px, 100%); }
.ie-body { display: flex; flex-direction: column; gap: 8px; }
.ie-tools, .ie-sub { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.ie-sub { font-size: 13px; padding: 6px 8px; background: var(--panel-2); border-radius: 8px; }
.ie-sub input[type="number"] { width: 80px; background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 6px; padding: 3px 6px; }
.ie-stage { position: relative; display: flex; justify-content: center; align-items: center; min-height: 200px; border-radius: 8px; overflow: hidden;
  background: repeating-conic-gradient(#8883 0 25%, transparent 0 50%) 0 0 / 18px 18px; }
.ie-stage canvas { max-width: 100%; max-height: 62vh; display: block; touch-action: none; }
.ie-stage canvas.cropping { cursor: crosshair; }
.ie-crop { position: absolute; border: 2px dashed #fff; box-shadow: 0 0 0 9999px rgba(0,0,0,.5); pointer-events: none; }
.ie-foot { display: flex; justify-content: space-between; gap: 10px; font-size: 12px; }
.ie-status { text-align: end; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- queue card */
.queue-card { max-width: 440px; margin: 0 auto; padding: 26px 24px 20px; background: var(--panel); border: 1px solid var(--border); border-radius: 16px; box-shadow: 0 8px 30px rgba(0,0,0,.18); }
.queue-card h1 { margin-top: 0; }
.queue-card .queue-pos { margin: 0; line-height: 1.1; }
.queue-card .queue-ahead { margin: 4px 0 14px; color: var(--text); }
.queue-bar { height: 8px; border-radius: 999px; background: var(--panel-2); overflow: hidden; margin: 0 0 16px; }
.queue-bar span { display: block; height: 100%; border-radius: inherit; background: var(--accent-2); transition: width 1s linear; }
[dir="rtl"] .queue-bar span { margin-inline-start: 0; background: var(--accent-2); }
.queue-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 14px; }
.queue-stats div { background: var(--panel-2); border-radius: 10px; padding: 8px 4px; display: flex; flex-direction: column; gap: 2px; }
.queue-stats b { font-size: 18px; color: var(--text); font-variant-numeric: tabular-nums; }
.queue-stats small { font-size: 11px; }
.queue-card .leave-btn { margin-top: 6px; font-size: 13px; color: var(--muted); }

/* ---------- usage panel */
button.timer { cursor: pointer; font-family: inherit; }
button.timer:hover { border-color: var(--accent); }
.usage-pop { min-width: 250px; padding: 10px 12px; font-size: 13px; gap: 4px; }
.usage-title { font-weight: 600; margin-bottom: 4px; }
.usage-bar { height: 6px; border-radius: 999px; background: var(--panel-2); overflow: hidden; margin-bottom: 6px; }
.usage-bar span { display: block; height: 100%; background: var(--accent); }
.usage-row { display: flex; justify-content: space-between; gap: 16px; padding: 2px 0; color: var(--muted); }
.usage-row b { color: var(--text); font-weight: 500; font-variant-numeric: tabular-nums; }

/* ---------- language + right-to-left */
.lang-select { background: transparent; color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 6px 6px; font: inherit; font-size: 13px; }
.lang-select option { background: var(--panel); color: var(--text); }
[dir="rtl"] .code, [dir="rtl"] pre, [dir="rtl"] code, [dir="rtl"] .katex-display, [dir="rtl"] .pv-name { direction: ltr; text-align: left; }
[dir="rtl"] .code-head { direction: ltr; }
[dir="rtl"] #scrollBtns { right: auto; left: max(16px, calc(50% - 470px)); }
[dir="rtl"] aside#filesPanel { right: auto; left: 12px; }
/* Arabic: keep the chat layout fixed (you on the right, Nyxo on the left); text inside follows its own language */
[dir="rtl"] #messages .msg { direction: ltr; }
[dir="rtl"] #messages .msg :is(.note, .plan, .thought summary, .typing, .msg-actions button, .tool .tt) { unicode-bidi: plaintext; }

/* files panel rows: friendly name, kind · created → edited · size */
#filesList li { align-items: flex-start; padding: 7px 12px; border-bottom: 1px solid color-mix(in srgb, var(--border) 50%, transparent); }
#filesList li:last-child { border-bottom: none; }
#filesList .file-main { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 2px; }
#filesList .file-main > a { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: start; }
#filesList .file-sub { color: var(--muted); font-size: 11.5px; line-height: 1.35; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
#filesList .file-sub.file-edit { color: var(--accent, #8b7cf6); }
#filesList li.edited .file-sub:not(.file-edit) { color: color-mix(in srgb, var(--warn) 70%, var(--muted)); }
#filesList a.dl { padding: 2px 4px; }

/* in-page confirm dialog */
.modal.ask .ask-card { border-color: var(--border); max-width: 420px; animation: askIn .16s ease-out; }
.modal.ask .ask-card h2 { color: var(--text); font-size: 18px; }
.modal.ask .ask-card p { color: var(--muted); font-size: 14px; }
.human-widget { display: flex; justify-content: center; min-height: 65px; margin-top: 12px; max-width: 100%; overflow: hidden; }
.human .modal-card:focus { outline: none; }
.ask-btns { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.modal-card .ask-btns button { width: auto; margin: 0; }
.ask-btns .ask-extra { margin-inline-end: auto !important; }
@keyframes askIn { from { opacity: 0; transform: translateY(8px) scale(.98); } }
@media (max-width: 520px) {
  .modal.ask { align-items: flex-end; padding: 0; }
  .modal.ask .ask-card { max-width: none; border-radius: 16px 16px 0 0; padding: 20px 18px calc(18px + env(safe-area-inset-bottom)); animation: askUp .2s ease-out; }
  .ask-btns { flex-direction: column-reverse; }
  .modal-card .ask-btns button { width: 100%; padding: 11px; }
  .ask-btns .ask-extra { margin-inline-end: 0 !important; }
  @keyframes askUp { from { transform: translateY(100%); } }
}

/* "closing this tab deletes the chat" bar */
.leave-bar { position: fixed; top: 10px; left: 50%; transform: translateX(-50%); z-index: 30; display: flex; align-items: center; gap: 10px; max-width: calc(100vw - 24px); width: max-content;
  padding: 9px 10px 9px 14px; background: var(--panel); border: 1px solid var(--warn); border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,.35); font-size: 14px; animation: lbIn .2s ease-out; }
.leave-bar .lb-icon { color: var(--warn); }
.leave-bar .lb-text { flex: 1; }
.leave-bar button { padding: 5px 12px; white-space: nowrap; }
.leave-bar .lb-x { padding: 5px 8px; }
@keyframes lbIn { from { opacity: 0; transform: translate(-50%, -8px); } }
@media (max-width: 520px) { .leave-bar { flex-wrap: wrap; width: auto; left: 12px; right: 12px; transform: none; } @keyframes lbIn { from { opacity: 0; } } }

/* ================= design refresh ================= */
html { -webkit-tap-highlight-color: transparent; }
body { overflow-x: hidden; -webkit-font-smoothing: antialiased; }
button { transition: background-color .15s, border-color .15s, color .15s, transform .08s, opacity .15s; }
button:active:not(:disabled) { transform: scale(.97); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button.primary { background: var(--grad); border-color: transparent; }
button.primary:hover:not(:disabled) { background: var(--grad); filter: brightness(1.08); }
svg { flex-shrink: 0; }

/* header */
header { position: relative; z-index: 8; gap: 10px; padding: 8px 16px; background: color-mix(in srgb, var(--panel) 82%, transparent); -webkit-backdrop-filter: saturate(1.4) blur(12px); backdrop-filter: saturate(1.4) blur(12px); border-bottom-color: color-mix(in srgb, var(--border) 70%, transparent); }
.brand { min-width: 0; gap: 9px; }
.brand .logo { width: 26px; height: 26px; border-radius: 8px; display: block; }
.brand-name { font-size: 16.5px; font-weight: 650; letter-spacing: -.01em; }
.actions { min-width: 0; gap: 4px; }
.model-select { border-radius: 10px; padding: 7px 10px; background: var(--panel-2); border-color: transparent; max-width: 200px; text-overflow: ellipsis; }
.model-select:hover { border-color: var(--border); background: var(--panel-2); }
.model-select.single { appearance: none; -webkit-appearance: none; pointer-events: none; cursor: default; }
.hbtn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 11px; border-radius: 10px; border-color: transparent; color: var(--text); font-size: 14px; }
.hbtn svg, .mi svg, #attachBtn svg, button.round svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.hbtn.only-icon { padding: 7px 8px; }
.hbtn.on { background: var(--panel-2); }
#moreBtn svg circle { fill: currentColor; stroke: none; }
.timer { padding: 3px 9px; }

/* more menu */
.more-wrap { position: relative; }
.more-menu { position: absolute; top: calc(100% + 8px); right: 0; z-index: 30; min-width: 230px; padding: 6px; display: flex; flex-direction: column; gap: 2px; background: var(--panel); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); animation: popIn .14s ease-out; transform-origin: top right; }
@keyframes popIn { from { opacity: 0; transform: translateY(-4px) scale(.98); } }
.mi { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 10px; border: none; border-radius: 9px; background: transparent; color: var(--text); font-size: 14px; text-align: start; cursor: pointer; white-space: nowrap; }
.mi:hover { background: var(--panel-2); }
.mi svg { color: var(--muted); }
.mi .lang-select { margin-inline-start: auto; padding: 4px 6px; border-radius: 8px; background: var(--panel-2); border-color: transparent; }
[dir="rtl"] .model-select { direction: ltr; }
[dir="rtl"] .more-menu { right: auto; left: 0; transform-origin: top left; }

/* empty state */
.empty { margin-top: 10vh; animation: msgIn .3s ease-out; }
.empty-logo { width: 56px; height: 56px; border-radius: 16px; display: block; margin: 0 auto 6px; box-shadow: 0 8px 30px rgba(123,107,255,.35); }
.empty h1 { font-size: 28px; letter-spacing: -.02em; margin: 12px 0 8px; }
.empty > p { max-width: 520px; margin-left: auto; margin-right: auto; }

/* messages */
main { scrollbar-width: thin; scrollbar-color: var(--border) transparent; padding-top: 26px; }
.msg.user .bubble { border-radius: 18px 18px 6px 18px; padding: 10px 15px; }
.msg-actions { flex-wrap: wrap; }
.file-link::before { content: "⬇ "; }
.act { white-space: nowrap; border-radius: 8px; }
.tool, .plan, .code, .diagram { border-radius: 10px; }
.tool { align-items: flex-start; }
.tool .tt { white-space: normal; overflow: visible; text-overflow: clip; overflow-wrap: anywhere; line-height: 1.45; }
.typing { border-color: color-mix(in srgb, var(--accent) 35%, var(--border)); }

/* composer */
footer { border-top: none; background: linear-gradient(to bottom, transparent, var(--bg) 22px); padding-top: 6px; padding-bottom: max(12px, env(safe-area-inset-bottom)); }
#composer { align-items: flex-end; gap: 6px; background: var(--panel); border-radius: 24px; padding: 6px 6px 6px 8px; box-shadow: var(--shadow); transition: border-color .15s, box-shadow .15s; }
#composer:focus-within { border-color: color-mix(in srgb, var(--accent) 65%, var(--border)); box-shadow: var(--shadow), 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }
#input { padding: 8px 4px; line-height: 1.45; overflow-y: hidden; }
#attachBtn { width: 38px; height: 38px; padding: 0; display: inline-flex; align-items: center; justify-content: center; border-radius: 50%; color: var(--muted); }
#attachBtn:hover { background: var(--panel-2); color: var(--text); }
button.round { width: 38px; height: 38px; padding: 0; display: inline-flex; align-items: center; justify-content: center; border-radius: 50%; border: none; flex-shrink: 0; }
button.round svg { width: 19px; height: 19px; stroke-width: 2.2; }
#stopBtn svg rect { fill: currentColor; stroke: none; }
#sendBtn:disabled { opacity: .35; filter: grayscale(.5); }
.hint { opacity: 1; }
.chip { border-radius: 10px; }

/* files panel */
aside { top: 56px; border-radius: 16px; box-shadow: var(--shadow); animation: popIn .14s ease-out; }
.panel-head { padding: 10px 12px 10px 16px; }
#filesClose { border: none; background: transparent; padding: 4px 9px; border-radius: 8px; font-size: 18px; line-height: 1; color: var(--muted); }
#filesClose:hover { background: var(--panel-2); color: var(--text); }

/* dialogs */
.modal { -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); }
.modal-card { border-radius: 18px; }

@media (max-width: 760px) {
  .hbtn .lbl { display: none; }
  .hbtn { padding: 8px; }
}
@media (max-width: 600px) {
  header { padding: 8px 10px; gap: 6px; }
  .brand { gap: 7px; }
  .brand-name { display: none; }
  .actions { flex: 1; justify-content: flex-end; }
  .model-select { flex: 0 1 auto; min-width: 0; width: 100%; max-width: 150px; font-size: 13px; padding: 7px 8px; }
  main { padding: 16px 12px; scrollbar-width: none; }
  main::-webkit-scrollbar { display: none; }
  footer { padding-left: 10px; padding-right: 10px; }
  #input { font-size: 16px; } /* prevents iOS zoom on focus */
  .hint { display: none; }
  .msg.user .bubble { max-width: 90%; }
  .msg-actions { opacity: 1; }
  .empty { margin-top: 5vh; }
  .empty-logo { width: 48px; height: 48px; }
  .empty h1 { font-size: 23px; }
  .empty > p { font-size: 14px; }
  #scrollBtns { right: 10px; }
  .fab { width: 36px; height: 36px; font-size: 15px; }
  .queue-pos { font-size: 48px; }
  .chip { max-width: 100%; }
  .modal-card { padding: 18px; }
  .modal.preview .pv-page { height: 92vh; max-height: 92vh; }
  /* files panel becomes a bottom sheet */
  aside, [dir="rtl"] aside#filesPanel { top: auto; bottom: 0; left: 0; right: 0; width: auto; max-height: 72dvh; border-radius: 18px 18px 0 0; border-bottom: none; padding-bottom: env(safe-area-inset-bottom); animation: sheetUp .22s ease-out; }
  aside .panel-head { position: sticky; top: 0; background: var(--panel); z-index: 1; padding-top: 14px; }
  aside .panel-head::before { content: ''; position: absolute; top: 5px; left: 50%; width: 36px; height: 4px; margin-left: -18px; border-radius: 4px; background: var(--border); }
  #filesList li { padding: 10px 16px; }
}
@keyframes sheetUp { from { transform: translateY(100%); } }
@media (max-width: 380px) {
  .timer { padding: 2px 6px; font-size: 11.5px; }
}
@media (max-width: 330px) {
  .brand .logo { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  :not(svg *), *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

/* Visually hidden, still read by screen readers. */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* Nyxo Code card in the waiting line */
.code-promo { margin-top: 16px; padding: 14px 14px 12px; border: 1px solid var(--border); border-radius: 12px; background: var(--panel-2); text-align: start; display: flex; flex-direction: column; gap: 6px; }
.code-promo b { color: var(--text); font-size: 15px; }
.code-promo p { margin: 0; font-size: 13.5px; line-height: 1.45; }
.code-promo .code-promo-btn { align-self: flex-start; margin-top: 4px; padding: 8px 14px; border-radius: 10px; background: var(--accent-2); color: var(--on-accent, #041a20); font-weight: 600; font-size: 14px; text-decoration: none; }
.code-promo .code-promo-btn:hover { background: var(--accent); }
.code-promo .code-promo-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.code-promo small { font-size: 12px; }
.notice.code-note a { color: var(--accent); font-weight: 600; }

/* 12-hour wait between chats: countdown card */
.cooldown-card { width: min(100%, 460px); box-sizing: border-box; text-align: center; padding: clamp(20px, 5vw, 30px) clamp(16px, 5vw, 28px) clamp(16px, 4vw, 22px); }
.cd-badge { width: 52px; height: 52px; margin: 0 auto 12px; border-radius: 50%; display: grid; place-items: center; color: var(--accent); background: var(--panel-2); border: 1px solid var(--border); }
.cooldown-card h1 { margin: 0 0 6px; font-size: clamp(22px, 5.5vw, 28px); }
.cooldown-card .cd-sub { margin: 0 auto 18px; max-width: 34ch; color: var(--muted); font-size: clamp(13.5px, 3.6vw, 15px); line-height: 1.45; }
.cd-clock { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: clamp(6px, 2.5vw, 12px); margin-bottom: 16px; }
.cd-clock div { background: var(--panel-2); border: 1px solid var(--border); border-radius: 14px; padding: clamp(10px, 3vw, 14px) 4px clamp(8px, 2vw, 10px); display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 0; }
.cd-clock b { font-size: clamp(28px, 9vw, 42px); line-height: 1; font-weight: 700; letter-spacing: -0.02em; color: var(--text); font-variant-numeric: tabular-nums; }
.cd-clock small { font-size: clamp(10.5px, 2.8vw, 12px); color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.cooldown-card .cd-bar { margin-bottom: 12px; }
.cooldown-card .cd-next { margin: 0; color: var(--text); font-size: 14px; }
.cooldown-card .cd-next + .primary { margin-top: 12px; width: 100%; }
.cooldown-card .code-promo { margin-top: 18px; }
@media (max-width: 420px) { .cooldown-card .code-promo .code-promo-btn { align-self: stretch; text-align: center; } }