/* ==========================================================================
   Request & Query Tracker — styles.css
   Three themes (rose default / light / midnight) as token sets, full RTL/LTR
   support via logical properties. Elevation replaces card borders. No CDN
   assets except Google Fonts, imported below — see report for preconnect.
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Tajawal:wght@300;400;500;700;800;900&family=Inter:wght@400;500;600;700;800&display=swap');

/* --------------------------------------------------------------------------
   1. DESIGN TOKENS — rose theme (default, lives on :root)
   Soft blush/rose surfaces, deep plum-wine text. A considered, warm palette
   that still reads as a professional daily-use tool, not a toy.
   -------------------------------------------------------------------------- */
:root {
  /* Surfaces */
  --bg: oklch(96.8% 0.014 18);
  --bg-elevated: oklch(99% 0.006 18);
  --surface: oklch(98.5% 0.008 18);
  --surface-2: oklch(95% 0.016 18);
  --surface-hover: oklch(92.5% 0.022 18);
  --border: oklch(87% 0.025 18);
  --border-soft: oklch(92% 0.016 18);

  /* Text */
  --text: oklch(29% 0.075 16);
  --text-muted: oklch(46% 0.06 16);
  --text-faint: oklch(52% 0.05 16);
  --text-dim: oklch(46% 0.06 16);

  /* Accent */
  --accent: oklch(56% 0.19 356);
  --accent-hover: oklch(50% 0.2 356);
  --accent-soft: oklch(56% 0.19 356 / 0.16);
  --accent-contrast: oklch(99% 0.006 18);
  --link-strong: oklch(48% 0.19 356);

  /* Semantic — status */
  --status-done: oklch(42% 0.13 155);
  --status-done-bg: oklch(42% 0.13 155 / 0.14);
  --status-not_done: oklch(46% 0.03 16);
  --status-not_done-bg: oklch(46% 0.03 16 / 0.12);
  --status-in_progress: oklch(48% 0.17 260);
  --status-in_progress-bg: oklch(48% 0.17 260 / 0.14);
  --status-urgent: oklch(48% 0.2 25);
  --status-urgent-bg: oklch(48% 0.2 25 / 0.1);

  /* Semantic — priority */
  --prio-low: oklch(42% 0.13 155);
  --prio-low-bg: oklch(42% 0.13 155 / 0.14);
  --prio-medium: oklch(48% 0.14 75);
  --prio-medium-bg: oklch(48% 0.14 75 / 0.15);
  --prio-high: oklch(48% 0.2 25);
  --prio-high-bg: oklch(48% 0.2 25 / 0.1);

  /* Semantic — payment */
  --paid: oklch(40% 0.12 165);
  --paid-bg: oklch(40% 0.12 165 / 0.14);
  --unpaid: oklch(48% 0.13 55);
  --unpaid-bg: oklch(48% 0.13 55 / 0.14);

  /* Feedback */
  --ok: oklch(42% 0.13 155);
  --ok-bg: oklch(42% 0.13 155 / 0.14);
  --err: oklch(48% 0.2 25);
  --err-bg: oklch(48% 0.2 25 / 0.15);

  /* Fixed identity swatches for the theme picker — deliberately NOT
     overridden per theme, they represent each option's own signature
     colour regardless of which theme is currently active. */
  --swatch-rose: oklch(58% 0.19 356);
  --swatch-light: oklch(97% 0.004 250);
  --swatch-midnight: oklch(21% 0.03 320);

  /* Shadows — card elevation replaces the old card borders */
  --shadow-sm: 0 1px 2px oklch(40% 0.05 16 / 0.1);
  --shadow-md: 0 8px 24px oklch(35% 0.06 16 / 0.12);
  --shadow-lg: 0 20px 60px oklch(30% 0.07 16 / 0.18);
  --shadow-card: 0 1px 2px oklch(40% 0.05 16 / 0.05), 0 10px 24px oklch(35% 0.06 16 / 0.1);

  /* Radii */
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 16px;
  --r-xl: 22px;
  --r-pill: 999px;

  /* Spacing scale */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 24px;
  --sp-6: 32px;
  --sp-7: 48px;

  /* Type scale (fluid) */
  --fs-xs: clamp(0.72rem, 0.7rem + 0.1vw, 0.78rem);
  --fs-sm: clamp(0.82rem, 0.8rem + 0.12vw, 0.88rem);
  --fs-base: clamp(0.92rem, 0.9rem + 0.14vw, 1rem);
  --fs-md: clamp(1.02rem, 1rem + 0.2vw, 1.15rem);
  --fs-lg: clamp(1.2rem, 1.1rem + 0.5vw, 1.5rem);
  --fs-xl: clamp(1.5rem, 1.3rem + 1vw, 2rem);
  --fs-2xl: clamp(1.9rem, 1.6rem + 1.6vw, 2.6rem);

  --focus-ring: 0 0 0 3px var(--accent-soft);
  --backdrop: oklch(20% 0.03 16 / 0.45);
}

