@font-face { font-family: "Vazirmatn"; src: url("/fonts/Vazirmatn-Regular.ttf") format("truetype"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Vazirmatn"; src: url("/fonts/Vazirmatn-Medium.ttf") format("truetype"); font-weight: 500; font-display: swap; }
@font-face { font-family: "Vazirmatn"; src: url("/fonts/Vazirmatn-SemiBold.ttf") format("truetype"); font-weight: 600; font-display: swap; }
@font-face { font-family: "Vazirmatn"; src: url("/fonts/Vazirmatn-Bold.ttf") format("truetype"); font-weight: 700 800; font-display: swap; }
@font-face { font-family: "JetBrains Mono"; src: url("/fonts/jetbrains-mono-400.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "JetBrains Mono"; src: url("/fonts/jetbrains-mono-600.woff2") format("woff2"); font-weight: 600 700; font-display: swap; }
@font-face { font-family: "DejaVu Sans Mono"; src: url("/fonts/DejaVuSansMono.ttf") format("truetype"); font-weight: 400 700; font-display: swap; }

:root {
  color-scheme: dark;
  --bg: #080c16;
  --bg-2: #0b1122;
  --panel: rgba(13, 19, 33, 0.86);
  --panel-solid: #0d1321;
  --soft: rgba(255, 255, 255, 0.045);
  --soft-2: rgba(255, 255, 255, 0.075);
  --border: rgba(255, 255, 255, 0.09);
  --text: #f3f5fb;
  --muted: #929bb0;
  --faint: #5f6883;
  --accent: #8b7cf8;
  --accent-2: #a7b4ff;
  --accent-soft: color-mix(in srgb, var(--accent) 14%, transparent);
  --accent-line: color-mix(in srgb, var(--accent) 34%, transparent);
  --success: #48d7a8;
  --warn: #f5c56b;
  --danger: #ff7890;
  --code-bg: #0a0f1d;
  --term-bg: #05070d;
  --term-fg: #d6dbe8;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.38);
  --sidebar-w: 320px;
  --chat-w: 900px;
  --fs: 15px;
  --lh: 1.85;
  --ui-font: "Vazirmatn", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "DejaVu Sans Mono", "JetBrains Mono", ui-monospace, monospace;
  --code-font: "JetBrains Mono", "DejaVu Sans Mono", ui-monospace, monospace;
  --radius: 16px;
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f5fb;
  --bg-2: #eceef8;
  --panel: rgba(255, 255, 255, 0.9);
  --panel-solid: #ffffff;
  --soft: rgba(15, 23, 42, 0.04);
  --soft-2: rgba(15, 23, 42, 0.07);
  --border: rgba(15, 23, 42, 0.1);
  --text: #151b2d;
  --muted: #5b6478;
  --faint: #8a93a8;
  --code-bg: #f1f3fa;
  --shadow: 0 20px 60px rgba(30, 41, 80, 0.14);
}
:root[data-accent="blue"] { --accent: #5b9dff; --accent-2: #8fd0ff; }
:root[data-accent="teal"] { --accent: #2ec5b0; --accent-2: #8ff0d8; }
:root[data-accent="rose"] { --accent: #f472b6; --accent-2: #ffb1d8; }
:root[data-accent="amber"] { --accent: #f5a524; --accent-2: #ffd27a; }

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--ui-font);
  font-size: var(--fs);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: not-allowed; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
svg { display: block; }

.bg-glow {
  position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background:
    radial-gradient(900px 520px at 85% -10%, color-mix(in srgb, var(--accent) 16%, transparent), transparent 70%),
    radial-gradient(700px 480px at 5% 110%, rgba(46, 197, 176, 0.08), transparent 70%),
    radial-gradient(600px 400px at 40% 50%, rgba(99, 102, 241, 0.05), transparent 70%);
}
:root[data-theme="light"] .bg-glow { opacity: .55; }

/* ---------- buttons ---------- */
.btn-primary {
  border: 0; border-radius: 12px; padding: 11px 20px; font-weight: 600;
  color: #fff; background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 10px 30px color-mix(in srgb, var(--accent) 30%, transparent);
  transition: transform .15s, filter .15s;
}
.btn-primary:hover { filter: brightness(1.07); }
.btn-primary:active { transform: translateY(1px); }
.btn-primary.wide { width: 100%; }
.btn-ghost {
  display: inline-flex; align-items: center; gap: 8px;
  border: 1px solid var(--border); background: var(--soft); border-radius: 11px;
  padding: 7px 13px; font-size: .88em; color: var(--text);
}
.btn-ghost:hover { background: var(--soft-2); }
.btn-ghost.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, transparent); }
.icon-btn {
  width: 36px; height: 36px; display: inline-grid; place-items: center; flex: none;
  border: 1px solid var(--border); background: var(--soft); border-radius: 11px; color: var(--muted);
}
.icon-btn:hover { color: var(--text); background: var(--soft-2); }
.icon-btn svg { width: 18px; height: 18px; }

/* ---------- login ---------- */
.login { position: relative; z-index: 1; min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; overflow: auto; }
.login-card {
  width: min(400px, 100%); padding: 34px 28px 28px; border-radius: 24px;
  background: var(--panel); border: 1px solid var(--border); box-shadow: var(--shadow);
  backdrop-filter: blur(18px); display: grid; gap: 14px;
}
.login-logo { width: 72px; height: 72px; margin: 0 auto 4px; border-radius: 22px; display: grid; place-items: center; background: var(--soft); border: 1px solid var(--border); }
.login-logo img { width: 52px; height: 52px; }
.login-card h1 { margin: 0; text-align: center; font-size: 1.45em; letter-spacing: .01em; }
.login-sub { margin: -8px 0 8px; text-align: center; color: var(--muted); font-size: .92em; }
.field { display: grid; gap: 6px; font-size: .88em; color: var(--muted); }
.field input {
  width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--soft); color: var(--text); font: inherit; font-size: 15px; text-align: left;
}
.field input:focus { outline: none; border-color: var(--accent-line); box-shadow: 0 0 0 3px var(--accent-soft); }
.login-error { min-height: 1.2em; margin: 0; color: var(--danger); font-size: .88em; text-align: center; }

/* ---------- layout ---------- */
.app {
  position: relative; z-index: 1; height: 100dvh;
  display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
}
.sidebar {
  display: flex; flex-direction: column; gap: 14px; min-height: 0;
  padding: 18px 16px 14px; background: var(--panel); border-inline-end: 1px solid var(--border);
  backdrop-filter: blur(18px);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-logo { width: 42px; height: 42px; flex: none; border-radius: 13px; display: grid; place-items: center; background: var(--soft); border: 1px solid var(--border); }
.brand-logo img { width: 28px; height: 28px; }
.brand-text { display: grid; line-height: 1.35; flex: 1; min-width: 0; }
.brand-text strong { font-size: 1.02em; }
.brand-text small { color: var(--muted); font-size: .78em; }

.power {
  position: relative; display: flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; padding: 13px 16px; border-radius: 14px; border: 1px solid transparent; font-weight: 700; font-size: 1em;
  color: #fff; background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 12px 34px color-mix(in srgb, var(--accent) 32%, transparent);
  transition: filter .15s, transform .15s, background .25s;
}
.power:hover { filter: brightness(1.06); }
.power:active { transform: translateY(1px); }
.power .power-icon svg { width: 19px; height: 19px; }
.power[data-state="on"] { background: var(--soft); color: var(--text); border-color: var(--border); box-shadow: none; }
.power[data-state="on"] .power-icon { color: var(--success); }
.power[data-state="confirm"] { background: color-mix(in srgb, var(--danger) 18%, transparent); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, transparent); box-shadow: none; }
.power[data-state="busy"] { opacity: .8; cursor: progress; }
.power[data-state="busy"] .power-icon { animation: spin 1s linear infinite; }
.power-note { margin: -6px 2px 0; color: var(--faint); font-size: .76em; line-height: 1.6; }

.section-head { display: flex; align-items: center; justify-content: space-between; color: var(--muted); font-size: .8em; font-weight: 600; padding: 4px 4px 0; }
.count { min-width: 24px; height: 22px; padding: 0 7px; display: inline-grid; place-items: center; border-radius: 999px; background: var(--soft-2); font-size: .9em; }

.session-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; overflow: auto; }
.session {
  width: 100%; display: flex; align-items: center; gap: 12px; text-align: start;
  padding: 11px 12px; border-radius: 14px; border: 1px solid transparent; background: transparent;
  transition: background .15s, border-color .15s, opacity .2s;
}
.session:hover:not(:disabled) { background: var(--soft); }
.session.active { background: var(--accent-soft); border-color: var(--accent-line); }
.session:disabled { opacity: .45; }
.avatar {
  width: 40px; height: 40px; flex: none; border-radius: 12px; display: grid; place-items: center;
  background: var(--soft-2); border: 1px solid var(--border); font-weight: 700; font-size: .85em; color: var(--accent-2);
  font-family: var(--code-font);
}
.session.active .avatar { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; border-color: transparent; }
.s-text { display: grid; min-width: 0; flex: 1; line-height: 1.4; }
.s-name { font-weight: 600; font-family: var(--code-font); font-size: .95em; direction: ltr; text-align: end; }
.s-sub { display: flex; align-items: center; gap: 6px; font-size: .76em; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--faint); }
.dot[data-state="ready"] { background: var(--success); box-shadow: 0 0 0 3px color-mix(in srgb, var(--success) 18%, transparent); }
.dot[data-state="busy"] { background: var(--accent); animation: glow 1.4s ease-in-out infinite; }
.dot[data-state="waiting"] { background: var(--warn); animation: glow 1.4s ease-in-out infinite; }
.dot[data-state="booting"] { background: var(--warn); opacity: .7; animation: blink 1s ease-in-out infinite; }
.lock { color: var(--faint); }
.lock svg { width: 15px; height: 15px; }

.sidebar-foot { margin-top: auto; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding-top: 12px; border-top: 1px solid var(--border); }
.user-chip { display: flex; align-items: center; gap: 8px; font-size: .86em; color: var(--muted); font-family: var(--code-font); direction: ltr; }
.user-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--success); }
.foot-actions { display: flex; gap: 6px; }

