/* ziro شات — styles. Logical properties everywhere so Arabic (RTL) and English (LTR) both just work. */

:root {
  --sx: -1;                 /* slide direction: -1 LTR, +1 RTL (set below) */
  --fs: 1;                  /* text-size setting */
  --sat: max(env(safe-area-inset-top, 0px), var(--safe-area-inset-top, 0px));
  --sab: max(env(safe-area-inset-bottom, 0px), var(--safe-area-inset-bottom, 0px));
  --sal: max(env(safe-area-inset-left, 0px), var(--safe-area-inset-left, 0px));
  --sar: max(env(safe-area-inset-right, 0px), var(--safe-area-inset-right, 0px));
  --ease: cubic-bezier(.2, .8, .2, 1);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Arabic", "Noto Naskh Arabic", "Noto Sans", Tahoma, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Roboto Mono", monospace;
  font-size: calc(16px * var(--fs));
}
:root[dir="rtl"] { --sx: 1; }

:root, :root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b0d12; --bg-2: #10131b; --surface: #151a25; --surface-2: #1c2231; --surface-3: #252c3f;
  --border: #262d3f; --border-strong: #343d56;
  --text: #eceef6; --text-dim: #a7aec4; --text-faint: #6f7791;
  --brand: #8196ff; --brand-2: #9a74ff; --brand-3: #2ee6c5;
  --grad: linear-gradient(135deg, #6c8cff 0%, #8b6cff 55%, #2ee6c5 140%);
  --user-bg: #222a47; --user-text: #f2f4ff;
  --code-bg: #0d1017; --code-head: #161b27;
  --danger: #ff6b81; --ok: #3ddc97; --warn: #ffb454;
  --scrim: rgba(3, 5, 10, .62);
  --shadow: 0 12px 44px rgba(0, 0, 0, .55);
  --glow: radial-gradient(70% 45% at 50% -5%, rgba(124, 141, 255, .22), transparent 72%);
  --hl-kw: #c3a6ff; --hl-str: #8ce0b8; --hl-num: #ffb38a; --hl-fn: #7fb4ff; --hl-cm: #6f7791; --hl-var: #ff9aa8; --hl-attr: #ffd479;
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #ffffff; --bg-2: #f7f8fc; --surface: #f1f3fa; --surface-2: #e8ebf5; --surface-3: #dde1ef;
  --border: #e2e5f0; --border-strong: #ccd2e4;
  --text: #14172a; --text-dim: #4f5873; --text-faint: #8089a3;
  --brand: #4f63f5; --brand-2: #7a52f0; --brand-3: #12b89d;
  --user-bg: #e6eaff; --user-text: #14172a;
  --code-bg: #f6f7fc; --code-head: #eceff8;
  --danger: #e0324f; --ok: #14a869; --warn: #c97a10;
  --scrim: rgba(15, 20, 40, .38);
  --shadow: 0 12px 44px rgba(20, 30, 70, .2);
  --glow: radial-gradient(70% 45% at 50% -5%, rgba(108, 140, 255, .20), transparent 72%);
  --hl-kw: #7a3fe0; --hl-str: #12805a; --hl-num: #c4560a; --hl-fn: #1d5fd6; --hl-cm: #8089a3; --hl-var: #c4284a; --hl-attr: #9a6a00;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--text); font: 400 1rem/1.55 var(--font);
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
  overflow: hidden; overscroll-behavior: none; -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; margin: 0; cursor: pointer; touch-action: manipulation; }
button:disabled { cursor: default; }
textarea, input { font: inherit; color: inherit; }
a { color: var(--brand); }
img { max-width: 100%; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 8px; }
::selection { background: color-mix(in srgb, var(--brand) 35%, transparent); }
svg { flex: none; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* scrollbars (desktop) */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }

/* ------------------------------------------------------------------ boot / gate / setup */
.boot { position: fixed; inset: 0; z-index: 100; display: grid; place-content: center; justify-items: center; gap: 22px; background: var(--bg); transition: opacity .35s var(--ease); }
.boot.gone { opacity: 0; pointer-events: none; }
.boot img { width: 84px; height: 84px; animation: pulse 1.8s ease-in-out infinite; }
.boot-dots { display: flex; gap: 6px; }
.boot-dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--text-faint); animation: bounce 1.2s infinite ease-in-out; }
.boot-dots i:nth-child(2) { animation-delay: .15s; } .boot-dots i:nth-child(3) { animation-delay: .3s; }

