/* PluruPush Admin — the one stylesheet. System fonts, light and dark, 375 px and up.
   No inline styles anywhere (the CSP forbids them); charts read their colours from here. */

:root {
  color-scheme: light dark;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --text: #16191f;
  --muted: #5d6573;
  --border: #d9dee6;
  --accent: #2357d9;
  --accent-text: #ffffff;
  --danger: #c4312b;
  --ok: #1f8a4c;
  --warn: #a86400;
  --chart-1: #2357d9;
  --chart-2: #c4312b;
  --chart-3: #1f8a4c;
  --chart-4: #a86400;
  --radius: 8px;
  --gap: 16px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216;
    --surface: #171b21;
    --surface-2: #1f252d;
    --text: #e6e9ee;
    --muted: #9aa3b2;
    --border: #2b323c;
    --accent: #7aa2ff;
    --accent-text: #0b1020;
    --danger: #ff7a73;
    --ok: #5ccf8f;
    --warn: #f0b45c;
    --chart-1: #7aa2ff;
    --chart-2: #ff7a73;
    --chart-3: #5ccf8f;
    --chart-4: #f0b45c;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: var(--accent); }
h1 { font-size: 1.5rem; margin: 0 0 var(--gap); overflow-wrap: anywhere; }
h2 { font-size: 1.1rem; margin: 0 0 12px; }
p { margin: 0 0 12px; }
.muted { color: var(--muted); }
.error { color: var(--danger); }
.ok { color: var(--ok); }
.warn { color: var(--warn); }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }

/* --- frame ------------------------------------------------------------------------- */

header.site {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px var(--gap);
  padding: 10px var(--gap);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand { font-weight: 650; white-space: nowrap; }

header.site nav { flex: 1 1 auto; overflow-x: auto; }
header.site nav ul { display: flex; gap: 4px; list-style: none; margin: 0; padding: 0; }
header.site nav a {
  display: block;
  padding: 6px 10px;
  border-radius: var(--radius);
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
}
header.site nav a:hover { background: var(--surface-2); }
header.site nav a[aria-current="page"] { background: var(--accent); color: var(--accent-text); }

form.period { display: flex; align-items: center; gap: 6px; }
form.period label { color: var(--muted); font-size: 0.85rem; white-space: nowrap; }
form.sign-out { margin: 0; }

main {
  flex: 1 0 auto;
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: var(--gap);
}

footer.site {
  padding: 12px var(--gap);
  color: var(--muted);
  font-size: 0.85rem;
  border-top: 1px solid var(--border);
  text-align: center;
}

/* --- controls ---------------------------------------------------------------------- */

input, select, button {
  font: inherit;
  color: inherit;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  padding: 6px 10px;
  min-height: 36px;
}

input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  cursor: pointer;
  font-weight: 600;
}
button.secondary { background: var(--surface-2); border-color: var(--border); color: var(--text); font-weight: 500; }
button.danger, a.button.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
a.button {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 6px 10px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  font-weight: 600;
  text-decoration: none;
}

/* --- building blocks --------------------------------------------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--gap);
  margin-bottom: var(--gap);
  min-width: 0;
  /* A wide table scrolls inside its card, never the page. */
  overflow-x: auto;
}

.grid {
  display: grid;
  gap: var(--gap);
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr));
  margin-bottom: var(--gap);
}
.grid > .card { margin-bottom: 0; }

.tiles {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  margin-bottom: var(--gap);
}

.tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.tile .label { display: block; color: var(--muted); font-size: 0.85rem; }
.tile .value { display: block; font-size: 1.6rem; font-weight: 650; font-variant-numeric: tabular-nums; }

.chart { position: relative; height: 260px; }
.chart canvas { width: 100%; height: 100%; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.93rem; }
th, td { padding: 7px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { color: var(--muted); font-weight: 600; white-space: nowrap; }
th a { color: inherit; }
tbody tr:hover { background: var(--surface-2); }
/* Wide tables scroll on a phone instead of wrapping dates, tags and keys into stacks. */
.table-wrap td { white-space: nowrap; }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: var(--gap); }
.toolbar input[type="search"] { flex: 1 1 220px; }

.flash { border-left: 4px solid var(--ok); }
.flash.error { border-left-color: var(--danger); color: inherit; }

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

.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.actions form { margin: 0; }

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

body.login main { max-width: 360px; margin-top: 12vh; }
body.login form { display: flex; flex-direction: column; gap: 10px; }

/* --- htmx -------------------------------------------------------------------------- */

.htmx-request main, main.htmx-request { opacity: 0.6; transition: opacity 120ms; }

@media (max-width: 600px) {
  header.site { padding: 8px 12px; }
  header.site nav { flex-basis: 100%; }
  header.site nav ul { flex-wrap: wrap; }
  main { padding: 12px; }
  .tile .value { font-size: 1.35rem; }
}
