:root {
  --blue: #1d4ed8;
  --blue-dark: #1e40af;
  --red: #b91c1c;
  --green: #16a34a;
  --bg: #f3f4f6;
  --card: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --border: #e5e7eb;
}


* {
  box-sizing: border-box;
}


body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: Arial, Helvetica, sans-serif;
  background: var(--bg);
  color: var(--text);
}


/* Header */


.site-header {
  background: var(--blue-dark);
  color: #fff;
  padding: 14px 24px;
}


.header-inner {
  max-width: 1100px;
  margin: auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
}


.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: bold;
  font-size: 18px;
}


.brand img {
  height: 42px;
  background: #fff;
  border-radius: 8px;
  padding: 3px;
}


.header-nav {
  display: flex;
  gap: 10px;
  align-items: center;
}


.header-nav a {
  color: #fff;
  text-decoration: none;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 8px;
  transition: background-color 0.2s ease, color 0.2s ease;
}


.header-nav a:hover {
  background-color: rgba(255, 255, 255, 0.18);
}


.header-nav a.active {
  background-color: #fff;
  color: var(--blue);
}


.header-nav .logout-link {
  background-color: #dc2626;
  color: #fff;
}


.header-nav .logout-link:hover {
  background-color: #b91c1c;
  color: #fff;
}


/* Layout */


.page {
  flex: 1;
  width: 100%;
  max-width: 960px;
  margin: 28px auto;
  padding: 0 16px;
}


.card {
  background: var(--card);
  border-radius: 16px;
  padding: 28px;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
}


.narrow {
  max-width: 520px;
  margin: 0 auto;
}


.page-title {
  margin: 0 0 6px;
  color: var(--blue);
}


.page-subtitle {
  margin: 0 0 22px;
  color: var(--muted);
}


.dashboard-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
}


.panel {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
  margin-bottom: 20px;
  background: #fff;
}


.panel h2,
.panel h3 {
  margin-top: 0;
  color: var(--blue-dark);
}


/* Forms */


label {
  display: block;
  font-weight: 600;
  margin-bottom: 6px;
}


input[type="text"],
input[type="password"],
select {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 16px;
}


textarea {
  width: 100%;
  min-height: 110px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-family: inherit;
  font-size: 16px;
}


.election-form {
  display: flex;
  flex-direction: column;
  gap: 18px;
  max-width: 650px;
}


.form-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}


.form-group label {
  font-size: 14px;
  font-weight: 700;
  color: #374151;
}


.form-group input,
.form-group textarea {
  width: 100%;
  padding: 12px 14px;
  border: 2px solid #cbd5f5;
  border-radius: 10px;
  font-size: 16px;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}


.form-group input:focus,
.form-group textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 4px rgba(29, 78, 216, 0.12);
}


.form-actions {
  display: flex;
  justify-content: flex-end;
}


/* Buttons */


.btn {
  display: inline-block;
  width: 100%;
  margin-top: 16px;
  padding: 13px 18px;
  border: 0;
  border-radius: 999px;
  background: var(--blue);
  color: #fff;
  font-size: 16px;
  font-weight: bold;
  cursor: pointer;
  text-decoration: none;
  text-align: center;
  transition: background-color 0.2s ease;
}


.btn:hover {
  background: var(--red);
}


.btn-secondary {
  background: #e5e7eb;
  color: var(--text);
}


.btn-secondary:hover {
  background: #d1d5db;
}


.btn.small {
  width: auto;
  padding: 8px 16px;
  font-size: 14px;
}


.btn.danger {
  background: var(--red);
}


.btn.danger:hover {
  background: #991b1b;
}


.panel .btn.disabled {
  opacity: 0.5;
  pointer-events: none;
}


/* Flash messages */


.flash {
  padding: 12px 14px;
  border-radius: 10px;
  margin-bottom: 10px;
}


.flash-success {
  background: #dcfce7;
  color: #166534;
}


.flash-error {
  background: #fee2e2;
  color: #b91c1c;
}


