/* Themes. Navy is the default (the tokens in app.css, no data-theme). Each
   other theme redefines the design tokens under html[data-theme="..."], set
   before first paint by partials/theme-boot.php and changed by theme-toggle.js.
   Below the themes: light-mode patches for components that still hardcode
   colors in a page's <style>. A component written through the tokens needs
   none.

   Contrast is part of each theme (AA, see the header of app.css): primary
   buttons are --btn-bg with --on-accent at 4.5:1 or more, so --accent itself
   stays light enough to read as text on the dark surfaces. */

html[data-theme="light"] {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #f3f5fa;
  --surface-3: #e9edf5;
  --overlay: rgba(15, 23, 42, .35);
  --border-input: #7f8ba0;
  --highlight: transparent;
  --text: #0f172a;
  --text-2: #475569;
  --text-3: #5d6b82;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-weak: color-mix(in oklch, var(--accent) 9%, transparent);
  --btn-bg: #2563eb;
  --btn-bg-hover: #1d4ed8;
  --success: #047857;
  --success-weak: color-mix(in oklch, var(--success) 10%, transparent);
  --warning: #9a4a07;
  --warning-weak: color-mix(in oklch, #d97706 12%, transparent);
  --danger: #c81e1e;
  --danger-weak: color-mix(in oklch, var(--danger) 9%, transparent);
  --violet: #7c3aed;
  --violet-weak: color-mix(in oklch, var(--violet) 9%, transparent);
  --neutral-weak: rgba(100, 116, 139, .1);
  --on-danger: #ffffff;
  --on-success: #ffffff;
  --chart-1: #2563eb;
  --chart-2: #b7791f;
  --chart-3: #0f8f84;
  --chart-4: #d6336c;
  --chart-5: #7c3aed;
  --chart-6: #4d8a1e;
  --chart-7: #d9622b;
  --chart-8: #0284c7;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06);
  --shadow-lg: 0 24px 64px rgba(15, 23, 42, .18);
  /* the older names (--panel, --muted, --blue, ...) are aliases in app.css
     and follow these values; nothing to redefine for them */
  color-scheme: light;
}

/* OLED: true black with neutral greys (no blue cast), for OLED screens.
   A dark theme: everything written for the default dark palette applies. */
html[data-theme="oled"] {
  --bg: #000000;
  --surface: #0b0b0d;
  --surface-2: #121215;
  --surface-3: #1a1a1f;
  --overlay: rgba(0, 0, 0, .72);
  --border-input: #62626a;
  --text: #ededf0;
  --text-2: #a4a4ad;
  --text-3: #85858f;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .6);
  --shadow-lg: 0 24px 64px rgba(0, 0, 0, .85);
  color-scheme: dark;
}

/* The colour tints (Green, Purple, Pink, Red, Orange, Yellow, Rainbow) and the
   seasons share one ramp in OKLCH: every surface, border and text step has the
   same lightness in each, tinted by the theme's hue (--tint-h) and chroma
   (--tint-c). So contrast is the same in all of them by construction: text-3
   is 5.5:1 on --surface, 4.7:1 on --surface-3; --border-input is 3:1. */
html:is([data-theme="green"], [data-theme="purple"], [data-theme="pink"], [data-theme="red"], [data-theme="orange"],
        [data-theme="yellow"], [data-theme="rainbow"], [data-theme="fall"], [data-theme="christmas"],
        [data-theme="winter"], [data-theme="spring"], [data-theme="summer"]) {
  --bg: oklch(18.5% var(--tint-c) var(--tint-h));
  --surface: oklch(21.5% calc(var(--tint-c) * 1.2) var(--tint-h));
  --surface-2: oklch(24% calc(var(--tint-c) * 1.4) var(--tint-h));
  --surface-3: oklch(27.2% calc(var(--tint-c) * 1.65) var(--tint-h));
  --border-input: oklch(53% calc(var(--tint-c) * 2.2) var(--tint-h));
  --text: oklch(95% calc(var(--tint-c) * .6) var(--tint-h));
  --text-2: oklch(78.5% calc(var(--tint-c) * 1.4) var(--tint-h));
  --text-3: oklch(65.5% calc(var(--tint-c) * 1.6) var(--tint-h));
  --overlay: oklch(8% calc(var(--tint-c) * .6) var(--tint-h) / .64);
  --accent-weak: color-mix(in oklch, var(--accent) 16%, transparent);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .35);
  --shadow-lg: 0 24px 64px rgba(0, 0, 0, .55);
  color-scheme: dark;
}

