/* Kontrol — estilos de la plataforma y componentes compartidos por los módulos */
:root {
  --bg: #f3f5f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --surface-3: #eef2f7;
  --text: #0f172a;
  --text-2: #334155;
  --muted: #64748b;
  --border: #e2e8f0;
  --border-2: #cbd5e1;
  --brand: #0f2744;
  --brand-2: #173a63;
  --on-brand: #ffffff;
  --on-brand-muted: rgba(255,255,255,.66);
  --primary: #2457c5;
  --primary-hover: #1c46a1;
  --primary-soft: #e8effc;
  --on-primary: #ffffff;
  --success: #047857;  --success-soft: #d1fae5;
  --warning: #b45309;  --warning-soft: #fef3c7;
  --danger: #c02626;   --danger-soft: #fee2e2;
  --accent: #10b981;
  --shadow: 0 1px 3px rgba(15,23,42,.06), 0 8px 24px rgba(15,23,42,.05);
  --shadow-lg: 0 24px 60px rgba(15,23,42,.28);
  --r: 14px;
  --r-sm: 9px;
  --sidebar: 252px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a1120;
    --surface: #111a2c;
    --surface-2: #142036;
    --surface-3: #1a2740;
    --text: #e6edf7;
    --text-2: #c4cfdf;
    --muted: #8fa0b8;
    --border: #22314d;
    --border-2: #2f4266;
    --brand: #0b1a30;
    --brand-2: #102341;
    --primary: #3d73e8;
    --primary-hover: #5584ee;
    --primary-soft: #1a2b4f;
    --success: #34d399;  --success-soft: #0f3328;
    --warning: #fbbf24;  --warning-soft: #3a2a0b;
    --danger: #f87171;   --danger-soft: #3d1518;
    --shadow: 0 1px 2px rgba(0,0,0,.4);
    --shadow-lg: 0 24px 60px rgba(0,0,0,.6);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.5 Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
.i { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.money { font-variant-numeric: tabular-nums; }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: inherit; font-weight: 600; font-size: 14px; cursor: pointer; text-decoration: none;
  border-radius: var(--r-sm); padding: 9px 16px; min-height: 40px;
  border: 1px solid var(--border-2); background: var(--surface); color: var(--text);
  transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--surface-3); }
.btn:focus-visible, .icon-btn:focus-visible, .tab:focus-visible, .nav a:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.btn:disabled { opacity: .6; cursor: progress; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); box-shadow: 0 1px 2px rgba(36,87,197,.3); }
.btn.primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn.ghost:hover { background: var(--surface-3); }
.btn.sm { padding: 5px 10px; min-height: 32px; font-size: 13px; }
.btn.success { color: var(--success); }
.icon-btn {
  display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: var(--r-sm);
  border: none; background: transparent; color: var(--muted); cursor: pointer; flex: none;
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); }
.icon-btn.danger:hover { color: var(--danger); background: var(--danger-soft); }
.link { background: none; border: none; padding: 0; font: inherit; font-weight: 600; color: var(--text); cursor: pointer; text-align: left; }
.link:hover { color: var(--primary); text-decoration: underline; }

