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

:root {
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --primary-light: #818cf8;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --bg: #f0f4ff;
  --card-bg: #ffffff;
  --text: #1e293b;
  --text-light: #64748b;
  --shadow: 0 4px 20px rgba(79, 70, 229, 0.1);
  --shadow-hover: 0 12px 40px rgba(79, 70, 229, 0.2);
  --radius: 16px;
}

body {
  font-family: 'PingFang SC', 'Microsoft YaHei', 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

/* ============ Hero Header ============ */
.hero {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #fff;
  padding: 60px 20px;
  text-align: center;
  position: relative;
  overflow: hidden;
}

.hero::before {
  content: '';
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: radial-gradient(circle, rgba(255,255,255,0.1) 1px, transparent 1px);
  background-size: 30px 30px;
  opacity: 0.5;
}

.hero-content {
  position: relative;
  z-index: 1;
}

.hero h1 {
  font-size: 2.8rem;
  margin-bottom: 12px;
  text-shadow: 0 2px 10px rgba(0,0,0,0.2);
}

.subtitle {
  font-size: 1.2rem;
  opacity: 0.95;
  margin-bottom: 16px;
}

.total-info {
  display: inline-block;
  background: rgba(255,255,255,0.2);
  padding: 8px 24px;
  border-radius: 50px;
  font-size: 1rem;
  backdrop-filter: blur(10px);
}

.total-info span {
  font-weight: bold;
  font-size: 1.3rem;
}

/* ============ Candidate Grid ============ */
.container {
  max-width: 1200px;
  margin: -30px auto 40px;
  padding: 0 20px;
  position: relative;
  z-index: 2;
}

.candidate-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 24px;
}

.loading {
  text-align: center;
  padding: 60px;
  color: var(--text-light);
  font-size: 1.1rem;
  grid-column: 1 / -1;
}

/* ============ Candidate Card ============ */
.candidate-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
  display: flex;
  flex-direction: column;
}

.candidate-card:hover {
  transform: translateY(-8px);
  box-shadow: var(--shadow-hover);
}

.candidate-card.voted {
  border: 2px solid var(--success);
}

