:root {
  --bg: #0c0e14;
  --surface: #141822;
  --surface2: #1c2230;
  --border: #2a3344;
  --text: #e8ecf4;
  --muted: #8b95a8;
  --accent: #e94560;
  --accent2: #0ea5e9;
  --good: #22c55e;
  --warn: #f59e0b;
  --radius: 12px;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { width: 100%; overflow-x: hidden; }
body {
  font-family: var(--font);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.45;
  background: #0a0c14;
  background-image:
    radial-gradient(ellipse 75% 55% at 12% 0%, rgba(233, 69, 96, 0.32), transparent 58%),
    radial-gradient(ellipse 55% 50% at 100% 8%, rgba(14, 165, 233, 0.24), transparent 55%),
    radial-gradient(ellipse 50% 45% at 50% 105%, rgba(233, 69, 96, 0.16), transparent 62%),
    radial-gradient(ellipse 40% 35% at 78% 55%, rgba(250, 204, 21, 0.06), transparent 60%),
    linear-gradient(180deg, #12151f 0%, #0a0c14 50%, #060710 100%);
  background-attachment: fixed;
}
.bg-grid {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: 1;
  background-image: radial-gradient(rgba(233, 236, 244, 0.14) 1.4px, transparent 1.4px);
  background-size: 32px 32px;
  background-position: -6px -6px;
  -webkit-mask-image: radial-gradient(ellipse 110% 95% at 50% 35%, #000 0%, transparent 88%);
  mask-image: radial-gradient(ellipse 110% 95% at 50% 35%, #000 0%, transparent 88%);
}
.bg-lights {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}
.bg-lights span {
  position: absolute;
  border-radius: 50%;
  filter: blur(60px);
  animation: pulseGlow 7s ease-in-out infinite;
}
.bg-lights span:nth-child(1) { top: 8%; left: 42%; width: 260px; height: 260px; background: rgba(233,69,96,0.16); animation-delay: 0s; }
.bg-lights span:nth-child(2) { top: 55%; left: 6%; width: 220px; height: 220px; background: rgba(14,165,233,0.14); animation-delay: 2.2s; }
.bg-lights span:nth-child(3) { top: 34%; right: 8%; width: 300px; height: 300px; background: rgba(250,204,21,0.09); animation-delay: 4.1s; }
.bg-lights span:nth-child(4) { top: 72%; right: 28%; width: 200px; height: 200px; background: rgba(233,69,96,0.13); animation-delay: 1.2s; }
@keyframes pulseGlow {
  0%, 100% { opacity: 0.55; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.15); }
}
.bg-scatter {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}
.bg-scatter svg { position: absolute; overflow: visible; }
.bg-scatter .s1 { top: 4%; left: 30%; width: min(110px, 12vw); transform: rotate(-16deg); opacity: 0.16; filter: drop-shadow(0 0 20px rgba(233,69,96,0.3)); }
.bg-scatter .s2 { top: 62%; right: 2%; width: min(220px, 20vw); transform: rotate(20deg); opacity: 0.16; filter: drop-shadow(0 0 24px rgba(14,165,233,0.25)); }
.bg-scatter .s3 { top: 10%; right: 3%; width: min(120px, 12vw); transform: rotate(10deg); opacity: 0.14; filter: drop-shadow(0 0 18px rgba(250,204,21,0.32)); }
.bg-scatter .s4 { top: 40%; right: 1.5%; width: min(90px, 9vw); transform: rotate(-8deg); opacity: 0.13; }
.bg-mark {
  position: fixed;
  z-index: 0;
  pointer-events: none;
  top: -6%;
  right: -8%;
  width: min(640px, 60vw);
  opacity: 0.18;
  transform: rotate(-18deg);
  filter: drop-shadow(0 0 50px rgba(233, 69, 96, 0.5));
}
.bg-horizon {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 0;
  pointer-events: none;
  width: 100%;
  height: min(340px, 38vh);
  overflow: hidden;
}
.bg-horizon svg {
  position: absolute; bottom: 0; left: 0; width: 100%; height: 100%;
  filter: drop-shadow(0 -6px 40px rgba(233, 69, 96, 0.3)) drop-shadow(0 -6px 40px rgba(14, 165, 233, 0.2));
}

/* Pantalla de Login */
.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(8, 10, 16, 0.94);
  backdrop-filter: blur(16px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  transition: opacity .3s ease, visibility .3s ease;
}
.login-overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}
.login-card {
  width: min(420px, 100%);
  background: linear-gradient(160deg, #182030 0%, #0e121c 100%);
  border: 1px solid rgba(56, 189, 248, 0.3);
  border-radius: 18px;
  padding: 2.2rem 2rem;
  box-shadow: 0 16px 40px rgba(0,0,0,0.6), 0 0 30px rgba(14, 165, 233, 0.2);
  text-align: center;
  position: relative;
  overflow: hidden;
}
.login-card::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0; height: 4px;
  background: linear-gradient(90deg, var(--accent), var(--accent2), var(--good));
}
.login-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 1.8rem;
}
.login-logo-icon {
  width: 64px; height: 64px;
  border-radius: 18px;
  background: linear-gradient(145deg, #0a1628 0%, #061018 100%);
  border: 1px solid rgba(0, 212, 255, 0.6);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 0 30px rgba(0, 212, 255, 0.4);
  margin-bottom: .8rem;
}
.login-title {
  font-size: 1.5rem; font-weight: 700; color: #fff;
}
.login-title span { color: var(--accent2); }
.login-subtitle { font-size: .85rem; color: var(--muted); margin-top: .2rem; }
.login-form { display: flex; flex-direction: column; gap: 1.1rem; text-align: left; }
.input-group { display: flex; flex-direction: column; gap: .35rem; }
.input-group label { font-size: .82rem; font-weight: 600; color: var(--muted); }
.input-wrapper { position: relative; }
.input-wrapper input {
  width: 100%;
  background: rgba(10, 14, 22, 0.8);
  border: 1px solid var(--border);
  color: #fff;
  padding: .75rem .9rem;
  border-radius: 10px;
  font-size: .95rem;
  outline: none;
  transition: border-color .2s, box-shadow .2s;
}
.input-wrapper input:focus {
  border-color: var(--accent2);
  box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.25);
}
.toggle-pwd {
  position: absolute; right: .75rem; top: 50%; transform: translateY(-50%);
  background: transparent; border: none; color: var(--muted); cursor: pointer;
  padding: .2rem; display: flex; align-items: center;
}
.btn-login {
  background: linear-gradient(135deg, var(--accent2) 0%, #0284c7 100%);
  color: #fff; font-weight: 700; font-size: 1rem;
  padding: .85rem; border-radius: 10px; border: none; cursor: pointer;
  box-shadow: 0 4px 18px rgba(14, 165, 233, 0.4);
  transition: transform .15s, box-shadow .15s;
  margin-top: .5rem;
}
.btn-login:hover { transform: translateY(-1px); box-shadow: 0 6px 24px rgba(14, 165, 233, 0.5); }
.btn-login:active { transform: scale(.98); }
.login-hint {
  font-size: .78rem; color: var(--muted); text-align: center; margin-top: .8rem;
  background: rgba(255,255,255,0.03); padding: .5rem; border-radius: 8px; border: 1px dashed var(--border);
}

.app {
  display: flex;
  min-height: 100vh;
  position: relative;
  z-index: 1;
}

/* Sidebar */
.sidebar {
  width: 245px;
  background: linear-gradient(165deg, #0a121c 0%, #070b12 42%, #060810 100%);
  border-right: 1px solid rgba(56, 189, 248, 0.35);
  padding: 1rem .75rem 1rem;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  backdrop-filter: blur(14px);
  box-shadow: 6px 0 28px rgba(0,0,0,.4);
  overflow: hidden;
}
.sidebar::after {
  content: ""; position: absolute; top: 0; right: 0; bottom: 0; width: 3px;
  background: linear-gradient(180deg, transparent 0%, rgba(14, 165, 233, 0.95) 50%, transparent 100%);
  z-index: 2; pointer-events: none;
}
.sidebar > * { position: relative; z-index: 1; }
.logo-wrap {
  display: flex; align-items: center; gap: .7rem;
  padding: .4rem .55rem .9rem;
  border-bottom: 1px solid rgba(56, 189, 248, 0.25);
  margin-bottom: .55rem; flex-shrink: 0;
}
.logo-icon {
  flex-shrink: 0; width: 44px; height: 44px; border-radius: 12px;
  background: linear-gradient(145deg, #0a1628 0%, #061018 100%);
  border: 1px solid rgba(0, 212, 255, 0.55);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 0 20px rgba(0, 212, 255, 0.4);
}
.logo { font-size: 1.15rem; font-weight: 700; color: #e8ecf4; }
.logo span { background: linear-gradient(120deg, #7dd3fc, #0ea5e9); -webkit-background-clip: text; background-clip: text; color: transparent; }
.logo-sub { font-size: .65rem; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; color: #38bdf8; }

.user-badge-sidebar {
  display: flex; align-items: center; justify-content: space-between;
  background: rgba(14, 165, 233, 0.1); border: 1px solid rgba(56, 189, 248, 0.25);
  padding: .5rem .7rem; border-radius: 9px; margin-bottom: .8rem;
  font-size: .8rem; color: #e0f2fe;
}
.btn-logout {
  background: transparent; border: none; color: var(--accent); cursor: pointer;
  display: flex; align-items: center; justify-content: center; padding: .2rem;
  border-radius: 6px; transition: background .15s;
}
.btn-logout:hover { background: rgba(233, 69, 96, 0.15); }

.nav-scroll {
  display: flex; flex-direction: column; gap: .15rem; flex: 1;
  min-height: 0; overflow-y: auto; overflow-x: hidden; padding-right: .15rem;
}
.nav-scroll::-webkit-scrollbar { width: 4px; }
.nav-scroll::-webkit-scrollbar-thumb { background: rgba(56,189,248,.4); border-radius: 4px; }
.nav-group {
  display: flex; flex-direction: column; gap: .12rem; margin-bottom: .6rem;
  padding: .35rem .2rem .4rem; border-radius: 12px;
  background: rgba(255, 255, 255, 0.02); border: 1px solid rgba(56, 189, 248, 0.1);
}
.nav-group-label {
  font-size: .62rem; font-weight: 800; letter-spacing: .14em; text-transform: uppercase;
  color: rgba(125, 211, 252, 0.9); padding: .35rem .55rem .15rem; user-select: none;
}
.nav-btn {
  background: transparent; border: none; border-left: 3px solid transparent;
  color: #a8b0c0; text-align: left; padding: .48rem .7rem; border-radius: 9px;
  cursor: pointer; font-size: .88rem; font-weight: 500; display: flex; align-items: center; gap: .55rem;
  transition: background .15s, color .15s, transform .1s; white-space: nowrap;
}
.nav-ic { width: 16px; height: 16px; flex-shrink: 0; color: #38bdf8; }
.nav-btn:hover { background: rgba(14, 165, 233, 0.12); color: #e0f2fe; transform: translateX(2px); }
.nav-btn.active {
  background: linear-gradient(135deg, #38bdf8 0%, #0ea5e9 100%);
  border-left-color: #e0f2fe; color: #04101a; font-weight: 700;
  box-shadow: 0 3px 16px rgba(14, 165, 233, 0.45);
}
.nav-btn.active .nav-ic { color: #04101a; }

.sidebar-foot {
  margin-top: .5rem; padding: .55rem .65rem; font-size: .72rem;
  color: rgba(125, 211, 252, 0.75); border-top: 1px solid rgba(56, 189, 248, 0.2);
}

/* Main Content */
.main {
  flex: 1; width: 100%; padding: 1.35rem 1.75rem 2.5rem; max-width: 1200px; position: relative; min-width: 0;
}
.page { display: none; min-width: 0; }
.page.active { display: block; animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
h1 { font-size: 1.65rem; font-weight: 700; margin-bottom: .25rem; letter-spacing: -.02em; }
.subtitle { color: var(--muted); margin-bottom: 1.5rem; font-size: .95rem; }

/* Tarjetas y Paneles */
.metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.metric {
  background: linear-gradient(160deg, #1a2030 0%, #141822 100%);
  border: 1px solid var(--border); border-top: 3px solid rgba(255,255,255,.08);
  border-radius: var(--radius); padding: 1.1rem 1.2rem; min-width: 0; overflow: hidden;
  box-shadow: 0 2px 12px rgba(0,0,0,.18); transition: transform .18s, box-shadow .18s;
}
.metric:hover { transform: translateY(-3px); box-shadow: 0 10px 28px rgba(0,0,0,.32); }
.metric:has(.val.good) { border-top-color: var(--good); }
.metric:has(.val.bad) { border-top-color: var(--accent); }
.metric:has(.val.info) { border-top-color: var(--accent2); }
.metric .val { font-size: clamp(1rem, 2.8vw, 1.55rem); font-weight: 700; font-variant-numeric: tabular-nums; }
.metric .lbl { font-size: .8rem; color: var(--muted); margin-top: .25rem; }
.val.good { color: var(--good); } .val.bad { color: var(--accent); } .val.info { color: var(--accent2); }

.panel {
  background: linear-gradient(165deg, #181e2a 0%, #141822 100%);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem;
  margin-bottom: 1.25rem; box-shadow: 0 3px 16px rgba(0,0,0,.2); min-width: 0;
}
.panel h2 { font-size: 1.05rem; margin-bottom: 1rem; font-weight: 600; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; }

@media (max-width: 900px) {
  .app { flex-direction: column; }
  .sidebar {
    width: 100%; height: auto; position: relative; padding: .7rem .7rem .55rem;
    border-right: none; border-bottom: 1px solid rgba(56, 189, 248, 0.28);
  }
  .logo-wrap { width: 100%; margin-bottom: .45rem; padding: .15rem .35rem .4rem; }
  .nav-scroll { flex-direction: row; flex-wrap: nowrap; overflow-x: auto; gap: .35rem; padding-bottom: .2rem; }
  .nav-group { flex-direction: row; margin-bottom: 0; background: transparent; border: none; padding: 0; }
  .nav-group-label { display: none; }
  .nav-btn { padding: .42rem .7rem; border-left: none; border-radius: 999px; font-size: .78rem; background: rgba(12, 22, 34, 0.95); border: 1px solid rgba(56, 189, 248, 0.28); }
  .nav-btn.active { background: linear-gradient(135deg, #38bdf8 0%, #0ea5e9 100%); }
  .grid-2 { grid-template-columns: 1fr; }
  .main { padding: .9rem .85rem 2rem; }
  .sidebar-foot { display: none; }
}

@media (max-width: 600px) {
  .sidebar { padding: .6rem .55rem .5rem; }
  .logo-wrap { gap: .5rem; }
  .logo { font-size: 1rem; }
  .user-badge-sidebar { margin-bottom: .55rem; }
  .nav-scroll { margin-inline: -.1rem; padding-inline: .1rem; }
  .nav-btn { flex-shrink: 0; }
  .main { padding: .8rem .65rem 5rem; }
  h1 { font-size: 1.35rem; }
  .subtitle { font-size: .88rem; margin-bottom: 1rem; }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .65rem; margin-bottom: 1rem; }
  .metric { padding: .85rem .8rem; }
  .metric .val { font-size: 1.1rem; }
  .metric .lbl { font-size: .72rem; }
  .panel { padding: .9rem; margin-bottom: .9rem; }
  .form-row { grid-template-columns: 1fr; gap: .7rem; margin-bottom: .7rem; }
  .toolbar { align-items: stretch; gap: .55rem; }
  .toolbar input { max-width: none; }
  .toolbar > * { width: 100%; }
  .actions { align-items: stretch; }
  .actions > button, .actions > .btn { flex: 1 1 100%; }
  .chart-panel-head { align-items: flex-start; flex-direction: column; }
  .chart-wrap { height: 230px; }
  .chart-legend { gap: .6rem .9rem; }
  .modal { width: calc(100vw - 1.2rem); padding: 1rem; }
  .toast { left: .65rem; right: .65rem; bottom: .75rem; }
}

@media (max-width: 380px) {
  .metrics { grid-template-columns: 1fr; }
  .nav-btn { padding-inline: .6rem; }
  .panel h2 { font-size: .98rem; }
}

/* Tablas */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { padding: .65rem .75rem; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; }
tbody tr:hover td { background: rgba(233, 69, 96, .05); }

.badge { display: inline-block; padding: .2rem .55rem; border-radius: 999px; font-size: .75rem; font-weight: 600; }
.badge.ok { background: rgba(34,197,94,.15); color: var(--good); }
.badge.no { background: rgba(233,69,96,.15); color: var(--accent); }
.badge.off { background: rgba(139,149,168,.15); color: var(--muted); }
.badge.info { background: rgba(14,165,233,.15); color: var(--accent2); }
.badge.warn { background: rgba(245,158,11,.18); color: var(--warn); }

/* Formularios y Botones */
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: .85rem; margin-bottom: .85rem; }
.form-row.full { grid-template-columns: 1fr; }
label { display: block; font-size: .8rem; color: var(--muted); margin-bottom: .3rem; }
input, select {
  width: 100%; background: var(--bg); border: 1px solid var(--border);
  color: var(--text); padding: .6rem .75rem; border-radius: 8px; font-size: .95rem; outline: none;
}
input:focus, select:focus { border-color: var(--accent2); box-shadow: 0 0 0 3px rgba(14,165,233,.15); }
.actions { display: flex; gap: .6rem; flex-wrap: wrap; margin-top: 1rem; align-items: center; }
button, .btn {
  border: none; border-radius: 8px; padding: .6rem 1.1rem; font-size: .9rem; font-weight: 600; cursor: pointer; transition: .15s;
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem; text-decoration: none;
}
button:active, .btn:active { transform: scale(.96); }
.btn-primary { background: var(--accent); color: #fff; box-shadow: 0 2px 10px rgba(233,69,96,.25); }
.btn-primary:hover { filter: brightness(1.1); transform: translateY(-1px); }
.btn-excel { background: linear-gradient(135deg, #16a34a 0%, #15803d 100%); color: #fff; box-shadow: 0 2px 10px rgba(34,197,94,.3); }
.btn-excel:hover { filter: brightness(1.1); transform: translateY(-1px); }
.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-sm { padding: .35rem .65rem; font-size: .8rem; }
.btn-wa { background: rgba(34,197,94,0.15); color: #22c55e; border: 1px solid rgba(34,197,94,0.3); }
.btn-wa:hover { background: rgba(34,197,94,0.28); }

.toolbar { display: flex; gap: .75rem; flex-wrap: wrap; margin-bottom: 1rem; align-items: center; }
.toolbar input { max-width: 260px; }
.empty { color: var(--muted); padding: 1.5rem; text-align: center; }

/* Toasts y Modales */
.toast {
  position: fixed; bottom: 1.5rem; right: 1.5rem; background: var(--surface2);
  border: 1px solid var(--border); padding: .85rem 1.2rem; border-radius: 10px;
  box-shadow: 0 8px 30px rgba(0,0,0,.4); z-index: 10000; display: none;
}
.toast.show { display: block; animation: fade .2s; }
.toast.ok { border-left: 3px solid var(--good); }
.toast.err { border-left: 3px solid var(--accent); }

.modal-bg {
  position: fixed; inset: 0; background: rgba(0,0,0,.7); backdrop-filter: blur(4px);
  display: none; align-items: center; justify-content: center; z-index: 9000;
}
.modal-bg.open { display: flex; }
.modal {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 1.5rem; width: min(520px, 94vw);
  max-height: 90vh; overflow-y: auto; box-shadow: 0 10px 40px rgba(0,0,0,0.5);
}
.modal h3 { margin-bottom: 1rem; }
.hint { font-size: .8rem; color: var(--muted); margin-top: .4rem; }

/* Gráficos */
.chart-panel-head { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: .75rem; margin-bottom: .25rem; }
.chart-legend { display: flex; gap: 1.1rem; flex-wrap: wrap; }
.chart-legend-item { display: flex; align-items: center; gap: .4rem; font-size: .78rem; color: var(--muted); }
.chart-legend-dot { width: 10px; height: 10px; border-radius: 3px; }
.chart-wrap { position: relative; width: 100%; height: 340px; margin-top: .75rem; }
.chart-empty { display: flex; align-items: center; justify-content: center; height: 100%; color: var(--muted); font-size: .85rem; }
.chart-hover-col { cursor: crosshair; }
.chart-tooltip {
  position: absolute; pointer-events: none; background: rgba(20, 24, 34, 0.97);
  border: 1px solid var(--border); border-radius: 10px; padding: .6rem .75rem;
  font-size: .78rem; min-width: 150px; box-shadow: 0 8px 24px rgba(0,0,0,.4); opacity: 0; z-index: 5;
}
.chart-tooltip-title { font-weight: 600; color: var(--text); margin-bottom: .4rem; }
.chart-tooltip-row { display: flex; align-items: center; justify-content: space-between; gap: .8rem; color: var(--muted); padding: .12rem 0; }
.chart-tooltip-row strong { color: var(--text); }
.chart-tooltip-dot { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: .35rem; }
