/* Dark / Light theme — Sept 2026 UI pass.
   ------------------------------------------------------------------------
   Why a color-inversion filter instead of re-coloring every component:
   the existing stylesheet hardcodes a white/light background on ~230 separate
   selectors across 15+ files (every .panel, .kpi, table, modal, card variant,
   each written independently, often with !important). Re-theming each one by
   hand for this pass would mean editing hundreds of individual rules with a
   real risk of missing some -- leaving a "half dark, half light" dashboard,
   which is worse than not shipping dark mode at all.
   Inverting lightness (then rotating hue back by 180°, which approximately
   restores each color's original hue while flipping its lightness) gives a
   complete, consistent dark theme across every current AND future page in one
   place, guaranteed not to miss a component. This is the same technique
   browser "force dark mode" features use for sites without native dark mode.
   The sidebar is already a dark navy in the light theme, so it's excluded from
   the filter (inverting it would make it light instead of dark). Photographic
   <img> content (evidence photos, the company logo) is inverted a second time
   so it renders normally instead of as a photo negative. The login screen
   (already dark-branded on its own) is left untouched in both themes. */

html[data-theme="dark"]{
  background:#0a0e14;
}
html[data-theme="dark"] body{
  background:#0a0e14;
}
/* Deliberately no `color-scheme:dark` anywhere: a first attempt scoped it to
   #app>main/#modal to get native dark scrollbars/form controls, but that backfired --
   color-scheme:dark makes the browser render native controls (particularly <select>)
   with ITS OWN dark UA background, and this rule's invert(1) filter then flips that
   already-dark control back to light, so every dropdown stood out as a bright white box
   against the rest of the dark, inverted page. Leaving color-scheme at its default
   (light) means selects render with their normal light UA background like they always
   did, and THIS filter inverts that once, same as everything else -- consistent. */
/* contrast(.88) + brightness(1.06): a plain invert(1) turns the near-white page
   background (#f3f6fb) into near-BLACK, and dark navy text (#162238) into near-PURE
   WHITE -- a full 0%-97% lightness swing. Pure-white-on-near-black is the single most
   common cause of dark-mode eye strain (halation around text, especially bold/small
   sans-serif). Pulling the curve in toward mid-gray softens both ends: the background
   settles into a dark charcoal instead of true black, and text settles into a soft
   off-white instead of stark white -- same technique, readable, much easier to stare
   at for a whole shift. */
html[data-theme="dark"] #app>main,
html[data-theme="dark"] #modal{
  filter:invert(1) hue-rotate(180deg) contrast(.75) brightness(1.04);
}

/* Undo the inversion specifically for photographic content so photos and the
   logo read normally instead of as a negative. Charts are plain SVG shapes
   (not photos), so they're left inverted along with everything else --
   inverted line/area charts still read fine, there's no "wrong way round".
   This must be the exact inverse of the parent's filter chain, in reverse order
   (brightness undone first, then contrast, then hue-rotate, then invert) -- since
   the parent filter now includes contrast()/brightness() (see above) and those
   aren't self-cancelling like invert()/hue-rotate(180deg) are, simply repeating
   the same filter on the image would apply contrast/brightness TWICE and leave
   photos visibly washed out instead of restored to their original look. */
html[data-theme="dark"] #app>main img,
html[data-theme="dark"] #modal img,
html[data-theme="dark"] #app>main svg image,
html[data-theme="dark"] #modal svg image{
  filter:brightness(0.9615) contrast(1.3333) hue-rotate(180deg) invert(1);
}

/* Evidence-gallery lightbox and any other overlay appended straight to <body>
   (outside #app/#modal) need the same treatment. */
html[data-theme="dark"] .evidence-gallery-overlay,
html[data-theme="dark"] .exec-drilldown-overlay,
html[data-theme="dark"] .repair-drawer-layer,
html[data-theme="dark"] .repair-actions-portal,
html[data-theme="dark"] .fdm-export-overlay,
html[data-theme="dark"] .fd-copy-overlay,
html[data-theme="dark"] .pck-evidence-lightbox{
  /* fdm-export-overlay (Fleet DMS "Export PDF/Excel"), fd-copy-overlay ("Salin Shift") and
     pck-evidence-lightbox (Pre Check evidence viewer) were missing from this list entirely --
     each is its own popup appended straight to <body> outside #app/#modal, built before dark
     mode existed, so none of them were included when the filter selector list was first
     written. They stayed fully light regardless of theme -- the "Export PDF" dialog that
     looked untouched by dark mode while everything behind it went dark. */
  filter:invert(1) hue-rotate(180deg) contrast(.75) brightness(1.04);
}
html[data-theme="dark"] .evidence-gallery-overlay img,
html[data-theme="dark"] .pck-evidence-lightbox img{
  filter:brightness(0.9615) contrast(1.3333) hue-rotate(180deg) invert(1);
}

