/* ============================= */
/* LAYOUT V2 (Global)            */
/* No toca lógica ni BD.         */
/* Sobrescribe estilos legacy.   */
/* ============================= */

:root{
  --color-primary:#0f3d75;
  --color-primary-hover:#0b2f5d;
  --color-primary-soft:#e8f1fb;
  --color-background:#f4f7fb;
  --color-surface:#ffffff;
  --color-surface-muted:#f8fafc;
  --color-text:#172033;
  --color-text-muted:#667085;
  --color-border:#dbe3ee;
  --color-success:#16803c;
  --color-warning:#b7791f;
  --color-danger:#c2410c;
  --sidebar-width: 272px;
  --sidebar-collapsed-width: 76px;
  --sidebar-collapsed: var(--sidebar-collapsed-width);
  --topbar-height: 64px;
  --content-padding: 24px;
  --content-max: 1480px;
  --radius-sm:8px;
  --radius-md:12px;
  --radius-lg:16px;
  --shadow-sm:0 1px 2px rgba(16,24,40,0.05);
  --shadow-md:0 10px 28px rgba(16,24,40,0.10);
  --space-1:4px;
  --space-2:8px;
  --space-3:12px;
  --space-4:16px;
  --space-5:24px;
  --space-6:32px;
  --primary:var(--color-primary);
  --primary-hover:var(--color-primary-hover);
  --primary-soft:var(--color-primary-soft);
  --bg:var(--color-background);
  --surface:var(--color-surface);
  --surface-muted:var(--color-surface-muted);
  --text:var(--color-text);
  --muted:var(--color-text-muted);
  --border:var(--color-border);
  --success:var(--color-success);
  --warning:var(--color-warning);
  --danger:var(--color-danger);
  --ring: 0 0 0 3px rgba(15,61,117,0.18);
}

body{
  overflow-x:hidden;
}

/* Box-model consistente (evita que el padding de la sidebar encime el contenido) */
#appScreen *, #appScreen *::before, #appScreen *::after{
  box-sizing:border-box;
}

/* Contenedor principal (Sidebar + Main) */
.app-container{
  /* Layout robusto: sidebar fija + main con margin-left (evita encimes por overrides legacy) */
  display:block !important;
  min-height:100vh;
  height:auto;
  width:100%;
  overflow:visible;
  box-sizing:border-box;
  /* Reserva espacio real para la sidebar fija (evita que se encime en cualquier módulo) */
  padding-left: var(--sidebar-width);
}

.app-container.sidebar-collapsed{
  --sidebar-width: var(--sidebar-collapsed);
}

