/* ==========================================================================
   Zar design library — zar.css
   The look and feel of every Zar project, distilled from local-claude (the
   reference) and zar_video/boxshow (glow topbar, cloud button, AI cursor).

   Stark, technical, high-contrast. Pure black on pure white, zero radius,
   hairline rules, OpenAI Sans. The interface is monochrome; the aurora is the
   brand and only appears in brand moments (see DESIGN.md → "Where colour lives").

   Load order: this file, then your app CSS. Theme with <html data-theme="dark|light">,
   or leave it unset to follow the OS.
   ========================================================================== */

/* ── Fonts ──────────────────────────────────────────────────────────────── */
@font-face {
  font-family: "OpenAI Sans";
  src: url("../assets/fonts/OpenAISans-Regular.woff2") format("woff2");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "OpenAI Sans";
  src: url("../assets/fonts/OpenAISans-Medium.woff2") format("woff2");
  font-style: normal;
  font-weight: 500;
  font-display: swap;
}
@font-face {
  font-family: "OpenAI Sans";
  src: url("../assets/fonts/OpenAISans-Semibold.woff2") format("woff2");
  font-style: normal;
  font-weight: 600;
  font-display: swap;
}

@property --z-sweep {
  syntax: "<angle>";
  inherits: false;
  initial-value: 0deg;
}

/* ── Tokens: light ──────────────────────────────────────────────────────── */
:root {
  color-scheme: light;

  /* surfaces */
  --bg: #ffffff;           /* app background — pure white, never off-white */
  --bg-sidebar: #ffffff;   /* sidebar is separated by a rule, not a fill */
  --bg-elevated: #ffffff;  /* composer, dialogs, panels, cards */
  --bg-user-msg: #f5f5f5;  /* user message, code blocks, tool output */
  --bg-hover: #f5f5f5;     /* row / button hover */

  /* text — two greys, not three */
  --text: #000000;
  --text-muted: #707070;
  --text-faint: #707070;

  /* lines */
  --border: #e0e0e0;       /* hairlines */
  --border-strong: #000000;/* emphasis, focus, selection */

  /* actions are black, not coloured */
  --accent: #000000;
  --accent-hover: #242424;
  --accent-fg: #ffffff;
  --accent-soft: #f5f5f5;

  /* status — reserved, never a series colour */
  --destructive: #b42318;
  --success: #35ba00;
  --running: #3b82f6;

  /* aurora — the brand. Only inside brand moments. */
  --aurora-c1: #ff7ab6; /* pink       */
  --aurora-c2: #ff5a3c; /* red        */
  --aurora-c3: #ffb020; /* amber      */
  --aurora-c4: #6aa9ff; /* light blue */
  --aurora-c5: #3b82f6; /* blue       */
  --aurora-c6: #2a1a6c; /* deep base  */
  --aurora-opacity: 0.82;

  /* chart palette — fixed order, never cycled, never improvised */
  --chart-1: #2563eb;
  --chart-2: #dc4a26;
  --chart-3: #0e9384;
  --chart-4: #a16207;
  --chart-5: #be3f8f;
  --chart-6: #6d28d9;

  /* scrims */
  --scrim: rgb(0 0 0 / 0.4);
  --scrim-media: rgb(0 0 0 / 0.72);
  --sweep: rgb(255 255 255 / 0.75); /* skeleton highlight */

  /* type */
  --font-sans: "OpenAI Sans", -apple-system, BlinkMacSystemFont, "Segoe UI",
    Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
    "Liberation Mono", monospace;
  --text-label: 11px;      /* uppercase labels, 0.06em */
  --text-caption: 12px;    /* captions, mono readouts, tool blocks */
  --text-meta: 12.5px;     /* model chip, descriptions */
  --text-ui: 13.5px;       /* sidebar, buttons, controls */
  --text-body: 15px;       /* prose, line-height 1.6 */
  --text-greeting: 28px;   /* empty-state greeting, weight 500, -0.02em */
  --text-display: 44px;    /* page titles, weight 500, -0.02em, lh 1.05 */

  /* radius — zero. Only genuine dots are round. */
  --radius: 0;

  /* layout */
  --sidebar-w: 260px;
  --column-w: 740px;
  --column-pad: 24px;
  --rhythm: 28px;          /* vertical gap between messages / blocks */

  /* motion */
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);   /* the house curve */
  --spring: cubic-bezier(0.34, 1.56, 0.64, 1);  /* press, pop, marker */
  --spring-soft: cubic-bezier(0.34, 1.3, 0.64, 1);
  --spring-pop: cubic-bezier(0.34, 1.96, 0.64, 1);
  --ease-camera: cubic-bezier(0.4, 0, 0.2, 1);  /* cursor zoom / camera */
  --dur-fast: 150ms;       /* hover colour */
  --dur-base: 220ms;       /* focus, fades, phrase swaps */
  --dur-resize: 300ms;     /* card resize */
  --panel-open-dur: 400ms;
  --panel-close-dur: 350ms;
  --panel-blur: 2px;
  --modal-open-dur: 250ms;
  --modal-close-dur: 150ms;
  --modal-scale: 0.96;
  --tabs-dur: 250ms;
  --text-swap-dur: 150ms;
  --text-swap-y: 4px;
  --text-swap-blur: 2px;
}

