/*
 * CRI Parco Mezzi — Stili frontend
 * Branding CRI, layout responsive (mobile + desktop), componenti custom.
 *
 * Breakpoint: mobile < 768px; desktop ≥ 768px (Tailwind md:)
 */

/* ============================================================
   Reset base
   ============================================================ */
*, *::before, *::after {
  box-sizing: border-box;
}

/* ============================================================
   Safe area iOS (notch, home bar) — solo mobile
   ============================================================ */
.safe-top {
  padding-top: max(0.75rem, env(safe-area-inset-top));
}
.safe-bottom {
  padding-bottom: max(0.5rem, env(safe-area-inset-bottom));
}

/* ============================================================
   Scrollbar
   ============================================================ */
#app-content {
  scrollbar-width: thin;
  scrollbar-color: #e5e7eb transparent;
}
#app-content::-webkit-scrollbar {
  width: 5px;
}
#app-content::-webkit-scrollbar-thumb {
  background: #d1d5db;
  border-radius: 3px;
}

/* ============================================================
   Sidebar navigazione (desktop)
   ============================================================ */
#sidebar-nav .sidebar-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0.75rem;
  border-radius: 0.625rem;
  color: #6b7280;
  font-size: 0.875rem;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  transition: background 0.12s, color 0.12s;
}
#sidebar-nav .sidebar-item svg {
  width: 1.25rem;
  height: 1.25rem;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}
#sidebar-nav .sidebar-item:hover {
  background: #f9fafb;
  color: #374151;
}
#sidebar-nav .sidebar-item.active {
  background: #FFF0F0;
  color: #E30613;
}
/* CTA button in sidebar */
#sidebar-nav .sidebar-item.sidebar-cta {
  background: #E30613;
  color: #fff;
  margin-top: 0.5rem;
  font-weight: 600;
}
#sidebar-nav .sidebar-item.sidebar-cta:hover {
  background: #B30010;
}
#sidebar-nav .sidebar-item.sidebar-cta.active {
  background: #B30010;
}

/* ============================================================
   Bottom nav (mobile) — invariato
   ============================================================ */
#bottom-nav {
  background: #fff;
  border-top: 1px solid #f3f4f6;
  display: flex;
  align-items: stretch;
  box-shadow: 0 -4px 12px rgba(0,0,0,.06);
}
.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.2rem;
  padding: 0.6rem 0;
  color: #9ca3af;
  font-size: 0.65rem;
  font-weight: 500;
  text-decoration: none;
  transition: color 0.15s;
  cursor: pointer;
  border: none;
  background: none;
  letter-spacing: 0.01em;
}
.nav-item svg {
  width: 1.4rem;
  height: 1.4rem;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: stroke 0.15s;
}
.nav-item.active {
  color: #E30613;
}
.nav-item.nav-cta {
  flex: 0 0 4.5rem;
}
.nav-cta-inner {
  width: 3rem;
  height: 3rem;
  border-radius: 9999px;
  background: #E30613;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 0.2rem;
  box-shadow: 0 4px 10px rgba(227,6,19,.35);
  transition: background 0.15s, transform 0.1s;
}
.nav-item.nav-cta:hover .nav-cta-inner {
  background: #B30010;
  transform: scale(1.05);
}
.nav-item.nav-cta svg {
  width: 1.4rem;
  height: 1.4rem;
  color: #fff;
}
.nav-cta-label {
  font-size: 0.6rem;
  color: #E30613;
  font-weight: 600;
}

/* ============================================================
   Carte / Card generiche
   ============================================================ */
.cri-card {
  background: #fff;
  border-radius: 1rem;
  padding: 1rem;
  box-shadow: 0 1px 4px rgba(0,0,0,.07);
  margin-bottom: 0.75rem;
}
/* Su desktop, le card nelle liste possono essere piu' compatte */
@media (min-width: 768px) {
  .cri-card-row {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.875rem 1.25rem;
    border-radius: 0.75rem;
    margin-bottom: 0.5rem;
  }
}

