:root {
  --bg: #0e0f12;
  --panel: #17191e;
  --panel-2: #1f2228;
  --line: #2c3038;
  --text: #f2f0eb;
  --muted: #9a9ca3;
  --gold: #c9a45c;
  --gold-ink: #1a1408;
  --ok: #5fb37c;
  --err: #e0705f;
  --radius: 14px;
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 16px; line-height: 1.45; -webkit-tap-highlight-color: transparent; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--gold); }

.top { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; padding-top: max(12px, env(safe-area-inset-top)); border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; letter-spacing: .02em; }
.brand small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; }
.lang { background: none; border: 1px solid var(--line); border-radius: 999px; min-height: 40px; min-width: 52px; padding: 6px 14px; cursor: pointer; }

.layout { display: grid; gap: 0; }
/* Celular: mapa arriba, formulario abajo. */
#map { height: 34vh; height: 34svh; min-height: 220px; background: var(--panel-2); }
.panel { padding: 18px 16px calc(40px + env(safe-area-inset-bottom)); max-width: 560px; width: 100%; margin: 0 auto; }
/* Tableta vertical */
@media (min-width: 700px) {
  #map { height: 42vh; height: 42svh; }
  .panel { max-width: 640px; padding: 26px 24px 48px; }
  h1 { font-size: 26px; }
}
/* Tableta horizontal y computadora: formulario a la izquierda, mapa a la derecha. */
@media (min-width: 960px) and (min-aspect-ratio: 1/1) {
  .layout { grid-template-columns: minmax(400px, 460px) 1fr; height: calc(100vh - 65px); height: calc(100dvh - 65px); }
  .panel { overflow-y: auto; order: -1; max-width: none; padding: 22px 24px 40px; }
  #map { height: 100%; }
}

h1 { font-size: 22px; margin: 0 0 4px; }
.sub { color: var(--muted); margin: 0 0 18px; font-size: 14px; }

.seg { display: grid; grid-template-columns: 1fr 1fr; background: var(--panel); border-radius: 999px; padding: 4px; margin-bottom: 16px; }
.seg button { border: 0; background: none; padding: 9px; min-height: 44px; border-radius: 999px; cursor: pointer; color: var(--muted); }
.seg button.on { background: var(--gold); color: var(--gold-ink); font-weight: 600; }

.field { margin-bottom: 14px; }
.field > label, .label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
/* 16px evita que el iPhone haga zoom al tocar un campo */
input, select, textarea {
  width: 100%; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px;
  font-size: 16px; min-height: 48px; -webkit-appearance: none; appearance: none;
}
select {
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 32px;
}
input[type=date], input[type=time], input[type=datetime-local] { display: block; text-align: left; }
input::-webkit-date-and-time-value { text-align: left; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--gold); outline-offset: 0; border-color: transparent; }
textarea { min-height: 70px; resize: vertical; }

