/* ===== Reset & Base ===== */
*,*::before,*::after { margin:0; padding:0; box-sizing:border-box; }

:root {
  --primary: #e63946;
  --primary-dark: #c1121f;
  --primary-light: #f1aeb5;
  --gold: #f4a261;
  --gold-dark: #e76f51;
  --bg: #fff5f5;
  --card-bg: #fff;
  --text: #2b2b2b;
  --text-light: #666;
  --border: #eee;
  --shadow: 0 4px 20px rgba(0,0,0,.08);
  --shadow-hover: 0 8px 30px rgba(230,57,70,.18);
  --radius: 16px;
}

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

/* ===== Header ===== */
.header {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 10px rgba(0,0,0,.15);
}
.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.logo { font-size: 20px; font-weight: 700; }
.header-actions { display: flex; gap: 12px; align-items: center; }
.admin-link {
  color: #fff;
  text-decoration: none;
  font-size: 14px;
  padding: 6px 16px;
  border: 1px solid rgba(255,255,255,.5);
  border-radius: 8px;
  transition: all .2s;
}
.admin-link:hover { background: rgba(255,255,255,.2); }

/* ===== Hero ===== */
.hero {
  text-align: center;
  padding: 60px 20px 40px;
  background: linear-gradient(180deg, #fff5f5 0%, #fff 100%);
}
.hero h1 {
  font-size: 42px;
  color: var(--primary-dark);
  margin-bottom: 12px;
  letter-spacing: 2px;
}
.hero p {
  font-size: 18px;
  color: var(--text-light);
  margin-bottom: 24px;
}
.total-votes {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  background: #fff;
  padding: 16px 40px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 2px solid var(--primary-light);
}
.total-num {
  font-size: 36px;
  font-weight: 800;
  color: var(--primary);
}
.total-label {
  font-size: 13px;
  color: var(--text-light);
  margin-top: 4px;
}

/* ===== Container ===== */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px 20px 60px;
}

/* ===== Grid ===== */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 24px;
}

/* ===== Candidate Card ===== */
.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  transition: all .3s ease;
  display: flex;
  flex-direction: column;
}
.card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-hover);
}
.card-photo {
  width: 100%;
  height: 320px;
  overflow: hidden;
  position: relative;
  background: linear-gradient(135deg, #f1aeb5, #e63946);
}
.card-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.card-photo .placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 64px;
  color: rgba(255,255,255,.9);
}
.card-body {
  padding: 20px;
  flex: 1;
  display: flex;
  flex-direction: column;
}
.card-name {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--text);
}
.card-intro {
  font-size: 14px;
  color: var(--text-light);
  margin-bottom: 16px;
  flex: 1;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.vote-count {
  display: flex;
  flex-direction: column;
  align-items: center;
}
.vote-num {
  font-size: 28px;
  font-weight: 800;
  color: var(--primary);
}
.vote-label {
  font-size: 12px;
  color: var(--text-light);
}
.vote-btn {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  border: none;
  padding: 10px 24px;
  border-radius: 10px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all .25s;
  white-space: nowrap;
}
.vote-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 15px rgba(230,57,70,.4);
}
.vote-btn:active { transform: scale(.96); }
.vote-btn.voted {
  background: #ccc;
  cursor: not-allowed;
}

