/* ==========================================================================
   Lona design system
   Black like the helmet, violet like the eyes. Violet is reserved for
   "Lona is doing something": focus, generation, the bot's gaze.
   ========================================================================== */

:root {
  --void: #000;
  --shell: #111114;      /* helmet */
  --shell-2: #18181d;
  --shell-3: #222229;
  --visor: #060608;      /* glossy inset surfaces */
  --line: rgba(255, 255, 255, .09);
  --line-2: rgba(255, 255, 255, .16);
  --ink: #f5f5f7;
  --ink-2: #c7c7cf;
  --mute: #86868f;
  --eye: #8f73ff;
  --eye-hi: #b9a8ff;
  --eye-deep: #5b3df5;
  --eye-wash: rgba(143, 115, 255, .14);
  --ok: #30d158;
  --warn: #ffd60a;
  --bad: #ff453a;

  --font-display: 'Alexandria', 'IBM Plex Sans Arabic', system-ui, sans-serif;
  --font-ui: 'IBM Plex Sans Arabic', 'Alexandria', -apple-system, 'Segoe UI', system-ui, sans-serif;
  --font-mono: ui-monospace, 'SF Mono', 'Cascadia Code', Consolas, monospace;

  --r-visor: 32px;   /* hero / feature surfaces */
  --r-panel: 22px;   /* tool panels */
  --r-ctl: 14px;     /* inputs, buttons */
  --ease: cubic-bezier(.2, .8, .2, 1);
  --topbar-h: 64px;
}

