/* ZEX design system — shared tokens, reset and primitives.
   Graphite + near-black surfaces, white/gray type, controlled Lime Spark accent. */
@font-face { font-family: 'Geist'; src: url('/assets/fonts/Geist-Variable.woff2') format('woff2'); font-weight: 100 900; font-display: swap; }
@font-face { font-family: 'Geist Mono'; src: url('/assets/fonts/GeistMono-Variable.woff2') format('woff2'); font-weight: 100 900; font-display: swap; }

:root {
  --lime: #9DFF2E;
  --lime-hover: #B2FF5C;
  --lime-ink: #0A0B0D;
  --lime-soft: rgba(157, 255, 46, 0.10);
  --lime-line: rgba(157, 255, 46, 0.32);
  --graphite: #23262F;

  --bg: #0A0B0D;
  --bg-1: #101115;
  --bg-2: #15171C;
  --bg-3: #1B1E24;
  --line: rgba(255, 255, 255, 0.08);
  --line-2: rgba(255, 255, 255, 0.14);
  --text: #EDEEF0;
  --text-2: #A6AAB3;
  --text-3: #6F737D;
  --danger: #FF7466;
  --danger-soft: rgba(255, 116, 102, 0.1);
  --warn: #F2C14E;
  --ok: #9DFF2E;
  --accent-text: #9DFF2E;

  --r-1: 6px;
  --r-2: 9px;
  --r-3: 12px;
  --surface-raised: #1A1C21;
  --shadow-pop: 0 18px 48px rgba(0, 0, 0, 0.42), 0 0 0 1px var(--line);
  --font: 'Geist', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --mono: 'Geist Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --ease: cubic-bezier(.2, .7, .2, 1);
  --ease-out: cubic-bezier(.16, 1, .3, 1);

  /* ZEX UI 5 — one scale for radii, control sizes, elevation and focus. */
  --r-4: 16px;
  --r-5: 22px;
  --r-pill: 999px;
  --ctl-sm: 32px;
  --ctl: 38px;
  --ctl-lg: 46px;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, .28), 0 0 0 1px var(--line);
  --shadow-2: 0 10px 30px rgba(0, 0, 0, .28), 0 0 0 1px var(--line);
  --ring: 0 0 0 3px var(--lime-soft);
  --surface-hover: color-mix(in srgb, var(--text) 5%, transparent);
  --surface-press: color-mix(in srgb, var(--text) 8%, transparent);

  /* Shared composer surface (.zx-composer). */
  --cmp-bg: color-mix(in srgb, var(--bg-2) 70%, var(--bg-1));
  --cmp-border: var(--line-2);
  --cmp-border-focus: color-mix(in srgb, var(--lime) 46%, var(--line-2));
  --cmp-radius: 24px;
  --cmp-shadow: 0 1px 0 rgba(255, 255, 255, .03) inset, 0 12px 36px rgba(0, 0, 0, .30);
  --cmp-shadow-focus: 0 0 0 4px color-mix(in srgb, var(--lime) 9%, transparent), 0 12px 36px rgba(0, 0, 0, .30);
  --cmp-font: 15.5px;
  --cmp-line: 1.6;
  --cmp-ctl: 36px;
  color-scheme: dark;
}

