/* Tokens (reference palette from the dataviz method; light + dark) */
:root {
  color-scheme: light;
  --surface-1: #fcfcfb;
  --page: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #008300;
  --series-7: #4a3aa7;
  --series-8: #e34948;
  --status-good: #0ca30c;
  --status-warning: #fab219;
  --status-serious: #ec835a;
  --status-critical: #d03b3b;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --surface-1: #1a1a19;
    --page: #0d0d0d;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.1);
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #008300;
    --series-7: #9085e9;
    --series-8: #e66767;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.45;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar h1 { font-size: 17px; margin: 0; }

.filters { display: flex; gap: 12px; align-items: end; flex-wrap: wrap; }
.filters label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--text-secondary); }
.filters input { width: 230px; }
.filters input, .filters select, .filters button {
  font: inherit;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--page);
  color: var(--text-primary);
}
.filters button { cursor: pointer; background: var(--series-1); color: #fff; border: none; }
.filters button:hover { opacity: 0.9; }
.filters button.secondary { background: var(--page); color: var(--text-primary); border: 1px solid var(--border); }

/* ---- App shell: full-height brand sidebar + content column ---- */
/* Sidebar palette is fixed (not theme-dependent), derived from the EW logo:
   #002d37 wordmark navy (lifted slightly so it reads as teal instead of black,
   and stays distinct from the near-black page in dark mode) + #e52420 red. */
:root {
  --side-bg: #0a333e;
  --side-bg-soft: #12444f;
  --side-line: rgba(255, 255, 255, 0.09);
  --side-text: #ffffff;
  --side-dim: #9fb8c0;
  --side-faint: #6f8e98;
  --side-hover: rgba(255, 255, 255, 0.06);
  --side-active: rgba(255, 255, 255, 0.11);
  --side-accent: #e52420;
}

.shell {
  display: grid;
  grid-template-columns: 282px minmax(0, 1fr);
  min-height: 100vh;
}
.content { min-width: 0; display: flex; flex-direction: column; }

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--side-bg);
  color: var(--side-text);
  padding-bottom: 28px;
  scrollbar-width: thin;
  scrollbar-color: var(--side-faint) transparent;
}
.sidebar::-webkit-scrollbar { width: 8px; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.14); border-radius: 4px; }

/* Header: red logo tile + product name */
.side-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 18px 20px;
  border-bottom: 1px solid var(--side-line);
  margin-bottom: 14px;
}
.side-logo {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: var(--side-accent);
  color: #fff;
  display: grid;
  place-items: center;
  box-shadow: 0 2px 10px rgba(229, 36, 32, 0.35);
}
.side-logo svg { width: 22px; height: 22px; }
.side-id { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.side-id strong { font-size: 16px; font-weight: 700; letter-spacing: -0.01em; }
.side-id small { font-size: 12.5px; color: var(--side-dim); }

.side-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--side-faint);
  margin: 0 0 8px;
  padding: 0 8px;
}

/* Nav */
.side-nav { padding: 0 12px 6px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  font: inherit;
  font-size: 13.5px;
  text-align: left;
  padding: 9px 11px;
  margin-bottom: 2px;
  border: none;
  border-radius: 9px;
  background: none;
  color: var(--side-dim);
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}
.nav-item svg { width: 18px; height: 18px; flex: 0 0 auto; }
.nav-item span { flex: 1; min-width: 0; }
.nav-item:hover { background: var(--side-hover); color: var(--side-text); }
.nav-item.active { background: var(--side-active); color: var(--side-text); font-weight: 500; }
.nav-badge:empty { display: none; }
.nav-badge {
  font-style: normal;
  font-size: 11px;
  font-weight: 600;
  min-width: 19px;
  text-align: center;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--side-accent);
  color: #fff;
}
.nav-badge.quiet { background: rgba(255, 255, 255, 0.16); color: var(--side-dim); }