/* ---------- main ---------- */
.main { position: relative; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 14px 22px; min-height: 66px;
  border-bottom: 1px solid var(--border); background: color-mix(in srgb, var(--bg) 70%, transparent); backdrop-filter: blur(14px);
}
.top-title { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }
.top-title strong { font-size: 1.05em; font-family: var(--code-font); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { display: flex; align-items: center; gap: 8px; }
.state-chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: .76em; background: var(--soft-2); color: var(--muted); white-space: nowrap; }
.state-chip[data-state="ready"] { color: var(--success); background: color-mix(in srgb, var(--success) 12%, transparent); }
.state-chip[data-state="busy"] { color: var(--accent-2); background: var(--accent-soft); }
.state-chip[data-state="waiting"] { color: var(--warn); background: color-mix(in srgb, var(--warn) 12%, transparent); }
.seg { display: inline-flex; padding: 3px; border-radius: 12px; background: var(--soft); border: 1px solid var(--border); }
.seg button { border: 0; background: transparent; padding: 6px 14px; border-radius: 9px; font-size: .86em; color: var(--muted); }
.seg button.on { background: var(--panel-solid); color: var(--text); box-shadow: 0 2px 10px rgba(0,0,0,.18); }
.i-stop svg { width: 14px; height: 14px; }

