:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1e222b;
  --line: #272c37;
  --text: #e6e9ef;
  --muted: #8b93a3;
  --accent: #4c8dff;
  --ok: #35c489;
  --warn: #e8b339;
  --bad: #f2585b;
  --radius: 10px;
}

* { box-sizing: border-box; }

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

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

/* ---------- shell ---------- */

.shell { display: flex; min-height: 100vh; align-items: stretch; }

/* Fixed rather than scrolling with the page: every screen here is a long table,
   and a nav that leaves the viewport is a nav you scroll back up to find. */
.sidebar {
  position: sticky;
  top: 0;
  flex: 0 0 220px;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-right: 1px solid var(--line);
  overflow-y: auto;
}

.brand {
  display: block;
  padding: 18px 20px 16px;
  font-weight: 650;
  letter-spacing: .2px;
  color: var(--text);
  border-bottom: 1px solid var(--line);
}
.brand:hover { text-decoration: none; }
.brand span { color: var(--muted); font-weight: 400; margin-left: 8px; font-size: 12px; }

.sidenav { display: flex; flex-direction: column; padding: 12px 0; flex: 1; }

.sidenav a {
  color: var(--muted);
  padding: 7px 20px;
  font-size: 13.5px;
  border-left: 2px solid transparent;
}
.sidenav a:hover { color: var(--text); background: var(--panel-2); text-decoration: none; }
.sidenav a.on { color: var(--text); background: var(--panel-2); border-left-color: var(--accent); }

/* Section labels, not links — they name a group of screens, they do not open one. */
.sidenav .group {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--muted);
  opacity: .65;
  padding: 18px 20px 6px;
}

.sidebar .who {
  padding: 14px 20px 18px;
  border-top: 1px solid var(--line);
  color: var(--text);
  font-size: 13px;
}
.sidebar .who form { margin-top: 10px; }
.sidebar .who .btn { width: 100%; }

.main { flex: 1; min-width: 0; }

.wrap { max-width: 1400px; margin: 0 auto; padding: 24px 28px; }

/* Under ~900px the sidebar becomes a strip along the top: the groups turn into
   run-in labels so the whole nav still fits on one or two lines. */
@media (max-width: 900px) {
  .shell { flex-direction: column; }

  .sidebar {
    position: static;
    flex: none;
    height: auto;
    width: 100%;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .brand { border-bottom: 0; padding-bottom: 12px; }

  .sidenav { flex-direction: row; flex-wrap: wrap; gap: 4px 10px; padding: 0 20px 14px; }
  .sidenav a { padding: 4px 8px; border-left: 0; border-radius: 6px; }
  .sidenav a.on { border-left: 0; }
  .sidenav .group { padding: 6px 0 6px 8px; width: 100%; }

  .sidebar .who { display: flex; align-items: center; gap: 12px; }
  .sidebar .who form { margin-top: 0; margin-left: auto; }
  .sidebar .who .btn { width: auto; }
}

h1 { font-size: 20px; margin: 0 0 4px; }
h2 { font-size: 14px; margin: 0 0 12px; color: var(--muted); font-weight: 600;
     text-transform: uppercase; letter-spacing: .6px; }
.sub { color: var(--muted); margin: 0 0 22px; }

/* ---------- panels ---------- */

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

.grid { display: grid; gap: 14px; }
.grid.tiles { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }

.tile {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}
.tile .k { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .6px; }
.tile .v { font-size: 26px; font-weight: 650; margin-top: 6px; font-variant-numeric: tabular-nums; }
.tile.warn .v { color: var(--warn); }
.tile.bad .v { color: var(--bad); }
.tile.ok .v { color: var(--ok); }
.tile a { color: inherit; }

/* ---------- tables ---------- */

table { width: 100%; border-collapse: collapse; }
th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--muted);
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--panel-2); }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }
.scroll { overflow-x: auto; }
.empty { color: var(--muted); padding: 24px 10px; text-align: center; }

/* ---------- bits ---------- */

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  border: 1px solid transparent;
  white-space: nowrap;
}
.badge.active   { color: var(--ok);   background: rgba(53,196,137,.12);  border-color: rgba(53,196,137,.3); }
.badge.suspended{ color: var(--bad);  background: rgba(242,88,91,.12);   border-color: rgba(242,88,91,.3); }
.badge.pending  { color: var(--warn); background: rgba(232,179,57,.12);  border-color: rgba(232,179,57,.3); }
.badge.drift    { color: var(--warn); background: rgba(232,179,57,.12);  border-color: rgba(232,179,57,.35); }
.badge.error    { color: var(--bad);  background: rgba(242,88,91,.12);   border-color: rgba(242,88,91,.3); }
.badge.synced   { color: var(--muted); background: var(--panel-2); border-color: var(--line); }
.badge.grace    { color: var(--accent); background: rgba(76,141,255,.12); border-color: rgba(76,141,255,.3); }

