/* ── Design tokens — dark (default) ─────────────────────────────────────────── */
:root {
  --bg:           #0d0e12;
  --bg-surface:   #161820;
  --bg-elevated:  #1e2029;
  --bg-hover:     #252836;
  --border:       rgba(255,255,255,.07);
  --border-acc:   rgba(245,197,24,.25);

  --gold:         #f5c518;
  --gold-dim:     #c9a400;
  --gold-glow:    rgba(245,197,24,.15);
  --text:         #e8e8e8;
  --text-dim:     #a2a8c2;
  --text-muted:   #797e9e;
  --up:           #4caf7d;
  --down:         #e05252;
  --new:          #7b9fff;

  --header-top:   #13141a;
  --header-shadow:rgba(0,0,0,.6);
  --logo-sub:     #a2a8c2;

  --header-h:    64px;
  --sidebar-w:   185px;
  --radius:      6px;
  --font-sans:   'Open Sans', system-ui, sans-serif;
  --font-display:'Oswald', 'Open Sans', sans-serif;
}

/* ── Design tokens — light ───────────────────────────────────────────────────── */
[data-theme="light"] {
  --bg:           #f0f1f5;
  --bg-surface:   #ffffff;
  --bg-elevated:  #e6e8ef;
  --bg-hover:     #dcdfe8;
  --border:       rgba(0,0,0,.09);
  --border-acc:   rgba(160,120,0,.28);

  --gold:         #a87c00;
  --gold-dim:     #866300;
  --gold-glow:    rgba(168,124,0,.10);
  --text:         #1a1c26;
  --text-dim:     #4a5070;
  --text-muted:   #7a80a0;
  --up:           #1e6e40;
  --down:         #b83232;
  --new:          #2246b0;

  --header-top:   #ffffff;
  --header-shadow:rgba(0,0,0,.10);
  --logo-sub:     #4a5070;
}

/* ── Reset ──────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

html {
  scroll-behavior: smooth;
  /* Smooth colour transition when switching themes */
  transition: background-color .25s, color .25s;
}

/* Prevent transition flash on page load */
html.no-transition, html.no-transition * { transition: none !important; }

body {
  font-family: var(--font-sans);
  font-size: 13px;
  background-color: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  /* Extremely subtle film-grain texture via CSS */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='300'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.75' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='300' height='300' filter='url(%23n)' opacity='0.03'/%3E%3C/svg%3E");
}

a { color: var(--gold); text-decoration: none; }
a:hover { color: #fff; text-decoration: none; }

/* ── Header ─────────────────────────────────────────────────────────────────── */
#header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-h);
  background: linear-gradient(180deg, var(--header-top) 0%, var(--bg) 100%);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 4px 24px var(--header-shadow);
}

.header-inner {
  max-width: 1100px;
  margin: 0 auto;
  height: 100%;
  padding: 0 20px;
  display: flex;
  align-items: center;
  gap: 20px;
}

/* Logo */
.logo a { display: flex; flex-direction: column; gap: 0; text-decoration: none; }
.logo-imdb {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 13px;
  letter-spacing: 3px;
  color: var(--logo-sub);
  text-transform: uppercase;
  line-height: 1;
}
.logo-history {
  font-family: var(--font-display);
  font-weight: 300;
  font-size: 26px;
  letter-spacing: 4px;
  color: var(--gold);
  text-transform: uppercase;
  line-height: 1;
}

/* Search */
.search-form {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  max-width: 340px;
}
.search-form input {
  flex: 1;
  height: 32px;
  font-size: 13px;
  padding: 0 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  outline: none;
  transition: border-color .2s;
}
.search-form input:focus { border-color: var(--gold); }
.search-form input::placeholder { color: var(--text-muted); }
.search-form button {
  height: 32px;
  width: 32px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color .2s, color .2s;
}
.search-form button:hover { border-color: var(--gold); color: var(--gold); }

/* Nav */
.main-nav {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 14px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 2px;
  white-space: nowrap;
}
.main-nav a {
  color: var(--text-dim);
  padding: 4px 10px;
  border-radius: 4px;
  transition: color .2s, background .2s;
}
.main-nav a:hover { color: var(--text); background: var(--bg-elevated); }
.main-nav .sep { color: var(--text-muted); padding: 0 2px; }

