@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@500;600;700&family=Inter:wght@400;500;600&family=IBM+Plex+Mono:wght@400;500&display=swap');

/* =========================================================================
   Design tokens
   Field-service software for electrical/security-systems maintenance —
   technicians reading this outdoors on a phone as often as office staff
   at a desk. Two themes, both calm and technical rather than a bright
   consumer look: three tonal surface layers instead of one flat panel
   color, a restrained teal accent, and shadows tinted toward the
   background instead of a neutral grey card-kit look.

   Theme resolution (see the inline script in index.html's <head>):
   - No stored preference → follows the OS/browser's prefers-color-scheme,
     and keeps following it live if the OS setting changes.
   - Manually toggled once (moon/sun control in the sidebar / mobile top
     bar) → pinned to that choice via data-theme="dark"|"light" on <html>,
     stored in localStorage, and no longer follows the OS.
   Dark is the fallback if the browser supports neither, since it's
   easier on the eyes/battery for outdoor field use.
   ========================================================================= */
:root, :root[data-theme="dark"] {
  /* Surfaces — layered, not flat: bg < panel < panel-alt < panel-2, each a
     step up in elevation. panel-2 is for things that float above panels
     (dropdowns, the date picker) — panel and panel-2 read as distinct
     without a border. */
  --bg: #0b121c;
  --panel: #131e2c;
  --panel-alt: #1a2636;
  --panel-2: #1c2c3f;
  --border: #263750;
  --border-strong: #34495f;

  /* Brand accent — teal reads as "circuitry / verified system", fitting
     for electrical and security-systems maintenance without leaning on
     an alarm-style red or a generic SaaS blue. */
  --accent: #3fb0a6;
  --accent-hover: #4dc0b5;
  --accent-soft: rgba(63,176,166,0.14);
  --accent-ink: #062420;
  --accent-border: rgba(63,176,166,0.3);

  /* Status */
  --amber: #dda44a;
  --amber-soft: rgba(221,164,74,0.14);
  --danger: #d1715f;
  --danger-soft: rgba(209,113,95,0.14);
  --danger-ink: #200a06;
  --danger-border: rgba(209,113,95,0.4);

  /* Text */
  --text: #eaeff5;
  --text-muted: #8fa0b6;
  --text-dim: #5f7189;

  /* Elevation — tinted toward the background color, not neutral grey */
  --shadow-sm: 0 1px 2px rgba(3,7,13,0.5);
  --shadow-md: 0 10px 28px rgba(3,7,13,0.45), 0 2px 6px rgba(3,7,13,0.35);
  --shadow-lg: 0 20px 56px rgba(3,7,13,0.55), 0 4px 12px rgba(3,7,13,0.4);

  /* Fine surface texture — the background grid and the sidebar's top
     sheen. Faint white on this dark theme. */
  --grid-line: rgba(255,255,255,0.022);
  --panel-sheen: rgba(255,255,255,0.015);
  --scrim: rgba(4,7,12,0.7);

  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  /* Only takes effect with no data-theme attribute at all, i.e. no
     manual choice has ever been stored — see the resolution note above.
     A manual choice (data-theme="light" or "dark") is handled by its own
     unconditional block below and always wins regardless of this. */
  :root:not([data-theme]) {
    --bg: #f3f5f8;
    --panel: #ffffff;
    --panel-alt: #edf0f4;
    --panel-2: #ffffff;
    --border: #dbe1e8;
    --border-strong: #c1cad4;

    --accent: #1f8f84;
    --accent-hover: #197a71;
    --accent-soft: rgba(31,143,132,0.12);
    --accent-ink: #ffffff;
    --accent-border: rgba(31,143,132,0.35);

    --amber: #a8701d;
    --amber-soft: rgba(168,112,29,0.12);
    --danger: #b8503d;
    --danger-soft: rgba(184,80,61,0.12);
    --danger-ink: #ffffff;
    --danger-border: rgba(184,80,61,0.4);

    --text: #1a2431;
    --text-muted: #5b6b7f;
    --text-dim: #8896a8;

    --shadow-sm: 0 1px 2px rgba(20,30,45,0.08);
    --shadow-md: 0 10px 28px rgba(20,30,45,0.10), 0 2px 6px rgba(20,30,45,0.06);
    --shadow-lg: 0 20px 56px rgba(20,30,45,0.14), 0 4px 12px rgba(20,30,45,0.08);

    --grid-line: rgba(20,30,45,0.035);
    --panel-sheen: rgba(20,30,45,0.02);
    --scrim: rgba(15,20,28,0.55);

    color-scheme: light;
  }
}
:root[data-theme="light"] {
  /* Explicit override — identical values to the media-query block above,
     duplicated so a manual "light" choice applies even when the OS itself
     is set to dark. */
  --bg: #f3f5f8;
  --panel: #ffffff;
  --panel-alt: #edf0f4;
  --panel-2: #ffffff;
  --border: #dbe1e8;
  --border-strong: #c1cad4;

  --accent: #1f8f84;
  --accent-hover: #197a71;
  --accent-soft: rgba(31,143,132,0.12);
  --accent-ink: #ffffff;
  --accent-border: rgba(31,143,132,0.35);

  --amber: #a8701d;
  --amber-soft: rgba(168,112,29,0.12);
  --danger: #b8503d;
  --danger-soft: rgba(184,80,61,0.12);
  --danger-ink: #ffffff;
  --danger-border: rgba(184,80,61,0.4);

  --text: #1a2431;
  --text-muted: #5b6b7f;
  --text-dim: #8896a8;

  --shadow-sm: 0 1px 2px rgba(20,30,45,0.08);
  --shadow-md: 0 10px 28px rgba(20,30,45,0.10), 0 2px 6px rgba(20,30,45,0.06);
  --shadow-lg: 0 20px 56px rgba(20,30,45,0.14), 0 4px 12px rgba(20,30,45,0.08);

  --grid-line: rgba(20,30,45,0.035);
  --panel-sheen: rgba(20,30,45,0.02);
  --scrim: rgba(15,20,28,0.55);

  color-scheme: light;
}
:root {
  /* Radius — a deliberate small scale, not one value reused everywhere */
  --r-sm: 4px;
  --r-md: 8px;
  --r-lg: 16px;

  /* Motion — one easing curve, one short duration, used only where a state
     genuinely changes (hover, focus, open/close) — never as decoration */
  --ease: cubic-bezier(0.2, 0.7, 0.3, 1);
  --dur: 140ms;

  --focus-ring: 0 0 0 3px var(--accent-soft), 0 0 0 1px var(--accent);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
/* Theme-switch polish: surfaces/text fade instead of flashing when the
   toggle is used or the OS setting changes underneath the app. */
*, *::before, *::after {
  transition: background-color var(--dur) var(--ease), border-color var(--dur) var(--ease), color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
html, body { height: 100%; }
body {
  margin: 0;
  font-family: 'Inter', sans-serif;
  color: var(--text);
  background:
    linear-gradient(var(--bg), var(--bg)),
    repeating-linear-gradient(0deg, var(--grid-line) 0px, var(--grid-line) 1px, transparent 1px, transparent 32px),
    repeating-linear-gradient(90deg, var(--grid-line) 0px, var(--grid-line) 1px, transparent 1px, transparent 32px);
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.5;
  overscroll-behavior-y: contain;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { font-family: 'Space Grotesk', sans-serif; margin: 0; letter-spacing: -0.012em; font-weight: 600; }
h1 { font-size: 22px; }
.mono { font-family: 'IBM Plex Mono', monospace; }
button { font-family: 'Inter', sans-serif; cursor: pointer; touch-action: manipulation; }
a, .navitem, .list-row, .alertrow, .list-row, .btn, .iconbtn, .logout-link { touch-action: manipulation; }
a { color: var(--accent); }

/* Visible keyboard focus everywhere — the one accessibility rule that
   covers the most ground for the least code. :focus-visible (not :focus)
   so a mouse click doesn't leave a ring behind, only real keyboard/AT
   navigation does. */
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible,
textarea:focus-visible, [tabindex]:focus-visible, [role="button"]:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-radius: var(--r-sm);
}
.skip-link {
  position: absolute; left: 8px; top: -60px; z-index: 100;
  background: var(--accent); color: var(--accent-ink); font-weight: 600;
  padding: 10px 14px; border-radius: var(--r-sm); font-size: 13px;
  transition: top var(--dur) var(--ease);
}
.skip-link:focus { top: 8px; }

@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; }
}

