/* EmoliDelivery — panel de operación. Sin framework: un CSS y un JS. */
:root {
  --bg: #f6f3ee; --panel: #ffffff; --ink: #1f1a17; --muted: #6b6259; --line: #e6e0d8;
  --brand: #b3541e; --brand-ink: #ffffff; --ok: #2e7d32; --warn: #b26a00; --bad: #b3261e; --info: #1d5f8a;
  --radius: 10px; --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.05);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--brand); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  padding: 6px 12px; border-radius: 8px; }
button:hover { border-color: #cfc6bb; }
button.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
button.danger { color: var(--bad); border-color: #efc7c3; }
button.small { padding: 3px 8px; font-size: 12px; }
button:disabled { opacity: .5; cursor: default; }
input, select, textarea { padding: 7px 9px; border: 1px solid var(--line); border-radius: 8px; background: #fff; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid #e9c9b5; border-color: var(--brand); }
label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
label > input, label > select, label > textarea { font-size: 14px; color: var(--ink); }
label.inline { flex-direction: row; align-items: center; gap: 8px; font-size: 14px; color: var(--ink); }

.app { min-height: 100%; display: flex; flex-direction: column; }
.login { margin: auto; width: min(380px, 92vw); background: var(--panel); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 28px; display: flex; flex-direction: column; gap: 14px; }
.login h1 { margin: 0; font-size: 22px; }
.login p.sub { margin: 0; color: var(--muted); }

.topbar { display: flex; align-items: center; gap: 16px; padding: 10px 18px; background: var(--panel);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.topbar .logo { font-weight: 700; font-size: 16px; white-space: nowrap; }
.topbar nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
.topbar nav a { text-decoration: none; color: var(--ink); padding: 6px 10px; border-radius: 8px; }
.topbar nav a.activo { background: #f3e6dc; color: var(--brand); font-weight: 600; }
.topbar .quien { color: var(--muted); font-size: 12px; white-space: nowrap; }

main { padding: 18px; max-width: 1400px; width: 100%; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }
h2 { margin: 0; font-size: 20px; }
h3 { margin: 0 0 8px; font-size: 15px; }
.fila { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; }
.fila > * { flex: 0 1 auto; }
.tarjeta { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.kpi { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; }
.kpi .n { font-size: 26px; font-weight: 700; }
.kpi .t { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.kpi .d { color: var(--muted); font-size: 12px; margin-top: 4px; }
.dos { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 900px) { .dos { grid-template-columns: 1fr; } }

table { width: 100%; border-collapse: collapse; background: var(--panel); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; background: #faf7f3; }
tr:last-child td { border-bottom: 0; }
tr.click { cursor: pointer; }
tr.click:hover td { background: #fbf6f1; }
td.acciones { white-space: nowrap; }
.tabla-scroll { overflow-x: auto; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }

.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: #eee; color: #444; white-space: nowrap; }
.pill.activo, .pill.entregado, .pill.completado, .pill.disponible, .pill.ok { background: #e3f2e5; color: var(--ok); }
.pill.prospecto, .pill.inactivo, .pill.offline { background: #eeeae4; color: var(--muted); }
.pill.en_lote, .pill.asignado, .pill.recogido, .pill.abierto, .pill.cerrado, .pill.en_ruta { background: #e3eef7; color: var(--info); }
.pill.pendiente, .pill.suspendido { background: #fdf0d5; color: var(--warn); }
.pill.no_entregado, .pill.cancelado, .pill.anulado, .pill.bad { background: #fbe3e1; color: var(--bad); }

#mapa { height: 68vh; min-height: 420px; border-radius: var(--radius); box-shadow: var(--shadow); }
.leyenda { display: flex; gap: 14px; flex-wrap: wrap; color: var(--muted); font-size: 12px; }
.leyenda i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 5px; }
.leaflet-popup-content { font: 13px/1.4 system-ui, sans-serif; min-width: 220px; }
.leaflet-popup-content .fila { align-items: center; margin-top: 6px; }

.drawer { position: fixed; top: 0; right: 0; height: 100%; width: min(520px, 96vw); background: var(--panel);
  box-shadow: -8px 0 30px rgba(0,0,0,.12); z-index: 30; padding: 18px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
.drawer .cerrar { align-self: flex-end; }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 4px 10px; font-size: 13px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; }

.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: #2b2622; color: #fff;
  padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); z-index: 50; max-width: 90vw; }
.toast.bad { background: var(--bad); }
.toast.ok { background: var(--ok); }
.vacio { color: var(--muted); padding: 16px; text-align: center; }
.aviso { background: #fdf0d5; color: #6b4a00; border-radius: 8px; padding: 8px 12px; font-size: 13px; }
details > summary { cursor: pointer; color: var(--brand); font-weight: 600; margin-bottom: 8px; }
.codigos { display: flex; flex-wrap: wrap; gap: 6px; }
.codigos code { background: #f3ede6; padding: 2px 6px; border-radius: 6px; }
