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

[hidden] {
  display: none !important;
}

:root {
  --bg: #14100d;
  --surface: #1e1712;
  --surface2: #29201a;
  --border: #3a2c20;
  --text: #ece3d6;
  --text-muted: #9a8a76;
  --accent: #c9822c;
  --accent-hover: #dd9a49;
  --danger: #c0392b;
  --danger-hover: #e74c3c;
  --radius: 8px;
  --font: 'Segoe UI', system-ui, sans-serif;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  min-height: 100vh;
}

/* Header */
header {
  background: var(--surface);
  border-bottom: 2px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}
.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 1.5rem;
  height: 56px;
  display: flex;
  align-items: stretch;
  justify-content: space-between;
}
.header-left {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}
.logo {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--accent);
  text-decoration: none;
  letter-spacing: 0.02em;
  margin-right: 0.5rem;
  display: flex;
  align-items: center;
  white-space: nowrap;
  flex-shrink: 0;
}
nav {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}
#nav-primary {
  display: flex;
  align-items: stretch;
  gap: 0;
}
.nav-link {
  display: flex;
  align-items: center;
  padding: 0 0.85rem;
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--text-muted);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition:
    color 0.15s,
    border-color 0.15s;
  white-space: nowrap;
}
.nav-link:hover {
  color: var(--text);
}
.nav-link-active {
  color: var(--text);
  border-bottom-color: var(--accent);
}

/* Main */
main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  padding: 0.55em 1.2em;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
  transition:
    background 0.15s,
    opacity 0.15s;
}
.btn:disabled {
  opacity: 0.5;
  cursor: default;
}
.btn-primary {
  background: var(--accent);
  color: #14100d;
}
.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}
.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.btn-ghost:hover:not(:disabled) {
  background: var(--surface2);
  color: var(--text);
}
.btn-danger {
  background: var(--danger);
  color: #fff;
}
.btn-danger:hover:not(:disabled) {
  background: var(--danger-hover);
}
.btn-sm {
  padding: 0.35em 0.9em;
  font-size: 0.82rem;
}
.btn-lg {
  padding: 0.75em 1.8em;
  font-size: 1rem;
}

/* Cards & surfaces */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
}

/* Login */
.login-wrap {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding-top: 6rem;
}
.login-card {
  width: 100%;
  max-width: 360px;
}
.login-card h1 {
  font-size: 1.5rem;
  margin-bottom: 0.25rem;
  color: var(--accent);
}
.login-card p {
  color: var(--text-muted);
  margin-bottom: 1.5rem;
  font-size: 0.9rem;
}
.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 1rem;
}
.form-group label {
  font-size: 0.85rem;
  color: var(--text-muted);
}
.form-group input,
.form-group select,
.form-group textarea {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) - 2px);
  color: var(--text);
  padding: 0.6em 0.85em;
  font-size: 0.95rem;
  font-family: inherit;
  width: 100%;
  transition: border-color 0.15s;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--accent);
}
.form-group textarea {
  resize: vertical;
  min-height: 80px;
}
.error-msg {
  color: #e74c3c;
  font-size: 0.85rem;
  margin-top: 0.5rem;
}

/* List header */
.list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.list-header h1 {
  font-size: 1.4rem;
}
.list-header-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}

/* Filter bar */
.filter-bar {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
}
.filter-bar-row {
  display: flex;
  gap: 0.6rem;
  align-items: center;
}
.filter-panel {
  display: none;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 0.5rem;
  padding: 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.filter-panel.open {
  display: grid;
}
.search-input {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 0.55em 0.9em;
  font-size: 0.9rem;
  font-family: inherit;
  flex: 1;
  min-width: 160px;
  max-width: 280px;
}
.search-input:focus {
  outline: none;
  border-color: var(--accent);
}
.filter-select {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 0.5em 0.75em;
  font-size: 0.85rem;
  font-family: inherit;
  cursor: pointer;
}
.filter-select:focus {
  outline: none;
  border-color: var(--accent);
}
.filter-select-active {
  border-color: var(--accent);
  background: rgba(201, 130, 44, 0.08);
  color: var(--text);
}

/* Table */
.bourbon-table-wrap {
  overflow-x: auto;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
thead th {
  text-align: left;
  padding: 0.6rem 0.85rem;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  user-select: none;
  cursor: pointer;
}
thead th:hover {
  color: var(--text);
}
.th-sorted {
  color: var(--accent) !important;
}
tbody tr {
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.1s;
}
tbody tr:hover {
  background: var(--surface2);
}
tbody td {
  padding: 0.75rem 0.85rem;
  vertical-align: middle;
}
.row-selected {
  background: rgba(192, 57, 43, 0.1) !important;
  box-shadow: inset 3px 0 0 var(--danger);
}
.td-muted {
  color: var(--text-muted);
  font-size: 0.85rem;
}
.empty-state {
  text-align: center;
  padding: 4rem 1rem;
  color: var(--text-muted);
}
.empty-state p {
  margin-bottom: 1.5rem;
  font-size: 1.05rem;
}

/* Rating */
.rating-value {
  color: var(--accent);
  font-weight: 600;
  font-size: 0.85rem;
}

/* Bulk action bar */
.bulk-bar {
  overflow: hidden;
  max-height: 0;
  transition:
    max-height 0.2s ease,
    margin 0.2s ease;
  margin-bottom: 0;
}
.bulk-bar-active {
  max-height: 60px;
  margin-bottom: 0.75rem;
}
.bulk-bar-inner {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 0.9rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  flex-wrap: wrap;
}
.bulk-count {
  font-size: 0.85rem;
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}

/* Column picker */
.col-picker-wrap {
  position: relative;
}
.col-picker-drop {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem 0;
  z-index: 200;
  min-width: 160px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}
.col-picker-drop.open {
  display: block;
}
.col-picker-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.9rem;
  font-size: 0.85rem;
  cursor: pointer;
  user-select: none;
}
.col-picker-item:hover {
  background: var(--surface2);
}
.col-picker-item input[type='checkbox'] {
  accent-color: var(--accent);
  cursor: pointer;
}

/* Form */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0 1rem;
}
.form-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 1.5rem;
}
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.3em;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.88rem;
  margin-bottom: 1.25rem;
}
.back-link:hover {
  color: var(--text);
}

