:root {
  color-scheme: light;
  --ink: #111827;
  --muted: #667085;
  --line: #cfd6dd;
  --paper: #f3f4f1;
  --panel: #ffffff;
  --head: #eef2f6;
  --base: #1f4e79;
  --fact: #217346;
  --delayed: #bf8f00;
  --restored: #7030a0;
  --tech: #0f6b78;
  --churn-tech: #d35400;
  --churn-fact: #c00000;
  --renewal: #4a235a;
  --good-bg: #d9ead3;
  --mid-bg: #fff2cc;
  --bad-bg: #fce4d6;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: "Aptos", "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input {
  font: inherit;
}

button:disabled {
  cursor: wait;
  opacity: .65;
}

.report-shell {
  width: min(1500px, 100%);
  margin: 0 auto;
  padding: 16px;
}

.report-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 10px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.15;
  font-weight: 900;
  letter-spacing: 0;
}

.freshness,
.section-subtitle,
.note {
  color: var(--muted);
  margin: 4px 0 0;
  font-size: 12px;
}

.toolbar {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  flex-wrap: wrap;
}

.segmented {
  display: inline-flex;
  border: 1px solid #aab4bf;
  background: var(--panel);
  border-radius: 4px;
  overflow: hidden;
}

.segmented button,
.icon-button,
.expand-actions button {
  min-height: 32px;
  border: 1px solid #aab4bf;
  background: var(--panel);
  color: var(--ink);
  border-radius: 4px;
  padding: 6px 10px;
  font-size: 13px;
  font-weight: 800;
  text-decoration: none;
  cursor: pointer;
}

.segmented button {
  border: 0;
  border-radius: 0;
}

.segmented .is-active,
.icon-button.primary {
  background: var(--base);
  color: #fff;
}

.tab-button {
  min-width: 158px;
}

.icon-button.subtle {
  color: var(--muted);
}

.error-banner {
  background: var(--bad-bg);
  border: 1px solid #efb7a0;
  color: var(--churn-fact);
  padding: 10px 12px;
  border-radius: 4px;
  margin-bottom: 10px;
  font-weight: 800;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}

.kpi-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-top: 4px solid var(--base);
  border-radius: 4px;
  padding: 10px 12px;
  min-height: 96px;
}

.kpi-card:nth-child(2) {
  border-top-color: var(--fact);
}

.kpi-card:nth-child(3) {
  border-top-color: var(--restored);
}

.kpi-card:nth-child(4) {
  border-top-color: var(--churn-fact);
}

.money-kpis .kpi-card:nth-child(2) {
  border-top-color: var(--fact);
}

.money-kpis .kpi-card:nth-child(3) {
  border-top-color: var(--delayed);
}

.money-kpis .kpi-card:nth-child(4) {
  border-top-color: var(--churn-fact);
}

