:root {
  --bg: #0b1220;
  --bg-elev: #141c2c;
  --bg-card: #1a2438;
  --line: #2a364c;
  --text: #f4f7fb;
  --muted: #9aa6b8;
  --ice: #7ec8ff;
  --gold: #f5c518;
  --go: #1f9d55;
  --go-press: #177a42;
  --stop: #d94444;
  --stop-press: #b13232;
  --on: #3dde86;
  --off: #8b96a8;
  --danger: #ff7a7a;
  --radius: 18px;
  --tap: 76px;
  --font: "SF Pro Display", "Segoe UI", system-ui, -apple-system, sans-serif;
  --tabbar-h: 84px;
  --topbar-h: 76px;
  color-scheme: dark;
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  min-height: 100dvh;
  overflow: hidden;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 520px;
  margin: 0 auto;
  background:
    radial-gradient(1200px 400px at 50% -80px, rgba(126, 200, 255, 0.10), transparent 60%),
    var(--bg);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(12px + env(safe-area-inset-top, 0px)) 18px 10px;
  min-height: calc(var(--topbar-h) + env(safe-area-inset-top, 0px));
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand-icon { border-radius: 9px; display: block; }
.brand-kicker {
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ice);
  font-weight: 700;
}
.topbar h1 { font-size: 20px; font-weight: 750; letter-spacing: -0.02em; line-height: 1.1; }
.live-clock {
  font-variant-numeric: tabular-nums;
  font-weight: 650;
  font-size: 15px;
  color: var(--muted);
  text-align: right;
}

.main {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px 16px calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 18px);
}

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  margin: 0 auto;
  max-width: 520px;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom, 0px));
  background: #0b1220;
  border-top: 1px solid var(--line);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.tab {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  min-height: 64px;
  border-radius: 14px;
  font: inherit;
  font-size: 11px;
  font-weight: 700;
  padding: 4px 2px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.tab-icon { font-size: 20px; line-height: 1; }
.tab[aria-current="page"] {
  color: var(--text);
  background: var(--bg-card);
}

button, .toggle, select {
  font: inherit;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
}

h2 { font-size: 22px; letter-spacing: -0.03em; margin-bottom: 6px; }
.lede { color: var(--muted); font-size: 16px; line-height: 1.4; margin-bottom: 16px; }

.name-list { display: flex; flex-direction: column; gap: 10px; }
.name-btn, .action-btn, .ghost-btn, .danger-btn, .secondary-btn {
  appearance: none;
  width: 100%;
  min-height: var(--tap);
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--bg-card);
  color: var(--text);
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
  padding: 12px 18px;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 12px;
  cursor: pointer;
  text-align: left;
}
.name-btn > span:nth-of-type(2) { flex: 1; }
.name-btn:active, .ghost-btn:active, .secondary-btn:active { transform: scale(0.985); }
.name-btn .meta { font-size: 15px; font-weight: 650; color: var(--muted); }
.name-btn .dot {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--off); flex-shrink: 0;
  box-shadow: 0 0 0 4px rgba(155, 166, 184, 0.15);
}
.name-btn .dot.on {
  background: var(--on);
  box-shadow: 0 0 0 4px rgba(61, 222, 134, 0.2);
  animation: pulse 2s ease-out infinite;
}

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(61, 222, 134, 0.45); }
  100% { box-shadow: 0 0 0 12px rgba(61, 222, 134, 0); }
}

.operator-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.operator-name { font-size: 28px; font-weight: 800; letter-spacing: -0.04em; line-height: 1.1; }
.switch-btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--ice);
  font-weight: 750;
  font-size: 16px;
  min-height: 52px;
  padding: 0 16px;
  border-radius: 14px;
  cursor: pointer;
  white-space: nowrap;
}