/* Sidebar */
.sidebar{
  position:fixed;
  left:0;
  top:0;
  bottom:0;
  width:var(--sidebar-width) !important;
  overflow:auto;
  padding:14px;
  background: linear-gradient(180deg, #0f1f3a 0%, #0b1930 100%);
  color:#e5e7eb;
  border-right:1px solid rgba(148,163,184,0.18);
  z-index:120;
}

.sidebar::-webkit-scrollbar{ width:10px; }
.sidebar::-webkit-scrollbar-thumb{ background:rgba(148,163,184,0.18); border-radius:999px; }
.sidebar::-webkit-scrollbar-track{ background:transparent; }

.sidebar-header{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  padding:8px 8px 12px 8px;
  border-bottom:1px solid rgba(148,163,184,0.14);
  margin-bottom:10px;
}

.brand{
  display:flex;
  align-items:center;
  gap:10px;
  min-width:0;
}

.brand-mark{
  width:44px;
  height:44px;
  object-fit:contain;
  border-radius:12px;
  background:rgba(255,255,255,0.92);
  border:1px solid rgba(148,163,184,0.16);
  padding:6px;
}

.brand-text{
  display:flex;
  flex-direction:column;
  gap:2px;
  min-width:0;
}
.brand-text .t{
  font-weight:800;
  letter-spacing:0.2px;
  font-size:13px;
  white-space:nowrap;
  overflow:visible;
  text-overflow:ellipsis;
}
.brand-text .s{
  font-size:11px;
  color:rgba(226,232,240,0.75);
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
}

.icon-btn{
  appearance:none;
  border:1px solid rgba(148,163,184,0.18);
  background:rgba(255,255,255,0.06);
  color:#e5e7eb;
  border-radius:10px;
  width:38px;
  height:38px;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  cursor:pointer;
  transition:all .15s ease;
}
.icon-btn:hover{ filter:brightness(1.06); transform:translateY(-1px); }
.icon-btn:focus{ outline:none; box-shadow: var(--ring); }

.sidebar-nav{
  display:flex;
  flex-direction:column;
  gap:6px;
  padding:6px 4px;
  background:transparent;
}

.nav-section-title{
  margin:10px 8px 6px 8px;
  font-size:11px;
  font-weight:900;
  letter-spacing:0.10em;
  text-transform:uppercase;
  color:rgba(226,232,240,0.70);
}

/* UX: secciones plegables */
.ux-section{
  padding:14px;
  border-radius:14px;
  border:1px solid var(--border);
  background:var(--surface);
  box-shadow:var(--shadow-sm);
  margin-bottom:14px;
}
/* Cuando una caja legacy recibe ux-section, forzamos el estilo moderno */
.ux-section.list-box,
.ux-section.dashboard-section,
.ux-section.form-box{
  background:var(--surface) !important;
  padding:14px !important;
  border-radius:14px !important;
  margin-bottom:14px !important;
  border:1px solid var(--border) !important;
  box-shadow:var(--shadow-sm) !important;
}
.ux-section > .ux-section-head{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  margin:0;
  padding:2px 0 10px 0;
  border-bottom:1px solid rgba(15,23,42,0.06);
  cursor:pointer;
}
.ux-section-title{
  font-size:14px;
  font-weight:950;
  color:var(--text);
}
.ux-section-toggle{
  width:34px;
  height:34px;
  border-radius:10px;
  border:1px solid var(--border);
  background:rgba(15,23,42,0.03);
  display:inline-flex;
  align-items:center;
  justify-content:center;
  cursor:pointer;
}
.ux-section-toggle:hover{ background:rgba(37,99,235,0.08); border-color:rgba(37,99,235,0.20); }
.ux-section-body{ padding-top:12px; }
.ux-section.collapsed > .ux-section-head{ border-bottom:0; }

/* UX: labels persistentes para inputs sin label (solo en forms simples) */
.ux-inline-label{
  font-size:12px;
  font-weight:800;
  color:var(--muted);
  margin:2px 0 6px 0;
}

/* UX: barras de acciones (Condóminos / Cartera, etc.) */
.ux-actions-row{
  display:flex;
  align-items:flex-start;
  justify-content:space-between;
  gap:12px;
  flex-wrap:wrap;
  width:100%;
}

/* Asegura que el contenedor de acciones ocupe el ancho completo */
.usuarios-actions{
  width:100%;
}
.ux-actions-left{
  display:flex;
  align-items:center;
  gap:10px;
  flex-wrap:wrap;
}
.ux-actions-right{
  flex:1 1 280px;
  min-width:260px;
  display:flex;
  justify-content:flex-end;
}
.ux-actions-right input{
  max-width:420px;
}

.ux-actions-more{
  position:relative;
}
.ux-actions-more > summary{
  list-style:none;
  cursor:pointer;
  user-select:none;
  padding:10px 12px;
  border:1px solid var(--border);
  border-radius:10px;
  background:rgba(15,23,42,0.03);
  font-weight:900;
  color:var(--text);
}
.ux-actions-more > summary:hover{
  background:rgba(37,99,235,0.08);
  border-color:rgba(37,99,235,0.20);
}
.ux-actions-more > summary::-webkit-details-marker{ display:none; }
.ux-actions-more[open] > summary{
  background:rgba(37,99,235,0.10);
  border-color:rgba(37,99,235,0.25);
}
.ux-actions-panel{
  margin-top:10px;
  padding:12px;
  border:1px solid var(--border);
  border-radius:14px;
  background:var(--surface);
  box-shadow:var(--shadow-md);
  min-width:min(720px, 92vw);
}
.ux-actions-subtitle{
  font-size:12px;
  font-weight:950;
  color:var(--muted);
  margin:6px 0 10px 0;
  text-transform:uppercase;
  letter-spacing:0.08em;
}
.ux-actions-grid{
  display:grid;
  grid-template-columns:repeat(2, minmax(0, 1fr));
  gap:10px;
}
.ux-inline-group{
  display:flex;
  gap:10px;
  flex-wrap:wrap;
  align-items:center;
}
.ux-divider{
  height:1px;
  background:rgba(15,23,42,0.08);
  margin:12px 0;
}

/* UX: barra de acciones por módulo (finanzas, etc.) */
.ux-modulebar{
  display:flex;
  align-items:flex-start;
  justify-content:space-between;
  gap:12px;
  padding:12px 14px;
  border:1px solid var(--border);
  background:rgba(15,23,42,0.02);
  border-radius:14px;
  box-shadow:var(--shadow-sm);
  margin:10px 0 14px 0;
}
.ux-modulebar-left{
  min-width:220px;
}
.ux-modulebar-title{
  font-weight:950;
  font-size:13px;
  color:var(--text);
}
.ux-modulebar-sub{
  margin-top:4px;
  font-size:12px;
  color:var(--muted);
  font-weight:700;
  line-height:1.2;
}
.ux-modulebar-actions{
  display:flex;
  gap:10px;
  flex-wrap:wrap;
  justify-content:flex-end;
}

@media (max-width: 900px){
  .ux-modulebar{ flex-direction:column; }
  .ux-modulebar-actions{ justify-content:flex-start; }
}

@media (max-width: 900px){
  .ux-actions-right{ justify-content:stretch; }
  .ux-actions-right input{ max-width:100%; }
  .ux-actions-panel{ min-width: min(560px, 94vw); }
  .ux-actions-grid{ grid-template-columns:1fr; }
}

/* Command palette (Ctrl+K) */
.ux-cmdk{
  position:fixed;
  inset:0;
  z-index:2000;
}
.ux-cmdk.hidden{ display:none; }
.ux-cmdk-backdrop{
  position:absolute;
  inset:0;
  background:rgba(15,23,42,0.55);
  backdrop-filter: blur(6px);
}
.ux-cmdk-dialog{
  position:relative;
  max-width:720px;
  margin:10vh auto 0 auto;
  background:var(--surface);
  border:1px solid var(--border);
  border-radius:16px;
  box-shadow:var(--shadow-md);
  padding:14px;
  width:calc(100% - 24px);
}
.ux-cmdk-head{
  display:flex;
  align-items:center;
  justify-content:space-between;
  margin-bottom:10px;
}
.ux-cmdk-title{
  font-weight:950;
  color:var(--text);
  font-size:14px;
}
.ux-cmdk-hint{
  font-size:12px;
  font-weight:900;
  color:var(--muted);
  padding:6px 10px;
  border-radius:999px;
  border:1px solid var(--border);
  background:rgba(15,23,42,0.03);
}
.ux-cmdk-input{
  width:100%;
  padding:12px 12px;
  border-radius:12px;
  border:1px solid var(--border);
  outline:none;
}
.ux-cmdk-list{
  margin-top:10px;
  display:flex;
  flex-direction:column;
  gap:8px;
  max-height:42vh;
  overflow:auto;
  padding-right:4px;
}
.ux-cmdk-item{
  display:flex;
  align-items:center;
  gap:10px;
  padding:10px 12px;
  border-radius:12px;
  border:1px solid var(--border);
  background:rgba(15,23,42,0.02);
  cursor:pointer;
  text-align:left;
}
.ux-cmdk-item:hover,
.ux-cmdk-item.active{
  background:rgba(37,99,235,0.10);
  border-color:rgba(37,99,235,0.25);
}
.ux-cmdk-item .k{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  width:44px;
  height:28px;
  border-radius:10px;
  font-weight:950;
  font-size:12px;
  background:rgba(15,23,42,0.04);
  border:1px solid rgba(15,23,42,0.08);
  color:var(--text);
  flex:0 0 auto;
}
.ux-cmdk-item .t{
  font-weight:900;
  color:var(--text);
}
.ux-cmdk-foot{
  display:flex;
  justify-content:flex-end;
  gap:10px;
  margin-top:10px;
  font-size:12px;
  color:var(--muted);
  font-weight:800;
}

.nav-btn{
  width:100%;
  display:flex;
  align-items:center;
  gap:10px;
  padding:10px 10px;
  border-radius:12px;
  border:1px solid rgba(148,163,184,0.14);
  background:rgba(255,255,255,0.04);
  color:#e5e7eb;
  cursor:pointer;
  text-align:left;
  transition:all .15s ease;
}
.nav-btn:hover{
  background:rgba(59,130,246,0.12);
  border-color:rgba(59,130,246,0.22);
}
.nav-btn.activo{
  background:rgba(59,130,246,0.20);
  border-color:rgba(59,130,246,0.35);
}

.nav-ico{
  flex:0 0 auto;
  width:30px;
  height:30px;
  border-radius:10px;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  background:rgba(255,255,255,0.06);
  border:1px solid rgba(148,163,184,0.16);
  font-weight:900;
  font-size:12px;
  color:#e5e7eb;
}

.nav-text{
  min-width:0;
  font-weight:800;
  font-size:13px;
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
}

.sidebar-footer{
  margin-top:12px;
  padding:12px 4px 4px 4px;
  border-top:1px solid rgba(148,163,184,0.14);
}

.nav-btn.logout{
  background:rgba(220,38,38,0.14);
  border-color:rgba(220,38,38,0.22);
}
.nav-btn.logout:hover{
  background:rgba(220,38,38,0.20);
  border-color:rgba(220,38,38,0.30);
}

/* Sidebar colapsada */
.app-container.sidebar-collapsed .brand-mark{
  width:34px;
  height:34px;
  padding:4px;
}
.app-container.sidebar-collapsed .brand-text{ display:none; }
.app-container.sidebar-collapsed .nav-text{ display:none; }
.app-container.sidebar-collapsed .nav-btn{ justify-content:center; padding:10px 8px; }
.app-container.sidebar-collapsed .sidebar-header{ justify-content:center; }
.app-container.sidebar-collapsed .sidebar-header .brand{ justify-content:center; }
.app-container.sidebar-collapsed .sidebar-header .icon-btn{ position:absolute; right:14px; }

/* Main */
.main-content{
  display:flex;
  flex-direction:column;
  overflow:hidden;
  background:var(--bg);
  min-height:100vh;
  height:auto;
  margin-left: 0 !important;
  width: 100% !important;
}

.topbar{
  position:sticky;
  top:0;
  z-index:50;
  height:var(--topbar-height);
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  padding:0 18px;
  background:rgba(255,255,255,0.88);
  border-bottom:1px solid var(--border);
  backdrop-filter: blur(10px);
}
.topbar-left{
  display:flex;
  align-items:center;
  gap:10px;
  min-width:0;
}
.topbar-title{
  font-size:16px;
  font-weight:900;
  color:var(--text);
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
}

.topbar-right{
  display:flex;
  align-items:center;
  gap:10px;
  flex-wrap:wrap;
}

.topbar-pill{
  font-size:12px;
  font-weight:800;
  color:var(--muted);
  padding:7px 10px;
  border-radius:999px;
  border:1px solid var(--border);
  background:rgba(148,163,184,0.10);
  white-space:nowrap;
}

#contentArea{
  padding: var(--content-padding) !important;
  overflow:visible;
  flex: initial;
  min-height: auto;
  max-width: var(--content-max);
  margin: 0 auto;
}