/* Sidebar footer: live scanner state */
.side-foot { margin-top: 14px; padding: 12px 20px 0; border-top: 1px solid var(--side-line); }
.side-foot-row { font-size: 11px; color: var(--side-faint); line-height: 1.5; }
.side-foot-row strong { color: var(--side-dim); font-weight: 600; }
.side-foot-row .dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  margin-right: 6px;
  background: #1baf7a;
}
.side-foot-row .dot.warn { background: #eda100; }
.side-foot-row .dot.bad { background: var(--side-accent); }
.side-label-gap { margin-top: 18px; }

/* ---- Views: one tab at a time ---- */
.view { display: none; }
.view.active { display: block; }
.view-head { margin-bottom: 18px; }
.view-head h2 { font-size: 20px; margin: 0 0 3px; letter-spacing: -0.01em; }
.view-head p { margin: 0; font-size: 13px; color: var(--text-secondary); max-width: 78ch; }

/* ---- Whitelist view (content area: uses the page theme, not the sidebar) ---- */
/* align-items: start so each panel keeps its own height instead of stretching
   to match the tallest one and leaving dead space. */
.wl-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  align-items: start;
  gap: 12px;
  margin-bottom: 12px;
}

.wl-form { display: flex; flex-direction: column; gap: 10px; }
.wl-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--text-secondary);
}
.wl-form label .opt { color: var(--text-muted); font-weight: 400; }
.wl-form input {
  font: inherit;
  font-size: 13px;
  padding: 8px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--page);
  color: var(--text-primary);
  width: 100%;
}
.wl-form input::placeholder { color: var(--text-muted); }
.wl-form input:focus {
  outline: none;
  border-color: color-mix(in srgb, var(--series-1) 55%, transparent);
}
.wl-detected:empty { display: none; }
.wl-detected {
  font-size: 12px;
  color: color-mix(in srgb, var(--status-good) 78%, var(--text-primary));
  line-height: 1.35;
}
.wl-form button { align-self: start; }

.wl-tip { font-size: 12px; color: var(--text-muted); line-height: 1.5; margin: 12px 0 0; }
.wl-tip code {
  font-family: ui-monospace, Menlo, monospace;
  font-size: 11.5px;
  background: var(--page);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0 4px;
}

