:root {
  color-scheme: dark;
  --bg: #060912; --bg2: #0b1124; --fg: #e6ecff; --muted: #8590b3;
  --card: rgba(16, 23, 44, 0.62); --card-hi: rgba(28, 38, 70, 0.7); --line: rgba(120, 160, 255, 0.14);
  --accent: #22d3ee; --accent2: #a78bfa; --ok: #34d399; --warn: #fbbf24; --bad: #fb7185;
  --on-accent: #041018; --glow: 0 0 18px rgba(34, 211, 238, 0.35); --grid: rgba(120, 160, 255, 0.05);
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #eef2fb; --bg2: #e3e9f7; --fg: #0b1222; --muted: #55607e;
  --card: rgba(255, 255, 255, 0.78); --card-hi: rgba(255, 255, 255, 0.95); --line: rgba(30, 50, 110, 0.14);
  --accent: #0891b2; --accent2: #7c3aed; --ok: #059669; --warn: #b45309; --bad: #e11d48;
  --on-accent: #fff; --glow: 0 0 14px rgba(8, 145, 178, 0.22); --grid: rgba(30, 50, 110, 0.05);
}

* { box-sizing: border-box; }
body {
  margin: 0; min-height: 100vh; color: var(--fg); background-color: var(--bg);
  background-image:
    radial-gradient(1200px 600px at 85% -10%, color-mix(in srgb, var(--accent2) 22%, transparent), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, color-mix(in srgb, var(--accent) 16%, transparent), transparent 60%),
    linear-gradient(var(--grid) 1px, transparent 1px), linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: auto, auto, 40px 40px, 40px 40px;
  background-attachment: fixed;
  font: 14.5px/1.55 Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre, .mono { font-family: var(--mono); font-size: 0.86em; }
pre { white-space: pre-wrap; word-break: break-word; margin: 0; }

.shell { display: grid; grid-template-columns: 230px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 0.25rem;
  padding: 1.1rem 0.8rem; border-right: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg2) 70%, transparent); backdrop-filter: blur(14px);
}
.brand { display: flex; align-items: center; gap: 0.6rem; font-weight: 700; letter-spacing: 0.08em;
         text-transform: uppercase; font-size: 0.95rem; padding: 0 0.4rem 1rem; }
.brand-mark { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center;
              background: linear-gradient(135deg, var(--accent), var(--accent2)); color: var(--on-accent);
              box-shadow: var(--glow); font-family: var(--mono); }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.sidebar nav a { display: flex; align-items: center; gap: 0.65rem; padding: 0.5rem 0.7rem; border-radius: 9px;
                 color: var(--muted); border: 1px solid transparent; }
.sidebar nav a:hover { color: var(--fg); background: var(--card); text-decoration: none; }
.sidebar nav a.active { color: var(--fg); background: var(--card-hi); border-color: var(--line);
                        box-shadow: inset 3px 0 0 var(--accent); }
.nav-icon { width: 1.2em; text-align: center; color: var(--accent); }
.sidebar-foot { display: flex; gap: 0.4rem; padding-top: 0.75rem; border-top: 1px solid var(--line); }
.topbar { display: none; }
main { padding: 1.6rem 1.8rem 4rem; max-width: 1320px; width: 100%; }

h1 { font-size: 1.45rem; margin: 0 0 1.1rem; letter-spacing: 0.01em; display: flex; align-items: center;
     gap: 0.75rem; flex-wrap: wrap; }
h1::before { content: ""; width: 6px; height: 1.2em; border-radius: 3px;
             background: linear-gradient(var(--accent), var(--accent2)); box-shadow: var(--glow); }
h2 { font-size: 0.8rem; margin: 0 0 0.8rem; text-transform: uppercase; letter-spacing: 0.12em; color: var(--muted);
     font-weight: 600; display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }

.grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(min(220px, 100%), 1fr));
        margin-bottom: 1rem; }
.grid-2 { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(min(440px, 100%), 1fr));
          margin-bottom: 1rem; }