/* Tipografía y jerarquía dentro del área de la app */
#appScreen{
  color:var(--text);
}

#appScreen h2{
  font-size:18px;
  font-weight:950;
  letter-spacing:-0.01em;
  margin:0 0 14px 0;
}
#appScreen h3{
  font-size:14px;
  font-weight:900;
  margin:0 0 10px 0;
  color:var(--text);
}

/* Normaliza márgenes de módulos para evitar "huecos" */
#appScreen .modulo{
  margin-top:0 !important;
}

/* Contenedores (cards/panels) */
#appScreen .card,
#appScreen .dashboard-box,
#appScreen .form-box,
#appScreen .list-box,
#appScreen .bi-card{
  background:var(--surface);
  border:1px solid var(--border);
  box-shadow:var(--shadow-sm);
}

/* Inputs uniformes */
#appScreen input,
#appScreen select,
#appScreen textarea{
  width:100%;
  padding:10px 12px;
  background:var(--surface);
  color:var(--text);
  border:1px solid var(--border);
  border-radius:10px;
}
#appScreen textarea{ resize:vertical; }

/* Botones uniformes (sin tocar navegación sidebar) */
.btn,
#appScreen button:not(.nav-btn):not(.icon-btn){
  appearance:none;
  border:1px solid var(--border);
  background:rgba(15,23,42,0.03);
  color:var(--text);
  border-radius:10px;
  padding:10px 12px;
  font-weight:900;
  cursor:pointer;
  transition:transform .12s ease, filter .12s ease, background .12s ease, border-color .12s ease;
}
.btn:hover,
#appScreen button:not(.nav-btn):not(.icon-btn):hover{
  background:rgba(37,99,235,0.08);
  border-color:rgba(37,99,235,0.20);
}
.btn:active,
#appScreen button:not(.nav-btn):not(.icon-btn):active{
  transform:translateY(1px);
}

