:root {
  --bg: #0d1117; --panel: #161b22; --card: #1c2330; --line: #2d3646;
  --fg: #e6edf3; --muted: #8b949e; --accent: #2f81f7; --good: #3fb950;
  --warn: #d29922; --bad: #f85149; --term-bg: #010409;
  --radius: 10px;
}
html[data-theme="light"] {
  --bg: #f6f8fa; --panel: #ffffff; --card: #ffffff; --line: #d0d7de;
  --fg: #1f2328; --muted: #57606a; --accent: #0969da; --good: #1a7f37;
  --warn: #9a6700; --bad: #cf222e; --term-bg: #0d1117;
}
* { box-sizing: border-box; }
html, body { background: var(--bg); }
body { margin: 0; color: var(--fg); font: 14px/1.5 system-ui, "Segoe UI", Roboto, sans-serif; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
h1 { font-size: 22px; margin: 0 0 2px; }
h3 { margin: 0 0 10px; font-size: 15px; }
h4 { margin: 16px 0 6px; font-size: 13px; }
a { color: var(--accent); }
code { font-family: "Cascadia Mono", Consolas, monospace; font-size: 12px; }

.status { margin: 6px 0; min-height: 1.2em; }
.status.error { color: var(--bad); } .status.good { color: var(--good); } .status.warn { color: var(--warn); }
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; border: 1px solid var(--line); }
.badge.good { color: var(--good); } .badge.warn { color: var(--warn); } .badge.bad { color: var(--bad); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
button, .button { background: var(--accent); color: #fff; border: 1px solid transparent; border-radius: 6px;
  padding: 7px 14px; cursor: pointer; font: inherit; font-size: 13px; text-decoration: none; display: inline-block; }
button:disabled { opacity: .6; cursor: default; }
button.danger { background: var(--bad); }
button.ghost, .button.ghost { background: transparent; color: var(--fg); border-color: var(--line); }
button.icon { padding: 4px 10px; font-size: 16px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input, select, textarea { background: var(--panel); color: var(--fg); border: 1px solid var(--line); border-radius: 6px;
  padding: 7px 10px; font: inherit; font-size: 13px; width: 100%; }
textarea { font-family: "Cascadia Mono", Consolas, monospace; }
label { display: block; margin: 10px 0 4px; color: var(--muted); font-size: 12px; }
label.check { display: inline-flex; gap: 6px; align-items: center; margin: 0; color: var(--fg); font-size: 13px; }
label.check input { width: auto; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-top: 12px; }
.row.end { justify-content: flex-end; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.toolbar select, .toolbar input { width: 200px; max-width: 100%; }

/* auth gate */
.gate { position: fixed; inset: 0; display: grid; place-items: center; padding: 16px; background: var(--bg); z-index: 50; }
.gate-card { width: min(420px, 100%); }
.gate-card button { margin-top: 8px; width: 100%; }

/* shell */
#app { display: grid; grid-template-columns: 220px minmax(0, 1fr); min-height: 100vh; }
.topbar { display: none; }
#side { background: var(--panel); border-right: 1px solid var(--line); padding: 14px 10px; display: flex;
  flex-direction: column; gap: 2px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { font-weight: 700; padding: 4px 8px 12px; }
#nav a { display: block; padding: 6px 10px; border-radius: 6px; color: var(--fg); text-decoration: none; border: 1px solid transparent; }
#nav a:hover { background: var(--card); }
#nav a.active { background: var(--card); border-color: var(--line); }
.nav-group { margin: 14px 10px 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.side-foot { margin-top: auto; padding-top: 12px; }
.side-foot button { width: 100%; color: var(--muted); }
#view { padding: 16px 24px 24px; max-width: 1100px; width: 100%; outline: none; }
.page-head { display: flex; gap: 16px; justify-content: space-between; align-items: flex-end; flex-wrap: wrap; margin-bottom: 16px; }

/* content */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.host-card { display: block; color: inherit; text-decoration: none; margin: 0; }
.host-card:hover { border-color: var(--accent); }
.host-card h3 { margin: 0 0 2px; }
.host-card .live { margin-top: 8px; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; }
.dot.on { background: var(--good); } .dot.off { background: var(--bad); } .dot.idle { background: var(--muted); }
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; overflow-wrap: anywhere; }
th { color: var(--muted); font-weight: 600; }
pre { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 12px; overflow: auto;
  max-height: 50vh; white-space: pre-wrap; font: 12px/1.45 "Cascadia Mono", Consolas, monospace; }
.chart { width: 100%; height: 160px; display: block; }
.chart polyline { fill: none; stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.chart .cpu { stroke: var(--accent); } .chart .mem { stroke: var(--good); }
.chart .grid-line { stroke: var(--line); stroke-dasharray: 3 3; vector-effect: non-scaling-stroke; }
.legend .key { display: inline-block; width: 10px; height: 3px; margin: 0 4px 2px 8px; vertical-align: middle; }
.legend .key.cpu { background: var(--accent); } .legend .key.mem { background: var(--good); }

/* terminal */
.term { height: calc(100vh - 170px); min-height: 320px; background: var(--term-bg); border: 1px solid var(--line);
  border-radius: 8px; padding: 6px; overflow: hidden; }
.term-fallback { width: 100%; height: 100%; background: transparent; color: #e6edf3; border: 0; resize: none;
  font: 13px/1.35 "Cascadia Mono", Consolas, monospace; white-space: pre; }

/* switch */
.switch { position: relative; display: inline-block; width: 38px; height: 22px; margin: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--line); border-radius: 999px; transition: .15s; cursor: pointer; }
.switch span::before { content: ""; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .15s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::before { transform: translateX(16px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

/* modal + toast */
.modal { position: fixed; inset: 0; background: rgba(0, 0, 0, .55); z-index: 55; display: grid; place-items: center; padding: 16px; }
.modal-card { width: min(820px, 100%); max-height: calc(100vh - 32px); overflow: auto; margin: 0; }
.toast { position: fixed; right: 16px; bottom: 16px; z-index: 70; background: var(--card); border: 1px solid var(--line);
  border-left: 4px solid var(--good); border-radius: 8px; padding: 10px 14px; box-shadow: 0 6px 24px rgba(0, 0, 0, .3); max-width: calc(100vw - 32px); }
.toast.warn { border-left-color: var(--warn); } .toast.bad { border-left-color: var(--bad); }

/* narrow screens: sidebar becomes a drawer */
@media (max-width: 760px) {
  #app { grid-template-columns: minmax(0, 1fr); }
  .topbar { display: flex; align-items: center; gap: 10px; padding: 8px 16px; background: var(--panel);
    border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 30; }
  .topbar .brand { padding: 0; }
  #side { position: fixed; inset: 0 auto 0 0; width: 240px; z-index: 40; transform: translateX(-100%); transition: transform .2s; }
  body.nav-open #side { transform: none; box-shadow: 0 0 40px rgba(0, 0, 0, .5); }
  #view { padding: 12px 16px 24px; }
  .toolbar select, .toolbar input { width: 100%; }
  .term { height: calc(100vh - 230px); }
}
