/* ILX AI web — tokens (the desktop app's palette, client/app/theme.py), layout, controls.  Mobile first. */

:root {
  --bg-base: #ffffff; --bg-surface: #f6f8fa; --bg-elevated: #eaeef2; --bg-hover: #d0d7de; --bg-input: #ffffff;
  --border: #d0d7de; --border-focus: #0969da; --border-subtle: #eaeef2;
  --text-primary: #1f2328; --text-secondary: #424a53; --text-muted: #525b66; --text-on-accent: #ffffff;
  --text-link: #0862cb; --accent: #1a7f37; --accent-hover: #116329; --accent-send: #0969da; --accent-send-h: #0550ae;
  --success: #1a7f37; --success-bg: #dafbe1; --warning: #9a6700; --warning-bg: #fff8c5; --error: #cf222e;
  --error-bg: #ffebe9; --error-border: #ff8182; --info-bg: #ddf4ff; --user-bubble: #e8f4fd; --user-bubble-fg: #0550ae;
  --code-bg: #f6f8fa; --code-header-bg: #eaeef2; --table-header-bg: #f6f8fa; --table-stripe: #fafbfc;
  --table-border: #d0d7de; --chip-bg: #f6f8fa; --chip-fg: #59636e; --chip-border: #d0d7de; --toast-bg: #1f2328;
  --toast-fg: #ffffff; --scrollbar: #8c959f; --shadow: 0 8px 24px rgba(31, 35, 40, .12), 0 1px 3px rgba(31, 35, 40, .08);
  --backdrop: rgba(31, 35, 40, .45);
  --space-xxs: 2px; --space-xs: 4px; --space-sm: 8px; --space-md: 12px; --space-lg: 16px; --space-xl: 24px; --space-xxl: 32px;
  --radius-sm: 4px; --radius-md: 8px; --radius-lg: 12px; --radius-xl: 16px; --radius-pill: 999px;
  --content-max: 760px; --sidebar-w: 280px; --row-h: 36px; --topbar-h: 52px;
  --font: "Segoe UI", -apple-system, BlinkMacSystemFont, "SF Pro Text", Roboto, system-ui, sans-serif;
  --mono: "Cascadia Code", "SF Mono", Consolas, "Liberation Mono", Menlo, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg-base: #0d1117; --bg-surface: #161b22; --bg-elevated: #21262d; --bg-hover: #30363d; --bg-input: #0d1117;
    --border: #30363d; --border-focus: #58a6ff; --border-subtle: #21262d;
    --text-primary: #e6edf3; --text-secondary: #c9d1d9; --text-muted: #9ba2ab; --text-on-accent: #ffffff;
    --text-link: #58a6ff; --accent: #238636; --accent-hover: #1f7a31; --accent-send: #1f6feb; --accent-send-h: #1a63d6;
    --success: #3fb950; --success-bg: #0f2a19; --warning: #d29922; --warning-bg: #2b2111; --error: #f85149;
    --error-bg: #2d1214; --error-border: #8e2c2c; --info-bg: #0c2341; --user-bubble: #1a3050; --user-bubble-fg: #e6edf3;
    --code-bg: #161b22; --code-header-bg: #21262d; --table-header-bg: #161b22; --table-stripe: #11161d;
    --table-border: #30363d; --chip-bg: #161b22; --chip-fg: #9ba2ab; --chip-border: #30363d; --toast-bg: #2d333b;
    --toast-fg: #e6edf3; --scrollbar: #5a636e; --shadow: 0 8px 24px rgba(1, 4, 9, .6), 0 1px 3px rgba(1, 4, 9, .4);
    --backdrop: rgba(1, 4, 9, .6);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg-base: #0d1117; --bg-surface: #161b22; --bg-elevated: #21262d; --bg-hover: #30363d; --bg-input: #0d1117;
  --border: #30363d; --border-focus: #58a6ff; --border-subtle: #21262d;
  --text-primary: #e6edf3; --text-secondary: #c9d1d9; --text-muted: #9ba2ab; --text-on-accent: #ffffff;
  --text-link: #58a6ff; --accent: #238636; --accent-hover: #1f7a31; --accent-send: #1f6feb; --accent-send-h: #1a63d6;
  --success: #3fb950; --success-bg: #0f2a19; --warning: #d29922; --warning-bg: #2b2111; --error: #f85149;
  --error-bg: #2d1214; --error-border: #8e2c2c; --info-bg: #0c2341; --user-bubble: #1a3050; --user-bubble-fg: #e6edf3;
  --code-bg: #161b22; --code-header-bg: #21262d; --table-header-bg: #161b22; --table-stripe: #11161d;
  --table-border: #30363d; --chip-bg: #161b22; --chip-fg: #9ba2ab; --chip-border: #30363d; --toast-bg: #2d333b;
  --toast-fg: #e6edf3; --scrollbar: #5a636e; --shadow: 0 8px 24px rgba(1, 4, 9, .6), 0 1px 3px rgba(1, 4, 9, .4);
  --backdrop: rgba(1, 4, 9, .6);
  color-scheme: dark;
}

