/* ============================================================
   CSS VARIABLES
   ============================================================ */
:root {
  --bg:        #121212;
  --surface:   #1c1c1c;
  --surface2:  #242424;
  --surface3:  #2e2e2e;
  --accent:    #f5c518;
  --accent-dim:#c9a215;
  --text:      #ffffff;
  --text2:     #a8a8a8;
  --text3:     #666666;
  --border:    #2e2e2e;
  --red:       #e53935;
  --topbar-h:  54px;
  --drawer-w:  280px;
  --radius:    8px;
  --radius-sm: 4px;
}

/* ============================================================
   RESET & BASE
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding-top: var(--topbar-h);
}
a { color: inherit; text-decoration: none; }
img { display: block; max-width: 100%; }
button { font: inherit; cursor: pointer; border: none; background: none; }
ul { list-style: none; }

/* ============================================================
   LOADING SCREEN
   ============================================================ */
.loading-screen {
  position: fixed; inset: 0; z-index: 1000;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  transition: opacity .3s;
}
.loading-screen.hidden { opacity: 0; pointer-events: none; }
.loading-inner { text-align: center; }
.loading-logo {
  font-size: 2rem; font-weight: 800; letter-spacing: .1em;
  margin-bottom: 2rem;
}
.loading-spinner {
  width: 40px; height: 40px;
  border: 3px solid var(--surface3);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
  margin: 0 auto 1rem;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { color: var(--text2); font-size: .9rem; }

/* ============================================================
   TOPBAR
   ============================================================ */
.topbar {
  position: fixed; top: 0; left: 0; right: 0;
  height: var(--topbar-h); z-index: 200;
  background: #0a0a0a;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  padding: 0 8px;
  gap: 8px;
}
.topbar-title {
  flex: 1; text-align: center;
  font-size: 1rem; font-weight: 700; letter-spacing: .02em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  padding: 0 4px;
}
.topbar-action { min-width: 40px; display: flex; justify-content: flex-end; }

/* ============================================================
   ICON BUTTON
   ============================================================ */
.icon-btn {
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm); color: var(--text);
  flex-shrink: 0;
  transition: background .15s;
}
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn:hover { background: var(--surface2); }

/* ============================================================
   DRAWER OVERLAY
   ============================================================ */
.drawer-overlay {
  position: fixed; inset: 0; z-index: 299;
  background: rgba(0,0,0,.7);
  opacity: 0; pointer-events: none;
  transition: opacity .25s;
}
.drawer-overlay.visible { opacity: 1; pointer-events: all; }

/* ============================================================
   DRAWER
   ============================================================ */
.drawer {
  position: fixed; top: 0; left: 0; bottom: 0;
  width: var(--drawer-w); z-index: 300;
  background: #0f0f0f;
  border-right: 1px solid var(--border);
  transform: translateX(-100%);
  transition: transform .25s ease;
  display: flex; flex-direction: column;
  overflow-y: auto;
}
.drawer.open { transform: translateX(0); }
.drawer-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.drawer-logo { font-size: 1.1rem; font-weight: 800; letter-spacing: .1em; }
.drawer-nav { padding: 8px 0; flex: 1; }
.drawer-nav li { }
.drawer-sep { height: 1px; background: var(--border); margin: 6px 12px; }
.drawer-link {
  display: block; padding: 11px 20px;
  color: var(--text2); font-size: .95rem;
  transition: color .15s, background .15s;
  border-left: 3px solid transparent;
}
.drawer-link:hover { color: var(--text); background: var(--surface); }
.drawer-link.active { color: var(--accent); border-left-color: var(--accent); }

/* ============================================================
   MAIN CONTENT
   ============================================================ */
.main-content {
  max-width: 1400px;
  margin: 0 auto;
  padding: 16px;
}
@media (min-width: 768px) { .main-content { padding: 24px; } }

/* ============================================================
   ACCENT
   ============================================================ */
