/* =============================================================================
   LUNEXUS Monitor — estilos del dashboard
   Tokens por rol; el modo oscuro tiene sus propios pasos (no es una inversión).
   ========================================================================== */

:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface-1: #fcfcfb;
  --surface-2: #f3f2ee;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #6f6d68;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --border-strong: rgba(11, 11, 11, 0.18);
  --hover: rgba(11, 11, 11, 0.04);
  --accent: #256abf;
  --accent-ink: #ffffff;
  --accent-soft: #cde2fb;
  --focus: #2a78d6;

  /* Series categóricas (orden fijo, validado) */
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #008300;
  --series-7: #4a3aa7;
  --series-8: #e34948;

  /* Estado (reservados, siempre con ícono + texto) */
  --status-good: #0ca30c;
  --status-warning: #fab219;
  --status-serious: #ec835a;
  --status-critical: #d03b3b;
  --status-unknown: #898781;
  --status-good-ink: #006300;
  --status-warning-ink: #7a5200;
  --status-critical-ink: #a32323;

  --meter-track: #e6eefa;
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.04), 0 4px 16px rgba(11, 11, 11, 0.04);
  --radius: 10px;
  --radius-sm: 6px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface-1: #1a1a19;
    --surface-2: #222220;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #9a988f;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --border-strong: rgba(255, 255, 255, 0.18);
    --hover: rgba(255, 255, 255, 0.05);
    --accent: #3987e5;
    --accent-ink: #0b0b0b;
    --accent-soft: #184f95;
    --focus: #5598e7;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #008300;
    --series-7: #9085e9;
    --series-8: #e66767;
    --status-good-ink: #0ca30c;
    --status-warning-ink: #fab219;
    --status-critical-ink: #ef6b6b;
    --meter-track: #1f2b3b;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface-1: #1a1a19;
  --surface-2: #222220;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #9a988f;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --border-strong: rgba(255, 255, 255, 0.18);
  --hover: rgba(255, 255, 255, 0.05);
  --accent: #3987e5;
  --accent-ink: #0b0b0b;
  --accent-soft: #184f95;
  --focus: #5598e7;
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --series-5: #d55181;
  --series-6: #008300;
  --series-7: #9085e9;
  --series-8: #e66767;
  --status-good-ink: #0ca30c;
  --status-warning-ink: #fab219;
  --status-critical-ink: #ef6b6b;
  --meter-track: #1f2b3b;
  --shadow: none;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  font: 14px/1.5 var(--font);
  min-height: 100vh;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; font-weight: 650; }
h2 { font-size: 15px; font-weight: 600; }
h3 { font-size: 13px; font-weight: 600; }
[hidden] { display: none !important; }
.muted { color: var(--text-muted); }
.secondary { color: var(--text-secondary); }
.num { font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip-link { position: absolute; left: -999px; top: 8px; background: var(--surface-1); padding: 8px 12px; z-index: 100; }
.skip-link:focus { left: 8px; }
.boot { padding: 48px 16px; text-align: center; color: var(--text-muted); }
code, .mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 12.5px; }

/* ---------- Top bar ---------- */
.topbar { position: sticky; top: 0; z-index: 20; background: var(--surface-1); border-bottom: 1px solid var(--border); }
.topbar__inner { max-width: 1320px; margin: 0 auto; padding: 0 16px; height: 56px; display: flex; align-items: center; gap: 24px; }
.brand { display: flex; align-items: center; gap: 8px; color: var(--text-primary); font-size: 15px; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand strong { font-weight: 650; }
.nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.nav a { color: var(--text-secondary); padding: 6px 10px; border-radius: var(--radius-sm); white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; }
.nav a:hover { background: var(--hover); text-decoration: none; color: var(--text-primary); }
.nav a[aria-current="page"] { color: var(--text-primary); background: var(--surface-2); font-weight: 600; }
.nav__badge { background: var(--status-critical); color: #fff; font-size: 11px; font-weight: 700; border-radius: 999px; padding: 0 6px; line-height: 18px; min-width: 18px; text-align: center; }
.topbar__right { display: flex; align-items: center; gap: 8px; }
.user-chip { color: var(--text-secondary); font-size: 13px; white-space: nowrap; }
@media (max-width: 720px) {
  .topbar__inner { gap: 12px; height: auto; min-height: 56px; flex-wrap: wrap; padding-top: 8px; padding-bottom: 8px; }
  .nav { order: 3; flex-basis: 100%; }
  .brand span { display: none; }
  .topbar__right { margin-left: auto; }
  .user-chip { display: none; }
}

/* ---------- Layout ---------- */
.main { max-width: 1320px; margin: 0 auto; padding: 24px 16px 64px; outline: none; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head__title { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.page-head__title h1 { overflow-wrap: anywhere; }
.page-head__meta { display: flex; flex-wrap: wrap; gap: 4px 16px; color: var(--text-secondary); font-size: 13px; }
.back-link { font-size: 13px; color: var(--text-secondary); display: inline-flex; gap: 4px; align-items: center; }
.section { margin-top: 24px; }
.section__head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.grid { display: grid; gap: 16px; }
.grid--charts { grid-template-columns: repeat(auto-fit, minmax(min(100%, 520px), 1fr)); }
.grid--2 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); }

.card { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); min-width: 0; }
.card__head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px 0; flex-wrap: wrap; }
.card__sub { color: var(--text-muted); font-size: 12px; margin-top: 2px; }
.card__body { padding: 12px 16px 16px; }
.card--pad { padding: 16px; }

