/* Bayan — Warm Sand visual system.
   Palette, radii, measures and rhythm are a byte-for-byte port of AI Zone's
   design tokens (ai-zone/lib/app/theme/zone_tokens.dart) so Bayan reads as
   the same craft — with its own brand and no shared identity. */

:root {
  --canvas: #F8F1E7;
  --surface: #FFFBF4;
  --elevated: #FFFFFF;
  --sidebar-active-tint: #F6E1D2;
  --border-subtle: #F0E6D6;
  --border: #ECE0CF;
  --ink: #2C2620;
  --ink-2: #6B5E4F;
  --brand: #C96F4C;
  --brand-subtle: #F7E6DB;
  --danger: #B23A28;
  --hover-8: rgba(44, 38, 32, 0.08);
  --active-16: rgba(44, 38, 32, 0.16);
  --raise: 0 12px 32px rgba(0,0,0,.16), 0 2px 8px rgba(0,0,0,.08);
  --raise-soft: 0 6px 16px rgba(0,0,0,.10);
  --ok: #4C8A5C;
  --warn: #B98A3A;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --canvas: #0B0D11;
    --surface: #13161B;
    --elevated: #181C23;
    --sidebar-active-tint: #13161B;
    --border-subtle: #1C2028;
    --border: #262A33;
    --ink: #ECEEF2;
    --ink-2: #9A8A76;
    --brand: #D6835F;
    --brand-subtle: rgba(214, 131, 95, 0.12);
    --danger: #B23A28;
    --hover-8: rgba(236, 238, 242, 0.08);
    --active-16: rgba(236, 238, 242, 0.16);
    --ok: #6CA97C;
    --warn: #C99C4E;
  }
}
:root[data-theme="dark"] {
  --canvas: #0B0D11;
  --surface: #13161B;
  --elevated: #181C23;
  --sidebar-active-tint: #13161B;
  --border-subtle: #1C2028;
  --border: #262A33;
  --ink: #ECEEF2;
  --ink-2: #9A8A76;
  --brand: #D6835F;
  --brand-subtle: rgba(214, 131, 95, 0.12);
  --danger: #B23A28;
  --hover-8: rgba(236, 238, 242, 0.08);
  --active-16: rgba(236, 238, 242, 0.16);
  --ok: #6CA97C;
  --warn: #C99C4E;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  font: 400 15.5px/1.6 "Libre Franklin", "IBM Plex Sans Arabic", -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; padding: 0; }
input, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid color-mix(in srgb, var(--brand) 50%, transparent); outline-offset: 2px; border-radius: 8px; }
svg { width: 18px; height: 18px; flex: none; }

.app { display: flex; height: 100dvh; overflow: hidden; }

/* ── Sidebar — same canvas as the page, separation via row fills only ── */
.sidebar {
  width: 264px; flex: none;
  display: flex; flex-direction: column;
  background: var(--canvas);
  padding: 12px;
  gap: 12px;
  transition: width .18s cubic-bezier(.215,.61,.355,1), transform .18s cubic-bezier(.215,.61,.355,1);
  overflow: hidden;
}
.side-head { display: flex; align-items: center; gap: 8px; min-height: 40px; }
.brand { display: flex; align-items: center; gap: 8px; padding: 4px 8px; border-radius: 12px; cursor: pointer; min-width: 0; }
.brand:hover { background: var(--hover-8); }
.brand-mark { color: var(--brand); font-size: 19px; line-height: 1; }
.brand-name { font-weight: 700; font-size: 17px; letter-spacing: .01em; white-space: nowrap; }
.brand-ar { font-family: "IBM Plex Sans Arabic", sans-serif; font-weight: 500; color: var(--ink-2); font-size: 15px; margin-inline-start: 2px; }
.collapse-btn { margin-inline-start: auto; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 10px; color: var(--ink-2);
}
.icon-btn:hover { background: var(--hover-8); color: var(--ink); }

.side-actions { display: flex; flex-direction: column; gap: 8px; }
.btn-primary {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; border-radius: 10px;
  background: var(--brand); color: #fff; font-weight: 600;
}
.btn-primary:hover { filter: brightness(1.06); }
.search-wrap { position: relative; }
.search-wrap svg { position: absolute; inset-inline-start: 12px; top: 50%; translate: 0 -50%; width: 16px; height: 16px; color: var(--ink-2); pointer-events: none; }
.search-wrap input {
  width: 100%; padding: 10px 12px;
  padding-inline-start: 36px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); color: var(--ink);
}
.search-wrap input::placeholder { color: var(--ink-2); }