.accent { color: var(--accent); }

/* ============================================================
   SECTIONS
   ============================================================ */
.section { margin-bottom: 32px; }
.section-title {
  font-size: 1rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .06em;
  color: var(--text2); margin-bottom: 14px;
  padding-bottom: 8px; border-bottom: 1px solid var(--border);
}

/* ============================================================
   STAT CARDS (Home)
   ============================================================ */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 32px;
}
@media (min-width: 640px) { .stat-grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 960px) { .stat-grid { grid-template-columns: repeat(6, 1fr); } }
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 12px;
  text-align: center;
}
.stat-value {
  font-size: 1.8rem; font-weight: 800;
  line-height: 1; margin-bottom: 6px;
}
.stat-label { font-size: .78rem; color: var(--text2); text-transform: uppercase; letter-spacing: .05em; }

/* ============================================================
   CHART WRAPPERS
   ============================================================ */
.chart-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.chart-wrap--bar  { height: 220px; }
.chart-wrap--hbar { height: 320px; }
.chart-wrap--tall { height: 300px; }
@media (min-width: 768px) {
  .chart-wrap--bar  { height: 260px; }
  .chart-wrap--hbar { height: 360px; }
  .chart-wrap--tall { height: 380px; }
}

/* ============================================================
   POSTER GRID & CARDS
   ============================================================ */
.poster-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 12px;
}
@media (min-width: 480px)  { .poster-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); } }
@media (min-width: 768px)  { .poster-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 16px; } }
@media (min-width: 1024px) { .poster-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); } }

.movie-card {
  display: block;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface);
  transition: transform .2s, box-shadow .2s;
  cursor: pointer;
}
.movie-card:hover { transform: translateY(-4px); box-shadow: 0 8px 24px rgba(0,0,0,.5); }

.card-poster {
  position: relative;
  aspect-ratio: 2/3;
  background: var(--surface2);
  overflow: hidden;
}
.card-poster-img {
  width: 100%; height: 100%;
  object-fit: cover;
  transition: opacity .3s;
}
.card-poster-placeholder {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface3);
  color: var(--text3); font-size: 1.4rem; font-weight: 700;
}
.card-rating {
  position: absolute; top: 6px; right: 6px;
  background: var(--accent); color: #000;
  font-size: .75rem; font-weight: 800;
  padding: 2px 6px; border-radius: 3px;
  line-height: 1.4;
}
.media-tag {
  position: absolute; top: 6px; left: 6px;
  font-size: .65rem; font-weight: 700;
  padding: 2px 5px; border-radius: 3px;
  line-height: 1.4; text-transform: uppercase;
}
.media-tag--tv         { background: #1565c0; color: #fff; }
.media-tag--tv_episode { background: #6a1b9a; color: #fff; }

.card-info { padding: 8px; }
.card-title {
  font-size: .82rem; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  margin-bottom: 3px;
}
.card-meta { font-size: .75rem; color: var(--text2); }

/* ============================================================
   LIST CONTROLS (Movies view)
   ============================================================ */
.view-list { display: flex; flex-direction: column; gap: 14px; }
.list-controls { display: flex; flex-direction: column; gap: 10px; }

.search-wrap { position: relative; }
.search-input {
  width: 100%; padding: 10px 14px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text);
  font: inherit; font-size: .95rem;
  outline: none; transition: border-color .15s;
}
.search-input:focus { border-color: var(--accent); }
.search-input::placeholder { color: var(--text3); }

.filter-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: .82rem; font-weight: 500;
  color: var(--text2);
  background: var(--surface);
  transition: all .15s; cursor: pointer; white-space: nowrap;
}
.chip:hover  { border-color: var(--text2); color: var(--text); }
.chip.active { background: var(--accent); border-color: var(--accent); color: #000; font-weight: 700; }

.sort-wrap { display: flex; align-items: center; gap: 8px; }
.sort-select {
  padding: 7px 10px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text);
  font: inherit; font-size: .85rem; cursor: pointer; outline: none;
}

