/* ==========================================================================
   HAULPAY — Design tokens
   Grounded in the subject: oilfield/bulk-hauling. Dark asphalt surfaces,
   safety-amber (hazard signage), condensed DOT-sign type, and a live
   digital hour-meter as the signature element — the one gauge every
   driver already reads all day.
   ========================================================================== */

:root {
  /* Surfaces */
  --bg-base: #15181a;
  --bg-panel: #1e2225;
  --bg-panel-raised: #272c2f;
  --bg-inset: #101314;

  /* Ticket / paper (used for receipt-style cards, always paper-colored even in dark theme) */
  --paper: #f2ede2;
  --paper-shadow: #d8d0bd;
  --ink: #1c1a16;
  --ink-soft: #4a453c;

  /* Accents */
  --amber: #e8720c;
  --amber-bright: #ff8f3d;
  --amber-ink: #2b1400;
  --steel: #57707e;
  --steel-light: #8aa2ae;
  --warn: #f4b740;
  --go: #4c9a5b;
  --danger: #c4452b;

  /* Text */
  --text-primary: #f2efe7;
  --text-secondary: #a8afb3;
  --text-tertiary: #6b7378;
  --text-on-amber: #2b1400;

  /* Type */
  --font-display: 'Oswald', 'Arial Narrow', 'Helvetica Neue', sans-serif;
  --font-body: 'IBM Plex Sans', 'Segoe UI', system-ui, sans-serif;
  --font-mono: 'IBM Plex Mono', 'SFMono-Regular', Consolas, monospace;

  /* Scale */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;

  --shadow-panel: 0 1px 0 rgba(255,255,255,0.03) inset, 0 8px 24px rgba(0,0,0,0.35);
  --shadow-inset: inset 0 2px 6px rgba(0,0,0,0.55), inset 0 0 0 1px rgba(255,255,255,0.02);

  color-scheme: dark;
}

* { box-sizing: border-box; }

/* The native `hidden` attribute must always win over component classes like
   .btn/.stack/.center-empty that set their own `display` — same selector
   specificity as the UA stylesheet's [hidden] rule means the last one
   declared would otherwise win, which is whichever component class happens
   to load after it. Force the correct outcome explicitly. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg-base);
  color: var(--text-primary);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  height: 100%;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  padding-bottom: env(safe-area-inset-bottom);
}

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  position: relative;
  background: var(--bg-base);
}

h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: 0.01em;
  margin: 0;
  text-transform: uppercase;
  color: var(--text-primary);
}

p { margin: 0; line-height: 1.5; }

a { color: var(--amber-bright); }

button, input, select, textarea { font-family: inherit; }

:focus-visible {
  outline: 2px solid var(--amber-bright);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

/* ==========================================================================
   Top bar
   ========================================================================== */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-4) var(--space-3);
  padding-top: max(var(--space-4), env(safe-area-inset-top));
  position: sticky;
  top: 0;
  z-index: 20;
  background: linear-gradient(var(--bg-base) 70%, transparent);
}

.topbar__left {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.topbar__back {
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 22px;
  line-height: 1;
  padding: var(--space-2);
  margin-left: calc(var(--space-2) * -1);
  cursor: pointer;
}

.brand {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-primary);
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.brand__mark { color: var(--amber); }

.screen-title {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.08em;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-tertiary);
  display: inline-block;
  flex-shrink: 0;
}
.status-dot[data-state="online"] { background: var(--go); box-shadow: 0 0 0 3px rgba(76,154,91,0.18); }
.status-dot[data-state="offline"] { background: var(--warn); box-shadow: 0 0 0 3px rgba(244,183,64,0.18); }

.topbar__status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-family: var(--font-mono);
}

.icon-btn {
  background: var(--bg-panel);
  border: 1px solid rgba(255,255,255,0.06);
  color: var(--text-secondary);
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.icon-btn svg { width: 18px; height: 18px; }

/* ==========================================================================
   Screens
   ========================================================================== */

.screen {
  flex: 1;
  display: none;
  flex-direction: column;
  padding: 0 var(--space-4) var(--space-7);
  gap: var(--space-5);
}
.screen.is-active { display: flex; }

.section-label {
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-tertiary);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.section-label::after {
  content: '';
  flex: 1;
  height: 1px;
  background: rgba(255,255,255,0.08);
}

/* ==========================================================================
   Buttons
   ========================================================================== */

.btn {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 15px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border: none;
  border-radius: var(--radius-md);
  padding: 16px 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  width: 100%;
  transition: transform 0.08s ease, filter 0.15s ease;
  min-height: 52px;
}
.btn:active { transform: scale(0.985); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn--primary {
  background: var(--amber);
  color: var(--text-on-amber);
}
.btn--primary:hover { filter: brightness(1.08); }

.btn--danger {
  background: var(--danger);
  color: #fff;
}

.btn--secondary {
  background: var(--bg-panel-raised);
  color: var(--text-primary);
  border: 1px solid rgba(255,255,255,0.08);
}

.btn--ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid rgba(255,255,255,0.12);
}

.btn--sm {
  padding: 10px 14px;
  font-size: 13px;
  min-height: 40px;
  width: auto;
}

.btn-row { display: flex; gap: var(--space-3); }
.btn-row .btn { flex: 1; }

/* ==========================================================================
   Cards / panels
   ========================================================================== */

.panel {
  background: var(--bg-panel);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  box-shadow: var(--shadow-panel);
  border: 1px solid rgba(255,255,255,0.04);
}

/* ==========================================================================
   Signature element: the hour-meter
   ========================================================================== */

.meter {
  background: var(--bg-inset);
  border-radius: var(--radius-lg);
  padding: var(--space-6) var(--space-4);
  box-shadow: var(--shadow-inset);
  text-align: center;
  position: relative;
  overflow: hidden;
}

.meter__site {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-bottom: var(--space-1);
}

.meter__since {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-tertiary);
  margin-bottom: var(--space-4);
}

