/* ============================================================
   Hoshana Design System V2 · Foundation
   Semantic tokens · Persian-first RTL · Neutral + intentional blue
   ============================================================ */

:root {
  /* Color — Light (overridden for default dark below) */
  --color-bg: #f3f5f8;
  --color-bg-elevated: #f8f9fb;
  --color-surface: #fbfcfd;
  --color-surface-subtle: #eef1f5;
  --color-surface-hover: #e8edf4;
  --color-surface-active: #e1e8f2;
  --color-text: #16202e;
  --color-text-secondary: #2a3a52;
  --color-text-muted: #526074;
  --color-text-inverse: #f8fafc;
  --color-border: #dfe5ee;
  --color-border-subtle: #e8edf4;
  --color-border-strong: #c5d0de;
  --color-primary: #2563eb;
  --color-primary-hover: #1d4fd7;
  --color-primary-active: #1e40af;
  --color-primary-subtle: #e8effc;
  --color-primary-ink: #174ea6;
  --color-danger: #dc2626;
  --color-danger-subtle: #fee2e2;
  --color-success: #16a34a;
  --color-success-subtle: #dcfce7;
  --color-warning: #d97706;
  --color-online: #16a34a;

  /* Typography */
  --font-sans: "Vazirmatn", "Segoe UI", Tahoma, system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --text-display: 2.5rem;
  --text-page-title: 1.625rem;
  --text-section: 1.2rem;
  --text-body: 0.9375rem;
  --text-body-strong: 0.9375rem;
  --text-small: 0.8125rem;
  --text-caption: 0.75rem;
  --text-meta: 0.75rem;
  --text-button: 0.875rem;
  --text-code: 0.8125rem;
  --leading-display: 1.35;
  --leading-title: 1.4;
  --leading-body: 1.85;
  --leading-reading: 2;
  --weight-regular: 400;
  --weight-medium: 500;
  --weight-semibold: 600;
  --weight-bold: 700;

  /* Content widths */
  --content-reading: 860px;
  --content-page: 1040px;
  --content-wide: 1200px;
  --chat-content-width: 860px;

  /* Spacing scale */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;
  --space-12: 48px;
  --space-16: 64px;
  --page-pad: var(--space-6);
  --section-gap: var(--space-6);
  --row-gap: var(--space-2);
  --card-pad: var(--space-5);
  --toolbar-gap: var(--space-3);
  --field-gap: var(--space-2);
  --sidebar-gap: var(--space-2);

  /* Radius */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 18px;
  --radius: var(--radius-md);

  /* Border */
  --border-subtle: 1px solid var(--color-border-subtle);
  --border-default: 1px solid var(--color-border);
  --border-strong: 1px solid var(--color-border-strong);

  /* Shadow — overlays only */
  --shadow-sm: 0 1px 2px rgba(22, 32, 46, 0.06);
  --shadow-md: 0 8px 24px rgba(22, 32, 46, 0.08);
  --shadow-overlay: 0 16px 40px rgba(22, 32, 46, 0.12);
  --shadow: var(--shadow-md);
  --shadow-lg: var(--shadow-overlay);
  --shadow-glow: none;

  /* Control heights / icons */
  --control-sm: 32px;
  --control-md: 40px;
  --control-lg: 48px;
  --icon-xs: 14px;
  --icon-sm: 16px;
  --icon-md: 18px;
  --icon-lg: 20px;
  --icon-xl: 24px;

  /* Motion */
  --ease: cubic-bezier(.22, 1, .36, 1);
  --motion-fast: 120ms;
  --motion-normal: 180ms;
  --motion-slow: 240ms;
  --duration: var(--motion-normal);

  /* Z-index */
  --z-base: 1;
  --z-sticky: 40;
  --z-dropdown: 50;
  --z-popover: 70;
  --z-modal: 200;
  --z-toast: 300;

  /* Layout (geometry contracts — do not change) */
  --sidebar-w: 260px;
  --nav-h: 56px;

  /* Legacy aliases — keep existing selectors working */
  --bg: var(--color-bg);
  --bg-elevated: var(--color-bg-elevated);
  --bg2: var(--color-surface-subtle);
  --card: var(--color-surface);
  --card-hover: var(--color-surface-hover);
  --line: var(--color-border);
  --line-soft: var(--color-border-subtle);
  --text: var(--color-text);
  --text-secondary: var(--color-text-secondary);
  --muted: var(--color-text-muted);
  --accent: var(--color-primary);
  --accent-2: var(--color-primary-hover);
  --accent-soft: var(--color-primary-subtle);
  --accent-dim: var(--color-primary-subtle);
  --accent-glow: color-mix(in srgb, var(--color-primary) 18%, transparent);
  --accent-ink: var(--color-primary-ink);
  --online: var(--color-online);
  --success: var(--color-success);
  --success-dim: var(--color-success-subtle);
  --danger: var(--color-danger);
  --danger-dim: var(--color-danger-subtle);
  --warning: var(--color-warning);
  --grad: var(--color-primary);
  --grad-soft: var(--color-primary-subtle);
  --grad-hero: none;
  --surface: var(--color-surface);
  --border: var(--color-border);
}

:root[data-theme="dark"],
:root:not([data-theme="light"]) {
  --color-bg: #0e141f;
  --color-bg-elevated: #131b2a;
  --color-surface: #161f31;
  --color-surface-subtle: #121a28;
  --color-surface-hover: #1c2740;
  --color-surface-active: #223050;
  --color-text: #e8eef7;
  --color-text-secondary: #c5d0e0;
  --color-text-muted: #8b98ab;
  --color-text-inverse: #0e141f;
  --color-border: #243044;
  --color-border-subtle: #1c2638;
  --color-border-strong: #33445c;
  --color-primary: #4d9fff;
  --color-primary-hover: #6eb0ff;
  --color-primary-active: #3b8ef0;
  --color-primary-subtle: #15243a;
  --color-primary-ink: #a9d0ff;
  --color-danger: #f87171;
  --color-danger-subtle: rgba(248, 113, 113, 0.12);
  --color-success: #34d399;
  --color-success-subtle: rgba(52, 211, 153, 0.12);
  --color-warning: #fbbf24;
  --color-online: #34d399;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.22);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.28);
  --shadow-overlay: 0 16px 40px rgba(0, 0, 0, 0.4);
}

/* ============================================================
   Reset & Base
   ============================================================ */
@font-face{font-family:"Vazirmatn"; src:url("/static/fonts/vazirmatn-fa-400.woff2") format("woff2"); font-weight:400; font-display:swap; ascent-override:80%; descent-override:30%; line-gap-override:0%; unicode-range: U+0020, U+00A0, U+0600-06FF, U+06F0-06F9, U+200C-200F, U+FB50-FDFF, U+0750-077F}
@font-face{font-family:"Vazirmatn"; src:url("/static/fonts/vazirmatn-fa-700.woff2") format("woff2"); font-weight:700; font-display:swap; ascent-override:80%; descent-override:30%; line-gap-override:0%; unicode-range: U+0020, U+00A0, U+0600-06FF, U+06F0-06F9, U+200C-200F, U+FB50-FDFF, U+0750-077F}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: clip;
}

body {
  font-family: var(--font-sans);
  background: var(--color-bg);
  color: var(--color-text);
  direction: rtl;
  line-height: var(--leading-body);
  min-height: 100vh;
  overflow-x: clip;
  font-size: var(--text-body);
  font-weight: var(--weight-regular);
}
.msg .stream-text, .msg { line-height: var(--leading-reading); font-size: var(--text-body); }
h1 { font-weight: var(--weight-bold); letter-spacing: -0.01em; }

[dir="ltr"] { direction: ltr; }

a {
  color: var(--accent-soft);
  text-decoration: none;
  transition: color var(--duration) var(--ease);
}
a:hover { color: var(--accent); }

img { max-width: 100%; display: block; }
button, input, textarea, select { font-family: inherit; }
code, .mono {
  font-family: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
  direction: ltr;
  unicode-bidi: embed;
}

.container {
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 24px;
}

.hidden, [hidden] { display: none !important; }
.center { text-align: center; }

/* ============================================================
   Typography
   ============================================================ */
h1, h2, h3, h4 {
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.35;
  color: var(--text);
}

.section-title {
  font-size: clamp(1.5rem, 3vw, 1.9rem);
  margin-bottom: 8px;
}
.section-sub {
  color: var(--muted);
  font-size: .95rem;
  margin-bottom: 36px;
}

/* ============================================================
   Buttons
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  height: var(--control-md);
  padding: 0 16px;
  line-height: 1;
  text-align: center;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  font-size: var(--text-button);
  font-weight: var(--weight-semibold);
  transition: background var(--duration) var(--ease),
              border-color var(--duration) var(--ease),
              color var(--duration) var(--ease),
              opacity var(--duration) var(--ease);
  white-space: nowrap;
  user-select: none;
}
.btn:active { background: var(--color-surface-active); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.btn-primary {
  background: var(--color-primary);
  color: var(--color-text-inverse);
  box-shadow: none;
}
.btn-primary:hover {
  background: var(--color-primary-hover);
  box-shadow: none;
}
.btn-primary:active { background: var(--color-primary-active); }

.btn-ghost,
.btn-secondary {
  background: transparent;
  color: var(--color-text-secondary);
  border: 1px solid var(--color-border);
}
.btn-ghost:hover,
.btn-secondary:hover {
  background: var(--color-surface-hover);
  border-color: var(--color-border-strong);
  color: var(--color-text);
}

.btn-plain {
  background: var(--text);
  color: var(--bg);
  padding: 0 20px;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  font-weight: 600;
  font-size: .9rem;
  transition: opacity var(--duration);
}
.btn-plain:hover { opacity: .88; }

.btn-sm {
  height: var(--control-sm);
  padding: 0 12px;
  font-size: var(--text-small);
  border-radius: var(--radius-sm);
}

.btn-lg { height: var(--control-lg); padding: 0 22px; font-size: var(--text-body, 1rem); }

.btn-icon {
  width: var(--control-md);
  height: var(--control-md);
  padding: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  border: 1px solid transparent;
  color: var(--color-text-muted);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background var(--duration) var(--ease), color var(--duration) var(--ease);
}
.btn-icon:hover {
  background: var(--color-surface-hover);
  color: var(--color-text);
  border-color: transparent;
}

/* ============================================================
   Cards
   ============================================================ */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius-md);
  padding: var(--card-pad);
  box-shadow: none;
  transition: border-color var(--duration), background var(--duration);
}
.card:hover { border-color: var(--color-border); background: var(--color-surface); }

/* ============================================================
   Form elements
   ============================================================ */
.input, textarea.input, select.input {
  width: 100%;
  min-height: var(--control-md);
  background: var(--color-surface-subtle);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  color: var(--color-text);
  padding: 8px 12px;
  font-size: var(--text-body);
  outline: none;
  transition: border-color var(--duration), box-shadow var(--duration);
}
.input:hover, textarea.input:hover, select.input:hover {
  border-color: var(--color-border-strong);
}
.input:focus, textarea.input:focus, select.input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-subtle);
}
.input::placeholder { color: var(--muted); }

label {
  display: block;
  font-size: .85rem;
  color: var(--muted);
  margin-bottom: 6px;
  font-weight: 500;
}

/* ============================================================
   Navigation (Landing)
   ============================================================ */
.nav {
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-border-subtle);
}
[data-theme="light"] .nav {
  background: var(--color-bg);
}

.nav-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--nav-h);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 1.12rem;
  color: var(--text);
  letter-spacing: -0.02em;
}
.brand .logo-img {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  object-fit: cover;
  box-shadow: 0 2px 10px rgba(107,147,255,.25);
}

.nav-links {
  display: flex;
  gap: 8px;
  align-items: center;
}
.nav-links a:not(.btn) {
  color: var(--muted);
  font-size: .9rem;
  padding: 6px 12px;
  border-radius: 8px;
  transition: color var(--duration), background var(--duration);
}
.nav-links a:not(.btn):hover {
  color: var(--text);
  background: var(--accent-dim);
}
.nav-burger{display:none;align-items:center;justify-content:center;width:36px;height:36px;border:1px solid var(--line);background:var(--card);border-radius:8px;color:var(--text);cursor:pointer}
.nav-cta{display:flex;gap:8px;align-items:center}
.nav-drawer{position:fixed;inset-inline:0;top:64px;background:var(--surface, var(--bg-elevated));border-bottom:1px solid var(--border, var(--line));padding:16px 24px;display:flex;flex-direction:column;gap:4px;transform:translateY(-8px);opacity:0;pointer-events:none;transition:.2s;z-index:60}
.nav-drawer a{display:block;padding:10px 0;color:var(--text);font-size:.95rem}
.nav-drawer.open{transform:none;opacity:1;pointer-events:auto}
.drawer-cta{display:flex;flex-direction:column;gap:8px;margin-top:10px}
@media (max-width: 860px) {.nav-links,.nav-cta{display: none !important}.nav-burger{display: flex !important}}
@media(display-mode:standalone){#installBtn{display:none}}

/* ============================================================
   Hero
   ============================================================ */
.hero-gpt {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: center;
  padding: 100px clamp(24px, 8vw, 120px) 90px;
  background: var(--grad-hero);
  min-height: calc(100vh - var(--nav-h) - 80px);
}
.hero-gpt > * { max-width: 680px; }

.hero-gpt h1 {
  font-size: clamp(1.7rem, 3.6vw, 2.55rem);
  font-weight: 800;
  line-height: 1.55;
  max-width: 640px;
  margin-bottom: 4px;
}
.hero-gpt h1 em {
  font-style: normal;
  background: var(--grad);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.hero-gpt p.tag {
  color: var(--muted);
  margin: 14px 0 28px;
  font-size: 1.02rem;
  max-width: 520px;
  line-height: 1.75;
}

/* Prompt box */
.prompt-box {
  width: 100%;
  max-width: 660px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 16px 18px 12px;
  text-align: right;
  transition: border-color var(--duration), box-shadow var(--duration);
  box-shadow: var(--shadow-sm);
}
.prompt-box:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim), var(--shadow);
}
.prompt-box textarea {
  width: 100%;
  border: none;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: .98rem;
  outline: none;
  resize: none;
  min-height: 52px;
  line-height: 1.6;
}
.prompt-box textarea::placeholder { color: var(--muted); }
.prompt-box .row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 8px;
}
.prompt-hint {
  color: var(--muted);
  font-size: .75rem;
}

/* Facts */
.facts {
  margin-top: 52px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  max-width: 660px;
}
.fact {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 16px 18px;
  background: var(--card);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  transition: border-color var(--duration), transform var(--duration);
}
.fact:hover {
  border-color: var(--line);
  transform: translateY(-2px);
}
.fact b {
  font-size: .9rem;
  color: var(--text);
  font-weight: 700;
}
.fact span {
  font-size: .84rem;
  color: var(--muted);
  line-height: 1.65;
}
.fact code {
  font-size: .78rem;
  background: var(--bg2);
  padding: 1px 6px;
  border-radius: 5px;
  color: var(--accent-soft);
}

/* ============================================================
   Pricing
   ============================================================ */
.section {
  padding-block: 72px;
}
.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 18px;
}

.price-card {
  position: relative;
  display: flex;
  flex-direction: column;
  padding: 28px 24px;
  transition: transform var(--duration) var(--ease),
              border-color var(--duration),
              box-shadow var(--duration);
}
.price-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow);
}
.price-card.featured {
  border-color: var(--accent);
  background: linear-gradient(180deg, rgba(107,147,255,.08) 0%, var(--card) 40%);
  box-shadow: var(--shadow-glow);
}
.price-card .badge {
  position: absolute;
  top: -11px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--grad);
  color: #fff;
  font-size: .72rem;
  font-weight: 700;
  padding: 4px 14px;
  border-radius: 20px;
  letter-spacing: .02em;
  white-space: nowrap;
}
.price-card h3 {
  font-size: 1.15rem;
  margin-bottom: 10px;
}
.price-card .price {
  font-size: 2.1rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin-bottom: 6px;
}
.price-card .price small {
  font-size: .82rem;
  font-weight: 500;
  color: var(--muted);
  letter-spacing: 0;
}
.price-card ul {
  list-style: none;
  margin: 18px 0 24px;
  flex: 1;
}
.price-card li {
  font-size: .88rem;
  padding: 6px 0;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-secondary);
}
.price-card li.ok::before {
  content: "";
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  background: var(--success-dim);
  border-radius: 50%;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='%2334d399'%3E%3Cpath d='M12.2 5.2a.75.75 0 01.08 1.06l-4.25 5a.75.75 0 01-1.1.04L4.2 8.7a.75.75 0 011.1-1.02l2.15 2.3 3.7-4.36a.75.75 0 011.06-.08z'/%3E%3C/svg%3E");
  background-size: 16px;
  background-repeat: no-repeat;
}
.price-card li.no {
  color: var(--muted);
  opacity: .65;
}
.price-card li.no::before {
  content: "";
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  background: rgba(122,132,158,.12);
  border-radius: 50%;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='%237a849e'%3E%3Cpath d='M4.28 3.22a.75.75 0 00-1.06 1.06L6.94 8l-3.72 3.72a.75.75 0 101.06 1.06L8 9.06l3.72 3.72a.75.75 0 101.06-1.06L9.06 8l3.72-3.72a.75.75 0 00-1.06-1.06L8 6.94 4.28 3.22z'/%3E%3C/svg%3E");
  background-size: 16px;
  background-repeat: no-repeat;
}