/* ── base ─────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg-base); color: var(--text-primary); font: 15px/1.55 var(--font);
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; overflow: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--text-link); }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--border-focus); outline-offset: 2px; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}
::selection { background: color-mix(in srgb, var(--accent-send) 30%, transparent); }
* { scrollbar-color: var(--scrollbar) transparent; scrollbar-width: thin; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: 0s !important; transition: none !important; } }

.splash { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg-base); }
.splash img { animation: pulse 1.4s ease-in-out infinite; }
.noscript { padding: var(--space-xl); text-align: center; }
@keyframes pulse { 50% { opacity: .45; transform: scale(.94); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes blink { 50% { opacity: .2; } }

/* ── buttons & fields ─────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-sm); min-height: 36px;
  padding: 0 var(--space-lg); border: 1px solid var(--border); border-radius: var(--radius-md);
  background: var(--bg-surface); color: var(--text-primary); font-weight: 600; cursor: pointer; text-decoration: none;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--bg-elevated); }
.btn:disabled { opacity: .6; cursor: default; }
.btn-primary { background: var(--accent-send); border-color: var(--accent-send); color: var(--text-on-accent); }
.btn-primary:hover { background: var(--accent-send-h); border-color: var(--accent-send-h); }
.btn-danger { background: var(--error); border-color: var(--error); color: #fff; }
.btn-danger:hover { filter: brightness(.92); background: var(--error); }
.btn-block { width: 100%; min-height: 44px; }
.icon-btn {
  display: inline-grid; place-items: center; width: 36px; height: 36px; padding: 0; border: 0; border-radius: var(--radius-md);
  background: transparent; color: var(--text-muted); cursor: pointer; flex: none;
}
.icon-btn:hover { background: var(--bg-elevated); color: var(--text-primary); }
.icon-btn[aria-pressed="true"] { color: var(--accent-send); }
.icon { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.icon-sm { width: 15px; height: 15px; }
.spinner { width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; flex: none; }

input[type="text"], input[type="password"], input[type="search"], input:not([type]), select, textarea {
  background: var(--bg-input); border: 1px solid var(--border); border-radius: var(--radius-md); color: var(--text-primary);
}
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--border-focus); outline-offset: -1px; border-color: var(--border-focus); }

/* ── sign-in ──────────────────────────────────────────────────────────────── */
.login { position: fixed; inset: 0; overflow-y: auto; display: grid; place-items: center; padding: var(--space-lg); background: var(--bg-surface); }
.login-card {
  width: 100%; max-width: 380px; padding: var(--space-xxl) var(--space-xl); background: var(--bg-base);
  border: 1px solid var(--border); border-radius: var(--radius-xl); box-shadow: var(--shadow); text-align: center;
}
.login-logo { display: block; margin: 0 auto var(--space-lg); }
.login-title { margin: 0 0 var(--space-xs); font-size: 1.4rem; line-height: 1.3; }
.login-sub { margin: 0 0 var(--space-xl); color: var(--text-muted); font-size: .92rem; }
.login-form { display: grid; gap: var(--space-xs); text-align: left; }
.login-form label { font-size: .88rem; font-weight: 600; color: var(--text-secondary); margin-top: var(--space-sm); }
.login-form input:not([type="checkbox"]) { width: 100%; height: 42px; padding: 0 var(--space-md); }
.pw-field { position: relative; }
.pw-field input { padding-right: 64px !important; }
.pw-reveal {
  position: absolute; right: 4px; top: 4px; height: 34px; padding: 0 var(--space-sm); border: 0; border-radius: var(--radius-sm);
  background: transparent; color: var(--text-link); font-size: .85rem; font-weight: 600; cursor: pointer;
}
.check { display: flex !important; align-items: center; gap: var(--space-sm); font-weight: 400 !important; color: var(--text-primary) !important; margin: var(--space-md) 0 var(--space-sm) !important; cursor: pointer; }
.check input { width: 16px; height: 16px; margin: 0; accent-color: var(--accent-send); }
.form-error {
  margin: 0 0 var(--space-sm); padding: var(--space-sm) var(--space-md); border: 1px solid var(--error-border);
  border-radius: var(--radius-md); background: var(--error-bg); color: var(--text-primary); font-size: .9rem;
}
.login-alt { margin: var(--space-xl) 0 0; font-size: .9rem; }