/* ==========================================================================
   Modern (macOS-style) popup / modal skin — applies in both themes.
   ------------------------------------------------------------------------
   Sept 2026 follow-up: it turned out there wasn't just one modal system to
   restyle. Five different popups had been built independently over time,
   each with its own header treatment, its own close-button shape/color, and
   its own corner radius: the generic `.modal`/`.modal-box` (forms, confirms),
   `.bp-history-v2` (Backup Part stock history, inside a `.modal-box:has()`
   variant with its own blue gradient header), `.exec-drilldown` (Executive
   KPI drilldown, a right-side panel with a different blue gradient header),
   `.fdm-export-dialog` (Fleet DMS "Export PDF/Excel", teal accents), and
   `.fd-copy-dialog` (Fleet DMS "Salin Shift"). Restyling only the generic one
   earlier left the other four looking like leftovers from a different app.
   Below, ALL of them are pulled onto one shared visual language: neutral
   header (no per-feature gradient banner -- a small muted eyebrow label
   carries the feature identity instead, the way a macOS panel keeps its
   title bar neutral and reserves color for content/icons), the same 30px
   circular close button everywhere, the same 18px corner radius, and a
   matching entrance motion (centered popups scale+fade in; the two
   right-anchored panels -- KPI drilldown and repair detail -- slide in from
   the edge, which is the correct mac-style motion for a docked panel, but
   now share the same floating position/radius/shadow instead of one being
   flush-edge and the other floating). Geometry (radius, blur, motion) is
   untouched by the dark-mode filter above (filter only transforms
   color/luminance), so writing it once here covers both themes at once. */
.modal{
  background:rgba(20,22,28,.4)!important;
  backdrop-filter:blur(22px) saturate(1.7)!important;
  -webkit-backdrop-filter:blur(22px) saturate(1.7)!important;
  animation:dmsModalBackdropIn .18s ease-out;
}
.modal-box{
  /* Was min(780px,96vw) for every plain modal, form or not -- a 4-field
     confirmation dialog (e.g. Part Request detail) stretched to nearly 800px
     wide, leaving large empty margins either side of a handful of short
     label/value pairs. Feature-specific modals that genuinely need more room
     (Pre Check form, Admin Repair edit, Backup Part history) set their own
     width via a `:has()` variant with higher specificity, so they keep their
     tuned size untouched by this smaller default. */
  width:min(600px,92vw)!important;
  border-radius:18px!important;
  border:1px solid rgba(0,0,0,.06);
  box-shadow:0 24px 60px -12px rgba(0,0,0,.35),0 0 0 1px rgba(0,0,0,.04)!important;
  animation:dmsModalIn .26s cubic-bezier(.34,1.35,.4,1);
}
/* A handful of simple detail views used a fixed 4-column info grid that only
   ever collapsed at a narrow VIEWPORT width via @media -- so on a normal
   desktop, shrinking the modal itself (above) still squeezed 4 columns into
   very little space. auto-fit lets the grid respond to the modal's own width
   instead, regardless of how wide the browser window is. */
.repair-detail-grid{grid-template-columns:repeat(auto-fit,minmax(150px,1fr))!important}
@keyframes dmsModalBackdropIn{from{opacity:0}to{opacity:1}}
@keyframes dmsModalIn{
  from{opacity:0;transform:scale(.92) translateY(14px)}
  60%{opacity:1;transform:scale(1.015) translateY(-1px)}
  to{opacity:1;transform:scale(1) translateY(0)}
}
@media (prefers-reduced-motion: reduce){
  .modal, .modal-box{animation:none}
}
/* One circular close button, reused verbatim across every popup family below. */
.modal-box>.close,
.modal-box>#modalClose,
.modal-box:has(.bp-history-v2)>#modalClose.close,
.modal-box:has(.bp-history-v2)>#modalClose,
.exec-drilldown-close,
.fdm-export-dialog>header button,
.fd-copy-close,
.repair-drawer-layer .repair-drawer-close,
.pck-lightbox-close{
  position:absolute!important;
  top:14px!important;
  right:14px!important;
  inset:14px 14px auto auto!important;
  width:30px!important;
  height:30px!important;
  min-width:30px!important;
  min-height:30px!important;
  display:flex!important;
  align-items:center!important;
  justify-content:center!important;
  padding:0!important;
  margin:0!important;
  border:0!important;
  border-radius:50%!important;
  background:rgba(120,120,128,.16)!important;
  color:#6e7681!important;
  font-size:16px!important;
  font-weight:400!important;
  line-height:1!important;
  box-shadow:none!important;
  transition:background .15s ease,transform .15s ease;
}
.modal-box>.close:hover,
.modal-box>#modalClose:hover,
.modal-box:has(.bp-history-v2)>#modalClose:hover,
.exec-drilldown-close:hover,
.fdm-export-dialog>header button:hover,
.fd-copy-close:hover,
.repair-drawer-layer .repair-drawer-close:hover,
.pck-lightbox-close:hover{
  background:rgba(120,120,128,.28)!important;
  border-color:transparent!important;
  transform:scale(1.05);
}