/* Buttons (shared: sidebar + content) */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  padding: 8px 13px;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, opacity 0.12s;
  white-space: nowrap;
}
.btn svg { width: 15px; height: 15px; flex: 0 0 auto; }
.btn-accent { background: var(--series-1); color: #fff; }
.btn-accent:hover { background: color-mix(in srgb, var(--series-1) 88%, #000); }
.btn-ghost { background: var(--surface-1); color: var(--text-primary); border-color: var(--border); }
.btn-ghost:hover { background: var(--page); }
.btn-danger { background: var(--side-accent); color: #fff; }
.btn-danger:hover { background: #cf1f1c; }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn[data-armed] { background: #f0a800; color: #1a1500; border-color: transparent; }

.wl-msg:empty { display: none; }
.wl-msg { font-size: 12.5px; padding: 8px 10px; border-radius: 7px; line-height: 1.4; }
.wl-msg.err { background: color-mix(in srgb, var(--status-critical) 15%, var(--surface-1)); color: var(--text-primary); }
.wl-msg.ok { background: color-mix(in srgb, var(--status-good) 15%, var(--surface-1)); color: var(--text-primary); }

.wl-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.wl-progress:empty, .wl-note:empty { display: none; }
.wl-progress { font-size: 12.5px; font-weight: 500; margin-top: 10px; line-height: 1.45; }
.wl-note {
  font-size: 12px;
  color: var(--text-secondary);
  background: color-mix(in srgb, var(--status-warning) 13%, var(--surface-1));
  border: 1px solid color-mix(in srgb, var(--status-warning) 38%, transparent);
  border-radius: 7px;
  padding: 8px 10px;
  margin-bottom: 10px;
  line-height: 1.45;
}

/* Type pill in the entries table */
.kind {
  display: inline-block;
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 2px 7px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  white-space: nowrap;
}
.kind.ua { border-color: color-mix(in srgb, var(--series-4) 55%, transparent); color: color-mix(in srgb, var(--series-4) 80%, var(--text-primary)); }
.kind.ip, .kind.cidr { border-color: color-mix(in srgb, var(--status-good) 50%, transparent); color: color-mix(in srgb, var(--status-good) 80%, var(--text-primary)); }
.btn-del {
  font: inherit;
  font-size: 15px;
  line-height: 1;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 5px;
}
.btn-del:hover { color: var(--status-critical); background: color-mix(in srgb, var(--status-critical) 12%, transparent); }

main { min-width: 0; padding: 20px 24px 60px; flex: 1; }

@media (max-width: 900px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: static; height: auto; max-height: none; }
  .side-nav { display: flex; flex-wrap: wrap; gap: 4px; }
  .side-nav .side-label { width: 100%; }
  .nav-item { width: auto; }
  .nav-item span { flex: 0 0 auto; }
}
section { margin-bottom: 34px; }
h2 { font-size: 15px; margin: 0 0 12px; color: var(--text-primary); }

.warnings:empty { display: none; }
.warnings {
  background: color-mix(in srgb, var(--status-warning) 14%, var(--surface-1));
  border: 1px solid color-mix(in srgb, var(--status-warning) 40%, transparent);
  border-radius: 8px;
  padding: 8px 12px;
  margin-bottom: 12px;
  color: var(--text-secondary);
  font-size: 12.5px;
}
.warnings div { margin: 2px 0; }

.scan-progress:empty { display: none; }
.scan-progress {
  background: color-mix(in srgb, var(--series-1) 10%, var(--surface-1));
  border: 1px solid color-mix(in srgb, var(--series-1) 30%, transparent);
  border-radius: 8px;
  padding: 8px 12px;
  margin-bottom: 12px;
  color: var(--text-secondary);
  font-size: 12.5px;
}
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: color-mix(in srgb, var(--series-1) 7%, transparent); }

/* Attention cards */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 12px; }
.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-left: 4px solid var(--text-muted);
  border-radius: 10px;
  padding: 12px 14px;
}
.card.critico { border-left-color: var(--status-critical); }
.card.aviso { border-left-color: var(--status-warning); }
.card.info { border-left-color: var(--text-muted); }
.card .zona { font-size: 11.5px; color: var(--text-muted); }
.card .titulo { font-weight: 600; margin: 2px 0 4px; }
.card .titulo .badge { font-size: 11px; font-weight: 600; margin-right: 6px; }
.card.critico .badge { color: var(--status-critical); }
.card.aviso .badge { color: color-mix(in srgb, var(--status-warning) 70%, var(--text-primary)); }
.card.info .badge { color: var(--text-muted); }
.card .detalle { color: var(--text-secondary); font-size: 13px; }
.card .metrica { margin-top: 6px; font-size: 12.5px; color: var(--text-primary); font-weight: 600; }
.card.ok { border-left-color: var(--status-good); }

/* Rule cards */
.cards.rules { grid-template-columns: repeat(auto-fill, minmax(420px, 1fr)); }
.card .accion { display: inline-block; font-size: 11px; font-weight: 600; padding: 1px 8px; border-radius: 999px; border: 1px solid var(--border); color: var(--text-secondary); margin-left: 6px; }
.card pre.expr {
  background: var(--page);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  overflow-x: auto;
  font-family: ui-monospace, Menlo, monospace;
  font-size: 11.5px;
  white-space: pre-wrap;
  word-break: break-all;
  margin: 8px 0 6px;
}
.card .copy-btn {
  font: inherit;
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-primary);
  cursor: pointer;
}
.card .copy-btn:hover { background: var(--page); }
.card .donde { font-size: 11.5px; color: var(--text-muted); margin-top: 6px; }
.card .deploy-btn { margin-left: 6px; border-color: color-mix(in srgb, var(--series-1) 50%, transparent); }
.card .deploy-btn[data-armed] { background: color-mix(in srgb, var(--status-warning) 20%, var(--surface-1)); }
.card .deploy-progress:empty { display: none; }
.card .zones-detail:empty { display: none; }
.card .zones-detail { margin-top: 8px; }
.card .zones-table { max-height: 320px; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; }
.card .deploy-progress { margin-top: 6px; font-size: 12.5px; font-weight: 600; }
.card ul.zonas { margin: 6px 0 0; padding-left: 18px; font-size: 12px; color: var(--text-secondary); }
td .trend-up { color: var(--status-critical); font-weight: 600; }
td .trend-down { color: var(--status-good); font-weight: 600; }
td .trend-flat { color: var(--text-muted); }

/* Stat tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 14px; }
.tile { background: var(--surface-1); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; }
.tile .label { font-size: 12px; color: var(--text-secondary); }
.tile .value { font-size: 26px; font-weight: 600; margin-top: 2px; }
.tile .sub { font-size: 11.5px; color: var(--text-muted); margin-top: 2px; }

/* Panels & charts */
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 12px; margin-bottom: 12px; }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; margin-bottom: 12px; }
.panel {
  margin: 0;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  min-width: 0;
}
.panel.wide { grid-column: 1 / -1; }
.panel figcaption { font-size: 12.5px; color: var(--text-secondary); margin-bottom: 8px; }
.chart-box { position: relative; height: 260px; }
.chart-box.small { height: 220px; }
.chart-box.tall { height: 380px; }