/* ── app shell ────────────────────────────────────────────────────────────── */
.app { position: fixed; inset: 0; display: flex; }
.sidebar {
  position: fixed; z-index: 30; inset: 0 auto 0 0; width: min(86vw, var(--sidebar-w)); display: flex; flex-direction: column;
  background: var(--bg-surface); border-right: 1px solid var(--border); transform: translateX(-100%);
  transition: transform .2s ease; visibility: hidden;
}
.app.drawer-open .sidebar { transform: none; visibility: visible; box-shadow: var(--shadow); }
.backdrop { position: fixed; inset: 0; z-index: 25; background: var(--backdrop); }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; height: 100%; }

@media (min-width: 900px) {
  .sidebar { position: relative; transform: none; visibility: visible; width: var(--sidebar-w); flex: none; transition: none; }
  .app.sidebar-collapsed .sidebar { display: none; }
  .app.drawer-open .sidebar { box-shadow: none; }
  .backdrop { display: none; }
}

.sb-head { display: flex; align-items: center; gap: var(--space-sm); padding: var(--space-md) var(--space-md) var(--space-sm); }
.brand { display: flex; align-items: center; gap: var(--space-sm); font-weight: 700; font-size: 1.02rem; flex: 1; min-width: 0; }
.new-chat { margin: 0 var(--space-md) var(--space-sm); justify-content: flex-start; gap: var(--space-sm); background: var(--bg-base); }
.sb-search { position: relative; margin: 0 var(--space-md) var(--space-sm); }
.sb-search .icon { position: absolute; left: 10px; top: 9px; color: var(--text-muted); pointer-events: none; }
.sb-search input { width: 100%; height: 36px; padding: 0 var(--space-sm) 0 34px; background: var(--bg-base); }
.conv-scroll { flex: 1; overflow-y: auto; overscroll-behavior: contain; position: relative; padding: 0 var(--space-sm); }
.conv-spacer { position: relative; width: 100%; }
.conv-row { position: absolute; left: 0; right: 0; height: var(--row-h); display: flex; align-items: center; }
.conv-header { padding: 14px var(--space-sm) 0; font-size: .75rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }
.conv-item {
  flex: 1; min-width: 0; height: 32px; display: flex; align-items: center; gap: var(--space-sm); padding: 0 34px 0 var(--space-sm);
  border: 0; border-radius: var(--radius-md); background: transparent; color: var(--text-secondary); text-align: left; cursor: pointer;
}
.conv-item:hover, .conv-row:focus-within .conv-item { background: var(--bg-elevated); color: var(--text-primary); }
.conv-item[aria-current="true"] { background: var(--bg-hover); color: var(--text-primary); font-weight: 600; }
.conv-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; font-size: .92rem; }
.conv-more { position: absolute; right: 2px; width: 30px; height: 30px; opacity: 0; }
.conv-row:hover .conv-more, .conv-row:focus-within .conv-more, .conv-more[aria-expanded="true"] { opacity: 1; }
@media (hover: none) { .conv-more { opacity: 1; } }
.conv-rename { flex: 1; height: 30px; padding: 0 var(--space-sm); }
.conv-empty { padding: var(--space-md) var(--space-lg); color: var(--text-muted); font-size: .9rem; }
.sb-foot { border-top: 1px solid var(--border); padding: var(--space-sm) var(--space-md); }
.user-btn {
  width: 100%; display: flex; align-items: center; gap: var(--space-sm); padding: var(--space-sm); border: 0;
  border-radius: var(--radius-md); background: transparent; cursor: pointer; text-align: left;
}
.user-btn:hover { background: var(--bg-elevated); }
.avatar {
  width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: var(--accent-send); color: var(--text-on-accent); font-weight: 700; font-size: .85rem;
}
.user-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; font-size: .92rem; }