/* ============================================================
   Footer
   ============================================================ */
.footer {
  border-top: 1px solid var(--line-soft);
  padding: 28px 0;
  color: var(--muted);
  font-size: .85rem;
  margin-top: 20px;
}
.footer a { color: var(--muted); }
.footer a:hover { color: var(--accent-soft); }

/* ============================================================
   Auth / Login
   ============================================================ */
.auth-page {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
  padding-top: calc(24px + env(safe-area-inset-top));
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
  position: relative;
  overflow-x: clip;
}
.auth-page::before,
.auth-page::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  filter: blur(120px);
  opacity: .14;
  pointer-events: none;
}
.auth-page::before {
  width: 520px; height: 520px;
  background: #6b93ff;
  top: -180px; left: -140px;
}
.auth-page::after {
  width: 460px; height: 460px;
  background: #3b63d8;
  bottom: -200px; right: -160px;
}

.auth-card {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 440px;
  padding: 44px 36px 36px;
  border-radius: var(--radius-xl);
  background: var(--card);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-lg);
  animation: cardIn .55s var(--ease) both;
}
@keyframes cardIn {
  from { opacity: 0; transform: translateY(18px) scale(.97); }
  to   { opacity: 1; transform: none; }
}

.auth-card .brand {
  justify-content: center;
  margin-bottom: 28px;
}
.auth-card .logo-img {
  width: 42px; height: 42px;
  border-radius: 12px;
  box-shadow: 0 4px 16px var(--accent-glow);
}
.auth-card h2 {
  font-size: 1.4rem;
  font-weight: 800;
  margin-bottom: 10px;
  text-align: center;
}
.auth-card .sub {
  color: var(--muted);
  font-size: .92rem;
  line-height: 1.85;
  margin-bottom: 28px;
  text-align: center;
}

.google-btn {
  white-space: nowrap;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: #fff;
  color: #1f2937;
  padding: 14px;
  border-radius: 13px;
  font-weight: 700;
  font-size: .98rem;
  border: none;
  cursor: pointer;
  transition: transform .14s var(--ease), box-shadow .2s;
}
.google-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 28px rgba(255,255,255,.1);
}
.google-btn:active { transform: none; }
.g-logo { width: 20px; height: 20px; flex-shrink: 0; display: block; }

.auth-note {
  color: var(--muted);
  font-size: .78rem;
  margin-top: 22px;
  text-align: center;
  line-height: 1.8;
}
.auth-err {
  background: var(--danger-dim);
  border: 1px solid rgba(248,113,113,.35);
  color: var(--danger);
  padding: 10px 14px;
  border-radius: 10px;
  font-size: .85rem;
  margin-bottom: 18px;
  text-align: center;
}

/* ============================================================
   App Shell (Panel) · Claude-inspired: hairline, calm
   ============================================================ */
.app-shell {
  display: flex;
  height: 100%;
  max-height: 100%;
  min-height: 0;
  overflow: hidden;
  box-sizing: border-box;
  /* The shell owns safe areas once, inside its viewport-sized border box. */
  padding-block: env(safe-area-inset-top) env(safe-area-inset-bottom);
}
.app-root.ios-viewport .app-shell {
  padding-bottom: var(--ios-safe-bottom, env(safe-area-inset-bottom));
}

/* Sidebar · warm, hairline, conversation-first */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg2);
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 12px 10px;
  gap: 4px;
  overflow-y: auto;
  z-index: 40;
}
.sidebar .brand {
  margin-bottom: 14px;
  padding: 4px 6px;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  background: var(--card);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  margin-bottom: 14px;
}
.user-chip img {
  width: 36px; height: 36px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}
.user-chip .nm {
  font-size: .88rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 110px;
}
.user-chip .em {
  font-size: .72rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 110px;
}
.plan-pill {
  margin-inline-start: auto;
  font-size: .68rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 20px;
  background: var(--accent-dim);
  color: var(--accent-soft);
  white-space: nowrap;
}

.side-link {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 4px 8px;
  min-height: 30px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: .86rem;
  font-weight: 500;
  border-radius: 8px;
  cursor: pointer;
  text-align: right;
}
.side-link:hover {
  background: var(--accent-dim);
  color: var(--text);
}
.side-link.active {
  background: var(--accent-dim);
  color: var(--accent-soft);
  font-weight: 600;
}
.side-link .icon {
  width: 18px;
  height: 18px;
  opacity: .85;
  flex-shrink: 0;
}

.side-divider {
  height: 1px;
  background: var(--line-soft);
  margin: 10px 6px;
}

/* Main pane */
.chat-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  max-height: 100%;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
  background: var(--bg);
  position: relative;
}

.chat-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
  min-height: 52px;
  position: relative; /* anchor for header menu + model popover */
}
.chat-head strong {
  font-size: .95rem;
  font-weight: 700;
}
.menu-btn {
  display: none;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--text);
  width: 36px; height: 36px;
  border-radius: 9px;
  cursor: pointer;
  font-size: 1.1rem;
  place-items: center;
}

/* Chat log */
.chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
  align-items: stretch;
}
/* B5: dark thin scrollbar */
.chat-log { scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
.chat-log::-webkit-scrollbar { width: 8px; }
.chat-log::-webkit-scrollbar-thumb { background: var(--line); border-radius: 8px; }
.chat-log::-webkit-scrollbar-track { background: transparent; }
.history-list { max-width: 720px; display: grid; gap: 2px; }
.history-list .card { background: transparent !important; border: 0 !important; border-bottom: 1px solid var(--line) !important; border-radius: 0 !important; padding: 14px 4px !important; box-shadow: none !important; }
.history-list .msg-actions { opacity: .65; }
.history-list .card:hover { background: color-mix(in srgb, var(--accent) 5%, transparent) !important; }
.msg {
  max-width: 100%;
  padding: 10px 0;
  font-size: 15.5px;
  line-height: 2;
  word-break: break-word;
}
.msg.user {
  background: var(--accent-soft) !important;
  color: var(--text);
  text-align: start;
  border: 1px solid var(--line) !important;
  border-radius: 16px 16px 4px 16px;
  padding: 10px 16px;
  margin-inline-start: auto;
  width: fit-content;
  max-width: min(85%, 560px);
  align-self: flex-end;
  line-height: 1.9;
  min-height: 0;
  height: auto;
}
.msg-actions { opacity: 0; transition: opacity .15s; gap: 6px; display: flex; flex-wrap: wrap; margin-top: 8px; }
.msg:hover .msg-actions { opacity: 1; }
.msg-actions button {
  font-size: .72rem; padding: 4px 10px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--card); color: var(--muted); cursor: pointer;
}
.msg-actions button:hover { border-color: var(--accent); color: var(--text); }

/* Composer · Claude rounded */
.chat-input {
  padding: 12px 16px;
  border-top: 1px solid var(--line);
  background: var(--bg);
  position: static;
  background: linear-gradient(to top, var(--bg) 72%, transparent);
}
.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 8px 10px;
  max-width: 720px;
  margin: 0 auto;
}
.composer:focus-within { border-color: var(--accent); }
.composer textarea {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: .93rem;
  outline: none;
  resize: none;
  min-height: 40px;
  max-height: 140px;
  padding: 8px 4px;
  line-height: 1.7;
}
.composer textarea::placeholder { color: var(--muted); }
.attach-btn, .send-btn {
  width: 34px; height: 34px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.attach-btn {
  background: transparent;
  color: var(--muted);
}
.attach-btn:hover { color: var(--accent); background: var(--accent-dim); }
.send-btn {
  background: var(--accent);
  color: #fff;
}
.send-btn:hover { opacity: .88; }
.send-btn:disabled { opacity: .4; cursor: default; }
.composer-caption { text-align: center; font-size: .7rem; color: var(--muted); margin-top: 8px; }

/* Views (non-chat) */
.view-pad {
  padding: 28px 28px 40px;
  overflow-y: auto;
  height: 100%;
}
.view-pad h2 {
  font-size: 1.35rem;
  margin-bottom: 6px;
}
.view-desc {
  color: var(--muted);
  font-size: .9rem;
  margin-bottom: 24px;
}

/* Usage grid */
.usage-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--card);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.stat-num {
  font-size: 1.55rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}
.stat-label {
  color: var(--muted);
  font-size: .8rem;
  margin-top: 2px;
}

/* The reading region owns chat scrolling within the constrained shell. */
.chat-log{flex:1; overflow-y:auto; overscroll-behavior:contain; -webkit-overflow-scrolling:touch}
.hist-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--card);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  margin-bottom: 8px;
  cursor: pointer;
  transition: border-color var(--duration), background var(--duration);
}
.hist-item:hover {
  border-color: var(--line);
  background: var(--card-hover);
}
.hist-item .title {
  flex: 1;
  font-size: .9rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.hist-item .meta {
  font-size: .75rem;
  color: var(--muted);
  white-space: nowrap;
}

/* Toast: see the WS4 block at the end of this file (single component) */

/* --- Phase2: starter chips, typing, stop, sidebar history, email truncation --- */
.user-chip .em{max-width:150px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;direction:ltr;display:inline-block;vertical-align:middle}
.sidebar-history{flex:0 0 auto;min-height:40px;margin:10px 0 14px;border:1px solid var(--line-soft);border-radius:10px;background:var(--bg2);max-height:32vh;overflow-y:auto;padding:6px;scrollbar-width:thin;scrollbar-color:var(--line) transparent}
.sidebar-history::-webkit-scrollbar{width:6px}
.sidebar-history::-webkit-scrollbar-thumb{background:var(--line);border-radius:8px}
.sidebar-history::-webkit-scrollbar-track{background:transparent}
.sidebar-history::-webkit-scrollbar-button{display:none}
.sidebar-history:empty{display:none}
.sidebar-history .sh-head{font-size:.72rem;color:var(--muted);padding:4px 8px 6px;display:flex;justify-content:space-between;align-items:center}
.sidebar-history .sh-item{display:flex;align-items:center;gap:8px;padding:7px 8px;border-radius:8px;cursor:pointer;font-size:.82rem;color:var(--text-secondary);transition:background .15s}
.sidebar-history .sh-item:hover{background:var(--accent-soft)}
.sidebar-history .sh-item.active{background:var(--accent-soft);color:var(--accent);box-shadow:inset 3px 0 0 var(--accent)}
.sidebar-history .sh-item .sh-title{flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-weight:600}
#starterChips{display:flex;flex-direction:column;align-items:center;gap:16px;padding:34px 18px 18px;text-align:center}
#starterChips.hidden{display:none!important}
#starterChips .starter-title{font-weight:700;font-size:1rem;color:var(--text)}
.chips-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(180px,1fr));gap:10px;max-width:680px;width:100%}
.chip{background:var(--card);border:1px solid var(--line);border-radius:14px;padding:12px 14px;cursor:pointer;transition:transform .18s,border-color .18s,box-shadow .18s,background .18s;text-align:right;font-size:.86rem;line-height:1.5;color:var(--text);animation:chipIn .4s both}
.chip:nth-child(2){animation-delay:.05s}.chip:nth-child(3){animation-delay:.1s}.chip:nth-child(4){animation-delay:.15s}.chip:nth-child(5){animation-delay:.2s}.chip:nth-child(6){animation-delay:.25s}
.chip:hover{border-color:var(--accent);background:var(--accent-soft);transform:translateY(-2px);box-shadow:var(--shadow-sm)}
@keyframes chipIn{from{opacity:0;transform:translateY(8px)}to{opacity:1;transform:none}}
.typing-indicator{display:flex;align-items:center;gap:10px;padding:10px 14px;background:var(--card);border:1px solid var(--line-soft);border-radius:12px;margin:10px 16px;width:fit-content}
.typing-indicator.hidden{display:none!important}
.typing-dots span{display:inline-block;width:7px;height:7px;border-radius:50%;background:var(--accent);animation:typingBounce 1.2s infinite}
.typing-dots span:nth-child(2){animation-delay:.2s}
.typing-dots span:nth-child(3){animation-delay:.4s}
@keyframes typingBounce{0%,60%,100%{transform:translateY(0);opacity:.45}30%{transform:translateY(-6px);opacity:1}}
.msg{animation:msgIn .25s ease}
@keyframes msgIn{from{opacity:0;transform:translateY(6px)}to{opacity:1;transform:none}}
/* Brand glow · logo only */
.brand .logo-img, .logo-img{box-shadow:0 0 0 1px var(--line), 0 0 18px rgba(77,159,255,.35);border-radius:12px;animation:brandPulse 3.5s ease-in-out infinite}
@keyframes brandPulse{0%,100%{box-shadow:0 0 0 1px var(--line), 0 0 14px rgba(77,159,255,.25)}50%{box-shadow:0 0 0 1px var(--line), 0 0 22px rgba(77,159,255,.45)}}
.presence-dot{width:8px;height:8px;border-radius:50%;background:var(--online);display:inline-block;animation:pulseAlive 2s infinite}
@keyframes pulseAlive{0%{box-shadow:0 0 0 0 rgba(52,211,153,.5)}70%{box-shadow:0 0 0 6px rgba(52,211,153,0)}100%{box-shadow:0 0 0 0 rgba(52,211,153,0)}}
.btn-primary{background:var(--color-primary);color:var(--color-text-inverse);transition:background var(--duration) var(--ease)}
.btn-primary:hover{background:var(--color-primary-hover);box-shadow:none}
.btn-primary:active{background:var(--color-primary-active)}
#newChatBtn:hover{box-shadow:none}
.send-btn:hover{box-shadow:none}
.composer:focus-within{border-color:var(--accent);box-shadow:0 0 0 3px var(--accent-dim)}
.stop-btn{position:sticky;bottom:86px;margin:8px auto;display:block;background:#ef4444;color:#fff;border:none;border-radius:999px;padding:8px 16px;font-size:.82rem;font-weight:700;cursor:pointer;box-shadow:0 4px 16px rgba(239,68,68,.35);z-index:5}
.stop-btn.hidden{display:none!important}

/* Sidebar backdrop (mobile) */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 35;
}
.sidebar-backdrop.open,
.sidebar-backdrop.show { display: block; }
@media(max-width:768px){
  .sidebar{ position:fixed; inset:0 auto 0 0; inset-inline-start:0; inset-inline-end:auto; transform:translateX(100%); width: min(300px,86vw); box-shadow: var(--shadow-lg); }
  :dir(ltr) .sidebar{ transform:translateX(-100%); }
  .sidebar.open{ transform:translateX(0); }
  .menu-btn{ display:grid !important; }
  .chat-log{ padding: 16px 12px; }
}
@media(min-width:769px){ #menuBtn{ display:none !important; } }
@keyframes blink{0%,80%,100%{opacity:.25}40%{opacity:1}}

/* Legacy light theme class support · blue */
body.light {
  --bg:          #f6f8fb;
  --bg-elevated: #ffffff;
  --bg2:         #eef2f8;
  --card:        #ffffff;
  --card-hover:  #eef2f8;
  --line:        #e2e8f0;
  --line-soft:   #eef2f8;
  --text:        #16202e;
  --text-secondary: #2a3a52;
  --muted:       #526074;
  --accent:      #2563eb;
  --accent-soft: #e8effc;
  --accent-dim:  #e8effc;
  --accent-glow: rgba(37,99,235,.18);
  --grad:        none;
  --shadow-sm:   0 1px 2px rgba(22,32,46,.06);
  --shadow:      0 4px 16px rgba(22,32,46,.07);
  --shadow-lg:   0 8px 32px rgba(22,32,46,.09);
}
body.light .nav {
  background: rgba(244, 246, 251, 0.8);
}

/* Tables */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: .88rem;
  min-width: 600px;
}
th, td {
  padding: 11px 14px;
  text-align: right;
  border-bottom: 1px solid var(--line-soft);
}
th {
  color: var(--muted);
  font-weight: 600;
  background: var(--bg2);
  font-size: .8rem;
}
tr:last-child td { border-bottom: none; }