[data-theme='light'] {
  --bg: #F6F6F4;
  --bg-1: #FFFFFF;
  --bg-2: #F0F0ED;
  --bg-3: #E7E7E3;
  --line: rgba(10, 11, 13, 0.08);
  --line-2: rgba(10, 11, 13, 0.16);
  --text: #121317;
  --text-2: #4D515A;
  --text-3: #80848D;
  --lime-soft: rgba(110, 170, 0, 0.12);
  --lime-line: rgba(90, 140, 0, 0.35);
  --danger: #C83226;
  --ok: #547D00;
  --accent-text: #4E7A00;
  --surface-raised: #FFFFFF;
  --danger-soft: rgba(209, 59, 43, 0.08);
  --shadow-pop: 0 12px 40px rgba(0, 0, 0, 0.12), 0 0 0 1px var(--line);
  --shadow-1: 0 1px 2px rgba(10, 11, 13, .06), 0 0 0 1px var(--line);
  --shadow-2: 0 10px 30px rgba(10, 11, 13, .08), 0 0 0 1px var(--line);
  --cmp-bg: #FFFFFF;
  --cmp-border: rgba(10, 11, 13, .12);
  --cmp-border-focus: rgba(78, 122, 0, .45);
  --cmp-shadow: 0 1px 2px rgba(10, 11, 13, .04), 0 10px 30px rgba(10, 11, 13, .07);
  --cmp-shadow-focus: 0 0 0 4px rgba(110, 170, 0, .12), 0 10px 30px rgba(10, 11, 13, .07);
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 15px; line-height: 1.55; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }
img, svg, video, canvas { display: block; max-width: 100%; }
button, input, textarea, select { font: inherit; color: inherit; }
a { color: inherit; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -0.02em; line-height: 1.15; }
p { margin: 0; }
code, pre, kbd { font-family: var(--mono); }
::selection { background: var(--lime); color: var(--lime-ink); }
:focus-visible { outline: 2px solid var(--lime); outline-offset: 2px; border-radius: 4px; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip-link { position: absolute; left: 12px; top: -48px; z-index: 1000; background: var(--lime); color: var(--lime-ink); padding: 8px 12px; border-radius: var(--r-1); font-weight: 600; text-decoration: none; }
.skip-link:focus { top: 12px; }

/* ---------- wordmark ---------- */
.wordmark { display: inline-flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: 0.14em; text-decoration: none; color: var(--text); font-size: 15px; }
.wordmark .mark { width: 22px; height: 22px; flex: none; }
.wordmark small { font-weight: 500; letter-spacing: 0.1em; font-size: 10px; color: var(--text-3); }

/* ---------- buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 38px; padding: 0 16px; border-radius: var(--r-2); border: 1px solid var(--line-2); background: transparent; color: var(--text); font-weight: 500; font-size: 14px; text-decoration: none; cursor: pointer; white-space: nowrap; transition: background .15s var(--ease), border-color .15s var(--ease), color .15s var(--ease), transform .1s; user-select: none; }
.btn:hover { background: var(--bg-3); border-color: var(--line-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled='true'] { opacity: .5; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--lime); border-color: var(--lime); color: var(--lime-ink); font-weight: 600; }
.btn-primary:hover { background: var(--lime-hover); border-color: var(--lime-hover); }
[data-theme='light'] .btn-primary { background: #121317; border-color: #121317; color: #fff; }
[data-theme='light'] .btn-primary:hover { background: #2a2d33; }
.btn-ghost { border-color: transparent; color: var(--text-2); }
.btn-ghost:hover { color: var(--text); background: var(--bg-3); }
.btn-danger { border-color: transparent; background: var(--danger-soft); color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-sm { height: 30px; padding: 0 10px; font-size: 13px; border-radius: var(--r-1); }
.btn-lg { height: 46px; padding: 0 22px; font-size: 15px; }
.btn-block { width: 100%; }
.icon-btn { display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: var(--r-2); border: 0; background: transparent; color: var(--text-2); cursor: pointer; transition: background .15s, color .15s; flex: none; }
.icon-btn:hover { background: var(--bg-3); color: var(--text); }
.icon-btn:disabled { opacity: .4; cursor: not-allowed; }
.icon-btn svg, .btn svg { width: 18px; height: 18px; flex: none; }
.btn-sm svg { width: 15px; height: 15px; }

/* ---------- forms ---------- */
.field { display: grid; gap: 6px; }
.field > span, .field > .field-label, .label { font-size: 13px; color: var(--text-2); font-weight: 500; }
.input, .textarea, .select { width: 100%; height: 42px; padding: 0 12px; border-radius: var(--r-2); border: 1px solid var(--line-2); background: var(--bg-1); color: var(--text); outline: none; transition: border-color .15s, box-shadow .15s; }
.textarea { height: auto; min-height: 96px; padding: 10px 12px; resize: vertical; line-height: 1.5; }
.select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--text-3) 50%), linear-gradient(135deg, var(--text-3) 50%, transparent 50%); background-position: calc(100% - 17px) 18px, calc(100% - 12px) 18px; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 32px; }
.input:focus, .textarea:focus, .select:focus { border-color: var(--lime-line); box-shadow: 0 0 0 3px var(--lime-soft); }
.input[aria-invalid='true'] { border-color: var(--danger); }
.hint { font-size: 12.5px; color: var(--text-3); }
.error-text { font-size: 13px; color: var(--danger); }
.check { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-size: 14px; color: var(--text-2); }
.switch { position: relative; width: 36px; height: 20px; flex: none; appearance: none; background: var(--bg-3); border: 1px solid var(--line-2); border-radius: 999px; cursor: pointer; transition: background .15s; margin: 0; }
.switch::after { content: ''; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: var(--text-2); transition: transform .18s var(--ease), background .18s; }
.switch:checked { background: var(--lime); border-color: var(--lime); }
.switch:checked::after { transform: translateX(16px); background: var(--lime-ink); }