.topbar {
  height: var(--topbar-h); flex: none; display: flex; align-items: center; gap: var(--space-xs); padding: 0 var(--space-sm);
  border-bottom: 1px solid var(--border-subtle);
}
.topbar-title { flex: 1; min-width: 0; margin: 0; font-size: 1rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 var(--space-xs); }
@media (min-width: 900px) { .app:not(.sidebar-collapsed) .topbar .only-collapsed { display: none; } }

/* ── menus, dialogs, toasts ───────────────────────────────────────────────── */
.menu {
  position: fixed; z-index: 60; min-width: 180px; padding: var(--space-xs); background: var(--bg-base);
  border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow);
}
.menu-item {
  width: 100%; display: flex; align-items: center; gap: var(--space-sm); min-height: 34px; padding: 0 var(--space-md);
  border: 0; border-radius: var(--radius-md); background: transparent; text-align: left; cursor: pointer; font-size: .92rem;
  color: var(--text-primary); text-decoration: none;
}
.menu-item:hover, .menu-item:focus-visible { background: var(--bg-elevated); outline: none; }
.menu-item.danger { color: var(--error); }
.menu-item[aria-checked="true"]::after { content: "\2713"; margin-left: auto; color: var(--accent-send); font-weight: 700; }
.menu-sep { height: 1px; margin: var(--space-xs) 0; background: var(--border); }
.menu-label { padding: var(--space-xs) var(--space-md); font-size: .75rem; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }

dialog.dialog {
  width: min(92vw, 420px); padding: var(--space-xl); border: 1px solid var(--border); border-radius: var(--radius-xl);
  background: var(--bg-base); color: var(--text-primary); box-shadow: var(--shadow);
}
dialog.dialog::backdrop { background: var(--backdrop); }
.dialog h2 { margin: 0 0 var(--space-sm); font-size: 1.1rem; }
.dialog p { margin: 0 0 var(--space-lg); color: var(--text-secondary); }
.dialog-actions { display: flex; justify-content: flex-end; gap: var(--space-sm); margin-top: var(--space-lg); }