.meter__display {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 52px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--text-primary);
  text-shadow: 0 0 24px rgba(232,114,12,0.25);
  line-height: 1;
}

.meter__track {
  height: 6px;
  border-radius: 3px;
  background: rgba(255,255,255,0.06);
  margin-top: var(--space-4);
  overflow: hidden;
}
.meter__fill {
  height: 100%;
  background: var(--steel-light);
  width: 0%;
  transition: width 1s linear, background-color 0.4s ease;
}
.meter__fill[data-state="accruing"] { background: var(--amber); }
.meter__fill[data-state="capped"] { background: var(--warn); }

.meter__note {
  margin-top: var(--space-3);
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-secondary);
}
.meter__note[data-state="accruing"] { color: var(--amber-bright); }
.meter__note[data-state="capped"] { color: var(--warn); }

.meter__amount {
  font-family: var(--font-mono);
  font-size: 28px;
  font-weight: 600;
  color: var(--go);
  margin-top: var(--space-2);
}

/* pulse only used sparingly, near cap — respects reduced motion via global rule above */
@keyframes pulse-ring {
  0%, 100% { box-shadow: 0 0 0 0 rgba(244,183,64,0.35); }
  50% { box-shadow: 0 0 0 8px rgba(244,183,64,0); }
}
.meter--nearcap { animation: pulse-ring 2s ease-in-out infinite; }

/* ==========================================================================
   Idle / not-checked-in state
   ========================================================================== */

.idle-card {
  text-align: center;
  padding: var(--space-6) var(--space-4);
}
.idle-card__glyph {
  width: 56px;
  height: 56px;
  margin: 0 auto var(--space-4);
  color: var(--steel-light);
}
.idle-card__title {
  font-size: 18px;
  margin-bottom: var(--space-2);
}
.idle-card__body {
  color: var(--text-secondary);
  font-size: 14px;
  max-width: 32ch;
  margin: 0 auto var(--space-5);
}

/* ==========================================================================
   Ticket motif (history entries + invoice)
   ========================================================================== */

.ticket {
  background: var(--paper);
  color: var(--ink);
  border-radius: var(--radius-md);
  position: relative;
  padding: var(--space-4);
  font-family: var(--font-mono);
  box-shadow: 0 4px 10px rgba(0,0,0,0.25);
}

.ticket::before {
  content: '';
  position: absolute;
  top: -6px;
  left: 0;
  right: 0;
  height: 12px;
  background:
    radial-gradient(circle at 8px 6px, transparent 5px, var(--bg-base) 5.5px) top left / 16px 12px repeat-x,
    var(--paper);
  border-radius: var(--radius-md) var(--radius-md) 0 0;
}

.ticket__row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: var(--space-1);
}
.ticket__client {
  font-family: var(--font-display);
  text-transform: uppercase;
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
}
.ticket__date { font-size: 11px; color: var(--ink-soft); }
.ticket__meta { font-size: 12px; color: var(--ink-soft); display: flex; gap: var(--space-3); flex-wrap: wrap; }
.ticket__amount {
  font-size: 22px;
  font-weight: 600;
  color: var(--ink);
  margin-top: var(--space-2);
}
.ticket__badge {
  display: inline-block;
  font-family: var(--font-body);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 3px 8px;
  border-radius: 999px;
  font-weight: 600;
}
.ticket__badge--pending { background: rgba(244,183,64,0.25); color: #7a5205; }
.ticket__badge--invoiced { background: rgba(87,112,126,0.25); color: #33454e; }
.ticket__badge--paid { background: rgba(76,154,91,0.22); color: #235c2e; }

.ticket-list { display: flex; flex-direction: column; gap: var(--space-4); }
.ticket-btn { all: unset; cursor: pointer; display: block; width: 100%; }

/* ==========================================================================
   Forms
   ========================================================================== */

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
  font-family: var(--font-mono);
}
.field input, .field select {
  background: var(--bg-inset);
  border: 1px solid rgba(255,255,255,0.08);
  color: var(--text-primary);
  border-radius: var(--radius-sm);
  padding: 13px 14px;
  font-size: 16px;
  font-family: var(--font-mono);
  width: 100%;
  min-width: 0;
}
.field input::placeholder { color: var(--text-tertiary); }
.field-hint { font-size: 11px; color: var(--text-tertiary); }
.field-row { display: flex; gap: var(--space-3); }
.field-row .field { flex: 1; }

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) 0;
  border-top: 1px solid rgba(255,255,255,0.06);
}
.toggle-row__label { font-size: 14px; }
.toggle-row__hint { font-size: 12px; color: var(--text-tertiary); margin-top: 2px; }