/* ---------- Login ---------- */
#login-screen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.login-box {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--r-lg);
  padding: 36px 32px; width: 360px; max-width: 100%;
  box-shadow: var(--shadow-lg);
  animation: rise-in 360ms var(--ease) both;
}
.login-brand { margin-bottom: 24px; }
.login-brand-title { font-family: 'Space Grotesk', sans-serif; font-size: 19px; font-weight: 600; letter-spacing: -0.01em; }
.login-brand-sub { color: var(--text-dim); font-size: 11px; margin-top: 4px; font-family: 'IBM Plex Mono', monospace; letter-spacing: 0.06em; }
.login-error { color: var(--danger); font-size: 12.5px; margin-top: 10px; min-height: 16px; }

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

/* ---------- App shell ---------- */
#app-screen { display: none; min-height: 100vh; }
#app-screen.visible { display: flex; animation: app-reveal 300ms var(--ease) both; }
/* One deliberate entrance moment — the app appearing after login — not a
   transition repeated on every navigation click afterward, which would
   slow down a tool people open dozens of times a day. */
@keyframes app-reveal {
  from { opacity: 0; }
  to { opacity: 1; }
}

.mobile-topbar { display: none; }

.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-scroll table { min-width: 480px; }

.sidebar {
  width: 216px; flex-shrink: 0; border-right: 1px solid var(--border);
  padding: 22px 14px; display: flex; flex-direction: column; gap: 22px;
  background: linear-gradient(180deg, var(--panel-sheen), transparent 120px);
}
.brand { padding: 0 8px; }
.brand-title { font-family: 'Space Grotesk', sans-serif; font-size: 16px; font-weight: 600; letter-spacing: -0.01em; }
.brand-sub { color: var(--text-dim); font-size: 11px; margin-top: 3px; font-family: 'IBM Plex Mono', monospace; letter-spacing: 0.06em; }
.navlist { display: flex; flex-direction: column; gap: 2px; }
.navitem {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: var(--r-sm);
  cursor: pointer; color: var(--text-muted); border: 1px solid transparent;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.navitem:hover { background: var(--panel-alt); color: var(--text); }
.navitem.active { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-border); font-weight: 500; }
.navitem svg { flex-shrink: 0; }
.nav-alert-dot {
  margin-left: auto; background: var(--danger); color: var(--danger-ink); font-size: 10px; font-weight: 600;
  min-width: 17px; height: 17px; border-radius: 9px; display: flex; align-items: center; justify-content: center;
  font-family: 'IBM Plex Mono', monospace;
}
.sidebar-footer { margin-top: auto; border-top: 1px solid var(--border); padding-top: 14px; }
.session-user { font-size: 12.5px; font-weight: 500; }
.session-role { color: var(--text-dim); font-size: 11px; font-family: 'IBM Plex Mono', monospace; text-transform: uppercase; letter-spacing: 0.05em; }
.logout-link { color: var(--text-dim); font-size: 12px; cursor: pointer; margin-top: 8px; margin-right: 12px; display: inline-block; transition: color var(--dur) var(--ease); }
.logout-link:hover { color: var(--text); }
.theme-toggle {
  background: transparent; border: none; padding: 0; margin-top: 10px; cursor: pointer;
  display: flex; align-items: center; gap: 7px; color: var(--text-dim); font-size: 12px;
  font-family: inherit; transition: color var(--dur) var(--ease);
}
.theme-toggle:hover { color: var(--text); }
.theme-toggle svg { flex-shrink: 0; }
.theme-toggle-mobile {
  background: transparent; border: none; padding: 2px; cursor: pointer; color: var(--text-dim);
  display: flex; align-items: center; transition: color var(--dur) var(--ease);
}
.theme-toggle-mobile:hover { color: var(--text); }

