/* VPS Monitor — tema oscuro de centro de operaciones.
   Colores de datos validados (paleta de referencia, modo oscuro):
   hostil = naranja, tráfico legítimo = azul, saliente = aqua. Estados reservados para alertas. */
:root {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #222220;
  --surface-3: #2a2a28;
  --border: rgba(255, 255, 255, 0.10);
  --border-strong: rgba(255, 255, 255, 0.18);
  --text: #ffffff;
  --text-2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --c-hostile: #d95926;
  --c-traffic: #3987e5;
  --c-out: #199e70;
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --focus: #6da7ec;
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", "JetBrains Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--page);
  color: var(--text);
  font: 14px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--focus); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.sec { color: var(--text-2); }
.hidden { display: none !important; }

/* ---------------------------------------------------------------- cabecera */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 16px;
  padding: 10px 20px;
  background: rgba(13, 13, 13, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand img { width: 26px; height: 26px; }
.brand h1 { margin: 0; font-size: 16px; font-weight: 650; letter-spacing: 0.2px; white-space: nowrap; }
.brand .host { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.live { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-2);
  padding: 3px 9px; border: 1px solid var(--border); border-radius: 999px; white-space: nowrap; }
.live .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.live.on .dot { background: var(--good); box-shadow: 0 0 0 0 rgba(12, 163, 12, 0.6); animation: pulse 2s infinite; }
.live.off .dot { background: var(--critical); }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(12,163,12,.55);} 70% { box-shadow: 0 0 0 7px rgba(12,163,12,0);} 100% { box-shadow: 0 0 0 0 rgba(12,163,12,0);} }
.tabs { display: flex; gap: 2px; margin-left: 8px; overflow-x: auto; scrollbar-width: none; flex: 1; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  background: none; border: 0; padding: 7px 12px; border-radius: 8px; cursor: pointer;
  color: var(--text-2); white-space: nowrap; position: relative;
}
.tab:hover { background: var(--surface-2); color: var(--text); }
.tab[aria-selected="true"] { background: var(--surface-3); color: var(--text); }
.tab .badge { margin-left: 6px; }
.top-right { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.clock { color: var(--text-2); font-size: 12.5px; white-space: nowrap; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 32px; min-width: 32px; padding: 0 10px; border-radius: 8px;
  background: var(--surface-2); border: 1px solid var(--border); cursor: pointer; color: var(--text-2);
}
.icon-btn:hover { color: var(--text); border-color: var(--border-strong); }
.icon-btn svg { width: 16px; height: 16px; }
.badge {
  display: inline-flex; align-items: center; justify-content: center; min-width: 18px; height: 18px;
  padding: 0 5px; border-radius: 999px; font-size: 11px; font-weight: 650; line-height: 1;
  background: var(--critical); color: #fff;
}
.badge.zero { display: none; }

.demo-banner { background: #2b2410; color: var(--warning); text-align: center; padding: 6px; font-size: 12.5px;
  border-bottom: 1px solid rgba(250, 178, 25, 0.25); }

/* ---------------------------------------------------------------- layout */
main { padding: 16px 20px 40px; max-width: 1920px; margin: 0 auto; }
.view { display: none; }
.view.active { display: block; }
.grid { display: grid; gap: 14px; }
.kpis { grid-template-columns: repeat(8, minmax(0, 1fr)); margin-bottom: 14px; }
.row-map { grid-template-columns: minmax(0, 1fr) 380px; margin-bottom: 14px; }
.row-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); margin-bottom: 14px; }
.row-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); margin-bottom: 14px; }
.row-21 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); margin-bottom: 14px; }
.row-12 { grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); margin-bottom: 14px; }
.row-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); margin-bottom: 14px; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  min-width: 0; display: flex; flex-direction: column;
}
.card-h {
  display: flex; align-items: center; gap: 10px; padding: 12px 14px 8px; min-height: 44px;
}
.card-h h2 { margin: 0; font-size: 13.5px; font-weight: 600; color: var(--text); }
.card-h .sub { color: var(--muted); font-size: 12px; }
.card-h .spacer { flex: 1; }
.card-b { padding: 4px 14px 14px; min-width: 0; flex: 1; }
.card-b.flush { padding: 0 0 6px; }
.empty { color: var(--muted); padding: 18px 0; text-align: center; font-size: 13px; }

