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

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface-hover: #1f2230;
  --border: #2a2e3a;
  --text: #f5f6fa;
  --text-muted: #9a9eb5;
  --accent: #6c8cff;
  --accent-hover: #8ba3ff;
  --stars: #f0c040;
  --radius: 6px;
}

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

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem 1rem 4rem;
}

/* --- Header --- */

header {
  text-align: center;
  margin-bottom: 1.5rem;
}

h1 {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.subtitle {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-top: 0.15rem;
}

/* --- Controls --- */

.controls {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.search-box {
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 12px;
  color: var(--text-muted);
  pointer-events: none;
}

#search {
  width: 100%;
  padding: 0.7rem 2.5rem 0.7rem 2.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.15s;
}

#search:focus {
  border-color: var(--accent);
}

#search::placeholder {
  color: var(--text-muted);
}

.clear-btn {
  display: none;
  position: absolute;
  right: 8px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.25rem;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}

.clear-btn:hover {
  color: #ff6b6b;
}

/* --- Toolbar (filter + reset buttons) --- */

.toolbar {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.toolbar-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.5rem 0.9rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.toolbar-btn:hover {
  border-color: var(--accent);
  color: var(--text);
}

.toolbar-btn svg {
  flex-shrink: 0;
}

.toolbar-btn--reset:hover {
  border-color: #ff6b6b;
  color: #ff6b6b;
  background: rgba(255, 107, 107, 0.08);
}

.filter-badge {
  display: none;
  min-width: 18px;
  height: 18px;
  line-height: 18px;
  text-align: center;
  border-radius: 999px;
  font-size: 0.65rem;
  font-weight: 800;
  background: var(--accent);
  color: #fff;
}

.filter-badge.is-visible {
  display: inline-block;
}

.toolbar-btn--reset {
  display: none;
}

.toolbar-btn--reset.is-visible {
  display: inline-flex;
}

/* --- Filter popup overlay --- */

.filter-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 10vh;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  animation: fadeIn 0.15s ease-out;
}

.filter-overlay[hidden] {
  display: none;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.filter-popup {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  width: 90%;
  max-width: 520px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.4);
  animation: popIn 0.15s ease-out;
}

@keyframes popIn {
  from { opacity: 0; transform: translateY(-10px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.filter-popup-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
}

.filter-popup-header-left {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
}

.filter-popup-title {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text);
}

.popup-stats {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 400;
}

.filter-popup-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
  transition: color 0.15s;
}

.filter-popup-close:hover {
  color: #ff6b6b;
}

.filter-popup-body {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 1rem;
}

.filter-popup-footer {
  padding: 0;
  border-top: none;
  overflow: hidden;
}

.filter-popup-footer:has(.is-visible) {
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border);
}

