/* =====================================================================
   TU SYSTEM — Sistema de diseño
   Azul tecnológico · Rojo intenso · Blanco · Azul oscuro
   ===================================================================== */
:root {
  --brand: #0b5cff; --brand-600: #0848c9; --brand-50: #eaf1ff;
  --red: #e3122d; --red-600: #b80d23; --red-50: #fdecee;
  --navy: #07112b; --navy-2: #0c1a3f; --navy-3: #132552;
  --ok: #0f9d58; --ok-50: #e7f6ee; --warn: #d98a00; --warn-50: #fff5e0;
  --bg: #f3f6fb; --surface: #ffffff; --surface-2: #f7f9fc; --border: #e1e7f0;
  --text: #0e1830; --muted: #5d6b85; --shadow: 0 1px 2px rgba(10,25,60,.06), 0 4px 16px rgba(10,25,60,.06);
  --radius: 14px; --radius-sm: 10px;
  --sidebar: 248px; --topbar: 60px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #060d22; --surface: #0c1735; --surface-2: #101e44; --border: #1d2d5a;
  --text: #e8eeff; --muted: #93a2c4; --brand-50: #10245a; --red-50: #3a0d18; --ok-50: #0b2e22; --warn-50: #33260a;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.25);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #060d22; --surface: #0c1735; --surface-2: #101e44; --border: #1d2d5a;
    --text: #e8eeff; --muted: #93a2c4; --brand-50: #10245a; --red-50: #3a0d18; --ok-50: #0b2e22; --warn-50: #33260a;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.25);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body { font-family: var(--font); background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.45; -webkit-font-smoothing: antialiased; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 .5em; line-height: 1.2; letter-spacing: -.01em; }
h1 { font-size: 1.45rem; } h2 { font-size: 1.15rem; } h3 { font-size: 1rem; }
img { max-width: 100%; }
small, .muted { color: var(--muted); }
.mono, .num { font-variant-numeric: tabular-nums; }
hr { border: 0; border-top: 1px solid var(--border); margin: 16px 0; }

/* ---------- Layout del panel ---------- */
.app { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }
.sidebar { background: linear-gradient(180deg, var(--navy) 0%, var(--navy-2) 100%); color: #cfd9f5; position: sticky; top: 0; height: 100vh; overflow-y: auto; padding: 14px 12px 24px; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 16px; color: #fff; }
.brand img { width: 40px; height: 40px; border-radius: 10px; }
.brand b { font-size: 1.05rem; letter-spacing: .02em; }
.brand b span { color: var(--red); }
.brand small { display: block; color: #8fa2d8; font-size: .72rem; }
.nav-group { margin: 14px 8px 6px; font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; color: #7084bd; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 10px; color: #cfd9f5; font-weight: 500; font-size: .93rem; }
.nav a:hover { background: rgba(255,255,255,.06); text-decoration: none; color: #fff; }
.nav a.active { background: linear-gradient(90deg, var(--brand), #2b74ff); color: #fff; box-shadow: 0 6px 18px rgba(11,92,255,.35); }
.nav svg { width: 18px; height: 18px; flex: 0 0 18px; opacity: .9; }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { height: var(--topbar); display: flex; align-items: center; gap: 12px; padding: 0 22px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
.topbar .spacer { flex: 1; }
.topbar select { max-width: 200px; }
.content { padding: 22px; max-width: 1400px; width: 100%; margin: 0 auto; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h1 { margin: 0; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.icon-btn { background: none; border: 1px solid var(--border); color: var(--text); width: 38px; height: 38px; border-radius: 10px; display: inline-grid; place-items: center; cursor: pointer; position: relative; }
.icon-btn svg { width: 18px; height: 18px; }
.badge-dot { position: absolute; top: -4px; right: -4px; background: var(--red); color: #fff; border-radius: 999px; font-size: .65rem; padding: 1px 5px; font-weight: 700; }
.menu-toggle { display: none; }
.bottom-nav { display: none; }

/* ---------- Componentes ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.card + .card { margin-top: 16px; }
.grid > .card + .card, .grid > div > .card:first-child { margin-top: 0; }
.card h2 { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0,1fr)); } .g3 { grid-template-columns: repeat(3, minmax(0,1fr)); } .g4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
.g-21 { grid-template-columns: 2fr 1fr; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); position: relative; overflow: hidden; }
.stat .label { color: var(--muted); font-size: .8rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 1.5rem; font-weight: 800; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat .sub { font-size: .82rem; color: var(--muted); margin-top: 2px; }
.stat::after { content: ""; position: absolute; right: -20px; top: -20px; width: 80px; height: 80px; border-radius: 50%; background: var(--accent, var(--brand)); opacity: .09; }
.stat.red { --accent: var(--red); } .stat.ok { --accent: var(--ok); } .stat.warn { --accent: var(--warn); }
.quick { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 10px; margin-bottom: 18px; }
.quick a { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 14px 6px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border); color: var(--text); font-weight: 600; font-size: .85rem; text-align: center; box-shadow: var(--shadow); }
.quick a:hover { border-color: var(--brand); text-decoration: none; transform: translateY(-1px); }
.quick a .ic { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; color: #fff; }
.quick a .ic svg { width: 22px; height: 22px; }
.quick a:first-child .ic { background: linear-gradient(135deg, var(--red), #ff4560); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 9px 16px; border-radius: 10px; border: 1px solid transparent; font: inherit; font-weight: 600; cursor: pointer; background: var(--brand); color: #fff; white-space: nowrap; min-height: 40px; }
.btn:hover { background: var(--brand-600); text-decoration: none; }
.btn svg { width: 17px; height: 17px; }
.btn.red { background: var(--red); } .btn.red:hover { background: var(--red-600); }
.btn.ok { background: var(--ok); }
.btn.ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.sm { padding: 5px 10px; min-height: 32px; font-size: .85rem; }
.btn.lg { padding: 14px 22px; font-size: 1.05rem; min-height: 52px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.link-btn { background: none; border: 0; color: var(--brand); cursor: pointer; font: inherit; padding: 0; }

/* Formularios */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 14px 16px; }
.form-grid.g3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.form-grid .full { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field > span, label.lbl { font-size: .83rem; font-weight: 600; color: var(--muted); }
input:not([type=checkbox]):not([type=radio]):not([type=hidden]):not([type=submit]), select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 9px 12px; width: 100%; min-height: 42px;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--brand) 35%, transparent); border-color: var(--brand); }
.check { display: flex; align-items: center; gap: 8px; font-size: .92rem; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--brand); }
.field-error { color: var(--red); font-size: .8rem; }
.input-group { display: flex; gap: 8px; }
.input-group > * { flex: 1; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.filters input, .filters select { width: auto; min-width: 150px; flex: 1 1 160px; max-width: 280px; }

/* Tablas */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: .76rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); background: var(--surface-2); font-weight: 700; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }
td.r, th.r { text-align: right; font-variant-numeric: tabular-nums; }
td.c, th.c { text-align: center; }
.empty { text-align: center; color: var(--muted); padding: 30px; }
.thumb { width: 40px; height: 40px; border-radius: 8px; object-fit: cover; background: var(--surface-2); border: 1px solid var(--border); }

.badge { display: inline-flex; align-items: center; padding: 2px 9px; border-radius: 999px; font-size: .75rem; font-weight: 700; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); white-space: nowrap; }
.badge.ok { background: var(--ok-50); color: var(--ok); border-color: transparent; }
.badge.red { background: var(--red-50); color: var(--red); border-color: transparent; }
.badge.warn { background: var(--warn-50); color: var(--warn); border-color: transparent; }
.badge.blue { background: var(--brand-50); color: var(--brand); border-color: transparent; }

.alert { padding: 12px 14px; border-radius: 12px; margin-bottom: 14px; border: 1px solid transparent; font-weight: 500; display: flex; gap: 10px; align-items: flex-start; }
.alert.success { background: var(--ok-50); color: var(--ok); }
.alert.error { background: var(--red-50); color: var(--red); }
.alert.info { background: var(--brand-50); color: var(--brand); }
.alert.warn { background: var(--warn-50); color: var(--warn); }
.alert a { font-weight: 700; color: inherit; text-decoration: underline; }
.banner-soporte { background: var(--warn); color: #000; padding: 8px 16px; display: flex; gap: 10px; align-items: center; justify-content: center; font-weight: 600; font-size: .9rem; }

.pager { display: flex; gap: 6px; align-items: center; margin-top: 14px; flex-wrap: wrap; }
.pager a, .pager .current { padding: 6px 11px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); }
.pager .current { background: var(--brand); color: #fff; border-color: var(--brand); }
.pager .muted { margin-left: 8px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tabs a { padding: 10px 14px; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a.active { color: var(--brand); border-color: var(--brand); }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; }
.kv dt { color: var(--muted); font-size: .88rem; } .kv dd { margin: 0; font-weight: 600; }
.list-plain { list-style: none; padding: 0; margin: 0; }
.list-plain li { padding: 9px 0; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; gap: 10px; }
.list-plain li:last-child { border: 0; }

/* Gráfico de barras SVG/CSS */
.bars { display: flex; align-items: flex-end; gap: 8px; height: 180px; padding-top: 10px; }
.bars .bar { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.bars .bar i { display: block; width: 100%; max-width: 46px; border-radius: 8px 8px 3px 3px; background: linear-gradient(180deg, #3b82ff, var(--brand)); min-height: 3px; }
.bars .bar:last-child i { background: linear-gradient(180deg, #ff4b63, var(--red)); }
.bars .bar small { font-size: .72rem; }
.bars .bar b { font-size: .7rem; color: var(--muted); font-weight: 600; }
.hbar { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; align-items: center; margin-bottom: 10px; font-size: .88rem; }
.hbar .track { grid-column: 1 / -1; height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.hbar .track i { display: block; height: 100%; background: var(--brand); border-radius: 99px; }

dialog { border: 0; border-radius: var(--radius); padding: 0; background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0,0,0,.35); width: min(520px, calc(100vw - 24px)); }
dialog::backdrop { background: rgba(5,12,35,.55); backdrop-filter: blur(2px); }
dialog .dlg-head { padding: 16px 18px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
dialog .dlg-head h3 { margin: 0; }
dialog .dlg-body { padding: 18px; max-height: 70vh; overflow-y: auto; }
dialog .dlg-foot { padding: 14px 18px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }

/* ---------- Auth ---------- */
.auth-page { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; background: radial-gradient(1200px 600px at 10% -10%, #1b3fa8 0%, transparent 60%), radial-gradient(900px 500px at 110% 110%, #7a0a1d 0%, transparent 55%), var(--navy); }
.auth-card { width: min(460px, 100%); background: var(--surface); border-radius: 20px; padding: 28px; box-shadow: 0 30px 80px rgba(0,0,0,.4); }
.auth-card.wide { width: min(820px, 100%); }
.auth-logo { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.auth-logo img { width: 54px; height: 54px; border-radius: 14px; }
.auth-logo b { font-size: 1.4rem; letter-spacing: .02em; } .auth-logo b span { color: var(--red); }
.auth-foot { text-align: center; margin-top: 16px; font-size: .9rem; color: var(--muted); }
.req-list li { display: flex; justify-content: space-between; }
.hp { position: absolute; left: -9999px; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) { .quick { grid-template-columns: repeat(4, minmax(0,1fr)); } .g4 { grid-template-columns: repeat(2, minmax(0,1fr)); } .g-21 { grid-template-columns: 1fr; } }
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; z-index: 60; width: 280px; transform: translateX(-100%); transition: transform .2s ease; }
  body.menu-open .sidebar { transform: none; box-shadow: 0 0 0 100vmax rgba(5,12,35,.55); }
  .menu-toggle { display: inline-grid; }
  .topbar { padding: 0 12px; }
  .content { padding: 14px 12px 90px; }
  .g2, .g3, .form-grid, .form-grid.g3 { grid-template-columns: 1fr; }
  .quick { grid-template-columns: repeat(4, minmax(0,1fr)); gap: 8px; }
  .quick a { padding: 10px 4px; font-size: .75rem; }
  .quick a .ic { width: 36px; height: 36px; }
  .bottom-nav { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; bottom: 0; left: 0; right: 0; background: var(--surface); border-top: 1px solid var(--border); z-index: 40; padding-bottom: env(safe-area-inset-bottom); }
  .bottom-nav a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 2px; font-size: .7rem; color: var(--muted); font-weight: 600; }
  .bottom-nav a.active { color: var(--brand); }
  .bottom-nav a.pos { color: #fff; background: var(--red); margin: -14px 6px 6px; border-radius: 16px; box-shadow: 0 8px 20px rgba(227,18,45,.4); }
  .bottom-nav svg { width: 22px; height: 22px; }
  .hide-sm { display: none !important; }
  .topbar select { max-width: 130px; }
  th, td { padding: 9px 8px; }
  .stat .value { font-size: 1.2rem; }
}
@media (max-width: 480px) { .g4 { grid-template-columns: 1fr 1fr; gap: 10px; } .stat { padding: 12px; } }

/* Impresión */
@media print { .sidebar, .topbar, .bottom-nav, .no-print { display: none !important; } .app { display: block; } .content { padding: 0; } .card { box-shadow: none; border: 0; } body { background: #fff; color: #000; } }
.filters input[type=checkbox] { min-width: 0; flex: 0 0 auto; width: 18px; }
.filters .check { flex: 0 0 auto; white-space: nowrap; }
