:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-alt: #f8fafc;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-muted: #475569;
  --text-light: #64748b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #eff6ff;
  --primary-border: #93c5fd;
  --success: #059669;
  --success-soft: #ecfdf5;
  --success-border: #6ee7b7;
  --warning: #d97706;
  --warning-soft: #fffbeb;
  --warning-border: #fcd34d;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --danger-border: #fca5a5;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 8px 24px -4px rgba(15, 23, 42, 0.08), 0 2px 6px -1px rgba(15, 23, 42, 0.04);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, Helvetica, Arial, sans-serif;
  background-color: var(--bg);
  color: var(--text);
  line-height: 1.55;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a {
  color: var(--primary);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* Header */
.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0.85rem 1rem;
  position: sticky;
  top: 0;
  z-index: 20;
}

.header-inner {
  max-width: 960px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text);
  text-decoration: none !important;
}

.brand-icon {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: linear-gradient(135deg, #2563eb, #1e40af);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1rem;
  flex-shrink: 0;
}

/* Main container */
.main-container {
  width: 100%;
  max-width: 680px;
  margin: 1.25rem auto 2.5rem;
  padding: 0 1rem;
  flex: 1;
}

.main-container.wide {
  max-width: 1040px;
}

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.35rem;
  box-shadow: var(--shadow-md);
  margin-bottom: 1.25rem;
}

@media (min-width: 640px) {
  .card {
    padding: 1.85rem;
  }
}

.card-title {
  font-size: 1.4rem;
  font-weight: 800;
  line-height: 1.25;
  color: var(--text);
  margin-bottom: 0.5rem;
}

@media (min-width: 640px) {
  .card-title {
    font-size: 1.65rem;
  }
}

.card-description {
  color: var(--text-muted);
  font-size: 0.98rem;
  white-space: pre-line;
  margin-bottom: 1.25rem;
}

/* Badges & Status Pills */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.28rem 0.7rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  line-height: 1.2;
}

.badge-active {
  background: var(--success-soft);
  color: var(--success);
  border: 1px solid var(--success-border);
}

.badge-upcoming {
  background: var(--warning-soft);
  color: var(--warning);
  border: 1px solid var(--warning-border);
}

.badge-ended {
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid var(--danger-border);
}

.badge-info {
  background: var(--primary-soft);
  color: var(--primary);
  border: 1px solid var(--primary-border);
}

.badge-neutral {
  background: var(--surface-alt);
  color: var(--text-muted);
  border: 1px solid var(--border-strong);
}

/* Schedule Grid (Start & End Time Display) */
.schedule-box {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.95rem 1rem;
  margin-bottom: 1.25rem;
}

.schedule-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  padding-bottom: 0.65rem;
  border-bottom: 1px solid var(--border);
}

.countdown-text {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
}

.schedule-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.65rem;
}

@media (min-width: 480px) {
  .schedule-grid {
    grid-template-columns: 1fr 1fr;
  }
}

.schedule-item {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.schedule-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-light);
  font-weight: 700;
}

.schedule-value {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text);
}

/* Question & Radio Options */
.question-block {
  margin-top: 1.1rem;
}

.question-title {
  font-size: 1.12rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 0.35rem;
}

.question-subtitle {
  font-size: 0.85rem;
  color: var(--text-light);
  margin-bottom: 0.9rem;
}

.options-list {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  margin-bottom: 1.35rem;
}

