/* =============================================================
   Plataforma de Asistencias — estilos
   Los colores de marca (--brand, --side y sus textos) se inyectan
   por usuario desde views/partials/head.ejs
   ============================================================= */
:root {
  --brand: #2563eb;
  --brand-text: #ffffff;
  --side: #0f172a;
  --side-text: #ffffff;

  --brand-hover: color-mix(in srgb, var(--brand) 85%, #000);
  --brand-soft: color-mix(in srgb, var(--brand) 10%, var(--surface));
  --side-muted: color-mix(in srgb, var(--side-text) 60%, var(--side));
  --side-hover: color-mix(in srgb, var(--side-text) 9%, var(--side));
  --side-active: color-mix(in srgb, var(--brand) 30%, var(--side));

  --bg: #f4f6fa;
  --surface: #ffffff;
  --input-bg: #ffffff;
  --input-border: #d1d5db;
  --row-alt: #fafbfc;
  --row-new: #fff7ed;
  --row-new-flash: #fed7aa;
  --text: #111827;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --danger: #dc2626;
  --success: #059669;

  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --sidebar-w: 256px;
  --topbar-h: 60px;
  font-size: 15px;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { line-height: 1.25; margin: 0; }
h1 { font-size: 1.5rem; display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
h2 { font-size: 1.1rem; }
h3 { font-size: .95rem; }
a { color: inherit; }
img { max-width: 100%; }
code { font-size: .85rem; }
[hidden] { display: none !important; }

.muted { color: var(--text-muted); }
.small { font-size: .85rem; }
.right { text-align: right; }
.table th.center, .table td.center { text-align: center; }
/* Botón que muestra/oculta bloques en celular (en escritorio no aparece) */
.solo-movil { display: none !important; }
.link { color: var(--brand); text-decoration: none; font-weight: 500; }
.link:hover { text-decoration: underline; }
.pre { white-space: pre-wrap; word-break: break-word; margin: .25rem 0 0; }
.upper { text-transform: uppercase; }
.stack { display: flex; flex-direction: column; gap: 1rem; }

/* ---------- Layout ---------- */
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w);
  background: var(--side); color: var(--side-text);
  display: flex; flex-direction: column; z-index: 40;
  transition: transform .25s ease;
}
.brand {
  display: flex; align-items: center; gap: .75rem;
  padding: 1rem 1.25rem; min-height: var(--topbar-h);
  text-decoration: none; color: var(--side-text);
  border-bottom: 1px solid color-mix(in srgb, var(--side-text) 10%, transparent);
}
.brand-logo { width: 36px; height: 36px; object-fit: contain; border-radius: 8px; background: #fff; padding: 3px; flex-shrink: 0; }
.brand-logo.lg { width: 64px; height: 64px; padding: 6px; box-shadow: var(--shadow); }
.brand-name { font-weight: 700; font-size: 1.05rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.nav { padding: .75rem .75rem 2rem; overflow-y: auto; flex: 1; }
.nav-section {
  font-size: .72rem; text-transform: uppercase; letter-spacing: .06em;
  color: var(--side-muted); padding: 1rem .75rem .35rem;
}
.nav-link {
  display: flex; align-items: center; gap: .75rem;
  padding: .55rem .75rem; border-radius: 8px;
  color: var(--side-text); text-decoration: none; opacity: .88;
}
.nav-link svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
.nav-link:hover { background: var(--side-hover); opacity: 1; }
.nav-link.active { background: var(--side-active); opacity: 1; font-weight: 600; box-shadow: inset 3px 0 0 var(--brand); }

.main { margin-left: var(--sidebar-w); min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 30;
  height: var(--topbar-h); display: flex; align-items: center; gap: 1rem;
  padding: 0 1.5rem; background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar-title { font-weight: 600; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.content { padding: 1.5rem; width: 100%; max-width: 1400px; margin: 0 auto; display: flex; flex-direction: column; gap: 1.25rem; }

.icon-btn { background: none; border: 0; padding: .4rem; border-radius: 8px; cursor: pointer; color: var(--text); }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.icon-btn:hover { background: var(--bg); }
.menu-toggle { display: none; }
.backdrop { display: none; }

/* Menú de usuario */
.user-menu { position: relative; }
.user-menu summary { list-style: none; display: flex; align-items: center; gap: .5rem; cursor: pointer; padding: .25rem .5rem; border-radius: 999px; }
.user-menu summary::-webkit-details-marker { display: none; }
.user-menu summary:hover { background: var(--bg); }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center;
  background: var(--brand); color: var(--brand-text); font-weight: 700; font-size: .8rem;
}
.user-dropdown {
  position: absolute; right: 0; top: calc(100% + .5rem); width: 260px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 10px 30px rgba(0, 0, 0, .12); padding: .5rem; z-index: 50;
}
.user-info { display: flex; flex-direction: column; padding: .5rem .75rem .75rem; border-bottom: 1px solid var(--border); margin-bottom: .35rem; }
.user-info small { color: var(--text-muted); }
.user-dropdown a, .user-dropdown button {
  display: block; width: 100%; text-align: left; padding: .55rem .75rem; border-radius: 8px;
  background: none; border: 0; font: inherit; color: inherit; text-decoration: none; cursor: pointer;
}
.user-dropdown a:hover, .user-dropdown button:hover { background: var(--bg); }

/* ---------- Componentes ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.25rem;
}
.card-header { display: flex; justify-content: space-between; align-items: center; gap: .75rem 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.card-header > h2 { margin-right: auto; }
.card-title { margin-bottom: 1rem; }
.subtitle { margin-top: 1.25rem; font-size: .9rem; }
.section-title { font-size: 1rem; margin: 1.75rem 0 .75rem; padding-top: 1.25rem; border-top: 1px solid var(--border); }
.section-title.first { margin-top: 0; padding-top: 0; border-top: 0; }
.section-heading { font-size: 1.15rem; margin-top: .5rem; }
.empty { padding: 1.5rem 0; text-align: center; margin: 0; }

.page-header { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; flex-wrap: wrap; }
.page-header p { margin: .25rem 0 0; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.back-link { display: inline-block; font-size: .85rem; color: var(--text-muted); text-decoration: none; margin-bottom: .35rem; }
.back-link:hover { color: var(--brand); }

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1.25rem; align-items: start; }
.grid-2.wide-right { grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); }

/* Botones */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  padding: .55rem 1rem; border-radius: 8px; border: 1px solid transparent;
  font: inherit; font-weight: 600; font-size: .9rem; line-height: 1.2;
  text-decoration: none; cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s;
}
.btn-sm { padding: .35rem .7rem; font-size: .82rem; }
.btn-block { width: 100%; }
.btn-primary { background: var(--brand); color: var(--brand-text); }
.btn-primary:hover { background: var(--brand-hover); }
.btn-ghost { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn-ghost:hover { border-color: var(--brand); color: var(--brand); }
.btn-danger-ghost { background: transparent; border-color: transparent; color: var(--danger); }
.btn-danger-ghost:hover { background: #fef2f2; }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, summary:focus-visible, .nav-link:focus-visible {
  outline: 2px solid var(--brand); outline-offset: 2px;
}

/* Formularios */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem 1.25rem; }
.form-grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.span-2 { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: .35rem; min-width: 0; }
.field > span:first-child { font-size: .85rem; font-weight: 600; }
input[type=text], input[type=email], input[type=tel], input[type=password], input[type=number],
input[type=search], input[type=date], input[type=file], select, textarea {
  width: 100%; font: inherit; color: var(--text);
  padding: .55rem .7rem; border: 1px solid var(--input-border); border-radius: 8px; background: var(--input-bg);
}
input[type=file] { padding: .4rem; }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--brand); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 20%, transparent); }
.form-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1.5rem; flex-wrap: wrap; }
.check { display: flex; align-items: flex-start; gap: .6rem; cursor: pointer; }
.check input { margin-top: .25rem; accent-color: var(--brand); width: 16px; height: 16px; }
.check-highlight { padding: .85rem 1rem; border: 1px dashed var(--border); border-radius: 8px; margin-bottom: 1rem; }
.color-field { display: flex; align-items: center; gap: .6rem; }
.color-field input[type=color] { width: 48px; height: 38px; padding: 2px; border: 1px solid var(--input-border); border-radius: 8px; background: var(--input-bg); cursor: pointer; }