.status-card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 22px 20px;
  margin-bottom: 18px;
  text-align: center;
}
.status-label {
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}
.status-card.on-shift .status-label { color: var(--on); }
.status-time {
  font-size: 42px;
  font-weight: 800;
  letter-spacing: -0.05em;
  margin: 8px 0 4px;
  font-variant-numeric: tabular-nums;
}
.status-sub { color: var(--muted); font-size: 16px; line-height: 1.4; }
.loc-line {
  margin-top: 12px;
  color: var(--ice);
  font-size: 15px;
  font-weight: 650;
}

.punch {
  appearance: none;
  width: 100%;
  min-height: 108px;
  border: 0;
  border-radius: 28px;
  font-size: 36px;
  font-weight: 850;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
  color: #08110a;
  margin: 8px 0 16px;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.28);
}
.punch:active { transform: scale(0.98); }
.punch.start { background: linear-gradient(180deg, #3ee57a, var(--go)); color: #06210f; }
.punch.start:active { background: var(--go-press); }
.punch.stop { background: linear-gradient(180deg, #ff6b6b, var(--stop)); color: #2a0707; }
.punch.stop:active { background: var(--stop-press); }
.punch:disabled { opacity: 0.55; cursor: wait; }

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  min-height: var(--tap);
}
.toggle-copy { font-size: 18px; font-weight: 700; }
.toggle-copy small { display: block; font-size: 14px; font-weight: 550; color: var(--muted); margin-top: 2px; }

.switch {
  position: relative;
  width: 68px;
  height: 40px;
  flex-shrink: 0;
}
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span {
  position: absolute;
  inset: 0;
  background: #2a3346;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s ease;
}
.switch span::after {
  content: "";
  position: absolute;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #e8eef6;
  top: 4px;
  left: 4px;
  transition: transform 0.15s ease;
}
.switch input:checked + span { background: #1d6a9a; }
.switch input:checked + span::after { transform: translateX(28px); }
.switch input:focus-visible + span { outline: 3px solid var(--ice); outline-offset: 2px; }

.section-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 10px;
  margin: 6px 0 12px;
}
.section-head h2 { margin: 0; }
.count-pill {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 12px;
  font-weight: 750;
  font-size: 14px;
  color: var(--muted);
}

.view-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 14px;
}
.view-toggle button {
  appearance: none;
  min-height: 56px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--muted);
  font-size: 18px;
  font-weight: 750;
  cursor: pointer;
}
.view-toggle button[aria-pressed="true"] {
  background: var(--bg-card);
  color: var(--text);
  border-color: #3a4d6b;
}

.crew-card, .shift-card, .panel {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px 16px;
  margin-bottom: 10px;
}
.crew-card {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: center;
  min-height: 84px;
}
.avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: #24344f;
  color: var(--ice);
  font-weight: 800;
  display: grid;
  place-items: center;
  font-size: 16px;
}
.crew-name { font-size: 18px; font-weight: 750; }
.crew-meta { color: var(--muted); font-size: 14px; margin-top: 2px; }
.elapsed { font-variant-numeric: tabular-nums; font-weight: 800; font-size: 18px; color: var(--text); }
.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(61, 222, 134, 0.14);
  color: var(--on);
  margin-bottom: 4px;
}
.badge.off { background: rgba(155, 166, 184, 0.12); color: var(--muted); }

#map {
  height: min(62vh, 520px);
  border-radius: 18px;
  border: 1px solid var(--line);
  overflow: hidden;
  background: #152033;
}
.map-fallback {
  min-height: 240px;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 24px;
  color: var(--muted);
  font-size: 16px;
}