.gate {
  position: fixed; inset: 0; z-index: 20; overflow-y: auto; background: var(--glow), var(--bg);
  display: flex; flex-direction: column; align-items: center;
  padding: calc(var(--sat) + 16px) 24px calc(var(--sab) + 22px);
}
.gate-top { align-self: stretch; display: flex; justify-content: flex-end; }
.chip-btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); font-size: .85rem; color: var(--text-dim); }
.chip-btn:hover { color: var(--text); background: var(--surface-2); }
.gate-main { flex: 1; width: 100%; max-width: 420px; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 10px; padding: 20px 0; }
.gate-logo { width: 104px; height: 104px; filter: drop-shadow(0 12px 40px rgba(124, 141, 255, .45)); animation: float 5s ease-in-out infinite; }
.gate-title { margin: 14px 0 0; font-size: 2rem; font-weight: 800; letter-spacing: -.01em; }
.gate-title b { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.gate-sub { margin: 0; color: var(--text-dim); font-size: 1.05rem; }
.gate-feats { list-style: none; margin: 22px 0 8px; padding: 0; width: 100%; display: grid; gap: 10px; text-align: start; }
.gate-feats li { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 16px; background: color-mix(in srgb, var(--surface) 80%, transparent); border: 1px solid var(--border); font-size: .95rem; }
.gate-feats .ic { width: 34px; height: 34px; border-radius: 11px; display: grid; place-items: center; background: var(--surface-2); color: var(--brand); flex: none; }
.gate-actions { width: 100%; max-width: 420px; display: grid; gap: 12px; }
.gbtn { display: flex; align-items: center; justify-content: center; gap: 12px; width: 100%; min-height: 54px; border-radius: 16px; background: #fff; color: #1f2430; font-weight: 600; font-size: 1.02rem; border: 1px solid #dadce0; box-shadow: 0 2px 10px rgba(0, 0, 0, .18); transition: transform .12s, box-shadow .2s; }
.gbtn:active { transform: scale(.985); }
.gbtn:disabled { opacity: .7; }
.gate-fine { margin: 0; font-size: .78rem; color: var(--text-faint); text-align: center; line-height: 1.7; }
.gate-fine a { color: var(--text-dim); }
.gate-err { margin: 0; padding: 10px 12px; border-radius: 12px; background: color-mix(in srgb, var(--danger) 14%, transparent); border: 1px solid color-mix(in srgb, var(--danger) 40%, transparent); color: var(--danger); font-size: .88rem; text-align: center; }
.spinner { width: 20px; height: 20px; border-radius: 50%; border: 2.5px solid color-mix(in srgb, currentColor 25%, transparent); border-top-color: currentColor; animation: spin .8s linear infinite; }

.setup-card { width: 100%; max-width: 520px; text-align: start; background: var(--surface); border: 1px solid var(--border); border-radius: 22px; padding: 22px; margin: auto 0; }
.setup-card h2 { margin: 0 0 6px; font-size: 1.25rem; }
.setup-card p { margin: 0 0 12px; color: var(--text-dim); font-size: .95rem; }
.setup-list { margin: 0 0 14px; padding-inline-start: 1.2em; font-family: var(--mono); font-size: .85rem; direction: ltr; text-align: left; color: var(--warn); }

/* ------------------------------------------------------------------ app shell */
#root { position: fixed; inset: 0; display: flex; flex-direction: column; background: var(--bg); }
.topbar {
  display: flex; align-items: center; gap: 6px; z-index: 5;
  padding: calc(var(--sat) + 6px) calc(8px + var(--sar)) 6px calc(8px + var(--sal));
  background: color-mix(in srgb, var(--bg) 86%, transparent); backdrop-filter: blur(14px);
}
.icon-btn { width: 42px; height: 42px; border-radius: 14px; display: grid; place-items: center; color: var(--text-dim); transition: background .15s, color .15s, transform .1s; flex: none; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn:active { transform: scale(.94); }
.model-pill { margin-inline: auto; display: inline-flex; align-items: center; gap: 8px; min-width: 0; max-width: calc(100% - 104px); padding: 7px 10px 7px 12px; padding-inline: 12px 8px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); transition: background .15s, border-color .15s; }
.model-pill:hover { background: var(--surface-2); border-color: var(--border-strong); }
.model-pill .dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.model-pill .name { font-weight: 650; font-size: .95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.model-pill .ver { font-size: .72rem; padding: 2px 7px; border-radius: 999px; background: var(--surface-3); color: var(--text-dim); white-space: nowrap; }
.model-pill .chev { color: var(--text-faint); }
.banner { text-align: center; font-size: .85rem; padding: 6px 12px; background: color-mix(in srgb, var(--warn) 18%, var(--bg)); color: var(--warn); }

.chat { position: relative; flex: 1; min-height: 0; display: flex; flex-direction: column; }
.msgs { flex: 1; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; padding: 6px 0 20px; }
.msgs-inner { width: 100%; max-width: 780px; margin: 0 auto; padding: 0 calc(16px + var(--sar)) 0 calc(16px + var(--sal)); display: flex; flex-direction: column; gap: 22px; min-height: 100%; }
.to-bottom { position: absolute; inset-inline: 0; bottom: 10px; margin-inline: auto; width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-2); border: 1px solid var(--border-strong); box-shadow: var(--shadow); color: var(--text); z-index: 3; animation: fadeUp .2s var(--ease); }

.empty { margin: auto 0; display: flex; flex-direction: column; align-items: center; text-align: center; gap: 6px; padding: 24px 0; animation: fadeUp .4s var(--ease); }
.empty-logo { width: 72px; height: 72px; filter: drop-shadow(0 10px 30px rgba(124, 141, 255, .4)); }
.empty-title { margin: 12px 0 0; font-size: 1.6rem; font-weight: 750; letter-spacing: -.01em; }
.empty-title b { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; font-weight: inherit; }
.empty-sub { margin: 0; color: var(--text-dim); }
.sugg { margin-top: 22px; width: 100%; display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.sugg-btn { text-align: start; display: flex; flex-direction: column; gap: 4px; padding: 13px 14px; border-radius: 16px; background: var(--surface); border: 1px solid var(--border); transition: background .15s, border-color .15s, transform .1s; min-width: 0; }
.sugg-btn:hover { background: var(--surface-2); border-color: var(--border-strong); }
.sugg-btn:active { transform: scale(.985); }
.sugg-btn .s-ic { color: var(--brand); }
.sugg-btn .s-t { font-weight: 650; font-size: .93rem; }
.sugg-btn .s-d { font-size: .8rem; color: var(--text-dim); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
@media (max-width: 380px) { .sugg { grid-template-columns: 1fr; } }

/* ------------------------------------------------------------------ messages */
.msg { animation: fadeUp .25s var(--ease); min-width: 0; }
.msg.user { align-self: flex-end; max-width: 90%; display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.bubble { background: var(--user-bg); color: var(--user-text); padding: 10px 15px; border-radius: 20px; border-end-end-radius: 6px; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.6; }
.files { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
.file-chip { display: inline-flex; align-items: center; gap: 6px; max-width: 220px; padding: 5px 10px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); font-size: .8rem; color: var(--text-dim); }
.file-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thumbs { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
.thumbs img { width: 96px; height: 96px; object-fit: cover; border-radius: 14px; border: 1px solid var(--border); }
.msg.ai { display: flex; flex-direction: column; gap: 8px; }
.ai-head { display: flex; align-items: center; gap: 8px; font-size: .82rem; color: var(--text-dim); }
.ai-head .av { width: 24px; height: 24px; }
.ai-head .who { font-weight: 600; }
.ai-head .ver { font-size: .7rem; padding: 1px 7px; border-radius: 999px; background: var(--surface-2); }
.think { border: 1px solid var(--border); border-radius: 14px; background: var(--surface); font-size: .9rem; overflow: hidden; }
.think summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 8px; padding: 9px 12px; color: var(--text-dim); font-weight: 600; font-size: .85rem; user-select: none; }
.think summary::-webkit-details-marker { display: none; }
.think summary .chev { margin-inline-start: auto; transition: transform .2s; }
.think[open] summary .chev { transform: rotate(180deg); }
.think .think-body { padding: 2px 14px 12px; color: var(--text-dim); white-space: pre-wrap; overflow-wrap: anywhere; max-height: 260px; overflow-y: auto; }

.md { line-height: 1.75; overflow-wrap: anywhere; min-width: 0; }
.md > :first-child { margin-top: 0; } .md > :last-child { margin-bottom: 0; }
.md p { margin: .65em 0; }
.md h1, .md h2, .md h3, .md h4 { line-height: 1.35; margin: 1.15em 0 .45em; font-weight: 750; }
.md h1 { font-size: 1.4rem; } .md h2 { font-size: 1.22rem; } .md h3 { font-size: 1.08rem; } .md h4 { font-size: 1rem; }
.md ul, .md ol { margin: .55em 0; padding-inline-start: 1.5em; }
.md li { margin: .3em 0; } .md li > p { margin: .2em 0; }
.md a { color: var(--brand); text-underline-offset: 3px; }
.md blockquote { margin: .9em 0; padding: .1em 1em; border-inline-start: 3px solid var(--brand-2); color: var(--text-dim); }
.md hr { border: 0; border-top: 1px solid var(--border); margin: 1.3em 0; }
.md :not(pre) > code { font-family: var(--mono); font-size: .87em; background: var(--surface-2); padding: .13em .42em; border-radius: 7px; direction: ltr; unicode-bidi: isolate; }
.code { margin: .95em 0; border: 1px solid var(--border); border-radius: 14px; overflow: hidden; background: var(--code-bg); direction: ltr; text-align: left; }
.code-head { display: flex; align-items: center; justify-content: space-between; padding: 5px 6px 5px 14px; background: var(--code-head); font-size: .74rem; color: var(--text-dim); font-family: var(--mono); }
.code-head button { display: inline-flex; align-items: center; gap: 6px; padding: 5px 9px; border-radius: 8px; color: var(--text-dim); font-family: var(--font); font-size: .75rem; }
.code-head button:hover { background: var(--surface-3); color: var(--text); }
.code pre { margin: 0; padding: 12px 14px; overflow-x: auto; font: .84rem/1.65 var(--mono); tab-size: 2; }
.code pre code { font: inherit; background: none; padding: 0; }
.tbl { overflow-x: auto; margin: .9em 0; border: 1px solid var(--border); border-radius: 12px; }
.md table { border-collapse: collapse; min-width: 100%; font-size: .93rem; }
.md th, .md td { padding: 8px 12px; border-bottom: 1px solid var(--border); text-align: start; }
.md th { background: var(--surface); font-weight: 650; white-space: nowrap; } .md tr:last-child td { border-bottom: 0; }
.hljs-keyword, .hljs-selector-tag, .hljs-built_in, .hljs-type, .hljs-literal { color: var(--hl-kw); }
.hljs-string, .hljs-regexp, .hljs-addition { color: var(--hl-str); }
.hljs-number, .hljs-symbol, .hljs-bullet { color: var(--hl-num); }
.hljs-title, .hljs-function, .hljs-section, .hljs-class .hljs-title { color: var(--hl-fn); }
.hljs-comment, .hljs-quote, .hljs-meta { color: var(--hl-cm); font-style: italic; }
.hljs-variable, .hljs-template-variable, .hljs-deletion, .hljs-name, .hljs-tag { color: var(--hl-var); }
.hljs-attr, .hljs-attribute, .hljs-params { color: var(--hl-attr); }
.msg.streaming .md > p:last-child::after, .msg.streaming .md > ul:last-child > li:last-child::after, .msg.streaming .md > ol:last-child > li:last-child::after {
  content: ""; display: inline-block; width: 8px; height: 1.05em; margin-inline-start: 3px; vertical-align: -.18em; border-radius: 3px; background: var(--grad); animation: blink 1s steps(2, start) infinite;
}
.typing { display: inline-flex; gap: 5px; padding: 10px 2px; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--text-faint); animation: bounce 1.2s infinite ease-in-out; }
.typing i:nth-child(2) { animation-delay: .15s; } .typing i:nth-child(3) { animation-delay: .3s; }
.msg-err { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: 14px; background: color-mix(in srgb, var(--danger) 12%, transparent); border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent); color: var(--text); font-size: .9rem; }
.msg-err svg { color: var(--danger); margin-top: 2px; }
.msg-err .grow { flex: 1; min-width: 0; }
.msg-err .btn { margin-top: 8px; }
.actions { display: flex; align-items: center; gap: 2px; margin-inline-start: -8px; }
.msg.user .actions { margin-inline: 0 -8px; }
.act { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; color: var(--text-faint); transition: background .15s, color .15s; }
.act:hover { background: var(--surface-2); color: var(--text); }
.act.done { color: var(--ok); }
.act-note { font-size: .75rem; color: var(--text-faint); margin-inline-start: 6px; }

/* ------------------------------------------------------------------ composer */
.composer-wrap { padding: 6px calc(12px + var(--sar)) calc(8px + var(--sab)) calc(12px + var(--sal)); background: linear-gradient(to top, var(--bg) 70%, transparent); }
.composer-inner { max-width: 780px; margin: 0 auto; }
.attach-row { display: flex; gap: 8px; overflow-x: auto; padding: 0 4px 8px; }
.pending { position: relative; flex: none; }
.pending img { width: 62px; height: 62px; object-fit: cover; border-radius: 12px; border: 1px solid var(--border); display: block; }
.pending.file { display: inline-flex; align-items: center; gap: 8px; height: 62px; padding: 0 14px; border-radius: 12px; background: var(--surface); border: 1px solid var(--border); font-size: .82rem; max-width: 200px; }
.pending.file span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pending .x { position: absolute; top: -6px; inset-inline-end: -6px; width: 22px; height: 22px; border-radius: 50%; background: var(--text); color: var(--bg); display: grid; place-items: center; }
.edit-banner { display: flex; align-items: center; gap: 8px; margin: 0 6px 8px; padding: 7px 12px; border-radius: 12px; background: var(--surface); border: 1px solid var(--border); font-size: .85rem; color: var(--text-dim); }
.edit-banner b { flex: 1; font-weight: 600; }
.composer { display: flex; align-items: flex-end; gap: 2px; background: var(--surface); border: 1px solid var(--border); border-radius: 28px; padding: 5px; transition: border-color .15s, box-shadow .15s; }
.composer:focus-within { border-color: color-mix(in srgb, var(--brand) 55%, var(--border)); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 16%, transparent); }
.composer textarea { flex: 1; min-width: 0; min-height: 42px; max-height: 168px; resize: none; border: 0; outline: 0; background: transparent; padding: 9px 6px; line-height: 1.55; }
.composer textarea::placeholder { color: var(--text-faint); }
.c-btn { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; color: var(--text-dim); flex: none; transition: background .15s, color .15s; }
.c-btn:hover { background: var(--surface-2); color: var(--text); }
.c-btn.rec { color: #fff; background: var(--danger); animation: pulse 1.2s infinite; }
.send { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; background: var(--grad); color: #fff; flex: none; transition: transform .1s, opacity .2s; }
.send:active { transform: scale(.92); }
.send[disabled] { background: var(--surface-3); color: var(--text-faint); }
.send.stop { background: var(--text); color: var(--bg); }
.disclaimer { margin: 7px 0 0; text-align: center; font-size: .72rem; color: var(--text-faint); }

/* ------------------------------------------------------------------ layers: sheets, drawer, pages, dialogs, toast */
.layer { position: fixed; inset: 0; z-index: 50; }
.scrim { position: absolute; inset: 0; background: var(--scrim); opacity: 0; transition: opacity .25s; }
.layer.open > .scrim { opacity: 1; }
.sheet { position: absolute; inset-inline: 0; bottom: 0; margin-inline: auto; width: 100%; max-width: 580px; max-height: min(88dvh, 760px); display: flex; flex-direction: column; background: var(--bg-2); border: 1px solid var(--border); border-bottom: 0; border-radius: 28px 28px 0 0; transform: translateY(104%); transition: transform .3s var(--ease); padding-bottom: var(--sab); box-shadow: var(--shadow); }
.layer.open .sheet { transform: none; }
.sheet-handle { width: 40px; height: 4px; border-radius: 4px; background: var(--border-strong); margin: 10px auto 2px; flex: none; }
.sheet-title { text-align: center; font-weight: 700; padding: 8px 16px 10px; flex: none; }
.sheet-sub { text-align: center; color: var(--text-dim); font-size: .85rem; margin: -6px 18px 10px; }
.sheet-body { overflow-y: auto; padding: 4px 12px 14px; overscroll-behavior: contain; }
.sheet-foot { padding: 6px 14px 12px; display: flex; gap: 10px; flex: none; }
.sheet-foot .btn { flex: 1; }
.drawer { position: absolute; top: 0; bottom: 0; inset-inline-start: 0; width: min(88vw, 348px); display: flex; flex-direction: column; background: var(--bg-2); border-inline-end: 1px solid var(--border); transform: translateX(calc(var(--sx) * 104%)); transition: transform .3s var(--ease); padding: var(--sat) 0 var(--sab); box-shadow: var(--shadow); }
.layer.open .drawer { transform: none; }
.page { position: absolute; inset: 0; display: flex; flex-direction: column; background: var(--bg); transform: translateX(calc(var(--sx) * -104%)); transition: transform .3s var(--ease); }
.layer.open .page { transform: none; }
.page-head { display: flex; align-items: center; gap: 4px; padding: calc(var(--sat) + 6px) 8px 6px; border-bottom: 1px solid var(--border); background: color-mix(in srgb, var(--bg) 90%, transparent); }
.page-head h2 { margin: 0; flex: 1; text-align: center; font-size: 1.05rem; font-weight: 700; }
.page-head .spacer { width: 42px; }
.page-body { flex: 1; overflow-y: auto; padding: 14px calc(14px + var(--sar)) calc(var(--sab) + 28px) calc(14px + var(--sal)); }
.page-inner { max-width: 640px; margin: 0 auto; display: grid; gap: 18px; }
.dialog { position: absolute; inset: 0; display: grid; place-items: center; padding: 20px; }
.dialog-card { width: min(92vw, 390px); background: var(--bg-2); border: 1px solid var(--border-strong); border-radius: 24px; padding: 22px 20px 16px; box-shadow: var(--shadow); transform: scale(.94); opacity: 0; transition: transform .25s var(--ease), opacity .2s; }
.layer.open .dialog-card { transform: none; opacity: 1; }
.dialog-card h3 { margin: 0 0 8px; font-size: 1.1rem; }
.dialog-card p { margin: 0 0 14px; color: var(--text-dim); font-size: .95rem; line-height: 1.65; white-space: pre-line; }
.dialog-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 6px; }
.dialog-actions .btn { flex: 1; }
.toast-host { position: fixed; inset-inline: 0; bottom: calc(var(--sab) + 96px); z-index: 90; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; padding: 0 16px; }
.toast { max-width: 92vw; padding: 10px 16px; background: var(--surface-3); border: 1px solid var(--border-strong); border-radius: 14px; box-shadow: var(--shadow); font-size: .9rem; animation: fadeUp .25s var(--ease); display: flex; gap: 8px; align-items: center; }
.toast.err { border-color: color-mix(in srgb, var(--danger) 50%, transparent); }
.toast.ok svg { color: var(--ok); } .toast.err svg { color: var(--danger); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 46px; padding: 0 18px; border-radius: 14px; background: var(--surface-2); border: 1px solid var(--border); font-weight: 600; transition: background .15s, transform .1s, opacity .2s; }
.btn:hover { background: var(--surface-3); }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--grad); border-color: transparent; color: #fff; }
.btn.danger { background: color-mix(in srgb, var(--danger) 16%, transparent); border-color: color-mix(in srgb, var(--danger) 45%, transparent); color: var(--danger); }
.btn.danger.solid { background: var(--danger); color: #fff; border-color: transparent; }
.btn.ghost { background: transparent; }
.btn.sm { min-height: 36px; padding: 0 12px; border-radius: 11px; font-size: .85rem; }
.btn[disabled] { opacity: .55; }

/* lists */
.list { display: grid; gap: 2px; }
.item { display: flex; align-items: center; gap: 14px; width: 100%; padding: 13px 14px; border-radius: 14px; text-align: start; font-weight: 550; }
.item:hover, .item:active { background: var(--surface-2); }
.item svg { color: var(--text-dim); }
.item.danger, .item.danger svg { color: var(--danger); }
.item .grow { flex: 1; min-width: 0; }
.item .sub { display: block; font-weight: 400; font-size: .82rem; color: var(--text-dim); }
.search { display: flex; align-items: center; gap: 8px; margin: 4px 12px 6px; padding: 0 12px; height: 42px; border-radius: 14px; background: var(--surface); border: 1px solid var(--border); color: var(--text-faint); }
.search input { flex: 1; min-width: 0; height: 100%; background: transparent; border: 0; outline: 0; color: var(--text); }
.search input::-webkit-search-cancel-button, .search input::-webkit-search-decoration { -webkit-appearance: none; appearance: none; display: none; }
.drawer-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px 4px; }
.drawer-head .brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 1.05rem; flex: 1; }
.drawer-head .brand img { width: 30px; height: 30px; }
.new-chat { display: flex; align-items: center; gap: 10px; margin: 8px 12px 6px; padding: 0 14px; min-height: 46px; border-radius: 14px; background: var(--grad); color: #fff; font-weight: 650; }
.chat-list { flex: 1; overflow-y: auto; padding: 0 8px 8px; overscroll-behavior: contain; }
.grp { font-size: .74rem; color: var(--text-faint); padding: 14px 12px 6px; font-weight: 700; letter-spacing: .03em; }
.chat-row { display: flex; align-items: center; gap: 2px; border-radius: 12px; min-height: 44px; }
.chat-row.active { background: var(--surface-2); }
.chat-row:hover { background: var(--surface); }
.chat-row .t { flex: 1; min-width: 0; text-align: start; padding: 10px 10px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .95rem; }
.chat-row .pin { color: var(--brand); display: grid; place-items: center; }
.chat-row .more { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; color: var(--text-faint); }
.chat-row .more:hover { background: var(--surface-3); color: var(--text); }
.empty-list { text-align: center; color: var(--text-faint); padding: 30px 16px; font-size: .9rem; }
.drawer-foot { border-top: 1px solid var(--border); padding: 10px 12px 6px; display: flex; align-items: center; gap: 10px; }
.drawer-foot .who { flex: 1; min-width: 0; text-align: start; display: flex; align-items: center; gap: 10px; padding: 6px; border-radius: 14px; }
.drawer-foot .who:hover { background: var(--surface); }
.avatar { width: 38px; height: 38px; border-radius: 50%; object-fit: cover; background: var(--grad); color: #fff; display: grid; place-items: center; font-weight: 800; flex: none; overflow: hidden; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.who .n { font-weight: 650; font-size: .93rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who .e { font-size: .76rem; color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; direction: ltr; text-align: start; }
.who > div { min-width: 0; }

/* model picker */
.fam-title { font-size: .74rem; font-weight: 700; letter-spacing: .04em; color: var(--text-faint); padding: 12px 10px 6px; }
.model-row { display: flex; align-items: flex-start; gap: 12px; width: 100%; padding: 12px; border-radius: 18px; text-align: start; border: 1px solid transparent; transition: background .15s; }
.model-row:hover { background: var(--surface); }
.model-row[aria-selected="true"] { background: var(--surface); border-color: color-mix(in srgb, var(--brand) 50%, var(--border)); }
.fam-ic { width: 40px; height: 40px; border-radius: 13px; display: grid; place-items: center; font-weight: 800; color: #fff; flex: none; font-size: 1.05rem; }
.mr-main { flex: 1; min-width: 0; display: grid; gap: 3px; }
.mr-name { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.mr-ver { font-size: .72rem; font-weight: 600; padding: 1px 8px; border-radius: 999px; background: var(--surface-3); color: var(--text-dim); }
.mr-desc { font-size: .85rem; color: var(--text-dim); line-height: 1.5; }
.tags { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 3px; }
.tag { display: inline-flex; align-items: center; gap: 4px; font-size: .7rem; padding: 2px 8px; border-radius: 999px; background: var(--surface-3); color: var(--text-dim); }
.tag.warn { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.tag.ok { background: color-mix(in srgb, var(--ok) 16%, transparent); color: var(--ok); }
.model-row .check { color: var(--brand); margin-top: 8px; }
.note { margin: 6px 12px 4px; padding: 10px 12px; border-radius: 12px; background: color-mix(in srgb, var(--warn) 10%, transparent); color: var(--text-dim); font-size: .8rem; line-height: 1.6; }

/* settings */
.sect-title { font-size: .78rem; font-weight: 700; color: var(--text-faint); letter-spacing: .04em; margin: 0 6px 8px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 20px; overflow: hidden; }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; min-height: 58px; width: 100%; text-align: start; }
.row + .row { border-top: 1px solid var(--border); }
button.row:hover, a.row:hover { background: var(--surface-2); }
a.row { text-decoration: none; color: inherit; }
.row .ic { width: 36px; height: 36px; border-radius: 11px; display: grid; place-items: center; background: var(--surface-2); color: var(--text-dim); flex: none; }
.row .txt { flex: 1; min-width: 0; }
.row .lbl { font-weight: 600; }
.row .sub { font-size: .82rem; color: var(--text-dim); margin-top: 1px; line-height: 1.5; }
.row .val { color: var(--text-dim); font-size: .88rem; max-width: 45%; text-align: end; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row.danger .lbl, .row.danger .ic { color: var(--danger); }
.row .chev { color: var(--text-faint); }
.row.col { flex-direction: column; align-items: stretch; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 12px; padding: 3px; flex: none; }
.seg button { padding: 6px 12px; border-radius: 9px; font-size: .85rem; color: var(--text-dim); font-weight: 600; }
.seg button[aria-pressed="true"] { background: var(--surface-3); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, .25); }
.switch { width: 48px; height: 28px; border-radius: 999px; background: var(--surface-3); position: relative; flex: none; transition: background .2s; }
.switch::after { content: ""; position: absolute; top: 3px; inset-inline-start: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .35); transition: transform .2s var(--ease); }
.switch[aria-checked="true"] { background: var(--grad); }
.switch[aria-checked="true"]::after { transform: translateX(calc(var(--sx) * -20px)); }
.profile { display: flex; align-items: center; gap: 14px; padding: 16px; }
.profile .avatar { width: 56px; height: 56px; font-size: 1.3rem; }
.profile .n { font-weight: 750; font-size: 1.05rem; }
.profile .e { color: var(--text-dim); font-size: .88rem; direction: ltr; text-align: start; overflow-wrap: anywhere; }
.field { width: 100%; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 12px 14px; outline: 0; resize: vertical; line-height: 1.6; }
.field:focus { border-color: color-mix(in srgb, var(--brand) 60%, var(--border)); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 16%, transparent); }
.counter { text-align: end; font-size: .75rem; color: var(--text-faint); margin-top: 4px; }
.radio-row { display: flex; align-items: center; gap: 12px; width: 100%; padding: 12px 14px; border-radius: 14px; text-align: start; }
.radio-row:hover { background: var(--surface-2); }
.radio-row .dot { width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--border-strong); flex: none; display: grid; place-items: center; }
.radio-row[aria-checked="true"] .dot { border-color: var(--brand); }
.radio-row[aria-checked="true"] .dot::after { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--brand); }
.about-logo { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 8px 0 2px; }
.about-logo img { width: 64px; height: 64px; }
.about-logo b { font-size: 1.15rem; } .about-logo span { color: var(--text-dim); font-size: .85rem; }
.perm-badge { font-size: .72rem; padding: 3px 9px; border-radius: 999px; background: var(--surface-3); color: var(--text-dim); white-space: nowrap; }
.perm-badge.ok { background: color-mix(in srgb, var(--ok) 16%, transparent); color: var(--ok); }
.perm-badge.warn { background: color-mix(in srgb, var(--warn) 16%, transparent); color: var(--warn); }

/* ------------------------------------------------------------------ motion */
@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes bounce { 0%, 80%, 100% { transform: scale(.6); opacity: .5; } 40% { transform: scale(1); opacity: 1; } }
@keyframes blink { to { visibility: hidden; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.06); } }
@keyframes float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; } }
@media (min-width: 900px) { .msgs-inner { padding-inline: 20px; } .sheet { border-radius: 28px; bottom: 6vh; border-bottom: 1px solid var(--border); } }
