@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&family=JetBrains+Mono:wght@400;700&display=swap');

/* ── Variables de tema ───────────────────────────────────────── */
:root {
  --bg0: #0f1117;
  --bg1: #161b27;
  --bg2: #1e2533;
  --bg3: #252d3d;
  --txt0: #e2e8f0;
  --txt1: #94a3b8;
  --txt2: #4a5568;
  --border: #1e2533;
  --border2: #2d3748;
  --green: #22c55e;
  --green-bg: #0f2d1a;
  --green-border: #14532d;
  --amber: #f59e0b;
  --amber-bg: #2d2010;
  --amber-border: #78350f;
  --blue: #60a5fa;
  --blue-bg: #1e2d45;
  --blue-border: #1e3a5f;
  --red: #f87171;
  --red-bg: #2d1010;
  --red-border: #7f1d1d;
  --mono: 'JetBrains Mono', monospace;
  --sans: 'Inter', system-ui, sans-serif;
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --sidebar-w: 210px;
  --topbar-h: 52px;
  --trans: 0.2s ease;
}

[data-theme="light"] {
  --bg0: #f1f5f9;
  --bg1: #ffffff;
  --bg2: #f8fafc;
  --bg3: #e2e8f0;
  --txt0: #0f172a;
  --txt1: #475569;
  --txt2: #94a3b8;
  --border: #e2e8f0;
  --border2: #cbd5e1;
  --green: #16a34a;
  --green-bg: #f0fdf4;
  --green-border: #bbf7d0;
  --amber: #d97706;
  --amber-bg: #fffbeb;
  --amber-border: #fde68a;
  --blue: #2563eb;
  --blue-bg: #eff6ff;
  --blue-border: #bfdbfe;
  --red: #dc2626;
  --red-bg: #fef2f2;
  --red-border: #fecaca;
}

/* ── Reset y base ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { height: 100%; }

body {
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  color: var(--txt0);
  background: var(--bg0);
  height: 100%;
  overflow: hidden;
  transition: background var(--trans), color var(--trans);
}

/* ── Layout principal ─────────────────────────────────────────── */
#app { display: flex; flex-direction: column; height: 100vh; }

/* Topbar */
.topbar {
  height: var(--topbar-h);
  background: var(--bg1);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  flex-shrink: 0;
  z-index: 100;
  transition: background var(--trans), border-color var(--trans);
}

.logo {
  font-family: var(--mono);
  font-size: 15px;
  font-weight: 700;
  color: var(--txt0);
  letter-spacing: .1em;
  user-select: none;
}
.logo em { color: var(--blue); font-style: normal; }

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

/* Botón toggle tema */
.theme-toggle {
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: 20px;
  padding: 4px 12px;
  font-size: 11px;
  font-weight: 600;
  color: var(--txt1);
  cursor: pointer;
  transition: all var(--trans);
  font-family: var(--sans);
}
.theme-toggle:hover { background: var(--bg3); color: var(--txt0); }

/* Pill de usuario */
.user-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: 20px;
  padding: 4px 12px 4px 6px;
  cursor: pointer;
  transition: background var(--trans);
}
.user-pill:hover { background: var(--bg3); }

.avatar {
  width: 26px; height: 26px;
  border-radius: 50%;
  background: var(--blue-bg);
  border: 1px solid var(--blue-border);
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 700;
  color: var(--blue);
  font-family: var(--mono);
}

.user-info { display: flex; flex-direction: column; }
.user-name { font-size: 12px; font-weight: 600; color: var(--txt0); line-height: 1.2; }
.user-role { font-size: 10px; color: var(--txt2); line-height: 1.2; }

/* Layout de contenido */
.content-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg1);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  flex-shrink: 0;
  padding: 12px 0;
  transition: background var(--trans), border-color var(--trans);
}

.nav-section { margin-bottom: 4px; }

.nav-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--txt2);
  letter-spacing: .1em;
  text-transform: uppercase;
  padding: 10px 18px 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 10px 7px 14px;
  margin: 1px 8px;
  border-radius: var(--radius-md);
  font-size: 13px;
  color: var(--txt1);
  cursor: pointer;
  transition: background var(--trans), color var(--trans);
  text-decoration: none;
  user-select: none;
}
.nav-item:hover { background: var(--bg2); color: var(--txt0); }
.nav-item.active { background: var(--blue-bg); color: var(--blue); font-weight: 500; }
.nav-item svg { width: 15px; height: 15px; flex-shrink: 0; }

.nav-badge {
  margin-left: auto;
  background: var(--amber-bg);
  color: var(--amber);
  border-radius: 10px;
  padding: 1px 7px;
  font-size: 10px;
  font-weight: 700;
  font-family: var(--mono);
}

