:root {
  --bg: #101317;
  --panel: #181c22;
  --panel-2: #20252d;
  --border: #2c333d;
  --text: #e6e9ee;
  --muted: #8d96a3;
  --accent: #e8a33d;
  --good: #3fb36b;
  --bad: #e0524f;
  --busy: #5b8def;
  --radius: 8px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
[hidden] { display: none !important; }
h1 { font-size: 18px; margin: 0; letter-spacing: .02em; }
h2 { font-size: 13px; margin: 0 0 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
h3 { font-size: 15px; margin: 20px 0 4px; }
code { background: var(--panel-2); padding: 1px 5px; border-radius: 4px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--bad); min-height: 1.2em; margin: 8px 0 0; white-space: pre-wrap; }

button, input {
  font: inherit;
  color: inherit;
}
input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  min-width: 0;
}
input:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
input[type=checkbox] { accent-color: var(--accent); padding: 0; margin: 0; }

button {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 14px;
  cursor: pointer;
  white-space: nowrap;
}
button:hover:not(:disabled) { border-color: var(--muted); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: #1a1205; font-weight: 600; }
button.good { border-color: color-mix(in srgb, var(--good) 60%, var(--border)); }
button.bad { border-color: color-mix(in srgb, var(--bad) 60%, var(--border)); }
button.ghost { background: transparent; }
button.icon { padding: 6px 10px; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(360px, 100%); display: grid; gap: 14px; }
.login-card label { display: grid; gap: 4px; font-size: 14px; color: var(--muted); }
.login-card input { color: var(--text); }

/* Top bar */
.topbar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 12px 20px; border-bottom: 1px solid var(--border); background: var(--panel);
}
.spacer { flex: 1; }
.pill {
  font-size: 13px; font-weight: 600; padding: 3px 10px; border-radius: 999px;
  background: var(--panel-2); color: var(--muted); border: 1px solid var(--border);
}
.pill::before { content: "●"; margin-right: 6px; }
.pill[data-state=running] { color: var(--good); border-color: color-mix(in srgb, var(--good) 45%, transparent); }
.pill[data-state=stopped] { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 45%, transparent); }
.pill[data-state=busy] { color: var(--busy); border-color: color-mix(in srgb, var(--busy) 45%, transparent); }

/* Layout */
.layout {
  display: grid;
  gap: 16px;
  padding: 16px 20px 24px;
  grid-template-columns: minmax(280px, 380px) 1fr;
  grid-template-areas:
    "controls console"
    "maps console"
    "quick console";
  align-items: start;
  max-width: 1500px;
  margin: 0 auto;
}
.controls { grid-area: controls; }
.maps { grid-area: maps; }
.quick { grid-area: quick; }
.console { grid-area: console; display: flex; flex-direction: column; min-height: 0; height: calc(100vh - 100px); position: sticky; top: 16px; }

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; grid-template-areas: "controls" "console" "maps" "quick"; padding: 12px; }
  .console { height: 70vh; position: static; }
  .topbar { padding: 10px 12px; }
  #user-name { display: none; }
}

.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }
.btn-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; }
.btn-grid button { white-space: normal; line-height: 1.25; overflow-wrap: anywhere; }
.inline-form { display: flex; gap: 8px; margin-top: 12px; }
.inline-form input { flex: 1; }

/* Job output */
.job { margin-top: 14px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); }
.job summary { padding: 8px 10px; cursor: pointer; font-size: 13px; color: var(--muted); }
.job.failed summary { color: var(--bad); }
.job pre { margin: 0; padding: 8px 10px; max-height: 260px; overflow: auto; font-size: 12px; border-top: 1px solid var(--border); white-space: pre-wrap; word-break: break-word; }

/* Console */
.console-head { display: flex; justify-content: space-between; align-items: baseline; }
.console-output {
  flex: 1; min-height: 200px; margin: 0; overflow: auto;
  background: #0a0c0f; border: 1px solid var(--border); border-radius: 6px;
  padding: 10px 12px; font: 12.5px/1.5 ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  white-space: pre-wrap; word-break: break-word;
}
.console .inline-form input { font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; }

/* Settings dialog */
dialog {
  width: min(760px, calc(100vw - 24px));
  max-height: calc(100vh - 48px);
  background: var(--panel); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 20px;
}
dialog::backdrop { background: rgb(0 0 0 / .6); }
dialog h2 { font-size: 16px; color: var(--text); text-transform: none; letter-spacing: 0; }
dialog p { margin: 0 0 8px; }
.rows { display: grid; gap: 6px; margin-bottom: 6px; }
.row { display: flex; gap: 6px; align-items: center; }
.row .label-input { width: 150px; flex: none; }
.row .grow { flex: 1; }
.row label { display: flex; align-items: center; gap: 4px; color: var(--muted); }
@media (max-width: 600px) {
  .row { flex-wrap: wrap; }
  .row .label-input { width: 100%; }
}
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 6px;
  padding: 10px 16px; box-shadow: 0 6px 24px rgb(0 0 0 / .4); max-width: calc(100vw - 32px);
}
.toast.error { border-color: var(--bad); color: #ffb4b2; }