/* Reveal animation */
.reveal {
  opacity: 0;
  transform: translateY(18px);
  transition: opacity .55s var(--ease), transform .55s var(--ease);
}
.reveal.in {
  opacity: 1;
  transform: none;
}

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 900px) {
  .grid-3 { grid-template-columns: 1fr; max-width: 380px; margin: 0 auto; }
  .facts { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    top: 0; right: 0; bottom: 0;
    transform: translateX(105%);
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: none; }
  .menu-btn { display: grid; }
  .hero-gpt { padding: 60px 20px 56px; min-height: auto; }
  .hero-gpt h1 { font-size: 1.7rem; }
}

@media (max-width: 480px) {
  .auth-card { padding: 32px 22px 28px; }
  .view-pad { padding: 20px 16px 32px; }
  .chat-head { padding: 10px 14px; }
  .chat-log { padding: 16px 12px; }
  .chat-input { padding: 10px 12px var(--space-2); }
  .chat-input > .composer-caption { margin-top: var(--space-3); }
  .ios-viewport .chat-input > .composer-caption { margin-top: var(--space-2); }
}

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

/* mobile hide utility */
.hide-m { display: none; }
@media (max-width: 720px) { .hide-m { display: none; } }

/* ============================================
   Mobile Responsive Overrides (Ponytail)
   ============================================ */
@media (max-width: 720px) {
  .app-shell { flex-direction: column; }
  .sidebar { width: 100%; border-left: none; border-bottom: 1px solid var(--line-soft); padding: 12px; }
  .chat-head { flex-wrap: wrap; gap: 6px; padding: 8px 10px; }
  .chat-head #modelPicker { max-width: 100%; font-size: .82rem; }
}

/* B3: typing as chat row */
.msg.typing-row { display: flex; gap: 12px; align-items: center; padding: 6px 0; background: transparent !important; border: none !important; }
.msg.typing-row .typing-dots span { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); animation: typingBounce 1.2s infinite; display: inline-block; }
.msg.typing-row .typing-dots span:nth-child(2){animation-delay:.2s}
.msg.typing-row .typing-dots span:nth-child(3){animation-delay:.4s}
/* B3: stop pill inside composer */
.stop-pill { display: block; margin: 0 auto 8px; position: static; background: var(--card); border: 1px solid var(--line); border-radius: 999px; padding: 6px 14px; font-size: .8rem; cursor: pointer; }
/* ===== Mobile UX Overhaul: Claude-grade ===== */
.chat-topbar{position:relative;z-index:40;display:flex;align-items:center;justify-content:space-between;gap:8px;padding:10px 12px;background:color-mix(in srgb, var(--bg) 85%, transparent);backdrop-filter:blur(8px);-webkit-backdrop-filter:blur(8px);border-bottom:1px solid var(--line)}
.icon-btn{width:var(--control-md);height:var(--control-md);border-radius:var(--radius-sm);border:1px solid var(--color-border);background:var(--color-surface);color:var(--color-text);display:grid;place-items:center;cursor:pointer;flex-shrink:0}
.icon-btn:hover{background:var(--color-surface-hover);border-color:var(--color-border);color:var(--color-text)}
.topbar-brand{display:flex;align-items:center;gap:8px;font-weight:800;font-size:.95rem;white-space:nowrap}
.topbar-brand img{width:26px;height:26px;border-radius:7px;object-fit:cover}
.side-drawer{position:fixed;top:0;bottom:0;inset-inline-start:0;width:min(320px,85vw);background:var(--bg2);border-inline-end:1px solid var(--line);transform:translateX(100%);transition:transform .25s var(--ease);z-index:70;overflow-y:auto}
.side-drawer.open{transform:none}
.drawer-backdrop{position:fixed;inset:0;background:rgba(0,0,0,.45);z-index:65;display:none}
.drawer-backdrop.show{display:block}
/* composer-card Claude-style */
.composer-card{background:var(--color-surface);border:1px solid var(--color-border);border-radius:var(--radius-xl);padding:10px 12px;max-width:720px;margin:0 auto;position:relative}
.composer-card:focus-within{border-color:var(--accent);box-shadow:0 0 0 3px var(--accent-dim)}
.composer-row{display:flex;align-items:center;gap:6px;margin-top:6px}
.model-pill{background:var(--accent-soft);color:var(--accent);border:1px solid transparent;border-radius:999px;padding:6px 12px;font-size:13px;font-weight:600;cursor:pointer;display:inline-flex;align-items:center;gap:6px;white-space:nowrap}
.model-pill:hover{border-color:var(--accent);background:var(--accent-dim)}
.composer-btn{width:32px;height:32px;border-radius:50%;border:none;background:transparent;color:var(--muted);display:grid;place-items:center;cursor:pointer;flex-shrink:0}
.composer-btn:hover{background:var(--accent-dim);color:var(--accent)}
.composer-card textarea{flex:1;border:none;background:transparent;color:var(--text);font-size:.93rem;outline:none;resize:none;min-height:40px;max-height:140px;padding:8px 4px;line-height:1.7;width:100%}
.composer-card textarea{scrollbar-width:none;overflow-y:auto;max-height:160px}
.composer-card textarea::-webkit-scrollbar{display:none}
.icon-btn:empty,.btn:empty{display:none!important}
.page-head{display:flex;align-items:center;gap:12px;margin-bottom:22px}.page-head h1{font-size:1.25rem}
.hist-item{position:relative;display:flex;align-items:center;justify-content:space-between;padding:12px 16px;border-bottom:1px solid var(--border,var(--line));cursor:pointer}.hist-item:hover{background:var(--accent-soft)}.hist-main{min-width:0}.hist-title{font-weight:600}.hist-meta{color:var(--muted);font-size:12px;margin-top:2px}.hist-popover{position:absolute;inset-inline-start:12px;top:48px;z-index:10;padding:5px;background:var(--card);border:1px solid var(--line);border-radius:10px;box-shadow:var(--shadow-lg);min-width:130px}.hist-popover button{display:block;width:100%;padding:7px 10px;border:0;background:transparent;color:var(--text);text-align:right;cursor:pointer}.hist-popover button:hover{background:var(--accent-soft)}.hist-popover .danger{color:var(--danger)}
/* bubble fix */
.chat-log > .msg.user { display: table !important; width: fit-content !important; min-height:0 !important; min-width: 0 !important; max-width: min(85%,560px) !important; flex: none !important; align-self: flex-end !important; margin-inline-start: auto !important; }
.msg.user{min-height:0;height:auto;padding:10px 16px}
.msg.user:empty{display:none}
.msg.user:has(> :only-child:empty){display:none}
.msg.user .citations:empty,.msg.user div:empty{height:0;min-height:0;padding:0;margin:0}
/* empty-state calm */
.empty-state{display:flex;flex-direction:column;align-items:center;gap:12px;padding:36px 18px 18px;text-align:center}
.empty-state .brand-avatar{width:56px;height:56px;border-radius:var(--radius-lg);background:var(--color-surface);border:1px solid var(--color-border);display:grid;place-items:center;box-shadow:none}
.empty-state h2{font-size:1.1rem;font-weight:800}
.empty-state p{color:var(--muted);font-size:.9rem;line-height:1.7;max-width:480px}
/* reasoning UI (LibreChat/NextChat-style CoT block) */
.reasoning-block{margin:4px 0 10px;padding:0;border:1px solid var(--line);border-radius:10px;background:var(--card);overflow:hidden}
.reasoning-block>summary{list-style:none;cursor:pointer;display:flex;align-items:center;gap:6px;padding:8px 12px;font-size:.8rem;color:var(--muted);user-select:none}
.reasoning-block>summary::-webkit-details-marker{display:none}
.reasoning-block>summary:hover{color:var(--accent)}
.reasoning-block[open]>summary{border-bottom:1px solid var(--line)}
.reasoning-block>pre{margin:0;padding:10px 12px;font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;font-size:.78rem;line-height:1.6;color:var(--text);white-space:pre-wrap;word-break:break-word;max-height:320px;overflow:auto;direction:ltr;text-align:left}
.starter-chips{display:grid;grid-template-columns:repeat(auto-fit,minmax(180px,1fr));gap:10px;max-width:680px;width:100%;margin-top:8px}
/* avatar (single source for topbar, empty-state, message rows) */
.msg-avatar{width:30px;height:30px;border-radius:50%;overflow:hidden;flex-shrink:0;box-shadow:0 0 0 1px var(--line);background:var(--card);display:inline-grid;place-items:center}
.avatar-img{width:100%;height:100%;display:block;object-fit:cover}
/* send spinner */
.send-btn.is-loading svg{display:none}
.send-btn.is-loading{position:relative;color:transparent;pointer-events:none}
.send-btn.is-loading::after{content:"";width:16px;height:16px;border-radius:50%;border:2px solid #fff;border-top-color:transparent;animation:hbspin .8s linear infinite;position:absolute;top:50%;left:50%;transform:translate(-50%,-50%)}
@keyframes hbspin{to{transform:translate(-50%,-50%) rotate(360deg)}}
/* typing dots */
.typing-dots{display:inline-flex;gap:4px;align-items:center;padding:6px 0}
.typing-dots span{width:8px;height:8px;border-radius:50%;background:var(--accent);animation:hbtblink 1.2s infinite}
.typing-dots span:nth-child(2){animation-delay:.15s}
.typing-dots span:nth-child(3){animation-delay:.3s}
@keyframes hbtblink{0%,80%,100%{opacity:.25}40%{opacity:1}}
/* thinking row (single visible feedback during pending) */
.thinking{display:flex;align-items:center;gap:10px;color:var(--muted);font-size:13.5px;padding:6px 0}
.t-dots i{display:inline-block;width:7px;height:7px;border-radius:50%;background:var(--accent);margin-inline-end:3px;animation:hbtbounce 1.2s infinite}
.t-dots i:nth-child(2){animation-delay:.15s}
.t-dots i:nth-child(3){animation-delay:.30s}
@keyframes hbtbounce{0%,60%,100%{transform:translateY(0);opacity:.4}30%{transform:translateY(-5px);opacity:1}}

/* Master-fix contract: one calm token layer and one responsive shell. */
:root {
  --surface: var(--card);
  --border: var(--line);
  --accent-ink: #174ea6;
  --grad: var(--accent);
  --grad-soft: var(--accent-soft);
}
:root[data-theme="dark"], :root:not([data-theme="light"]) {
  --accent-ink: #a9d0ff;
  --surface: var(--card);
  --border: var(--line);
  --grad: var(--accent);
  --grad-soft: var(--accent-soft);
}
html { scroll-behavior: auto; }
body { min-height: 100dvh; }
a { color: var(--accent-ink); }
a:hover { color: var(--accent-2); }
.plan-pill, .side-link.active { color: var(--accent-ink); }
.chat-topbar { background: var(--bg); backdrop-filter: none; -webkit-backdrop-filter: none; }
.chat-input { background: var(--bg); }
.price-card.featured { background: var(--card); border-color: var(--accent); }
.chat-pane { min-height: 0; }
.chat-log { scroll-behavior: auto; }
.msg.assistant { display: flex; gap: 12px; padding: 6px 0; background: transparent !important; border: 0 !important; min-width: 0; }
.msg.assistant .msg-avatar { margin-top: 2px; }
.msg.assistant .body { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.msg .stream-text, .msg .message-text { overflow-wrap: anywhere; }
.msg-actions { opacity: 1; align-items: center; }
.msg-actions button { min-width: 32px; min-height: 32px; }
.msg-actions button:focus-visible, .btn:focus-visible, .icon-btn:focus-visible,
.side-link:focus-visible, .chip:focus-visible, .composer-btn:focus-visible,
.model-pill:focus-visible, .send-btn:focus-visible, .stop-pill:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent);
  outline-offset: 2px;
}
.msg[data-state="failed"], .msg[data-state="aborted"] { border-inline-start: 2px solid var(--warning) !important; padding-inline-start: 10px; }
.stream-error { color: var(--danger); font-size: .84rem; margin-top: 8px; line-height: 1.7; }
.inline-action { margin-top: 8px; border: 1px solid var(--accent); color: var(--accent-ink); background: var(--accent-soft); border-radius: 999px; padding: 6px 12px; cursor: pointer; font: inherit; font-size: .78rem; }
.scroll-bottom { position: absolute; inset-inline-end: 18px; bottom: 112px; z-index: 20; border: 1px solid var(--line); background: var(--card); color: var(--text); border-radius: 999px; padding: 7px 12px; box-shadow: var(--shadow); cursor: pointer; }
.response-media { display: block; max-width: 100%; height: auto; margin-top: 10px; border-radius: 12px; }
.key-row { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--line-soft); }
.key-row > div:first-child { min-width: 0; flex: 1; }
.key-row small { display: block; color: var(--muted); font-size: .76rem; overflow-wrap: anywhere; }
.offline-note, .sw-update-note { position: fixed; inset-inline: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); z-index: 120; display: flex; align-items: center; justify-content: center; gap: 10px; padding: 10px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); color: var(--text); box-shadow: var(--shadow-lg); font-size: .82rem; }
.sw-update-note button { border: 1px solid var(--accent); background: var(--accent-soft); color: var(--accent-ink); border-radius: 999px; padding: 5px 10px; cursor: pointer; font: inherit; }

/* >=1200px: persistent navigation; <1200px: real overlay drawer. */
@media (min-width: 1200px) {
  .sidebar.side-drawer { position: fixed; inset-block: 0; inset-inline-start: 0; width: var(--sidebar-w); transform: none; border-inline-end: 1px solid var(--line); border-left: 0; z-index: 70; }
  .chat-pane { margin-inline-start: var(--sidebar-w); width: auto; }
  .drawer-backdrop, .sidebar-backdrop, #drawerBtn, #menuBtn { display: none !important; }
}
@media (max-width: 1199px) {
  .app-shell { width: 100%; }
  .sidebar.side-drawer { position: fixed; inset-block: 0; inset-inline-start: 0; width: min(320px, 86vw); transform: translateX(105%); border-inline-end: 1px solid var(--line); border-left: 0; z-index: 70; }
  .sidebar.side-drawer.open { transform: none; }
  .chat-pane { width: 100%; margin: 0; }
  #drawerBtn { display: grid !important; }
  .drawer-backdrop.show, .sidebar-backdrop.show { display: block; }
  body.drawer-open { overflow: hidden; touch-action: none; }
}
@media (max-width: 480px) {
  .chat-log { padding: 18px 12px; gap: 14px; }
  .chat-input { padding-inline: 10px; }
  .composer-card { border-radius: 16px; padding: 8px 9px; }
  .composer-card textarea { font-size: .92rem; }
  .model-pill { padding-inline: 9px; max-width: 38vw; overflow: hidden; text-overflow: ellipsis; }
  .msg.user { max-width: 91% !important; }
  .view-pad, #view-history, #view-prompts, #view-kb, #view-memory, #view-settings, #view-billing, #view-api { padding: 20px 14px 32px !important; }
  .key-row { align-items: flex-start; }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
  .reveal { opacity: 1; transform: none; }
}
@media (pointer: coarse) {
  .msg-actions button, .hist-menu, .icon-btn, .composer-btn, .send-btn, .stop-pill { min-width: 40px; min-height: 40px; }
  .msg-actions { opacity: 1; }
}

/* Final certification pass: shared states, icons and bounded history. */
.ui-icon { width: 18px; height: 18px; flex: 0 0 auto; display: inline-block; vertical-align: middle; }
.view-item-icon { color: var(--color-text-muted); margin-top: 2px; }
.attachment-icon { width: var(--icon-sm); height: var(--icon-sm); color: var(--color-text-muted); }
.sh-pin { width: var(--icon-xs); height: var(--icon-xs); color: var(--color-primary); flex: 0 0 auto; }
.state-message { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 10px; min-height: 88px; color: var(--muted); text-align: center; line-height: 1.8; padding: 16px; }
.view-state.is-error { border: 1px solid color-mix(in srgb, var(--danger) 35%, var(--line)); border-radius: 12px; }
.view-state.is-error .state-message { color: var(--danger); }
.state-message .btn { color: var(--accent-ink); }
.history-list > .history-load-more { grid-column: 1 / -1; justify-self: center; min-width: 160px; margin: 8px 0 18px; }
.feature-icon-svg { width: 24px; height: 24px; display: block; }
.price-card.featured { background: var(--card) !important; }
.chat-input { background: var(--bg); }
.auth-page::before, .auth-page::after { display: none; }

