:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #14171c;
  --muted: #667085;
  --border: #e3e6ea;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --stream: #067a50;
  --stream-bg: #e3f6ee;
  --rent: #9a5b00;
  --rent-bg: #fdf1dc;
  --unavail: #9b1c1c;
  --unavail-bg: #fde8e8;
  --unknown-bg: #eceef1;
  --danger: #c0262d;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #171a21;
    --surface-2: #1f232c;
    --text: #e8eaee;
    --muted: #98a1b0;
    --border: #2a2f3a;
    --accent: #5b8cff;
    --stream: #4ade9a;
    --stream-bg: #11372a;
    --rent: #fbbf5c;
    --rent-bg: #3a2c10;
    --unavail: #f8a1a1;
    --unavail-bg: #3b1717;
    --unknown-bg: #262a33;
    --danger: #f87171;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.6rem; margin: .4rem 0 1rem; }
h2 { font-size: 1.15rem; margin: 1.6rem 0 .6rem; }
h3 { font-size: 1rem; margin: 0 0 .2rem; line-height: 1.25; }
h3 a { color: inherit; }
code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
img { max-width: 100%; }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; color: var(--text); font-size: 1.05rem; white-space: nowrap; }
.brand span { color: var(--accent); }
.topbar nav { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
.topbar nav a, .topbar nav .linklike { color: var(--muted); padding: 6px 10px; border-radius: 8px; font-size: .95rem; }
.topbar nav a.active, .topbar nav a:hover { color: var(--text); background: var(--surface-2); text-decoration: none; }

.container { max-width: 1180px; margin: 0 auto; padding: 16px; }
.footer { max-width: 1180px; margin: 24px auto; padding: 0 16px 24px; color: var(--muted); font-size: .8rem; }

.muted { color: var(--muted); }
.small { font-size: .88rem; }
.tiny { font-size: .78rem; margin-top: 6px; }
.err { color: var(--danger); }
.inline { display: inline; }
.linklike { background: none; border: 0; color: var(--accent); cursor: pointer; font: inherit; padding: 0; }

.btn {
  display: inline-flex; align-items: center; gap: 4px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 8px 14px; border-radius: 9px; font: inherit; cursor: pointer;
}
.btn:hover:not(:disabled) { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-primary:hover:not(:disabled) { background: var(--accent); filter: brightness(1.08); }
.btn-sm { padding: 4px 9px; font-size: .82rem; border-radius: 7px; }
.btn-danger { color: var(--danger); }

.flash { padding: 10px 14px; border-radius: 10px; margin: 0 0 12px; background: var(--surface-2); }
.flash-success { background: var(--stream-bg); color: var(--stream); }
.flash-error { background: var(--unavail-bg); color: var(--unavail); }

/* search */
.search-panel { margin-bottom: 18px; }
.search { display: flex; gap: 8px; }
.search input {
  flex: 1; min-width: 0; padding: 11px 14px; font: inherit; font-size: 1rem;
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--text);
}
.search input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.results {
  margin-top: 10px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
}
.result { display: flex; gap: 12px; padding: 12px; border-bottom: 1px solid var(--border); }
.result:last-child { border-bottom: 0; }
.result img, .result .noposter { width: 64px; height: 96px; border-radius: 6px; object-fit: cover; flex: none; }
.result-body { flex: 1; min-width: 0; }
.result-body p { margin: 4px 0; font-size: .85rem; color: var(--muted);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.result-side { display: flex; align-items: flex-start; }
.results-head { display: flex; justify-content: space-between; align-items: center; padding: 8px 12px; background: var(--surface-2); font-size: .85rem; }

/* toolbar + filters */
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.tabs { display: flex; gap: 4px; }
.tab { padding: 7px 12px; border-radius: 9px; color: var(--muted); font-weight: 600; }
.tab.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); border: 1px solid var(--border); }
.tab:hover { text-decoration: none; color: var(--text); }
.sort select { font: inherit; padding: 5px 8px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); }
.filters { display: flex; gap: 6px; margin: 12px 0 6px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: thin; }
.pill {
  white-space: nowrap; padding: 6px 12px; border-radius: 999px; font-size: .88rem;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
.pill:hover { text-decoration: none; background: var(--surface-2); }
.pill.active { background: var(--text); color: var(--bg); border-color: var(--text); }
.count { opacity: .65; font-size: .85em; margin-left: 2px; }
.scan-line { margin: 4px 0 14px; }

/* cards */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.card {
  display: flex; gap: 12px; padding: 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
}
.poster { position: relative; flex: none; width: 92px; }
.poster img, .noposter { width: 92px; height: 138px; object-fit: cover; border-radius: 8px; display: block; background: var(--surface-2); }
.noposter { display: grid; place-items: center; font-size: 2rem; color: var(--muted); }
.noposter.big { width: 100%; height: auto; aspect-ratio: 2/3; font-size: 4rem; }
.ribbon {
  position: absolute; top: 6px; left: -4px; background: var(--stream); color: #fff;
  font-size: .7rem; font-weight: 700; padding: 2px 7px; border-radius: 4px; text-transform: uppercase;
}
.card-body { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.meta { font-size: .85rem; color: var(--muted); margin-bottom: 6px; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }

.badge { font-size: .74rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.badge-stream { background: var(--stream-bg); color: var(--stream); }
.badge-rent { background: var(--rent-bg); color: var(--rent); }
.badge-unavailable { background: var(--unavail-bg); color: var(--unavail); }
.badge-unknown { background: var(--unknown-bg); color: var(--muted); }

.prov-row { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin: 3px 0; }
.prov-label { font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); width: 62px; flex: none; }
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: .8rem; padding: 2px 8px 2px 2px; border-radius: 999px;
  border: 1px solid var(--border); color: var(--text); background: var(--surface);
}
.chip:hover { text-decoration: none; background: var(--surface-2); }
.chip img { width: 20px; height: 20px; border-radius: 50%; }
.chip-stream { border-color: var(--stream); }
.chip-rent { border-color: var(--rent); }
.chip-other { opacity: .7; }
.chip-pending { border-style: dashed; border-color: var(--muted); padding-left: 8px; }
.chip:not(:has(img)) { padding-left: 8px; }
.btn-xs { padding: 1px 7px; font-size: .74rem; border-radius: 6px; }
.tier-buttons { display: inline-flex; gap: 4px; flex-wrap: wrap; }
.tiny-inline { font-size: .76rem; }
.pending-row { gap: 6px; }
.leaving { margin-left: 6px; font-size: .74rem; font-weight: 700; color: var(--rent); background: var(--rent-bg); padding: 1px 7px; border-radius: 999px; }
.leaving-line { font-size: .8rem; font-weight: 600; color: var(--rent); margin-top: 4px; }
.yes-box { margin: 8px 0 4px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 9px; background: var(--surface-2); }

.actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: auto; padding-top: 10px; }
.actions form { margin: 0; }

