:root {
  --bg: #f4f6fa;
  --panel: #ffffff;
  --text: #1c2333;
  --muted: #6b7489;
  --border: #e3e7ef;
  --primary: #2f6bff;
  --primary-dark: #1f50d1;
  --success: #17a568;
  --warning: #f2a516;
  --danger: #e5484d;
  --purple: #7c4dff;
  --teal: #0fa3b1;
  --radius: 10px;
  --shadow: 0 2px 10px rgba(20, 30, 60, .07);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}
h1, h2, h3, h4 { margin: 0 0 8px; }
a { color: var(--primary); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.hidden, [data-install][hidden] { display: none !important; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ----- Controles ----- */
.btn {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  transition: background .15s, transform .05s;
}
.btn:hover { background: #f0f3f9; }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.success { background: var(--success); border-color: var(--success); color: #fff; }
.btn.danger { background: #fff; border-color: #f3c3c5; color: var(--danger); }
.btn.sm { padding: 5px 10px; font-size: 12px; }
.btn.block { width: 100%; }
.btn.lg { padding: 13px 18px; font-size: 15px; }

input, select, textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  background: #fff;
  color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(47, 107, 255, .25); border-color: var(--primary); }
label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin: 10px 0 4px; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
}

.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}
.st-pending   { background: #fff4dc; color: #a86b00; }
.st-accepted  { background: #e5edff; color: #2f6bff; }
.st-preparing { background: #efe7ff; color: #6a3fe0; }
.st-ready     { background: #dff6f7; color: #0b7f8a; }
.st-assigned  { background: #e3f0ff; color: #1b5fb8; }
.st-picked_up { background: #ffe9dc; color: #c25400; }
.st-delivered { background: #dcf5e9; color: #0f7d4d; }
.st-cancelled { background: #fde4e5; color: #c2262c; }

.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.dot.on { background: var(--success); box-shadow: 0 0 0 3px rgba(23, 165, 104, .2); }
.dot.off { background: #b6bdcc; }

/* ----- Modal ----- */
.modal-bg {
  position: fixed; inset: 0; background: rgba(15, 22, 40, .45);
  display: flex; align-items: center; justify-content: center; z-index: 2000; padding: 16px;
}
.modal {
  background: #fff; border-radius: 14px; width: 100%; max-width: 520px; max-height: 92vh; overflow: auto;
  padding: 20px; box-shadow: 0 20px 60px rgba(0, 0, 0, .25);
}
.modal.wide { max-width: 760px; }
.modal-head { display: flex; align-items: center; margin-bottom: 10px; }
.modal-head h3 { margin: 0; flex: 1; }
.x { background: none; border: none; font-size: 22px; cursor: pointer; color: var(--muted); }

/* ----- Toast ----- */
#toasts { position: fixed; bottom: 18px; right: 18px; z-index: 3000; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: #1c2333; color: #fff; padding: 11px 16px; border-radius: 9px; box-shadow: var(--shadow);
  font-weight: 500; animation: slideIn .25s ease; max-width: 340px;
}
.toast.error { background: var(--danger); }
.toast.ok { background: var(--success); }
@keyframes slideIn { from { transform: translateY(12px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ----- Marcadores de mapa ----- */
.pin {
  width: 34px; height: 34px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg);
  display: flex; align-items: center; justify-content: center; border: 3px solid #fff;
  box-shadow: 0 3px 8px rgba(0, 0, 0, .3);
}
.pin span { transform: rotate(45deg); font-size: 16px; }
.pin.store { background: #1c2333; }
.pin.pickup { background: var(--purple); }
.pin.dest { background: var(--danger); }
.pin.dest.ready { background: var(--teal); }
.pin.dest.assigned, .pin.dest.picked_up { background: var(--warning); }
.driver-pin {
  width: 34px; height: 34px; border-radius: 50%; background: var(--primary); border: 3px solid #fff;
  display: flex; align-items: center; justify-content: center; font-size: 16px;
  box-shadow: 0 3px 10px rgba(47, 107, 255, .5);
}
.driver-pin.off { background: #9aa3b5; box-shadow: none; }
.driver-pin.live { background: var(--success); box-shadow: 0 3px 10px rgba(23, 165, 104, .5); }
.driver-pin.offline { background: var(--danger); box-shadow: 0 3px 10px rgba(229, 72, 77, .45); }
.driver-pin.stale { background: #9aa3b5; box-shadow: none; }
.leaflet-container { font: inherit; }

/* ----- Landing ----- */
.landing { max-width: 980px; margin: 0 auto; padding: 50px 20px; }
.landing h1 { font-size: 34px; }
.apps { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 18px; margin-top: 30px; }
.app-card { text-decoration: none; color: inherit; transition: transform .15s, box-shadow .15s; display: block; }
.app-card:hover { transform: translateY(-3px); box-shadow: 0 10px 30px rgba(20, 30, 60, .12); }
.app-card .icon { font-size: 40px; }

/* ----- Paneles con cuenta ----- */
.login-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; background: linear-gradient(135deg, #1c2333, #2f6bff); }
.login-card { width: 100%; max-width: 340px; text-align: center; padding: 28px; }
.logo-big { font-size: 48px; }
.lvl-urgent { background: #fde4e5; color: #c2262c; }
.lvl-relaxed { background: #eef0f4; color: var(--muted); }
.user-chip { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.user-chip .avatar-sm { width: 30px; height: 30px; border-radius: 50%; background: var(--bg); display: flex; align-items: center; justify-content: center; font-weight: 700; }

/* ----- Piezas compartidas de formularios ----- */
.sum-row { display: flex; justify-content: space-between; padding: 4px 0; }
.sum-row.total { font-weight: 800; font-size: 16px; border-top: 1px solid var(--border); margin-top: 6px; padding-top: 8px; }
.pay-opts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.pay-opts label { margin: 0; border: 1px solid var(--border); border-radius: 10px; padding: 10px; display: flex; gap: 8px; align-items: center; cursor: pointer; color: var(--text); font-size: 14px; }
.pay-opts input { width: auto; }
.geo-results { border: 1px solid var(--border); border-radius: 8px; margin-top: 4px; max-height: 160px; overflow: auto; background: #fff; }
.geo-results div { padding: 8px 10px; cursor: pointer; font-size: 12px; }
.geo-results div:hover { background: var(--bg); }
.qty { display: flex; align-items: center; gap: 6px; }
.qty button { width: 30px; height: 30px; border-radius: 50%; border: 1px solid var(--border); background: #fff; font-size: 16px; font-weight: 700; cursor: pointer; }
.qty button.add { background: var(--primary); color: #fff; border-color: var(--primary); }
.qty b { min-width: 16px; text-align: center; }

/* ----- "Ver como" del Centro de control ----- */
.admin-view-bar {
  position: fixed; left: 50%; bottom: 14px; z-index: 2600; transform: translateX(-50%); max-width: calc(100% - 24px);
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap; justify-content: center;
  padding: 9px 10px 9px 16px; border-radius: 999px; background: #1c2333; color: #fff; font-size: 13px;
  box-shadow: 0 10px 30px rgba(20, 30, 60, .35);
}
.admin-view-bar a { color: #1c2333; background: #fff; border-radius: 999px; padding: 6px 12px; font-weight: 700; text-decoration: none; white-space: nowrap; }
body.admin-viewing { padding-bottom: 70px; }
body.admin-viewing #dList .acts button { opacity: .45; pointer-events: none; }

/* Botón "Salir" de los paneles */
.exit-btn { gap: 6px; }
.exit-ico { flex: none; }

/* Teléfono o nombre con formato inválido: mensaje debajo del campo */
input[aria-invalid="true"] { border-color: var(--danger); }
input[aria-invalid="true"]:focus { outline-color: rgba(229, 72, 77, .25); border-color: var(--danger); }
.field-err { margin-top: 4px; color: var(--danger); font-size: 12px; font-weight: 600; line-height: 1.35; }

/* Asignación automática: tiempo para aceptar y búsqueda de repartidor */
.offer-timer { font-weight: 800; font-variant-numeric: tabular-nums; }
.offer-timer.late { color: var(--danger); }
.auto-note { margin: 0 0 8px; padding: 6px 9px; border-radius: 8px; background: #eef4ff; color: #1b4fc4; font-weight: 600; }

/* Selector del sonido de los avisos */
.sound-pick label { margin-top: 0; }
.sound-pick select { width: auto; flex: 1; min-width: 0; }

/* Chat entre el Centro de control y locales/repartidores */
.chat { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.chat-log { flex: 1; min-height: 0; overflow: auto; padding: 14px; display: flex; flex-direction: column; gap: 6px; background: #f4f6fa; }
.chat-empty { margin: auto; max-width: 320px; text-align: center; color: var(--muted); font-size: 13px; }
.chat-day { align-self: center; margin: 8px 0 2px; padding: 3px 10px; border-radius: 99px; background: #e4e8f0; color: var(--muted); font-size: 11px; font-weight: 700; text-transform: capitalize; }
.chat-msg { max-width: 78%; padding: 8px 11px 6px; border-radius: 14px; background: #fff; box-shadow: 0 1px 2px rgba(20, 30, 60, .08); align-self: flex-start; border-bottom-left-radius: 4px; }
.chat-msg.mine { align-self: flex-end; background: #dcf2ff; border-bottom-left-radius: 14px; border-bottom-right-radius: 4px; }
.chat-author { display: block; font-size: 12px; color: var(--primary); margin-bottom: 2px; }
.chat-tag { display: inline-block; margin-bottom: 4px; padding: 1px 7px; border-radius: 99px; background: #fff4dc; color: #8a5300; font-size: 11px; font-weight: 700; }
.chat-body { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14px; line-height: 1.4; }
.chat-meta { display: block; margin-top: 2px; text-align: right; font-size: 10.5px; color: var(--muted); }
.chat-readonly { padding: 10px 14px; border-top: 1px solid var(--border); }
.chat-form { display: flex; gap: 8px; align-items: flex-end; padding: 10px; border-top: 1px solid var(--border); background: #fff; }
.chat-form textarea { flex: 1; resize: none; max-height: 140px; line-height: 1.4; }

/* Repartidor: foto de perfil y calificaciones (cliente, local, Centro de control y app del repartidor) */
.drv-av { display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; border-radius: 50%; object-fit: cover; background: #e5edff; vertical-align: middle; }
.rating-badge { color: #b26a00; font-weight: 700; font-size: 13px; white-space: nowrap; }
.rating-badge small { color: var(--muted); font-weight: 500; }
.stars-txt { color: #f5a400; letter-spacing: 1px; }
.star-pick { display: flex; flex-direction: column; gap: 8px; }
.star-pick .stars { display: flex; gap: 2px; }
.star-pick .stars button { padding: 0 2px; border: 0; background: none; font-size: 34px; line-height: 1; color: #c9ced8; cursor: pointer; }
.star-pick .stars button.on { color: #f5a400; }
.star-pick .btn { align-self: flex-start; }
