:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --fg: #1d2330;
  --muted: #667085;
  --line: #e3e6eb;
  --input: #ffffff;
  --accent: #2f6fed;
  --accent-fg: #ffffff;
  --ok: #14804a;
  --ok-bg: #e6f6ec;
  --warn: #8a5a00;
  --warn-bg: #fff4d6;
  --err: #b42318;
  --err-bg: #fdecea;
  --chip: #eef1f5;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121418;
    --card: #1b1e24;
    --fg: #e8eaed;
    --muted: #9aa3b2;
    --line: #2c313a;
    --input: #14171c;
    --accent: #5b8cff;
    --accent-fg: #0b1020;
    --ok: #5fd394;
    --ok-bg: #14301f;
    --warn: #f3c969;
    --warn-bg: #3a2f12;
    --err: #ff8a80;
    --err-bg: #3a1c1a;
    --chip: #262a32;
  }
}

* { box-sizing: border-box; }

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

.hidden { display: none !important; }

code, .mono { font-family: ui-monospace, Consolas, "SF Mono", monospace; font-size: 13px; }
code { background: var(--chip); padding: 1px 5px; border-radius: 5px; }

h1 { font-size: 22px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 8px; }
h2:not(:first-child) { margin-top: 20px; }

.hint { color: var(--muted); margin: 0 0 12px; }
.sub { color: var(--muted); font-size: 12px; }
.error { color: var(--err); min-height: 1.5em; margin: 8px 0 0; }

button {
  font: inherit;
  padding: 7px 14px;
  border-radius: 8px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-fg);
  cursor: pointer;
  white-space: nowrap;
}
button:hover { filter: brightness(1.08); }
button.ghost { background: transparent; color: var(--fg); border-color: var(--line); }
button.danger { background: transparent; color: var(--err); border-color: var(--line); }
button.small { padding: 3px 9px; font-size: 13px; }

input, textarea, select {
  font: inherit;
  color: var(--fg);
  background: var(--input);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 10px;
  width: 100%;
}
input[type="checkbox"] { width: auto; }
textarea { font-family: ui-monospace, Consolas, monospace; resize: vertical; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

label { display: flex; flex-direction: column; gap: 4px; font-weight: 500; }
label small { font-weight: 400; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: 6px; font-weight: 400; white-space: nowrap; }

/* login */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: 10px; }

/* layout */
header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 20px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 5;
  flex-wrap: wrap;
}
.brand { font-weight: 700; font-size: 16px; }
nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
nav button { background: transparent; color: var(--muted); border-color: transparent; }
nav button.active { background: var(--chip); color: var(--fg); }

main { max-width: 1280px; margin: 0 auto; padding: 20px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 18px;
  margin-bottom: 16px;
}

.toolbar { display: flex; gap: 12px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar input { max-width: 340px; }
.toolbar .hint { margin: 0; }
.row { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; align-items: center; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }

.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; }
.stat .v { font-size: 22px; font-weight: 650; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat .l { color: var(--muted); font-size: 13px; }

.alert { border-radius: 10px; padding: 10px 14px; margin-bottom: 12px; background: var(--warn-bg); color: var(--warn); }

/* tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; background: var(--card); }
.card .table-wrap { border: 0; border-radius: 0; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-weight: 600; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
td.actions { min-width: 240px; }
td.actions > * { margin: 0 4px 4px 0; vertical-align: middle; }
tr.muted td { opacity: .55; }
.empty { color: var(--muted); padding: 18px; text-align: center; }

.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.off { background: var(--chip); color: var(--muted); }
.badge.err { background: var(--err-bg); color: var(--err); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--chip);
  border-radius: 7px;
  padding: 2px 4px 2px 8px;
  margin: 0 4px 4px 0;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 13px;
}
.chip small { color: var(--muted); font-family: system-ui, sans-serif; font-size: 11px; }
.chip button { padding: 0 6px; border: 0; background: transparent; color: var(--muted); font-size: 15px; line-height: 1.2; }
.chip button:hover { color: var(--err); }
.over { color: var(--err); font-weight: 600; }

/* dialogs */
dialog {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--card);
  color: var(--fg);
  padding: 22px;
  width: min(440px, calc(100vw - 32px));
}
dialog::backdrop { background: rgba(0, 0, 0, .45); }
dialog form { display: flex; flex-direction: column; gap: 12px; }

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--fg);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 10px;
  z-index: 50;
  max-width: calc(100vw - 32px);
}
.toast.err { background: var(--err); color: #fff; }

@media (max-width: 640px) {
  header { padding: 10px 16px; }
  main { padding: 16px; }
  #logout { margin-left: auto; }
}