/* Área principal */
.main {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  background: var(--bg0);
  transition: background var(--trans);
}

/* ── Componentes de página ────────────────────────────────────── */

.page-header { margin-bottom: 20px; }
.page-title { font-size: 20px; font-weight: 600; color: var(--txt0); }
.page-sub { font-size: 12px; color: var(--txt2); margin-top: 3px; }

/* KPI cards */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}

.kpi {
  background: var(--bg1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  transition: background var(--trans), border-color var(--trans);
}
.kpi-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--txt2);
  text-transform: uppercase;
  letter-spacing: .07em;
  margin-bottom: 8px;
}
.kpi-value {
  font-size: 22px;
  font-weight: 700;
  font-family: var(--mono);
  line-height: 1;
}
.kpi-note { font-size: 11px; color: var(--txt2); margin-top: 5px; }

/* Cards */
.card {
  background: var(--bg1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  margin-bottom: 14px;
  transition: background var(--trans), border-color var(--trans);
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.card-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--txt1);
  text-transform: uppercase;
  letter-spacing: .08em;
}

/* Grid 2 columnas */
.grid-2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 14px; margin-bottom: 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-bottom: 14px; }

/* ── Tablas ───────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
th {
  text-align: left;
  font-size: 10px;
  font-weight: 600;
  color: var(--txt2);
  text-transform: uppercase;
  letter-spacing: .07em;
  padding: 0 12px 10px 0;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
td {
  padding: 10px 12px 10px 0;
  border-bottom: 1px solid var(--border);
  color: var(--txt1);
  vertical-align: middle;
}
td:first-child { color: var(--txt0); font-weight: 500; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--bg2); }

.mono { font-family: var(--mono); }

/* ── Badges ───────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .04em;
  white-space: nowrap;
}
.badge-green  { background: var(--green-bg);  color: var(--green);  border: 1px solid var(--green-border); }
.badge-amber  { background: var(--amber-bg);  color: var(--amber);  border: 1px solid var(--amber-border); }
.badge-blue   { background: var(--blue-bg);   color: var(--blue);   border: 1px solid var(--blue-border); }
.badge-red    { background: var(--red-bg);    color: var(--red);    border: 1px solid var(--red-border); }
.badge-gray   { background: var(--bg2);       color: var(--txt1);   border: 1px solid var(--border2); }

/* ── Botones ──────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius-md);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--border2);
  background: var(--bg2);
  color: var(--txt0);
  font-family: var(--sans);
  transition: all var(--trans);
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { background: var(--bg3); }
.btn:active { transform: scale(.98); }

.btn-primary {
  background: var(--blue-bg);
  border-color: var(--blue-border);
  color: var(--blue);
}
.btn-primary:hover { background: var(--blue-border); }

.btn-success {
  background: var(--green-bg);
  border-color: var(--green-border);
  color: var(--green);
}

.btn-danger {
  background: var(--red-bg);
  border-color: var(--red-border);
  color: var(--red);
}

.btn-sm { padding: 4px 10px; font-size: 11px; }
.btn-lg { padding: 10px 20px; font-size: 14px; }

.btn-icon {
  width: 28px; height: 28px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* ── Formularios ──────────────────────────────────────────────── */
.form-group { margin-bottom: 14px; }
.form-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--txt1);
  margin-bottom: 5px;
  text-transform: uppercase;
  letter-spacing: .05em;
}
.form-control {
  width: 100%;
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: var(--radius-md);
  padding: 8px 12px;
  font-size: 13px;
  color: var(--txt0);
  font-family: var(--sans);
  transition: border-color var(--trans), background var(--trans);
  outline: none;
}
.form-control:focus {
  border-color: var(--blue);
  background: var(--bg1);
}
.form-control::placeholder { color: var(--txt2); }

select.form-control { cursor: pointer; }
textarea.form-control { resize: vertical; min-height: 80px; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }

/* ── Modal ────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(2px);
}
.modal {
  background: var(--bg1);
  border: 1px solid var(--border2);
  border-radius: var(--radius-lg);
  width: min(520px, 94vw);
  max-height: 88vh;
  overflow-y: auto;
  padding: 24px;
  transition: background var(--trans);
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px;
}
.modal-title { font-size: 16px; font-weight: 600; color: var(--txt0); }
.modal-close {
  width: 28px; height: 28px;
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--txt1);
  font-size: 16px;
  line-height: 1;
}
.modal-footer {
  display: flex; gap: 8px; justify-content: flex-end;
  margin-top: 20px; padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* ── Avisos/notificaciones ────────────────────────────────────── */