/* ---- Neutral header treatment for the popups that had their own colored
   gradient banner. Each keeps its distinguishing eyebrow label so you can
   still tell them apart at a glance -- only the loud gradient goes. ---- */
.bp-history-v2-head{
  background:#f1f5f9!important;
  color:inherit!important;
  padding:20px 56px 16px 22px!important;
}
.bp-history-v2-title small{color:#64748b!important}
.bp-history-v2-title h2{color:#0f172a!important}
.bp-history-v2-title p{color:#475569!important}
.bp-history-v2-stock{background:#fff!important;border:1px solid #dbe4ee!important}
.bp-history-v2-stock>span{color:#64748b!important}
.bp-history-v2-stock strong,.bp-history-v2-stock small{color:#0f172a!important}

.exec-drilldown-head{
  background:#f1f5f9!important;
  color:inherit!important;
  box-shadow:none!important;
  border-bottom:1px solid #e2e8f0!important;
}
.exec-drilldown-head h3{color:#0f172a!important;text-shadow:none!important}
.exec-drilldown-head p{color:#475569!important}
.exec-drilldown-count{background:#e2e8f0!important;color:#1d4ed8!important;box-shadow:none!important}
/* Match the repair-detail drawer's floating position/radius instead of a
   flush full-height edge panel -- the two "slide-in from the side" popups
   now share the same shape. */
.exec-drilldown{
  /* The base rule never set `position` -- it relied on being a flex child of
     `.exec-drilldown-overlay{display:flex;justify-content:flex-end}` to sit at
     the right edge, so top/right/bottom below would otherwise do nothing.
     Taking it out of flex flow and positioning it directly is what actually
     lets it float with a margin instead of sitting flush full-height. */
  position:absolute!important;
  top:3vh!important;
  bottom:3vh!important;
  right:18px!important;
  height:94vh!important;
  border-radius:18px!important;
  border:1px solid rgba(0,0,0,.06);
  box-shadow:0 24px 60px -12px rgba(0,0,0,.35),0 0 0 1px rgba(0,0,0,.04)!important;
}
@media(max-width:640px){
  .exec-drilldown{top:0!important;bottom:0!important;right:0!important;height:100%!important;border-radius:0!important}
}

.fdm-export-dialog>header{background:#f1f5f9!important;border-bottom:1px solid #e2e8f0!important}
.fdm-export-dialog>header small{color:#64748b!important}
.fdm-export-dialog>header h3{color:#0f172a!important}
.fdm-export-overlay{
  background:rgba(20,22,28,.4)!important;
  backdrop-filter:blur(22px) saturate(1.7)!important;
  -webkit-backdrop-filter:blur(22px) saturate(1.7)!important;
  animation:dmsModalBackdropIn .18s ease-out;
}
.fdm-export-dialog{border-radius:18px!important;animation:dmsModalIn .26s cubic-bezier(.34,1.35,.4,1)}

.fd-copy-dialog>header{background:#f1f5f9!important;border-bottom:1px solid #e2e8f0!important}
.fd-copy-dialog>header span{color:#64748b!important}
.fd-copy-overlay{
  background:rgba(20,22,28,.4)!important;
  backdrop-filter:blur(22px) saturate(1.7)!important;
  -webkit-backdrop-filter:blur(22px) saturate(1.7)!important;
  animation:dmsModalBackdropIn .18s ease-out;
}
.fd-copy-dialog{border-radius:18px!important;animation:dmsModalIn .26s cubic-bezier(.34,1.35,.4,1)}

.repair-drawer-layer .repair-drawer-header{background:#f1f5f9!important;border-bottom:1px solid #e2e8f0!important}
.repair-drawer-layer .repair-drawer{border-radius:18px!important}

.pck-evidence-lightbox-dialog{border-radius:18px!important}
.pck-evidence-lightbox{animation:dmsModalBackdropIn .18s ease-out}
.pck-evidence-lightbox-dialog{animation:dmsModalIn .26s cubic-bezier(.34,1.35,.4,1)}

@media (prefers-reduced-motion: reduce){
  .exec-drilldown-overlay, .exec-drilldown,
  .fdm-export-overlay, .fdm-export-dialog,
  .fd-copy-overlay, .fd-copy-dialog,
  .pck-evidence-lightbox, .pck-evidence-lightbox-dialog{animation:none!important}
}

/* Theme toggle control (lives in the sidebar, which is not inverted). */
.theme-toggle-btn{
  display:flex;
  align-items:center;
  justify-content:center;
  gap:8px;
  width:100%;
  background:#ffffff12;
  border:1px solid #ffffff24;
  color:#fff;
  padding:9px 12px;
  border-radius:8px;
  font:inherit;
  font-size:12px;
  font-weight:700;
  cursor:pointer;
  margin-bottom:8px;
}
.theme-toggle-btn:hover{background:#ffffff20}