/* ---------- Estructura: menú lateral + cuerpo ---------- */
.shell { display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column;
  background: linear-gradient(180deg, var(--brand) 0%, var(--brand-2) 100%); color: var(--on-brand);
  padding: calc(18px + env(safe-area-inset-top)) 14px 16px;
}
.sb-marca { display: flex; align-items: center; gap: 11px; padding: 2px 8px 22px; }
.sb-marca img { width: 38px; height: 38px; border-radius: 10px; }
.sb-marca b { display: block; font-size: 18px; letter-spacing: -.02em; line-height: 1.2; }
.sb-marca span { display: block; font-size: 12px; color: var(--on-brand-muted); }
.sb-tit { font-size: 11px; font-weight: 600; letter-spacing: .09em; text-transform: uppercase; color: var(--on-brand-muted); padding: 6px 12px 8px; }
.nav { display: grid; gap: 4px; }
.nav a {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px;
  color: rgba(255,255,255,.8); text-decoration: none; font-weight: 600; font-size: 14.5px;
}
.nav a small { display: block; font-size: 12px; font-weight: 400; color: var(--on-brand-muted); }
.nav a:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav a.activo { background: rgba(255,255,255,.13); color: #fff; box-shadow: inset 3px 0 0 var(--accent); }
.nav a .i { width: 20px; height: 20px; }
.sb-nota { margin: 14px 12px 0; font-size: 12px; color: var(--on-brand-muted); line-height: 1.4; }
.sb-pie { margin-top: auto; padding: 12px; border-top: 1px solid rgba(255,255,255,.1); font-size: 12px; color: var(--on-brand-muted); }
.velo { position: fixed; inset: 0; background: rgba(10,17,32,.5); z-index: 55; }

.cuerpo { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  --tb-fg: var(--text); --tb-muted: var(--muted); --tb-chip: var(--surface-2); --tb-chip-b: var(--border-2); --tb-hover: var(--surface-3);
  position: sticky; top: 0; z-index: 40; background: var(--surface); color: var(--tb-fg);
  border-bottom: 1px solid var(--border); padding-top: env(safe-area-inset-top);
}
.topbar-in { display: flex; align-items: center; gap: 10px; padding: 10px 28px; min-height: 62px; }
.tb-titulo { margin-right: auto; min-width: 0; font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tb-titulo span { color: var(--tb-muted); font-weight: 500; }
.topbar .icon-btn { color: var(--tb-fg); }
.topbar .icon-btn:hover { background: var(--tb-hover); }
#btnNav { display: none; }
.chip-tasa {
  display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font: inherit; font-size: 13px; font-weight: 600;
  color: var(--tb-fg); background: var(--tb-chip); border: 1px solid var(--tb-chip-b);
  border-radius: 999px; padding: 6px 12px; white-space: nowrap; font-variant-numeric: tabular-nums;
}
.chip-tasa:hover { background: var(--tb-hover); }
.chip-tasa small { color: var(--tb-muted); font-weight: 500; }
.chip-tasa.vieja { border-color: var(--warning); }
.chip-tasa.vieja small { color: var(--warning); }
.conexion { width: 9px; height: 9px; border-radius: 50%; background: #10b981; box-shadow: 0 0 0 3px rgba(16,185,129,.2); flex: none; }
.conexion.off { background: #ef4444; box-shadow: 0 0 0 3px rgba(239,68,68,.2); }

.menu-wrap { position: relative; }
.menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 50; min-width: 250px;
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: var(--shadow-lg); padding: 6px;
}
.menu button {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; font: inherit; font-size: 14px;
  background: none; border: none; color: var(--text); padding: 9px 10px; border-radius: 8px; cursor: pointer;
}
.menu button:hover { background: var(--surface-3); }
.menu button .i { color: var(--muted); }
.menu hr { border: none; border-top: 1px solid var(--border); margin: 6px 4px; }
.menu .peligro, .menu .peligro .i { color: var(--danger); }

main { width: 100%; max-width: 1240px; margin: 0 auto; padding: 24px 28px 100px; }

/* ---------- Componentes de página ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.page-head h1 { margin: 0; font-size: 25px; letter-spacing: -.02em; }
.page-head p { margin: 2px 0 0; color: var(--muted); font-size: 14px; }
.aviso-banda {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; margin-bottom: 16px;
  background: var(--primary-soft); border: 1px solid var(--border); border-left: 4px solid var(--primary);
  border-radius: var(--r-sm); padding: 12px 14px; font-size: 14px;
}
.aviso-banda span { flex: 1 1 260px; }

.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 20px; }
.kpi {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r);
  padding: 16px 18px; box-shadow: var(--shadow); display: flex; gap: 14px; align-items: flex-start; min-width: 0;
}
.kpi-ico { width: 42px; height: 42px; border-radius: 11px; display: grid; place-items: center; flex: none; }
.kpi-ico .i { width: 21px; height: 21px; }
.kpi.azul .kpi-ico { background: var(--primary-soft); color: var(--primary); }
.kpi.verde .kpi-ico { background: var(--success-soft); color: var(--success); }
.kpi.rojo .kpi-ico { background: var(--danger-soft); color: var(--danger); }
.kpi.ambar .kpi-ico { background: var(--warning-soft); color: var(--warning); }
.kpi .lbl { font-size: 13px; color: var(--muted); font-weight: 500; }
.kpi .val { font-size: 24px; font-weight: 700; letter-spacing: -.02em; line-height: 1.25; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.kpi .sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.kpi.rojo .val { color: var(--danger); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); box-shadow: var(--shadow); overflow: hidden; }
.tabs { display: flex; gap: 2px; padding: 0 12px; border-bottom: 1px solid var(--border); overflow-x: auto; }
.tab {
  font: inherit; font-weight: 600; font-size: 14px; color: var(--muted); background: none; cursor: pointer;
  border: none; border-bottom: 2px solid transparent; padding: 14px 12px 12px; white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 12px; border-bottom: 1px solid var(--border); background: var(--surface-2); }
.buscar { position: relative; flex: 1 1 220px; }
.buscar .i { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); width: 17px; height: 17px; }
.buscar input { padding-left: 36px; }

input, select, textarea {
  font: inherit; font-size: 14px; color: var(--text); background: var(--surface);
  border: 1px solid var(--border-2); border-radius: var(--r-sm); padding: 9px 11px; width: 100%; min-height: 40px;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.toolbar select, .toolbar input[type=month] { width: auto; }

/* ---------- Tablas ---------- */
.table-wrap { overflow-x: auto; }
.tabla { width: 100%; border-collapse: collapse; font-size: 14px; }
.tabla th, .tabla td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tabla th { font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); background: var(--surface-2); white-space: nowrap; }
.tabla td.num, .tabla th.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.tabla tbody tr:hover { background: var(--surface-2); }
.tabla tfoot td { font-weight: 700; background: var(--surface-3); border-bottom: none; }
.tabla .sec { display: block; color: var(--muted); font-size: 12.5px; font-weight: 400; }
.tabla .debe { color: var(--danger); font-weight: 600; }
.acciones { display: flex; gap: 4px; justify-content: flex-end; align-items: center; }
.vacio { padding: 56px 16px; text-align: center; color: var(--muted); }
.vacio > .i { width: 40px; height: 40px; stroke-width: 1.5; margin-bottom: 8px; color: var(--border-2); }

.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 999px; white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.b-verde { color: var(--success); background: var(--success-soft); }
.b-ambar { color: var(--warning); background: var(--warning-soft); }
.b-rojo { color: var(--danger); background: var(--danger-soft); }

/* ---------- Diálogos ---------- */
dialog {
  border: 1px solid var(--border); border-radius: 16px; padding: 0; width: min(560px, calc(100vw - 24px));
  background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg);
}
dialog::backdrop { background: rgba(10,17,32,.55); backdrop-filter: blur(2px); }
.dlg-head { padding: 18px 20px 14px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.dlg-head h2 { margin: 0; font-size: 18px; letter-spacing: -.01em; }
.dlg-head p { margin: 2px 0 0; color: var(--muted); font-size: 13.5px; }
.dlg-body { padding: 18px 20px; max-height: min(68vh, 640px); overflow-y: auto; }
.dlg-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; background: var(--surface-2); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; min-width: 0; }
.field > label { font-size: 13px; color: var(--text-2); font-weight: 600; }
.field.full { grid-column: 1 / -1; }
.hint { font-size: 12.5px; color: var(--muted); }
.hint:empty { display: none; }
.combo { display: flex; gap: 6px; }
.combo select { width: 76px; flex: none; }
.err { color: var(--danger); font-size: 13.5px; font-weight: 500; margin: 0; }
.err:empty { display: none; }
.resumen { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 18px; }
.resumen div { background: var(--surface-3); border-radius: 10px; padding: 10px 12px; font-size: 12.5px; color: var(--muted); }
.resumen b { display: block; font-size: 17px; color: var(--text); font-variant-numeric: tabular-nums; }
.resumen small { display: block; }
.sub-tit { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 6px 0 8px; }
.lista { list-style: none; padding: 0; margin: 0; border: 1px solid var(--border); border-radius: 10px; }
.lista li { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--border); font-size: 14px; }
.lista li:last-child { border-bottom: none; }
.lista .det { display: block; color: var(--muted); font-size: 12.5px; }
.tasas-lista { display: grid; gap: 8px; margin-top: 12px; }
.tasa-op { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; }
.tasa-op b { font-size: 17px; font-variant-numeric: tabular-nums; }

