/* =====================================================================
   Breakdown Hub — styles
   1. Tokens  2. Base  3. Login  4. Shell (sidebar/topbar)  5. Components
   6. Dashboard  7. Records  8. Other pages  9. Modal/toast  10. Mobile
   ===================================================================== */

/* ---------- 1. Tokens ---------- */
:root {
  --navy:        #0E2A47;   /* sidebar, headings, primary buttons */
  --navy-2:      #17395D;   /* sidebar hover */
  --blue:        #1F5F99;   /* links, focus, active states */
  --blue-soft:   #9CC4E8;   /* accents on navy */
  --mist:        #EAF2F9;   /* page background */
  --mist-2:      #F5F9FC;   /* table stripes, inputs */
  --line:        #D3E0EC;   /* borders */
  --white:       #FFFFFF;
  --ink:         #14202E;   /* body text */
  --muted:       #586A7D;   /* secondary text */
  --amber:       #E3A21A;   /* "still down" — yard safety yellow */
  --amber-ink:   #6B4A00;
  --amber-bg:    #FFF3D6;
  --red:         #B3261E;
  --red-bg:      #FCE9E7;
  --green:       #1E7B4F;
  --green-bg:    #E3F4EA;

  --font: "Barlow", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-display: "Barlow Condensed", "Barlow", system-ui, sans-serif;

  /* type scale (1.2 ratio) */
  --fs-xs: .8125rem;
  --fs-sm: .875rem;
  --fs-md: 1rem;
  --fs-lg: 1.2rem;
  --fs-xl: 1.44rem;
  --fs-2xl: 1.875rem;
  --fs-3xl: 2.5rem;

  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;

  --sidebar-w: 248px;
  --sidebar-w-collapsed: 72px;
  --topbar-h: 60px;
  --focus: 0 0 0 3px rgba(31, 95, 153, .35);
}

/* ---------- 2. Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: var(--fs-md);
  line-height: 1.5;
  color: var(--ink);
  background: var(--mist);
}
h1, h2, h3 { font-family: var(--font-display); color: var(--navy); line-height: 1.15; margin: 0; letter-spacing: .01em; }
p { margin: 0; }
a { color: var(--blue); }
button, input, select, textarea { font: inherit; color: inherit; }
img, svg { display: block; }
code { font-size: .9em; background: var(--mist); padding: 1px 5px; border-radius: 4px; }
[hidden] { display: none !important; }

.icon { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

:focus-visible { outline: none; box-shadow: var(--focus); }

.skip-link {
  position: absolute; left: 8px; top: -60px; z-index: 100;
  background: var(--navy); color: var(--white); padding: 10px 14px; border-radius: var(--r-sm);
}
.skip-link:focus { top: 8px; }

.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0s !important; animation-duration: 0s !important; }
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px;
  border: 1px solid transparent; border-radius: var(--r-sm);
  font-weight: 600; font-size: var(--fs-sm); text-decoration: none;
  cursor: pointer; transition: background .15s, border-color .15s, color .15s;
  white-space: nowrap;
}
.btn .icon { width: 18px; height: 18px; }
.btn-primary { background: var(--navy); color: var(--white); }
.btn-primary:hover { background: var(--blue); }
.btn-secondary { background: var(--white); color: var(--navy); border-color: var(--line); }
.btn-secondary:hover { border-color: var(--blue); color: var(--blue); }
.btn-danger { background: var(--red); color: var(--white); }
.btn-danger:hover { background: #8f1d17; }
.btn-ghost { background: transparent; color: var(--blue); padding: 0 10px; }
.btn-ghost:hover { background: var(--mist); }
.btn-block { width: 100%; }
.btn:disabled { opacity: .6; cursor: not-allowed; }
.btn-sm { min-height: 36px; padding: 0 12px; }

.btn .spinner { display: none; }
.btn.is-loading .spinner { display: inline-block; }
.btn.is-loading .btn-label { opacity: .7; }
.spinner {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.4); border-top-color: var(--white);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.icon-btn {
  display: inline-grid; place-items: center;
  width: 44px; height: 44px; padding: 0;
  background: transparent; border: 0; border-radius: var(--r-sm);
  color: inherit; cursor: pointer;
}
.icon-btn:hover { background: rgba(14, 42, 71, .07); }

/* ---------- Form fields ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field label, .field .label { font-weight: 600; font-size: var(--fs-sm); color: var(--navy); }
.field .hint { font-size: var(--fs-xs); color: var(--muted); }
.req { color: var(--red); }
input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="search"], input[type="date"], input[type="datetime-local"], select, textarea {
  width: 100%; min-height: 44px; padding: 10px 12px;
  background: var(--white); border: 1px solid var(--line); border-radius: var(--r-sm);
  font-size: 16px; /* 16px stops iPhone from zooming in */
  transition: border-color .15s, box-shadow .15s;
}
textarea { min-height: 96px; resize: vertical; line-height: 1.45; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--blue); box-shadow: var(--focus); }
input[aria-invalid="true"], select[aria-invalid="true"], textarea[aria-invalid="true"] { border-color: var(--red); }
.field-error { color: var(--red); font-size: var(--fs-xs); min-height: 0; }
.field-error:empty { display: none; }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: var(--fs-sm); cursor: pointer; min-height: 32px; }
.check input { width: 18px; height: 18px; accent-color: var(--navy); }

.form-alert {
  background: var(--red-bg); color: var(--red); border-left: 4px solid var(--red);
  padding: 10px 12px; border-radius: var(--r-sm); margin-bottom: 16px; font-size: var(--fs-sm);
}

/* ---------- 3. Login ---------- */
.login-body { background: var(--white); }
.login { min-height: 100vh; min-height: 100dvh; display: grid; grid-template-columns: minmax(320px, 5fr) 6fr; }
.login-brand {
  position: relative; overflow: hidden;
  background: var(--navy); color: var(--white);
  display: flex; flex-direction: column; justify-content: center;
  padding: 56px;
}
.login-brand-inner { position: relative; z-index: 1; max-width: 26rem; }
.login-mark { width: 56px; height: 56px; margin-bottom: 28px; box-shadow: 0 0 0 1px rgba(156,196,232,.35); border-radius: 12px; }
.login-wordmark { font-family: var(--font-display); font-weight: 700; font-size: 3.4rem; line-height: 1; letter-spacing: .005em; }
.login-tagline { margin-top: 16px; font-size: var(--fs-lg); color: var(--blue-soft); max-width: 22rem; }
.login-yard { position: absolute; left: 0; right: 0; bottom: 0; width: 100%; height: auto; color: rgba(156,196,232,.28); }

.login-panel { display: grid; place-items: center; padding: 40px 24px; }
.login-form { width: 100%; max-width: 380px; }
.login-mark-small { display: none; margin-bottom: 20px; }
.login-form h1 { font-size: var(--fs-3xl); margin-bottom: 6px; }
.login-sub { color: var(--muted); margin-bottom: 28px; }
.password-wrap { position: relative; }
.password-wrap input { padding-right: 76px; }
.password-toggle {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  min-height: 36px; padding: 0 12px; border: 0; border-radius: var(--r-sm);
  background: transparent; color: var(--blue); font-weight: 600; font-size: var(--fs-sm); cursor: pointer;
}
.password-toggle:hover { background: var(--mist); }
.login-form .btn-primary { margin-top: 8px; min-height: 48px; font-size: var(--fs-md); }
.demo-note {
  margin-top: 24px; padding: 12px 14px; border-radius: var(--r-sm);
  background: var(--mist); color: var(--muted); font-size: var(--fs-sm); line-height: 1.5;
}
.demo-note strong { color: var(--navy); }