/* --------------------------------------------------------------------------
   2. THEME OVERRIDES — light (clean, neutral, bright) and midnight (refined
   dark, warmer and deeper than a flat near-black). :root above already IS
   the rose theme, so no [data-theme='rose'] block is needed, but one is
   included for explicitness / in case markup always sets the attribute.
   -------------------------------------------------------------------------- */
[data-theme='rose'] {
  /* Identical to :root — present so an explicit data-theme="rose" attribute
     always resolves, even though :root already carries these values. */
  --bg: oklch(96.8% 0.014 18);
  --bg-elevated: oklch(99% 0.006 18);
  --surface: oklch(98.5% 0.008 18);
  --surface-2: oklch(95% 0.016 18);
  --surface-hover: oklch(92.5% 0.022 18);
  --border: oklch(87% 0.025 18);
  --border-soft: oklch(92% 0.016 18);
  --text: oklch(29% 0.075 16);
  --text-muted: oklch(46% 0.06 16);
  --text-faint: oklch(52% 0.05 16);
  --text-dim: oklch(46% 0.06 16);
  --accent: oklch(56% 0.19 356);
  --accent-hover: oklch(50% 0.2 356);
  --accent-soft: oklch(56% 0.19 356 / 0.16);
  --accent-contrast: oklch(99% 0.006 18);
  --link-strong: oklch(48% 0.19 356);
  --status-done: oklch(42% 0.13 155);
  --status-done-bg: oklch(42% 0.13 155 / 0.14);
  --status-not_done: oklch(46% 0.03 16);
  --status-not_done-bg: oklch(46% 0.03 16 / 0.12);
  --status-in_progress: oklch(48% 0.17 260);
  --status-in_progress-bg: oklch(48% 0.17 260 / 0.14);
  --status-urgent: oklch(48% 0.2 25);
  --status-urgent-bg: oklch(48% 0.2 25 / 0.1);
  --prio-low: oklch(42% 0.13 155);
  --prio-low-bg: oklch(42% 0.13 155 / 0.14);
  --prio-medium: oklch(48% 0.14 75);
  --prio-medium-bg: oklch(48% 0.14 75 / 0.15);
  --prio-high: oklch(48% 0.2 25);
  --prio-high-bg: oklch(48% 0.2 25 / 0.1);
  --paid: oklch(40% 0.12 165);
  --paid-bg: oklch(40% 0.12 165 / 0.14);
  --unpaid: oklch(48% 0.13 55);
  --unpaid-bg: oklch(48% 0.13 55 / 0.14);
  --ok: oklch(42% 0.13 155);
  --ok-bg: oklch(42% 0.13 155 / 0.14);
  --err: oklch(48% 0.2 25);
  --err-bg: oklch(48% 0.2 25 / 0.15);
  --shadow-sm: 0 1px 2px oklch(40% 0.05 16 / 0.1);
  --shadow-md: 0 8px 24px oklch(35% 0.06 16 / 0.12);
  --shadow-lg: 0 20px 60px oklch(30% 0.07 16 / 0.18);
  --shadow-card: 0 1px 2px oklch(40% 0.05 16 / 0.05), 0 10px 24px oklch(35% 0.06 16 / 0.1);
  --backdrop: oklch(20% 0.03 16 / 0.45);
}

