:root {
  --bg: #0e151c;
  --surface: #182330;
  --surface-alt: #1f2c3a;
  --border: #2a3846;
  --text: #e7ecf2;
  --text-muted: #8a97a6;
  --primary: #4f7cff;
  --primary-hover: #6690ff;
  --primary-text: #0b1016;
  --clean: #3ddc84;
  --clean-bg: #123120;
  --dirty: #ff6b6b;
  --dirty-bg: #3a1a1e;
  --warn-bg: #3a2f0c;
  --warn-text: #f0d477;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 2px 8px rgba(0, 0, 0, .25);
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f5f6f8;
    --surface: #ffffff;
    --surface-alt: #f2f4f7;
    --border: #e2e5ea;
    --text: #1a1d23;
    --text-muted: #6b7280;
    --primary: #3558e8;
    --primary-hover: #2a46c4;
    --primary-text: #ffffff;
    --clean: #1a7f37;
    --clean-bg: #e9f7ee;
    --dirty: #c62828;
    --dirty-bg: #fdecea;
    --warn-bg: #fff6e0;
    --warn-text: #7a5b00;
    --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  }
}

:root[data-theme="dark"] {
  --bg: #0e151c; --surface: #182330; --surface-alt: #1f2c3a; --border: #2a3846;
  --text: #e7ecf2; --text-muted: #8a97a6; --primary: #4f7cff; --primary-hover: #6690ff;
  --primary-text: #0b1016; --clean: #3ddc84; --clean-bg: #123120; --dirty: #ff6b6b;
  --dirty-bg: #3a1a1e; --warn-bg: #3a2f0c; --warn-text: #f0d477;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 2px 8px rgba(0,0,0,.25);
}
:root[data-theme="light"] {
  --bg: #f5f6f8; --surface: #ffffff; --surface-alt: #f2f4f7; --border: #e2e5ea;
  --text: #1a1d23; --text-muted: #6b7280; --primary: #3558e8; --primary-hover: #2a46c4;
  --primary-text: #ffffff; --clean: #1a7f37; --clean-bg: #e9f7ee; --dirty: #c62828;
  --dirty-bg: #fdecea; --warn-bg: #fff6e0; --warn-text: #7a5b00;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
}

* { box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  margin: 0;
  line-height: 1.5;
}

.wrap {
  max-width: 960px;
  margin: 0 auto;
  padding: 0 1.25rem 3rem;
}

header.topbar {
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  margin-bottom: 2rem;
}

header.topbar .wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 1rem;
  padding-bottom: 1rem;
}

.brand {
  font-weight: 700;
  font-size: 1.05rem;
  display: flex;
  align-items: center;
  gap: .5rem;
}

.brand .dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--primary);
  display: inline-block;
}

nav.tabs { display: flex; gap: .25rem; }

nav.tabs a {
  text-decoration: none;
  color: var(--text-muted);
  padding: .45rem .9rem;
  border-radius: 8px;
  font-size: .9rem;
  font-weight: 600;
}

nav.tabs a:hover { background: var(--bg); color: var(--text); }
nav.tabs a.active { background: var(--primary); color: var(--primary-text); }

h1 { font-size: 1.35rem; margin: 0 0 .35rem; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; }
p.lead { color: var(--text-muted); margin-top: 0; font-size: .92rem; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem 1.4rem;
  margin-bottom: 1.5rem;
}

.card legend, fieldset.card legend {
  font-weight: 700;
  font-size: .95rem;
  padding: 0 .4rem;
}

fieldset.card { border: 1px solid var(--border); }

label {
  display: block;
  margin-top: .85rem;
  margin-bottom: .3rem;
  font-weight: 600;
  font-size: .82rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .02em;
}

label:first-of-type { margin-top: 0; }

input[type=text], input[type=password], input[type=number], textarea, select {
  width: 100%;
  padding: .55rem .7rem;
  font-size: .92rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
}

input:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
}

textarea { min-height: 90px; font-family: "SF Mono", Consolas, monospace; font-size: .82rem; resize: vertical; }

.hint { font-size: .78rem; color: var(--text-muted); margin-top: .3rem; }

button, .btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .6rem 1.15rem;
  margin-top: 1rem;
  cursor: pointer;
  border: none;
  border-radius: 8px;
  background: var(--primary);
  color: var(--primary-text);
  font-weight: 600;
  font-size: .9rem;
}

button:hover, .btn:hover { background: var(--primary-hover); }
button:disabled { opacity: .6; cursor: default; }

button.secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}
button.secondary:hover { background: var(--bg); }

.checkbox-row { display: flex; align-items: center; gap: .55rem; margin-top: .85rem; }
.checkbox-row input { width: auto; }
.checkbox-row label { margin: 0; text-transform: none; font-weight: 500; font-size: .88rem; color: var(--text); }

