@font-face {
  font-family: "Satoshi";
  src: url("../assets/fonts/Satoshi-Regular.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Satoshi";
  src: url("../assets/fonts/Satoshi-Bold.ttf") format("truetype");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

/* —— Light (default) —— */
:root,
html[data-theme="light"] {
  --red: #E31F26;
  --red-brand: #D2222A;
  --red-dim: #b51a20;
  --red-soft: #FDECEC;
  --chrome: #1A1A1A;
  --chrome-2: #222;
  --chrome-3: #2A2A2A;
  --chrome-border: #3A3A3A;
  --chrome-text: #F7F7F7;
  --chrome-muted: #9A9A9A;
  --bg: #E6E6E6;
  --bg-gradient: linear-gradient(180deg, #F5F5F5 0%, #E8E8E8 55%, #E0E0E0 100%);
  --surface: #FFFFFF;
  --surface-elevated: #FFFFFF;
  --border: #E4E4E4;
  --border-strong: #D0D0D0;
  --text: #1A1A1A;
  --muted: #6E6E6E;
  --ok: #1FA66A;
  --ok-soft: #E8F7EF;
  --danger: #E31F26;
  --btn-primary-bg: #1A1A1A;
  --btn-primary-hover: #2A2A2A;
  --btn-primary-active: #111111;
  --btn-primary-fg: #FFFFFF;
  --modal-scrim: rgba(26, 26, 26, 0.35);
  --theme-toggle-bg: rgba(26, 26, 26, 0.06);
  --theme-toggle-hover: rgba(26, 26, 26, 0.1);
  --radius: 10px;
  --tap: 48px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --header-bar: 64px; /* header content+pads excl. safe-top */
  --font: "Satoshi", "Segoe UI", system-ui, -apple-system, sans-serif;
  color-scheme: light;
}

/* —— Dark —— */
html[data-theme="dark"] {
  --red: #E31F26;
  --red-brand: #E31F26;
  --red-dim: #FF6B6F;
  --red-soft: rgba(227, 31, 38, 0.18);
  --chrome: #1A1A1A;
  --chrome-2: #222;
  --chrome-3: #2A2A2A;
  --chrome-border: #3A3A3A;
  --chrome-text: #F7F7F7;
  --chrome-muted: #8A8A8A;
  --bg: #242424;
  --bg-gradient: linear-gradient(180deg, #2A2A2A 0%, #242424 55%, #1F1F1F 100%);
  --surface: #2A2A2A;
  --surface-elevated: #303030;
  --border: #3A3A3A;
  --border-strong: #4A4A4A;
  --text: #F2F2F2;
  --muted: #9A9A9A;
  --ok: #3DCC8A;
  --ok-soft: rgba(31, 166, 106, 0.18);
  --danger: #E31F26;
  --btn-primary-bg: #E31F26;
  --btn-primary-hover: #C91B21;
  --btn-primary-active: #B0181D;
  --btn-primary-fg: #FFFFFF;
  --modal-scrim: rgba(0, 0, 0, 0.55);
  --theme-toggle-bg: rgba(255, 255, 255, 0.08);
  --theme-toggle-hover: rgba(255, 255, 255, 0.14);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font);
  background: var(--bg);
  background-image: var(--bg-gradient);
  background-attachment: fixed;
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  min-height: 100%;
  scroll-padding-top: calc(var(--header-bar) + var(--safe-top));
}

.app {
  min-height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  background: var(--surface);
  background-image: var(--bg-gradient);
  display: flex;
  flex-direction: column;
  padding-bottom: calc(24px + var(--safe-bottom));
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
}

.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: #FFFFFF;
  color: #1A1A1A;
  padding: calc(12px + var(--safe-top)) 16px 12px 20px;
  border-bottom: 1px solid #E31F26; /* thin brand red separator */
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

/* Dark theme: charcoal header matching logo plate (~#1e1e1e) */
html[data-theme="dark"] .header {
  background: #1e1e1e;
  color: #F7F7F7;
  border-bottom: 1px solid #E31F26; /* thin brand red separator */
}

html[data-theme="dark"] .header .theme-toggle {
  color: #F7F7F7;
  background: rgba(255, 255, 255, 0.08);
}

html[data-theme="dark"] .header .theme-toggle:hover {
  background: rgba(255, 255, 255, 0.14);
}

.brand {
  display: flex;
  gap: 14px;
  align-items: center;
  min-width: 0;
  flex: 1;
}

.brand-text { min-width: 0; }

.brand-logo {
  height: 40px;
  width: auto;
  max-width: 200px;
  object-fit: contain;
  display: block;
  flex-shrink: 0;
  border-radius: 6px;
}

/* Dark Drive white-plate logo has internal padding — bump height to match/exceed light */
.brand-logo.logo-for-dark {
  height: 63px;
  max-width: 281px;
}

/* Dual logos: light = red/black noslogan; dark = Drive white plate */
.logo-for-dark { display: none; }
.brand-logo.logo-for-dark,
.pin-logo.logo-for-dark { display: none; }
html[data-theme="dark"] .logo-for-light,
html[data-theme="dark"] .brand-logo.logo-for-light,
html[data-theme="dark"] .pin-logo.logo-for-light { display: none; }
html[data-theme="dark"] .logo-for-dark,
html[data-theme="dark"] .brand-logo.logo-for-dark,
html[data-theme="dark"] .pin-logo.logo-for-dark { display: block; }
html[data-theme="dark"] .logo-chip.logo-for-dark { display: inline-flex; }

/* Dark chrome chip behind white logo for contrast on white header / light PIN strip */
.logo-chip {
  display: none;
  align-items: center;
  justify-content: center;
  padding: 6px 10px;
  border-radius: 8px;
  background: #1A1A1A;
  flex-shrink: 0;
  line-height: 0;
}

.logo-chip .brand-logo,
.logo-chip .pin-logo {
  margin: 0;
  height: 28px;
  max-width: 160px;
}

.pin-logo-chip {
  margin: 0 auto 24px;
}

.pin-logo-chip .pin-logo {
  height: 36px;
  max-width: 200px;
  margin: 0;
}

.brand-mark {
  /* legacy fallback if img missing */
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: var(--chrome);
  color: var(--chrome-text);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 1.1rem;
}

.page-title {
  margin: 0 0 22px;
}

.page-title h1 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}

.subtitle {
  margin: 4px 0 0;
  font-size: 0.9rem;
  color: var(--muted);
  font-weight: 400;
}

/* —— Theme toggle —— */
.theme-toggle {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 999px;
  background: var(--theme-toggle-bg);
  color: var(--text);
  cursor: pointer;
  display: grid;
  place-items: center;
  font-size: 1.1rem;
  line-height: 1;
  padding: 0;
  transition: background 0.15s ease;
  font-family: inherit;
}

.theme-toggle:hover { background: var(--theme-toggle-hover); }
.theme-toggle:active { transform: scale(0.96); }

.theme-toggle .theme-icon { display: none; line-height: 1; }
html[data-theme="light"] .theme-toggle .theme-icon-moon { display: block; }
html[data-theme="dark"] .theme-toggle .theme-icon-sun { display: block; }

.theme-toggle--pin {
  position: absolute;
  top: calc(12px + var(--safe-top));
  right: 16px;
  z-index: 2;
}

.main {
  /* Header is sticky (in-flow); top padding is content inset, not under-header offset */
  padding: 24px 20px;
  padding-top: 24px;
  flex: 1;
}

.field {
  margin-bottom: 22px;
}

.field-row {
  display: flex;
  gap: 12px;
  margin-bottom: 22px;
}

.field-row .field {
  margin-bottom: 0;
  flex: 1;
}

.field-row .grow { flex: 1.3; }

label {
  display: block;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--muted);
  margin-bottom: 8px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.optional {
  font-weight: 400;
  color: var(--chrome-muted);
  text-transform: none;
  letter-spacing: 0;
}

input[type="text"],
input[type="number"],
input[type="date"],
input[type="search"],
input[type="password"],
textarea {
  width: 100%;
  min-height: var(--tap);
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 1rem;
  background: var(--surface-elevated);
  color: var(--text);
  appearance: none;
  -webkit-appearance: none;
  font-family: inherit;
  transition: border-color 0.15s ease;
}

input:focus, textarea:focus {
  outline: none;
  border-color: var(--text);
  box-shadow: none;
}

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

.input-prefix {
  display: flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-elevated);
  overflow: hidden;
  transition: border-color 0.15s ease;
}

.input-prefix:focus-within {
  border-color: var(--text);
  box-shadow: none;
}

.input-prefix span {
  padding: 0 0 0 14px;
  color: var(--muted);
  font-weight: 500;
}

.input-prefix input {
  border: none;
  box-shadow: none;
  min-height: var(--tap);
  background: transparent;
}

.input-prefix input:focus { box-shadow: none; }

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.chip {
  min-height: 40px;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--muted);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: border-color 0.12s ease, background 0.12s ease, color 0.12s ease;
}

