:root {
  --bg: #f6f4f1;
  --surface: #ffffff;
  --surface-soft: #f2ece7;
  --ink: #18110f;
  --muted: #6f625c;
  --line: #e4dbd4;
  --blue: #f05a28;
  --green: #2e7d58;
  --red: #c9412f;
  --amber: #c65f1d;
  --teal: #d95621;
  --orange: #f05a28;
  --black: #140d0b;
  --shadow: 0 16px 45px rgba(20, 31, 43, 0.08);
  --radius: 8px;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  border-radius: var(--radius);
  background: var(--blue);
  color: #fff;
  cursor: pointer;
  min-height: 38px;
  padding: 0 14px;
  font-weight: 700;
}

button.secondary {
  background: #efe8e2;
  color: var(--ink);
}

button.danger {
  background: #f5dddd;
  color: #99251f;
}

button.chip {
  background: #fff;
  border: 1px solid var(--line);
  color: var(--ink);
  min-height: 34px;
}

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

.app-header {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  padding: 28px clamp(18px, 4vw, 48px);
  background:
    radial-gradient(circle at 6% 95%, rgba(240, 90, 40, 0.32), transparent 22%),
    linear-gradient(120deg, #140d0b 0%, #23120d 56%, #0e0c0b 100%);
  color: #fff;
  border-bottom: 5px solid var(--orange);
}

.app-header h1 {
  margin: 4px 0 6px;
  font-size: clamp(28px, 4vw, 46px);
  line-height: 1;
  letter-spacing: 0;
}

.lead {
  margin: 0;
  color: #f2dfd4;
  max-width: 760px;
}

.eyebrow {
  margin: 0;
  color: var(--teal);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.app-header .eyebrow {
  color: #ffb18e;
}

.header-actions {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  flex-wrap: wrap;
}

main {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 24px clamp(14px, 3vw, 34px) 48px;
}

.version-footer {
  width: 100%;
  margin: 0;
  padding: 9px clamp(14px, 3vw, 34px) 18px;
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.42);
}

.version-footer__inner {
  display: grid;
  gap: 2px;
  width: min(1440px, 100%);
  margin: 0 auto;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  line-height: 1.35;
  text-align: left;
}

.version-footer__row {
  display: flex;
  gap: 8px;
  align-items: baseline;
}

.version-footer__label {
  min-width: 118px;
  color: #7b6e68;
}

.version-footer__value {
  color: #4b403b;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  min-width: 0;
}

.section-heading {
  margin-bottom: 16px;
}

.section-heading h2,
.chart-panel h2 {
  margin: 4px 0 0;
  font-size: 20px;
  line-height: 1.2;
  letter-spacing: 0;
}

.with-action {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
}

.section-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  min-height: 92px;
}

.kpi-card span {
  color: var(--muted);
  font-size: 13px;
}

.kpi-card strong {
  display: block;
  margin-top: 8px;
  font-size: 24px;
  line-height: 1.1;
}

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(300px, 410px) 1fr;
  gap: 16px;
  align-items: start;
}

.simulation-stack {
  display: grid;
  gap: 16px;
  min-width: 0;
}

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

label span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input,
select {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  padding: 8px 10px;
}

input[type="checkbox"] {
  accent-color: var(--orange);
}

input[type="color"] {
  padding: 2px;
  min-width: 44px;
}

.static-value {
  display: flex;
  align-items: center;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
  color: var(--ink);
  padding: 8px 10px;
  font-weight: 700;
}

.suffix-input {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
}

.suffix-input input {
  border-radius: var(--radius) 0 0 var(--radius);
}

.suffix-input span {
  display: flex;
  align-items: center;
  min-height: 38px;
  margin: 0;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-left: 0;
  border-radius: 0 var(--radius) var(--radius) 0;
  background: var(--surface-soft);
}

.check-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 14px 0 0;
}

.check-row input {
  width: 18px;
  min-height: 18px;
}

.check-row span {
  margin: 0;
  color: var(--ink);
}

.manual-delegates {
  display: none;
  margin-top: 12px;
}

.manual-delegates.is-visible {
  display: block;
}

.single-only,
.small-census-only,
.personal-only {
  display: none;
}

body.single-mode .single-only,
body.small-census .small-census-only {
  display: block;
}

body.personal-mode .single-only,
body.personal-mode .personal-only {
  display: block;
}

