/* ==========================================================================
   DARK THEME — only when the page is opened with ?theme=dark (the inline
   script in index.html sets <html data-theme="dark">). Normal visits never
   load any of this, so the light look is untouched.

   Palette (slate):
     page        #0b1120     grid      #0f172a     headers / dates  #131c31
     thin line   #1e293b     group     #334155     week / month     #475569
     text        #e2e8f0     muted     #94a3b8     accent           #60a5fa
   ========================================================================== */

html[data-theme="dark"] {
  color-scheme: dark;
  --bg-main: #0b1120;
  --bg-surface: rgba(15, 23, 42, 0.92);
  --border-color: #1e293b;
  --text-main: #e2e8f0;
  --text-muted: #94a3b8;
  --accent: #3b82f6;
  --accent-hover: #60a5fa;
}
html[data-theme="dark"],
html[data-theme="dark"] body { background: #0b1120; background-image: none; color: #e2e8f0; }

/* ── Toolbar ───────────────────────────────────────────────────────────── */
html[data-theme="dark"] .calendar-toolbar,
html[data-theme="dark"] .toolbar,
html[data-theme="dark"] .unified-sticky-header { background: #0b1120 !important; border-color: #1e293b; }
html[data-theme="dark"] .toolbar-btn { background: #1e293b; border-color: #334155; color: #e2e8f0; }
html[data-theme="dark"] .toolbar-btn:hover { background: #273449; }
html[data-theme="dark"] .toolbar-btn.mode-view { background: #131c31; color: #94a3b8; }
html[data-theme="dark"] .toolbar-btn.mode-edit { background: #052e16; color: #86efac; border-color: #166534; }
html[data-theme="dark"] .toolbar-btn.active,
html[data-theme="dark"] .zoom-switch .toolbar-btn.active { background: #e2e8f0; color: #0f172a; border-color: #e2e8f0; }
html[data-theme="dark"] .sync-badge { background: rgba(15, 23, 42, 0.92); border-color: #334155; color: #94a3b8; }
html[data-theme="dark"] .sync-badge[data-state="stale"] { background: #2a1d06; border-color: #92400e; color: #fbbf24; }

/* ── Grid ──────────────────────────────────────────────────────────────── */
html[data-theme="dark"] .calendar-root { background: #0b1120; }
html[data-theme="dark"] .timeline-matrix { border-color: #1e293b; box-shadow: none; }
html[data-theme="dark"] .timeline-matrix.sheet-matrix { background: #0f172a; }

html[data-theme="dark"] .sg-corner,
html[data-theme="dark"] .sg-group,
html[data-theme="dark"] .sg-lane-head { background: #131c31; color: #94a3b8; }
html[data-theme="dark"] .sg-corner { color: #93c5fd; border-right-color: #334155; border-bottom-color: #334155; }
html[data-theme="dark"] .sg-group { border-left-color: #334155; border-bottom-color: #1e293b; }
html[data-theme="dark"] .sg-group[style*="1 / 3"] { border-bottom-color: #334155; }
html[data-theme="dark"] .sg-lane-head { border-left-color: #1e293b; border-bottom-color: #334155; color: #64748b; }
html[data-theme="dark"] .sg-missing { color: #64748b; }

html[data-theme="dark"] .sg-day { background: #131c31; border-right-color: #334155; border-bottom-color: #1e293b; }
html[data-theme="dark"] .sg-day .sg-dn { color: #94a3b8; }
html[data-theme="dark"] .sg-day .sg-dd { color: #e2e8f0; }
html[data-theme="dark"] .sg-day.weekend { color: #64748b; }
html[data-theme="dark"] .sg-day.today { background: #172554; }
html[data-theme="dark"] .today-text { color: #60a5fa !important; }

html[data-theme="dark"] .sg-cell { border-left-color: #1e293b; border-bottom-color: #1e293b; }
html[data-theme="dark"] .sg-cell.grp-start { border-left-color: #334155; }
html[data-theme="dark"] .sg-cell.today { background: rgba(59, 130, 246, 0.10); }
html[data-theme="dark"] .sg-cell.clickable-cell:hover { background: rgba(96, 165, 250, 0.10); }
/* Weekends: a shade darker than weekdays (the light theme makes them greyer). */
html[data-theme="dark"] .weekend { background-color: #0a1020 !important; }
html[data-theme="dark"] .sg-day.weekend { background-color: #0e1528 !important; }
html[data-theme="dark"] .sg-day.wk-start,
html[data-theme="dark"] .sg-cell.wk-start { border-top-color: #475569; }
html[data-theme="dark"] .sheet-grid { border-right-color: #475569; border-bottom-color: #475569; }

html[data-theme="dark"] .sg-holiday { background: rgba(148, 163, 184, 0.10); color: #94a3b8; }
html[data-theme="dark"] .sg-today-frame { border-color: #3b82f6; box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.25); }

html[data-theme="dark"] .sg-month-strip { background: #0f1d3a; border-right-color: #1e3a8a; }
html[data-theme="dark"] .sg-month-strip span { color: #93c5fd; }

/* ── Bookings ──────────────────────────────────────────────────────────── */
/* Sheet colours stay (they carry meaning), toned down a touch so they don't
   glare on a dark screen. */
html[data-theme="dark"] .sheet-grid .project-pill { filter: brightness(0.88) saturate(0.92); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.5); }
/* White bookings in the sheet would be bright white blocks: show them as
   slate cards with a light outline instead (kept apart from the dark-grey
   bookings). The pill's colours are inline !important, so this paints a
   background-image over them, draws the outline as a shadow and recolours
   the text on the children. */
html[data-theme="dark"] .sheet-grid .project-pill.pill-pale {
  filter: none;
  background-image: linear-gradient(#1e293b, #1e293b);
  border-width: 0 !important;
  box-shadow: inset 0 0 0 1px #64748b, inset 0 -3px 0 #64748b;
}
html[data-theme="dark"] .sheet-grid .project-pill.pill-pale .title,
html[data-theme="dark"] .sheet-grid .project-pill.pill-pale .detail { color: #e2e8f0; }
/* Pale pastel bookings (dark text): dim a little more. */
html[data-theme="dark"] .sheet-grid .project-pill.pill-light { filter: brightness(0.78); }
html[data-theme="dark"] .project-pill.is-active { outline-color: #93c5fd; }

/* ── Year scrubber ─────────────────────────────────────────────────────── */
html[data-theme="dark"] .ys-track { background: rgba(19, 28, 49, 0.95); box-shadow: 0 0 0 1px rgba(71, 85, 105, 0.6); }
html[data-theme="dark"] .ys-band { background: rgba(226, 232, 240, 0.22); }
html[data-theme="dark"] .ys-month { color: #94a3b8; background: rgba(15, 23, 42, 0.85); }
html[data-theme="dark"] .ys-bubble { background: #e2e8f0; color: #0f172a; }

/* ── Today button, colour bar, loading ─────────────────────────────────── */
html[data-theme="dark"] #todayFab { background: #1e293b; box-shadow: 0 3px 12px rgba(0, 0, 0, 0.6), 0 0 0 1px #334155; }
html[data-theme="dark"] #todayFab .tf-top { background: #3b82f6; }
html[data-theme="dark"] #todayFab .tf-day { color: #e2e8f0; }
html[data-theme="dark"] #pillColorPicker { background: rgba(15, 23, 42, 0.98) !important; box-shadow: 0 -2px 16px rgba(0, 0, 0, 0.6) !important; }
html[data-theme="dark"] .loading-state { color: #94a3b8; }

/* ==========================================================================
   SCREENSAVER (?screensaver=1): the calendar alone. Any mouse or key input
   closes the screensaver, so nothing here is meant to be clicked.
   ========================================================================== */
html[data-screensaver="1"] .calendar-toolbar,
html[data-screensaver="1"] #todayFab,
html[data-screensaver="1"] .year-scrubber,
html[data-screensaver="1"] .sync-badge[data-state="updating"] { display: none !important; }
html[data-screensaver="1"] body { cursor: none; }
html[data-screensaver="1"] .timeline-matrix.sheet-matrix { scrollbar-width: none; }
html[data-screensaver="1"] .timeline-matrix.sheet-matrix::-webkit-scrollbar { display: none; }
/* Columns fill the screen width (sheetView uses fr widths in this mode). */
html[data-screensaver="1"] .sheet-grid { width: 100%; }
/* Fluid screensaver motion (screensaver.js setScroll): the calendar is shifted
   by the sub-pixel part of the scroll; the header stuck at the top is shifted
   back so it stays still. */
html[data-screensaver="1"] .sheet-grid { transform: translate(calc(-1 * var(--ssx, 0px)), calc(-1 * var(--ssf, 0px))); will-change: transform; }
/* stuck at the top: undo the vertical fraction */
html[data-screensaver="1"] .sheet-grid.ss-stuck > .sg-group,
html[data-screensaver="1"] .sheet-grid.ss-stuck > .sg-lane-head,
html[data-screensaver="1"] .sheet-grid.ss-stuck > .sg-month-strip > span { transform: translateY(var(--ssf, 0px)); }
/* stuck on the left (dates, month name): undo the sideways fraction */
html[data-screensaver="1"] .sheet-grid > .sg-day,
html[data-screensaver="1"] .sheet-grid > .sg-month-strip,
html[data-screensaver="1"] .sheet-grid > .sg-corner { transform: translateX(var(--ssx, 0px)); }
html[data-screensaver="1"] .sheet-grid.ss-stuck > .sg-corner { transform: translate(var(--ssx, 0px), var(--ssf, 0px)); }
html[data-theme="dark"] .sg-pill-day::before { background: rgba(255, 255, 255, 0.35); }
html[data-theme="dark"] .sg-pill-day.on-pale::before { background: rgba(226, 232, 240, 0.16); }
html[data-theme="dark"] .sg-pill-day.on-pale { color: rgba(226, 232, 240, 0.6); }   /* pale bookings are slate in dark mode */
html[data-theme="dark"] .sg-pill-day.on-pale .nm.own { color: #e2e8f0; }
/* No year bar in the screensaver: give its space back to the calendar. */
html[data-screensaver="1"] .sheet-wrapper { padding-right: 0; }
/* Narrow columns (portrait screen): long words wrap instead of sticking out. */
html[data-screensaver="1"] .sg-title,
html[data-screensaver="1"] .sheet-grid .project-pill .title { overflow-wrap: break-word; hyphens: auto; -webkit-hyphens: auto; }
html[data-screensaver="1"] .sg-group { overflow: hidden; }
/* No snapping to column groups (phone swipes): it would fight the sideways loop. */
html[data-screensaver="1"] .timeline-matrix.sheet-matrix { scroll-snap-type: none; }

/* Section backgrounds, dark: a faint warm (Production) / blue (Livraison) tint. */
html[data-theme="dark"] .sg-cell[data-category-group="production"]:not(.weekend):not(.today) { background: #1c1a17; }
html[data-theme="dark"] .sg-cell[data-category-group="livraison"]:not(.weekend):not(.today)  { background: #121c2b; }
html[data-theme="dark"] .sg-group.sec-production { background: #2a2419; }
html[data-theme="dark"] .sg-group.sec-livraison  { background: #16243a; }
html[data-theme="dark"] .sg-cell[data-category-group].clickable-cell:hover { background: rgba(96, 165, 250, 0.14); }