.empty { text-align: center; padding: 48px 16px; color: var(--muted); background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius); }

/* detail */
.detail { display: grid; grid-template-columns: 240px 1fr; gap: 24px; }
.detail-poster img { width: 100%; border-radius: var(--radius); box-shadow: var(--shadow); }
.detail-body h1 { margin-top: 0; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; font-size: .9rem; margin: 16px 0 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; word-break: break-word; }

.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: 8px 0; border-bottom: 1px solid var(--border); font-size: .9rem; }
.plus, .to-stream { color: var(--stream); font-weight: 700; }
.minus, .to-unavailable { color: var(--unavail); font-weight: 700; }
.to-rent { color: var(--rent); }

.two-col { display: grid; grid-template-columns: 1.3fr 1fr; gap: 24px; }
.two-col h2:first-child { margin-top: 0; }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .88rem; }
.table th, .table td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table th { color: var(--muted); font-weight: 600; }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 18px; box-shadow: var(--shadow); }
.panel h2 { margin-top: 0; }
.provider-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 8px; margin: 12px 0 16px; }
.provider-opt { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border: 1px solid var(--border); border-radius: 9px; cursor: pointer; font-size: .9rem; }
.provider-opt:has(input:checked) { border-color: var(--accent); background: var(--surface-2); }
.provider-opt img { width: 26px; height: 26px; border-radius: 6px; }

