:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --wash: rgba(11, 11, 11, 0.05);
  --accent: #2a78d6;
  --s1: #2a78d6; /* Largometraje */
  --s2: #eb6834; /* Cortometraje */
  --co: #1baf7a; /* Colombian films (market section) */
  --us: #4a3aa7; /* US films */
  --ot: #c3c2b7; /* other countries: neutral, it is context */
  --mk: #6b6a64; /* whole market series */
  /* Map: one blue ramp, light -> dark = less -> more (ordinal; lightest step still clears 2:1). */
  --seq1: #86b6ef; --seq2: #5598e7; --seq3: #2a78d6; --seq4: #1c5cab; --seq5: #104281; --seq6: #0d366b;
  --nodata: #e7e6e1;
  --wash-strong: rgba(11, 11, 11, 0.14);
  --on-accent: #ffffff;
  --radius: 12px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --wash: rgba(255, 255, 255, 0.06);
    --accent: #3987e5;
    --s1: #3987e5;
    --s2: #d95926;
    --co: #199e70;
    --us: #9085e9;
    --ot: #4a4945;
    --mk: #a3a29a;
    /* Same direction as light mode (darker = more); the darkest step still clears 2:1 on the dark surface. */
    --seq1: #b7d3f6; --seq2: #86b6ef; --seq3: #5598e7; --seq4: #2a78d6; --seq5: #1c5cab; --seq6: #184f95;
    --nodata: #2c2c2a;
    --wash-strong: rgba(255, 255, 255, 0.18);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --ink: #ffffff;
  --ink-2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --wash: rgba(255, 255, 255, 0.06);
  --accent: #3987e5;
  --s1: #3987e5;
  --s2: #d95926;
  --co: #199e70;
  --us: #9085e9;
  --ot: #4a4945;
  --mk: #a3a29a;
  --seq1: #b7d3f6; --seq2: #86b6ef; --seq3: #5598e7; --seq4: #2a78d6; --seq5: #1c5cab; --seq6: #184f95;
  --nodata: #2c2c2a;
  --wash-strong: rgba(255, 255, 255, 0.18);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--page);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
button, select, input { font: inherit; color: inherit; }
a { color: var(--accent); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Top bar */
.topbar {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 16px;
  padding: 20px 24px 12px; max-width: 1440px; margin: 0 auto;
}
.brand h1 { font-size: 22px; font-weight: 650; margin: 0; letter-spacing: -0.01em; }
.subtitle { margin: 2px 0 0; color: var(--ink-2); }
.lang { display: inline-flex; border: 1px solid var(--border); border-radius: 999px; padding: 2px; background: var(--surface); flex-shrink: 0; }
.lang button {
  border: 0; background: transparent; padding: 5px 12px; border-radius: 999px;
  font-weight: 600; font-size: 13px; cursor: pointer; color: var(--ink-2);
}
.lang button[aria-pressed="true"] { background: var(--ink); color: var(--surface); }
.toggles { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.theme-btn {
  width: 34px; height: 34px; display: grid; place-items: center; cursor: pointer;
  border: 1px solid var(--border); border-radius: 999px; background: var(--surface); color: var(--ink-2);
}
.theme-btn:hover { color: var(--ink); background: var(--wash); }
.theme-btn svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
/* Show the icon of the mode you would switch to. */
.theme-btn .i-sun { display: none; }
:root[data-theme="dark"] .theme-btn .i-sun { display: block; }
:root[data-theme="dark"] .theme-btn .i-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) .theme-btn .i-sun { display: block; }
  :root:not([data-theme]) .theme-btn .i-moon { display: none; }
}

