/* ============================================================
   PreferênciasApp — Stylesheet
   ============================================================ */

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

:root {
  --primary:    #6366f1;
  --primary-dk: #4f46e5;
  --success:    #10b981;
  --danger:     #ef4444;
  --warn:       #f59e0b;
  --bg:         #f8fafc;
  --surface:    #ffffff;
  --border:     #e2e8f0;
  --text:       #1e293b;
  --muted:      #64748b;
  --radius:     12px;
  --shadow:     0 2px 16px rgba(0,0,0,.08);
}

html { font-size: 16px; }
body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

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

/* ---- Header ---- */
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: .75rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
}
.logo {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--primary);
  text-decoration: none;
}
nav { display: flex; gap: .75rem; align-items: center; }

.btn-admin, .btn-export, .btn-logout, .btn-primary {
  padding: .4rem .9rem;
  border-radius: 8px;
  font-size: .875rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  text-decoration: none;
  transition: opacity .15s;
}
.btn-admin   { background: var(--primary); color: #fff; }
.btn-export  { background: var(--success); color: #fff; }
.btn-logout  { background: var(--border); color: var(--text); }
.btn-primary { background: var(--primary); color: #fff; display: inline-block; }
.btn-admin:hover, .btn-export:hover, .btn-primary:hover { opacity: .85; text-decoration: none; }

/* ---- Main & Footer ---- */
main { flex: 1; padding: 2rem 1rem; max-width: 900px; margin: 0 auto; width: 100%; }
footer { text-align: center; padding: 1rem; color: var(--muted); font-size: .8rem; }

/* ---- Hero / Index ---- */
.hero { text-align: center; margin-bottom: 2rem; }
.hero h1 { font-size: 2rem; font-weight: 800; margin-bottom: .5rem; }
.subtitle { color: var(--muted); font-size: 1rem; }

.category-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 1rem;
}
.category-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem 1rem;
  text-align: center;
  color: var(--text);
  font-weight: 600;
  font-size: .95rem;
  transition: box-shadow .2s, transform .2s;
  text-decoration: none;
}
.category-card:hover {
  box-shadow: var(--shadow);
  transform: translateY(-3px);
  text-decoration: none;
}
.cat-icon { font-size: 2rem; margin-bottom: .5rem; }

/* ---- Vote Page ---- */
.vote-container { max-width: 860px; margin: 0 auto; }

.vote-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
}
.vote-header h2 { flex: 1; font-size: 1.4rem; }
.vote-count {
  background: var(--primary);
  color: #fff;
  border-radius: 20px;
  padding: .25rem .8rem;
  font-size: .85rem;
  font-weight: 600;
}
.back-link { color: var(--muted); font-size: .9rem; }

.instruction {
  text-align: center;
  color: var(--muted);
  margin-bottom: 1.5rem;
  font-size: 1rem;
}

.pair-wrapper {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.25rem;
  min-height: 340px;
}

@media (min-width: 700px) {
  .pair-wrapper {
    grid-template-columns: 1fr 1fr;
    min-height: 340px;
  }
}

.image-card {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: border-color .2s, box-shadow .2s, transform .15s;
  height: 320px;
  position: relative;
  -webkit-transform: translateZ(0);
  transform: translateZ(0);
}
.image-card:hover {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99,102,241,.2);
  transform: scale(1.01);
}
.image-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  display: block;
  user-select: none;
  pointer-events: none;
  -webkit-user-drag: none;
}

/* Winner / Loser feedback */
.image-card.winner {
  border-color: var(--success);
  box-shadow: 0 0 0 4px rgba(16,185,129,.3);
  transform: scale(1.03);
}
.image-card.loser {
  opacity: .45;
  transform: scale(.97);
}

/* Loading */
.loading-pair {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  color: var(--muted);
  min-height: 280px;
}
.spinner {
  width: 40px; height: 40px;
  border: 4px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Progress bar */
.progress-bar-wrap {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  margin-top: 1.5rem;
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  background: var(--primary);
  width: 0;
  transition: width .4s ease;
  border-radius: 3px;
}
.progress-bar.complete { background: var(--success); }

/* Error */
.error-msg {
  margin-top: 1rem;
  padding: .75rem 1rem;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 8px;
  color: var(--danger);
  font-size: .9rem;
}
.hidden { display: none; }

/* ---- Login Page ---- */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg);
}
.login-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow);
}
.login-box h1 { font-size: 1.5rem; margin-bottom: 1.5rem; text-align: center; }
.login-box label { display: block; margin-bottom: .4rem; font-size: .9rem; font-weight: 600; }
.login-box input {
  width: 100%;
  padding: .6rem .9rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  margin-bottom: 1rem;
  outline: none;
  transition: border-color .15s;
}
.login-box input:focus { border-color: var(--primary); }
.login-box .btn-primary { width: 100%; padding: .65rem; font-size: 1rem; }
.alert-error {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: var(--danger);
  padding: .6rem .9rem;
  border-radius: 8px;
  margin-bottom: 1rem;
  font-size: .9rem;
}

/* ---- Admin Page ---- */
.admin-page body, .admin-main {  }
.admin-main { max-width: 1100px; margin: 0 auto; padding: 2rem 1rem; }
.admin-main h1 { font-size: 1.75rem; font-weight: 800; margin-bottom: 1.5rem; }
.admin-main h2 { font-size: 1.2rem; font-weight: 700; margin-bottom: 1rem; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: .25rem;
}
.stat-card.warn { border-color: var(--warn); }
.stat-value { font-size: 2rem; font-weight: 800; color: var(--primary); }
.stat-card.warn .stat-value { color: var(--warn); }
.stat-label { font-size: .85rem; color: var(--muted); }

.chart-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 2rem;
}
.chart-wrap { max-height: 280px; }

.ranking-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 2rem;
}
.ranking-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .9rem;
}
.ranking-table th {
  text-align: left;
  padding: .5rem .75rem;
  border-bottom: 2px solid var(--border);
  color: var(--muted);
  font-weight: 600;
  font-size: .8rem;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.ranking-table td {
  padding: .6rem .75rem;
  border-bottom: 1px solid var(--border);
}
.ranking-table tr:last-child td { border-bottom: none; }
.thumb-cell { display: flex; align-items: center; gap: .75rem; }
.thumb { width: 48px; height: 48px; object-fit: cover; border-radius: 6px; border: 1px solid var(--border); }

.empty-note { color: var(--muted); font-size: .9rem; }
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--muted);
}
.empty-state code {
  background: var(--border);
  padding: .1rem .4rem;
  border-radius: 4px;
  font-size: .9rem;
}

/* ---- Responsivo ---- */
@media (max-width: 768px) {
  /* Vote page: imagens empilhadas */
  .pair-wrapper {
    grid-template-columns: 1fr;
    gap: 1rem;
    min-height: unset;
  }
  .image-card {
    height: 200px !important;
    min-height: 0 !important;
  }

  /* Header da votação mais compacto */
  .vote-header {
    flex-wrap: wrap;
    gap: .5rem;
  }
  .vote-header h2 {
    font-size: 1.1rem;
  }

  /* Hero */
  .hero h1 { font-size: 1.4rem; }

  /* Admin */
  .stats-grid { grid-template-columns: 1fr 1fr; }

  /* Main com menos padding lateral */
  main { padding: 1.25rem .75rem; }
}

@media (max-width: 480px) {
  .image-card {
    height: 170px !important;
  }
  .vote-header h2 {
    font-size: 1rem;
  }
}