.main { flex: 1; padding: 28px 34px 60px; overflow-x: hidden; max-width: 1180px; }
.topbar { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 24px; flex-wrap: wrap; gap: 10px; }
.topbar .date { color: var(--text-dim); font-family: 'IBM Plex Mono', monospace; font-size: 12px; }

.statgrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 24px; }
.stat {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--r-md); padding: 16px;
  box-shadow: var(--shadow-sm);
}
.stat-label { color: var(--text-dim); font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; }
.stat-value { font-family: 'Space Grotesk', sans-serif; font-size: 30px; font-weight: 600; margin-top: 6px; letter-spacing: -0.015em; }
.stat.warn .stat-value { color: var(--amber); }
.stat.bad .stat-value { color: var(--danger); }

.section {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--r-md); padding: 18px 20px; margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
}
.section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; flex-wrap: wrap; gap: 8px; }
.section-head h2 { font-size: 13.5px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }

.alertrow {
  display: grid; grid-template-columns: 20px 1.4fr 1fr 110px 90px; gap: 12px; align-items: center;
  padding: 11px 6px; border-bottom: 1px solid var(--border); cursor: pointer; border-radius: var(--r-sm);
  transition: background var(--dur) var(--ease);
}
.alertrow:last-child { border-bottom: none; }
.alertrow:hover { background: var(--panel-alt); }
.alertrow .due { color: var(--text-dim); font-family: 'IBM Plex Mono', monospace; font-size: 12px; }
.alertrow .cust { font-weight: 500; }
.sys-with-icon { color: var(--text-muted); display: flex; align-items: center; gap: 6px; }

