:root {
  --bg: #0d1117;
  --surface: #151a22;
  --surface-2: #1b212b;
  --border: #262d38;
  --border-strong: #343c4a;
  --text: #d6dbe3;
  --text-strong: #f0f3f6;
  --muted: #7d8694;
  --ok: #3fb950;
  --ok-bg: rgba(63, 185, 80, 0.10);
  --fail: #f85149;
  --fail-bg: rgba(248, 81, 73, 0.10);
  --warn: #d29922;
  --warn-bg: rgba(210, 153, 34, 0.12);
  --idle: #4a5260;
  --accent: #4c8dff;
  --radius: 6px;
  --gap: 10px;
  font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 13px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body { overflow: hidden; -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
.num, .kpi-value, .stat-value, .row-val, .metric-val { font-variant-numeric: tabular-nums; }
code { font-family: ui-monospace, 'SF Mono', Consolas, monospace; font-size: 12px; color: var(--text); background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }

/* ---------- Controles ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 12px;
  background: var(--surface-2); color: var(--text); border: 1px solid var(--border-strong);
  border-radius: var(--radius); font: inherit; font-weight: 500; cursor: pointer;
}
.btn:hover { background: #222a35; color: var(--text-strong); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #3d7bea; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--text-strong); background: var(--surface-2); }
.btn.danger-text { background: transparent; border-color: var(--border); color: var(--muted); }
.btn.danger-text:hover { color: var(--fail); border-color: var(--fail); background: transparent; }
input {
  width: 100%; height: 34px; padding: 0 10px; background: var(--bg); color: var(--text-strong);
  border: 1px solid var(--border-strong); border-radius: var(--radius); font: inherit; outline: none;
}
input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(76, 141, 255, .18); }
label { display: flex; flex-direction: column; gap: 6px; font-size: 12px; font-weight: 500; color: var(--muted); }
.form-error { color: var(--fail); min-height: 1.2em; margin: 8px 0 0; font-size: 12px; }
.divider { width: 1px; height: 22px; background: var(--border); }
.brand { font-weight: 600; font-size: 15px; color: var(--text-strong); letter-spacing: .2px; }

/* ---------- Login ---------- */
.login-view { height: 100%; display: grid; place-items: center; }
.login-card {
  width: min(360px, 92vw); padding: 28px; display: flex; flex-direction: column; gap: 16px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
}
.login-head { margin-bottom: 4px; }
.login-head p { margin: 4px 0 0; color: var(--muted); }
.login-card .btn { height: 36px; justify-content: center; margin-top: 4px; }

/* ---------- Topbar ---------- */
.dash-view { height: 100%; display: flex; flex-direction: column; }
.topbar {
  flex: 0 0 auto; height: 56px; display: flex; align-items: center; gap: 18px; padding: 0 16px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.summary { flex: 1; display: flex; align-items: center; gap: 26px; min-width: 0; }
.kpi { display: flex; flex-direction: column; line-height: 1.15; }
.kpi-label { font-size: 10.5px; font-weight: 500; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); }
.kpi-value { font-size: 18px; font-weight: 600; color: var(--text-strong); }
.kpi.ok .kpi-value { color: var(--ok); }
.kpi.fail .kpi-value { color: var(--fail); }
.kpi.fail.zero .kpi-value { color: var(--muted); }
.segments { flex: 1; display: flex; gap: 2px; height: 8px; max-width: 420px; min-width: 60px; }
.segments span { flex: 1; background: var(--idle); }
.segments span:first-child { border-radius: 2px 0 0 2px; }
.segments span:last-child { border-radius: 0 2px 2px 0; }
.segments span.ok { background: var(--ok); }
.segments span.fail { background: var(--fail); }

.top-actions { display: flex; align-items: center; gap: 8px; }
.refresh-info { display: flex; flex-direction: column; align-items: flex-end; gap: 5px; font-size: 11.5px; color: var(--muted); margin-right: 6px; }
.refresh-bar { width: 96px; height: 2px; background: var(--border); overflow: hidden; }
#refresh-progress { height: 100%; width: 0; background: var(--muted); }
.user { color: var(--muted); padding: 0 2px; }

/* ---------- Grid ---------- */
.grid { flex: 1; min-height: 0; display: grid; gap: var(--gap); padding: var(--gap); }
.empty { grid-column: 1 / -1; grid-row: 1 / -1; display: grid; place-items: center; text-align: center; color: var(--muted); }
.empty h2 { margin: 0 0 6px; font-size: 16px; font-weight: 600; color: var(--text-strong); }
.empty p { margin: 0 0 16px; }

/* ---------- Card ---------- */
.card {
  position: relative; min-width: 0; min-height: 0; display: flex; flex-direction: column; overflow: hidden;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.card::before { content: ''; position: absolute; inset: 0 0 auto 0; height: 3px; background: var(--idle); }
.card.ok::before { background: var(--ok); }
.card.ok {
  background: linear-gradient(180deg, rgba(63, 185, 80, 0.09) 0%, rgba(63, 185, 80, 0.04) 100%), var(--surface);
  border-color: rgba(63, 185, 80, .35);
}
.card.fail::before { background: var(--fail); }
.card.fail {
  background: linear-gradient(180deg, rgba(248, 81, 73, 0.10) 0%, rgba(248, 81, 73, 0.05) 100%), var(--surface);
  border-color: rgba(248, 81, 73, .45);
}

.card-head { flex: 0 0 auto; display: flex; align-items: center; gap: 10px; padding: 14px 14px 10px; }
.favicon {
  flex: 0 0 auto; width: 28px; height: 28px; border-radius: 5px; background: var(--surface-2);
  border: 1px solid var(--border); display: grid; place-items: center; overflow: hidden;
}
.favicon img { width: 18px; height: 18px; object-fit: contain; }
.favicon .letter { font-weight: 600; font-size: 13px; color: var(--muted); }
.title { flex: 1; min-width: 0; }
.title .name { font-size: 14px; font-weight: 600; color: var(--text-strong); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.title .sub { font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 1px; }

.badge {
  flex: 0 0 auto; display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 8px;
  border-radius: 4px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px;
  color: var(--muted); background: var(--surface-2); border: 1px solid var(--border);
}
.badge::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.ok { color: var(--ok); background: var(--ok-bg); border-color: rgba(63, 185, 80, .35); }
.badge.fail { color: var(--fail); background: var(--fail-bg); border-color: rgba(248, 81, 73, .4); }
.card.loading .badge { opacity: .6; }

.card-body { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
.placeholder { display: grid; place-items: center; color: var(--muted); }

/* Stats */
.stats { flex: 0 0 auto; display: grid; grid-template-columns: repeat(3, 1fr); border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.stat { padding: 8px 14px; min-width: 0; }
.stat + .stat { border-left: 1px solid var(--border); }
.stat-label { display: block; font-size: 10.5px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); }
.stat-value { display: block; margin-top: 2px; font-size: 16px; font-weight: 600; color: var(--text-strong); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat-value.ok { color: var(--ok); }
.stat-value.fail { color: var(--fail); }

/* Secciones */
.section { flex: 0 1 auto; min-height: 0; display: flex; flex-direction: column; padding: 10px 14px 0; }
.section-title { flex: 0 0 auto; display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px;
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); }
.section-title .num.ok { color: var(--ok); }
.section-title .num.fail { color: var(--fail); }

/* Dependencias */
.rows { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); column-gap: 18px; overflow: auto; min-height: 0; scrollbar-width: thin; }
.row { display: flex; align-items: center; gap: 8px; min-width: 0; height: 24px; border-bottom: 1px solid var(--border); }
.row .ind { flex: 0 0 auto; width: 8px; height: 8px; border-radius: 2px; background: var(--idle); }
.row.ok .ind { background: var(--ok); }
.row.fail .ind { background: var(--fail); }
.row-name { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row.fail .row-name { color: var(--fail); font-weight: 500; }
.row-val { flex: 0 0 auto; color: var(--muted); font-size: 11.5px; }
.row.fail .row-val { color: var(--fail); opacity: .85; }

/* Métricas */
.metrics { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px 18px; }
.metric { min-width: 0; }
.metric-top { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; margin-bottom: 4px; }
.metric-name { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.metric-val { font-weight: 600; color: var(--text-strong); white-space: nowrap; }
.metric.fail .metric-val { color: var(--fail); }
.bar { height: 4px; background: var(--surface-2); border-radius: 2px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--ok); transition: width .5s ease; }
.metric.fail .bar > i { background: var(--fail); }
.bar.empty > i { width: 0 !important; }

/* Historial (estilo status page) */
.history-wrap { flex: 0 0 auto; margin-top: auto; padding: 10px 14px 12px; }
.history { display: flex; gap: 2px; height: 16px; }
.history span { flex: 1; background: var(--surface-2); border-radius: 1px; }
.history span.ok { background: var(--ok); opacity: .85; }
.history span.fail { background: var(--fail); }

.card-error {
  flex: 0 0 auto; padding: 7px 14px; font-size: 12px; color: var(--fail); background: var(--fail-bg);
  border-top: 1px solid rgba(248, 81, 73, .3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ---------- Densidad ---------- */
.grid[data-density="compact"] .card-head { padding: 12px 12px 8px; }
.grid[data-density="compact"] .stat { padding: 6px 12px; }
.grid[data-density="compact"] .stat-value { font-size: 14px; }
.grid[data-density="compact"] .section { padding: 8px 12px 0; }
.grid[data-density="compact"] .row { height: 22px; font-size: 12px; }
.grid[data-density="compact"] .history-wrap { padding: 8px 12px 10px; }

.grid[data-density="tiny"] .card-head { padding: 10px 10px 6px; gap: 8px; }
.grid[data-density="tiny"] .favicon { width: 22px; height: 22px; }
.grid[data-density="tiny"] .favicon img { width: 14px; height: 14px; }
.grid[data-density="tiny"] .title .name { font-size: 12.5px; }
.grid[data-density="tiny"] .title .sub, .grid[data-density="tiny"] .section.metrics-section,
.grid[data-density="tiny"] .history-wrap .section-title { display: none; }
.grid[data-density="tiny"] .stat { padding: 5px 10px; }
.grid[data-density="tiny"] .stat-value { font-size: 13px; }
.grid[data-density="tiny"] .section { padding: 6px 10px 0; }
.grid[data-density="tiny"] .rows { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); column-gap: 12px; }
.grid[data-density="tiny"] .row { height: 20px; font-size: 11.5px; }
.grid[data-density="tiny"] .row-val { display: none; }
.grid[data-density="tiny"] .history-wrap { padding: 6px 10px 8px; }
.grid[data-density="tiny"] .history { height: 10px; }

/* ---------- Dialog ---------- */
.dialog {
  width: min(620px, 94vw); max-height: 86vh; padding: 20px; color: var(--text);
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: 8px;
}
.dialog::backdrop { background: rgba(1, 4, 9, .72); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.dialog-head h2 { margin: 0; font-size: 15px; font-weight: 600; color: var(--text-strong); }
.add-form { display: grid; grid-template-columns: 1fr 1.5fr auto; gap: 10px; align-items: end; }
.add-form .btn { height: 34px; }
.hint { margin: 4px 0 0; font-size: 12px; color: var(--muted); }
.domain-list { list-style: none; padding: 0; margin: 16px 0 0; max-height: 50vh; overflow: auto; border-top: 1px solid var(--border); }
.domain-list li { display: flex; align-items: center; gap: 12px; padding: 10px 2px; border-bottom: 1px solid var(--border); }
.domain-list .ind { flex: 0 0 auto; width: 8px; height: 8px; border-radius: 50%; background: var(--idle); }
.domain-list li.ok .ind { background: var(--ok); }
.domain-list li.fail .ind { background: var(--fail); }
.domain-list .info { flex: 1; min-width: 0; }
.domain-list .info b { display: block; font-weight: 600; color: var(--text-strong); }
.domain-list .info span { font-size: 12px; color: var(--muted); word-break: break-all; }
.domain-list .none { justify-content: center; color: var(--muted); padding: 18px 0; }

@media (max-width: 1000px) {
  .refresh-info, .user, .segments, .topbar .divider { display: none; }
  .add-form { grid-template-columns: 1fr; }
}

/* ---------- Estado "warn" (respuesta lenta) ---------- */
.kpi.warn .kpi-value { color: var(--warn); }
.kpi.zero .kpi-value { color: var(--muted); }
.segments span.warn { background: var(--warn); }
.card.warn::before { background: var(--warn); }
.card.warn { border-color: rgba(210, 153, 34, .45); }
.badge.warn { color: var(--warn); background: var(--warn-bg); border-color: rgba(210, 153, 34, .4); }
.stat-value.warn { color: var(--warn); }
.history span.warn { background: var(--warn); }
.domain-list li.warn .ind { background: var(--warn); }
.card-warning {
  flex: 0 0 auto; padding: 7px 14px; font-size: 12px; color: var(--warn); background: var(--warn-bg);
  border-top: 1px solid rgba(210, 153, 34, .3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