/* Green: a muted green cast and a cyan-teal accent (kept apart from the
   emerald --success, so "paid"/"done" never reads as a button). */
html[data-theme="green"] {
  --tint-h: 166; --tint-c: .013;
  --accent: oklch(66% .111 211);
  --accent-hover: oklch(71% .105 211);
  --btn-bg: oklch(55% .095 211);
  --btn-bg-hover: oklch(50% .09 211);
}

/* Purple, Pink, Red: a muted cast of the colour, and an accent in it. Where
   the accent would collide with a status colour, the status colour moves
   (review, --violet, goes fuchsia on Purple). Red's accent is a true red, kept
   well clear of Orange's hue; a Save is a solid red fill while a delete is a
   tinted --danger button, so the two still read differently. */
html[data-theme="purple"] {
  --tint-h: 297; --tint-c: .023;
  --accent: oklch(68.5% .182 293);
  --accent-hover: oklch(73.5% .16 293);
  --btn-bg: oklch(58% .2 293);
  --btn-bg-hover: oklch(53% .2 293);
  --violet: #e879f9;
}
html[data-theme="pink"] {
  --tint-h: 342; --tint-c: .016;
  --accent: oklch(69% .19 357);
  --accent-hover: oklch(74% .16 357);
  --btn-bg: oklch(58.5% .19 357);
  --btn-bg-hover: oklch(53.5% .18 357);
}
html[data-theme="red"] {
  --tint-h: 19; --tint-c: .015;
  --accent: oklch(69% .185 18);
  --accent-hover: oklch(74% .16 18);
  --btn-bg: oklch(55% .2 20);
  --btn-bg-hover: oklch(50% .185 20);
}

/* Orange and Yellow: the same cast. Their accent would collide with --warning
   (amber), so warnings move: to yellow on Orange, to orange on Yellow. Yellow
   is too light for white text, so --on-accent is dark there (buttons, the
   calendar's today, switches, the top-bar avatar). */
html[data-theme="orange"] {
  --tint-h: 63; --tint-c: .018;
  --accent: oklch(68.5% .175 50);
  --accent-hover: oklch(73.5% .16 50);
  --btn-bg: oklch(57.5% .153 50);
  --btn-bg-hover: oklch(52.5% .14 50);
  --warning: #facc15;
}
html[data-theme="yellow"] {
  --tint-h: 96; --tint-c: .019;
  --accent: #eab308;
  --accent-hover: #facc15;
  --btn-bg: #eab308;
  --btn-bg-hover: #facc15;
  --on-accent: #1c1600;
  --warning: #fb923c;
}

/* Rainbow: neutral charcoal, a violet accent, and the spectrum on the frame:
   a rainbow line under the top bar and on primary buttons (stops dark enough
   for white text). */