.kpi-card span,
.kpi-card small {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.kpi-card strong {
  display: block;
  margin-top: 7px;
  font-size: 28px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.kpi-card small {
  margin-top: 5px;
  font-size: 11px;
  line-height: 1.3;
}

.table-block {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 4px;
  margin-bottom: 12px;
  overflow: hidden;
}

.section-title {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfd;
}

.section-title h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 900;
}

.expand-actions {
  display: flex;
  gap: 6px;
}

.quarter-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.quarter-tabs {
  display: inline-flex;
  gap: 0;
  border: 1px solid #aab4bf;
  border-radius: 4px;
  overflow: hidden;
  background: var(--panel);
}

.quarter-tabs button {
  min-height: 32px;
  border: 0;
  border-right: 1px solid #aab4bf;
  background: var(--panel);
  color: var(--ink);
  padding: 6px 10px;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
}

.quarter-tabs button:last-child {
  border-right: 0;
}

.quarter-tabs .is-active {
  background: var(--base);
  color: #fff;
}

.quarter-export {
  min-height: 34px;
}

.table-wrap {
  width: 100%;
  overflow: auto;
  max-height: 62vh;
}

table {
  width: 100%;
  min-width: 1320px;
  border-collapse: collapse;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.detail-table {
  min-width: 1120px;
}

.wiki-quarter-table {
  min-width: 1760px;
}

th,
td {
  border: 1px solid var(--line);
  padding: 6px 7px;
  text-align: right;
  vertical-align: top;
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: var(--head);
  color: #344054;
  font-weight: 900;
}

.sticky-cell {
  position: sticky;
  left: 0;
  z-index: 2;
  min-width: 270px;
  text-align: left;
  background: inherit;
}

th.sticky-cell {
  z-index: 4;
  background: var(--head);
}

.status-row {
  color: #fff;
  font-weight: 900;
}

.status-row small {
  display: block;
  margin-top: 3px;
  color: rgba(255, 255, 255, .82);
  font-weight: 600;
}

.base { background: var(--base); }
.fact { background: var(--fact); }
.delayed { background: var(--delayed); }
.restored { background: var(--restored); }
.tech { background: var(--tech); }
.churn-tech { background: var(--churn-tech); }
.churn-fact { background: var(--churn-fact); }

.row-toggle {
  min-width: 24px;
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
  font-weight: 900;
}

.detail-row td {
  background: #fbfcfd;
  color: var(--ink);
  font-size: 12px;
}

.detail-row td + td {
  text-align: left;
  white-space: normal;
}

.detail-row span {
  display: inline-block;
  margin-right: 12px;
  color: #475467;
}

.person-pill {
  color: #111827 !important;
  font-weight: 900;
}

.membership-detail td {
  background: #faf5ff;
}

.percent-row {
  background: #d9ead3;
  color: #14532d;
  font-weight: 900;
}

.membership-head {
  background: var(--renewal);
  color: #fff;
  font-weight: 900;
}

.wiki-total-row {
  background: #edf4fb;
  color: var(--ink);
  font-weight: 900;
}

.wiki-quarter-table tfoot td {
  position: sticky;
  bottom: 0;
  z-index: 5;
  background: #edf4fb;
  box-shadow: 0 -2px 0 rgba(31, 78, 121, .22);
}

.wiki-quarter-table tfoot .sticky-cell {
  z-index: 6;
  background: #edf4fb;
}

.wiki-year-row {
  background: #d9ead3;
  color: var(--ink);
  font-weight: 900;
}

.wiki-detail-row td {
  background: #fff;
}

.wiki-quarter-table .sticky-cell {
  min-width: 180px;
}

.good-text {
  color: var(--fact);
  font-weight: 900;
}

.bad-text {
  color: var(--churn-fact);
  font-weight: 900;
}

.quarter-total {
  background: #f2f4f7;
  color: var(--ink);
  font-weight: 900;
}

.year-total {
  background: #e7eff8;
  color: var(--ink);
  font-weight: 900;
}

.pct-good {
  background: var(--good-bg);
  color: #14532d;
  font-weight: 900;
}

.pct-mid {
  background: var(--mid-bg);
  color: #7a5600;
  font-weight: 900;
}

.pct-bad {
  background: var(--bad-bg);
  color: var(--churn-fact);
  font-weight: 900;
}

.empty-row td {
  text-align: left;
  color: var(--muted);
}

[hidden] {
  display: none !important;
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
}

.login-shell {
  width: min(430px, calc(100% - 28px));
}

.login-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-top: 5px solid var(--base);
  border-radius: 4px;
  padding: 26px;
}

.login-form {
  display: grid;
  gap: 14px;
  margin-top: 22px;
}

.login-form label span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.login-form input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 9px 10px;
  background: #fff;
}

.login-form button {
  min-height: 44px;
  border: 0;
  border-radius: 4px;
  background: var(--base);
  color: #fff;
  font-weight: 900;
  cursor: pointer;
}

.form-error {
  min-height: 20px;
  margin: 0;
  color: var(--churn-fact);
  font-weight: 800;
}

@media (max-width: 860px) {
  .report-shell {
    padding: 10px;
  }

  .report-header {
    display: block;
  }

  .toolbar {
    justify-content: flex-start;
    margin-top: 10px;
  }

  .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .section-title {
    display: block;
  }

  .expand-actions {
    margin-top: 8px;
  }

  .quarter-tabs {
    margin-top: 8px;
  }

  .quarter-actions {
    justify-content: flex-start;
  }
}

@media (max-width: 520px) {
  .kpi-grid {
    grid-template-columns: 1fr;
  }

  .toolbar {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .segmented {
    grid-column: 1 / -1;
  }

  .tab-button {
    min-width: 0;
    width: 50%;
  }
}
