/* ==========================================================================
   Design tokens, reset and base typography.
   Light is the default palette; dark overrides only the semantic tokens so
   every component stays theme-correct without duplicated rules.
   ========================================================================== */

:root {
  color-scheme: light;

  /* ── Neutrals ── */
  --slate-50:  #f8fafc;
  --slate-100: #f1f5f9;
  --slate-200: #e2e8f0;
  --slate-300: #cbd5e1;
  --slate-400: #94a3b8;
  --slate-500: #64748b;
  --slate-600: #475569;
  --slate-700: #334155;
  --slate-800: #1e293b;
  --slate-900: #0f172a;

  /* ── Brand & status hues ── */
  --blue-500:    #3b82f6;
  --blue-600:    #2563eb;
  --blue-700:    #1d4ed8;
  --emerald-500: #10b981;
  --emerald-600: #059669;
  --emerald-700: #047857;
  --amber-500:   #f59e0b;
  --amber-600:   #d97706;
  --rose-500:    #f43f5e;
  --rose-600:    #e11d48;
  --violet-500:  #8b5cf6;

  /* ── Semantic surfaces ── */
  --bg:            #f5f7fa;
  --bg-subtle:     #eaf0f6;
  --surface:       #ffffff;
  --surface-2:     #f8fafc;
  --surface-hover: #edf2f8;
  --sidebar-bg:    #fbfcfe;
  --overlay:       rgba(15, 23, 42, 0.48);

  /* ── Semantic ink ── */
  --text:        #18263a;
  --text-muted:  #526176;
  --text-subtle: #5e6c80;
  --text-invert: #ffffff;

  /* ── Lines ── */
  --border:        #dfe5ee;
  --border-strong: #c4cedc;
  /* WCAG 1.4.11 wants 3:1 for the visible boundary of a form control, which
     --border-strong does not reach. Decorative rules keep using that. */
  --field-border:  #7c8a9c;
  --divider:       #eef2f7;

  /* ── Accents ── */
  --accent:        #245ea8;
  --accent-hover:  #194b8b;
  /* Filled button background; kept separate from --accent so the link colour
     can be lighter in dark mode without dropping button contrast. */
  --accent-solid:       #245ea8;
  --accent-solid-hover: #194b8b;
  --accent-soft:   #eaf2fc;
  --accent-border: #bfcee5;
  --accent-ink:    #204f8c;

  --ok:        #147d64;
  /* Filled variants carry white text, so they need a darker green than the
     --ok used for text-on-tint. */
  --ok-solid:     #147d64;
  --ok-solid-ink: #ffffff;
  --ok-soft:   #ecfdf5;
  --ok-border: #a7f3d0;
  --ok-ink:    #065f46;

  --warn:        #9a620c;
  --warn-soft:   #fffbeb;
  --warn-border: #fde68a;
  --warn-ink:    #92400e;

  --danger:        var(--rose-600);
  --danger-solid:  #be123c;
  --danger-soft:   #fff1f2;
  --danger-border: #fecdd3;
  --danger-ink:    #9f1239;

  --info-soft:   #f5f3ff;
  --info-border: #ddd6fe;
  --info-ink:    #5b21b6;

  /* ── Spacing scale (4px base) ── */
  --sp-1: 0.25rem;
  --sp-2: 0.5rem;
  --sp-3: 0.75rem;
  --sp-4: 1rem;
  --sp-5: 1.25rem;
  --sp-6: 1.5rem;
  --sp-8: 2rem;
  --sp-10: 2.5rem;
  --sp-12: 3rem;

  /* ── Radii ── */
  --r-sm: 8px;
  --r-md: 11px;
  --r-lg: 16px;
  --r-xl: 22px;
  --r-full: 999px;

  /* ── Type scale ── */
  --fs-xs:  0.75rem;
  --fs-sm:  0.875rem;
  --fs-base: 0.9375rem;
  --fs-md:  1rem;
  --fs-lg:  1.125rem;
  --fs-xl:  1.375rem;
  --fs-2xl: 1.875rem;
  --fs-3xl: 2.375rem;

  --font: "Segoe UI", system-ui, -apple-system, "Assistant", "Rubik", "Heebo",
          "Noto Sans Hebrew", Arial, sans-serif;
  --font-num: ui-monospace, "SF Mono", "Cascadia Mono", "Segoe UI Mono", Menlo, monospace;

  /* ── Elevation ── */
  --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-sm: 0 2px 6px rgba(24, 38, 58, 0.035), 0 1px 2px rgba(24, 38, 58, 0.025);
  --shadow-md: 0 8px 24px rgba(24, 38, 58, 0.07), 0 2px 5px rgba(24, 38, 58, 0.03);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.14), 0 2px 8px rgba(15, 23, 42, 0.06);

  --ring: 0 0 0 3px rgba(37, 99, 235, 0.28);

  /* ── Layout ── */
  --sidebar-w: 252px;
  --topbar-h: 72px;
  --content-max: 1440px;

  --t-fast: 120ms ease;
  --t-base: 180ms cubic-bezier(0.2, 0, 0.2, 1);
}

