/* =============================================================
   PIRULIN TRANSPORT — CSS
   Mobile-first, dark theme, dedos grandes, sol holandés.
   Acento: naranja #f0a500
   Fondo: #1a1a2e  Superficie: #16213e  Tarjeta: #0f3460
   Texto: #e0e0e0  Muted: #9a9aaa
   ============================================================= */

/* ----- RESET MÍNIMO ----------------------------------------- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* ----- TOKENS ----------------------------------------------- */
:root {
  --bg:          #1a1a2e;
  --surface:     #16213e;
  --card:        #0f3460;
  --accent:      #f0a500;
  --accent-dk:   #c98800;
  --danger:      #e05252;
  --success:     #4caf7d;
  --text:        #e0e0e0;
  --text-muted:  #9a9aaa;
  --border:      #2a2a4e;

  --radius-sm:   10px;
  --radius-md:   16px;
  --radius-lg:   24px;

  --space-1:     0.5rem;
  --space-2:     1rem;
  --space-3:     1.5rem;
  --space-4:     2rem;

  /* Input heights grandes para dedos */
  --input-h:     3.25rem;

  --trans:       0.2s ease;

  /* Fuente del sistema — sin descarga, legible, android+ios */
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* ----- BASE -------------------------------------------------- */
html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font);
  background-color: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  /* Padding bottom para que el último botón no quede bajo la barra iOS */
  padding-bottom: env(safe-area-inset-bottom, 1rem);
}

/* ----- CABECERA ---------------------------------------------- */
.app-header {
  background-color: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
  padding-top: env(safe-area-inset-top, 0);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
}

.app-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent);
  white-space: nowrap;
  flex-shrink: 0;
}

/* ----- NAVEGACIÓN TABS --------------------------------------- */
.screen-nav {
  display: flex;
  gap: var(--space-1);
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 3px;
}

.nav-btn {
  font-family: var(--font);
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-muted);
  background: transparent;
  border: none;
  border-radius: calc(var(--radius-sm) - 3px);
  padding: 0.45rem 0.9rem;
  cursor: pointer;
  transition: background var(--trans), color var(--trans);
  white-space: nowrap;
}

.nav-btn.active,
.nav-btn[aria-selected="true"] {
  background: var(--accent);
  color: #1a1a2e;
}

.nav-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ----- MAIN -------------------------------------------------- */
.app-main {
  padding: var(--space-3) var(--space-2);
  max-width: 480px;
  margin: 0 auto;
}

/* ----- SCREENS ---------------------------------------------- */
.screen { display: flex; flex-direction: column; gap: var(--space-3); }
.screen[hidden] { display: none; }

/* ----- TARJETA DE RESULTADO ---------------------------------- */
.result-card {
  background: var(--card);
  border-radius: var(--radius-lg);
  padding: var(--space-3) var(--space-2);
  text-align: center;
  border: 2px solid var(--border);
  transition: border-color var(--trans);
}

.result-card.has-result {
  border-color: var(--accent);
}

.result-label {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: var(--space-1);
}

.result-price {
  font-size: clamp(3rem, 15vw, 5rem);
  font-weight: 800;
  color: var(--accent);
  line-height: 1;
  letter-spacing: -0.02em;
}

.result-notice {
  margin-top: var(--space-1);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  min-height: 1.2em;
}

.result-notice.notice--minimo { color: var(--success); }
.result-notice.notice--warning { color: var(--danger); }

/* ----- DESGLOSE --------------------------------------------- */
.breakdown {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-2) var(--space-3);
}

.breakdown-title {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: var(--space-2);
}

.breakdown-list {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.6rem var(--space-2);
}