.chip.active {
  background: var(--red-soft);
  border-color: var(--red);
  color: var(--red-dim);
}

.chip.recent {
  background: var(--surface-elevated);
  font-size: 0.8rem;
}

.select-list {
  max-height: 220px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-top: 8px;
  background: var(--surface-elevated);
  display: none;
}

.select-list.open { display: block; }

.opt-group {
  padding: 8px 12px 4px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  background: var(--bg);
  position: sticky;
  top: 0;
}

.opt {
  display: block;
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  border: none;
  border-bottom: 1px solid var(--border);
  background: var(--surface-elevated);
  font-size: 0.95rem;
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
  min-height: var(--tap);
}

.opt:last-child { border-bottom: none; }

.opt:active, .opt:hover { background: var(--bg); }

.opt .code {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 2px;
}

.selected-pill {
  margin-top: 8px;
  padding: 10px 14px;
  background: var(--red-soft);
  border: 1px solid rgba(227, 31, 38, 0.25);
  border-radius: var(--radius);
  color: var(--red-dim);
  font-weight: 600;
  font-size: 0.9rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.selected-pill button {
  border: none;
  background: transparent;
  color: var(--red);
  font-size: 0.8rem;
  cursor: pointer;
  padding: 4px 8px;
  font-family: inherit;
}

.ticket-box input[type="file"] {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  overflow: hidden;
}

.ticket-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 56px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--muted);
  font-weight: 500;
  cursor: pointer;
  margin: 0;
  transition: border-color 0.12s ease, color 0.12s ease;
}