.nav-dropdown { position: relative; }
.nav-dropdown-menu {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px 0;
  min-width: 180px;
  z-index: 200;
  box-shadow: 0 8px 24px var(--header-shadow);
}
.nav-dropdown:hover .nav-dropdown-menu { display: block; }
.nav-dropdown-menu a {
  display: block;
  padding: 7px 14px;
  font-size: 12px;
  color: var(--text-dim);
  letter-spacing: 0.5px;
  white-space: nowrap;
}
.nav-dropdown-menu a:hover { background: var(--bg-hover); color: var(--gold); }

/* Header action buttons */
.header-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.update-form button {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-dim);
  font-size: 12px;
  font-family: var(--font-sans);
  padding: 5px 12px;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color .2s, color .2s;
}
.update-form button:hover { border-color: var(--gold); color: var(--gold); }

#theme-toggle {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 15px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: border-color .2s, color .2s;
  flex-shrink: 0;
}
#theme-toggle:hover { border-color: var(--gold); color: var(--gold); }

/* ── Flash messages ──────────────────────────────────────────────────────────── */
.flash-container { max-width: 1100px; margin: 12px auto 0; padding: 0 20px; }
.flash {
  padding: 10px 16px;
  border-radius: var(--radius);
  margin-bottom: 6px;
  font-size: 13px;
}
.flash-success { background: rgba(76,175,125,.15); border: 1px solid rgba(76,175,125,.3); color: #6fcf97; }
.flash-error   { background: rgba(224,82,82,.15);  border: 1px solid rgba(224,82,82,.3);  color: #eb5757; }

/* ── Page body ───────────────────────────────────────────────────────────────── */
#page-body {
  max-width: 1100px;
  margin: 20px auto;
  padding: 0 20px;
}

.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr var(--sidebar-w);
  gap: 16px;
  align-items: start;
}

/* ── Sidebars ────────────────────────────────────────────────────────────────── */
.sidebar-left,
.sidebar-right {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.poster-wrap {
  text-align: center;
  margin-bottom: 12px;
}
.poster-img {
  width: 100%;
  max-width: 182px;
  border-radius: var(--radius);
  display: block;
  margin: 0 auto;
  border: 1px solid var(--border);
}

.sidebar-section {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
}

.sidebar-section h3 {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 13px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--gold);
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-acc);
}

.sidebar-sub {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin: 10px 0 4px;
}

.stats-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.stats-table tr + tr td,
.stats-table tr + tr th {
  border-top: 1px solid var(--border);
}
.stats-table th {
  text-align: left;
  padding: 4px 6px 4px 0;
  color: var(--text-dim);
  font-weight: 400;
}
.stats-table td {
  text-align: right;
  padding: 4px 0 4px 6px;
  color: var(--text);
  white-space: nowrap;
}
.stats-table strong { color: var(--gold); }
.stats-table a { color: var(--text-dim); font-weight: 400; }
.stats-table a:hover { color: var(--gold); }

.no-stats {
  font-size: 12px;
  color: var(--text-muted);
  padding: 4px 0;
  font-style: italic;
}

.sidebar-more-btn {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 4px 0;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 11px;
  font-family: var(--font-sans);
  letter-spacing: 0.5px;
  cursor: pointer;
  text-align: center;
  transition: color .2s, border-color .2s;
}
.sidebar-more-btn:hover { color: var(--gold); border-color: var(--gold); }

/* ── Rank chart ─────────────────────────────────────────────────────────────── */
.rank-chart-wrap {
  padding: 16px 20px 8px;
  border-bottom: 1px solid var(--border);
}

.local-only-note {
  padding: 8px 20px;
  font-size: 12px;
  color: var(--text-muted);
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  font-style: italic;
}

/* ── Main content area ───────────────────────────────────────────────────────── */
.main-content {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  min-height: 500px;
}

/* ── Snapshot header ─────────────────────────────────────────────────────────── */
.snapshot-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(135deg, var(--bg-elevated) 0%, var(--bg-surface) 100%);
}

.snapshot-title {
  font-family: var(--font-display);
  font-weight: 300;
  font-size: 24px;
  color: var(--text);
  letter-spacing: 1px;
}
.snapshot-title .year {
  font-size: 16px;
  color: var(--text-dim);
  margin-left: 8px;
}