/* ---------- misc ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 8px; border-radius: 999px; font-size: 11.5px; font-weight: 500; background: var(--bg-3); color: var(--text-2); border: 1px solid var(--line); white-space: nowrap; }
.badge-lime { background: var(--lime-soft); color: var(--accent-text); border-color: var(--lime-line); }
.badge-danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.badge-warn { background: rgba(242, 193, 78, .1); color: var(--warn); border-color: transparent; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--text-3); display: inline-block; flex: none; }
.dot-lime { background: var(--lime); box-shadow: 0 0 0 3px var(--lime-soft); }
.dot-danger { background: var(--danger); }
.muted { color: var(--text-2); }
.faint { color: var(--text-3); }
.mono { font-family: var(--mono); }
.spinner { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--line-2); border-top-color: var(--lime); animation: spin .7s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.kbd { font-family: var(--mono); font-size: 11px; padding: 1px 5px; border: 1px solid var(--line-2); border-radius: 4px; color: var(--text-3); }

/* ---------- toasts ---------- */
.toasts { position: fixed; z-index: 2000; left: 50%; bottom: 24px; transform: translateX(-50%); display: grid; gap: 8px; width: min(420px, calc(100vw - 24px)); pointer-events: none; }
.toast { pointer-events: auto; display: flex; align-items: flex-start; gap: 10px; padding: 12px 14px; border-radius: var(--r-2); background: var(--bg-2); box-shadow: var(--shadow-pop); font-size: 14px; animation: toast-in .2s var(--ease); }
.toast.error { border-left: 3px solid var(--danger); }
.toast.success, .toast.ok { border-left: 0; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ---------- dialog ---------- */
dialog.modal { padding: 0; border: 0; border-radius: var(--r-3); background: var(--bg-1); color: var(--text); box-shadow: var(--shadow-pop); width: min(520px, calc(100vw - 24px)); max-height: calc(100dvh - 48px); overflow: auto; }
dialog.modal::backdrop { background: rgba(0, 0, 0, .6); backdrop-filter: blur(2px); }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 20px 0; }
.modal-head h2 { font-size: 17px; }
.modal-body { padding: 16px 20px; display: grid; gap: 14px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 0 20px 18px; flex-wrap: wrap; }

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

/* Server-rendered status pages (403/503 from the edge middleware). */
.status-page { min-height: 100dvh; display: grid; place-items: center; padding: 24px; text-align: center; }
.status-card { display: grid; gap: 12px; justify-items: center; max-width: 440px; }
.status-code { font-family: var(--mono); color: var(--accent-text); font-size: 13px; letter-spacing: .08em; }
.status-card h1 { font-size: 26px; letter-spacing: -0.03em; }