.breakdown-list dt {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.breakdown-list dd {
  text-align: right;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
}

.bd-total-label {
  color: var(--text) !important;
  font-weight: 700;
  border-top: 1px solid var(--border);
  padding-top: 0.6rem;
  margin-top: 0.2rem;
}

.bd-total-val {
  border-top: 1px solid var(--border);
  padding-top: 0.6rem;
  margin-top: 0.2rem;
  color: var(--accent) !important;
  font-size: 1rem !important;
  font-weight: 700;
}

/* ----- FIELDSETS / GRUPOS ------------------------------------ */
.field-group {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-2) var(--space-3);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.field-group-title {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding-bottom: var(--space-1);
  border-bottom: 1px solid var(--border);
  width: 100%;
}

/* ----- FILAS DE CAMPO --------------------------------------- */
.field-row {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.field-label {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.field-hint {
  font-size: 0.78rem;
  font-weight: 400;
  color: var(--text-muted);
}

.extra-amount {
  color: var(--accent);
  font-weight: 600;
}

/* ----- INPUTS ----------------------------------------------- */
.input-unit-wrap {
  display: flex;
  align-items: center;
  background: var(--bg);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  transition: border-color var(--trans);
}

.input-unit-wrap:focus-within {
  border-color: var(--accent);
}

.input-unit {
  padding: 0 0.75rem;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
  height: var(--input-h);
  display: flex;
  align-items: center;
  background: var(--surface);
  flex-shrink: 0;
}

.input-unit--prefix {
  border-right: 1px solid var(--border);
}

.field-input {
  font-family: var(--font);
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text);
  background: transparent;
  border: none;
  outline: none;
  height: var(--input-h);
  width: 100%;
  min-width: 0;
  padding: 0 0.75rem;
  /* Quitar flechas en number inputs — poco espacio en móvil */
  -moz-appearance: textfield;
}

.field-input--prefixed {
  padding-left: 0.5rem;
}

.field-input::-webkit-outer-spin-button,
.field-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

/* ----- TOGGLE SWITCH ---------------------------------------- */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  min-height: 2.5rem;
}

.toggle-label {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  flex: 1;
}

.toggle-btn {
  flex-shrink: 0;
  width: 3.2rem;
  height: 1.8rem;
  border-radius: 999px;
  background: var(--border);
  border: 2px solid transparent;
  cursor: pointer;
  position: relative;
  transition: background var(--trans), border-color var(--trans);
  padding: 0;
}

.toggle-btn[aria-checked="true"] {
  background: var(--accent);
}

.toggle-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.toggle-thumb {
  position: absolute;
  top: 50%;
  left: 3px;
  transform: translateY(-50%);
  width: 1.2rem;
  height: 1.2rem;
  border-radius: 50%;
  background: #fff;
  transition: left var(--trans);
  pointer-events: none;
}

.toggle-btn[aria-checked="true"] .toggle-thumb {
  left: calc(100% - 1.2rem - 3px);
}

/* ----- INPUT FULL WIDTH ------------------------------------ */
.field-input--full {
  width: 100%;
  height: var(--input-h);
  background: var(--bg);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 1rem;
  font-family: var(--font);
  padding: 0 0.75rem;
  transition: border-color var(--trans);
}

.field-input--full:focus {
  outline: none;
  border-color: var(--accent);
}

/* ----- BOTÓN CALCULAR RUTA ---------------------------------- */
.btn-ruta {
  font-family: var(--font);
  font-size: 1rem;
  font-weight: 700;
  color: var(--bg);
  background: var(--accent);
  border: none;
  border-radius: var(--radius-sm);
  height: 2.75rem;
  width: 100%;
  margin: var(--space-1) 0;
  cursor: pointer;
  transition: background var(--trans);
  -webkit-tap-highlight-color: transparent;
}

.btn-ruta:active { background: var(--accent-dk); }
.btn-ruta:disabled {
  background: var(--text-muted);
  cursor: not-allowed;
}

/* ----- ESTADO Y RESULTADO RUTA ------------------------------ */
.ruta-estado {
  font-size: 0.9rem;
  color: var(--text-muted);
  text-align: center;
  padding: 0.25rem 0;
}

.ruta-resultado {
  display: flex;
  gap: var(--space-2);
  background: rgba(240, 165, 0, 0.08);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: var(--space-1) var(--space-2);
  margin: var(--space-1) 0;
}

.ruta-dato {
  display: flex;
  flex-direction: column;
  flex: 1;
}

.ruta-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.ruta-valor {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent);
}

/* ----- FILA MANUAL (fallback) ------------------------------- */
.manual-row {
  border-top: 1px dashed var(--border);
  padding-top: var(--space-1);
  margin-top: var(--space-1);
}