/* Frontend recovery: ordinary interface SVGs must never inherit container dimensions. */
svg:not([data-artwork]) { max-width: 64px; max-height: 64px; flex: 0 0 auto; }
svg.ui-icon { width: 18px; height: 18px; }
.sidebar-section-label {
  color: var(--muted);
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .02em;
  padding: 4px 8px 1px;
  margin-top: 1px;
}
.sidebar-install {
  width: 100%;
  margin: 5px 0 0;
  justify-content: center;
  gap: 6px;
  padding: 7px 10px;
  font-size: .78rem;
}

/* Keep every turn in one reading column and keep actions attached to its content. */
.chat-log > .msg.assistant { width: 100%; }
.chat-log > .msg.user {
  align-self: flex-start !important;
  margin-inline-start: 0 !important;
  margin-inline-end: auto !important;
}
.msg.assistant .msg-actions {
  width: 100%;
  justify-content: flex-start;
}
@media (max-width: 1199px) {
  .view-pad, #view-history, #view-prompts, #view-kb, #view-memory, #view-settings, #view-billing, #view-api { padding-bottom: 32px; }
  .history-list { grid-template-columns: minmax(0, 1fr); }
  .page-head { margin-bottom: 16px; }
}
@media (max-width: 480px) {
  .state-message { padding-inline: 8px; }
  .starter-chips { grid-template-columns: 1fr; }
  .composer-caption { padding-inline: 8px; }
}

/* Frontend product quality pass: shared secondary-view rhythm and explicit
   component bounds. These rules are intentionally scoped to the app shell. */
.app-shell { overflow: hidden; }
.sidebar { gap: 2px; }
.sidebar-nav { flex-shrink: 0; }
.sidebar-actions { flex-shrink: 0; }
.user-chip {
  width: 100%;
  margin: 0 0 4px;
  padding: 8px;
  min-height: 58px;
  background: color-mix(in srgb, var(--card) 72%, var(--bg2));
  cursor: pointer;
  transition: border-color var(--duration), background var(--duration);
}
.user-chip:hover { border-color: var(--color-border); background: var(--color-surface-hover); }
.user-chip:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent);
  outline-offset: 2px;
}
.account-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  flex: 0 0 36px;
  overflow: hidden;
  background: var(--accent-dim);
  border: 1px solid var(--line);
  color: var(--accent-ink);
  font-weight: 800;
}
.account-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar-fallback { font-size: .95rem; line-height: 1; }
.account-copy { min-width: 0; flex: 1; display: flex; flex-direction: column; align-items: flex-start; }
.user-chip .nm, .user-chip .em { display: block; max-width: 100%; width: 100%; }
.user-chip .nm { font-size: .84rem; line-height: 1.45; }
.user-chip .em { font-size: .68rem; line-height: 1.4; }
.user-chip .plan-pill { flex: 0 0 auto; margin-inline-start: 0; }
.danger-action { color: var(--danger) !important; }
.danger-action:hover { color: var(--danger) !important; border-color: color-mix(in srgb, var(--danger) 55%, var(--line)); background: var(--danger-dim); }
.sidebar-history { max-height: none; overflow: visible; margin-block: 8px 10px; }
.sidebar-history .sh-head { padding: 3px 8px 5px; }
.sidebar-history .sh-item { min-height: 31px; padding-block: 5px; }
.sidebar-history .sh-more {
  width: 100%;
  margin-top: 3px;
  padding: 5px 8px;
  border: 0;
  border-top: 1px solid var(--line-soft);
  background: transparent;
  color: var(--accent-ink);
  font: inherit;
  font-size: .7rem;
  text-align: right;
  cursor: pointer;
}
.sidebar-history .sh-more:hover { color: var(--text); }

.chat-title-wrap {
  min-width: 0;
  flex: 1 1 0;
  overflow: hidden;
  text-align: center;
  line-height: 1.35;
}
.chat-title-wrap #chatTitle {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-title-wrap #routeInfo { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-log, .composer-card { max-width: 820px; }
.chat-log > .msg { min-width: 0; }
.chat-log > .msg.user { max-width: min(84%, 600px) !important; }

.app-view {
  height: 100%;
  min-height: 0;
  overflow-y: auto;
  padding: 30px 30px 40px;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}
.app-view::-webkit-scrollbar { width: 8px; }
.app-view::-webkit-scrollbar-track { background: transparent; }
.app-view::-webkit-scrollbar-thumb { background: var(--line); border-radius: 8px; }
.app-view::-webkit-scrollbar-thumb:hover { background: var(--muted); }
.app-view > .view-header,
.app-view > .view-toolbar,
.app-view > .view-section { width: min(100%, 960px); margin-inline: auto; }
.view-header { align-items: flex-start; margin-bottom: 18px; }
.view-heading { min-width: 0; flex: 1; }
.view-heading h1 { font-size: 1.4rem; margin: 0; }
.view-description { color: var(--muted); font-size: .86rem; line-height: 1.8; margin-top: 4px; }
.view-toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.history-toolbar .input { max-width: 420px; }
.prompt-create, .memory-create { max-width: 560px !important; }
.prompt-create .input, .memory-create .input { min-width: 0; }
.view-section { margin-bottom: 18px; }
.history-list { max-width: 960px; gap: 0; }
.history-list .view-item-icon,
.prompt-list .view-item-icon,
.kb-results .view-item-icon,
.memory-list .view-item-icon {
  width: 18px !important;
  height: 18px !important;
  max-width: 18px !important;
  max-height: 18px !important;
  flex: 0 0 18px !important;
}
.history-list .hist-item {
  min-width: 0;
  margin: 0;
  padding: 13px 10px;
  gap: 12px;
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--line-soft);
  border-radius: 8px;
}
.history-list .hist-item:hover, .history-list .hist-item:focus-visible { background: var(--accent-dim); }
.history-list .hist-main { flex: 1; min-width: 0; }
.history-list .hist-title { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history-list .hist-meta { overflow-wrap: anywhere; white-space: normal; line-height: 1.6; }
.history-list .hist-menu { flex: 0 0 36px; }
.prompt-list { display: flex; flex-direction: column; gap: 8px; }
.prompt-list .prompt-card {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  padding: 14px 16px !important;
  cursor: default;
}
.prompt-list .prompt-card:hover { border-color: var(--line); }
.prompt-body { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 2px; }
.prompt-title, .prompt-preview { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.prompt-title { font-size: .9rem; }
.prompt-preview { color: var(--muted); font-size: .76rem; }
.prompt-category { color: var(--accent-ink); font-size: .68rem; margin-top: 2px; }
.prompt-actions { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; }
.prompt-actions .btn { min-height: 32px; }
.kb-form, .kb-search-wrap, .kb-results, .memory-create, .memory-list { max-width: 640px !important; }
.memory-list { display: flex; flex-direction: column; gap: 10px; }
.api-intro { display: grid; grid-template-columns: minmax(0, 1fr) minmax(280px, .9fr); gap: 12px; }
.api-security-note, .api-endpoint { min-width: 0; padding: 15px 16px; background: var(--card); border: 1px solid var(--line-soft); border-radius: var(--radius); }
.api-security-note h2 { font-size: .95rem; margin-bottom: 7px; }
.api-security-note ul { padding-inline-start: 18px; color: var(--muted); font-size: .78rem; line-height: 1.9; }
.api-endpoint { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.api-endpoints { min-width: 0; display: grid; gap: 8px; }
.api-endpoint > div { min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.api-label { color: var(--muted); font-size: .7rem; }
.api-endpoint code, .api-base-badge, .key-prefix { direction: ltr; unicode-bidi: plaintext; text-align: left; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.api-endpoint code { overflow-wrap: anywhere; font-size: .78rem; }
.copy-inline { flex: 0 0 auto; }
.api-key-panel, .api-inventory-panel, .api-quickstart { max-width: 960px !important; }
.api-panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.api-panel-head > div { min-width: 0; }
.api-panel-head h2 { font-size: 1rem; margin-bottom: 3px; }
.api-panel-head p { color: var(--muted); font-size: .78rem; line-height: 1.8; }
.api-panel-head > .btn { flex: 0 0 auto; }
.api-base-badge { color: var(--accent-ink); background: var(--accent-dim); border: 1px solid var(--line); border-radius: 999px; padding: 5px 9px; font-size: .68rem; white-space: nowrap; }
.api-tabs { display: flex; gap: 4px; margin: 18px 0 10px; border-bottom: 1px solid var(--line-soft); }
.api-tabs button { border: 0; border-bottom: 2px solid transparent; background: transparent; color: var(--muted); padding: 7px 12px; font: inherit; font-size: .78rem; cursor: pointer; }
.api-tabs button[aria-selected="true"] { color: var(--accent-ink); border-bottom-color: var(--accent); }
.api-tabs button:focus-visible, .copy-inline:focus-visible, .code-copy:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 2px; }
.code-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 6px; color: var(--muted); font-size: .72rem; }
.api-code { max-width: 100%; margin: 0; padding: 14px; overflow: auto; border: 1px solid var(--line-soft); border-radius: 10px; background: var(--bg2); color: var(--text-secondary); font-size: .78rem; line-height: 1.75; white-space: pre; direction: ltr; text-align: left; unicode-bidi: plaintext; }
.api-code code { direction: ltr; text-align: left; unicode-bidi: plaintext; font-family: inherit; }
.api-step-heading { display: flex; align-items: center; gap: 8px; margin: 18px 0 8px; }
.api-step-heading h3 { font-size: .9rem; }
.api-step-number { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--accent-dim); color: var(--accent-ink); font-size: .75rem; font-weight: 800; }
.api-request-step { margin-top: 22px; }
.api-install-code { padding-block: 10px; }
.key-row { min-width: 0; }
.key-row .key-prefix { display: block; font-size: .82rem; }

/* State-matrix recovery: keep empty secondary views useful without
   introducing artwork that can stretch with a flex/grid parent. */
.view-empty-state {
  min-height: 132px;
  padding: 24px 16px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  gap: 8px;
}
.view-empty-state .empty-state-icon {
  width: 32px !important;
  height: 32px !important;
  max-width: 32px !important;
  max-height: 32px !important;
  flex: 0 0 32px !important;
  color: var(--accent);
}
.view-empty-state h2 { font-size: .95rem; font-weight: 700; }
.view-empty-state p { max-width: 420px; font-size: .78rem; line-height: 1.8; }

/* State-matrix recovery: profile media has a definite square containing
   block. This prevents portrait URLs from becoming clipped slivers. */
.account-avatar { position: relative; }
.account-avatar img { position: absolute; inset: 0; width: 100%; height: 100%; min-width: 0; min-height: 0; aspect-ratio: 1 / 1; object-fit: cover; display: block; }
.account-avatar img[hidden] { display: none !important; }
.user-chip .plan-pill { direction: rtl; }
.user-chip { min-height: 52px; padding-block: 8px; }

/* Explicit component owners for interface glyphs. The generic safety cap is
   retained, but these rules make every state deterministic at the owner. */
.history-list .hist-item > .view-item-icon,
.prompt-list .prompt-card > .view-item-icon,
.kb-results > .card > .view-item-icon,
.memory-list > .card > .view-item-icon {
  width: 16px !important;
  height: 16px !important;
  max-width: 16px !important;
  max-height: 16px !important;
  flex: 0 0 16px !important;
}
.sidebar-history .sh-pin { width: 14px !important; height: 14px !important; max-width: 14px !important; max-height: 14px !important; flex: 0 0 14px !important; }

/* One named reading column is the geometry contract for both loaded and new
   message builders. */
.chat-log.chat-reading-column {
  width: min(100%, 860px);
  max-width: 860px;
  margin-inline: auto;
  box-sizing: border-box;
}
.chat-reading-column > .msg { min-width: 0; }
.chat-reading-column > .msg.user { max-width: min(75%, 600px) !important; }

/* Secondary pages own horizontal overflow; code blocks own their own LTR
   scroll area. */
.app-view { overflow-x: hidden; }
.chat-log { overflow-x: hidden; }
.sidebar { overflow-x: hidden; }

@media (max-width: 1199px) {
  .app-view { padding-bottom: 32px; }
}
@media (max-width: 600px) {
  .app-view { padding-inline: 14px; }
  .api-intro { grid-template-columns: 1fr; }
  .api-panel-head { flex-direction: column; gap: 10px; }
  .api-panel-head > .btn { width: 100%; }
  .api-base-badge { align-self: flex-start; }
  .prompt-list .prompt-card { align-items: flex-start; }
  .prompt-actions { flex-direction: column; align-items: stretch; }
  .prompt-actions .btn { min-width: 58px; }
}

/* Native hidden attributes must remain authoritative over component display
   rules (notably the deferred install button and profile-image fallback). */
[hidden] { display: none !important; }

/* Theme continuity + final chat geometry contract. */
:root { --chat-content-width: 860px; }
.theme-toggle {
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: color var(--duration), background var(--duration), border-color var(--duration);
}
.theme-toggle:hover { color: var(--color-text); background: var(--color-surface-hover); border-color: var(--color-border); }
.theme-toggle:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 2px; }
.theme-toggle svg { width: 17px; height: 17px; }
.drawer-theme-toggle { width: 100%; height: 40px; flex: 0 0 auto; justify-content: flex-start; gap: 8px; padding-inline: 10px; font: inherit; font-size: .9rem; }

/* One viewport budget. The middle row can shrink below its content height;
   html/body cannot acquire a scroll range when the keyboard opens. */
html.app-root {
  height: var(--app-viewport-height, 100dvh);
  max-height: var(--app-viewport-height, 100dvh);
  min-height: 0;
  overflow: hidden;
  overscroll-behavior: none;
}
.app-body {
  height: 100%;
  max-height: 100%;
  min-height: 0;
  overflow: hidden;
}
#view-chat {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}
.chat-log-region {
  position: relative;
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}
.chat-log-region > .chat-log { flex: 1 1 auto; min-height: 0; }
.chat-input { flex: 0 0 auto; }
#log > #starterChips { flex-shrink: 0; margin-block: auto; }
@media (max-width: 1199px) {
  /* Prevent iOS focus zoom from changing the keyboard viewport budget. */
  #msgInput { font-size: 16px; }
}
.chat-log.chat-reading-column,
.chat-input > .composer-card {
  width: min(100%, var(--chat-content-width));
  max-width: var(--chat-content-width);
  margin-inline: auto;
}
.chat-reading-column > .msg.user {
  align-self: flex-end !important;
  margin-inline-start: auto !important;
  margin-inline-end: 0 !important;
  max-width: min(75%, 600px) !important;
}
.chat-reading-column > .msg.assistant { width: 100%; }
.chat-log-region > .scroll-bottom {
  position: absolute;
  inset-inline: 0;
  bottom: 12px;
  width: max-content;
  max-width: calc(100% - 24px);
  margin-inline: auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  color: var(--text);
  box-shadow: var(--shadow);
  cursor: pointer;
}
.chat-log-region > .scroll-bottom:hover { border-color: var(--accent); background: var(--accent-dim); }
.chat-log-region > .scroll-bottom .ui-icon { width: 16px; height: 16px; }
.chat-log-region > .scroll-bottom:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 2px; }

/* ============================================================
   Chat geometry: LTR layout coordinates, RTL/auto text
   ============================================================ */
.chat-log.chat-reading-column {
  direction: ltr;
  width: min(100%, var(--chat-content-width));
  max-width: var(--chat-content-width);
  margin-inline: auto;
  align-items: stretch;
}
.chat-reading-column > .msg {
  direction: ltr;
  min-width: 0;
}
.chat-reading-column > .msg.user {
  display: flex !important;
  flex-direction: column;
  align-items: flex-end;
  align-self: flex-end !important;
  margin-left: auto !important;
  margin-right: 0 !important;
  margin-inline-start: auto !important;
  margin-inline-end: 0 !important;
  width: fit-content !important;
  max-width: min(70%, 620px) !important;
  background: transparent !important;
  border: 0 !important;
  padding: 2px 0 0 !important;
  min-height: 0 !important;
  height: auto !important;
}
.msg.user .msg-bubble {
  background: var(--accent-soft);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 16px 16px 4px 16px;
  padding: 8px 14px;
  width: fit-content;
  max-width: 100%;
  line-height: 1.8;
}
.msg.user .message-text {
  direction: auto;
  text-align: start;
  unicode-bidi: plaintext;
  display: block;
}
.msg.user .message-text.editing-hidden { display: none; }
.msg.user .edit-box {
  width: min(100%, 420px);
  min-width: 180px;
  margin-top: 6px;
  direction: auto;
  text-align: start;
}
.chat-reading-column > .msg.assistant {
  width: 100%;
  max-width: 100%;
}
.msg.assistant .body {
  direction: rtl;
  text-align: start;
}
.msg.assistant .stream-text,
.msg.assistant .message-text {
  direction: auto;
  unicode-bidi: plaintext;
}