/* ── Tokens: dark (a dark theme is chosen, not a flipped light theme) ───── */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #000000;
  --bg-sidebar: #000000;
  --bg-elevated: #111111;
  --bg-user-msg: #161616;
  --bg-hover: #161616;
  --text: #ffffff;
  --text-muted: #a3a3a3;
  --text-faint: #a3a3a3;
  --border: #2a2a2a;
  --border-strong: #ffffff;
  --accent: #ffffff;
  --accent-hover: #e5e5e5;
  --accent-fg: #000000;
  --accent-soft: #161616;
  --destructive: #ff6b5f;
  --chart-1: #4f8ff7;
  --chart-2: #e2532f;
  --chart-3: #0d9488;
  --chart-4: #b8820e;
  --chart-5: #e05aa0;
  --chart-6: #8b6cf0;
  --aurora-c3: #ffd24a;
  --aurora-c4: #ffffff;
  --aurora-c6: #340b05;
  --aurora-opacity: 0.95;
  --sweep: rgb(255 255 255 / 0.06);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #000000;
    --bg-sidebar: #000000;
    --bg-elevated: #111111;
    --bg-user-msg: #161616;
    --bg-hover: #161616;
    --text: #ffffff;
    --text-muted: #a3a3a3;
    --text-faint: #a3a3a3;
    --border: #2a2a2a;
    --border-strong: #ffffff;
    --accent: #ffffff;
    --accent-hover: #e5e5e5;
    --accent-fg: #000000;
    --accent-soft: #161616;
    --destructive: #ff6b5f;
    --chart-1: #4f8ff7;
    --chart-2: #e2532f;
    --chart-3: #0d9488;
    --chart-4: #b8820e;
    --chart-5: #e05aa0;
    --chart-6: #8b6cf0;
    --aurora-c3: #ffd24a;
    --aurora-c4: #ffffff;
    --aurora-c6: #340b05;
    --aurora-opacity: 0.95;
    --sweep: rgb(255 255 255 / 0.06);
  }
}

/* ── Base ───────────────────────────────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
  border-radius: 0;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--text-body);
  font-weight: 400;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4, h5, h6 {
  margin: 0;
  font-weight: 500;
  letter-spacing: -0.02em;
  line-height: 1.05;
}

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

button {
  border: 0;
  background: none;
  padding: 0;
  cursor: pointer;
}

a {
  color: inherit;
  text-underline-offset: 3px;
}

code, kbd, pre, samp {
  font-family: var(--font-mono);
}

::selection {
  background: var(--text);
  color: var(--bg);
}

/* Focus is a hard rule, never a glow or a coloured ring. */
:focus-visible {
  outline: 1px solid var(--border-strong);
  outline-offset: 2px;
}

/* ── Type helpers ───────────────────────────────────────────────────────── */
.z-label {
  color: var(--text-muted);
  font-size: var(--text-label);
  font-weight: 400;
  letter-spacing: 0.06em;
  line-height: 1.4;
  text-transform: uppercase;
}

.z-eyebrow {
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: var(--text-label);
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.z-display {
  font-size: var(--text-display);
  font-weight: 500;
  letter-spacing: -0.02em;
  line-height: 1.05;
}

.z-greeting {
  margin: 0;
  font-size: var(--text-greeting);
  font-weight: 500;
  letter-spacing: -0.02em;
  line-height: 1.6;
  text-align: center;
}

.z-muted { color: var(--text-muted); }
.z-mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.z-caption { color: var(--text-muted); font-size: var(--text-caption); }

/* ── Buttons ────────────────────────────────────────────────────────────── */
/* Default button: hairline outline, transparent, hover fills --bg-hover. */
.z-btn {
  display: inline-flex;
  min-height: 32px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font-size: var(--text-ui);
  font-weight: 400;
  line-height: 1.5;
  padding: 5px 12px;
  text-decoration: none;
  white-space: nowrap;
  transition:
    background-color 180ms var(--ease-out),
    border-color 180ms var(--ease-out),
    color 180ms var(--ease-out),
    transform 180ms var(--ease-out);
}
.z-btn:hover:not(:disabled) { background: var(--bg-hover); }
.z-btn svg { width: 16px; height: 16px; flex: 0 0 auto; }

/* Primary: --accent fill. Black on light, white on dark. Never coloured. */
.z-btn--primary {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-fg);
}
.z-btn--primary:hover:not(:disabled) {
  border-color: var(--accent-hover);
  background: var(--accent-hover);
}

/* Ghost: no outline until hovered; nav items, toolbars. */
.z-btn--ghost { border-color: transparent; }
.z-btn--ghost[aria-current="page"],
.z-btn--ghost[aria-pressed="true"] { background: var(--bg-hover); }

.z-btn--danger { color: var(--destructive); }
.z-btn--sm { min-height: 28px; font-size: 12.5px; padding: 3px 8px; }
.z-btn--block { width: 100%; justify-content: flex-start; }

.z-btn:disabled,
.z-icon-btn:disabled {
  color: var(--text-faint);
  cursor: not-allowed;
  opacity: 0.6;
}

/* Square icon button: 28 (inline) or 32 (toolbar). */
.z-icon-btn {
  display: inline-grid;
  width: 32px;
  height: 32px;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  transition:
    background-color 150ms var(--ease-out),
    color 150ms var(--ease-out),
    transform 180ms var(--ease-out);
}
.z-icon-btn:hover:not(:disabled) { background: var(--bg-hover); color: var(--text); }
.z-icon-btn--outline { border-color: var(--border); color: var(--text); }
.z-icon-btn--sm { width: 28px; height: 28px; }
.z-icon-btn svg { width: 16px; height: 16px; }