.flash-warning {
  background: #fef3c7;
  color: #92400e;
}


/* Candidates and voting */


.candidate {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  margin-bottom: 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #f9fafb;
  cursor: pointer;
}


.candidate:hover {
  border-color: var(--blue);
  background: #eff6ff;
}


.candidate img {
  width: 52px;
  height: 52px;
  border-radius: 10px;
  object-fit: cover;
}


.position {
  margin-bottom: 24px;
}


.position h3 {
  margin: 0 0 12px;
  color: var(--blue-dark);
}


.position-header {
  background: linear-gradient(90deg, #eff6ff, #f8fafc);
  border-bottom: 1px solid #dbeafe;
}


.category-identity {
  display: flex;
  align-items: center;
  gap: 10px;
}


.category-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 10px;
  background: var(--blue);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
}


.position-number {
  color: var(--blue-dark);
  font-size: 15px;
}


.position-block {
  border-color: #dbeafe;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.05);
}


.position-block:hover {
  border-color: #93c5fd;
}


.position-block + .position-block {
  margin-top: 25px;
}


.candidates-section {
  background: #fbfdff;
}


.active-step {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(29, 78, 216, 0.12);
}


.step-badge {
  display: inline-block;
  background: var(--blue);
  color: #fff;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 13px;
  font-weight: bold;
  margin-bottom: 8px;
}


.step-badge.danger {
  background-color: #dc2626;
}


.step-badge.danger:hover {
  background-color: #b91c1c;
}


/* Election setup */


.setup-progress {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 10px;
  margin: 20px 0;
}


.step-card {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #f9fafb;
  text-decoration: none;
  transition: border-color 0.15s ease, transform 0.15s ease;
}


.step-card:hover {
  border-color: var(--blue);
  transform: translateY(-2px);
}


.step-number {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 9px;
  background: #e5e7eb;
  color: #374151;
  font-weight: bold;
  font-size: 14px;
}


.step-title {
  font-weight: bold;
  color: var(--text);
  font-size: 14px;
}


.step-status {
  font-size: 12px;
  color: var(--muted);
}


.step-card.completed {
  border-color: #bbf7d0;
  background: #f0fdf4;
}


.step-card.completed .step-number {
  background: var(--green);
  color: #fff;
}


.step-card.completed .step-status {
  color: #166534;
}


.step-card.current {
  border-color: var(--blue);
  background: #eff6ff;
  box-shadow: 0 0 0 3px rgba(29, 78, 216, 0.1);
}


.step-card.current .step-number {
  background: var(--blue);
  color: #fff;
}


.step-card.current .step-status {
  color: var(--blue-dark);
  font-weight: bold;
}


.step-card.locked {
  opacity: 0.55;
  pointer-events: none;
}


/* Admin tables */


.data-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 16px;
}


.data-table th,
.data-table td {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}


.data-table th {
  background: #eff6ff;
  color: var(--blue-dark);
}


/* Candidate photos and tokens */


.photo-preview {
  width: 64px;
  height: 64px;
  border-radius: 12px;
  object-fit: cover;
  border: 1px solid var(--border);
  background: #f3f4f6;
}


.photo-preview.placeholder {
  opacity: 0.6;
}


.candidate-fields {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
}


.token-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}


.token-chip {
  background: #eff6ff;
  color: var(--blue-dark);
  border: 1px solid #bfdbfe;
  padding: 6px 10px;
  border-radius: 999px;
  font-family: Consolas, monospace;
  font-size: 14px;
}


/* Live results */


.results-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 15px;
  font-size: 15px;
}


.results-table th,
.results-table td {
  padding: 12px 14px;
  border-bottom: 1px solid #e5e7eb;
  text-align: left;
}


.results-table th {
  background: #eff6ff;
  color: #1f2937;
  font-weight: 700;
  font-size: 14px;
}


.results-table tbody tr:hover {
  background: #f9fafb;
}


.results-table td:first-child {
  font-weight: 600;
  color: #111827;
}