.perm-grid { border: 0; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem; }
.perm-grid:disabled { opacity: .45; }
.perm-group { display: flex; flex-direction: column; gap: .5rem; padding: 1rem; background: var(--bg); border-radius: 8px; }
.perm-group h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); }

.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; align-self: flex-start; }
.segmented label { cursor: pointer; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span { display: block; padding: .5rem 1rem; font-weight: 600; font-size: .9rem; }
.segmented input:checked + span { background: var(--brand); color: var(--brand-text); }
.segmented input:disabled + span { opacity: .4; cursor: not-allowed; }
.segmented input:focus-visible + span { outline: 2px solid var(--brand); outline-offset: -2px; }

/* Barra de filtros */
.toolbar { display: flex; flex-wrap: wrap; gap: .75rem 1rem; align-items: flex-end; padding: 1rem 1.25rem; }
.toolbar .field { flex: 0 1 180px; }
.toolbar .field.grow { flex: 1 1 240px; }
.toolbar-actions { display: flex; gap: .5rem; }

/* Tablas */
.table-wrap { overflow-x: auto; margin: 0 -1.25rem; }
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th, .table td { padding: .7rem 1.25rem; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); font-weight: 600; background: var(--row-alt); white-space: nowrap; }
.table th.right, .table td.right { text-align: right; }
.table tbody tr:hover { background: var(--row-alt); }
.table tbody tr:last-child td { border-bottom: 0; }
.table.compact th, .table.compact td { padding: .5rem 1.25rem; }
.row-actions { white-space: nowrap; }
.row-actions form { display: inline; }