/* SILVERX precision layer: consistent controls, readable surfaces and safe motion. */
:root { --space-1: 4px; --space-2: 8px; --space-3: 12px; --space-4: 16px; --space-6: 24px; --space-8: 32px; }
html { scroll-padding-top: 16px; }
body { font-feature-settings: 'ss01' on, 'cv11' on; }
button, a, input, textarea, select { -webkit-tap-highlight-color: transparent; }
button:not(:disabled), [role='button']:not([aria-disabled='true']) { touch-action: manipulation; }
button:disabled, input:disabled, textarea:disabled, select:disabled { cursor: not-allowed; }
::placeholder { color: var(--text-3); opacity: 1; }
::selection { background: color-mix(in srgb, var(--lime) 34%, transparent); color: var(--text); }
.btn, .icon-btn, .input, .textarea, .select, .badge, dialog.modal { transition-timing-function: var(--ease); }
.icon-btn:focus-visible, .btn:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible { outline: 2px solid var(--lime); outline-offset: 2px; }
dialog.modal { overscroll-behavior: contain; }
dialog.modal::backdrop { animation: backdrop-in .16s ease-out; }
@keyframes backdrop-in { from { opacity: 0; } to { opacity: 1; } }
:dir(rtl) { text-align: start; }
:dir(rtl) .skip-link { left: auto; right: 12px; }
:lang(ar) { font-family: 'Noto Sans Arabic', 'Noto Naskh Arabic', Tahoma, var(--font); line-height: 1.72; }
:dir(rtl) :is(code, pre, kbd, .mono) { direction: ltr; unicode-bidi: isolate; }
:dir(rtl) :is(input[type='number'], input[type='range'], .numeric, .credits-chip) { direction: ltr; }
:dir(rtl) .md :is(th, td) { text-align: start; }
:dir(rtl) .error-text, :dir(rtl) .notice.error { border-left: 0; border-right: 3px solid var(--danger); }
@media (max-width: 360px) {
  body { font-size: 14px; }
  dialog.modal { width: calc(100vw - 16px); max-height: calc(100dvh - 24px); }
}
@media (prefers-reduced-motion: reduce) {
  dialog.modal::backdrop { animation: none; }
}

/* ===================================================================
   ZEX UI 5 — shared primitives used by every workspace page.
   =================================================================== */
.btn { height: var(--ctl); border-radius: var(--r-2); }
.btn-sm { height: var(--ctl-sm); }
.btn-lg { height: var(--ctl-lg); border-radius: 12px; }
.btn-primary { box-shadow: 0 1px 0 rgba(255, 255, 255, .25) inset, 0 6px 18px color-mix(in srgb, var(--lime) 18%, transparent); }
.btn-primary:hover { box-shadow: 0 1px 0 rgba(255, 255, 255, .3) inset, 0 8px 24px color-mix(in srgb, var(--lime) 26%, transparent); }
[data-theme='light'] .btn-primary, [data-theme='light'] .btn-primary:hover { box-shadow: 0 6px 16px rgba(10, 11, 13, .14); }
.icon-btn:active:not(:disabled) { background: var(--surface-press); transform: scale(.96); }
.input:hover:not(:focus), .textarea:hover:not(:focus), .select:hover:not(:focus) { border-color: color-mix(in srgb, var(--text) 22%, transparent); }
.input:focus, .textarea:focus, .select:focus { box-shadow: var(--ring); }
dialog.modal { border-radius: var(--r-4); box-shadow: var(--shadow-2), 0 30px 80px rgba(0, 0, 0, .45); animation: modal-in .2s var(--ease-out); }
@keyframes modal-in { from { opacity: 0; transform: translateY(8px) scale(.985); } }
.toast { border-radius: var(--r-3); padding: 12px 16px; }