.aviso-card {
  padding: 12px 16px;
  border-left: 3px solid var(--blue);
  background: var(--blue-bg);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  margin-bottom: 10px;
}
.aviso-card.warning { border-left-color: var(--amber); background: var(--amber-bg); }
.aviso-card.success { border-left-color: var(--green); background: var(--green-bg); }
.aviso-title { font-size: 13px; font-weight: 600; color: var(--txt0); }
.aviso-meta  { font-size: 11px; color: var(--txt2); margin-top: 2px; }
.aviso-body  { font-size: 12px; color: var(--txt1); margin-top: 6px; line-height: 1.6; }

/* ── Toast ────────────────────────────────────────────────────── */
#toast-container {
  position: fixed; bottom: 20px; right: 20px;
  display: flex; flex-direction: column; gap: 8px;
  z-index: 9999;
}
.toast {
  background: var(--bg1);
  border: 1px solid var(--border2);
  border-radius: var(--radius-md);
  padding: 10px 16px;
  font-size: 13px;
  color: var(--txt0);
  min-width: 220px;
  box-shadow: 0 4px 16px rgba(0,0,0,.4);
  animation: toastIn .2s ease;
}
.toast.success { border-left: 3px solid var(--green); }
.toast.error   { border-left: 3px solid var(--red); }
.toast.info    { border-left: 3px solid var(--blue); }
@keyframes toastIn { from { opacity:0; transform:translateY(8px); } to { opacity:1; transform:none; } }

/* ── Gauge semicircular ───────────────────────────────────────── */
.gauge-wrap { display: flex; flex-direction: column; align-items: center; justify-content: center; }
.gauge-value { font-size: 28px; font-weight: 700; font-family: var(--mono); color: var(--green); margin-top: 6px; }
.gauge-label { font-size: 11px; color: var(--txt2); margin-top: 2px; }

/* ── Barra de progreso ────────────────────────────────────────── */
.bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.bar-key { font-size: 12px; color: var(--txt1); font-family: var(--mono); width: 36px; text-align: right; }
.bar-track { flex: 1; height: 7px; background: var(--bg2); border-radius: 4px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 4px; transition: width .6s ease; }
.bar-amount { font-size: 11px; color: var(--txt1); font-family: var(--mono); width: 64px; text-align: right; white-space: nowrap; }

/* ── Estado vacío ─────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--txt2);
}
.empty-icon { font-size: 32px; margin-bottom: 10px; opacity: .4; }
.empty-msg  { font-size: 13px; }

/* ── Paginación ───────────────────────────────────────────────── */
.pagination {
  display: flex; align-items: center; gap: 6px;
  margin-top: 14px; justify-content: flex-end;
}
.page-btn {
  width: 30px; height: 30px;
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  font-size: 12px; font-weight: 600;
  color: var(--txt1);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all var(--trans);
}
.page-btn:hover { background: var(--bg3); color: var(--txt0); }
.page-btn.active { background: var(--blue-bg); border-color: var(--blue-border); color: var(--blue); }

/* ── Login page ───────────────────────────────────────────────── */
.login-wrap {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg0);
  padding: 20px;
  transition: background var(--trans);
}
.login-card {
  background: var(--bg1);
  border: 1px solid var(--border2);
  border-radius: var(--radius-lg);
  padding: 36px 32px;
  width: min(380px, 100%);
}
.login-logo {
  font-family: var(--mono);
  font-size: 22px;
  font-weight: 700;
  color: var(--txt0);
  letter-spacing: .1em;
  text-align: center;
  margin-bottom: 6px;
}
.login-logo em { color: var(--blue); font-style: normal; }
.login-sub { font-size: 12px; color: var(--txt2); text-align: center; margin-bottom: 28px; }
.login-error {
  background: var(--red-bg);
  border: 1px solid var(--red-border);
  border-radius: var(--radius-md);
  color: var(--red);
  font-size: 12px;
  padding: 8px 12px;
  margin-bottom: 14px;
  display: none;
}

/* ── Separador ────────────────────────────────────────────────── */
.sep { border: none; border-top: 1px solid var(--border); margin: 16px 0; }

/* ── Loading spinner ──────────────────────────────────────────── */
.spinner {
  width: 18px; height: 18px;
  border: 2px solid var(--border2);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-overlay {
  display: flex; align-items: center; justify-content: center;
  padding: 40px;
}

/* ── Color helpers ────────────────────────────────────────────── */
.text-green { color: var(--green); }
.text-amber { color: var(--amber); }
.text-blue  { color: var(--blue); }
.text-red   { color: var(--red); }
.text-muted { color: var(--txt2); }

/* ── Scroll styling ───────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--txt2); }

/* ── Responsive básico ────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar { display: none; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
}