/* ---------------------------------------------------------------- KPIs */
.kpi { padding: 12px 14px 10px; position: relative; overflow: hidden; }
.kpi .label { color: var(--text-2); font-size: 12px; display: flex; align-items: center; gap: 6px; }
.kpi .value { font-size: 26px; font-weight: 650; margin-top: 2px; line-height: 1.15; white-space: nowrap; }
.kpi .value small { font-size: 13px; font-weight: 500; color: var(--text-2); margin-left: 4px; }
.kpi .foot { color: var(--muted); font-size: 11.5px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi svg.spark { position: absolute; right: 10px; bottom: 10px; width: 72px; height: 26px; opacity: 0.9; }
.swatch { width: 9px; height: 9px; border-radius: 2px; display: inline-block; flex: none; }
.meter { height: 4px; background: var(--grid); border-radius: 4px; margin-top: 7px; overflow: hidden; }
.meter > i { display: block; height: 100%; border-radius: 4px; background: var(--c-traffic); transition: width .6s; }
.meter.warn > i { background: var(--warning); }
.meter.crit > i { background: var(--critical); }

/* ---------------------------------------------------------------- mapa */
.map-card { position: relative; min-height: 560px; overflow: hidden; }
.map-wrap { position: absolute; inset: 0; }
.map-wrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
#fxCanvas { pointer-events: none; }
.map-ui { position: absolute; left: 14px; top: 12px; right: 14px; display: flex; gap: 8px; align-items: flex-start;
  pointer-events: none; flex-wrap: wrap; }
.map-ui > * { pointer-events: auto; }
.map-title { background: rgba(26,26,25,.85); border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; }
.map-title h2 { margin: 0; font-size: 13.5px; }
.map-title .sub { color: var(--muted); font-size: 12px; }
.seg { display: inline-flex; background: rgba(26,26,25,.9); border: 1px solid var(--border); border-radius: 8px; padding: 2px; }
.seg button { background: none; border: 0; padding: 5px 10px; border-radius: 6px; cursor: pointer; color: var(--text-2); font-size: 12.5px; }
.seg button[aria-pressed="true"] { background: var(--surface-3); color: var(--text); }
.seg button:hover { color: var(--text); }
.map-ui .spacer { flex: 1; }
.legend { position: absolute; left: 14px; bottom: 12px; display: flex; flex-wrap: wrap; gap: 6px 14px; max-width: calc(100% - 28px);
  background: rgba(26,26,25,.85); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font-size: 12px; color: var(--text-2); }
.legend .item { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; user-select: none; }
.legend .item.off { opacity: .35; text-decoration: line-through; }
.legend svg { width: 12px; height: 12px; }
.legend .sep { width: 1px; background: var(--border); align-self: stretch; }
.map-stats { position: absolute; right: 14px; bottom: 12px; background: rgba(26,26,25,.85); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 12px; font-size: 12px; color: var(--text-2); text-align: right; }
.map-stats b { color: var(--text); font-size: 15px; }
.map-tip { position: absolute; pointer-events: none; z-index: 5; }
.chor-legend { display: flex; align-items: center; gap: 6px; }
.chor-legend .ramp { width: 90px; height: 8px; border-radius: 4px; }

/* ---------------------------------------------------------------- feed */
.feed-card { height: 560px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; padding: 0 14px 8px; }
.chip { border: 1px solid var(--border); background: var(--surface-2); color: var(--text-2); border-radius: 999px;
  padding: 3px 10px; font-size: 12px; cursor: pointer; }
.chip[aria-pressed="true"] { background: var(--surface-3); color: var(--text); border-color: var(--border-strong); }
.feed { list-style: none; margin: 0; padding: 0 6px 0 14px; overflow-y: auto; flex: 1; min-height: 0; }
.feed li { display: grid; grid-template-columns: 54px 1fr; gap: 8px; padding: 7px 8px 7px 0; border-bottom: 1px solid var(--grid);
  cursor: pointer; animation: flashin 1.2s ease-out; }
.feed li:hover { background: var(--surface-2); }
.feed .t { color: var(--muted); font-size: 11.5px; padding-top: 1px; }
.feed .l1 { display: flex; align-items: center; gap: 6px; min-width: 0; }
.feed .l2 { color: var(--text-2); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 1px; }
.feed .ip { font-family: var(--mono); font-size: 12.5px; }
@keyframes slidein { from { transform: translateY(-6px); } to { transform: none; } }
@keyframes flashin { from { background: rgba(217, 89, 38, 0.16); } to { background: transparent; } }

.tag { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 600; padding: 1px 7px 1px 6px;
  border-radius: 5px; background: var(--surface-3); color: var(--text); white-space: nowrap; }
.tag .swatch { width: 7px; height: 7px; }
.cc { display: inline-block; font-size: 10.5px; font-weight: 700; padding: 0 5px; border-radius: 4px; background: var(--surface-3);
  color: var(--text-2); letter-spacing: .3px; font-family: var(--mono); }
.pill { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; padding: 1px 8px; border-radius: 999px;
  border: 1px solid var(--border); color: var(--text-2); white-space: nowrap; }
.pill.blocked { color: var(--text); border-color: rgba(255,255,255,.3); }
.pill.trusted { color: var(--good); border-color: rgba(12,163,12,.45); }
.status { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.status svg { width: 14px; height: 14px; flex: none; }
.status.good { color: var(--good); } .status.warning { color: var(--warning); }
.status.serious { color: var(--serious); } .status.critical { color: var(--critical); } .status.info { color: var(--text-2); }

/* ---------------------------------------------------------------- tablas */
.tbl-wrap { overflow: auto; max-height: 420px; }
.tbl-wrap.tall { max-height: 640px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; font-weight: 600; color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: .4px;
  padding: 8px 10px; border-bottom: 1px solid var(--axis); position: sticky; top: 0; background: var(--surface); z-index: 1; white-space: nowrap; }
td { padding: 7px 10px; border-bottom: 1px solid var(--grid); vertical-align: middle; }
td.r, th.r { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:hover { background: var(--surface-2); }
tr.click { cursor: pointer; }
td .ell { display: block; max-width: 320px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* barras horizontales (listas top) */
.bars { list-style: none; margin: 0; padding: 0; }
.bars li { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 10px; padding: 5px 0; cursor: default; }
.bars li.click { cursor: pointer; }
.bars li:hover .bar > i { filter: brightness(1.15); }
.bars .name { display: flex; align-items: center; gap: 7px; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 13px; }
.bars .name span.ell { overflow: hidden; text-overflow: ellipsis; }
.bars .val { font-variant-numeric: tabular-nums; font-size: 13px; color: var(--text); text-align: right; }
.bars .val small { color: var(--muted); margin-left: 6px; font-size: 11.5px; }
.bars .bar { grid-column: 1 / -1; height: 6px; background: transparent; }
.bars .bar > i { display: block; height: 100%; border-radius: 0 4px 4px 0; background: var(--c-hostile); min-width: 2px; }
.bars.blue .bar > i { background: var(--c-traffic); }
.bars.aqua .bar > i { background: var(--c-out); }

/* ---------------------------------------------------------------- gráficos */
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart .axis text { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .axis path, .chart .axis line { stroke: var(--axis); }
.chart .grid line { stroke: var(--grid); }
.chart .grid path { display: none; }
.chart-legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--text-2); margin-bottom: 6px; }
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.tooltip {
  position: fixed; z-index: 100; pointer-events: none; background: #0f0f0e; border: 1px solid var(--border-strong);
  border-radius: 8px; padding: 8px 10px; font-size: 12px; color: var(--text-2); box-shadow: 0 8px 24px rgba(0,0,0,.5);
  min-width: 140px; max-width: 320px;
}
.tooltip .tt-h { color: var(--text); font-weight: 600; margin-bottom: 4px; }
.tooltip .tt-r { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.tooltip .tt-r span:first-child { display: inline-flex; align-items: center; gap: 6px; }
.tooltip .tt-r b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }

.cores { display: grid; grid-template-columns: repeat(auto-fill, minmax(46px, 1fr)); gap: 6px; }
.core { background: var(--surface-2); border-radius: 6px; padding: 6px; text-align: center; font-size: 11px; color: var(--muted); }
.core b { display: block; color: var(--text); font-size: 13px; font-variant-numeric: tabular-nums; }
.core .meter { margin-top: 4px; }

/* ---------------------------------------------------------------- formularios */
.btn {
  display: inline-flex; align-items: center; gap: 6px; border-radius: 8px; padding: 7px 12px; cursor: pointer;
  background: var(--surface-3); border: 1px solid var(--border-strong); color: var(--text); font-size: 13px; white-space: nowrap;
}
.btn:hover { background: #343431; }
.btn.danger { background: #3a1716; border-color: rgba(208, 59, 59, .5); color: #ffd9d9; }
.btn.danger:hover { background: #4a1d1c; }
.btn.small { padding: 4px 9px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.input, select.input {
  background: var(--surface-2); border: 1px solid var(--border-strong); border-radius: 8px; padding: 7px 10px; min-width: 0;
}
.input:focus { border-color: var(--focus); outline: none; }
.form-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.setting { display: grid; grid-template-columns: 1fr auto; gap: 4px 16px; padding: 12px 0; border-bottom: 1px solid var(--grid); align-items: center; }
.setting:last-child { border-bottom: 0; }
.setting .desc { color: var(--muted); font-size: 12.5px; grid-column: 1; }
.setting .ctl { grid-column: 2; grid-row: 1 / span 2; display: flex; align-items: center; gap: 6px; }
.setting .ctl .input { width: 90px; text-align: right; }
.switch { position: relative; width: 40px; height: 22px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; background: var(--surface-3); border: 1px solid var(--border-strong); border-radius: 999px; cursor: pointer; transition: .2s; }
.switch span::before { content: ""; position: absolute; width: 16px; height: 16px; left: 2px; top: 2px; background: var(--text-2); border-radius: 50%; transition: .2s; }
.switch input:checked + span { background: #134a8a; border-color: var(--c-traffic); }
.switch input:checked + span::before { transform: translateX(18px); background: #fff; }
.switch input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ---------------------------------------------------------------- panel lateral de IP */
.drawer-bg { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 40; opacity: 0; pointer-events: none; transition: opacity .2s; }
.drawer-bg.open { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100vw); z-index: 41; background: var(--surface);
  border-left: 1px solid var(--border-strong); transform: translateX(100%); transition: transform .25s ease; display: flex; flex-direction: column;
}
.drawer.open { transform: none; }
.drawer-h { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.drawer-h h2 { margin: 0; font-family: var(--mono); font-size: 16px; }
.drawer-b { overflow-y: auto; padding: 14px 16px 30px; flex: 1; }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 6px 12px; font-size: 13px; margin-bottom: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.drawer h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); margin: 18px 0 8px; font-weight: 600; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0 4px; }
.note { font-size: 12.5px; color: var(--text-2); background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; }
.note.warn { border-color: rgba(250,178,25,.35); }

/* alertas */
.alert-list { list-style: none; margin: 0; padding: 0; }
.alert-list li { display: grid; grid-template-columns: auto 1fr auto; gap: 4px 12px; padding: 11px 0; border-bottom: 1px solid var(--grid); }
.alert-list li.ack { opacity: .55; }
.alert-list .a-t { font-weight: 600; }
.alert-list .a-d { grid-column: 2 / -1; color: var(--text-2); font-size: 12.5px; overflow-wrap: anywhere; }
.alert-list .a-m { color: var(--muted); font-size: 12px; white-space: nowrap; text-align: right; }
.toast-stack { position: fixed; right: 16px; bottom: 16px; z-index: 60; display: flex; flex-direction: column; gap: 8px; max-width: 380px; }
.toast { background: #0f0f0e; border: 1px solid var(--border-strong); border-left: 4px solid var(--critical); border-radius: 8px;
  padding: 10px 12px; box-shadow: 0 10px 30px rgba(0,0,0,.5); animation: slidein .3s; cursor: pointer; }
.toast.warning { border-left-color: var(--warning); } .toast.serious { border-left-color: var(--serious); }
.toast.info { border-left-color: var(--c-traffic); }
.toast .tt { font-weight: 600; font-size: 13px; display: flex; gap: 6px; align-items: center; }
.toast .td { color: var(--text-2); font-size: 12px; margin-top: 2px; }

/* ---------------------------------------------------------------- login */
.login-page { display: grid; place-items: center; min-height: 100vh; padding: 16px; background:
  radial-gradient(ellipse at 50% 30%, #1b2230 0%, var(--page) 60%); }
.login-box { width: min(380px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 28px; }
.login-box h1 { font-size: 18px; margin: 12px 0 4px; }
.login-box p { color: var(--muted); margin: 0 0 18px; font-size: 13px; }
.login-box .input { width: 100%; padding: 10px 12px; }
.login-box .btn { width: 100%; justify-content: center; margin-top: 12px; padding: 10px; background: #1c5cab; border-color: #2a78d6; }
.login-box .err { color: #ff9b9b; font-size: 13px; min-height: 20px; margin-top: 10px; }

.foot-note { color: var(--muted); font-size: 11.5px; text-align: center; padding: 18px 0 0; }

/* ---------------------------------------------------------------- responsive */
@media (max-width: 1500px) { .kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@media (max-width: 1200px) {
  .row-map { grid-template-columns: 1fr; }
  .feed-card { height: 460px; }
  .row-3, .row-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .row-21, .row-12 { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  main { padding: 12px 16px 30px; }
  .topbar { flex-wrap: wrap; padding: 8px 16px; gap: 8px; }
  .tabs { order: 3; flex-basis: 100%; margin-left: 0; }
  .clock, .brand .host { display: none; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .row-3, .row-2, .row-4 { grid-template-columns: 1fr; }
  .map-card { min-height: 380px; }
  .legend { font-size: 11px; }
  .map-stats { display: none; }
  .map-title .sub { display: none; }
  .kv { grid-template-columns: 100px 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  .feed li, .toast { animation: none; }
  .live.on .dot { animation: none; }
}
