/* Global Admin. Single hand-written stylesheet: the panel is server-rendered
   and must not reach out to any CDN. No build step, no preprocessor. */

/* ---------- tokens ---------- */
:root {
  color-scheme: light dark;

  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #f7f9fc;
  --header-bg: #11161f;
  --header-text: #e8ecf4;
  --header-muted: #97a3b6;

  --text: #16202e;
  --muted: #5d6b80;
  --line: #dde3ec;
  --line-strong: #c6cfdc;

  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --on-accent: #ffffff;
  --accent-soft: rgba(37, 99, 235, 0.10);

  --ok: #17803d;
  --ok-soft: rgba(23, 128, 61, 0.12);
  --warn: #9a6400;
  --warn-soft: rgba(154, 100, 0, 0.14);
  --bad: #c02626;
  --bad-soft: rgba(192, 38, 38, 0.12);
  --neutral: #5d6b80;
  --neutral-soft: rgba(93, 107, 128, 0.12);

  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.06);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
          Arial, "Noto Sans", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
               "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1218;
    --surface: #161b23;
    --surface-2: #1b212b;
    --header-bg: #0a0e14;
    --header-text: #e6e9ef;
    --header-muted: #8b97a8;

    --text: #e3e8f0;
    --muted: #9aa5b6;
    --line: #262d38;
    --line-strong: #333c4a;

    --accent: #5a9dff;
    --accent-hover: #7fb3ff;
    --on-accent: #08111f;
    --accent-soft: rgba(90, 157, 255, 0.14);

    --ok: #56d364;
    --ok-soft: rgba(86, 211, 100, 0.14);
    --warn: #e3b341;
    --warn-soft: rgba(227, 179, 65, 0.14);
    --bad: #ff7b72;
    --bad-soft: rgba(255, 123, 114, 0.14);
    --neutral: #9aa5b6;
    --neutral-soft: rgba(154, 165, 182, 0.14);

    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  }
}

/* ---------- base ---------- */
* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 var(--font);
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: 24px; line-height: 1.25; margin: 0 0 6px; letter-spacing: -0.01em; }
h2 { font-size: 17px; line-height: 1.3; margin: 24px 0 10px; letter-spacing: -0.005em; }
h3 { font-size: 15px; margin: 16px 0 8px; }
p { margin: 8px 0; }

.muted { color: var(--muted); }
.mono { font-family: var(--font-mono); font-size: 13px; }
.error { color: var(--bad); }

/* ---------- header ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
  padding: 10px 24px;
  background: var(--header-bg);
  color: var(--header-text);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.topbar .brand {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--header-text);
  font-weight: 650;
  font-size: 15px;
  letter-spacing: -0.01em;
}
.topbar .brand:hover { text-decoration: none; opacity: 0.9; }
.topbar .brand svg { display: block; }

.topbar nav { display: flex; gap: 2px; flex-wrap: wrap; }
.topbar nav a {
  color: var(--header-muted);
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  font-size: 14px;
}
.topbar nav a:hover { color: var(--header-text); background: rgba(255, 255, 255, 0.06); text-decoration: none; }
/* Active item is marked by aria-current, so the state survives markup edits. */
.topbar nav a[aria-current="page"] {
  color: var(--header-text);
  background: rgba(255, 255, 255, 0.10);
  box-shadow: inset 0 -2px 0 var(--accent);
}

.topbar .session {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--header-muted);
  font-size: 14px;
}
.topbar .session form { margin: 0; }
.topbar .session .who { display: flex; align-items: center; gap: 6px; color: var(--header-text); }

main {
  padding: 24px;
  max-width: 1180px;
  margin: 0 auto;
}

.page-head { margin-bottom: 4px; }

/* ---------- cards ---------- */
.card, form.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  margin: 16px 0;
}
.card > :first-child { margin-top: 0; }
.card > :last-child { margin-bottom: 0; }
.card h2 { margin-top: 0; }

/* ---------- tables ---------- */
/* Wrapper scrolls instead of the page: a wide grid must not break narrow screens. */
.table-wrap {
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin: 16px 0;
}