body.personal-mode .personal-only {
  display: table-cell;
}

.college-box {
  margin-top: 14px;
}

.config-helper {
  margin-top: 10px;
}

.college-list {
  display: grid;
  gap: 12px;
}

.college-entry {
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.college-entry h3 {
  margin: 0 0 10px;
  font-size: 14px;
  line-height: 1.25;
}

.college-entry__fields {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.college-entry__fields label span {
  margin-bottom: 4px;
  font-size: 11px;
}

.college-entry__fields input {
  min-width: 0;
  padding-inline: 7px;
}

.college-entry--optional .college-toggle {
  margin-bottom: 10px;
}

.college-toggle {
  margin-top: 0;
}

.college-toggle .toggle-status {
  margin-left: auto;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 11px;
  line-height: 1;
  padding: 6px 8px;
  white-space: nowrap;
}

.college-toggle .toggle-status.is-on {
  background: #dff4ea;
  color: var(--green);
}

.tables-box {
  display: none;
  margin-top: 0;
}

.tables-box.is-visible {
  display: block;
}

.tables-box__heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.tables-box__heading h2 {
  margin: 4px 0 6px;
  font-size: 20px;
  line-height: 1.2;
}

.tables-box__title {
  margin: 0;
  font-size: 14px;
  font-weight: 800;
}

.toggle-status {
  margin-left: 4px;
  font-size: 11px;
  font-weight: 800;
}

.toggle-status.is-on {
  color: var(--green);
}

.tables-input-scroll {
  margin-top: 12px;
}

.tables-input-table {
  min-width: 900px;
  table-layout: fixed;
}

.tables-input-table .table-name-column {
  width: 17%;
}

.tables-input-table .table-college-column {
  width: 20%;
}

.tables-input-table .table-census-column {
  width: 12%;
}

.tables-input-table .table-votes-column {
  width: 13%;
}

.tables-input-table .table-other-total-column {
  width: 12%;
}

.tables-input-table .table-action-column {
  width: 14%;
}

.tables-input-table input,
.tables-input-table select {
  width: 100%;
  min-width: 0;
}

.tables-input-table .table-total-value {
  display: flex;
  width: 100%;
  min-height: 38px;
}

.config-summary {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.config-summary__item {
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
}

.config-summary__item span {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.config-summary__item strong {
  display: block;
  overflow-wrap: anywhere;
  font-size: 16px;
  line-height: 1.2;
}

.table-total-value,
.readonly-table-value {
  display: inline-block;
  min-width: 52px;
  font-weight: 800;
}

.candidate-total-value {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: fit-content;
  min-width: 60px;
  min-height: 34px;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
  color: var(--ink);
  font-weight: 700;
}

.table-detail-button {
  min-width: 78px;
  padding-inline: 10px;
}

.candidate-table-detail {
  display: none;
}

.candidate-table-detail.is-open {
  display: table-row;
}

.candidate-table-detail > td {
  padding: 0 8px 12px;
  background: #fffaf7;
}

.candidate-table-detail__inner {
  display: grid;
  gap: 10px;
  padding: 12px 14px;
  background: #fffaf7;
  white-space: normal;
}

.candidate-table-detail__inner strong {
  display: block;
}

.candidate-vote-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(max(150px, calc((100% - 32px) / 5)), 1fr));
  gap: 8px;
}

.candidate-vote-card {
  display: grid;
  gap: 6px;
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.candidate-vote-card__name {
  overflow: hidden;
  color: var(--ink);
  font-size: 13px;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.candidate-vote-card__label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.candidate-vote-card input {
  min-width: 0;
  width: 100%;
}

.scenario-buttons {
  display: flex;
  gap: 8px;
  margin-top: 16px;
  flex-wrap: wrap;
}

.table-scroll {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table {
  border-collapse: collapse;
  width: 100%;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px 8px;
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
}

th {
  color: #4d5b66;
  font-size: 12px;
  text-transform: uppercase;
}

.compact-table input {
  min-width: 82px;
}

.data-table input {
  min-width: 96px;
}

.data-table tbody tr:hover {
  background: #fff8f4;
}

.candidate-name {
  min-width: 160px;
}

.candidate-condition {
  min-width: 170px;
}

.helper {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.college-breakdown {
  display: grid;
  gap: 2px;
  white-space: normal;
  min-width: 230px;
  line-height: 1.3;
}

.college-breakdown span {
  display: block;
}

.muted-cell {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}

.college-votes {
  display: table-cell;
}

.college-3 {
  display: none;
}

body.third-college-enabled .college-3 {
  display: table-cell;
}

.single-votes {
  display: none;
}

body.single-mode .college-votes {
  display: none;
}

body.single-mode .single-votes {
  display: table-cell;
}

body.single-mode #collegeBox {
  display: none;
}

body.personal-mode .college-votes,
body.personal-mode #collegeBox {
  display: none;
}

body.personal-mode .single-votes {
  display: table-cell;
}

.notice-stack {
  display: grid;
  gap: 10px;
  margin: 16px 0;
}

.inputs-panel > .notice-stack {
  margin-bottom: 0;
}

.notice {
  border-left: 4px solid var(--amber);
  background: #fff4e7;
  border-radius: var(--radius);
  padding: 12px 14px;
  color: #5d2d0e;
}

.notice.critical {
  border-left-color: var(--red);
  background: #fff0ef;
  color: #77201b;
}

.notice.good {
  border-left-color: var(--green);
  background: #edf8f2;
  color: #155c3e;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  padding: 5px 9px;
  min-width: 48px;
  font-size: 12px;
  font-weight: 800;
}

.status-pill.yes {
  background: #dff4ea;
  color: var(--green);
}

.status-pill.no {
  background: #f8dddd;
  color: var(--red);
}

.status-pill.neutral {
  background: #e9eef3;
  color: #4c5964;
}

.represent-row.yes {
  background: #f2faf5;
}

.represent-row.no {
  background: #fff4f0;
}

.swatch {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  margin-right: 8px;
  vertical-align: middle;
}

.allocation-grid {
  display: grid;
  gap: 16px;
  min-width: 0;
}

.allocation-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
}

.allocation-card h3 {
  margin: 0 0 8px;
  font-size: 18px;
  letter-spacing: 0;
}

.allocation-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.allocation-meta span {
  background: var(--surface-soft);
  border-radius: 999px;
  padding: 5px 9px;
  color: #41505c;
  font-size: 12px;
  font-weight: 700;
}

.inline-select {
  min-width: min(260px, 100%);
}

.objective-controls {
  display: flex;
  align-items: end;
  gap: 12px;
  flex-wrap: wrap;
}

.inline-check {
  margin: 0 0 1px;
  min-height: 38px;
}

.charts-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  margin-top: 16px;
  align-items: start;
}

.chart-panel {
  min-height: 350px;
  overflow: hidden;
}

.chart-panel canvas {
  display: block;
  width: 100%;
  height: 260px;
  max-width: 100%;
}

main > .panel {
  margin-top: 16px;
}

@media (max-width: 1120px) {
  .kpi-grid,
  .charts-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .workspace-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .app-header {
    display: block;
  }

  .header-actions {
    margin-top: 18px;
  }

  .field-grid,
  .kpi-grid,
  .charts-grid {
    grid-template-columns: 1fr;
  }

  .config-summary {
    grid-template-columns: 1fr;
  }

  .with-action {
    display: block;
  }

  .section-actions {
    margin-top: 12px;
  }

  .with-action button,
  .with-action label {
    margin-top: 12px;
  }

  .section-actions button {
    margin-top: 0;
  }

  .tables-box__heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .tables-box__heading button {
    width: 100%;
  }

  main {
    overflow-x: hidden;
  }

  .allocation-card {
    padding: 12px;
  }

  .allocation-meta {
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 4px;
    -webkit-overflow-scrolling: touch;
  }

  .allocation-meta span {
    flex: 0 0 auto;
  }

  .allocation-card .data-table {
    min-width: 640px;
  }

  .version-footer {
    padding-bottom: 20px;
  }

  .version-footer__row {
    gap: 7px;
  }

  .version-footer__label {
    min-width: 112px;
  }
}

@media print {
  body {
    background: #fff;
  }

  .app-header,
  .panel,
  .kpi-card {
    box-shadow: none;
  }

  button,
  .header-actions,
  .scenario-buttons,
  #addCandidateBtn,
  .danger {
    display: none !important;
  }

  main {
    padding: 16px;
  }

  .workspace-grid,
  .charts-grid {
    grid-template-columns: 1fr;
  }
}
