:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --text: #15181e;
  --muted: #5b6472;
  --border: #e3e6eb;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --accent-soft: #e8efff;
  --danger: #c2410c;
  --ok: #15803d;
  --code-bg: #f0f2f5;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06);
  --radius: 10px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1216;
    --surface: #171b21;
    --text: #e6e9ee;
    --muted: #9aa4b2;
    --border: #262c35;
    --accent: #5b8def;
    --accent-text: #0b1020;
    --accent-soft: #1a2540;
    --danger: #f97316;
    --ok: #4ade80;
    --code-bg: #0b0e12;
    --shadow: none;
  }
}

:root[data-theme="dark"] {
  --bg: #0f1216;
  --surface: #171b21;
  --text: #e6e9ee;
  --muted: #9aa4b2;
  --border: #262c35;
  --accent: #5b8def;
  --accent-text: #0b1020;
  --accent-soft: #1a2540;
  --danger: #f97316;
  --ok: #4ade80;
  --code-bg: #0b0e12;
  --shadow: none;
}

* { box-sizing: border-box; }

/* Class display rules must not override the hidden attribute. */
[hidden] { display: none !important; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

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

code, pre { font-family: var(--mono); font-size: 0.9em; }
code { background: var(--code-bg); padding: 0.1em 0.35em; border-radius: 4px; }
pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  overflow-x: auto;
  margin: 12px 0 0;
}
pre code { background: none; padding: 0; }

h1 { font-size: clamp(1.9rem, 4vw, 2.8rem); line-height: 1.15; margin: 0 0 12px; letter-spacing: -0.02em; }
h3 { margin: 0 0 10px; font-size: 1.05rem; }
p { margin: 0 0 10px; }
.muted { color: var(--muted); }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 5;
}
.brand { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; color: var(--text); font-size: 1.1rem; }
.brand:hover { text-decoration: none; }
.brand-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.topnav { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.topnav a { color: var(--muted); font-size: 0.95rem; }
.user-chip { font-size: 0.9rem; color: var(--muted); max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

main { flex: 1; width: 100%; max-width: 1040px; margin: 0 auto; padding: 24px 16px 48px; }

.hero { padding: 36px 0 28px; max-width: 760px; }
.lead { font-size: 1.1rem; color: var(--muted); }
.hero-actions { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 18px; }

.grid { display: grid; gap: 16px; margin: 16px 0; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid.three { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  margin: 16px 0;
}
.grid .card { margin: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.card-head h3 { margin: 0; }

ul.plain { list-style: none; padding: 0; margin: 0; }
ul.plain li { padding: 4px 0; border-bottom: 1px dashed var(--border); }
ul.plain li:last-child { border-bottom: 0; }

.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.95rem;
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.btn:hover { border-color: var(--accent); text-decoration: none; }
.btn:disabled { opacity: 0.6; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn-primary:hover { filter: brightness(1.05); }
.btn-lg { padding: 12px 20px; font-size: 1.05rem; }
.btn-sm { padding: 4px 10px; font-size: 0.85rem; }
.btn-danger { color: var(--danger); }
.btn-danger:hover { border-color: var(--danger); }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }

.meter { height: 10px; background: var(--code-bg); border: 1px solid var(--border); border-radius: 999px; overflow: hidden; margin: 6px 0 8px; }
.meter-fill { height: 100%; width: 0; background: var(--accent); transition: width 0.3s ease; }
.meter-fill.warn { background: var(--danger); }

.table { width: 100%; border-collapse: collapse; font-size: 0.93rem; }
.table th, .table td { text-align: left; padding: 8px 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th { color: var(--muted); font-weight: 600; font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.03em; }
.table tr:last-child td { border-bottom: 0; }
.table.compact td, .table.compact th { padding: 5px 6px; }
.table-wrap { overflow-x: auto; }

.inline-form { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 14px; }
.inline-form label { display: flex; flex-direction: column; gap: 4px; font-size: 0.85rem; color: var(--muted); }
.inline-form input, .inline-form select {
  font: inherit;
  font-size: 0.95rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  min-width: 160px;
}

.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 0.8rem; border: 1px solid var(--border); }
.badge.ok { color: var(--ok); border-color: currentColor; }
.badge.off { color: var(--muted); }
.badge.warn { color: var(--danger); border-color: currentColor; }

.status {
  margin: 0 0 16px;
  padding: 10px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
}
.status.error { border-color: var(--danger); color: var(--danger); }

.footer {
  border-top: 1px solid var(--border);
  padding: 16px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 0.9rem;
}

.modal { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.5); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 20; }
.modal-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 22px; max-width: 640px; width: 100%; }
.token-row { display: flex; gap: 8px; align-items: center; }
.token { flex: 1; overflow-wrap: anywhere; padding: 8px 10px; }
.modal-actions { display: flex; justify-content: flex-end; margin-top: 16px; }

@media (max-width: 640px) {
  .topnav a:not(.btn) { display: none; }
  .table th:nth-child(4), .table td:nth-child(4) { display: none; }
}