.toasts { position: fixed; z-index: 80; left: 50%; bottom: var(--space-xl); transform: translateX(-50%); display: grid; gap: var(--space-sm); width: max-content; max-width: calc(100vw - 32px); pointer-events: none; }
.toast {
  padding: var(--space-sm) var(--space-lg); border-radius: var(--radius-md); background: var(--toast-bg); color: var(--toast-fg);
  box-shadow: var(--shadow); font-size: .92rem; pointer-events: auto; animation: toast-in .18s ease-out;
}
.toast.error { background: var(--error-bg); color: var(--text-primary); border: 1px solid var(--error-border); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ── messages ─────────────────────────────────────────────────────────────── */
.scroller { flex: 1; overflow-y: auto; overscroll-behavior: contain; scroll-padding-bottom: 24px; }
.thread { max-width: var(--content-max); margin: 0 auto; padding: var(--space-lg) var(--space-lg) var(--space-xl); }
.load-older { display: flex; justify-content: center; padding: var(--space-sm); color: var(--text-muted); font-size: .88rem; }
.msg { margin: 0 0 var(--space-lg); }
.msg-user + .msg-assistant { margin-top: calc(-1 * var(--space-sm)); }
.msg-user { display: flex; flex-direction: column; align-items: flex-end; }
.bubble {
  max-width: min(85%, 640px); padding: var(--space-sm) var(--space-lg); border-radius: var(--radius-xl) var(--radius-xl) var(--radius-sm) var(--radius-xl);
  background: var(--user-bubble); color: var(--user-bubble-fg); white-space: pre-wrap; overflow-wrap: anywhere;
}
.edit-box { width: min(100%, 640px); display: grid; gap: var(--space-sm); }
.edit-box textarea { width: 100%; min-height: 96px; padding: var(--space-md); resize: vertical; line-height: 1.5; }
.edit-actions { display: flex; justify-content: flex-end; gap: var(--space-sm); }
.msg-actions { display: flex; gap: var(--space-xxs); margin-top: var(--space-xs); color: var(--text-muted); min-height: 32px; align-items: center; flex-wrap: wrap; }
.msg-actions .icon-btn { width: 32px; height: 32px; }
.msg-user .msg-actions { opacity: 0; transition: opacity .12s; }
.msg-user:hover .msg-actions, .msg-user:focus-within .msg-actions { opacity: 1; }
@media (hover: none) { .msg-user .msg-actions { opacity: 1; } }
.msg-stat { font-size: .78rem; color: var(--text-muted); margin-left: var(--space-sm); }
.chips { display: flex; flex-wrap: wrap; gap: var(--space-xs); margin-top: var(--space-xs); justify-content: flex-end; }
.msg-assistant .chips { justify-content: flex-start; }
.chip {
  display: inline-flex; align-items: center; gap: var(--space-xs); max-width: 260px; min-height: 28px; padding: 0 var(--space-sm);
  border: 1px solid var(--chip-border); border-radius: var(--radius-pill); background: var(--chip-bg); color: var(--chip-fg);
  font-size: .82rem; text-decoration: none;
}
.chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
a.chip:hover { border-color: var(--text-muted); color: var(--text-primary); }
.notice { margin: var(--space-sm) 0; padding: var(--space-sm) var(--space-md); border-radius: var(--radius-md); background: var(--warning-bg); color: var(--text-primary); font-size: .9rem; border-left: 3px solid var(--warning); }
.notice.error { background: var(--error-bg); border-left-color: var(--error); }
.retry-btn { margin-top: var(--space-sm); }

.steps { display: flex; align-items: center; gap: var(--space-sm); margin: 0 0 var(--space-sm); color: var(--text-muted); font-size: .88rem; min-height: 22px; }
.steps .live { animation: blink 1.2s ease-in-out infinite; }
.typing { display: inline-flex; gap: 4px; padding: var(--space-sm) 0; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--text-muted); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; }
.typing i:nth-child(3) { animation-delay: .4s; }

details.thinking { margin: 0 0 var(--space-sm); font-size: .9rem; }
details.thinking summary { cursor: pointer; color: var(--text-muted); width: max-content; border-radius: var(--radius-sm); list-style-position: inside; }
details.thinking .thinking-body {
  margin: var(--space-sm) 0 0; padding: var(--space-xs) var(--space-md); border-left: 2px solid var(--border);
  color: var(--text-muted); white-space: pre-wrap; max-height: 320px; overflow-y: auto;
}