/* Tables */
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
th {
  text-align: left;
  color: var(--text-muted);
  font-weight: 500;
  border-bottom: 1px solid var(--axis);
  padding: 6px 8px;
  white-space: nowrap;
}
td { padding: 6px 8px; border-bottom: 1px solid var(--grid); vertical-align: top; }
td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td .mono { font-family: ui-monospace, Menlo, monospace; font-size: 12px; }
td .pill {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 11.5px;
  border: 1px solid var(--border);
  white-space: nowrap;
}
.empty { color: var(--text-muted); padding: 14px 0; }

footer { text-align: center; color: var(--text-muted); font-size: 12px; padding: 20px; }

.loading { opacity: 0.55; transition: opacity 0.2s; }

/* ---- Domain restrictions view ---- */
.dom-picker {
  display: flex;
  align-items: end;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.dom-picker label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-secondary); }
.dom-picker input {
  font: inherit;
  font-size: 13px;
  padding: 8px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--page);
  color: var(--text-primary);
  min-width: 320px;
}
.dom-meta { font-size: 12px; color: var(--text-muted); padding-bottom: 8px; }
.dom-meta strong { color: var(--text-primary); }

.dom-quota {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  font-weight: 600;
  padding: 2px 9px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--text-secondary);
}
.dom-quota.full { border-color: color-mix(in srgb, var(--status-critical) 55%, transparent); color: var(--status-critical); }

/* Rule rows */
.rule-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: start;
  padding: 10px 0;
  border-bottom: 1px solid var(--grid);
}
.rule-row:last-child { border-bottom: none; }
.rule-row.off { opacity: 0.55; }
.rule-row .rr-main { min-width: 0; }
.rule-row .rr-desc { font-weight: 500; font-size: 13px; word-break: break-word; }
.rule-row .rr-expr {
  font-family: ui-monospace, Menlo, monospace;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 3px;
  word-break: break-all;
  max-height: 3.2em;
  overflow: hidden;
}
.rule-row .rr-tags { display: flex; gap: 6px; align-items: center; margin-top: 5px; flex-wrap: wrap; }
.rule-row .pos {
  font-size: 11px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  min-width: 22px;
  padding-top: 2px;
}

/* Switch */
.switch { position: relative; display: inline-block; width: 40px; height: 22px; flex: 0 0 auto; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch .track {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: var(--axis);
  transition: background 0.15s;
  pointer-events: none;
}
.switch .track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.15s;
}
.switch input:checked + .track { background: var(--status-good); }
.switch input:checked + .track::after { transform: translateX(18px); }
.switch input:disabled + .track { opacity: 0.5; }

.dom-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(330px, 1fr)); align-items: start; gap: 12px; margin-top: 12px; }
.dom-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.dom-msg:empty { display: none; }
.dom-msg { font-size: 12.5px; margin-top: 10px; padding: 8px 10px; border-radius: 7px; line-height: 1.45; }
.dom-msg.ok { background: color-mix(in srgb, var(--status-good) 15%, var(--surface-1)); }
.dom-msg.err { background: color-mix(in srgb, var(--status-critical) 15%, var(--surface-1)); }
.dom-tpl { display: flex; flex-direction: column; gap: 7px; }
.dom-tpl-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 12.5px; }
.dom-tpl-row .name { min-width: 0; }
textarea.dom-list {
  font-family: ui-monospace, Menlo, monospace;
  font-size: 12px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--page);
  color: var(--text-primary);
  width: 100%;
  min-height: 76px;
  resize: vertical;
}
.dom-radio { display: flex; gap: 14px; font-size: 12.5px; color: var(--text-secondary); margin-top: 8px; }
.dom-radio label { display: flex; align-items: center; gap: 5px; }

/* Sidebar footer: signed-in user */
.side-user:empty { display: none; }
.side-user {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--side-line);
  font-size: 11.5px;
  color: var(--side-dim);
  min-width: 0;
}
.side-user img { width: 24px; height: 24px; border-radius: 50%; flex: 0 0 auto; }
.side-user .who { flex: 1; min-width: 0; line-height: 1.3; }
.side-user .who strong { display: block; color: var(--side-text); font-weight: 600; font-size: 12px; }
.side-user .who span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 10.5px; }
.side-user a { color: var(--side-faint); text-decoration: none; flex: 0 0 auto; }
.side-user a:hover { color: var(--side-accent); }