.ticket-btn:hover {
  border-color: var(--red);
  color: var(--red-dim);
  background: var(--red-soft);
}

.ticket-icon { font-size: 1.25rem; }

.ticket-preview {
  margin-top: 10px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.ticket-preview img {
  width: 72px;
  height: 72px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.btn-text {
  border: none;
  background: none;
  color: var(--danger);
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.9rem;
  padding: 8px;
}

.btn-primary, .btn-secondary {
  display: block;
  width: 100%;
  min-height: 52px;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  line-height: 52px;
  letter-spacing: -0.01em;
}

.btn-primary {
  background: var(--btn-primary-bg);
  color: var(--btn-primary-fg);
  margin-top: 8px;
  box-shadow: none;
}

.btn-primary:hover { background: var(--btn-primary-hover); }
.btn-primary:active { background: var(--btn-primary-active); }

.btn-primary:disabled {
  opacity: 0.55;
  cursor: wait;
}

.btn-secondary {
  background: var(--surface-elevated);
  color: var(--text);
  border: 1px solid var(--border);
  margin-bottom: 10px;
}

.form-error {
  color: var(--danger);
  background: var(--red-soft);
  border: 1px solid rgba(227, 31, 38, 0.2);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 0.9rem;
  margin: 0 0 12px;
}

.history {
  margin-top: 32px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

.history h2 {
  margin: 0 0 12px;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.history-list li {
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

.history-list li:last-child { border-bottom: none; }

.history-list .amt {
  font-weight: 700;
  color: var(--text);
}

.history-list .meta {
  color: var(--muted);
  font-size: 0.8rem;
  margin-top: 2px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + var(--safe-bottom));
  transform: translateX(-50%);
  background: var(--chrome);
  color: var(--chrome-text);
  padding: 12px 18px;
  border-radius: 999px;
  font-size: 0.9rem;
  z-index: 50;
  max-width: 90vw;
}

html[data-theme="dark"] .toast {
  background: #2A2A2A;
  border: 1px solid var(--border);
}

.modal {
  position: fixed;
  inset: 0;
  background: var(--modal-scrim);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 40;
}

.modal[hidden] { display: none; }

.modal-card {
  background: var(--surface-elevated);
  border-radius: 12px;
  padding: 28px 22px;
  width: min(400px, 100%);
  text-align: center;
  border: 1px solid var(--border);
}

.modal-ok {
  width: 52px;
  height: 52px;
  margin: 0 auto 12px;
  border-radius: 50%;
  background: var(--ok-soft);
  color: var(--ok);
  display: grid;
  place-items: center;
  font-size: 1.4rem;
  font-weight: 700;
}

.modal-card h2 {
  margin: 0 0 8px;
  font-size: 1.2rem;
  letter-spacing: -0.02em;
  color: var(--text);
}

.modal-card p { color: var(--muted); margin: 0 0 16px; line-height: 1.45; }

.fallback-hint { font-size: 0.9rem !important; }

.fallback-actions { margin-bottom: 8px; }

@media (min-width: 481px) {
  body { padding: 32px 0; background: var(--bg); background-image: var(--bg-gradient); }
  .app {
    border-radius: 12px;
    min-height: calc(100dvh - 64px);
    overflow: hidden;
    border: 1px solid var(--border);
  }
}

/* —— PIN gate —— */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.pin-gate {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--bg);
  background-image: var(--bg-gradient);
  display: grid;
  place-items: center;
  padding: 24px 16px;
  padding-top: calc(24px + var(--safe-top));
  padding-bottom: calc(24px + var(--safe-bottom));
}

.pin-gate[hidden] { display: none; }

.pin-card {
  background: var(--surface-elevated);
  border-radius: 12px;
  padding: 24px 22px 20px;
  width: min(340px, 100%);
  text-align: center;
  border: 1px solid var(--border);
  box-shadow: none;
}

.pin-logo {
  height: 72px;
  width: auto;
  max-width: 200px;
  object-fit: contain;
  margin: 0 auto 24px;
  display: block;
  border-radius: 8px;
}

/* PIN: light = noslogan red/black; dark = Drive white plate */
.pin-logo-wrap {
  display: block;
  margin: 0 auto 0;
}

.pin-mark {
  margin: 0 auto 16px;
  background: var(--chrome);
  color: var(--chrome-text);
  border: none;
}

.pin-card h1 {
  margin: 0 0 6px;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}

.pin-hint {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 400;
}

.pin-card input[type="password"],
.pin-card input[type="text"] {
  text-align: center;
  letter-spacing: 0.2em;
  font-size: 1.2rem;
  font-weight: 600;
  margin-bottom: 12px;
}

.pin-card .btn-primary {
  margin-top: 4px;
}

.pin-card .form-error {
  text-align: left;
}

.gps-hint {
  margin: 0 0 14px;
  font-size: 0.75rem;
  color: var(--chrome-muted);
  text-align: center;
}