.empty { flex: 1; display: grid; place-content: center; justify-items: center; text-align: center; padding: 24px 16px; gap: 6px; }
.empty-logo { width: 150px; height: 150px; opacity: .14; filter: saturate(1.2); margin-bottom: 8px; }
.empty h2 { margin: 0; font-size: 1.5em; }
.empty p { margin: 0; color: var(--muted); max-width: 460px; font-size: .95em; }

.chat-view { position: relative; flex: 1; min-height: 0; display: flex; }
.chat-scroll { flex: 1; overflow-y: auto; overflow-x: hidden; scroll-behavior: auto; }
.chat-inner { width: min(var(--chat-w), 100%); margin: 0 auto; padding: 26px 22px 18px; }
.load-more { display: block; margin: 0 auto 18px; border: 1px solid var(--border); background: var(--soft); color: var(--muted); border-radius: 999px; padding: 6px 16px; font-size: .82em; }
.messages { display: grid; gap: 14px; }

.msg-user { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; }
.bubble {
  max-width: min(88%, 720px); padding: 12px 16px; border-radius: 18px; border-end-start-radius: 6px;
  background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 22%, transparent), color-mix(in srgb, var(--accent-2) 10%, transparent));
  border: 1px solid var(--accent-line); white-space: pre-wrap; min-width: 46px; text-align: start; word-break: break-word; line-height: var(--lh);
}
.bubble.pending { opacity: .6; border-style: dashed; }
.meta { font-size: .72em; color: var(--faint); padding: 0 6px; display: flex; gap: 8px; align-items: center; }
.meta button { border: 0; background: none; color: var(--faint); padding: 0; font-size: 1em; }