[data-theme='light'] {
  --bg: oklch(97.5% 0.004 250);
  --bg-elevated: oklch(99.2% 0.002 250);
  --surface: oklch(99% 0.003 250);
  --surface-2: oklch(95.5% 0.005 250);
  --surface-hover: oklch(93% 0.006 250);
  --border: oklch(87% 0.008 250);
  --border-soft: oklch(92% 0.005 250);

  --text: oklch(24% 0.015 250);
  --text-muted: oklch(45% 0.012 250);
  --text-faint: oklch(55% 0.01 250);
  --text-dim: oklch(45% 0.012 250);

  --accent: oklch(52% 0.16 258);
  --accent-hover: oklch(46% 0.17 258);
  --accent-soft: oklch(52% 0.16 258 / 0.12);
  --accent-contrast: oklch(99.2% 0.002 250);
  --link-strong: oklch(46% 0.17 258);

  --status-done: oklch(40% 0.12 155);
  --status-done-bg: oklch(40% 0.12 155 / 0.14);
  --status-not_done: oklch(46% 0.01 250);
  --status-not_done-bg: oklch(46% 0.01 250 / 0.12);
  --status-in_progress: oklch(50% 0.15 258);
  --status-in_progress-bg: oklch(50% 0.15 258 / 0.14);
  --status-urgent: oklch(46% 0.19 25);
  --status-urgent-bg: oklch(46% 0.19 25 / 0.1);

  --prio-low: oklch(40% 0.12 155);
  --prio-low-bg: oklch(40% 0.12 155 / 0.14);
  --prio-medium: oklch(46% 0.13 75);
  --prio-medium-bg: oklch(46% 0.13 75 / 0.15);
  --prio-high: oklch(46% 0.19 25);
  --prio-high-bg: oklch(46% 0.19 25 / 0.1);

  --paid: oklch(38% 0.1 170);
  --paid-bg: oklch(38% 0.1 170 / 0.14);
  --unpaid: oklch(46% 0.12 55);
  --unpaid-bg: oklch(46% 0.12 55 / 0.14);

  --ok: oklch(40% 0.12 155);
  --ok-bg: oklch(40% 0.12 155 / 0.14);
  --err: oklch(46% 0.19 25);
  --err-bg: oklch(46% 0.19 25 / 0.15);

  --shadow-sm: 0 1px 2px oklch(30% 0.01 250 / 0.07);
  --shadow-md: 0 8px 24px oklch(25% 0.02 250 / 0.09);
  --shadow-lg: 0 20px 60px oklch(20% 0.02 250 / 0.16);
  --shadow-card: 0 1px 2px oklch(30% 0.01 250 / 0.05), 0 10px 24px oklch(25% 0.02 250 / 0.08);

  --backdrop: oklch(20% 0.01 250 / 0.4);
}

[data-theme='midnight'] {
  --bg: oklch(16% 0.02 320);
  --bg-elevated: oklch(19% 0.022 320);
  --surface: oklch(21% 0.024 320);
  --surface-2: oklch(25% 0.026 320);
  --surface-hover: oklch(29% 0.03 320);
  --border: oklch(32% 0.03 320);
  --border-soft: oklch(27% 0.026 320);

  --text: oklch(93% 0.015 320);
  --text-muted: oklch(72% 0.02 320);
  --text-faint: oklch(64% 0.02 320);
  --text-dim: oklch(72% 0.02 320);

  --accent: oklch(74% 0.16 350);
  --accent-hover: oklch(80% 0.15 350);
  --accent-soft: oklch(74% 0.16 350 / 0.18);
  --accent-contrast: oklch(16% 0.02 320);
  --link-strong: oklch(78% 0.15 350);

  --status-done: oklch(72% 0.15 155);
  --status-done-bg: oklch(72% 0.15 155 / 0.18);
  --status-not_done: oklch(68% 0.02 320);
  --status-not_done-bg: oklch(68% 0.02 320 / 0.16);
  --status-in_progress: oklch(74% 0.14 255);
  --status-in_progress-bg: oklch(74% 0.14 255 / 0.18);
  --status-urgent: oklch(72% 0.17 20);
  --status-urgent-bg: oklch(72% 0.17 20 / 0.16);

  --prio-low: oklch(72% 0.15 155);
  --prio-low-bg: oklch(72% 0.15 155 / 0.18);
  --prio-medium: oklch(78% 0.13 80);
  --prio-medium-bg: oklch(78% 0.13 80 / 0.18);
  --prio-high: oklch(72% 0.17 20);
  --prio-high-bg: oklch(72% 0.17 20 / 0.16);

  --paid: oklch(70% 0.13 165);
  --paid-bg: oklch(70% 0.13 165 / 0.16);
  --unpaid: oklch(72% 0.12 55);
  --unpaid-bg: oklch(72% 0.12 55 / 0.16);

  --ok: oklch(72% 0.15 155);
  --ok-bg: oklch(72% 0.15 155 / 0.18);
  --err: oklch(72% 0.17 20);
  --err-bg: oklch(72% 0.17 20 / 0.18);

  --shadow-sm: 0 1px 2px oklch(0% 0 0 / 0.3);
  --shadow-md: 0 10px 28px oklch(0% 0 0 / 0.45);
  --shadow-lg: 0 24px 64px oklch(0% 0 0 / 0.6);
  --shadow-card: inset 0 1px 0 oklch(100% 0 0 / 0.04), 0 1px 2px oklch(0% 0 0 / 0.3),
    0 12px 28px oklch(0% 0 0 / 0.45);

  --backdrop: oklch(8% 0.01 320 / 0.65);
}

