/* Roots AI design system.
   Shape rule: buttons and inputs 10px, cards and panels 16px, chips and toggles full pill.
   One accent (teal) per theme; status colors only for real state, always with an icon and label. */

:root {
  color-scheme: light;
  --bg: #f2f4f5;
  --bg-elevated: #f7f8f9;
  --surface: #ffffff;
  --surface-2: #eef1f3;
  --surface-3: #e4e9ec;
  --line: #dde3e6;
  --line-strong: #c7d0d5;
  --text: #11191e;
  --text-2: #3f4d55;
  --text-3: #5b6a73;
  --accent: #0f766e;
  --accent-hover: #0b5f58;
  --accent-ink: #ffffff;
  --accent-soft: #e0f2ef;
  --accent-line: #a7d8d0;
  --chart-1: #0d9488;
  --chart-grid: #e6eaec;
  --ok: #15803d;
  --ok-soft: #e3f4e8;
  --warn: #a16207;
  --warn-soft: #fbf1dc;
  --danger: #b42318;
  --danger-soft: #fbe7e5;
  --shadow-sm: 0 1px 2px rgb(17 40 48 / .06);
  --shadow-md: 0 10px 30px -12px rgb(17 40 48 / .18);
  --shadow-lg: 0 30px 70px -30px rgb(17 40 48 / .35);
  --scrim: rgb(9 16 20 / .55);
  --radius-control: 10px;
  --radius-panel: 16px;
  --font: "IBM Plex Sans Arabic", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --ease: cubic-bezier(.16, 1, .3, 1);
  --header-h: 64px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0a0e11;
    --bg-elevated: #0d1215;
    --surface: #11171b;
    --surface-2: #161e23;
    --surface-3: #1d272d;
    --line: #232e35;
    --line-strong: #31404a;
    --text: #e7edef;
    --text-2: #b4c1c7;
    --text-3: #8d9da5;
    --accent: #2dd4bf;
    --accent-hover: #5eead4;
    --accent-ink: #04211d;
    --accent-soft: #0e2a27;
    --accent-line: #1b5c54;
    --chart-1: #1aa395;
    --chart-grid: #1d272d;
    --ok: #4ade80;
    --ok-soft: #10261a;
    --warn: #fbbf24;
    --warn-soft: #2a2110;
    --danger: #f87171;
    --danger-soft: #2c1414;
    --shadow-sm: 0 1px 2px rgb(0 0 0 / .4);
    --shadow-md: 0 14px 34px -14px rgb(0 0 0 / .7);
    --shadow-lg: 0 34px 80px -30px rgb(0 0 0 / .85);
    --scrim: rgb(0 0 0 / .65);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0a0e11;
  --bg-elevated: #0d1215;
  --surface: #11171b;
  --surface-2: #161e23;
  --surface-3: #1d272d;
  --line: #232e35;
  --line-strong: #31404a;
  --text: #e7edef;
  --text-2: #b4c1c7;
  --text-3: #8d9da5;
  --accent: #2dd4bf;
  --accent-hover: #5eead4;
  --accent-ink: #04211d;
  --accent-soft: #0e2a27;
  --accent-line: #1b5c54;
  --chart-1: #1aa395;
  --chart-grid: #1d272d;
  --ok: #4ade80;
  --ok-soft: #10261a;
  --warn: #fbbf24;
  --warn-soft: #2a2110;
  --danger: #f87171;
  --danger-soft: #2c1414;
  --shadow-sm: 0 1px 2px rgb(0 0 0 / .4);
  --shadow-md: 0 14px 34px -14px rgb(0 0 0 / .7);
  --shadow-lg: 0 34px 80px -30px rgb(0 0 0 / .85);
  --scrim: rgb(0 0 0 / .65);
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}
img, video, svg, canvas { display: block; max-width: 100%; }
img, video { height: auto; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
h1, h2, h3, h4 { margin: 0; line-height: 1.3; letter-spacing: -.01em; }
p { margin: 0; }
.num, .mono { font-family: var(--mono); font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; }
/* Numbers read left to right but sit on the Arabic (right) edge of their block. */
[dir="rtl"] .num, [dir="rtl"] .mono { text-align: right; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
::selection { background: var(--accent-soft); color: var(--text); }
.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; }
.container { width: 100%; max-width: 1280px; margin-inline: auto; padding-inline: 32px; }
.ph { line-height: 1; }

/* ---------- Header ---------- */
.site-header {
  position: sticky; top: 0; z-index: 40;
  height: var(--header-h);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(14px) saturate(140%);
  -webkit-backdrop-filter: blur(14px) saturate(140%);
  border-bottom: 1px solid var(--line);
}
.site-header .container { height: 100%; display: flex; align-items: center; gap: 28px; }
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; white-space: nowrap; }
.brand-mark {
  width: 34px; height: 34px; display: grid; place-items: center;
  border-radius: 10px; background: var(--accent); color: var(--accent-ink); font-size: 19px;
}
.brand small { color: var(--text-3); font-weight: 500; font-size: 13px; }
.main-nav { display: flex; align-items: center; gap: 2px; }
.main-nav a {
  padding: 8px 12px; border-radius: 999px; color: var(--text-2); font-size: 14px; font-weight: 500;
  transition: background .2s var(--ease), color .2s var(--ease);
}
.main-nav a:hover { color: var(--text); background: var(--surface-2); }
.main-nav a[aria-current="page"] { color: var(--accent); background: var(--accent-soft); }
.header-actions { margin-inline-start: auto; display: flex; align-items: center; gap: 8px; }
.icon-btn.menu-toggle { display: none; }

