:root {
  --bg: #0b0d10;
  --surface: #14171c;
  --surface-2: #1a1e25;
  --surface-3: #212630;
  --line: #262b34;
  --line-soft: #1e232b;
  --text: #e7eaf0;
  --muted: #8b94a3;
  --dim: #616b7a;

  --accent: #ff7a45;
  --accent-soft: rgba(255, 122, 69, 0.12);
  --ok: #4ade80;
  --bad: #f87171;
  --warn: #fbbf24;

  --r: 10px;
  --r-sm: 7px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

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

.hidden { display: none !important; }
code {
  font: 12.5px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: var(--surface-3);
  padding: 2px 6px;
  border-radius: 5px;
  color: var(--text);
}
a { color: var(--accent); }

/* ---------- login ---------- */
.gate { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: min(330px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 28px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.login-mark, .mark {
  font-size: 17px; font-weight: 700; letter-spacing: -.02em;
  margin-bottom: 4px;
}
.login-mark span, .mark span { color: var(--accent); }

/* ---------- shell ---------- */
.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 208px;
  flex: none;
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 20px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.sidebar .mark { padding: 0 10px 16px; }
#nav { display: flex; flex-direction: column; gap: 2px; }

.nav-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%;
  background: none; border: 0;
  color: var(--muted);
  font: inherit;
  padding: 9px 10px;
  border-radius: var(--r-sm);
  cursor: pointer;
  text-align: left;
}
.nav-item svg { width: 16px; height: 16px; fill: currentColor; flex: none; opacity: .8; }
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); }
.nav-item.logout { margin-top: auto; color: var(--dim); }

.main {
  flex: 1;
  min-width: 0;
  padding: 24px 28px 56px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  max-width: 1120px;
}

/* ---------- topbar ---------- */
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  gap: 16px; flex-wrap: wrap;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line-soft);
}
.topbar-id { display: flex; align-items: center; gap: 12px; min-width: 0; }
.topbar-actions { display: flex; gap: 8px; }

h1 { font-size: 18px; font-weight: 650; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 11.5px; margin: 0; text-transform: uppercase; letter-spacing: .08em; color: var(--dim); font-weight: 650; }
p { margin: 0; }
.muted { color: var(--muted); font-size: 13px; }
.error { color: var(--bad); min-height: 18px; font-size: 13px; margin: 0; }
.empty { color: var(--dim); font-size: 13.5px; padding: 6px 2px; }
.hint { color: var(--muted); font-size: 13px; line-height: 1.6; }
.hint code { font-size: 12px; }

.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--dim); flex: none; }
.dot.on { background: var(--ok); box-shadow: 0 0 0 3px rgba(74, 222, 128, .15); }
.dot.off { background: var(--bad); box-shadow: 0 0 0 3px rgba(248, 113, 113, .15); }

.pill {
  font-size: 11.5px; color: var(--muted);
  background: var(--surface-3); border-radius: 20px; padding: 3px 10px;
}

/* ---------- cards ---------- */
.view { display: flex; flex-direction: column; gap: 18px; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.card-head-right { display: flex; align-items: center; gap: 12px; }
.check { font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 6px; cursor: pointer; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
.stat {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r); padding: 14px 16px;
  display: flex; flex-direction: column; gap: 3px;
}
.label { font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--dim); font-weight: 600; }
.value { font-size: 19px; font-weight: 650; letter-spacing: -.01em; }

.kv { display: flex; flex-direction: column; gap: 8px; }
.kv > div { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.kv .label { min-width: 90px; }

/* ---------- lists ---------- */
.list { display: flex; flex-direction: column; gap: 6px; }
.list .row-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-sm);
}
.row-item .grow { flex: 1; min-width: 0; }
.row-item .name { font-weight: 550; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-item .meta { font-size: 12px; color: var(--dim); }
.row-item.off { opacity: .55; }

/* ---------- console ---------- */
.console-card { gap: 12px; }
.console {
  height: min(58vh, 520px);
  overflow-y: auto;
  overscroll-behavior: contain;
  background: #07090b;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: 12px 14px;
  font: 12.5px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: pre-wrap;
  word-break: break-word;
  color: #c3ccd9;
}
.console div { padding: .5px 0; }
.console .warn { color: var(--warn); }
.console .err { color: var(--bad); }
.console .self { color: var(--accent); font-weight: 600; }
.console .sys { color: var(--ok); }

.cmd { display: flex; gap: 8px; }
.cmd input { flex: 1; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }

/* ---------- forms ---------- */
input, .select, textarea {
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: var(--r-sm);
  padding: 9px 11px;
  font: inherit;
  min-width: 0;
}
input::placeholder { color: var(--dim); }
input:focus, .select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.select { cursor: pointer; }

.form { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field.wide { grid-column: 1 / -1; }

.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row input { flex: 1; min-width: 180px; }

.btn {
  background: var(--accent); color: #17100c;
  border: 0; border-radius: var(--r-sm);
  padding: 9px 16px;
  font: inherit; font-weight: 650;
  cursor: pointer; white-space: nowrap;
}
.btn:hover { filter: brightness(1.08); }
.btn:disabled { opacity: .45; cursor: not-allowed; filter: none; }
.btn.sm { padding: 7px 13px; font-size: 13px; }
.btn.xs { padding: 5px 10px; font-size: 12px; }
.btn.ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); font-weight: 500; }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.danger { background: transparent; color: var(--bad); border: 1px solid rgba(248,113,113,.35); font-weight: 550; }
.btn.danger:hover { background: rgba(248,113,113,.12); }