/* --------------------------------------------------------------------------
   3. RESET & BASE
   -------------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: var(--fs-base);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
  transition: background-color 0.2s ease, color 0.2s ease;
}

/* Font stacks: Tajawal leads for Arabic/RTL, Inter leads for Latin/LTR */
html[dir='rtl'] body {
  font-family: 'Tajawal', 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
}
html[dir='ltr'] body {
  font-family: 'Inter', 'Tajawal', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

h1, h2, h3, h4 { margin: 0; font-weight: 700; }
p { margin: 0; }
ul, ol { margin: 0; padding: 0; }
button { font-family: inherit; }

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

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

a { color: var(--accent); }

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

input, select, textarea {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: var(--sp-2) var(--sp-3);
  color: var(--text);
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}

input:hover, select:hover, textarea:hover { border-color: var(--text-faint); }

input:focus, select:focus, textarea:focus, button:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--focus-ring);
}

input:disabled, select:disabled, textarea:disabled, button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

input::placeholder, textarea::placeholder { color: var(--text-faint); }

button {
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: var(--r-sm);
  padding: var(--sp-2) var(--sp-4);
  font-weight: 600;
  font-size: var(--fs-sm);
  transition: background-color 0.15s ease, border-color 0.15s ease,
    transform 0.1s ease, box-shadow 0.15s ease;
}
button:hover:not(:disabled) { background: var(--surface-hover); }
button:active:not(:disabled) { transform: translateY(1px); }

/* --------------------------------------------------------------------------
   4. APP SHELL / LAYOUT
   -------------------------------------------------------------------------- */
#app {
  max-width: 1400px;
  margin-inline: auto;
  padding: var(--sp-5) var(--sp-5) var(--sp-7);
  display: flex;
  flex-direction: column;
  gap: var(--sp-6);
}

/* --------------------------------------------------------------------------
   5. TOPBAR
   -------------------------------------------------------------------------- */
#topbar {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  column-gap: var(--sp-4);
  row-gap: var(--sp-1);
  padding-block-end: var(--sp-4);
  border-block-end: 1px solid var(--border-soft);
}

#appTitle {
  grid-column: 1;
  grid-row: 1;
  font-size: var(--fs-2xl);
  font-weight: 800;
  letter-spacing: -0.01em;
}

#appSub {
  grid-column: 1;
  grid-row: 2;
  color: var(--text-muted);
  font-size: var(--fs-sm);
}

#langToggle, #themeToggle {
  grid-row: 1 / span 2;
  align-self: center;
  background: var(--surface);
  border-color: var(--border-soft);
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--r-md);
}
#langToggle:hover, #themeToggle:hover { background: var(--surface-hover); }

/* --------------------------------------------------------------------------
   5b. THEME PICKER — three swatch buttons replacing the single toggle.
   Each dot's own colour is fixed to its theme identity (--swatch-*), not the
   currently active theme, so the owner can always see which is which.
   -------------------------------------------------------------------------- */
.theme-picker {
  grid-row: 1 / span 2;
  align-self: center;
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2);
  background: var(--surface);
  border-radius: var(--r-pill);
  box-shadow: var(--shadow-sm);
}

.theme-dot {
  min-width: 28px;
  min-height: 28px;
  width: 28px;
  height: 28px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--border-soft);
  background: var(--swatch-rose);
  cursor: pointer;
  position: relative;
  transition: transform 0.15s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.15s ease;
}
.theme-dot[data-theme-choice='light'] { background: var(--swatch-light); }
.theme-dot[data-theme-choice='midnight'] { background: var(--swatch-midnight); }

.theme-dot:hover { transform: scale(1.1); }

.theme-dot[aria-pressed='true'] {
  box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--accent);
}

/* --------------------------------------------------------------------------
   6. KPI CARDS — elevation instead of a border, more typographic presence.
   -------------------------------------------------------------------------- */
#kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: var(--sp-4);
}