.badge { font-family: 'IBM Plex Mono', monospace; font-size: 11px; padding: 3px 8px; border-radius: var(--r-sm); white-space: nowrap; display: inline-block; font-weight: 500; }
.badge-overdue { background: var(--danger-soft); color: var(--danger); }
.badge-due-soon { background: var(--amber-soft); color: var(--amber); }
.badge-ok { background: var(--accent-soft); color: var(--accent); }
.badge-ended { background: var(--panel-alt); color: var(--text-dim); border: 1px solid var(--border); }

.empty { color: var(--text-dim); padding: 32px 0; text-align: center; font-size: 13px; }

.btn {
  font-size: 13px; font-weight: 500; background: var(--accent); color: var(--accent-ink); border: none;
  border-radius: var(--r-sm); padding: 9px 14px; display: inline-flex; align-items: center; gap: 6px;
  transition: background var(--dur) var(--ease), filter var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.btn:hover { background: var(--accent-hover); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn.secondary { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn.secondary:hover { color: var(--text); border-color: var(--border-strong); background: var(--panel-alt); }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid var(--danger-border); }
.btn.danger:hover { background: var(--danger-soft); }
.btn.ghost { background: transparent; color: var(--accent); padding: 6px 8px; }
.btn.ghost:hover { background: var(--accent-soft); }
.iconbtn { background: transparent; border: none; color: var(--text-dim); padding: 4px; border-radius: var(--r-sm); transition: color var(--dur) var(--ease), background var(--dur) var(--ease); }
.iconbtn:hover { color: var(--text); background: var(--panel-alt); }

.searchbar { display: flex; align-items: center; gap: 8px; background: var(--panel-alt); border: 1px solid var(--border); border-radius: var(--r-sm); padding: 7px 10px; width: 220px; transition: border-color var(--dur) var(--ease); }
.searchbar:focus-within { border-color: var(--accent); }
.searchbar input { background: transparent; border: none; outline: none; color: var(--text); font-size: 13px; width: 100%; }

.list-row { display: flex; align-items: center; justify-content: space-between; padding: 13px 6px; border-bottom: 1px solid var(--border); cursor: pointer; border-radius: var(--r-sm); transition: background var(--dur) var(--ease); }
.list-row:hover { background: var(--panel-alt); }
.list-row:last-child { border-bottom: none; }
.list-row .name { font-weight: 500; }
.list-row .meta { color: var(--text-dim); font-size: 12px; margin-top: 2px; }

.field { margin-bottom: 12px; }
.field label { display: block; font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 5px; }
.field input, .field select, .field textarea {
  width: 100%; background: var(--panel-alt); border: 1px solid var(--border); border-radius: var(--r-sm);
  padding: 8px 10px; color: var(--text); font-family: 'Inter', sans-serif; font-size: 13px; outline: none;
  transition: border-color var(--dur) var(--ease);
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); }
.field input:disabled, .field select:disabled { color: var(--text-dim); cursor: not-allowed; opacity: 0.75; }
.fieldrow { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

table.systable { width: 100%; border-collapse: collapse; }
table.systable th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-dim); font-weight: 500; padding: 6px 8px; border-bottom: 1px solid var(--border); }
table.systable td { padding: 10px 8px; border-bottom: 1px solid var(--border); font-size: 13px; }
table.systable tr:last-child td { border-bottom: none; }
.sysname { display: flex; align-items: center; gap: 8px; }

