/* ==========================================================================
   Envirowaste OS — shared design system
   One stylesheet for portal + admin. Theme is a token swap (see [data-theme]).
   To restyle the whole app, edit the tokens in :root below.
   ========================================================================== */

:root {
  /* Brand */
  --brand:        #98CA4A;
  --brand-bright: #aad45a;
  --brand-deep:   #5fa130;
  --brand-ink:    #14210a;   /* text that sits on a brand-green fill */

  /* Surfaces (dark default) */
  --bg:           #26292e;
  --surface:      #34383f;
  --surface-2:    #3b4047;
  --surface-hover:#434952;
  --border:       #41464e;
  --border-soft:  #383d44;

  /* Text */
  --text:         #e9ebed;
  --text-dim:     #9aa1a9;
  --text-faint:   #6e757d;

  /* Status */
  --ok:       #98CA4A;
  --pending:  #ffd28a;
  --due:      #ffb84a;
  --critical: #e25b5b;
  --info:     #6db3f2;

  /* Shape & depth */
  --radius:    12px;
  --radius-sm: 8px;
  --radius-pill: 999px;
  --shadow:    0 1px 2px rgba(0,0,0,.30), 0 4px 14px rgba(0,0,0,.18);
  --shadow-lift: 0 4px 8px rgba(0,0,0,.30), 0 12px 28px rgba(0,0,0,.22);

  /* Spacing scale */
  --sp-1: 4px;  --sp-2: 8px;  --sp-3: 12px; --sp-4: 16px;
  --sp-5: 20px; --sp-6: 24px; --sp-8: 32px; --sp-10: 40px;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --maxw: 960px;
  --nav-w: 216px;      /* left rail width on desktop */
  --topbar-h: 54px;    /* mobile top bar height */
}

/* Light theme: same component rules, different tokens. */
[data-theme="light"] {
  --bg:           #f4f6f3;
  --surface:      #ffffff;
  --surface-2:    #f7f9f4;
  --surface-hover:#eef3e6;
  --border:       #e1e5dd;
  --border-soft:  #ebeee8;
  --text:         #1b1e1a;
  --text-dim:     #5a6159;
  --text-faint:   #8b918a;
  --brand:        #5fa130;
  --brand-bright: #4a8025;
  --brand-ink:    #ffffff;
  --pending:  #c98a1a;
  --due:      #d98726;
  --critical: #cf4040;
  --info:     #2f7fc4;
  --shadow:    0 1px 2px rgba(0,0,0,.06), 0 2px 8px rgba(0,0,0,.06);
  --shadow-lift: 0 4px 10px rgba(0,0,0,.10), 0 10px 24px rgba(0,0,0,.10);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font);
  font-size: 13.5px;
  line-height: 1.55;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* When a page uses the shared nav, body is offset to clear the left rail. */
body.has-nav { padding-left: var(--nav-w); }

a { color: var(--brand); }

.container {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: var(--sp-6) var(--sp-4) var(--sp-10);
}

/* ----------------------------------------------------------- Left side nav */
.ew-nav {
  position: fixed; top: 0; left: 0; bottom: 0; width: var(--nav-w);
  z-index: 100; background: var(--surface);
  border-right: 1px solid var(--border-soft);
  display: flex; flex-direction: column;
}
.ew-nav-inner { display: flex; flex-direction: column; height: 100%; }
.ew-brand {
  display: flex; align-items: center; gap: 9px;
  font-weight: 700; font-size: 14px; letter-spacing: .2px;
  color: var(--brand); text-decoration: none; white-space: nowrap;
  padding: 16px 18px; border-bottom: 1px solid var(--border-soft);
}
.ew-brand .dot { width: 11px; height: 11px; border-radius: 3px; background: var(--brand); display: inline-block; flex-shrink: 0; }
.ew-nav-links {
  display: flex; flex-direction: column; align-items: stretch; gap: 2px;
  flex: 1; overflow-y: auto; padding: 10px;
}
.ew-nav-links a {
  color: var(--text-dim); text-decoration: none;
  font-size: 13.5px; font-weight: 500;
  padding: 10px 14px; border-radius: var(--radius-sm);
  min-height: 44px; display: flex; align-items: center;
  transition: background .12s, color .12s;
}
.ew-nav-links a:hover { color: var(--text); background: var(--surface-hover); }
.ew-nav-links a.active { color: var(--brand-ink); background: var(--brand); }
.ew-nav-actions {
  display: flex; align-items: center; gap: 8px;
  padding: 12px; border-top: 1px solid var(--border-soft);
}
.ew-icon-btn {
  background: transparent; border: 1px solid var(--border);
  color: var(--text-dim); height: 40px; flex: 1;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font-size: 16px; border-radius: var(--radius-sm); cursor: pointer;
  transition: background .12s, color .12s, border-color .12s;
}
.ew-icon-btn:hover { color: var(--brand); border-color: var(--brand); background: color-mix(in srgb, var(--brand) 12%, transparent); }