.kpi-card {
  background: var(--surface);
  border-radius: var(--r-lg);
  padding: var(--sp-5);
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  box-shadow: var(--shadow-card);
  min-height: 108px;
  position: relative;
  overflow: hidden;
}

.kpi-value {
  font-size: var(--fs-xl);
  font-weight: 800;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
}

.kpi-label {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.kpi-sub {
  margin-block-start: auto;
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--text-faint);
  display: flex;
  align-items: center;
  gap: var(--sp-1);
}

.kpi-sub.is-up { color: var(--status-done); }
.kpi-sub.is-down { color: var(--status-urgent); }

/* --------------------------------------------------------------------------
   7. CHARTS
   -------------------------------------------------------------------------- */
#charts {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--sp-4);
}

.chart-card {
  background: var(--surface);
  border-radius: var(--r-lg);
  padding: var(--sp-4) var(--sp-5) var(--sp-5);
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  min-height: 260px;
  box-shadow: var(--shadow-card);
}

.chart-card h3 {
  font-size: var(--fs-md);
  font-weight: 700;
}

.chart-card > div {
  flex: 1;
  min-height: 180px;
}

/* The monthly series is 12 columns wide — in a half-width card its 640-unit
   viewBox scales down to roughly 0.6, shrinking the axis labels below legible
   size. Giving it the full row keeps the SVG near 1:1. */
.chart-card:has(#chartMonthly),
.chart-card:has(#chartPayment) {
  grid-column: 1 / -1;
}

/* The payment-status chart is only a couple of bars — let it span the row for
   layout symmetry, but cap the SVG so the bars don't stretch across the full
   width. */
#chartPayment {
  max-inline-size: 560px;
  margin-inline: auto;
  inline-size: 100%;
}

@media (max-width: 860px) {
  #charts { grid-template-columns: 1fr; }
}

/* --------------------------------------------------------------------------
   8. TOOLBAR
   -------------------------------------------------------------------------- */
#toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-3);
  background: var(--surface);
  border-radius: var(--r-lg);
  padding: var(--sp-3) var(--sp-4);
  box-shadow: var(--shadow-card);
}

#searchInput {
  flex: 1 1 220px;
  min-width: 160px;
}

#filterStatus, #filterPriority { flex: 0 1 160px; }
#filterFrom, #filterTo { flex: 0 1 150px; }

#btnClearFilters {
  background: transparent;
  border-color: var(--border);
  color: var(--text-muted);
}

#btnNew {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-contrast);
  margin-inline-start: auto;
}
#btnNew:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }

#btnExport, #btnPrint {
  background: var(--surface-2);
}

/* --------------------------------------------------------------------------
   8b. COLUMN PICKER
   -------------------------------------------------------------------------- */
.col-picker {
  position: relative;
}

#btnColumns {
  background: var(--surface-2);
}

.columns-panel {
  position: absolute;
  inset-block-start: calc(100% + var(--sp-2));
  inset-inline-start: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  min-inline-size: 220px;
  max-inline-size: min(300px, calc(100vw - var(--sp-5) * 2));
  background: var(--surface-2);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-md);
  padding: var(--sp-3);
}

.columns-panel[hidden] { display: none; }

.columns-panel__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  padding-block-end: var(--sp-2);
  margin-block-end: var(--sp-1);
  border-block-end: 1px solid var(--border-soft);
  font-size: var(--fs-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.linkish {
  background: transparent;
  border: none;
  padding: 0;
  color: var(--link-strong);
  font-weight: 600;
  font-size: var(--fs-xs);
  text-transform: none;
  letter-spacing: normal;
  border-radius: var(--r-sm);
}
.linkish:hover { color: var(--accent-hover); text-decoration: underline; background: transparent; }

.col-opt {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  min-block-size: 32px;
  padding: var(--sp-1) var(--sp-2);
  border-radius: var(--r-sm);
  cursor: pointer;
  user-select: none;
  font-size: var(--fs-sm);
  transition: background-color 0.12s ease;
}
.col-opt:hover { background: var(--surface-hover); }
.col-opt input[type='checkbox'] { accent-color: var(--accent); cursor: pointer; }

/* Keyboard focus visibility */
#btnColumns:focus-visible,
#btnColumnsReset:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.col-opt:has(:focus-visible) {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  background: var(--surface-hover);
}

@media (max-width: 640px) {
  .columns-panel {
    inset-inline-start: 0;
    max-inline-size: calc(100vw - var(--sp-4) * 2);
    max-block-size: 60vh;
    overflow-y: auto;
  }
}