.switch {
  position: relative;
  width: 44px;
  height: 26px;
  flex-shrink: 0;
}
.switch input { opacity: 0; width: 100%; height: 100%; position: absolute; margin: 0; cursor: pointer; }
.switch__track {
  position: absolute; inset: 0;
  background: var(--bg-inset);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 999px;
  transition: background 0.15s ease;
}
.switch__thumb {
  position: absolute; top: 3px; left: 3px;
  width: 18px; height: 18px;
  background: var(--text-secondary);
  border-radius: 50%;
  transition: transform 0.15s ease, background 0.15s ease;
}
.switch input:checked + .switch__track { background: rgba(232,114,12,0.25); border-color: var(--amber); }
.switch input:checked + .switch__track + .switch__thumb { transform: translateX(18px); background: var(--amber); }

/* ==========================================================================
   List rows (profiles, settings)
   ========================================================================== */

.list-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4);
  background: var(--bg-panel);
  border-radius: var(--radius-md);
  border: 1px solid rgba(255,255,255,0.04);
}
.list-row + .list-row { margin-top: var(--space-2); }
.list-row__title { font-size: 15px; font-weight: 500; }
.list-row__sub { font-size: 12px; color: var(--text-tertiary); font-family: var(--font-mono); margin-top: 2px; }
.list-row__chevron { color: var(--text-tertiary); }
.list-stack { display: flex; flex-direction: column; }

/* ==========================================================================
   Bottom sheet / modal
   ========================================================================== */

.sheet-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 40;
  display: none;
}
.sheet-backdrop.is-active { display: block; }

.sheet {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  background: var(--bg-panel-raised);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: var(--space-5) var(--space-4) calc(var(--space-6) + env(safe-area-inset-bottom));
  z-index: 41;
  display: none;
  flex-direction: column;
  gap: var(--space-4);
  max-height: 85vh;
  overflow-y: auto;
}
.sheet.is-active { display: flex; }
.sheet__handle {
  width: 36px; height: 4px;
  background: rgba(255,255,255,0.15);
  border-radius: 2px;
  margin: 0 auto;
}
.sheet__title { font-size: 17px; }

/* ==========================================================================
   Toast
   ========================================================================== */

.toast {
  position: fixed;
  bottom: calc(var(--space-5) + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(8px);
  background: var(--bg-panel-raised);
  border: 1px solid rgba(255,255,255,0.1);
  color: var(--text-primary);
  padding: 12px 18px;
  border-radius: 999px;
  font-size: 13px;
  z-index: 60;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  max-width: 90%;
  text-align: center;
  box-shadow: 0 8px 20px rgba(0,0,0,0.4);
}
.toast.is-active { opacity: 1; transform: translateX(-50%) translateY(0); pointer-events: auto; }
.toast--danger { border-color: var(--danger); }

/* ==========================================================================
   PIN lock screen
   ========================================================================== */

.lock-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-5);
  padding: var(--space-6);
  text-align: center;
}
.pin-dots { display: flex; gap: 14px; }
.pin-dot {
  width: 16px; height: 16px;
  border-radius: 50%;
  border: 2px solid var(--steel-light);
  transition: background 0.1s ease, border-color 0.1s ease;
}
.pin-dot.is-filled { background: var(--amber); border-color: var(--amber); }
.pin-pad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-3);
  width: 100%;
  max-width: 280px;
}
.pin-key {
  background: var(--bg-panel);
  border: 1px solid rgba(255,255,255,0.06);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 22px;
  border-radius: var(--radius-md);
  aspect-ratio: 1;
  cursor: pointer;
}
.pin-key:active { background: var(--bg-panel-raised); }
.pin-key--ghost { background: none; border: none; }

/* ==========================================================================
   Camera preview thumbnails
   ========================================================================== */

.photo-strip { display: flex; gap: var(--space-2); flex-wrap: wrap; }
.photo-thumb {
  width: 64px; height: 64px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  border: 1px solid rgba(255,255,255,0.1);
}
.photo-add {
  width: 64px; height: 64px;
  border-radius: var(--radius-sm);
  border: 1px dashed rgba(255,255,255,0.25);
  display: flex; align-items: center; justify-content: center;
  color: var(--text-tertiary);
  background: none;
  cursor: pointer;
  font-size: 22px;
}

/* ==========================================================================
   Utility
   ========================================================================== */

.stack { display: flex; flex-direction: column; gap: var(--space-4); }
.row-between { display: flex; align-items: center; justify-content: space-between; }
.muted { color: var(--text-tertiary); }
.center-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: var(--space-3);
  padding: var(--space-6);
  color: var(--text-tertiary);
}
.visually-hidden {
  position: absolute; width: 1px; height: 1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap;
}

::-webkit-scrollbar { width: 0; height: 0; }
