:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e2e5ea;
  --text: #1c2129;
  --muted: #667085;
  --accent: #2f6fde;
  --ok: #1f9d55;
  --warn: #d98a00;
  --crit: #d93025;
  --ok-soft: #e7f6ed;
  --warn-soft: #fff4dc;
  --crit-soft: #fde8e7;
  --log-bg: #0f1419;
  --log-text: #d6dde6;
  --log-ts: #6b7a8c;
  --log-warn: #f0b429;
  --log-error: #ff6b61;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1116;
    --surface: #161b22;
    --surface-2: #1d232c;
    --border: #2a313c;
    --text: #e4e8ee;
    --muted: #8b95a5;
    --accent: #6ea2ff;
    --ok: #3fbf74;
    --warn: #f0b429;
    --crit: #ff6b61;
    --ok-soft: #12291c;
    --warn-soft: #2e2510;
    --crit-soft: #331816;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: inherit; text-decoration: none; }
h1, h2, h3 { margin: 0; font-weight: 600; }
h2 { font-size: 15px; margin: 28px 0 12px; display: flex; align-items: center; gap: 8px; }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; word-break: break-all; }
.count { background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 0 8px; font-size: 12px; font-weight: 500; color: var(--muted); }

/* Barra superior */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 14px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px; }
.server-name { color: var(--muted); border-left: 1px solid var(--border); padding-left: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.logout { margin-left: auto; display: flex; align-items: center; gap: 4px; }
.current-user { font-size: 13px; }
.wrap { max-width: 1280px; margin: 0 auto; padding: 20px 16px 48px; }

/* Botones y formularios */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 34px; padding: 6px 12px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text);
  font: inherit; cursor: pointer;
}
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn[aria-pressed="true"] { background: var(--ok-soft); border-color: var(--ok); color: var(--ok); }
.btn[aria-pressed="true"]::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--ok); animation: pulse 1.6s infinite; }
input, select {
  font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  min-height: 34px; padding: 5px 9px; width: 100%;
}
input:focus, select:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: 6px; }
label.check input { width: auto; min-height: 0; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.alert { padding: 10px 14px; border-radius: 8px; margin: 12px 0; }
.alert-crit { background: var(--crit-soft); color: var(--crit); }

/* Semáforo */
.dot { flex: none; width: 9px; height: 9px; border-radius: 50%; background: var(--ok); }
.dot-lg { width: 14px; height: 14px; }
.level-ok .dot, .bar-fill.level-ok { background: var(--ok); }
.level-warn .dot, .bar-fill.level-warn { background: var(--warn); }
.level-crit .dot, .bar-fill.level-crit { background: var(--crit); }
.level-crit > .dot-lg { animation: pulse 1.6s infinite; }
@keyframes pulse { 50% { opacity: .35; } }

.banner {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 18px; border-radius: var(--radius);
  border: 1px solid var(--border);
}
.banner.level-ok { background: var(--ok-soft); }
.banner.level-warn { background: var(--warn-soft); }
.banner.level-crit { background: var(--crit-soft); }
.banner-text { display: flex; flex-direction: column; min-width: 0; }
.banner-text strong { font-size: 17px; overflow-wrap: anywhere; }
.banner-side { margin-left: auto; font-size: 12px; text-align: right; }

/* Sistema operativo */
.sysinfo { display: flex; flex-wrap: wrap; gap: 10px 28px; margin-top: 16px; padding: 12px 16px; }
.sys-item { display: flex; flex-direction: column; min-width: 0; }
.sys-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.sys-ok { color: var(--ok); }
.sys-warn { color: var(--warn); font-weight: 500; overflow-wrap: anywhere; }

/* Métricas */
.metrics { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; margin-top: 16px; }
.metric { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); }
.metric-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.metric-title { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.metric-value { font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums; }
.metric-net { display: flex; flex-wrap: wrap; gap: 4px 14px; font-weight: 600; font-variant-numeric: tabular-nums; margin: 4px 0 2px; }
.metric-sub { color: var(--muted); font-size: 12px; margin-top: 6px; }
.bar { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; margin-top: 8px; }
.bar-fill { display: block; height: 100%; border-radius: 3px; transition: width .4s; }

/* Requiere atención */
.attention { list-style: none; margin: 0; padding: 4px 0; }
.row { display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto; align-items: center; gap: 12px; padding: 9px 14px; }
.row:hover { background: var(--surface-2); }
.row-main { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.level-crit .row-reason { color: var(--crit); }
.level-warn .row-reason { color: var(--warn); }
.row-when { font-size: 12px; }

/* Avisos */
.count-crit { background: var(--crit-soft); border-color: var(--crit); color: var(--crit); }
.channels { margin-left: auto; display: flex; gap: 6px; flex-wrap: wrap; }
.chip { font-size: 12px; font-weight: 500; padding: 1px 9px; border-radius: 999px; border: 1px solid var(--border); color: var(--muted); background: var(--surface); }
.chip-ok { color: var(--ok); border-color: var(--ok); }
.chip-crit { color: var(--crit); border-color: var(--crit); background: var(--crit-soft); }
.alert-list { list-style: none; margin: 0; padding: 4px 0; }
.alert-item { display: grid; grid-template-columns: 22px 92px minmax(120px, 240px) minmax(0, 1fr); gap: 10px; align-items: baseline; padding: 7px 14px; }
.alert-item + .alert-item { border-top: 1px solid var(--border); }
.alert-time { font-size: 12px; font-variant-numeric: tabular-nums; }
.alert-subject { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.alert-subject a:hover { text-decoration: underline; }
.alert-subject .muted { font-weight: 400; margin-left: 4px; }
.alert-item.kind-resolved .alert-text { color: var(--ok); }
.alert-item.level-crit:not(.kind-resolved) .alert-text { color: var(--crit); }
.alert-item.level-warn:not(.kind-resolved) .alert-text { color: var(--warn); }

/* Aplicaciones */
.apps { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 14px; }
.app { display: flex; flex-direction: column; overflow: hidden; }
.app.level-warn { border-top: 3px solid var(--warn); }
.app.level-crit { border-top: 3px solid var(--crit); }
.app-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px 8px; }
.app-head h3 { font-size: 15px; overflow-wrap: anywhere; }
.app-count { margin-left: auto; font-variant-numeric: tabular-nums; }
.services { list-style: none; margin: 0; padding: 0 0 6px; }
.service {
  display: grid; grid-template-columns: auto minmax(60px, auto) minmax(0, 1fr) 52px 64px;
  align-items: center; gap: 10px; padding: 6px 14px;
}
.service:hover { background: var(--surface-2); }
.service-name { font-weight: 500; }
.service-status { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.level-crit .service-status { color: var(--crit); }
.level-warn .service-status { color: var(--warn); }
.service-num { text-align: right; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.app-foot { margin-top: auto; padding: 8px 14px; border-top: 1px solid var(--border); font-size: 12px; }

/* Detalle de contenedor */
.back { display: inline-block; color: var(--muted); margin-bottom: 12px; }
.back:hover { color: var(--text); }
.details { margin-top: 16px; padding: 4px 16px; }
.details dl { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 0 24px; margin: 0; }
.details dl > div { padding: 9px 0; border-bottom: 1px solid var(--border); }
.details dt { font-size: 12px; color: var(--muted); }
.details dd { margin: 2px 0 0; }

/* Logs */
.logs { margin-top: 20px; padding: 14px 16px 16px; }
.logs-toolbar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px 12px; }
.logs-toolbar h2 { margin: 0 8px 7px 0; }
.logs-toolbar label { width: 140px; }
.logs-toolbar label:has(#log-since) { width: 200px; }
.logs-toolbar label:has(#log-level) { width: 190px; }
.logs-toolbar label.grow { flex: 1 1 180px; }
.logs-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.logs-status { display: flex; align-items: center; gap: 14px; margin: 12px 0 8px; font-size: 12px; }
.logs-status .check { margin-left: auto; }
.log-output {
  height: 62vh; min-height: 320px; overflow: auto;
  background: var(--log-bg); color: var(--log-text);
  border-radius: 8px; padding: 10px 0;
  font: 12.5px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.log-line { padding: 0 12px; white-space: pre-wrap; overflow-wrap: anywhere; }
.log-line:hover { background: rgba(255, 255, 255, .04); }
.log-ts { color: var(--log-ts); user-select: none; margin-right: 10px; }
.log-line.lv-warn .log-msg { color: var(--log-warn); }
.log-line.lv-error { background: rgba(255, 107, 97, .08); }
.log-line.lv-error .log-msg { color: var(--log-error); }
.log-line mark { background: #f0b429; color: #111; border-radius: 2px; }
.log-empty { color: var(--log-ts); padding: 12px; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; padding: 28px; display: flex; flex-direction: column; gap: 14px; }
.login-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.login-brand h1 { font-size: 22px; }
.login-card .btn { margin-top: 6px; }

@media (max-width: 640px) {
  .apps { grid-template-columns: 1fr; }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .metric-value { font-size: 17px; }
  .service { grid-template-columns: auto minmax(60px, auto) minmax(0, 1fr) 56px; }
  .service-num:last-child { display: none; }
  .row { grid-template-columns: auto minmax(0, 1fr); }
  .row-reason, .row-when { grid-column: 2; }
  .alert-item { grid-template-columns: 22px minmax(0, 1fr); gap: 2px 8px; }
  .alert-item > :not(.alert-icon) { grid-column: 2; }
  .alert-subject { white-space: normal; }
  .banner-side { display: none; }
  .logs-toolbar label, .logs-toolbar label:has(#log-since), .logs-toolbar label:has(#log-level) { width: 100%; }
  .server-name { display: none; }
}
