/* ══ SIRIO — Paleta institucional idéntica a generador_cdp.py ══════════════ */
:root {
  --c-rojo:     #C0392B;
  --c-azul:     #1A3A5C;
  --c-azul2:    #2980B9;
  --c-gris:     #F4F6F8;
  --c-gris2:    #BDC3C7;
  --c-blanco:   #FFFFFF;
  --c-texto:    #2C3E50;
  --c-verde:    #27AE60;
  --c-amarillo: #F39C12;
  --font:       "Segoe UI", system-ui, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; font-family: var(--font); background: var(--c-gris); color: var(--c-texto); }

/* ══ HEADER ════════════════════════════════════════════════════════════════ */
.inst-header {
  background: var(--c-azul);
  display: flex; align-items: center;
  padding: 0 16px; min-height: 64px; gap: 12px;
}
.inst-header .logo img { height: 48px; object-fit: contain; }
.inst-header .titles { flex: 1; }
.inst-header .titles h1 { font-size: 11pt; font-weight: bold; color: var(--c-blanco); }
.inst-header .titles .subtitle { font-size: 9pt; color: var(--c-azul2); }
.inst-header .version { font-size: 8pt; color: var(--c-azul2); white-space: nowrap; }
.header-divider { height: 4px; background: var(--c-rojo); }

/* ══ BARRA USUARIO ═════════════════════════════════════════════════════════ */
.user-bar {
  background: #1A3A5C; height: 38px;
  display: flex; align-items: center; padding: 0 12px; gap: 6px;
}
.user-bar .user-info { color: var(--c-blanco); font-size: 9pt; flex: 1; }
/* Menú de cuenta: en escritorio los enlaces fluyen en la barra (display:contents);
   en móvil se colapsan bajo el botón "Cuenta ▾" (ver @media). */
.user-menu { display: contents; }
.user-menu-toggle { display: none; }
.btn-logout {
  background: var(--c-rojo); color: var(--c-blanco);
  border: none; padding: 4px 14px; font-size: 8pt; font-weight: bold;
  cursor: pointer; border-radius: 2px; text-decoration: none;
  display: inline-flex; align-items: center;
}
.btn-admin {
  background: var(--c-amarillo); color: var(--c-azul);
  border: none; padding: 4px 14px; font-size: 8pt; font-weight: bold;
  cursor: pointer; border-radius: 2px; text-decoration: none;
  display: inline-flex; align-items: center;
}

/* ══ FOOTER ════════════════════════════════════════════════════════════════ */
.inst-footer {
  background: var(--c-azul); text-align: center; padding: 5px;
  position: fixed; bottom: 0; width: 100%; z-index: 10;
}
.inst-footer span { font-size: 8pt; color: var(--c-azul2); }