/* Spinner */
.spinner {
  text-align: center;
  padding: 3rem;
  color: var(--text-muted);
}

/* Toast */
#toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1.25rem;
  font-size: 0.9rem;
  z-index: 999;
  opacity: 0;
  transform: translateY(8px);
  transition:
    opacity 0.2s,
    transform 0.2s;
  pointer-events: none;
  max-width: 320px;
}
#toast.show {
  opacity: 1;
  transform: translateY(0);
}
#toast.toast-error {
  border-color: var(--danger);
  color: #e74c3c;
}

/* ── Stats page ────────────────────────────────────────────────────────────── */
.stats-header {
  margin-bottom: 1.5rem;
}
.stats-header h1 {
  font-size: 1.4rem;
}
.stats-summary {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.stats-stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  text-align: center;
}
.stats-stat-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--accent);
  line-height: 1;
  margin-bottom: 0.4rem;
}
.stats-stat-label {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}
.stats-chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.5rem;
}
.stats-chart-wrap {
  position: relative;
  height: 220px;
}
.stats-rankings {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.stats-ranking-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  min-width: 0;
  overflow: hidden;
}
.stats-card-title {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 1rem;
  font-weight: 600;
}
.stats-ranking-list {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.stats-ranking-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.stats-rank {
  font-size: 0.75rem;
  color: var(--text-muted);
  width: 1.5rem;
  flex-shrink: 0;
  text-align: right;
}
.stats-ranking-bar-wrap {
  flex: 1;
  min-width: 0;
}
.stats-ranking-label-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.5rem;
  margin-bottom: 0.25rem;
}
.stats-ranking-name {
  font-size: 0.88rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.stats-ranking-count {
  font-size: 0.78rem;
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}
.stats-bar-track {
  height: 4px;
  background: var(--surface2);
  border-radius: 2px;
  overflow: hidden;
}
.stats-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.4s ease;
  min-width: 2px;
}

/* ── Mobile ─────────────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  main {
    padding: 1rem;
  }
  .header-inner {
    padding: 0 0.75rem;
  }
  .logo {
    font-size: 1rem;
    margin-right: 0.2rem;
  }
  .logo-sub {
    display: none;
  }
  .nav-link {
    padding: 0 0.45rem;
    font-size: 0.82rem;
  }
  #nav {
    gap: 0.35rem;
  }
  #btn-add-nav .btn-text,
  #btn-logout .btn-text {
    display: none;
  }
  #nav .btn-sm {
    padding: 0.35em 0.6em;
  }
  .search-input {
    max-width: 100%;
    flex: 1;
  }
  .filter-panel {
    grid-template-columns: repeat(2, 1fr);
  }
  .col-picker-wrap {
    display: none;
  }
  tbody td,
  thead th {
    padding-left: 0.6rem;
    padding-right: 0.6rem;
  }
  .list-header h1,
  .stats-header h1 {
    font-size: 1.2rem;
  }
  #toast {
    left: 1rem;
    right: 1rem;
    bottom: 1rem;
    max-width: none;
  }
  .stats-summary {
    grid-template-columns: repeat(2, 1fr);
  }
  .stats-rankings {
    grid-template-columns: 1fr;
  }
  .stats-stat-value {
    font-size: 1.5rem;
  }
}