/* Nav + recents scroll as ONE column, so recents can never be flex-squeezed
   to zero height on short viewports (the "where did my chats go" bug). */
.side-scroll { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
.side-nav { display: flex; flex-direction: column; gap: 2px; flex: none; }
.side-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 10px;
  color: var(--ink); text-align: start; width: 100%; min-height: 38px;
}
.side-item svg { color: var(--ink-2); }
.side-item:hover { background: var(--hover-8); }
.side-item.active { background: var(--active-16); font-weight: 600; }
.side-item .label { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pill {
  font-size: 10.5px; font-weight: 600; letter-spacing: .04em;
  padding: 2px 8px; border-radius: 999px; white-space: nowrap;
}
.pill-beta { background: var(--brand-subtle); color: var(--brand); }

.side-heading {
  margin: 10px 10px 4px; font-size: 11px; font-weight: 600;
  letter-spacing: .08em; text-transform: uppercase; color: var(--ink-2);
}
.recents { flex: none; display: flex; flex-direction: column; }
.recents-list { list-style: none; margin: 0; padding: 0 0 8px; }
.recent-row {
  display: flex; align-items: center; gap: 4px;
  border-radius: 10px; padding: 7px 6px 7px 10px; cursor: pointer;
  color: var(--ink);
}
.recent-row:hover { background: var(--hover-8); }
.recent-row.active { background: var(--active-16); }
.recent-title { flex: 1; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.recent-menu-btn { opacity: 0; width: 28px; height: 28px; border-radius: 8px; display: inline-flex; align-items: center; justify-content: center; color: var(--ink-2); }
.recent-row:hover .recent-menu-btn, .recent-row.active .recent-menu-btn { opacity: 1; }
.recent-menu-btn:hover { background: var(--hover-8); color: var(--ink); }
.recents-empty { color: var(--ink-2); font-size: 13.5px; padding: 6px 10px; }

.side-foot { display: flex; flex-direction: column; gap: 2px; border-top: 1px solid var(--border-subtle); padding-top: 10px; }
.status-chip {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; border-radius: 10px; color: var(--ink-2);
  font-size: 13px; text-align: start;
}
.status-chip:hover { background: var(--hover-8); }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--ink-2); }
.dot.ready { background: var(--ok); }
.dot.loading { background: var(--warn); animation: pulse 1.2s ease-in-out infinite; }
.dot.off { background: var(--ink-2); }
@keyframes pulse { 50% { opacity: .35; } }

/* ── Private-beta lock screen ── */
.lock {
  position: fixed; inset: 0; z-index: 100;
  background: var(--canvas); color: var(--ink);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.lock[hidden] { display: none; }
.lock-card {
  width: 100%; max-width: 380px; text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 14px;
}
.lock-card h1 { margin: 6px 0 0; font-size: 24px; letter-spacing: -0.01em; }
.lock-card .sub { margin: 0; color: var(--ink-2); font-size: 14.5px; }
.lock-card form { width: 100%; display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }
.lock-card input {
  width: 100%; padding: 13px 14px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); color: var(--ink);
  text-align: center;
}
.lock-card input::placeholder { color: var(--ink-2); }
.lock-error { color: var(--danger); font-size: 13.5px; margin: 0; }
.app[hidden] { display: none; }

/* collapsed rail (desktop) */
.sidebar.collapsed { width: 68px; padding: 12px 10px; }
.sidebar.collapsed .label, .sidebar.collapsed .brand-name, .sidebar.collapsed .brand-ar,
.sidebar.collapsed .search-wrap, .sidebar.collapsed .recents, .sidebar.collapsed .pill,
.sidebar.collapsed .side-heading, .sidebar.collapsed .status-chip .label { display: none; }
.sidebar.collapsed .side-item, .sidebar.collapsed .btn-primary, .sidebar.collapsed .status-chip { justify-content: center; padding: 8px; }
.sidebar.collapsed .side-head { justify-content: center; }
.sidebar.collapsed .brand { display: none; }
.sidebar.collapsed .collapse-btn { margin: 0; rotate: 180deg; }