.msg-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px;
  margin-top: 4px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .15s;
}
.msg:hover .msg-actions,
.msg:focus-within .msg-actions,
.msg.msg-actions-open .msg-actions {
  opacity: 1;
  pointer-events: auto;
}
.msg-actions button,
.msg-action-btn {
  width: 28px;
  min-width: 28px;
  height: 28px;
  min-height: 28px;
  padding: 0;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  display: inline-grid;
  place-items: center;
  cursor: pointer;
}
.msg-actions button:hover,
.msg-action-btn:hover { color: var(--text); background: var(--accent-dim); }
.msg-actions .ui-icon { width: 15px; height: 15px; }
.msg.assistant .msg-actions { width: auto; justify-content: flex-start; }
.msg.user .msg-actions { justify-content: flex-end; }
@media (pointer: coarse) {
  .msg-actions { opacity: 1; pointer-events: auto; }
  .msg-actions button, .msg-action-btn { width: 36px; min-width: 36px; height: 36px; min-height: 36px; }
}

/* ============================================================
   Sidebar: recents own scroll; chrome stays fixed
   ============================================================ */
.sidebar,
.sidebar.side-drawer {
  height: var(--app-viewport-height, 100dvh);
  max-height: var(--app-viewport-height, 100dvh);
  overflow: hidden !important;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  min-height: 0;
  box-sizing: border-box;
}
.sidebar-chrome-top {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.sidebar-chrome-bottom {
  flex: 0 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
.sidebar .brand,
.sidebar .user-chip,
.sidebar #newChatBtn,
.sidebar .sidebar-search,
.sidebar #quotaBox,
.sidebar .sidebar-nav,
.sidebar .sidebar-install,
.sidebar .sidebar-actions {
  flex-shrink: 0;
}
#sidebarHistory.sidebar-history,
.sidebar-history {
  flex: 1 1 0px !important;
  min-height: 168px !important;
  max-height: none !important;
  overflow: hidden !important;
  display: flex !important;
  flex-direction: column !important;
  margin: 4px 0 !important;
  padding: 0 !important;
  border: 0 !important;
  background: transparent !important;
}
.sidebar-history .sh-head {
  flex-shrink: 0;
  padding: 4px 8px 6px;
  font-size: .7rem;
  color: var(--muted);
}
#sidebarHistoryList.sidebar-history-list,
.sidebar-history-list {
  direction: ltr;
  flex: 1 1 0%;
  min-height: 0;
  height: auto;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0 2px 4px;
  scrollbar-width: thin;
  scrollbar-color: color-mix(in srgb, var(--muted) 40%, transparent) transparent;
}
.sidebar-history-list::-webkit-scrollbar { width: 6px; }
.sidebar-history-list::-webkit-scrollbar-track { background: transparent; }
.sidebar-history-list::-webkit-scrollbar-thumb {
  background: color-mix(in srgb, var(--muted) 35%, transparent);
  border-radius: 8px;
}
.sidebar-history-list::-webkit-scrollbar-thumb:hover {
  background: color-mix(in srgb, var(--muted) 65%, transparent);
}
.sidebar-history-list .sh-empty { direction: rtl; }
.sidebar-history .sh-item {
  direction: ltr;
  display: flex;
  flex-direction: row;
  justify-content: flex-end;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  padding: 5px 8px;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  font-size: .8rem;
  color: var(--text-secondary);
  background: transparent;
}
.sidebar-history .sh-item:hover { background: var(--color-surface-hover); }
.sidebar-history .sh-item.active {
  background: var(--accent-soft);
  color: var(--accent-ink);
  box-shadow: inset -2px 0 0 var(--accent);
}
.sidebar-history .sh-item .sh-title {
  direction: rtl;
  unicode-bidi: plaintext;
  text-align: right;
  flex: 0 1 auto !important;
  min-width: 0;
  max-width: calc(100% - 22px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
}
.sidebar-history .sh-pin {
  width: 14px !important;
  height: 14px !important;
  max-width: 14px !important;
  max-height: 14px !important;
  flex: 0 0 14px !important;
  order: 0;
  color: var(--accent);
}
.sidebar-history .sh-empty {
  color: var(--muted);
  font-size: .75rem;
  padding: 6px 8px;
}
@media (max-width: 720px) {
  .app-shell { overflow: hidden; flex-direction: row; }
}

/* ============================================================
   Design System V2 primitives (progressive; do not rewrite HTML)
   ============================================================ */
:root { --chat-content-width: 860px; }

.ds-page { width: min(100%, var(--content-page)); margin-inline: auto; padding: var(--page-pad); }
.ds-section { display: flex; flex-direction: column; gap: var(--section-gap); }
.ds-row { display: flex; align-items: center; gap: var(--row-gap); }
.ds-stack { display: flex; flex-direction: column; gap: var(--space-3); }
.ds-inline { display: inline-flex; align-items: center; gap: var(--space-2); }
.ds-button { height: var(--control-md); }
.ds-icon-button { width: var(--control-md); height: var(--control-md); }
.ds-input { min-height: var(--control-md); border-radius: var(--radius-md); }
.ds-badge {
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--color-surface-subtle);
  color: var(--color-text-secondary);
  font-size: var(--text-meta);
  font-weight: var(--weight-medium);
  border: 1px solid var(--color-border-subtle);
}
.ds-divider { height: 1px; background: var(--color-border-subtle); border: 0; }
.ds-empty { display: flex; flex-direction: column; align-items: center; gap: var(--space-3); padding: var(--space-8) var(--space-4); color: var(--color-text-muted); text-align: center; }
.ds-popover { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-md); box-shadow: var(--shadow-overlay); z-index: var(--z-popover); }

.ds-page-title { font-size: var(--text-page-title); font-weight: var(--weight-semibold); line-height: var(--leading-title); }
.ds-section-title { font-size: var(--text-section); font-weight: var(--weight-semibold); line-height: var(--leading-title); }
.ds-caption { font-size: var(--text-caption); color: var(--color-text-muted); }
.ds-meta { font-size: var(--text-meta); color: var(--color-text-muted); }

svg.ui-icon { width: var(--icon-md); height: var(--icon-md); }
.icon-xs { width: var(--icon-xs); height: var(--icon-xs); }
.icon-sm { width: var(--icon-sm); height: var(--icon-sm); }
.icon-md { width: var(--icon-md); height: var(--icon-md); }
.icon-lg { width: var(--icon-lg); height: var(--icon-lg); }
.icon-xl { width: var(--icon-xl); height: var(--icon-xl); }

:focus:not(:focus-visible) { outline: none; }
:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

.plan-pill {
  background: var(--color-surface-subtle);
  color: var(--color-text-secondary);
  border: 1px solid var(--color-border-subtle);
  box-shadow: none;
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .reveal, .reveal.in { opacity: 1; transform: none; transition: none; }
}

/* ============================================================
   Phase 2 — AI shell / chat experience
   Geometry contracts from Phase 1 remain authoritative.
   ============================================================ */
:root {
  --composer-max-height: 200px;
  --msg-gap: var(--space-4);
}

.chat-pane, #view-chat, .chat-log-region, .chat-log {
  background: var(--color-bg);
}
.chat-input {
  border-top: 0;
  background: linear-gradient(to top, var(--color-bg) 78%, transparent);
  padding-top: var(--space-3);
}

.chat-log.chat-reading-column {
  gap: var(--msg-gap);
  padding-block: var(--space-4);
}
.chat-reading-column > .msg {
  padding-block: 0;
}
.chat-reading-column > .msg.user {
  background: transparent !important;
  border: 0 !important;
  box-shadow: none !important;
}
.msg.user .msg-bubble {
  background: var(--color-surface-subtle);
  color: var(--color-text);
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius-lg) var(--radius-lg) var(--radius-sm) var(--radius-lg);
  box-shadow: none;
  padding: 8px 14px;
  line-height: 1.8;
}
.msg.assistant {
  gap: var(--space-3);
  padding: 2px 0 6px !important;
}
.msg.assistant .body {
  font-size: var(--text-body);
  line-height: var(--leading-reading);
}
.msg.assistant .msg-avatar {
  width: 24px;
  height: 24px;
  opacity: .9;
  box-shadow: none;
  border: 0;
  background: transparent;
}

.msg-actions {
  gap: 2px;
  margin-top: 4px;
  transition: opacity var(--motion-fast) var(--ease);
}
.msg-action-btn {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
}
.msg-action-btn:hover {
  color: var(--color-text);
  background: var(--color-surface-hover);
}
.msg-action-btn.is-copied { color: var(--color-success); }

.thinking {
  gap: 8px;
  font-size: var(--text-small);
  color: var(--color-text-muted);
  min-height: 24px;
}
.t-dots i { width: 5px; height: 5px; background: var(--color-text-muted); }
.stream-error {
  margin-top: var(--space-2);
  padding: 8px 12px;
  border-radius: var(--radius-md);
  border: 1px solid color-mix(in srgb, var(--color-danger) 35%, var(--color-border));
  background: var(--color-danger-subtle);
  color: var(--color-danger);
  font-size: var(--text-small);
}
.inline-action {
  margin-top: 6px;
  background: none;
  border: 0;
  color: var(--color-primary);
  cursor: pointer;
  font: inherit;
  font-size: var(--text-small);
}

.composer-card {
  border-radius: var(--radius-xl);
  padding: 10px 12px 8px;
  box-shadow: var(--shadow-sm);
  max-width: var(--chat-content-width);
}
.composer-card:focus-within {
  border-color: var(--color-border-strong);
  box-shadow: 0 0 0 3px var(--color-primary-subtle);
}
.composer-card textarea {
  min-height: 28px;
  max-height: var(--composer-max-height);
  padding: 6px 4px 4px;
  line-height: 1.7;
  font-size: var(--text-body);
}
.composer-row { margin-top: 4px; gap: 4px; align-items: center; }
.model-pill {
  background: transparent;
  color: var(--color-text-secondary);
  border: 1px solid var(--color-border-subtle);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: var(--text-caption);
  font-weight: var(--weight-medium);
}
.model-pill:hover {
  background: var(--color-surface-hover);
  border-color: var(--color-border);
  color: var(--color-text);
}
.composer-btn:hover { background: var(--color-surface-hover); color: var(--color-text); }
.send-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--color-primary);
  color: var(--color-text-inverse);
  border: none;
  display: grid;
  place-items: center;
  cursor: pointer;
}
.send-btn:hover { background: var(--color-primary-hover); }
.send-btn.is-stop,
.send-btn.is-loading {
  background: var(--color-text-secondary);
  pointer-events: auto;
  color: var(--color-text-inverse);
}
.send-btn.is-loading::after { display: none; }
.send-btn.is-stop svg.send-glyph,
.send-btn.is-loading svg.send-glyph { display: none; }
.send-btn .stop-glyph { display: none; }
.send-btn.is-stop .stop-glyph,
.send-btn.is-loading .stop-glyph { display: block; }
.send-btn.is-loading { color: var(--color-text-inverse); }

.stop-pill {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  margin: 0;
  padding: 0;
  border: 0;
}

.composer-attach {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 2px 6px;
}
.att-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--color-surface-subtle);
  border: 1px solid var(--color-border-subtle);
  color: var(--color-text-secondary);
  font-size: var(--text-caption);
}
.att-chip .att-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px; }
.att-chip .att-remove {
  border: 0;
  background: transparent;
  color: var(--color-text-muted);
  cursor: pointer;
  width: 18px;
  height: 18px;
  border-radius: 50%;
}
.att-chip .att-remove:hover { color: var(--color-danger); background: var(--color-danger-subtle); }

.drop-overlay {
  position: absolute;
  inset: 0;
  z-index: var(--z-dropdown);
  display: none;
  align-items: center;
  justify-content: center;
  background: color-mix(in srgb, var(--color-bg) 72%, transparent);
  border: 1px dashed var(--color-border-strong);
  color: var(--color-text-secondary);
  font-size: var(--text-small);
  pointer-events: none;
}
.chat-log-region.is-drop-target .drop-overlay { display: flex; }

.chat-topbar {
  border-bottom-color: var(--color-border-subtle);
  padding-block: 8px;
}
.topbar-brand { display: none; }
@media (max-width: 1199px) {
  .topbar-brand { display: flex; }
}

.empty-state { padding: 48px 16px 24px; gap: 8px; }
.empty-state h2 { font-size: 1.15rem; font-weight: 600; }
.empty-state p { font-size: .86rem; }
.starter-chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  max-width: 560px;
  margin-top: 12px;
}
.chip, .starter-chips .chip {
  background: transparent;
  border: 1px solid var(--color-border);
  border-radius: 999px;
  padding: 7px 12px;
  font-size: var(--text-small);
  line-height: 1.4;
  animation: none;
  box-shadow: none;
}
.chip:hover {
  transform: none;
  background: var(--color-surface-hover);
  border-color: var(--color-border-strong);
  box-shadow: none;
}

.sidebar {
  background: var(--color-bg-elevated);
  border-inline-end: 1px solid var(--color-border-subtle);
}
.sidebar-search {
  background: var(--color-surface-subtle) !important;
  border-color: var(--color-border-subtle) !important;
}
.sidebar-history .sh-item { min-height: 32px; padding: 4px 8px; }
.sidebar-history .sh-item.active {
  background: var(--color-surface-hover);
  color: var(--color-text);
  box-shadow: inset -2px 0 0 var(--color-primary);
}
.quota-box, #quotaBox {
  background: transparent !important;
  border-color: transparent !important;
}

.ds-popover,
#headerMenu,
#modelPopover,
.hist-popover {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-overlay);
  padding: 6px;
  z-index: var(--z-popover);
}
.ds-popover [role="option"]:hover,
#modelPopover [role="option"]:hover {
  background: var(--color-surface-hover);
}
#modelPopover [aria-selected="true"] {
  background: var(--color-primary-subtle);
  color: var(--color-primary-ink);
}

.code-block {
  margin: 10px 0;
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius-md);
  background: var(--color-surface-subtle);
  overflow: hidden;
  max-width: 100%;
}
.code-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  font-size: var(--text-caption);
  color: var(--color-text-muted);
  border-bottom: 1px solid var(--color-border-subtle);
  direction: ltr;
}
.code-block pre {
  margin: 0;
  padding: 12px;
  overflow-x: auto;
  direction: ltr;
  text-align: left;
  unicode-bidi: isolate;
  font-family: var(--font-mono);
  font-size: var(--text-code);
  line-height: 1.65;
}
.inline-code {
  font-family: var(--font-mono);
  font-size: .88em;
  direction: ltr;
  unicode-bidi: isolate;
  background: var(--color-surface-subtle);
  border-radius: 4px;
  padding: 0 4px;
}
.msg.assistant .body h2, .msg.assistant .body h3, .msg.assistant .body h4 {
  font-weight: 600;
  margin: 12px 0 6px;
  line-height: 1.45;
}
.msg.assistant .body ul { padding-inline-start: 1.2em; margin: 8px 0; }
.msg.assistant .body blockquote {
  margin: 8px 0;
  padding-inline-start: 12px;
  border-inline-start: 2px solid var(--color-border);
  color: var(--color-text-secondary);
}
.msg.assistant .body table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-small);
  display: block;
  overflow-x: auto;
}
.msg.assistant .body a { color: var(--color-primary-ink); }

.citations { margin-top: 10px; display: flex; flex-direction: column; gap: 4px; }
.cit-head { font-size: var(--text-caption); color: var(--color-text-muted); }
.cit {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--color-surface-subtle);
  border: 1px solid var(--color-border-subtle);
  color: var(--color-text-secondary);
  font-size: var(--text-caption);
}
.cit-n {
  min-width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--color-surface-hover);
  display: inline-grid;
  place-items: center;
  font-size: 10px;
}

.chat-log-region > .scroll-bottom {
  box-shadow: var(--shadow-sm);
  background: var(--color-surface);
  border-color: var(--color-border);
  font-size: var(--text-caption);
  padding: 6px 10px;
}