table.grid {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  min-width: 560px;
}
table.grid th,
table.grid td {
  text-align: left;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
table.grid thead th {
  position: sticky;
  top: 0;
  background: var(--surface-2);
  color: var(--muted);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
  border-bottom: 1px solid var(--line-strong);
}
table.grid tbody tr:nth-child(even) { background: var(--surface-2); }
table.grid tbody tr:hover { background: var(--accent-soft); }
table.grid tbody tr:last-child td { border-bottom: 0; }

/* Numbers align on the right and keep equal digit width so columns stay readable. */
table.grid th.num, table.grid td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
table.grid td.ts, table.grid td.mono { font-family: var(--font-mono); font-size: 13px; white-space: nowrap; }
table.grid td.wrap { white-space: normal; }
table.grid .empty { color: var(--muted); text-align: center; padding: 22px; }

/* ---------- badges ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.6;
  white-space: nowrap;
  color: var(--neutral);
  background: var(--neutral-soft);
  border: 1px solid transparent;
}
.badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex: none;
}
.badge-online, .badge-fresh, .badge-ok { color: var(--ok); background: var(--ok-soft); }
.badge-stale, .badge-degraded { color: var(--warn); background: var(--warn-soft); }
.badge-offline, .badge-blocked, .badge-bad { color: var(--bad); background: var(--bad-soft); }
.badge-never_seen, .badge-unknown { color: var(--neutral); background: var(--neutral-soft); }

a .badge { text-decoration: none; }
a:hover .badge { text-decoration: none; filter: brightness(1.06); }

.counters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 12px 0; }

/* ---------- notices ---------- */
.notice {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  border: 1px solid transparent;
  border-left: 3px solid var(--warn);
  background: var(--warn-soft);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  margin: 12px 0;
}
.notice svg { flex: none; margin-top: 2px; color: var(--warn); }
.notice-bad { border-left-color: var(--bad); background: var(--bad-soft); }
.notice-bad svg { color: var(--bad); }

/* ---------- forms ---------- */
label { display: block; margin: 12px 0 5px; color: var(--muted); font-size: 13px; font-weight: 600; }

input[type=text], input[type=password], input[type=search], input[type=email],
textarea, select {
  width: 100%;
  padding: 9px 11px;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  font: inherit;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--accent); }

textarea { min-height: 320px; font-family: var(--font-mono); font-size: 13px; line-height: 1.5; }
textarea[rows] { min-height: 0; }

button, .button {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin-top: 14px;
  padding: 9px 16px;
  background: var(--accent);
  color: var(--on-accent);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font: inherit;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
}
button:hover, .button:hover { background: var(--accent-hover); text-decoration: none; }
button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button.secondary {
  background: transparent;
  color: inherit;
  border-color: currentColor;
  opacity: 0.85;
}
button.secondary:hover { background: rgba(127, 127, 127, 0.15); opacity: 1; }

pre {
  background: var(--surface-2);
  border: 1px solid var(--line);
  padding: 14px;
  border-radius: var(--radius-sm);
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 13px;
}

/* ---------- login ---------- */
.login-page { max-width: 440px; margin: 48px auto; padding: 0 16px; }
.login-page .logo { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; font-size: 18px; font-weight: 650; }
.login-page .logo svg { color: var(--accent); }

/* ---------- narrow screens ---------- */
@media (max-width: 720px) {
  .topbar { padding: 10px 16px; gap: 12px; }
  .topbar .session { margin-left: 0; width: 100%; }
  main { padding: 16px; }
  h1 { font-size: 20px; }
  .card, form.card { padding: 14px 16px; }
}

/* ---------- field grid ---------- */
/* Short inputs sit side by side; on a narrow screen they fall into one column. */
.field-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 0 18px;
  align-items: end;
}
.field-grid > div { min-width: 0; }
.field-grid label { margin-top: 0; }
.form-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.stat-row { display: flex; flex-wrap: wrap; gap: 8px 22px; margin: 0; }
.stat-row > span { white-space: nowrap; }
.stat-row b { font-variant-numeric: tabular-nums; }
