@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700;1,9..40,400&family=IBM+Plex+Mono:wght@400;500;600&display=swap');

:root {
  --bg: #0c1017;
  --surface: #141b26;
  --surface-2: #1c2636;
  --border: #2a3648;
  --fg: #e8eef6;
  --muted: #8b9bb0;
  --dim: #5c6b80;
  --accent: #c4a574;
  --accent-dim: rgba(196, 165, 116, 0.15);
  --good: #34d399;
  --warn: #fbbf24;
  --bad: #f87171;
  --info: #38bdf8;
  --hzj: #60a5fa;
  --hj60: #a78bfa;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --nav-h: 4.5rem;
  --radius: 14px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: 'DM Sans', system-ui, sans-serif;
  overscroll-behavior: none;
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

.mono { font-family: 'IBM Plex Mono', ui-monospace, monospace; }

/* ─── Lock screen ─── */
#lock-screen {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background:
    radial-gradient(ellipse 80% 50% at 50% -10%, rgba(196, 165, 116, 0.12), transparent),
    var(--bg);
}

.lock-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 2rem 1.5rem;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.4);
}

.lock-card h1 {
  margin: 0 0 0.35rem;
  font-size: 1.45rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.lock-card .sub {
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 1.5rem;
  line-height: 1.4;
}

.lock-card label {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 0.4rem;
  font-weight: 500;
}

.lock-card input[type='password'] {
  width: 100%;
  padding: 0.85rem 1rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg);
  margin-bottom: 1rem;
  outline: none;
}

.lock-card input:focus {
  border-color: var(--accent);
}

.lock-card .btn-primary {
  width: 100%;
}

.lock-error {
  color: var(--bad);
  font-size: 0.85rem;
  margin: 0 0 0.75rem;
  min-height: 1.2em;
}

/* ─── App shell ─── */
#app {
  display: none;
  min-height: 100dvh;
  padding-bottom: calc(var(--nav-h) + var(--safe-b) + 1rem);
}

#app.ready { display: block; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(12, 16, 23, 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 0.65rem 1rem 0.75rem;
}

.topbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.topbar h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.sync-pill {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.25rem 0.55rem;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  border: 1px solid var(--border);
  white-space: nowrap;
}

.sync-pill.ok { color: var(--good); border-color: rgba(52, 211, 153, 0.35); }
.sync-pill.err { color: var(--bad); border-color: rgba(248, 113, 113, 0.35); }
.sync-pill.busy { color: var(--info); }

.vehicle-tabs {
  display: flex;
  gap: 0.4rem;
  margin-top: 0.65rem;
}

.vehicle-tabs button {
  flex: 1;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 10px;
  padding: 0.55rem 0.4rem;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--muted);
  transition: 0.15s ease;
}

.vehicle-tabs button.active {
  color: var(--fg);
  border-color: transparent;
}

.vehicle-tabs button[data-id='hzj76'].active {
  background: rgba(96, 165, 250, 0.18);
  color: var(--hzj);
  box-shadow: inset 0 0 0 1px rgba(96, 165, 250, 0.45);
}

.vehicle-tabs button[data-id='hj60'].active {
  background: rgba(167, 139, 250, 0.18);
  color: var(--hj60);
  box-shadow: inset 0 0 0 1px rgba(167, 139, 250, 0.45);
}

.vehicle-tabs button[data-id='fleet'].active {
  background: var(--accent-dim);
  color: var(--accent);
  box-shadow: inset 0 0 0 1px rgba(196, 165, 116, 0.45);
}

main {
  padding: 1rem;
  max-width: 720px;
  margin: 0 auto;
}

.page { display: none; }
.page.active { display: block; }

/* ─── Cards ─── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 0.75rem;
}

.card h2 {
  margin: 0 0 0.75rem;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
}

.stat {
  background: var(--surface-2);
  border-radius: 12px;
  padding: 0.75rem;
}

.stat .label {
  font-size: 0.72rem;
  color: var(--muted);
  margin-bottom: 0.25rem;
}

.stat .value {
  font-size: 1.15rem;
  font-weight: 700;
  font-family: 'IBM Plex Mono', monospace;
  letter-spacing: -0.02em;
}

.stat .value.sm { font-size: 0.95rem; }

.stat.wide { grid-column: 1 / -1; }

.stat .value.accent { color: var(--accent); }
.stat .value.good { color: var(--good); }
.stat .value.warn { color: var(--warn); }

.note-box {
  font-size: 0.9rem;
  line-height: 1.45;
  color: var(--muted);
  background: var(--surface-2);
  border-radius: 10px;
  padding: 0.75rem;
}

/* ─── Lists ─── */
.list-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
  gap: 0.5rem;
}

.list-head h2 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  text-transform: none;
  letter-spacing: -0.02em;
  color: var(--fg);
}

.row-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.85rem 0.9rem;
  margin-bottom: 0.55rem;
  cursor: pointer;
  transition: border-color 0.12s;
}

.row-card:active { border-color: var(--accent); }

.row-card .title {
  font-weight: 600;
  font-size: 0.95rem;
  margin-bottom: 0.25rem;
}