.pagination { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; padding-top: 1rem; margin-top: .5rem; border-top: 1px solid var(--border); font-size: .85rem; }
.pager { display: flex; align-items: center; gap: .75rem; }

/* Badges y chips */
.badge { display: inline-block; padding: .15rem .6rem; border-radius: 999px; font-size: .75rem; font-weight: 600; white-space: nowrap; background: #f3f4f6; color: #374151; }
.badge-activo, .badge-cerrada { background: #d1fae5; color: #065f46; }
.badge-inactivo, .badge-cancelada { background: #f3f4f6; color: #6b7280; }
.badge-abierta { background: #fef3c7; color: #92400e; }
.badge-asignada { background: #dbeafe; color: #1e40af; }
.badge-en_camino { background: #ede9fe; color: #5b21b6; }
.badge-en_proceso { background: #cffafe; color: #155e75; }
.badge-arribo { background: #f3e8ff; color: #6b21a8; }
.badge-contacto { background: #fce7f3; color: #9d174d; }
.badge-no_procedente { background: #e7e5e4; color: #44403c; }
/* Estado del seguro de los vehículos */
.badge-seguro-vigente { background: #d1fae5; color: #065f46; }
.badge-seguro-por_vencer { background: #fef3c7; color: #92400e; }
.badge-seguro-vencido { background: #fee2e2; color: #991b1b; }
.badge-seguro-sin { background: #f3f4f6; color: #6b7280; }
.pdf-link { display: inline-flex; align-items: center; gap: .2rem; margin-left: .35rem; font-size: .8rem; font-weight: 600; color: #b91c1c; text-decoration: none; }
.pdf-link:hover { text-decoration: underline; }
/* Cobranza */
.badge-cobro-por_facturar { background: #e0f2fe; color: #075985; }
.badge-cobro-facturada { background: #fef3c7; color: #92400e; }
.badge-cobro-pagada { background: #d1fae5; color: #065f46; }
.badge-cobro-cancelada { background: #f3f4f6; color: #6b7280; text-decoration: line-through; }
.cobro-grupo { border: 1px solid var(--border); border-radius: 8px; padding: 1rem; }
.cobro-grupo-header { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: .5rem; }
.cobro-grupo .table-wrap { margin: 0; }
.cobro-resumen { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-top: .75rem; padding-top: .75rem; border-top: 1px solid var(--border); font-size: .9rem; }
.cobro-factura { margin-top: .75rem; font-size: .9rem; }
.cobro-factura summary { cursor: pointer; padding: .25rem 0; }
.cobro-factura .form-grid { margin-top: .5rem; }
.cobro-grupo .alert { margin-bottom: .5rem; }
.inline-filtro select { width: auto; padding: .35rem .6rem; font-size: .85rem; }
.totales { display: grid; grid-template-columns: auto 140px; justify-content: end; gap: .3rem 1.5rem; margin: 1rem 0 0; font-size: .95rem; }
.totales dt { color: var(--text-muted); text-align: right; }
.totales dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.totales .total { font-weight: 700; font-size: 1.1rem; color: var(--text); padding-top: .3rem; border-top: 1px solid var(--border); }
.cfdi-form { margin-top: 1rem; padding-top: 1rem; border-top: 1px dashed var(--border); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }

/* Aviso de seguros en Inicio */
.alert-seguros { align-items: center; text-decoration: none; background: #fffbeb; border-color: #fde68a; color: #92400e; }
.alert-seguros-vencidos { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.alert-seguros:hover { filter: brightness(.98); }
.chip { display: inline-block; padding: .1rem .5rem; margin: .1rem .15rem .1rem 0; border-radius: 6px; font-size: .75rem; background: var(--bg); border: 1px solid var(--border); }
.chip-brand { background: var(--brand-soft); border-color: transparent; color: var(--brand); font-weight: 600; }
.prio { font-size: .8rem; font-weight: 600; }
.prio::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: .35rem; background: currentColor; }
.prio-baja { color: #6b7280; }
.prio-media { color: #2563eb; }
.prio-alta { color: #d97706; }
.prio-urgente { color: #dc2626; }

/* Alertas */
.alert { display: flex; justify-content: space-between; gap: 1rem; padding: .85rem 1rem; border-radius: 8px; border: 1px solid; font-size: .9rem; }
.alert ul { margin: .35rem 0 0; padding-left: 1.2rem; }
.alert-success { background: #ecfdf5; border-color: #a7f3d0; color: #065f46; }
.alert-error { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.alert-close { background: none; border: 0; font-size: 1.2rem; line-height: 1; cursor: pointer; color: inherit; opacity: .6; }

/* KPIs */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 1rem; }
.kpi { display: flex; flex-direction: column; gap: .25rem; text-decoration: none; border-top: 3px solid var(--brand); }
a.kpi:hover { border-color: var(--brand); }
.kpi-label { font-size: .8rem; color: var(--text-muted); font-weight: 600; }
.kpi-value { font-size: 1.9rem; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.kpi-value.sm { font-size: 1.35rem; }
.kpi-sub { font-size: .8rem; color: var(--text-muted); }

/* Lista de definición */
.dl { display: grid; grid-template-columns: max-content 1fr; gap: .5rem 1.25rem; margin: 0; font-size: .92rem; }
.dl dt { color: var(--text-muted); }
.dl dd { margin: 0; word-break: break-word; }

/* Progreso de la asistencia */
.stepper { list-style: none; margin: 0; padding: 0; display: flex; gap: .35rem; }
.stepper li { flex: 1 1 0; min-width: 0; font-size: .8rem; font-weight: 600; color: var(--text-muted); overflow-wrap: anywhere; }
.stepper li::before { content: ""; display: block; height: 6px; border-radius: 3px; background: var(--border); margin-bottom: .4rem; }
.stepper li.done::before { background: color-mix(in srgb, var(--brand) 45%, #fff); }
.stepper li.current::before { background: var(--brand); }
.stepper li.current { color: var(--text); }

/* Bitácora */
.timeline { list-style: none; margin: 0; padding: 0 0 0 1rem; border-left: 2px solid var(--border); display: flex; flex-direction: column; gap: 1.1rem; }
.timeline li { position: relative; }
.timeline li::before { content: ""; position: absolute; left: calc(-1rem - 6px); top: .35rem; width: 10px; height: 10px; border-radius: 50%; background: var(--brand); box-shadow: 0 0 0 3px var(--surface); }
.timeline-head { display: flex; justify-content: space-between; gap: .5rem; flex-wrap: wrap; }

/* Reportes */
.chart-box { position: relative; height: 280px; }
.bar-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: .8rem; }
.bar-list-row { display: flex; justify-content: space-between; font-size: .9rem; margin-bottom: .25rem; }
.bar { height: 8px; background: var(--bg); border-radius: 4px; overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--brand); border-radius: 4px; }

/* Vista previa de marca */
.brand-preview { display: flex; height: 110px; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; margin: 1rem 0 1.25rem; }
.brand-preview-side { width: 42%; background: var(--side); color: var(--side-text); display: flex; align-items: flex-start; gap: .5rem; padding: .75rem; font-weight: 700; font-size: .9rem; }
.brand-preview-side img { width: 28px; height: 28px; object-fit: contain; background: #fff; border-radius: 6px; padding: 2px; }
.brand-preview-body { flex: 1; background: var(--bg); padding: .75rem; display: flex; flex-direction: column; justify-content: space-between; align-items: flex-start; }
.brand-preview-bar { display: block; width: 70%; height: 10px; border-radius: 5px; background: var(--brand); opacity: .35; }
.restore { display: flex; justify-content: flex-end; }

/* Login */
.auth-body { min-height: 100vh; display: grid; place-items: center; padding: 1rem; background: linear-gradient(160deg, var(--brand-soft), var(--bg) 60%); }
.auth-card { width: 100%; max-width: 400px; padding: 2rem; display: flex; flex-direction: column; gap: 1.25rem; }
.auth-brand { text-align: center; display: flex; flex-direction: column; align-items: center; gap: .5rem; }
.auth-brand p { margin: 0; }
/* Botón de Iniciar sesión: naranja de la marca con letra oscura (contraste legible) */
.btn-login { background: #ffac1a; color: #111827; }
.btn-login:hover { background: #f59e0b; }
.btn-login:focus-visible { outline-color: #b45309; }
.empty-state { text-align: center; padding: 3rem 1.5rem; display: flex; flex-direction: column; align-items: center; gap: .75rem; }
.empty-state h1 { justify-content: center; }

/* ---------- Responsivo ---------- */
/* ---------- v2: tiempo real, direcciones, proveedores, API ---------- */

/* Indicador "En vivo" */
.live { display: inline-flex; align-items: center; gap: .4rem; font-size: .78rem; font-weight: 600; color: var(--text-muted); padding: .25rem .6rem; border-radius: 999px; background: var(--bg); }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: #9ca3af; }
.live[data-estado="conectado"] { color: #047857; background: #ecfdf5; }
.live[data-estado="conectado"] .live-dot { background: #10b981; box-shadow: 0 0 0 0 rgba(16, 185, 129, .6); animation: pulso 2s infinite; }
.live[data-estado="desconectado"] { color: #b45309; background: #fffbeb; }
.live[data-estado="desconectado"] .live-dot { background: #f59e0b; }
@keyframes pulso { 70% { box-shadow: 0 0 0 7px rgba(16, 185, 129, 0); } 100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); } }

/* Filas nuevas (tiempo real) y filas recibidas por API */
.chip-api { background: #fff7ed; border-color: #fed7aa; color: #c2410c; font-weight: 700; font-size: .68rem; letter-spacing: .03em; vertical-align: middle; margin-left: .35rem; }
.table tbody tr.row-api td:first-child { box-shadow: inset 3px 0 0 #fb923c; }
.table tbody tr.row-new { background: var(--row-new); animation: fila-nueva 1.2s ease-out 3; }
.table tbody tr.row-new td:first-child { box-shadow: inset 4px 0 0 #f97316; }
.table tbody tr.row-new.row-seen { animation: none; }
@keyframes fila-nueva { 0% { background: var(--row-new-flash); } 100% { background: var(--row-new); } }
.kpi-bump { animation: kpi-bump .6s ease-out 2; color: #ea580c; }
@keyframes kpi-bump { 50% { transform: scale(1.15); } }

/* Avisos flotantes */
.toasts { position: fixed; right: 1rem; bottom: 1rem; z-index: 60; display: flex; flex-direction: column; gap: .5rem; max-width: calc(100vw - 2rem); }
.toast {
  display: flex; align-items: center; gap: .75rem; width: 340px; max-width: 100%;
  background: var(--surface); border: 1px solid #fed7aa; border-left: 5px solid #f97316;
  border-radius: var(--radius); box-shadow: 0 12px 30px rgba(0, 0, 0, .18); padding: .8rem .9rem;
  animation: toast-in .3s ease-out;
}
.toast > div { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.toast strong { font-size: .88rem; }
.toast span { font-size: .85rem; color: var(--text-muted); }
.toast-close { background: none; border: 0; font-size: 1.2rem; cursor: pointer; color: var(--text-muted); }
.toast-out { opacity: 0; transform: translateY(8px); transition: opacity .5s, transform .5s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(12px); } }

/* Diálogo de confirmación */
.confirm-dialog { border: 0; border-radius: var(--radius); padding: 1.5rem; width: min(420px, calc(100vw - 2rem)); box-shadow: 0 20px 50px rgba(0, 0, 0, .25); }
.confirm-dialog::backdrop { background: rgba(15, 23, 42, .45); }
.confirm-dialog p { margin: 0; font-size: 1rem; }
.confirm-dialog .form-actions { margin-top: 1.25rem; }

/* Tarjetas especiales */
.card-muted { background: var(--bg); box-shadow: none; }
.card-highlight { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.alert-muted { background: var(--bg); border-color: var(--border); color: var(--text); }

/* Dirección: coordenadas */
.geo-inputs { display: flex; gap: .4rem; }
.geo-inputs input { min-width: 0; }
.flash-input { box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 35%, transparent); border-color: var(--brand); }

/* Detalle: pin de mapa, acciones y popups */
.map-pin { display: inline-flex; vertical-align: -3px; margin-left: .35rem; color: #ea580c; border-radius: 6px; padding: 2px; }
.map-pin svg { width: 18px; height: 18px; fill: #ffedd5; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.map-pin:hover { color: #c2410c; background: #fff7ed; }
.detalle-acciones { display: flex; gap: .5rem; flex-wrap: wrap; }
.detalle-acciones .btn { flex: 1 1 180px; }
.modal {
  border: 0; border-radius: var(--radius); padding: 1.25rem 1.5rem 1.5rem;
  width: min(560px, calc(100vw - 2rem)); max-height: calc(100vh - 2rem); overflow-y: auto;
  box-shadow: 0 20px 50px rgba(0, 0, 0, .25); color: var(--text);
}
.modal::backdrop { background: rgba(15, 23, 42, .45); }
.modal-header { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 1rem; }
.modal-header h2 { font-size: 1.15rem; }
.modal-close { border: 0; background: none; font-size: 1.6rem; line-height: 1; cursor: pointer; color: var(--text-muted); padding: 0 .25rem; border-radius: 6px; }
.modal-close:hover { color: var(--text); background: var(--bg); }

/* Evidencias */
.evidencia { display: inline-block; margin-top: .5rem; }
.evidencia img { width: 140px; height: 105px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); }
.evidencia:hover img { border-color: var(--brand); }

/* Proveedores: servicios y zonas */
.check-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: .5rem; }
.check-card { padding: .6rem .75rem; border: 1px solid var(--border); border-radius: 8px; }
.check-card:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); }
.zone-picker { display: flex; flex-direction: column; gap: .75rem; }
.zone-picker-controls { display: flex; gap: 1rem; flex-wrap: wrap; }
.zone-picker-controls .field { flex: 0 1 260px; }
.zone-picker-controls .field.grow { flex: 1 1 240px; }
.zone-options {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: .35rem .75rem;
  max-height: 260px; overflow-y: auto; padding: .75rem; border: 1px solid var(--border); border-radius: 8px; background: var(--bg);
}
.zone-options .check-all { grid-column: 1 / -1; font-weight: 600; padding-bottom: .4rem; border-bottom: 1px solid var(--border); }
.zone-options .check input:disabled + span { opacity: .45; }
.zone-list { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: .4rem; }
.zone-list li { display: inline-flex; align-items: center; gap: .35rem; padding: .3rem .35rem .3rem .7rem; border-radius: 999px; background: var(--brand-soft); font-size: .85rem; }
.zone-remove { border: 0; background: none; cursor: pointer; font-size: 1.1rem; line-height: 1; padding: 0 .3rem; color: var(--text-muted); border-radius: 50%; }
.zone-remove:hover { color: var(--danger); }

/* API: token y bloques de código */
.copy-box { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; padding: .75rem 1rem; background: var(--bg); border-radius: 8px; }
.copy-box code { font-size: .95rem; word-break: break-all; flex: 1; }
.code-block { position: relative; }
.code-block pre { margin: 0; padding: 1rem; background: #0f172a; color: #e2e8f0; border-radius: 8px; overflow-x: auto; font-size: .8rem; line-height: 1.5; }
.code-block .btn { position: absolute; top: .5rem; right: .5rem; }
.first-subtitle { margin-top: 0; }

@media (max-width: 1100px) {
  .grid-2, .grid-2.wide-right { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 960px) {
  .sidebar { transform: translateX(-100%); box-shadow: none; }
  .nav-open .sidebar { transform: none; box-shadow: 0 0 40px rgba(0, 0, 0, .3); }
  .nav-open .backdrop { display: block; position: fixed; inset: 0; background: rgba(15, 23, 42, .45); z-index: 35; }
  .main { margin-left: 0; }
  .menu-toggle { display: inline-flex; }
  .topbar { padding: 0 1rem; }
  .content { padding: 1rem; }
}

@media (max-width: 720px) {
  :root { font-size: 14.5px; }
  /* Filtros y resumen ocultos por defecto; el botón los muestra */
  .solo-movil { display: inline-flex !important; align-self: flex-start; }
  .colapsable-movil:not(.abierto) { display: none !important; }
  .user-name { display: none; }
  .form-grid, .form-grid.cols-3 { grid-template-columns: minmax(0, 1fr); }
  .card { padding: 1rem; }
  .toolbar .field, .toolbar .field.grow { flex: 1 1 100%; }
  .toolbar-actions { width: 100%; }
  .toolbar-actions .btn { flex: 1; }
  .page-header .actions { width: 100%; }
  .page-header .actions .btn { flex: 1; }
  .form-actions .btn { flex: 1; }
  .dl { grid-template-columns: minmax(0, 1fr); gap: .1rem; }
  .dl dd { margin-bottom: .5rem; }
  /* En móvil solo se rotula la etapa actual */
  .stepper li:not(.current) span { visibility: hidden; }
  .stepper li.current { flex: 2.5 1 0; }
  .chart-box { height: 240px; }
  .live-text { display: none; }
  .toast { width: 100%; }
  .table tr.row-new { border-color: #f97316; }
  .table tr.row-api { border-left: 3px solid #fb923c; }
  .table tbody tr.row-new td:first-child, .table tbody tr.row-api td:first-child { box-shadow: none; }

  /* Las tablas se convierten en tarjetas apiladas */
  .table-wrap { margin: 0; overflow: visible; }
  .table thead { display: none; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table tr { border: 1px solid var(--border); border-radius: 8px; padding: .5rem .75rem; margin-bottom: .75rem; }
  .table tbody tr:last-child td { border-bottom: 1px solid var(--border); }
  .table td { display: flex; justify-content: space-between; gap: 1rem; padding: .4rem 0; border-bottom: 1px dashed var(--border); text-align: right; }
  .table td.right { text-align: right; }
  .table td:last-child, .table tbody tr:last-child td:last-child { border-bottom: 0; }
  .table td[data-label]::before { content: attr(data-label); font-weight: 600; color: var(--text-muted); text-align: left; flex-shrink: 0; }
  .table td.row-actions, .table td:not([data-label]) { justify-content: flex-end; flex-wrap: wrap; white-space: normal; }
  .table.compact td { padding: .35rem 0; }
}
.cfdi-requisitos { margin: .5rem 0 1rem; font-size: .9rem; }
.cfdi-requisitos summary { cursor: pointer; font-weight: 600; }
.cfdi-requisitos ul { margin: .5rem 0; padding-left: 1.2rem; }
/* Pendientes de relación: antigüedad desde el cierre */
.kpis.antiguedades { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.antiguedades .kpi { text-decoration: none; color: inherit; border-top: 4px solid var(--antig, var(--border)); }
.antiguedades .kpi:hover { filter: brightness(.98); }
.antiguedades .kpi.activo { outline: 2px solid var(--antig); }
.antig-1 { --antig: #10b981; }
.antig-2 { --antig: #84cc16; }
.antig-3 { --antig: #f59e0b; }
.antig-4 { --antig: #f97316; }
.antig-5 { --antig: #dc2626; }
.badge.antig-1 { background: #d1fae5; color: #065f46; }
.badge.antig-2 { background: #ecfccb; color: #3f6212; }
.badge.antig-3 { background: #fef3c7; color: #92400e; }
.badge.antig-4 { background: #ffedd5; color: #9a3412; }
.badge.antig-5 { background: #fee2e2; color: #991b1b; }
.lista-simple { margin: .25rem 0 0; padding-left: 1.2rem; }
.lista-simple li { margin: .2rem 0; }
.fieldset-limpio { border: 0; padding: 0; margin: 0; min-width: 0; }
.fieldset-limpio:disabled input, .fieldset-limpio:disabled select, .fieldset-limpio:disabled textarea { background: var(--bg); color: var(--text-muted); cursor: not-allowed; }
/* Selector de mapa (OpenStreetMap) */
.modal-mapa { width: min(860px, calc(100vw - 32px)); }
.mapa-buscar { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: .5rem; }
.mapa-buscar input { flex: 1 1 220px; }
.mapa { height: min(60vh, 440px); border-radius: 8px; border: 1px solid var(--border); }
.mapa-resultados { list-style: none; margin: 0 0 .5rem; padding: 0; max-height: 170px; overflow: auto; border: 1px solid var(--border); border-radius: 8px; }
.mapa-resultados li + li { border-top: 1px solid var(--border); }
.mapa-resultados li.muted { padding: .5rem .75rem; }
.mapa-resultados button { all: unset; display: block; width: 100%; box-sizing: border-box; padding: .5rem .75rem; cursor: pointer; font-size: .9rem; }
.mapa-resultados button:hover, .mapa-resultados button:focus-visible { background: var(--bg); }
.mapa-direccion { margin: .5rem 0 0; font-size: .9rem; min-height: 1.4em; }

/* Combo con buscador (select[data-buscador]) */
.combo { position: relative; }
.combo > input { width: 100%; }
.combo-lista {
  position: absolute; z-index: 30; left: 0; right: 0; top: calc(100% + 2px);
  max-height: 260px; overflow-y: auto; margin: 0; padding: .25rem 0; list-style: none;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow);
}
.combo-lista li { padding: .45rem .75rem; cursor: pointer; }
.combo-lista li.activa, .combo-lista li:hover { background: var(--brand-soft); }
.combo-lista li.combo-siempre { color: var(--brand); font-weight: 600; border-bottom: 1px solid var(--border); }
.combo-lista li.combo-nota { color: var(--text-muted); font-size: .85rem; cursor: default; background: none; }

/* Equipamiento que atiende (detalle de la asistencia) */
.equipo-form { margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--border); }

/* Propuestas de precio (Mi cobertura) */
.card-aviso { border-color: color-mix(in srgb, var(--brand) 45%, var(--border)); background: var(--brand-soft); margin-bottom: 1.25rem; }
form.inline { display: inline-block; margin: 0 0 0 .25rem; }
.nowrap { white-space: nowrap; }

.checks-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: .5rem 1rem; }

/* Cobro en los listados y aviso de equipamiento */
.badge-facturada { background: #ede9fe; color: #5b21b6; }
.badge-pagada { background: #ccfbf1; color: #115e59; }
.chip-alerta { background: #fee2e2; color: #991b1b; border-color: #fecaca; margin-left: .25rem; }

.auth-link { text-align: center; margin: 1rem 0 0; font-size: .9rem; }

/* ---------- Modo oscuro (botón en el menú del usuario; si no se elige, el del sistema) ---------- */
:root[data-theme="dark"] {
  --bg: #0e1320;
  --surface: #161c2b;
  --text: #e5e8ef;
  --text-muted: #9aa4b8;
  --border: #283146;
  --input-bg: #10172a;
  --input-border: #3a465f;
  --row-alt: #1b2234;
  --row-new: #3a2a14;
  --row-new-flash: #6b4316;
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1320;
    --surface: #161c2b;
    --text: #e5e8ef;
    --text-muted: #9aa4b8;
    --border: #283146;
    --input-bg: #10172a;
    --input-border: #3a465f;
    --row-alt: #1b2234;
    --row-new: #3a2a14;
    --row-new-flash: #6b4316;
    color-scheme: dark;
  }
}
