/* ==========================================================================
   LifeOS design tokens — semantic only. Never raw colors in components.
   Dark is default; light via [data-theme="light"] on <html>.
   Logical properties only (inline/block), safe-area aware.
   ========================================================================== */

:root {
  --bg: hsl(212 30% 6%);
  --surface-1: hsl(210 26% 9%);
  --surface-2: hsl(210 22% 12%);
  --surface-3: hsl(210 18% 16%);
  --hairline: hsl(210 16% 20%);
  --border: hsl(210 16% 20%);
  --border-strong: hsl(210 14% 30%);

  --text-1: hsl(210 24% 96%);
  --text-2: hsl(212 14% 76%);
  --muted: hsl(213 13% 62%);
  --faint: hsl(212 10% 45%);

  --accent: hsl(167 68% 46%);
  --accent-strong: hsl(167 72% 36%);
  --accent-text: hsl(165 66% 62%);
  --accent-ink: hsl(210 40% 7%);
  --accent-soft: hsl(167 68% 46% / 0.14);
  --accent-line: hsl(167 68% 46% / 0.35);

  --danger: hsl(4 76% 63%);
  --danger-soft: hsl(4 76% 63% / 0.14);
  --warning: hsl(38 92% 60%);
  --warning-soft: hsl(38 92% 60% / 0.14);
  --success: hsl(150 58% 47%);
  --success-soft: hsl(150 58% 47% / 0.14);
  --info: hsl(205 80% 66%);
  --info-soft: hsl(205 80% 66% / 0.14);

  --user-bubble: hsl(167 45% 20%);
  --user-bubble-text: hsl(160 30% 95%);

  --r-s: 10px;
  --r-m: 14px;
  --r-l: 20px;
  --r-xl: 28px;
  --r-full: 999px;

  --shadow-1: 0 1px 2px hsl(212 45% 2% / 0.35), 0 6px 20px -10px hsl(212 45% 2% / 0.5);
  --shadow-2: 0 2px 4px hsl(212 45% 2% / 0.35), 0 14px 40px -12px hsl(212 45% 2% / 0.6);
  --shadow-pop: 0 18px 50px -16px hsl(212 45% 2% / 0.7);

  --dur-1: 150ms;
  --dur-2: 260ms;
  --ease: cubic-bezier(0.2, 0.7, 0.3, 1);

  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial,
    "Noto Sans Arabic", "Noto Kufi Arabic", Tahoma, "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;

  --fs-base: 16px;
  --tabbar-h: 60px;
  --app-height: 100dvh;
  color-scheme: dark;
}

[data-theme="light"] {
  --bg: hsl(210 30% 98%);
  --surface-1: hsl(0 0% 100%);
  --surface-2: hsl(210 28% 96%);
  --surface-3: hsl(210 24% 92%);
  --hairline: hsl(210 20% 90%);
  --border: hsl(210 20% 88%);
  --border-strong: hsl(210 16% 78%);

  --text-1: hsl(212 42% 12%);
  --text-2: hsl(212 22% 30%);
  --muted: hsl(213 14% 40%);
  --faint: hsl(212 12% 52%);

  --accent: hsl(168 76% 30%);
  --accent-strong: hsl(168 80% 25%);
  --accent-text: hsl(168 72% 28%);
  --accent-ink: hsl(0 0% 100%);
  --accent-soft: hsl(168 76% 30% / 0.10);
  --accent-line: hsl(168 76% 30% / 0.35);

  --danger: hsl(4 68% 48%);
  --danger-soft: hsl(4 68% 48% / 0.10);
  --warning: hsl(34 88% 40%);
  --warning-soft: hsl(34 88% 40% / 0.12);
  --success: hsl(152 62% 34%);
  --success-soft: hsl(152 62% 34% / 0.12);
  --info: hsl(208 74% 42%);
  --info-soft: hsl(208 74% 42% / 0.10);

  --user-bubble: hsl(167 62% 91%);
  --user-bubble-text: hsl(168 55% 14%);

  --shadow-1: 0 1px 2px hsl(212 30% 60% / 0.16), 0 6px 20px -12px hsl(212 30% 40% / 0.25);
  --shadow-2: 0 2px 6px hsl(212 30% 60% / 0.18), 0 16px 40px -16px hsl(212 30% 40% / 0.3);
  --shadow-pop: 0 20px 60px -20px hsl(212 30% 30% / 0.4);
  color-scheme: light;
}