/* ---------- Filtros (una fila, arriba de lo que filtran) ---------- */
.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-bottom: 16px; }
.filters__spacer { flex: 1; }
.segmented { display: inline-flex; background: var(--surface-2); border-radius: 8px; padding: 2px; gap: 2px; flex-wrap: wrap; }
.segmented button { border: 0; background: transparent; color: var(--text-secondary); font: inherit; font-size: 13px; padding: 5px 12px; border-radius: 6px; cursor: pointer; }
.segmented button:hover { color: var(--text-primary); }
.segmented button[aria-pressed="true"] { background: var(--surface-1); color: var(--text-primary); font-weight: 600; box-shadow: 0 0 0 1px var(--border); }
.refresh-note { color: var(--text-muted); font-size: 12px; }

/* ---------- Formularios y botones ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-size: 13px; font-weight: 550; border-radius: var(--radius-sm); border: 1px solid transparent; padding: 7px 14px; cursor: pointer; background: var(--accent); color: var(--accent-ink); white-space: nowrap; }
.btn:hover { filter: brightness(1.08); }
.btn:disabled { opacity: .55; cursor: not-allowed; filter: none; }
.btn--ghost { background: transparent; color: var(--text-primary); border-color: var(--border-strong); }
.btn--ghost:hover { background: var(--hover); filter: none; }
.btn--danger { background: transparent; color: var(--status-critical-ink); border-color: var(--status-critical); }
.btn--danger:hover { background: rgba(208, 59, 59, .08); filter: none; }
.btn--sm { padding: 4px 10px; font-size: 12.5px; }
.btn--block { width: 100%; }
.icon-btn { border: 0; background: transparent; color: var(--text-secondary); width: 34px; height: 34px; border-radius: 8px; cursor: pointer; display: inline-grid; place-items: center; }
.icon-btn:hover { background: var(--hover); color: var(--text-primary); }
.link-btn { border: 0; background: none; padding: 0; font: inherit; color: var(--accent); cursor: pointer; }
.link-btn:hover { text-decoration: underline; }

.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field label, .field__label { font-size: 12.5px; font-weight: 550; color: var(--text-secondary); }
.field__hint { font-size: 12px; color: var(--text-muted); }
.input, .select, .textarea {
  font: inherit; font-size: 14px; color: var(--text-primary); background: var(--surface-1);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm); padding: 7px 10px; width: 100%; min-width: 0;
}
.select { width: auto; padding-right: 28px; }
.textarea { min-height: 72px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus { outline: 2px solid var(--focus); outline-offset: -1px; border-color: transparent; }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-secondary); }
.form-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr)); align-items: end; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 16px; }
.form-error { color: var(--status-critical-ink); font-size: 13px; margin-top: 8px; }

/* ---------- Estado: ícono + etiqueta, nunca solo color ---------- */
.status { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 550; white-space: nowrap; color: var(--text-primary); }
.status svg { flex: none; }
.status--good svg { color: var(--status-good); }
.status--warning svg { color: var(--status-warning); }
.status--serious svg { color: var(--status-serious); }
.status--critical svg { color: var(--status-critical); }
.status--unknown svg { color: var(--status-unknown); }
.pill { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); color: var(--text-secondary); white-space: nowrap; }
.pill--critical { background: rgba(208, 59, 59, .12); color: var(--status-critical-ink); }
.pill--warning { background: rgba(250, 178, 25, .16); color: var(--status-warning-ink); }
.pill--good { background: rgba(12, 163, 12, .12); color: var(--status-good-ink); }

