/* ===================================================================== Base ===== */
*, *::before, *::after { box-sizing: border-box; }
/* Reset estándar: restaura la semántica nativa de [hidden] frente a reglas display de componentes.
   Solo se usa para controles pequeños (menús, insignias). Las pantallas (login / AppShell) NO se
   ocultan: la máquina de estados las monta y destruye (js/main.js). */
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  font: var(--t-md)/1.45 var(--fuente); color: var(--txt); background: var(--sup-fondo);
  -webkit-font-smoothing: antialiased; font-feature-settings: "cv11", "ss01";
}
:root.bloqueo-scroll, :root.bloqueo-scroll body { overflow: hidden; }
#root { min-height: 100dvh; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
h1 { font-size: var(--t-2xl); } h2 { font-size: var(--t-xl); } h3 { font-size: var(--t-lg); } h4 { font-size: var(--t-md); }
a { color: var(--acento-texto); }
:focus-visible { outline: 2px solid var(--foco); outline-offset: 2px; }
.tenue { color: var(--txt-3); }
.mono { font-family: var(--fuente-mono); font-size: .92em; }
.num, td.num, th.num { font-variant-numeric: tabular-nums lining-nums; text-align: right; white-space: nowrap; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ================================================================ Controles ===== */
input, select, textarea, button { font: inherit; color: inherit; }
input, select, textarea {
  background: var(--sup-panel); border: 1px solid var(--borde-fuerte); border-radius: var(--r-md);
  padding: 7px 10px; min-height: 34px; width: 100%;
}
input:focus, select:focus, textarea:focus { border-color: var(--foco); outline: none; box-shadow: 0 0 0 3px var(--acento-suave); }
input[type=checkbox] { width: auto; min-height: 0; }
.btn {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid transparent; border-radius: var(--r-md);
  padding: 7px 14px; min-height: 34px; cursor: pointer; background: var(--acento); color: #fff; font-weight: 500;
  text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--acento-hover); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-sec { background: var(--sup-panel); color: var(--acento-texto); border-color: var(--borde-fuerte); }
.btn-sec:hover { background: var(--acento-suave); }
.btn-fantasma { background: transparent; color: inherit; border-color: transparent; padding: 6px 8px; }
.btn-fantasma:hover { background: rgba(127, 140, 160, .16); }
.btn-peligro { background: var(--riesgo); }
.icono { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.campo { display: flex; flex-direction: column; gap: 4px; font-size: var(--t-sm); color: var(--txt-2); }
.campo-check { flex-direction: row; align-items: center; gap: 8px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: var(--e-3) var(--e-4); align-items: end; }
.form-col { display: flex; flex-direction: column; gap: var(--e-3); }
.acciones { display: flex; flex-wrap: wrap; gap: var(--e-2); align-items: center; }

/* ============================================================== Componentes ===== */
.panel { background: var(--sup-panel); border: 1px solid var(--borde); border-radius: var(--r-lg); box-shadow: var(--sombra-1); }
.panel > .panel-cab { display: flex; justify-content: space-between; align-items: center; gap: var(--e-3);
  padding: var(--e-3) var(--e-4); border-bottom: 1px solid var(--borde); flex-wrap: wrap; }
.panel > .panel-cuerpo { padding: var(--e-4); }
.panel + .panel, .panel + .grid, .grid + .panel { margin-top: var(--e-4); }
.grid { display: grid; gap: var(--e-4); grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.kpis { display: grid; gap: var(--e-3); grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); margin-bottom: var(--e-4); }
.kpi { background: var(--sup-panel); border: 1px solid var(--borde); border-radius: var(--r-lg); padding: var(--e-3) var(--e-4); }
.kpi .kpi-etq { font-size: var(--t-xs); text-transform: uppercase; letter-spacing: .04em; color: var(--txt-3); }
.kpi .kpi-val { font-size: var(--t-xl); font-weight: 600; font-variant-numeric: tabular-nums; margin-top: 2px; }
.kpi.riesgo .kpi-val { color: var(--riesgo); } .kpi.ok .kpi-val { color: var(--ok); }

.tabla-wrap { overflow: auto; border: 1px solid var(--borde); border-radius: var(--r-lg); background: var(--sup-panel); max-height: 70dvh; }
.panel .tabla-wrap { border: 0; border-radius: 0; }
table { width: 100%; border-collapse: collapse; font-size: var(--t-sm); }
th, td { padding: 7px 12px; border-bottom: 1px solid var(--borde); text-align: left; vertical-align: top; }
thead th { position: sticky; top: 0; z-index: 1; background: var(--sup-hundida); color: var(--txt-2); font-weight: 600;
  font-size: var(--t-xs); text-transform: uppercase; letter-spacing: .03em; }
tbody tr:hover { background: var(--sup-hundida); }
tfoot td { font-weight: 700; border-top: 2px solid var(--borde-fuerte); background: var(--sup-hundida); }
td.vacio { text-align: center; color: var(--txt-3); padding: var(--e-5); }

.chip { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 999px; font-size: var(--t-xs);
  background: var(--acento-suave); color: var(--acento-texto); white-space: nowrap; font-weight: 500; }
.sem { display: inline-flex; align-items: center; gap: 6px; padding: 1px 9px; border-radius: 999px; font-size: var(--t-xs); font-weight: 600; white-space: nowrap; }
.sem::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.sem-verde, .sem-ok { background: var(--ok-suave); color: var(--ok); }
.sem-amarillo, .sem-alta { background: var(--aviso-suave); color: var(--aviso); }
.sem-rojo, .sem-vencido, .sem-critica { background: var(--riesgo-suave); color: var(--riesgo); }
.sem-cerrado, .sem-info { background: var(--sup-hundida); color: var(--txt-3); }
.alerta { border: 1px solid; border-radius: var(--r-md); padding: var(--e-2) var(--e-3); margin-bottom: var(--e-3); font-size: var(--t-sm); }
.alerta-info { background: var(--info-suave); border-color: transparent; color: var(--info); }
.alerta-aviso { background: var(--aviso-suave); border-color: transparent; color: var(--aviso); }
.alerta-riesgo { background: var(--riesgo-suave); border-color: transparent; color: var(--riesgo); }
ul.lista-alertas { margin: 0; padding-left: 16px; color: var(--aviso); font-size: var(--t-xs); max-width: 420px; }
.drop { display: block; border: 2px dashed var(--borde-fuerte); border-radius: var(--r-lg); padding: var(--e-6); text-align: center;
  color: var(--txt-3); cursor: pointer; }
.drop.sobre { border-color: var(--foco); background: var(--acento-suave); }
.drop input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.no-disponible { border: 1px dashed var(--borde-fuerte); border-radius: var(--r-lg); padding: var(--e-4); color: var(--txt-3); }

/* =========================================================== Pantalla login ===== */
.login { min-height: 100dvh; display: grid; place-items: center; padding: var(--e-4);
  background: radial-gradient(1200px 600px at 20% -10%, var(--acento-suave), transparent), var(--sup-fondo); }
.login-caja { width: min(420px, 100%); padding: var(--e-6); }
.login-marca { display: flex; align-items: center; gap: var(--e-3); margin-bottom: var(--e-5); }
.login-logo { width: 40px; height: 40px; border-radius: var(--r-md); background: var(--acento); color: #fff;
  display: grid; place-items: center; font-weight: 700; }
.login details { margin-top: var(--e-4); }
.login summary { cursor: pointer; color: var(--acento-texto); font-size: var(--t-sm); }
.login .error { color: var(--riesgo); font-size: var(--t-sm); min-height: 1.2em; margin-top: var(--e-2); }
.cargando { min-height: 100dvh; display: grid; place-items: center; color: var(--txt-3); }

/* ================================================================ AppShell ===== */
.shell {
  display: grid; height: 100dvh; overflow: hidden;
  grid-template-columns: var(--ancho-lateral) minmax(0, 1fr);
  grid-template-rows: var(--alto-topbar) minmax(0, 1fr);
  grid-template-areas: "topbar topbar" "lateral contenido";
}
.topbar { grid-area: topbar; display: flex; align-items: center; gap: var(--e-3); padding: 0 var(--e-4);
  background: var(--sup-barra); color: var(--sup-barra-texto); z-index: 30; }
.topbar .marca { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.topbar .marca b { font-size: var(--t-md); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 240px; }
.topbar .marca span { font-size: var(--t-xs); color: var(--sup-barra-tenue); }
.topbar .selectores { display: flex; gap: var(--e-2); align-items: center; margin-left: var(--e-4); min-width: 0; }
.topbar .selectores select, .topbar .selectores input { background: rgba(255, 255, 255, .06); border-color: rgba(255, 255, 255, .16);
  color: var(--sup-barra-texto); min-height: 32px; padding: 4px 8px; }
.topbar .selectores select option { color: #111; }
.topbar .sel-cliente { width: 300px; } .topbar .sel-ejercicio { width: 84px; } .topbar .sel-mes { width: 120px; }
.topbar .espaciador { flex: 1; }
.topbar .btn-fantasma { color: var(--sup-barra-texto); position: relative; }
.btn-menu { display: none; }
.insignia { position: absolute; top: 0; right: 0; min-width: 17px; height: 17px; padding: 0 4px; border-radius: 9px; background: var(--riesgo);
  color: #fff; font-size: 10px; font-weight: 700; display: grid; place-items: center; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--acento); color: #fff; display: grid; place-items: center; font-weight: 600; font-size: var(--t-sm); }

.menu-flotante { position: absolute; right: 0; top: calc(100% + 6px); min-width: 280px; max-width: 360px; max-height: 70dvh; overflow: auto;
  background: var(--sup-elevada); color: var(--txt); border: 1px solid var(--borde); border-radius: var(--r-lg); box-shadow: var(--sombra-2); z-index: 50; }
.menu-flotante .item { display: block; width: 100%; text-align: left; padding: 10px 14px; border: 0; background: none; cursor: pointer;
  border-bottom: 1px solid var(--borde); color: inherit; text-decoration: none; font-size: var(--t-sm); }
.menu-flotante .item:hover { background: var(--sup-hundida); }
.menu-flotante .cab { padding: 12px 14px; border-bottom: 1px solid var(--borde); }
.anclaje { position: relative; }

.lateral { grid-area: lateral; background: var(--sup-lateral); border-right: 1px solid var(--borde); display: flex; flex-direction: column;
  overflow: hidden; z-index: 20; }
.lateral nav { flex: 1; overflow-y: auto; padding: var(--e-2); }
.linea { margin-bottom: 2px; }
.linea-btn { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border: 0; background: none; cursor: pointer;
  border-radius: var(--r-md); color: var(--txt-2); font-weight: 600; font-size: var(--t-sm); text-align: left; }
.linea-btn:hover { background: var(--sup-hundida); color: var(--txt); }
.linea.activa > .linea-btn { color: var(--acento-texto); }
.linea-btn .flecha { margin-left: auto; transition: transform .15s; }
.linea.abierta > .linea-btn .flecha { transform: rotate(90deg); }
.linea ul { list-style: none; margin: 2px 0 6px; padding: 0 0 0 30px; display: none; }
.linea.abierta ul { display: block; }
.linea li a { display: block; padding: 6px 10px; border-radius: var(--r-md); color: var(--txt-2); text-decoration: none; font-size: var(--t-sm); }
.linea li a:hover { background: var(--sup-hundida); color: var(--txt); }
.linea li a[aria-current="page"] { background: var(--acento-suave); color: var(--acento-texto); font-weight: 600; }
.linea li a.bloqueada { color: var(--txt-3); }
.mini-macro { border-top: 1px solid var(--borde); padding: var(--e-3); display: grid; grid-template-columns: 1fr 1fr; gap: 6px 10px; font-size: var(--t-xs); }
.mini-macro div { display: flex; flex-direction: column; } .mini-macro b { font-size: var(--t-sm); font-variant-numeric: tabular-nums; }
.mini-macro .tenue { font-size: 10px; }

.contenido { grid-area: contenido; overflow: auto; padding: var(--e-5) var(--e-5) var(--e-6); }
.contenido .cab-vista { display: flex; justify-content: space-between; align-items: flex-end; gap: var(--e-3); margin-bottom: var(--e-4); flex-wrap: wrap; }
.migas { font-size: var(--t-xs); color: var(--txt-3); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 2px; }
.velo { display: none; }
#toasts { position: fixed; right: var(--e-4); bottom: var(--e-4); display: flex; flex-direction: column; gap: var(--e-2); z-index: 60; max-width: min(420px, 90vw); }
#toasts .alerta { box-shadow: var(--sombra-2); margin: 0; }

.macro-widget .tc { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: var(--e-3); }
.macro-widget .noticias { max-height: 320px; overflow-y: auto; margin-top: var(--e-3); border-top: 1px solid var(--borde); }
.macro-widget .noticia { padding: 8px 0; border-bottom: 1px solid var(--borde); font-size: var(--t-sm); }
.macro-widget .noticia .tenue { font-size: var(--t-xs); }

.modal-velo { position: fixed; inset: 0; background: rgba(8, 12, 20, .55); display: grid; place-items: center; z-index: 70; padding: var(--e-4); }
.modal { width: min(440px, 100%); }

/* ============================================ Dirección ejecutiva: gráficas ===== */
.grafica { margin: 0 0 var(--e-3); overflow-x: auto; }
.grafica svg { width: 100%; min-width: 520px; height: auto; display: block; font-family: var(--fuente); }
.grafica .g-eje { font-size: 11px; fill: var(--txt-3); font-variant-numeric: tabular-nums; }
.grafica .g-rejilla { stroke: var(--borde); stroke-dasharray: 2 4; }
.grafica .g-cero { stroke: var(--borde-fuerte); }
.g-entrada { fill: var(--ok); background: var(--ok); }
.g-salida { fill: var(--riesgo); background: var(--riesgo); }
.grafica .g-acumulado { fill: none; stroke: var(--acento); stroke-width: 2.5; stroke-linejoin: round; }
.leyenda { display: flex; gap: var(--e-4); flex-wrap: wrap; font-size: var(--t-xs); color: var(--txt-2); margin-top: var(--e-2); }
.leyenda span { display: inline-flex; align-items: center; gap: 6px; }
.leyenda i { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.leyenda i.g-acumulado-i { height: 3px; width: 14px; background: var(--acento); }
.score { display: inline-flex; align-items: center; gap: var(--e-2); min-width: 140px; }
.score-barra { flex: 1; height: 6px; border-radius: 999px; background: var(--sup-hundida); overflow: hidden; min-width: 80px; }
.score-barra > span { display: block; height: 100%; border-radius: inherit; background: var(--ok); }
.score-barra > span.medio { background: var(--aviso); } .score-barra > span.alto { background: var(--riesgo); }
ul.notas { font-size: var(--t-xs); margin: var(--e-3) 0 0; padding-left: 16px; }

/* ================================================= Identidad Vértice / tenant ===== */
.por-vertice { color: var(--marca-dorado); font-style: normal; font-weight: 600; letter-spacing: .02em; }
.login-logo { background: var(--marca-marino); color: var(--marca-dorado); box-shadow: inset 0 0 0 2px var(--marca-dorado); }
.topbar { border-bottom: 2px solid var(--marca-dorado); }
.topbar .logo-despacho { height: 32px; max-width: 120px; object-fit: contain; border-radius: var(--r-sm); background: #fff; padding: 2px; }
.lateral a[aria-current="page"] { box-shadow: inset 3px 0 0 var(--marca-dorado); }
/* Alta densidad (data-dense): tablas y paneles compactos */
.shell[data-densidad="alta"] th, .shell[data-densidad="alta"] td { padding: 4px 8px; }
.shell[data-densidad="alta"] .panel > .panel-cuerpo { padding: var(--e-3); }
.shell[data-densidad="alta"] .kpi { padding: var(--e-2) var(--e-3); }

/* ============================================= Tablero de cumplimiento SAT ===== */
.matriz-cumplimiento td:first-child::first-letter { text-transform: uppercase; }
.matriz-cumplimiento td.celda { text-align: center; padding: 3px; min-width: 34px; }
.celda span { display: block; height: 22px; border-radius: var(--r-sm); line-height: 22px; font-size: var(--t-xs); font-weight: 600; }
.celda-verde { background: var(--ok); color: var(--txt-invertido); }
.celda-rojo { background: var(--riesgo); color: var(--txt-invertido); }
.celda-revisar { background: var(--aviso); color: var(--txt-invertido); }
.celda-por_vencer, .celda-sin_opinion { background: var(--celda-gris); color: var(--txt-3); }
.celda-no_aplica { background: transparent; color: var(--txt-3); border: 1px dashed var(--borde); }
.leyenda-celdas { display: flex; gap: var(--e-3); flex-wrap: wrap; font-size: var(--t-xs); color: var(--txt-2); margin-top: var(--e-2); }
.leyenda-celdas span { display: inline-flex; align-items: center; gap: 6px; }
.leyenda-celdas i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
/* ===================================================== Operación integral ===== */
input.inline { border: 1px solid transparent; background: transparent; padding: 2px 4px; width: 100%; font: inherit; color: inherit; border-radius: var(--r-sm); }
input.inline:hover, input.inline:focus { border-color: var(--borde-fuerte); background: var(--sup-panel); }
.matriz-permisos td.num input { width: 16px; height: 16px; accent-color: var(--marca-marino-2); }
#lineas input, #lineas select, #conceptos input, #conceptos select { width: 100%; min-width: 70px; }
.opinion-sello {display: inline-flex; align-items: center; gap: var(--e-2); padding: 4px 12px; border-radius: 999px; font-weight: 700; }
.opinion-sello.positivo { background: var(--ok-suave); color: var(--ok); }
.opinion-sello.negativo { background: var(--riesgo-suave); color: var(--riesgo); }

/* ========================================================== Responsive ===== */
/* Tablet: barra lateral compacta (solo íconos) salvo que se expanda */
@media (max-width: 1199px) {
  .shell:not([data-lateral="expandido"]) { grid-template-columns: var(--ancho-lateral-compacto) minmax(0, 1fr); }
  .shell:not([data-lateral="expandido"]) .linea-btn .etq, .shell:not([data-lateral="expandido"]) .linea-btn .flecha,
  .shell:not([data-lateral="expandido"]) .linea ul, .shell:not([data-lateral="expandido"]) .mini-macro { display: none; }
  .shell:not([data-lateral="expandido"]) .linea-btn { justify-content: center; }
  .topbar .sel-cliente { width: 220px; }
  .btn-menu { display: inline-flex; }
}
/* Móvil: cajón deslizable sobre el contenido */
@media (max-width: 767px) {
  /* Misma especificidad que la regla compacta de tablet (0,2,0) y declarada después: gana en móvil */
  .shell:not([data-lateral="expandido"]), .shell[data-lateral="expandido"] {
    grid-template-columns: minmax(0, 1fr); grid-template-areas: "topbar" "contenido"; }
  .lateral { position: fixed; top: var(--alto-topbar); bottom: 0; left: 0; width: min(88vw, 320px); transform: translateX(-102%);
    transition: transform .2s ease; box-shadow: var(--sombra-2); }
  .shell[data-cajon="abierto"] .lateral { transform: none; }
  .shell .lateral .linea-btn .etq, .shell .lateral .linea-btn .flecha { display: inline; }
  .shell .lateral .linea.abierta ul { display: block; }
  .shell .lateral .mini-macro { display: grid; }
  .shell .lateral .linea-btn { justify-content: flex-start; }
  .shell[data-cajon="abierto"] .velo { display: block; position: fixed; inset: var(--alto-topbar) 0 0 0; background: rgba(8, 12, 20, .45); z-index: 15; }
  :root { --alto-topbar: 100px; }
  .topbar { flex-wrap: wrap; align-content: center; gap: 6px var(--e-2); padding: 6px var(--e-2); }
  .topbar .marca { flex: 1; } .topbar .marca span { display: none; }
  .topbar .selectores { order: 10; width: 100%; margin-left: 0; }
  .topbar .sel-cliente { flex: 1; width: auto; min-width: 0; } .topbar .sel-ejercicio { width: 76px; } .topbar .sel-mes { width: 108px; }
  .topbar .espaciador { display: none; }
  .contenido { padding: var(--e-3); }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