/* Press feedback: lift 1px on hover, spring down on press. */
:is(.z-btn, .z-icon-btn, .z-send):hover:not(:disabled) { transform: translateY(-1px); }
:is(.z-btn, .z-icon-btn, .z-send):active:not(:disabled) {
  transform: scale(0.92);
  transition:
    background-color 180ms var(--ease-out),
    color 180ms var(--ease-out),
    transform 120ms var(--spring);
}

/* ── Cloud button (brand moment) ────────────────────────────────────────────
   The one primary CTA on a page (Generate, Record, Start). A monochrome button
   floating in a feathered aurora cloud that blooms on hover. Use once per view. */
.z-btn--cloud {
  position: relative;
  isolation: isolate;
  border-color: var(--text);
  background: var(--accent);
  color: var(--accent-fg);
  font-weight: 500;
  padding: 7px 16px;
  transition: transform 160ms ease;
}
.z-btn--cloud::before {
  position: absolute;
  z-index: -1;
  inset: -9px -13px;
  content: "";
  background:
    radial-gradient(58% 82% at 26% 22%, color-mix(in srgb, var(--aurora-c4) 72%, transparent), transparent 64%),
    radial-gradient(58% 82% at 82% 80%, color-mix(in srgb, var(--aurora-c1) 64%, transparent), transparent 64%),
    radial-gradient(72% 92% at 50% 55%, color-mix(in srgb, var(--aurora-c5) 38%, transparent), transparent 72%);
  filter: blur(14px);
  opacity: 0.4;
  pointer-events: none;
  transition: opacity 240ms ease, filter 240ms ease, inset 240ms ease;
}
.z-btn--cloud:hover:not(:disabled) {
  border-color: var(--text);
  background: var(--accent);
  transform: translateY(-1px);
}
.z-btn--cloud:hover:not(:disabled)::before {
  inset: -14px -20px;   /* the cloud swells */
  filter: blur(18px);
  opacity: 0.92;
}
.z-btn--cloud:active:not(:disabled) { transform: translateY(0); }

/* The Zar mark as a monochrome glyph inside a button. */
.z-mark-icon {
  display: inline-block;
  width: 1.05rem;
  height: 1.05rem;
  flex: 0 0 auto;
  background: currentColor;
  -webkit-mask: url("../assets/logo-mask.png") center / contain no-repeat;
  mask: url("../assets/logo-mask.png") center / contain no-repeat;
}

/* ── Inputs ─────────────────────────────────────────────────────────────── */
.z-field { display: grid; gap: 6px; }
.z-field__hint { color: var(--text-muted); font-size: var(--text-caption); }
.z-field__error { color: var(--destructive); font-size: 13px; }

.z-input,
.z-textarea,
.z-select {
  width: 100%;
  min-height: 34px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  padding: 6px 10px;
  transition: border-color var(--dur-base) var(--ease-out);
}
.z-textarea { min-height: 96px; resize: vertical; }
.z-textarea--mono { font-family: var(--font-mono); font-size: 13px; }
.z-input::placeholder,
.z-textarea::placeholder { color: var(--text-muted); }
.z-input:focus,
.z-textarea:focus,
.z-select:focus {
  border-color: var(--border-strong);
  outline: none;
}
.z-input[aria-invalid="true"] { border-color: var(--destructive); }

/* ── Switch (square) ────────────────────────────────────────────────────── */
.z-switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font-size: var(--text-meta);
  padding: 5px 7px;
}
.z-switch__track {
  position: relative;
  display: block;
  width: 34px;
  height: 18px;
  flex: 0 0 34px;
  border: 1px solid var(--border-strong);
  background: var(--bg);
  transition: background-color 180ms var(--ease-out);
}
.z-switch__thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 12px;
  height: 12px;
  background: var(--text-muted);
  transition: transform 180ms var(--ease-out), background-color 180ms var(--ease-out);
}
.z-switch[aria-checked="true"] { color: var(--text); }
.z-switch[aria-checked="true"] .z-switch__track { background: var(--text); }
.z-switch[aria-checked="true"] .z-switch__thumb {
  background: var(--bg);
  transform: translateX(16px);
}

/* ── Segmented control (fixed segments) ─────────────────────────────────── */
.z-segmented {
  display: inline-grid;
  grid-auto-columns: 1fr;
  grid-auto-flow: column;
  border: 1px solid var(--border);
  padding: 3px;
}
.z-segmented > button {
  background: transparent;
  color: var(--text-muted);
  font-size: var(--text-ui);
  line-height: 1.5;
  padding: 5px 14px;
  transition: background-color 150ms var(--ease-out), color 150ms var(--ease-out);
}
.z-segmented > button:hover { color: var(--text); }
.z-segmented > button[aria-selected="true"],
.z-segmented > button[data-selected="true"] {
  background: var(--accent);
  color: var(--accent-fg);
}

/* ── Sliding tabs (pill tweens between measured positions; see js/zar.js) ── */
.z-tabs {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  border: 1px solid var(--border);
  background: var(--bg);
  padding: 3px;
}
.z-tab {
  position: relative;
  z-index: 1;
  height: 26px;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  padding: 4px 12px;
  white-space: nowrap;
  transition: color var(--tabs-dur) var(--ease-out);
}
.z-tab:hover { color: var(--text); }
.z-tab[aria-selected="true"] { color: var(--accent-fg); }
.z-tabs__pill {
  position: absolute;
  z-index: 0;
  top: 3px;
  left: 0;
  width: 0;
  height: 26px;
  background: var(--accent);
  pointer-events: none;
  transform: translateX(0);
  transition:
    transform var(--tabs-dur) var(--ease-out),
    width var(--tabs-dur) var(--ease-out);
  will-change: transform, width;
}