/* ── Main pane ── */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--canvas); }
.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; min-height: 56px;
}
.topbar-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.spacer { flex: 1; }
.hamburger { display: none; }

.model-pick-wrap { position: relative; }
.model-pick {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 12px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface);
  font-weight: 500; font-size: 13.5px;
}
.model-pick:hover { background: var(--hover-8); }
.model-pick svg { width: 14px; height: 14px; color: var(--ink-2); }
.menu {
  position: absolute; top: calc(100% + 6px); inset-inline-end: 0; z-index: 40;
  min-width: 300px; padding: 6px;
  background: var(--elevated); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--raise-soft);
  display: none; flex-direction: column; gap: 2px;
}
.menu.open { display: flex; }
.menu-item {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 9px 10px; border-radius: 9px; text-align: start; width: 100%;
}
.menu-item:hover:not(:disabled) { background: var(--hover-8); }
.menu-item:disabled { cursor: not-allowed; opacity: .82; }
.menu-item .dot { margin-top: 6px; }
.menu-item .m-name { font-weight: 600; font-size: 14px; }
.menu-item .m-sub { font-size: 12.5px; color: var(--ink-2); line-height: 1.45; }
.menu-item .check { margin-inline-start: auto; color: var(--brand); visibility: hidden; }
.menu-item.selected .check { visibility: visible; }