[data-theme="dark"] {
  color-scheme: dark;

  --bg:            #0c131e;
  --bg-subtle:     #152030;
  --surface:       #141e2d;
  --surface-2:     #192536;
  --surface-hover: #203047;
  --sidebar-bg:    #101925;
  --overlay:       rgba(2, 6, 16, 0.7);

  --text:        #e8eef7;
  --text-muted:  #b0bed0;
  --text-subtle: #96a8c0;
  --text-invert: #0b1120;

  --border:        #24334d;
  --border-strong: #334566;
  --field-border:  #647d9f;
  --divider:       #1b2942;

  --accent:        #89baff;
  --accent-hover:  #b1d2ff;
  --accent-solid:       #245ea8;
  --accent-solid-hover: #194b8b;
  --accent-soft:   #142544;
  --accent-border: #1e3a68;
  --accent-ink:    #bfdbfe;

  --ok:        #60d6b1;
  /* Inverted in dark: a bright fill with near-black ink reads far better than
     white on mint (which was only 1.9:1). */
  --ok-solid:     #34d399;
  --ok-solid-ink: #052e21;   /* 7.70:1 */
  --ok-soft:   #052e21;
  --ok-border: #10593f;
  --ok-ink:    #6ee7b7;

  --warn:        #fbbf24;
  --warn-soft:   #2c1e05;
  --warn-border: #6b4a09;
  --warn-ink:    #fcd34d;

  --danger:        #fb7185;
  --danger-solid:  #be123c;
  --danger-soft:   #2d0d15;
  --danger-border: #6b1f2e;
  --danger-ink:    #fda4af;

  --info-soft:   #1c1533;
  --info-border: #3b2d66;
  --info-ink:    #c4b5fd;

  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.5);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.6);
  --ring: 0 0 0 3px rgba(59, 130, 246, 0.4);
}

/* ── Reset ─────────────────────────────────────────────────────────────── */

*,
*::before,
*::after { box-sizing: border-box; }

* { margin: 0; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  /* Any stray sub-pixel/layout overflow on a narrow phone otherwise expands
     the "layout viewport" beyond the real screen width — which then makes
     every position:fixed element (nav drawer, modals) size and center
     itself against that inflated width instead of the real one, and in an
     RTL document shifts the whole page right with dead space on the left.
     Clipping at the root is the standard guard; anything meant to scroll
     horizontally (e.g. .table-wrap) keeps its own overflow-x:auto. */
  overflow-x: hidden;
}

body {
  font-family: var(--font);
  font-size: var(--fs-base);
  line-height: 1.65;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-wrap: break-word;
}

h1, h2, h3, h4 { line-height: 1.25; font-weight: 650; letter-spacing: -0.01em; }
h1 { font-size: var(--fs-2xl); }
h2 { font-size: var(--fs-xl); }
h3 { font-size: var(--fs-lg); }
h4 { font-size: var(--fs-md); }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

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

img, svg { display: block; max-width: 100%; }

ul, ol { padding: 0; list-style: none; }

table { border-collapse: separate; border-spacing: 0; }

/* Visible, consistent keyboard focus everywhere. */
:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
  border-radius: var(--r-sm);
}
:focus:not(:focus-visible) { outline: none; }

::selection { background: var(--accent-soft); color: var(--accent-ink); }

/* Numeric alignment in tables and stat tiles. */

/* ── Utilities ─────────────────────────────────────────────────────────── */

.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;
  inset-inline-start: var(--sp-4);
  top: -100px;
  z-index: 2000;
  padding: var(--sp-2) var(--sp-4);
  background: var(--accent);
  color: #fff;
  border-radius: var(--r-md);
  font-weight: 600;
  transition: top var(--t-fast);
}
.skip-link:focus { top: var(--sp-3); text-decoration: none; }

.muted { color: var(--text-muted); }
.subtle { color: var(--text-subtle); }
.small { font-size: var(--fs-sm); }
.xsmall { font-size: var(--fs-xs); }
.strong { font-weight: 650; }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.text-center { text-align: center; }

.row { display: flex; align-items: center; gap: var(--sp-2); }
.row > *, .row-wrap > *, .grid > * { min-width: 0; }
.row-wrap { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; }
.spacer { flex: 1 1 auto; }
.stack-4 > * + * { margin-top: var(--sp-4); }

/* Visibility helpers deliberately do NOT set a display value at their visible
   size: forcing `display: initial` resolves to `inline`, which would collapse
   the <th>/<td> cells these classes are applied to. Only the hidden state is
   declared. */
.only-mobile { display: none; }

@media (max-width: 720px) {
  .hide-mobile { display: none !important; }
  .only-mobile { display: revert; }
}

@media (max-width: 400px) {
  :root { --sp-4: 0.875rem; --sp-5: 1rem; }
  .week-strip { gap: var(--sp-1); }
  .week-day { padding: var(--sp-2) 2px; }
  .week-day-state { display: none; }
  .cal-day { min-height: 40px; font-size: var(--fs-sm); }
  .page-title { font-size: var(--fs-xl); }
  .stat-value { font-size: var(--fs-2xl); }
}

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