.edit-box {
  width: min(100%, 420px);
  min-height: 64px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-text);
  padding: 8px 10px;
  font: inherit;
}
.edit-btns { display: flex; gap: 6px; margin-top: 6px; justify-content: flex-end; }

@media (pointer: coarse) {
  .msg-actions { opacity: 1; pointer-events: auto; }
}
@media (prefers-reduced-motion: reduce) {
  .msg-actions, #toast, .chip { transition: none; }
  .t-dots i, .presence-dot { animation: none !important; }
}

/* ============================================================
   Phase 3 — secondary views
   ============================================================ */
.app-view.secondary-page {
  --secondary-width: 1040px;
  padding: var(--space-6) var(--space-6) var(--space-10);
}
.settings-page { --secondary-width: 880px; }
.app-view.secondary-page > .view-header,
.app-view.secondary-page > .view-toolbar,
.app-view.secondary-page > .view-section {
  width: min(100%, var(--secondary-width));
  margin-inline: auto;
}
.secondary-header { gap: var(--space-3); margin-bottom: var(--space-4); }
.secondary-title { font-size: var(--text-page-title); font-weight: var(--weight-semibold); }
.secondary-description { margin-top: 4px; color: var(--color-text-muted); }
.ds-toolbar { gap: var(--space-2); margin-bottom: var(--space-4); }
.ds-toolbar .input { min-height: var(--control-md); max-width: 420px; }
.prompt-create, .memory-create { max-width: 640px !important; }
.kb-form { display: flex; flex-direction: column; gap: var(--space-2); max-width: 640px !important; background: transparent; border: 0; padding: 0; }
.kb-form .btn { align-self: flex-start; }

.secondary-row,
.prompt-row,
.kb-row,
.memory-row,
.key-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 56px;
  padding: 12px 4px;
  border: 0;
  border-bottom: 1px solid var(--color-border-subtle);
  background: transparent;
  box-shadow: none;
  border-radius: 0;
}
.secondary-row:hover,
.prompt-row:hover,
.kb-row:hover,
.memory-row:hover,
.history-list .hist-item:hover { background: var(--color-surface-hover); }
.row-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.row-title, .hist-title, .prompt-title { font-size: var(--text-body); font-weight: var(--weight-medium); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-meta, .hist-meta, .prompt-preview { font-size: var(--text-caption); color: var(--color-text-muted); }
.prompt-category { color: var(--color-text-muted); font-size: var(--text-meta); }
.prompt-list { gap: 0; }
.prompt-list .prompt-card {
  padding: 12px 4px !important;
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--color-border-subtle);
  border-radius: 0;
}
.history-list .hist-item { min-height: 56px; padding: 10px 4px; border-radius: 0; }
.history-list .hist-item:hover, .history-list .hist-item:focus-visible { background: var(--color-surface-hover); }
.history-list .view-item-icon { color: var(--color-text-muted); }

.setting-row {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: var(--space-2);
  padding: 16px 0;
  border-bottom: 1px solid var(--color-border-subtle);
  background: transparent;
}
.setting-copy h3 { font-size: var(--text-section); font-weight: var(--weight-semibold); }
.setting-hint { color: var(--color-text-muted); font-size: var(--text-small); line-height: 1.7; }
.usage-rows { display: flex; flex-direction: column; gap: 0; }
.usage-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 8px 0;
  border-bottom: 1px solid var(--color-border-subtle);
}
.usage-row .stat-label { color: var(--color-text-muted); font-size: var(--text-small); }
.usage-row .stat-num { font-size: var(--text-body); font-weight: var(--weight-semibold); }
.ltr-value, .api-endpoint code, .key-prefix {
  direction: ltr;
  unicode-bidi: isolate;
  text-align: left;
  overflow-x: auto;
  overflow-y: hidden;
  white-space: nowrap;
  max-width: 100%;
}
.model-option {
  width: 100%;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: none;
  background: transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-align: right;
}
.model-option[aria-selected="true"] { background: var(--color-primary-subtle); }
.model-check {
  flex: 0 0 16px;
  width: 16px;
  color: var(--color-primary);
  order: 0;
}
.model-copy { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: flex-start; }
.model-name { font-size: .86rem; color: var(--color-text); }
.model-hint { font-size: .72rem; color: var(--color-text-muted); }
@media (hover: hover) and (pointer: fine) {
  [data-tip] { position: relative; }
  [data-tip]::after {
    content: attr(data-tip);
    position: absolute;
    bottom: calc(100% + 6px);
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    background: var(--color-surface);
    color: var(--color-text);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    padding: 4px 8px;
    font-size: var(--text-caption);
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    z-index: var(--z-popover);
    box-shadow: var(--shadow-sm);
    transition: opacity var(--motion-fast) var(--ease);
  }
  [data-tip]:hover::after,
  [data-tip]:focus-visible::after { opacity: 1; }
}
@media (pointer: coarse) {
  [data-tip]::after { display: none !important; }
}
@media (prefers-reduced-motion: reduce) {
  [data-tip]::after { transition: none; }
}

.plans-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-4);
}
.plan-col {
  padding: var(--space-4);
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.plan-col.is-current { border-color: var(--color-primary); }
.plan-col .price { font-size: 1.25rem; font-weight: 600; }
.plan-col .plan-limit { color: var(--color-text-muted); font-size: var(--text-small); line-height: 1.7; }
.plan-col .btn { margin-top: auto; width: 100%; }

.api-intro { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(220px, .8fr); gap: var(--space-6); background: transparent; }
.api-security-note, .api-endpoint, .api-key-panel, .api-inventory-panel, .api-quickstart {
  background: transparent;
  border: 0;
  border-radius: 0;
  padding: 0;
  box-shadow: none;
}
.api-facts { display: flex; flex-direction: column; }
.api-endpoint {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--color-border-subtle);
}
.api-panel-head { padding-bottom: var(--space-3); border-bottom: 1px solid var(--color-border-subtle); margin-bottom: var(--space-3); }
.key-row { padding-inline: 0; }
.api-code {
  max-height: 280px;
  overflow: auto;
  direction: ltr;
  unicode-bidi: isolate;
  text-align: left;
}

.view-empty-state {
  min-height: 120px;
  padding: var(--space-6) var(--space-4);
  border: 0;
  background: transparent;
}
.view-empty-state .empty-state-icon {
  width: 32px !important;
  height: 32px !important;
  max-width: 40px !important;
  max-height: 40px !important;
  color: var(--color-text-muted);
}
.view-state.is-loading .state-message,
.view-state.is-error .state-message {
  min-height: 64px;
  justify-content: flex-start;
}

@media (max-width: 900px) {
  .plans-grid { grid-template-columns: 1fr; }
  .api-intro { grid-template-columns: 1fr; }
  .prompt-actions { flex-wrap: wrap; }
}
@media (max-width: 600px) {
  .app-view.secondary-page { padding-inline: 14px; }
  .secondary-row, .prompt-row, .kb-row, .memory-row, .key-row { align-items: flex-start; }
  .prompt-actions { flex-direction: column; align-items: stretch; width: 100%; }
}

/* ============================================================
   4.3 Secondary geometry contract
   Direct children share one 1040px frame. Narrow inner stacks
   pin to inline-start of that frame (physical-right in RTL).
   ============================================================ */
.app-view.secondary-page {
  --secondary-form-width: 640px;
  --secondary-row-measure: 36rem;
}
.app-view.secondary-page > .view-header,
.app-view.secondary-page > .view-toolbar,
.app-view.secondary-page > .view-section {
  width: min(100%, var(--secondary-width)) !important;
  max-width: var(--secondary-width) !important;
  margin-inline: auto;
}
.app-view.secondary-page > .prompt-create,
.app-view.secondary-page > .memory-create,
.app-view.secondary-page > .kb-search-wrap {
  display: flex;
  justify-content: flex-start;
  gap: var(--space-2);
}
.app-view.secondary-page > .prompt-create .input,
.app-view.secondary-page > .memory-create .input,
.app-view.secondary-page > .kb-search-wrap .input,
.app-view.secondary-page > .history-toolbar .input {
  max-width: var(--secondary-form-width);
  flex: 1 1 auto;
}
.app-view.secondary-page > .kb-form .input,
.app-view.secondary-page > .kb-form textarea {
  max-width: var(--secondary-form-width);
}
.app-view.secondary-page .hist-item,
.app-view.secondary-page .prompt-row,
.app-view.secondary-page .kb-row,
.app-view.secondary-page .memory-row {
  justify-content: flex-start;
  width: max-content;
  max-width: min(100%, calc(var(--secondary-row-measure) + 8rem));
  margin-inline-start: 0;
  margin-inline-end: auto;
}
.app-view.secondary-page .hist-popover {
  inset-inline-start: auto;
  inset-inline-end: 0;
}
.app-view.secondary-page .hist-main,
.app-view.secondary-page .prompt-body,
.app-view.secondary-page .row-body {
  flex: 1 1 auto;
  min-width: 0;
  max-width: var(--secondary-row-measure);
}
.app-view.secondary-page .hist-menu,
.app-view.secondary-page .prompt-actions {
  flex: 0 0 auto;
  margin-inline: 0;
}
.app-view.secondary-page .view-empty-state,
.app-view.secondary-page .empty-state.view-empty-state {
  align-items: flex-start;
  text-align: start;
  max-width: min(100%, var(--secondary-form-width));
  margin-inline-start: 0;
  margin-inline-end: auto;
  width: 100%;
  box-sizing: border-box;
}
[dir="ltr"] [data-back] svg {
  transform: scaleX(-1);
}
[dir="rtl"] [data-back] svg {
  transform: none;
}

/* ============================================================
   History Conversation Library V3 — scoped to #view-history
   ============================================================ */
#view-history.history-library {
  --history-library-width: 880px;
  --secondary-width: var(--history-library-width);
}
#view-history.history-library > .view-header,
#view-history.history-library > .view-toolbar,
#view-history.history-library > .view-section {
  width: min(100%, var(--history-library-width)) !important;
  max-width: var(--history-library-width) !important;
  margin-inline: auto;
}
#view-history .history-toolbar {
  display: flex;
  justify-content: stretch;
}
#view-history .history-toolbar .input {
  max-width: none;
  width: 100%;
  flex: 1 1 auto;
}
#view-history .history-list {
  max-width: var(--history-library-width) !important;
  display: flex;
  flex-direction: column;
  gap: 0;
}
#view-history .history-group-title {
  font-size: var(--text-caption);
  font-weight: var(--weight-semibold);
  color: var(--color-text-muted);
  padding: 16px 8px 6px;
}
#view-history .hist-item {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr) auto;
  align-items: center;
  column-gap: 10px;
  width: 100%;
  max-width: none;
  min-height: 60px;
  margin: 0;
  padding: 8px 8px;
  border-radius: var(--radius-sm);
  border-bottom: 0;
  position: relative;
}
#view-history .hist-item:hover,
#view-history .hist-item:focus-visible {
  background: var(--color-surface-hover);
}
#view-history .hist-main {
  max-width: none;
  min-width: 0;
  flex: unset;
  text-align: start;
}
#view-history .hist-title {
  display: block;
  direction: rtl;
  text-align: right;
  unicode-bidi: isolate;
}
#view-history .hist-menu {
  opacity: .4;
  width: 36px;
  height: 36px;
}
#view-history .hist-item:hover .hist-menu,
#view-history .hist-item:focus-within .hist-menu {
  opacity: 1;
}
@media (pointer: coarse) {
  #view-history .hist-menu { opacity: 1; }
}
#view-history .hist-popover {
  inset-inline-end: 8px;
  inset-inline-start: auto;
}
#view-history .view-empty-state,
#view-history .empty-state.view-empty-state {
  max-width: 100%;
  width: 100%;
  align-items: center;
  text-align: center;
  margin-inline: auto;
  padding: var(--space-8) var(--space-4);
}
#view-history .history-load-more {
  align-self: center;
  margin: 12px 0;
}

/* ============================================================
   Workspace Architecture V3 — archetypes (geometry only)
   ============================================================ */
.chat-pane {
  min-width: 0;
}
.workspace-frame--library {
  --secondary-width: 880px;
  --history-library-width: 880px;
}
.workspace-frame--settings {
  --secondary-width: 880px;
}
.workspace-frame--wide {
  --secondary-width: 1080px;
}
.workspace-frame--library > .view-header,
.workspace-frame--library > .view-toolbar,
.workspace-frame--library > .view-section,
.workspace-frame--settings > .view-header,
.workspace-frame--settings > .view-toolbar,
.workspace-frame--settings > .view-section,
.workspace-frame--wide > .view-header,
.workspace-frame--wide > .view-toolbar,
.workspace-frame--wide > .view-section {
  width: min(100%, var(--secondary-width)) !important;
  max-width: var(--secondary-width) !important;
  margin-inline: auto;
}
.workspace-frame--library > .view-toolbar .input,
.workspace-frame--library > .kb-form .input,
.workspace-frame--library > .kb-form textarea {
  max-width: none !important;
  width: 100%;
}
.app-view.workspace-frame--library .prompt-row,
.app-view.workspace-frame--library .kb-row,
.app-view.workspace-frame--library .memory-row {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr) auto;
  align-items: center;
  width: 100% !important;
  max-width: none !important;
  margin-inline: 0 !important;
  column-gap: 10px;
}
.workspace-frame--library .prompt-body,
.workspace-frame--library .row-body {
  max-width: none;
  min-width: 0;
}
.workspace-frame--library .prompt-actions {
  flex: 0 0 auto;
}
.app-view.workspace-frame--library .view-empty-state,
.app-view.workspace-frame--library .empty-state.view-empty-state {
  max-width: 100% !important;
  width: 100% !important;
  margin-inline: auto !important;
  align-items: center;
  text-align: center;
}
.workspace-frame--settings .setting-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(min-content, 320px);
  gap: 16px;
  align-items: start;
  width: 100%;
  max-width: none;
}
.workspace-frame--settings .setting-copy { min-width: 0; }
.workspace-frame--settings .setting-row > .mono,
.workspace-frame--settings .setting-row > .btn,
.workspace-frame--settings .setting-row > .usage-rows {
  min-width: 0;
}
.chat-reading-column > .msg.assistant {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr);
  column-gap: 12px;
  align-items: start;
  justify-content: stretch;
  width: 100%;
}
.chat-reading-column > .msg.assistant .msg-avatar {
  width: 24px;
  height: 24px;
}
.chat-reading-column > .msg.assistant .body {
  min-width: 0;
}
@media (max-width: 720px) {
  .workspace-frame--library,
  .workspace-frame--settings,
  .workspace-frame--wide {
    --secondary-width: 100%;
    --history-library-width: 100%;
  }
  .workspace-frame--settings .setting-row {
    grid-template-columns: 1fr;
  }
}

/* ============================================================
   Web Search + Citations V1 — inline evidence only
   ============================================================ */