/* Filters: one row above the content they scope */
.filters {
  position: sticky; top: 0; z-index: 5;
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px 16px;
  max-width: 1440px; margin: 0 auto; padding: 12px 24px;
  background: color-mix(in srgb, var(--page) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.filter { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.filter.grow { flex: 1 1 180px; }
.filter.period { flex-direction: column; }
.period .chips, .period .range { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.period-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.flabel { font-size: 12px; color: var(--ink-2); font-weight: 500; }
select, input[type="search"], input[type="date"] {
  height: 32px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface);
  padding: 0 10px; min-width: 0;
}
input[type="search"] { width: 100%; }
select:focus-visible, input:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.chips button, .seg button, .reset, .ghost {
  height: 32px; border: 1px solid var(--border); background: var(--surface); border-radius: 8px;
  padding: 0 12px; cursor: pointer; white-space: nowrap;
}
.chips button:hover, .seg button:hover, .reset:hover, .ghost:hover { background: var(--wash); }
.chips button[aria-pressed="true"], .seg button[aria-pressed="true"] {
  background: var(--ink); color: var(--surface); border-color: var(--ink);
}
.seg { display: inline-flex; }
.seg button { border-radius: 0; margin-left: -1px; }
.seg button:first-child { border-radius: 8px 0 0 8px; margin-left: 0; }
.seg button:last-child { border-radius: 0 8px 8px 0; }
.seg.small button { height: 28px; padding: 0 10px; font-size: 13px; }
.period .range { display: flex; }
.range input[type="date"] { width: 140px; }
.reset { color: var(--ink-2); }

main { max-width: 1440px; margin: 0 auto; padding: 16px 24px 8px; }

/* KPI tiles */
.kpis { display: grid; grid-template-columns: 1.3fr repeat(4, 1fr); gap: 12px; margin-bottom: 12px; }
.kpi {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; min-width: 0;
}
.kpi h2 { font-size: 13px; font-weight: 500; color: var(--ink-2); margin: 0 0 4px; }
.kpi .value { font-size: 30px; font-weight: 600; margin: 0; letter-spacing: -0.02em; line-height: 1.15; }
.kpi.hero .value { font-size: 48px; }
.kpi .note { margin: 4px 0 0; color: var(--muted); font-size: 12px; }

/* Cards */
.grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px 12px; min-width: 0; display: flex; flex-direction: column;
}
.span2 { grid-column: span 2; }
.span3 { grid-column: span 3; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.card h2 { font-size: 15px; font-weight: 600; margin: 0; }
.card h2.sub { margin-top: 12px; }
.hint { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.controls { display: flex; gap: 8px; flex-wrap: wrap; }
.chart { width: 100%; height: 300px; margin-top: 4px; }
.chart.short { height: 150px; }
#chType { height: 110px; }
#chGenre { height: 250px; }

/* Market section */
.section-head { margin: 28px 0 10px; }
.section-head h2 { font-size: 18px; font-weight: 650; margin: 0; letter-spacing: -0.01em; }
.section-head p { margin: 2px 0 0; color: var(--ink-2); font-size: 13px; }
#marketGrid, #regionsGrid { margin-bottom: 12px; }
.chart.map { height: 520px; }
.dep-pill { display: flex; align-items: center; gap: 8px; margin: 8px 0 0; font-size: 13px; font-weight: 500; }
.dep-pill button {
  border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: 2px 10px;
  font-size: 12px; color: var(--ink-2); cursor: pointer;
}
.dep-pill button:hover { background: var(--wash); }

/* Upcoming releases */
#upGrid { margin-bottom: 12px; }
.up-list { list-style: none; margin: 8px 0 0; padding: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px 20px; }
.up-list li { display: flex; align-items: flex-start; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--grid); min-width: 0; }
.up-poster img { display: block; width: 40px; height: 56px; object-fit: cover; border-radius: 4px; background: var(--wash); }
.up-body { flex: 1; min-width: 0; }
.up-title { color: var(--ink); text-decoration: none; font-weight: 600; }
.up-title:hover { text-decoration: underline; }
.up-meta { margin: 2px 0 0; font-size: 12px; color: var(--ink-2); }
.up-links { margin: 4px 0 0; font-size: 12px; color: var(--muted); }
.up-date { flex-shrink: 0; font-size: 13px; font-weight: 600; color: var(--s1); white-space: nowrap; }
@media (max-width: 1100px) { .up-list { grid-template-columns: minmax(0, 1fr); } }
.foot p { margin: 0 0 4px; }
.card.note h2 { margin-bottom: 8px; }
.card.note p { margin: 0 0 8px; color: var(--ink-2); line-height: 1.5; font-size: 13px; }
.card.note .stat { color: var(--ink); font-weight: 500; font-size: 14px; }

/* Collapsible sections */
.ai-note { margin-top: 8px; font-size: 12px; color: var(--ink-2); }
.ai-note summary, details.shorts > summary { cursor: pointer; }
.ai-note summary { color: var(--ink-2); font-weight: 500; }
.ai-note p { margin: 6px 0 0; line-height: 1.5; }
details.shorts { margin-top: 12px; }
details.shorts > summary { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; list-style-position: outside; }
details.shorts > summary .sum-title { font-size: 15px; font-weight: 600; }
details.shorts > summary .hint { margin: 0; }
details.shorts[open] > summary { margin-bottom: 4px; }
.chart.tall { height: 420px; }
.footnote { margin: 6px 0 0; font-size: 12px; color: var(--muted); }

.legend { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 8px; font-size: 12px; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }

/* Table */
/* The table scrolls inside its own box so the sticky header row stays in view. */
.table-wrap { overflow: auto; margin-top: 8px; max-height: min(70vh, 720px); overscroll-behavior: contain; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--grid); white-space: nowrap; }
td:first-child { white-space: normal; min-width: 220px; font-weight: 500; }
th {
  color: var(--ink-2); font-weight: 500; cursor: pointer; user-select: none;
  position: sticky; top: 0; z-index: 2; background: var(--surface);
  /* Borders scroll away on sticky cells; a shadow line stays with the header. */
  border-bottom: 0; box-shadow: inset 0 -1px 0 var(--axis);
}
th:hover { color: var(--ink); }
th[aria-sort="ascending"]::after { content: " ▲"; font-size: 10px; }
th[aria-sort="descending"]::after { content: " ▼"; font-size: 10px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:hover { background: var(--wash); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; vertical-align: 0; }
.more { align-self: center; margin-top: 10px; }
tr.row { cursor: pointer; }
tr.row.open td { border-bottom-color: transparent; background: var(--wash); }
.expander {
  border: 0; background: none; color: var(--muted); cursor: pointer; padding: 0 6px 0 0;
  font-size: 11px; width: 18px; display: inline-block;
}
td.dir { white-space: normal; min-width: 140px; color: var(--ink-2); }
td.chips-cell { white-space: normal; min-width: 180px; }
.chip {
  display: inline-block; margin: 1px 4px 1px 0; padding: 1px 8px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--page); color: var(--ink-2); font-size: 12px; white-space: nowrap;
}
tr.detail td { white-space: normal; background: var(--wash); padding: 4px 16px 14px 34px; }
/* Keep the synopsis readable inside the horizontally scrolling table on phones. */
tr.detail td > * { position: sticky; left: 34px; max-width: min(80ch, calc(100vw - 96px)); }
tr.detail h3 { font-size: 12px; font-weight: 600; color: var(--ink-2); margin: 0 0 4px; }
tr.detail .syn { margin: 0 0 8px; line-height: 1.55; color: var(--ink); }
tr.detail .meta { margin: 0; font-size: 12px; color: var(--muted); }
.empty { color: var(--muted); padding: 24px 0; text-align: center; }

.foot { max-width: 1440px; margin: 0 auto; padding: 8px 24px 32px; color: var(--muted); font-size: 12px; }
.foot p { margin: 0 0 4px; }
.foot .credit { color: var(--ink-2); }

.loading {
  position: fixed; inset: 0; display: grid; place-items: center; background: var(--page);
  color: var(--ink-2); z-index: 20; transition: opacity .2s;
}
.loading.hide { opacity: 0; pointer-events: none; }
.loading.error { color: #d03b3b; }

@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .kpi.hero { grid-column: span 2; }
  .grid { grid-template-columns: minmax(0, 1fr); }
  .span2, .span3 { grid-column: auto; }
}
@media (max-width: 640px) {
  .topbar, .filters, main, .foot { padding-left: 16px; padding-right: 16px; }
  .brand h1 { font-size: 19px; }
  .filters { position: static; }
  .filter, .filter.grow { flex: 1 1 100%; }
  .filter select { width: 100%; }
  .reset { width: 100%; }
  .kpi .value { font-size: 24px; }
  .kpi.hero .value { font-size: 40px; }
  .chart.tall { height: 380px; }
  .chart.map { height: 420px; }
}