/* ══ MÓDULOS GRID (réplica _build_card) ════════════════════════════════════ */
.page-center {
  padding: 24px 0 60px;
  display: flex; flex-direction: column; align-items: center;
}
.section-title { font-size: 13pt; font-weight: bold; color: var(--c-azul); }
.section-divider { height: 2px; width: 300px; background: var(--c-rojo); margin: 4px 0; }
.section-sub { font-size: 9pt; color: #888; margin-bottom: 20px; }

.modules-grid {
  display: flex; flex-wrap: wrap; gap: 24px; justify-content: center;
  padding: 8px 24px;
}
.module-card {
  background: var(--c-blanco); border: 2px solid var(--c-azul);
  width: 210px; min-height: 215px;
  display: flex; flex-direction: column; align-items: center;
  cursor: pointer; transition: background 150ms; text-decoration: none;
  color: inherit;
}
.module-card:hover:not(.disabled) { background: #D6EAF8; }
.module-card .card-bar { height: 6px; width: 100%; background: var(--c-azul); }
.module-card .card-icon { font-size: 38px; padding: 12px 0 2px; color: var(--c-azul); }
.module-card .card-title {
  font-size: 10pt; font-weight: bold; color: var(--c-azul);
  text-align: center; padding: 0 10px; line-height: 1.4;
}
.module-card .card-desc {
  font-size: 8pt; color: #555;
  text-align: center; padding: 3px 10px 0;
}
.module-card.disabled {
  background: #ECECEC; cursor: default; border-color: var(--c-gris2);
}
.module-card.disabled .card-bar   { background: var(--c-gris2); }
.module-card.disabled .card-icon  { color: var(--c-gris2); }
.module-card.disabled .card-title { color: var(--c-gris2); }
.module-card.disabled .card-desc  { color: #AAA; }
.badge-restricted { font-size: 8pt; font-style: italic; color: var(--c-rojo); padding: 4px; }
.badge-soon       { font-size: 8pt; font-style: italic; color: var(--c-amarillo); padding: 4px; }

/* ══ LAYOUT SIDEBAR ════════════════════════════════════════════════════════ */
.layout {
  display: flex;
  /* header + divider + userbar + nav-bar(atras/inicio) + footer */
  height: calc(100vh - 64px - 4px - 38px - 38px - 24px);
}
.sidebar {
  width: 220px; background: var(--c-azul);
  display: flex; flex-direction: column; flex-shrink: 0;
  overflow-y: auto;
}
.sidebar .sb-logo { text-align: center; padding: 14px 8px 2px; }
.sidebar .sb-logo img { height: 36px; object-fit: contain; }
.sidebar .sb-title {
  color: var(--c-blanco); font-size: 10pt; font-weight: bold;
  text-align: center; padding: 4px 8px 0; line-height: 1.3;
}
.sidebar .sb-sub { color: var(--c-azul2); font-size: 8pt; text-align: center; padding-bottom: 8px; }
.sidebar .sb-divider { height: 1px; background: var(--c-azul2); margin: 0 16px 4px; }
.sidebar .nav-item {
  color: var(--c-blanco); font-size: 9pt;
  padding: 10px 16px; cursor: pointer;
  display: block; text-decoration: none;
  border-left: 3px solid transparent;
  transition: background 150ms;
}
.sidebar .nav-item:hover, .sidebar .nav-item.active {
  background: rgba(255,255,255,.1);
  border-left-color: var(--c-rojo);
}
.sidebar .btn-back {
  margin: auto 12px 12px;
  background: var(--c-rojo); color: white;
  border: none; padding: 7px 0; text-align: center;
  cursor: pointer; font-size: 9pt; text-decoration: none;
  display: block; border-radius: 2px;
}
.main-panel { flex: 1; overflow-y: auto; background: var(--c-gris); padding: 20px; }

/* Cajón lateral: el botón ☰ está SIEMPRE visible (colapsa el menú en cualquier
   ancho). Backdrop y ✕ solo aparecen en modo overlay (móvil angosto, @media). */
.sb-close, .sb-backdrop { display: none; }
.sb-toggle {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--c-rojo); color: #fff; border: none; border-radius: 4px;
  padding: 7px 12px; font-size: 10pt; line-height: 1; cursor: pointer;
  font-family: inherit; font-weight: 600;
}
.sb-toggle-float {
  position: fixed; left: 12px; bottom: 58px; z-index: 1100;
  box-shadow: 0 2px 8px rgba(0,0,0,.3);
}
/* Ancho (landscape/tablet/escritorio): el ☰ oculta/muestra el sidebar acoplado
   y el contenido ocupa todo el ancho. En angosto (≤768) manda el overlay. */
@media (min-width: 769px) {
  html.sb-hidden .sidebar { display: none; }
}

/* ══ TABLAS (réplica ttk.Treeview) ════════════════════════════════════════ */
.sirio-table { width: 100%; border-collapse: collapse; font-size: 9pt; }
.sirio-table thead th {
  background: var(--c-azul); color: var(--c-blanco);
  padding: 6px 10px; text-align: left; font-size: 8.5pt;
}
.sirio-table tbody tr:nth-child(even) { background: #EBF5FB; }
.sirio-table tbody tr:hover { background: #D6EAF8; cursor: pointer; }
.sirio-table tbody td { padding: 5px 10px; border-bottom: 1px solid #DDD; }
.sirio-table tbody tr.selected { background: var(--c-azul2); color: white; }
.table-wrap { background: white; border-radius: 2px; overflow: hidden; box-shadow: 0 1px 3px rgba(0,0,0,.1); }

/* ══ FORMULARIOS ═══════════════════════════════════════════════════════════ */
.form-label { font-size: 9pt; color: var(--c-texto); display: block; margin-bottom: 2px; margin-top: 10px; }
.form-input {
  width: 100%; padding: 5px 8px;
  border: 1px solid #CCC; border-bottom: 2px solid var(--c-azul);
  font-family: var(--font); font-size: 10pt;
  background: white;
}
.form-input:focus { outline: none; border-bottom-color: var(--c-azul2); }
.form-select { width: 100%; padding: 5px 8px; border: 1px solid #CCC; font-family: var(--font); font-size: 10pt; }

/* ══ BOTONES ════════════════════════════════════════════════════════════════ */
.btn {
  padding: 6px 16px; border: none; cursor: pointer;
  font-family: var(--font); font-size: 9pt; border-radius: 2px;
  text-decoration: none; display: inline-block;
}
.btn-primary { background: var(--c-azul);     color: white; }
.btn-success { background: var(--c-verde);    color: white; }
.btn-danger  { background: var(--c-rojo);     color: white; }
.btn-warning { background: var(--c-amarillo); color: var(--c-azul); font-weight: bold; }
.btn-sm      { padding: 4px 10px; font-size: 8pt; }
.btn-group   { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }

/* ══ PROGRESS BAR ══════════════════════════════════════════════════════════ */
.progress-wrap { background: #EEE; border-radius: 2px; overflow: hidden; height: 20px; margin: 8px 0; }
.progress-fill  { height: 100%; background: var(--c-azul2); transition: width 300ms ease; }
.progress-label { font-size: 8pt; color: #666; }

/* ══ MODAL ═════════════════════════════════════════════════════════════════ */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.4);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
.modal-card {
  background: white; min-width: 380px; max-width: 480px;
  padding: 0; border-radius: 2px; box-shadow: 0 4px 24px rgba(0,0,0,.2);
}
.modal-header {
  background: var(--c-azul); color: white;
  padding: 12px 20px; font-weight: bold; font-size: 11pt;
}
.modal-body   { padding: 20px; }
.modal-footer { padding: 12px 20px; border-top: 1px solid #EEE; display: flex; gap: 8px; justify-content: flex-end; }

/* ══ LOGIN ═════════════════════════════════════════════════════════════════ */
.login-bg {
  min-height: 100vh; background: var(--c-azul);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.login-logo { margin-bottom: 18px; }
.login-logo img { height: 110px; object-fit: contain; }
.login-card {
  background: white; width: 380px; padding: 0;
  box-shadow: 0 4px 24px rgba(0,0,0,.3);
}
.login-card .card-top { height: 4px; background: var(--c-azul); }
.login-card .card-body { padding: 28px 40px 32px; }
.login-card h2 { font-size: 16pt; font-weight: bold; color: var(--c-azul); margin-bottom: 2px; }
.login-card .brand { font-size: 8pt; color: #888; margin-bottom: 12px; }
.login-divider { height: 2px; background: var(--c-rojo); margin-bottom: 20px; }
.login-card .card-bot { height: 4px; background: var(--c-azul); }
.login-error { color: var(--c-rojo); font-size: 9pt; font-style: italic; min-height: 18px; margin-bottom: 8px; }
.btn-login {
  width: 100%; background: var(--c-azul); color: white;
  border: none; padding: 10px; font-size: 11pt; font-weight: bold;
  cursor: pointer; font-family: var(--font);
}
.btn-login:hover { background: var(--c-azul2); }
.pw-row { display: flex; align-items: center; border: 1px solid #CCC; border-bottom: 2px solid var(--c-azul); background: white; }
.pw-row input { flex: 1; padding: 5px 8px; border: none; font-family: var(--font); font-size: 10pt; outline: none; }
.pw-eye { background: none; border: none; cursor: pointer; padding: 0 8px; color: #888; font-size: 14px; }

/* ══ ALERTAS ═══════════════════════════════════════════════════════════════ */
.alert { padding: 8px 12px; border-radius: 2px; font-size: 9pt; margin-bottom: 8px; }
.alert-error   { background: #FADBD8; color: var(--c-rojo); border-left: 3px solid var(--c-rojo); }
.alert-success { background: #D5F5E3; color: var(--c-verde); border-left: 3px solid var(--c-verde); }
.alert-info    { background: #D6EAF8; color: var(--c-azul); border-left: 3px solid var(--c-azul2); }

/* ══ UTILIDADES ════════════════════════════════════════════════════════════ */
.mt8  { margin-top: 8px; }  .mt16 { margin-top: 16px; }
.mb8  { margin-bottom: 8px; }
.page-header { margin-bottom: 16px; }
.page-header h2 { font-size: 13pt; font-weight: bold; color: var(--c-azul); }
.page-header .ph-div { height: 2px; background: var(--c-rojo); width: 100%; margin: 4px 0 2px; }
.page-header p { font-size: 9pt; color: #888; }
.badge-activo    { color: var(--c-verde); font-weight: bold; }
.badge-inactivo  { color: var(--c-rojo);  font-weight: bold; }
.badge-admin     { color: var(--c-azul);  font-weight: bold; }

/* ══ INDICADOR DE PROGRESO GLOBAL ══════════════════════════════════════════ */
#sirio-progress-overlay {
  position: fixed; inset: 0; z-index: 99999;
  background: rgba(26, 58, 92, 0.55);
  backdrop-filter: blur(2px);
  display: none;
  align-items: center; justify-content: center;
  animation: sp-fade 0.18s ease-out;
}
#sirio-progress-overlay.sp-visible { display: flex; }

#sirio-progress-overlay .sp-card {
  background: var(--c-blanco);
  border-radius: 6px;
  padding: 26px 32px 22px;
  min-width: 320px; max-width: 460px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.35), 0 0 0 1px rgba(255,255,255,0.05);
  text-align: center;
  border-top: 4px solid var(--c-rojo);
  position: relative;
}
#sirio-progress-overlay .sp-close {
  position: absolute; top: 6px; right: 8px;
  width: 26px; height: 26px;
  background: transparent; border: none;
  color: #94A3B8; font-size: 13pt; font-weight: bold;
  cursor: pointer; line-height: 1;
  border-radius: 50%;
  transition: background 0.15s, color 0.15s;
}
#sirio-progress-overlay .sp-close:hover {
  background: #FADBD8; color: var(--c-rojo);
}
#sirio-progress-overlay .sp-hint-action {
  color: var(--c-rojo); font-weight: bold;
}

#sirio-progress-overlay .sp-spinner {
  width: 44px; height: 44px;
  margin: 0 auto 14px;
  border: 4px solid #E8EEF4;
  border-top-color: var(--c-azul);
  border-right-color: var(--c-rojo);
  border-radius: 50%;
  animation: sp-spin 0.8s linear infinite;
}

#sirio-progress-overlay .sp-msg {
  font-size: 11pt; font-weight: bold;
  color: var(--c-azul);
  margin-bottom: 4px;
}
#sirio-progress-overlay .sp-sub {
  font-size: 8.5pt; color: #6B7C93;
  margin-bottom: 14px; line-height: 1.4;
}

#sirio-progress-overlay .sp-bar {
  height: 6px; background: #ECF1F6;
  border-radius: 3px; overflow: hidden;
  margin-bottom: 10px;
}
#sirio-progress-overlay .sp-bar-fill {
  height: 100%; width: 35%;
  background: linear-gradient(90deg,
    var(--c-azul) 0%, var(--c-azul2) 50%, var(--c-rojo) 100%);
  border-radius: 3px;
  animation: sp-bar 1.4s ease-in-out infinite;
}

#sirio-progress-overlay .sp-hint {
  font-size: 7.5pt; color: #94A3B8;
  letter-spacing: 0.4px; text-transform: uppercase;
}

@keyframes sp-spin { to { transform: rotate(360deg); } }
@keyframes sp-bar {
  0%   { margin-left: -35%; }
  100% { margin-left: 100%; }
}
@keyframes sp-fade { from { opacity: 0; } to { opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
  #sirio-progress-overlay .sp-spinner { animation-duration: 2s; }
  #sirio-progress-overlay .sp-bar-fill { animation-duration: 3s; }
}

/* ══ RESPONSIVE / MÓVIL ════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  /* CRÍTICO: evitar que contenido ancho (tablas, grids) expanda la página y
     fuerce el "zoom-out" global del navegador móvil. La página no scrollea en
     horizontal; las tablas anchas scrollean dentro de su propio contenedor. */
  html, body { overflow-x: hidden; max-width: 100%; width: 100%; }
  #main-content, main, .main-panel { max-width: 100%; min-width: 0; }
  /* En móvil el scroll es de la página completa, no de un panel interno. */
  .layout { height: auto; min-height: 0; }
  .main-panel { overflow: visible; }
  /* Cualquier tabla suelta (sin wrapper) se vuelve deslizable en bloque. */
  table { max-width: 100%; }

  /* Header e info de usuario: permitir salto de línea y reducir tamaños */
  .inst-header { flex-wrap: wrap; padding: 6px 10px; }
  .inst-header .logo img { height: 34px; }
  .inst-header .titles h1 { font-size: 10pt; line-height: 1.2; }
  .inst-header .titles .subtitle { font-size: 8pt; }
  /* Encabezado compacto: fuera subtítulo y versión (ya están en el breadcrumb),
     título en una sola línea. Ahorra ~2 renglones en vertical. */
  .inst-header .titles .subtitle,
  .inst-header .version { display: none; }
  .inst-header .titles h1 {
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }

  /* Barra de usuario en UNA fila: acciones colapsadas en "Cuenta ▾" */
  .user-bar { height: auto; flex-wrap: nowrap; padding: 6px 10px; gap: 8px;
    position: relative; }
  .user-bar .user-info {
    flex: 1 1 auto; min-width: 0; white-space: nowrap;
    overflow: hidden; text-overflow: ellipsis;
  }
  .user-menu-toggle {
    display: inline-flex; align-items: center; gap: 4px; flex: 0 0 auto;
    background: var(--c-rojo); color: #fff; border: none; border-radius: 4px;
    padding: 8px 12px; font-size: 9.5pt; font-weight: 600; line-height: 1;
    cursor: pointer; font-family: inherit; min-height: 38px;
  }
  .user-menu {
    display: none; position: absolute; top: 100%; right: 8px; margin-top: 4px;
    flex-direction: column; min-width: 190px; background: #14304d;
    border: 1px solid rgba(255,255,255,.15); border-radius: 6px;
    box-shadow: 0 6px 20px rgba(0,0,0,.45); z-index: 950; overflow: hidden;
  }
  .user-menu.open { display: flex; }
  .user-menu .btn-admin, .user-menu .btn-logout {
    display: block; width: 100%; text-align: left; border-radius: 0; margin: 0;
    padding: 13px 14px; border-bottom: 1px solid rgba(255,255,255,.08);
  }
  .user-menu .btn-logout { border-bottom: none; }

  /* Layout en una sola columna con scroll natural de página */
  .layout { flex-direction: column; height: auto; }

  /* Sidebar = cajón vertical (position/width los fija base.html inline).
     Aquí solo el estilo interno: ítems a todo el ancho, apilados. */
  .sidebar .nav-item {
    white-space: normal; padding: 14px 16px;
    border-left: 3px solid transparent; border-bottom: none;
  }
  .sidebar .nav-item:hover, .sidebar .nav-item.active {
    border-left-color: var(--c-rojo); border-bottom: none;
  }
  .sidebar .btn-back { margin: 10px 12px; padding: 10px 14px; white-space: nowrap; }

  /* Fondo translúcido tras el cajón abierto (solo overlay móvil) */
  .sb-backdrop {
    display: block; position: fixed; inset: 0; background: rgba(0,0,0,.45);
    z-index: 1150; opacity: 0; visibility: hidden; transition: opacity .25s ease;
  }
  .sb-backdrop.show { opacity: 1; visibility: visible; }
  /* Botón cerrar (✕) dentro del cajón */
  .sb-close {
    display: block; position: sticky; top: 0; align-self: flex-end;
    background: transparent; color: #fff; border: none; font-size: 20px;
    line-height: 1; padding: 8px 14px; cursor: pointer;
  }

  /* Contenido: padding reducido y espacio para el footer fijo */
  .main-panel { padding: 12px; padding-bottom: 44px; }

  /* Tablas: scrolleables horizontalmente aunque no tengan contenedor wrapper.
     display:block + overflow-x permite el deslizamiento táctil sin recortar. */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .sirio-table {
    display: block; overflow-x: auto; white-space: nowrap;
    -webkit-overflow-scrolling: touch; font-size: 8.5pt;
  }
  /* Grids fijos de los módulos (KPIs, coordenadas) → menos columnas en móvil.
     !important para ganar a los <style> locales de cada plantilla. */
  .kpi-strip  { grid-template-columns: repeat(2, 1fr) !important; }
  .coord-grid { grid-template-columns: repeat(3, 1fr) !important; }

  /* Objetivos táctiles cómodos */
  .btn, .btn-logout, .btn-admin {
    min-height: 42px; display: inline-flex; align-items: center;
    justify-content: center;
  }

  /* Inputs legibles y a 16px para evitar el auto-zoom de iOS */
  input, select, textarea { font-size: 16px; max-width: 100%; }

  /* Firma electrónica y otros formularios: los grids multi-columna
     (pasos de flujo, circuito, variantes, notificación, firmantes) colapsan
     a una sola columna para operar cómodamente desde el móvil. */
  .paso-row, .firmante-form, .firma-variante-grid,
  .circuit-steps, .circuit-grid, .notify-form {
    grid-template-columns: 1fr !important;
  }
  /* Modales: casi pantalla completa y con scroll vertical en móvil. */
  #modal-circuito > div, #modal-fea-c > div, #modal-importar > div,
  .modal-card {
    width: 96% !important; max-width: 96% !important; max-height: 90vh;
  }
}

/* Teléfonos pequeños */
@media (max-width: 480px) {
  .kpi-strip { grid-template-columns: 1fr !important; }
  .main-panel { padding: 10px; padding-bottom: 44px; }
  .inst-header .titles h1 { font-size: 9.5pt; }
}