.row-card .meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.65rem;
  font-size: 0.78rem;
  color: var(--muted);
}

.badge {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 600;
  padding: 0.15rem 0.45rem;
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--muted);
  border: 1px solid var(--border);
}

.badge.high { color: var(--bad); border-color: rgba(248, 113, 113, 0.4); background: rgba(248, 113, 113, 0.1); }
.badge.medium { color: var(--warn); border-color: rgba(251, 191, 36, 0.35); }
.badge.low { color: var(--muted); }
.badge.pending { color: var(--info); border-color: rgba(56, 189, 248, 0.35); }
.badge.progress { color: var(--warn); }
.badge.done { color: var(--good); border-color: rgba(52, 211, 153, 0.35); }
.badge.order { color: var(--warn); }
.badge.purchased { color: var(--info); }
.badge.hand { color: var(--accent); }
.badge.installed { color: var(--good); }

.empty {
  text-align: center;
  color: var(--dim);
  padding: 2rem 1rem;
  font-size: 0.9rem;
}

/* ─── Buttons ─── */
.btn-primary, .btn-secondary, .btn-ghost, .btn-danger {
  border: none;
  border-radius: 11px;
  padding: 0.7rem 1rem;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
}

.btn-primary {
  background: linear-gradient(135deg, #c4a574, #a8895a);
  color: #0c1017;
}

.btn-secondary {
  background: var(--surface-2);
  color: var(--fg);
  border: 1px solid var(--border);
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
}

.btn-danger {
  background: rgba(248, 113, 113, 0.15);
  color: var(--bad);
  border: 1px solid rgba(248, 113, 113, 0.3);
}

.btn-sm {
  padding: 0.45rem 0.75rem;
  font-size: 0.8rem;
  border-radius: 9px;
}

.btn-icon {
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--fg);
  cursor: pointer;
  font-size: 1.2rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* ─── Bottom nav ─── */
.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  display: flex;
  background: rgba(20, 27, 38, 0.96);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
  padding: 0.35rem 0.4rem calc(0.35rem + var(--safe-b));
}

.bottom-nav button {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--dim);
  padding: 0.4rem 0.2rem;
  cursor: pointer;
  font-size: 0.65rem;
  font-weight: 600;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
}

.bottom-nav button .ico { font-size: 1.2rem; line-height: 1; }
.bottom-nav button.active { color: var(--accent); }

/* ─── Modal / sheet ─── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(0, 0, 0, 0.55);
  display: none;
  align-items: flex-end;
  justify-content: center;
}

.modal-backdrop.open { display: flex; }

.modal {
  width: 100%;
  max-width: 560px;
  max-height: min(92dvh, 900px);
  overflow: auto;
  background: var(--surface);
  border-radius: 18px 18px 0 0;
  border: 1px solid var(--border);
  border-bottom: none;
  padding: 1rem 1rem calc(1.25rem + var(--safe-b));
  animation: slideUp 0.2s ease;
}

@keyframes slideUp {
  from { transform: translateY(24px); opacity: 0.6; }
  to { transform: translateY(0); opacity: 1; }
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  gap: 0.5rem;
}

.modal-head h3 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
}

.form-grid {
  display: grid;
  gap: 0.75rem;
}

.form-grid label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 0.3rem;
}

.form-grid input,
.form-grid select,
.form-grid textarea {
  width: 100%;
  padding: 0.7rem 0.8rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  outline: none;
}

.form-grid input:focus,
.form-grid select:focus,
.form-grid textarea:focus {
  border-color: var(--accent);
}

.form-grid textarea { min-height: 72px; resize: vertical; }

.form-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
}

.modal-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1.1rem;
  flex-wrap: wrap;
}

.modal-actions .btn-primary,
.modal-actions .btn-secondary,
.modal-actions .btn-danger {
  flex: 1;
  min-width: 100px;
}

/* ─── Breakdown bars ─── */
.bar-row {
  display: grid;
  grid-template-columns: 7rem 1fr auto;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 0.45rem;
  font-size: 0.78rem;
}

.bar-row .name { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row .amt { font-family: 'IBM Plex Mono', monospace; color: var(--fg); min-width: 4.5rem; text-align: right; }

.bar-track {
  height: 6px;
  background: var(--bg);
  border-radius: 99px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #d4bc94);
  border-radius: 99px;
  min-width: 2px;
}

.interval-row {
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}

.interval-row:last-child { border-bottom: none; }
.interval-row .item { font-weight: 600; }
.interval-row .iv { color: var(--accent); font-size: 0.78rem; font-family: 'IBM Plex Mono', monospace; }
.interval-row .nt { color: var(--muted); font-size: 0.78rem; margin-top: 0.15rem; }

.hidden { display: none !important; }

@media (min-width: 720px) {
  .modal-backdrop { align-items: center; padding: 1rem; }
  .modal {
    border-radius: 18px;
    border-bottom: 1px solid var(--border);
    max-height: 90dvh;
  }
}

/* ─── Vehicle photo identity ─── */
.vehicle-tabs button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.4rem 0.35rem;
}