.linklike { background: none; border: 0; color: var(--accent); font: inherit; padding: 0; cursor: pointer; text-decoration: underline; }

/* ---------- maps ---------- */
.maps { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 6px; max-height: 420px; overflow-y: auto; }
.map-btn {
  background: var(--surface-2); border: 1px solid var(--line-soft);
  color: var(--text); border-radius: var(--r-sm);
  padding: 9px 12px; font: inherit; font-size: 13px;
  cursor: pointer; text-align: left;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.map-btn:hover { border-color: var(--accent); color: var(--accent); }
.map-btn.current { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }

/* ---------- misc ---------- */
.job {
  background: #07090b; border: 1px solid var(--line); border-radius: var(--r-sm);
  padding: 10px 12px; max-height: 150px; overflow-y: auto;
  font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color: var(--muted);
}
.job .ok { color: var(--ok); }
.job .err { color: var(--bad); }

.toast {
  position: fixed; right: 20px; bottom: 20px; z-index: 50;
  background: var(--surface-3); border: 1px solid var(--line);
  border-radius: var(--r-sm); padding: 11px 15px;
  font-size: 13.5px; max-width: 360px;
  box-shadow: 0 10px 30px rgba(0,0,0,.45);
}
.toast.bad { border-color: rgba(248,113,113,.4); color: var(--bad); }
.toast.good { border-color: rgba(74,222,128,.35); color: var(--ok); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 6px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: #303845; }

/* ---------- responsive ---------- */
@media (max-width: 760px) {
  .shell { flex-direction: column; }
  .sidebar {
    width: 100%; flex-direction: row; align-items: center;
    border-right: 0; border-bottom: 1px solid var(--line);
    padding: 10px 12px; overflow-x: auto; gap: 6px;
  }
  .sidebar .mark { display: none; }
  #nav { flex-direction: row; gap: 4px; }
  .nav-item { padding: 7px 11px; font-size: 13px; }
  .nav-item svg { display: none; }
  .nav-item.logout { margin-top: 0; margin-left: auto; }
  .main { padding: 18px 16px 48px; }
  .topbar-actions { width: 100%; }
  .toast { left: 16px; right: 16px; max-width: none; }
}

/* ---------- settings groups ---------- */
.groups { display: flex; flex-direction: column; gap: 10px; }

.group { border: 1px solid var(--line-soft); border-radius: var(--r-sm); background: var(--surface-2); }
.group > summary {
  cursor: pointer; list-style: none;
  padding: 12px 14px;
  display: flex; align-items: center; gap: 10px;
  font-size: 13px; font-weight: 600; color: var(--text);
}
.group > summary::-webkit-details-marker { display: none; }
.group > summary::before {
  content: '▸'; color: var(--dim); font-size: 11px;
  transition: transform .15s;
}
.group[open] > summary::before { transform: rotate(90deg); }
.group > summary .count { margin-left: auto; font-size: 11.5px; color: var(--dim); font-weight: 400; }
.group-body { padding: 0 14px 14px; display: flex; flex-direction: column; gap: 14px; }
.group-help { font-size: 12.5px; color: var(--muted); line-height: 1.6; }
.group-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 14px; }

.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field.wide { grid-column: 1 / -1; }
.field-label { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
.field-label .label { text-transform: none; letter-spacing: 0; font-size: 12.5px; color: var(--text); font-weight: 550; }
.field-help { font-size: 11.5px; color: var(--dim); line-height: 1.5; }
.field.changed > .field-label .label { color: var(--accent); }
.field.changed input, .field.changed .select { border-color: var(--accent); }
.field code.cvar { font-size: 10.5px; color: var(--dim); background: none; padding: 0; }

.tag {
  font-size: 9.5px; text-transform: uppercase; letter-spacing: .06em; font-weight: 700;
  background: var(--surface-3); color: var(--muted);
  padding: 2px 6px; border-radius: 4px;
}

/* toggle */
.switch { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .track {
  width: 38px; height: 21px; border-radius: 20px; flex: none;
  background: var(--surface-3); border: 1px solid var(--line);
  position: relative; transition: background .15s, border-color .15s;
}
.switch .track::after {
  content: ''; position: absolute; top: 2px; left: 2px;
  width: 15px; height: 15px; border-radius: 50%;
  background: var(--dim); transition: transform .15s, background .15s;
}
.switch input:checked + .track { background: var(--accent-soft); border-color: var(--accent); }
.switch input:checked + .track::after { transform: translateX(17px); background: var(--accent); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }

input[type="number"] { -moz-appearance: textfield; }
input[type="search"] { min-width: 150px; }

.raw {
  width: 100%;
  font: 12.5px/1.6 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  resize: vertical;
}
details.card > summary { cursor: pointer; list-style: none; }
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary h2::after { content: ' ▸'; color: var(--dim); }
details.card[open] > summary h2::after { content: ' ▾'; }

.sticky-save {
  position: sticky; bottom: 0;
  background: linear-gradient(transparent, var(--surface) 30%);
  padding-top: 10px; margin: -4px -2px -2px;
}

.row-item .tag { flex: none; }
