:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --text: #1d2430;
  --muted: #6b7585;
  --line: #e1e6ee;
  --accent: #2563eb;
  --ok: #16a34a;
  --off: #9aa3b2;
  --warn: #d97706;
  --danger: #dc2626;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111827;
    --panel: #1b2433;
    --text: #e6ebf2;
    --muted: #9aa6b8;
    --line: #2b3648;
    --accent: #5b8def;
  }
}
:root[data-theme="dark"] {
  --bg: #111827;
  --panel: #1b2433;
  --text: #e6ebf2;
  --muted: #9aa6b8;
  --line: #2b3648;
  --accent: #5b8def;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font: 14px/1.4 "Segoe UI", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}
.hidden { display: none !important; }

.top {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.brand { font-weight: 600; font-size: 16px; }
.summary { color: var(--muted); flex: 1; }
.top-actions { display: flex; gap: 8px; }

button {
  font: inherit; padding: 7px 12px; border-radius: 8px; border: 1px solid var(--accent);
  background: var(--accent); color: #fff; cursor: pointer;
}
button:hover { filter: brightness(1.08); }
button.ghost { background: transparent; color: var(--accent); }
button.small { padding: 5px 10px; font-size: 13px; }
button.warn { background: var(--warn); border-color: var(--warn); }
button.danger { background: var(--danger); border-color: var(--danger); }

input, select, textarea {
  font: inherit; width: 100%; padding: 8px; margin-top: 4px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--text);
}
textarea { font-family: Consolas, monospace; min-height: 120px; }

.login { display: flex; justify-content: center; padding: 60px 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.login-card { width: min(380px, 100%); display: grid; gap: 12px; }
.login-card h2 { margin: 0; }
.error { color: var(--danger); min-height: 1em; }

.layout {
  display: grid; grid-template-columns: minmax(300px, 420px) 1fr; gap: 16px;
  padding: 16px; align-items: start;
}
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; padding: 12px; }
}
.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  min-height: 300px;
}
.panel-head {
  display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 12px 14px; border-bottom: 1px solid var(--line); font-weight: 600;
}
.head-buttons { display: flex; gap: 6px; flex-wrap: wrap; }

.tree { padding: 8px; max-height: calc(100vh - 150px); overflow: auto; }
.firm { margin: 6px 0; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.firm > summary, .city > summary {
  cursor: pointer; padding: 8px 10px; display: flex; align-items: center; gap: 8px;
  list-style: none; user-select: none;
}
.firm > summary { background: color-mix(in srgb, var(--accent) 10%, var(--panel)); font-weight: 600; }
.firm > summary::-webkit-details-marker, .city > summary::-webkit-details-marker { display: none; }
.firm > summary::before, .city > summary::before { content: "▸"; color: var(--muted); transition: transform .15s; }
details[open] > summary::before { transform: rotate(90deg); }
.city { margin: 4px 0 4px 14px; border-left: 2px solid var(--line); padding-left: 6px; }
.city > summary { font-weight: 500; }
.count { margin-left: auto; color: var(--muted); font-size: 12px; }
.pcs { list-style: none; margin: 4px 0 6px 6px; padding: 0; }
.pc {
  display: flex; align-items: center; gap: 10px; padding: 7px 8px; border-radius: 8px; cursor: pointer;
}
.pc:hover { background: color-mix(in srgb, var(--accent) 8%, transparent); }
.pc.selected { background: color-mix(in srgb, var(--accent) 18%, transparent); }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--off); flex: none; }
.dot.on { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 25%, transparent); }
.pc-name { font-weight: 500; }
.pc-user { color: var(--muted); font-size: 12px; margin-left: auto; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 45%; }

.detail-panel { padding: 16px; }
.empty { color: var(--muted); padding: 60px 10px; text-align: center; }
.detail-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.pc-title { font-size: 18px; font-weight: 600; }
.pc-sub { color: var(--muted); }
.badge { padding: 4px 10px; border-radius: 999px; font-size: 12px; background: var(--off); color: #fff; white-space: nowrap; }
.badge.on { background: var(--ok); }
.badge.off { background: var(--off); }

.metrics {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin: 16px 0;
}
.metric { border: 1px solid var(--line); border-radius: 8px; padding: 10px; }
.metric .label { color: var(--muted); font-size: 12px; }
.metric .value { font-size: 20px; font-weight: 600; }
.meter { height: 6px; background: var(--line); border-radius: 3px; margin-top: 6px; overflow: hidden; }
.meter > span { display: block; height: 100%; background: var(--accent); }
.meter > span.hi { background: var(--danger); }

.actions { display: flex; gap: 6px; flex-wrap: wrap; }
.subhead { margin: 18px 0 8px; font-weight: 600; }
.commands { display: grid; gap: 8px; }
.cmd { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.cmd-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; color: var(--muted); font-size: 12px; }
.cmd-status { font-weight: 600; }
.cmd-status.done { color: var(--ok); }
.cmd-status.failed { color: var(--danger); }
.cmd-status.queued, .cmd-status.sent { color: var(--warn); }
.cmd-text { font-family: Consolas, monospace; white-space: pre-wrap; margin: 6px 0 0; font-size: 12px; }
.cmd-out { font-family: Consolas, monospace; white-space: pre-wrap; margin: 6px 0 0; font-size: 12px;
  max-height: 220px; overflow: auto; background: var(--bg); padding: 6px; border-radius: 6px; }

dialog {
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); color: var(--text);
  width: min(520px, calc(100% - 32px));
}
dialog::backdrop { background: rgba(0, 0, 0, .4); }
dialog h3 { margin: 0 0 12px; }
dialog label { display: block; margin-bottom: 10px; }
.dlg-error { color: var(--danger); min-height: 1em; margin-top: 4px; }
.dlg-buttons { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.token-box { font-family: Consolas, monospace; word-break: break-all; background: var(--bg); padding: 10px; border-radius: 8px; }

.files { display: grid; gap: 6px; }
.file-row { display: flex; gap: 10px; align-items: center; border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; font-size: 13px; }
.file-row .dir { color: var(--muted); font-size: 12px; white-space: nowrap; }
.file-row .fname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-row .fsize { color: var(--muted); font-size: 12px; margin-left: auto; white-space: nowrap; }
.file-row a.dl { color: var(--accent); text-decoration: none; white-space: nowrap; }

#screen-dlg { width: min(1180px, calc(100% - 20px)); max-width: none; padding: 0; overflow: hidden; }
.screen-top { display: flex; align-items: center; gap: 12px; padding: 8px 12px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
#screen-title { font-weight: 600; }
.screen-status { color: var(--ok); font-size: 12px; }
.screen-hint { color: var(--muted); font-size: 12px; flex: 1; min-width: 160px; }
.screen-top button { margin-left: auto; }
#screen-img { display: block; width: 100%; height: auto; max-height: calc(100vh - 120px); object-fit: contain; background: #000; cursor: crosshair; outline: none; }

.inv-when { color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.inv-grid { display: grid; gap: 4px; margin-bottom: 8px; }
.inv-row { display: flex; gap: 10px; font-size: 13px; border-bottom: 1px solid var(--line); padding: 3px 0; }
.inv-k { color: var(--muted); min-width: 150px; flex: none; }
.inv-ver { color: var(--muted); margin-left: auto; white-space: nowrap; }
.inv-soft summary { cursor: pointer; font-weight: 600; padding: 6px 0; }
.inv-soft-list { max-height: 260px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; }
.inv-soft-list .inv-k { min-width: 0; color: var(--text); }