.vehicle-tabs .tab-thumb {
  width: 1.65rem;
  height: 1.65rem;
  border-radius: 50%;
  object-fit: cover;
  border: 1.5px solid var(--border);
  flex-shrink: 0;
  background: var(--bg);
}

.vehicle-tabs button.active .tab-thumb {
  border-color: currentColor;
  box-shadow: 0 0 0 2px rgba(196, 165, 116, 0.2);
}

.vehicle-tabs button[data-id='fleet'] .tab-fleet-stack {
  display: flex;
  width: 1.85rem;
  height: 1.65rem;
  position: relative;
}

.vehicle-tabs .tab-fleet-stack img {
  width: 1.35rem;
  height: 1.35rem;
  border-radius: 50%;
  object-fit: cover;
  border: 1.5px solid var(--border);
  position: absolute;
  top: 0.15rem;
  background: var(--bg);
}

.vehicle-tabs .tab-fleet-stack img:first-child { left: 0; z-index: 1; }
.vehicle-tabs .tab-fleet-stack img:last-child { right: 0; z-index: 2; }
.vehicle-tabs button[data-id='fleet'].active .tab-fleet-stack img {
  border-color: var(--accent);
}

/* Hero banner on dashboard */
.hero {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 0.75rem;
  border: 1px solid var(--border);
  min-height: 160px;
  background: var(--surface-2);
}

.hero img.hero-photo {
  width: 100%;
  height: 180px;
  object-fit: cover;
  object-position: center 45%;
  display: block;
}

.hero-overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(
    to top,
    rgba(12, 16, 23, 0.92) 0%,
    rgba(12, 16, 23, 0.45) 45%,
    rgba(12, 16, 23, 0.15) 100%
  );
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 0.9rem 1rem 1rem;
}

.hero-overlay .code {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 0.15rem;
}

.hero-overlay h2 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  text-transform: none;
  color: var(--fg);
}

.hero-overlay .sub {
  font-size: 0.82rem;
  color: var(--muted);
  margin-top: 0.2rem;
}

.hero-stats {
  display: flex;
  gap: 0.75rem;
  margin-top: 0.55rem;
  flex-wrap: wrap;
}

.hero-stats span {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.78rem;
  color: var(--fg);
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.08);
  padding: 0.2rem 0.5rem;
  border-radius: 6px;
}

/* Fleet dual hero */
.fleet-hero {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.fleet-hero .hero {
  margin-bottom: 0;
  min-height: 0;
}

.fleet-hero .hero img.hero-photo {
  height: 120px;
}

.fleet-hero .hero-overlay h2 {
  font-size: 0.95rem;
}

/* Row card with vehicle chip */
.row-card {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.65rem;
  align-items: start;
}

.row-card .row-thumb {
  width: 2.6rem;
  height: 2.6rem;
  border-radius: 10px;
  object-fit: cover;
  border: 1px solid var(--border);
  background: var(--bg);
}

.row-card .row-body { min-width: 0; }

.veh-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.68rem;
  font-weight: 700;
  padding: 0.12rem 0.4rem;
  border-radius: 6px;
  letter-spacing: 0.02em;
}

.veh-chip.hzj76 {
  color: var(--hzj);
  background: rgba(96, 165, 250, 0.12);
  border: 1px solid rgba(96, 165, 250, 0.35);
}

.veh-chip.hj60 {
  color: var(--hj60);
  background: rgba(167, 139, 250, 0.12);
  border: 1px solid rgba(167, 139, 250, 0.35);
}

/* Fleet summary strip on list pages */
.fleet-strip {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  margin-bottom: 0.85rem;
}

.fleet-strip .pill {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.65rem 0.75rem;
}

.fleet-strip .pill .lbl {
  font-size: 0.68rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
}

.fleet-strip .pill .val {
  font-family: 'IBM Plex Mono', monospace;
  font-weight: 700;
  font-size: 0.95rem;
  margin-top: 0.15rem;
}

.fleet-banner {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: linear-gradient(135deg, rgba(196, 165, 116, 0.12), rgba(96, 165, 250, 0.08));
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.75rem;
  margin-bottom: 0.85rem;
}

.fleet-banner .stack {
  display: flex;
  flex-shrink: 0;
}

.fleet-banner .stack img {
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--surface);
  margin-left: -0.55rem;
}

.fleet-banner .stack img:first-child { margin-left: 0; }

.fleet-banner .txt { font-size: 0.82rem; color: var(--muted); line-height: 1.35; }
.fleet-banner .txt strong { color: var(--fg); display: block; font-size: 0.9rem; margin-bottom: 0.1rem; }

.section-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--dim);
  margin: 1rem 0 0.5rem;
}

.lock-card .lock-photos {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  margin-bottom: 1.1rem;
}

.lock-card .lock-photos img {
  width: 4.5rem;
  height: 4.5rem;
  border-radius: 14px;
  object-fit: cover;
  border: 1px solid var(--border);
  box-shadow: 0 8px 20px rgba(0,0,0,0.35);
}
