/* Cadetería — hoja de estilos. Mobile primero: se usa en la calle, con una mano. */

:root {
  --bg: #0f172a;
  --panel: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --brand: #2563eb;
  --brand-dark: #1d4ed8;
  --ok: #15803d;
  --warn: #b45309;
  --bad: #b91c1c;
  --ok-bg: #dcfce7;
  --warn-bg: #fef3c7;
  --bad-bg: #fee2e2;
  --radius: 12px;
  --tap: 44px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: #f1f5f9;
  color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

/* ------------------------------------------------------------- barra superior */
.topbar {
  position: sticky;
  top: 0;
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 14px;
  padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--bg);
  color: #fff;
}
.brand strong { font-size: 17px; }
.tagline { display: block; font-size: 12px; color: #94a3b8; }
.icon-btn {
  width: var(--tap); height: var(--tap);
  display: grid; place-items: center;
  background: #1e293b; color: #fff;
  border: 0; border-radius: 10px;
  font-size: 20px; cursor: pointer;
}
.icon-btn:active { background: #334155; }

/* -------------------------------------------------------------------- layout */
.app { padding: 12px 12px calc(24px + env(safe-area-inset-bottom)); display: grid; gap: 12px; }

.panel {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: 0 1px 2px rgb(15 23 42 / 8%);
}
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.panel-head h1, .panel-head h2 { font-size: 17px; margin: 0; }
.sub { font-size: 14px; color: var(--muted); margin: 16px 0 8px; text-transform: uppercase; letter-spacing: .04em; }
.count {
  min-width: 26px; padding: 2px 8px;
  background: var(--brand); color: #fff;
  border-radius: 999px; font-size: 13px; font-weight: 600; text-align: center;
}

/* --------------------------------------------------------------- formularios */
input[type="text"] {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 16px; /* 16px evita el zoom automático en iOS */
  background: #fff;
  color: var(--ink);
}
input[type="text"]:focus { outline: 2px solid var(--brand); outline-offset: 1px; border-color: var(--brand); }

label { display: block; margin-bottom: 12px; font-size: 14px; font-weight: 600; color: var(--muted); }
label input { margin-top: 4px; font-weight: 400; color: var(--ink); }

textarea {
  width: 100%;
  margin-top: 4px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font: 15px/1.4 inherit;
  font-family: inherit;
  resize: vertical;
  color: var(--ink);
}
textarea:focus { outline: 2px solid var(--brand); outline-offset: 1px; border-color: var(--brand); }

.add-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: start; }
.field-wrap { position: relative; }

.suggestions {
  position: absolute; z-index: 600;
  left: 0; right: 0; top: calc(100% + 4px);
  margin: 0; padding: 4px;
  list-style: none;
  background: #fff; border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 8px 24px rgb(15 23 42 / 18%);
  max-height: 260px; overflow-y: auto;
}
.suggestions li { padding: 10px; border-radius: 8px; cursor: pointer; font-size: 14px; }
.suggestions li:hover, .suggestions li[aria-selected="true"] { background: #eff6ff; }
.suggestions li small { display: block; color: var(--muted); font-size: 12px; }

/* ------------------------------------------------------------------ botones */
button { font-family: inherit; }

.btn-primary, .btn-ghost {
  min-height: var(--tap);
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 15px; font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
}
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:active { background: var(--brand-dark); }
.btn-primary:disabled { background: #cbd5e1; color: #94a3b8; cursor: not-allowed; }
.btn-ghost { background: #fff; color: var(--ink); border-color: var(--line); }
.btn-ghost:active { background: #f1f5f9; }
.btn-primary.big { width: 100%; font-size: 16px; }
.btn-ghost.small { min-height: 32px; padding: 4px 10px; font-size: 13px; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.actions .btn-primary.big { flex: 1 1 100%; }
.route-actions .btn-primary { flex: 1 1 100%; }

.hint { font-size: 13px; color: var(--muted); margin: 8px 0 0; }
.hint.warn { color: var(--warn); font-weight: 600; }
.empty { color: var(--muted); font-size: 14px; text-align: center; padding: 18px 8px; }

/* ------------------------------------------------------------ lista pedidos */
.order-list { list-style: none; margin: 12px 0 0; padding: 0; display: grid; gap: 8px; }
.order-item {
  display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center;
  padding: 10px; border: 1px solid var(--line); border-radius: 10px; background: #fff;
}
.order-item .badge {
  width: 26px; height: 26px; border-radius: 50%;
  display: grid; place-items: center;
  background: #e2e8f0; color: var(--ink); font-size: 13px; font-weight: 700;
}
.order-item .addr { font-size: 14px; word-break: break-word; }
.order-item .meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.order-item .rm {
  width: 34px; height: 34px; border: 0; border-radius: 8px;
  background: #f1f5f9; color: var(--bad); font-size: 18px; cursor: pointer;
}
.order-item .rm:active { background: var(--bad-bg); }

.status { display: inline-block; padding: 1px 7px; border-radius: 999px; font-size: 11px; font-weight: 700; }
.status.alta { background: var(--ok-bg); color: var(--ok); }
.status.media { background: var(--warn-bg); color: var(--warn); }
.status.baja, .status.revisar { background: var(--bad-bg); color: var(--bad); }

/* ---------------------------------------------------------------- recorrido */
.summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.summary .stat { background: #f8fafc; border: 1px solid var(--line); border-radius: 10px; padding: 10px; text-align: center; }
.summary .stat b { display: block; font-size: 18px; }
.summary .stat span { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.summary .stat.good b { color: var(--ok); }

.map { height: 320px; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); }
.map.small { height: 220px; margin-top: 8px; }

.stops { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.stop {
  display: grid; grid-template-columns: auto 1fr; gap: 10px;
  padding: 10px; border: 1px solid var(--line); border-radius: 10px; background: #fff;
}
.stop.origin { background: #f8fafc; border-style: dashed; }
.stop .num {
  width: 28px; height: 28px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--brand); color: #fff; font-weight: 700; font-size: 14px;
}
.stop.origin .num { background: var(--bg); }
.stop .label { font-size: 15px; font-weight: 600; word-break: break-word; }
.stop .detail { font-size: 12px; color: var(--muted); margin-top: 3px; }
.stop .warn { color: var(--warn); font-weight: 600; }
.stop button.link { background: none; border: 0; padding: 0; color: var(--brand); font-size: 12px; cursor: pointer; text-decoration: underline; }

.maneuvers { margin-top: 16px; }
.maneuvers summary { cursor: pointer; font-weight: 600; padding: 8px 0; }
.maneuvers ol { margin: 8px 0 0; padding-left: 20px; font-size: 14px; }
.maneuvers li { margin-bottom: 6px; }

.saved { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.saved li { padding: 10px; border: 1px solid var(--line); border-radius: 10px; font-size: 14px; }
.saved .saved-name { font-weight: 600; word-break: break-word; }
.saved .meta { font-size: 12px; color: var(--muted); margin: 2px 0 6px; }
.saved button.link { background: none; border: 0; padding: 0; color: var(--brand); font-size: 12px; cursor: pointer; text-decoration: underline; }

/* ------------------------------------------------------------------ diálogo */
.dlg {
  border: 0; border-radius: var(--radius);
  padding: 18px; width: min(94vw, 480px);
  box-shadow: 0 20px 50px rgb(15 23 42 / 35%);
}
.dlg::backdrop { background: rgb(15 23 42 / 55%); }
.dlg h2 { margin: 0 0 8px; font-size: 18px; }
.dlg-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.dlg-actions button { flex: 1; }

/* -------------------------------------------------------------------- toast */
.toast {
  position: fixed; z-index: 900;
  left: 50%; bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: 92vw;
  padding: 12px 16px;
  background: var(--bg); color: #fff;
  border-radius: 10px; font-size: 14px;
  box-shadow: 0 10px 30px rgb(15 23 42 / 35%);
}
.toast.err { background: var(--bad); }
.toast.ok { background: var(--ok); }

/* ------------------------------------------------------------------ markers */
.pin {
  width: 28px; height: 28px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--brand); color: #fff;
  font-weight: 700; font-size: 13px;
  border: 2px solid #fff;
  box-shadow: 0 2px 6px rgb(15 23 42 / 40%);
}
.pin.origin { background: var(--bg); }
.pin.warn { background: var(--warn); }

/* --------------------------------------------------------------- pantalla amplia */
@media (min-width: 900px) {
  .app { grid-template-columns: 400px 1fr; align-items: start; max-width: 1400px; margin: 0 auto; }
  #panelRoute { grid-column: 2; grid-row: 1 / span 3; }
  #panelSaved { grid-column: 1; }
  .map { height: 520px; }
  .route-actions .btn-primary { flex: 0 1 auto; }
}
