:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --accent: #2a78d6;
  --good: #0ca30c;
  --good-ink: #006300;
  --warning: #fab219;
  --critical: #d03b3b;
  --input: #ffffff;
  --radius: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.1);
    --series-1: #3987e5;
    --series-2: #d95926;
    --accent: #3987e5;
    --good-ink: #0ca30c;
    --input: #121211;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.45;
}

h1, h2 { margin: 0; font-weight: 600; }
h1 { font-size: 1.25rem; }
h2 { font-size: 1rem; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.9em; }
.muted { color: var(--muted); font-weight: 400; }
.hint { color: var(--ink-2); font-size: 0.85rem; margin: 0 0 10px; }
.error { color: var(--critical); min-height: 1.2em; margin: 0; }

/* ---------- botones e inputs ---------- */
.btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  border-radius: 8px;
  padding: 7px 12px;
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: var(--axis); }
.btn:disabled { opacity: 0.5; cursor: wait; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--critical); }
.btn.ghost { background: transparent; }
.btn.small { padding: 3px 8px; font-size: 0.8rem; }

input[type="password"], input:not([type]), input[type="text"] {
  width: 100%;
  min-width: 0;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--input);
  color: var(--ink);
  font: inherit;
}
input:focus-visible, .btn:focus-visible, pre:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.inline-form { display: flex; gap: 8px; margin-bottom: 10px; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 340px; display: grid; gap: 10px; }
.login-card p { margin: 0; }

/* ---------- layout ---------- */
.topbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; }
.topbar-actions { display: flex; flex-wrap: wrap; gap: 6px; }

.content { max-width: 1200px; margin: 0 auto; padding: 16px; display: grid; gap: 16px; }
.address { margin: 0; color: var(--ink-2); overflow-wrap: anywhere; }
.address code { color: var(--ink); font-size: 1rem; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin: 0;
  min-width: 0;
}
.card > h2, .card-head { margin-bottom: 10px; }
.card-head { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; }
.card-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  padding: 2px 9px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--ink-2);
}
.badge::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.badge.on::before { background: var(--good); }
.badge.off::before { background: var(--critical); }
.badge.wait::before { background: var(--warning); }

/* ---------- indicadores ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; }
.tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: grid;
  gap: 2px;
}
.tile-label { font-size: 0.8rem; color: var(--ink-2); }
.tile-value { font-size: 1.5rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.tile-sub { font-size: 0.8rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.tile-sub .st-good { color: var(--good-ink); }
.tile-sub .st-bad { color: var(--critical); }

/* ---------- graficas ---------- */
.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }
.chart figcaption { display: flex; flex-wrap: wrap; gap: 8px; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.legend { list-style: none; margin: 0; padding: 0; display: flex; gap: 14px; font-size: 0.8rem; color: var(--ink-2); }
.legend li { display: flex; align-items: center; gap: 6px; }
.swatch { width: 14px; height: 3px; border-radius: 2px; }
.swatch.s1 { background: var(--series-1); }
.swatch.s2 { background: var(--series-2); }
.plot { position: relative; height: 200px; }
.plot svg { display: block; width: 100%; height: 100%; overflow: visible; }
.plot .gridline { stroke: var(--grid); stroke-width: 1; }
.plot .baseline { stroke: var(--axis); stroke-width: 1; }
.plot .tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.plot .limit { stroke: var(--ink-2); stroke-width: 1; stroke-dasharray: 4 4; }
.plot .limit-label { fill: var(--ink-2); font-size: 11px; }
.plot .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.plot .line.s1 { stroke: var(--series-1); }
.plot .line.s2 { stroke: var(--series-2); }
.plot .end-label { font-size: 11px; fill: var(--ink-2); font-variant-numeric: tabular-nums; }
.plot .crosshair { stroke: var(--axis); stroke-width: 1; }
.plot .dot { stroke: var(--surface); stroke-width: 2; }
.plot .dot.s1 { fill: var(--series-1); }
.plot .dot.s2 { fill: var(--series-2); }

.tooltip {
  position: fixed;
  z-index: 10;
  pointer-events: none;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 0.8rem;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
  font-variant-numeric: tabular-nums;
}
.tooltip .tt-time { color: var(--muted); margin-bottom: 4px; }
.tooltip .tt-row { display: flex; align-items: center; gap: 6px; }
.tooltip .tt-row b { margin-left: auto; padding-left: 12px; }

/* ---------- listas ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; }
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; max-height: 260px; overflow-y: auto; }
.list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 4px;
  border-bottom: 1px solid var(--border);
  min-width: 0;
}
.list li:last-child { border-bottom: 0; }
.list .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .meta { color: var(--muted); font-size: 0.8rem; }
.list .empty { color: var(--muted); border: 0; }

.switch { display: inline-flex; align-items: center; gap: 6px; font-size: 0.85rem; color: var(--ink-2); cursor: pointer; }
.switch input { width: 16px; height: 16px; accent-color: var(--accent); }

/* ---------- consola ---------- */
.logs, .cmd-out {
  margin: 0 0 10px;
  padding: 10px;
  border-radius: 8px;
  background: var(--input);
  border: 1px solid var(--border);
  font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.logs { height: 280px; overflow-y: auto; }
.cmd-out { margin: 10px 0 0; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  background: var(--ink);
  color: var(--page);
  padding: 9px 14px;
  border-radius: 8px;
  font-size: 0.9rem;
  z-index: 20;
}
.toast.err { background: var(--critical); color: #fff; }

@media (max-width: 520px) {
  .inline-form { flex-wrap: wrap; }
  .inline-form .btn { flex: 1; }
  .tile-value { font-size: 1.25rem; }
}