[data-fontsize="s"] { --fs-base: 15px; }
[data-fontsize="m"] { --fs-base: 16px; }
[data-fontsize="l"] { --fs-base: 17.5px; }

/* ==========================================================================
   Reset & base
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; }

html {
  font-size: var(--fs-base);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

html, body { margin: 0; padding: 0; }

body {
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.55;
  color: var(--text-1);
  background: var(--bg);
  overscroll-behavior-y: none;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3, h4, p, figure { margin: 0; }

button, input, textarea, select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  background: none;
  border: 0;
  padding: 0;
  touch-action: manipulation;
}

a { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; }

:focus { outline: none; }
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-s);
}

::selection { background: var(--accent-soft); }

input, textarea { caret-color: var(--accent); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ==========================================================================
   App shell
   ========================================================================== */

.app-root { min-height: var(--app-height); }

.app-shell {
  display: flex;
  flex-direction: column;
  height: var(--app-height);
  max-width: 720px;
  margin-inline: auto;
  background: var(--bg);
  position: relative;
}

.app-main { flex: 1; min-height: 0; display: flex; flex-direction: column; }

.view-holder { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.view-holder[hidden] { display: none; }

.view {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.view-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-inline: 16px;
  padding-block-end: 28px;
  scrollbar-width: thin;
}

.top-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-block: 10px;
  padding-inline: 12px;
  padding-block-start: max(env(safe-area-inset-top), 10px);
  background: var(--bg);
  border-block-end: 1px solid transparent;
  position: sticky;
  top: 0;
  z-index: 5;
}

.top-bar.is-scrolled { border-block-end-color: var(--hairline); }

.top-bar .title {
  font-size: 1.125rem;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.top-bar .sub {
  font-size: 0.75rem;
  color: var(--muted);
  margin-block-start: -2px;
}

.spacer { flex: 1; }

/* Tab bar */

.tabbar {
  display: flex;
  align-items: stretch;
  justify-content: space-around;
  background: var(--surface-1);
  border-block-start: 1px solid var(--hairline);
  padding-block-end: max(env(safe-area-inset-bottom), 8px);
  padding-block-start: 4px;
  z-index: 20;
}

.kb-open .tabbar { display: none; }

.tab {
  flex: 1;
  min-height: 52px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--muted);
  border-radius: var(--r-m);
  position: relative;
  transition: color var(--dur-1) var(--ease);
}

.tab .tab-label { font-size: 0.6875rem; font-weight: 600; letter-spacing: 0.01em; }
.tab[aria-selected="true"] { color: var(--accent-text); }

.tab .dot {
  position: absolute;
  top: 6px;
  inset-inline-end: calc(50% - 16px);
  width: 8px;
  height: 8px;
  border-radius: var(--r-full);
  background: var(--accent);
  border: 2px solid var(--surface-1);
}

/* ==========================================================================
   Buttons & controls
   ========================================================================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding-inline: 18px;
  border-radius: var(--r-m);
  font-size: 0.9375rem;
  font-weight: 620;
  border: 1px solid transparent;
  transition: transform var(--dur-1) var(--ease), background var(--dur-1) var(--ease),
    border-color var(--dur-1) var(--ease), opacity var(--dur-1) var(--ease);
}

.btn:active { transform: scale(0.98); }
.btn[disabled] { opacity: 0.45; pointer-events: none; }

.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent-strong); }

.btn-soft { background: var(--accent-soft); color: var(--accent-text); border-color: var(--accent-line); }
.btn-soft:hover { background: var(--accent-soft); border-color: var(--accent-text); }

.btn-ghost { background: transparent; color: var(--text-2); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text-1); }

.btn-danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.btn-danger:hover { border-color: var(--danger); }

.btn-block { width: 100%; }
.btn-sm { min-height: 38px; padding-inline: 12px; font-size: 0.8125rem; border-radius: var(--r-s); }

.icon-btn {
  width: 48px;
  height: 48px;
  min-width: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--r-m);
  color: var(--text-2);
  transition: background var(--dur-1) var(--ease), color var(--dur-1) var(--ease);
}

.icon-btn:hover { background: var(--surface-2); color: var(--text-1); }
.icon-btn.is-accent { color: var(--accent-text); }
.icon-btn[disabled] { opacity: 0.4; pointer-events: none; }

[dir="rtl"] .icon-flip { transform: scaleX(-1); }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding-inline: 12px;
  border-radius: var(--r-full);
  font-size: 0.8125rem;
  font-weight: 580;
  color: var(--text-2);
  background: var(--surface-2);
  border: 1px solid var(--hairline);
  transition: all var(--dur-1) var(--ease);
}

.chip:hover { border-color: var(--border-strong); color: var(--text-1); }
.chip.is-on {
  background: var(--accent-soft);
  border-color: var(--accent-line);
  color: var(--accent-text);
}

.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }

.seg {
  display: flex;
  gap: 6px;
  background: var(--surface-2);
  border: 1px solid var(--hairline);
  padding: 4px;
  border-radius: var(--r-m);
}

.seg button {
  flex: 1;
  min-height: 48px;
  min-width: 48px;
  border-radius: var(--r-s);
  font-weight: 620;
  font-size: 0.9375rem;
  color: var(--muted);
  transition: all var(--dur-1) var(--ease);
}

.seg button.is-on {
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: var(--shadow-1);
}

.switch {
  position: relative;
  width: 50px;
  height: 30px;
  min-width: 50px;
  border-radius: var(--r-full);
  background: var(--surface-3);
  border: 1px solid var(--border);
  transition: background var(--dur-1) var(--ease);
}

.switch::after {
  content: "";
  position: absolute;
  inset-block-start: 2px;
  inset-inline-start: 2px;
  width: 24px;
  height: 24px;
  border-radius: var(--r-full);
  background: var(--text-2);
  transition: transform var(--dur-1) var(--ease), background var(--dur-1) var(--ease);
}

.switch.is-on { background: var(--accent); border-color: var(--accent); }
.switch.is-on::after { transform: translateX(20px); background: var(--accent-ink); }
[dir="rtl"] .switch.is-on::after { transform: translateX(-20px); }

/* Fields */