.search-activity {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  min-height: 24px;
  margin: 0 0 8px;
  color: var(--color-text-muted);
  font-size: var(--text-caption);
  line-height: 1.5;
  white-space: normal;
}
.search-activity-icon {
  width: 14px;
  height: 14px;
  flex: 0 0 14px;
  color: var(--color-text-secondary);
}
.search-activity-label { color: var(--color-text-secondary); font-weight: 600; }
.search-activity-status { color: var(--color-text-muted); }
.search-activity-detail {
  max-width: min(360px, 60vw);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  unicode-bidi: plaintext;
}
.search-activity.is-active .search-activity-icon { animation: search-activity-pulse 1.2s ease-in-out infinite; }
@keyframes search-activity-pulse {
  0%, 100% { opacity: .45; }
  50% { opacity: 1; }
}
.market-quote-widget {
  box-sizing: border-box;
  width: min(100%, 560px);
  max-width: 100%;
  margin: 10px 0 12px;
  padding: var(--space-4);
  border: var(--border-default);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  color: var(--color-text);
  box-shadow: var(--shadow-sm);
  direction: rtl;
  overflow-wrap: anywhere;
}
.market-quote-head,
.market-quote-price-row,
.market-quote-details,
.market-quote-source {
  display: flex;
  align-items: center;
  min-width: 0;
}
.market-quote-head { gap: var(--space-2); justify-content: space-between; }
.market-quote-label {
  color: var(--color-text);
  font-size: var(--text-body-strong);
  letter-spacing: .02em;
}
.market-quote-name {
  min-width: 0;
  flex: 1;
  color: var(--color-text-muted);
  font-size: var(--text-caption);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.market-quote-refresh {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: var(--control-sm);
  height: var(--control-sm);
  padding: 0;
  border: var(--border-default);
  border-radius: 999px;
  background: var(--color-surface-subtle);
  color: var(--color-text-secondary);
  cursor: pointer;
}
.market-quote-refresh:hover,
.market-quote-refresh:focus-visible {
  border-color: var(--color-primary);
  color: var(--color-primary-ink);
  outline: 2px solid color-mix(in srgb, var(--color-primary) 28%, transparent);
  outline-offset: 1px;
}
.market-quote-refresh:disabled { cursor: wait; opacity: .72; }
.market-quote-refresh-icon { width: var(--icon-sm); height: var(--icon-sm); }
.market-quote-widget.is-refreshing .market-quote-refresh-icon { animation: market-quote-spin 1s linear infinite; }
@keyframes market-quote-spin { to { transform: rotate(360deg); } }
.market-quote-price-row { gap: var(--space-3); margin-top: 10px; flex-wrap: wrap; }
.market-quote-price {
  font-family: var(--font-mono);
  font-size: clamp(1.25rem, 3vw, 1.6rem);
  line-height: 1.3;
  font-variant-numeric: tabular-nums;
}
.market-quote-movement {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 7px;
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: var(--text-caption);
  font-variant-numeric: tabular-nums;
  unicode-bidi: isolate;
}
.market-quote-movement.is-positive { color: var(--color-success); background: var(--color-success-subtle); }
.market-quote-movement.is-negative { color: var(--color-danger); background: var(--color-danger-subtle); }
.market-quote-movement.is-neutral { color: var(--color-text-muted); background: var(--color-surface-subtle); }
.market-quote-details {
  gap: 6px 10px;
  margin-top: 8px;
  color: var(--color-text-muted);
  font-size: var(--text-caption);
  flex-wrap: wrap;
}
.market-quote-status,
.market-quote-change { unicode-bidi: isolate; }
.market-quote-source {
  gap: 2px;
  margin-top: 10px;
  color: var(--color-text-muted);
  font-size: var(--text-caption);
}
.market-quote-source a {
  min-width: 0;
  color: var(--color-primary-ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.market-quote-refresh-state {
  display: block;
  min-height: 1.4em;
  margin-top: 6px;
  color: var(--color-text-muted);
  font-size: var(--text-caption);
}
.market-quote-refresh-state.is-failed { color: var(--color-danger); }
.citation-wrap {
  position: relative;
  display: inline-flex;
  vertical-align: baseline;
  margin-inline: 2px;
  direction: ltr;
  unicode-bidi: isolate;
}
.citation-chip {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  min-height: 22px;
  padding: 1px 5px;
  border: 1px solid var(--color-border-subtle);
  border-radius: 999px;
  background: var(--color-primary-subtle);
  color: var(--color-primary-ink);
  font: inherit;
  font-size: var(--text-caption);
  line-height: 1.25;
  cursor: pointer;
  direction: ltr;
  unicode-bidi: isolate;
}
.citation-chip:hover,
.citation-chip:focus-visible {
  border-color: var(--color-primary);
  outline: 2px solid color-mix(in srgb, var(--color-primary) 28%, transparent);
  outline-offset: 1px;
}
.citation-preview {
  position: absolute;
  z-index: 30;
  inset-block-start: calc(100% + 6px);
  inset-inline-start: 0;
  width: min(300px, calc(100vw - 32px));
  max-width: calc(100vw - 24px);
  padding: 10px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-text);
  box-shadow: var(--shadow-md);
  direction: rtl;
  text-align: start;
  overflow-wrap: anywhere;
}
.citation-preview[hidden] { display: none !important; }
.citation-preview-title,
.source-title { display: block; overflow-wrap: anywhere; line-height: 1.55; }
.citation-preview-domain,
.source-meta {
  display: block;
  margin-top: 2px;
  color: var(--color-text-muted);
  font-family: var(--font-mono);
  font-size: 10px;
  overflow-wrap: anywhere;
}
.citation-preview-snippet,
.source-snippet {
  margin: 6px 0 0;
  color: var(--color-text-secondary);
  font-size: var(--text-caption);
  line-height: 1.65;
  overflow-wrap: anywhere;
}
.citation-preview-date { display: block; margin-top: 5px; color: var(--color-text-muted); font-size: 10px; }
.citation-preview-link,
.source-open {
  display: inline-flex;
  margin-top: 8px;
  color: var(--color-primary-ink);
  font-size: var(--text-caption);
  text-decoration: none;
}
.citation-preview-link:focus-visible,
.source-open:focus-visible {
  border-radius: 4px;
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}
.sources-section { width: 100%; max-width: 100%; gap: 7px; }
.sources-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}
.sources-bar .cit-head { margin: 0; }
.source-chips { display: flex; flex-wrap: wrap; gap: 6px; min-width: 0; }
.source-chip {
  display: inline-flex;
  align-items: center;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 3px 8px;
  border: 1px solid var(--color-border-subtle);
  border-radius: 999px;
  background: var(--color-surface-subtle);
  color: var(--color-text-secondary);
  font-size: var(--text-caption);
  unicode-bidi: isolate;
}
.source-chip-more { font-variant-numeric: tabular-nums; }
.source-bar-open {
  appearance: none;
  margin-inline-start: auto;
  border: none;
  background: none;
  color: var(--color-primary-ink);
  font: inherit;
  font-size: var(--text-caption);
  cursor: pointer;
}
.source-bar-open:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; }
.source-drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 70;
  background: color-mix(in srgb, var(--color-text) 28%, transparent);
  pointer-events: auto;
}
.source-drawer-backdrop[hidden],
.source-drawer[hidden] {
  display: none !important;
}
html.source-drawer-open { overflow: hidden; }
.source-drawer {
  position: fixed;
  z-index: 72;
  inset-block: 0;
  inset-inline-end: 0;
  width: min(420px, 100vw);
  max-width: 460px;
  display: flex;
  flex-direction: column;
  background: var(--color-surface);
  color: var(--color-text);
  border-inline-start: 1px solid var(--color-border);
  box-shadow: var(--shadow-md);
  direction: rtl;
  overflow: hidden;
}
.source-drawer.is-sheet {
  inset-block-start: auto;
  inset-inline: 0;
  width: 100%;
  max-width: none;
  max-height: min(78vh, 640px);
  border-inline-start: none;
  border-start-start-radius: 16px;
  border-start-end-radius: 16px;
}
.source-drawer-close {
  position: relative;
  z-index: 2;
  pointer-events: auto;
  flex-shrink: 0;
}
.source-drawer-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 16px 10px;
  border-bottom: 1px solid var(--color-border-subtle);
}
.source-drawer-head h2 { margin: 0; font-size: 1rem; }
.source-drawer-sub { margin: 4px 0 0; color: var(--color-text-muted); font-size: var(--text-caption); }
.source-drawer-list { overflow: auto; padding: 8px 16px 24px; }
.source-drawer-item { padding-block: 12px; }
@media (prefers-reduced-motion: reduce) {
  .source-drawer, .source-drawer-backdrop { transition: none; }
}
.sources-section .cit-head { display: flex; align-items: baseline; gap: 2px; margin-bottom: 1px; }
.cit-count { color: var(--color-text-muted); font-weight: 400; }
.source-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: start;
  gap: 8px;
  min-width: 0;
  padding: 7px 0;
  border-top: 1px solid var(--color-border-subtle);
}
.source-row .cit-n {
  margin-top: 2px;
  min-width: 30px;
  height: 20px;
  border-radius: 999px;
  background: var(--color-surface-subtle);
  color: var(--color-text-secondary);
  font-size: 10px;
  line-height: 20px;
  text-align: center;
  unicode-bidi: isolate;
}
.source-copy { min-width: 0; }
.source-open { align-self: start; white-space: nowrap; }
@media (max-width: 480px) {
  .search-activity-detail { max-width: 48vw; }
  .market-quote-widget { width: 100%; padding: var(--space-3); }
  .market-quote-details { align-items: flex-start; flex-direction: column; gap: 3px; }
  .citation-preview { inset-inline-start: auto; inset-inline-end: 0; width: min(300px, calc(100vw - 24px)); }
  .source-row { grid-template-columns: auto minmax(0, 1fr); }
  .source-open { grid-column: 2; justify-self: start; margin-top: 3px; }
}
@media (prefers-reduced-motion: reduce) {
  .search-activity.is-active .search-activity-icon { animation: none; }
  .market-quote-widget.is-refreshing .market-quote-refresh-icon { animation: none; }
}

/* ===================================================================
   Motion & Interaction V1 — one token set, state-driven only.
   Every rule here animates a REAL ui state (sendable, streaming, search
   lifecycle, drawer open, upload state). No decorative loops.
   =================================================================== */
:root {
  --mf-micro: 140ms;   /* micro feedback                     */
  --mf-ui: 200ms;      /* ui transition (open/close, hover)  */
  --mf-state: 320ms;   /* meaningful state change only       */
  --mf-ease: cubic-bezier(.22, 1, .36, 1);
  --mf-ease-out: cubic-bezier(.16, 1, .3, 1);
}

/* ---- 1 COMPOSER / SEND ------------------------------------------- */
.send-btn { transition: transform var(--mf-micro) var(--mf-ease), opacity var(--mf-micro) var(--mf-ease); }
.send-btn.is-sendable { opacity: 1; transform: scale(1); }
.send-btn.is-sendable:active { transform: scale(.96); }
.send-btn:not(.is-sendable):not(.is-loading):not(.is-stop) { opacity: .45; transform: scale(.98); }
.send-btn.is-stop { opacity: 1; }

/* ---- message enter ----------------------------------------------- */
.msg.mf-enter { animation: mfMsgIn var(--mf-state) var(--mf-ease-out) both; }
.msg.mf-enter.is-leaving { animation: mfMsgOut var(--mf-ui) var(--mf-ease) both; }
@keyframes mfMsgIn  { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes mfMsgOut { from { opacity: 1; transform: none; } to { opacity: 0; transform: translateY(-4px); } }

/* ---- 2 THINKING INDICATOR ---------------------------------------- */
.thinking { transition: opacity var(--mf-ui) var(--mf-ease); }
.thinking.is-done { opacity: 0; }

/* ---- 3 PRO SEARCH RAIL ------------------------------------------- */
.mf-rail {
  display: flex; align-items: center; gap: 8px;
  font-size: .76rem; color: var(--muted);
  margin: 0 0 6px; min-height: 20px;
  transition: opacity var(--mf-ui) var(--mf-ease);
}
.mf-rail[hidden] { display: none; }
.mf-rail-step { display: inline-flex; align-items: center; gap: 5px; opacity: .4; transition: opacity var(--mf-ui) var(--mf-ease); }
.mf-rail-step::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.mf-rail-step[data-on="1"] { opacity: 1; color: var(--accent); }
.mf-rail-sep { opacity: .3; }
/* thin settle line, not a fake percentage bar */
.mf-rail-line { flex: 1; height: 1px; background: var(--line-soft); border-radius: 1px; overflow: hidden; min-width: 24px; }
.mf-rail-line i { display: block; height: 100%; width: 0; background: var(--accent); transition: width var(--mf-state) var(--mf-ease); }
.mf-rail.is-settled .mf-rail-line i { width: 100%; }

/* ---- 5 MESSAGE ACTIONS ------------------------------------------- */
.msg-actions {
  opacity: 0; transform: translateY(2px);
  transition: opacity var(--mf-ui) var(--mf-ease), transform var(--mf-ui) var(--mf-ease);
  pointer-events: none;
}
.msg:hover .msg-actions,
.msg:focus-within .msg-actions,
.msg-actions:focus-within { opacity: 1; transform: none; pointer-events: auto; }
@media (hover: none) { .msg-actions { opacity: 1; transform: none; pointer-events: auto; } }
@media (pointer: coarse) { .msg-actions { opacity: 1; transform: none; pointer-events: auto; } }

/* ---- 6 SIDEBAR RECENTS ------------------------------------------ */
.sidebar-history-item { transition: background var(--mf-ui) var(--mf-ease), opacity var(--mf-ui) var(--mf-ease), transform var(--mf-ui) var(--mf-ease); }
.sidebar-history-item.mf-enter { animation: mfRowIn var(--mf-state) var(--mf-ease-out) both; }
.sidebar-history-item.mf-leaving { opacity: 0; transform: scale(.98); }
@keyframes mfRowIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }

/* ---- 4 / 11 SOURCES ---------------------------------------------- */
.mf-source-chip { transition: transform var(--mf-micro) var(--mf-ease), border-color var(--mf-micro) var(--mf-ease); }
.mf-source-chip:hover, .mf-source-chip:focus-visible { transform: translateY(-1px); }
.mf-source-row { transition: background var(--mf-ui) var(--mf-ease), border-color var(--mf-ui) var(--mf-ease); }
.mf-source-row.is-flash { animation: mfSourceFlash 380ms var(--mf-ease); }
@keyframes mfSourceFlash { 0% { background: var(--accent-soft); } 100% { background: transparent; } }
.mf-source-count { display: inline-block; transition: opacity var(--mf-ui) var(--mf-ease); }
.mf-source-count.is-new { animation: mfCountIn var(--mf-ui) var(--mf-ease-out) both; }
@keyframes mfCountIn { from { opacity: 0; transform: translateY(-3px); } to { opacity: 1; transform: none; } }
.mf-source-count.is-pulse { animation: mfCountPulse 420ms var(--mf-ease) 1; }
@keyframes mfCountPulse { 0% { opacity: 1; } 45% { opacity: .35; } 100% { opacity: 1; } }

