:root {
  /* Paleta de marca: blanco cálido, negro tinta, taupe del banner */
  --negro: #1b1714;
  --taupe: #7c7269;
  --taupe-claro: #efeae3;
  --crema: #f7f4ef;
  --texto: #26211d;
  --gris: #9a9088;
  --borde: #e6ded4;
  --blanco: #ffffff;
  /* Estados de urgencia, en tonos apagados acordes a la paleta */
  --rojo: #a8443a;
  --rojo-bg: #f2e2df;
  --amarillo: #8a6d2f;
  --amarillo-bg: #efe7d6;
  --ok: #5c6b54;
  --ok-bg: #e7ebe3;
  --radio: 8px;
  --sombra: 0 1px 2px rgba(27,23,20,.04), 0 10px 30px rgba(27,23,20,.05);
  --serif-titulo: 'Manrope', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --serif-texto: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--serif-texto);
  background: var(--crema);
  color: var(--texto);
  line-height: 1.5;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { font-family: var(--serif-titulo); font-weight: 700; letter-spacing: -.01em; }

.hidden { display: none !important; }

/* ---------- Botones (estilo editorial: negro, rectos, mayúsculas) ---------- */
.btn {
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 12px 18px;
  font-family: var(--serif-texto);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: opacity .15s, background .15s;
}
.btn-primary { background: var(--negro); color: #fff; }
.btn-primary:active { opacity: .8; }
.btn-secondary { background: transparent; color: var(--negro); border-color: var(--negro); }
.btn-secondary:active { background: var(--taupe-claro); }
.btn-danger { background: transparent; color: var(--rojo); border-color: var(--rojo); }
.btn-sm { padding: 8px 13px; font-size: 12px; }
.btn-ghost {
  background: none; border: none; color: inherit;
  font-size: 15px; cursor: pointer; padding: 6px 8px;
  font-family: var(--serif-texto); letter-spacing: .04em;
}
.btn-block { width: 100%; }

/* ---------- Login ---------- */
.login-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--crema);
}
.login-card {
  background: var(--blanco);
  border: 1px solid var(--borde);
  border-radius: var(--radio);
  box-shadow: var(--sombra);
  padding: 40px 28px;
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.brand {
  font-family: var(--serif-titulo);
  font-size: 30px; font-weight: 800; color: var(--negro);
  text-align: center; letter-spacing: -.02em;
}
.brand span { font-weight: 600; color: var(--taupe); }
.login-sub {
  text-align: center; color: var(--taupe); margin-bottom: 8px;
  text-transform: uppercase; letter-spacing: .18em; font-size: 12px;
}

label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--gris); font-weight: 600; letter-spacing: .03em; }
input, select, textarea {
  font-size: 16px;
  font-family: var(--serif-texto);
  padding: 11px 12px;
  border: 1px solid var(--borde);
  border-radius: 4px;
  background: #fff;
  color: var(--texto);
  width: 100%;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--taupe); box-shadow: 0 0 0 2px var(--taupe-claro); }
textarea { resize: vertical; min-height: 64px; }

.error-msg { color: var(--rojo); font-size: 14px; min-height: 18px; text-align: center; }