/* ----- STEPPERS (frágil, ayudante) -------------------------- */
.stepper-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--border);
  gap: var(--space-2);
}

.stepper-label {
  font-size: 1rem;
  color: var(--text);
  line-height: 1.3;
}

.stepper-controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
}

.stepper-btn {
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 50%;
  border: 2px solid var(--accent);
  background: transparent;
  color: var(--accent);
  font-size: 1.5rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  transition: background var(--trans), color var(--trans);
  -webkit-tap-highlight-color: transparent;
}

.stepper-btn:active {
  background: var(--accent);
  color: var(--bg);
}

.stepper-btn:disabled {
  border-color: var(--text-muted);
  color: var(--text-muted);
  cursor: not-allowed;
}

.stepper-value {
  min-width: 1.5rem;
  text-align: center;
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text-muted);
  transition: color var(--trans);
}

.stepper-value.active {
  color: var(--accent);
}

/* ----- WARNING PESO ----------------------------------------- */
.warning-peso {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--danger);
  padding: 0.5rem 0.75rem;
  background: rgba(224, 82, 82, 0.12);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--danger);
}

/* ----- BOTÓN COPIAR WHATSAPP -------------------------------- */
.btn-copiar {
  font-family: var(--font);
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--accent);
  background: transparent;
  border: 2px solid var(--accent);
  border-radius: var(--radius-md);
  height: 2.75rem;
  width: 100%;
  margin-top: var(--space-2);
  cursor: pointer;
  letter-spacing: 0.02em;
  transition: background var(--trans), color var(--trans);
  -webkit-tap-highlight-color: transparent;
}

.btn-copiar:active {
  background: var(--accent);
  color: var(--bg);
}

.copiar-ok {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--success);
  text-align: center;
  margin-top: 0.4rem;
}

/* ----- BOTONES PRINCIPALES ---------------------------------- */
.btn-calcular {
  font-family: var(--font);
  font-size: 1.1rem;
  font-weight: 800;
  color: #1a1a2e;
  background: var(--accent);
  border: none;
  border-radius: var(--radius-md);
  height: 3.5rem;
  width: 100%;
  cursor: pointer;
  letter-spacing: 0.02em;
  transition: background var(--trans), transform 0.1s ease;
  -webkit-tap-highlight-color: transparent;
}

.btn-calcular:hover {
  background: var(--accent-dk);
}

.btn-calcular:active {
  transform: scale(0.98);
}

.btn-calcular:focus-visible {
  outline: 2px solid var(--text);
  outline-offset: 3px;
}

.btn-reset {
  font-family: var(--font);
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-muted);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  height: 3rem;
  width: 100%;
  cursor: pointer;
  transition: border-color var(--trans), color var(--trans);
  -webkit-tap-highlight-color: transparent;
}

.btn-reset:hover {
  border-color: var(--text-muted);
  color: var(--text);
}

.btn-reset:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

/* ----- FORMULARIO CALC -------------------------------------- */
.calc-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

/* ----- PANTALLA AJUSTES ------------------------------------- */
.config-intro {
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.config-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.config-actions {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.config-saved-msg {
  text-align: center;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--success);
  padding: var(--space-1);
}

/* ----- RESPONSIVE: tablets / desktop donde aplica ----------- */
@media (min-width: 480px) {
  .app-main {
    padding: var(--space-4) var(--space-3);
  }

  .result-price {
    font-size: 5rem;
  }
}

/* ----- AUTOCOMPLETADO --------------------------------------- */
.autocomplete-wrap {
  position: relative;
  width: 100%;
}

.autocomplete-list {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 200;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-top: 4px;
  list-style: none;
  padding: 4px 0;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  max-height: 220px;
  overflow-y: auto;
}

.autocomplete-item {
  padding: 12px 14px;
  cursor: pointer;
  font-size: 0.875rem;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}

.autocomplete-item:last-child {
  border-bottom: none;
}

.autocomplete-item:hover,
.autocomplete-item:active {
  background: var(--surface);
  color: var(--text);
}

/* ----- RESPETA preferencia de movimiento reducido ------------ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
