:root {
  --bg: #f4f5f7;
  --panel-bg: #ffffff;
  --text: #1b1e24;
  --text-muted: #6b7280;
  --border: #e2e4e9;
  --header-bg: #14532d;
  --header-text: #ffffff;
  --accent: #14532d;
  --g4-bg: rgba(34, 139, 87, 0.14);
  --g4-border: #1c8a4d;
  --z4-bg: rgba(200, 45, 45, 0.12);
  --z4-border: #c53030;
  --row-hover: rgba(0, 0, 0, 0.03);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --panel-bg: #1d2025;
    --text: #eef0f3;
    --text-muted: #9aa1ab;
    --border: #2d313a;
    --header-bg: #0f3d21;
    --header-text: #f2f5f2;
    --g4-bg: rgba(34, 139, 87, 0.18);
    --g4-border: #2fa860;
    --z4-bg: rgba(220, 60, 60, 0.16);
    --z4-border: #e05252;
    --row-hover: rgba(255, 255, 255, 0.04);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  background: var(--header-bg);
  color: var(--header-text);
  padding: 28px 20px;
  text-align: center;
}

.topbar h1 { margin: 0 0 4px; font-size: 1.8rem; }
.subtitle { margin: 0; opacity: 0.85; font-size: 0.95rem; }

.band-carousel {
  margin-top: 12px;
  overflow: hidden;
  width: 100%;
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 8%, #000 92%, transparent);
  mask-image: linear-gradient(90deg, transparent, #000 8%, #000 92%, transparent);
}

.carousel-track {
  display: flex;
  gap: 8px;
  width: max-content;
  animation: carousel-scroll linear infinite;
}

.carousel-img {
  height: 44px;
  width: 44px;
  object-fit: cover;
  border-radius: 6px;
  flex: 0 0 auto;
  opacity: 0.9;
}

@keyframes carousel-scroll {
  from { transform: translateX(0); }
  to { transform: translateX(-50%); }
}

@media (prefers-reduced-motion: reduce) {
  .carousel-track { animation: none; }
}

.topbar { position: relative; }

.admin-toggle-btn {
  position: absolute;
  top: 16px;
  right: 20px;
  background: transparent;
  border-color: rgba(255, 255, 255, 0.5);
  color: #fff;
  font-weight: 500;
  padding: 6px 14px;
  font-size: 0.85rem;
}

.admin-toggle-btn.is-logged-in {
  border-color: var(--g4-border);
  background: rgba(34, 139, 87, 0.25);
}

.hidden { display: none !important; }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
}

.edit-card { max-width: 380px; }

.band-card {
  position: relative;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 22px;
  width: 100%;
  max-width: 460px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.35);
}
.band-modal-close {
  position: absolute;
  top: 10px;
  right: 12px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
  padding: 4px 8px;
}
.band-modal-head { display: flex; gap: 14px; align-items: center; margin-bottom: 14px; }
.band-modal-img {
  width: 84px; height: 84px; object-fit: cover; border-radius: 10px; flex: 0 0 auto;
}
.band-modal-pos { font-size: 0.85rem; color: var(--text-muted); font-weight: 700; }
.band-modal-name { margin: 2px 0 6px; font-size: 1.35rem; }
.band-modal-head .band-meta { margin-top: 0; }
.band-bio { font-size: 0.9rem; color: var(--text-muted); line-height: 1.5; margin: 0 0 14px; }
.band-embed { border-radius: 12px; display: block; margin-bottom: 14px; }
.band-history { margin-bottom: 14px; }
.band-history .sparkline { width: 100%; height: 44px; display: block; margin-top: 4px; }
.band-modal-links { display: flex; justify-content: center; }
.band-modal-links .band-icons { gap: 14px; transform: scale(1.4); }

.band-name-link { cursor: pointer; }
.band-name-link:hover { text-decoration: underline; }

.band-share-btn {
  display: block;
  width: 100%;
  margin-top: 16px;
  padding: 11px;
  border-radius: 9px;
  background: var(--g4-border);
  border: none;
  color: #fff;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
}
.band-share-btn:hover { filter: brightness(1.08); }

.login-card {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 28px 26px;
  width: 100%;
  max-width: 320px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

.login-card h2 {
  margin: 0 0 6px;
  text-align: center;
  font-size: 1.2rem;
}

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

.login-actions button { flex: 1; }

.login-error {
  margin: 0;
  color: var(--z4-border);
  font-size: 0.85rem;
  text-align: center;
}

main {
  max-width: 760px;
  margin: 0 auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.panel {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 20px;
}

.panel h2 { margin: 0 0 12px; font-size: 1.1rem; }

#band-form {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

#band-form input[type="text"],
#band-form input[type="url"] { flex: 2 1 200px; }
#band-form input[type="number"] { flex: 1 1 140px; }

input, button {
  font-family: inherit;
  font-size: 0.95rem;
}

input[type="text"], input[type="number"], input[type="url"] {
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
}

button {
  padding: 9px 16px;
  border-radius: 6px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font-weight: 600;
}

button:hover { opacity: 0.9; }

button.secondary {
  background: transparent;
  color: var(--accent);
}

.hint {
  margin: 10px 0 0;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.stats {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.stats strong { color: var(--text); }

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: center;
}

.filters input[type="text"] { flex: 2 1 220px; }

.filters select {
  flex: 1 1 160px;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
}

.filters button {
  flex: 0 0 auto;
  background: transparent;
  color: var(--text);
  border-color: var(--border);
  white-space: nowrap;
}

.tier-title {
  margin: 0 0 10px;
  font-size: 1.15rem;
  display: inline-block;
  padding: 4px 12px;
  border-radius: 6px;
  color: #fff;
  cursor: pointer;
  user-select: none;
}

.tier-caret {
  display: inline-block;
  transition: transform 0.15s ease;
  font-size: 0.85em;
}

.tier.collapsed .tier-caret { transform: rotate(-90deg); }
.tier.collapsed .table-wrap { display: none; }

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel-bg);
}

table.liga-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 480px;
}