.result-count { font-size: .82rem; color: var(--text3); }

/* ============================================================
   PEOPLE LIST
   ============================================================ */
.people-list { display: flex; flex-direction: column; }
.people-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  transition: background .15s;
  gap: 8px;
}
.people-row:first-child { border-top: 1px solid var(--border); }
.people-row:hover { background: var(--surface); }

.people-rank { font-size: .8rem; color: var(--text3); min-width: 22px; flex-shrink: 0; text-align: right; }
/* Used for rows without an avatar (genres, countries, timeline, episodes, failed) */
.people-rank-col { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }
/* Used for rows with an avatar (people leaderboards) — name + stats stacked */
.people-row-content { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.people-avatar {
  width: 36px; height: 36px;
  border-radius: 50%; object-fit: cover;
  flex-shrink: 0; background: var(--surface3);
}
.people-avatar--placeholder {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--surface3);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: .9rem; color: var(--text2);
  flex-shrink: 0;
}
.people-name {
  font-size: .92rem; font-weight: 500;
  line-height: 1.3;
}
.people-stats-col { display: flex; align-items: center; justify-content: space-between; gap: 8px; width: 100%; }
.people-stats-left  { display: flex; align-items: center; gap: 8px; }
.people-stats-right { display: flex; align-items: center; gap: 5px; }
.people-count { font-size: .8rem; color: var(--text2); white-space: nowrap; }
.people-time  { font-size: .78rem; color: var(--text3); white-space: nowrap; }

/* ============================================================
   RATING BADGE & TAGS
   ============================================================ */
.rating-badge {
  background: var(--accent); color: #000;
  font-size: .75rem; font-weight: 800;
  padding: 2px 7px; border-radius: 3px;
  line-height: 1.5; flex-shrink: 0;
}
.rating-none { color: var(--text3); }

.tag {
  display: inline-block;
  padding: 3px 8px;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 4px; font-size: .75rem; color: var(--text2);
  transition: border-color .15s, color .15s;
  white-space: nowrap;
}
a.tag:hover { border-color: var(--accent); color: var(--accent); }
.tag--external { cursor: pointer; }

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  display: inline-block; padding: 8px 18px;
  border-radius: var(--radius-sm); font: inherit; font-size: .88rem;
  font-weight: 600; cursor: pointer; transition: all .15s;
}
.btn--outline {
  border: 1px solid var(--border); color: var(--text2); background: none;
}
.btn--outline:hover { border-color: var(--text); color: var(--text); }

/* ============================================================
   DETAIL PAGE
   ============================================================ */
.view-detail { }

.detail-backdrop {
  width: 100%; height: 200px;
  background-size: cover; background-position: center top;
  margin: -16px -16px 0;
  width: calc(100% + 32px);
  position: relative;
}
.detail-backdrop::after {
  content: '';
  position: absolute; inset: 0;
  background: linear-gradient(to bottom, rgba(18,18,18,0) 30%, var(--bg) 100%);
}
@media (min-width: 768px) {
  .detail-backdrop { height: 280px; margin: -24px -24px 0; width: calc(100% + 48px); }
}

.detail-body { padding-top: 16px; }

.detail-main {
  display: flex; gap: 20px;
  margin-bottom: 24px;
  align-items: flex-start;
}
.detail-poster-wrap { flex-shrink: 0; }
.detail-poster {
  width: 110px; border-radius: var(--radius-sm);
  box-shadow: 0 4px 20px rgba(0,0,0,.6);
}
.detail-poster--placeholder {
  width: 110px; aspect-ratio: 2/3;
  background: var(--surface2); border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.5rem; font-weight: 700; color: var(--text3);
}
@media (min-width: 480px) { .detail-poster { width: 140px; } .detail-poster--placeholder { width: 140px; } }
@media (min-width: 768px) { .detail-poster { width: 180px; } .detail-poster--placeholder { width: 180px; } }