.popup-reset-btn {
  display: none;
  width: 100%;
  padding: 0.55rem;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.popup-reset-btn.is-visible {
  display: block;
}

.popup-reset-btn:hover {
  border-color: #ff6b6b;
  color: #ff6b6b;
  background: rgba(255, 107, 107, 0.08);
}

/* --- Admin-only elements (hidden by default, shown via body.is-admin) --- */

.admin-only {
  display: none !important;
}

body.is-admin .admin-only {
  display: flex !important;
}

/* --- Filter groups (inside popup) --- */

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.filter-group label {
  font-size: 0.72rem;
  color: var(--text-muted);
  white-space: nowrap;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
}

/* --- Choices.js dark theme overrides --- */

.choices-dark .choices__inner {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-height: 40px;
  padding: 5px 6px 5px;
  font-size: 0.82rem;
  color: var(--text);
}

.choices-dark.is-focused .choices__inner {
  border-color: var(--accent);
}

.choices-dark .choices__input {
  background: transparent;
  color: var(--text);
  font-size: 0.82rem;
  margin-bottom: 0;
  padding: 2px 0;
}

.choices-dark .choices__input::placeholder {
  color: var(--text-muted);
}

.choices-dark .choices__list--multiple .choices__item {
  background: var(--accent);
  border: none;
  border-radius: 4px;
  color: #fff;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 2px 6px;
  margin: 1.5px 2px;
}

.choices-dark .choices__list--multiple .choices__item .choices__button {
  border-left: 1px solid rgba(255, 255, 255, 0.3);
  filter: brightness(2);
}

.choices-dark .choices__list--dropdown,
.choices-dark .choices__list[aria-expanded] {
  background: #1e2130;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  z-index: 110;
}

.choices-dark .choices__list--dropdown .choices__item {
  color: var(--text);
  font-size: 0.82rem;
  padding: 6px 10px;
}

.choices-dark .choices__list--dropdown .choices__item--selectable.is-highlighted {
  background: var(--surface-hover);
  color: var(--text);
}

.choices-dark .choices__list--dropdown .choices__item--selectable::after {
  display: none;
}

.choices-dark .choices__placeholder {
  color: var(--text-muted);
  opacity: 1;
}



/* --- Stats --- */

.stats {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

/* --- Table --- */

.song-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.song-table thead {
  position: sticky;
  top: 0;
  z-index: 2;
}

.song-table th {
  background: #151720;
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.5rem 0.5rem;
  text-align: left;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
  user-select: none;
}

.th-sortable {
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
}

.th-sortable:hover {
  color: var(--text);
  background: #1c1f2e;
}

.th-active {
  color: var(--accent);
}

.sort-idle {
  opacity: 0.3;
  font-size: 0.8em;
}

.song-table td {
  padding: 0.45rem 0.5rem;
  border-bottom: 1px solid #1e2130;
  vertical-align: middle;
  white-space: nowrap;
}

.song-table tbody tr {
  transition: background 0.1s;
}

.song-table tbody tr:hover {
  background: var(--surface-hover);
}

/* Column widths */
.th-name { min-width: 160px; }
.th-artist { min-width: 130px; }
.th-rating { text-align: center; }
.th-key { text-align: center; }
.th-time { text-align: center; }
.th-tempo { text-align: center; }
.th-capo { text-align: center; }
.th-badges { text-align: center; }
.th-conf { text-align: center; }

.td-name {
  font-weight: 600;
  color: var(--text);
}

.td-artist {
  color: var(--text-muted);
}

.artist-taborova {
  display: inline-block;
  padding: 0.05rem 0.4rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  background: #2d3a1f;
  color: #a3cf5e;
}

.td-rating,
.td-key,
.td-time,
.td-tempo,
.td-capo,
.td-badges,
.td-conf {
  text-align: center;
  color: var(--text-muted);
}

/* --- Stars --- */

.stars {
  color: var(--stars);
  font-size: 0.78rem;
  letter-spacing: 0.5px;
}

.stars-empty {
  color: #333;
}

.stars-dim {
  color: transparent;
}

/* --- Key chip --- */

.chip-key {
  display: inline-block;
  padding: 0.08rem 0.4rem;
  border-radius: 4px;
  font-size: 0.72rem;
  font-weight: 700;
  background: #1e2740;
  color: #7ea8e0;
}

/* --- Tempo chip --- */

.chip-tempo {
  display: inline-block;
  padding: 0.08rem 0.35rem;
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: 600;
}

.tempo-pomala {
  background: #1a2830;
  color: #6cbdcf;
}

.tempo-stredni {
  background: #262830;
  color: #9ca0b8;
}

.tempo-rychla {
  background: #2d2020;
  color: #cf7a6c;
}

/* --- Badges (N = nazpaměť, V = vybrnk) --- */

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  font-size: 0.6rem;
  font-weight: 800;
  margin: 0 1px;
}

.badge-heart {
  background: #1f3a2d;
  color: #5ecf8e;
}

.badge-finger {
  background: #2d1f3a;
  color: #a85ecf;
}

/* --- Confidence --- */

.conf-velmi {
  color: #5ecf8e;
  font-weight: 600;
  font-size: 0.75rem;
}

.conf-stredne {
  color: #cfb85e;
  font-weight: 600;
  font-size: 0.75rem;
}

.conf-malo {
  color: #cf5e5e;
  font-weight: 600;
  font-size: 0.75rem;
}

/* --- Song link (name → chords) --- */

.song-link {
  color: var(--text);
  text-decoration: none;
  transition: color 0.15s;
}

.song-link:hover {
  color: #fff;
  text-decoration: underline;
}

/* --- States --- */

.loading,
.empty,
.error {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
}

.error {
  color: #ff6b6b;
}

/* --- Responsive --- */

@media (max-width: 800px) {
  .container {
    padding: 0.75rem 0.6rem 3rem;
  }

  /* Larger touch targets for Choices.js */
  .choices-dark .choices__inner {
    min-height: 44px;
    padding: 6px 8px;
    font-size: 0.88rem;
  }

  .choices-dark .choices__input {
    font-size: 0.88rem;
    padding: 4px 0;
  }

  .choices-dark .choices__list--multiple .choices__item {
    font-size: 0.8rem;
    padding: 3px 8px;
    margin: 2px 2px;
  }

  /* Bigger dropdown items for easy tapping */
  .choices-dark .choices__list--dropdown .choices__item {
    font-size: 0.92rem;
    padding: 10px 12px;
  }

  /* Search input bigger touch target */
  #search {
    padding: 0.75rem 2.5rem;
    font-size: 1rem;
  }

  /* Popup full width on mobile */
  .filter-popup {
    width: 95%;
  }

  .filter-popup-body {
    gap: 0.6rem;
  }

  /* Table horizontal scroll */
  .song-table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
}
