:root {
  --paper: #f6f8fb;
  --sheet: #ffffff;
  --sheet-soft: #f9f9f9;
  --header: #ebeff2;
  --grid: #d9e1e7;
  --grid-dark: #9fb2c1;
  --ink: #1f2933;
  --muted: #667085;
  --blue: #3c78b5;
  --navy: #1f4e78;
  --teal: #2f9e9b;
  --mint: #d9ead3;
  --peach: #fce2d2;
  --pink: #f4e0e9;
  --cyan: #daeef2;
  --green-soft: #e4f0e0;
  --yellow: #fff6db;
  --red: #d94f45;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  font-family: Aptos, "Segoe UI", sans-serif;
  background:
    linear-gradient(90deg, rgba(60, 120, 181, 0.08) 1px, transparent 1px),
    linear-gradient(rgba(60, 120, 181, 0.06) 1px, transparent 1px),
    var(--paper);
  background-size: 28px 28px;
}

.workbook {
  width: min(1520px, calc(100% - 24px));
  margin: 0 auto;
  padding: 18px 0;
}

.workbook-header,
.public-draft-banner,
.access-strip,
.formula-bar,
.sheet,
.handoff-drawer {
  border: 1px solid var(--grid);
  border-radius: 8px;
  background: var(--sheet);
  box-shadow: 0 10px 24px rgba(31, 78, 121, 0.1);
}

.workbook-header {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  padding: 18px;
  border-top: 6px solid var(--blue);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--blue);
  font-size: 12px;
  font-weight: 850;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1,
h2,
h3 {
  color: var(--navy);
}

.workbook-header p:last-child {
  max-width: 860px;
  margin-top: 8px;
  color: var(--muted);
}

.workbook-header a {
  color: var(--blue);
  font-weight: 800;
}

.public-draft-banner {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-top: 12px;
  padding: 12px 14px;
  border-left: 6px solid var(--teal);
  background: linear-gradient(90deg, var(--yellow), var(--cyan));
  box-shadow: none;
}

.public-draft-banner strong {
  color: var(--navy);
}

.public-draft-banner span {
  flex: 1 1 420px;
  color: var(--ink);
  line-height: 1.35;
}

.access-strip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
  padding: 12px;
  background: linear-gradient(90deg, var(--cyan), var(--yellow));
}

.access-strip label {
  display: grid;
  gap: 4px;
  color: var(--navy);
  font-size: 12px;
  font-weight: 800;
}

.access-strip select,
input,
textarea {
  min-height: 34px;
  border: 1px solid var(--grid-dark);
  border-radius: 6px;
  background: white;
  color: var(--ink);
  font: inherit;
}

.access-strip strong {
  color: var(--navy);
}

.role-summary {
  flex: 1 1 280px;
  color: var(--muted);
  line-height: 1.35;
}

.access-notice {
  margin-top: 8px;
  padding: 9px 12px;
  border: 1px solid var(--grid);
  border-radius: 7px;
  background: var(--yellow);
  color: var(--navy);
  font-size: 13px;
  font-weight: 750;
}

.sheet-tabs {
  display: flex;
  gap: 4px;
  margin-top: 14px;
  overflow-x: auto;
  border-bottom: 2px solid var(--blue);
}

.sheet-tabs button {
  flex: 0 0 auto;
  padding: 11px 14px;
  border: 1px solid var(--grid);
  border-bottom: 0;
  border-radius: 7px 7px 0 0;
  color: var(--navy);
  font-weight: 800;
  background: var(--header);
}

.sheet-tabs .active {
  background: var(--sheet);
  box-shadow: inset 0 3px 0 var(--teal);
}

.sheet-tabs button.locked,
.review-tabs button.locked {
  border-color: var(--grid);
  color: #8292a0;
  background: #eef2f5;
  cursor: help;
  opacity: 0.72;
}

.formula-bar {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  margin-top: 10px;
  padding: 10px 12px;
  overflow-x: auto;
  background: var(--sheet-soft);
}

.formula-bar span {
  flex: 0 0 auto;
  color: var(--blue);
  font-weight: 900;
}