/* Variantes */
.btn.primary,
#appScreen button.primary{
  background:var(--primary);
  color:#fff;
  border-color:rgba(37,99,235,0.35);
}
.btn.primary:hover,
#appScreen button.primary:hover{
  background:var(--primary-dark);
  border-color:rgba(37,99,235,0.45);
}
.btn.danger,
#appScreen button.danger{
  background:#ef4444;
  border-color:#ef4444;
  color:#fff;
}
.btn.danger:hover,
#appScreen button.danger:hover{
  background:#dc2626;
  border-color:#dc2626;
}

/* Modo compatibilidad para entorno local (file://)
   En algunos equipos/navegadores el scroll interno puede sentirse "bloqueado".
   Este modo usa el scroll normal del documento para asegurar que el contenido
   (incluido Nube/Supabase) siempre sea visible. */
body.allow-body-scroll .app-container{
  height:auto;
  min-height:100vh;
  overflow:visible;
}
body.allow-body-scroll .main-content{
  height:auto;
  min-height:100vh;
  overflow:visible;
}
body.allow-body-scroll #contentArea{
  overflow:visible;
  flex:initial;
  min-height:auto;
}

/* Componentes globales */
.card, .dashboard-box, .form-box, .list-box{
  border-radius:14px !important;
}

.btn:focus, .nav-btn:focus{ outline:none; box-shadow: var(--ring); }

