/* Passaggio — stili. Pensati per il telefono, centrati su schermi grandi. */
:root {
  --primary: #6c4cf1;
  --primary-dark: #5235d6;
  --primary-soft: #ece7ff;
  --accent: #ffb020;
  --accent-soft: #fff3d6;
  --accent-text: #8a5a00;
  --bg: #f6f5fb;
  --card: #ffffff;
  --text: #1b1530;
  --muted: #6e6a80;
  --border: #e4e1ee;
  /* Abbastanza scuri da superare 4.5:1 col bianco e con i loro sfondi chiari (pulsanti, badge, testi d'errore). */
  --success: #137a50;
  --success-soft: #ddf5ea;
  --danger: #c2252b;
  --danger-soft: #fde4e4;
  --radius: 20px;
  --radius-sm: 14px;
  --shadow: 0 4px 16px rgba(27, 21, 48, 0.08);
  --tabbar-h: 64px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Apple Color Emoji',
    'Segoe UI Emoji', 'Noto Color Emoji', sans-serif;
  font-size: 16px;
  line-height: 1.4;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

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

.boot {
  display: grid;
  place-items: center;
  min-height: 100vh;
  font-size: 56px;
}

/* --- Struttura ---------------------------------------------------------- */
.page {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(16px + var(--safe-top)) 16px calc(var(--tabbar-h) + 32px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.page.no-tabs {
  padding-bottom: calc(32px + var(--safe-bottom));
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 40px;
}
.header .title {
  flex: 1;
}

.title {
  font-size: 28px;
  font-weight: 800;
  margin: 0;
  line-height: 1.15;
}
.section-title {
  font-size: 17px;
  font-weight: 700;
  margin: 0;
}
.muted {
  color: var(--muted);
  font-size: 14px;
  margin: 0;
}
.center {
  text-align: center;
}
.row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.row > .grow {
  flex: 1;
}
.stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: var(--shadow);
}
.card.highlight {
  outline: 2px solid var(--accent);
}
.card.success {
  background: var(--success-soft);
}
.card.hero {
  align-items: center;
  text-align: center;
}
.hero-emoji {
  font-size: 52px;
  line-height: 1.1;
}
.hero-title {
  font-size: 24px;
  font-weight: 800;
}
.hero-subtitle {
  color: var(--muted);
}

/* --- Controlli ---------------------------------------------------------- */
.btn {
  min-height: 48px;
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-weight: 700;
  font-size: 16px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-decoration: none; /* anche i link con l'aspetto di pulsante (navigatore) */
  transition: opacity 0.15s, transform 0.05s;
}
.btn:active {
  transform: scale(0.98);
}
.btn:disabled {
  opacity: 0.45;
  cursor: default;
}
.btn-big {
  min-height: 64px;
  font-size: 20px;
  border-radius: var(--radius);
}
.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-secondary {
  background: var(--card);
  color: var(--primary);
  border-color: var(--border);
}
.btn-ghost {
  background: transparent;
  color: var(--muted);
}
.btn-danger {
  background: var(--danger-soft);
  color: var(--danger);
}
.btn-success {
  background: var(--success);
  color: #fff;
}
.row > .btn {
  flex: 1;
}
/* Link del navigatore in fila (Google Maps, Waze, Mappe): su una riga sola anche su un telefono stretto. */
.row > a.btn {
  padding: 12px 8px;
  white-space: nowrap;
  font-size: 15px;
}

.link {
  background: none;
  border: 0;
  min-height: 44px; /* bersaglio comodo per il dito (Apple: 44px) */
  padding: 10px 0;
  color: var(--primary);
  font-weight: 700;
  cursor: pointer;
  text-align: left;
}
.link.back {
  padding-right: 12px;
}
a {
  color: var(--primary);
}
.close {
  background: none;
  border: 0;
  font-size: 26px;
  color: var(--muted);
  cursor: pointer;
  padding: 4px 8px;
  min-width: 44px;
  min-height: 44px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.chip {
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--card);
  border: 1.5px solid var(--border);
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
}
.chip-on {
  background: var(--primary-soft);
  border-color: var(--primary);
  color: var(--primary-dark);
}

.input {
  width: 100%;
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  font-size: 17px;
  outline: none;
}
.input:focus {
  border-color: var(--primary);
}
textarea.input {
  resize: vertical;
}
.code-input {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: 6px;
  text-align: center;
  text-transform: uppercase;
}
.code {
  font-size: 34px;
  font-weight: 900;
  letter-spacing: 8px;
  text-align: center;
  color: var(--primary);
  user-select: all;
}

/* Riga dell'interruttore: è tutta un <label>, quindi anche il testo lo cambia. */
.switch-row {
  min-height: 44px;
  cursor: pointer;
}
.switch {
  position: relative;
  display: inline-block;
  width: 52px;
  height: 32px;
  flex: none;
}
.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}
.slider {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 999px;
  transition: background 0.2s;
  cursor: pointer;
}
.slider::before {
  content: '';
  position: absolute;
  width: 26px;
  height: 26px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}
.switch input:checked + .slider {
  background: var(--success);
}
.switch input:checked + .slider::before {
  transform: translateX(20px);
}

.spinner {
  width: 20px;
  height: 20px;
  border: 3px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  display: inline-block;
  animation: spin 0.8s linear infinite;
}
.spinner.big {
  width: 36px;
  height: 36px;
  color: var(--primary);
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
.loading {
  display: grid;
  place-items: center;
  min-height: 40vh;
}

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 40px 0;
}
.empty-emoji {
  font-size: 56px;
}
.empty-title {
  font-size: 20px;
  font-weight: 800;
}

/* --- Ruoli (benvenuto) -------------------------------------------------- */
.roles {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.role {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 20px 12px;
  border-radius: var(--radius);
  background: var(--card);
  border: 2px solid var(--border);
  cursor: pointer;
}
.role.on {
  border-color: var(--primary);
  background: var(--primary-soft);
}
.role-emoji {
  font-size: 44px;
}
.role-title {
  font-weight: 800;
  font-size: 18px;
}
.role-subtitle {
  font-size: 13px;
  color: var(--muted);
}
.brand {
  text-align: center;
  padding: 24px 0 8px;
}
.brand-emoji {
  font-size: 64px;
}
.brand-name {
  font-size: 34px;
  font-weight: 900;
  color: var(--primary);
}

.tip {
  background: var(--accent-soft);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 14px;
  color: var(--accent-text);
}
.tip strong {
  color: var(--text);
}

/* --- Passaggi ----------------------------------------------------------- */
.route {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.route-line {
  width: 2px;
  height: 14px;
  background: var(--border);
  margin-left: 11px;
}
.stop {
  display: flex;
  gap: 8px;
  align-items: flex-start;
}
.stop-icon {
  width: 24px;
  text-align: center;
  font-size: 18px;
}
.stop-label {
  font-size: 17px;
  font-weight: 700;
}
.stop-address {
  font-size: 14px;
  color: var(--muted);
}
.route-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 8px;
  font-size: 14px;
  font-weight: 600;
}
.note {
  font-style: italic;
  color: var(--muted);
  margin: 4px 0 0;
}

.steps {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  gap: 4px;
  width: 100%;
}
.step {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.step-bar {
  height: 5px;
  border-radius: 999px;
  background: var(--border);
}
.step.done .step-bar {
  background: var(--primary);
}
.step-label {
  font-size: 11px;
  line-height: 1.15;
  color: var(--muted);
  text-align: center;
  white-space: normal; /* "Confermato" va a capo invece di essere tagliato */
  overflow-wrap: anywhere;
}
.step.current .step-label {
  color: var(--primary-dark);
  font-weight: 800;
}

.badge {
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}
.badge-pending {
  background: var(--accent-soft);
  color: var(--accent-text);
}
.badge-accepted,
.badge-en_route {
  background: var(--primary-soft);
  color: var(--primary-dark);
}
.badge-arrived,
.badge-onboard,
.badge-completed {
  background: var(--success-soft);
  color: var(--success);
}
.badge-declined {
  background: var(--danger-soft);
  color: var(--danger);
}
.badge-cancelled {
  background: var(--border);
  color: var(--muted);
}

.ride-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.ride-who {
  font-size: 20px;
  font-weight: 800;
}
.ride-when {
  font-size: 15px;
  font-weight: 700;
  color: var(--primary-dark);
}
.ride-urgent {
  font-size: 15px;
  font-weight: 700;
  color: var(--accent-text);
}

/* --- Mappa -------------------------------------------------------------- */
.map {
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--primary-soft);
  z-index: 0;
}
.map-pin {
  background: #fff;
  border: 2px solid var(--primary);
  border-radius: 50%;
  display: grid !important;
  place-items: center;
  font-size: 20px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
}
.map-pin-driver {
  border-color: var(--accent);
}
.map-pin-rider {
  border-color: var(--success);
}

/* --- Messaggi ----------------------------------------------------------- */
.messages {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.bubble {
  max-width: 85%;
  border-radius: var(--radius-sm);
  padding: 8px 12px;
}
.bubble.mine {
  align-self: flex-end;
  background: var(--primary);
  color: #fff;
}
.bubble.theirs {
  align-self: flex-start;
  background: var(--primary-soft);
}
.bubble-author {
  font-size: 12px;
  font-weight: 700;
  color: var(--primary-dark);
}
.bubble-text {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.bubble-time {
  font-size: 11px;
  opacity: 0.7;
  text-align: right;
}
.send {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 0;
  background: var(--primary);
  color: #fff;
  font-size: 20px;
  flex: none;
  cursor: pointer;
}

/* --- Prenotazione ------------------------------------------------------- */
.time-picker {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
}
.time {
  font-size: 40px;
  font-weight: 900;
  min-width: 120px;
  text-align: center;
}
.step-btn {
  background: var(--primary-soft);
  color: var(--primary-dark);
  border: 0;
  border-radius: var(--radius-sm);
  padding: 12px;
  min-width: 52px;
  font-weight: 800;
  cursor: pointer;
}

.found {
  color: var(--success);
  font-weight: 600;
  font-size: 15px;
  margin: 0;
}
.results {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.result {
  text-align: left;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  cursor: pointer;
}

/* --- Elenchi ------------------------------------------------------------ */
.list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.list-item .name {
  font-weight: 700;
}
.icon-btn {
  background: none;
  border: 0;
  font-size: 20px;
  cursor: pointer;
  padding: 4px;
  min-width: 44px;
  min-height: 44px;
}

/* --- Barra in basso, avvisi --------------------------------------------- */
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: calc(var(--tabbar-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: rgba(255, 255, 255, 0.96);
  -webkit-backdrop-filter: blur(10px); /* Safari iOS 17 vuole ancora il prefisso */
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: center;
  z-index: 1000;
}
.tab {
  flex: 1;
  max-width: 186px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: none;
  border: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.tab-icon {
  font-size: 22px;
  filter: grayscale(1);
  opacity: 0.6;
}
.tab.on {
  color: var(--primary);
}
.tab.on .tab-icon {
  filter: none;
  opacity: 1;
}

.toast {
  /* Centrato senza left: 50% (che lo limitava a metà schermo): largo quanto il testo, al massimo la pagina. */
  position: fixed;
  left: 16px;
  right: 16px;
  margin-inline: auto;
  width: fit-content;
  max-width: 528px;
  transform: none;
  bottom: calc(var(--tabbar-h) + 16px + var(--safe-bottom));
  background: var(--text);
  color: #fff;
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  z-index: 2000;
  box-shadow: var(--shadow);
  font-size: 15px;
}
.offline {
  position: sticky;
  top: 0;
  z-index: 1500;
  background: var(--accent-soft);
  color: var(--accent-text);
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  padding: calc(6px + var(--safe-top)) 12px 6px;
}
.offline + .page {
  padding-top: 16px;
}

@media (min-width: 600px) {
  .page {
    padding-top: 32px;
  }
}

/* === Aggiunte per le viste (17/10/2026) === */
/* Nota: .row, .stack, .chip, .badge-pending ed .empty esistono gia' sopra e
   restano invariati. Qui solo cio' che mancava. */

/* --- Utilita' ----------------------------------------------------------- */
.hidden {
  display: none !important;
}
.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;
}
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

/* --- Testi ausiliari (form) --------------------------------------------- */
.help-text {
  font-size: 13px;
  color: var(--muted);
  margin: 0;
}
.error-text {
  font-size: 13px;
  font-weight: 600;
  color: var(--danger);
  margin: 0;
}
.danger-text {
  color: var(--danger);
}
.input[aria-invalid='true'],
.select[aria-invalid='true'] {
  border-color: var(--danger);
}

/* --- Select e input data/ora (stessa resa di .input) -------------------- */
select {
  font: inherit;
  color: inherit;
}
.select,
input[type='time'],
input[type='date'],
input[type='datetime-local'] {
  width: 100%;
  min-height: 48px;
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  font-size: 17px; /* >= 16px: evita lo zoom automatico su iOS */
  line-height: 1.3;
  color: var(--text);
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}
.select {
  padding-right: 44px;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 22px) 50%, calc(100% - 16px) 50%;
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
  cursor: pointer;
}
.select:focus,
input[type='time']:focus,
input[type='date']:focus,
input[type='datetime-local']:focus {
  border-color: var(--primary);
}
/* Safari iOS: il campo data/ora e' un flex con altezza propria; forziamo riempimento. */
input[type='time'],
input[type='date'],
input[type='datetime-local'] {
  display: flex;
  align-items: center;
  min-width: 0;
}
input[type='time']::-webkit-date-and-time-value,
input[type='date']::-webkit-date-and-time-value,
input[type='datetime-local']::-webkit-date-and-time-value {
  text-align: left;
  min-height: 1.3em;
}

/* --- ETA grande --------------------------------------------------------- */
.eta-big {
  font-size: 44px;
  font-weight: 700;
  line-height: 1.1;
  color: var(--accent-text);
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.eta-label {
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  text-align: center;
  margin: 0;
}

/* --- Elenchi, chip, badge ----------------------------------------------- */
.list-item .meta {
  font-size: 13px;
  color: var(--muted);
}
.list-item.pending {
  background: var(--accent-soft);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}
.chip-warn {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent-text);
}
.badge-expired {
  background: var(--border);
  color: var(--muted);
}

/* --- Codice famiglia ---------------------------------------------------- */
.code-box {
  background: var(--primary-soft);
  border: 1.5px dashed var(--primary);
  border-radius: var(--radius-sm);
  padding: 16px 12px;
  text-align: center;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, 'Liberation Mono', monospace;
  font-size: 32px;
  font-weight: 800;
  letter-spacing: 8px;
  text-indent: 8px; /* compensa lo spazio finale del letter-spacing */
  color: var(--primary-dark);
  user-select: all;
  -webkit-user-select: all;
  word-break: break-all;
}
/* Codice di verifica accanto a una richiesta di ingresso (Famiglia): lo stesso numero che vede chi chiede. */
.verify {
  margin: 0;
  font-size: 15px;
}
.verify strong {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, 'Liberation Mono', monospace;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 4px;
  color: var(--primary-dark);
}
.code-expiry {
  font-size: 13px;
  color: var(--muted);
  text-align: center;
  margin: 0;
}

/* --- Pulsante flottante ------------------------------------------------- */
.fab {
  position: fixed;
  right: 16px;
  bottom: calc(var(--tabbar-h) + 16px + var(--safe-bottom));
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: 0;
  background: var(--primary);
  color: #fff;
  font-size: 28px;
  line-height: 1;
  display: grid;
  place-items: center;
  box-shadow: 0 6px 20px rgba(108, 76, 241, 0.4);
  cursor: pointer;
  z-index: 1100;
  transition: transform 0.05s;
}
.fab:active {
  transform: scale(0.95);
}
.page.no-tabs ~ .fab,
.no-tabs .fab {
  bottom: calc(16px + var(--safe-bottom));
}

/* --- Mappa: pin partenza/arrivo ----------------------------------------- */
.map-pin-pickup {
  border-color: var(--success);
}
.map-pin-dropoff {
  border-color: var(--danger);
}

/* --- Foglio dal basso (bottom sheet) ------------------------------------ */
.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(27, 21, 48, 0.5);
  z-index: 1800; /* sopra tabbar (1000), offline (1500) e fab (1100); sotto toast (2000) */
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: backdrop-in 0.15s ease-out;
}
.sheet {
  width: 100%;
  max-width: 560px;
  max-height: 85vh;
  max-height: 85dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  background: var(--card);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 12px 16px calc(16px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 -4px 24px rgba(27, 21, 48, 0.18);
  animation: sheet-in 0.2s ease-out;
}
.sheet::before {
  content: '';
  display: block;
  width: 40px;
  height: 4px;
  border-radius: 999px;
  background: var(--border);
  margin: 0 auto 4px;
  flex: none;
}
.sheet-title {
  font-size: 20px;
  font-weight: 800;
  margin: 0;
  line-height: 1.2;
}
.sheet-actions {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}
.sheet-actions > .btn {
  flex: 1;
}
@keyframes backdrop-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}
@keyframes sheet-in {
  from {
    transform: translateY(24px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}
@media (prefers-reduced-motion: reduce) {
  .backdrop,
  .sheet {
    animation: none;
  }
}
