:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --text: #1f2933;
  --muted: #6b7280;
  --line: #e2e5e9;
  --accent: #2563eb;
  --on: #16a34a;
  --off: #9ca3af;
  --warn: #d97706;
  --bar: #1f2933;
  --bar-text: #ffffff;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418;
    --panel: #1b1f24;
    --text: #e5e7eb;
    --muted: #9aa3ad;
    --line: #2c323a;
    --accent: #60a5fa;
    --on: #22c55e;
    --off: #5b636d;
    --warn: #f59e0b;
    --bar: #0b0d10;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.bar {
  position: sticky; top: 0; z-index: 2;
  display: flex; align-items: center; gap: 8px;
  min-height: 52px;
  padding: 0 12px;
  padding-top: env(safe-area-inset-top);
  background: var(--bar); color: var(--bar-text);
}
.bar h1 {
  flex: 1; margin: 0;
  font-size: 18px; font-weight: 600;
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
}
.bar button { color: var(--bar-text); }

main { max-width: 900px; margin: 0 auto; padding: 12px 16px 24px; }

button { font: inherit; cursor: pointer; }
button.icon, button.link {
  min-width: 44px; min-height: 44px;
  background: none; border: 0;
}
button.icon { font-size: 22px; }
button.primary {
  min-height: 48px; width: 100%;
  border: 0; border-radius: 8px;
  background: var(--accent); color: #fff; font-weight: 600;
}
button.primary:disabled { opacity: .6; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 16px;
}
#login-form { max-width: 380px; margin: 8vh auto 0; display: grid; gap: 14px; }
label { display: grid; gap: 6px; font-size: 14px; color: var(--muted); }
input {
  font: inherit; color: var(--text);
  min-height: 46px; padding: 8px 12px;
  background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px;
}
input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.error { color: #dc2626; min-height: 1.4em; margin: 0; }
.muted { color: var(--muted); }

.tools { display: flex; gap: 10px; align-items: center; margin-bottom: 12px; }
.tools input[type=search] { flex: 1; min-width: 0; }
label.check { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
label.check input { min-height: 0; width: 20px; height: 20px; }

details.firm {
  background: var(--panel);
  border: 1px solid var(--line); border-radius: 10px;
  margin-bottom: 10px; overflow: hidden;
}
details.firm > summary {
  list-style: none;
  display: flex; align-items: center; gap: 10px;
  min-height: 52px; padding: 8px 14px;
  font-weight: 600; cursor: pointer;
}
details.firm > summary::-webkit-details-marker { display: none; }
summary .count { margin-left: auto; font-weight: 400; color: var(--muted); font-size: 14px; }

.place {
  padding: 6px 14px;
  font-size: 13px; color: var(--muted);
  background: var(--bg);
  border-top: 1px solid var(--line);
}
.machine {
  display: flex; align-items: center; gap: 12px;
  width: 100%; min-height: 56px; padding: 8px 14px;
  background: none; border: 0; border-top: 1px solid var(--line);
  color: inherit; text-align: left;
}
.machine:active { background: var(--bg); }
.machine .names { flex: 1; min-width: 0; }
.machine .t, .machine .n { display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.machine .n { font-size: 13px; color: var(--muted); }

.dot { flex: none; width: 12px; height: 12px; border-radius: 50%; background: var(--off); }
.dot.on { background: var(--on); }
.dot.warn { background: var(--warn); }

.badge {
  flex: none;
  font-size: 12px; padding: 2px 8px; border-radius: 999px;
  border: 1px solid var(--line); color: var(--muted);
}
.badge.old { border-color: var(--warn); color: var(--warn); }

#card h2 { margin: 0 0 4px; font-size: 20px; }
#card .sub { margin: 0 0 14px; color: var(--muted); }
.state { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; }
dl.props { display: grid; grid-template-columns: 1fr; gap: 2px 16px; margin: 0; }
dl.props dt { font-size: 13px; color: var(--muted); margin-top: 10px; }
dl.props dd { margin: 0; overflow-wrap: anywhere; }
ul.users { margin: 4px 0 0; padding-left: 18px; }

section.actions { margin: 4px 0 16px; padding-top: 12px; border-top: 1px solid var(--line); display: grid; gap: 10px; }
section.actions h3 { margin: 0; font-size: 16px; }
textarea.command {
  font: 14px/1.4 ui-monospace, "Cascadia Mono", Consolas, monospace;
  color: var(--text); background: var(--bg);
  width: 100%; padding: 10px 12px; resize: vertical;
  border: 1px solid var(--line); border-radius: 8px;
}
button.secondary, button.danger {
  min-height: 44px; padding: 0 14px;
  border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel); color: var(--text);
}
button.danger { background: #dc2626; border-color: #dc2626; color: #fff; font-weight: 600; }
button.small { min-height: 36px; justify-self: start; }
.row { display: flex; gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.row > button { flex: 1 1 auto; }
pre.job-output {
  margin: 0; max-height: 50vh; overflow: auto;
  padding: 10px; border-radius: 8px;
  background: #0b0d10; color: #d1d5db;
  font: 13px/1.35 ui-monospace, "Cascadia Mono", Consolas, monospace;
  white-space: pre-wrap; overflow-wrap: anywhere;
}
pre.job-output:empty { display: none; }
.job { display: grid; gap: 8px; }
.job-status { margin: 0; }

dialog {
  width: min(420px, calc(100vw - 32px));
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--panel); color: var(--text); padding: 0;
}
dialog::backdrop { background: rgba(0, 0, 0, .5); }
.dlg { display: grid; gap: 12px; padding: 16px; }
.dlg h3 { margin: 0; }
.dlg p { margin: 0; }
fieldset.choice { border: 0; margin: 0; padding: 0; display: grid; gap: 8px; }
fieldset.choice label.check { white-space: normal; color: var(--text); font-size: 15px; }

body.screen-open { overflow: hidden; }
.screen {
  position: fixed; inset: 0; z-index: 10;
  display: flex; flex-direction: column;
  background: #000;
}
.screen[hidden] { display: none; }
.screen-bar {
  display: flex; align-items: center; gap: 6px;
  min-height: 48px; padding: 0 6px;
  padding-top: env(safe-area-inset-top);
  background: #111; color: #fff;
}
.screen-bar button { color: #fff; }
.screen-bar .tool {
  min-height: 36px; padding: 0 10px;
  background: #2a2f36; border: 0; border-radius: 6px; font-size: 14px;
}
.screen-bar .tool[hidden] { display: none; }
.scr-title { flex: 1; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: 14px; }
.screen-view { flex: 1; min-height: 0; position: relative; overflow: hidden; touch-action: none; }
.scr-status {
  position: absolute; left: 16px; right: 16px; top: 45%;
  margin: 0; text-align: center; color: #d1d5db;
}
.scr-status[hidden] { display: none; }
.scr-input { position: absolute; left: -1000px; top: 0; width: 1px; height: 1px; opacity: 0; }

footer { text-align: center; font-size: 12px; padding: 8px 16px 24px; }

@media (min-width: 700px) {
  dl.props { grid-template-columns: 180px 1fr; }
  dl.props dt { margin-top: 0; padding: 6px 0; }
  dl.props dd { padding: 6px 0; }
}