/* ============================================================
   Badge stati corsa
   ============================================================ */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.6rem;
  border-radius: 9999px;
  font-size: 0.7rem;
  font-weight: 600;
  white-space: nowrap;
  letter-spacing: 0.01em;
}
.badge-bozza       { background: #f3f4f6; color: #6b7280; }
.badge-in_attesa   { background: #fef9c3; color: #a16207; }
.badge-approvata   { background: #dbeafe; color: #1d4ed8; }
.badge-in_corso    { background: #d1fae5; color: #065f46; }
.badge-completata  { background: #d1fae5; color: #065f46; }
.badge-rifiutata   { background: #fee2e2; color: #b91c1c; }
.badge-annullata   { background: #f3f4f6; color: #9ca3af; }

/* ============================================================
   Pagamenti badge
   ============================================================ */
.badge-pag-non_richiesto { background: #f3f4f6; color: #9ca3af; }
.badge-pag-in_attesa     { background: #fef3c7; color: #b45309; }
.badge-pag-segnalato     { background: #dbeafe; color: #1e40af; }
.badge-pag-versato       { background: #d1fae5; color: #065f46; }

/* ============================================================
   Toast
   ============================================================ */
.cri-toast {
  padding: 0.65rem 1.25rem;
  border-radius: 0.75rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: #fff;
  pointer-events: auto;
  box-shadow: 0 8px 24px rgba(0,0,0,.18);
  animation: toast-in 0.25s ease;
  max-width: 280px;
  text-align: center;
}
.cri-toast-success { background: #059669; }
.cri-toast-error   { background: #dc2626; }
.cri-toast-info    { background: #1d4ed8; }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(10px) scale(0.95); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes toast-out {
  from { opacity: 1; transform: translateY(0); }
  to   { opacity: 0; transform: translateY(8px); }
}
.toast-hiding {
  animation: toast-out 0.2s ease forwards;
}

/* ============================================================
   Spinner personalizzato
   ============================================================ */
.cri-spinner {
  width: 2.5rem;
  height: 2.5rem;
  border: 3px solid #e5e7eb;
  border-top-color: #E30613;
  border-radius: 9999px;
  animation: cri-spin 0.7s linear infinite;
}
.cri-spinner-sm {
  width: 1.25rem;
  height: 1.25rem;
  border: 2px solid #e5e7eb;
  border-top-color: #E30613;
  border-radius: 9999px;
  animation: cri-spin 0.7s linear infinite;
}
@keyframes cri-spin {
  to { transform: rotate(360deg); }
}

/* ============================================================
   Loader di pagina
   ============================================================ */
.page-loader {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  min-height: 240px;
  gap: 0.75rem;
  color: #9ca3af;
  font-size: 0.875rem;
}

/* ============================================================
   Wizard steps
   ============================================================ */
.wizard-steps {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  margin-bottom: 1.5rem;
}
.wizard-step-dot {
  width: 2rem;
  height: 2rem;
  border-radius: 9999px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  border: 2px solid #e5e7eb;
  background: #fff;
  color: #9ca3af;
  transition: all 0.2s;
}
.wizard-step-dot.active {
  background: #E30613;
  border-color: #E30613;
  color: #fff;
}
.wizard-step-dot.done {
  background: #d1fae5;
  border-color: #059669;
  color: #059669;
}
.wizard-step-line {
  flex: 1;
  height: 2px;
  background: #e5e7eb;
  max-width: 2.5rem;
}
.wizard-step-line.done {
  background: #059669;
}

/* ============================================================
   Input stili base (complementa Tailwind)
   ============================================================ */
.cri-input {
  width: 100%;
  padding: 0.75rem 1rem;
  border-radius: 0.75rem;
  border: 1.5px solid #e5e7eb;
  background: #fff;
  font-size: 0.9375rem;
  color: #111827;
  transition: border-color 0.15s, box-shadow 0.15s;
  outline: none;
  -webkit-appearance: none;
}
.cri-input:focus {
  border-color: #E30613;
  box-shadow: 0 0 0 3px rgba(227,6,19,.12);
}
.cri-input::placeholder {
  color: #d1d5db;
}

/* ============================================================
   Pulsanti grandi (autista: km)
   ============================================================ */
.btn-km-big {
  flex: 1;
  padding: 1rem;
  border-radius: 1rem;
  font-size: 1rem;
  font-weight: 700;
  border: 2px solid #e5e7eb;
  background: #fff;
  color: #374151;
  cursor: pointer;
  transition: all 0.15s;
  text-align: center;
  -webkit-tap-highlight-color: transparent;
}
.btn-km-big.selected {
  border-color: #E30613;
  background: #FFF0F0;
  color: #E30613;
}

/* ============================================================
   Sezione KPI (dashboard struttura)
   ============================================================ */
.kpi-card {
  background: #fff;
  border-radius: 0.875rem;
  padding: 0.875rem 1rem;
  box-shadow: 0 1px 4px rgba(0,0,0,.07);
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}
.kpi-value {
  font-size: 1.75rem;
  font-weight: 800;
  color: #111827;
  line-height: 1;
}
.kpi-label {
  font-size: 0.7rem;
  color: #6b7280;
  font-weight: 500;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

/* ============================================================
   Profilo page
   ============================================================ */
.profile-avatar {
  width: 5rem;
  height: 5rem;
  border-radius: 9999px;
  background: #E30613;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.875rem;
  font-weight: 800;
  color: #fff;
  margin: 0 auto 1rem;
  box-shadow: 0 4px 12px rgba(227,6,19,.3);
}

/* ============================================================
   LAYOUT RESPONSIVE — Desktop (≥ 768px)
   ============================================================ */

@media (min-width: 768px) {

  /* KPI grid — 4 colonne invece di 2 */
  .kpi-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
  }
  .kpi-card {
    padding: 1.25rem;
  }
  .kpi-value {
    font-size: 2.25rem;
  }

  /* Corse list — layout tabella su desktop */
  .corse-table-header {
    display: grid;
    grid-template-columns: 100px 1fr 120px 100px 80px;
    gap: 0.75rem;
    padding: 0.5rem 1.25rem;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #9ca3af;
    border-bottom: 1px solid #f3f4f6;
    margin-bottom: 0.25rem;
  }
  .corse-table-row {
    display: grid;
    grid-template-columns: 100px 1fr 120px 100px 80px;
    gap: 0.75rem;
    padding: 0.75rem 1.25rem;
    align-items: center;
    background: #fff;
    border-radius: 0.625rem;
    margin-bottom: 0.375rem;
    font-size: 0.875rem;
    box-shadow: 0 1px 3px rgba(0,0,0,.04);
    cursor: pointer;
    transition: box-shadow 0.12s;
    color: inherit;
    text-decoration: none;
  }
  .corse-table-row:hover {
    box-shadow: 0 2px 8px rgba(0,0,0,.08);
  }

  /* Profilo desktop — layout a due colonne */
  .profile-desktop-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    align-items: start;
  }

  /* Contenuto desktop — padding extra */
  .desktop-padded {
    padding: 0;
  }

  /* Wizard su desktop: form piu' largo, centrato */
  .wizard-desktop {
    max-width: 640px;
    margin: 0 auto;
  }

  /* Dettaglio corsa — due colonne su desktop */
  .dettaglio-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem 2rem;
    align-items: start;
  }
  .dettaglio-full {
    grid-column: 1 / -1;
  }

  /* CTA actions row */
  .actions-row {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
  }
  .actions-row > * {
    flex: 1;
    min-width: 180px;
  }

  /* Nascondi elementi mobile-only su desktop */
  .mobile-only {
    display: none !important;
  }
}

/* Elementi desktop-only nascosti su mobile */
@media (max-width: 767px) {
  .desktop-only {
    display: none !important;
  }
}

/* ============================================================
   Bottom nav visibile solo su mobile
   ============================================================ */
@media (min-width: 768px) {
  #bottom-nav {
    display: none !important;
  }
}

/* ============================================================
   CRI Select — Componente select filtrabile (REQ-01)
   ============================================================ */
.cri-select-container {
  position: relative;
  width: 100%;
  font-family: inherit;
  user-select: none;
}
.cri-select-container.disabled {
  opacity: 0.6;
  pointer-events: none;
}
.cri-select-search {
  width: 100%;
  padding: 0.75rem 2.25rem 0.75rem 1rem;
  border-radius: 0.75rem;
  border: 1.5px solid #e5e7eb;
  background: #fff;
  font-size: 0.9375rem;
  color: #111827;
  outline: none;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
  -webkit-appearance: none;
}
.cri-select-search:focus {
  border-color: #E30613;
  box-shadow: 0 0 0 3px rgba(227,6,19,.12);
}
.cri-select-search::placeholder {
  color: #d1d5db;
}
.cri-select-arrow {
  position: absolute;
  right: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  color: #9ca3af;
  transition: transform 0.2s;
}
.cri-select-container.open .cri-select-arrow {
  transform: translateY(-50%) rotate(180deg);
}
.cri-select-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 0.25rem;
  background: #fff;
  border: 1.5px solid #e5e7eb;
  border-radius: 0.75rem;
  box-shadow: 0 12px 32px rgba(0,0,0,.12);
  overflow-y: auto;
  z-index: 100;
  max-height: 252px;
}
.cri-select-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.65rem 1rem;
  cursor: pointer;
  transition: background 0.1s;
  font-size: 0.9rem;
  color: #374151;
  gap: 0.5rem;
  min-height: 42px;
}
.cri-select-option:hover,
.cri-select-option.active {
  background: #fef2f2;
}
.cri-select-option.selected {
  background: #fff0f0;
  color: #E30613;
  font-weight: 600;
}
.cri-select-option.selected::after {
  content: '✓';
  font-size: 0.8rem;
  font-weight: 700;
  color: #E30613;
  flex-shrink: 0;
}
.cri-select-option-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cri-select-option-label mark {
  background: #fde68a;
  color: #92400e;
  font-weight: 600;
  border-radius: 2px;
  padding: 0 2px;
}
.cri-select-option-extra {
  font-size: 0.75rem;
  color: #9ca3af;
  flex-shrink: 0;
  max-width: 40%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cri-select-empty {
  padding: 1rem;
  text-align: center;
  color: #9ca3af;
  font-size: 0.85rem;
}

/* Mobile: dropdown a tutto schermo come modal */
@media (max-width: 767px) {
  .cri-select-dropdown {
    position: fixed;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    margin: 0;
    border-radius: 1rem 1rem 0 0;
    max-height: 50vh;
    box-shadow: 0 -8px 32px rgba(0,0,0,.15);
    border-bottom: none;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .cri-select-container.open::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,.3);
    z-index: 99;
    animation: fade-in 0.2s;
  }
  @keyframes fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
  }
}

/* ============================================================
   Link navigazione Google Maps (FEAT-04)
   ============================================================ */
.btn-maps-link {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.6rem 1rem;
  background: #4285F4;
  color: #fff;
  border-radius: 0.75rem;
  font-size: 0.875rem;
  font-weight: 600;
  text-decoration: none;
  transition: background 0.15s;
  white-space: nowrap;
}
.btn-maps-link:hover,
.btn-maps-link:active {
  background: #3367D6;
}
.btn-maps-link svg {
  width: 1rem;
  height: 1rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.5;
}

/* ============================================================
   Report & Pagamenti — filtri bar
   ============================================================ */
.filtri-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  padding: 0.75rem;
  background: #fff;
  border-radius: 0.75rem;
  margin-bottom: 1rem;
  box-shadow: 0 1px 3px rgba(0,0,0,.05);
}
.filtri-bar > * {
  flex: 1;
  min-width: 140px;
}

/* ============================================================
   Pagamenti card (ricevuta cumulativa)
   ============================================================ */
.pagamenti-summary {
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 0.75rem;
  padding: 1rem;
  margin-bottom: 1rem;
}

/* ============================================================
   Contenitori grafici Chart.js
   ============================================================ */
.chart-container {
  position: relative;
  width: 100%;
  max-height: 300px;
}
.chart-container canvas {
  width: 100% !important;
  max-height: 300px;
}