.candidate-photo {
  width: 100%;
  height: 280px;
  background: linear-gradient(135deg, #e0e7ff, #c7d2fe);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
}

.candidate-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.candidate-photo .placeholder {
  font-size: 4rem;
  color: var(--primary-light);
}

.rank-badge {
  position: absolute;
  top: 12px;
  left: 12px;
  background: var(--primary);
  color: #fff;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  font-size: 1rem;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.rank-badge.gold {
  background: linear-gradient(135deg, #ffd700, #ffb700);
  font-size: 1.4rem;
  width: 44px;
  height: 44px;
}

.rank-badge.silver {
  background: linear-gradient(135deg, #c0c0c0, #a8a8a8);
  font-size: 1.3rem;
}

.rank-badge.bronze {
  background: linear-gradient(135deg, #cd7f32, #b8742a);
  font-size: 1.2rem;
}

.candidate-info {
  padding: 20px;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.candidate-name {
  font-size: 1.4rem;
  font-weight: bold;
  margin-bottom: 8px;
  color: var(--text);
}

.candidate-bio {
  color: var(--text-light);
  font-size: 0.95rem;
  margin-bottom: 16px;
  flex: 1;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.candidate-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.vote-count {
  font-size: 1.5rem;
  font-weight: bold;
  color: var(--primary);
}

.vote-count-label {
  font-size: 0.85rem;
  color: var(--text-light);
}

/* ============ Buttons ============ */
.btn {
  padding: 10px 24px;
  border: none;
  border-radius: 10px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.25s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
}

.btn:active {
  transform: scale(0.96);
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
}

.btn-primary:hover {
  box-shadow: 0 4px 15px rgba(79,70,229,0.4);
  transform: translateY(-2px);
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  background: var(--text-light);
  box-shadow: none;
  transform: none;
}

.btn-success {
  background: linear-gradient(135deg, #10b981, #059669);
  color: #fff;
}

.btn-success:hover {
  box-shadow: 0 4px 15px rgba(16,185,129,0.4);
  transform: translateY(-2px);
}

.btn-secondary {
  background: #e2e8f0;
  color: var(--text);
}

.btn-secondary:hover {
  background: #cbd5e1;
}

.btn-warning {
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: #fff;
}

.btn-warning:hover {
  box-shadow: 0 4px 15px rgba(245,158,11,0.4);
}

.btn-danger {
  background: linear-gradient(135deg, #ef4444, #dc2626);
  color: #fff;
}

.btn-danger:hover {
  box-shadow: 0 4px 15px rgba(239,68,68,0.4);
}

.btn-full {
  width: 100%;
}

.btn-small {
  padding: 6px 14px;
  font-size: 0.85rem;
}

/* ============ Footer ============ */
.footer {
  text-align: center;
  padding: 30px 20px;
  color: var(--text-light);
  font-size: 0.9rem;
}

.admin-link {
  display: inline-block;
  margin-top: 8px;
  color: var(--primary);
  text-decoration: none;
  font-size: 0.85rem;
  opacity: 0.6;
}

.admin-link:hover {
  opacity: 1;
}

/* ============ Toast ============ */
.toast {
  position: fixed;
  top: 30px;
  left: 50%;
  transform: translateX(-50%) translateY(-150px);
  background: var(--text);
  color: #fff;
  padding: 14px 32px;
  border-radius: 50px;
  font-size: 0.95rem;
  font-weight: 500;
  box-shadow: 0 8px 30px rgba(0,0,0,0.3);
  z-index: 9999;
  transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  max-width: 90%;
  text-align: center;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
}

.toast.success {
  background: var(--success);
}

.toast.error {
  background: var(--danger);
}

.toast.info {
  background: var(--primary);
}

/* ============ Login Screen ============ */
.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  padding: 20px;
}

.login-card {
  background: #fff;
  border-radius: 20px;
  padding: 40px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  text-align: center;
}

.login-card h2 {
  margin-bottom: 24px;
  color: var(--text);
}

.login-card input {
  width: 100%;
  padding: 14px 18px;
  border: 2px solid #e2e8f0;
  border-radius: 12px;
  font-size: 1rem;
  margin-bottom: 16px;
  transition: border-color 0.25s ease;
}

.login-card input:focus {
  outline: none;
  border-color: var(--primary);
}

.login-hint {
  color: var(--text-light);
  font-size: 0.85rem;
  margin-top: 12px;
}

.back-link {
  display: inline-block;
  margin-top: 20px;
  color: var(--primary);
  text-decoration: none;
  font-size: 0.9rem;
}

/* ============ Admin Panel ============ */
.admin-panel {
  min-height: 100vh;
  background: var(--bg);
}

.admin-header {
  background: linear-gradient(135deg, #4f46e5, #6366f1);
  color: #fff;
  padding: 24px 30px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.admin-header h1 {
  font-size: 1.6rem;
}

.admin-actions {
  display: flex;
  gap: 10px;
}

.admin-main {
  max-width: 1100px;
  margin: 30px auto;
  padding: 0 20px;
  display: grid;
  grid-template-columns: 350px 1fr;
  gap: 30px;
  align-items: start;
}

.form-section, .list-section {
  background: #fff;
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
}

.form-section h2, .list-section h2 {
  margin-bottom: 20px;
  color: var(--text);
  font-size: 1.25rem;
  border-bottom: 2px solid var(--bg);
  padding-bottom: 12px;
}

.candidate-form .form-row {
  margin-bottom: 16px;
}

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

.candidate-form input[type="text"],
.candidate-form textarea {
  width: 100%;
  padding: 10px 14px;
  border: 2px solid #e2e8f0;
  border-radius: 10px;
  font-size: 0.95rem;
  font-family: inherit;
  transition: border-color 0.25s ease;
  resize: vertical;
}

.candidate-form input[type="text"]:focus,
.candidate-form textarea:focus {
  outline: none;
  border-color: var(--primary);
}

.candidate-form input[type="file"] {
  width: 100%;
  padding: 8px;
}

.photo-preview {
  margin-top: 10px;
}

.photo-preview img {
  width: 100%;
  max-height: 180px;
  object-fit: cover;
  border-radius: 10px;
}

.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}

/* ============ Candidate Table ============ */
.candidate-table {
  width: 100%;
  border-collapse: collapse;
}

.candidate-table th {
  text-align: left;
  padding: 10px 12px;
  background: var(--bg);
  color: var(--text-light);
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-radius: 8px;
}

.candidate-table th:first-child { border-radius: 8px 0 0 8px; }
.candidate-table th:last-child { border-radius: 0 8px 8px 0; }

.candidate-table td {
  padding: 12px;
  border-bottom: 1px solid #e2e8f0;
  font-size: 0.9rem;
  vertical-align: middle;
}

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

.table-photo {
  width: 50px;
  height: 50px;
  border-radius: 8px;
  object-fit: cover;
  background: var(--bg);
}

.table-photo-placeholder {
  width: 50px;
  height: 50px;
  border-radius: 8px;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  color: var(--text-light);
}

.table-bio {
  max-width: 200px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-light);
}

.table-actions {
  display: flex;
  gap: 8px;
}

.empty-state {
  text-align: center;
  padding: 40px;
  color: var(--text-light);
}

/* ============ Responsive ============ */
@media (max-width: 768px) {
  .hero {
    padding: 40px 20px;
  }
  .hero h1 {
    font-size: 1.8rem;
  }
  .admin-main {
    grid-template-columns: 1fr;
  }
  .candidate-grid {
    grid-template-columns: 1fr;
  }
  .admin-header {
    flex-direction: column;
    text-align: center;
  }
  .candidate-table {
    font-size: 0.8rem;
  }
  .candidate-table th, .candidate-table td {
    padding: 8px 6px;
  }
  .table-bio {
    display: none;
  }
}

/* ============ Vote Animation ============ */
@keyframes votePop {
  0% { transform: scale(1); }
  50% { transform: scale(1.3); color: var(--success); }
  100% { transform: scale(1); }
}

.vote-count.animate {
  animation: votePop 0.5s ease;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.candidate-card {
  animation: fadeInUp 0.5s ease backwards;
}

.candidate-card:nth-child(1) { animation-delay: 0.05s; }
.candidate-card:nth-child(2) { animation-delay: 0.1s; }
.candidate-card:nth-child(3) { animation-delay: 0.15s; }
.candidate-card:nth-child(4) { animation-delay: 0.2s; }
.candidate-card:nth-child(5) { animation-delay: 0.25s; }
.candidate-card:nth-child(6) { animation-delay: 0.3s; }
.candidate-card:nth-child(7) { animation-delay: 0.35s; }
.candidate-card:nth-child(8) { animation-delay: 0.4s; }