/* --------------------------------------------------------------------------
   9. TABLE
   -------------------------------------------------------------------------- */
#tableWrap {
  background: var(--surface);
  border-radius: var(--r-lg);
  overflow: hidden;
  box-shadow: var(--shadow-card);
}

.table-scroll {
  overflow-x: auto;
  overflow-y: visible;
  max-width: 100%;
}

#requestsTable {
  width: 100%;
  border-collapse: collapse;
  min-width: 900px;
  font-size: var(--fs-sm);
}

#tableHead {
  position: sticky;
  inset-block-start: 0;
  z-index: 2;
  background: var(--surface-2);
}

#requestsTable th {
  text-align: start;
  padding: var(--sp-3) var(--sp-4);
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  font-weight: 700;
  border-block-end: 1px solid var(--border);
  white-space: nowrap;
}

#requestsTable td {
  padding: var(--sp-3) var(--sp-4);
  border-block-end: 1px solid var(--border-soft);
  vertical-align: middle;
}

/* Faint zebra striping, derived entirely from surface/text tokens (no colour
   literal) — helps the eye track a row across a dense, wide table. */
#requestsTable tbody tr:nth-child(even) {
  background: color-mix(in oklch, var(--surface) 96%, var(--text) 4%);
}

#requestsTable tbody tr {
  transition: background-color 0.12s ease;
}
#requestsTable tbody tr:hover {
  background: var(--surface-hover);
}
#requestsTable tbody tr:last-child td {
  border-block-end: none;
}

.cell-clamp {
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.col-actions {
  display: flex;
  gap: var(--sp-2);
  align-items: center;
  white-space: nowrap;
}

.icon-btn, .btn-icon {
  min-width: 32px;
  min-height: 32px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
}
.icon-btn:hover, .btn-icon:hover {
  background: var(--surface-2);
  color: var(--text);
}
.icon-btn.is-danger:hover, .btn-icon.is-danger:hover {
  color: var(--status-urgent);
  background: var(--status-urgent-bg);
}

#emptyState {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: var(--sp-7) var(--sp-4);
  color: var(--text-muted);
  text-align: center;
}
#emptyState.is-visible { display: flex; }

/* --------------------------------------------------------------------------
   9b. AMOUNT & INVOICE CELLS
   -------------------------------------------------------------------------- */
.cell-amount {
  font-variant-numeric: tabular-nums;
  text-align: end;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
}

.cell-amount.amount-zero,
.cell-amount .amount-zero {
  color: var(--text-faint);
  font-weight: 500;
}

.cell-invoice {
  white-space: nowrap;
}

.invoice-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  max-width: 180px;
  padding: var(--sp-1);
  padding-inline-end: var(--sp-3);
  background: var(--surface-2);
  border-radius: var(--r-pill);
  color: var(--text);
  text-decoration: none;
  font-size: var(--fs-xs);
  font-weight: 600;
  transition: background-color 0.15s ease, transform 0.12s ease;
}
.invoice-chip:hover {
  background: var(--surface-hover);
  transform: translateY(-1px);
}
.invoice-chip:active { transform: translateY(0); }

.invoice-chip img,
.invoice-chip .invoice-chip__thumb {
  inline-size: 26px;
  block-size: 26px;
  border-radius: var(--r-sm);
  object-fit: cover;
  flex-shrink: 0;
  background: var(--surface-hover);
}

.invoice-chip span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.invoice-empty {
  color: var(--text-faint);
  font-size: var(--fs-sm);
}

/* --------------------------------------------------------------------------
   10. PILLS (status / priority)
   -------------------------------------------------------------------------- */
.pill {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  padding: var(--sp-1) var(--sp-3);
  border-radius: var(--r-pill);
  font-size: var(--fs-xs);
  font-weight: 700;
  white-space: nowrap;
  line-height: 1.6;
}