.research {
  margin: 0 0 var(--space-md); padding: var(--space-md) var(--space-lg); border: 1px solid var(--border);
  border-radius: var(--radius-lg); background: var(--bg-surface);
}
.research-head { display: flex; align-items: center; gap: var(--space-sm); font-weight: 600; font-size: .92rem; }
.research-head .pct { margin-left: auto; color: var(--text-muted); font-weight: 400; font-variant-numeric: tabular-nums; }
.progress { height: 6px; margin: var(--space-sm) 0; border-radius: var(--radius-pill); background: var(--bg-elevated); overflow: hidden; }
.progress-bar { height: 100%; width: 100%; background: var(--accent-send); border-radius: inherit; transform-origin: left; transition: transform .3s ease; }
.phases { display: flex; flex-wrap: wrap; gap: var(--space-xs) var(--space-md); margin: 0; padding: 0; list-style: none; font-size: .84rem; color: var(--text-muted); }
.phases li::before { content: "\25CB"; margin-right: 4px; }
.phases li.active { color: var(--text-primary); font-weight: 600; }
.phases li.active::before { content: "\25CF"; color: var(--accent-send); }
.phases li.done::before { content: "\2713"; color: var(--success); }
.research-detail { margin: var(--space-sm) 0 0; font-size: .88rem; color: var(--text-secondary); }
.research .chips { justify-content: flex-start; margin-top: var(--space-sm); }

.sources { margin-top: var(--space-md); }
.sources summary { cursor: pointer; font-weight: 600; font-size: .9rem; color: var(--text-secondary); width: max-content; border-radius: var(--radius-sm); }
.source-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: var(--space-sm); margin: var(--space-sm) 0 0; padding: 0; list-style: none; }
.source {
  display: flex; gap: var(--space-sm); padding: var(--space-sm) var(--space-md); border: 1px solid var(--border); border-radius: var(--radius-md);
  background: var(--bg-surface); text-decoration: none; color: var(--text-primary); min-width: 0; height: 100%;
}
a.source:hover { border-color: var(--text-muted); }
.source-n { flex: none; min-width: 20px; height: 20px; border-radius: var(--radius-pill); background: var(--bg-elevated); color: var(--text-secondary); font-size: .75rem; font-weight: 700; display: grid; place-items: center; }
.source-body { min-width: 0; display: grid; }
.source-title { font-size: .86rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.source-domain { font-size: .78rem; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.source:target, .source.flash { border-color: var(--accent-send); }

.empty { min-height: 100%; display: grid; place-items: center; padding: var(--space-xl) var(--space-lg); text-align: center; }
.empty h2 { margin: var(--space-md) 0 var(--space-xs); font-size: 1.5rem; }
.empty p { margin: 0 0 var(--space-xl); color: var(--text-muted); }
.suggestions { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: var(--space-sm); max-width: 560px; margin: 0 auto; }
.suggestion { padding: var(--space-md); border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--bg-base); text-align: left; cursor: pointer; color: var(--text-secondary); font-size: .9rem; }
.suggestion:hover { background: var(--bg-surface); color: var(--text-primary); }

/* ── composer ─────────────────────────────────────────────────────────────── */
.composer-wrap { flex: none; padding: 0 var(--space-md) max(var(--space-sm), env(safe-area-inset-bottom)); }
.composer {
  max-width: var(--content-max); margin: 0 auto; border: 1px solid var(--border); border-radius: var(--radius-xl);
  background: var(--bg-input); box-shadow: 0 1px 3px rgba(0, 0, 0, .06); transition: border-color .12s;
}
.composer:focus-within { border-color: var(--border-focus); }
.composer.dragging { border-color: var(--accent-send); border-style: dashed; }
.composer textarea {
  display: block; width: 100%; min-height: 52px; max-height: 40vh; padding: var(--space-md) var(--space-lg) var(--space-xs);
  border: 0; background: transparent; resize: none; line-height: 1.5; outline: none;
}
.composer textarea:focus-visible { outline: none; }
.attachments { display: flex; flex-wrap: wrap; gap: var(--space-xs); padding: var(--space-sm) var(--space-md) 0; }
.attachments:empty { display: none; }
.attachment { position: relative; padding-right: 2px; }
.attachment.error { border-color: var(--error); color: var(--error); }
.attachment .icon-btn { width: 22px; height: 22px; }
.attachment-progress { position: absolute; left: 8px; right: 8px; bottom: 2px; height: 2px; background: var(--accent-send); transform-origin: left; border-radius: 2px; }
.toolbar { display: flex; align-items: center; gap: var(--space-xs); padding: var(--space-xs) var(--space-sm) var(--space-sm); flex-wrap: wrap; }
.toolbar .spacer { flex: 1; }
.pill-select {
  height: 32px; padding: 0 26px 0 var(--space-md); border-radius: var(--radius-pill) !important; background-color: var(--bg-base);
  font-size: .85rem; color: var(--text-secondary); cursor: pointer; appearance: none; border: 1px solid var(--border);
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 13px) 14px, calc(100% - 9px) 14px; background-size: 4px 4px; background-repeat: no-repeat;
}
.pill-toggle {
  display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 var(--space-md); border: 1px solid var(--border);
  border-radius: var(--radius-pill); background: var(--bg-base); color: var(--text-secondary); font-size: .85rem; cursor: pointer;
}
.pill-toggle[aria-pressed="true"] { background: var(--info-bg); border-color: var(--accent-send); color: var(--text-primary); font-weight: 600; }
.pill-toggle:disabled, .pill-select:disabled { opacity: .55; cursor: not-allowed; }
.send-btn { width: 36px; height: 36px; border-radius: 50%; background: var(--accent-send); color: var(--text-on-accent); }
.send-btn:hover { background: var(--accent-send-h); color: var(--text-on-accent); }
.send-btn:disabled { background: var(--bg-elevated); color: var(--text-muted); cursor: default; }
.stop-btn { background: var(--text-primary); color: var(--bg-base); }
.stop-btn:hover { background: var(--text-secondary); color: var(--bg-base); }
.disclaimer { max-width: var(--content-max); margin: var(--space-xs) auto 0; text-align: center; font-size: .75rem; color: var(--text-muted); }
@media (max-width: 520px) {
  .label-wide { display: none; }
  .toolbar { gap: 2px; }
  .pill-select { padding: 0 22px 0 10px; background-position: calc(100% - 12px) 14px, calc(100% - 8px) 14px; }
  .pill-toggle { padding: 0 10px; }
  .thread { padding: var(--space-md) var(--space-md) var(--space-lg); }
  .bubble { max-width: 92%; }
  body { font-size: 15px; }
}