.formula-bar div {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.formula-bar strong {
  color: var(--navy);
  font-size: 13px;
}

.formula-bar code {
  white-space: normal;
  overflow-wrap: anywhere;
  color: var(--ink);
}

.sheet {
  display: none;
  margin-top: 12px;
  padding: 16px;
}

.sheet.active {
  display: block;
}

.sheet-title-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 12px;
}

.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
  padding: 10px;
  border: 1px solid var(--grid);
  border-radius: 8px;
  background: var(--cyan);
}

.filter-row label {
  display: grid;
  gap: 4px;
  min-width: 190px;
  color: var(--navy);
  font-size: 12px;
  font-weight: 850;
}

.filter-row select {
  min-height: 34px;
  border: 1px solid var(--grid-dark);
  border-radius: 6px;
  background: white;
  color: var(--ink);
  font: inherit;
}

button {
  border: 1px solid var(--blue);
  border-radius: 6px;
  padding: 9px 12px;
  color: white;
  font: inherit;
  font-weight: 800;
  background: var(--blue);
}

.button-link {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid var(--blue);
  border-radius: 6px;
  background: var(--blue);
  color: white;
  font-weight: 800;
  text-decoration: none;
  white-space: nowrap;
}

.kpi-grid,
.setup-grid,
.workbook-card-grid,
.alert-list {
  display: grid;
  grid-template-columns: repeat(4, minmax(170px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.secondary-kpis article {
  background: var(--sheet) !important;
}

.accounting-flow-grid {
  display: grid;
  grid-template-columns: minmax(280px, 0.95fr) minmax(380px, 1.35fr);
  gap: 12px;
  margin-bottom: 14px;
}

.accounting-flow-grid > article {
  min-width: 0;
  padding: 13px;
  border: 1px solid var(--grid);
  border-radius: 8px;
  background: var(--sheet-soft);
}

.accounting-flow-grid h3 {
  margin-bottom: 10px;
}

.compact-card-list {
  display: grid;
  gap: 9px;
}

.compact-card-list .workbook-card {
  background: var(--sheet);
}

.rules-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.sample-overview {
  display: grid;
  grid-template-columns: 1.2fr repeat(4, minmax(150px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.sample-overview article {
  padding: 13px;
  border: 1px solid var(--grid);
  border-radius: 8px;
  background: var(--sheet);
}

.sample-overview article:first-child {
  background: var(--yellow);
}

.sample-overview strong,
.sample-sheet-card strong {
  display: block;
  color: var(--navy);
}

.sample-overview span,
.sample-sheet-card span {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.sample-overview .mini-actions,
.sample-sheet-card .mini-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 10px;
}

.mini-actions a {
  display: inline-flex;
  min-height: 30px;
  align-items: center;
  padding: 0 9px;
  border: 1px solid var(--grid-dark);
  border-radius: 6px;
  background: var(--cyan);
  color: var(--navy);
  font-size: 12px;
  font-weight: 850;
  text-decoration: none;
}

.sample-sheet-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.sample-sheet-card {
  overflow: hidden;
  border: 1px solid var(--grid);
  border-radius: 8px;
  background: var(--sheet);
}

.sample-sheet-card header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 13px;
  border-bottom: 1px solid var(--grid);
  background: var(--header);
}

.sample-preview-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 12px;
}

.sample-preview-pair.single-preview {
  grid-template-columns: 1fr;
}

.sample-preview {
  overflow: hidden;
  border: 1px solid var(--grid);
  border-radius: 8px;
  background: var(--sheet-soft);
}

.sample-preview b {
  display: block;
  padding: 8px 10px;
  color: var(--navy);
  background: var(--cyan);
}

.sample-preview img {
  display: block;
  width: 100%;
  height: auto;
}

.council-list-panel {
  display: flex;
  flex-direction: column;
}

.council-link-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  padding: 10px;
}

.council-link-grid a {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 7px 9px;
  border: 1px solid var(--grid);
  border-radius: 6px;
  background: var(--cyan);
  color: var(--navy);
  font-size: 12px;
  font-weight: 850;
  line-height: 1.2;
  text-decoration: none;
}

.locked-copy {
  grid-column: 1 / -1;
  padding: 10px;
  border: 1px solid var(--grid);
  border-radius: 6px;
  background: #eef2f5;
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

.rules-grid article,
.kpi-grid article,
.setup-grid article,
.workbook-card,
.alert-card,
.territory-card,
.handoff-card {
  padding: 13px;
  border: 1px solid var(--grid);
  border-radius: 8px;
  background: var(--sheet-soft);
}

.setup-action-card {
  display: grid;
  gap: 8px;
}

.setup-action-card small,
.handoff-card small,
.workbook-card small {
  color: var(--muted);
  line-height: 1.35;
}

.setup-action-card a,
.workbook-card a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  width: fit-content;
  padding: 0 10px;
  border: 1px solid var(--grid-dark);
  border-radius: 6px;
  background: var(--cyan);
  color: var(--navy);
  font-size: 12px;
  font-weight: 850;
  text-decoration: none;
}

.locked-card {
  opacity: 0.72;
  background: #eef2f5 !important;
}

.locked-card button {
  border-color: var(--grid-dark);
  background: #dbe3ea;
  color: #6b7785;
  cursor: not-allowed;
}

.kpi-grid article:nth-child(1),
.workbook-card:nth-child(1),
.alert-card:nth-child(1),
.handoff-card:nth-child(1) {
  background: var(--cyan);
}

.kpi-grid article:nth-child(2),
.workbook-card:nth-child(2),
.alert-card:nth-child(2),
.handoff-card:nth-child(2) {
  background: var(--mint);
}

.kpi-grid article:nth-child(3),
.workbook-card:nth-child(3),
.alert-card:nth-child(3),
.handoff-card:nth-child(3) {
  background: var(--peach);
}

.kpi-grid article:nth-child(4),
.workbook-card:nth-child(4),
.alert-card:nth-child(4),
.handoff-card:nth-child(4) {
  background: var(--pink);
}

a.handoff-card {
  display: block;
  color: var(--ink);
  text-decoration: none;
}

a.handoff-card:not(.locked-card):hover {
  border-color: var(--blue);
  box-shadow: inset 0 0 0 2px rgba(60, 120, 181, 0.2);
}

.rules-grid article {
  background: var(--yellow);
}

.rules-grid h3 {
  margin: 0 0 10px;
}

.rule-list {
  display: grid;
  gap: 8px;
}

.rule-list div {
  padding: 9px 10px;
  border: 1px solid var(--grid);
  border-radius: 6px;
  background: var(--sheet);
}

.rule-list strong,
.workbook-card strong,
.alert-card strong {
  display: block;
  color: var(--navy);
}

.rule-list span,
.workbook-card span,
.alert-card span {
  color: var(--muted);
  font-size: 13px;
}

.kpi-grid span,
.setup-grid span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.kpi-grid small {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
}

.kpi-grid strong,
.setup-grid strong {
  display: block;
  margin-top: 5px;
  color: var(--navy);
  font-size: 26px;
}

.grid-panel,
.table-wrap,
.fund-card {
  overflow-x: auto;
}

.fund-snapshot {
  display: grid;
  gap: 6px;
  padding: 12px;
}

.fund-snapshot span,
.fund-snapshot small {
  color: var(--muted);
}

.fund-snapshot strong {
  color: var(--navy);
  font-size: 22px;
}

table {
  width: 100%;
  min-width: 980px;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--sheet);
}

th,
td {
  padding: 10px 11px;
  border-right: 1px solid var(--grid);
  border-bottom: 1px solid var(--grid);
  text-align: left;
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  color: var(--navy);
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  background: var(--header);
}

td small {
  display: block;
  color: var(--muted);
}

.fund-card {
  margin-bottom: 12px;
  border: 1px solid var(--grid);
  border-radius: 8px;
  background: var(--sheet);
}

.fund-card h3 {
  margin: 0;
  padding: 10px 12px;
  color: var(--navy);
  background: var(--header);
}

.territory-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(220px, 1fr));
  gap: 12px;
}