.place gmp-place-autocomplete { width: 100%; color-scheme: dark; }
.ac-osm { position: relative; }
.ac-osm input::-webkit-search-cancel-button { -webkit-appearance: none; }
.ac-osm .sug { list-style: none; margin: 4px 0 0; padding: 0; position: absolute; left: 0; right: 0; z-index: 1000;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.ac-osm .sug:empty { display: none; }
.ac-osm .sug li { padding: 12px; min-height: 44px; font-size: 15px; border-bottom: 1px solid var(--line); cursor: pointer; }
.ac-osm .sug li:last-child { border-bottom: 0; }
.ac-osm .sug li:active, .ac-osm .sug li:hover { background: var(--panel); }
.ac[hidden] { display: none; }
#map.leaflet-container { background: var(--panel-2); }
/* Mapa de OpenStreetMap en modo oscuro */
#map .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(.9) contrast(.9); }
.place .chosen { display: flex; align-items: center; gap: 8px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.place .chosen span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.chip { border: 1px solid var(--line); background: none; border-radius: 999px; padding: 8px 14px; min-height: 40px; font-size: 14px; cursor: pointer; }
.chip:active { border-color: var(--gold); }
@media (hover: hover) { .chip:hover { border-color: var(--gold); } }
.x { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 22px; line-height: 1; min-width: 40px; min-height: 40px; margin: -8px -8px -8px 0; }

.btn { width: 100%; border: 0; border-radius: 12px; padding: 14px; min-height: 52px; font-size: 17px; font-weight: 600; cursor: pointer; background: var(--gold); color: var(--gold-ink); touch-action: manipulation; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.ghost { background: none; border: 1px solid var(--line); color: var(--text); }

.clases { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.clase { display: grid; gap: 2px; text-align: left; background: var(--panel); border: 2px solid var(--line); border-radius: var(--radius);
  padding: 12px; min-height: 96px; cursor: pointer; touch-action: manipulation; }
.clase.on { border-color: var(--gold); background: color-mix(in srgb, var(--gold) 10%, var(--panel)); }
.clase:disabled { opacity: .45; cursor: default; }
.clase-nom { font-weight: 700; font-size: 17px; }
.clase-desc { font-size: 12px; color: var(--muted); line-height: 1.3; }
.clase-precio { font-size: 22px; color: var(--gold); margin-top: 4px; }
.quote { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin: 12px 0 18px; }
.quote .total { display: flex; justify-content: space-between; align-items: baseline; }
.quote .total b { font-size: 32px; color: var(--gold); }
.quote ul { list-style: none; padding: 0; margin: 10px 0 0; font-size: 14px; color: var(--muted); }
.quote li { display: flex; justify-content: space-between; gap: 10px; padding: 3px 0; }
.quote .meta { font-size: 13px; color: var(--muted); }

.msg { padding: 10px 12px; border-radius: 10px; font-size: 14px; margin: 10px 0; }
.msg.err { background: color-mix(in srgb, var(--err) 18%, transparent); color: #ffd3cb; }
.msg.ok { background: color-mix(in srgb, var(--ok) 18%, transparent); color: #d4f5df; }
.hidden { display: none !important; }
.fine { font-size: 12px; color: var(--muted); margin-top: 12px; }

.done { text-align: center; padding: 30px 0; }
.done .code { font-size: 28px; letter-spacing: .15em; color: var(--gold); font-weight: 700; margin: 8px 0 16px; }

/* Panel del chofer */
.wrap { max-width: 760px; margin: 0 auto; padding: 18px 16px calc(60px + env(safe-area-inset-bottom)); }
/* Tableta: viajes en dos columnas */
@media (min-width: 700px) {
  .wrap { padding: 24px 24px 60px; }
  #tab-proximos:not(.hidden), #tab-pasados:not(.hidden) { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; align-items: start; }
  #tab-proximos > .card, #tab-pasados > .card { margin: 0; }
  #tab-proximos > p, #tab-pasados > p { grid-column: 1 / -1; }
}
@media (min-width: 1100px) { .wrap { max-width: 1060px; } }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.card.cancelada { opacity: .5; }
.card h3 { margin: 0 0 4px; font-size: 16px; display: flex; justify-content: space-between; gap: 8px; }
.card p { margin: 4px 0; font-size: 14px; }
.tag { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--panel-2); color: var(--muted); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.actions a, .actions button { display: inline-flex; align-items: center; min-height: 42px; font-size: 14px; padding: 8px 14px; border-radius: 999px; border: 1px solid var(--line); background: none; text-decoration: none; color: var(--text); cursor: pointer; touch-action: manipulation; }
.actions .tag { align-self: center; }
.actions a.nav { border-color: var(--gold); color: var(--gold); }
.tabs { gap: 6px; margin: 0 0 12px; }
.nav-row { margin-top: 10px; }
.nav-label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.nav-btns { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.nav-btns a { display: flex; align-items: center; justify-content: center; min-height: 44px; border: 1px solid var(--gold); color: var(--gold); border-radius: 10px; text-decoration: none; font-size: 14px; touch-action: manipulation; }
.tabs { display: grid; grid-template-columns: repeat(4, 1fr); position: sticky; top: 0; z-index: 2; background: var(--bg); padding: 8px 0; scrollbar-width: none; }
.tabs button { border: 1px solid var(--line); background: none; border-radius: 999px; padding: 8px 4px; min-height: 42px; font-size: 14px; cursor: pointer; white-space: nowrap; }
.tabs button.on { background: var(--gold); color: var(--gold-ink); border-color: var(--gold); }
.grid-t { display: grid; grid-template-columns: 1fr 110px; gap: 8px 12px; align-items: center; font-size: 14px; }
.grid-r { display: grid; grid-template-columns: 1fr 76px 76px; gap: 8px; align-items: center; font-size: 14px; }
@media (max-width: 380px) { .grid-t { grid-template-columns: 1fr 90px; } .grid-r { grid-template-columns: 1fr 66px 66px; font-size: 13px; } }

/* Chat cliente ↔ chofer */
.chat-wrap { max-width: 640px; }
.hilo { display: flex; flex-direction: column; gap: 8px; max-height: 55vh; max-height: 55svh; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; min-height: 160px; }
.burbuja { max-width: 85%; padding: 9px 12px; border-radius: 14px; background: var(--panel-2); }
.burbuja p { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.burbuja.mia { align-self: flex-end; background: color-mix(in srgb, var(--gold) 22%, var(--panel-2)); border-bottom-right-radius: 4px; }
.burbuja.suya { align-self: flex-start; border-bottom-left-radius: 4px; }
.burbuja small { display: block; font-size: 12px; color: var(--muted); margin-top: 4px; }
.burbuja .original { font-style: italic; }
.enviar { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: end; margin-top: 10px;
  position: sticky; bottom: 0; background: var(--bg); padding: 8px 0 calc(8px + env(safe-area-inset-bottom)); }
.enviar textarea { min-height: 48px; resize: none; }
.enviar .btn { width: auto; padding: 0 18px; }
.badge { display: inline-flex; align-items: center; justify-content: center; min-width: 20px; height: 20px; padding: 0 6px;
  border-radius: 999px; background: var(--err); color: #fff; font-size: 12px; font-weight: 700; margin-left: 6px; }
.chat-chofer { margin-top: 10px; }
.chat-chofer .hilo { max-height: 320px; }
.hoja { position: fixed; inset: 0; z-index: 50; background: var(--bg); display: flex; flex-direction: column; }
.hoja .wrap { flex: 1; display: flex; flex-direction: column; width: 100%; min-height: 0; padding-bottom: 0; }
.hoja .hilo { flex: 1; max-height: none; }
@media (min-width: 700px) { .hoja { inset: 24px; border: 1px solid var(--line); border-radius: var(--radius); max-width: 720px; margin: 0 auto; } }

/* Seguimiento del viaje */
.seguimiento { margin: 10px 0 4px; display: grid; gap: 8px; }
.seguimiento.activo { background: color-mix(in srgb, var(--ok) 12%, transparent); border: 1px solid color-mix(in srgb, var(--ok) 40%, transparent); border-radius: 12px; padding: 10px; }
.seguimiento p { margin: 0; font-size: 14px; }
.seguimiento .gps { color: var(--muted); }
.cobro { margin: 10px 0 4px; display: grid; gap: 8px; }
.cobro.ok b { color: var(--gold); }
.enlace { display: grid; grid-template-columns: 1fr auto; gap: 6px; }
.enlace input { min-height: 44px; font-size: 14px; }
.enlace button { border: 1px solid var(--line); background: none; border-radius: 10px; padding: 0 12px; cursor: pointer; }
.seguimiento-cliente { display: grid; gap: 8px; }
.pasos { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; list-style: none; padding: 0; margin: 0; counter-reset: paso; }
.pasos li { font-size: 12px; color: var(--muted); text-align: center; padding-top: 10px; border-top: 4px solid var(--line); }
.pasos li.hecho { border-color: var(--ok); color: var(--text); }
.pasos li.ahora { border-color: var(--gold); color: var(--gold); font-weight: 700; }
.estado-grande { font-size: 20px; font-weight: 700; margin: 4px 0 0; }
.mapa-vivo { height: 260px; border-radius: 12px; overflow: hidden; background: var(--panel-2); }
.mapa-vivo .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(.9) contrast(.9); }
.icono-chofer { font-size: 28px; line-height: 34px; text-align: center; filter: drop-shadow(0 1px 2px #000); }
#s-enlace { display: block; text-align: center; text-decoration: none; }
.toggle { display: flex; align-items: center; gap: 10px; font-size: 16px; cursor: pointer; }
.toggle input { width: 22px; height: 22px; accent-color: var(--accent, #d4af6a); }

/* Equipo: horario del segundo chofer y de quién es cada viaje */
.grid-h { display: grid; grid-template-columns: auto 1fr 1fr; gap: 8px 10px; align-items: center; }
.grid-h input { min-width: 0; }
.unidad { color: var(--muted); font-size: 14px; display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; }
button.link { background: none; border: 0; padding: 0; color: inherit; text-decoration: underline; font: inherit; cursor: pointer; }