/* Mobile top bar (hamburger + brand) — hidden on desktop */
.ew-topbar {
  display: none;
  position: fixed; top: 0; left: 0; right: 0; height: var(--topbar-h); z-index: 95;
  align-items: center; gap: 12px; padding: 0 12px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border-soft);
}
.ew-topbar .ew-brand { padding: 0; border: none; }
.ew-hamburger {
  background: transparent; border: 1px solid var(--border); color: var(--text);
  width: 40px; height: 40px; border-radius: var(--radius-sm); cursor: pointer;
  font-size: 18px; display: inline-flex; align-items: center; justify-content: center;
}
.ew-topbar-refresh {
  margin-left: auto;
  background: transparent; border: 1px solid var(--border); color: var(--text);
  width: 40px; height: 40px; border-radius: var(--radius-sm); cursor: pointer;
  font-size: 20px; display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.ew-topbar-refresh:active { transform: translateY(1px); }
.ew-icon-btn.spin span, .ew-topbar-refresh.spin { animation: ew-spin .6s linear infinite; }
@keyframes ew-spin { to { transform: rotate(360deg); } }
.ew-backdrop { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 99; }

@media (max-width: 899px) {
  body.has-nav { padding-left: 0; padding-top: var(--topbar-h); }
  .ew-topbar { display: flex; }
  .ew-backdrop.show { display: block; }
  .ew-nav {
    transform: translateX(-100%);
    transition: transform .22s ease; box-shadow: var(--shadow-lift);
  }
  .ew-nav.open { transform: translateX(0); }
}

/* ------------------------------------------------------------------- Header */
header.page-head {
  display: flex; justify-content: space-between; align-items: flex-end;
  flex-wrap: wrap; gap: var(--sp-3);
  padding: var(--sp-2) 2px var(--sp-5);
  border-bottom: 2px solid var(--brand);
  margin-bottom: var(--sp-6);
}
header.page-head h1 { font-size: 20px; font-weight: 700; color: var(--brand); letter-spacing: .2px; }
header.page-head p { font-size: 13px; color: var(--text-dim); margin-top: 2px; }
.head-back { color: var(--brand); text-decoration: none; font-size: 13px; font-weight: 600; }
.head-back:hover { text-decoration: underline; }

.section-label {
  font-size: 11px; font-weight: 700; color: var(--text-faint);
  padding: var(--sp-5) 0 var(--sp-2);
  text-transform: uppercase; letter-spacing: .7px;
}

/* -------------------------------------------------------------------- Tiles */
.tiles { display: grid; grid-template-columns: 1fr; gap: var(--sp-3); }
@media (min-width: 600px) { .tiles { grid-template-columns: 1fr 1fr; } }
@media (min-width: 900px) { .tiles.cols-3 { grid-template-columns: 1fr 1fr 1fr; } }

.tile {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-left: 3px solid var(--brand);
  border-radius: var(--radius);
  padding: var(--sp-4) var(--sp-5);
  text-decoration: none; color: var(--text);
  box-shadow: var(--shadow);
  transition: transform .12s ease, box-shadow .12s ease, border-color .12s, background .12s;
}
.tile:hover { transform: translateY(-2px); box-shadow: var(--shadow-lift); border-left-color: var(--brand-bright); background: var(--surface-hover); }
.tile .icon { font-size: 22px; margin-bottom: var(--sp-2); display: block; line-height: 1; }
.tile h2 { font-size: 15px; font-weight: 600; margin-bottom: var(--sp-1); }
.tile p { font-size: 13px; color: var(--text-dim); line-height: 1.45; }

.badge {
  display: inline-block; background: var(--brand); color: var(--brand-ink);
  padding: 2px 9px; border-radius: var(--radius-pill);
  font-size: 11px; font-weight: 700; margin-left: 6px; vertical-align: middle;
}

/* ------------------------------------------------ Glance / signal cards */
.glance {
  display: grid; gap: var(--sp-3);
  grid-template-columns: repeat(2, 1fr);
}
@media (min-width: 640px) { .glance { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 900px) { .glance { grid-template-columns: repeat(6, 1fr); } }

.signal {
  position: relative;
  display: flex; flex-direction: column; gap: 4px;
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-top: 3px solid var(--border);
  border-radius: var(--radius);
  padding: var(--sp-4) var(--sp-4) var(--sp-3);
  text-decoration: none; color: var(--text);
  box-shadow: var(--shadow);
  transition: transform .12s ease, box-shadow .12s ease, background .12s;
  min-height: 104px;
}
.signal:hover { transform: translateY(-2px); box-shadow: var(--shadow-lift); background: var(--surface-hover); }
.signal .s-num { font-size: 27px; font-weight: 700; line-height: 1; }
.signal .s-label { font-size: 12px; color: var(--text-dim); font-weight: 500; line-height: 1.3; }
.signal .s-icon { position: absolute; top: 12px; right: 12px; font-size: 18px; opacity: .8; }
/* state coloring driven by .is-* */
.signal.is-clear   { border-top-color: var(--ok); }
.signal.is-clear   .s-num { color: var(--text-dim); }
.signal.is-info    { border-top-color: var(--info); }
.signal.is-info    .s-num { color: var(--info); }
.signal.is-warn    { border-top-color: var(--due); }
.signal.is-warn    .s-num { color: var(--due); }
.signal.is-alert   { border-top-color: var(--critical); }
.signal.is-alert   .s-num { color: var(--critical); }
.signal.is-alert::after {
  content: ""; position: absolute; inset: 0; border-radius: var(--radius);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--critical) 45%, transparent);
  pointer-events: none;
}