.detail-info { flex: 1; min-width: 0; }
.detail-title { font-size: 1.3rem; font-weight: 800; line-height: 1.2; margin-bottom: 6px; }
@media (min-width: 480px) { .detail-title { font-size: 1.6rem; } }
.detail-original-title { font-size: .9rem; color: var(--text2); margin-bottom: 6px; }
.detail-tagline { font-size: .88rem; color: var(--text3); font-style: italic; margin-bottom: 10px; }
.detail-meta-row {
  display: flex; flex-wrap: wrap; gap: 8px;
  font-size: .83rem; color: var(--text2); margin-bottom: 10px;
}
.detail-meta-row span { display: flex; align-items: center; }
.lang-badge {
  background: var(--surface3); padding: 1px 6px;
  border-radius: 3px; font-size: .72rem; font-weight: 700;
}
.detail-genres { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }

.detail-ratings { display: flex; gap: 20px; margin-bottom: 12px; }
.rating-block { }
.rating-value { font-size: 1.6rem; font-weight: 800; line-height: 1; }
.rating-label { font-size: .72rem; color: var(--text3); margin-top: 3px; }

.detail-financial { font-size: .82rem; color: var(--text2); display: flex; gap: 16px; }

.detail-section { margin-bottom: 28px; }
.detail-section-title {
  font-size: .88rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .06em;
  color: var(--text2); margin-bottom: 12px;
  padding-bottom: 8px; border-bottom: 1px solid var(--border);
}
.detail-overview { font-size: .92rem; line-height: 1.65; color: var(--text2); }

.detail-crew { display: flex; flex-direction: column; gap: 8px; }
.detail-crew-group { font-size: .88rem; display: flex; flex-wrap: wrap; gap: 4px; align-items: baseline; }
.crew-label { color: var(--text3); min-width: 110px; flex-shrink: 0; font-size: .82rem; }
.crew-names { display: flex; flex-wrap: wrap; gap: 6px; }
.crew-link { color: var(--text); transition: color .15s; }
.crew-link:hover { color: var(--accent); }
.crew-jobs { color: var(--text3); font-size: .78rem; }

.detail-links { display: flex; gap: 10px; flex-wrap: wrap; padding-top: 8px; }

/* ============================================================
   CAST GRID
   ============================================================ */
.cast-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  gap: 12px;
}
.cast-item {
  display: flex; flex-direction: column; align-items: center;
  text-align: center; gap: 5px;
  padding: 8px 4px;
  border-radius: var(--radius-sm);
  transition: background .15s;
}
.cast-item:hover { background: var(--surface); }
.cast-avatar {
  width: 56px; height: 56px; border-radius: 50%;
  object-fit: cover; background: var(--surface3);
}
.cast-avatar--placeholder {
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--surface3);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.2rem; font-weight: 700; color: var(--text2);
}
.cast-name    { font-size: .75rem; font-weight: 600; line-height: 1.2; }
.cast-character { font-size: .7rem; color: var(--text3); line-height: 1.2; }

/* ============================================================
   PERSON DETAIL
   ============================================================ */
.person-header {
  display: flex; gap: 20px; align-items: flex-start;
  margin-bottom: 24px;
}
.person-photo {
  width: 100px; height: 100px; border-radius: 50%;
  object-fit: cover; flex-shrink: 0;
  box-shadow: 0 4px 20px rgba(0,0,0,.5);
}
.person-photo--placeholder {
  width: 100px; height: 100px; border-radius: 50%;
  background: var(--surface3); flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 2rem; font-weight: 700; color: var(--text2);
}
.person-header-info { flex: 1; min-width: 0; }
.person-role-badges { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 12px; }

/* ============================================================
   GENRE / COUNTRY / DECADE HEADER
   ============================================================ */
