/* ─── Tokens ────────────────────────────────────────────────────────────
   Paleta de datos validada en ambos modos contra sus superficies
   (#fcfcfb claro, #1a1a19 oscuro). Los slots se asignan en orden fijo. */
:root,
:root[data-bs-theme="light"] {
  color-scheme: light;
  --page: #f3f3f1;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --surface-hover: #eeede9;
  --border: rgba(11, 11, 11, 0.09);
  --border-strong: rgba(11, 11, 11, 0.16);
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #898781;
  --accent: #2a78d6;
  --accent-soft: rgba(42, 120, 214, 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;

  --viz-grid: #e1e0d9;
  --viz-axis: #c3c2b7;
  --viz-muted: #898781;
  --meter-track: #cde2fb;

  --good: #0ca30c;
  --good-text: #006300;
  --warning: #fab219;
  --warning-text: #8a5a00;
  --serious: #ec835a;
  --critical: #d03b3b;
  --critical-text: #b42323;
  --good-soft: rgba(12, 163, 12, 0.1);
  --warning-soft: rgba(250, 178, 25, 0.14);
  --critical-soft: rgba(208, 59, 59, 0.1);
}

:root[data-bs-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #232321;
  --surface-hover: #262624;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.15);
  --text: #f5f5f3;
  --text-2: #c3c2b7;
  --muted: #898781;
  --accent: #3987e5;
  --accent-soft: rgba(57, 135, 229, 0.14);

  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --series-5: #d55181;
  --series-6: #008300;
  --series-7: #9085e9;
  --series-8: #e66767;

  --viz-grid: #2c2c2a;
  --viz-axis: #383835;
  --meter-track: #184f95;

  --good-text: #3fcf3f;
  --warning-text: #fab219;
  --critical-text: #f07a7a;
  --good-soft: rgba(12, 163, 12, 0.16);
  --warning-soft: rgba(250, 178, 25, 0.13);
  --critical-soft: rgba(208, 59, 59, 0.18);
}

/* Bootstrap hereda los tokens para que modales, tablas y formularios casen. */
:root[data-bs-theme] {
  --bs-body-bg: var(--page);
  --bs-body-color: var(--text);
  --bs-secondary-color: var(--text-2);
  --bs-tertiary-color: var(--muted);
  --bs-border-color: var(--border);
  --bs-border-color-translucent: var(--border);
  --bs-secondary-bg: var(--surface-2);
  --bs-tertiary-bg: var(--surface-2);
  --bs-emphasis-color: var(--text);
  --bs-link-color: var(--accent);
  --bs-link-hover-color: var(--accent);
  --bs-primary: var(--accent);
  --bs-body-font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --bs-body-font-size: 0.875rem;
  --bs-border-radius: 0.5rem;
}

body {
  min-height: 100vh;
  background: var(--page);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

a { text-decoration: none; }
a:hover { text-decoration: underline; }

.text-2 { color: var(--text-2) !important; }
.text-muted-2 { color: var(--muted) !important; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 0.8em; }
.num { font-variant-numeric: tabular-nums; }

/* ─── Cabecera ──────────────────────────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 1020;
  background: color-mix(in srgb, var(--page) 88%, transparent);
  backdrop-filter: saturate(160%) blur(10px);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: 1440px;
  margin: 0 auto;
  padding: 0.75rem 1.25rem 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text);
  white-space: nowrap;
}

.brand-mark {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: #fff;
  font-size: 0.75rem;
}

.brand-sub { color: var(--muted); font-weight: 400; }

.health-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.28rem 0.7rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 0.8rem;
  font-weight: 500;
  white-space: nowrap;
  cursor: default;
}

.health-pill[data-level="ok"] { background: var(--good-soft); border-color: transparent; color: var(--good-text); }
.health-pill[data-level="warning"] { background: var(--warning-soft); border-color: transparent; color: var(--warning-text); }
.health-pill[data-level="critical"] { background: var(--critical-soft); border-color: transparent; color: var(--critical-text); }

.live {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--muted);
  font-size: 0.78rem;
  white-space: nowrap;
}

.live-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
}

.live[data-state="on"] .live-dot { background: var(--good); animation: pulse 2s ease-in-out infinite; }
.live[data-state="off"] .live-dot { background: var(--critical); }

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--good) 55%, transparent); }
  50% { box-shadow: 0 0 0 4px transparent; }
}

@media (prefers-reduced-motion: reduce) {
  .live[data-state="on"] .live-dot { animation: none; }
}

.icon-btn {
  width: 32px;
  height: 32px;
  display: inline-grid;
  place-items: center;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
}

.icon-btn:hover { background: var(--surface-hover); color: var(--text); }

/* Pestañas: subrayado, sin cajas. */
.tabs {
  display: flex;
  gap: 1.25rem;
  margin-top: 0.7rem;
  overflow-x: auto;
  scrollbar-width: none;
}

.tabs::-webkit-scrollbar { display: none; }

.tab {
  position: relative;
  padding: 0.55rem 0 0.7rem;
  background: none;
  border: 0;
  color: var(--text-2);
  font-weight: 500;
  font-size: 0.875rem;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { color: var(--text); }

.tab[aria-selected="true"]::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 2px;
  border-radius: 2px;
  background: var(--accent);
}

.tab-count {
  min-width: 1.25rem;
  padding: 0 0.35rem;
  border-radius: 999px;
  background: var(--critical);
  color: #fff;
  font-size: 0.7rem;
  line-height: 1.25rem;
  text-align: center;
}

/* ─── Contenido ─────────────────────────────────────────────────────── */
.page {
  max-width: 1440px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
}

.view[hidden] { display: none !important; }

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin: 2rem 0 0.85rem;
}

.section-head:first-child { margin-top: 0; }

.section-title {
  margin: 0;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.panel-body { padding: 1.1rem 1.2rem; }

.panel-title {
  margin: 0 0 0.85rem;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text);
}

/* Aviso de incidencias en la parte alta del resumen. */
.issues {
  border-radius: 12px;
  padding: 0.9rem 1.1rem;
  margin-bottom: 1.25rem;
  border: 1px solid transparent;
}

.issues[data-level="critical"] { background: var(--critical-soft); }
.issues[data-level="warning"] { background: var(--warning-soft); }

.issues-title { font-weight: 600; margin-bottom: 0.35rem; }
.issues[data-level="critical"] .issues-title { color: var(--critical-text); }
.issues[data-level="warning"] .issues-title { color: var(--warning-text); }

.issues ul { margin: 0; padding-left: 1.1rem; color: var(--text-2); }
.issues li + li { margin-top: 0.15rem; }

/* ─── Indicadores ───────────────────────────────────────────────────── */
.kpi {
  height: 100%;
  padding: 1rem 1.15rem 0.9rem;
  display: flex;
  flex-direction: column;
}

.kpi-label {
  font-size: 0.78rem;
  color: var(--text-2);
  font-weight: 500;
}

.kpi-value {
  margin-top: 0.2rem;
  font-size: clamp(1.6rem, 1.2rem + 1.1vw, 2.05rem);
  font-weight: 600;
  line-height: 1.1;
  letter-spacing: -0.01em;
}

.kpi-unit { font-size: 0.55em; font-weight: 500; color: var(--text-2); margin-left: 0.15rem; }
.kpi-detail { margin-top: 0.3rem; font-size: 0.78rem; color: var(--muted); }
.kpi-trend { margin-top: auto; padding-top: 0.75rem; height: 46px; }
.kpi-trend svg { display: block; width: 100%; height: 34px; overflow: visible; }

.meter {
  margin-top: auto;
  height: 6px;
  border-radius: 999px;
  background: var(--meter-track);
  overflow: hidden;
}

.meter > span {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: var(--accent);
  transition: width 0.4s ease;
}

.meter[data-level="warning"] > span { background: var(--warning); }
.meter[data-level="critical"] > span { background: var(--critical); }
.meter-wrap { margin-top: auto; padding-top: 0.9rem; }
.meter-caption { display: flex; justify-content: space-between; margin-top: 0.4rem; font-size: 0.75rem; color: var(--muted); }

/* ─── Estado (siempre punto + texto, nunca solo color) ─────────────── */
.status {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  white-space: nowrap;
  font-size: 0.8rem;
  color: var(--text-2);
}

.dot {
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
}

.dot-good { background: var(--good); }
.dot-warning { background: var(--warning); }
.dot-critical { background: var(--critical); }
.dot-progress { background: var(--accent); animation: pulse-accent 1.4s ease-in-out infinite; }

@keyframes pulse-accent {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

/* ─── Tarjetas de aplicación ────────────────────────────────────────── */
.app-card {
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 1.05rem 1.15rem 1rem;
  transition: border-color 0.15s ease;
}

.app-card:hover { border-color: var(--border-strong); }
.app-card[data-level="critical"] { border-color: color-mix(in srgb, var(--critical) 55%, transparent); }
.app-card[data-level="warning"] { border-color: color-mix(in srgb, var(--warning) 55%, transparent); }

.app-head { display: flex; align-items: center; gap: 0.55rem; }
.app-name { font-weight: 600; font-size: 0.975rem; }
.app-link { margin-left: auto; color: var(--muted); }
.app-link:hover { color: var(--text); text-decoration: none; }

.app-domain {
  margin-top: 0.1rem;
  font-size: 0.78rem;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.5rem;
  margin-top: 0.95rem;
}

.app-stat-label { font-size: 0.72rem; color: var(--muted); }
.app-stat-value { font-size: 0.875rem; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.app-deploy {
  margin-top: 0.95rem;
  padding-top: 0.85rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  flex: 1;
}

.app-deploy-message {
  font-size: 0.8rem;
  color: var(--text-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Tira de despliegues: la forma distingue el resultado además del color
   (fallo = barra completa, correcto = barra corta), apta para daltonismo. */
.deploy-strip {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 22px;
  margin-top: auto;
}

.deploy-strip-wrap {
  margin-top: auto;
  padding-top: 0.6rem;
  display: flex;
  align-items: flex-end;
  gap: 0.75rem;
}

.deploy-strip-caption { font-size: 0.7rem; color: var(--muted); white-space: nowrap; line-height: 1; }

.deploy-strip span {
  width: 5px;
  flex: none;
  border-radius: 2px;
  background: var(--good);
  height: 50%;
  opacity: 0.8;
}

.deploy-strip span[data-status="failed"] { background: var(--critical); height: 100%; opacity: 1; }
.deploy-strip span[data-status="in_progress"],
.deploy-strip span[data-status="queued"] { background: var(--accent); height: 80%; animation: pulse-accent 1.4s ease-in-out infinite; }
.deploy-strip span[data-status="cancelled-by-user"] { background: var(--muted); height: 35%; }

/* ─── Tablas ────────────────────────────────────────────────────────── */
.table-clean {
  width: 100%;
  margin: 0;
  border-collapse: separate;
  border-spacing: 0;
}

.table-clean th {
  padding: 0.55rem 0.75rem;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  background: transparent;
}

.table-clean td {
  padding: 0.65rem 0.75rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  background: transparent;
  color: var(--text);
}

.table-clean tbody tr:last-child td { border-bottom: 0; }
.table-clean tbody tr:hover td { background: var(--surface-hover); }
.table-clean td.num, .table-clean th.num { text-align: right; font-variant-numeric: tabular-nums; }

.group-row td {
  padding-top: 1.1rem;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  background: transparent !important;
}

.cell-title { font-weight: 500; }
.cell-sub { font-size: 0.75rem; color: var(--muted); max-width: 22rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.bar-cell { display: flex; align-items: center; justify-content: flex-end; gap: 0.6rem; }

.inline-bar {
  width: 64px;
  height: 5px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
  flex: none;
}

.inline-bar > span { display: block; height: 100%; background: var(--accent); border-radius: 999px; }

/* ─── Despliegues ───────────────────────────────────────────────────── */
.chips { display: flex; flex-wrap: wrap; gap: 0.4rem; }

.chip {
  padding: 0.3rem 0.75rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  font-size: 0.8rem;
  font-weight: 500;
}

.chip:hover { color: var(--text); border-color: var(--border-strong); }
.chip[aria-pressed="true"] { background: var(--text); border-color: var(--text); color: var(--page); }

.summary-stats { display: flex; flex-wrap: wrap; gap: 1.75rem; }
.summary-stat-value { font-size: 1.35rem; font-weight: 600; line-height: 1.2; }
.summary-stat-label { font-size: 0.75rem; color: var(--muted); }

.day-label {
  padding: 1rem 1.2rem 0.45rem;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.deploy-row {
  display: grid;
  grid-template-columns: 7.5rem 7rem minmax(0, 1fr) auto auto auto auto;
  align-items: center;
  gap: 1rem;
  padding: 0.6rem 1.2rem;
  border-top: 1px solid var(--border);
}

.deploy-row:hover { background: var(--surface-hover); }
.deploy-row .deploy-app { font-weight: 500; }
.deploy-row .deploy-msg { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-2); }

.tag {
  display: inline-block;
  padding: 0.05rem 0.45rem;
  border-radius: 5px;
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 0.72rem;
  font-weight: 500;
  white-space: nowrap;
}

.sev {
  display: inline-block;
  padding: 0.05rem 0.45rem;
  border-radius: 5px;
  font-size: 0.72rem;
  font-weight: 600;
}

.sev-critical { background: var(--critical-soft); color: var(--critical-text); }
.sev-warning { background: var(--warning-soft); color: var(--warning-text); }
.sev-info { background: var(--accent-soft); color: var(--accent); }

@media (max-width: 991.98px) {
  .deploy-row { grid-template-columns: 6.5rem minmax(0, 1fr) auto; row-gap: 0.2rem; }
  .deploy-row .deploy-msg { grid-column: 1 / -1; order: 5; }
  .deploy-row .hide-md { display: none; }
}

/* ─── Actividad reciente ────────────────────────────────────────────── */
.feed { list-style: none; margin: 0; padding: 0; }

.feed li {
  display: flex;
  align-items: flex-start;
  gap: 0.7rem;
  padding: 0.65rem 0;
  border-top: 1px solid var(--border);
}

.feed li:first-child { border-top: 0; padding-top: 0; }
.feed .dot { margin-top: 0.4rem; }
.feed-main { min-width: 0; flex: 1; }
.feed-title { font-weight: 500; }
.feed-sub { font-size: 0.78rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.feed-time { font-size: 0.75rem; color: var(--muted); white-space: nowrap; }

/* ─── Gráficas y vacíos ─────────────────────────────────────────────── */
.chart-wrap { position: relative; height: 240px; }

.empty {
  padding: 2.5rem 1rem;
  text-align: center;
  color: var(--text-2);
}

.empty-icon { font-size: 1.6rem; color: var(--muted); }
.empty-title { margin-top: 0.5rem; font-weight: 600; color: var(--text); }
.empty-text { margin: 0.35rem auto 0; max-width: 32rem; font-size: 0.83rem; }

.btn-soft {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-weight: 500;
}

.btn-soft:hover { background: var(--surface-hover); border-color: var(--border-strong); color: var(--text); }

.form-select-sm { background-color: var(--surface); border-color: var(--border); }

.modal-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
}

/* ─── Acceso ────────────────────────────────────────────────────────── */
.login-body {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 1rem;
  background:
    radial-gradient(60rem 40rem at 50% -10%, var(--accent-soft), transparent 70%),
    var(--page);
}

.login-card { width: min(100%, 24rem); }
.login-card .panel { padding: 2rem 1.9rem; }

@media (max-width: 575.98px) {
  .topbar-inner { padding: 0.65rem 1rem 0; }
  .topbar-inner > .d-flex { gap: 0.6rem !important; }
  .brand-sub { display: none; }
  .health-pill { padding: 0.25rem 0.6rem; }
  .meter-caption span:last-child { display: none; }
  .page { padding: 1.1rem 1rem 2.5rem; }
  .chart-wrap { height: 200px; }
  .app-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