/* Espaciado estándar para toolbars con campos (evita encimes) */
.bi-toolbar-left{
  gap: 10px !important;
}
.bi-field{
  min-width: 160px;
}

/* Responsive */
@media (max-width: 980px){
  :root{ --content-padding: 16px; }
  .app-container{ --sidebar-mobile-width: min(86vw, 320px); }
  .sidebar{
    position:fixed;
    left:0;
    top:0;
    bottom:0;
    width:var(--sidebar-mobile-width);
    transform:translateX(-102%);
    transition:transform .18s ease;
    z-index:1000;
  }
  .main-content{
    margin-left: 0 !important;
    width: 100% !important;
    transition: margin-left .18s ease, width .18s ease;
  }
  .app-container{
    padding-left: 0;
    transition: padding-left .18s ease;
  }
  .app-container.sidebar-open .sidebar{
    transform:translateX(0);
  }
  /* Evita que la barra lateral quede encima del contenido (push layout) */
  .app-container.sidebar-open .main-content{
    margin-left: 0 !important;
    width: 100% !important;
  }
  .app-container.sidebar-open{
    padding-left: var(--sidebar-mobile-width);
  }
  /* Sin overlay: al usar "push", el overlay tapa el contenido. */
  .app-container.sidebar-open::before{
    content:"";
    display:none;
  }
  #contentArea{ max-width: 100%; }
}

@media (max-width: 520px){
  .topbar{
    padding:0 12px;
    gap:8px;
  }
  .topbar-title{ font-size:15px; }
  .topbar-pill{ display:none; }
}

/* ============================= */
/* RENOVACION UX 2026            */
/* Sistema visual administrativo */
/* ============================= */

html, body{
  background:var(--color-background);
  color:var(--color-text);
  font-family:Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
}

#contentArea{
  max-width:var(--content-max);
  margin:0 auto;
  padding:var(--space-5);
}

.main-content{
  background:var(--color-background);
  min-height:100vh;
}

.sidebar{
  background:#0d203a;
  border-right:1px solid rgba(255,255,255,0.08);
}

.nav-section-title{
  color:rgba(226,232,240,0.62);
  letter-spacing:.08em;
  font-size:10px;
  margin-top:var(--space-4);
}

.nav-btn{
  min-height:42px;
  border-radius:var(--radius-md);
}

.nav-ico{
  width:24px;
  min-width:24px;
  height:24px;
  display:inline-flex;
  align-items:center;
  justify-content:center;
}

.nav-ico svg{
  width:20px;
  height:20px;
  stroke:currentColor;
  stroke-width:2;
  fill:none;
}

.app-container.sidebar-collapsed .nav-btn{
  position:relative;
}

.app-container.sidebar-collapsed .nav-btn:hover::after{
  content:attr(data-title);
  position:absolute;
  left:calc(100% + 10px);
  top:50%;
  transform:translateY(-50%);
  background:#111827;
  color:#fff;
  padding:7px 9px;
  border-radius:8px;
  white-space:nowrap;
  box-shadow:var(--shadow-md);
  z-index:300;
  font-size:12px;
}

.topbar{
  background:rgba(255,255,255,0.92);
  backdrop-filter:saturate(120%) blur(12px);
}

.topbar-left{
  min-width:0;
}

.topbar-subtitle{
  color:var(--color-text-muted);
  font-size:12px;
  font-weight:700;
  margin-top:2px;
}

.topbar-right{
  gap:var(--space-2);
}

.system-menu{
  position:relative;
}

.system-menu summary{
  list-style:none;
  cursor:pointer;
  min-height:38px;
  padding:0 14px;
  display:inline-flex;
  align-items:center;
  border:1px solid var(--color-border);
  border-radius:999px;
  background:var(--color-surface);
  color:var(--color-text);
  font-weight:800;
}

