/* ===== Variables ===== */
:root {
  --bg:        #f4f6fb;
  --surface:   #ffffff;
  --border:    #e2e8f0;
  --primary:   #FFA000;
  --primary-h: #e08c00;
  --success:   #22c55e;
  --danger:    #ef4444;
  --info:      #3b82f6;
  --text:      #1e293b;
  --muted:     #64748b;
  --radius:    12px;
  --shadow:    0 1px 4px rgba(0,0,0,.08);
  --shadow-md: 0 4px 16px rgba(0,0,0,.1);
  --shadow-lg: 0 8px 32px rgba(0,0,0,.15);
  --header-h:  60px;
  --nav-h:     64px;
}

[data-theme="dark"] {
  --bg:      #1a1f27;
  --surface: #242b35;
  --border:  #2f3844;
  --text:    #f0f0f0;
  --muted:   #8d99a8;
}

/* ===== Reset ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg); color: var(--text);
  min-height: 100vh; min-height: 100dvh;
  overflow-x: hidden;
  transition: background .2s, color .2s;
  -webkit-tap-highlight-color: transparent;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; }

/* ===== Login Page ===== */
.login-wrap {
  min-height: 100vh; min-height: 100dvh;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 36px 28px;
  width: 100%; max-width: 360px;
  box-shadow: var(--shadow-lg);
}
.login-logo {
  text-align: center; margin-bottom: 6px;
}
.login-logo img { height: 48px; width: auto; }
.login-subtitle {
  text-align: center; font-size: .82rem;
  color: var(--muted); margin-bottom: 28px;
}
.form-group { margin-bottom: 16px; }
.form-label {
  display: block; font-size: .78rem; font-weight: 700;
  color: var(--muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .04em;
}
.form-input {
  width: 100%; padding: 13px 14px;
  border: 1.5px solid var(--border); border-radius: 10px;
  font-size: 1rem; color: var(--text); background: var(--surface);
  outline: none; transition: border-color .15s;
  -webkit-appearance: none;
}
.form-input:focus { border-color: var(--primary); }
.btn-login {
  width: 100%; padding: 14px;
  background: var(--primary); color: #fff;
  border: none; border-radius: 50px; cursor: pointer;
  font-size: 1rem; font-weight: 700;
  box-shadow: 0 4px 14px rgba(255,160,0,.35);
  transition: opacity .15s, transform .1s;
  margin-top: 4px;
}
.btn-login:active  { transform: scale(.97); opacity: .9; }
.btn-login:disabled{ opacity: .6; pointer-events: none; }
.error-msg {
  background: #fef2f2; border: 1px solid #fecaca; color: #dc2626;
  border-radius: 8px; padding: 10px 14px; font-size: .85rem;
  margin-bottom: 14px; display: none;
}
.error-msg.show { display: block; }

/* ===== App Shell ===== */
.app { display: flex; flex-direction: column; min-height: 100vh; min-height: 100dvh; }

/* Header */
.header {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  height: var(--header-h);
  background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px;
  box-shadow: var(--shadow);
}
.header-left  { display: flex; align-items: center; gap: 10px; }
.header-right { display: flex; align-items: center; gap: 10px; }

.header-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: .9rem; flex-shrink: 0;
}
.header-name  { font-size: .9rem; font-weight: 700; }
.header-role  { font-size: .72rem; color: var(--muted); }

/* Live indicator */
.live-badge {
  display: flex; align-items: center; gap: 5px;
  font-size: .72rem; color: var(--success); font-weight: 600;
}
.live-dot {
  width: 7px; height: 7px; border-radius: 50%; background: var(--success);
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(34,197,94,.6); }
  70%  { box-shadow: 0 0 0 7px rgba(34,197,94,0); }
  100% { box-shadow: 0 0 0 0 rgba(34,197,94,0); }
}

.btn-icon {
  background: none; border: 1px solid var(--border);
  color: var(--muted); border-radius: 8px;
  width: 36px; height: 36px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: .9rem; transition: background .15s;
}
.btn-icon:active { background: var(--border); }
#btnInstall i { animation: install-pulse 2s ease-in-out infinite; }
@keyframes install-pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: .35; }
}

/* ===== Campana de notificaciones ===== */
.btn-notif { position: relative; }
.notif-dot {
  position: absolute; top: 5px; right: 5px;
  width: 9px; height: 9px; border-radius: 50%;
  background: #ef4444;
  border: 2px solid var(--surface);
  animation: notif-pulse 2s infinite;
}
@keyframes notif-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(239,68,68,.6); }
  70%  { box-shadow: 0 0 0 6px rgba(239,68,68,0); }
  100% { box-shadow: 0 0 0 0 rgba(239,68,68,0); }
}

.notif-overlay {
  display: none; position: fixed; inset: 0; z-index: 149;
}
.notif-overlay.open { display: block; }