/* ---------- base for pages built on the system ---------- */
.lona-page, .lona-page * { box-sizing: border-box; }
.lona-page {
  margin: 0;
  min-height: 100vh;
  background: var(--void);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
:where(.lona-page) :is(h1, h2, h3) { font-family: var(--font-display); line-height: 1.15; margin: 0; font-weight: 600; }
:where(.lona-page) p { margin: 0; }
:where(.lona-page) a { color: inherit; }
.lona-page :focus-visible { outline: 2px solid var(--eye); outline-offset: 3px; border-radius: 6px; }
.lona-page ::selection { background: var(--eye); color: #fff; }
/* Latin-only tracking: letter-spacing breaks Arabic joining. */
:lang(en) .l-display, :lang(en) .lona-page h1 { letter-spacing: -0.035em; }

/* ---------- top bar ---------- */
.l-topbar {
  position: fixed; inset: 0 0 auto 0; z-index: 900;
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 12px;
  padding: 0 max(16px, calc((100vw - 1240px) / 2));
  background: rgba(0, 0, 0, .62);
  backdrop-filter: saturate(180%) blur(22px);
  -webkit-backdrop-filter: saturate(180%) blur(22px);
  border-bottom: 1px solid var(--line);
  font-family: var(--font-ui);
  color: var(--ink);
  direction: rtl;
}
html[dir="ltr"] .l-topbar { direction: ltr; }
.l-brand { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); font-family: var(--font-display); font-weight: 600; font-size: 1.05rem; flex-shrink: 0; }
.l-brand svg { width: 34px; height: 34px; display: block; }
.l-crumb { display: flex; align-items: center; gap: 10px; min-width: 0; color: var(--mute); font-size: .95rem; }
.l-crumb::before { content: ''; width: 1px; height: 18px; background: var(--line-2); }
.l-crumb b { color: var(--ink); font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.l-nav { display: flex; gap: 4px; margin-inline-start: 18px; }
.l-nav a { padding: 8px 14px; border-radius: 999px; text-decoration: none; color: var(--ink-2); font-size: .95rem; transition: color .2s, background .2s; }
.l-nav a:hover, .l-nav a[aria-current="page"] { color: var(--ink); background: rgba(255, 255, 255, .07); }
.l-topbar .l-spacer { flex: 1; }
.l-icon-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 38px; min-width: 38px; padding: 0 12px;
  border-radius: 999px; border: 1px solid var(--line); background: rgba(255, 255, 255, .04);
  color: var(--ink); font: 500 .9rem var(--font-ui); cursor: pointer; text-decoration: none;
  transition: background .2s, border-color .2s;
}
.l-icon-btn:hover { background: rgba(255, 255, 255, .09); border-color: var(--line-2); }
.l-icon-btn svg { width: 18px; height: 18px; }
.l-kbd { font: 500 .72rem var(--font-mono); color: var(--mute); border: 1px solid var(--line-2); border-radius: 6px; padding: 1px 6px; }
@media (max-width: 760px) {
  .l-nav, .l-kbd, .l-hide-sm { display: none !important; }
  .l-topbar { gap: 8px; }
}

/* ---------- buttons ---------- */
.l-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  height: 50px; padding: 0 24px; border-radius: 999px; border: 0;
  background: var(--ink); color: #000;
  font: 600 1rem var(--font-ui); text-decoration: none; cursor: pointer;
  transition: transform .25s var(--ease), background .2s, box-shadow .3s, opacity .2s;
}
.l-btn:hover { background: #fff; }
.l-btn:active { transform: scale(.97); }
.l-btn:disabled { opacity: .45; cursor: not-allowed; }
.l-btn svg { width: 18px; height: 18px; }
.l-btn--eye { background: var(--eye); color: #fff; box-shadow: 0 0 0 0 var(--eye-wash); }
.l-btn--eye:hover { background: #9d84ff; box-shadow: 0 10px 40px -8px rgba(143, 115, 255, .6); }
.l-btn--ghost { background: rgba(255, 255, 255, .06); color: var(--ink); border: 1px solid var(--line); }
.l-btn--ghost:hover { background: rgba(255, 255, 255, .11); }
.l-btn--sm { height: 40px; padding: 0 16px; font-size: .92rem; }
.l-btn--block { width: 100%; }

/* ---------- fields ---------- */
.l-field {
  width: 100%; min-height: 50px; padding: 13px 16px;
  background: var(--visor); color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--r-ctl);
  font: 400 1rem/1.5 var(--font-ui); outline: none;
  transition: border-color .2s, box-shadow .2s, background .2s;
}
.l-field::placeholder { color: #5d5d66; }
.l-field:focus { border-color: var(--eye); box-shadow: 0 0 0 4px var(--eye-wash); }
textarea.l-field { min-height: 160px; resize: vertical; }
select.l-field { appearance: none; cursor: pointer; }
.l-label { display: block; font-size: .88rem; color: var(--mute); margin-bottom: 8px; }
.l-row { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.l-stack { display: grid; gap: 16px; }
.l-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.l-actions > * { flex: 0 1 auto; }
@media (max-width: 520px) { .l-actions > * { flex: 1 1 auto; } }

/* segmented control */
.l-seg { display: inline-flex; padding: 4px; gap: 4px; border-radius: 999px; background: var(--shell-2); border: 1px solid var(--line); flex-wrap: wrap; }
.l-seg button { height: 36px; padding: 0 16px; border: 0; border-radius: 999px; background: transparent; color: var(--ink-2); font: 500 .92rem var(--font-ui); cursor: pointer; transition: background .2s, color .2s; }
.l-seg button:hover { color: var(--ink); }
.l-seg button[aria-pressed="true"] { background: var(--ink); color: #000; }

/* ---------- panels ---------- */
.l-panel {
  background: linear-gradient(180deg, var(--shell-2), var(--shell));
  border: 1px solid var(--line);
  border-radius: var(--r-panel);
  padding: clamp(20px, 3vw, 32px);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .05);
}
.l-readout {
  background: var(--visor); border: 1px solid var(--line); border-radius: 18px;
  padding: 22px; text-align: center;
  box-shadow: inset 0 0 40px rgba(143, 115, 255, .06);
}
.l-readout strong { display: block; font: 600 clamp(2rem, 6vw, 3.2rem)/1.1 var(--font-display); color: var(--ink); font-variant-numeric: tabular-nums; }
.l-readout span { color: var(--mute); font-size: .95rem; }
.l-readout.is-live strong { color: var(--eye-hi); text-shadow: 0 0 28px rgba(143, 115, 255, .55); }

/* ---------- utility tool layout ---------- */
.l-tool { max-width: 760px; margin: 0 auto; padding: calc(var(--topbar-h) + clamp(28px, 6vw, 64px)) 16px 80px; }
.l-tool--wide { max-width: 1120px; }
.l-tool-head { display: flex; align-items: center; gap: 18px; margin-bottom: 28px; }
.l-tool-icon {
  width: 60px; height: 60px; flex-shrink: 0; border-radius: 18px;
  display: grid; place-items: center;
  background: radial-gradient(120% 120% at 50% 0%, #2a2338, var(--visor) 70%);
  border: 1px solid var(--line-2);
  color: var(--eye-hi);
  box-shadow: 0 0 30px -8px rgba(143, 115, 255, .5), inset 0 1px 0 rgba(255, 255, 255, .08);
}
.l-tool-icon svg { width: 28px; height: 28px; }
.l-tool-head h1 { font-size: clamp(1.7rem, 4vw, 2.4rem); }
.l-tool-head p { color: var(--mute); margin-top: 4px; }
.l-hint { color: var(--mute); font-size: .9rem; }
.l-error { color: var(--bad); font-size: .92rem; min-height: 1.4em; }

/* ---------- command palette ---------- */
.l-palette { position: fixed; inset: 0; z-index: 1000; display: none; align-items: flex-start; justify-content: center; padding: 12vh 16px 16px; background: rgba(0, 0, 0, .6); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); font-family: var(--font-ui); direction: rtl; }
html[dir="ltr"] .l-palette { direction: ltr; }
.l-palette.is-open { display: flex; animation: l-fade .18s ease-out; }
.l-palette-box { width: min(640px, 100%); max-height: 70vh; display: flex; flex-direction: column; background: rgba(22, 22, 27, .96); border: 1px solid var(--line-2); border-radius: 24px; overflow: hidden; box-shadow: 0 40px 120px -20px rgba(0, 0, 0, .9), 0 0 0 1px rgba(143, 115, 255, .08); animation: l-rise .28s var(--ease); }
.l-palette-search { display: flex; align-items: center; gap: 12px; padding: 0 20px; border-bottom: 1px solid var(--line); color: var(--mute); }
.l-palette-search input { flex: 1; height: 62px; background: none; border: 0; outline: none; color: var(--ink); font: 400 1.1rem var(--font-ui); }
.l-palette-list { overflow-y: auto; padding: 8px; }
.l-palette-group { padding: 12px 12px 6px; color: var(--mute); font-size: .82rem; }
.l-palette-item { display: flex; align-items: center; gap: 14px; padding: 10px 12px; border-radius: 14px; color: var(--ink); text-decoration: none; }
.l-palette-item[aria-selected="true"] { background: rgba(143, 115, 255, .16); }
.l-palette-item .ic { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; background: var(--shell-3); color: var(--ink-2); flex-shrink: 0; }
.l-palette-item[aria-selected="true"] .ic { color: var(--eye-hi); }
.l-palette-item .ic svg { width: 19px; height: 19px; }
.l-palette-item small { display: block; color: var(--mute); font-size: .84rem; }
.l-palette-item.is-off { opacity: .45; }
.l-palette-empty { padding: 28px; text-align: center; color: var(--mute); }

/* ---------- toast ---------- */
.l-toast { position: fixed; bottom: 28px; left: 50%; z-index: 1100; transform: translate(-50%, 20px); opacity: 0; pointer-events: none; padding: 12px 20px; border-radius: 999px; background: rgba(30, 30, 36, .95); border: 1px solid var(--line-2); color: var(--ink); font: 500 .95rem var(--font-ui); transition: opacity .25s, transform .35s var(--ease); }
.l-toast.is-on { opacity: 1; transform: translate(-50%, 0); }

/* ---------- badges ---------- */
.l-badge { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px; border-radius: 999px; font-size: .76rem; font-weight: 500; background: rgba(255, 255, 255, .08); color: var(--ink-2); white-space: nowrap; }
.l-badge--eye { background: rgba(143, 115, 255, .18); color: var(--eye-hi); }
.l-badge--off { background: rgba(255, 214, 10, .12); color: var(--warn); }

@keyframes l-fade { from { opacity: 0; } }
@keyframes l-rise { from { opacity: 0; transform: translateY(14px) scale(.98); } }

@media (prefers-reduced-motion: reduce) {
  .lona-page *, .l-palette, .l-palette-box { animation: none !important; transition: none !important; }
}

/* ==========================================================================
   Harmonizing layer for the original tool pages (body[data-lona-tool]).
   It replaces the old per-page chrome with the shared top bar and brings
   backgrounds, type and controls onto the system without touching tool logic.
   ========================================================================== */
body[data-lona-tool] {
  background: var(--void) radial-gradient(1200px 520px at 50% -180px, rgba(91, 61, 245, .16), transparent 70%) no-repeat !important;
  color: var(--ink);
  font-family: var(--font-ui) !important;
  padding-top: var(--topbar-h);
  -webkit-font-smoothing: antialiased;
}
body[data-lona-tool] :is(button, input, textarea, select) { font-family: var(--font-ui); }
body[data-lona-tool] :is(h1, h2) { font-family: var(--font-display); font-weight: 600; }
body[data-lona-tool] ::selection { background: var(--eye); color: #fff; }
body[data-lona-tool] :focus-visible { outline: 2px solid var(--eye); outline-offset: 2px; }

/* Old navigation chrome — the shared top bar replaces it. */
body[data-lona-tool] [data-lona-legacy],
body[data-lona-tool] .mobile-nav,
body[data-lona-tool] .desktop-nav { display: none !important; }

/* Low-specificity defaults: only reach controls a page left unstyled. */
:where(body[data-lona-tool]) :where(input:not([type=checkbox], [type=radio], [type=range], [type=file], [type=color]), textarea, select) {
  background: var(--visor); color: var(--ink); border: 1px solid var(--line); border-radius: var(--r-ctl);
}
:where(body[data-lona-tool]) :where(input, textarea, select):focus { border-color: var(--eye); outline: none; box-shadow: 0 0 0 4px var(--eye-wash); }
:where(body[data-lona-tool]) input[type=range] { accent-color: var(--eye); }

/* ---------- shared bits for the utility tools ---------- */
.l-mono { font-family: var(--font-mono); direction: ltr; text-align: left; }
.l-kv { display: grid; gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: 16px; overflow: hidden; }
.l-kv > div { display: flex; justify-content: space-between; gap: 16px; padding: 12px 16px; background: var(--shell); }
.l-kv dt { color: var(--mute); margin: 0; }
.l-kv dd { margin: 0; font-weight: 500; word-break: break-all; }
.l-split { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.l-dropzone { display: grid; place-items: center; gap: 10px; min-height: 200px; padding: 28px; text-align: center; border: 1.5px dashed var(--line-2); border-radius: var(--r-panel); background: var(--visor); color: var(--mute); cursor: pointer; transition: border-color .2s, background .2s; }
.l-dropzone:hover, .l-dropzone.is-over { border-color: var(--eye); background: rgba(143, 115, 255, .06); color: var(--ink-2); }
.l-dropzone svg { width: 34px; height: 34px; color: var(--eye-hi); }
.l-dropzone input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.l-step { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 999px; background: var(--visor); }
.l-step button { width: 44px; height: 44px; border: 0; background: none; color: var(--ink); font-size: 1.3rem; cursor: pointer; border-radius: 999px; }
.l-step button:hover { background: rgba(255, 255, 255, .07); }
.l-step output { min-width: 44px; text-align: center; font-weight: 600; font-variant-numeric: tabular-nums; }
.l-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.l-empty { text-align: center; color: var(--mute); padding: 24px; }

/* mini Lona placeholder for empty states: <span data-minibot></span> */
[data-minibot] { display: inline-block; width: 84px; height: 84px; }
[data-minibot] svg { width: 100%; height: 100%; display: block; filter: drop-shadow(0 10px 30px rgba(107, 61, 255, .35)); }

/* styles.css is light-themed through variables; flip them for every tool page. */
body[data-lona-tool] {
  --bg: #000;
  --card: rgba(22, 22, 27, .86);
  --border: rgba(255, 255, 255, .09);
  --primary: #8f73ff;
  --primary-glow: rgba(143, 115, 255, .25);
  --selection: rgba(143, 115, 255, .3);
  --text-main: #f5f5f7;
  --text-dim: #86868f;
  --font-main: var(--font-ui);
}
body[data-lona-tool] .search-page-header { display: none; }
body[data-lona-tool] .search-page { padding-top: clamp(24px, 5vw, 48px); }
body[data-lona-tool] .search-page-content {
  background: linear-gradient(180deg, var(--shell-2), var(--shell));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .05);
  border-radius: var(--r-panel);
}
body[data-lona-tool] .ai-search-heading h1 { font-size: clamp(1.8rem, 4vw, 2.4rem); }
/* styles.css paints <html> with its light --bg; keep the page root black on tool pages. */
html:has(> body[data-lona-tool]) { background: #000; color-scheme: dark; }
