:root {
  --bg: #eef3f9;
  --panel: #ffffff;
  --border: #c9d3e1;
  --primary: #9c1c27;
  --primary-dark: #7a111c;
  --secondary: #123b7a;
  --secondary-soft: #dce7f8;
  --gold: #b88a2a;
  --text: #1f2a3d;
  --muted: #5d6b82;
  --success: #1c7c54;
  --danger: #d73333;
  --red-cell: #f43f3f;
  --white-cell: #fffaf1;
  --shadow: 0 16px 40px rgba(18, 59, 122, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: 'Be Vietnam Pro', sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top right, rgba(184, 138, 42, 0.18), transparent 20%),
    linear-gradient(180deg, #f7f9fc 0%, var(--bg) 100%);
}

button,
input {
  font: inherit;
}

.page-shell {
  max-width: 1600px;
  margin: 0 auto;
  padding: 32px 20px 40px;
}

.mode-tabs,
.ballot-tabs {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.mode-tab,
.ballot-tab {
  border: 1px solid rgba(18, 59, 122, 0.14);
  border-radius: 16px;
  padding: 14px 18px;
  background: rgba(255, 255, 255, 0.88);
  color: var(--secondary);
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--shadow);
}

.mode-tab.is-active,
.ballot-tab.is-active {
  background: linear-gradient(135deg, var(--secondary) 0%, #2759a8 100%);
  color: #fff;
  border-color: transparent;
}

.view-section.is-hidden {
  display: none;
}

.hero-card,
.panel,
.table-card,
.result-block,
.summary-card {
  background: var(--panel);
  border: 1px solid rgba(18, 59, 122, 0.12);
  border-radius: 22px;
  box-shadow: var(--shadow);
}

.hero-card {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  padding: 28px 32px;
  margin-bottom: 24px;
  border-top: 8px solid var(--primary);
}

.eyebrow {
  margin: 0 0 6px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--secondary);
  font-size: 13px;
  font-weight: 700;
}

.hero-card h1,
.hero-card h2 {
  margin: 0;
  font-size: clamp(28px, 4vw, 40px);
  color: var(--secondary);
}

.hero-title {
  margin: 8px 0 0;
  color: var(--primary);
  font-weight: 700;
}

.hero-guide-link {
  display: inline-flex;
  align-items: center;
  margin-top: 14px;
  padding: 10px 14px;
  border-radius: 12px;
  background: rgba(18, 59, 122, 0.08);
  color: var(--secondary);
  font-weight: 700;
  text-decoration: none;
}

.hero-guide-link:hover {
  background: rgba(18, 59, 122, 0.14);
}

.hero-badge {
  min-width: 220px;
  align-self: center;
  padding: 18px 20px;
  border-radius: 18px;
  background: linear-gradient(135deg, var(--secondary) 0%, #214f96 100%);
  color: #fff;
  text-align: center;
}

.hero-badge span {
  display: block;
  font-size: 14px;
  opacity: 0.8;
}

.hero-badge strong {
  display: block;
  margin-top: 6px;
  font-size: 18px;
}

.layout-grid {
  display: grid;
  grid-template-columns: minmax(340px, 480px) 1fr;
  gap: 24px;
}

.summary-layout-grid {
  align-items: start;
}

.panel {
  padding: 24px;
}

.panel-heading {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin-bottom: 16px;
}

.panel-heading h2,
.panel-heading h3,
.result-block h3 {
  margin: 0;
}

.sub-heading {
  margin-top: 24px;
}

.inline-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.config-notice {
  display: none;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(184, 138, 42, 0.14);
  color: var(--gold);
  font-size: 12px;
  font-weight: 700;
}

.config-notice.is-visible {
  display: inline-flex;
}

.is-hidden {
  display: none;
}

label {
  display: block;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--secondary);
}

label span {
  display: block;
  margin-bottom: 8px;
}

input {
  width: 100%;
  margin-top: 8px;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 14px;
  background: #fcfdff;
}

input:focus {
  outline: 2px solid rgba(18, 59, 122, 0.18);
  border-color: var(--secondary);
}

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

.candidate-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.summary-candidate-rows {
  display: grid;
  gap: 14px;
}

.summary-candidate-row {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(140px, 0.6fr);
  gap: 12px;
  padding: 14px;
  border-radius: 18px;
  border: 1px solid rgba(18, 59, 122, 0.12);
  background: linear-gradient(180deg, #fbfdff 0%, #f3f7fd 100%);
}

.step-button {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--secondary) 0%, #2759a8 100%);
  color: #fff;
  font-size: 20px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 6px 14px rgba(18, 59, 122, 0.18);
}

.step-button:hover {
  transform: translateY(-1px);
}

.step-button:active {
  transform: translateY(1px);
}

.decrement-button {
  background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 100%);
}

