:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1c2024;
  --muted: #687076;
  --border: #dfe3e6;
  --accent: #3e63dd;
  --accent-text: #ffffff;
  --ok: #18794e;
  --warn: #ad5700;
  --bad: #cd2b31;
  --idle: #8b8d98;
  --console-bg: #111418;
  --console-text: #d7dde3;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111214;
    --surface: #1a1b1e;
    --text: #e8eaed;
    --muted: #9ba1a6;
    --border: #2e3135;
    --accent: #6e8cf7;
    --accent-text: #0b0d12;
    --ok: #4cc38a;
    --warn: #f1a10d;
    --bad: #ff6369;
    --idle: #6f6e77;
    --console-bg: #0a0b0d;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
h1 { font-size: 18px; margin: 0; }
h2 { font-size: 17px; margin: 0 0 12px; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--bad); white-space: pre-wrap; margin: 8px 0; }

button {
  font: inherit;
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
button:hover { border-color: var(--muted); }
button:disabled { opacity: .5; cursor: progress; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.ghost { background: transparent; }
button.danger { color: var(--bad); background: transparent; }
button.small { padding: 3px 8px; font-size: 12px; }

input, textarea {
  font: inherit;
  width: 100%;
  padding: 6px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}
input[readonly] { background: transparent; color: var(--muted); }
textarea { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; resize: vertical; }
label { display: block; color: var(--muted); font-size: 12px; margin: 6px 0; }
label input, label textarea { margin-top: 3px; color: var(--text); font-size: 14px; }
label.check { display: flex; align-items: center; gap: 6px; color: var(--text); font-size: 14px; }
label.check input { width: auto; margin: 0; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 24px; width: min(360px, 100%); }
.card h1 { margin-bottom: 12px; }
.card button { width: 100%; margin-top: 8px; }

.topbar {
  display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between;
  padding: 12px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 2;
}
.actions { display: flex; flex-wrap: wrap; gap: 6px; }
main { padding: 16px; max-width: 1400px; margin: 0 auto; }
.banner { background: var(--surface); border: 1px solid var(--warn); color: var(--warn); padding: 8px 12px; border-radius: 6px; overflow-wrap: anywhere; }

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; }
table { border-collapse: collapse; width: 100%; min-width: 900px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; font-weight: 600; color: var(--muted); }
tbody tr:last-child td { border-bottom: none; }
td .id { font-weight: 600; }
td .sub { color: var(--muted); font-size: 12px; }
td code { font-size: 12px; }
td.row-actions { white-space: nowrap; text-align: right; }
td.row-actions button { margin-left: 4px; }

.state { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--idle); flex: none; }
.dot.ok { background: var(--ok); }
.dot.warn { background: var(--warn); }
.dot.bad { background: var(--bad); }

.console {
  position: fixed; left: 0; right: 0; bottom: 0; height: 45vh; z-index: 3;
  background: var(--console-bg); color: var(--console-text);
  display: flex; flex-direction: column; border-top: 1px solid var(--border);
}
.console-bar { display: flex; justify-content: space-between; align-items: center; padding: 6px 12px; gap: 8px; }
.console-bar button { color: var(--console-text); border-color: #3a3f45; }
.console pre { margin: 0; padding: 0 12px 12px; overflow: auto; flex: 1; font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre-wrap; word-break: break-all; }

dialog {
  width: min(760px, calc(100vw - 32px)); max-height: calc(100vh - 32px);
  border: 1px solid var(--border); border-radius: 10px; padding: 20px;
  background: var(--surface); color: var(--text);
}
dialog::backdrop { background: rgb(0 0 0 / .45); }
fieldset { border: 1px solid var(--border); border-radius: 8px; margin: 12px 0; padding: 8px 12px 12px; }
legend { color: var(--muted); font-size: 12px; padding: 0 4px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0 12px; align-items: end; }
.forward { display: grid; grid-template-columns: 1fr 2fr 1fr 1.4fr 1fr auto; gap: 6px; margin-bottom: 6px; }
.dialog-actions { display: flex; gap: 8px; align-items: center; margin-top: 12px; }
.spacer { flex: 1; }

@media (max-width: 640px) {
  .forward { grid-template-columns: 1fr 1fr; }
  .console { height: 60vh; }
}