.email-form label { font-weight: 600; font-size: .9rem; }
.email-row { display: flex; gap: 8px; margin: 6px 0 4px; }
.email-row input { flex: 1; min-width: 0; padding: 9px 12px; font: inherit; border: 1px solid var(--border); border-radius: 9px; background: var(--surface); color: var(--text); }
.login { max-width: 360px; margin: 40px auto; display: flex; flex-direction: column; gap: 12px; }
.login label { display: flex; flex-direction: column; gap: 4px; }
.login input { padding: 10px; font: inherit; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); }

@media (max-width: 760px) {
  .detail { grid-template-columns: 1fr; }
  .detail-poster { max-width: 200px; }
  .two-col { grid-template-columns: 1fr; }
  .grid { grid-template-columns: 1fr; }
  .topbar { flex-wrap: wrap; }
}
@media (max-width: 420px) {
  .poster, .poster img, .noposter { width: 76px; }
  .poster img, .noposter { height: 114px; }
  .prov-label { width: auto; }
}

/* Hebrew titles, IMDb badge, search clear */
.title-he { font-size: .88rem; font-weight: 700; color: var(--text); opacity: .8; margin: -1px 0 4px; text-align: left; unicode-bidi: plaintext; }
.title-he.big { font-size: 1.05rem; margin: -6px 0 8px; }
.poster-col { flex: none; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.imdb { display: inline-flex; align-items: center; gap: 5px; font-size: .82rem; color: var(--text); white-space: nowrap; }
.imdb:hover { text-decoration: none; }
.imdb-logo { background: #f5c518; color: #000; font-weight: 800; font-size: .66rem; padding: 1px 4px; border-radius: 3px; letter-spacing: -.02em; }
.detail-poster .imdb { margin-top: 10px; font-size: .95rem; }
.search-field { position: relative; flex: 1; min-width: 0; display: flex; }
.search-field input { width: 100%; padding-right: 38px; }
.search-clear { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); width: 28px; height: 28px;
  border: 0; border-radius: 50%; background: var(--surface-2); color: var(--muted); font-size: 1.2rem; line-height: 1; cursor: pointer; }
.search-clear:hover { color: var(--text); }
.result .poster-col img, .result .poster-col .noposter { width: 64px; height: 96px; border-radius: 6px; object-fit: cover; }

.schedule-form { margin-bottom: 14px; }
.schedule-form label { font-weight: 600; font-size: .9rem; }
.schedule-form select { flex: 1; min-width: 0; padding: 9px 10px; font: inherit; border: 1px solid var(--border); border-radius: 9px; background: var(--surface); color: var(--text); }

/* Movies / TV series */
.kind-tabs { display: flex; gap: 8px; margin: 4px 0 12px; border-bottom: 1px solid var(--border); }
.kind-tab { padding: 9px 14px; font-weight: 700; color: var(--muted); border-bottom: 3px solid transparent; margin-bottom: -1px; }
.kind-tab:hover { text-decoration: none; color: var(--text); }
.kind-tab.active { color: var(--text); border-bottom-color: var(--accent); }
.seasons-line { font-size: .8rem; color: var(--muted); margin-top: 4px; }

/* accounts */
.login label, .stack-form label { display: block; margin: 0 0 12px; }
.login label input, .stack-form label input { display: block; width: 100%; margin-top: 4px; }
.stack-form { max-width: 420px; }
.link-box input[readonly] { font-family: ui-monospace, monospace; font-size: 13px; }
.row-actions { white-space: nowrap; }
.inline-details { display: inline-block; vertical-align: middle; }
.inline-details > summary { list-style: none; cursor: pointer; }
.inline-details[open] form { margin-top: 6px; }