/* ---------- 4. Shell ---------- */
body.is-loading-app .shell { visibility: hidden; }
.shell { display: flex; min-height: 100vh; min-height: 100dvh; }

.sidebar {
  position: sticky; top: 0; height: 100vh; height: 100dvh;
  width: var(--sidebar-w); flex: none;
  display: flex; flex-direction: column;
  background: var(--navy); color: #C9DBEC;
  transition: width .2s ease;
  z-index: 40;
}
.sidebar-head { display: flex; align-items: center; justify-content: space-between; height: var(--topbar-h); padding: 0 14px 0 18px; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--white); text-decoration: none; min-width: 0; }
.brand img { border-radius: 7px; box-shadow: 0 0 0 1px rgba(156,196,232,.35); }
.brand-name { font-family: var(--font-display); font-weight: 700; font-size: 1.35rem; white-space: nowrap; }
.sidebar-close { display: none; color: var(--white); }
.sidebar-close:hover { background: var(--navy-2); }

.nav { flex: 1; overflow-y: auto; padding: 8px 10px; display: flex; flex-direction: column; gap: 2px; }
.nav a, .nav-signout, .collapse-btn, .nav-profile {
  display: flex; align-items: center; gap: 12px;
  min-height: 44px; padding: 0 12px;
  border-radius: var(--r-sm); border: 0; background: transparent;
  color: inherit; text-decoration: none; font-weight: 500; font-size: var(--fs-sm);
  cursor: pointer; white-space: nowrap; width: 100%; text-align: left;
}
.nav a:hover, .nav-signout:hover, .collapse-btn:hover, .nav-profile:hover { background: var(--navy-2); color: var(--white); }
.nav a.is-active { background: var(--white); color: var(--navy); font-weight: 600; }
.nav a.is-active .icon { color: var(--blue); }
.nav-group { margin: 18px 12px 6px; font-size: var(--fs-xs); color: #7F9BB8; font-weight: 600; }

.sidebar-foot { padding: 10px; border-top: 1px solid rgba(156,196,232,.18); display: flex; flex-direction: column; gap: 2px; }
.nav-profile { min-height: 52px; }
.avatar {
  display: grid; place-items: center; flex: none;
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--blue-soft); color: var(--navy);
  font-weight: 700; font-size: var(--fs-sm);
}
.profile-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.profile-name { color: var(--white); font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.profile-role { font-size: var(--fs-xs); color: #7F9BB8; }
.nav-profile.is-active { background: var(--navy-2); }
.collapse-btn .icon { transition: transform .2s; }

/* Desktop: collapsed sidebar shows icons only */
.shell.is-collapsed .sidebar { width: var(--sidebar-w-collapsed); }
.shell.is-collapsed .brand-name,
.shell.is-collapsed .nav span,
.shell.is-collapsed .nav-group,
.shell.is-collapsed .profile-text,
.shell.is-collapsed .nav-signout span,
.shell.is-collapsed .collapse-btn span { display: none; }
.shell.is-collapsed .nav a, .shell.is-collapsed .nav-signout,
.shell.is-collapsed .collapse-btn, .shell.is-collapsed .nav-profile { justify-content: center; padding: 0; }
.shell.is-collapsed .sidebar-head { justify-content: center; padding: 0; }
.shell.is-collapsed .collapse-btn .icon { transform: rotate(180deg); }
.shell.is-collapsed .nav-group { display: block; height: 1px; margin: 12px 8px; background: rgba(156,196,232,.18); font-size: 0; }

.main-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 30;
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 8px;
  padding: 0 24px;
  background: var(--white); border-bottom: 1px solid var(--line);
}
.hamburger { display: none; color: var(--navy); margin-left: -8px; }
.page-title { font-size: var(--fs-xl); font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-status { display: flex; align-items: center; gap: 8px; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  height: 30px; padding: 0 10px; border-radius: 999px;
  font-size: var(--fs-xs); font-weight: 600; white-space: nowrap;
}
.chip .icon { width: 16px; height: 16px; }
.chip-online { background: var(--green-bg); color: var(--green); }
.chip-offline { background: var(--amber-bg); color: var(--amber-ink); }
.chip-sync { background: var(--mist); color: var(--navy); }
.chip-sync.has-pending { background: var(--amber-bg); color: var(--amber-ink); }
.chip-short { display: none; }

.demo-banner {
  background: var(--navy-2); color: #DCE9F5;
  font-size: var(--fs-xs); padding: 8px 24px;
}

.view { padding: 28px 24px 56px; max-width: 1240px; width: 100%; margin: 0 auto; }
.view:focus { outline: none; }

.overlay {
  position: fixed; inset: 0; z-index: 35;
  background: rgba(14, 42, 71, .45);
}

/* ---------- 5. Components ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head p { color: var(--muted); margin-top: 4px; max-width: 60ch; }
.page-head h2 { font-size: var(--fs-2xl); }

.panel { background: var(--white); border: 1px solid var(--line); border-radius: var(--r-md); }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px 0; }
.panel-head h3 { font-size: var(--fs-lg); }
.panel-body { padding: 16px 20px 20px; }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 9px; border-radius: 999px;
  font-size: var(--fs-xs); font-weight: 600; white-space: nowrap;
  background: var(--mist); color: var(--navy);
}
.pill-down { background: var(--amber-bg); color: var(--amber-ink); }
.pill-down::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--amber); }
.pill-hours { background: #E6F0FA; color: #1D5FA0; white-space: nowrap; }
.pill-hours::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: #1D5FA0; }
.pill-done { background: var(--green-bg); color: var(--green); }
.pill-pending { background: var(--amber-bg); color: var(--amber-ink); }
.pill-type-Breakdown { background: var(--red-bg); color: var(--red); }
.pill-type-Accident { background: var(--red); color: var(--white); }
.pill-type-Planned { background: #E4ECF8; color: var(--blue); }
.pill-type-Operation { background: #EFE8F7; color: #5B3A8A; }
.pill-type-Others { background: var(--mist); color: var(--muted); }

.crane-tag { font-family: var(--font-display); font-weight: 600; font-size: 1.05rem; color: var(--navy); white-space: nowrap; }

.empty {
  text-align: center; padding: 48px 20px; color: var(--muted);
}
.empty h3 { margin-bottom: 6px; }
.empty .btn { margin-top: 16px; }

.stage-note {
  display: flex; gap: 14px; align-items: flex-start;
  padding: 18px 20px; border-radius: var(--r-md);
  background: var(--white); border: 1px dashed var(--blue-soft);
}
.stage-note .icon { width: 28px; height: 28px; color: var(--blue); margin-top: 2px; }
.stage-note h3 { font-size: var(--fs-lg); margin-bottom: 4px; }
.stage-note p { color: var(--muted); }
.stage-note ul { margin: 10px 0 0; padding-left: 20px; color: var(--ink); }

.segmented { display: inline-flex; background: var(--white); border: 1px solid var(--line); border-radius: var(--r-sm); padding: 3px; gap: 2px; flex-wrap: wrap; }
.segmented button {
  min-height: 36px; padding: 0 14px; border: 0; border-radius: 4px;
  background: transparent; color: var(--muted); font-weight: 600; font-size: var(--fs-sm); cursor: pointer;
}
.segmented button[aria-pressed="true"] { background: var(--navy); color: var(--white); }
.segmented button:not([aria-pressed="true"]):hover { color: var(--navy); background: var(--mist); }
.segmented .count { opacity: .7; font-weight: 500; margin-left: 4px; }

/* ---------- 6. Dashboard ---------- */
.dash-greeting { margin-bottom: 20px; }
.dash-greeting h2 { font-size: var(--fs-2xl); }
.dash-greeting p { color: var(--muted); }

/* stats band: one strip, not separate cards */
.stats {
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 1px;
  background: var(--line); border: 1px solid var(--line); border-radius: var(--r-md);
  margin-bottom: 24px; overflow: hidden;
}
.stat { padding: 16px 20px; background: var(--white); text-decoration: none; color: inherit; display: block; }
a.stat:hover { background: var(--mist-2); }
.stat-value { font-family: var(--font-display); font-size: var(--fs-3xl); font-weight: 600; color: var(--navy); line-height: 1.05; }
.stat-label { font-size: var(--fs-sm); color: var(--muted); }
.stat-down .stat-value { color: var(--amber-ink); }
.stat-down.is-zero .stat-value { color: var(--green); }

/* fleet strip — the signature element */
.fleet { background: var(--navy); color: var(--white); border-radius: var(--r-md); padding: 20px 20px 18px; margin-bottom: 24px; }
.fleet-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.fleet-head h3 { color: var(--white); font-size: var(--fs-xl); }
.fleet-legend { display: flex; gap: 16px; font-size: var(--fs-xs); color: var(--blue-soft); flex-wrap: wrap; }
.fleet-legend span { display: inline-flex; align-items: center; gap: 6px; }
.fleet-legend i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.legend-ok { background: #24496F; }
.legend-busy { background: #24496F; box-shadow: inset 0 -3px 0 var(--blue-soft); }
.legend-down { background: var(--amber); }
.fleet-row { display: grid; grid-template-columns: 44px 1fr; gap: 10px; align-items: start; }
.fleet-row + .fleet-row { margin-top: 12px; }
.fleet-type { font-family: var(--font-display); font-weight: 700; font-size: var(--fs-lg); color: var(--blue-soft); padding-top: 6px; }
.fleet-units { display: flex; flex-wrap: wrap; gap: 5px; }
.unit {
  position: relative;
  width: 40px; height: 40px; border-radius: 5px; border: 0;
  background: #24496F; color: #DCE9F5;
  font-family: var(--font-display); font-weight: 600; font-size: 1.05rem;
  cursor: pointer; overflow: hidden;
  transition: background .15s, transform .15s;
}
.unit:hover { background: #2E5884; transform: translateY(-1px); }
.unit-bar { position: absolute; left: 0; bottom: 0; height: 3px; background: var(--blue-soft); }
.unit.is-down { background: var(--amber); color: var(--navy); font-weight: 700; }
.unit.is-down:hover { background: #F0B53A; }
.unit.is-down .unit-bar { display: none; }
.unit:focus-visible { box-shadow: 0 0 0 3px var(--white); }
.fleet-foot { margin-top: 14px; font-size: var(--fs-xs); color: var(--blue-soft); }

.dash-grid { display: grid; grid-template-columns: 3fr 2fr; gap: 24px; }
.dash-grid > * { min-width: 0; }

.event-list { list-style: none; margin: 0; padding: 0; }
.event-list li { border-top: 1px solid var(--line); }
.event-list li:first-child { border-top: 0; }
.event-item {
  display: grid; grid-template-columns: 72px 1fr auto; gap: 12px; align-items: start;
  width: 100%; padding: 12px 0; border: 0; background: transparent; text-align: left; cursor: pointer;
}
.event-item:hover .event-fault { color: var(--blue); }
.event-fault { font-weight: 500; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical; }
.event-meta { display: block; font-size: var(--fs-xs); color: var(--muted); margin-top: 2px; }

.kpi-list { display: grid; gap: 14px; }
.kpi { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; align-items: baseline; }
.kpi-name { font-weight: 600; color: var(--navy); font-size: var(--fs-sm); }
.kpi-val { font-family: var(--font-display); font-size: var(--fs-xl); font-weight: 600; }
.kpi-target { grid-column: 1 / -1; font-size: var(--fs-xs); color: var(--muted); }
.kpi-meter { grid-column: 1 / -1; height: 6px; background: var(--mist); border-radius: 3px; position: relative; overflow: hidden; }
.kpi-meter span { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 3px; background: var(--green); }
.kpi.is-bad .kpi-meter span { background: var(--red); }
.kpi.is-bad .kpi-val { color: var(--red); }
.kpi.is-good .kpi-val { color: var(--green); }

/* ---------- 7. Records ---------- */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.search { position: relative; flex: 1 1 280px; }
.search .icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search input { padding-left: 40px; }

.filters {
  display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px;
  padding: 16px; margin-bottom: 16px;
  background: var(--white); border: 1px solid var(--line); border-radius: var(--r-md);
}
.filters .field { margin: 0; }
.filters .field label { font-size: var(--fs-xs); }
.filters select, .filters input { min-height: 40px; padding: 8px 10px; }
.period-totals { grid-column: span 4; display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; align-self: end; }
.period-totals[hidden] { display: none; }
.period-totals > div { background: #EEF4FA; border: 1px solid #D5E2EF; border-radius: 10px; padding: 7px 12px; display: flex; flex-direction: column; justify-content: center; min-height: 40px; }
.period-totals span { font-size: var(--fs-xs); color: #5B6B7B; }
.period-totals strong { font-size: 18px; font-variant-numeric: tabular-nums; color: #0F2A47; }
@media (max-width: 760px) { .period-totals { grid-template-columns: 1fr 1fr 1fr; } .period-totals > div { padding: 6px 8px; } .period-totals strong { font-size: 15px; } }
.filters-actions { grid-column: 1 / -1; display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.result-count { font-size: var(--fs-sm); color: var(--muted); }

.table-wrap { background: var(--white); border: 1px solid var(--line); border-radius: var(--r-md); overflow: hidden; }
.table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.table th {
  text-align: left; font-weight: 600; color: var(--navy);
  padding: 12px 14px; background: var(--mist-2); border-bottom: 1px solid var(--line); white-space: nowrap;
}
.table td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr { cursor: pointer; }
.table tbody tr:hover td { background: var(--mist-2); }
.table tr.is-down td:first-child { box-shadow: inset 4px 0 0 var(--amber); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.cell-fault { max-width: 40ch; }
.cell-fault .clamp { display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.cell-sub { font-size: var(--fs-xs); color: var(--muted); }
.row-actions { display: flex; gap: 2px; justify-content: flex-end; }
.row-actions .icon-btn { width: 36px; height: 36px; color: var(--muted); }
.row-actions .icon-btn:hover { color: var(--blue); }
.row-actions .icon-btn.danger:hover { color: var(--red); background: var(--red-bg); }
.row-actions .icon { width: 18px; height: 18px; }

.pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 14px; border-top: 1px solid var(--line); font-size: var(--fs-sm); color: var(--muted); flex-wrap: wrap; }
.pager-btns { display: flex; gap: 8px; }

.is-bad-num { color: var(--red); font-weight: 600; }
.is-good-num { color: var(--green); font-weight: 600; }
.table tfoot td { font-weight: 600; background: var(--mist-2); border-top: 1px solid var(--line); border-bottom: 0; }

/* record details */
.detail-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 14px 20px; margin: 0; }
.detail-grid div { min-width: 0; }
.detail-grid dt { font-size: var(--fs-xs); color: var(--muted); font-weight: 600; }
.detail-grid dd { margin: 2px 0 0; overflow-wrap: anywhere; }
.detail-grid .wide { grid-column: 1 / -1; }
.detail-grid .long { white-space: pre-wrap; background: var(--mist-2); border-radius: var(--r-sm); padding: 10px 12px; }
.detail-source { margin-top: 18px; padding-top: 12px; border-top: 1px solid var(--line); font-size: var(--fs-xs); color: var(--muted); }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 0 16px; }
.form-grid .wide { grid-column: 1 / -1; }

/* ---------- 8. Other pages ---------- */
.perm-grid { display: flex; flex-wrap: wrap; gap: 4px 16px; }
.profile-card { display: flex; gap: 18px; align-items: center; }
.profile-card .avatar { width: 64px; height: 64px; font-size: var(--fs-xl); background: var(--navy); color: var(--white); }
.profile-card h3 { font-size: var(--fs-xl); }
.perm-list { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 8px; }
.perm-list li { display: flex; align-items: center; gap: 8px; font-size: var(--fs-sm); }
.perm-yes::before, .perm-no::before { content: ""; width: 18px; height: 18px; border-radius: 4px; flex: none; }
.perm-yes::before { background: var(--green) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12l5 5 9-10'/%3E%3C/svg%3E") center/14px no-repeat; }
.perm-no { color: var(--muted); }
.perm-no::before { background: var(--mist); border: 1px solid var(--line); }
.stack { display: grid; gap: 20px; }

/* ---------- Weekly performance charts ---------- */
.chart-legend { display: inline-flex; align-items: center; gap: 6px 14px; flex-wrap: wrap; font-size: var(--fs-xs); color: var(--muted); }
.chart-legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: -8px; vertical-align: -1px; }
.chart-legend .lg-ok { background: var(--blue); }
.chart-legend .lg-bad { background: var(--red); }
.chart-legend .lg-target { width: 18px; height: 0; border-top: 2px dashed var(--navy); border-radius: 0; }
.chart-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.chart-card { padding: 16px 18px 14px; min-width: 0; }
.chart-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 10px; }
.chart-head h3 { font-size: var(--fs-lg); }
/* Average | Target boxes, like the FRONT sheet */
.avg-target { display: grid; grid-template-columns: 1fr 1fr; flex: none; border: 1px solid var(--line); border-radius: var(--r-sm); overflow: hidden; }
.avg-target > div { display: flex; flex-direction: column; align-items: center; padding: 6px 14px 8px; min-width: 92px; }
.avg-target > div + div { border-left: 1px solid var(--line); background: var(--mist-2); }
.avg-target-label { font-size: var(--fs-xs); color: var(--muted); font-weight: 600; }
.avg-target-val { font-family: var(--font-display); font-size: var(--fs-2xl); font-weight: 600; line-height: 1.1; color: var(--navy); }
.avg-target-val.is-good-num { color: var(--green); }
.avg-target-val.is-bad-num { color: var(--red); }
.chart-box { position: relative; }
.bar-chart { width: 100%; height: auto; overflow: visible; }
.bar-chart .grid { stroke: var(--line); stroke-width: 1; }
.bar-chart .baseline { stroke: #9FB3C6; stroke-width: 1; }
.bar-chart .target { stroke: var(--navy); stroke-width: 2; stroke-dasharray: 6 4; }
.bar-chart .axis { font-family: var(--font); font-size: 13px; fill: var(--muted); }
.bar-chart .bar { transition: opacity .12s; }
.bar-chart .bar-ok { fill: var(--blue); }
.bar-chart .bar-bad { fill: var(--red); }
.bar-chart .hit { fill: transparent; cursor: pointer; }
.chart-box:hover .bar:not(.is-hover) { opacity: .55; }
.chart-tip {
  position: absolute; z-index: 5; pointer-events: none;
  display: flex; flex-direction: column; gap: 1px; min-width: 150px;
  background: var(--white); border: 1px solid var(--line); border-radius: var(--r-sm);
  box-shadow: 0 8px 24px rgba(14, 42, 71, .16); padding: 8px 10px; font-size: var(--fs-xs); color: var(--ink);
}
.chart-tip strong { color: var(--navy); font-size: var(--fs-sm); }
.chart-tip .tip-val { font-family: var(--font-display); font-size: var(--fs-xl); font-weight: 600; color: var(--ink); }
.chart-tip .tip-ok { color: var(--green); font-weight: 600; }
.chart-tip .tip-bad { color: var(--red); font-weight: 600; }
.chart-tip .tip-sub { color: var(--muted); }
.chart-xlabel { text-align: center; font-size: var(--fs-xs); color: var(--muted); margin-top: -2px; }
.chart-foot { margin-top: 8px; font-size: var(--fs-sm); color: var(--muted); border-top: 1px solid var(--line); padding-top: 8px; }
.sample-note { margin: -2px 0 14px; padding: 8px 12px; border-radius: var(--r-sm); background: var(--amber-bg); color: var(--amber-ink); font-size: var(--fs-sm); }
.chart-tip .tip-sample { display: inline-block; margin-left: 4px; padding: 0 6px; border-radius: 999px; background: var(--amber-bg); color: var(--amber-ink); font-size: 11px; font-weight: 600; vertical-align: 1px; }
.chart-tip .tip-hint { margin-top: 3px; color: var(--blue); font-weight: 600; }
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; background: var(--white); border: 1px solid var(--line); border-radius: var(--r-md); }
.table-perf th, .table-perf td { padding: 9px 8px; }
.table-perf th { white-space: normal; min-width: 62px; vertical-align: bottom; line-height: 1.25; font-size: var(--fs-xs); }
.numbers { margin-top: 20px; }
.numbers summary { cursor: pointer; font-weight: 600; color: var(--blue); min-height: 44px; display: flex; align-items: center; }
.numbers summary:hover { color: var(--navy); }
.numbers[open] summary { margin-bottom: 8px; }
@media (max-width: 1000px) { .chart-grid { grid-template-columns: 1fr; } }
@media (max-width: 760px) {
  .chart-card { padding: 14px 12px 12px; }
  .bar-chart .axis { font-size: 12px; }
  .chart-head { flex-direction: column; gap: 6px; }
  .avg-target { align-self: stretch; }
}

/* ---------- Weekly report ---------- */
.report-title { font-size: var(--fs-xl); margin: 8px 0 12px; }
.report-title .cell-sub { font-family: var(--font); font-weight: 400; margin-left: 6px; }
.report-stats { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); margin-bottom: 8px; }
.report-stats .stat-kpi.is-good .stat-value { color: var(--green); }
.report-stats .stat-kpi.is-bad .stat-value { color: var(--red); }
.report-note { margin-bottom: 16px; }
.report-numbers { margin-bottom: 8px; }
.report-numbers .panel-head { align-items: flex-start; }
.num-boxes { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--r-sm); overflow: hidden; }
.num-box { display: flex; flex-direction: column; padding: 10px 14px; background: var(--white); }
.num-box-label { font-size: var(--fs-xs); color: var(--muted); font-weight: 600; }
.num-box-val { font-family: var(--font-display); font-size: var(--fs-2xl); font-weight: 600; line-height: 1.1; color: var(--navy); }
.num-box-val.is-good-num { color: var(--green); }
.num-box-val.is-bad-num { color: var(--red); }
.report-section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 26px 0 10px; flex-wrap: wrap; }
.report-section { font-size: var(--fs-xl); margin: 0; }
.empty-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 16px; }
.empty-actions .btn { margin-top: 0; }
.report-empty p { max-width: 62ch; margin: 0 auto; }
.log-guide { display: flex; flex-direction: column; gap: 2px; padding: 10px 12px; margin-bottom: 16px; border-radius: var(--r-sm); background: var(--mist); font-size: var(--fs-sm); }
.log-guide strong { color: var(--navy); }
.report-chart { margin: 16px 0 20px; }
.count-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px; margin-bottom: 20px; align-items: start; }
.count-panel .panel-head { align-items: baseline; }
.count-table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.count-table th { text-align: left; font-weight: 500; padding: 5px 8px 5px 0; white-space: nowrap; }
.count-table td { padding: 5px 0; }
.count-table .num { text-align: right; font-weight: 600; width: 32px; font-variant-numeric: tabular-nums; }
.count-table .count-hours { width: 1%; padding-left: 12px; font-weight: 500; color: #9AA9B8; white-space: nowrap; text-align: right; }
.count-table thead th { font-size: 11px; color: #7A8A9A; font-weight: 600; padding-bottom: 2px; text-transform: uppercase; letter-spacing: .03em; }
.count-table thead th.num { font-weight: 600; }
.count-table tfoot th, .count-table tfoot td { border-top: 1px solid var(--line, #DCE3EA); padding-top: 8px; font-weight: 700; }
.count-bar { width: 100%; padding-right: 10px !important; }
.count-bar span { display: block; height: 8px; border-radius: 4px; background: var(--blue); min-width: 0; }
.count-table tr.is-zero th, .count-table tr.is-zero .num { color: #9AA9B8; font-weight: 400; }
.mini-list { margin: 0; padding-left: 16px; }
.mini-list li + li { margin-top: 4px; }
@media (max-width: 1000px) { .count-grid { grid-template-columns: 1fr; } }

/* ---------- Import Excel ---------- */
.dropzone {
  display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center;
  padding: 36px 20px; border: 2px dashed var(--blue-soft); border-radius: var(--r-md);
  background: var(--white); cursor: pointer; transition: background .15s, border-color .15s;
}
.dropzone .icon { width: 32px; height: 32px; color: var(--blue); }
.dropzone:hover, .dropzone.is-over { background: var(--mist-2); border-color: var(--blue); }
.dropzone:focus-within { box-shadow: var(--focus); }
.dropzone-title { font-weight: 600; color: var(--navy); }
.import-plan, .import-done { margin-top: 20px; }
.import-plan .td-check { width: 36px; }
.import-plan .td-check input { width: 18px; height: 18px; accent-color: var(--navy); }
.import-plan tr.is-muted td { color: var(--muted); }
.import-fields { display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: center; margin-top: 6px; font-size: var(--fs-xs); color: var(--muted); }
.import-fields label { display: inline-flex; align-items: center; gap: 6px; }
.import-fields input, .import-fields select { min-height: 32px; width: auto; padding: 4px 8px; font-size: 14px; }
.import-fields input { width: 84px; }
.import-actions { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 16px; }
.reject-list { margin: 8px 0 0; padding-left: 20px; font-size: var(--fs-sm); color: var(--ink); }
.import-done h3 { font-size: var(--fs-xl); margin-bottom: 6px; }
.import-done ul { margin: 0; padding-left: 20px; }
.import-history { margin-top: 28px; }
.import-history h3 { font-size: var(--fs-lg); margin-bottom: 2px; }
.import-history .cell-sub { margin-bottom: 10px; }
.btn.danger-text { color: var(--red); }
.btn.danger-text:hover { background: var(--red-bg); }

/* ---------- 9. Modal & toast ---------- */
.modal {
  width: min(680px, calc(100% - 24px)); max-height: calc(100dvh - 24px);
  padding: 0; border: 0; border-radius: var(--r-lg);
  background: var(--white); color: var(--ink);
  box-shadow: 0 24px 60px rgba(14, 42, 71, .3);
}
.modal.is-small { width: min(440px, calc(100% - 24px)); }
.modal::backdrop { background: rgba(14, 42, 71, .5); }
.modal[open] { display: flex; }
.modal-box { display: flex; flex-direction: column; width: 100%; max-height: calc(100dvh - 24px); }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 14px 10px 22px; border-bottom: 1px solid var(--line); }
.modal-head h2 { font-size: var(--fs-xl); }
.modal-body { padding: 18px 22px; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 12px 22px 16px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.modal-foot:empty { display: none; }
.modal-foot .spacer { flex: 1; }

.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 200; display: flex; flex-direction: column; gap: 8px; max-width: calc(100% - 32px); }
.toast {
  background: var(--navy); color: var(--white);
  padding: 12px 16px; border-radius: var(--r-sm);
  box-shadow: 0 10px 30px rgba(14,42,71,.3);
  font-size: var(--fs-sm); border-left: 4px solid var(--blue-soft);
  animation: toast-in .2s ease-out;
}
.toast.is-error { border-left-color: #FF8A80; }
.toast.is-success { border-left-color: #7FD3A8; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ---------- 10. Responsive ---------- */
@media (max-width: 1100px) {
  .filters { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .period-totals { grid-column: 1 / -1; }
  .dash-grid { grid-template-columns: 1fr; }
}

/* Tablet & phone: sidebar slides out */
@media (max-width: 900px) {
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0;
    width: min(300px, 86vw);
    transform: translateX(-100%);
    transition: transform .25s ease;
    box-shadow: 8px 0 30px rgba(14,42,71,.25);
  }
  .shell.is-menu-open .sidebar { transform: none; }
  .sidebar-close { display: inline-grid; }
  .hamburger { display: inline-grid; }
  .collapse-btn { display: none; }
  /* collapsed mode is desktop-only */
  .shell.is-collapsed .sidebar { width: min(300px, 86vw); }
  .shell.is-collapsed .brand-name, .shell.is-collapsed .nav span, .shell.is-collapsed .profile-text,
  .shell.is-collapsed .nav-signout span { display: initial; }
  .shell.is-collapsed .nav-group { display: block; height: auto; margin: 18px 12px 6px; background: none; font-size: var(--fs-xs); }
  .shell.is-collapsed .nav a, .shell.is-collapsed .nav-signout, .shell.is-collapsed .nav-profile { justify-content: flex-start; padding: 0 12px; }
  .shell.is-collapsed .sidebar-head { justify-content: space-between; padding: 0 14px 0 18px; }
  .shell.is-collapsed .profile-text { display: flex; }

  .stats { grid-template-columns: repeat(6, 1fr); }
  .stat { grid-column: span 2; }
  .stat:nth-child(n+4) { grid-column: span 3; }
}

@media (max-width: 760px) {
  .login { grid-template-columns: 1fr; }
  .login-brand { display: none; }
  .login-mark-small { display: block; }
  .login-panel { align-items: start; padding-top: 48px; }

  .topbar { padding: 0 12px; }
  .chip-long { display: none; }
  .chip-short { display: inline; }
  .view { padding: 20px 14px 48px; }
  .demo-banner { padding: 8px 14px; }
  .page-head h2 { font-size: var(--fs-xl); }

  .stats { grid-template-columns: repeat(2, 1fr); }
  .stat, .stat:nth-child(n+4) { grid-column: auto; padding: 14px 16px; }
  .stat:first-child { grid-column: 1 / -1; }
  .stat-value { font-size: var(--fs-2xl); }

  .fleet { padding: 16px 14px; }
  .fleet-row { grid-template-columns: 1fr; gap: 6px; }
  .fleet-type { padding-top: 0; }
  .unit { width: 38px; height: 38px; }

  .filters { grid-template-columns: repeat(2, minmax(0, 1fr)); padding: 14px; }
  .toolbar .btn { flex: 1 1 auto; }

  /* Table becomes cards */
  .table-wrap { background: transparent; border: 0; overflow: visible; }
  .table.responsive thead { display: none; }
  .table.responsive, .table.responsive tbody, .table.responsive tr, .table.responsive td { display: block; width: 100%; }
  .table.responsive tr {
    background: var(--white); border: 1px solid var(--line); border-radius: var(--r-md);
    padding: 12px 14px; margin-bottom: 10px; position: relative;
    display: grid; grid-template-columns: 1fr 1fr; column-gap: 12px;
  }
  /* short fields sit side by side; long ones take the full width */
  .table.responsive td.td-head, .table.responsive td.cell-fault,
  .table.responsive td[data-label="Permissions"] { grid-column: 1 / -1; }
  .table.responsive td.cell-fault { order: 1; }
  .table.responsive tr.is-down { border-left: 4px solid var(--amber); }
  .table.responsive tr.is-down td:first-child { box-shadow: none; }
  .table.responsive td { border: 0; padding: 3px 0; }
  .table.responsive td[data-label]::before {
    content: attr(data-label); display: block; font-size: var(--fs-xs); color: var(--muted); font-weight: 600;
  }
  .table.responsive td.td-head::before, .table.responsive td.td-actions::before { display: none; }
  .table.responsive td.td-head { padding-right: 84px; }
  .table.responsive td.td-actions { position: absolute; top: 6px; right: 6px; width: auto; padding: 0; }
  .table.responsive tbody tr:hover td { background: transparent; }
  .table.responsive .num { text-align: left; }
  .cell-fault { max-width: none; }
  .pager { background: var(--white); border: 1px solid var(--line); border-radius: var(--r-md); }

  /* Wide numeric tables scroll sideways inside their box only */
  .table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; background: var(--white); border: 1px solid var(--line); border-radius: var(--r-md); }
  .table-scroll .table { min-width: 720px; }

  .event-item { grid-template-columns: 60px 1fr; }
  .event-item > :last-child { grid-column: 2; justify-self: start; }

  .detail-grid, .form-grid { grid-template-columns: 1fr; }
  .modal { width: 100%; max-width: 100%; max-height: 100dvh; height: 100dvh; border-radius: 0; margin: 0; }
  .modal.is-small { width: calc(100% - 24px); height: fit-content; max-height: calc(100dvh - 24px); border-radius: var(--r-lg); margin: auto; }
  .modal-box { max-height: 100dvh; }
  .modal-foot .btn { flex: 1 1 auto; }
  .modal-foot .spacer { display: none; }
  .toasts { left: 16px; right: 16px; }
}

@media (max-width: 380px) {
  .chip-sync { display: none; }
  .filters { grid-template-columns: 1fr; }
}

/* Year box in the top bar (one year for the whole app) */
.year-pick { display: flex; align-items: center; gap: 6px; font-size: var(--fs-sm); font-weight: 600; color: var(--navy); }
.year-pick[hidden] { display: none; }
.year-pick select { width: auto; min-height: 34px; padding: 4px 10px; border-radius: 999px; font-weight: 600; font-size: var(--fs-sm); }
@media (max-width: 600px) {
  .year-pick label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .topbar-status { gap: 4px; }
}

/* Formula page */
.formula-panel { margin-bottom: 16px; }
.formula-switch { font-size: var(--fs-md, 1rem); }
.formula-row { display: grid; grid-template-columns: 200px 1fr; gap: 6px 16px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.formula-row:last-of-type { border-bottom: 0; }
.formula-name { font-weight: 700; color: var(--navy); }
.formula-rule { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.formula-rule:has(.inline-num) { flex-direction: row; flex-wrap: wrap; align-items: center; }
.check-row { display: flex; flex-wrap: wrap; gap: 4px 18px; }
input.inline-num { width: 84px; min-height: 36px; padding: 6px 8px; }
#fRules.is-off { opacity: .55; }
.formula-fixed { margin: 12px 0 0; padding-left: 18px; color: var(--muted); font-size: var(--fs-sm); line-height: 1.8; }
.formula-actions { display: flex; justify-content: flex-end; margin: 0 0 16px; }
.typed-num { display: block; }
@media (max-width: 600px) {
  .formula-row { grid-template-columns: 1fr; }
}

/* Breakdown records table: same columns as the Excel log */
.table-records .cell-date { white-space: nowrap; }
.table-records .cell-fault { min-width: 160px; }
.table-records .td-head { white-space: nowrap; }
.table-records .cell-staff { min-width: 110px; font-size: var(--fs-sm); }

/* Records whose end time must be fixed */
.check-banner { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  background: #fff6db; border: 1px solid #f1d48a; border-radius: var(--r-sm); padding: 10px 14px; margin-bottom: 12px; font-size: var(--fs-sm); }
.check-banner-btns { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.warn-text { color: #9a6700; }
.bar.bar-none { fill: #c9d3df; }

/* User management (real accounts) */
.table-users select { width: auto; min-height: 36px; padding: 4px 10px; }
.cred-box { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 24px; padding: 12px 14px; margin-bottom: 10px;
  background: var(--mist); border: 1px solid var(--line); border-radius: var(--r-sm); }
.cred-box > div { display: flex; flex-direction: column; }
.cred-pass { font-family: ui-monospace, Consolas, monospace; font-size: 1.1rem; letter-spacing: .04em; }
.panel.must-change { border-color: #f1d48a; box-shadow: 0 0 0 3px #fff6db; }
.name-edit { margin-top: 4px; padding: 2px 8px; min-height: 0; font-size: var(--fs-xs); }
.name-edit .icon { width: 14px; height: 14px; }

/* Eye button to show / hide a password */
.password-wrap input { padding-right: 52px; }
.password-toggle { display: inline-flex; align-items: center; justify-content: center; padding: 0 10px; color: var(--muted); }
.password-toggle:hover { color: var(--navy); }
.password-toggle[aria-pressed="true"] { color: var(--blue); }

/* Turned-off account: permissions shown greyed out */
.perm-grid .check.is-off { opacity: .45; cursor: not-allowed; }

/* Phones: smaller page title so it fits; status chips show only their icon */
@media (max-width: 600px) {
  .page-title { font-size: 1.05rem; }
  .chip { padding: 0 8px; }
  .chip .chip-text, .chip .chip-short { display: none; }
  .year-pick select { padding: 4px 6px; }
  #newYearBtn { padding: 0 8px; }
}
@media (max-width: 380px) {
  .page-title { font-size: 1rem; line-height: 1.1; white-space: normal; text-overflow: clip; }
}

/* Compare years */
.year-chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 16px; }
.year-chip { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border: 1px solid var(--line); border-radius: 999px;
  background: var(--white); font-weight: 600; font-size: var(--fs-sm); cursor: pointer; }
.year-chip input { width: 16px; height: 16px; min-height: 0; margin: 0; }
.year-chip.is-on { border-color: var(--navy); }
.year-chip i, .cmp-swatch, .line-legend i, .tip-row i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; }
.year-chip:has(input:disabled) { opacity: .5; cursor: not-allowed; }
.cmp-table th[scope="row"] { text-align: left; font-weight: 600; white-space: nowrap; }
.cmp-swatch { margin-right: 6px; vertical-align: -1px; }
.line-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-bottom: 8px; font-size: var(--fs-sm); color: var(--ink); }
.line-legend span { display: inline-flex; align-items: center; gap: 6px; }
.line-legend .lg-target { width: 18px; height: 0; border-top: 2px dashed var(--navy); border-radius: 0; }
.line-chart { width: 100%; height: auto; display: block; }
.line-chart .grid { stroke: var(--line); stroke-width: 1; }
.line-chart .baseline { stroke: #9fb3c8; stroke-width: 1; }
.line-chart .target { stroke: var(--navy); stroke-width: 1.5; stroke-dasharray: 5 4; }
.line-chart .axis { fill: var(--muted); font-size: 11px; }
.line-chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.line-chart .dot { stroke: var(--white); stroke-width: 2; }
.line-chart .crosshair { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }
.line-chart .line-hit { fill: transparent; cursor: crosshair; touch-action: pan-y; }
.tip-row { display: flex; align-items: center; gap: 6px; }
.panel-head .segmented { flex-wrap: wrap; }
@media (max-width: 760px) {
  .table-scroll .cmp-table { min-width: 0; font-size: var(--fs-sm); }
  .cmp-table th[scope="row"] { white-space: normal; }
  .cmp-table th, .cmp-table td { padding-left: 8px; padding-right: 8px; }
}

/* Sync box in the top bar: click to sync now */
.chip-sync { cursor: pointer; }
.chip-sync:focus-visible { outline: 2px solid var(--navy); outline-offset: 2px; }
.chip-sync.is-syncing .icon { animation: bh-spin 1.2s linear infinite; }
@keyframes bh-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .chip-sync.is-syncing .icon { animation: none; } }
@media (max-width: 600px) {
  .chip-sync.has-pending .chip-short, .chip-sync.is-syncing .chip-short { display: inline; }
}
@media (max-width: 380px) {
  .chip-sync { display: inline-flex; }
  #netStatus { display: none; }
}

/* Desktop menu: thin strip of icons that opens over the page while the mouse is on it */
.nav { scrollbar-width: none; }               /* no scroll bar (it still scrolls on very short screens) */
.nav::-webkit-scrollbar { display: none; }
@media (min-width: 901px) {
  .shell .sidebar { transition: width .18s ease, margin-right .18s ease, box-shadow .18s ease; }
  .shell.is-peek .sidebar {
    width: var(--sidebar-w);
    margin-right: calc(var(--sidebar-w-collapsed) - var(--sidebar-w)); /* opens over the page; the page doesn't move */
    box-shadow: 10px 0 30px rgba(14, 42, 71, .28);
    z-index: 60;
  }
  .shell.is-peek .brand-name, .shell.is-peek .nav span, .shell.is-peek .nav-signout span { display: initial; }
  .shell.is-peek .profile-text { display: flex; }
  .shell.is-peek .nav-group { display: block; height: auto; margin: 14px 12px 6px; background: none; font-size: var(--fs-xs); }
  .shell.is-peek .nav a, .shell.is-peek .nav-signout, .shell.is-peek .nav-profile { justify-content: flex-start; padding: 0 12px; }
  .shell.is-peek .sidebar-head { justify-content: space-between; padding: 0 14px 0 18px; }
}

/* Drop-down lists: the "-- Select ... --" line shows in grey until something is chosen */
.form-grid select:has(option[value=""]:checked) { color: var(--muted); }
.form-grid select option { color: var(--ink); }
.form-grid select option[value=""] { color: var(--muted); }

/* Phones: the main button of each page (Add record, Add job, Add user ...) sits on the right */
@media (max-width: 760px) {
  .page-head > .btn { margin-left: auto; }
  /* Maintenance jobs: the three lists side by side, and the status buttons full width */
  .job-tabs, .job-status { display: grid; grid-template-columns: repeat(3, 1fr); width: 100%; }
  .job-tabs button, .job-status button { padding: 4px 6px; line-height: 1.2; white-space: normal; text-align: center; }
  .job-tabs .count { display: block; margin: 2px 0 0; }
}

/* Name of the up-down (y) axis, shown above the chart */
.chart-ylabel { font-size: var(--fs-xs); color: var(--muted); margin: 0 0 2px; }

/* Compare years: "By week / By month" and the measure buttons side by side */
.line-controls { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }
@media (max-width: 760px) {
  .panel-head:has(.line-controls) { flex-direction: column; align-items: stretch; gap: 10px; }
  .line-controls { justify-content: flex-start; }
}

/* ---------- Summary page (RTG / RMG performance tables) ---------- */
.sum-block { margin-top: 18px; }
.sum-title { font-size: var(--fs-lg); margin: 6px 0 10px; }
.sum-table { font-size: var(--fs-xs); }
.sum-table th, .sum-table td { padding: 7px 8px; white-space: nowrap; }
.sum-table thead th { background: var(--navy); color: var(--white); text-align: center; }
.sum-table thead th:first-child { text-align: left; }
.sum-table tbody th { font-weight: 500; color: var(--ink); }
.sum-table tr.sum-key th, .sum-table tr.sum-key td { font-weight: 700; }
.sum-table .sum-avg { background: var(--mist); }
.sum-table thead .sum-avg { background: var(--navy-2); }
.sum-charts { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 14px; }
.sum-chart .panel-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.sum-chart .lg-target { display: inline-block; width: 16px; border-top: 2px dashed var(--navy); vertical-align: middle; margin-right: 4px; }
.sum-line { width: 100%; height: auto; display: block; }
.sum-line .grid { stroke: var(--line); stroke-width: 1; }
.sum-line .axis { font-size: 10px; fill: var(--muted); }
.sum-line .target { stroke: var(--navy); stroke-dasharray: 5 4; stroke-width: 1.5; }
.sum-line .line { fill: none; stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.sum-line .sum-val { font-size: 9.5px; fill: var(--ink); font-weight: 600; }
.sum-combo { margin-top: 18px; }
.sum-avgs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px 18px; margin-bottom: 16px; }
.sum-avgs div { display: flex; justify-content: space-between; border-bottom: 1px solid var(--line); padding: 6px 0; font-size: var(--fs-sm); }
.sum-avgs span { color: var(--muted); }
.sum-combo-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.sum-combo-item { border: 1px solid var(--line); border-radius: var(--r-sm); padding: 12px 14px; }
.sum-combo-item h4 { font-size: var(--fs-sm); margin-bottom: 4px; }
.sum-formula { font-size: var(--fs-xs); color: var(--muted); }
.sum-result { font-family: var(--font-display); font-size: 1.6rem; font-weight: 700; color: var(--navy); margin-top: 2px; }
.sum-note { margin-top: 12px; }
.month-inputs .inline-num { width: 90px; }
@media (max-width: 760px) {
  .sum-charts, .sum-combo-grid { grid-template-columns: 1fr; }
  .sum-avgs { grid-template-columns: 1fr 1fr; }
}

/* Performance Report PDF: A4 portrait, one page per crane type (RMG, then RTG + combined) */
.sum-print { display: none; background: #fff; color: #14202E; font-size: 10px; }
.sp-page { break-after: page; page-break-after: always; overflow: hidden; }
.sp-page:last-child { break-after: auto; page-break-after: auto; }
.sp-head { display: flex; align-items: center; gap: 8px; border-bottom: 2px solid #0E2A47; padding-bottom: 4px; margin-bottom: 5px; }
.sp-head strong { font-family: var(--font-display); font-size: 16px; color: #0E2A47; }
.sp-head span { margin-left: auto; font-size: 9px; color: #586A7D; white-space: nowrap; }
.sp-head strong { white-space: nowrap; }
.sp-block { margin-bottom: 8px; }
.sp-block h3 { font-size: 13px; margin: 2px 0 6px; color: #0E2A47; }
.sp-empty { font-size: 8px; color: #586A7D; margin: 0; }
.sum-print .table-scroll { overflow: visible; border: 0; }
.sum-print .sum-table { width: 100%; font-size: 9.5px; border-collapse: collapse; }
.sum-print .sum-table th, .sum-print .sum-table td { padding: 3.5px 4px; line-height: 1.3; border-bottom: 1px solid #E3E9F0; }
.sum-print .sum-table thead th { padding: 4px 4px; }
.sp-charts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 10px; }
.sum-print .panel { box-shadow: none; border: 1px solid #DCE3EB; border-radius: 4px; margin: 0; }
.sum-print .panel-head { padding: 3px 6px; min-height: 0; }
.sum-print .panel-head h3 { font-size: 11px; margin: 0; }
.sum-print .panel-head .cell-sub { font-size: 9px; }
.sum-print .panel-body { padding: 2px 4px 3px; }
.sum-print .sum-line .axis { font-size: 11px; }
.sum-print .sum-line .sum-val { font-size: 10.5px; }
.sum-print .sum-combo { margin: 0; }
.sum-print .sum-avgs { grid-template-columns: repeat(3, 1fr); gap: 2px 8px; margin-bottom: 6px; }
.sum-print .sum-avgs div { flex-direction: column; font-size: 9px; padding: 1px 0; }
.sum-print .sum-avgs b { font-size: 12px; }
.sum-print .sum-combo-grid { grid-template-columns: repeat(2, 1fr); gap: 6px; }
.sum-print .sum-combo-item { padding: 3px 5px; }
.sum-print .sum-combo-item h4 { font-size: 9.5px; margin: 0 0 2px; }
.sum-print .sum-formula { font-size: 8px; margin: 0; }
.sum-print .sum-result { font-size: 15px; margin: 0; }

@media print {
  @page { size: A4 portrait; margin: 8mm; }
  html, body { background: #fff !important; height: auto !important; min-height: 0 !important; }
  .sidebar, .topbar, .overlay, .toasts, .no-print, .skip-link, dialog { display: none !important; }
  .shell, .main-col, main, .view { display: block !important; min-height: 0 !important; height: auto !important; padding: 0 !important; margin: 0 !important; max-width: none !important; }
  .sum-print { display: block !important; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* App name "RTG / RMG PERFORMANCE": a bit smaller so it fits the menu and the sign-in page */
.brand-name { font-size: 1.12rem; letter-spacing: .01em; }
.login-wordmark { font-size: 2.9rem; line-height: 1.02; max-width: 9ch; }

/* Report: System / Servicing Type / Downtime Type lines open their records */
.dt-link { background: none; border: 0; padding: 0; font: inherit; color: var(--blue, #1d5fa0); cursor: pointer; text-decoration: underline dotted; }
.dt-link:hover { text-decoration: underline; }
.sum-print .dt-link { color: inherit; text-decoration: none; }
.count-link { cursor: pointer; }
.count-link th a { color: inherit; text-decoration: none; }
.count-link th a:hover, .count-link th a:focus, .count-link th a:visited { color: inherit; text-decoration: none; outline: none; }
.count-link:hover { background: rgba(37, 99, 235, 0.06); }

/* 24-hour date + time fields */
.dt24 { display: grid; grid-template-columns: minmax(0, 1fr) 92px; gap: 8px; }
.dt24 .time24 { text-align: center; font-variant-numeric: tabular-nums; letter-spacing: .04em; }
.sum-th-dates { display: block; font-size: 11px; font-weight: 500; opacity: .75; white-space: nowrap; margin-top: 1px; }
.sum-print .sum-th-dates { font-size: 8px; }

/* Crane Performance → Months: Export PDF (A4 portrait) */
.perf-combined { margin-top: 22px; }
.print-only { display: none; }
.perf-print-head { width: 100%; margin: 4px 0 0; font-size: 12px; color: #586A7D; }
.perf-print-head strong { color: #0E2A47; font-size: 15px; }
.perf-combined > .cell-sub { margin: -4px 0 12px; }
@media print {
  body.print-perf .toolbar .segmented, body.print-perf .chart-tip, body.print-perf .numbers > summary { display: none !important; }
  body.print-perf .toolbar { margin-bottom: 6px; }
  body.print-perf .page-head { margin-bottom: 6px; }
  body.print-perf .page-head p { max-width: none; }
  body.print-perf .chart-grid { grid-template-columns: 1fr 1fr !important; gap: 10px; }
  body.print-perf .panel, body.print-perf .chart-card, body.print-perf .sum-combo, body.print-perf .sum-charts > * { break-inside: avoid; box-shadow: none !important; }
  body.print-perf details.numbers { break-inside: avoid; margin-top: 10px; }
  body.print-perf .print-only { display: block !important; }
  body.print-perf details.numbers .table { font-size: 11px; }
  body.print-perf details.numbers .table th, body.print-perf details.numbers .table td { padding-top: 5px !important; padding-bottom: 5px !important; }
  body.print-perf .sum-combo .panel-body { padding-top: 6px; }
  body.print-perf .sum-combo-item { padding: 8px 10px; }
  body.print-perf .perf-combined { break-before: page; margin-top: 0; }
  body.print-perf .perf-combined .sum-charts { break-inside: avoid; }
  body.print-perf .sum-charts { grid-template-columns: 1fr 1fr !important; }
}


/* To-do list in the Admin-only Maintenance Jobs module */
.todo-panel { margin: 18px 0 0; }
.todo-panel .panel-head { align-items: center; gap: 14px; }
.page-permissions { min-width: 300px; display: grid; gap: 12px; }
.module-permission { display: grid; gap: 6px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.module-permission > strong { font-size: 13px; color: var(--ink); }
.permission-ticks { display: flex; flex-wrap: wrap; gap: 8px 16px; }
.permission-ticks label { display: inline-flex; align-items: center; gap: 5px; color: var(--muted); font-size: 12px; white-space: nowrap; }
.permission-ticks input { width: 15px; height: 15px; accent-color: var(--navy); }
.permission-ticks input:disabled { cursor: not-allowed; }
.admin-only-permissions { display: flex; justify-content: space-between; align-items: center; gap: 10px; color: var(--muted); padding: 5px 0; font-size: 13px; }
.admin-only-permissions strong { color: var(--ink); font-size: 12px; }
.todo-list { display: grid; gap: 0; }
.todo-item { display: flex; align-items: flex-start; gap: 12px; padding: 13px 0; border-bottom: 1px solid var(--line); }
.todo-item:last-child { border-bottom: 0; }
.todo-check { padding-top: 3px; }
.todo-check input { width: 17px; height: 17px; accent-color: var(--navy); }
.todo-copy { flex: 1; min-width: 0; }
.todo-copy strong { display: block; overflow-wrap: anywhere; }
.todo-copy p { margin: 4px 0; color: var(--muted); white-space: pre-wrap; overflow-wrap: anywhere; }
.todo-item.is-done .todo-copy strong { text-decoration: line-through; color: var(--muted); }
.todo-actions { display: flex; gap: 4px; }
.todo-empty { display: grid; gap: 4px; padding: 20px 0; text-align: center; color: var(--muted); }
.todo-empty strong { color: var(--ink); }
@media (max-width: 700px) {
  .page-permissions { min-width: 0; }
  .permission-ticks { gap: 8px 12px; }
  .todo-panel .panel-head { align-items: flex-start; }
}


/* ---------- Inventory module ---------- */
.inventory-tabs { margin: 0 0 16px; }
.inventory-stats { grid-template-columns: repeat(3, minmax(0,1fr)); margin-bottom: 16px; }
.inventory-toolbar { align-items: center; }
.inv-head-actions { display:flex; gap:8px; flex-wrap:wrap; }
.inv-period { display:flex; align-items:center; gap:8px; color:var(--muted); font-size:var(--fs-sm); }
.inv-period select, .inv-period input { min-height:40px; border:1px solid var(--line); border-radius:var(--r-sm); background:var(--white); color:var(--ink); padding:0 10px; }
.inventory-table { min-width:900px; }
.inventory-empty { padding:28px; display:flex; flex-direction:column; gap:5px; align-items:center; color:var(--muted); }
.inventory-empty strong { color:var(--navy); }
.inv-footnote { margin-top:10px; }
.form-alert.success { background:var(--green-bg); color:var(--green); border-color:var(--green); }
@media(max-width:760px) { .inventory-stats { grid-template-columns:1fr 1fr; } .inv-head-actions { width:100%; } .inv-head-actions .btn { flex:1; } .inv-period { width:100%; justify-content:space-between; } }