.liga-table th, .liga-table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 0.92rem;
}

.liga-table th {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.liga-table tbody tr:last-child td { border-bottom: none; }
.liga-table tbody tr:hover { background: var(--row-hover); }

.liga-table td.pos { font-weight: 700; width: 40px; }
.rank-move {
  display: block;
  font-size: 0.68rem;
  font-weight: 700;
  line-height: 1.2;
  margin-top: 1px;
}
.rank-move.up { color: #22c55e; }
.rank-move.down { color: #ef4444; }
.liga-table td.actions { white-space: nowrap; text-align: right; }
.liga-table td.image-col { width: 72px; }
.liga-table td.vote-col { white-space: nowrap; }

.band-thumb {
  width: 56px;
  height: 56px;
  border-radius: 6px;
  object-fit: cover;
  display: block;
  background: var(--bg);
}

.band-thumb-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  font-weight: 700;
  border: 1px solid var(--border);
  color: var(--text-muted);
}

.band-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 10px;
  margin-top: 3px;
  font-size: 0.74rem;
  color: var(--text-muted);
}

.band-genre {
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--border);
  color: var(--text);
  text-transform: capitalize;
}

.vote-cell {
  display: inline-flex;
  gap: 6px;
}

.vote-btn {
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  font-size: 1.05rem;
  line-height: 1;
  border-radius: 9px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
  transition: transform 0.08s ease, background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}

.vote-btn:hover { transform: translateY(-1px); }
.vote-btn:active { transform: scale(0.92); }
.vote-btn.vote-up:hover { border-color: #22c55e; color: #22c55e; }
.vote-btn.vote-down:hover { border-color: #ef4444; color: #ef4444; }

/* Voto escolhido: preenchido na cor da direção. Clique de novo remove. */
.vote-btn.vote-up.vote-chosen {
  background: #22c55e;
  border-color: #22c55e;
  color: #fff;
}
.vote-btn.vote-down.vote-chosen {
  background: #ef4444;
  border-color: #ef4444;
  color: #fff;
}

.band-icons {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-left: 8px;
  vertical-align: middle;
}

.band-icon {
  display: inline-flex;
  text-decoration: none;
  cursor: pointer;
  opacity: 0.85;
}

.band-icon:hover { opacity: 1; }
.band-icon svg { display: block; }

.liga-table tr.g4 { background: var(--g4-bg); box-shadow: inset 3px 0 0 var(--g4-border); }
.liga-table tr.z4 { background: var(--z4-bg); box-shadow: inset 3px 0 0 var(--z4-border); }

.empty-row td {
  text-align: center;
  color: var(--text-muted);
  font-style: italic;
  padding: 18px;
}

.icon-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 4px 9px;
  font-size: 0.8rem;
  font-weight: 500;
  margin-left: 4px;
}

.icon-btn.danger:hover { border-color: var(--z4-border); color: var(--z4-border); }
.icon-btn:hover { color: var(--text); }

.update-dates {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  justify-content: center;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.update-dates strong { color: var(--text); }

.howto {
  display: flex;
  gap: 10px 20px;
  flex-wrap: wrap;
  justify-content: center;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel-bg);
  font-size: 0.85rem;
  color: var(--text-muted);
}

.howto strong { color: var(--text); }

.highlights {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
}

.highlight-card {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.highlight-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
}

.highlight-name { font-weight: 700; }

.highlight-value {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.legend {
  display: flex;
  gap: 20px;
  justify-content: center;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.legend-item { display: flex; align-items: center; gap: 6px; }

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}

.dot.g4 { background: var(--g4-border); }
.dot.z4 { background: var(--z4-border); }

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

.votes-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 20px;
  margin-bottom: 12px;
  font-size: 0.9rem;
  color: var(--text-muted);
}
.votes-summary strong { color: var(--text); font-size: 1.05rem; }
.votes-table th, .votes-table td { font-size: 0.85rem; }
.votes-table td.vp-pos, .votes-table th:nth-child(2) { text-align: center; }
.votes-table td.vp-neg, .votes-table th:nth-child(3) { text-align: center; }
.votes-table th:nth-child(4), .votes-table th:nth-child(5),
.votes-table td:nth-child(4), .votes-table td:nth-child(5) { text-align: center; }
.vp-pos { color: #22c55e; font-weight: 600; }
.vp-neg { color: #ef4444; font-weight: 600; }

/* ---- Mobile ---- */
@media (max-width: 600px) {
  main { padding: 12px; gap: 18px; }
  /* padding-top maior: o botão Admin é absoluto no topo, o título passa abaixo dele. */
  .topbar { padding: 46px 12px 16px; }
  .topbar h1 { font-size: 1.35rem; }
  .subtitle { font-size: 0.82rem; }
  .admin-toggle-btn { top: 10px; right: 10px; padding: 5px 10px; font-size: 0.78rem; }

  /* Tabela cabe sem rolar de lado: menos padding, foto e fontes menores. */
  table.liga-table { min-width: 0; }
  .liga-table th, .liga-table td { padding: 8px 6px; font-size: 0.86rem; }
  .liga-table td.pos { width: 26px; }
  .liga-table td.image-col { width: 52px; }
  .band-thumb { width: 44px; height: 44px; }
  .band-icons { gap: 4px; }
  .vote-btn { width: 40px; height: 40px; font-size: 1.1rem; }
  .vote-cell { gap: 5px; }

  .howto { font-size: 0.8rem; gap: 6px 14px; }
  .panel { padding: 14px; }
}