.genre-header { margin-bottom: 20px; }
.genre-header .detail-title { margin-bottom: 12px; }

/* ============================================================
   VIEW HOME
   ============================================================ */
.view-home { }

/* ============================================================
   MUTED TEXT
   ============================================================ */
.muted-text { color: var(--text2); font-size: .9rem; margin-bottom: 12px; }

/* ============================================================
   SCROLLBAR
   ============================================================ */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--surface3); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text3); }

.show-more-btn {
  display: block; width: 100%;
  padding: 12px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text2);
  font: inherit; font-size: .88rem; cursor: pointer;
  transition: border-color .15s, color .15s;
  margin-top: 8px;
}
.show-more-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ============================================================
   PAGINATION
   ============================================================ */
.pagination {
  display: flex; align-items: center; justify-content: center;
  gap: 12px; padding: 16px 0;
}
.page-btn {
  padding: 8px 16px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text2);
  font: inherit; font-size: .88rem; cursor: pointer;
  transition: border-color .15s, color .15s;
}
.page-btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.page-btn:disabled { opacity: .35; cursor: default; }
.page-indicator { font-size: .88rem; color: var(--text2); }

/* ============================================================
   WATCHLIST — LIST VIEW
   ============================================================ */
.list-row {
  display: block;
  padding: 10px 14px;
  background: var(--surface2);
  border-radius: var(--radius-sm);
  margin-bottom: 4px;
  transition: background .15s;
}
.list-row:hover { background: var(--surface3); }
.list-title-line { display: flex; align-items: center; flex-wrap: wrap; gap: 5px; margin-bottom: 4px; }
.list-title { font-size: .92rem; font-weight: 600; }
.list-original { font-size: .8rem; color: var(--text3); }
.list-meta { font-size: .78rem; color: var(--text2); }

/* ============================================================
   WATCHLIST — SUBFILTER ROW & SORT ROW
   ============================================================ */
