/* =========================================================
   TACSA · Evaluación Post-Auditoría
   ---------------------------------------------------------
   COLORES DE MARCA: cambia solo las 4 variables --marca*
   Los colores de estado (verde = bien, ámbar = atención,
   rojo = mal) son independientes de la marca a propósito.
   ========================================================= */
:root {
  /* ---- Marca TACSA ---- */
  --marca: #C00000;        /* color principal: botones, encabezados, menú activo */
  --marca-osc: #8E0000;    /* menú lateral, hover de botones */
  --marca-claro: #FBECEC;  /* fondos suaves de sección */
  --marca-foco: rgba(192, 0, 0, .22);

  /* ---- Estados (no cambiar por la marca) ---- */
  --verde: #1B7A3E;        /* bien / Sí / éxito */
  --verde-claro: #E6F4EA;
  --acento: #D69E2E;       /* atención / pendiente */
  --rojo: #B42318;         /* mal / No / error */
  --ambar: #B7791F;
  --azul: #2B6CB0;
  --gris: #718096;

  /* ---- Neutros ---- */
  --texto: #222222;
  --texto-2: #626262;
  --borde: #E2E2E2;
  --fondo: #F5F5F4;
  --blanco: #FFFFFF;
  --radio: 10px;
  --sombra: 0 1px 2px rgba(0,0,0,.05), 0 4px 14px rgba(0,0,0,.04);
  --ancho-menu: 220px;
  --alto-top: 58px;
  --alto-bottom: 64px;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
html { -webkit-text-size-adjust: 100%; }
body { background: var(--fondo); color: var(--texto); font-size: 15px; line-height: 1.45; }
a { color: var(--marca); }
h1 { font-size: 1.45rem; margin: 0 0 4px; line-height: 1.2; }
h2 { font-size: 1.15rem; margin: 0 0 12px; }
h3 { font-size: 1rem; margin: 0 0 10px; }
small, .muted { color: var(--texto-2); }

/* ---------- Barra superior ---------- */
.topbar {
  position: fixed; inset: 0 0 auto 0; height: var(--alto-top); z-index: 30;
  display: flex; align-items: center; gap: 12px; padding: 0 18px;
  background: var(--blanco); border-bottom: 3px solid var(--marca);
  padding-top: env(safe-area-inset-top);
}
.marca { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--texto); min-width: 0; }
.marca img { height: 36px; }
.marca-texto { font-weight: 800; font-size: 1.35rem; letter-spacing: 1px; color: var(--marca); }
.marca-sub { font-size: .85rem; color: var(--texto-2); border-left: 1px solid var(--borde); padding-left: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-usuario { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--marca); color: #fff; display: grid; place-items: center; font-weight: 700; flex: none; }
.usr-txt { display: flex; flex-direction: column; line-height: 1.15; font-size: .85rem; }
.lnk { font-size: .85rem; text-decoration: none; padding: 8px 10px; border-radius: 6px; white-space: nowrap; }
.lnk:hover { background: var(--marca-claro); }
.btn-menu { display: none; background: none; border: 0; padding: 6px; margin-left: -6px; cursor: pointer; }
.btn-menu svg { width: 26px; height: 26px; fill: var(--texto); }

/* ---------- Menú lateral (escritorio) ---------- */
.sidebar {
  position: fixed; top: var(--alto-top); bottom: 0; left: 0; width: var(--ancho-menu); z-index: 20;
  background: var(--marca-osc); padding: 14px 10px; display: flex; flex-direction: column; gap: 2px; overflow-y: auto;
}
.sidebar a {
  display: flex; align-items: center; gap: 10px; color: #F6DADA; text-decoration: none;
  padding: 11px 12px; border-radius: 8px; font-size: .93rem;
}
.sidebar a svg { width: 20px; height: 20px; fill: currentColor; flex: none; }
.sidebar a:hover { background: rgba(255,255,255,.1); color: #fff; }
.sidebar a.activo { background: var(--marca); color: #fff; box-shadow: inset 3px 0 0 #fff; }
.sidebar-pie { margin-top: auto; font-size: .72rem; color: #E9A9A9; padding: 10px 12px; font-style: italic; }

/* ---------- Barra inferior (móvil, perfiles con pocas opciones) ---------- */
.bottomnav { display: none; }

.contenido { padding: 24px; }
.con-menu .contenido { margin: var(--alto-top) 0 0 var(--ancho-menu); }

/* ---------- Componentes ---------- */
.card { background: var(--blanco); border: 1px solid var(--borde); border-radius: var(--radio); padding: 20px; box-shadow: var(--sombra); margin-bottom: 18px; }
.encabezado { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.encabezado p { margin: 0; color: var(--texto-2); }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0,1fr)); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--marca); background: var(--marca); color: #fff;
  padding: 10px 16px; border-radius: 8px; font-size: .9rem; font-weight: 600; cursor: pointer; text-decoration: none; line-height: 1.2; font-family: inherit;
}
.btn:hover { background: var(--marca-osc); border-color: var(--marca-osc); }
.btn-sec { background: #fff; color: var(--marca); }
.btn-sec:hover { background: var(--marca-claro); color: var(--marca-osc); }
.btn-ok { background: var(--verde); border-color: var(--verde); }
.btn-ok:hover { background: #12592C; border-color: #12592C; }
.btn-peligro { background: #fff; color: var(--rojo); border-color: #E9B8B4; }
.btn-peligro:hover { background: #FDF0EF; color: var(--rojo); }
.btn-sm { padding: 6px 10px; font-size: .8rem; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.acciones { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.acciones form { margin: 0; }

/* Formularios */
label { display: block; font-size: .85rem; font-weight: 600; margin-bottom: 4px; color: var(--texto-2); }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=time], input[type=number], select, textarea {
  width: 100%; padding: 10px 11px; border: 1px solid #D4D4D4; border-radius: 8px; font: inherit; background: #fff; color: var(--texto); min-height: 42px;
}
input:focus, select:focus, textarea:focus { outline: 3px solid var(--marca-foco); border-color: var(--marca); }
input[readonly] { background: #F7F7F6; color: var(--texto); font-weight: 600; }
textarea { min-height: 90px; resize: vertical; }
.campo { margin-bottom: 14px; }
.check { display: flex; align-items: flex-start; gap: 10px; font-weight: 500; color: var(--texto); cursor: pointer; }
.check input { width: 20px; height: 20px; margin: 1px 0 0; accent-color: var(--marca); flex: none; }
.ayuda { font-size: .78rem; color: var(--texto-2); margin-top: 3px; }

/* Tablas */
.tabla-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.tabla { width: 100%; border-collapse: collapse; font-size: .88rem; }
.tabla th { text-align: left; font-size: .75rem; text-transform: uppercase; letter-spacing: .4px; color: var(--texto-2); background: #F7F7F6; padding: 10px 8px; border-bottom: 1px solid var(--borde); white-space: nowrap; }
.tabla td { padding: 10px 8px; border-bottom: 1px solid #EFEFEE; vertical-align: middle; }
.tabla tr:hover td { background: #FBFBFA; }
.tabla td > strong:first-child, .tabla td > a > strong { white-space: nowrap; }
@media (min-width: 861px) {
  .tabla td:last-child:has(.acciones) { width: 1%; }
  .tabla .acciones { flex-wrap: nowrap; justify-content: flex-end; }
  .tabla .acciones select { width: auto; min-height: 32px; padding: 5px 6px; font-size: .8rem; }
}
@media (min-width: 861px) and (max-width: 1400px) {
  .tabla .acciones { flex-wrap: wrap; flex-direction: column; align-items: stretch; }
}
.tabla .num { text-align: right; font-variant-numeric: tabular-nums; }
.vacio { text-align: center; color: var(--texto-2); padding: 28px !important; }

/* Badges (colores de estado) */
.badge { display: inline-block; padding: 3px 9px; border-radius: 20px; font-size: .74rem; font-weight: 700; white-space: nowrap; }
.badge-verde { background: #E3F2E8; color: #1B7A3E; }
.badge-ambar { background: #FDF3DC; color: #8A5A0B; }
.badge-rojo  { background: #FDE8E7; color: #A11C12; }
.badge-azul  { background: #E3EEFA; color: #22558C; }
.badge-gris  { background: #EEEEEE; color: #555; }
.calif { display: inline-block; min-width: 42px; text-align: center; font-weight: 800; padding: 3px 8px; border-radius: 6px; }
.calif.verde { background: #E3F2E8; color: #1B7A3E; } .calif.ambar { background: #FDF3DC; color: #8A5A0B; }
.calif.rojo { background: #FDE8E7; color: #A11C12; } .calif.gris { background: #EEEEEE; color: #555; }

/* Alertas */
.alerta { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; border: 1px solid; font-size: .92rem; }
.alerta-ok { background: #E8F5EC; border-color: #B6DCC2; color: #165C30; }
.alerta-error { background: #FDF0EF; border-color: #EBC1BD; color: #9B1C12; }
.alerta-aviso { background: #FFF8E6; border-color: #F1DA9C; color: #7A5208; }

/* KPIs */
.kpi { background: #fff; border: 1px solid var(--borde); border-radius: var(--radio); padding: 16px 18px; box-shadow: var(--sombra); position: relative; overflow: hidden; }
.kpi::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--kpi-color, #8A8A8A); }
.kpi .kpi-tit { font-size: .78rem; text-transform: uppercase; letter-spacing: .4px; color: var(--texto-2); font-weight: 600; }
.kpi .kpi-val { font-size: 1.9rem; font-weight: 800; margin: 4px 0 2px; font-variant-numeric: tabular-nums; }
.kpi .kpi-sub { font-size: .8rem; color: var(--texto-2); }
.grafica { position: relative; height: 280px; }
.barra-mini { height: 8px; background: #EFEFEE; border-radius: 6px; overflow: hidden; min-width: 80px; }
.barra-mini > span { display: block; height: 100%; background: var(--marca); }

/* Filtros */
.filtros { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.filtros .campo { margin: 0; min-width: 150px; }

/* Tarjetas de pendientes (inicio auditor/responsable) */
.lista-tarjetas { display: flex; flex-direction: column; gap: 10px; }
.tarjeta { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border: 1px solid var(--borde); border-radius: 10px; background: #fff; }
.tarjeta-info { flex: 1; min-width: 0; }
.tarjeta-info strong { display: block; }
.tarjeta-info small { display: block; }
.fecha-chip { flex: none; width: 52px; text-align: center; border-radius: 8px; background: var(--marca-claro); color: var(--marca-osc); padding: 6px 0; line-height: 1.1; }
.fecha-chip b { display: block; font-size: 1.3rem; }
.fecha-chip span { font-size: .7rem; text-transform: uppercase; font-weight: 700; }

/* ---------- Encuesta ---------- */
.formato-tit { text-align: center; padding: 14px; background: var(--marca); color: #fff; border-radius: var(--radio) var(--radio) 0 0; margin: -20px -20px 18px; font-weight: 700; letter-spacing: .3px; }
.seccion-tit { background: var(--marca-claro); color: var(--marca-osc); font-weight: 700; padding: 10px 14px; border-left: 4px solid var(--marca); border-radius: 6px; margin: 22px 0 6px; }
.instruccion { font-size: .85rem; color: var(--texto-2); margin: 4px 0 10px; }
.preg { display: grid; grid-template-columns: 34px 1fr auto; gap: 12px; align-items: center; padding: 12px 6px; border-bottom: 1px solid #EFEFEE; }
.preg-num { width: 28px; height: 28px; border-radius: 50%; background: var(--marca); color: #fff; font-weight: 700; display: grid; place-items: center; font-size: .85rem; }
.opciones { display: flex; gap: 6px; }
.opciones label { margin: 0; cursor: pointer; }
.opciones input { position: absolute; opacity: 0; pointer-events: none; }
.opciones span {
  display: grid; place-items: center; min-width: 44px; height: 44px; padding: 0 10px; border: 2px solid #D4D4D4; border-radius: 8px;
  font-weight: 700; color: var(--texto-2); background: #fff; transition: .12s; font-size: 1rem; user-select: none;
}
.opciones label:hover span { border-color: var(--marca); }
.opciones input:checked + span { background: var(--marca); border-color: var(--marca); color: #fff; }
.opciones input.si:checked + span { background: var(--verde); border-color: var(--verde); }
.opciones input.no:checked + span { background: var(--rojo); border-color: var(--rojo); }
.opciones input.na:checked + span { background: var(--gris); border-color: var(--gris); }
.opciones input:focus-visible + span { outline: 3px solid var(--marca-foco); }
.escala-leyenda { display: flex; justify-content: flex-end; gap: 14px; font-size: .75rem; color: var(--texto-2); padding: 0 6px; }
.preg.falta { background: #FFF4F3; }
.preg-texto { grid-template-columns: 34px 1fr; }
.firma-caja { border: 2px dashed #CFCFCF; border-radius: 8px; background: #fff; position: relative; max-width: 520px; }
.firma-caja canvas { display: block; width: 100%; height: 180px; touch-action: none; cursor: crosshair; }
.firma-caja .firma-guia { position: absolute; left: 20px; right: 20px; bottom: 36px; border-bottom: 1px solid #CCC; pointer-events: none; }
.firma-img { max-width: 320px; width: 100%; border-bottom: 1px solid var(--texto); }

/* Login */
.login-fondo { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 20px;
  background: linear-gradient(135deg, #6E0000 0%, #A00000 50%, #C00000 100%); }
.login-caja { width: 100%; max-width: 390px; background: #fff; border-radius: 14px; padding: 32px 28px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.login-caja .marca-texto { font-size: 2rem; }
.login-caja .btn { width: 100%; padding: 12px; font-size: 1rem; }

/* Asignaciones (checkbox lista) */
.lista-check { max-height: 260px; overflow-y: auto; border: 1px solid var(--borde); border-radius: 8px; padding: 8px 10px; }
.lista-check .check { padding: 6px 0; }

/* ---------- Tablet ---------- */
@media (max-width: 1100px) { .g4 { grid-template-columns: repeat(2, minmax(0,1fr)); } }

/* ---------- Móvil ---------- */
@media (max-width: 860px) {
  body { font-size: 16px; }
  /* 16 px evita el zoom automático de iOS al enfocar campos */
  input[type=text], input[type=email], input[type=password], input[type=date], input[type=time], input[type=number], select, textarea { font-size: 16px; min-height: 46px; }
  .btn { min-height: 44px; }
  .btn-sm { min-height: 36px; }

  .topbar { padding: 0 12px; gap: 8px; }
  .btn-menu { display: block; }
  .marca-sub, .usr-txt, .lnk-perfil { display: none; }
  .avatar { width: 32px; height: 32px; }

  .sidebar { transform: translateX(-100%); transition: transform .2s; width: 260px; }
  .menu-abierto .sidebar { transform: none; box-shadow: 8px 0 30px rgba(0,0,0,.25); }
  .menu-abierto::after { content: ""; position: fixed; inset: var(--alto-top) 0 0 0; background: rgba(0,0,0,.35); z-index: 15; }

  .con-menu .contenido { margin-left: 0; padding: 14px 12px; }
  h1 { font-size: 1.25rem; }
  .card { padding: 16px 14px; border-radius: 12px; }
  .formato-tit { margin: -16px -14px 16px; font-size: .9rem; padding: 12px; }
  .g2, .g3 { grid-template-columns: 1fr; gap: 0 16px; }
  .g4 { gap: 10px; }
  .g4 .campo, .g3 .campo, .g2 .campo { grid-column: auto !important; }
  .kpi { padding: 12px 14px; }
  .kpi .kpi-val { font-size: 1.5rem; }
  .kpi .kpi-tit { font-size: .7rem; }
  .grafica { height: 250px; }

  /* Encabezados y filtros a lo ancho */
  .encabezado { align-items: stretch; flex-direction: column; }
  .encabezado > .btn, .encabezado > .acciones .btn { width: 100%; }
  .filtros { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
  .filtros .campo { min-width: 0; }
  .filtros .btn { grid-column: 1 / -1; }

  /* Formularios: botón principal a lo ancho */
  form.card > .acciones .btn, form.card > .btn { flex: 1; }

  /* Tablas → tarjetas apiladas (data-label lo pone app.js) */
  .tabla-wrap { overflow: visible; }
  table.tabla, .tabla tbody, .tabla tr, .tabla td { display: block; width: 100%; }
  .tabla thead { display: none; }
  .tabla tr { border: 1px solid var(--borde); border-radius: 10px; margin-bottom: 10px; padding: 6px 12px; background: #fff; }
  .tabla tr:hover td { background: transparent; }
  .tabla td { border: 0; border-bottom: 1px dashed #EFEFEE; padding: 7px 0; display: flex; justify-content: space-between; align-items: center; gap: 12px; text-align: right; }
  .tabla td:last-child { border-bottom: 0; }
  .tabla td::before { content: attr(data-label); font-size: .72rem; text-transform: uppercase; letter-spacing: .3px; color: var(--texto-2); font-weight: 600; text-align: left; flex: none; max-width: 45%; }
  .tabla td:first-child { font-size: 1rem; }
  .tabla td[data-label=""]::before, .tabla td.sin-etiqueta::before { display: none; }
  .tabla td.vacio { display: block; text-align: center; border: 0; }
  .tabla td .acciones { justify-content: flex-end; width: 100%; }
  .tabla td .td-val { text-align: right; }
  .tabla .num { text-align: right; }

  /* Encuesta: opciones a lo ancho y grandes para el dedo */
  .preg { grid-template-columns: 30px 1fr; gap: 10px; padding: 14px 2px; }
  .preg .opciones { grid-column: 1 / -1; }
  .opciones { width: 100%; }
  .opciones label { flex: 1; }
  .opciones span { width: 100%; height: 50px; font-size: 1.1rem; }
  .escala-leyenda { justify-content: space-between; padding: 0; }
  .firma-caja canvas { height: 200px; }
}

/* Barra inferior para Auditor y Responsable en móvil */
@media (max-width: 860px) {
  .con-bottomnav .contenido { padding-bottom: calc(var(--alto-bottom) + 20px + env(safe-area-inset-bottom)); }
  .con-bottomnav .btn-menu { display: none; }
  .bottomnav {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: #fff;
    border-top: 1px solid var(--borde); box-shadow: 0 -4px 14px rgba(0,0,0,.06);
    height: calc(var(--alto-bottom) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  }
  .bottomnav a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; text-decoration: none; color: var(--texto-2); font-size: .72rem; font-weight: 600; position: relative; }
  .bottomnav a svg { width: 24px; height: 24px; fill: currentColor; }
  .bottomnav a.activo { color: var(--marca); }
  .bottomnav a.activo::before { content: ""; position: absolute; top: 0; left: 25%; right: 25%; height: 3px; border-radius: 0 0 3px 3px; background: var(--marca); }
  .bottomnav .punto { position: absolute; top: 8px; left: calc(50% + 6px); min-width: 18px; height: 18px; border-radius: 9px; background: var(--marca); color: #fff; font-size: .68rem; display: grid; place-items: center; padding: 0 4px; }
}

/* Filtros plegables en móvil (el botón lo agrega app.js) */
.btn-filtros { display: none; }
@media (max-width: 860px) {
  .btn-filtros { display: flex; width: 100%; margin-bottom: 10px; }
  .filtros.plegado { display: none; }
}
@media (max-width: 420px) {
  .opciones { gap: 4px; }
  .opciones span { padding: 0 4px; }
}

/* ---------- Impresión ---------- */
@media print {
  .topbar, .sidebar, .bottomnav, .no-print, .alerta { display: none !important; }
  .con-menu .contenido { margin: 0; padding: 0; }
  body { background: #fff; }
  .card { box-shadow: none; border: 0; }
  .formato-tit, .preg-num, .opciones input:checked + span { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