.field { display: flex; flex-direction: column; gap: 6px; margin-block-end: 14px; }
.field > label { font-size: 0.8125rem; font-weight: 620; color: var(--text-2); }
.field .hint { font-size: 0.75rem; color: var(--muted); }

.input, .textarea, .select {
  width: 100%;
  min-height: 48px;
  padding-block: 12px;
  padding-inline: 14px;
  border-radius: var(--r-m);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-1);
  font-size: 1rem;
  transition: border-color var(--dur-1) var(--ease), background var(--dur-1) var(--ease);
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
  min-height: 32px;
}

.input:focus, .textarea:focus, .select:focus { border-color: var(--accent-line); background: var(--surface-1); }

.textarea { resize: vertical; min-height: 96px; line-height: 1.5; }
.textarea.mono, .input.mono { font-family: var(--font-mono); font-size: 0.8125rem; }

.select { appearance: none; background-image: none; }

.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.row { display: flex; align-items: center; gap: 10px; }
.col { display: flex; flex-direction: column; gap: 10px; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.small { font-size: 0.8125rem; }
.xs { font-size: 0.75rem; }
.strong { font-weight: 650; }
.mono-text { font-family: var(--font-mono); font-size: 0.8125rem; }

/* ==========================================================================
   Cards, lists, meters, badges
   ========================================================================== */

.card {
  background: var(--surface-1);
  border: 1px solid var(--hairline);
  border-radius: var(--r-l);
  padding: 16px;
  box-shadow: var(--shadow-1);
}

.card + .card { margin-block-start: 12px; }
.card .card-title { font-size: 0.9375rem; font-weight: 650; letter-spacing: -0.01em; }
.card .card-sub { font-size: 0.8125rem; color: var(--muted); }

.section-title {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  margin-block: 22px 10px;
}

.section-title:first-child { margin-block-start: 8px; }

.list { display: flex; flex-direction: column; }

.list-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding-block: 12px;
  padding-inline: 2px;
  border-block-end: 1px solid var(--hairline);
  text-align: start;
  width: 100%;
  min-height: 48px;
}

.list-item:last-child { border-block-end: 0; }
button.list-item:hover { background: var(--surface-2); border-radius: var(--r-m); }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.6875rem;
  font-weight: 650;
  padding-block: 2px;
  padding-inline: 8px;
  border-radius: var(--r-full);
  background: var(--surface-3);
  color: var(--text-2);
}