.leaflet-container { background: #152033; font-family: var(--font); }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: #1a2438; color: #f4f7fb; }
.leaflet-popup-content { margin: 12px 14px; font-size: 15px; }
.leaflet-control-attribution { font-size: 10px !important; }

.filter-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 8px;
  margin-bottom: 8px;
  -webkit-overflow-scrolling: touch;
}
.chip {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--muted);
  border-radius: 999px;
  min-height: 48px;
  padding: 0 16px;
  font-size: 15px;
  font-weight: 750;
  white-space: nowrap;
  cursor: pointer;
}
.chip[aria-pressed="true"] { background: var(--bg-card); color: var(--text); border-color: #3a4d6b; }

.shift-top { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.shift-who { font-size: 18px; font-weight: 750; }
.shift-dur { font-weight: 800; font-variant-numeric: tabular-nums; color: var(--gold); }
.shift-times { color: var(--muted); font-size: 15px; margin-top: 6px; line-height: 1.45; }
.shift-loc { color: var(--ice); font-size: 14px; margin-top: 6px; }

.empty {
  text-align: center;
  color: var(--muted);
  padding: 32px 12px;
  font-size: 16px;
}

.secondary-btn, .ghost-btn, .danger-btn {
  justify-content: center;
  text-align: center;
  margin-bottom: 10px;
}
.secondary-btn { background: var(--bg-card); }
.ghost-btn { background: transparent; color: var(--ice); }
.danger-btn {
  background: transparent;
  border-color: #5a2a2a;
  color: var(--danger);
  font-size: 18px;
}

.note {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
  margin: 8px 0 16px;
}
.steps { color: var(--text); font-size: 16px; line-height: 1.55; padding-left: 1.15em; margin: 8px 0 16px; }
.steps li { margin: 6px 0; }
.kicker {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ice);
  margin-bottom: 6px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 12px);
  transform: translateX(-50%);
  background: #eff4fb;
  color: #0b1220;
  font-weight: 750;
  font-size: 16px;
  padding: 14px 18px;
  border-radius: 14px;
  max-width: calc(100% - 32px);
  z-index: 50;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}
.toast[hidden] { display: none; }

.confirm-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 60;
  display: grid;
  place-items: end center;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom, 0px));
}
.confirm-sheet {
  width: min(520px, 100%);
  background: #1a2438;
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 22px 18px 16px;
}
.confirm-sheet h3 { font-size: 22px; margin-bottom: 8px; }
.confirm-sheet p { color: var(--muted); font-size: 16px; margin-bottom: 16px; line-height: 1.4; }

@media (min-width: 700px) {
  body { overflow: auto; }
  #app {
    min-height: 100dvh;
    height: auto;
    border-left: 1px solid var(--line);
    border-right: 1px solid var(--line);
  }
}