.notif-panel {
  position: fixed; top: var(--header-h); right: 12px;
  width: min(360px, calc(100vw - 24px));
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; box-shadow: 0 8px 32px rgba(0,0,0,.18);
  z-index: 150; display: flex; flex-direction: column;
  max-height: calc(100vh - var(--header-h) - 80px);
  transform: translateY(-10px) scale(.97);
  opacity: 0; pointer-events: none;
  transition: transform .18s ease, opacity .18s ease;
}
.notif-panel.open {
  transform: translateY(6px) scale(1);
  opacity: 1; pointer-events: auto;
}
.notif-panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--border);
}
.notif-panel-title { font-weight: 700; font-size: .95rem; }
.notif-panel-close {
  background: none; border: none; cursor: pointer;
  color: var(--muted); font-size: 1rem; padding: 4px 6px;
  border-radius: 6px; transition: background .15s;
}
.notif-panel-close:hover { background: var(--border); }

.notif-list {
  overflow-y: auto; flex: 1;
  -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
}
.notif-item {
  display: flex; flex-direction: column; gap: 3px;
  padding: 12px 16px; border-bottom: 1px solid var(--border);
  cursor: default; transition: background .12s;
}
.notif-item.unread { background: rgba(255,160,0,.07); }
.notif-item-title {
  font-size: .88rem; font-weight: 600; color: var(--text);
  display: flex; align-items: center; gap: 6px;
}
.notif-item-title .unread-dot {
  width: 7px; height: 7px; border-radius: 50%; background: #FFA000;
  flex-shrink: 0;
}
.notif-item-body { font-size: .82rem; color: var(--muted); }
.notif-item-time { font-size: .72rem; color: var(--muted); margin-top: 2px; }
.notif-empty {
  text-align: center; padding: 32px 16px;
  font-size: .88rem; color: var(--muted);
}

/* ===== Bottom Nav ===== */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 100;
  height: var(--nav-h);
  background: var(--surface); border-top: 1px solid var(--border);
  display: flex; box-shadow: 0 -2px 12px rgba(0,0,0,.08);
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.nav-tab {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 4px;
  background: none; border: none; cursor: pointer;
  color: var(--muted); font-size: .68rem; font-weight: 600;
  padding: 8px 4px; transition: color .15s; -webkit-tap-highlight-color: transparent;
}
.nav-tab i { font-size: 1.2rem; }
.nav-tab.active { color: var(--primary); }
.nav-tab .nav-badge {
  position: absolute;
  top: 6px; right: calc(50% - 22px);
  background: var(--danger); color: #fff;
  font-size: .62rem; font-weight: 700; border-radius: 10px;
  padding: 1px 5px; min-width: 16px; text-align: center;
}
.nav-tab { position: relative; }

/* ===== Content ===== */
.content {
  flex: 1;
  margin-top: var(--header-h);
  margin-bottom: var(--nav-h);
  padding: 14px;
  overflow-y: auto;
}

/* Section */
.section { display: none; }
.section.active { display: block; }

/* Section header */
.section-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px;
}
.section-title {
  font-size: 1rem; font-weight: 800;
}
.section-count {
  background: var(--primary); color: #fff;
  font-size: .72rem; font-weight: 700;
  border-radius: 20px; padding: 2px 10px;
}
.section-count.empty { background: var(--border); color: var(--muted); }
#countHistorial { background: var(--border); color: var(--text); }

/* Empty */
.empty-state {
  text-align: center; padding: 48px 24px; color: var(--muted);
}
.empty-state i { font-size: 3rem; margin-bottom: 12px; opacity: .3; display: block; }
.empty-state p { font-size: .9rem; }

/* ===== Order Card ===== */
.order-card {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  margin-top: 5px;
  margin-bottom: 5px;
  overflow: hidden;
  box-shadow: var(--shadow);
  transition: box-shadow .15s;
}
.order-card:active { box-shadow: var(--shadow-md); }

.card-strip {
  height: 4px;
  background: var(--primary);
}
.card-strip.entregado { background: var(--primary); }

.card-body { padding: 14px; }

.card-row1 {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 10px;
}
.card-num   { font-weight: 800; font-size: 1rem; color: var(--primary); }
.card-time  { font-size: .72rem; color: var(--muted); }

.card-cliente { font-weight: 700; font-size: .95rem; margin-bottom: 6px; }

.card-address {
  display: flex; align-items: flex-start; gap: 6px;
  font-size: .82rem; color: var(--muted); margin-bottom: 8px;
}
.card-address i { margin-top: 2px; flex-shrink: 0; font-size: .78rem; color: var(--primary); }

.card-phone {
  display: flex; align-items: center; gap: 6px;
  font-size: .82rem; margin-bottom: 10px;
}
.card-phone i { color: var(--success); font-size: .8rem; }
.card-phone a { color: var(--text); }

.card-items {
  background: var(--bg); border-radius: 8px; padding: 8px 10px;
  margin-bottom: 10px; font-size: .8rem; color: var(--muted);
}
.card-item-row { display: flex; justify-content: space-between; padding: 2px 0; }
.card-item-name{ flex: 1; }
.card-item-qty { color: var(--muted); margin-right: 8px; }
.card-item-price{ font-weight: 600; color: var(--text); white-space: nowrap; }