/* ── Image mode ───────────────────────────────────────────────────────────── */
.mode-hidden { display: none !important; }
.narrow-only { display: none !important; }
@media (max-width: 520px) {
  .wide-only { display: none !important; }
  .narrow-only:not(.mode-hidden) { display: inline-grid !important; }
}
.image-opts { max-width: 220px; }
.image-opts .label-wide { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.btn-sm { min-height: 28px; padding: 0 var(--space-md); font-size: .82rem; }
.image-job {
  margin: 0 0 var(--space-md); padding: var(--space-md) var(--space-lg); border: 1px solid var(--border);
  border-radius: var(--radius-lg); background: var(--bg-surface);
}
.image-job-head { display: flex; align-items: center; gap: var(--space-sm); font-size: .92rem; font-weight: 600; min-height: 28px; }
.image-job-text { flex: 1; min-width: 0; }
.image-job-head .pct { color: var(--text-muted); font-weight: 400; font-variant-numeric: tabular-nums; }
.image-job-prompt { margin: var(--space-xs) 0 0; font-size: .84rem; color: var(--text-secondary); overflow-wrap: anywhere; }
.media { margin: 0 0 var(--space-md); }
.media:empty { display: none; }
.image-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-sm); max-width: 560px; }
.image-grid.single { grid-template-columns: minmax(0, 1fr); max-width: 420px; }
.image-tile {
  display: block; width: 100%; padding: 0; border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden;
  background: var(--bg-surface); cursor: zoom-in; line-height: 0;
}
.image-tile:hover { border-color: var(--text-muted); }
.image-tile img { display: block; width: 100%; height: auto; }
.image-placeholder { aspect-ratio: 1 / 1; cursor: default; background: var(--bg-elevated); animation: pulse 1.4s ease-in-out infinite; }