.option-card {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 1rem 1.1rem;
  min-height: 58px;
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.option-card:hover {
  border-color: var(--primary-border);
  background: var(--surface-alt);
}

.option-card.selected {
  border-color: var(--primary);
  background: var(--primary-soft);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.option-card input[type="radio"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.option-radio-indicator {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid var(--border-strong);
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.15s ease;
}

.option-card.selected .option-radio-indicator {
  border-color: var(--primary);
  background: var(--primary);
}

.option-card.selected .option-radio-indicator::after {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #ffffff;
}

.option-card:focus-within {
  outline: 3px solid rgba(37, 99, 235, 0.35);
  outline-offset: 2px;
}

.option-text {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.35;
  word-break: break-word;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  padding: 0.85rem 1.35rem;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s ease;
  text-decoration: none !important;
  min-height: 48px;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  color: #ffffff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border-strong);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--surface-alt);
}

.btn-danger {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: var(--danger-border);
}

.btn-danger:hover:not(:disabled) {
  background: var(--danger);
  color: #ffffff;
}

.btn-sm {
  font-size: 0.85rem;
  padding: 0.45rem 0.8rem;
  min-height: 36px;
  border-radius: var(--radius-sm);
}

.btn-block {
  width: 100%;
}

/* Alerts & Banners */
.alert {
  padding: 0.95rem 1.1rem;
  border-radius: var(--radius-md);
  margin-bottom: 1.1rem;
  font-size: 0.93rem;
  border: 1px solid transparent;
}

.alert-success {
  background: var(--success-soft);
  color: #065f46;
  border-color: var(--success-border);
}

.alert-warning {
  background: var(--warning-soft);
  color: #92400e;
  border-color: var(--warning-border);
}

.alert-error {
  background: var(--danger-soft);
  color: #991b1b;
  border-color: var(--danger-border);
}

.alert-info {
  background: var(--primary-soft);
  color: #1e40af;
  border-color: var(--primary-border);
}

/* Results View */
.results-section {
  margin-top: 1.35rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
}

.results-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.results-title {
  font-size: 1.1rem;
  font-weight: 700;
}

.result-row {
  margin-bottom: 0.95rem;
}

.result-label-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.5rem;
  margin-bottom: 0.35rem;
  font-size: 0.93rem;
}

.result-option-name {
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.result-stats {
  font-weight: 700;
  color: var(--text-muted);
  white-space: nowrap;
  font-size: 0.88rem;
}

.progress-track {
  width: 100%;
  height: 12px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #2563eb, #3b82f6);
  border-radius: 999px;
  transition: width 0.4s ease;
}

.progress-fill.my-choice {
  background: linear-gradient(90deg, #059669, #10b981);
}

/* Security Footer inside Voter Card */
.security-bar {
  margin-top: 1.35rem;
  padding-top: 0.95rem;
  border-top: 1px dashed var(--border);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.78rem;
  color: var(--text-light);
}

/* Forms (Admin & Code input) */
.form-group {
  margin-bottom: 1.1rem;
}

.form-label {
  display: block;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.38rem;
}

.form-hint {
  display: block;
  font-size: 0.8rem;
  color: var(--text-light);
  margin-top: 0.25rem;
}

.form-input,
.form-textarea,
.form-select {
  width: 100%;
  font-family: inherit;
  font-size: 0.96rem;
  padding: 0.72rem 0.9rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.15s ease;
}

.form-input:focus,
.form-textarea:focus,
.form-select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.form-row-2 {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.9rem;
}

@media (min-width: 600px) {
  .form-row-2 {
    grid-template-columns: 1fr 1fr;
  }
}

.checkbox-row {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-alt);
  margin-bottom: 0.65rem;
  cursor: pointer;
}

.checkbox-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  margin-top: 0.15rem;
  accent-color: var(--primary);
  flex-shrink: 0;
}

/* Admin Tables & Lists */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
  text-align: left;
}

table.data-table th,
table.data-table td {
  padding: 0.7rem 0.85rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

table.data-table th {
  background: var(--surface-alt);
  font-weight: 700;
  color: var(--text-muted);
  white-space: nowrap;
}

table.data-table tr:last-child td {
  border-bottom: none;
}

.dynamic-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.55rem;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 100;
}

.modal-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  max-width: 440px;
  width: 100%;
  padding: 1.5rem;
  box-shadow: var(--shadow-md);
  text-align: center;
}

.qr-box {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 1rem;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin: 1rem auto;
  max-width: 260px;
}