/* ── Chips, badges, dots ────────────────────────────────────────────────── */
.z-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: var(--text-caption);
  line-height: 1.6;
  padding: 1px 7px;
}
.z-chip--mono { font-family: var(--font-mono); }
.z-chip--solid { border-color: var(--accent); background: var(--accent); color: var(--accent-fg); }
.z-chip--danger { border-color: currentColor; color: var(--destructive); }

/* Dots are the one genuinely round shape. */
.z-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--text-muted);
}
.z-dot--success { background: var(--success); }
.z-dot--running { background: var(--running); animation: z-pulse 1.6s ease-in-out infinite; }
.z-dot--danger { background: var(--destructive); }
/* A status square (banners) — 12px, square. */
.z-square { display: inline-block; width: 12px; height: 12px; flex: 0 0 auto; background: var(--destructive); }

/* ── Surfaces ───────────────────────────────────────────────────────────── */
.z-card {
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  padding: 16px;
}
.z-card--interactive {
  cursor: pointer;
  transition: background-color 150ms var(--ease-out), border-color 150ms var(--ease-out);
}
.z-card--interactive:hover { background: var(--bg-hover); }
.z-card[aria-selected="true"],
.z-card[data-selected="true"] { border-color: var(--border-strong); }

.z-rule { height: 1px; border: 0; margin: 0; background: var(--border); }

/* ── Table: hairlines, no zebra ─────────────────────────────────────────── */
.z-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.z-table th,
.z-table td {
  border: 1px solid var(--border);
  padding: 8px 10px;
  text-align: left;
  vertical-align: top;
}
.z-table th { font-weight: 600; }
.z-table .num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; text-align: right; }

/* ── App shell + sidebar ────────────────────────────────────────────────── */
.z-shell {
  display: flex;
  width: 100%;
  height: 100dvh;
  min-width: 0;
  overflow: hidden;
  background: var(--bg);
}

.z-sidebar {
  display: flex;
  width: var(--sidebar-w);
  flex: 0 0 auto;
  flex-direction: column;
  border-right: 1px solid var(--border);   /* a rule, not a fill */
  background: var(--bg-sidebar);
  padding: 12px 10px;
  transition:
    transform var(--panel-open-dur) var(--ease-out),
    opacity var(--panel-open-dur) var(--ease-out),
    filter var(--panel-open-dur) var(--ease-out);
}
.z-sidebar[data-collapsed="true"] {
  opacity: 0;
  filter: blur(var(--panel-blur));
  pointer-events: none;
  transform: translateX(-24px);
  transition-duration: var(--panel-close-dur);
}

.z-brand {
  display: flex;
  min-height: 32px;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1;
}

.z-section-label {
  display: block;
  padding: 0 10px;
  margin: 20px 0 7px;
}

.z-row {
  position: relative;
  display: flex;
  width: 100%;
  min-width: 0;
  align-items: center;
  gap: 8px;
  border-left: 2px solid transparent;
  background: transparent;
  color: var(--text);
  font-size: var(--text-ui);
  padding: 8px 10px;
  text-align: left;
  transition:
    background-color 150ms var(--ease-out),
    border-color 150ms var(--ease-out);
}
.z-row__title { min-width: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.z-row:hover,
.z-row:focus-within { background: var(--bg-hover); }
.z-row[aria-current="true"],
.z-row[data-active="true"] {
  border-left-color: var(--border-strong);
  background: var(--bg-hover);
}

/* ── Chat ───────────────────────────────────────────────────────────────── */
.z-column {
  width: 100%;
  max-width: var(--column-w);
  margin: 0 auto;
  padding: 0 var(--column-pad);
}

.z-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
}
.z-empty .z-glogo { margin-bottom: 8px; }
.z-empty .z-composer { margin-top: 24px; }

.z-msg + .z-msg { margin-top: var(--rhythm); }

/* User: right-aligned grey block. Assistant: plain prose under the mark.
   Keep this asymmetry. */
.z-msg--user {
  width: fit-content;
  max-width: 75%;
  margin-left: auto;
  background: var(--bg-user-msg);
  padding: 10px 14px;
}
.z-msg--assistant { width: 100%; }
.z-marker {
  display: block;
  width: 13px;
  height: 13px;
  margin-bottom: 7px;
  background: var(--text-muted);
  -webkit-mask: url("../assets/zar-mark.svg") center / contain no-repeat;
  mask: url("../assets/zar-mark.svg") center / contain no-repeat;
}

.z-enter-user { animation: z-user-enter 280ms var(--spring-soft) backwards; }
.z-enter-assistant { animation: z-assistant-enter 260ms var(--ease-out) backwards; }
.z-enter-assistant .z-marker { animation: z-marker-enter 240ms var(--spring) backwards; }

.z-streaming-cursor {
  display: inline-block;
  width: 1ch;
  height: 1em;
  background: var(--accent);
  vertical-align: text-bottom;
  animation: z-blink 1s step-end infinite;
}

