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

body {
  font-family: 'Segoe UI', Tahoma, sans-serif;
  background: #f0f2f5;
  color: #1a1a2e;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ===== HEADER ===== */
header {
  background: #1a1a2e;
  color: white;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
  position: sticky;
  top: 0;
  z-index: 100;
}
.header-left .logo { font-size: 1.2rem; font-weight: 700; }
.header-right { display: flex; align-items: center; gap: 12px; }

.admin-link {
  color: #ffd700;
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 600;
  border: 1px solid #ffd700;
  padding: 6px 12px;
  border-radius: 6px;
  transition: all 0.2s;
}
.admin-link:hover { background: #ffd700; color: #1a1a2e; }

/* ===== BUTTONS ===== */
.btn-primary {
  background: #3b82f6; color: white; border: none;
  padding: 8px 18px; border-radius: 8px; cursor: pointer;
  font-size: 0.9rem; font-weight: 600; transition: all 0.2s;
}
.btn-primary:hover { background: #2563eb; }
.btn-primary:disabled { background: #9ca3af; cursor: not-allowed; }

.btn-secondary {
  background: transparent; color: #374151;
  border: 1.5px solid #d1d5db; padding: 8px 18px;
  border-radius: 8px; cursor: pointer; font-size: 0.9rem;
  font-weight: 600; transition: all 0.2s;
}
.btn-secondary:hover { background: #f3f4f6; }
.btn-secondary:disabled { color: #9ca3af; cursor: not-allowed; }

.btn-danger {
  background: #ef4444; color: white; border: none;
  padding: 8px 18px; border-radius: 8px; cursor: pointer;
  font-size: 0.9rem; font-weight: 600; transition: all 0.2s;
}
.btn-danger:hover { background: #dc2626; }
.btn-danger:disabled { background: #9ca3af; cursor: not-allowed; }

.btn-success {
  background: #22c55e; color: white; border: none;
  padding: 8px 18px; border-radius: 8px; cursor: pointer;
  font-size: 0.9rem; font-weight: 600; transition: all 0.2s;
}
.btn-success:hover { background: #16a34a; }
.btn-success:disabled { background: #9ca3af; cursor: not-allowed; }

.btn-lg { padding: 12px 32px; font-size: 1rem; }

/* ===== STATUS BADGES ===== */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 12px; border-radius: 20px;
  font-size: 0.85rem; font-weight: 700;
}
.badge-not-initialized { background: #dbeafe; color: #1d4ed8; }
.badge-pending         { background: #f3f4f6; color: #6b7280; }
.badge-active          { background: #dcfce7; color: #15803d; }
.badge-ended           { background: #fee2e2; color: #dc2626; }

.live-dot {
  width: 8px; height: 8px; background: #ef4444;
  border-radius: 50%; animation: blink 1.2s ease-in-out infinite;
  display: inline-block;
}
@keyframes blink { 0%,100% { opacity: 1; } 50% { opacity: 0.2; } }

/* ===== MAIN ===== */
main {
  flex: 1; max-width: 900px; margin: 0 auto;
  padding: 24px 16px; width: 100%;
}

/* ===== ELECTION INFO ===== */
.election-info {
  background: white; border-radius: 12px; padding: 24px;
  margin-bottom: 20px; box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  text-align: center;
}
.election-info h1 { font-size: 1.6rem; color: #1a1a2e; margin-bottom: 16px; }
.election-meta {
  display: flex; justify-content: center; gap: 20px;
  margin-bottom: 16px; flex-wrap: wrap;
}
.time-box {
  background: #f8fafc; border: 1px solid #e2e8f0;
  border-radius: 8px; padding: 10px 20px; text-align: center;
}
.time-box span:first-child { display: block; font-size: 0.75rem; color: #6b7280; margin-bottom: 4px; }
.time-box span:last-child  { font-size: 0.9rem; font-weight: 600; }
.status-row { display: flex; align-items: center; justify-content: center; gap: 16px; }
.total-votes { font-size: 0.9rem; color: #6b7280; }

/* ===== CARD ===== */
.card {
  background: white; border-radius: 12px; padding: 24px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08); margin-bottom: 20px;
}
.card h2 {
  font-size: 1.1rem; color: #374151; margin-bottom: 16px;
  padding-bottom: 12px; border-bottom: 1px solid #e5e7eb;
}

/* ===== LOADING ===== */
.loading { text-align: center; padding: 60px 20px; color: #9ca3af; }
.spinner {
  width: 40px; height: 40px; border: 4px solid #e5e7eb;
  border-top-color: #3b82f6; border-radius: 50%;
  animation: spin 0.8s linear infinite; margin: 0 auto 16px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== NOT INITIALIZED ===== */
.preparing-card { text-align: center; padding: 60px 20px; }
.preparing-card .icon { font-size: 3rem; margin-bottom: 16px; }
.preparing-card h2 { font-size: 1.3rem; color: #374151; border: none; }
.preparing-card p { color: #6b7280; margin-top: 8px; }

/* ===== PENDING COUNTDOWN ===== */
.countdown-section { text-align: center; padding: 32px 20px; }
.countdown-title { font-size: 1.1rem; color: #6b7280; margin-bottom: 24px; }
.countdown-boxes {
  display: flex; justify-content: center; gap: 12px;
  margin-bottom: 20px; flex-wrap: wrap;
}
.countdown-box {
  background: #1a1a2e; color: white; border-radius: 12px;
  padding: 16px 24px; min-width: 80px; text-align: center;
}
.countdown-box .count { display: block; font-size: 2rem; font-weight: 700; line-height: 1; }
.countdown-box .label { display: block; font-size: 0.75rem; color: #9ca3af; margin-top: 4px; }
.election-period-text { font-size: 0.85rem; color: #6b7280; }

/* ===== CANDIDATE CARDS ===== */
.candidates-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px; margin-top: 16px;
}
.candidate-card {
  background: white; border: 2px solid #e5e7eb;
  border-radius: 12px; padding: 20px 16px;
  text-align: center; transition: all 0.2s;
}
.candidate-card:hover { border-color: #93c5fd; }
.candidate-card.selected {
  border-color: #3b82f6; background: #eff6ff;
  box-shadow: 0 0 0 3px rgba(59,130,246,0.2);
}
.candidate-card.clickable { cursor: pointer; }
.candidate-number { font-size: 0.75rem; color: #6b7280; margin-bottom: 8px; }
.candidate-img {
  width: 80px; height: 80px; border-radius: 50%;
  object-fit: cover; margin: 0 auto 12px;
  display: block; background: #f3f4f6;
}
.candidate-name { font-size: 1rem; font-weight: 700; color: #1f2937; }
.candidate-selected-icon { color: #3b82f6; font-size: 1.2rem; margin-top: 8px; }
.candidate-vote-count { font-size: 0.9rem; font-weight: 600; color: #374151; margin-top: 8px; }

/* ===== ACTIVE STATE ===== */
.live-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px; flex-wrap: wrap; gap: 8px;
}
.live-badge {
  display: flex; align-items: center; gap: 8px;
  font-weight: 700; font-size: 1rem; color: #ef4444;
}
.time-remaining { font-size: 0.85rem; color: #6b7280; }

.vote-section { margin-top: 20px; }
.section-title { font-size: 1rem; font-weight: 600; color: #374151; text-align: center; margin-bottom: 16px; }
.vote-btn-container { text-align: center; margin-top: 24px; }

.voted-banner {
  background: #dcfce7; border: 1.5px solid #86efac;
  border-radius: 10px; padding: 14px 18px;
  display: flex; align-items: center; gap: 12px; margin-bottom: 20px;
}
.voted-banner .icon { font-size: 1.4rem; }
.voted-banner .text { font-size: 0.95rem; color: #15803d; font-weight: 600; }

/* ===== VOTE COMPLETE SCR-009 ===== */
.vote-complete { text-align: center; padding: 40px 20px; }
.checkmark-circle {
  width: 80px; height: 80px; border-radius: 50%;
  background: #22c55e; color: white; font-size: 2.5rem;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 20px; animation: scaleIn 0.4s ease-out;
}
@keyframes scaleIn { from { transform: scale(0); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.vote-complete h2 { font-size: 1.4rem; margin-bottom: 16px; border: none; }
.vote-complete .detail { color: #6b7280; font-size: 0.9rem; margin-bottom: 6px; }
.vote-complete .detail strong { color: #1f2937; }
.etherscan-link { color: #3b82f6; text-decoration: none; font-size: 0.9rem; display: inline-block; margin: 12px 0; }
.etherscan-link:hover { text-decoration: underline; }

/* ===== MODALS ===== */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; padding: 16px;
}
.modal-overlay.hidden { display: none !important; }
.modal {
  background: white; border-radius: 16px; padding: 28px;
  width: 100%; max-width: 440px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3); position: relative;
}
.modal-header {
  display: flex; align-items: center;
  justify-content: space-between; margin-bottom: 20px;
}
.modal-title { font-size: 1.1rem; font-weight: 700; color: #1f2937; }
.modal-close {
  background: none; border: none; font-size: 1.4rem;
  cursor: pointer; color: #9ca3af; padding: 2px 6px; line-height: 1;
}
.modal-close:hover { color: #374151; }
.modal-body { margin-bottom: 20px; }
.modal-footer { display: flex; gap: 12px; justify-content: flex-end; }

.metamask-icon { font-size: 3rem; text-align: center; margin-bottom: 16px; }
.modal-desc { text-align: center; color: #4b5563; line-height: 1.6; margin-bottom: 16px; }
.install-link { text-align: center; margin-top: 14px; }
.install-link a { color: #3b82f6; text-decoration: none; font-size: 0.9rem; }

.network-warning {
  color: #92400e; background: #fef3c7; border-radius: 8px;
  padding: 12px 16px; margin-bottom: 16px; font-size: 0.9rem;
}

.confirm-candidate { text-align: center; margin: 16px 0; }
.confirm-candidate img {
  width: 100px; height: 100px; border-radius: 50%;
  object-fit: cover; margin-bottom: 12px; background: #f3f4f6;
}
.confirm-candidate .name { font-size: 1.2rem; font-weight: 700; color: #1f2937; }
.warning-box {
  background: #fef9c3; border: 1px solid #fde047;
  border-radius: 8px; padding: 12px 16px;
  font-size: 0.85rem; color: #713f12; margin: 16px 0;
}

/* TX Progress */
.tx-steps { margin: 16px 0; }
.tx-step {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 8px 0; color: #9ca3af; font-size: 0.9rem;
}
.tx-step.active { color: #1f2937; font-weight: 600; }
.tx-step.done   { color: #16a34a; }
.tx-step-icon { width: 20px; text-align: center; flex-shrink: 0; }

.tx-hash-row {
  background: #f8fafc; border-radius: 8px; padding: 8px 12px;
  font-size: 0.8rem; color: #6b7280; margin-top: 12px;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.tx-hash-row a { color: #3b82f6; text-decoration: none; }
.copy-btn {
  background: none; border: 1px solid #d1d5db; border-radius: 4px;
  padding: 2px 8px; font-size: 0.75rem; cursor: pointer; color: #6b7280;
}
.tx-notice { font-size: 0.8rem; color: #9ca3af; margin-top: 8px; text-align: center; }
.tx-error { color: #dc2626; font-size: 0.9rem; text-align: center; margin: 12px 0; background: #fee2e2; padding: 10px 14px; border-radius: 8px; }

/* ===== TOAST ===== */
.toast-container {
  position: fixed; top: 16px; right: 16px;
  z-index: 2000; display: flex; flex-direction: column; gap: 8px;
}
.toast {
  background: white; border-radius: 8px; padding: 12px 16px;
  display: flex; align-items: center; gap: 10px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  min-width: 280px; max-width: 380px;
  animation: slideIn 0.3s ease-out;
  border-left: 4px solid #3b82f6;
}
.toast.toast-success { border-left-color: #22c55e; }
.toast.toast-error   { border-left-color: #ef4444; }
.toast.toast-warning { border-left-color: #f59e0b; }
.toast-icon { font-size: 1.1rem; }
.toast-message { flex: 1; font-size: 0.9rem; color: #1f2937; }
.toast-close { background: none; border: none; cursor: pointer; color: #9ca3af; font-size: 1rem; padding: 0; }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes fadeOut { from { opacity: 1; } to { opacity: 0; transform: translateX(30px); } }
.toast.removing { animation: fadeOut 0.3s ease-in forwards; }

/* ===== FOOTER ===== */
footer {
  background: #1a1a2e; color: #9ca3af;
  text-align: center; padding: 16px;
  font-size: 0.8rem; margin-top: auto;
}
footer a { color: #60a5fa; text-decoration: none; }
footer a:hover { text-decoration: underline; }

/* ===== ADMIN ===== */
.admin-header { display: flex; align-items: center; gap: 16px; margin-bottom: 24px; }
.admin-header h1 { font-size: 1.4rem; color: #1f2937; }

.admin-section {
  background: white; border-radius: 12px; padding: 24px;
  margin-bottom: 20px; box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}
.admin-section h2 {
  font-size: 1rem; font-weight: 700; color: #374151;
  margin-bottom: 20px; padding-bottom: 12px;
  border-bottom: 2px solid #e5e7eb;
}

.form-group { margin-bottom: 16px; }
.form-group label {
  display: block; font-size: 0.85rem; font-weight: 600;
  color: #374151; margin-bottom: 6px;
}
.form-group input[type="text"],
.form-group input[type="password"],
.form-group input[type="datetime-local"] {
  width: 100%; padding: 10px 14px;
  border: 1.5px solid #d1d5db; border-radius: 8px;
  font-size: 0.9rem; color: #1f2937; transition: border-color 0.2s; background: white;
}
.form-group input:focus { outline: none; border-color: #3b82f6; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-hint { font-size: 0.75rem; color: #9ca3af; margin-top: 4px; }

.auth-status { font-size: 0.85rem; margin-top: 10px; font-weight: 600; }
.auth-status.success { color: #16a34a; }
.auth-status.error   { color: #dc2626; }

.image-preview {
  width: 80px; height: 80px; border-radius: 8px;
  object-fit: cover; border: 1px solid #e5e7eb; margin-top: 8px;
}

.candidates-list { margin-top: 20px; border-top: 1px solid #e5e7eb; padding-top: 16px; }
.candidates-list-title { font-size: 0.9rem; font-weight: 600; color: #374151; margin-bottom: 12px; }
.candidate-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 0; border-bottom: 1px solid #f3f4f6;
}
.candidate-item img {
  width: 44px; height: 44px; border-radius: 50%;
  object-fit: cover; background: #f3f4f6; flex-shrink: 0;
}
.candidate-item-info { flex: 1; }
.candidate-item-name { font-size: 0.9rem; font-weight: 600; color: #1f2937; }
.candidate-item-id   { font-size: 0.75rem; color: #9ca3af; }

.candidates-count-badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 0.8rem; font-weight: 600;
  padding: 2px 10px; border-radius: 20px; margin-left: 8px;
}
.candidates-count-badge.ok   { background: #dcfce7; color: #16a34a; }
.candidates-count-badge.warn { background: #fef3c7; color: #92400e; }

.min-candidates-hint {
  font-size: 0.82rem; padding: 8px 12px; border-radius: 6px; margin-top: 8px;
}
.min-candidates-hint.ok   { background: #dcfce7; color: #16a34a; }
.min-candidates-hint.warn { background: #fef3c7; color: #92400e; }

/* ===== UTILITY ===== */
.hidden { display: none !important; }

/* ===== RESULT SCREEN (SCR-010) ===== */
.result-header { text-align: center; margin-bottom: 20px; }
.result-title { font-size: 1.4rem; font-weight: 700; color: #1f2937; margin-bottom: 8px; border: none; }
.result-subtitle { font-size: 0.85rem; color: #6b7280; margin-top: 4px; }
.result-total  { font-size: 0.95rem; color: #374151; font-weight: 600; margin-top: 8px; }
.no-votes-msg  { text-align: center; color: #9ca3af; padding: 40px 20px; font-size: 1rem; }

/* Full-width bar chart section */
.result-bar-container { position: relative; margin-bottom: 24px; }

/* Rank + Donut row */
.rank-donut-row {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 20px; margin-top: 8px; align-items: start;
}
.result-donut-container { position: relative; height: 280px; }

/* Ranking cards */
.rank-cards-wrapper {
  display: flex; flex-direction: column; gap: 12px;
}
.rank-card {
  display: flex; align-items: center; gap: 14px;
  border-radius: 12px; padding: 14px 16px;
  background: #fafafa; border: 2px solid #e5e7eb;
  position: relative; transition: transform 0.2s;
}
.rank-1 {
  border: 3px solid #ffd700;
  box-shadow: 0 4px 16px rgba(255,215,0,0.25);
  background: #fffdf0;
}
.rank-2 { border: 2px solid #c0c0c0; background: #fafafa; }
.rank-3 { border: 2px solid #cd7f32; background: #fdf8f4; }

.rank-badge-label { font-size: 1.3rem; flex-shrink: 0; }
.rank-img { border-radius: 50%; object-fit: cover; background: #f3f4f6; flex-shrink: 0; }
.rank-img-large  { width: 72px; height: 72px; }
.rank-img-medium { width: 56px; height: 56px; }
.rank-info { flex: 1; }
.rank-name   { font-size: 1rem; font-weight: 700; color: #1f2937; margin-bottom: 2px; }
.rank-votes  { font-size: 1rem; font-weight: 700; color: #374151; }
.rank-pct    { font-size: 0.82rem; color: #9ca3af; }
.rank-elected {
  display: inline-block; background: #fef3c7; color: #d97706;
  font-weight: 700; font-size: 0.8rem; padding: 2px 8px; border-radius: 20px; margin-top: 4px;
}

.result-footer {
  text-align: center; margin-top: 20px; padding-top: 16px;
  border-top: 1px solid #f3f4f6; font-size: 0.8rem; color: #9ca3af;
}
.result-footer a { color: #60a5fa; text-decoration: none; }

/* Live chart container */
.live-chart-wrapper { position: relative; margin-bottom: 12px; }

/* Responsive */
@media (max-width: 640px) {
  .rank-donut-row { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .countdown-box { min-width: 62px; padding: 12px 16px; }
  .countdown-box .count { font-size: 1.6rem; }
}