/* ----------------------------------------------- Pull-to-refresh indicator */
.ew-ptr {
  position: fixed; top: -44px; left: 50%; transform: translateX(-50%);
  z-index: 300; width: 36px; height: 36px; border-radius: 50%;
  background: var(--surface); border: 1px solid var(--border); color: var(--brand);
  display: flex; align-items: center; justify-content: center; font-size: 20px;
  box-shadow: var(--shadow); opacity: 0; transition: opacity .15s;
}
.ew-ptr.ready { color: var(--brand-bright); border-color: var(--brand); }
.ew-ptr.spin .ew-ptr-icon { animation: ew-spin .6s linear infinite; display: inline-block; }

/* ------------------------------------------------------- Date-range calendar */
.ew-cal-overlay {
  position: fixed; inset: 0; z-index: 500; background: rgba(0,0,0,.5);
  display: flex; align-items: center; justify-content: center; padding: 16px;
  -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px);
}
.ew-cal {
  width: 320px; max-width: 100%; background: var(--surface);
  border: 1px solid var(--border-soft); border-radius: var(--radius);
  box-shadow: var(--shadow-lift); padding: var(--sp-4); color: var(--text);
}
.ew-cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--sp-3); }
.ew-cal-title { font-weight: 700; font-size: 15px; }
.ew-cal-nav {
  background: transparent; border: 1px solid var(--border); color: var(--text);
  width: 36px; height: 36px; border-radius: var(--radius-sm); cursor: pointer; font-size: 18px;
}
.ew-cal-nav:hover { border-color: var(--brand); color: var(--brand); }
.ew-cal-dow, .ew-cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.ew-cal-dow > div { text-align: center; font-size: 11px; color: var(--text-faint); font-weight: 700; padding-bottom: 4px; }
.ew-cal-day {
  text-align: center; padding: 8px 0; font-size: 13px; border-radius: var(--radius-sm);
  cursor: pointer; user-select: none;
}
.ew-cal-day.empty { cursor: default; }
.ew-cal-day:not(.empty):hover { background: var(--surface-hover); }
.ew-cal-day.inrange { background: color-mix(in srgb, var(--brand) 22%, transparent); border-radius: 0; }
.ew-cal-day.sel { background: var(--brand); color: var(--brand-ink); font-weight: 800; }
.ew-cal-day.sel.start { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.ew-cal-day.sel.end { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.ew-cal-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: var(--sp-3); padding-top: var(--sp-3); border-top: 1px solid var(--border); }
.ew-cal-range { font-size: 12px; color: var(--text-dim); }
.ew-cal-btns { display: flex; gap: 6px; }

/* ------------------------------------------------ Alert banner (dashboard) */
/* Big, top-of-page notice. Use .ew-banner.critical for failed safety items. */
.ew-banner {
  display: flex; align-items: flex-start; gap: var(--sp-3);
  border-radius: var(--radius); padding: var(--sp-4) var(--sp-5);
  margin-bottom: var(--sp-5); box-shadow: var(--shadow);
  border: 1px solid var(--border-soft); border-left: 4px solid var(--due);
  background: color-mix(in srgb, var(--due) 12%, var(--surface));
}
.ew-banner.critical {
  border-left-color: var(--critical);
  background: color-mix(in srgb, var(--critical) 16%, var(--surface));
  animation: ew-banner-pulse 2.4s ease-in-out infinite;
}
@keyframes ew-banner-pulse {
  0%, 100% { box-shadow: var(--shadow); }
  50% { box-shadow: var(--shadow), 0 0 0 3px color-mix(in srgb, var(--critical) 30%, transparent); }
}
.ew-banner .b-icon { font-size: 22px; line-height: 1.2; flex-shrink: 0; }
.ew-banner .b-body { flex: 1; min-width: 0; }
.ew-banner .b-title { font-size: 15px; font-weight: 800; letter-spacing: .2px; }
.ew-banner.critical .b-title { color: var(--critical); }
.ew-banner .b-list { margin-top: var(--sp-2); display: grid; gap: 4px; }
.ew-banner .b-item {
  font-size: 13px; display: flex; flex-wrap: wrap; gap: 6px; align-items: baseline;
}
.ew-banner .b-item a { font-weight: 700; }
.ew-banner .b-item .b-truck { font-weight: 800; color: var(--brand); }
.ew-banner .b-item .b-sev {
  font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .5px;
  padding: 1px 7px; border-radius: var(--radius-pill); background: var(--critical); color: #fff;
}
@media (prefers-reduced-motion: reduce) { .ew-banner.critical { animation: none; } }

/* ---------------------------------------------------------- Cards & rows */
.card {
  background: var(--surface); border: 1px solid var(--border-soft);
  border-radius: var(--radius); padding: var(--sp-4) var(--sp-5);
  box-shadow: var(--shadow);
}

/* status-tinted card (maintenance fleet) */
.truck-grid { display: grid; grid-template-columns: 1fr; gap: var(--sp-3); }
@media (min-width: 700px) { .truck-grid { grid-template-columns: 1fr 1fr; } }
.truck-card {
  background: var(--surface); border: 1px solid var(--border-soft);
  border-left: 3px solid var(--text-faint); border-radius: var(--radius);
  padding: var(--sp-3) var(--sp-5); display: block; text-decoration: none;
  color: var(--text); box-shadow: var(--shadow); transition: background .12s, transform .12s, box-shadow .12s;
}
.truck-card:hover { background: var(--surface-hover); transform: translateY(-1px); box-shadow: var(--shadow-lift); }
.truck-card.status-ok       { border-left-color: var(--ok); }
.truck-card.status-pending  { border-left-color: var(--pending); }
.truck-card.status-due      { border-left-color: var(--due); }
.truck-card.status-critical { border-left-color: var(--critical); }
.truck-card .top { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; }
.truck-card .name { font-size: 16px; font-weight: 700; }
.truck-card .desc { font-size: 13px; color: var(--text-dim); margin-bottom: 4px; }
.truck-card .meta { font-size: 12px; color: var(--text-faint); }
.truck-card .meta strong { color: var(--brand); }

.status-pill {
  font-size: 11px; font-weight: 700; padding: 2px 9px; border-radius: var(--radius-pill);
  text-transform: uppercase; letter-spacing: .5px; color: var(--brand-ink);
}
.status-ok       .status-pill, .pill-ok       { background: var(--ok); }
.status-pending  .status-pill, .pill-pending  { background: var(--pending); color: #1a1a1a; }
.status-due      .status-pill, .pill-due      { background: var(--due); color: #1a1a1a; }
.status-critical .status-pill, .pill-critical { background: var(--critical); color: #fff; }

.defect-list { display: grid; grid-template-columns: 1fr; gap: var(--sp-2); }
.defect-row {
  background: var(--surface); border: 1px solid var(--border-soft);
  border-left: 3px solid var(--text-faint); padding: var(--sp-3) var(--sp-4);
  border-radius: var(--radius-sm); display: flex; justify-content: space-between;
  align-items: flex-start; gap: var(--sp-3); box-shadow: var(--shadow);
}
.defect-row.critical { border-left-color: var(--critical); }
.defect-row.normal   { border-left-color: var(--due); }
.defect-row .left { flex: 1; }
.defect-row .truck { font-size: 13px; font-weight: 700; color: var(--brand); }
.defect-row .desc { font-size: 14px; margin: 2px 0; }
.defect-row .meta { font-size: 11px; color: var(--text-faint); }
.defect-row .actions { display: flex; gap: 6px; }

/* --------------------------------------------------------------- Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 15px; min-height: 40px;
  font-size: 13.5px; font-weight: 600; font-family: inherit;
  background: var(--brand); color: var(--brand-ink);
  border: none; border-radius: var(--radius-sm); cursor: pointer;
  text-decoration: none; transition: filter .12s, transform .08s;
}
.btn:hover { filter: brightness(1.06); }
.btn:active { transform: translateY(1px); }
.btn-sm { padding: 6px 11px; min-height: 34px; font-size: 12px; }
.btn-ghost { background: transparent; color: var(--brand); border: 1px solid var(--border); }
.btn-ghost:hover { background: color-mix(in srgb, var(--brand) 12%, transparent); border-color: var(--brand); filter: none; }
.btn-muted { background: var(--text-faint); color: #fff; }

/* ---------------------------------------------------------------- Forms */
label.field { display: block; margin-bottom: var(--sp-4); }
label.field > span { display: block; font-size: 13px; font-weight: 600; color: var(--text-dim); margin-bottom: 6px; }
input, select, textarea {
  width: 100%; font-family: inherit; font-size: 16px; /* 16px avoids iOS zoom */
  color: var(--text); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 11px 13px; min-height: 44px;
  transition: border-color .12s, box-shadow .12s;
}
textarea { min-height: 96px; resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 28%, transparent);
}

/* --------------------------------------------------------------- Misc */
.empty {
  padding: var(--sp-6); text-align: center; color: var(--text-faint);
  font-style: italic; background: var(--surface); border: 1px solid var(--border-soft);
  border-radius: var(--radius);
}
footer {
  margin-top: var(--sp-8); padding-top: var(--sp-4);
  border-top: 1px solid var(--border-soft);
  font-size: 11px; color: var(--text-faint); text-align: center;
}

/* Legacy floating theme toggle — kept so un-migrated pages still work.
   On nav pages the toggle lives in the nav, so hide the floating one. */
.theme-toggle {
  position: fixed; top: 14px; right: 14px; z-index: 200;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--brand); padding: 6px 12px; font-size: 16px;
  border-radius: var(--radius-sm); cursor: pointer; line-height: 1;
}
.theme-toggle:hover { background: var(--surface-hover); }
body.has-nav .theme-toggle { display: none; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