/* ── Prose (markdown) ───────────────────────────────────────────────────── */
.z-prose { font-size: var(--text-body); line-height: 1.6; overflow-wrap: anywhere; }
.z-prose > :first-child { margin-top: 0; }
.z-prose > :last-child { margin-bottom: 0; }
.z-prose p { margin: 1em 0; }
.z-prose h1, .z-prose h2, .z-prose h3, .z-prose h4 {
  margin: 1.2em 0 0.6em;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.3;
}
.z-prose h1 { font-size: 22px; }
.z-prose h2 { font-size: 18px; }
.z-prose h3 { font-size: 16px; }
.z-prose ul, .z-prose ol { margin: 1em 0; padding-left: 24px; }
.z-prose li + li { margin-top: 3px; }
.z-prose a { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }
.z-prose strong { font-weight: 600; }
.z-prose blockquote { margin: 1em 0; border-left: 2px solid var(--border-strong); padding-left: 14px; color: var(--text-muted); }
.z-prose table { width: 100%; margin: 1em 0; border-collapse: collapse; }
.z-prose th, .z-prose td { border: 1px solid var(--border); padding: 8px 10px; text-align: left; vertical-align: top; }
.z-prose th { font-weight: 600; }
.z-prose :not(pre) > code {
  border: 1px solid var(--border);
  background: var(--bg-user-msg);
  font-size: 13px;
  padding: 1px 4px;
}
.z-prose pre,
.z-code {
  position: relative;
  overflow-x: auto;
  margin: 1em 0;
  border: 1px solid var(--border);
  background: var(--bg-user-msg);
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.65;
  padding: 12px 14px;
}
.z-prose pre code { border: 0; background: transparent; font: inherit; padding: 0; }
.z-copy {
  position: absolute;
  top: 10px;
  right: 10px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 12px;
  opacity: 0;
  padding: 2px 8px;
  transition: opacity 150ms var(--ease-out), background-color 150ms var(--ease-out);
}
:is(.z-prose pre, .z-code):hover .z-copy,
.z-copy:focus-visible { opacity: 1; }
.z-copy:hover { background: var(--bg-hover); color: var(--text); }

/* ── Composer ───────────────────────────────────────────────────────────── */
.z-composer {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  padding: 12px 14px;
  transition: border-color var(--dur-base) var(--ease-out);
}
.z-composer:focus-within { border-color: var(--border-strong); } /* no glow, no ring */
.z-composer__input {
  display: block;
  width: 100%;
  min-height: 24px;
  max-height: calc(12 * 1.6em);
  border: 0;
  background: transparent;
  font-size: var(--text-body);
  line-height: 1.6;
  outline: none;
  padding: 0;
  resize: none;
}
.z-composer__input::placeholder { color: var(--text-muted); }
.z-composer__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 12px;
}
.z-composer__left { display: flex; align-items: center; gap: 2px; }
.z-model-chip {
  display: inline-flex;
  max-width: min(52vw, 320px);
  align-items: baseline;
  gap: 5px;
  overflow: hidden;
  background: transparent;
  color: var(--text-muted);
  font-size: var(--text-meta);
  padding: 3px 8px;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: background-color 180ms var(--ease-out);
}
.z-model-chip:hover,
.z-model-chip[aria-expanded="true"] { background: var(--bg-hover); }

/* Send: a 32px square, --accent fill. Becomes a stop square while streaming. */
.z-send {
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  background: var(--accent);
  color: var(--accent-fg);
  transition: background-color 180ms var(--ease-out), transform 180ms var(--ease-out);
}
.z-send:hover:not(:disabled) { background: var(--accent-hover); }
.z-send:active:not(:disabled) { transform: scale(0.88); }
.z-send:disabled { background: var(--bg-hover); color: var(--text-muted); cursor: not-allowed; }
.z-send svg { width: 16px; height: 16px; }

/* Picker anchored above the composer (skills, models). */
.z-menu {
  max-height: 260px;
  overflow-y: auto;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  padding: 0;
}
.z-menu__item {
  display: grid;
  width: 100%;
  gap: 1px;
  border-left: 2px solid transparent;
  padding: 10px 12px;
  text-align: left;
  transition: background-color 150ms var(--ease-out);
}
.z-menu__item:hover,
.z-menu__item[data-highlighted="true"] { background: var(--bg-hover); }
.z-menu__item[aria-selected="true"] { border-left-color: var(--border-strong); }
.z-menu__name { font-family: var(--font-mono); font-size: var(--text-ui); }
.z-menu__desc { overflow: hidden; color: var(--text-muted); font-size: var(--text-meta); text-overflow: ellipsis; white-space: nowrap; }

/* ── Working indicator: a conic sweep travelling a static square ────────── */
.z-working {
  display: grid;
  grid-template-rows: 1fr;
  margin-bottom: 12px;
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.4;
  transition:
    grid-template-rows 420ms var(--ease-out),
    margin-bottom 420ms var(--ease-out),
    opacity 420ms var(--ease-out);
}
/* When work finishes it simply leaves — collapses so the answer slides up. */
.z-working[data-leaving="true"] { grid-template-rows: 0fr; margin-bottom: 0; opacity: 0; }
.z-working__inner { display: flex; min-height: 22px; min-width: 0; align-items: center; gap: 8px; overflow: hidden; }
.z-badge-spin {
  position: relative;
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
  margin: 2px;
}
.z-badge-spin::before,
.z-badge-spin::after { position: absolute; inset: 0; content: ""; }
.z-badge-spin::before { border: 1px solid var(--border); }
.z-badge-spin::after {
  padding: 1.5px;
  background: conic-gradient(
    from var(--z-sweep, 0deg),
    transparent 0deg,
    transparent 190deg,
    var(--text-muted) 320deg,
    var(--text) 360deg
  );
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  mask-composite: exclude;
  animation: z-sweep 800ms linear infinite;
}
.z-working__copy { display: grid; min-width: 0; }
.z-working__phrase {
  grid-area: 1 / 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: opacity var(--dur-base) var(--ease-out);
}
.z-working__phrase[data-out="true"] { opacity: 0; }