.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 7px; }
.dot.on  { background: var(--ok);  box-shadow: 0 0 0 3px rgba(53,196,137,.15); }
.dot.off { background: #4a5160; }

.muted { color: var(--muted); }
.small { font-size: 12px; }

/* ---------- forms & buttons ---------- */

.btn {
  display: inline-block;
  padding: 7px 13px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.btn:hover { border-color: #3b4252; filter: brightness(1.15); }
.btn.danger { color: var(--bad); border-color: rgba(242,88,91,.35); }
.btn.go     { color: var(--ok);  border-color: rgba(53,196,137,.35); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.sm { padding: 4px 9px; font-size: 12px; }

input[type=text], input[type=email], input[type=password], input[type=number], select {
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 10px;
  font: inherit;
  font-size: 13px;
}
input:focus, select:focus { outline: none; border-color: var(--accent); }

.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 16px; }
.filters input[type=text] { min-width: 240px; }
.actions { display: flex; gap: 8px; align-items: center; }

.flash {
  background: rgba(76,141,255,.1);
  border: 1px solid rgba(76,141,255,.35);
  color: #cfe0ff;
  padding: 10px 14px;
  border-radius: var(--radius);
  margin-bottom: 18px;
}

/* A reported failure — a connection test that did not answer, say. */
.flash.bad {
  background: rgba(242,88,91,.1);
  border-color: rgba(242,88,91,.35);
  color: #ffd4d5;
}
.error { color: var(--bad); font-size: 13px; margin-top: 8px; }

.pager { display: flex; gap: 6px; margin-top: 16px; flex-wrap: wrap; }
.pager a, .pager span {
  padding: 5px 10px; border: 1px solid var(--line); border-radius: 7px;
  color: var(--muted); font-size: 13px;
}
.pager .cur { background: var(--panel-2); color: var(--text); }

/* ---------- login ---------- */

.login { max-width: 360px; margin: 12vh auto; }
.login .panel { padding: 26px; }
.login label { display: block; font-size: 12px; color: var(--muted); margin: 14px 0 6px; }
.login input { width: 100%; }
.login .btn { width: 100%; margin-top: 20px; }

/* ---------- detail ---------- */

.kv { display: grid; grid-template-columns: 150px 1fr; gap: 10px 16px; }
.kv dt { color: var(--muted); font-size: 12.5px; }
.kv dd { margin: 0; }

.bar { height: 6px; background: var(--panel-2); border-radius: 3px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); }
.bar.ok  > i { background: var(--ok); }
.bar.warn > i { background: var(--warn); }
.bar.bad > i { background: var(--bad); }

/* ---------- column chart ---------- */

/* Plain divs rather than a charting library: twelve bars do not justify a
   JavaScript dependency, and this renders with scripting off. */
.chart { display: flex; align-items: flex-end; gap: 8px; height: 160px; padding-top: 8px; }
.chart .col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end;
              align-items: center; gap: 4px; height: 100%; min-width: 0; }
.chart .stack { width: 100%; display: flex; align-items: flex-end; justify-content: center;
                gap: 3px; height: 100%; }
.chart .stack i { display: block; width: 45%; max-width: 22px; border-radius: 3px 3px 0 0;
                  background: var(--accent); min-height: 2px; }
.chart .stack i.spend { background: #6b7387; }
.chart .col b { font-size: 11px; font-weight: 600; font-variant-numeric: tabular-nums; }
.chart .col span { font-size: 10.5px; color: var(--muted); white-space: nowrap;
                   overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.chart .col.peak .stack i { background: var(--ok); }

.legend { display: flex; gap: 16px; font-size: 12px; color: var(--muted); margin-top: 12px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px;
            background: var(--accent); margin-right: 6px; }
.legend i.spend { background: #6b7387; }

/* ---------- data entry forms ---------- */

/* The login screen styled its own labels; anything with more than two fields
   needs the same treatment, so this is the shared version. */
.form label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin: 16px 0 6px;
}

.form .panel > label:first-of-type,
.form .grid > div > label:first-of-type { margin-top: 0; }

.form input[type=text],
.form input[type=email],
.form input[type=number],
.form input[type=date],
.form select {
  width: 100%;
}

/* Help text sits tight under the field it explains, not floating between two. */
.form .small.muted { margin: 6px 0 0; }
.form .error { margin-top: 6px; }

.form code {
  background: var(--panel-2);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 12px;
}

/* ---------- confirm dialog ---------- */

/* A real element rather than window.confirm(): the native dialog cannot say
   which account is about to be cut off, and it blocks the whole tab. */
.confirm-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(8, 10, 14, .72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
}

.confirm {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px 24px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 18px 48px rgba(0, 0, 0, .5);
}

/* Section headings are uppercase; a question asked of the operator is not.
   Reset the global h2 treatment rather than shouting at them. */
.confirm h2 {
  margin: 0 0 10px;
  font-size: 16px;
  color: var(--text);
  text-transform: none;
  letter-spacing: 0;
}
.confirm p { margin: 0; color: var(--muted); font-size: 13.5px; }
.confirm p strong { color: var(--text); font-weight: 600; }

.confirm .actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 22px;
}

.confirm.bad h2 { color: var(--bad); }

/* Keyboard users land on Cancel, so Enter cannot cut somebody off by reflex. */
.confirm .btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: no-preference) {
  .confirm { animation: confirm-in .12s ease-out; }
  @keyframes confirm-in {
    from { opacity: 0; transform: translateY(-6px); }
    to   { opacity: 1; transform: none; }
  }
}