/* ---- lots, forms, time pickers ---- */
.back-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--ice);
  font: inherit;
  font-size: 17px;
  font-weight: 750;
  min-height: 48px;
  padding: 0 0 8px;
  cursor: pointer;
}
.field { margin-bottom: 14px; }
.field label, .field-label {
  display: block;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 6px;
}
.field input[type="text"],
.field input[type="date"],
.field input[type="time"],
.field input[type="datetime-local"],
.field textarea,
.field select {
  width: 100%;
  min-height: var(--tap);
  border-radius: 16px;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--text);
  font: inherit;
  font-size: 20px;
  font-weight: 650;
  padding: 12px 16px;
}
.field textarea { min-height: 84px; resize: vertical; line-height: 1.35; }
.field input:focus, .field textarea:focus, .field select:focus {
  outline: 3px solid rgba(126, 200, 255, 0.45);
  outline-offset: 1px;
}
.time-block {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 14px;
  margin-bottom: 14px;
}
.time-block h3 { font-size: 18px; margin-bottom: 10px; }
.stepper-row {
  display: grid;
  grid-template-columns: var(--tap) 1fr var(--tap);
  gap: 8px;
  margin-top: 8px;
  align-items: stretch;
}
.stepper-row button {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--text);
  border-radius: 16px;
  font: inherit;
  font-size: 28px;
  font-weight: 800;
  min-height: var(--tap);
  cursor: pointer;
}
.stepper-row button:active { transform: scale(0.97); }
.lot-card, .visit-card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px;
  margin-bottom: 10px;
  width: 100%;
  text-align: left;
  color: inherit;
  font: inherit;
  display: block;
  cursor: pointer;
  min-height: 84px;
}
.lot-card:active, .visit-card:active { transform: scale(0.985); }
.lot-card .lot-name, .visit-card .lot-name { font-size: 19px; font-weight: 800; letter-spacing: -0.02em; }
.lot-card .lot-addr, .visit-card .visit-meta { color: var(--muted); font-size: 14px; margin-top: 4px; line-height: 1.4; }
.lot-card.active-lot { border-color: #2f7a54; box-shadow: inset 0 0 0 1px #2f7a54; }
.current-lot {
  background: var(--bg-card);
  border: 1px solid #2f7a54;
  border-radius: 22px;
  padding: 20px 18px 16px;
  margin-bottom: 16px;
  text-align: center;
}
.current-lot .lot-name { font-size: 26px; font-weight: 800; letter-spacing: -0.03em; margin: 4px 0 6px; }
.shift-mini {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 10px 12px;
  min-height: 58px;
}
.shift-mini .label { font-size: 14px; font-weight: 700; color: var(--muted); }
.shift-mini .time { font-weight: 800; font-variant-numeric: tabular-nums; }
.end-shift {
  appearance: none;
  border: 1px solid #5a2a2a;
  background: transparent;
  color: var(--danger);
  font: inherit;
  font-size: 15px;
  font-weight: 750;
  min-height: 48px;
  padding: 0 14px;
  border-radius: 12px;
  cursor: pointer;
  white-space: nowrap;
}
.lot-start-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
}
.lot-start-row .lot-info { flex: 1; text-align: left; }
.mini-go, .mini-stop {
  appearance: none;
  border: 0;
  min-width: 92px;
  min-height: 64px;
  border-radius: 16px;
  font: inherit;
  font-size: 18px;
  font-weight: 850;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  cursor: pointer;
  flex-shrink: 0;
}
.mini-go { background: linear-gradient(180deg, #3ee57a, var(--go)); color: #06210f; }
.mini-stop { background: linear-gradient(180deg, #ff6b6b, var(--stop)); color: #2a0707; }
.pin-status { color: var(--ice); font-size: 15px; font-weight: 650; margin: 4px 0 8px; }
.row-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.icon-btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--ice);
  font: inherit;
  font-weight: 750;
  font-size: 15px;
  min-height: 52px;
  padding: 0 12px;
  border-radius: 14px;
  cursor: pointer;
}
.row-btns .icon-btn { min-height: var(--tap); font-size: 18px; }


/* ---- live status + storms ---- */
.top-meta { text-align: right; flex-shrink: 0; }
.mode-pill {
  display: inline-block;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 3px 8px;
  border-radius: 999px;
  margin-bottom: 2px;
  background: rgba(155, 166, 184, 0.16);
  color: var(--muted);
}
.mode-pill[data-mode="live"] { background: rgba(61, 222, 134, 0.16); color: var(--on); }
.mode-pill[data-mode="offline"] { background: rgba(245, 197, 24, 0.16); color: var(--gold); }
.mode-pill[data-mode="syncing"] { background: rgba(126, 200, 255, 0.16); color: var(--ice); }

.storm-banner {
  background: #2a2410;
  border: 1px solid #6a5a1c;
  color: var(--gold);
  border-radius: 16px;
  padding: 12px 14px;
  margin-bottom: 14px;
  font-weight: 750;
  font-size: 15px;
}
.report-card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px;
  margin-bottom: 10px;
}
.report-card .row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: baseline;
  margin-top: 8px;
}
.report-card .who { color: var(--muted); font-size: 14px; line-height: 1.4; margin-top: 4px; }
.report-card h3 { font-size: 18px; }
.totals { font-weight: 800; font-variant-numeric: tabular-nums; color: var(--gold); }
.storm-active {
  border-color: #6a5a1c;
  box-shadow: inset 0 0 0 1px #6a5a1c;
}