.results-table .leading-row {
  background: #ecfdf5;
}


.results-table .leading-badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--green);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
}


.results-table .tie-row {
  background: #fffbeb;
}


.results-table .falling-row {
  background: #f8fafc;
}


.tie-badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  background: #f59e0b;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
}


.falling-badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  background: #64748b;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
}


.no-votes-badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  background: #e5e7eb;
  color: #374151;
  font-size: 12px;
  font-weight: 700;
}


.chart-container {
  position: relative;
  width: 100%;
  max-width: 100%;
  margin-top: 20px;
  padding: 12px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  overflow: hidden;
}


.chart-container canvas {
  width: 100% !important;
  max-width: 100% !important;
  height: 100% !important;
}


.chart-box {
  position: relative;
  height: 260px;
}


.chart-box canvas {
  max-height: 240px;
}


.live-results-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 15px;
}


/* Token voting page */


.token-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 70vh;
  padding: 30px 15px;
}


.token-page .token-brand {
  display: flex;
  justify-content: center;
  margin-bottom: 18px;
}


.token-page .token-brand img {
  height: 90px;
  object-fit: contain;
}


.token-page .token-title {
  margin: 0;
  font-size: 28px;
  font-weight: 800;
  color: var(--blue);
  text-align: center;
  letter-spacing: 0.02em;
}


.token-page .token-election {
  margin: 8px 0 0;
  font-size: 18px;
  font-weight: 700;
  color: #111827;
  text-align: center;
}


.token-page .token-instructions {
  margin: 14px 0 22px;
  color: #4b5563;
  font-size: 15px;
  text-align: center;
}


.token-page .token-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}


.token-page label {
  font-size: 14px;
  font-weight: 700;
  color: #374151;
}


.token-page input {
  width: 100%;
  padding: 14px 16px;
  border: 2px solid #cbd5f5;
  border-radius: 10px;
  font-size: 18px;
  letter-spacing: 2px;
  text-align: center;
  text-transform: uppercase;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}


.token-page input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 4px rgba(29, 78, 216, 0.12);
}


.token-page button {
  width: 100%;
  margin-top: 8px;
  padding: 14px;
  border: none;
  border-radius: 10px;
  background: var(--blue);
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: background-color 0.2s ease, transform 0.1s ease;
}


.token-page button:hover {
  background: var(--blue-dark);
  transform: translateY(-1px);
}


.token-page .token-note {
  margin-top: 20px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}


.token-page .token-error {
  margin-bottom: 16px;
  padding: 12px 14px;
  border-radius: 10px;
  background: #fee2e2;
  border-left: 5px solid #dc2626;
  color: #991b1b;
  font-size: 14px;
  text-align: center;
}


/* Past Elections page */


.history-filter {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  flex-wrap: nowrap;
  overflow-x: auto;
  padding-bottom: 5px;
}


.filter-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 170px;
  flex-shrink: 0;
}


.filter-field label {
  font-size: 13px;
  font-weight: 700;
  color: #374151;
  white-space: nowrap;
}


.filter-field input {
  width: 100%;
  padding: 10px 12px;
  border: 2px solid #cbd5f5;
  border-radius: 8px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}


.filter-field input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 4px rgba(29, 78, 216, 0.12);
}


.history-filter .btn {
  height: 42px;
  white-space: nowrap;
}


.elections-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 15px;
  font-size: 14px;
}


.elections-table th,
.elections-table td {
  padding: 12px 14px;
  border-bottom: 1px solid #e5e7eb;
  text-align: left;
  vertical-align: top;
}


.elections-table th {
  background: #eff6ff;
  color: #1f2937;
  font-weight: 700;
}


.elections-table tbody tr:hover {
  background: #f9fafb;
}


.status-pill {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}


.status-active {
  background: #dcfce7;
  color: #166534;
}


.status-closed {
  background: #fee2e2;
  color: #991b1b;
}


.status-upcoming {
  background: #e0f2fe;
  color: #075985;
}