/* ---------- Entrada ---------- */
.login {
  min-height: 100vh; display: grid; place-items: center; padding: 24px 16px;
  background: radial-gradient(1200px 600px at 10% -10%, #24508a 0%, transparent 60%), linear-gradient(140deg, #0b1d36, #0f2744 55%, #173a63);
}
.login-card { width: min(400px, 100%); background: var(--surface); border-radius: 18px; padding: 30px 26px; box-shadow: var(--shadow-lg); }
.login-card img { width: 56px; height: 56px; border-radius: 14px; }
.login-card h1 { font-size: 24px; margin: 14px 0 2px; letter-spacing: -.02em; }
.login-card p { margin: 0 0 20px; color: var(--muted); font-size: 14px; }
.login-card .btn { width: 100%; margin-top: 12px; }

/* ---------- Avisos y botón flotante ---------- */
.toasts { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 100; display: grid; gap: 8px; width: min(420px, calc(100vw - 32px)); }
.toast { background: #0f172a; color: #fff; padding: 12px 16px; border-radius: 10px; box-shadow: var(--shadow-lg); font-size: 14px; border-left: 4px solid #34d399; animation: entra .2s ease-out; }
.toast.error { border-left-color: #f87171; }
@keyframes entra { from { opacity: 0; transform: translateY(8px); } }
.fab {
  display: none; position: fixed; right: 18px; bottom: calc(18px + env(safe-area-inset-bottom)); z-index: 30;
  width: 58px; height: 58px; border-radius: 50%; border: none; cursor: pointer;
  background: var(--primary); color: #fff; box-shadow: 0 10px 24px rgba(36,87,197,.45); place-items: center;
}
.fab .i { width: 26px; height: 26px; }
.pie { color: var(--muted); font-size: 12.5px; margin-top: 14px; }

/* ---------- Tableta y celular ---------- */
@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; width: 280px; height: auto; z-index: 60;
    transform: translateX(-100%); transition: transform .22s ease; box-shadow: var(--shadow-lg);
  }
  .shell.nav-abierta .sidebar { transform: none; }
  #btnNav { display: inline-grid; }
  .topbar {
    --tb-fg: #fff; --tb-muted: rgba(255,255,255,.7); --tb-chip: rgba(255,255,255,.1); --tb-chip-b: rgba(255,255,255,.2); --tb-hover: rgba(255,255,255,.14);
    background: linear-gradient(120deg, var(--brand), var(--brand-2)); border-bottom: none;
  }
  .chip-tasa.vieja { border-color: #fbbf24; }
  .chip-tasa.vieja small { color: #fcd34d; }
  .topbar-in { padding: 8px 12px; min-height: 56px; gap: 6px; }
  main { padding: 18px 16px 100px; }
}
@media (max-width: 720px) {
  .tb-titulo span, .chip-tasa .txt-tasa { display: none; }
  .page-head .btn { display: none; }
  .page-head h1 { font-size: 22px; }
  .fab { display: grid; }
  .kpis { gap: 10px; }
  .kpi { padding: 12px; gap: 10px; flex-direction: column; }
  .kpi-ico { width: 34px; height: 34px; border-radius: 9px; }
  .kpi .val { font-size: 19px; }
  .grid2 { grid-template-columns: 1fr; }
  .toolbar select, .toolbar input[type=month] { flex: 1 1 140px; }
  .tabla thead { display: none; }
  .tabla, .tabla tbody, .tabla tfoot, .tabla tr, .tabla td { display: block; width: 100%; }
  .tabla tbody tr, .tabla tfoot tr {
    width: auto; margin: 10px; padding: 12px 14px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface);
  }
  .tabla tfoot tr { background: var(--surface-3); }
  .tabla td, .tabla tfoot td { border: none; padding: 3px 0; display: flex; justify-content: space-between; align-items: baseline; gap: 12px; text-align: right; background: none; }
  .tabla td::before { content: attr(data-label); color: var(--muted); font-size: 13px; font-weight: 500; text-align: left; flex: none; }
  .tabla td.principal { display: block; text-align: left; font-size: 15.5px; padding-bottom: 6px; }
  .tabla td.principal::before, .tabla td.acc::before { content: none; }
  .tabla td.vacia { display: none; }
  .tabla td.acc { padding-top: 10px; margin-top: 8px; border-top: 1px solid var(--border); }
  .tabla td.acc .acciones { width: 100%; justify-content: flex-end; }
  .tabla td.acc:empty { display: none; }
  dialog { margin: auto auto 0; width: 100vw; max-width: 100vw; border-radius: 18px 18px 0 0; padding-bottom: env(safe-area-inset-bottom); }
  .dlg-body { max-height: 70vh; }
}
@media print {
  .sidebar, .topbar, .toolbar, .tabs, .acc, .fab, .page-head .btn, .pie, .aviso-banda, .toasts { display: none !important; }
  .shell { display: block; }
  body { background: #fff; color: #000; }
  .card, .kpi { box-shadow: none; }
  main { padding: 0; }
}