.card-footer {
  display: flex; align-items: center; justify-content: space-between;
  border-top: 1px solid var(--border); padding-top: 10px; gap: 8px;
}
.card-total { font-weight: 800; font-size: 1rem; }

.card-actions { display: flex; gap: 8px; }

.btn-map {
  display: flex; align-items: center; gap: 5px;
  padding: 9px 14px; border-radius: 8px;
  background: rgba(59,130,246,.1); color: var(--info);
  border: 1.5px solid rgba(59,130,246,.3);
  font-size: .78rem; font-weight: 700; cursor: pointer;
  white-space: nowrap; transition: background .15s;
  text-decoration: none;
}
.btn-map:active { background: rgba(59,130,246,.2); }

.btn-deliver {
  display: flex; align-items: center; gap: 5px;
  padding: 9px 14px; border-radius: 8px;
  background: var(--success); color: #fff;
  border: none; font-size: .78rem; font-weight: 700; cursor: pointer;
  white-space: nowrap; transition: opacity .15s, transform .1s;
}
.btn-deliver:active   { opacity: .85; transform: scale(.97); }
.btn-deliver:disabled { opacity: .5; pointer-events: none; }

.btn-abandonar {
  display: flex; align-items: center; gap: 5px;
  padding: 9px 12px; border-radius: 8px;
  background: transparent; color: var(--danger);
  border: 1px solid var(--danger); font-size: .78rem; font-weight: 700; cursor: pointer;
  white-space: nowrap; transition: opacity .15s, transform .1s, background .15s;
}
.btn-abandonar:hover    { background: var(--danger); color: #fff; }
.btn-abandonar:active   { opacity: .85; transform: scale(.97); }
.btn-abandonar:disabled { opacity: .5; pointer-events: none; }

/* ===== Estado badge en card ===== */
.card-estado-badge {
  font-size: .7rem; font-weight: 700; border-radius: 20px;
  padding: 3px 10px; letter-spacing: .02em;
}

/* ===== Secciones contenedor de pedidos ===== */
.pedidos-seccion {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 16px;
  overflow: hidden;
  border: 1.5px solid var(--border);
}
.pedidos-seccion--entregar { border-top: 4px solid var(--success); min-height: 250px; display: flex; flex-direction: column; }
.pedidos-seccion--tomar    { border-top: 4px solid var(--info); min-height: 250px; display: flex; flex-direction: column; }

.pedidos-seccion-header {
  display: flex; align-items: center; gap: 8px;
  padding: 13px 16px;
  font-size: .8rem; font-weight: 800;
  text-transform: uppercase; letter-spacing: .06em;
  border-bottom: 1px solid var(--border);
}
.pedidos-seccion--entregar .pedidos-seccion-header { color: var(--success); }
.pedidos-seccion--tomar    .pedidos-seccion-header { color: var(--info); }

.pedidos-seccion-count {
  margin-left: auto;
  min-width: 22px; height: 22px;
  border-radius: 11px; padding: 0 6px;
  display: flex; align-items: center; justify-content: center;
  font-size: .75rem; font-weight: 800; color: #fff;
}
.pedidos-seccion--entregar .pedidos-seccion-count { background: var(--success); }
.pedidos-seccion--tomar    .pedidos-seccion-count { background: var(--info); }

.pedidos-seccion-lista {
  padding: 10px;
  display: flex; flex-direction: column; gap: 8px;
}
.pedidos-seccion-lista:empty { padding: 0; }

.pedidos-seccion-empty {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 20px 16px;
  text-align: center;
  color: var(--muted); font-size: .84rem;
}
.pedidos-seccion-empty i { font-size: 1.4rem; display: block; margin-bottom: 6px; opacity: .4; }

/* ===== Mini tarjeta: Para entregar (verde) ===== */
.mini-card-entregar {
  background: rgba(34,197,94,.10);
  border-radius: 12px;
  border: 1.5px solid rgba(34,197,94,.4);
  border-left: 5px solid var(--success);
  padding: 14px 14px;
  margin-top: 5px;
  margin-bottom: 5px;
}
.mce-top {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 8px;
}
.mce-num  { font-weight: 800; font-size: 1.1rem; color: var(--text); }
.mce-time { font-size: .82rem; color: #fff; }
.mce-info-row {
  display: flex; align-items: flex-start; gap: 8px;
  font-size: .95rem; color: var(--text); line-height: 1.4; margin-bottom: 5px;
}
.mce-info-row i {
  color: var(--success); width: 16px; margin-top: 3px;
  flex-shrink: 0; text-align: center; font-size: .88rem;
}
.mini-card-tomar .mce-info-row i { color: var(--info); }
.mce-tarifa-row,
.mct-tarifa-row {
  margin-top: 5px;
  margin-bottom: 5px;
  font-size: 1.05rem; font-weight: 800; color: var(--text);
  text-align: center;
}
.mce-btn-row {
  display: flex; gap: 8px; margin-top: 8px;
}
.mce-btn-half {
  flex: 1;
  padding: 12px 8px;
  border-radius: 9px; font-size: .95rem; font-weight: 700;
  cursor: pointer; min-height: 48px;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  transition: opacity .15s, transform .1s;
}
.mce-btn-half:active   { opacity: .85; transform: scale(.97); }
.mce-btn-half:disabled { opacity: .4; pointer-events: none; }
.mce-btn-ruta {
  background: transparent; color: var(--success);
  border: 1.5px solid var(--success);
}
.mce-btn-ruta:active { background: rgba(34,197,94,.1); }
.mce-btn-wa {
  background: transparent; color: var(--success);
  border: 1.5px solid var(--success);
}
.mce-btn-wa:active { background: rgba(34,197,94,.1); }
.mce-btn-devolver {
  background: transparent; color: var(--success);
  border: 1.5px solid var(--success);
}
.mce-btn-devolver:active { opacity: .75; }
.mce-btn-entregar {
  background: var(--success); color: #fff;
  border: none;
}
.mce-btn-entregar:active { opacity: .85; transform: scale(.97); }

/* ===== Mini tarjeta: Para tomar (azul) ===== */
.mini-card-tomar {
  background: rgba(59,130,246,.10);
  border-radius: 12px;
  border: 1.5px solid rgba(59,130,246,.4);
  border-left: 5px solid var(--info);
  padding: 14px 14px;
  margin-top: 5px;
  margin-bottom: 5px;
}
.mct-top {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 8px;
}
.mct-num  { font-weight: 800; font-size: 1.1rem; color: var(--text); }
.mct-time { font-size: .82rem; color: #fff; }
.mct-info-row {
  display: flex; align-items: flex-start; gap: 8px;
  font-size: .95rem; color: var(--text); line-height: 1.4; margin-bottom: 5px;
}
.mct-info-row i {
  color: var(--info); width: 16px; margin-top: 3px;
  flex-shrink: 0; text-align: center; font-size: .88rem;
}
.mct-meta {
  font-size: .88rem; color: var(--muted);
  margin: 5px 0 0; display: flex; gap: 12px; flex-wrap: wrap;
}
.mct-meta i { color: var(--info); margin-right: 4px; }
.mct-bottom {
  display: flex; gap: 8px; margin-top: 12px;
}
.mct-btn-ruta,
.mct-btn-tomar {
  flex: 1; padding: 12px 8px;
  border-radius: 9px; font-size: 1rem; font-weight: 700; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 48px;
  transition: opacity .15s, transform .1s;
}
.mct-btn-ruta {
  border: 1.5px solid var(--info); background: transparent; color: var(--info);
}
.mct-btn-ruta:active  { background: rgba(59,130,246,.1); }
.mct-btn-ruta:disabled { opacity: .4; pointer-events: none; }
.mct-btn-tomar {
  background: var(--info); color: #fff; border: none;
}
.mct-btn-tomar:active { opacity: .85; transform: scale(.97); }

/* ===== Mapa embebido en card ===== */
.card-map-wrap {
  margin: 10px 0; border-radius: 10px; overflow: hidden;
  border: 1px solid var(--border);
}
.card-map-frame {
  width: 100%; height: 160px; display: block; border: none;
}
.card-map-open {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px; font-size: .78rem; font-weight: 600;
  color: var(--info); background: rgba(59,130,246,.06);
  border-top: 1px solid var(--border); text-decoration: none;
}
.card-map-open:active { background: rgba(59,130,246,.14); }
.card-map-wrap--nocoords { border: none; }
.dash-card-map { margin: 8px 0; }
.dash-card-map .card-map-frame { height: 130px; }

.card-punto {
  display: flex; align-items: flex-start; gap: 8px;
  font-size: .82rem; color: var(--text); margin-top: 5px;
  line-height: 1.35;
}
.card-punto i { color: var(--primary); flex-shrink: 0; margin-top: 2px; font-size: .78rem; }
.btn-mostrar-ruta {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  width: 100%; margin-top: 10px; padding: 9px;
  background: transparent; color: var(--primary);
  border: 1.5px solid var(--primary); border-radius: 8px;
  font-size: .82rem; font-weight: 700; cursor: pointer;
  transition: background .15s;
}
.btn-mostrar-ruta:active { background: rgba(var(--primary-rgb, 255,160,0),.1); }
.btn-whatsapp {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  width: 100%; margin-top: 8px; padding: 9px;
  background: transparent; color: var(--primary);
  border: 1.5px solid var(--primary); border-radius: 10px;
  font-size: .82rem; font-weight: 700; cursor: pointer;
  transition: background .15s;
}
.btn-whatsapp:active { background: rgba(var(--primary-rgb, 255,160,0),.1); }
.dash-card-travel {
  display: flex; gap: 16px; margin-top: 4px;
  font-size: .82rem; font-weight: 600; color: var(--text);
}
.dash-card-travel i { color: var(--primary); margin-right: 4px; }

.btn-ver-pedido {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  width: 100%; margin-top: 8px; padding: 10px;
  background: var(--surface2, rgba(0,0,0,.04)); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; cursor: pointer;
  font-size: .85rem; font-weight: 600;
}
.btn-ver-pedido:active { background: var(--border); }

/* ===== Modal: detalle de pedido ===== */
.pm-block { margin-bottom: 14px; }
.pm-block-title {
  font-size: .72rem; font-weight: 700; text-transform: uppercase;
  color: var(--muted); margin-bottom: 6px; letter-spacing: .04em;
}
.pm-row {
  display: flex; align-items: flex-start; gap: 8px;
  font-size: .88rem; color: var(--text); padding: 4px 0;
}
.pm-row i { color: var(--primary); margin-top: 3px; flex-shrink: 0; width: 14px; }
.pm-row a { color: var(--info, #3b82f6); text-decoration: none; }
.pm-items {
  border: 1px solid var(--border); border-radius: 10px; overflow: hidden;
}
.pm-item {
  display: grid; grid-template-columns: auto 1fr auto;
  gap: 10px; padding: 9px 12px; font-size: .85rem;
  border-bottom: 1px solid var(--border);
}
.pm-item:last-child { border-bottom: none; }
.pm-item-qty { font-weight: 700; color: var(--primary); }
.pm-item-name { color: var(--text); }
.pm-item-price { font-weight: 600; color: var(--text); }
.pm-total-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 4px 0; margin-top: 6px;
  border-top: 1.5px solid var(--border);
  font-weight: 800; font-size: .95rem;
}

/* ===== Entregado card (historial) ===== */
.card-entregado { margin-bottom: 20px; }
.card-strip-success { background: var(--success); }
.card-entregado .card-num { color: var(--success); }
.badge-entregado {
  display: inline-flex; align-items: center; gap: 4px;
  background: rgba(255,160,0,.12); color: var(--primary);
  border-radius: 20px; padding: 3px 10px; font-size: .72rem; font-weight: 700;
}
.hist-icon-primary { color: var(--success); }
.hist-times {
  display: flex; flex-direction: column; gap: 4px;
  font-size: .8rem; color: var(--muted); margin-top: 8px;
}
.hist-times strong { color: var(--text); }
.hist-meta {
  display: flex; gap: 14px; font-size: .78rem; color: var(--muted); margin-top: 6px;
}
.hist-footer {
  display: flex; align-items: flex-end; justify-content: space-between;
  margin-top: 10px; padding-top: 10px; border-top: 1.5px solid var(--border);
}
.badge-cobrar {
  display: inline-flex; align-items: center;
  background: rgba(34,197,94,.15); color: var(--success);
  border-radius: 20px; padding: 3px 10px; font-size: .72rem; font-weight: 700;
}
.hist-monto {
  font-size: 1.4rem; font-weight: 900; color: var(--success); letter-spacing: -.5px;
}

/* ===== Modal Detalle Historial ===== */
.detalle-row {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 10px 0; border-bottom: 1px solid var(--border);
}
.detalle-row:last-of-type { border-bottom: none; }
.detalle-icon { color: var(--success); font-size: .95rem; margin-top: 2px; flex-shrink: 0; }
.detalle-label { font-size: .72rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.detalle-value { font-size: .9rem; color: var(--text); font-weight: 500; margin-top: 2px; }
.detalle-monto {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 14px; padding: 12px 14px;
  background: rgba(34,197,94,.08); border: 1.5px solid rgba(34,197,94,.25); border-radius: 10px;
}
.detalle-monto span:first-child { font-size: .82rem; color: var(--muted); font-weight: 600; }
.detalle-monto span:last-child  { font-size: 1.4rem; font-weight: 900; color: var(--success); }
.detalle-hist-footer {
  padding: 12px 18px; border-top: 1px solid var(--border); flex-shrink: 0;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
}
.detalle-hist-btn-ruta {
  width: 100%; padding: 14px; border: none; border-radius: 12px;
  background: var(--success); color: #fff;
  font-size: .95rem; font-weight: 700; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 8px;
}
.detalle-hist-btn-ruta:disabled { opacity: .4; cursor: default; }

/* ===== Profile section ===== */
.profile-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px 16px;
  box-shadow: var(--shadow); margin-bottom: 14px;
}
.profile-avatar {
  width: 64px; height: 64px; border-radius: 50%;
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 1.5rem; margin: 0 auto 12px;
  overflow: hidden;
}
.profile-avatar img {
  width: 100%; height: 100%; object-fit: cover; display: block;
}
.profile-name  { text-align: center; font-size: 1.1rem; font-weight: 800; margin-bottom: 4px; }
.profile-role  { text-align: center; font-size: .8rem; color: var(--muted); margin-bottom: 20px; }
.profile-row   { display: flex; justify-content: space-between; padding: 10px 0; border-top: 1px solid var(--border); font-size: .88rem; }
.profile-label { color: var(--muted); }
.profile-value { font-weight: 600; }

.btn-logout {
  width: 100%; padding: 13px; border: none;
  background: var(--primary); color: #fff; border-radius: 10px;
  font-size: .9rem; font-weight: 700; cursor: pointer; margin-top: 12px;
  transition: background .15s;
}
.btn-logout:active { background: var(--primary-h); }

.toggle-row {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px;
  box-shadow: var(--shadow); margin-bottom: 10px;
}
.toggle-label { font-size: .88rem; font-weight: 600; }
.toggle-switch { display: flex; align-items: center; cursor: pointer; }
.toggle-switch input { display: none; }
.toggle-track {
  width: 44px; height: 24px; border-radius: 12px;
  background: var(--border); position: relative; transition: background .2s;
}
.toggle-switch input:checked + .toggle-track { background: var(--primary); }
.toggle-thumb {
  position: absolute; top: 3px; left: 3px;
  width: 18px; height: 18px; border-radius: 50%;
  background: #fff; transition: transform .2s;
  box-shadow: 0 1px 4px rgba(0,0,0,.2);
}
.toggle-switch input:checked + .toggle-track .toggle-thumb { transform: translateX(20px); }

/* ===== Refresh btn (pull-to-refresh hint) ===== */
.refresh-bar {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px; font-size: .75rem; color: var(--muted);
  cursor: pointer; user-select: none;
}
.refresh-bar i { font-size: .8rem; }

/* ===== Loading overlay ===== */
.loading-overlay {
  display: none; position: fixed; inset: 0; z-index: 500;
  background: rgba(0,0,0,.3); align-items: center; justify-content: center;
}
.loading-overlay.show { display: flex; }
.spinner {
  width: 48px; height: 48px;
  border: 4px solid rgba(255,255,255,.3); border-top-color: var(--primary);
  border-radius: 50%; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Toast ===== */
.toast {
  position: fixed; bottom: calc(var(--nav-h) + 12px); left: 16px; right: 16px;
  background: #1e293b; color: #fff;
  padding: 13px 18px; border-radius: 12px;
  font-size: .88rem; text-align: center;
  opacity: 0; pointer-events: none;
  transition: opacity .25s; z-index: 999;
  box-shadow: var(--shadow-md);
}
.toast.show { opacity: 1; }
[data-theme="dark"] .toast { background: var(--surface); color: var(--text); border: 1px solid var(--border); }

/* ===== Modal ===== */
.modal-wrap {
  display: none; position: fixed; inset: 0; z-index: 300;
  background: rgba(0,0,0,.5); backdrop-filter: blur(3px);
  align-items: flex-end; justify-content: center;
}
.modal-wrap.open { display: flex; }
.modal {
  background: var(--surface); border-radius: 20px 20px 0 0;
  width: 100%; max-width: 500px;
  max-height: 80vh; max-height: 80dvh;
  display: flex; flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.modal-handle {
  width: 36px; height: 4px; border-radius: 2px;
  background: var(--border); margin: 10px auto 0;
}
.modal-header {
  padding: 14px 18px; border-bottom: 1px solid var(--border); flex-shrink: 0;
  display: flex; align-items: center; justify-content: space-between;
}
.modal-title { font-size: 1rem; font-weight: 800; }
.modal-close {
  background: none; border: none; color: var(--muted); cursor: pointer;
  width: 32px; height: 32px; display: flex; align-items: center; justify-content: center;
  border-radius: 8px; font-size: 1.1rem;
}
.modal-body { flex: 1; overflow-y: auto; padding: 16px 18px; }

/* ===== Modal Confirmación ===== */
.modal-confirm-wrap { align-items: center; justify-content: center; }
.modal-confirm {
  border-radius: 20px;
  width: calc(100% - 32px);
  max-width: 360px;
  padding: 20px 20px 24px;
}
.confirm-msg {
  font-size: 1rem; color: var(--text); text-align: center;
  line-height: 1.5; margin: 16px 0 24px;
}
.confirm-btns { display: flex; gap: 10px; }
.confirm-btn-cancel {
  flex: 1; padding: 12px; border: 1.5px solid var(--border);
  border-radius: 10px; background: none; color: var(--text);
  font-size: .95rem; cursor: pointer;
}
.confirm-btn-ok {
  flex: 1; padding: 12px; border: none; border-radius: 10px;
  background: var(--primary); color: #fff;
  font-size: .95rem; font-weight: 700; cursor: pointer;
}

/* ===== Modal Ruta ===== */
.modal-ruta-wrap { align-items: center; justify-content: center; }
.modal-ruta {
  border-radius: 20px; width: calc(100% - 24px); max-width: 560px;
  max-height: 95vh; max-height: 95dvh;
  padding: 0; overflow: hidden;
}
.card-pago {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 8px; padding: 6px 10px;
  background: var(--primary)18; border: 1px solid var(--primary)40;
  border-radius: 8px;
}
.card-pago-label { font-size: .82rem; color: #fff; font-weight: 600; }
.card-pago-valor { font-size: 1.2rem; font-weight: 800; color: var(--primary); }

.ruta-modal-title {
  padding: 10px 16px 8px; font-size: .95rem; font-weight: 700;
  border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.ruta-iframe {
  flex: none; aspect-ratio: 1 / 1; width: 100%; border: none; display: block;
}
.btn-cerrar-ruta {
  width: 100%; padding: 14px 16px; flex-shrink: 0;
  background: var(--primary); border: none;
  cursor: pointer; font-size: .95rem; font-weight: 700;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  color: #fff;
}

/* ===== Dashboard ===== */
/* ===== Conexión card (estado conectado / desconectado) ===== */
/* Desconectado: card grande y centrada — llama a la acción. */
.conexion-card {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 18px;
  margin-bottom: 16px;
  text-align: center;
  box-shadow: var(--shadow);
  transition: border-color .2s, background .2s, padding .2s;
}
.conexion-card-icon {
  width: 56px; height: 56px; margin: 0 auto 10px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: color-mix(in srgb, var(--muted) 18%, var(--surface));
  color: var(--muted);
  font-size: 1.4rem;
  transition: background .2s, color .2s, width .2s, height .2s, margin .2s, font-size .2s;
}
.conexion-card-title {
  font-size: 1rem; font-weight: 700; color: var(--text); margin-bottom: 4px;
}
.conexion-card-text {
  font-size: .82rem; color: var(--muted); margin-bottom: 14px;
}
.conexion-btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 22px;
  border: none; border-radius: 999px;
  background: var(--success); color: #fff;
  font-size: .9rem; font-weight: 700;
  cursor: pointer; user-select: none;
  transition: background .15s, opacity .15s, padding .2s, font-size .2s;
}
.conexion-btn:disabled { opacity: .6; cursor: not-allowed; }

/* Conectado: barra compacta horizontal — deja espacio a la lista. */
.conexion-card.is-conectado {
  border-color: var(--success);
  background: color-mix(in srgb, var(--success) 8%, var(--surface));
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px;
  text-align: left;
  margin-bottom: 12px;
}
.conexion-card.is-conectado .conexion-card-icon {
  width: 28px; height: 28px; margin: 0;
  background: color-mix(in srgb, var(--success) 18%, var(--surface));
  color: var(--success);
  font-size: .85rem;
}
.conexion-card.is-conectado .conexion-card-title {
  font-size: .85rem; margin: 0; flex: 1;
}
.conexion-card.is-conectado .conexion-card-text { display: none; }
.conexion-card.is-conectado .conexion-btn {
  padding: 6px 14px;
  font-size: .78rem;
  background: var(--danger);
}

.dash-stats {
  display: flex; gap: 12px; margin-bottom: 20px;
}
.dash-stat {
  flex: 1; background: var(--surface); border: 1.5px solid var(--border);
  border-radius: var(--radius); padding: 16px 12px; text-align: center;
  box-shadow: var(--shadow);
}
.dash-stat-icon {
  font-size: 1.1rem; margin-bottom: 6px;
}
.dash-stat--pending .dash-stat-icon    { color: var(--success); }
.dash-stat--disponible .dash-stat-icon { color: var(--info, #3b82f6); }
.dash-stat--delivered .dash-stat-icon  { color: var(--text); }
.dash-stat--cobrar .dash-stat-icon     { color: var(--success); }
.dash-stat--cobrado .dash-stat-icon    { color: var(--primary); }
.dash-stat-num {
  font-size: 2rem; font-weight: 800; line-height: 1;
}
.dash-stat-num--currency { font-size: 1.35rem; }
.dash-stat--pending .dash-stat-num    { color: var(--success); }
.dash-stat--disponible .dash-stat-num { color: var(--info, #3b82f6); }
.dash-stat--delivered .dash-stat-num  { color: var(--text); }
.dash-stat--cobrar .dash-stat-num     { color: var(--success); }
.dash-stat--cobrado .dash-stat-num    { color: var(--primary); }
.dash-stat-label {
  font-size: .72rem; color: var(--muted); font-weight: 600;
  margin-top: 4px; text-transform: uppercase; letter-spacing: .03em;
}

@keyframes stat-pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: .3; }
}
.stat-pulsing {
  animation: stat-pulse 1s ease-in-out infinite;
}

.dash-block-title {
  font-size: .78rem; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: .05em;
  margin-bottom: 10px; display: flex; align-items: center; gap: 6px;
}

.dash-card {
  background: var(--surface); border: 1.5px solid var(--border);
  border-radius: var(--radius); margin-bottom: 8px;
  overflow: hidden; box-shadow: var(--shadow);
  display: flex; cursor: pointer; -webkit-tap-highlight-color: transparent;
  transition: box-shadow .15s;
}
.dash-card:active { box-shadow: var(--shadow-md); }

.dash-card-strip {
  width: 4px; flex-shrink: 0; background: var(--primary);
}
.dash-card-strip--ok { background: var(--primary); }

.dash-card-body {
  flex: 1; padding: 11px 13px;
}
.dash-card-top {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 4px;
}
.dash-card-bottom {
  display: flex; justify-content: space-between; align-items: center;
}
.dash-card-num {
  font-weight: 800; font-size: .9rem; color: var(--primary);
}
.dash-card--delivered .dash-card-num { color: var(--primary); }
.dash-card-time {
  font-size: .7rem; color: var(--muted);
}
.dash-card-cliente {
  font-size: .85rem; font-weight: 600; color: var(--text);
}
.dash-card-total {
  font-size: .85rem; font-weight: 700;
}
.dash-card-addr {
  font-size: .75rem; color: var(--muted);
  margin-top: 5px; display: flex; align-items: flex-start; gap: 5px;
}
.dash-card-addr i { color: var(--primary); margin-top: 1px; flex-shrink: 0; }
.btn-tomar {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  width: 100%; margin-top: 10px; padding: 10px;
  background: var(--primary); color: #fff;
  border: none; border-radius: 8px; cursor: pointer;
  font-size: .85rem; font-weight: 700;
  box-shadow: 0 3px 10px rgba(255,160,0,.3);
  transition: opacity .15s, transform .1s;
  -webkit-tap-highlight-color: transparent;
}
.btn-tomar:active   { opacity: .85; transform: scale(.97); }
.btn-tomar:disabled { opacity: .5; pointer-events: none; }

/* ===== Misc ===== */
.logo-dark  { display: none; }
[data-theme="dark"] .logo-light { display: none; }
[data-theme="dark"] .logo-dark  { display: block; }

/* ===== Banner: instalar PWA en iOS (prerequisito para push) ===== */
.pwa-installed-screen {
  display: none; position: fixed; inset: 0; z-index: 3000;
  background: var(--bg); color: var(--text);
  flex-direction: column; align-items: center; justify-content: center;
  padding: 32px 24px; text-align: center;
}
.pwa-installed-screen.open { display: flex; }
.pwa-installed-screen img { height: 60px; width: auto; margin-bottom: 28px; }
.pwa-installed-title {
  font-size: 1.4rem; font-weight: 700; margin-bottom: 14px;
}
.pwa-installed-text {
  font-size: .95rem; color: var(--muted); line-height: 1.5;
  margin: 0; max-width: 320px;
}
.pwa-installed-text b { color: var(--primary); }

.ios-install-backdrop {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, .55);
  display: none; align-items: flex-end; justify-content: center;
  z-index: 2000; padding: 20px;
  -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px);
}
.ios-install-backdrop.open { display: flex; animation: fadeIn .2s ease-out; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

#pwaInstallModal { align-items: center; }

.ios-install-card {
  background: var(--surface); color: var(--text);
  width: 100%; max-width: 420px;
  border-radius: 18px;
  padding: 28px 22px 24px;
  box-shadow: 0 25px 60px rgba(0, 0, 0, .35);
  position: relative;
  animation: slideUp .25s ease-out;
}
@keyframes slideUp { from { transform: translateY(30px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.ios-install-close {
  position: absolute; top: 10px; right: 10px;
  background: transparent; border: none; cursor: pointer;
  width: 36px; height: 36px; border-radius: 50%;
  color: var(--muted); font-size: 1.1rem;
  display: flex; align-items: center; justify-content: center;
}
.ios-install-close:active { background: rgba(0, 0, 0, .06); }

.ios-install-icon {
  width: 56px; height: 56px; border-radius: 14px;
  background: linear-gradient(135deg, var(--primary), #f59e0b);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-size: 1.6rem; margin: 0 auto 14px;
  box-shadow: 0 6px 20px rgba(255, 160, 0, .35);
}
.ios-install-title {
  text-align: center; font-size: 1.05rem; font-weight: 700;
  margin-bottom: 8px;
}
.ios-install-text {
  text-align: center; font-size: .88rem;
  color: var(--muted); margin-bottom: 14px;
}
.ios-install-steps {
  margin: 0; padding-left: 22px; font-size: .88rem; line-height: 1.55;
}
.ios-install-steps li { margin-bottom: 6px; }
.ios-install-steps b { color: var(--primary, #FFA000); }

.btn-install-confirm, .btn-install-cancel {
  width: 100%; padding: 13px; border: none; border-radius: 10px;
  font-size: .9rem; font-weight: 700; cursor: pointer;
  transition: background .15s;
}
.btn-install-confirm {
  background: var(--primary); color: #fff; margin-top: 4px;
}
.btn-install-confirm:active { background: var(--primary-h); }
.btn-install-cancel {
  background: transparent; color: var(--muted);
  margin-top: 8px;
}
.btn-install-cancel:active { background: rgba(0,0,0,.04); }

/* ===== Version banner ===== */
.version-banner {
  position: fixed; top: 0; left: 0; right: 0; z-index: 9999;
  background: #1e40af; color: #fff;
  padding: 10px 20px;
  display: flex; align-items: center; justify-content: center; gap: 16px;
  font-size: .9rem; font-weight: 500;
  box-shadow: 0 2px 8px rgba(0,0,0,.25);
}
.version-banner button {
  background: #fff; color: #1e40af;
  border: none; border-radius: 6px;
  padding: 5px 14px; font-size: .85rem; font-weight: 600;
  cursor: pointer;
}
.version-banner button:hover { background: #e0e7ff; }