.back { display: flex; align-items: center; gap: 6px; color: var(--text-muted); cursor: pointer; font-size: 13px; margin-bottom: 16px; transition: color var(--dur) var(--ease); }
.back:hover { color: var(--text); }

.bar-chart { display: flex; align-items: flex-end; gap: 6px; height: 180px; padding-top: 10px; }
.bar-chart .bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; }
.bar-chart .bar { width: 100%; max-width: 26px; background: var(--accent); border-radius: 2px 2px 0 0; min-height: 2px; transition: opacity var(--dur) var(--ease); }
.bar-chart .bar.over { background: var(--danger); }
.bar-chart .bar-label { color: var(--text-dim); font-size: 10px; margin-top: 6px; font-family: 'IBM Plex Mono', monospace; white-space: nowrap; }
.bar-chart .bar-count { color: var(--text-dim); font-size: 10px; margin-bottom: 4px; font-family: 'IBM Plex Mono', monospace; }

/* ---------- Searchable customer combo (Log a visit / Reports) ---------- */
.combo { position: relative; }
.combo-input-wrap {
  display: flex; align-items: center; gap: 8px; background: var(--panel-alt);
  border: 1px solid var(--border); border-radius: var(--r-sm); padding: 8px 10px;
  transition: border-color var(--dur) var(--ease);
}
.combo-input-wrap:focus-within { border-color: var(--accent); }
.combo-input { flex: 1; background: transparent; border: none; outline: none; color: var(--text); font-family: 'Inter', sans-serif; font-size: 13px; }
.combo-list {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 30;
  background: var(--panel-2); border: 1px solid var(--border-strong); border-radius: var(--r-md);
  max-height: 240px; overflow-y: auto; box-shadow: var(--shadow-md);
}
.combo-item { padding: 9px 12px; font-size: 13px; cursor: pointer; transition: background var(--dur) var(--ease); }
.combo-item:hover { background: var(--panel-alt); }
.combo-item.selected { color: var(--accent); }
.combo-empty { padding: 12px; color: var(--text-dim); font-size: 12.5px; }

/* ---------- Donut chart ---------- */
.donut-wrap { display: flex; align-items: center; gap: 28px; flex-wrap: wrap; }
.donut-svg svg { display: block; }
.donut-legend { display: flex; flex-direction: column; gap: 8px; flex: 1; min-width: 160px; }
.legend-row { display: flex; align-items: center; gap: 8px; font-size: 12.5px; }
.legend-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.legend-label { color: var(--text-muted); flex: 1; }
.legend-value { color: var(--text); }