.pill::before {
  content: '';
  inline-size: 6px;
  block-size: 6px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

.pill--done { color: var(--status-done); background: var(--status-done-bg); }
.pill--not_done { color: var(--status-not_done); background: var(--status-not_done-bg); }
.pill--in_progress { color: var(--status-in_progress); background: var(--status-in_progress-bg); }
.pill--urgent { color: var(--status-urgent); background: var(--status-urgent-bg); }

.pill--low { color: var(--prio-low); background: var(--prio-low-bg); }
.pill--medium { color: var(--prio-medium); background: var(--prio-medium-bg); }
.pill--high { color: var(--prio-high); background: var(--prio-high-bg); }

.pill--paid { color: var(--paid); background: var(--paid-bg); }
.pill--unpaid { color: var(--unpaid); background: var(--unpaid-bg); }

/* --------------------------------------------------------------------------
   11. DIALOG / FORM
   -------------------------------------------------------------------------- */
#formDialog {
  border: none;
  border-radius: var(--r-xl);
  padding: 0;
  background: var(--bg-elevated);
  color: var(--text);
  box-shadow: var(--shadow-lg);
  width: min(640px, 92vw);
  max-height: 88vh;
  overflow: auto;
  opacity: 1;
  transform: translateY(0) scale(1);
  transition: opacity 0.2s cubic-bezier(0.16, 1, 0.3, 1),
    transform 0.2s cubic-bezier(0.16, 1, 0.3, 1),
    overlay 0.2s allow-discrete, display 0.2s allow-discrete;
}

@starting-style {
  #formDialog[open] {
    opacity: 0;
    transform: translateY(10px) scale(0.98);
  }
}

#formDialog::backdrop {
  background: var(--backdrop);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  opacity: 1;
  transition: opacity 0.2s ease, overlay 0.2s allow-discrete, display 0.2s allow-discrete;
}

@starting-style {
  #formDialog[open]::backdrop { opacity: 0; }
}

#formTitle {
  font-size: var(--fs-lg);
  font-weight: 800;
  padding: var(--sp-5) var(--sp-5) 0;
}

#requestForm {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-4);
  padding: var(--sp-4) var(--sp-5) var(--sp-5);
}

#requestForm label {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--text-muted);
}

#requestForm label.span-2 { grid-column: 1 / -1; }

.checkbox-field {
  flex-direction: row !important;
  align-items: center;
  gap: var(--sp-2) !important;
}
.checkbox-field input[type='checkbox'] { accent-color: var(--accent); cursor: pointer; }

#f_details, #f_notes { resize: vertical; min-height: 72px; }

.form-actions {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-end;
  gap: var(--sp-3);
  padding-block-start: var(--sp-2);
  border-block-start: 1px solid var(--border-soft);
}

#f_save {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-contrast);
}
#f_save:hover:not(:disabled) { background: var(--accent-hover); }

#f_cancel {
  background: transparent;
  color: var(--text-muted);
}

@media (max-width: 560px) {
  #requestForm { grid-template-columns: 1fr; }
}

/* --------------------------------------------------------------------------
   11b. FILE UPLOAD FIELD
   -------------------------------------------------------------------------- */
.file-field {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}

.file-input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.file-drop {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--sp-1);
  padding: var(--sp-5) var(--sp-4);
  border: 1.5px dashed var(--border);
  border-radius: var(--r-md);
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: var(--fs-sm);
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease, color 0.15s ease;
}

.file-drop:hover,
.file-drop.is-dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--text);
}

.file-preview {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-3);
  background: var(--surface-2);
  border-radius: var(--r-md);
}
.file-preview[hidden] { display: none; }

.file-preview img,
.file-preview .file-preview__thumb {
  inline-size: 40px;
  block-size: 40px;
  border-radius: var(--r-sm);
  object-fit: cover;
  background: var(--surface-hover);
  flex-shrink: 0;
}

.file-preview__name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: var(--fs-sm);
  font-weight: 600;
}

.file-remove {
  min-width: 28px;
  min-height: 28px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
  border-radius: var(--r-sm);
}
.file-remove:hover {
  color: var(--status-urgent);
  background: var(--status-urgent-bg);
}

/* --------------------------------------------------------------------------
   11c. COMBOBOX — looks/behaves like a native select until you type
   -------------------------------------------------------------------------- */
.combo {
  position: relative;
}

.combo-input {
  width: 100%;
  padding-inline-end: calc(var(--sp-4) + 20px);
  cursor: pointer;
}

.combo-toggle {
  position: absolute;
  inset-inline-end: var(--sp-1);
  inset-block-start: 50%;
  transform: translateY(-50%);
  min-width: 28px;
  min-height: 28px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
  border-radius: var(--r-sm);
}
.combo-toggle:hover { background: var(--surface-hover); color: var(--text); }

.combo-list {
  position: absolute;
  inset-inline-start: 0;
  inset-block-start: calc(100% + var(--sp-1));
  z-index: 50;
  min-inline-size: 100%;
  max-block-size: 19rem;
  overflow-y: auto;
  margin: 0;
  padding: var(--sp-1);
  list-style: none;
  background: var(--surface-2);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-md);
}
.combo-list[hidden] { display: none; }