/* One composer surface. Pages add `.zx-composer` to their input container. */
.zx-composer {
  position: relative;
  background: var(--cmp-bg);
  border: 1px solid var(--cmp-border);
  border-radius: var(--cmp-radius);
  box-shadow: var(--cmp-shadow);
  transition: border-color .18s var(--ease), box-shadow .18s var(--ease), background .18s var(--ease);
}
.zx-composer:hover:not(:focus-within) { border-color: color-mix(in srgb, var(--text) 20%, transparent); }
.zx-composer:focus-within { border-color: var(--cmp-border-focus); box-shadow: var(--cmp-shadow-focus); }
.zx-composer textarea {
  display: block; width: 100%; resize: none; border: 0; outline: none; background: transparent;
  color: var(--text); font-size: var(--cmp-font); line-height: var(--cmp-line);
  unicode-bidi: plaintext; text-align: start; scrollbar-width: thin;
}
.zx-composer textarea:focus, .zx-composer textarea:focus-visible { outline: none; box-shadow: none; }
.zx-composer textarea::placeholder { color: var(--text-3); }
.zx-composer textarea[dir='rtl'] { font-family: 'Noto Sans Arabic', 'Noto Naskh Arabic', Tahoma, var(--font); line-height: 1.75; }

/* Composer icon buttons (attach, tools, mic) share one size and shape. */
.zx-cmp-btn {
  width: var(--cmp-ctl); height: var(--cmp-ctl); border-radius: var(--r-pill);
  display: inline-grid; place-items: center; flex: none; padding: 0;
  border: 1px solid transparent; background: transparent; color: var(--text-2); cursor: pointer;
  transition: background .15s var(--ease), color .15s var(--ease), border-color .15s var(--ease), transform .1s;
}
.zx-cmp-btn:hover:not(:disabled) { background: var(--surface-hover); color: var(--text); }
.zx-cmp-btn:active:not(:disabled) { transform: scale(.94); background: var(--surface-press); }
.zx-cmp-btn[aria-expanded='true'] { background: var(--surface-press); color: var(--text); }
.zx-cmp-btn[aria-pressed='true'] { background: var(--lime-soft); color: var(--lime-strong); border-color: var(--lime-line); }
.zx-cmp-btn svg { width: 18px; height: 18px; }

/* The send button is identical everywhere. */
.zx-send {
  width: var(--cmp-ctl); height: var(--cmp-ctl); border-radius: var(--r-pill); flex: none;
  display: grid; place-items: center; padding: 0; border: 0; cursor: pointer;
  background: var(--lime); color: var(--lime-ink);
  box-shadow: 0 1px 0 rgba(255, 255, 255, .35) inset, 0 4px 14px color-mix(in srgb, var(--lime) 28%, transparent);
  transition: background .15s var(--ease), transform .12s var(--ease), box-shadow .15s var(--ease), opacity .15s;
}
.zx-send:hover:not(:disabled) { background: var(--lime-hover); transform: translateY(-1px); }
.zx-send:active:not(:disabled) { transform: scale(.94); }
.zx-send:disabled { background: var(--bg-3); color: var(--text-3); box-shadow: none; opacity: 1; cursor: not-allowed; }
.zx-send svg { width: 18px; height: 18px; stroke-width: 2.2; }
[data-theme='light'] .zx-send { background: #121317; color: #fff; box-shadow: 0 4px 12px rgba(10, 11, 13, .18); }
[data-theme='light'] .zx-send:hover:not(:disabled) { background: #2A2D33; }
[data-theme='light'] .zx-send:disabled { background: var(--bg-3); color: var(--text-3); box-shadow: none; }

/* Pill controls inside the composer (power, thinking, active tool). */
.zx-pill {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; flex: none;
  height: 32px; padding: 0 12px; border-radius: var(--r-pill);
  border: 1px solid var(--line); background: transparent; color: var(--text-2);
  font: inherit; font-size: 12.5px; font-weight: 500; white-space: nowrap; cursor: pointer;
  transition: background .15s var(--ease), color .15s var(--ease), border-color .15s var(--ease);
}
.zx-pill:hover, .zx-pill[aria-expanded='true'] { background: var(--surface-hover); color: var(--text); border-color: var(--line-2); }
.zx-pill svg { width: 15px; height: 15px; }

@media (pointer: coarse) {
  :root { --cmp-ctl: 40px; }
}
@media (max-width: 600px) {
  :root { --cmp-radius: 20px; --cmp-font: 16px; }
}
@media (prefers-reduced-motion: reduce) {
  dialog.modal { animation: none; }
  .zx-send:hover:not(:disabled) { transform: none; }
}