.status-draft {
  background: #f3f4f6;
  color: #374151;
}


/* Footer */


.site-footer {
  padding: 18px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}


/* Responsive rules */


@media (max-width: 900px) {
  .setup-progress {
    grid-template-columns: repeat(3, 1fr);
  }


  .history-filter {
    flex-direction: column;
    align-items: stretch;
  }


  .filter-field {
    min-width: 100%;
  }
}


@media (max-width: 700px) {
  .results-table {
    font-size: 14px;
  }


  .results-table th,
  .results-table td {
    padding: 10px 8px;
  }


  .chart-container {
    height: 240px;
  }
}


@media (max-width: 640px) {
  .card {
    padding: 20px;
  }


  .brand span {
    font-size: 16px;
  }
}


@media (max-width: 600px) {
  .setup-progress {
    grid-template-columns: repeat(2, 1fr);
  }
}


@media (max-width: 500px) {
  .token-page .token-title {
    font-size: 23px;
  }


  .token-page .token-election {
    font-size: 16px;
  }


  .token-page input {
    font-size: 16px;
  }
}


@media (max-width: 800px) {
  .elections-table {
    display: block;
    overflow-x: auto;
  }
}

.btn.disabled {
    background: #9ca3af;
    color: #ffffff;
    cursor: not-allowed;
    opacity: 0.7;
    pointer-events: none;
}

.review-summary {
    display: grid;
    grid-template-columns: repeat(
        auto-fit,
        minmax(220px, 1fr)
    );
    gap: 16px;
    margin-top: 20px;
}

.review-item {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 16px;
}

.review-label {
    display: block;
    font-size: 13px;
    color: #64748b;
    margin-bottom: 6px;
}

.review-value {
    font-size: 16px;
    font-weight: 700;
    color: #1f2937;
}

.review-positions {
    display: grid;
    gap: 20px;
    margin-top: 20px;
}

.review-position {
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 18px;
    background: #ffffff;
}

.review-position-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
}

.review-position-header h4 {
    margin: 0;
    font-size: 18px;
    color: #1d4ed8;
}

.candidate-count {
    font-size: 13px;
    color: #64748b;
    background: #eff6ff;
    padding: 4px 10px;
    border-radius: 999px;
}

.candidate-grid {
    display: grid;
    grid-template-columns: repeat(
        auto-fill,
        minmax(220px, 1fr)
    );
    gap: 14px;
}

.candidate-card {
    display: flex;
    align-items: center;
    gap: 12px;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    padding: 10px;
    background: #f9fafb;
}

.candidate-photo {
    width: 52px;
    height: 52px;
    border-radius: 8px;
    object-fit: cover;
}

.candidate-photo.placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    background: #1d4ed8;
    color: #ffffff;
    font-weight: 700;
}

.candidate-name {
    font-weight: 600;
    color: #111827;
}

.empty-message {
    color: #6b7280;
    font-style: italic;
}

.review-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 24px;
}

.manage-voting-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    flex-wrap: wrap;
}

.voting-window {
    color: #64748b;
    margin-top: 6px;
}

.status-badge {
    display: inline-block;
    padding: 6px 14px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 700;
}

.status-badge.open {
    background: #dcfce7;
    color: #166534;
}

.token-summary {
    display: grid;
    grid-template-columns: repeat(
        auto-fit,
        minmax(180px, 1fr)
    );
    gap: 16px;
    margin-top: 20px;
}

.token-card {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 16px;
}

.token-label {
    display: block;
    font-size: 13px;
    color: #64748b;
    margin-bottom: 6px;
}

.token-value {
    font-size: 24px;
    font-weight: 800;
    color: #1f2937;
}

.token-progress {
    margin-top: 20px;
}

.token-progress-bar {
    width: 100%;
    height: 10px;
    background: #e2e8f0;
    border-radius: 999px;
    overflow: hidden;
}

.token-progress-fill {
    height: 100%;
    background: #1d4ed8;
    border-radius: 999px;
}