/* ---------- Buttons ---------- */
.btn {
  min-height: 42px; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px 18px; border: 1px solid transparent; border-radius: var(--radius-control);
  font-size: 14px; font-weight: 600; white-space: nowrap; cursor: pointer;
  transition: background .2s var(--ease), border-color .2s var(--ease), color .2s var(--ease), transform .15s var(--ease);
}
.btn .ph { font-size: 18px; }
.btn:active:not(:disabled) { transform: translateY(1px) scale(.99); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--line-strong); }
.btn-secondary:hover:not(:disabled) { border-color: var(--accent-line); color: var(--accent); }
.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.btn-danger { background: transparent; color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, transparent); }
.btn-danger:hover:not(:disabled) { background: var(--danger-soft); }
.btn-sm { min-height: 34px; padding: 6px 12px; font-size: 13px; }
.btn-lg { min-height: 50px; padding: 12px 24px; font-size: 15px; }
.btn-block { width: 100%; }
.icon-btn {
  width: 40px; height: 40px; display: inline-grid; place-items: center; flex: 0 0 auto;
  border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--text-2);
  font-size: 18px; cursor: pointer; transition: color .2s var(--ease), border-color .2s var(--ease);
}
.icon-btn:hover { color: var(--accent); border-color: var(--accent-line); }
.theme-toggle .ph-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .ph-sun { display: inline; }
:root[data-theme="dark"] .theme-toggle .ph-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .ph-sun { display: inline; }
  :root:not([data-theme="light"]) .theme-toggle .ph-moon { display: none; }
}

/* ---------- Panels, chips, badges ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-panel); box-shadow: var(--shadow-sm); }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.panel-head h2, .panel-head h3 { font-size: 15px; font-weight: 600; display: flex; align-items: center; gap: 9px; }
.panel-head h2 .ph, .panel-head h3 .ph { color: var(--accent); font-size: 19px; }
.panel-head p { color: var(--text-3); font-size: 13px; }
.panel-body { padding: 20px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 11px; border-radius: 999px;
  background: var(--surface-2); color: var(--text-2); font-size: 12px; font-weight: 500; white-space: nowrap;
}
.chip-accent { background: var(--accent-soft); color: var(--accent); }
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-neutral { background: var(--surface-2); color: var(--text-2); }

/* ---------- Forms ---------- */
.field { display: grid; gap: 7px; }
.field > label, .field-label { font-size: 13px; font-weight: 600; color: var(--text-2); }
.field-help { font-size: 12px; color: var(--text-3); }
.field-error { font-size: 12px; color: var(--danger); min-height: 18px; }
.input, .select {
  width: 100%; min-height: 44px; padding: 10px 14px; border: 1px solid var(--line-strong); border-radius: var(--radius-control);
  background: var(--bg-elevated); color: var(--text); font-size: 14px;
  transition: border-color .2s var(--ease), box-shadow .2s var(--ease);
}
.input::placeholder { color: var(--text-3); }
.input:focus, .select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input[aria-invalid="true"] { border-color: var(--danger); }
.input-wrap { position: relative; }
.input-wrap .input { padding-inline-end: 46px; }
.input-wrap .input-action {
  position: absolute; inset-inline-end: 6px; top: 50%; transform: translateY(-50%);
  width: 34px; height: 34px; display: grid; place-items: center; border: 0; border-radius: 8px;
  background: transparent; color: var(--text-3); font-size: 18px; cursor: pointer;
}
.input-wrap .input-action:hover { color: var(--text); background: var(--surface-2); }
.check { display: flex; align-items: flex-start; gap: 10px; font-size: 13px; color: var(--text-2); line-height: 1.7; cursor: pointer; }
.check input { width: 18px; height: 18px; margin-top: 3px; flex: 0 0 auto; accent-color: var(--accent); }
.dropzone {
  position: relative; display: grid; place-items: center; gap: 6px; min-height: 160px; padding: 24px;
  border: 1.5px dashed var(--line-strong); border-radius: var(--radius-panel); background: var(--bg-elevated);
  text-align: center; cursor: pointer; transition: border-color .2s var(--ease), background .2s var(--ease);
}
.dropzone:hover, .dropzone.dragover { border-color: var(--accent); background: var(--accent-soft); }
.dropzone .ph { font-size: 30px; color: var(--accent); }
.dropzone strong { font-size: 14px; }
.dropzone span { font-size: 12px; color: var(--text-3); }
.dropzone input[type="file"] { position: absolute; width: 1px; height: 1px; opacity: 0; }

