:root {
  --navy: #0a1e52;
  --navy2: #1a3a8f;
  --naranja: #ff6b35;
  --naranja-osc: #e0551f;
  --texto: #1c1c22;
  --gris: #6a6a75;
  --linea: #dcdce4;
  --fondo: #f5f6fa;
  --verde: #1c9c4d;
  --rojo: #b3261e;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
  font-family: 'Segoe UI', system-ui, -apple-system, Arial, sans-serif;
  background: var(--fondo);
  color: var(--texto);
  font-size: 16px;
  line-height: 1.5;
}

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100dvh;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--navy) 0%, var(--navy2) 100%);
  padding: 24px;
}
.login-card {
  background: #fff; border-radius: 18px; padding: 32px 28px;
  width: 100%; max-width: 380px; box-shadow: 0 10px 40px rgba(0,0,0,.25);
}
.login-card h1 { font-size: 21px; color: var(--navy); margin-bottom: 4px; }
.login-card .sub { color: var(--gris); font-size: 14px; margin-bottom: 22px; }

label { display: block; font-size: 13px; font-weight: 600; color: var(--gris); margin: 14px 0 5px; }
input, select, textarea {
  width: 100%; padding: 12px 14px; border: 1px solid var(--linea);
  border-radius: 10px; font-size: 16px; font-family: inherit; background: #fff; color: var(--texto);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--navy2); border-color: transparent; }

button {
  font-family: inherit; font-size: 15px; font-weight: 700; cursor: pointer;
  border: none; border-radius: 10px; padding: 12px 20px; background: var(--navy);
  color: #fff; transition: filter .15s;
}
button:hover { filter: brightness(1.15); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.naranja { background: var(--naranja); }
button.gris { background: #e7e7ef; color: var(--texto); }
button.rojo { background: var(--rojo); }
button.full { width: 100%; margin-top: 20px; }
button.chico { padding: 7px 13px; font-size: 13px; border-radius: 8px; }

.error { background: #fdecea; color: var(--rojo); padding: 10px 14px; border-radius: 8px; font-size: 14px; margin-top: 14px; }
.ok    { background: #e8f6ed; color: var(--verde); padding: 10px 14px; border-radius: 8px; font-size: 14px; margin-top: 14px; }

/* ---------- Cabecera ---------- */
header {
  background: var(--navy); color: #fff; padding: 12px 18px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  position: sticky; top: 0; z-index: 50;
}
header .marca { font-weight: 800; font-size: 16px; letter-spacing: .3px; }
header .marca span { color: var(--naranja); }
header .quien { font-size: 12.5px; opacity: .8; }
header button { background: rgba(255,255,255,.15); padding: 7px 13px; font-size: 13px; }

/* ---------- Layout ---------- */
main { padding: 18px; max-width: 1100px; margin: 0 auto; }

nav.tabs {
  display: flex; gap: 6px; overflow-x: auto; padding: 12px 18px 0;
  background: var(--navy); position: sticky; top: 52px; z-index: 49;
}
nav.tabs button {
  background: transparent; color: rgba(255,255,255,.65); border-radius: 8px 8px 0 0;
  padding: 9px 15px; font-size: 14px; white-space: nowrap;
}
nav.tabs button.activo { background: var(--fondo); color: var(--navy); }

.panel { display: none; }
.panel.activo { display: block; }

.card {
  background: #fff; border: 1px solid var(--linea); border-radius: 14px;
  padding: 18px; margin-bottom: 16px;
}
.card h2 { font-size: 17px; color: var(--navy); margin-bottom: 12px; }
.card h3 { font-size: 14px; color: var(--gris); text-transform: uppercase; letter-spacing: 1px; margin: 18px 0 8px; }

.fila {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 11px 0; border-bottom: 1px solid var(--linea);
}
.fila:last-child { border-bottom: none; }
.fila .info { min-width: 0; }
.fila .nom { font-weight: 600; }
.fila .det { font-size: 13px; color: var(--gris); }
.acciones { display: flex; gap: 7px; flex-shrink: 0; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 620px) { .grid2 { grid-template-columns: 1fr; } }

.vacio { color: var(--gris); font-size: 14px; padding: 16px 0; text-align: center; }

.chip {
  display: inline-block; padding: 3px 10px; border-radius: 20px;
  font-size: 12px; font-weight: 700;
}
.chip.on  { background: #e8f6ed; color: var(--verde); }
.chip.off { background: #f0f0f5; color: var(--gris); }

#mapa { height: 420px; border-radius: 12px; overflow: hidden; }

/* ---------- Chat ---------- */
.chat-caja {
  height: 340px; overflow-y: auto; background: var(--fondo);
  border: 1px solid var(--linea); border-radius: 12px; padding: 12px;
  display: flex; flex-direction: column; gap: 8px;
}
.msg { max-width: 78%; padding: 8px 12px; border-radius: 14px; font-size: 14.5px; word-break: break-word; }
.msg.mio  { align-self: flex-end; background: var(--navy); color: #fff; border-bottom-right-radius: 4px; }
.msg.otro { align-self: flex-start; background: #fff; border: 1px solid var(--linea); border-bottom-left-radius: 4px; }
.msg img { max-width: 100%; border-radius: 8px; margin-top: 5px; display: block; }
.msg .hora { font-size: 11px; opacity: .65; margin-top: 3px; }
.chat-barra { display: flex; gap: 8px; margin-top: 10px; align-items: center; }
.chat-barra input[type=text] { flex: 1; }
.aviso-chat {
  font-size: 12px; color: var(--gris); background: #fff8e6;
  border: 1px solid #f0d98c; border-radius: 8px; padding: 8px 12px; margin-bottom: 10px;
}

.pill-btn {
  display: inline-flex; align-items: center; gap: 8px; background: var(--verde);
  color: #fff; padding: 11px 20px; border-radius: 50px; text-decoration: none;
  font-weight: 700; font-size: 15px;
}

/* ---------- Sub-tabs (archivo de chats) ---------- */
.subtabs { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.subtabs button {
  background: var(--fondo); color: var(--texto); border: 1px solid var(--linea);
  padding: 8px 14px; font-size: 13.5px; font-weight: 600; border-radius: 20px;
  display: inline-flex; align-items: center; gap: 7px;
}
.subtabs button:hover { filter: none; background: #ececf4; }
.migas { font-size: 13px; color: var(--gris); margin-bottom: 14px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.migas button {
  background: none; color: var(--navy2); font-weight: 700; padding: 0;
  font-size: 13px; text-decoration: underline; border-radius: 0;
}

/* ---------- Checklist del mapa ---------- */
.filtro-mapa { display: flex; gap: 8px; margin-bottom: 10px; }
.filtro-mapa button { padding: 6px 12px; font-size: 12.5px; }

/* ---------- Facturación / recibos para imprimir ---------- */
.recibo-bloque { border: 2px solid #000; margin-bottom: 24px; page-break-inside: avoid; }
.recibo-bloque table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; }
.recibo-bloque th, .recibo-bloque td {
  border-right: 1px solid #000; border-bottom: 1px solid #000;
  padding: 8px 9px; text-align: center; min-width: 34px;
}
.recibo-bloque tr > *:first-child { border-left: none; }
.recibo-bloque tr:first-child th, .recibo-bloque tr:first-child td { border-top: none; }
.recibo-bloque tr > *:last-child { border-right: none; }
.recibo-bloque tr:first-child th {
  background: var(--navy); color: #fff; border-bottom: 2px solid #000; font-size: 13.5px;
}
.recibo-bloque th.nombre-col, .recibo-bloque td.nombre-col { text-align: left; font-weight: 700; }
.recibo-bloque tr:not(:first-child):not(.fila-total):nth-child(even) td { background: #eef0f7; }
.recibo-bloque tr.fila-ajuste td { font-style: italic; color: #7a1f1f; }
.recibo-bloque .fila-total td { font-weight: 700; background: #ffe9d1; border-top: 2px solid #000; border-bottom: none; }
.recibo-firma { padding: 10px 10px; font-size: 13px; display: flex; justify-content: space-between; border-top: 2px solid #000; background: #fafafa; }
.recibo-aclaraciones { padding: 8px 10px; font-size: 11.5px; color: #555; border-top: 1px solid #000; }

@media print {
  header, nav.tabs { display: none !important; }
  main > *:not(#tab-facturacion) { display: none !important; }
  #tab-facturacion > .card:not(#cardRecibos) { display: none !important; }
  #cardRecibos > .card-toggle,
  #cardRecibos #btnVerRecibosCadetes,
  #cardRecibos #btnVerRecibosClientes,
  #cardRecibos #btnImprimirRecibos { display: none !important; }
  #cardRecibos { border: none !important; padding: 0 !important; margin: 0 !important; }
}

/* ---------- Tarjetas plegables (acordeón) ---------- */
.card-toggle, .card-toggle * {
  cursor: pointer !important; user-select: none;
}
.card-toggle {
  display: flex; align-items: center; justify-content: space-between;
}
.card-toggle .chevron { font-size: 13px; color: var(--gris); transition: transform .15s; }
.card-toggle.abierto .chevron { transform: rotate(90deg); }