/* ---------- Stat tiles ---------- */
.tiles { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 160px), 1fr)); margin-bottom: 16px; }
.tile { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); min-width: 0; }
.tile__label { color: var(--text-secondary); font-size: 13px; display: flex; align-items: center; gap: 6px; }
.tile__value { font-size: 28px; font-weight: 650; margin-top: 4px; line-height: 1.1; }
.tile__foot { color: var(--text-muted); font-size: 12px; margin-top: 4px; }
button.tile { font: inherit; text-align: left; cursor: pointer; color: inherit; }
button.tile:hover { border-color: var(--border-strong); }
button.tile[aria-pressed="true"] { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }

/* ---------- Medidor (meter) ---------- */
.meter { display: grid; grid-template-columns: minmax(48px, 1fr) auto; align-items: center; gap: 8px; min-width: 110px; }
.meter__track { height: 6px; background: var(--meter-track); border-radius: 999px; overflow: hidden; }
.meter__fill { height: 100%; border-radius: 999px; background: var(--series-1); }
.meter__fill--warning { background: var(--status-warning); }
.meter__fill--critical { background: var(--status-critical); }
.meter__value { font-size: 13px; font-variant-numeric: tabular-nums; min-width: 44px; text-align: right; }

/* ---------- Tablas ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th { text-align: left; font-weight: 550; color: var(--text-muted); font-size: 12px; padding: 8px 12px; border-bottom: 1px solid var(--grid); white-space: nowrap; }
.table td { padding: 10px 12px; border-bottom: 1px solid var(--grid); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table tbody tr.is-clickable { cursor: pointer; }
.table tbody tr.is-clickable:hover { background: var(--hover); }
.table .cell-title { font-weight: 600; color: var(--text-primary); }
.table .cell-sub { color: var(--text-muted); font-size: 12px; }
.empty { padding: 32px 16px; text-align: center; color: var(--text-muted); }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }

/* Servidores en tarjetas en móvil */
@media (max-width: 760px) {
  .table--responsive thead { display: none; }
  .table--responsive tr { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px; padding: 12px; border-bottom: 1px solid var(--grid); }
  .table--responsive td { border: 0; padding: 0; }
  .table--responsive td[data-label]::before { content: attr(data-label); display: block; color: var(--text-muted); font-size: 11.5px; }
  .table--responsive td.cell-main { grid-column: 1 / -1; }
  .table--responsive td.num { text-align: left; }
}