/* ---------- Status messages ---------- */
.status-line { min-height: 22px; font-size: 13px; color: var(--text-3); display: flex; align-items: center; gap: 7px; }
.status-line.error { color: var(--danger); }
.status-line.success { color: var(--ok); }
.alert { display: flex; gap: 10px; padding: 12px 14px; border-radius: var(--radius-control); font-size: 13px; line-height: 1.7; }
.alert .ph { font-size: 18px; flex: 0 0 auto; margin-top: 2px; }
.alert-error { background: var(--danger-soft); color: var(--danger); }
.alert-info { background: var(--surface-2); color: var(--text-2); }
.alert-warn { background: var(--warn-soft); color: var(--warn); }
.empty-state { display: grid; place-items: center; gap: 8px; padding: 36px 20px; text-align: center; color: var(--text-3); font-size: 13px; }
.empty-state .ph { font-size: 30px; color: var(--line-strong); }
.empty-state strong { color: var(--text-2); font-size: 14px; }
.skeleton { position: relative; overflow: hidden; border-radius: 8px; background: var(--surface-2); }
.skeleton::after {
  content: ""; position: absolute; inset: 0; transform: translateX(100%);
  background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--surface) 55%, transparent), transparent);
  animation: shimmer 1.4s infinite;
}
@keyframes shimmer { to { transform: translateX(-100%); } }
.spinner { width: 22px; height: 22px; border: 2.5px solid var(--accent-soft); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Toasts ---------- */
.toast-stack { position: fixed; z-index: 80; inset-block-end: 20px; inset-inline-start: 20px; display: grid; gap: 8px; width: min(360px, calc(100% - 40px)); }
.toast {
  display: flex; align-items: flex-start; gap: 10px; padding: 12px 14px; border: 1px solid var(--line);
  border-radius: var(--radius-control); background: var(--surface); box-shadow: var(--shadow-md); font-size: 13px;
  animation: toast-in .35s var(--ease);
}
.toast .ph { font-size: 18px; margin-top: 2px; }
.toast.success .ph { color: var(--ok); }
.toast.error .ph { color: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ---------- Dialog ---------- */
.dialog { width: min(92vw, 460px); padding: 0; border: 1px solid var(--line); border-radius: var(--radius-panel); background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg); }
.dialog::backdrop { background: var(--scrim); backdrop-filter: blur(3px); }
.dialog-body { padding: 22px; display: grid; gap: 10px; }
.dialog-body h3 { font-size: 17px; }
.dialog-body p { color: var(--text-2); font-size: 14px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 22px; border-top: 1px solid var(--line); background: var(--bg-elevated); border-radius: 0 0 var(--radius-panel) var(--radius-panel); }

/* ---------- Footer ---------- */
.site-footer { border-top: 1px solid var(--line); padding: 34px 0 40px; color: var(--text-3); font-size: 13px; }
.site-footer .container { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 18px; }
.footer-links { display: flex; flex-wrap: wrap; gap: 20px; }
.footer-links a:hover { color: var(--accent); }

/* ---------- Reveal on scroll ---------- */
@media (prefers-reduced-motion: no-preference) {
  .reveal { opacity: 0; transform: translateY(18px); transition: opacity .7s var(--ease), transform .7s var(--ease); transition-delay: calc(var(--i, 0) * 70ms); }
  .reveal.is-visible { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}

/* ---------- Responsive header ---------- */
@media (max-width: 900px) {
  .container { padding-inline: 20px; }
  .icon-btn.menu-toggle { display: inline-grid; }
  .main-nav {
    position: fixed; inset-inline: 0; top: var(--header-h); z-index: 39;
    flex-direction: column; align-items: stretch; gap: 4px; padding: 12px 20px 18px;
    background: var(--surface); border-bottom: 1px solid var(--line); box-shadow: var(--shadow-md);
    transform: translateY(-8px); opacity: 0; pointer-events: none; transition: opacity .2s var(--ease), transform .2s var(--ease);
  }
  .main-nav.open { opacity: 1; transform: none; pointer-events: auto; }
  .main-nav a { padding: 12px 14px; border-radius: var(--radius-control); font-size: 15px; }
  .header-actions .btn-label { display: none; }
}
@media (max-width: 520px) {
  .container { padding-inline: 16px; }
  .brand small { display: none; }
}

@media print {
  .site-header, .site-footer, .toast-stack { display: none !important; }
  body { background: #fff; color: #111; }
}