/* ---- 8 UPLOAD CHIP ----------------------------------------------- */
.att-chip { transition: opacity var(--mf-ui) var(--mf-ease), transform var(--mf-ui) var(--mf-ease); }
.att-chip.mf-enter { animation: mfRowIn var(--mf-state) var(--mf-ease-out) both; }
.att-chip[data-state="uploading"], .att-chip[data-state="processing"] { border-color: var(--accent); }
.att-chip[data-state="ready"] { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.att-chip[data-state="failed"] { border-color: #ef4444; animation: mfErrOnce var(--mf-ui) var(--mf-ease) 1; }
@keyframes mfErrOnce { 0%,100% { transform: none; } 40% { transform: translateX(-3px); } }
.att-chip.is-leaving { opacity: 0; transform: scale(.96); }

/* ---- 9 SELECTORS ------------------------------------------------- */
.ds-popover, #modelPopover, #headerMenu {
  transform-origin: top center;
  transition: opacity var(--mf-micro) var(--mf-ease), transform var(--mf-micro) var(--mf-ease);
}
.ds-popover:not([hidden]) { animation: mfPop var(--mf-micro) var(--mf-ease-out) both; }
@keyframes mfPop { from { opacity: 0; transform: translateY(-4px) scale(.985); } to { opacity: 1; transform: none; } }
.ds-option, [role="option"] { transition: background var(--mf-micro) var(--mf-ease), color var(--mf-micro) var(--mf-ease); }

/* ---- 10 EMPTY STATE ---------------------------------------------- */
.empty-state .brand-avatar { animation: mfBreathe 4.5s var(--mf-ease) infinite; }
@keyframes mfBreathe { 0%,100% { opacity: 1; transform: none; } 50% { opacity: .82; transform: scale(1.015); } }
.starter-chip, .empty-state button { transition: transform var(--mf-micro) var(--mf-ease), border-color var(--mf-micro) var(--mf-ease), background var(--mf-micro) var(--mf-ease); }
.starter-chip:hover, .empty-state button:hover { transform: translateY(-1px); }
.starter-chip:focus-visible, .empty-state button:focus-visible { transform: none; }

/* ---- 7 / 14 READING-REGION + WORKSPACE TRANSITIONS --------------- */
.chat-log, .app-view:not(.hidden) {
  animation: mfRegionIn var(--mf-ui) var(--mf-ease-out) both;
}
@keyframes mfRegionIn { from { opacity: .85; transform: translateY(3px); } to { opacity: 1; transform: none; } }

/* ---- 12 COMMAND PALETTE ------------------------------------------ */
.mf-palette-backdrop {
  position: fixed; inset: 0; z-index: 200;
  background: color-mix(in srgb, #000 46%, transparent);
  display: grid; place-items: start center;
  padding-top: 12vh;
  animation: mfFade var(--mf-ui) var(--mf-ease) both;
}
.mf-palette {
  width: min(520px, calc(100vw - 24px));
  background: var(--card); border: 1px solid var(--line);
  border-radius: 14px; box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: mfPop var(--mf-ui) var(--mf-ease-out) both;
}
.mf-palette-input {
  width: 100%; border: 0; border-bottom: 1px solid var(--line);
  background: transparent; color: var(--text);
  padding: 14px 16px; font: inherit; outline: none;
}
.mf-palette-list { max-height: 46vh; overflow-y: auto; padding: 6px; }
.mf-palette-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 10px 12px; border: 0; border-radius: 9px;
  background: transparent; color: var(--text);
  font: inherit; text-align: start; cursor: pointer;
  transition: background var(--mf-micro) var(--mf-ease);
}
.mf-palette-item[aria-selected="true"] { background: var(--accent-soft); color: var(--accent-ink); }
.mf-palette-empty { padding: 18px; text-align: center; color: var(--muted); font-size: .84rem; }
@keyframes mfFade { from { opacity: 0; } to { opacity: 1; } }

/* ---- 13 CONTINUE PILL -------------------------------------------- */
.scroll-bottom { transition: opacity var(--mf-ui) var(--mf-ease), transform var(--mf-ui) var(--mf-ease); }
.scroll-bottom:not(.hidden) { animation: mfPillIn var(--mf-ui) var(--mf-ease-out) both; }
@keyframes mfPillIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---- REDUCED MOTION (explicit, additive) ------------------------- */
@media (prefers-reduced-motion: reduce) {
  .empty-state .brand-avatar { animation: none; }
  .msg.mf-enter, .sidebar-history-item.mf-enter, .att-chip.mf-enter { animation: none; }
  .msg.mf-enter.is-leaving, .sidebar-history-item.mf-leaving, .att-chip.is-leaving { animation: none; opacity: 0; }
  .mf-rail-line i { transition: none; }
  .mf-source-row.is-flash, .mf-source-count.is-pulse, .mf-source-count.is-new, .att-chip[data-state="failed"] { animation: none; }
  .ds-popover:not([hidden]), .mf-palette, .mf-palette-backdrop, .scroll-bottom:not(.hidden) { animation: none; }
  .chat-log, .app-view:not(.hidden) { animation: none; }
  .msg-actions { transform: none; }
}

/* ---- 4 SOURCES DRAWER: restrained, RTL-aware --------------------- */
.source-drawer, .source-drawer-backdrop {
  transition: opacity var(--mf-ui) var(--mf-ease), transform var(--mf-ui) var(--mf-ease);
}
.source-drawer-backdrop { opacity: 0; }
.source-drawer { transform: translateX(-12px); opacity: 0; }
.source-drawer-backdrop.is-open { opacity: 1; }
.source-drawer.is-open { transform: none; opacity: 1; }
/* mobile bottom sheet: slide from its own edge */
.source-drawer.is-sheet { transform: translateY(14px); opacity: 0; }
.source-drawer.is-sheet.is-open { transform: none; opacity: 1; }
.source-drawer-item { transition: background var(--mf-ui) var(--mf-ease); border-radius: 8px; }
.source-drawer-item.mf-flash { animation: mfSourceFlash 380ms var(--mf-ease); }
.source-chip { transition: transform var(--mf-micro) var(--mf-ease), border-color var(--mf-micro) var(--mf-ease); }
@media (hover: hover) {
  .source-chip:hover { transform: translateY(-1px); }
}
@media (prefers-reduced-motion: reduce) {
  .source-drawer, .source-drawer-backdrop { transition: none; transform: none; opacity: 1; }
  .source-drawer-item.mf-flash { animation: none; }
}

/* Trust/legal pages — minimal, same tokens as the rest of the site. */
.legal-page{max-width:760px;margin:0 auto;padding:56px 24px 80px;line-height:1.95;color:var(--color-text,inherit)}
.legal-page h1{font-size:1.9rem;margin:0 0 8px}
.legal-page h2{font-size:1.15rem;margin:32px 0 8px}
.legal-page ul{padding-inline-start:20px;margin:8px 0}
.legal-page li{margin:4px 0}
.legal-page code{background:var(--color-surface-raised,#f1f3f6);padding:1px 5px;border-radius:5px;font-size:.9em}
.legal-updated{color:var(--color-text-muted,var(--muted));font-size:.85rem;margin:0 0 28px}
.legal-note{margin-top:28px;padding:14px 16px;border:1px solid var(--color-border-subtle,var(--line));border-radius:12px;font-size:.9rem;color:var(--color-text-muted,var(--muted))}
.legal-back{margin-top:40px}

/* ---- P1 public pages: /pricing /api/* /search ---- */
.page-body{margin:0;background:var(--bg,#f6f8fb);color:var(--color-text,#111827);line-height:1.9}
.site-header{display:flex;align-items:center;justify-content:space-between;gap:16px;flex-wrap:wrap;
  max-width:1080px;margin:0 auto;padding:18px 24px}
.site-brand{display:flex;align-items:center;gap:8px;text-decoration:none;color:inherit;font-weight:700}
.site-brand img{border-radius:8px}
.site-nav{display:flex;gap:18px;flex-wrap:wrap}
.site-nav a{text-decoration:none;color:inherit;opacity:.85;padding:4px 2px;border-bottom:2px solid transparent}
.site-nav a:hover,.site-nav a.is-current{opacity:1;border-bottom-color:var(--accent,#2563eb)}
.page-main{max-width:1080px;margin:0 auto;padding:8px 24px 72px}
.page-main h1{font-size:2rem;line-height:1.5;margin:8px 0 12px}
.page-main h2{font-size:1.25rem;margin:36px 0 10px}
.page-main h3{font-size:1.05rem;margin:22px 0 8px}
.page-main .lead{font-size:1.05rem;opacity:.85;margin:0 0 18px}
.page-main p{margin:10px 0}
.page-main a{color:var(--accent,#2563eb)}
.crumbs{font-size:.85rem;opacity:.7;margin:6px 0}
.crumbs a{color:inherit}
.crumbs span{margin:0 6px;opacity:.5}
.pre{white-space:pre-wrap;overflow-x:auto}
pre.code{background:#0f172a;color:#e2e8f0;direction:ltr;text-align:left;padding:16px 18px;
  border-radius:12px;overflow-x:auto;font-size:.85rem;line-height:1.7;margin:14px 0}
pre.code code{font-family:ui-monospace,SFMono-Regular,Menlo,monospace;background:none;padding:0;color:inherit}
code{font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:.92em;
  background:rgba(15,23,42,.07);padding:1px 5px;border-radius:5px}
table.plan-table{width:100%;border-collapse:collapse;margin:16px 0;font-size:.92rem;display:block;overflow-x:auto}
table.plan-table caption{text-align:start;font-weight:700;padding-bottom:8px}
table.plan-table th,table.plan-table td{border:1px solid rgba(15,23,42,.12);padding:10px 12px;text-align:start;vertical-align:top}
table.plan-table thead th{background:rgba(15,23,42,.05)}
.plan-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(260px,1fr));gap:16px;margin:22px 0}
.plan-card{border:1px solid rgba(15,23,42,.12);border-radius:16px;padding:20px;background:#fff}
.plan-card h2{margin:0 0 6px;font-size:1.15rem}
.plan-price{font-size:1.5rem;font-weight:700;margin:0 0 10px}
.plan-price small{font-size:.75rem;font-weight:400;opacity:.7}
.plan-facts{margin:0 0 10px;padding-inline-start:18px;font-size:.92rem}
.plan-features{font-size:.9rem;opacity:.85}
.cta-row{display:flex;gap:10px;flex-wrap:wrap;margin:22px 0}
/* WS4: legacy public-page .btn neutralized; base .btn (inline-flex, centered) applies */
a.btn{text-decoration:none}
.api-toc{margin:36px 0 0;padding:18px;border:1px solid rgba(15,23,42,.12);border-radius:14px;background:rgba(15,23,42,.03)}
.api-toc h2{margin:0 0 10px;font-size:1.05rem}
.api-toc ul{list-style:none;margin:0;padding:0;display:grid;gap:8px}
.api-toc a{display:block;font-weight:600}
.api-toc span{font-size:.85rem;opacity:.75}
.model-list{display:grid;gap:14px;margin:20px 0}
.model-card{border:1px solid rgba(15,23,42,.12);border-radius:14px;padding:16px 18px;background:#fff}
.model-card h3{margin:0 0 8px}
.model-card p{margin:6px 0;font-size:.94rem}
.search-demo{border:1px solid rgba(15,23,42,.12);border-radius:14px;padding:18px;background:#fff;margin:16px 0}
.demo-q{font-weight:700;margin:0 0 8px}
.demo-a{margin:0 0 10px}
.demo-src{margin:0;padding-inline-start:18px;font-size:.9rem}
.site-footer{border-top:1px solid rgba(15,23,42,.12);margin-top:40px}
.site-footer-inner{max-width:1080px;margin:0 auto;padding:22px 24px;display:flex;justify-content:space-between;
  gap:14px;flex-wrap:wrap;font-size:.88rem;opacity:.8}
.site-footer-inner nav{display:flex;gap:16px;flex-wrap:wrap}
@media (max-width:640px){
  .page-main h1{font-size:1.5rem}
  .site-header{padding:14px 16px}
  .page-main{padding:4px 16px 56px}
  .plan-grid{grid-template-columns:1fr}
}


/* WS4: design-system level — page layout, header, toast, skeleton, bidi, a11y */
:root {
  --page-max: var(--content-page, 1040px);   /* ONE content width for every top-level view */
  --page-pad-inline: var(--space-6, 24px);
  --page-gap: var(--space-4, 16px);          /* vertical rhythm between header and sections */
  --toast-bg: #1f2937;
  --toast-fg: #f8fafc;
  --toast-action: #93c5fd;
}
:root[data-theme="light"] { --toast-bg: #1f2937; --toast-fg: #f8fafc; --toast-action: #93c5fd; }
:root[data-theme="dark"], :root:not([data-theme="light"]) { --toast-bg: #e8edf5; --toast-fg: #111827; --toast-action: #1d4ed8; }

/* one width for history, skills, prompts, knowledge, memory, settings, plans, keys */
.workspace-frame--library, .workspace-frame--settings, .workspace-frame--wide,
.app-view.secondary-page, .settings-page, #view-history.history-library {
  --secondary-width: var(--page-max);
  --history-library-width: var(--page-max);
}
@media (max-width: 720px) {
  .workspace-frame--library, .workspace-frame--settings, .workspace-frame--wide,
  .app-view.secondary-page, .settings-page, #view-history.history-library {
    --secondary-width: 100%;
    --history-library-width: 100%;
  }
}
#view-skills #skillsRoot { max-width: var(--page-max); }

/* shared page header: title, optional subtitle, optional primary-action slot (.page-actions) */
.page-head[data-page-header] {
  display: flex; align-items: flex-start; gap: var(--space-3, 12px); flex-wrap: wrap;
  margin-block: 0 var(--page-gap);
}
.page-head[data-page-header] .view-heading { flex: 1 1 16rem; min-inline-size: 0; }
.page-head[data-page-header] .secondary-title { font-size: var(--text-page-title, 1.4rem); line-height: 1.4; }
.page-head[data-page-header] .secondary-description { margin-block-start: 4px; color: var(--color-text-muted); }
.page-head[data-page-header] .page-actions { margin-inline-start: auto; display: flex; gap: var(--space-2, 8px); align-items: center; flex-wrap: wrap; }

/* LTR islands: code, URLs, keys, snippets keep their own direction and never merge with neighbours */
.ltr-island, .ltr-value, .key-prefix, .api-endpoint code {
  direction: ltr; unicode-bidi: isolate; text-align: start; overflow-wrap: anywhere;
}
bdi { unicode-bidi: isolate; }
/* mixed-language strings rendered from data: pick direction from the first strong character (== dir="auto") */
.hist-title, .row-title, .prompt-title, .msg-search-title, .sh-title, .source-title, .model-name { unicode-bidi: plaintext; text-align: start; }
.ltr-island-row { display: flex; align-items: center; gap: var(--space-2, 8px); min-inline-size: 0; }
.ltr-island-row > .ltr-island { flex: 1 1 auto; min-inline-size: 0; }

/* toast: one component, one rule. Mobile = bottom-center; desktop = bottom inline-end */
.toast {
  position: fixed; z-index: var(--z-toast, 300);
  inset-inline: 16px; inset-block-end: calc(20px + env(safe-area-inset-bottom, 0px));
  margin-inline: auto; inline-size: fit-content; max-inline-size: calc(100% - 32px);
  display: flex; align-items: center; gap: 14px;
  padding: 10px 16px; border-radius: 12px;
  background: var(--toast-bg); color: var(--toast-fg);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .25);
  font-size: var(--text-small, .875rem); font-weight: 500; line-height: 1.6;
  opacity: 0; visibility: hidden; pointer-events: none; translate: 0 8px;
  transition: opacity .2s ease, translate .2s ease, visibility 0s linear .2s;
}
.toast.show { opacity: 1; visibility: visible; pointer-events: auto; translate: 0 0; transition-delay: 0s; }
@media (min-width: 721px) {
  .toast { inset-inline: auto 24px; margin-inline: 0; inset-block-end: 24px; }
}
.toast-action {
  border: 0; background: transparent; color: var(--toast-action); font: inherit; font-weight: 700;
  cursor: pointer; padding: 4px 8px; border-radius: 6px; min-block-size: 32px;
}
.toast-action:focus-visible { outline: 2px solid var(--toast-action); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { .toast, .toast.show { transition: none; translate: 0 0; } }

/* skeleton: one base for every placeholder (WS2 hist-skel, WS3 sk-skel-bar, shared .skel) */
.skel, .sk-skel-bar, #view-history .hist-skel-line, #view-history .hist-skel-dot {
  background: linear-gradient(90deg, var(--color-surface-subtle) 0%, var(--color-surface-hover, #e8edf4) 50%, var(--color-surface-subtle) 100%);
  background-size: 200% 100%;
}
@media (prefers-reduced-motion: no-preference) {
  .skel { animation: skelShimmer 1.4s linear infinite; }
}
@keyframes skelShimmer { to { background-position: -200% 0; } }
.skel-line { display: block; block-size: 12px; border-radius: 6px; margin-block: 6px; }
.skel-line.w90 { inline-size: 90%; } .skel-line.w70 { inline-size: 70%; } .skel-line.w40 { inline-size: 40%; }
.skel-circle { display: inline-block; inline-size: 18px; block-size: 18px; border-radius: 50%; }
.skel-lines { flex: 1 0 100%; inline-size: 100%; }
/* reserve space for async regions so content does not shift when it arrives */
#chatList, #promptList, #kbResults, #memoryList, #plansGrid, #usageGrid, #keyInventory, #shareList { min-block-size: 120px; }
#plansGrid { min-block-size: 260px; }
.view-state.is-loading .state-message { min-block-size: 120px; }

/* accessibility baseline */
:where(a, button, input, select, textarea, summary, [role="button"], [tabindex]):focus-visible {
  outline: 2px solid var(--color-primary); outline-offset: 2px;
}
:root[data-theme="dark"] :where(a, button, input, select, textarea, summary, [role="button"], [tabindex]):focus-visible,
:root:not([data-theme="light"]) :where(a, button, input, select, textarea, summary, [role="button"], [tabindex]):focus-visible {
  outline-color: #8cc2ff;
}
.btn-lg { min-inline-size: 0; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; }
  .skel, .sk-skel-bar { animation: none !important; }
}

/* WS7: QA fixes - page menu button, plans notice width, keys rows, history action column, dark primary text */
.page-menu-btn { display: none; flex: 0 0 auto; place-items: center; align-self: flex-start; }
@media (max-width: 1199px) {
  .page-menu-btn { display: grid; }
  .page-head[data-page-header] .view-heading { flex-basis: 8rem; }
}
.app-view.secondary-page > .ws6-note { width: min(100%, var(--secondary-width, var(--page-max))); max-width: var(--secondary-width, var(--page-max)); margin-inline: auto; margin-block: 0 var(--page-gap); box-sizing: border-box; }
#view-api .api-endpoint .api-value { flex-direction: row; justify-content: flex-start; align-items: center; }
#view-api .api-endpoint .api-label { align-self: center; }
#view-api .api-quickstart .api-panel-head { align-items: center; }
.page-head[data-page-header] .page-actions > .btn { white-space: nowrap; }
@media (max-width: 480px) { #view-api .api-endpoint { grid-template-columns: minmax(0, 1fr); gap: 6px; } }
.send-btn { color: var(--color-text-inverse, #fff); }

/* WS7b: dialogs centred (global *{margin:0} removed UA margin:auto); empty-state RTL; focusable history link */
dialog{margin:auto}
#starterChips{direction:rtl;text-align:start}