/* ── Tool call block ────────────────────────────────────────────────────── */
.z-tool { min-width: 0; font-family: var(--font-mono); font-size: var(--text-caption); }
.z-tool + .z-tool { margin-top: 6px; }
.z-tool__head {
  display: flex;
  width: 100%;
  min-width: 0;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font: inherit;
  line-height: 1.5;
  padding: 6px 8px;
  text-align: left;
  transition: background-color 150ms var(--ease-out);
}
.z-tool__head:hover { background: var(--bg-hover); }
.z-tool__chev {
  width: 12px;
  height: 12px;
  flex: 0 0 12px;
  color: var(--text-muted);
  transition: transform 180ms var(--ease-out);
}
.z-tool[open] .z-tool__chev,
.z-tool[data-expanded="true"] .z-tool__chev { transform: rotate(90deg); }
.z-tool__arg { min-width: 0; overflow: hidden; color: var(--text-muted); text-overflow: ellipsis; white-space: nowrap; }
.z-tool__status { margin-left: auto; color: var(--success); white-space: nowrap; }
.z-tool__status[data-failed="true"] { color: var(--destructive); }
.z-tool__spinner {
  display: block;
  width: 12px;
  height: 12px;
  border: 1px solid var(--border);
  border-top-color: var(--text-muted);
  animation: z-spin 700ms linear infinite;
}
.z-tool__out {
  max-height: 240px;
  overflow: auto;
  margin: -1px 0 0;
  border: 1px solid var(--border);
  background: var(--bg-user-msg);
  line-height: 1.55;
  padding: 10px 12px;
  white-space: pre-wrap;
}
.z-tool > summary { list-style: none; }
.z-tool > summary::-webkit-details-marker { display: none; }

/* ── Skeleton: one monochrome highlight sweeping. Never a colour shimmer. ── */
.z-skeleton {
  position: relative;
  isolation: isolate; /* the sweep paints between the fill and the label */
  display: grid;
  overflow: hidden;
  place-items: center;
  border: 1px solid var(--border);
  background: var(--bg-user-msg);
  color: var(--text-muted);
  font-size: 13px;
}
.z-skeleton::after {
  position: absolute;
  z-index: -1;
  inset: 0;
  content: "";
  background: linear-gradient(
    100deg,
    transparent 20%,
    var(--sweep) 50%,
    transparent 80%
  );
  transform: translateX(-100%);
  animation: z-skeleton-sweep 1600ms var(--ease-out) infinite;
}

/* ── Dialog ─────────────────────────────────────────────────────────────── */
.z-scrim {
  position: fixed;
  z-index: 50;
  inset: 0;
  display: grid;
  place-items: center;
  background: var(--scrim);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--modal-open-dur) var(--ease-out);
}
.z-scrim.is-open { opacity: 1; pointer-events: auto; }
.z-dialog {
  width: min(560px, 100vw - 32px);
  max-height: min(720px, 100dvh - 32px);
  overflow: auto;
  border: 1px solid var(--border);   /* an edge, not a shadow */
  background: var(--bg-elevated);
  opacity: 0;
  transform: scale(var(--modal-scale));
  transition:
    transform var(--modal-close-dur) var(--ease-out),
    opacity var(--modal-close-dur) var(--ease-out);
}
.z-scrim.is-open .z-dialog {
  opacity: 1;
  transform: scale(1);
  transition-duration: var(--modal-open-dur);
}
.z-dialog__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  font-size: 15px;
  font-weight: 600;
}
.z-dialog__body { display: grid; gap: 16px; padding: 16px; }
.z-dialog__foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  border-top: 1px solid var(--border);
  padding: 12px 16px;
}

/* ── Banner (fixed, top) ────────────────────────────────────────────────── */
.z-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
  font-size: 13px;
  padding: 8px 16px;
}
.z-banner .z-btn { margin-left: auto; }

/* ── Text swap: one label leaving upward as the next arrives from below ─── */
.z-swap {
  display: inline-block;
  transition:
    transform var(--text-swap-dur) ease-in-out,
    filter var(--text-swap-dur) ease-in-out,
    opacity var(--text-swap-dur) ease-in-out;
}
.z-swap.is-exit {
  filter: blur(var(--text-swap-blur));
  opacity: 0;
  transform: translateY(calc(var(--text-swap-y) * -1));
}
.z-swap.is-enter {
  filter: blur(var(--text-swap-blur));
  opacity: 0;
  transform: translateY(var(--text-swap-y));
  transition: none;
}

/* ==========================================================================
   BRAND MOMENTS — where the aurora is allowed to live
   ========================================================================== */