/* ---------- Horizontal bar chart (technician workload, cities) ---------- */
.hbar-chart { display: flex; flex-direction: column; gap: 10px; }
.hbar-row { display: grid; grid-template-columns: 120px 1fr 34px; gap: 10px; align-items: center; }
.hbar-label { font-size: 12.5px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hbar-track { background: var(--panel-alt); border-radius: 2px; height: 10px; overflow: hidden; }
.hbar-fill { height: 100%; background: var(--accent); border-radius: 2px; }
.hbar-value { font-size: 11.5px; color: var(--text-dim); text-align: right; }

/* ---------- Year-over-year comparison chart (two bars per row) ---------- */
.compare-legend { display: flex; gap: 18px; margin-bottom: 12px; }
.compare-chart { display: flex; flex-direction: column; gap: 12px; }
.compare-row { display: grid; grid-template-columns: 120px 1fr 60px; gap: 10px; align-items: center; }
.compare-label { font-size: 12.5px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.compare-bars { display: flex; flex-direction: column; gap: 3px; }
.compare-track { background: var(--panel-alt); border-radius: 2px; height: 7px; overflow: hidden; }
.compare-fill { height: 100%; border-radius: 2px; }
.compare-fill-current { background: var(--accent); }
.compare-fill-previous { background: var(--text-dim); }
.compare-values { font-size: 11px; color: var(--text); text-align: right; }

/* ---------- Reports tab bar (Overview / By customer) ---------- */
.tabbar { display: flex; gap: 4px; margin-bottom: 18px; border-bottom: 1px solid var(--border); }
.tab { padding: 9px 4px; margin-right: 18px; font-size: 13px; color: var(--text-dim); cursor: pointer; border-bottom: 2px solid transparent; transition: color var(--dur) var(--ease), border-color var(--dur) var(--ease); }
.tab:hover { color: var(--text-muted); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 500; }

.clickable-row { cursor: pointer; }
.clickable-row:hover { background: var(--panel-alt); }

/* ---------- Filter bar (Reports > Overview > Maintenance schedule) ---------- */
.filterbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.filter-input {
  background: var(--panel-alt); border: 1px solid var(--border); border-radius: var(--r-sm);
  padding: 8px 10px; color: var(--text); font-family: 'Inter', sans-serif; font-size: 13px;
  width: 180px; max-width: 100%; transition: border-color var(--dur) var(--ease);
}
.filter-input:focus { outline: none; border-color: var(--accent); }
/* The customer-name combo box wasn't originally built for this flex row
   (it's normally full-width inside a block-level .field) — give it the
   same width as its .filter-input siblings so it doesn't render oddly
   narrow next to them. */
.filterbar .combo { width: 180px; max-width: 100%; }
.filterbar .combo-input-wrap { padding: 7px 8px; }
.filterbar .combo-input { font-size: 13px; }
.filter-date-group { display: flex; align-items: center; gap: 6px; }
.filter-date {
  background: var(--panel-alt); border: 1px solid var(--border); border-radius: var(--r-sm);
  padding: 7px 8px; color: var(--text); font-family: 'IBM Plex Mono', monospace; font-size: 12.5px;
}
.filter-date-sep { color: var(--text-dim); font-size: 12px; }

/* ---------- Custom date picker (replaces native <input type="date">) ---------- */
.datepicker { position: relative; }
.datepicker-display {
  width: 100%; display: flex; align-items: center; gap: 7px;
  background: var(--panel-alt); border: 1px solid var(--border); border-radius: var(--r-sm);
  padding: 8px 10px; color: var(--text); font-family: 'IBM Plex Mono', monospace; font-size: 12.5px;
  cursor: pointer; text-align: left; transition: border-color var(--dur) var(--ease);
}
.datepicker-display:hover { border-color: var(--border-strong); }
.datepicker-display:disabled { color: var(--text-dim); cursor: not-allowed; opacity: 0.75; }
.datepicker-display.datepicker-placeholder { color: var(--text-dim); }
/* Compact variant for filter bars — sits next to .filter-input/.filter-date siblings */
.filter-date-group .datepicker-display { padding: 7px 8px; font-size: 12.5px; width: auto; min-width: 122px; }

.dp-panel {
  /* top/left are set inline by JS (renderDatePickerPanel), positioned
     against the trigger button's actual on-screen location — fixed, not
     absolute, so it's anchored to the viewport rather than any scrolling
     ancestor (the modals these fields live in scroll internally). */
  position: fixed; z-index: 60;
  background: var(--panel-2); border: 1px solid var(--border-strong); border-radius: var(--r-md);
  padding: 10px; width: 250px; box-shadow: var(--shadow-lg);
  animation: dp-in 120ms var(--ease) both;
}
@keyframes dp-in {
  from { opacity: 0; transform: translateY(-4px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.dp-header { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; }
.dp-nav {
  background: var(--panel-alt); border: 1px solid var(--border); border-radius: var(--r-sm);
  padding: 4px 7px; cursor: pointer; color: var(--text); display: flex; align-items: center;
  transition: border-color var(--dur) var(--ease);
}
.dp-nav:hover { border-color: var(--accent); }
.dp-month-label { font-size: 12.5px; font-weight: 500; flex: 1; text-align: center; }
.dp-year-select {
  background: var(--panel-alt); border: 1px solid var(--border); border-radius: var(--r-sm);
  padding: 4px 5px; font-family: 'IBM Plex Mono', monospace; font-size: 11.5px; color: var(--text);
}
.dp-weekdays { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; margin-bottom: 4px; }
.dp-wd { text-align: center; font-size: 9.5px; color: var(--text-dim); text-transform: uppercase; }
.dp-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.dp-cell { text-align: center; padding: 6px 0; font-size: 12px; border-radius: var(--r-sm); cursor: pointer; transition: background var(--dur) var(--ease); }
.dp-cell:hover { background: var(--panel-alt); }
.dp-cell.dp-empty { cursor: default; }
.dp-cell.dp-empty:hover { background: transparent; }
.dp-cell.dp-selected { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.dp-cell.dp-today:not(.dp-selected) { border: 1px solid var(--accent); }
.dp-footer { margin-top: 8px; display: flex; justify-content: space-between; }
.dp-footer .logout-link { margin: 0; }

.location-inline { display: inline-flex; align-items: center; gap: 3px; }
.location-inline svg { position: relative; top: 1px; }

.roleselect {
  background: var(--panel-alt); border: 1px solid var(--border); border-radius: var(--r-sm);
  padding: 4px 6px; color: var(--text); font-family: 'IBM Plex Mono', monospace; font-size: 11.5px;
}

/* ---------- Per-user permission checklist (Edit user modal) ---------- */
.permlist {
  background: var(--panel-alt); border: 1px solid var(--border); border-radius: var(--r-md);
  padding: 10px 12px; display: flex; flex-direction: column; gap: 9px;
}
.permlist-row { display: flex; align-items: center; gap: 9px; font-size: 12.5px; color: var(--text-muted); cursor: pointer; }
.permlist-row input[type="checkbox"] { flex-shrink: 0; width: 15px; height: 15px; accent-color: var(--accent); cursor: pointer; }

.modal-overlay {
  position: fixed; inset: 0; background: var(--scrim); display: flex; align-items: center; justify-content: center; z-index: 50;
  animation: overlay-in 160ms var(--ease) both;
}
@keyframes overlay-in { from { opacity: 0; } to { opacity: 1; } }
.modal-box {
  background: var(--panel-2); border: 1px solid var(--border-strong); border-radius: var(--r-lg);
  padding: 20px 22px; width: 420px; max-width: 90vw; max-height: 85vh; overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: modal-in 180ms var(--ease) both;
}
@keyframes modal-in {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.modal-head h3 { font-size: 15.5px; }

.banner-error { color: var(--danger); font-size: 12.5px; margin-bottom: 12px; }

/* =====================================================================
   Mobile — makes the app behave like a native phone app: a fixed top
   bar, a bottom tab bar instead of a side rail, full-width bottom-sheet
   modals, larger tap targets, and no accidental iOS zoom on inputs.
   ===================================================================== */
@media (max-width: 860px) {

  /* Top bar: brand + current user + logout, replaces the sidebar's brand/footer */
  .mobile-topbar {
    display: flex; align-items: center; justify-content: space-between;
    position: fixed; top: 0; left: 0; right: 0; z-index: 45;
    height: 52px; padding: 0 16px; padding-top: env(safe-area-inset-top);
    background: var(--panel); border-bottom: 1px solid var(--border);
  }
  .mobile-topbar-brand { font-family: 'Space Grotesk', sans-serif; font-weight: 600; font-size: 15px; }
  .mobile-topbar-user { display: flex; align-items: center; gap: 12px; font-size: 12px; color: var(--text-dim); }
  .mobile-topbar-user .logout-link { margin-top: 0; }

  /* Sidebar becomes a fixed bottom tab bar; its brand/footer are replaced by the top bar above */
  .sidebar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 45;
    width: 100%; height: auto; flex-direction: row;
    border-right: none; border-top: 1px solid var(--border);
    padding: 4px 4px calc(4px + env(safe-area-inset-bottom));
    gap: 0; background: var(--panel);
  }
  .sidebar .brand, .sidebar .sidebar-footer { display: none; }
  .navlist { flex-direction: row; width: 100%; gap: 2px; }
  .navitem {
    flex: 1; flex-direction: column; gap: 3px; padding: 7px 2px 6px;
    border-radius: var(--r-md); font-size: 10px; text-align: center;
    min-height: 44px; justify-content: center;
  }
  .navitem span { white-space: nowrap; }
  .navitem svg { width: 19px; height: 19px; }
  .nav-alert-dot { position: absolute; margin-left: 0; top: 2px; right: 18%; }
  .navitem { position: relative; }

  /* Main content: clear the fixed top/bottom bars, tighter side padding */
  .main {
    padding: calc(52px + env(safe-area-inset-top) + 18px) 16px calc(64px + env(safe-area-inset-bottom) + 20px);
    max-width: 100%;
  }
  .topbar h1 { font-size: 20px; }

  .statgrid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .stat { padding: 12px; }
  .stat-value { font-size: 22px; }

  .section { padding: 14px; }

  .fieldrow { grid-template-columns: 1fr; gap: 0; }
  /* 16px prevents iOS Safari from auto-zooming the page on focus */
  .field input, .field select, .field textarea { font-size: 16px; padding: 10px 12px; }
  .field { margin-bottom: 14px; }

  .searchbar { width: 100%; }

  /* Alerts: drop the redundant date column and let the row wrap instead of clipping */
  .alertrow {
    display: flex; flex-wrap: wrap; align-items: center; gap: 5px 10px;
    padding: 12px 6px;
  }
  .alertrow .due { display: none; }
  .alertrow .cust { flex: 1 1 100%; order: 1; }
  .alertrow .sys-with-icon { order: 2; font-size: 12px; }
  .alertrow .badge { order: 3; margin-left: auto; }

  /* Buttons: comfortable tap targets */
  .btn, .btn.secondary, .btn.danger { min-height: 44px; }
  .btn.ghost { min-height: 36px; }
  .iconbtn { min-width: 40px; min-height: 40px; display: inline-flex; align-items: center; justify-content: center; }

  /* Bar charts: scroll horizontally instead of squeezing bars unreadably thin */
  .bar-chart { overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 4px; }
  .bar-chart .bar-col { min-width: 32px; }

  /* Modals become a full-width bottom sheet */
  .modal-overlay { align-items: flex-end; }
  .modal-box {
    width: 100%; max-width: 100%; max-height: 88vh;
    border-radius: 18px 18px 0 0;
    padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
    animation: sheet-in 220ms var(--ease) both;
  }
  @keyframes sheet-in {
    from { opacity: 0; transform: translateY(24px); }
    to { opacity: 1; transform: translateY(0); }
  }

  .list-row { padding: 14px 6px; min-height: 44px; }

  /* Donut + horizontal-bar charts: stack instead of squeezing side by side */
  .donut-wrap { flex-direction: column; align-items: flex-start; gap: 16px; }
  .hbar-row { grid-template-columns: 90px 1fr 30px; gap: 8px; }
  .compare-row { grid-template-columns: 90px 1fr 50px; gap: 8px; }
  .compare-legend { flex-wrap: wrap; gap: 10px 18px; }
  .tabbar { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .tab { padding: 10px 4px; }
  .filterbar { flex-direction: column; align-items: stretch; }
  .filter-input { width: 100%; font-size: 16px; padding: 10px 12px; }
  .filterbar .combo { width: 100%; }
  .filterbar .combo-input-wrap { padding: 10px 12px; }
  .filterbar .combo-input { font-size: 16px; }
  .filter-date-group { width: 100%; }
  .filter-date { flex: 1; font-size: 16px; padding: 9px 8px; }
  .filter-date-group .datepicker-display { flex: 1; width: auto; font-size: 15px; padding: 9px 8px; }
  .dp-panel { width: min(280px, calc(100vw - 40px)); }
  .dp-cell { padding: 9px 0; font-size: 13px; }
}