.turn { display: grid; grid-template-columns: 34px minmax(0, 1fr); gap: 12px; align-items: start; }
.turn-avatar { width: 34px; height: 34px; border-radius: 11px; display: grid; place-items: center; background: linear-gradient(135deg, #d97757, #f0a67e); color: #fff; font-weight: 800; font-size: .8em; margin-top: 2px; }
.turn-body { display: grid; gap: 10px; min-width: 0; }

.md { line-height: var(--lh); word-break: break-word; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 .7em; }
.md h1, .md h2, .md h3, .md h4 { margin: 1.1em 0 .45em; line-height: 1.45; }
.md h1 { font-size: 1.35em; } .md h2 { font-size: 1.2em; } .md h3 { font-size: 1.07em; } .md h4 { font-size: 1em; }
.md ul, .md ol { margin: 0 0 .7em; padding-inline-start: 1.5em; }
.md li { margin: .2em 0; }
.md li > ul, .md li > ol { margin: .2em 0; }
.md blockquote { margin: 0 0 .7em; padding: 4px 14px; border-inline-start: 3px solid var(--accent-line); color: var(--muted); }
.md hr { border: 0; border-top: 1px solid var(--border); margin: 1em 0; }
.md a { color: var(--accent-2); text-decoration: none; border-bottom: 1px dashed var(--accent-line); }
.md code { font-family: var(--code-font); font-size: .86em; padding: .12em .42em; border-radius: 6px; background: var(--soft-2); direction: ltr; unicode-bidi: isolate; }
.md strong { font-weight: 700; }
.codeblock { margin: 0 0 .8em; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; background: var(--code-bg); direction: ltr; }
.code-head { display: flex; justify-content: space-between; align-items: center; padding: 6px 12px; font-size: .74em; color: var(--faint); border-bottom: 1px solid var(--border); font-family: var(--code-font); }
.code-head button { border: 0; background: none; color: var(--muted); font-size: 1em; font-family: var(--ui-font); }
.codeblock pre { margin: 0; padding: 12px 14px; overflow-x: auto; font-family: var(--code-font); font-size: .84em; line-height: 1.65; text-align: left; }
.codeblock code { background: none; padding: 0; font-size: 1em; }
.table-wrap { overflow-x: auto; margin: 0 0 .8em; border: 1px solid var(--border); border-radius: 12px; }
.md table { border-collapse: collapse; width: 100%; font-size: .92em; }
.md th, .md td { padding: 8px 12px; border-bottom: 1px solid var(--border); text-align: start; vertical-align: top; }
.md th { background: var(--soft); font-weight: 600; }
.md tr:last-child td { border-bottom: 0; }

.thinking { border: 1px solid var(--border); border-radius: 12px; background: var(--soft); }
.thinking summary { cursor: pointer; padding: 7px 12px; color: var(--muted); font-size: .84em; list-style: none; display: flex; align-items: center; gap: 8px; }
.thinking summary::-webkit-details-marker, .tool summary::-webkit-details-marker { display: none; }
.thinking .md { padding: 4px 14px 12px; color: var(--muted); font-size: .92em; }

.tools { display: grid; gap: 6px; }
.tool { border: 1px solid var(--border); border-radius: 12px; background: var(--soft); overflow: hidden; }
.tool summary { cursor: pointer; list-style: none; display: flex; align-items: center; gap: 10px; padding: 8px 12px; font-size: .86em; }
.tool summary:hover { background: var(--soft-2); }
.t-icon { width: 26px; height: 26px; flex: none; display: grid; place-items: center; border-radius: 8px; background: var(--soft-2); color: var(--accent-2); }
.t-icon svg { width: 15px; height: 15px; }
.t-name { font-weight: 600; font-family: var(--code-font); font-size: .92em; direction: ltr; }
.t-desc { color: var(--muted); flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.t-desc.ltr { direction: ltr; text-align: right; font-family: var(--code-font); font-size: .92em; }
.t-status { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--accent); animation: glow 1.2s ease-in-out infinite; }
.t-status.ok { background: var(--success); animation: none; }
.t-status.err { background: var(--danger); animation: none; }
.tool-body { border-top: 1px solid var(--border); padding: 10px 12px; display: grid; gap: 8px; }
.io-label { font-size: .72em; color: var(--faint); }
.io { margin: 0; padding: 10px 12px; border-radius: 10px; background: var(--code-bg); border: 1px solid var(--border); font-family: var(--code-font); font-size: .8em; line-height: 1.6; white-space: pre-wrap; word-break: break-word; max-height: 360px; overflow: auto; direction: ltr; text-align: left; }
.io.err { border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.io.del { background: color-mix(in srgb, var(--danger) 8%, var(--code-bg)); }
.io.add { background: color-mix(in srgb, var(--success) 8%, var(--code-bg)); }
.todo { list-style: none; margin: 0; padding: 10px 12px; display: grid; gap: 5px; border: 1px solid var(--border); border-radius: 12px; background: var(--soft); font-size: .9em; }
.todo li { display: flex; gap: 8px; align-items: baseline; }
.todo .box { width: 15px; height: 15px; flex: none; border-radius: 5px; border: 1.5px solid var(--faint); transform: translateY(2px); }
.todo .done .box { background: var(--success); border-color: var(--success); }
.todo .done span:last-child { color: var(--faint); text-decoration: line-through; }
.todo .doing .box { border-color: var(--accent); background: var(--accent-soft); }

.cmd { justify-self: start; display: inline-flex; gap: 8px; align-items: center; padding: 5px 12px; border-radius: 999px; background: var(--soft-2); border: 1px solid var(--border); font-family: var(--code-font); font-size: .82em; color: var(--muted); direction: ltr; }
.note { text-align: center; color: var(--faint); font-size: .8em; white-space: pre-wrap; padding: 2px 10px; }
.divider { display: flex; align-items: center; gap: 12px; color: var(--faint); font-size: .78em; }
.divider::before, .divider::after { content: ""; flex: 1; border-top: 1px dashed var(--border); }

.pending-box { display: grid; gap: 10px; margin-top: 14px; }
.pending-box:empty { display: none; }
.activity { display: flex; align-items: center; gap: 10px; margin-top: 16px; padding: 10px 14px; border-radius: 12px; border: 1px solid var(--accent-line); background: var(--accent-soft); color: var(--accent-2); font-size: .86em; font-family: var(--code-font); direction: ltr; }
.pulse { width: 9px; height: 9px; border-radius: 50%; background: var(--accent); animation: glow 1.1s ease-in-out infinite; flex: none; }
.to-bottom { position: absolute; bottom: 16px; left: 50%; transform: translateX(-50%); width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--border); background: var(--panel-solid); color: var(--text); display: grid; place-items: center; box-shadow: var(--shadow); }
.to-bottom svg { width: 18px; height: 18px; }

/* ---------- terminal ---------- */
.term-view { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 10px; padding: 16px 18px 10px; }
.term-wrap { flex: 1; min-height: 0; overflow: auto; border-radius: 16px; background: var(--term-bg); border: 1px solid var(--border); box-shadow: inset 0 0 0 1px rgba(255,255,255,.02); }
.term { margin: 0; padding: 14px 16px; color: var(--term-fg); font-family: var(--mono); font-size: 13px; line-height: 1.22; white-space: pre; text-align: left; font-variant-ligatures: none; width: max-content; min-width: 100%; }
.keybar { direction: ltr; display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.keybar button { min-width: 42px; padding: 6px 10px; border-radius: 10px; border: 1px solid var(--border); background: var(--soft); font-family: var(--code-font); font-size: .8em; direction: ltr; }
.keybar button:hover { background: var(--soft-2); }

/* ---------- dialog + composer ---------- */
.dialog-card { width: min(var(--chat-w), calc(100% - 32px)); margin: 0 auto 10px; padding: 12px 14px; border-radius: 16px; border: 1px solid color-mix(in srgb, var(--warn) 40%, transparent); background: color-mix(in srgb, var(--warn) 8%, var(--panel-solid)); display: grid; gap: 10px; }
.dialog-q { font-size: .9em; font-weight: 600; direction: ltr; text-align: left; font-family: var(--code-font); }
.dialog-q:empty { display: none; }
.dialog-opts { display: flex; flex-wrap: wrap; gap: 8px; direction: ltr; }
.dialog-opts button { padding: 7px 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--panel-solid); font-size: .84em; text-align: left; font-family: var(--code-font); max-width: 100%; white-space: normal; }
.dialog-opts button.sel { border-color: var(--accent-line); background: var(--accent-soft); }
.dialog-opts button.esc { color: var(--danger); }

.composer { padding: 6px 16px calc(12px + env(safe-area-inset-bottom)); }
.composer-box {
  width: min(var(--chat-w), 100%); margin: 0 auto; display: flex; align-items: flex-end; gap: 10px;
  padding: 10px 10px 10px 10px; border-radius: 20px; background: var(--panel); border: 1px solid var(--border); box-shadow: var(--shadow);
  backdrop-filter: blur(16px); transition: border-color .15s, box-shadow .15s;
}
.composer-box:focus-within { border-color: var(--accent-line); box-shadow: var(--shadow), 0 0 0 3px var(--accent-soft); }
.composer textarea {
  flex: 1; min-height: 26px; max-height: 38vh; resize: none; border: 0; outline: 0; background: transparent; color: var(--text);
  font: inherit; font-size: var(--fs); line-height: 1.7; padding: 6px 8px;
}
.composer textarea::placeholder { color: var(--faint); }
.send-btn { width: 42px; height: 42px; flex: none; border: 0; border-radius: 14px; display: grid; place-items: center; color: #fff; background: linear-gradient(135deg, var(--accent), var(--accent-2)); box-shadow: 0 8px 22px color-mix(in srgb, var(--accent) 30%, transparent); }
.send-btn:disabled { opacity: .45; box-shadow: none; }
.send-btn svg { width: 19px; height: 19px; transform: scaleX(-1); }
.composer-hint { width: min(var(--chat-w), 100%); margin: 6px auto 0; display: flex; justify-content: space-between; gap: 10px; font-size: .72em; color: var(--faint); padding: 0 8px; }

/* ---------- appearance dialog ---------- */
.look { border: 1px solid var(--border); border-radius: 22px; padding: 0; background: var(--panel-solid); color: var(--text); box-shadow: var(--shadow); width: min(520px, calc(100% - 32px)); max-height: calc(100dvh - 40px); }
.look::backdrop { background: rgba(3, 6, 14, .55); backdrop-filter: blur(4px); }
.look-inner { display: grid; gap: 16px; padding: 22px; }
.look-head { display: grid; gap: 2px; }
.look-head small { color: var(--muted); font-size: .8em; }
.look-grid { display: grid; gap: 14px; }
.look-row { display: grid; gap: 7px; }
.look-row > span { font-size: .84em; color: var(--muted); }
.look-row .seg { flex-wrap: wrap; }
.look-row input[type="range"] { width: 100%; accent-color: var(--accent); }
.range-line { display: flex; align-items: center; gap: 12px; }
.range-line output { min-width: 42px; text-align: center; font-family: var(--code-font); font-size: .86em; color: var(--muted); }
.swatches { display: flex; gap: 10px; }
.swatch { width: 30px; height: 30px; border-radius: 50%; border: 2px solid transparent; }
.swatch.on { border-color: var(--text); }
.look-foot { display: flex; justify-content: space-between; gap: 10px; }

.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 50; padding: 10px 18px; border-radius: 12px; background: var(--panel-solid); border: 1px solid var(--border); box-shadow: var(--shadow); font-size: .88em; max-width: calc(100% - 32px); }
.toast.err { border-color: color-mix(in srgb, var(--danger) 45%, transparent); color: var(--danger); }

.scrim { position: fixed; inset: 0; background: rgba(3, 6, 14, .5); z-index: 20; }
.only-mobile { display: none; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes glow { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }
@keyframes blink { 0%, 100% { opacity: .9; } 50% { opacity: .25; } }

@media (max-width: 900px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; inset-block: 0; inset-inline-start: 0; width: min(330px, 88vw); z-index: 30; transform: translateX(105%); transition: transform .22s ease; box-shadow: var(--shadow); background: var(--panel-solid); }
  .sidebar.open { transform: translateX(0); }
  .only-mobile { display: inline-grid; }
  .topbar { padding: 10px 16px; min-height: 58px; gap: 10px; }
  .chat-inner { padding: 18px 16px 14px; }
  .term-view { padding: 10px 16px 8px; }
  .turn { grid-template-columns: minmax(0, 1fr); }
  .turn-avatar { display: none; }
  .bubble { max-width: 94%; }
  .seg button { padding: 6px 10px; }
  .btn-ghost.danger span:last-child { display: none; }
  .composer { padding-inline: 12px; }
  .composer-hint #hintKeys { display: none; }
}
.hide-thinking .thinking { display: none; }

/* all-English answers sit next to the avatar instead of the far edge */
.md.ltr-only { justify-self: start; direction: ltr; text-align: left; max-width: 100%; }
.power-sub { display: flex; justify-content: center; margin-top: -6px; }
.power-sub button { border: 0; background: none; color: var(--faint); font-size: .76em; padding: 2px 6px; text-decoration: underline dotted; }
.power-sub button:hover { color: var(--danger); }

/* ======================= v3 — Codex/Claude Web-grade visuals ======================= */
/* Composer with attachments */
.composer-box { display: grid; gap: 8px; align-items: stretch; }
.composer-row { display: flex; align-items: flex-end; gap: 8px; }
.attach-btn { width: 40px; height: 40px; flex: none; border: 0; border-radius: 12px; display: grid; place-items: center; background: transparent; color: var(--muted); }
.attach-btn:hover { background: var(--soft-2); color: var(--text); }
.attach-btn svg { width: 20px; height: 20px; }
.attach-tray { display: flex; flex-wrap: wrap; gap: 8px; padding: 2px 4px 0; }
.attach-chip { position: relative; width: 64px; height: 64px; border-radius: 12px; overflow: hidden; border: 1px solid var(--border); background: var(--soft); }
.attach-chip img { width: 100%; height: 100%; object-fit: cover; display: block; }
.attach-chip.loading { opacity: .55; }
.attach-chip button { position: absolute; top: 3px; inset-inline-end: 3px; width: 20px; height: 20px; border-radius: 50%; border: 0; background: rgba(0,0,0,.65); color: #fff; font-size: 12px; line-height: 20px; padding: 0; }
.drop-hint { position: absolute; inset: 12px; z-index: 40; display: grid; place-items: center; border: 2px dashed var(--accent); border-radius: 20px; background: color-mix(in srgb, var(--bg) 80%, transparent); color: var(--accent-2); font-size: 1.1em; pointer-events: none; }

/* Images in the conversation */
.img-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.img-grid img, .md img.inline-img { max-width: min(320px, 100%); max-height: 260px; border-radius: 12px; border: 1px solid var(--border); cursor: zoom-in; object-fit: cover; background: var(--soft); display: block; }
.msg-user .img-grid { justify-content: flex-start; max-width: min(88%, 720px); }
.path-previews { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.path-previews figure { margin: 0; display: grid; gap: 4px; }
.path-previews figcaption { font-size: .7em; color: var(--faint); direction: ltr; text-align: left; font-family: var(--code-font); max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lightbox { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; background: rgba(3, 6, 14, .88); backdrop-filter: blur(6px); cursor: zoom-out; padding: 16px; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 14px; box-shadow: var(--shadow); }

/* Markdown — typography closer to Codex Web */
.md { font-size: 1em; }
.md p { margin: 0 0 .85em; }
.md strong { color: color-mix(in srgb, var(--text) 100%, var(--accent-2) 0%); font-weight: 700; }
:root[data-theme="dark"] .md strong { color: #ffffff; }
.md em { color: color-mix(in srgb, var(--text) 80%, var(--accent-2)); }
.md mark { background: color-mix(in srgb, var(--warn) 30%, transparent); color: inherit; padding: .05em .3em; border-radius: 5px; }
.md code { color: color-mix(in srgb, var(--accent-2) 75%, var(--text)); background: color-mix(in srgb, var(--accent) 12%, transparent); border: 1px solid color-mix(in srgb, var(--accent) 18%, transparent); }
.md h1, .md h2, .md h3 { letter-spacing: -.005em; }
.md h2 { padding-bottom: .3em; border-bottom: 1px solid var(--border); }
.md ul { list-style: none; padding-inline-start: 1.3em; }
.md ul > li { position: relative; }
.md ul > li::before { content: ""; position: absolute; inset-inline-start: -1em; top: .78em; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); opacity: .8; }
.md ul ul > li::before { background: transparent; border: 1.5px solid var(--accent); width: 5px; height: 5px; }
.md ol { padding-inline-start: 1.6em; }
.md ol > li::marker { color: var(--accent-2); font-weight: 700; }
.md li.task::before { display: none; }
.md li.task { list-style: none; margin-inline-start: -1.3em; display: flex; gap: 8px; align-items: baseline; }
.md li.task .box { width: 15px; height: 15px; flex: none; border-radius: 5px; border: 1.5px solid var(--faint); transform: translateY(2px); }
.md li.task.done .box { background: var(--success); border-color: var(--success); }
.md li.task.done > span:last-child { color: var(--faint); text-decoration: line-through; }
.md blockquote { background: var(--soft); border-radius: 0 12px 12px 0; padding: 8px 14px; color: var(--text); }
.md blockquote > :last-child { margin-bottom: 0; }

/* Tables — same frame as Claude Web: sticky header, zebra rows, sideways scroll */
.md .table-wrap { margin: 14px 0 18px; overflow-x: auto; border: 1px solid var(--border); border-radius: 14px; background: rgba(255,255,255,.02); -webkit-overflow-scrolling: touch; }
.md table.md-table { width: 100%; border-collapse: collapse; font-size: .93em; line-height: 1.7; }
.md table.md-table.is-wide { width: max-content; min-width: 100%; }
.md table.md-table.is-wide th, .md table.md-table.is-wide td { min-width: 130px; }
.md table.md-table th, .md table.md-table td { padding: 9px 13px; text-align: start; border-bottom: 1px solid var(--border); border-inline-end: 1px solid color-mix(in srgb, var(--border) 60%, transparent); vertical-align: top; max-width: 340px; overflow-wrap: break-word; }
.md table.md-table th:last-child, .md table.md-table td:last-child { border-inline-end: 0; }
.md table.md-table tbody tr:last-child td { border-bottom: 0; }
.md table.md-table thead th { position: sticky; top: 0; font-weight: 700; background: color-mix(in srgb, var(--accent) 16%, var(--panel-solid)); color: var(--text); white-space: nowrap; }
.md table.md-table tbody tr:nth-child(even) { background: rgba(255,255,255,.022); }
:root[data-theme="light"] .md table.md-table tbody tr:nth-child(even) { background: rgba(15,23,42,.025); }
.md table.md-table tbody tr:hover { background: var(--accent-soft); }
.md table.md-table code { white-space: normal; overflow-wrap: anywhere; }
@media (max-width: 640px) {
  .md .table-wrap { overflow: visible; border: 0; background: transparent; }
  .md table.md-table, .md table.md-table tbody, .md table.md-table tr, .md table.md-table td { display: block; width: 100%; max-width: none; min-width: 0 !important; }
  .md table.md-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .md table.md-table tr { margin-bottom: 10px; border: 1px solid var(--border); border-radius: 14px; overflow: hidden; background: var(--soft); }
  .md table.md-table td { border: 0; border-bottom: 1px solid var(--border); display: grid; grid-template-columns: minmax(80px, 34%) 1fr; gap: 10px; }
  .md table.md-table td:last-child { border-bottom: 0; }
  .md table.md-table td::before { content: attr(data-label); color: var(--muted); font-size: .85em; font-weight: 600; }
}

/* Code blocks + syntax colours (highlight.js classes) */
.codeblock { border-radius: 14px; }
.codeblock pre { font-size: .82em; line-height: 1.7; }
.code-head { background: rgba(255,255,255,.025); }
.code-head span { text-transform: lowercase; }
.hljs-keyword, .hljs-selector-tag, .hljs-built_in, .hljs-literal { color: #c792ea; }
.hljs-string, .hljs-attr-value, .hljs-template-tag, .hljs-regexp { color: #9ee6a8; }
.hljs-number, .hljs-symbol, .hljs-bullet { color: #f7b267; }
.hljs-comment, .hljs-quote { color: #6b7591; font-style: italic; }
.hljs-title, .hljs-title.function_, .hljs-section { color: #82aaff; }
.hljs-attr, .hljs-attribute, .hljs-property, .hljs-variable, .hljs-params { color: #f2c572; }
.hljs-type, .hljs-class .hljs-title, .hljs-title.class_ { color: #ffcb6b; }
.hljs-meta, .hljs-meta .hljs-keyword { color: #89ddff; }
.hljs-deletion { color: #ff8fa3; background: rgba(255,120,144,.08); }
.hljs-addition { color: #7ef0c4; background: rgba(72,215,168,.08); }
.hljs-tag, .hljs-name { color: #f07178; }
:root[data-theme="light"] .hljs-keyword, :root[data-theme="light"] .hljs-built_in, :root[data-theme="light"] .hljs-literal { color: #7c3aed; }
:root[data-theme="light"] .hljs-string, :root[data-theme="light"] .hljs-regexp { color: #15803d; }
:root[data-theme="light"] .hljs-number { color: #c2410c; }
:root[data-theme="light"] .hljs-comment { color: #8a93a8; }
:root[data-theme="light"] .hljs-title, :root[data-theme="light"] .hljs-title.function_ { color: #1d4ed8; }
:root[data-theme="light"] .hljs-attr, :root[data-theme="light"] .hljs-variable, :root[data-theme="light"] .hljs-property { color: #a16207; }

/* Diff inside Edit cards */
.diff { margin: 0; padding: 8px 0; border-radius: 10px; background: var(--code-bg); border: 1px solid var(--border); font-family: var(--code-font); font-size: .78em; line-height: 1.6; max-height: 380px; overflow: auto; direction: ltr; text-align: left; }
.diff div { padding: 0 12px; white-space: pre-wrap; word-break: break-word; }
.diff .del { background: rgba(255,120,144,.1); color: #ffb3c1; }
.diff .add { background: rgba(72,215,168,.1); color: #a8f0d4; }
:root[data-theme="light"] .diff .del { color: #9f1239; }
:root[data-theme="light"] .diff .add { color: #166534; }

/* Assistant message actions */
.md-wrap { position: relative; }
.msg-actions { display: flex; gap: 6px; opacity: 0; transition: opacity .15s; margin-top: 2px; }
.turn:hover .msg-actions, .msg-actions:focus-within { opacity: 1; }
.msg-actions button { border: 1px solid var(--border); background: var(--soft); color: var(--muted); border-radius: 8px; font-size: .72em; padding: 2px 9px; }
.msg-actions button:hover { color: var(--text); }
@media (hover: none) { .msg-actions { opacity: .7; } }

/* Usage in topbar and sidebar */
.usage-chip { font-size: .72em; color: var(--muted); background: var(--soft); border: 1px solid var(--border); border-radius: 999px; padding: 2px 10px; white-space: nowrap; }
.usage-chip.limited { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.session-row { display: flex; align-items: center; gap: 4px; }
.session-row .session { flex: 1; min-width: 0; }
.s-power { width: 30px; height: 30px; flex: none; border-radius: 9px; border: 1px solid transparent; background: transparent; color: var(--faint); display: grid; place-items: center; }
.s-power:hover { background: var(--soft-2); color: var(--text); }
.s-power[data-on="1"] { color: var(--success); }
.s-power svg { width: 15px; height: 15px; }
.s-meta { font-size: .7em; color: var(--faint); display: flex; gap: 8px; flex-wrap: wrap; }
.s-owner { color: var(--accent-2); font-family: var(--code-font); }
.bar { height: 3px; border-radius: 3px; background: var(--soft-2); overflow: hidden; margin-top: 3px; }
.bar > i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); }
.bar.full > i { background: var(--danger); }
.role-badge { font-size: .72em; padding: 1px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-2); font-family: var(--ui-font); }

/* Admin dialog */
.admin { border: 1px solid var(--border); border-radius: 22px; padding: 0; background: var(--panel-solid); color: var(--text); box-shadow: var(--shadow); width: min(980px, calc(100% - 32px)); max-height: calc(100dvh - 32px); }
.admin::backdrop { background: rgba(3, 6, 14, .6); backdrop-filter: blur(4px); }
.admin-inner { display: grid; gap: 14px; padding: 20px; max-height: calc(100dvh - 34px); overflow: auto; }
.admin-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.admin-head strong { display: block; font-size: 1.1em; }
.admin-head small { color: var(--muted); font-size: .8em; }
.admin-tabs { justify-self: start; }
.admin-body { display: grid; gap: 16px; }
.card { border: 1px solid var(--border); border-radius: 16px; background: var(--soft); padding: 14px; display: grid; gap: 12px; }
.card h3 { margin: 0; font-size: .95em; }
.card p.hint { margin: 0; color: var(--muted); font-size: .8em; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; align-items: end; }
.form-grid label { display: grid; gap: 5px; font-size: .8em; color: var(--muted); }
.form-grid .wide { grid-column: 1 / -1; }
.inp { width: 100%; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--panel-solid); color: var(--text); font: inherit; font-size: 14px; }
.inp:focus { outline: none; border-color: var(--accent-line); box-shadow: 0 0 0 3px var(--accent-soft); }
.inp.ltr { direction: ltr; text-align: left; }
textarea.inp { resize: vertical; min-height: 64px; }
.tbl-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 14px; }
.tbl { width: 100%; border-collapse: collapse; font-size: .85em; }
.tbl th, .tbl td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: start; vertical-align: middle; white-space: nowrap; }
.tbl th { background: var(--soft-2); font-weight: 600; color: var(--muted); }
.tbl tr:last-child td { border-bottom: 0; }
.tbl .mono { font-family: var(--code-font); direction: ltr; }
.tbl .inp { padding: 5px 8px; font-size: 13px; width: 110px; }
.tbl select.inp { width: auto; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.btn-sm { border: 1px solid var(--border); background: var(--panel-solid); border-radius: 9px; padding: 4px 10px; font-size: .78em; }
.btn-sm:hover { background: var(--soft-2); }
.btn-sm.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, transparent); }
.btn-sm.primary { color: #fff; border-color: transparent; background: linear-gradient(135deg, var(--accent), var(--accent-2)); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; font-size: .85em; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-family: var(--code-font); direction: ltr; text-align: left; }