dialog.lightbox {
  width: 100vw; height: 100dvh; max-width: none; max-height: none; margin: 0; padding: 0; border: 0;
  background: rgba(1, 4, 9, .94); color: #fff; flex-direction: column;
}
dialog.lightbox[open] { display: flex; }
dialog.lightbox::backdrop { background: rgba(1, 4, 9, .6); }
.lightbox-bar {
  display: flex; align-items: center; gap: var(--space-xs); flex: none;
  padding: max(var(--space-sm), env(safe-area-inset-top)) max(var(--space-sm), env(safe-area-inset-right)) var(--space-sm)
    max(var(--space-md), env(safe-area-inset-left));
}
.lightbox-bar .spacer { flex: 1; }
.lightbox-bar .icon-btn, .lightbox-nav { color: #e6edf3; }
.lightbox-bar .icon-btn:hover, .lightbox-nav:hover { background: rgba(255, 255, 255, .14); color: #fff; }
.lightbox-counter { font-size: .9rem; color: #c9d1d9; font-variant-numeric: tabular-nums; }
.lightbox-figure {
  position: relative; flex: 1; min-height: 0; margin: 0; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: var(--space-sm); padding: 0 var(--space-lg) max(var(--space-lg), env(safe-area-inset-bottom));
}
.lightbox-img { flex: 1 1 auto; width: 100%; min-height: 0; object-fit: contain; }
.lightbox-caption { max-width: 760px; font-size: .9rem; color: #c9d1d9; text-align: center; overflow-wrap: anywhere; flex: none; }
.lightbox-nav {
  position: absolute; top: 50%; transform: translateY(-50%); width: 44px; height: 44px; border-radius: 50%;
  background: rgba(0, 0, 0, .4);
}
.lightbox-nav.prev { left: max(var(--space-sm), env(safe-area-inset-left)); }
.lightbox-nav.next { right: max(var(--space-sm), env(safe-area-inset-right)); }

/* ── installed app (PWA) and phones ───────────────────────────────────────── */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
button, a, select, summary { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
.menu { max-height: calc(100dvh - 16px); overflow-y: auto; overscroll-behavior: contain; }
/* Notches and rounded corners (viewport-fit=cover): content stays out of the unsafe edges. */
.main { padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left); }
.sidebar { padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom) env(safe-area-inset-left); }
.login {
  padding: max(var(--space-lg), env(safe-area-inset-top)) max(var(--space-lg), env(safe-area-inset-right))
    max(var(--space-lg), env(safe-area-inset-bottom)) max(var(--space-lg), env(safe-area-inset-left));
}
.toasts { bottom: calc(var(--space-xl) + env(safe-area-inset-bottom)); }
/* iOS zooms into a field whose text is under 16 px: touch screens get 16 px fields. */
@media (pointer: coarse) {
  .composer textarea, .login-form input:not([type="checkbox"]), .sb-search input, .conv-rename, .edit-box textarea, select { font-size: 16px; }
}
@media (display-mode: standalone) {
  body { overscroll-behavior: none; }
  .topbar, .sb-head { -webkit-user-select: none; user-select: none; }
}
.toast-update { display: flex; align-items: center; gap: var(--space-md); }
.toast-action {
  border: 0; padding: 4px var(--space-sm); border-radius: var(--radius-sm); background: transparent; color: inherit;
  font-weight: 700; cursor: pointer; text-decoration: underline; text-underline-offset: 2px;
}
.offline-page .btn { margin-top: var(--space-md); }
/* The empty chat's text and suggestions wrap to the screen (a grid item is otherwise as wide as its content). */
.empty > div { width: 100%; min-width: 0; max-width: 560px; }