/* Rank badge */
.rank-badge {
  position: absolute;
  top: 10px;
  left: 10px;
  background: rgba(0,0,0,.6);
  color: #ffd700;
  font-size: 14px;
  font-weight: 700;
  padding: 4px 12px;
  border-radius: 20px;
  z-index: 2;
}
.rank-badge.rank-1 { background: linear-gradient(135deg, #ffd700, #ff8c00); color: #fff; }
.rank-badge.rank-2 { background: linear-gradient(135deg, #c0c0c0, #808080); color: #fff; }
.rank-badge.rank-3 { background: linear-gradient(135deg, #cd7f32, #8b4513); color: #fff; }

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

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: #333;
  color: #fff;
  padding: 14px 28px;
  border-radius: 10px;
  font-size: 15px;
  z-index: 9999;
  opacity: 0;
  transition: all .3s ease;
  pointer-events: none;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.toast.success { background: #2a9d8f; }
.toast.error { background: #e63946; }

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

/* ===== Admin: Login ===== */
.login-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 60px);
}
.login-card {
  background: #fff;
  padding: 40px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 400px;
}
.login-card h2 {
  text-align: center;
  margin-bottom: 24px;
  color: var(--primary-dark);
}
.login-error {
  color: var(--primary);
  text-align: center;
  margin-top: 12px;
  font-size: 14px;
  min-height: 20px;
}

/* ===== Admin: Panel ===== */
.admin-panel {
  max-width: 1200px;
  margin: 0 auto;
  padding: 30px 20px;
}
.admin-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 12px;
}
.admin-toolbar h2 { color: var(--primary-dark); }
.toolbar-actions { display: flex; gap: 10px; }

/* ===== Admin: Table ===== */
.candidate-table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.candidate-table th,
.candidate-table td {
  padding: 14px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.candidate-table th {
  background: #fff0f0;
  font-weight: 600;
  font-size: 14px;
  color: var(--primary-dark);
}
.candidate-table td { font-size: 14px; }
.candidate-table tr:last-child td { border-bottom: none; }
.candidate-table tr:hover { background: #fff9f9; }
.table-photo {
  width: 50px;
  height: 50px;
  border-radius: 8px;
  object-fit: cover;
  background: var(--primary-light);
}
.table-photo.placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  color: #fff;
}
.table-intro {
  max-width: 300px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-light);
}
.table-votes {
  font-weight: 700;
  color: var(--primary);
  font-size: 18px;
}
.table-actions { display: flex; gap: 8px; }
.btn-edit {
  background: #457b9d;
  color: #fff;
  border: none;
  padding: 6px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
}
.btn-edit:hover { background: #35617a; }
.btn-delete {
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 6px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
}
.btn-delete:hover { background: var(--primary-dark); }

/* ===== Buttons ===== */
.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  border: none;
  padding: 10px 22px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all .2s;
}
.btn-primary:hover { box-shadow: 0 4px 12px rgba(230,57,70,.35); }
.btn-secondary {
  background: #e9ecef;
  color: var(--text);
  border: none;
  padding: 10px 22px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all .2s;
}
.btn-secondary:hover { background: #dee2e6; }
.btn-full { width: 100%; }
.btn-logout {
  background: rgba(255,255,255,.2);
  color: #fff;
  border: 1px solid rgba(255,255,255,.5);
  padding: 6px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
}
.btn-logout:hover { background: rgba(255,255,255,.3); }

/* ===== Modal ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}
.modal {
  background: #fff;
  border-radius: var(--radius);
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { color: var(--primary-dark); }
.modal-close {
  background: none;
  border: none;
  font-size: 28px;
  cursor: pointer;
  color: #999;
  line-height: 1;
}
.modal-close:hover { color: var(--primary); }

/* ===== Forms ===== */
.form-group { margin-bottom: 18px; padding: 0 24px; }
.form-group label {
  display: block;
  margin-bottom: 6px;
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
}
.form-group input,
.form-group textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid #ddd;
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  transition: border-color .2s;
}
.form-group input:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
}
.form-group textarea { resize: vertical; }
.photo-upload { text-align: center; }
.photo-preview {
  width: 150px;
  height: 150px;
  object-fit: cover;
  border-radius: 12px;
  margin-bottom: 10px;
  border: 2px solid var(--border);
}
.hint { font-size: 12px; color: var(--text-light); }
.modal-footer {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  padding: 20px 24px;
  border-top: 1px solid var(--border);
}
.modal-footer button { width: auto; }

/* ===== Responsive ===== */
@media (max-width: 600px) {
  .hero h1 { font-size: 28px; }
  .hero p { font-size: 14px; }
  .grid { grid-template-columns: 1fr; }
  .card-photo { height: 260px; }
  .admin-toolbar { flex-direction: column; align-items: stretch; }
  .candidate-table { font-size: 12px; }
  .candidate-table th, .candidate-table td { padding: 8px; }
  .table-intro { max-width: 120px; }
}
