:root {
  color-scheme: light dark;
  --bg: #f7f7f5;
  --panel: #ffffff;
  --text: #1c1e21;
  --muted: #55595f;
  --line: #d3d5d8;
  --accent: #0b5cad;
  --accent-text: #ffffff;
  --danger: #a4161a;
  --ok: #1b6e3c;
  --warn: #8a5a00;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141517;
    --panel: #1d1f22;
    --text: #e8e9eb;
    --muted: #a9adb3;
    --line: #3a3d42;
    --accent: #7ab6f5;
    --accent-text: #0b1420;
    --danger: #ff8a8d;
    --ok: #6fd39a;
    --warn: #e8b95a;
  }
}

* { box-sizing: border-box; }

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

header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

header:empty { display: none; }
header .brand { font-weight: 700; margin-right: auto; color: var(--text); text-decoration: none; }

main { max-width: 860px; margin: 0 auto; padding: 16px; outline: none; }

h1 { font-size: 1.5rem; margin: 8px 0 16px; overflow-wrap: anywhere; }
h2 { font-size: 1.15rem; margin: 0 0 12px; }

a { color: var(--accent); }

section {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 16px;
  margin-bottom: 16px;
}

label { display: block; margin-bottom: 12px; font-weight: 600; }
label.check { display: flex; gap: 8px; align-items: flex-start; font-weight: 400; }
label small { display: block; font-weight: 400; color: var(--muted); }

input, select, textarea {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 8px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--muted);
  border-radius: 4px;
  font: inherit;
}

label.check input { width: auto; margin-top: 5px; flex: none; }
textarea { min-height: 96px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 14px; }

button {
  padding: 8px 14px;
  background: var(--accent);
  color: var(--accent-text);
  border: 1px solid var(--accent);
  border-radius: 4px;
  font: inherit;
  cursor: pointer;
}

button.plain { background: transparent; color: var(--accent); }
button.danger { background: transparent; color: var(--danger); border-color: var(--danger); }
button:disabled { opacity: .6; cursor: default; }

:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.spread { justify-content: space-between; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 8px 8px 0; border-bottom: 1px solid var(--line); vertical-align: top; overflow-wrap: anywhere; }
th { color: var(--muted); font-weight: 600; }

.table-wrap { overflow-x: auto; }
.mono { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 14px; overflow-wrap: anywhere; }
.muted { color: var(--muted); }

.error { color: var(--danger); font-weight: 600; }
.notice { color: var(--muted); }
.events { list-style: none; margin: 0; padding: 0; max-height: 16rem; overflow: auto; }
.events li { padding: 2px 0; }

.state-running, .state-succeeded { color: var(--ok); font-weight: 600; }
.state-failed, .state-purge_incomplete { color: var(--danger); font-weight: 600; }
.state-applying, .state-purging { color: var(--warn); font-weight: 600; }

pre {
  overflow-x: auto;
  padding: 12px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 4px;
  font-size: 13px;
  margin: 0;
}

dialog {
  width: min(480px, calc(100vw - 32px));
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 16px;
}

dialog::backdrop { background: rgba(0, 0, 0, .5); }

textarea.editor { min-height: 280px; }
pre .added { color: var(--ok, #1a7f37); }
pre .removed { color: var(--danger, #cf222e); }

[hidden] { display: none !important; }