.badge.accent { background: var(--accent-soft); color: var(--accent-text); }
.badge.warn { background: var(--warning-soft); color: var(--warning); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.dim { opacity: 0.75; }

.meter { display: flex; flex-direction: column; gap: 6px; }
.meter .meter-head { display: flex; justify-content: space-between; font-size: 0.8125rem; color: var(--text-2); }
.meter .track {
  height: 8px;
  border-radius: var(--r-full);
  background: var(--surface-3);
  overflow: hidden;
}
.meter .fill {
  height: 100%;
  border-radius: var(--r-full);
  background: linear-gradient(90deg, var(--accent-strong), var(--accent));
  transform-origin: inline-start;
  transition: width var(--dur-2) var(--ease);
}

.stars { display: inline-flex; gap: 1px; color: var(--warning); }

.avatar {
  width: 34px;
  height: 34px;
  min-width: 34px;
  border-radius: var(--r-full);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-soft);
  color: var(--accent-text);
  font-weight: 700;
  font-size: 0.875rem;
}

/* ==========================================================================
   Banners & toasts
   ========================================================================== */

.banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-block: 10px;
  padding-inline: 14px;
  border-radius: var(--r-m);
  font-size: 0.8125rem;
  border: 1px solid transparent;
}

.banner.warn { background: var(--warning-soft); color: var(--warning); border-color: var(--warning-soft); }
.banner.danger { background: var(--danger-soft); color: var(--danger); }
.banner.info { background: var(--info-soft); color: var(--info); }
.banner.soft { background: var(--surface-2); color: var(--text-2); border-color: var(--hairline); }
.banner .btn { margin-inline-start: auto; }

.toast-wrap {
  position: fixed;
  inset-inline: 0;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 12px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: 90;
  pointer-events: none;
  padding-inline: 16px;
}

.toast {
  max-width: 480px;
  width: fit-content;
  background: var(--surface-3);
  color: var(--text-1);
  border: 1px solid var(--border);
  border-radius: var(--r-m);
  padding-block: 10px;
  padding-inline: 14px;
  font-size: 0.8125rem;
  box-shadow: var(--shadow-pop);
  pointer-events: auto;
  animation: toast-in var(--dur-2) var(--ease);
}