.qr-box svg {
  width: 100%;
  height: auto;
  display: block;
}

.hidden {
  display: none !important;
}

/* Info Article Button & Modal */
.btn-info-article {
  background: var(--primary-soft);
  color: var(--primary);
  border: 1.5px solid var(--primary-border);
  font-weight: 700;
  margin-bottom: 1.15rem;
}

.btn-info-article:hover:not(:disabled) {
  background: #dbeafe;
  border-color: var(--primary);
}

.article-modal-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  max-width: 780px;
  width: 100%;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 40px -10px rgba(15, 23, 42, 0.25);
  text-align: left;
  overflow: hidden;
}

.article-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1.1rem 1.35rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface-alt);
}

.article-modal-title {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--text);
  line-height: 1.3;
}

.article-modal-body {
  padding: 1.35rem;
  overflow-y: auto;
  flex: 1;
}

@media (min-width: 640px) {
  .article-modal-body {
    padding: 1.75rem;
  }
}

.article-modal-footer {
  padding: 0.9rem 1.35rem;
  border-top: 1px solid var(--border);
  background: var(--surface-alt);
  display: flex;
  justify-content: flex-end;
}

/* Markdown Content Formatting */
.md-content {
  color: var(--text);
  font-size: 0.98rem;
  line-height: 1.65;
  word-break: break-word;
}

.md-content > *:first-child {
  margin-top: 0 !important;
}

.md-content > *:last-child {
  margin-bottom: 0 !important;
}

.md-h1, .md-h2, .md-h3, .md-h4, .md-h5, .md-h6 {
  font-weight: 800;
  color: var(--text);
  line-height: 1.3;
  margin-top: 1.35rem;
  margin-bottom: 0.6rem;
}

.md-h1 {
  font-size: 1.45rem;
  padding-bottom: 0.35rem;
  border-bottom: 1px solid var(--border);
}

.md-h2 {
  font-size: 1.25rem;
  padding-bottom: 0.25rem;
  border-bottom: 1px solid var(--border);
}

.md-h3 { font-size: 1.1rem; }
.md-h4 { font-size: 1rem; }
.md-h5, .md-h6 { font-size: 0.92rem; color: var(--text-muted); }

.md-p {
  margin-bottom: 0.95rem;
}

.md-list {
  margin: 0.5rem 0 1rem 1.35rem;
}

.md-list li {
  margin-bottom: 0.35rem;
}

.md-task-item {
  list-style: none;
  margin-left: -1.1rem;
  display: flex;
  align-items: baseline;
  gap: 0.45rem;
}

.md-blockquote {
  border-left: 4px solid var(--primary);
  background: var(--surface-alt);
  padding: 0.75rem 1rem;
  margin: 0.9rem 0;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text-muted);
}

.md-inline-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.86em;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  padding: 0.12rem 0.38rem;
  border-radius: 5px;
}

.md-pre {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.85rem;
  background: #0f172a;
  color: #f8fafc;
  padding: 0.95rem 1.1rem;
  border-radius: var(--radius-sm);
  overflow-x: auto;
  margin: 0.95rem 0;
}

.md-table-wrap {
  width: 100%;
  overflow-x: auto;
  margin: 1rem 0;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
}

.md-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.md-table th,
.md-table td {
  padding: 0.65rem 0.85rem;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

.md-table th:last-child,
.md-table td:last-child {
  border-right: none;
}

.md-table tr:last-child td {
  border-bottom: none;
}

.md-table th {
  background: var(--surface-alt);
  font-weight: 700;
  color: var(--text);
}

.md-table tbody tr:nth-child(even) {
  background: #fcfdff;
}

.md-hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 1.25rem 0;
}

.md-img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-sm);
  margin: 0.5rem 0;
}

.app-footer {
  text-align: center;
  padding: 1.25rem 1rem;
  font-size: 0.82rem;
  color: var(--text-light);
  border-top: 1px solid var(--border);
  background: var(--surface);
}