.combo-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-2);
  min-block-size: 36px;
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--r-sm);
  cursor: pointer;
  font-size: var(--fs-sm);
}
.combo-option:hover,
.combo-option[aria-selected='true'] {
  background: var(--surface-hover);
}

.combo-del {
  min-width: 24px;
  min-height: 24px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border-color: transparent;
  color: var(--text-faint);
  opacity: 0;
  border-radius: var(--r-sm);
  transition: opacity 0.12s ease, color 0.12s ease, background-color 0.12s ease;
}
.combo-option:hover .combo-del,
.combo-del:focus-visible {
  opacity: 1;
}
.combo-del:hover {
  color: var(--status-urgent);
  background: var(--status-urgent-bg);
}

.combo-add {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  min-block-size: 36px;
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--r-sm);
  color: var(--link-strong);
  font-weight: 700;
  font-size: var(--fs-sm);
  cursor: pointer;
}
.combo-add:hover { background: var(--accent-soft); }

/* --------------------------------------------------------------------------
   12. TOASTS
   -------------------------------------------------------------------------- */
#toastHost {
  position: fixed;
  inset-block-end: var(--sp-5);
  inset-inline-end: var(--sp-5);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  min-width: 220px;
  max-width: 340px;
  background: var(--surface);
  border-radius: var(--r-md);
  padding: var(--sp-3) var(--sp-4);
  box-shadow: var(--shadow-lg);
  font-size: var(--fs-sm);
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  animation: toast-in 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.toast--ok { color: var(--ok); }
.toast--err { color: var(--err); }

/* --------------------------------------------------------------------------
   13. STATUSBAR
   -------------------------------------------------------------------------- */
#statusbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-block-start: var(--sp-3);
  color: var(--text-faint);
  font-size: var(--fs-xs);
}

#syncState { display: inline-flex; align-items: center; gap: var(--sp-1); }

/* --------------------------------------------------------------------------
   14. RESPONSIVE (down to 375px)
   -------------------------------------------------------------------------- */
@media (max-width: 640px) {
  #app { padding: var(--sp-4) var(--sp-3) var(--sp-6); gap: var(--sp-4); }

  #topbar {
    grid-template-columns: 1fr auto;
  }
  #langToggle, #themeToggle {
    grid-row: auto;
    min-width: 40px;
    min-height: 40px;
  }
  .theme-picker { grid-row: auto; }

  #kpis { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }

  #toolbar { flex-direction: column; align-items: stretch; }
  #btnNew { margin-inline-start: 0; }
  #searchInput, #filterStatus, #filterPriority, #filterFrom, #filterTo {
    flex: 1 1 auto;
    width: 100%;
  }
}

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

/* --------------------------------------------------------------------------
   16. PRINT
   Paper is always white/black regardless of active theme — a deliberate,
   scoped exception to the token rule so a dark or rose theme never prints
   with a tinted page background or low-contrast ink.
   -------------------------------------------------------------------------- */
@media print {
  #topbar, #toolbar, #charts, #formDialog, #toastHost, .columns-panel {
    display: none !important;
  }

  body {
    background: #ffffff;
    color: #000000;
  }

  #app { padding: 0; max-width: none; }

  #tableWrap {
    border: none;
    box-shadow: none;
    border-radius: 0;
  }

  .table-scroll { overflow: visible; }

  #requestsTable {
    width: 100%;
    min-width: 0;
  }

  #requestsTable th, #requestsTable td {
    color: #000000;
    border-color: #ccc;
  }

  .col-actions, #requestsTable th:last-child, #requestsTable td:last-child {
    display: none !important;
  }

  #statusbar { display: none; }
}

/* --------------------------------------------------------------------------
   ACTIONS COLUMN
   The two icon buttons must stay on one line. Note these cells are
   deliberately NOT flex containers: display:flex on a th/td takes it out of
   the table layout and knocks the column alignment out of sync with the
   header. Keep them table cells and lay the buttons out inline instead.
   -------------------------------------------------------------------------- */
th.col-actions {
  display: table-cell;
  white-space: nowrap;
}

td.row-actions {
  white-space: nowrap;
}

td.row-actions .btn-icon {
  display: inline-flex;
  vertical-align: middle;
}

td.row-actions .btn-icon + .btn-icon {
  margin-inline-start: var(--sp-2);
}