/* Date nav */
.date-nav { display: flex; gap: 6px; align-items: center; }
.date-nav-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-dim);
  font-size: 12px;
  cursor: pointer;
  transition: all .2s;
}
.date-nav-btn:hover {
  background: var(--gold);
  color: #000;
  border-color: var(--gold);
}
.date-nav-btn.disabled { opacity: .25; cursor: default; pointer-events: none; }

.imdb-link-large {
  font-size: 13px;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 4px;
}
.imdb-link-large:hover { color: var(--gold); }

.show-all-btn {
  display: block;
  margin: 10px auto 0;
  padding: 6px 18px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.85rem;
}
.show-all-btn:hover { border-color: var(--gold); color: var(--gold); }

/* ── Top 250 table ─────────────────────────────────────────────────────────── */
.top250-table {
  width: 100%;
  border-collapse: collapse;
}

.top250-table thead th {
  background: var(--bg-elevated);
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 2px;
  text-transform: uppercase;
  padding: 10px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}

.top250-table tbody td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.top250-table tbody tr { transition: background .15s; }
.top250-table tbody tr:hover { background: var(--bg-hover) !important; }
.top250-table tbody tr:last-child td { border-bottom: none; }

.row-norm { background: var(--bg-surface); }
.row-alt  { background: rgba(255,255,255,.02); }
.row-new  { background: rgba(123,159,255,.05); }

/* Column widths */
.col-rank   { width: 52px;  text-align: center; }
.col-change { width: 36px;  text-align: center; }
.col-rating { width: 64px;  text-align: center; }
.col-title  { }
.col-votes  { width: 100px; text-align: right; }
.col-links  { width: 56px;  text-align: center; }

.col-rank b {
  font-size: 13px;
  color: var(--text-dim);
  font-weight: 600;
}

.col-rating {
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 500;
  color: var(--gold);
  letter-spacing: 0.5px;
}
.rating-up   { color: var(--up)   !important; }
.rating-down { color: var(--down) !important; }

.col-title a {
  color: var(--text);
  font-weight: 600;
  font-size: 13px;
  transition: color .15s;
}
.col-title a:hover { color: var(--gold); }
.col-title .year {
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 400;
  margin-left: 6px;
}

.col-votes { color: var(--text-muted); font-size: 12px; }

/* Change indicators */
.change-up   { color: var(--up);   font-size: 11px; white-space: nowrap; }
.change-down { color: var(--down); font-size: 11px; white-space: nowrap; }
.change-same { color: var(--text-muted); font-size: 11px; }
.change-new  { color: var(--new);  font-size: 13px; }

/* IMDb link */
.imdb-link {
  display: inline-block;
  font-family: var(--font-display);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 1px;
  color: #000;
  background: var(--gold);
  padding: 2px 7px;
  border-radius: 3px;
  transition: background .2s;
}
.imdb-link:hover { background: var(--gold-dim); color: #000; }

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

/* ── History layout ─────────────────────────────────────────────────────────── */
.history-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  align-items: start;
}
.history-col {
  padding: 16px 20px;
}
.history-col + .history-col {
  border-left: 1px solid var(--border);
}
.history-section-title {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 14px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.history-note {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 14px;
  line-height: 1.6;
}
.history-note strong { color: var(--text-dim); }
.badge {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 11px;
  padding: 1px 8px;
  color: var(--gold);
  font-family: var(--font-sans);
  letter-spacing: 0;
  font-weight: 600;
}

/* Date fetch buttons */
.fetch-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-height: 600px;
  overflow-y: auto;
  padding-right: 4px;
}
.fetch-date-btn {
  font-size: 11px;
  font-family: var(--font-sans);
  padding: 4px 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-dim);
  cursor: pointer;
  transition: all .15s;
}
.fetch-date-btn:hover {
  background: var(--gold);
  color: #000;
  border-color: var(--gold);
}
.fetch-date-stored {
  border-color: var(--gold);
  color: var(--gold);
  background: var(--gold-glow);
}
.fetch-date-stored:hover {
  background: var(--gold);
  color: #000;
}

/* ── History table ──────────────────────────────────────────────────────────── */
.history-table {
  width: 100%;
  border-collapse: collapse;
}
.history-table thead th {
  background: var(--bg-elevated);
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 2px;
  text-transform: uppercase;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}