/* ── GlowLogo: the aurora lives *inside* the mark ───────────────────────── */
.z-glogo,
.z-flogo {
  position: relative;
  display: inline-block;
  width: var(--gsize, 132px);
  height: var(--gsize, 132px);
  flex: 0 0 auto;
}
.z-glogo::before,
.z-flogo.is-fallback::before {
  position: absolute;
  inset: 0;
  content: "";
  background: linear-gradient(
    125deg,
    var(--aurora-c1),
    var(--aurora-c2),
    var(--aurora-c3),
    var(--aurora-c4),
    var(--aurora-c5),
    var(--aurora-c1)
  );
  background-size: 260% 260%;
  -webkit-mask: url("../assets/logo-mask.png") center / contain no-repeat;
  mask: url("../assets/logo-mask.png") center / contain no-repeat;
  will-change: background-position, filter;
}
@media (prefers-reduced-motion: no-preference) {
  .z-glogo::before,
  .z-flogo.is-fallback::before {
    animation:
      z-glogo-drift var(--gspeed, 9s) ease-in-out infinite alternate,
      z-glogo-hue calc(var(--gspeed, 9s) * 2) linear infinite;
  }
}

/* ── FluidLogo: a WebGL fluid of aurora colour inside the mark ─────────────
   js/zar-fluid.js draws the canvas; the host's mask clips it to the logo.
   Hero moments only (one WebGL context each). Without WebGL it falls back to
   the GlowLogo gradient via .is-fallback. */
.z-flogo {
  -webkit-mask: url("../assets/logo-mask.png") center / contain no-repeat;
  mask: url("../assets/logo-mask.png") center / contain no-repeat;
}
.z-flogo__canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}
.z-flogo.is-fallback .z-flogo__canvas { display: none; }
/* The host already masks, so the fallback gradient needn't mask twice. */
.z-flogo.is-fallback::before { -webkit-mask: none; mask: none; }

/* ── Aurora: Dia-style blurred bars rising and breathing (SVG via js/zar.js) */
.z-aurora {
  position: absolute;
  z-index: 0;
  inset: 0;
  overflow: visible;
  pointer-events: none;
}
.z-aurora__rise {
  position: absolute;
  right: 0;
  bottom: -7%;
  left: 0;
  height: var(--ah, 78%);
  transform-origin: bottom;
}
.z-aurora__svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
  opacity: var(--aurora-opacity, 0.9);
}
.z-aurora__g { transform-box: fill-box; transform-origin: center bottom; }
.z-aurora__bar {
  transform-box: fill-box;
  transform-origin: bottom center;
  animation: z-aurora-flow var(--bdur, 9s) ease-in-out var(--bdelay, 0s) infinite alternate;
}
@media (prefers-reduced-motion: no-preference) {
  .z-aurora__g { animation: z-aurora-drift 18s ease-in-out infinite alternate; }
}

/* ── Glow topbar: the aurora rising behind the header ───────────────────────
   Three columns: nav left, GlowLogo centred, utilities right. One hairline
   below. The aurora sits at 150% height / 0.45 opacity so it washes up from
   behind the rule rather than filling the bar. */
.z-topbar-wrap { position: relative; isolation: isolate; overflow: hidden; }
.z-topbar-wrap > .z-aurora { --aurora-opacity: 0.45; }
.z-topbar {
  position: relative;
  z-index: 1;
  display: grid;
  min-height: 144px;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 16px;
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
}
.z-topbar__nav { display: flex; align-items: center; gap: 4px; justify-self: start; }
.z-topbar__nav .z-btn { min-height: 40px; }
.z-topbar__logo { display: inline-flex; color: var(--text); text-decoration: none; }
.z-topbar__end { display: flex; align-items: center; gap: 8px; justify-self: end; }
/* Compact variant for dense app chrome. */
.z-topbar--compact { min-height: 64px; }
.z-topbar--compact .z-glogo { --gsize: 36px; }
@media (max-width: 640px) {
  .z-topbar { grid-template-columns: minmax(0, 1fr); justify-items: center; padding: 24px 16px; }
  .z-topbar__nav, .z-topbar__end { justify-self: center; }
  .z-topbar__logo { order: -1; }
  /* Below this, prefer a dropdown of sections (boxshow does); as a fallback
     the nav scrolls sideways rather than clipping. */
  .z-topbar__nav { max-width: 100%; overflow-x: auto; scrollbar-width: none; }
  .z-topbar__nav::-webkit-scrollbar { display: none; }
}

/* ── Gradient text: reserved for a single "special" label (premium model) ── */
.z-gradient-text {
  background:
    radial-gradient(40% 70% at 20% 30%, color-mix(in srgb, var(--aurora-c5) 90%, transparent), transparent 70%),
    radial-gradient(40% 70% at 80% 70%, color-mix(in srgb, var(--aurora-c1) 85%, transparent), transparent 70%),
    radial-gradient(35% 60% at 55% 20%, color-mix(in srgb, var(--aurora-c3) 80%, transparent), transparent 70%),
    linear-gradient(rgb(108 108 108), rgb(216 216 216));
  background-size: 180% 180%, 180% 180%, 180% 180%, 100% 100%;
  background-repeat: no-repeat;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation:
    z-gradient-hue 4s linear infinite,
    z-gradient-drift 5s ease-in-out infinite;
}

/* ── AI cursor (js/zar-cursor.js builds the DOM) ────────────────────────────
   A white arrow that glides on eased paths, a "thinking" Zar mark that
   swooshes, and a caption that types into a soft gradient cloud. */