.msg { padding: .7rem 1rem; border-radius: 8px; margin: 0 0 1.25rem; font-size: .9rem; }
.msg.ok { background: var(--clean-bg); color: var(--clean); }
.msg.err { background: var(--dirty-bg); color: var(--dirty); }
.msg.warn { background: var(--warn-bg); color: var(--warn-text); }

.stat-row { display: flex; gap: 1rem; margin-bottom: 1.5rem; flex-wrap: wrap; }
.stat {
  flex: 1 1 140px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  box-shadow: var(--shadow);
}
.stat .num { font-size: 1.6rem; font-weight: 700; line-height: 1; }
.stat .label { font-size: .78rem; color: var(--text-muted); margin-top: .35rem; text-transform: uppercase; letter-spacing: .03em; }
.stat.dirty .num { color: var(--dirty); }
.stat.clean .num { color: var(--clean); }

table { width: 100%; border-collapse: collapse; font-size: .88rem; }
th, td { text-align: left; padding: .6rem .8rem; border-bottom: 1px solid var(--border); }
th { font-size: .76rem; text-transform: uppercase; letter-spacing: .03em; color: var(--text-muted); font-weight: 700; background: var(--surface-alt); }
td.ip { font-family: "SF Mono", Consolas, monospace; }
tr:last-child td { border-bottom: none; }

.rbl-table-card { padding: 0; overflow: hidden; }
.rbl-table-card h2 { padding: 1.1rem 1.4rem 0; }
.rbl-table tr:nth-child(even) td { background: var(--surface-alt); }
.rbl-table th:first-child, .rbl-table td:first-child { padding-left: 1.4rem; }
.rbl-table th:last-child, .rbl-table td:last-child { padding-right: 1.4rem; }

.pill {
  display: inline-block;
  padding: .2rem .65rem;
  border-radius: 5px;
  font-size: .74rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .03em;
}
.pill.clean { background: var(--clean-bg); color: var(--clean); }
.pill.dirty { background: var(--dirty-bg); color: var(--dirty); }
.pill.neutral { background: var(--surface-alt); color: var(--text-muted); }

.pill-link {
  display: inline-block;
  padding: .2rem .65rem;
  border-radius: 5px;
  font-size: .74rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .03em;
  text-decoration: none;
}
.pill-link.dirty { background: var(--dirty); color: #1a0a0a; }
.pill-link.dirty:hover { opacity: .85; }

code {
  background: var(--bg);
  border: 1px solid var(--border);
  padding: .1rem .4rem;
  border-radius: 5px;
  font-size: .85em;
  word-break: break-all;
}

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 640px) { .grid-2 { grid-template-columns: 1fr; } }

.cron-log {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .7rem .9rem;
  margin: .5rem 0 0;
  max-height: 260px;
  overflow: auto;
  font-size: .78rem;
  line-height: 1.6;
  color: var(--text-muted);
  white-space: pre-wrap;
  word-break: break-all;
}

.footer-note { color: var(--text-muted); font-size: .8rem; margin-top: 2rem; }
.footer-note.center { text-align: center; }

/* ---- Topbar: nav + signed-in user ---- */
.nav-right { display: flex; align-items: center; gap: 1rem; }
.user-box { display: flex; align-items: center; gap: .6rem; font-size: .82rem; color: var(--text-muted); white-space: nowrap; }
.user-box strong { color: var(--text); font-weight: 600; }
.user-box a {
  text-decoration: none;
  color: var(--text);
  border: 1px solid var(--border);
  padding: .35rem .8rem;
  border-radius: 8px;
  font-size: .8rem;
  font-weight: 600;
}
.user-box a:hover { background: var(--bg); border-color: var(--primary); }
@media (max-width: 720px) {
  header.topbar .wrap { flex-wrap: wrap; gap: .6rem; }
  .nav-right { width: 100%; justify-content: space-between; }
  .user-box span { display: none; }
}

/* ---- Login / setup page ---- */
body.login-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem 1rem;
}
.login-wrap { width: 100%; max-width: 420px; }
.login-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .55rem;
  font-weight: 700;
  font-size: 1.15rem;
  margin-bottom: 1.25rem;
}
.login-brand .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--primary); display: inline-block; }
.login-card { padding: 1.6rem 1.6rem 1.5rem; margin-bottom: 1rem; }
.login-card h1 { font-size: 1.25rem; margin-bottom: .25rem; }
.login-card p.lead { margin-bottom: 1.1rem; }
.login-card label:first-of-type { margin-top: 0; }
button.full { width: 100%; justify-content: center; margin-top: 1.25rem; }

#spinner { display: none; align-items: center; gap: .5rem; margin-top: 1rem; color: var(--text-muted); font-size: .85rem; }
#spinner.active { display: flex; }
.spin {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