.toast.danger { color: var(--danger); border-color: var(--danger-soft); }
.toast.success { color: var(--success); border-color: var(--success-soft); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ==========================================================================
   Bottom sheet
   ========================================================================== */

.scrim {
  position: fixed;
  inset: 0;
  background: hsl(212 45% 2% / 0.55);
  z-index: 50;
  animation: fade-in var(--dur-1) var(--ease);
}

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.sheet {
  position: fixed;
  inset-inline: 0;
  inset-block-end: 0;
  margin-inline: auto;
  max-width: 720px;
  max-height: 86%;
  display: flex;
  flex-direction: column;
  background: var(--surface-1);
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  box-shadow: var(--shadow-pop);
  z-index: 51;
  animation: sheet-up var(--dur-2) var(--ease);
  padding-block-end: max(env(safe-area-inset-bottom), 8px);
}

@keyframes sheet-up {
  from { transform: translateY(24px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.sheet .grabber {
  width: 40px;
  height: 4px;
  border-radius: var(--r-full);
  background: var(--border-strong);
  margin-block: 8px 4px;
  margin-inline: auto;
}

.sheet-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-block: 6px 10px;
  padding-inline: 8px 16px;
}

.sheet-title { font-size: 1rem; font-weight: 650; }
.sheet-body { overflow-y: auto; padding-inline: 16px; padding-block-end: 16px; }

.sheet .action {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  min-height: 52px;
  padding-inline: 14px;
  border-radius: var(--r-m);
  font-size: 0.9375rem;
  color: var(--text-1);
  text-align: start;
}

.sheet .action:hover { background: var(--surface-2); }
.sheet .action.danger { color: var(--danger); }

/* ==========================================================================
   Chat
   ========================================================================== */

.chat-col { position: relative; }

.thread {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-block: 12px 16px;
  padding-inline: 12px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.thread .day-sep {
  align-self: center;
  font-size: 0.6875rem;
  color: var(--faint);
  background: var(--surface-2);
  padding-block: 3px;
  padding-inline: 10px;
  border-radius: var(--r-full);
}

.msg { display: flex; flex-direction: column; max-width: 100%; }
.msg.user { align-items: flex-end; }
.msg.assistant { align-items: flex-start; }

.bubble {
  max-width: 88%;
  border-radius: var(--r-l);
  padding-block: 10px;
  padding-inline: 14px;
  font-size: 0.9375rem;
  line-height: 1.6;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  user-select: text;
}

.msg.user .bubble {
  background: var(--user-bubble);
  color: var(--user-bubble-text);
  border-end-end-radius: var(--r-s);
}

.msg.assistant .bubble {
  background: var(--surface-1);
  border: 1px solid var(--hairline);
  border-end-start-radius: var(--r-s);
  white-space: normal;
}

.bubble .caret {
  display: inline-block;
  width: 8px;
  height: 1.05em;
  vertical-align: text-bottom;
  margin-inline-start: 2px;
  background: var(--accent);
  border-radius: 2px;
  animation: caret-blink 1s steps(1) infinite;
}

@keyframes caret-blink { 50% { opacity: 0; } }

.msg-meta { display: flex; align-items: center; gap: 6px; margin-block-start: 6px; flex-wrap: wrap; }

.msg.error .bubble { border-color: var(--danger); background: var(--danger-soft); color: var(--danger); }

.msg-actions {
  position: relative;
}

.typing { display: inline-flex; gap: 4px; align-items: center; padding-block: 2px; }
.typing i {
  width: 6px;
  height: 6px;
  border-radius: var(--r-full);
  background: var(--muted);
  animation: dot-pulse 1.2s var(--ease) infinite;
}
.typing i:nth-child(2) { animation-delay: 0.15s; }
.typing i:nth-child(3) { animation-delay: 0.3s; }

@keyframes dot-pulse {
  0%, 60%, 100% { opacity: 0.35; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-2px); }
}

.search-row {
  display: flex;
  align-items: center;
  gap: 8px;
  align-self: flex-start;
  font-size: 0.8125rem;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--hairline);
  border-radius: var(--r-full);
  padding-block: 7px;
  padding-inline: 14px;
}

.spin { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.latest-pill {
  position: absolute;
  inset-inline-end: 14px;
  bottom: 14px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 40px;
  padding-inline: 14px;
  border-radius: var(--r-full);
  background: var(--surface-3);
  border: 1px solid var(--border);
  color: var(--text-1);
  font-size: 0.8125rem;
  font-weight: 600;
  box-shadow: var(--shadow-2);
  z-index: 6;
}

/* Composer */

.composer {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  padding-block: 8px calc(max(env(safe-area-inset-bottom), 8px));
  padding-inline: 10px;
  background: var(--bg);
  border-block-start: 1px solid var(--hairline);
}

.kb-open .composer { padding-block-end: 8px; }

.composer .input-wrap {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: flex-end;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--r-l);
  padding-block: 4px;
  padding-inline: 6px;
  transition: border-color var(--dur-1) var(--ease);
}

.composer .input-wrap:focus-within { border-color: var(--accent-line); }

.input-hint {
  position: absolute;
  inset-inline-start: 18px;
  inset-block-start: 50%;
  transform: translateY(-50%);
  color: var(--faint);
  font-size: 1rem;
  line-height: 1;
  pointer-events: none;
  white-space: nowrap;
  overflow: hidden;
  max-width: 82%;
}

.composer textarea {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  resize: none;
  max-height: 132px;
  padding-block: 10px;
  padding-inline: 8px;
  font-size: 1rem;
  line-height: 1.45;
}

.composer textarea:focus-visible { outline: none; }

.composer .attach-strip { display: flex; gap: 6px; padding-block-end: 6px; padding-inline: 10px; flex-wrap: wrap; }
.attach-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--hairline);
  border-radius: var(--r-m);
  padding: 4px;
  font-size: 0.75rem;
  color: var(--text-2);
}
.attach-chip img { width: 40px; height: 40px; border-radius: var(--r-s); object-fit: cover; display: block; }

.send-btn {
  width: 48px;
  height: 48px;
  min-width: 48px;
  border-radius: var(--r-full);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: var(--accent-ink);
  transition: transform var(--dur-1) var(--ease), opacity var(--dur-1) var(--ease);
}

.send-btn:active { transform: scale(0.94); }
.send-btn[disabled] { opacity: 0.4; pointer-events: none; }
.send-btn.is-stop { background: var(--surface-3); color: var(--text-1); }

/* Markdown inside assistant bubbles */