/* ---------- Gráficas ---------- */
.chart { position: relative; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart.is-loading { opacity: .5; transition: opacity .15s; }
.chart__grid { stroke: var(--grid); stroke-width: 1; shape-rendering: crispEdges; }
.chart__baseline { stroke: var(--axis); stroke-width: 1; shape-rendering: crispEdges; }
.chart__tick { fill: var(--text-muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart__line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart__area { stroke: none; opacity: .10; }
.chart__dot { stroke: var(--surface-1); stroke-width: 2; }
.chart__endlabel { fill: var(--text-secondary); font-size: 11.5px; font-variant-numeric: tabular-nums; }
.chart__threshold { stroke-width: 1; shape-rendering: crispEdges; }
.chart__threshold-label { fill: var(--text-muted); font-size: 10.5px; }
.chart__crosshair { stroke: var(--text-muted); stroke-width: 1; shape-rendering: crispEdges; pointer-events: none; }
.chart__overlay { fill: transparent; cursor: crosshair; outline: none; }
.chart__overlay:focus-visible { stroke: var(--focus); stroke-width: 2; }
.chart__empty { fill: var(--text-muted); font-size: 13px; }
.chart-tooltip {
  position: absolute; pointer-events: none; z-index: 5; min-width: 150px; max-width: 260px;
  background: var(--surface-1); border: 1px solid var(--border-strong); border-radius: 8px; box-shadow: 0 6px 24px rgba(0,0,0,.14);
  padding: 8px 10px; font-size: 12px;
}
.chart-tooltip__time { color: var(--text-muted); margin-bottom: 4px; }
.chart-tooltip__row { display: grid; grid-template-columns: 14px auto 1fr; align-items: center; gap: 6px; line-height: 1.6; }
.chart-tooltip__row strong { font-size: 13px; font-variant-numeric: tabular-nums; color: var(--text-primary); }
.chart-tooltip__row span { color: var(--text-secondary); }
.line-key { width: 14px; height: 2px; border-radius: 2px; display: inline-block; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12px; color: var(--text-secondary); }
.legend__item { display: inline-flex; align-items: center; gap: 6px; }
.chart-table { max-height: 280px; overflow: auto; margin-top: 8px; border-top: 1px solid var(--grid); }
.chart-table .table td, .chart-table .table th { padding: 5px 10px; font-size: 12.5px; }
.chart-table .table th { position: sticky; top: 0; background: var(--surface-1); }

/* ---------- Alertas ---------- */
.timeline { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.timeline li { display: grid; grid-template-columns: 12px 1fr; gap: 10px; font-size: 13px; }
.timeline__dot { width: 8px; height: 8px; border-radius: 50%; background: var(--axis); margin-top: 6px; }
.timeline__meta { color: var(--text-muted); font-size: 12px; }

/* ---------- Diálogo ---------- */
dialog.modal { border: 1px solid var(--border); border-radius: 12px; padding: 0; background: var(--surface-1); color: var(--text-primary); width: min(640px, calc(100vw - 32px)); max-height: calc(100vh - 48px); box-shadow: 0 24px 64px rgba(0,0,0,.25); }
dialog.modal::backdrop { background: rgba(0, 0, 0, .45); }
.modal__head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px 0; gap: 12px; }
.modal__body { padding: 16px 20px 20px; overflow: auto; }
.secret-box { display: flex; gap: 8px; align-items: stretch; margin: 8px 0 4px; }
.secret-box code, .code-block { flex: 1; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 10px; overflow-x: auto; white-space: pre; display: block; }
.code-block { margin: 6px 0 12px; font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 12px; }
.callout { border-left: 3px solid var(--status-warning); background: rgba(250, 178, 25, .10); padding: 8px 12px; border-radius: 0 6px 6px 0; font-size: 13px; margin: 8px 0 12px; }
.callout--info { border-left-color: var(--accent); background: rgba(42, 120, 214, .08); }

/* ---------- Login ---------- */
.login { min-height: calc(100vh - 80px); display: grid; place-items: center; padding: 24px 0; }
.login__card { width: min(380px, 100%); padding: 28px; }
.login__brand { display: flex; align-items: center; gap: 10px; margin-bottom: 20px; font-size: 17px; }
.login__brand strong { font-weight: 650; }
.login form { display: flex; flex-direction: column; gap: 14px; }

/* ---------- Toasts ---------- */
.toast-region { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 50; max-width: calc(100vw - 32px); }
.toast { background: var(--text-primary); color: var(--page); padding: 10px 14px; border-radius: 8px; font-size: 13px; box-shadow: 0 8px 24px rgba(0,0,0,.2); max-width: 380px; }
.toast--error { background: var(--status-critical); color: #fff; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
@media (forced-colors: active) {
  .meter__fill, .chart__line { forced-color-adjust: none; }
}

/* ---------- Manual ---------- */
.help-btn__icon { display: inline-grid; place-items: center; width: 18px; height: 18px; border-radius: 50%; border: 1.5px solid currentColor; font-size: 11px; font-weight: 700; line-height: 1; }
.help-btn[aria-current="page"] { background: var(--surface-2); }
.help-toc { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.help-toc a { display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px 6px 6px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface-1); color: var(--text-primary); font-size: 13px; }
.help-toc a:hover { border-color: var(--border-strong); text-decoration: none; }
.help-toc__n, .help-step__n { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); font-size: 12px; font-weight: 700; flex: none; }
.help-section { margin-bottom: 16px; scroll-margin-top: 72px; }
.help-section > h2 { font-size: 17px; margin-bottom: 4px; }
.help-section > p { margin: 4px 0 12px; max-width: 72ch; }
.help-steps { list-style: none; margin: 12px 0 0; padding: 0; display: flex; flex-direction: column; gap: 18px; }
.help-step { display: grid; grid-template-columns: 22px minmax(0, 1fr); gap: 12px; }
.help-step__body h3 { font-size: 14px; margin: 1px 0 4px; }
.help-step__body p { margin: 4px 0 6px; max-width: 72ch; }
.help-sub { margin: 20px 0 4px; }
.help-code { position: relative; }
.help-code .code-block { padding-right: 76px; }
.help-code__copy { position: absolute; top: 6px; right: 6px; background: var(--surface-1); }
.help-table { margin: 8px 0 4px; }
.help-table td { vertical-align: top; }
.help-foot { display: flex; align-items: center; gap: 6px; }
@media (max-width: 720px) {
  .help-btn { padding: 4px 8px; }
}
.help-table td { overflow-wrap: anywhere; }
.help-section { min-width: 0; overflow-wrap: anywhere; }