.z-cursor {
  position: fixed;
  z-index: 2147483647;
  top: 0;
  left: 0;
  width: 30px;
  height: 30px;
  filter: drop-shadow(0 2px 3px rgb(0 0 0 / 0.4));
  pointer-events: none;
  transition: opacity 200ms ease;
  will-change: transform;
}
.z-cursor svg { display: block; }
.z-cursor__ring {
  position: absolute;
  top: -10px;
  left: -11px;
  width: 34px;
  height: 34px;
  border: 2px solid var(--aurora-c3);
  border-radius: 50%;
  opacity: 0;
  pointer-events: none;
}
.z-cursor__ring.is-clicking { animation: z-cursor-ring 520ms var(--ease-out) forwards; }

.z-cursor-chip {
  position: fixed;
  z-index: 2147483646;
  top: 0;
  left: 0;
  display: flex;
  max-width: min(80vw, 320px);
  align-items: center;
  gap: 10px;
  color: #eaf0ff;
  font: 600 13px/1.3 var(--font-sans);
  letter-spacing: 0.1px;
  opacity: 0;
  padding: 12px 18px;
  pointer-events: none;
  text-shadow: 0 1px 6px rgb(0 6 22 / 0.6);
  transform: translateY(5px) scale(0.96);
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.z-cursor-chip.is-visible { opacity: 1; transform: translateY(0) scale(1); }
/* The cloud: blue + violet washes over a deep navy core, feathered. */
.z-cursor-chip::before {
  position: absolute;
  z-index: -1;
  inset: -10px -16px;
  content: "";
  background:
    radial-gradient(58% 80% at 26% 22%, rgb(90 140 255 / 0.5), transparent 64%),
    radial-gradient(58% 80% at 84% 82%, rgb(150 100 255 / 0.45), transparent 64%),
    radial-gradient(ellipse at center, rgb(14 20 42 / 0.96), rgb(14 20 42 / 0.8) 50%, rgb(14 20 42 / 0) 80%);
  filter: blur(5px);
  transition: filter 0.45s ease, transform 0.45s ease, opacity 0.3s ease;
}
.z-cursor-chip.is-typing::before { filter: blur(12px); transform: scale(1.07); }
.z-cursor-chip.is-thinking { padding: 4px; text-shadow: none; }
.z-cursor-chip.is-thinking::before { opacity: 0; }
.z-cursor-chip__text { white-space: normal; word-break: break-word; }
/* "Thinking": the Zar mark, still, with the aurora sweeping through it. */
.z-cursor-chip__mark {
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  background: linear-gradient(115deg, #ff7ab6, #ffb020, #6aa9ff, #3b82f6, #ff7ab6);
  background-size: 260% 260%;
  -webkit-mask: url("../assets/logo-mask.png") center / contain no-repeat;
  mask: url("../assets/logo-mask.png") center / contain no-repeat;
  animation: z-swoosh 1.6s linear infinite;
  transition: opacity 0.16s ease;
}

/* ── Keyframes ──────────────────────────────────────────────────────────── */
@keyframes z-glogo-drift { 0% { background-position: 0% 50%; } 100% { background-position: 100% 50%; } }
@keyframes z-glogo-hue { to { filter: hue-rotate(360deg); } }
@keyframes z-aurora-flow {
  0% { transform: scaleY(0.88) translateX(-3%); }
  50% { transform: scaleY(1.04) translateX(0%); }
  100% { transform: scaleY(1.18) translateX(3%); }
}
@keyframes z-aurora-drift { 0% { transform: translateX(-2.5%); } 100% { transform: translateX(2.5%); } }
@keyframes z-swoosh { 0% { background-position: 0% 50%; } 100% { background-position: 260% 50%; } }
@keyframes z-cursor-ring { from { opacity: 0.9; transform: scale(0.35); } to { opacity: 0; transform: scale(1.2); } }
@keyframes z-gradient-hue { from { filter: hue-rotate(0deg) saturate(1.3); } to { filter: hue-rotate(-360deg) saturate(1.3); } }
@keyframes z-gradient-drift {
  0%, 100% { background-position: 100% 0%, 0% 100%, 50% 0%, 0 0; }
  50% { background-position: 0% 100%, 100% 0%, 50% 100%, 0 0; }
}
@keyframes z-sweep { to { --z-sweep: 360deg; } }
@keyframes z-spin { to { transform: rotate(360deg); } }
@keyframes z-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }
@keyframes z-blink { 0%, 49% { opacity: 1; } 50%, 100% { opacity: 0; } }
@keyframes z-skeleton-sweep { to { transform: translateX(100%); } }
@keyframes z-user-enter { from { opacity: 0; filter: blur(3px); transform: translate(10px, 6px) scale(0.96); } }
@keyframes z-assistant-enter { from { opacity: 0; transform: translateY(6px); } }
@keyframes z-marker-enter { from { transform: scale(0.7); } }

/* ── Reduced motion: everything settles to its final state ──────────────── */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .z-skeleton::after { display: none; }
}

/* ── Touch: 44px targets, 16px inputs (no iOS zoom) ─────────────────────── */
@media (pointer: coarse) {
  .z-btn, .z-icon-btn, .z-tab, .z-segmented > button, .z-row { min-height: 44px; }
  .z-icon-btn { min-width: 44px; }
  .z-input, .z-textarea, .z-select, .z-composer__input { font-size: 16px; }
  .z-input, .z-select { min-height: 44px; }
}