.md > * + * { margin-block-start: 0.7em; }
.md h1 { font-size: 1.25rem; font-weight: 700; line-height: 1.3; }
.md h2 { font-size: 1.125rem; font-weight: 680; line-height: 1.3; }
.md h3 { font-size: 1rem; font-weight: 660; }
.md ul, .md ol { padding-inline-start: 1.35em; margin-block: 0.4em; }
.md li { margin-block: 0.18em; }
.md blockquote {
  border-inline-start: 3px solid var(--accent-line);
  padding-inline-start: 10px;
  color: var(--text-2);
}
.md code.inline {
  font-family: var(--font-mono);
  font-size: 0.8125em;
  background: var(--surface-3);
  border-radius: 5px;
  padding-block: 2px;
  padding-inline: 5px;
}
.md pre {
  background: var(--surface-2);
  border: 1px solid var(--hairline);
  border-radius: var(--r-m);
  padding: 12px;
  overflow-x: auto;
  direction: ltr;
  text-align: start;
}
.md pre code { font-family: var(--font-mono); font-size: 0.8125rem; line-height: 1.5; }
.md hr { border: 0; border-block-start: 1px solid var(--hairline); margin-block: 0.8em; }
.md a { word-break: break-all; }

/* ==========================================================================
   Screens: setup / auth / onboarding
   ========================================================================== */

.center-screen {
  min-height: var(--app-height);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 24px;
  padding-block-start: max(env(safe-area-inset-top), 24px);
  padding-block-end: max(env(safe-area-inset-bottom), 24px);
}

.center-card {
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.brand-mark {
  width: 64px;
  height: 64px;
  border-radius: 18px;
  box-shadow: var(--shadow-2);
  align-self: center;
}

.brand-name { font-size: 1.625rem; font-weight: 750; letter-spacing: -0.02em; text-align: center; }
.brand-tag { text-align: center; color: var(--muted); font-size: 0.9375rem; margin-block-start: -8px; }

.steps-dots { display: flex; gap: 6px; justify-content: center; }
.steps-dots i {
  width: 8px;
  height: 8px;
  border-radius: var(--r-full);
  background: var(--surface-3);
  transition: all var(--dur-1) var(--ease);
}
.steps-dots i.is-on { background: var(--accent); width: 22px; }

.option-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.option-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: flex-start;
  text-align: start;
  min-height: 76px;
  padding: 12px;
  border-radius: var(--r-m);
  background: var(--surface-1);
  border: 1.5px solid var(--border);
  transition: all var(--dur-1) var(--ease);
}

.option-card .opt-title { font-weight: 650; font-size: 0.9375rem; }
.option-card .opt-sub { font-size: 0.75rem; color: var(--muted); line-height: 1.4; }
.option-card.is-on { border-color: var(--accent); background: var(--accent-soft); }

.skip-link {
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 0.875rem;
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* ==========================================================================
   Misc
   ========================================================================== */

.skeleton {
  border-radius: var(--r-m);
  background: linear-gradient(100deg, var(--surface-2) 40%, var(--surface-3) 50%, var(--surface-2) 60%);
  background-size: 200% 100%;
  animation: shimmer 1.4s linear infinite;
  min-height: 16px;
}

@keyframes shimmer { to { background-position: -200% 0; } }

.noscript {
  padding: 32px;
  font-family: system-ui, sans-serif;
  color: #f2f6f9;
  background: #0b0f14;
  min-height: 100dvh;
}

.pre-wrap { white-space: pre-wrap; overflow-wrap: anywhere; }

.kv { display: flex; justify-content: space-between; gap: 12px; font-size: 0.8125rem; padding-block: 6px; }
.kv .k { color: var(--muted); }

.divider { height: 1px; background: var(--hairline); margin-block: 14px; border: 0; }

details.acc {
  border: 1px solid var(--hairline);
  border-radius: var(--r-m);
  background: var(--surface-1);
  margin-block-end: 10px;
  overflow: hidden;
}

details.acc > summary {
  list-style: none;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 52px;
  padding-inline: 14px;
  cursor: pointer;
  font-weight: 620;
  font-size: 0.9375rem;
}

details.acc > summary::-webkit-details-marker { display: none; }
details.acc > summary .chev { margin-inline-start: auto; transition: transform var(--dur-1) var(--ease); color: var(--muted); }
details.acc[open] > summary .chev { transform: rotate(90deg); }
[dir="rtl"] details.acc[open] > summary .chev { transform: rotate(-90deg); }
details.acc .acc-body { padding-inline: 14px; padding-block-end: 14px; }

.tool-result-pill {
  font-size: 0.75rem;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--hairline);
  border-radius: var(--r-full);
  padding-block: 4px;
  padding-inline: 10px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.fade-top { position: relative; }
.fade-top::before {
  content: "";
  position: absolute;
  inset-inline: 0;
  top: 0;
  height: 24px;
  background: linear-gradient(to bottom, var(--bg), transparent);
  pointer-events: none;
  z-index: 4;
}