/* ── Chat view ── */
.view { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.chat-scroll { flex: 1; overflow-y: auto; }
.chat-col { max-width: 768px; margin: 0 auto; padding: 24px 16px 8px; }

.turn { margin-top: 40px; }
.turn:first-child { margin-top: 8px; }
.turn-user { display: flex; justify-content: flex-end; }
.user-stack { display: flex; flex-direction: column; align-items: flex-end; max-width: 566px; }
.bubble-user {
  padding: 10px 16px;
  background: var(--sidebar-active-tint); border: 1px solid var(--border-subtle);
  border-radius: 12px; overflow-wrap: break-word;
}
:root[data-theme="dark"] .bubble-user { border-color: var(--border); }
.bot-head { display: flex; align-items: center; gap: 7px; margin-bottom: 6px; color: var(--ink-2); font-size: 12.5px; font-weight: 600; }
.bot-head .brand-mark { font-size: 14px; }
.bot-body { overflow-wrap: break-word; }
.bot-body .caret { display: inline-block; width: 3px; height: 1.05em; vertical-align: text-bottom; background: var(--brand); animation: pulse .9s ease-in-out infinite; border-radius: 2px; margin-inline-start: 2px; }
.bot-meta { margin-top: 8px; font-size: 12px; color: var(--ink-2); }
.turn-error .bot-body { color: var(--danger); }
.thinking { color: var(--ink-2); font-style: italic; }

/* empty state */
.home { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px 16px; overflow-y: auto; }
.home-inner { width: 100%; max-width: 672px; display: flex; flex-direction: column; align-items: center; gap: 20px; }
.home-ar { font-family: "IBM Plex Sans Arabic", sans-serif; font-size: 44px; color: var(--brand); font-weight: 600; line-height: 1; }
.home h1 { margin: 0; font-size: 27px; font-weight: 700; text-align: center; letter-spacing: -0.01em; }
.home p.sub { margin: -8px 0 0; color: var(--ink-2); text-align: center; max-width: 480px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.chip {
  padding: 8px 14px; border-radius: 999px; font-size: 13.5px;
  background: var(--surface); border: 1px solid var(--border); color: var(--ink-2);
}
.chip:hover { background: var(--hover-8); color: var(--ink); }

/* composer */
.composer-zone { padding: 8px 16px calc(14px + env(safe-area-inset-bottom)); }
.composer-zone.docked { max-width: 768px; margin: 0 auto; width: 100%; }
.composer {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 20px; box-shadow: var(--raise);
  padding: 12px 12px 8px; width: 100%;
}
.composer textarea {
  display: block; width: 100%; resize: none; border: none; outline: none;
  background: transparent; max-height: 200px; min-height: 24px;
  padding: 2px 6px 10px; line-height: 1.5;
}
.composer textarea::placeholder { color: var(--ink-2); }
.composer-row { display: flex; align-items: center; gap: 4px; }
.composer-row .spacer { flex: 1; }
.send-btn {
  width: 36px; height: 36px; border-radius: 12px;
  background: var(--brand); color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
}
.send-btn:disabled { opacity: .4; cursor: default; }
.send-btn.stop { background: var(--ink); }
.composer-note { text-align: center; font-size: 11.5px; color: var(--ink-2); margin-top: 8px; }

/* ── Feature (beta) view ── */
.feature-view { flex: 1; display: flex; align-items: center; justify-content: center; padding: 24px 16px; overflow-y: auto; }
.feature-card { max-width: 420px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 14px; }
.feature-icon {
  width: 64px; height: 64px; border-radius: 20px;
  background: var(--brand-subtle); color: var(--brand);
  display: flex; align-items: center; justify-content: center;
}
.feature-icon svg { width: 30px; height: 30px; }
.feature-card h2 { margin: 0; font-size: 22px; display: flex; align-items: center; gap: 10px; }
.feature-card p { margin: 0; color: var(--ink-2); }
.feature-note { font-size: 12.5px; border-top: 1px solid var(--border-subtle); padding-top: 12px; }

/* ── Modals, toast, scrim ── */
.modal-scrim {
  position: fixed; inset: 0; z-index: 60; display: none;
  align-items: center; justify-content: center;
  background: rgba(0,0,0,.4); padding: 20px;
}
.modal-scrim.open { display: flex; }
.modal {
  width: 100%; max-width: 560px; max-height: min(84dvh, 720px);
  background: var(--elevated); border-radius: 24px; box-shadow: var(--raise);
  display: flex; flex-direction: column; overflow: hidden;
}
.modal-head { display: flex; align-items: center; gap: 10px; padding: 18px 20px 8px; }
.modal-head h2 { margin: 0; font-size: 19px; flex: 1; }
.modal-body { padding: 4px 20px 22px; overflow-y: auto; }
.modal-body h3 { font-size: 14px; margin: 18px 0 8px; }
.modal-body p { margin: 8px 0; font-size: 14.5px; }
.muted { color: var(--ink-2); font-size: 13px; }
.score-table { width: 100%; border-collapse: collapse; margin: 6px 0; }
.score-table th, .score-table td { border: 1px solid var(--border); padding: 7px 6px; text-align: center; font-size: 13px; }
.score-table th { color: var(--ink-2); font-weight: 600; background: var(--surface); }
.score-table td { font-weight: 700; font-size: 15px; }
.family-list { list-style: none; margin: 6px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.family-list li { display: flex; gap: 10px; align-items: baseline; font-size: 14px; }
.family-list .dot { translate: 0 -1px; }
.family-list .muted { font-size: 12.5px; }

.seg { display: inline-flex; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button { padding: 7px 14px; border-radius: 8px; font-size: 13.5px; color: var(--ink-2); }
.seg button.on { background: var(--brand); color: #fff; font-weight: 600; }
input[type="range"] { width: 100%; accent-color: var(--brand); }

.toast {
  position: fixed; bottom: 24px; left: 50%; translate: -50% 0; z-index: 80;
  background: var(--ink); color: var(--canvas);
  padding: 10px 18px; border-radius: 12px; box-shadow: var(--raise-soft);
  font-size: 14px; max-width: min(90vw, 480px); text-align: center;
  opacity: 0; pointer-events: none; transition: opacity .18s, translate .18s;
}
.toast.show { opacity: 1; translate: -50% -6px; }

.scrim { position: fixed; inset: 0; z-index: 45; background: rgba(0,0,0,.4); display: none; }

/* ── Responsive: phone drawer below 640 (640–767 is the icon rail) ── */
@media (max-width: 639.98px) {
  .sidebar {
    position: fixed; inset-block: 0; inset-inline-start: 0; z-index: 50;
    width: 280px; translate: -100% 0; box-shadow: none;
  }
  [dir="rtl"] .sidebar { translate: 100% 0; }
  [dir="rtl"] .sidebar.open { translate: 0 0; }
  .sidebar.open { translate: 0 0; box-shadow: var(--raise); }
  .sidebar.collapsed { width: 280px; padding: 12px; }
  .sidebar.collapsed .label, .sidebar.collapsed .brand-name, .sidebar.collapsed .brand-ar,
  .sidebar.collapsed .search-wrap, .sidebar.collapsed .recents, .sidebar.collapsed .pill,
  .sidebar.collapsed .side-heading, .sidebar.collapsed .status-chip .label { display: revert; }
  .sidebar.collapsed .recents { display: flex; }
  .sidebar.collapsed .brand { display: flex; }
  .sidebar.collapsed .side-item, .sidebar.collapsed .btn-primary, .sidebar.collapsed .status-chip { justify-content: flex-start; padding: 8px 10px; }
  .sidebar.collapsed .btn-primary { justify-content: center; }
  .collapse-btn { display: none; }
  .hamburger { display: inline-flex; }
  .scrim.show { display: block; }
  .bubble-user { max-width: 85%; }
  .pill-beta { display: none; }
  .recent-menu-btn { opacity: 1; }
}

/* ═══ Feature-parity components (message actions, branching, markdown,
   code blocks, dialogs, menus, slash menu, modes, queue, welcome) ═══ */

/* ── markdown body ── */
.md-body { line-height: 1.6; }
.md-body p { margin: 0 0 10px; }
.md-body p:last-child { margin-bottom: 0; }
.md-body h1, .md-body h2, .md-body h3, .md-body h4, .md-body h5, .md-body h6 {
  margin: 16px 0 8px; line-height: 1.3; font-weight: 700;
}
.md-body h1 { font-size: 1.45em; } .md-body h2 { font-size: 1.28em; }
.md-body h3 { font-size: 1.14em; } .md-body h4, .md-body h5, .md-body h6 { font-size: 1em; }
.md-body > :first-child { margin-top: 0; }
.md-body ul, .md-body ol { margin: 0 0 10px; padding-inline-start: 24px; }
.md-body li { margin: 3px 0; }
.md-body blockquote {
  margin: 0 0 10px; padding: 4px 14px;
  border-inline-start: 3px solid var(--brand);
  color: var(--ink-2); background: var(--hover-8); border-radius: 6px;
}
.md-body hr { border: none; border-top: 1px solid var(--border-subtle); margin: 12px 0; }
.md-body a { color: var(--brand); text-decoration: underline; text-underline-offset: 2px; }
.md-body code {
  font-family: "SF Mono", ui-monospace, "Cascadia Mono", Menlo, monospace;
  font-size: .88em; background: var(--hover-8);
  padding: 1px 5px; border-radius: 5px;
}
.md-table-wrap { overflow-x: auto; margin: 0 0 10px; max-width: 100%; }
.md-body table { border-collapse: collapse; font-size: .94em; }
.md-body th, .md-body td { border: 1px solid var(--border); padding: 6px 10px; text-align: start; }
.md-body th { background: var(--surface); font-weight: 600; }

/* code blocks */
.codeblock {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; margin: 0 0 10px; overflow: hidden;
}
.code-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 5px 10px 5px 12px; border-bottom: 1px solid var(--border-subtle);
  font-size: 11.5px; color: var(--ink-2);
}
.code-lang { font-family: ui-monospace, monospace; letter-spacing: .04em; }
.code-copy {
  font-size: 11.5px; font-weight: 600; color: var(--ink-2);
  padding: 3px 10px; border-radius: 6px;
}
.code-copy:hover { background: var(--hover-8); color: var(--ink); }
.codeblock pre {
  margin: 0; padding: 12px 14px; overflow-x: auto;
}
.codeblock pre code {
  background: none; padding: 0; font-size: 13px; line-height: 1.55;
}

/* click-to-load external images */
.md-img {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 12px; border-radius: 10px; font-size: 13px;
  background: var(--surface); border: 1px dashed var(--border); color: var(--ink-2);
  margin: 2px 0 10px;
}
.md-img:hover { background: var(--hover-8); color: var(--ink); }
.md-loaded-img { max-width: 100%; max-height: 320px; border-radius: 12px; margin: 2px 0 10px; display: block; }

/* ── message action row (hover-revealed; resident on touch) ── */
.msg-actions {
  display: flex; align-items: center; gap: 6px;
  margin-top: 6px; min-height: 28px;
  opacity: 0; transition: opacity .12s cubic-bezier(.215,.61,.355,1);
}
.turn:hover .msg-actions, .turn:focus-within .msg-actions { opacity: 1; }
@media (hover: none) { .msg-actions { opacity: 1; } }
.ma {
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; border-radius: 7px; color: var(--ink-2);
}
.ma svg { width: 15px; height: 15px; }
.ma:hover { background: var(--hover-8); color: var(--ink); }
.msg-time { font-size: 11.5px; color: var(--ink-2); margin-inline-start: 14px; }
.turn-user .msg-actions { justify-content: flex-end; }

/* branch switcher ‹ 1/2 › */
.branch { display: inline-flex; align-items: center; gap: 2px; margin-inline-start: 6px; }
.branch-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; border-radius: 6px; color: var(--ink-2);
}
.branch-btn svg { width: 14px; height: 14px; }
.branch-btn:hover:not(:disabled) { background: var(--hover-8); color: var(--ink); }
.branch-btn:disabled { color: var(--border); cursor: default; }
.branch-n { font-size: 11.5px; color: var(--ink-2); min-width: 26px; text-align: center; }
[dir="rtl"] .chev-start svg, [dir="rtl"] .chev-end svg, [dir="rtl"] .chev-flip svg { transform: scaleX(-1); }
[dir="rtl"] .collapse-btn svg { transform: scaleX(-1); }
[dir="rtl"] .sidebar.collapsed .collapse-btn svg { transform: none; }

/* inline edit box (edit → save & submit creates a branch) */
.edit-box {
  width: 100%; max-width: 566px; margin-inline-start: auto;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 10px 12px;
}
[dir] .turn-user .edit-box { margin-inline-start: auto; }
.edit-box textarea {
  width: 100%; border: none; outline: none; background: transparent;
  resize: none; min-height: 40px; line-height: 1.5;
}
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }
.btn-ghost {
  padding: 9px 16px; border-radius: 10px; color: var(--ink-2); font-weight: 500;
}
.btn-ghost:hover { background: var(--hover-8); color: var(--ink); }
.btn-danger { background: var(--danger); }
.dialog .modal-head h2 { font-size: 17px; }
.dialog-input {
  width: 100%; padding: 11px 14px; border: 1px solid var(--border);
  border-radius: 10px; background: var(--surface); color: var(--ink);
}

/* context menu (recents ⋮, title caret) */
.ctx-menu {
  position: fixed; z-index: 90; min-width: 200px;
  display: flex;
}
.ctx-menu .menu-item svg { width: 16px; height: 16px; color: var(--ink-2); flex: none; }
.ctx-menu .menu-item { align-items: center; gap: 10px; font-size: 14px; }
.ctx-menu .menu-item.danger, .ctx-menu .menu-item.danger svg { color: var(--danger); }
.menu-head {
  padding: 8px 10px 4px; font-size: 11px; font-weight: 600;
  letter-spacing: .06em; text-transform: uppercase; color: var(--ink-2);
}
.menu-foot { padding: 8px 10px; font-size: 11.5px; border-top: 1px solid var(--border-subtle); margin-top: 4px; }
.model-item .m-col { display: flex; flex-direction: column; min-width: 0; }
.model-item .m-name { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 14px; }
.model-item .m-sub { font-size: 12.5px; color: var(--ink-2); line-height: 1.45; }
.topbar-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 6px 10px; border-radius: 9px; text-align: start; }
.topbar-title.has-menu { cursor: pointer; }
.topbar-title.has-menu:hover { background: var(--hover-8); }

/* ── composer extras ── */
.composer-wrap { position: relative; }
.composer { position: relative; transition: box-shadow .18s, border-color .18s; }
.composer:focus-within { border-color: color-mix(in srgb, var(--brand) 35%, transparent); box-shadow: var(--raise); }
.mode-row {
  display: flex; gap: 6px; overflow-x: auto; padding: 2px 4px 8px;
  scrollbar-width: none;
}
.mode-row::-webkit-scrollbar { display: none; }
.mode-chip {
  display: inline-flex; align-items: center; gap: 6px; flex: none;
  padding: 5px 12px; border-radius: 999px; font-size: 12.5px;
  border: 1px solid var(--border); color: var(--ink-2);
}
.mode-chip svg { width: 13px; height: 13px; }
.mode-chip:hover { background: var(--hover-8); }
.mode-chip.on {
  background: var(--sidebar-active-tint); border-color: transparent;
  color: var(--ink); font-weight: 600;
}
.mode-chip.on svg { color: var(--brand); }

/* queued-message chip */
.queued-chip {
  display: none; align-items: center; gap: 8px;
  margin: 0 8px 8px; padding: 7px 12px;
  background: var(--surface); border: 1px solid var(--border);
  border-inline-start: 3px solid var(--brand);
  border-radius: 10px; font-size: 13px;
}
.queued-chip.show { display: flex; }
.q-label { font-weight: 700; color: var(--brand); font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; }
.q-text { flex: 1; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.q-cancel { color: var(--ink-2); width: 24px; height: 24px; border-radius: 6px; flex: none; }
.q-cancel:hover { background: var(--hover-8); color: var(--ink); }

/* slash menu */
.slash-menu {
  position: absolute; inset-inline: 0; bottom: calc(100% + 8px); z-index: 40;
  display: none; flex-direction: column;
  background: var(--elevated); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: var(--raise-soft);
  max-height: 260px; overflow-y: auto; padding: 4px;
}
.slash-menu.open { display: flex; }
.slash-item {
  display: flex; align-items: baseline; gap: 12px;
  padding: 8px 10px; border-radius: 8px; text-align: start;
  border-inline-start: 3px solid transparent;
}
.slash-item:hover, .slash-item.hot { background: var(--hover-8); border-inline-start-color: var(--brand); }
.slash-cmd { font-family: ui-monospace, monospace; font-weight: 600; font-size: 13.5px; }
.slash-hint { font-size: 12.5px; color: var(--ink-2); }

/* typing indicator */
.typing { display: inline-flex; gap: 4px; align-items: center; }
.typing span {
  width: 6px; height: 6px; border-radius: 50%; background: var(--brand);
  animation: typing 1.2s ease-in-out infinite;
}
.typing span:nth-child(2) { animation-delay: .15s; }
.typing span:nth-child(3) { animation-delay: .3s; }
@keyframes typing { 0%, 60%, 100% { opacity: .25; } 30% { opacity: 1; } }
.think-label { color: var(--ink-2); font-style: italic; }

/* jump to latest */
.jump-btn {
  position: absolute; bottom: 130px; left: 50%; translate: -50% 0; z-index: 20;
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--elevated); border: 1px solid var(--border);
  color: var(--ink-2); box-shadow: var(--raise-soft);
  display: none; align-items: center; justify-content: center;
}
.jump-btn.show { display: inline-flex; }
.jump-btn:hover { color: var(--ink); background: var(--surface); }
.view { position: relative; }

/* ── welcome capability cards ── */
.cap-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; width: 100%;
}
.cap-card {
  display: flex; flex-direction: column; align-items: flex-start; gap: 4px;
  padding: 12px 14px; border-radius: 16px; text-align: start;
  background: var(--surface); border: 1px solid var(--border);
}
.cap-card:hover { background: var(--hover-8); }
.cap-icon { color: var(--brand); display: inline-flex; }
.cap-icon svg { width: 18px; height: 18px; }
.cap-name { font-weight: 600; font-size: 13.5px; display: flex; align-items: center; gap: 6px; }
.cap-body { font-size: 12px; color: var(--ink-2); line-height: 1.4; }
.sug-heading { margin: 4px 0 -10px; align-self: center; }

/* middle band (640–767px): forced icon rail, like AI Zone's auto-collapse */
@media (min-width: 640px) and (max-width: 767.98px) {
  .sidebar { width: 68px; padding: 12px 10px; }
  .sidebar .label, .sidebar .brand-name, .sidebar .brand-ar,
  .sidebar .search-wrap, .sidebar .recents, .sidebar .pill,
  .sidebar .side-heading, .sidebar .status-chip .label { display: none; }
  .sidebar .side-item, .sidebar .btn-primary, .sidebar .status-chip { justify-content: center; padding: 8px; }
  .sidebar .side-head { justify-content: center; }
  .sidebar .brand { display: none; }
  .sidebar .collapse-btn { display: none; }
}

@media (max-width: 767.98px) {
  .cap-grid { grid-template-columns: repeat(2, 1fr); }
  .user-stack { max-width: 85%; }
  .edit-box { max-width: 100%; }
}
[lang="ar"] body, [lang="ar"] button, [lang="ar"] input, [lang="ar"] textarea {
  font-family: "IBM Plex Sans Arabic", "Libre Franklin", -apple-system, sans-serif;
}