.history-table tbody td {
  padding: 9px 16px;
  border-bottom: 1px solid var(--border);
}
.history-table tbody tr:hover { background: var(--bg-hover); }
.history-table tbody tr:last-child td { border-bottom: none; }
.view-link { font-size: 12px; color: var(--text-muted); }
.view-link:hover { color: var(--gold); }

/* ── No data page ────────────────────────────────────────────────────────────── */
.no-data-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 400px;
  text-align: center;
  padding: 60px 40px;
}
.no-data-page h1 {
  font-family: var(--font-display);
  font-weight: 300;
  font-size: 32px;
  color: var(--text-dim);
  letter-spacing: 2px;
  margin-bottom: 16px;
}
.no-data-page p { color: var(--text-muted); margin-bottom: 32px; font-size: 14px; }
.btn-fetch {
  background: var(--gold);
  color: #000;
  border: none;
  border-radius: var(--radius);
  padding: 12px 28px;
  font-size: 14px;
  font-family: var(--font-display);
  font-weight: 500;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  cursor: pointer;
  transition: background .2s;
}
.btn-fetch:hover { background: var(--gold-dim); }

/* ── Section headings within main content ────────────────────────────────────── */
.section-heading {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 15px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--text-dim);
  padding: 14px 20px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
}
.section-heading:not(:first-child) { border-top: 2px solid var(--border-acc); }
.section-count {
  font-size: 12px;
  color: var(--text-muted);
  letter-spacing: 0;
  font-family: var(--font-sans);
}

.row-disappeared { background: rgba(224,82,82,.04); }

.full-list-toggle {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}
.full-list-toggle button {
  font-family: var(--font-display);
  font-size: 12px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-dim);
  padding: 7px 18px;
  cursor: pointer;
  transition: color .2s, border-color .2s;
}
.full-list-toggle button:hover { color: var(--gold); border-color: var(--gold); }

/* ── Row filter ──────────────────────────────────────────────────────────────── */
.row-filtered-out { opacity: 0.1; }

.sidebar-filter { color: var(--text-dim); font-weight: 400; }
.sidebar-filter:hover { color: var(--gold); }
.sidebar-filter.filter-active { color: var(--gold) !important; font-weight: 600; }

.filter-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 20px;
  background: var(--gold-glow);
  border-bottom: 1px solid var(--border-acc);
  font-size: 12px;
  color: var(--text-dim);
}
.filter-bar strong { color: var(--gold); }
#filter-clear {
  background: none;
  border: 1px solid var(--border-acc);
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 11px;
  padding: 2px 8px;
  cursor: pointer;
  transition: color .2s, border-color .2s;
}
#filter-clear:hover { color: var(--gold); border-color: var(--gold); }

/* ── Sources page ────────────────────────────────────────────────────────────── */
.sources-body {
  padding: 24px 28px;
  max-width: 740px;
}
.sources-section {
  margin-bottom: 36px;
}
.sources-section h2 {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 16px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--text);
  margin-bottom: 6px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-acc);
}
.sources-url {
  font-size: 12px;
  color: var(--gold);
  margin-bottom: 10px;
}
.sources-url a { color: var(--gold); }
.sources-offline { color: var(--text-muted); font-style: italic; }
.sources-section p {
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.7;
  margin-bottom: 10px;
}
.sources-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  margin: 10px 0;
}
.sources-table th {
  text-align: left;
  padding: 6px 10px;
  color: var(--text-muted);
  font-size: 10px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  border-bottom: 1px solid var(--border);
}
.sources-table td {
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
  color: var(--text-dim);
}
.sources-table td code {
  font-family: monospace;
  font-size: 12px;
  color: var(--gold-dim);
  background: var(--bg-elevated);
  padding: 1px 5px;
  border-radius: 3px;
}
.sources-note {
  font-size: 11px !important;
  color: var(--text-muted) !important;
  font-style: italic;
}

/* ── Footer ──────────────────────────────────────────────────────────────────── */
#footer {
  max-width: 1100px;
  margin: 32px auto 0;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 11px;
  text-align: center;
}
#footer p + p { margin-top: 4px; }
.footer-sub { font-size: 10px; }
#footer a { color: var(--gold); }
#footer a:hover { color: #fff; }

/* ── Responsive ──────────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
  }
  .sidebar-left,
  .sidebar-right {
    display: none;
  }
  .main-nav { display: none; }
}