.system-menu summary::-webkit-details-marker{ display:none; }

.system-menu-panel{
  position:absolute;
  right:0;
  top:calc(100% + 8px);
  width:220px;
  padding:var(--space-2);
  border:1px solid var(--color-border);
  border-radius:var(--radius-lg);
  background:var(--color-surface);
  box-shadow:var(--shadow-md);
  z-index:260;
  display:grid;
  gap:var(--space-2);
}

.visually-hidden{
  position:absolute !important;
  width:1px !important;
  height:1px !important;
  padding:0 !important;
  margin:-1px !important;
  overflow:hidden !important;
  clip:rect(0,0,0,0) !important;
  white-space:nowrap !important;
  border:0 !important;
}

#appScreen button.primary,
#appScreen .primary,
#appScreen button.btn-primary{
  background:var(--color-primary) !important;
  color:#fff !important;
  border-color:var(--color-primary) !important;
}

#appScreen button.primary:hover,
#appScreen .primary:hover{
  background:var(--color-primary-hover) !important;
}

#appScreen button.danger,
#appScreen .danger{
  color:#fff !important;
  background:var(--color-danger) !important;
  border-color:var(--color-danger) !important;
}

.btn-ghost{
  background:var(--color-surface-muted) !important;
}

.modulo{
  animation:erpFadeIn .14s ease-out;
}

@keyframes erpFadeIn{
  from{ opacity:.7; transform:translateY(4px); }
  to{ opacity:1; transform:none; }
}

.modulo > h2,
.usuarios-header h2,
#modulo-finanzas > h2{
  font-size:22px;
  line-height:1.2;
  margin:0 0 var(--space-4);
  color:var(--color-text);
  letter-spacing:0;
}

.dashboard-section,
.list-box,
.form-box,
.card,
.kpi-card,
.dashboard-box{
  border:1px solid var(--color-border);
  border-radius:var(--radius-lg);
  background:var(--color-surface);
  box-shadow:var(--shadow-sm);
}

.card,
.kpi-card{
  padding:var(--space-4);
}

.dashboard-section{
  padding:var(--space-4);
  margin-bottom:var(--space-4);
}

.dashboard-section > h3,
.form-box > h3,
.list-box > h3{
  font-size:15px;
  color:var(--color-text);
  margin:0 0 var(--space-3);
  letter-spacing:0;
}

.dashboard-kpis{
  grid-template-columns:repeat(auto-fit, minmax(210px, 1fr));
  gap:var(--space-3);
}

.kpi-card{
  min-height:104px;
}

.kpi-card strong{
  color:var(--color-text-muted);
  font-size:12px;
  text-transform:none;
}

.kpi-card span{
  color:var(--color-text);
  font-size:26px;
}

#appScreen input:not([type="checkbox"]):not([type="radio"]):not([type="file"]),
#appScreen select,
#appScreen textarea{
  min-height:40px;
  border:1px solid var(--color-border);
  border-radius:var(--radius-md);
  background:#fff;
  color:var(--color-text);
  padding:9px 11px;
  font-size:14px;
}

#appScreen textarea{
  min-height:92px;
}

#appScreen input:focus,
#appScreen select:focus,
#appScreen textarea:focus,
#appScreen button:focus-visible,
#appScreen summary:focus-visible{
  outline:none;
  box-shadow:var(--ring);
  border-color:rgba(15,61,117,.45);
}

.table-responsive{
  border:1px solid var(--color-border);
  border-radius:var(--radius-lg);
  overflow:auto;
  background:#fff;
}

#appScreen table{
  border-collapse:separate;
  border-spacing:0;
  width:100%;
}

#appScreen th{
  position:sticky;
  top:0;
  z-index:3;
  background:#f3f6fa !important;
  color:#22324a;
  font-size:12px;
  font-weight:900;
  text-align:left;
  border-bottom:1px solid var(--color-border);
}

#appScreen td{
  border-bottom:1px solid #eef2f7;
  color:#172033;
}

#appScreen tbody tr:hover td{
  background:#f8fbff;
}

.usuarios-header,
.checklist-header,
.ops-toolbar,
.ux-modulebar{
  border:1px solid var(--color-border);
  border-radius:var(--radius-lg);
  background:var(--color-surface);
  box-shadow:var(--shadow-sm);
  padding:var(--space-4);
  margin-bottom:var(--space-4);
}

.usuarios-header{
  display:grid;
  gap:var(--space-3);
}

.ux-actions-more summary{
  background:var(--color-surface-muted);
  border:1px solid var(--color-border);
  border-radius:var(--radius-md);
  min-height:40px;
  padding:0 12px;
}

