:root {
  --bg0: #0f1c17;
  --bg1: #16261f;
  --ink: #e8f0ea;
  --muted: #9bb0a3;
  --line: #2a4035;
  --accent: #c4a35a;
  --accent-ink: #1a1408;
  --danger: #e07a5f;
  --up: #7dcea0;
  --down: #e07a5f;
  --row: rgba(255, 255, 255, 0.03);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: "IBM Plex Sans", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 10% -10%, #243d32 0%, transparent 55%),
    radial-gradient(900px 500px at 100% 0%, #2c2414 0%, transparent 50%),
    linear-gradient(160deg, var(--bg0), var(--bg1));
}

.shell {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
}

.top {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem 1.5rem;
  justify-content: space-between;
  align-items: end;
  margin-bottom: 1.25rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--line);
}

.brand {
  margin: 0;
  font-size: 1.6rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.sub {
  margin: 0.2rem 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  align-items: end;
}

.presets {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.presets button {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
  padding: 0.45rem 0.7rem;
}

.presets button.active {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
}

label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

label.toggle {
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
  text-transform: none;
  letter-spacing: 0;
  font-size: 0.85rem;
  padding-bottom: 0.45rem;
}

label.toggle input {
  min-width: auto;
  width: auto;
}

input {
  font: inherit;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.9rem;
  color: var(--ink);
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.45rem 0.55rem;
  min-width: 9.5rem;
}

input[type="search"] {
  min-width: 11rem;
}

button {
  font: inherit;
  font-weight: 500;
  border: 0;
  border-radius: 6px;
  padding: 0.55rem 0.95rem;
  background: var(--accent);
  color: var(--accent-ink);
  cursor: pointer;
}

button:hover { filter: brightness(1.05); }

button:disabled {
  opacity: 0.55;
  cursor: wait;
}

.back {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--line);
  margin-bottom: 1rem;
}

.error {
  color: var(--danger);
  background: rgba(224, 122, 95, 0.12);
  border: 1px solid rgba(224, 122, 95, 0.35);
  padding: 0.65rem 0.8rem;
  border-radius: 6px;
}

.loading, .empty {
  color: var(--muted);
  margin: 0.75rem 0;
}

.summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.summary div {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.75rem 0.85rem;
  background: rgba(0, 0, 0, 0.18);
}

.summary dt {
  margin: 0;
  color: var(--muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.summary dd {
  margin: 0.25rem 0 0;
  font-family: "IBM Plex Mono", monospace;
  font-size: 1.45rem;
  font-weight: 500;
}

.summary .sum-active dd { color: var(--up); }
.summary .sum-quiet dd { color: var(--danger); }
.summary .sum-dormant dd { color: var(--muted); }

.segments {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 1rem;
}

.segments button {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
  padding: 0.4rem 0.75rem;
}

.segments button.active {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
}

.adoption {
  margin-bottom: 1.25rem;
}

.adoption h2 {
  margin-top: 0;
}

.adoption-sub {
  margin: -0.35rem 0 0.75rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.adoption-grid {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.85rem 1rem;
  background: rgba(0, 0, 0, 0.18);
}

.adoption-row {
  display: grid;
  grid-template-columns: 9rem 1fr 3rem;
  gap: 0.65rem;
  align-items: center;
}

.adoption-label {
  font-size: 0.88rem;
}

.adoption-bar {
  height: 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  overflow: hidden;
}

.adoption-bar span {
  display: block;
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
}

.adoption-count {
  font-family: "IBM Plex Mono", monospace;
  text-align: right;
  font-size: 0.9rem;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.18);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

th, td {
  text-align: left;
  padding: 0.65rem 0.75rem;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

th {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  font-weight: 500;
  cursor: pointer;
  user-select: none;
}

th[data-sort].sorted {
  color: var(--accent);
}

tbody tr:nth-child(even) { background: var(--row); }

tbody tr.school-row {
  cursor: pointer;
}

tbody tr.school-row:hover {
  background: rgba(196, 163, 90, 0.12);
}

tbody tr.quiet {
  opacity: 0.85;
}

tbody tr.quiet td:first-child::after {
  content: " quiet";
  color: var(--danger);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-left: 0.4rem;
}

tbody tr.dormant td:first-child::after {
  content: " dormant";
  color: var(--muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-left: 0.4rem;
}

td.num, th.num {
  font-family: "IBM Plex Mono", monospace;
  text-align: right;
}

.delta-up { color: var(--up); }
.delta-down { color: var(--down); }
.delta-flat { color: var(--muted); }

.modules-cell {
  white-space: normal;
  max-width: 14rem;
  color: var(--muted);
  font-size: 0.82rem;
}

.totals {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.totals div, .comms div {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.75rem;
  background: rgba(0, 0, 0, 0.18);
}

.totals dt, .comms dt {
  margin: 0;
  color: var(--muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.totals dd, .comms dd {
  margin: 0.3rem 0 0;
  font-family: "IBM Plex Mono", monospace;
  font-size: 1.2rem;
  font-weight: 500;
}

.totals .delta {
  display: block;
  margin-top: 0.25rem;
  font-size: 0.78rem;
  font-weight: 500;
}

.comms {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.charts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1rem;
}

.spark {
  height: 64px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.18);
  padding: 0.5rem 0.6rem;
}

.spark svg {
  width: 100%;
  height: 100%;
  display: block;
}

.spark .empty-spark {
  color: var(--muted);
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  height: 100%;
}

h2 {
  font-size: 1rem;
  font-weight: 600;
  margin: 1.5rem 0 0.6rem;
}

@media (max-width: 720px) {
  .shell { padding: 1rem; }
  .brand { font-size: 1.35rem; }
  .charts { grid-template-columns: 1fr; }
  .summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .adoption-row { grid-template-columns: 1fr 2.5rem; }
  .adoption-bar { display: none; }
}