.grid-flash {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 1000;
  min-height: 0;
  margin: 0;
  border-radius: 12px;
  padding: 10px 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  max-width: min(420px, calc(100vw - 32px));
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  box-shadow: 0 12px 30px rgba(18, 59, 122, 0.22);
  transform: translateY(-10px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.grid-flash.flash-visible {
  opacity: 1;
  transform: translateY(0);
}

.flash-increase {
  background: rgba(28, 124, 84, 0.92);
}

.flash-decrease {
  background: rgba(156, 28, 39, 0.92);
}

.flash-edit {
  background: rgba(18, 59, 122, 0.92);
}

.helper-text {
  margin: 0 0 16px;
  color: var(--muted);
  line-height: 1.5;
}

.form-actions {
  margin-top: 20px;
}

.primary-button,
.secondary-button {
  border: none;
  border-radius: 14px;
  padding: 12px 18px;
  cursor: pointer;
  font-weight: 700;
}

.primary-button {
  background: linear-gradient(135deg, var(--primary) 0%, #bb2b37 100%);
  color: #fff;
  width: 100%;
}

.secondary-button {
  background: var(--secondary-soft);
  color: var(--secondary);
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.summary-card {
  padding: 18px;
}

.summary-card span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 6px;
}

.summary-card strong {
  display: block;
  font-size: 28px;
  color: var(--secondary);
}

.status-chip {
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(28, 124, 84, 0.12);
  color: var(--success);
  font-weight: 700;
  font-size: 13px;
}

.batch-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 14px;
  padding: 14px 16px;
  border: 1px solid rgba(18, 59, 122, 0.1);
  border-radius: 16px;
  background: linear-gradient(180deg, #f8fbff 0%, #eef4fc 100%);
}

.batch-status {
  display: grid;
  gap: 4px;
}

.batch-status strong {
  color: var(--secondary);
}

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

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  box-shadow: none;
}

.table-card {
  overflow: hidden;
}

.table-scroll {
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 880px;
}

th,
td {
  border: 1px solid var(--border);
  text-align: center;
  padding: 10px 8px;
}

th {
  background: linear-gradient(180deg, #eef3fb 0%, #dde8f8 100%);
  color: var(--secondary);
  font-size: 14px;
}

tbody tr:nth-child(even) td:not(.excluded-cell) {
  background: #fbfcff;
}

.excluded-cell {
  background: var(--red-cell);
  color: transparent;
}

.active-cell {
  background: var(--white-cell);
  font-weight: 600;
}

.count-control-cell {
  min-width: 190px;
}

.count-control {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}

.count-pill {
  min-width: 72px;
  padding: 8px 10px;
  border-radius: 999px;
  background: linear-gradient(180deg, #ffffff 0%, #eff4fb 100%);
  border: 1px solid rgba(18, 59, 122, 0.14);
  color: var(--secondary);
  font-weight: 800;
  line-height: 1;
}

.count-caption {
  display: block;
  width: 100%;
  color: var(--muted);
  font-size: 11px;
}

.editable-row {
  transition: background-color 0.2s ease;
}

.editable-row.row-updated td:not(.excluded-cell) {
  background: #eef8f2;
}

.total-row td {
  font-weight: 800;
  background: #f4efe3;
}

.results-bottom {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-top: 18px;
}

.result-block {
  padding: 18px;
}

.result-list {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.result-item {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 14px;
  border-radius: 14px;
  background: #f8fafc;
}

.result-item strong {
  color: var(--secondary);
}

.result-item .ok {
  color: var(--success);
}

.result-item .warn {
  color: var(--gold);
}

#summaryResultsTable th,
#summaryResultsTable td {
  text-align: left;
}

#summaryResultsTable td:last-child,
#summaryResultsTable th:last-child {
  text-align: right;
}

.rank-badge,
.winner-badge,
.pending-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.rank-badge {
  background: rgba(18, 59, 122, 0.12);
  color: var(--secondary);
}

.winner-badge {
  background: rgba(28, 124, 84, 0.12);
  color: var(--success);
}

.pending-badge {
  background: rgba(184, 138, 42, 0.14);
  color: var(--gold);
}

@media (max-width: 1120px) {
  .layout-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .hero-card {
    flex-direction: column;
  }

  .mode-tabs,
  .ballot-tabs {
    flex-direction: column;
  }

  .mode-tab,
  .ballot-tab {
    width: 100%;
  }

  .inline-fields,
  .results-bottom {
    grid-template-columns: 1fr;
  }

  .batch-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .inline-actions {
    justify-content: stretch;
  }

  .inline-actions .secondary-button,
  .inline-actions .config-notice {
    width: 100%;
    justify-content: center;
  }

  .step-button {
    width: 32px;
  }

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

.panel-heading h2,
.panel-heading h3,
.result-block h3 {
  margin: 0;
}

.sub-heading {
  margin-top: 24px;
}

.inline-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.config-notice {
  display: none;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(184, 138, 42, 0.14);
  color: var(--gold);
  font-size: 12px;
  font-weight: 700;
}

.config-notice.is-visible {
  display: inline-flex;
}

.is-hidden {
  display: none;
}

label {
  display: block;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--secondary);
}

label span {
  display: block;
  margin-bottom: 8px;
}

input {
  width: 100%;
  margin-top: 8px;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 14px;
  background: #fcfdff;
}

input:focus {
  outline: 2px solid rgba(18, 59, 122, 0.18);
  border-color: var(--secondary);
}

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

.candidate-grid {
  display: grid;
  gap: 12px;
}

.candidate-grid {
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.step-button {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--secondary) 0%, #2759a8 100%);
  color: #fff;
  font-size: 20px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 6px 14px rgba(18, 59, 122, 0.18);
}

.step-button:hover {
  transform: translateY(-1px);
}

.step-button:active {
  transform: translateY(1px);
}

.decrement-button {
  background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 100%);
}

.grid-flash {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 1000;
  min-height: 0;
  margin: 0;
  border-radius: 12px;
  padding: 10px 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  max-width: min(420px, calc(100vw - 32px));
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  box-shadow: 0 12px 30px rgba(18, 59, 122, 0.22);
  transform: translateY(-10px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.grid-flash.flash-visible {
  opacity: 1;
  transform: translateY(0);
}

.flash-increase {
  background: rgba(28, 124, 84, 0.92);
}

.flash-decrease {
  background: rgba(156, 28, 39, 0.92);
}

.flash-edit {
  background: rgba(18, 59, 122, 0.92);
}

.helper-text {
  margin: 0 0 16px;
  color: var(--muted);
  line-height: 1.5;
}

.form-actions {
  margin-top: 20px;
}

.primary-button,
.secondary-button {
  border: none;
  border-radius: 14px;
  padding: 12px 18px;
  cursor: pointer;
  font-weight: 700;
}

.primary-button {
  background: linear-gradient(135deg, var(--primary) 0%, #bb2b37 100%);
  color: #fff;
  width: 100%;
}

.secondary-button {
  background: var(--secondary-soft);
  color: var(--secondary);
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.summary-card {
  padding: 18px;
}

.summary-card span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 6px;
}

.summary-card strong {
  display: block;
  font-size: 28px;
  color: var(--secondary);
}

.status-chip {
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(28, 124, 84, 0.12);
  color: var(--success);
  font-weight: 700;
  font-size: 13px;
}

.batch-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 14px;
  padding: 14px 16px;
  border: 1px solid rgba(18, 59, 122, 0.1);
  border-radius: 16px;
  background: linear-gradient(180deg, #f8fbff 0%, #eef4fc 100%);
}

.batch-status {
  display: grid;
  gap: 4px;
}

.batch-status strong {
  color: var(--secondary);
}

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

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  box-shadow: none;
}

.table-card {
  overflow: hidden;
}

.table-scroll {
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 880px;
}

th,
td {
  border: 1px solid var(--border);
  text-align: center;
  padding: 10px 8px;
}

th {
  background: linear-gradient(180deg, #eef3fb 0%, #dde8f8 100%);
  color: var(--secondary);
  font-size: 14px;
}

tbody tr:nth-child(even) td:not(.excluded-cell) {
  background: #fbfcff;
}

.excluded-cell {
  background: var(--red-cell);
  color: transparent;
}

.active-cell {
  background: var(--white-cell);
  font-weight: 600;
}

.count-control-cell {
  min-width: 190px;
}

.count-control {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}

.count-pill {
  min-width: 72px;
  padding: 8px 10px;
  border-radius: 999px;
  background: linear-gradient(180deg, #ffffff 0%, #eff4fb 100%);
  border: 1px solid rgba(18, 59, 122, 0.14);
  color: var(--secondary);
  font-weight: 800;
  line-height: 1;
}

.count-caption {
  display: block;
  width: 100%;
  color: var(--muted);
  font-size: 11px;
}

.editable-row {
  transition: background-color 0.2s ease;
}

.editable-row.row-updated td:not(.excluded-cell) {
  background: #eef8f2;
}

.total-row td {
  font-weight: 800;
  background: #f4efe3;
}

.results-bottom {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-top: 18px;
}

.result-block {
  padding: 18px;
}

.result-list {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.result-item {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 14px;
  border-radius: 14px;
  background: #f8fafc;
}

.result-item strong {
  color: var(--secondary);
}

.result-item .ok {
  color: var(--success);
}

.result-item .warn {
  color: var(--gold);
}

@media (max-width: 1120px) {
  .layout-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .hero-card {
    flex-direction: column;
  }

  .ballot-tabs {
    flex-direction: column;
  }

  .ballot-tab {
    width: 100%;
  }

  .inline-fields,
  .results-bottom {
    grid-template-columns: 1fr;
  }

  .batch-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .inline-actions {
    justify-content: stretch;
  }

  .inline-actions .secondary-button,
  .inline-actions .config-notice {
    width: 100%;
    justify-content: center;
  }

  .step-button {
    width: 32px;
  }

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