.card { position: relative; background: var(--card); border: 1px solid var(--line); border-radius: 14px;
        padding: 1rem 1.1rem; margin-bottom: 1rem; overflow-x: auto; backdrop-filter: blur(12px);
        box-shadow: 0 10px 30px rgba(0, 0, 0, 0.18); }
.grid > .card, .grid-2 > .card { margin-bottom: 0; }
.card.glow { border-color: color-mix(in srgb, var(--accent) 45%, transparent); box-shadow: var(--glow); }
.kpi { font: 600 1.7rem/1.2 var(--mono); letter-spacing: -0.02em; }
.label { color: var(--muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.1em; }
.muted { color: var(--muted); font-size: 0.85rem; }
.ok { color: var(--ok); } .warn { color: var(--warn); } .bad { color: var(--bad); }
.row { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.spacer { flex: 1; }

.gauge { --p: 0; --c: var(--accent); width: 74px; height: 74px; border-radius: 50%; flex: none;
         display: grid; place-items: center; font: 600 0.9rem var(--mono);
         background: radial-gradient(closest-side, var(--bg2) 76%, transparent 78% 100%),
                     conic-gradient(var(--c) calc(var(--p) * 1%), var(--line) 0);
         filter: drop-shadow(0 0 6px color-mix(in srgb, var(--c) 40%, transparent)); }
.gauge.warn { --c: var(--warn); } .gauge.bad { --c: var(--bad); }
.kpi-card { display: flex; align-items: center; gap: 1rem; }
.meter { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.meter > span { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent2)); }

.pill { display: inline-flex; align-items: center; gap: 0.35rem; padding: 0.1rem 0.55rem; border-radius: 999px;
        font-size: 0.78rem; border: 1px solid var(--line); background: var(--card-hi); white-space: nowrap; }
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.pill.ok::before { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.pill.warn::before { background: var(--warn); box-shadow: 0 0 8px var(--warn); }
.pill.bad::before { background: var(--bad); box-shadow: 0 0 8px var(--bad); }

.uptime { display: grid; grid-template-columns: repeat(24, 1fr); gap: 2px; margin-top: 0.5rem; }
.uptime span { height: 16px; border-radius: 2px; background: var(--line); }
.uptime span.ok { background: var(--ok); opacity: 0.85; }
.uptime span.warn { background: var(--warn); }
.uptime span.bad { background: var(--bad); }

table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
th, td { text-align: left; padding: 0.5rem 0.55rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-weight: 500; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.08em; }
tr:hover td { background: color-mix(in srgb, var(--accent) 4%, transparent); }
td.actions { white-space: nowrap; text-align: right; width: 1%; }
table.fit { table-layout: fixed; }
table.fit th:nth-child(1) { width: 22%; } table.fit th:nth-child(2) { width: 24%; }
table.fit th:nth-child(3) { width: 20%; } table.fit th.num { width: 11%; } table.fit th:last-child { width: 140px; }
td.clip { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
td .pill { max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
th.num, td.num { text-align: right; white-space: nowrap; }
th[data-sort] { cursor: pointer; user-select: none; }
th[data-sort]:hover { color: var(--fg); }
th[data-sort]::after { content: " ⇅"; opacity: 0.35; }
th[aria-sort="ascending"]::after { content: " ▲"; opacity: 1; color: var(--accent); }
th[aria-sort="descending"]::after { content: " ▼"; opacity: 1; color: var(--accent); }
table.fit th { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 600px) {
  table.fit th:nth-child(2), table.fit td:nth-child(2), table.fit th.num, table.fit td.num { display: none; }
  table.fit th:nth-child(1) { width: 38%; } table.fit th:nth-child(3) { width: 30%; }
}

input, select, button, textarea { font: inherit; color: inherit; }
input[type=text], input[type=number], input[type=password], input[type=email], input[type=date], select {
  padding: 0.42rem 0.65rem; background: var(--card-hi); border: 1px solid var(--line); border-radius: 8px;
  max-width: 100%; }
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
button, .btn { display: inline-flex; align-items: center; gap: 0.35rem; padding: 0.42rem 0.85rem;
               border-radius: 8px; border: 1px solid var(--accent); cursor: pointer; font-weight: 600;
               background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 60%, var(--accent2)));
               color: var(--on-accent); box-shadow: var(--glow); }
button:hover, .btn:hover { filter: brightness(1.1); text-decoration: none; }
button.secondary, .btn.secondary { background: transparent; color: var(--fg); border-color: var(--line); box-shadow: none; }
button.danger { background: color-mix(in srgb, var(--bad) 18%, transparent); color: var(--bad); border-color: var(--bad);
                box-shadow: none; }
button.small, .btn.small { padding: 0.2rem 0.55rem; font-size: 0.8rem; }
button:disabled { opacity: 0.35; cursor: not-allowed; filter: none; }
form.inline { display: inline; }
.scopes { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(160px, 100%), 1fr)); gap: 0.25rem 1rem; }

