:root {
  --bg: #f4f5f7; --surface: #fff; --text: #1d2330; --muted: #6b7280; --border: #e3e6ea;
  --accent: #2563eb; --accent-text: #fff; --ok: #15803d; --ok-bg: #e7f6ec; --off: #6b7280; --off-bg: #eef0f3;
  --warn: #d97706; --crit: #dc2626; --crit-bg: #fdecec; --bar: #e5e7eb;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151b; --surface: #1b1f27; --text: #e6e8ec; --muted: #9aa2b1; --border: #2c323d;
    --accent: #4f8cff; --ok: #4ade80; --ok-bg: #16321f; --off: #9aa2b1; --off-bg: #262b35;
    --warn: #f59e0b; --crit: #f87171; --crit-bg: #3a1d1d; --bar: #2c323d;
    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; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }

button { font: inherit; border-radius: 6px; padding: 6px 12px; cursor: pointer; border: 1px solid var(--border); background: var(--surface); color: var(--text); }
button:disabled { opacity: .6; cursor: wait; }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
button.ghost { background: transparent; }
button.ghost:hover { background: var(--off-bg); }
button.danger { color: var(--crit); }
button.danger-solid { background: var(--crit); color: #fff; border-color: var(--crit); }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 7px 9px; width: 100%; }
input[readonly] { background: var(--off-bg); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
label { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; font-weight: 500; }
label small { font-weight: 400; }
label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; margin-bottom: 8px; }
label.check input { width: auto; }
fieldset { border: 1px solid var(--border); border-radius: 6px; margin: 0 0 12px; padding: 8px 12px 2px; display: flex; gap: 16px; flex-wrap: wrap; }
legend { padding: 0 4px; font-weight: 500; }

.top { display: flex; align-items: center; gap: 24px; padding: 10px 24px; background: var(--surface); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.brand { font-weight: 600; font-size: 16px; }
.tabs { display: flex; gap: 4px; }
.tabs button { border: 0; background: transparent; padding: 8px 14px; }
.tabs button.active { background: var(--off-bg); font-weight: 600; }
.user { margin-left: auto; color: var(--muted); }

main#app { padding: 20px 24px; max-width: 1400px; margin: 0 auto; }
.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar select, .toolbar input { width: auto; min-width: 200px; }
.spacer { flex: 1; }

.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: color-mix(in srgb, var(--off-bg) 50%, transparent); }
td.actions { text-align: right; white-space: nowrap; }
.link { text-decoration: none; color: inherit; }
.link:hover strong { color: var(--accent); }

.pill { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 999px; background: var(--off-bg); color: var(--off); }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.bar { height: 5px; background: var(--bar); border-radius: 3px; margin-top: 5px; min-width: 90px; overflow: hidden; }
.bar span { display: block; height: 100%; width: 0; background: var(--accent); }
.bar span.warn { background: var(--warn); }
.bar span.crit { background: var(--crit); }

.alert { padding: 9px 12px; border-radius: 6px; margin-bottom: 8px; }
.alert.error { background: var(--crit-bg); color: var(--crit); }
.alert.success { background: var(--ok-bg); color: var(--ok); }
#toasts { position: fixed; right: 20px; bottom: 20px; z-index: 100; display: flex; flex-direction: column; max-width: 420px; }
#toasts .alert { box-shadow: 0 4px 16px rgba(0,0,0,.15); }

dialog { border: 1px solid var(--border); border-radius: 10px; padding: 0; width: min(640px, calc(100vw - 32px)); background: var(--surface); color: var(--text); }
dialog::backdrop { background: rgba(0,0,0,.4); }
dialog form { padding: 20px 24px; }
dialog h2 { margin: 0 0 16px; font-size: 18px; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.row { display: flex; gap: 12px; }
.row > label { flex: 1; min-width: 0; }
.row.addr > label:first-child { flex: 3; }
.row.addr > label:last-child { flex: 2; }
.inline { display: flex; gap: 6px; }
.inline input { flex: 1; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 28px; }
.login-card { width: min(360px, 100%); }
.login-card h1 { margin: 0; font-size: 20px; }
.login-card p { margin: 2px 0 18px; }
.login-card button { width: 100%; margin-top: 4px; padding: 9px; }

@media (max-width: 700px) {
  .top { padding: 10px 16px; gap: 10px; }
  main#app { padding: 16px; }
  .row { flex-direction: column; gap: 0; }
  .toolbar select, .toolbar input { min-width: 0; flex: 1; }
}