/* ---------- App layout ---------- */
.app { min-height: 100vh; padding-bottom: 80px; }
.topbar {
  position: sticky; top: 0; z-index: 5;
  background: var(--taupe);
  color: #fff;
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px; padding-top: max(16px, env(safe-area-inset-top));
}
.topbar-title { font-family: var(--serif-titulo); font-size: 20px; font-weight: 700; letter-spacing: -.01em; }
.topbar .btn-ghost { color: #fff; text-transform: uppercase; font-size: 12px; letter-spacing: .1em; }

.content { padding: 18px 16px; max-width: 760px; margin: 0 auto; }
.view-hint { color: var(--taupe); font-size: 14px; margin-bottom: 16px; }

.list-head { display: flex; gap: 10px; margin-bottom: 16px; align-items: center; }
.list-head input, .list-head select { flex: 1; }

/* ---------- Recuadro de pendientes (dashboard) ---------- */
.pendientes { padding: 16px; margin-bottom: 16px; }
.pend-row {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 12px 0; border-bottom: 1px solid var(--crema); cursor: pointer; font-size: 15px;
}
.pend-row:last-child { border-bottom: none; }
.pend-row:active { opacity: .6; }
.pend-num {
  font-family: var(--serif-titulo); font-weight: 800; color: var(--negro);
  background: var(--taupe-claro); border-radius: 999px;
  min-width: 30px; text-align: center; padding: 2px 9px;
}

/* ---------- Cards ---------- */
.cards { display: flex; flex-direction: column; gap: 12px; }
.card {
  background: var(--blanco);
  border: 1px solid var(--borde);
  border-radius: var(--radio);
  box-shadow: var(--sombra);
  padding: 18px;
}
.card-title { font-family: var(--serif-titulo); font-size: 19px; font-weight: 600; }
.card-sub { color: var(--gris); font-size: 14px; margin-top: 2px; }
.card-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.card-actions { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.card-actions .btn { flex: 1; min-width: 120px; }

.badge {
  display: inline-block;
  padding: 3px 11px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .04em;
  white-space: nowrap;
}
.badge-rojo { background: var(--rojo-bg); color: var(--rojo); }
.badge-amarillo { background: var(--amarillo-bg); color: var(--amarillo); }
.badge-verde { background: var(--ok-bg); color: var(--ok); }
.badge-tipo { background: var(--taupe-claro); color: var(--taupe); }

.meta-line { font-size: 15px; color: var(--gris); margin-top: 6px; }
.meta-line strong { color: var(--texto); font-weight: 600; }

.empty { text-align: center; color: var(--gris); padding: 40px 16px; font-style: italic; }

.linklike { background: none; border: none; color: var(--taupe); font-weight: 600; cursor: pointer; padding: 0; font-size: 14px; font-family: var(--serif-texto); }

/* ---------- Sub-listas ---------- */
.subsection { margin-top: 18px; border-top: 1px solid var(--borde); padding-top: 16px; }
.subsection h3 { font-size: 17px; margin-bottom: 10px; display: flex; justify-content: space-between; align-items: center; }
.sub-item {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 10px 0; border-bottom: 1px solid var(--crema); font-size: 15px;
}
.sub-item:last-child { border-bottom: none; }

/* ---------- Métricas (perfil) ---------- */
.stats-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 18px 0; }
.stat {
  background: var(--taupe-claro);
  border-radius: 6px;
  padding: 12px 8px;
  text-align: center;
  display: flex; flex-direction: column; gap: 3px;
}
.stat-num { font-family: var(--serif-titulo); font-size: 17px; font-weight: 700; color: var(--negro); }
.stat-lbl { font-size: 11px; color: var(--taupe); text-transform: uppercase; letter-spacing: .06em; }

/* ---------- Dashboard ---------- */
.kpi-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-bottom: 16px; }
.kpi {
  background: var(--blanco);
  border: 1px solid var(--borde);
  border-radius: var(--radio);
  box-shadow: var(--sombra);
  padding: 18px;
}
.kpi-num { font-family: var(--serif-titulo); font-size: 26px; font-weight: 700; color: var(--negro); }
.kpi-lbl { font-size: 12px; color: var(--taupe); margin-top: 2px; text-transform: uppercase; letter-spacing: .05em; }
.chart-title { font-size: 17px; margin-bottom: 14px; }
.config-h { font-size: 20px; margin-bottom: 12px; }

/* ---------- Toggle Hoy/Semana (despacho) ---------- */
.seg-toggle { display: flex; flex: 1; border: 1px solid var(--borde); border-radius: 6px; overflow: hidden; }
.seg-btn {
  flex: 1; background: var(--blanco); border: none; cursor: pointer;
  padding: 10px; font-family: var(--serif-texto); font-size: 14px; font-weight: 600; color: var(--gris);
}
.seg-btn.active { background: var(--taupe); color: #fff; }

/* ---------- Modo repartidor: solo despachos ---------- */
.rol-repartidor .bottom-nav { display: none; }
.rol-repartidor .app { padding-bottom: 16px; }
.desp-foto { width: 100%; max-height: 220px; object-fit: cover; border-radius: 8px; margin-top: 10px; display: block; }
.check-row { flex-direction: row; align-items: center; gap: 8px; font-size: 15px; color: var(--texto); font-weight: 500; }
.check-row input { width: auto; }
.parada-num { background: var(--negro); color: #fff; border-radius: 999px; padding: 2px 10px; font-size: 13px; font-weight: 700; }
.card canvas { max-height: 260px; }

/* ---------- Bottom nav ---------- */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 5;
  background: var(--blanco);
  border-top: 1px solid var(--borde);
  display: flex;
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-btn {
  flex: 1;
  background: none; border: none; cursor: pointer;
  padding: 10px 4px;
  font-size: 20px;
  color: var(--gris);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-family: var(--serif-texto);
}
.nav-btn span { font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }
.nav-btn.active { color: var(--negro); }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(27,23,20,.45); }
.modal-card {
  position: relative;
  background: var(--blanco);
  width: 100%; max-width: 560px;
  border-radius: 12px 12px 0 0;
  max-height: 92vh; overflow-y: auto;
  padding: 22px;
  padding-bottom: max(22px, env(safe-area-inset-bottom));
  animation: slideup .2s ease;
}
@keyframes slideup { from { transform: translateY(30px); opacity: .6; } to { transform: none; opacity: 1; } }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; }
.modal-head h2 { font-size: 23px; }
.modal-form { display: flex; flex-direction: column; gap: 14px; }
.modal-form .row2 { display: flex; gap: 10px; }
.modal-form .row2 > * { flex: 1; }

@media (min-width: 600px) {
  .modal { align-items: center; }
  .modal-card { border-radius: 12px; }
}

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 92px; left: 50%; transform: translateX(-50%);
  background: var(--negro); color: #fff;
  padding: 12px 22px; border-radius: 999px; font-size: 15px;
  z-index: 30; box-shadow: 0 4px 16px rgba(27,23,20,.3);
  max-width: 90%;
}

.loading { text-align: center; color: var(--gris); padding: 30px; font-style: italic; }