.modal{
  z-index:220;
  background:rgba(15,23,42,0.54);
  padding:var(--space-5);
}

.modal-content{
  width:min(760px, 96vw);
  max-height:min(88vh, 860px);
  border-radius:var(--radius-lg);
  border:1px solid var(--color-border);
  box-shadow:0 24px 80px rgba(15,23,42,.22);
  padding:0;
  overflow:auto;
}

.modal-content > h3,
.modal-content > .modal-header{
  position:sticky;
  top:0;
  z-index:2;
  background:#fff;
  margin:0;
  padding:var(--space-4) var(--space-5);
  border-bottom:1px solid var(--color-border);
}

.modal-content > :not(h3):not(.modal-header){
  margin-left:var(--space-5);
  margin-right:var(--space-5);
}

.modal-content > :last-child{
  margin-bottom:var(--space-5);
}

.form-actions,
.modal-actions{
  position:sticky;
  bottom:0;
  background:#fff;
  border-top:1px solid var(--color-border);
  padding:var(--space-3) 0;
}

.erp-ui-tabs{
  display:flex;
  gap:6px;
  overflow:auto;
  padding:6px;
  margin:0 0 var(--space-4);
  border:1px solid var(--color-border);
  border-radius:var(--radius-lg);
  background:var(--color-surface);
  box-shadow:var(--shadow-sm);
}

.erp-ui-tab{
  border:0 !important;
  background:transparent !important;
  color:var(--color-text-muted) !important;
  min-height:36px !important;
  padding:0 12px !important;
  white-space:nowrap;
}

.erp-ui-tab[aria-selected="true"]{
  background:var(--color-primary-soft) !important;
  color:var(--color-primary) !important;
}

.erp-ui-tab-panel[hidden]{
  display:none !important;
}

@media (max-width: 1024px){
  #contentArea{ padding:var(--space-4); }
  .dashboard-grid-2{ grid-template-columns:1fr; }
  .topbar-subtitle{ display:none; }
}

@media (max-width: 760px){
  #contentArea{ padding:var(--space-3); }
  .topbar-right{ gap:6px; }
  #btnCmdK{ display:none !important; }
  .system-menu summary{ padding:0 10px; }
  .system-menu-panel{ right:-4px; }
  .usuarios-header,
  .checklist-header,
  .ops-toolbar,
  .ux-modulebar{ padding:var(--space-3); }
  .modal{ padding:var(--space-2); }
  .modal-content{ width:100%; max-height:94vh; }
}

@media (prefers-reduced-motion: reduce){
  *, *::before, *::after{
    animation-duration:.01ms !important;
    transition-duration:.01ms !important;
    scroll-behavior:auto !important;
  }
}

/* Login institucional sin modificar autenticación */
#loginScreen{
  min-height:100vh;
  display:grid;
  place-items:center;
  padding:var(--space-5);
  background:
    radial-gradient(circle at 18% 16%, rgba(15,61,117,.12), transparent 28%),
    linear-gradient(180deg, #f8fbff 0%, #eef5fb 100%);
}

/* Correccion UI: el login debe desaparecer por completo al iniciar sesion. */
#loginScreen.hidden,
#appScreen.hidden,
#userPortalScreen.hidden{
  display:none !important;
}

/* Portal usuario: version de consulta, separada del panel administrador */
#userPortalScreen{
  min-height:100vh;
  background:var(--color-background);
  color:var(--color-text);
}

.user-portal-header{
  min-height:72px;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:16px;
  padding:14px 22px;
  background:#fff;
  border-bottom:1px solid var(--color-border);
  position:sticky;
  top:0;
  z-index:20;
}

.user-portal-brand{
  display:flex;
  align-items:center;
  gap:12px;
}

.user-portal-brand img{
  width:88px;
  height:42px;
  object-fit:contain;
}

.user-portal-brand strong{
  display:block;
  font-size:16px;
}

.user-portal-brand span,
.user-portal-muted,
.user-portal-note{
  color:var(--color-text-muted);
}

.user-portal-header button{
  border:1px solid var(--color-border);
  border-radius:var(--radius-md);
  background:var(--color-surface-muted);
  padding:10px 12px;
  font-weight:900;
  cursor:pointer;
}

.user-portal-main{
  width:min(1120px, calc(100% - 32px));
  margin:0 auto;
  padding:28px 0 42px;
}

.user-portal-hero{
  display:flex;
  align-items:flex-start;
  justify-content:space-between;
  gap:16px;
  margin-bottom:18px;
}