html[data-theme="rainbow"] {
  --tint-h: 286; --tint-c: .006;
  --accent: oklch(69% .202 304);
  --accent-hover: oklch(74% .17 304);
  --btn-bg: oklch(58.5% .21 304);
  --btn-bg-hover: oklch(53.5% .2 304);
  --frame-line: linear-gradient(90deg in oklch, #ef4444, #f97316, #eab308, #22c55e, #06b6d4, #3b82f6, #8b5cf6, #ec4899);
  --rainbow-deep: linear-gradient(90deg in oklch, #d33a4c, #c25100, #986d05, #0f863f, #007abc, #5a5ee0, #9a48d6);
}
html[data-theme="rainbow"] .btn:not(.secondary):not(.ghost):not(.danger):not(.success) {
  background-image: var(--rainbow-deep); color: var(--on-accent); text-shadow: 0 1px 1px rgba(0, 0, 0, .35);
}
html[data-theme="rainbow"] .btn:not(.secondary):not(.ghost):not(.danger):not(.success):hover { filter: brightness(.92); }

/* Seasonal: the 'seasonal' theme shows one of these, by date or as picked on
   Settings (theme-toggle.js). Each is a tint on the shared ramp with an
   accent, a line under the top bar (--frame-line) and Home's glow colours
   (--glow-1, --glow-2). Status colours stay put except where the accent would
   collide: warnings go yellow on Fall and orange on Christmas. Christmas keeps
   its red and green to the decoration, since red and green mean error and
   success everywhere else; its accent is gold, with dark text. */
html[data-theme="fall"] {
  --tint-h: 65; --tint-c: .016;
  --accent: oklch(68% .144 56);
  --accent-hover: oklch(73% .13 56);
  --btn-bg: oklch(57% .14 56);
  --btn-bg-hover: oklch(52% .13 56);
  --warning: #facc15;
  --frame-line: linear-gradient(90deg in oklch, #7c2d12, #c2410c, #d97706, #ca8a04, #a16207, #7c2d12);
  --glow-1: #c2410c;
  --glow-2: #ca8a04;
}
html[data-theme="christmas"] {
  --tint-h: 162; --tint-c: .018;
  --accent: #d4a62a;
  --accent-hover: #e2b843;
  --btn-bg: #d4a62a;
  --btn-bg-hover: #e2b843;
  --on-accent: #1a1400;
  --warning: #fb923c;
  --frame-line: repeating-linear-gradient(90deg, #c0392b 0 28px, #e8e2d0 28px 36px, #1f8a4c 36px 64px, #e8e2d0 64px 72px);
  --glow-1: #c0392b;
  --glow-2: #1f8a4c;
}
html[data-theme="winter"] {
  --tint-h: 252; --tint-c: .017;
  --accent: oklch(66.5% .116 228);
  --accent-hover: oklch(71.5% .105 228);
  --btn-bg: oklch(55.5% .108 228);
  --btn-bg-hover: oklch(50.5% .1 228);
  --frame-line: linear-gradient(90deg in oklch, #1e3a5f, #7dd3fc, #f0f9ff, #7dd3fc, #1e3a5f);
  --glow-1: #7dd3fc;
  --glow-2: #e0f2fe;
}
html[data-theme="spring"] {
  --tint-h: 297; --tint-c: .018;
  --accent: oklch(69% .159 351);
  --accent-hover: oklch(74% .14 351);
  --btn-bg: oklch(58% .159 351);
  --btn-bg-hover: oklch(53% .15 351);
  --frame-line: linear-gradient(90deg in oklch, #f9a8d4, #fde68a, #a7f3d0, #c4b5fd, #bae6fd, #f9a8d4);
  --glow-1: #f472b6;
  --glow-2: #6ee7b7;
}
html[data-theme="summer"] {
  --tint-h: 86; --tint-c: .010;
  --accent: oklch(66.5% .143 243);
  --accent-hover: oklch(71.5% .13 243);
  --btn-bg: oklch(55.5% .135 243);
  --btn-bg-hover: oklch(50.5% .13 243);
  --frame-line: linear-gradient(90deg in oklch, #f59e0b, #f97316, #fb7185, #06b6d4, #0284c7);
  --glow-1: #f59e0b;
  --glow-2: #06b6d4;
}

/* the coloured line under the top bar: Rainbow and the seasons */
html[data-theme="rainbow"] .pf-topbar, html[data-theme="fall"] .pf-topbar, html[data-theme="christmas"] .pf-topbar,
html[data-theme="winter"] .pf-topbar, html[data-theme="spring"] .pf-topbar, html[data-theme="summer"] .pf-topbar {
  border-bottom: 2px solid transparent; border-image: var(--frame-line) 1;
}

html[data-theme="light"] .wrap,
html[data-theme="light"] .card,
html[data-theme="light"] .column,
html[data-theme="light"] .modal,
html[data-theme="light"] .widget,
html[data-theme="light"] .dash-header,
html[data-theme="light"] table {
  box-shadow: var(--shadow-sm);
}

/* A handful of pages use hardcoded (non-variable) colors for table striping,
   status chips, task cards and inputs; in Light they're mapped back to the
   tokens here rather than in every page's <style>. */
html[data-theme="light"] th,
html[data-theme="light"] .subtbl th {
  background: var(--surface);
}
html[data-theme="light"] tr:hover td {
  background: var(--surface-2);
}
/* Status chips/badges with dark-tuned literal colors (projects, contracts,
   billing, the customer portal): each semantic family on its status tokens. */
html[data-theme="light"] .chip.paid,
html[data-theme="light"] .chip.active,
html[data-theme="light"] .chip.ok,
html[data-theme="light"] .badge.active,
html[data-theme="light"] .status-select.active {
  color: var(--success);
  background: var(--success-weak);
  border-color: color-mix(in oklch, var(--success) 25%, transparent);
}
html[data-theme="light"] .chip.overdue,
html[data-theme="light"] .chip.bad,
html[data-theme="light"] .chip.expired {
  color: var(--danger);
  background: var(--danger-weak);
  border-color: color-mix(in oklch, var(--danger) 25%, transparent);
}
html[data-theme="light"] .chip.warn,
html[data-theme="light"] .chip.expiring-soon,
html[data-theme="light"] .chip.terminated,
html[data-theme="light"] .badge.on_hold,
html[data-theme="light"] .status-select.on_hold {
  color: var(--warning);
  background: var(--warning-weak);
  border-color: color-mix(in oklch, var(--warning) 25%, transparent);
}
html[data-theme="light"] .badge.archived,
html[data-theme="light"] .status-select.archived {
  color: var(--text-2);
  background: var(--neutral-weak);
  border-color: var(--border);
}
html[data-theme="light"] .badge.done,
html[data-theme="light"] .status-select.done {
  color: var(--accent);
  background: var(--accent-weak);
  border-color: color-mix(in oklch, var(--accent) 25%, transparent);
}
html[data-theme="light"] .col-count.wip-over {
  background: var(--danger-weak);
}
html[data-theme="light"] .card:hover {
  background: var(--surface-2);
}
html[data-theme="light"] .progress {
  background: var(--surface-3);
}
html[data-theme="light"] .jira-dropdown {
  background: var(--surface);
}
html[data-theme="light"] .jira-dropdown .jira-opt:hover,
html[data-theme="light"] .jira-dropdown .jira-opt.active {
  background: var(--surface-3);
}
html[data-theme="light"] .card {
  background: var(--surface);
}
html[data-theme="light"] input[type="text"],
html[data-theme="light"] input[type="date"],
html[data-theme="light"] input[type="month"],
html[data-theme="light"] input[type="datetime-local"],
html[data-theme="light"] input[type="number"],
html[data-theme="light"] input[type="time"],
html[data-theme="light"] input[type="email"],
html[data-theme="light"] input[type="password"],
html[data-theme="light"] input[type="file"],
html[data-theme="light"] select,
html[data-theme="light"] textarea,
html[data-theme="light"] .toast,
html[data-theme="light"] .dash-search input {
  background: var(--surface);
}

/* Toggle button (icon swaps based on current theme) */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
  padding: 0;
}
.theme-toggle:hover { color: var(--text); border-color: var(--accent); }
.theme-toggle svg { width: 16px; height: 16px; }
.theme-toggle .icon-moon { display: none; }
html[data-theme="light"] .theme-toggle .icon-sun { display: none; }
html[data-theme="light"] .theme-toggle .icon-moon { display: block; }
