:root{
  --bg: #eef2f8;
  --text: #0f172a;
  --muted: #64748b;
  --card: #ffffff;
  --border: #d7deea;
  --primary: #1e88e5;
  --primary-2: #1666c7;
  --ok:#16a34a;
  --warn:#f59e0b;
  --danger:#ef4444;
  --radius-sm: 10px;
  --radius: 14px;
  --radius-lg: 18px;
  --shadow: 0 10px 30px rgba(2,12,27,.08);
  --shadow-strong: 0 16px 40px rgba(2,12,27,.12);
  color-scheme: light;
}

[data-theme="dark"]{
  --bg: #0b1222;
  --text: #e6eefc;
  --muted:#9fb1d0;
  --card:#121a2c;
  --border:#243455;
  --primary:#4aa3ff;
  --primary-2:#2f7ad9;
  --shadow: 0 10px 30px rgba(0,0,0,.35);
  --shadow-strong: 0 16px 40px rgba(0,0,0,.45);
  color-scheme: dark;
}

/* Reset y fuente */
*{box-sizing:border-box;}
html,body{min-height:100%;}
body{
  margin:0;
  background:
    radial-gradient(1000px 600px at 120% -10%, rgba(30,136,229,.08), transparent),
    radial-gradient(800px 500px at -10% -20%, rgba(30,136,229,.08), transparent),
    var(--bg);
  color:var(--text);
  font: 15px/1.5 "Inter", system-ui, -apple-system, Segoe UI, Roboto, Arial;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background .3s ease, color .3s ease;
}

h1,h2,h3{margin:0 0 8px;}
a{text-decoration:none; color:inherit;}
button,input,select{font:inherit; color:inherit;}
:focus-visible{
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  border-radius: 8px;
}

/* Botones generales */
.btn{
  border:1px solid var(--border);
  background:var(--card);
  padding:10px 14px;
  border-radius:var(--radius-sm);
  cursor:pointer;
  box-shadow: var(--shadow);
  transition: transform .1s ease, box-shadow .2s ease;
}

.btn:hover{
  transform: translateY(-1px);
  box-shadow: var(--shadow-strong);
}

.btn.primary{
  background:var(--primary);
  border-color:transparent;
  color:#fff;
}

.btn.primary:hover{ background:var(--primary-2); }
.btn.ghost{ background:transparent; box-shadow:none; }
.icon-btn{
  border:1px solid var(--border);
  background:var(--card);
  border-radius:12px;
  padding:8px 12px;
  cursor:pointer;
  box-shadow: var(--shadow);
}

/* Paneles & Cards */
.panel, .card{
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.panel{ padding:16px; }
.card{ padding:16px; }

/* KPI Cards */
.kpi{ display:flex; align-items:center; gap:12px; }
.kpi-icon{
  font-size:22px;
  display:grid;
  place-items:center;
  width:42px; height:42px;
  border-radius:12px;
  background: rgba(30,136,229,.12);
}
.kpi.warn .kpi-icon{ background: rgba(245,158,11,.15); }
.kpi.ok .kpi-icon{ background: rgba(22,163,74,.15); }
.kpi.danger .kpi-icon{ background: rgba(239,68,68,.15); }
.kpi-body h3{ font-size:14px; color:var(--muted); font-weight:600; }
.kpi-body p{ font-size:24px; font-weight:700; margin-top:2px; }

/* Navbar */
.navbar{
  position: sticky;
  top: 0;
  z-index: 5;
  display:flex;
  align-items:center;
  justify-content:space-between;
  background:var(--card);
  border:1px solid var(--border);
  border-radius:var(--radius);
  padding:10px 14px;
  box-shadow: var(--shadow);
  transition: box-shadow .2s ease;
}
.navbar.scrolled{ box-shadow: var(--shadow-strong); }

/* Sidebar (base) */
.sidebar{
  background:var(--card);
  border-right:1px solid var(--border);
  box-shadow: var(--shadow);
  display:flex;
  flex-direction:column;
  padding:16px 0;
  width:270px;
}

/* Enlaces Sidebar */
.sidebar nav{
  display:flex;
  flex-direction:column;
  gap:4px;
  margin-top:20px;
}
.sidebar nav a{
  padding:12px 20px;
  border-radius: var(--radius-sm);
  transition: background .2s ease, color .2s ease;
}
.sidebar nav a:hover{
  background: var(--primary);
  color:#fff;
}
.sidebar nav a.active{
  background: var(--primary);
  color:#fff;
  font-weight:600;
}

/* Chips */
.chip{
  display:inline-flex;
  align-items:center;
  gap:8px;
  padding:10px 12px;
  border-radius:999px;
  border:1px solid var(--border);
  background:var(--card);
  box-shadow: var(--shadow);
}
.chip:hover{
  border-color: var(--primary);
  color: var(--primary);
}

/* Tablas */
.table-wrap{
  overflow:auto;
  border:1px solid var(--border);
  border-radius:12px;
}
.table{
  width:100%;
  border-collapse:collapse;
}
.table th,.table td{
  padding:12px 14px;
  border-bottom:1px solid var(--border);
  white-space:nowrap;
}
.table thead th{
  position:sticky;
  top:0;
  background:var(--card);
  z-index:1;
}

/* Backdrop */
.backdrop{
  position: fixed;
  inset:0;
  background: rgba(0,0,0,.45);
  opacity:0;
  visibility:hidden;
  transition: opacity .2s ease;
  z-index: 50;
}
.backdrop.show{
  opacity:1;
  visibility:visible;
}

/* ===========================
   MODAL GENÉRICO
=========================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  display: none;
  place-items: center;
  z-index: 50;
}
.modal-backdrop.show { display: grid; }
.modal {
  width: min(520px, 92vw);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-strong);
  padding: 18px;
  animation: modalfade .18s ease-out;
}
@keyframes modalfade {
  from { transform: translateY(6px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
.modal-head {
  display:flex;
  justify-content:space-between;
  align-items:center;
  margin-bottom:10px;
}
.modal-body { display:grid; gap:12px; }
.modal-actions {
  display:flex;
  justify-content:flex-end;
  gap:8px;
  margin-top:14px;
}
.btn.danger {
  background: var(--danger);
  border-color: transparent;
  color:#fff;
}
.btn.danger:hover {
  filter: brightness(0.95);
}

/* ===========================
   SIDEBAR RESPONSIVE (MÓVIL)
=========================== */

/* Móvil: oculto inicialmente */
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 270px;
  transform: translateX(-100%);
  transition: transform .25s ease;
  z-index: 60;
}
.sidebar.show{
  transform: translateX(0);
}

/* Escritorio: sidebar siempre visible */
@media (min-width:960px){
  .sidebar{
    position: fixed;
    transform: none;
  }
}

/* Separar contenido del sidebar en escritorio */
@media (min-width:960px){
  .main{
    margin-left: 290px;
  }
}

/* Compatibilidad accesibilidad */
@media (prefers-reduced-motion: reduce){
  *{
    transition:none !important;
    animation:none !important;
  }
}