.territory-card {
  display: grid;
  gap: 7px;
  min-height: 178px;
  background: var(--yellow);
}

.score-card {
  width: 100%;
  border-color: var(--grid);
  color: var(--ink);
  text-align: left;
  background:
    linear-gradient(135deg, rgba(218, 238, 242, 0.96), rgba(255, 246, 219, 0.96));
  cursor: pointer;
}

.score-card:hover {
  border-color: var(--blue);
  box-shadow: inset 0 0 0 2px rgba(60, 120, 181, 0.18), 0 12px 24px rgba(31, 78, 121, 0.12);
}

.territory-card h3,
.territory-card p {
  margin: 0;
}

.territory-card span,
.territory-card small {
  color: var(--muted);
}

.territory-card strong {
  color: var(--navy);
  font-size: 30px;
}

.score-card strong {
  display: inline-grid;
  width: 64px;
  height: 64px;
  place-items: center;
  border: 4px solid var(--teal);
  border-radius: 50%;
  background: white;
  font-size: 25px;
}

.territory-card a {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  min-height: 32px;
  padding: 0 10px;
  border: 1px solid var(--grid-dark);
  border-radius: 6px;
  background: var(--cyan);
  color: var(--navy);
  font-size: 12px;
  font-weight: 850;
  text-decoration: none;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(31, 41, 51, 0.45);
}

