:root {
  --brand: #0d5c4d;
  --brand-claro: #e6f2ef;
  --acento: #d97706;
  --fondo: #f4f6f8;
  --panel: #ffffff;
  --borde: #dde3e8;
  --texto: #1f2933;
  --texto-suave: #64748b;
  --rojo: #dc2626;
  --verde: #16a34a;
  --azul: #2563eb;
  --ambar: #d97706;
  --radius: 10px;
  --sombra: 0 1px 3px rgba(15, 40, 60, .08), 0 4px 14px rgba(15, 40, 60, .06);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--fondo);
  color: var(--texto);
  font-size: 14px;
  display: flex;
}

/* ---------- Sidebar ---------- */
aside {
  width: 220px; min-width: 220px;
  background: linear-gradient(180deg, #0b3d34, #0d5c4d);
  color: #e8f3f0;
  display: flex; flex-direction: column;
  height: 100vh; position: sticky; top: 0;
}
.marca { padding: 18px 16px 14px; border-bottom: 1px solid rgba(255,255,255,.12); }
.marca .logo { display: block; width: 100%; max-width: 176px; height: auto; margin: 0 0 7px; filter: drop-shadow(0 2px 5px rgba(0,0,0,.4)); }
.marca small { color: #9fc6bd; display: block; margin-top: 3px; font-size: 11px; }
nav { padding: 10px 8px; flex: 1; }
nav button {
  display: flex; align-items: center; gap: 10px;
  width: 100%; text-align: left;
  background: none; border: none; color: #cfe5df;
  padding: 11px 12px; margin: 2px 0;
  border-radius: 8px; cursor: pointer; font-size: 14px; font-family: inherit;
}
nav button:hover { background: rgba(255,255,255,.08); }
nav button.activo { background: rgba(255,255,255,.16); color: #fff; font-weight: 600; }
.sidebar-pie { padding: 12px 16px; font-size: 11px; color: #8fb8ae; border-top: 1px solid rgba(255,255,255,.12); }

/* ---------- Layout principal ---------- */
main { flex: 1; padding: 22px 26px; overflow-x: auto; min-height: 100vh; }
.vista { display: none; }
.vista.activa { display: block; }
.vista-encabezado { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 16px; flex-wrap: wrap; }
.vista-encabezado h2 { margin: 0; font-size: 20px; }
.acciones-encabezado { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ---------- Componentes ---------- */
.panel { background: var(--panel); border: 1px solid var(--borde); border-radius: var(--radius); box-shadow: var(--sombra); padding: 16px; }
.boton {
  background: var(--brand); color: #fff; border: none; border-radius: 8px;
  padding: 9px 15px; font-size: 13.5px; cursor: pointer; font-family: inherit; font-weight: 600;
  display: inline-flex; align-items: center; gap: 6px;
}
.boton:hover { filter: brightness(1.1); }
.boton:disabled { opacity: .5; cursor: not-allowed; }
.boton.secundario { background: #fff; color: var(--texto); border: 1px solid var(--borde); font-weight: 500; }
.boton.secundario:hover { background: #f1f5f9; filter: none; }
.boton.peligro { background: #fee2e2; color: var(--rojo); }
.boton.chico { padding: 5px 10px; font-size: 12.5px; }
.boton.whatsapp { background: #16a34a; }

input, select, textarea {
  font-family: inherit; font-size: 13.5px;
  padding: 8px 10px; border: 1px solid var(--borde); border-radius: 7px;
  background: #fff; color: var(--texto); width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(13, 92, 77, .3); border-color: var(--brand); }
label { font-size: 12px; font-weight: 600; color: var(--texto-suave); display: block; margin-bottom: 4px; }
.campo { margin-bottom: 12px; }
.fila-campos { display: grid; gap: 12px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13.5px; color: var(--texto); font-weight: 500; }
.check input { width: auto; }

table.tabla { width: 100%; border-collapse: collapse; background: var(--panel); border-radius: var(--radius); overflow: hidden; box-shadow: var(--sombra); }
.tabla th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .4px; color: var(--texto-suave); background: #f8fafc; padding: 10px 12px; border-bottom: 1px solid var(--borde); white-space: nowrap; }
.tabla td { padding: 10px 12px; border-bottom: 1px solid #eef2f5; vertical-align: middle; }
.tabla tr:last-child td { border-bottom: none; }
.tabla tr:hover td { background: #f8fafc; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

.badge { display: inline-block; padding: 3px 9px; border-radius: 20px; font-size: 11.5px; font-weight: 600; white-space: nowrap; }
.badge.Solicitado { background: #fef3c7; color: #92400e; }
.badge.Confirmado { background: #dbeafe; color: #1e40af; }
.badge.Pagado { background: #dcfce7; color: #166534; }
.badge.Rechazado { background: #f1f5f9; color: #64748b; text-decoration: line-through; }
.badge.Cancelado { background: #fee2e2; color: #991b1b; }
.badge.gris { background: #f1f5f9; color: #475569; }
.badge.verde { background: #dcfce7; color: #166534; }
.badge.rojo { background: #fee2e2; color: #991b1b; }
.badge.ambar { background: #fef3c7; color: #92400e; }
.badge.azul { background: #dbeafe; color: #1e40af; }

.filtros { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.filtros .chip {
  border: 1px solid var(--borde); background: #fff; border-radius: 20px;
  padding: 6px 14px; font-size: 12.5px; cursor: pointer; font-family: inherit;
}
.filtros .chip.activo { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
.filtros input[type=search] { width: 230px; }

/* ---------- Calendario ---------- */
.cal-contenedor { overflow-x: auto; background: var(--panel); border: 1px solid var(--borde); border-radius: var(--radius); box-shadow: var(--sombra); }
table.calendario { border-collapse: collapse; width: max-content; min-width: 100%; }
.calendario th, .calendario td { border: 1px solid #e8edf1; padding: 0; }
.calendario thead th { background: #f8fafc; font-size: 11px; color: var(--texto-suave); padding: 6px 4px; min-width: 34px; position: sticky; top: 0; z-index: 2; }
.calendario thead th.finde { background: #eef2f6; }
.calendario thead th.hoy { background: var(--brand-claro); color: var(--brand); }
.calendario .col-unidad {
  position: sticky; left: 0; background: #fff; z-index: 3;
  min-width: 170px; max-width: 170px; padding: 7px 10px; text-align: left;
  font-size: 12.5px; border-right: 2px solid var(--borde);
}
.calendario .col-unidad small { color: var(--texto-suave); display: block; font-size: 10.5px; }
.calendario .grupo td { background: #eef4f2; font-weight: 700; font-size: 11.5px; color: var(--brand); padding: 5px 10px; text-transform: uppercase; letter-spacing: .5px; }
.calendario td.dia { height: 40px; min-width: 34px; vertical-align: top; }
.calendario td.dia.finde { background: #fafbfd; }
.calendario td.dia.hoy { background: #f0faf7; }
.cal-chip {
  display: block; font-size: 10px; line-height: 1.25; padding: 2px 4px; margin: 1px;
  border-radius: 4px; cursor: pointer; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
  max-width: 120px; border-left: 3px solid transparent; font-weight: 600;
}
.cal-chip.Confirmado { background: #dbeafe; color: #1e40af; border-left-color: #2563eb; }
.cal-chip.Pagado { background: #dcfce7; color: #166534; border-left-color: #16a34a; }
.cal-chip.Solicitado { background: #fef9c3; color: #854d0e; border-left-color: #eab308; border-style: dashed; }
.cal-chip.bloqueo { background: #e2e8f0; color: #475569; border-left-color: #64748b; cursor: default; }
.cal-chip.promotor { box-shadow: inset 0 0 0 1.5px #7c3aed; background: #f3e8ff; color: #6b21a8; }
.cal-chip.ruta {
  background: repeating-linear-gradient(45deg, #d6ede4, #d6ede4 5px, #e8f5ef 5px, #e8f5ef 10px);
  color: #0b5c42; border-left-color: #0d9468; cursor: default;
}
.cal-leyenda { display: flex; gap: 16px; align-items: center; font-size: 12px; color: var(--texto-suave); margin-top: 10px; flex-wrap: wrap; }
.cal-leyenda span::before { content: ''; display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; }
.cal-leyenda .l-conf::before { background: #2563eb; }
.cal-leyenda .l-pag::before { background: #16a34a; }
.cal-leyenda .l-sol::before { background: #eab308; }
.cal-leyenda .l-blo::before { background: #64748b; }
.cal-leyenda .l-prom::before { background: #7c3aed; }
.cal-leyenda .l-ruta::before { background: #0d9468; }

/* ---------- Cotizador ---------- */
.cotizador-grid { display: grid; grid-template-columns: minmax(380px, 1fr) minmax(340px, 460px); gap: 18px; align-items: start; }
@media (max-width: 1100px) { .cotizador-grid { grid-template-columns: 1fr; } }
.desglose-linea { display: flex; justify-content: space-between; padding: 5px 0; font-size: 13.5px; }
.desglose-linea span:last-child { font-variant-numeric: tabular-nums; font-weight: 600; }
.desglose-linea.sub { color: var(--texto-suave); font-size: 12.5px; padding-left: 12px; }
.desglose-linea.total { border-top: 2px solid var(--borde); margin-top: 6px; padding-top: 10px; font-size: 17px; font-weight: 700; color: var(--brand); }
.aviso { background: #fef3c7; border: 1px solid #fcd34d; color: #92400e; border-radius: 8px; padding: 9px 12px; font-size: 12.5px; margin: 8px 0; }
.nota-info { background: var(--brand-claro); border: 1px solid #b5d6cd; color: var(--brand); border-radius: 8px; padding: 9px 12px; font-size: 12.5px; margin: 8px 0; }
.modelo-costos { background: #f8fafc; border: 1px dashed var(--borde); border-radius: 8px; padding: 12px 14px; margin-top: 14px; }
.modelo-costos h4 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--texto-suave); }
.disponibilidad-mini { margin-top: 14px; font-size: 13px; }
.disponibilidad-mini ul { margin: 6px 0 0; padding-left: 18px; }
.tachado { color: var(--texto-suave); text-decoration: line-through; }

/* ---------- Modal ---------- */
.modal-fondo {
  position: fixed; inset: 0; background: rgba(15, 30, 40, .45);
  display: none; align-items: flex-start; justify-content: center; z-index: 50;
  padding: 5vh 16px; overflow-y: auto;
}
.modal-fondo.abierto { display: flex; }
.modal {
  background: #fff; border-radius: 14px; box-shadow: 0 20px 60px rgba(0,0,0,.25);
  width: 100%; max-width: 640px; padding: 22px; position: relative;
}
.modal.ancho { max-width: 860px; }
.modal h3 { margin: 0 0 16px; font-size: 17px; }
.modal-cerrar { position: absolute; top: 14px; right: 14px; background: #f1f5f9; border: none; border-radius: 50%; width: 30px; height: 30px; cursor: pointer; font-size: 15px; }
.modal-pie { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; flex-wrap: wrap; }

/* ---------- Toast ---------- */
#toasts { position: fixed; bottom: 20px; right: 20px; z-index: 100; display: flex; flex-direction: column; gap: 8px; }
.toast { background: #1f2933; color: #fff; padding: 12px 18px; border-radius: 10px; box-shadow: var(--sombra); font-size: 13.5px; max-width: 380px; animation: entra .2s ease-out; }
.toast.error { background: #b91c1c; }
.toast.exito { background: var(--brand); }
@keyframes entra { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

.texto-suave { color: var(--texto-suave); }
.mono { font-variant-numeric: tabular-nums; }
.whatsapp-msg { white-space: pre-wrap; background: #f0fdf4; border: 1px solid #bbf7d0; border-radius: 10px; padding: 14px; font-size: 13px; max-height: 320px; overflow-y: auto; }
.lista-radios { display: flex; flex-direction: column; gap: 6px; max-height: 320px; overflow-y: auto; }
.radio-unidad { display: flex; align-items: flex-start; gap: 10px; border: 1px solid var(--borde); border-radius: 8px; padding: 10px 12px; cursor: pointer; }
.radio-unidad:hover { background: #f8fafc; }
.radio-unidad.nodisp { opacity: .55; cursor: not-allowed; background: #f8fafc; }
.radio-unidad input { width: auto; margin-top: 3px; }
.radio-unidad .detalle { font-size: 12px; color: var(--texto-suave); }
.radio-unidad .motivo { font-size: 11.5px; color: var(--rojo); }

#serv-tabla, #usuarios-tabla, #bloqueos-tabla { overflow-x: auto; }

/* el desplegable de agencia vive sobre fondo oscuro, pero su lista abre sobre fondo claro */
#agencia-activa option { background: #fff; color: var(--texto); }

/* ---------- Teléfonos y tablets ---------- */
@media (max-width: 840px) {
  body { flex-direction: column; }
  aside { width: 100%; min-width: 0; height: auto; position: static; }
  .marca { padding: 10px 16px 6px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
  .marca .logo { max-width: 118px; margin: 0; }
  .marca small { display: inline; margin: 0; }
  nav { display: flex; overflow-x: auto; padding: 4px 8px 8px; gap: 4px; -webkit-overflow-scrolling: touch; }
  nav button { white-space: nowrap; width: auto; padding: 8px 12px; font-size: 13px; flex-shrink: 0; }
  .sidebar-pie { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 8px 14px; }
  #usuario-box { margin-bottom: 0 !important; }
  main { padding: 14px 12px; min-height: 0; }
  .vista-encabezado h2 { font-size: 17px; }
  .cotizador-grid { grid-template-columns: 1fr; }
  .fila-campos { grid-template-columns: 1fr 1fr !important; }
  .filtros input[type=search] { width: 100%; }
  .modal { padding: 16px; }
  .modal-pie { justify-content: stretch; }
  .modal-pie .boton { flex: 1; justify-content: center; }
  input, select, textarea { font-size: 16px; } /* evita el zoom automático de iOS */
}