.subfilter-row {
  display: flex; flex-wrap: wrap; gap: 8px;
}
.sort-row {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.topbar-action { display: flex; align-items: center; gap: 2px; }

.view-toggle-btn {
  padding: 5px 10px;
  border: 1px solid var(--text3);
  border-radius: var(--radius-sm);
  color: var(--text); background: none;
  font: inherit; font-size: .78rem; font-weight: 600;
  cursor: pointer; transition: border-color .15s, color .15s;
  white-space: nowrap;
}
.view-toggle-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ============================================================
   STAT CARD SUBLABEL
   ============================================================ */
.stat-sublabel {
  font-size: .72rem;
  color: var(--text3);
  margin-top: 4px;
}

/* Chart.js handles cursor changes on hover automatically */

/* ============================================================
   WATCHLIST — SEARCH/VIEW ROW & FILTER DROPDOWN
   ============================================================ */
.search-view-row {
  display: flex; gap: 8px; align-items: center;
}
.search-view-row .search-input { flex: 1; }

.filter-drop-wrap { position: relative; }
.filter-drop-btn {
  cursor: pointer; white-space: nowrap;
  background: var(--surface); color: var(--text);
}
.filter-drop-menu {
  display: none;
  position: absolute; top: calc(100% + 4px); left: 0;
  min-width: 160px; z-index: 50;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  box-shadow: 0 4px 16px rgba(0,0,0,.4);
}
.filter-drop-menu.open { display: block; }
.subfilter-panel.open  { display: flex; } /* override: panel uses flex column */
.filter-option {
  display: block; width: 100%;
  padding: 10px 14px; text-align: left;
  background: none; border: none;
  color: var(--text2); font: inherit; font-size: .88rem;
  cursor: pointer; transition: background .15s;
}
.filter-option:hover  { background: var(--surface3); color: var(--text); }
.filter-option.active { color: var(--accent); font-weight: 700; }

/* ============================================================
   DUAL RATING (you / tmdb) — inline two-tone pill
   ============================================================ */
.dual-rating {
  display: inline-flex; align-items: center;
  border-radius: 3px; overflow: hidden;
  font-size: .75rem; font-weight: 700;
  flex-shrink: 0;
}
.rating-lbl {
  padding: 3px 4px;
  font-size: .58rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: .03em;
  line-height: 1; align-self: stretch;
  display: flex; align-items: center;
}
.rating-num {
  padding: 3px 5px;
  line-height: 1;
  display: flex; align-items: center;
}
.dual-rating--you { background: var(--accent); color: #000; }
.dual-rating--you .rating-lbl { background: rgba(0,0,0,.18); }
.dual-rating--tmdb { background: var(--surface3); color: var(--text2); }
.dual-rating--tmdb .rating-lbl { background: var(--surface2); color: var(--text3); }

.sort-dir-btn {
  padding: 7px 10px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text2);
  font: inherit; font-size: .9rem; cursor: pointer;
  transition: border-color .15s, color .15s;
  flex-shrink: 0; line-height: 1;
}
.sort-dir-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ============================================================
   WATCHLIST CONTROLS ROW
   ============================================================ */
.wl-controls-row {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.wl-btn {
  padding: 7px 11px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text);
  font: inherit; font-size: .85rem; cursor: pointer;
  transition: border-color .15s; white-space: nowrap;
}
.wl-btn:hover { border-color: var(--text2); }
.wl-btn--active { border-color: var(--accent); color: var(--accent); }

/* Sub-filters panel */
.subfilter-panel {
  display: none;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  margin-top: 4px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  /* No absolute positioning — sits as a full-width block in the flow */
}
.subfilter-panel.open { display: flex; }
.subfilter-row-item {
  display: flex; align-items: center; gap: 10px;
}
.subfilter-lbl {
  font-size: .8rem; color: var(--text2);
  min-width: 72px; flex-shrink: 0;
}
.subfilter-row-item .sort-select { flex: 1; }
.subfilter-clear {
  display: block; width: 100%;
  padding: 7px; margin-top: 2px;
  background: none; border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text3);
  font: inherit; font-size: .82rem; cursor: pointer;
  transition: border-color .15s, color .15s;
}
.subfilter-clear:hover { border-color: var(--accent); color: var(--accent); }

/* Sort menu and subfilter panel: right-align so they don't overflow on narrow screens */
#sortMenu { left: auto; right: 0; }

/* ============================================================
   SCROLLABLE CHART (e.g. By Year on mobile)
   ============================================================ */
.chart-scroll-outer {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.chart-scroll-inner {
  height: 260px;
  padding: 16px;
}

.charts-toggle {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 14px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text2);
  font: inherit; font-size: .88rem; cursor: pointer;
  transition: border-color .15s, color .15s;
}
.charts-toggle:hover { border-color: var(--text2); color: var(--text); }

/* ============================================================
   HTML BAR CHART (Countries)
   ============================================================ */
.hbar-chart {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-top: 8px;
  display: flex; flex-direction: column; gap: 8px;
}
.hbar-item {
  display: block; text-decoration: none;
  padding: 4px 0;
  transition: opacity .15s;
}
.hbar-item:hover { opacity: .8; }
.hbar-name {
  display: block;
  font-size: .82rem; color: var(--text2);
  margin-bottom: 4px; line-height: 1.3;
}
.hbar-row {
  display: flex; align-items: center; gap: 8px;
}
.hbar-track {
  flex: 1; height: 8px;
  background: var(--surface3);
  border-radius: 4px; overflow: hidden;
}
.hbar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 4px;
  transition: width .4s ease;
}
.hbar-count {
  font-size: .75rem; color: var(--text3);
  min-width: 28px; text-align: right;
  white-space: nowrap;
}

.hbar-pct { color: var(--text3); font-size: .72rem; }

.hbar-pct-line {
  display: block;
  font-size: .72rem; color: var(--text3);
  margin-top: 2px;
}