.score-modal {
  position: relative;
  width: min(760px, 100%);
  max-height: min(760px, calc(100vh - 36px));
  overflow: auto;
  padding: 22px;
  border: 1px solid var(--grid);
  border-top: 6px solid var(--teal);
  border-radius: 8px;
  background: var(--sheet);
  box-shadow: 0 24px 60px rgba(31, 78, 121, 0.28);
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 50%;
}

.score-breakdown-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 16px 0;
}

.score-breakdown-grid article,
.formula-note {
  padding: 13px;
  border: 1px solid var(--grid);
  border-radius: 8px;
  background: var(--cyan);
}

.score-breakdown-grid article:nth-child(2) {
  background: var(--mint);
}

.score-breakdown-grid article:nth-child(3) {
  background: var(--peach);
}

.score-breakdown-grid article:nth-child(4) {
  background: var(--pink);
}

.score-breakdown-grid span,
.score-breakdown-grid small,
.formula-note span {
  display: block;
  color: var(--muted);
}

.score-breakdown-grid strong {
  display: block;
  color: var(--navy);
  font-size: 28px;
}

.formula-note {
  display: grid;
  gap: 8px;
  background: var(--yellow);
}

.formula-note code {
  white-space: normal;
  overflow-wrap: anywhere;
}

.notice {
  margin-bottom: 12px;
  color: var(--muted);
}

.inline-action-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.inline-action-row .notice {
  margin-bottom: 0;
}

.handoff-drawer {
  margin-top: 12px;
  padding: 16px;
}

#handoffRows {
  display: grid;
  grid-template-columns: repeat(4, minmax(180px, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.review-tabs {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px;
  margin-bottom: 14px;
  padding: 10px;
  border: 1px solid var(--grid);
  border-radius: 8px;
  background: var(--sheet-soft);
}

.review-tabs button {
  min-height: 44px;
  border-color: var(--grid-dark);
  background: var(--sheet);
  color: var(--navy);
  text-align: center;
  white-space: normal;
  line-height: 1.2;
}

.review-tabs button.active {
  border-color: var(--blue);
  background: var(--blue);
  color: white;
}

.review-tabs button.locked {
  border-style: dashed;
  background: #f4f7f9;
}

.review-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(170px, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}

.review-summary article {
  display: grid;
  gap: 5px;
  padding: 13px;
  border: 1px solid var(--grid);
  border-radius: 8px;
  background: var(--cyan);
}

.review-summary article:nth-child(2) {
  background: var(--mint);
}

.review-summary article:nth-child(3) {
  background: var(--peach);
}

.review-summary article:nth-child(4) {
  background: var(--pink);
}

.review-summary span,
.review-summary small {
  color: var(--muted);
}

.review-summary strong {
  color: var(--navy);
  font-size: 24px;
}

.review-extra {
  margin-top: 12px;
}

.hidden {
  display: none !important;
}

@media (max-width: 760px) {
  .workbook-header,
  .sheet-title-row {
    display: block;
  }

  .kpi-grid,
  .sample-overview,
    .setup-grid,
    .rules-grid,
    .accounting-flow-grid,
    .workbook-card-grid,
    .alert-list,
    .review-summary,
    .sample-sheet-grid,
    .sample-preview-pair,
    .council-link-grid,
  .territory-grid,
  #handoffRows {
    grid-template-columns: 1fr;
  }
}