.token-progress-text {
    margin-top: 8px;
    font-size: 14px;
    color: #64748b;
}

.danger-panel {
    border-color: #fecaca;
    background: #fff5f5;
}

.danger-panel p {
    color: #7f1d1d;
}

.vote-header {
    text-align: center;
    margin-bottom: 24px;
}

.vote-header .page-title {
    margin-bottom: 6px;
}

.vote-header .page-subtitle {
    margin: 0;
}

.vote-institution {
    margin: 8px auto 0;
    font-size: 22px;
    font-weight: 800;
    color: #111827;
    text-align: center;
}

.vote-description {
    max-width: 720px;
    margin: 10px auto 0;
    color: #4b5563;
    font-size: 15px;
    font-weight: 400;
    line-height: 1.6;
    text-align: center;
}

.result-candidate {
    display: flex;
    align-items: center;
    gap: 10px;
}

.result-candidate-photo {
    width: 42px;
    height: 42px;
    border-radius: 8px;
    object-fit: cover;
    flex-shrink: 0;
}

.result-candidate-photo.placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    background: #1d4ed8;
    color: #ffffff;
    font-weight: 700;
}

.flash-messages {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9999;
    width: 90%;
    max-width: 420px;
}

.flash-message {
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    text-align: center;
    box-shadow: 0 4px 14px rgba(15, 23, 42, 0.18);
}

.flash-error {
    background: #fee2e2;
    color: #b91c1c;
    border: 1px solid #fecaca;
}

.flash-success {
    background: #d1fae5;
    color: #065f46;
    border: 1px solid #a7f3d0;
}

.flash-warning {
    background: #fef3c7;
    color: #92400e;
    border: 1px solid #fde68a;
}

.login-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: calc(100vh - 80px);
    padding: 30px 15px;
}

.login-card {
    width: 100%;
    max-width: 400px;
    text-align: center;
}

.login-card .page-title {
    text-align: center;
}

.login-card .page-subtitle {
    text-align: center;
}

.login-card form {
    text-align: left;
}

.login-card label {
    display: block;
    margin-bottom: 6px;
    font-weight: 600;
}

.login-card input {
    width: 100%;
    margin-bottom: 16px;
}

.login-card .btn {
    width: 100%;
}

/* Mobile menu */

.menu-toggle {
    display: none;
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.15);
    cursor: pointer;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
}

.menu-toggle span {
    display: block;
    width: 22px;
    height: 3px;
    background: #ffffff;
    border-radius: 2px;
}

.mobile-nav {
    display: none;
    width: 100%;
    background: var(--blue-dark);
    border-top: 1px solid rgba(255, 255, 255, 0.2);
}

.mobile-nav.open {
    display: block;
}

.mobile-nav a {
    display: block;
    padding: 14px 20px;
    color: #ffffff;
    font-weight: 600;
    text-decoration: none;
    border-bottom: 1px solid rgba(255, 255, 255, 0.15);
}

.mobile-nav a:last-child {
    border-bottom: none;
}

.mobile-nav a.active {
    background: #ffffff;
    color: var(--blue);
}

.mobile-nav .logout-link {
    background: #dc2626;
    color: #ffffff;
}

@media (max-width: 768px) {
    .site-header {
        padding: 10px 14px;
    }

    .header-inner {
        flex-wrap: wrap;
    }

    .brand {
        font-size: 16px;
    }

    .brand img {
        height: 36px;
    }

    .header-nav {
        display: none;
    }

    .menu-toggle {
        display: flex;
    }

    .mobile-nav {
        order: 3;
    }
}

.live-results-button {
  display: block;
  margin-top: 14px;
  padding: 14px;
  border-radius: 10px;
  background: #16a34a;
  color: #ffffff;
  font-size: 16px;
  font-weight: 700;
  text-align: center;
  text-decoration: none;
  transition: background-color 0.2s ease, transform 0.1s ease;
}

.live-results-button:hover {
  background: #15803d;
  transform: translateY(-1px);
}