.flash { padding: 0.7rem 0.9rem; border-radius: 10px; margin-bottom: 1rem; border: 1px solid currentColor;
         background: color-mix(in srgb, currentColor 10%, transparent); }
.plan-banner { border: 1px solid var(--warn); box-shadow: 0 0 22px color-mix(in srgb, var(--warn) 30%, transparent); }
.plan-banner h2 { color: var(--warn); }

.tabs { display: inline-flex; gap: 2px; padding: 3px; border-radius: 10px; border: 1px solid var(--line);
        background: var(--card); }
.tabs a { padding: 0.2rem 0.7rem; border-radius: 7px; color: var(--muted); font: 0.8rem var(--mono); }
.tabs a.active { background: var(--card-hi); color: var(--accent); box-shadow: inset 0 0 0 1px var(--line); }
.tabs a:hover { text-decoration: none; color: var(--fg); }

.chart { min-height: 200px; width: 100%; }
.chart.small { min-height: 120px; }
.chart-empty { display: grid; place-items: center; min-height: inherit; color: var(--muted); font-size: 0.85rem; }
.u-legend { font-size: 0.78rem; color: var(--muted); }
.u-legend .u-marker { border-radius: 2px; }
.uplot { font-family: var(--mono); }

.logs { max-height: 65vh; overflow: auto; padding: 0.8rem; border-radius: 10px; background: rgba(0, 0, 0, 0.35);
        border: 1px solid var(--line); font: 0.8rem/1.5 var(--mono); }
:root[data-theme="light"] .logs { background: rgba(10, 20, 40, 0.04); }
.logs .stderr { color: var(--bad); }
.logs .ts { color: var(--muted); margin-right: 0.6rem; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 10; inset: 0 auto 0 0; width: 240px; transform: translateX(-100%);
             transition: transform 0.2s; }
  body.nav-open .sidebar { transform: none; }
  .topbar { display: flex; align-items: center; gap: 0.6rem; padding: 0.7rem 1rem; position: sticky; top: 0;
            z-index: 5; border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--bg2) 85%, transparent);
            backdrop-filter: blur(12px); }
  main { padding: 1rem 1rem 3rem; }
}

.stackbar { display: flex; height: 16px; border-radius: 8px; overflow: hidden; background: var(--line); }
.stackbar span { display: block; height: 100%; }
.legend { display: flex; flex-wrap: wrap; gap: 0.4rem 1.2rem; margin-top: 0.7rem; font-size: 0.85rem; align-items: center; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 0.4rem; }
.c-user { background: var(--accent); } .c-system { background: var(--accent2); }
.c-iowait { background: var(--warn); } .c-steal { background: var(--bad); }
.c-idle { background: var(--line); }
.cores { display: grid; gap: 0.7rem 1.1rem; grid-template-columns: repeat(auto-fill, minmax(min(150px, 100%), 1fr)); }
.meter.warn > span { background: var(--warn); } .meter.bad > span { background: var(--bad); }
tr.muted td { opacity: 0.55; }