.user-portal-hero h1{
  margin:0;
  font-size:28px;
  line-height:1.15;
}

.user-portal-hero p{
  margin:6px 0 0;
  color:var(--color-text-muted);
  font-weight:700;
}

.user-portal-pill{
  border:1px solid rgba(15,61,117,.18);
  background:var(--color-primary-soft);
  color:var(--color-primary);
  border-radius:999px;
  padding:8px 12px;
  font-weight:900;
  white-space:nowrap;
}

.user-portal-pill.error{
  border-color:rgba(194,65,12,.25);
  color:var(--color-danger);
  background:#fff7ed;
}

.user-portal-grid{
  display:grid;
  grid-template-columns:repeat(2, minmax(0, 1fr));
  gap:14px;
}

.user-portal-card{
  background:#fff;
  border:1px solid var(--color-border);
  border-radius:var(--radius-lg);
  box-shadow:var(--shadow-sm);
  padding:18px;
}

.user-portal-house{
  grid-column:1 / -1;
}

.user-portal-card h2{
  margin:0 0 12px;
  font-size:18px;
}

.user-portal-card-head{
  display:flex;
  align-items:flex-start;
  justify-content:space-between;
  gap:12px;
  margin-bottom:16px;
}

.user-portal-card-head span,
.user-portal-kpis span,
.user-portal-row span{
  display:block;
  color:var(--color-text-muted);
  font-size:12px;
  font-weight:800;
}

.user-portal-card-head strong{
  display:block;
  font-size:34px;
  line-height:1;
  margin-top:4px;
}

.user-portal-access{
  border-radius:999px;
  padding:8px 12px;
  font-weight:950;
  font-size:12px;
}

.user-portal-access.ok{
  color:#166534;
  background:#dcfce7;
}

.user-portal-access.warn{
  color:#92400e;
  background:#fef3c7;
}

.user-portal-kpis{
  display:grid;
  grid-template-columns:repeat(4, minmax(0, 1fr));
  gap:10px;
  margin-bottom:14px;
}

.user-portal-kpis div{
  border:1px solid var(--color-border);
  border-radius:var(--radius-md);
  padding:12px;
  background:var(--color-surface-muted);
}

.user-portal-kpis strong{
  display:block;
  margin-top:4px;
  font-size:20px;
}

.user-portal-detail{
  display:grid;
  grid-template-columns:repeat(2, minmax(0, 1fr));
  gap:10px;
  color:var(--color-text);
}

.user-portal-list{
  display:grid;
  gap:8px;
}

.user-portal-row{
  display:flex;
  justify-content:space-between;
  gap:12px;
  border-bottom:1px solid #eef2f7;
  padding:9px 0;
}

.user-portal-row:last-child{
  border-bottom:0;
}

.user-portal-row > div:last-child{
  text-align:right;
  flex:0 0 auto;
}

.user-portal-note{
  margin:14px 0 0;
  font-size:12px;
  line-height:1.4;
}

@media (max-width: 760px){
  .user-portal-header,
  .user-portal-hero{
    flex-direction:column;
    align-items:stretch;
  }
  .user-portal-grid,
  .user-portal-kpis,
  .user-portal-detail{
    grid-template-columns:1fr;
  }
  .user-portal-row{
    flex-direction:column;
  }
  .user-portal-row > div:last-child{
    text-align:left;
  }
}

.login-box{
  width:min(440px, 94vw) !important;
  border:1px solid var(--color-border);
  border-radius:22px !important;
  box-shadow:0 24px 80px rgba(15,23,42,.14) !important;
  padding:30px !important;
  background:#fff !important;
}

.login-box::before{
  content:"";
  display:block;
  width:180px;
  height:86px;
  margin:0 auto 14px;
  background:url("../ALBERCA.png") center / contain no-repeat;
}

.login-box h2{
  margin:0 0 6px;
  text-align:center;
  color:var(--color-text);
  font-size:23px;
  line-height:1.2;
}

.login-box p{
  text-align:center;
  color:var(--color-text-muted);
}

.login-box details{
  border:1px solid var(--color-border);
  border-radius:var(--radius-lg);
  padding:10px 12px;
  background:var(--color-surface-muted);
}

.login-box summary{
  color:var(--color-primary);
  outline:none;
}

.login-box button[onclick="login()"]{
  width:100%;
  margin-top:var(--space-3);
  min-height:44px;
  border-radius:var(--radius-md);
  background:var(--color-primary);
  color:#fff;
  border:1px solid var(--color-primary);
  font-weight:900;
}

.login-box .error{
  color:var(--color-danger);
  font-weight:800;
  min-height:20px;
}
