/* =====================================================================
   components.css: buttons, chips, pickers, fields, segmented, toggle,
   meta, spinner, skeleton, empty states, toast.
   ===================================================================== */

/* ---------------------------------------------------------------- .btn */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: var(--control); padding: 0 22px; border-radius: var(--radius-pill);
  font: 600 15px/1 var(--font); letter-spacing: -.005em; white-space: nowrap;
  transition: background-color var(--dur-2) var(--ease-std), color var(--dur-2) var(--ease-std), transform var(--dur-1) var(--ease-std);
}
.btn .icon { width: 20px; height: 20px; }
.btn:active { transform: scale(.97); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .4; cursor: default; }
.btn[aria-busy="true"] > .icon { display: none; }
/* playTitle() puts a spinner before the label; the inline min-width holds the width. */
.btn[aria-busy="true"]:disabled { opacity: 1; cursor: progress; }
.btn > .spinner { flex: none; width: 20px; height: 20px; border-width: 2px; }
.btn--primary > .spinner { border-color: rgba(0, 0, 0, .2); border-top-color: var(--on-inverse); }
.btn--lg { height: var(--control-lg); padding: 0 28px; font-size: 17px; }
.btn--lg .icon { width: 22px; height: 22px; }
.btn--sm { height: var(--control-sm); padding: 0 16px; font-size: 14px; }
.btn--icon { width: var(--control); padding: 0; }
.btn--sm.btn--icon { width: var(--control-sm); }
.btn--lg.btn--icon { width: var(--control-lg); }
.btn--block { width: 100%; }
.btn--primary { background: var(--inverse); color: var(--on-inverse); }
.btn--secondary { background: var(--fill-2); color: var(--text); }
.btn--overlay { background: var(--btn-overlay); color: var(--text); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .22); }
.btn--ghost { color: var(--text-2); }
/* Glass: round controls and secondary buttons over artwork (hero). TVs skip the blur (shell cost). */
.btn--glass {
  background: var(--glass); color: var(--text); box-shadow: var(--glass-ring);
  -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
}
html.is-tv .btn--glass { -webkit-backdrop-filter: none; backdrop-filter: none; background: rgba(40, 40, 46, .88); }
@media (hover: hover) and (pointer: fine) {
  .btn--primary:hover { background: var(--inverse-hover); }
  .btn--secondary:hover { background: var(--fill-3); }
  .btn--overlay:hover { background: var(--btn-overlay-hover); }
  .btn--glass:hover { background: var(--glass-hover); }
  .btn--ghost:hover { background: var(--fill-1); color: var(--text); }
}
.btn:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; box-shadow: 0 0 0 2px var(--focus-halo); }
.btn--overlay:focus-visible { box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .22), 0 0 0 2px var(--focus-halo); }
.btn--glass:focus-visible { box-shadow: var(--glass-ring), 0 0 0 2px var(--focus-halo); }
html.is-tv .btn:focus-visible { background: var(--inverse); color: var(--on-inverse); transform: scale(1.04); }

/* --------------------------------------------------------------- .chip */
.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 40px; padding: 0 16px;
  border-radius: var(--radius-pill); background: var(--fill-1); color: var(--text-2);
  font: 500 15px/1 var(--font); white-space: nowrap; flex: none;
  transition: background-color var(--dur-2), color var(--dur-2);
}
@media (pointer: coarse) { .chip { height: 44px; } }
@media (hover: hover) and (pointer: fine) { .chip:hover { background: var(--fill-3); color: var(--text); } }
.chip[aria-pressed="true"], .chip[aria-current="page"], .chip[aria-current="true"], .chip[aria-selected="true"], .chip.is-active {
  background: var(--inverse); color: var(--on-inverse); font-weight: 600;
}
.chip:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; box-shadow: 0 0 0 3px var(--focus-halo); }
html.is-tv .chip { height: var(--control); font-size: var(--fs-callout); transition: background-color var(--dur-2), color var(--dur-2), transform var(--dur-3) var(--ease-calm); }
html.is-tv .chip:focus-visible { transform: scale(1.06); }

/* ------------------------------------------------------------- .picker */
/* pickerControl(): a native <select> stretched invisibly over a chip. */
.picker-wrap { position: relative; display: inline-flex; align-items: center; flex: none; }
.picker {
  position: relative; display: inline-flex; align-items: center; gap: 6px; height: 40px; padding: 0 14px 0 16px;
  border-radius: var(--radius-pill); background: var(--fill-1); color: var(--text);
  font: 500 15px/1 var(--font); white-space: nowrap;
  transition: background-color var(--dur-2), color var(--dur-2);
}
@media (pointer: coarse) { .picker { height: 44px; } }
.picker select {
  position: absolute; inset: 0; width: 100%; opacity: 0; font-size: 16px; cursor: pointer;
  appearance: none; -webkit-appearance: none;
}
.picker select option { background: var(--surface-2); color: var(--text); }
.picker__text { max-width: 18ch; overflow: hidden; text-overflow: ellipsis; }
.picker .icon { width: 16px; height: 16px; color: var(--text-2); }
@media (hover: hover) and (pointer: fine) { .picker:hover { background: var(--fill-3); } }
.picker[data-set] { background: var(--inverse); color: var(--on-inverse); font-weight: 600; }
.picker[data-set] .icon { color: var(--on-inverse); }
/* With a clear button the chevron gives way to the X. */
.picker-wrap--clearable .picker[data-set] { padding-right: 40px; }
.picker-wrap--clearable .picker[data-set] > .icon { display: none; }
/* Chip ring. :focus-within is the base for engines without :has(); where :has()
   exists, the second rule removes the ring for mouse focus. */
.picker:focus-within { outline: 3px solid var(--focus); outline-offset: 3px; box-shadow: 0 0 0 3px var(--focus-halo); }
.picker:focus-within:not(:has(select:focus-visible)) { outline: none; box-shadow: none; }
.picker__clear {
  position: absolute; top: 50%; right: 0; width: 44px; height: 44px; margin-top: -22px;
  display: grid; place-items: center; border-radius: 50%; color: var(--on-inverse);
}
.picker__clear .icon { width: 16px; height: 16px; stroke-width: 2.2; }
.picker__clear:focus-visible { outline: 2px solid var(--on-inverse); outline-offset: -8px; box-shadow: none; }
html.is-tv .picker { height: var(--control); font-size: var(--fs-callout); transition: background-color var(--dur-2), color var(--dur-2), transform var(--dur-3) var(--ease-calm); }
html.is-tv .picker:focus-within { transform: scale(1.06); }

/* -------------------------------------------------------------- .field */
.field {
  display: flex; align-items: center; gap: 10px; height: 44px; padding: 0 16px;
  border-radius: var(--radius-pill); background: var(--fill-1); border: 1px solid transparent; color: var(--text-2);
  transition: background-color var(--dur-2);
}
.field input { flex: 1; min-width: 0; height: 100%; background: none; border: 0; outline: none; color: var(--text); font-size: var(--fs-input); }
/* The pill's own ring (.field:focus-within) is the focus mark: not base.css's square ring and halo on the input inside. */
.field input:focus-visible { outline: none; box-shadow: none; }
.field input::placeholder { color: var(--text-3); }
.field input::-webkit-search-cancel-button { display: none; }
.field .icon { width: 18px; height: 18px; }
@media (hover: hover) and (pointer: fine) { .field:hover { background: rgba(255, 255, 255, .11); } }
.field:focus-within { background: var(--fill-2); outline: 2px solid var(--focus); outline-offset: 2px; color: var(--text); }
.field--lg { height: 56px; }
.field--lg input { font-size: max(17px, var(--fs-input)); }
html.is-tv .field--lg { height: calc(72px * var(--tvu)); }
/* Clear button inside a search field (search.js, live.js). */
.field__clear {
  flex: none; display: grid; place-items: center; width: 44px; height: 44px; margin-right: -12px;
  border-radius: 50%; color: var(--text-2);
}
.field__clear .icon { width: 16px; height: 16px; stroke-width: 2.2; }
.field__clear:focus-visible { outline-offset: -4px; box-shadow: none; }
@media (hover: hover) and (pointer: fine) { .field__clear:hover { color: var(--text); } }

/* ---------------------------------------------------------- .segmented */
.segmented {
  display: inline-flex; gap: 2px; padding: 3px; height: 40px; max-width: 100%;
  border-radius: var(--radius-pill); background: var(--fill-1);
  overflow-x: auto; scrollbar-width: none;
}
.segmented::-webkit-scrollbar { display: none; }
@media (pointer: coarse) { .segmented { height: 44px; } }
.segmented button {
  flex: none; padding: 0 14px; border-radius: var(--radius-pill);
  font: 600 14px/1 var(--font); color: var(--text-2); font-variant-numeric: tabular-nums;
}
.segmented button[aria-pressed="true"] { background: var(--inverse); color: var(--on-inverse); }
.segmented button:focus-visible { outline-offset: -3px; box-shadow: none; }

/* ------------------------------------------------------------- .toggle */
.toggle { display: inline-flex; align-items: center; gap: 12px; min-height: 44px; color: var(--text-2); font-size: 15px; cursor: pointer; user-select: none; }
.toggle input {
  appearance: none; -webkit-appearance: none; position: relative; flex: none; margin: 0; cursor: pointer;
  width: 44px; height: 26px; border-radius: var(--radius-pill); background: var(--toggle-off);
  transition: background-color var(--dur-2);
}
.toggle input::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff;
  transition: transform var(--dur-2) var(--ease-calm), background-color var(--dur-2);
}
.toggle input:checked { background: var(--inverse); }
.toggle input:checked::after { background: #000; transform: translateX(18px); }

/* --------------------------------------------------------------- .meta */
.meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 0; color: var(--text-2); font-size: var(--fs-callout); }
.meta > * + *::before {
  content: ""; display: inline-block; width: 3px; height: 3px; border-radius: 50%;
  background: currentColor; opacity: .55; margin: 0 8px; vertical-align: middle;
}
.meta .score { display: inline-flex; align-items: center; gap: 4px; color: var(--text); }
.meta .score .icon { width: 12px; height: 12px; color: currentColor; }

/* ------------------------------------------------------------ spinners */
.spinner { width: 32px; height: 32px; border-radius: 50%; border: 3px solid rgba(255, 255, 255, .18); border-top-color: #fff; animation: spin .9s linear infinite; }
.spinner--sm { width: 20px; height: 20px; border-width: 2px; }
.spinner--lg { width: 40px; height: 40px; }

/* ------------------------------------------------------------ skeleton */
/* An opacity pulse, no shimmer: background-position is never animated. */
.skeleton { background: var(--skeleton); border-radius: var(--radius-sm); animation: skeleton-pulse 1.4s ease-in-out infinite alternate; }
@keyframes skeleton-pulse { from { opacity: .55; } to { opacity: 1; } }
html.is-tv .skeleton { animation: none; }
@media (prefers-reduced-motion: reduce) { .skeleton { animation: none; } }
.skeleton-card { min-width: 0; }
.skeleton--poster { aspect-ratio: 2 / 3; border-radius: var(--radius-card); }
.skeleton--line { width: 80%; height: 12px; margin-top: 10px; border-radius: var(--radius-xs); }
.skeleton--title { width: 180px; height: 22px; }
.skeleton--pill { width: 160px; height: 48px; border-radius: var(--radius-pill); }

/* skeletonHero(): the billboard (catalog.css .hero), or the tall stacked block with centred lines. */
.skeleton-hero { position: relative; margin-left: calc(-1 * var(--shell-x)); height: clamp(560px, 86vh, 920px); height: clamp(560px, 86svh, 920px); overflow: hidden; }
.skeleton-hero__media { position: absolute; inset: 0; border-radius: 0; }
.skeleton-hero__body { position: absolute; left: var(--content-x); bottom: 104px; width: min(720px, 58%); }
.skeleton-hero__body .skeleton { background: var(--surface-3); }
.skeleton-hero__body .skeleton--line { height: 20px; margin-top: 14px; }
.skeleton-hero__body .skeleton--line:nth-child(1) { width: 60%; height: 72px; margin-top: 0; }
.skeleton-hero__body .skeleton--line:nth-child(2) { width: 40%; }
.skeleton-hero__body .skeleton--line:nth-child(3) { width: 30%; }
.skeleton-hero__actions { display: flex; gap: 12px; margin-top: 28px; }
.skeleton-hero__actions .skeleton--pill:last-child { width: 48px; }
@media (max-width: 860px), (orientation: portrait) and (max-width: 1119px) {
  .skeleton-hero { height: 70vh; height: 70svh; min-height: 460px; max-height: 860px; }
  .skeleton-hero__body { left: var(--gutter); right: var(--gutter); bottom: 76px; width: auto; max-width: 560px; margin: 0 auto; }
  .skeleton-hero__body .skeleton--line { margin-left: auto; margin-right: auto; }
  .skeleton-hero__actions { justify-content: center; }
  .skeleton-hero__actions .skeleton--pill:first-child { flex: 1; width: auto; }
}
html.is-tv .skeleton-hero { height: 74vh; height: 74svh; }
html.is-tv .skeleton-hero__body { bottom: calc(160px * var(--tvu)); width: calc(820px * var(--tvu)); }

/* ------------------------------------------------------- empty / error */
.empty { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 10px; padding: 72px 16px; color: var(--text-2); }
.empty__icon { display: grid; place-items: center; width: 56px; height: 56px; border-radius: 50%; background: var(--surface-2); color: var(--text-2); }
.empty__icon .icon { width: 26px; height: 26px; }
.empty h2 { margin-top: 6px; color: var(--text); font-size: var(--fs-title-3); font-weight: 600; }
.empty p { max-width: 44ch; font-size: 15px; line-height: 1.55; }
.empty__actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; margin-top: 16px; }

/* --------------------------------------------------------------- toast */
.toast {
  /* Centred on the content, beside the desktop sidebar (--shell-x is 0 elsewhere). */
  position: fixed; left: calc(50% + var(--shell-x) / 2); bottom: calc(24px + var(--tabbar-total)); z-index: var(--z-toast);
  transform: translate(-50%, 12px); opacity: 0; display: flex; align-items: center; gap: 12px;
  /* max-content: with left:50% a shrink-to-fit box only gets half the screen and wraps word by word. */
  width: max-content; min-height: 44px; padding: 10px 20px; max-width: min(480px, calc(100% - 32px));
  border-radius: var(--radius-pill); background: var(--inverse); color: var(--on-inverse);
  font: 500 15px/1.3 var(--font); box-shadow: var(--shadow-1); pointer-events: none;
  transition: opacity var(--dur-3), transform var(--dur-3) var(--ease-calm);
}
/* Inside an open dialog or over the player the sidebar does not count: centred on the window. */
dialog .toast { left: 50%; }
body:has(> .player) .toast { left: 50%; }
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }
.toast.has-action.is-visible { pointer-events: auto; }
.toast__text { min-width: 0; }
/* 44px hit area inside a 44px pill: the negative margins cancel the vertical padding. */
.toast__action {
  flex: none; display: inline-flex; align-items: center; min-height: 44px; margin: -10px -8px -10px 0; padding: 0 8px 0 12px;
  border-left: 1px solid rgba(0, 0, 0, .15); color: var(--on-inverse); font: 700 15px/1 var(--font);
}
.toast__action:focus-visible { outline: 2px solid var(--focus-on-inverse); outline-offset: -4px; box-shadow: none; }

/* ------------------------------------------------------ glass and brand pills */
/* Glass pills (Colecciones and Géneros on the section pages, Explorar): frosted, the page's tint shows through. */
.chip--glass {
  background: rgba(255, 255, 255, .1); color: var(--text); box-shadow: var(--glass-ring);
  -webkit-backdrop-filter: blur(20px) saturate(160%); backdrop-filter: blur(20px) saturate(160%);
}
@supports not ((-webkit-backdrop-filter: blur(1px)) or (backdrop-filter: blur(1px))) { .chip--glass { background: rgba(48, 48, 56, .72); } }
html.is-tv .chip--glass { background: rgba(48, 48, 56, .8); -webkit-backdrop-filter: none; backdrop-filter: none; }
@media (hover: hover) and (pointer: fine) { .chip--glass:hover { background: rgba(255, 255, 255, .2); color: #fff; } }
/* A platform's pill: its colour (ui.js brandStyle) as a small gradient tile, the name in bold white. */
.chip--platform {
  background: linear-gradient(150deg, rgb(var(--p-face)) 0, rgb(var(--p-deep)) 100%); color: #fff; font-weight: 700; letter-spacing: -.01em;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .26), inset 0 0 0 1px rgba(255, 255, 255, .1);
}
@media (hover: hover) and (pointer: fine) {
  .chip--platform:hover { background: rgb(var(--p-face)); color: #fff; }
}
html.is-tv .chip--glass:focus-visible, html.is-tv .chip--platform:focus-visible { background: var(--inverse); color: var(--on-inverse); }

/* Glass segmented control over artwork or a colour band (#/platform: "Películas | Series"); the selected one a white pill. */
.segmented--glass {
  height: 44px; padding: 4px; gap: 4px; background: rgba(255, 255, 255, .14); box-shadow: var(--glass-ring);
  -webkit-backdrop-filter: blur(24px) saturate(170%); backdrop-filter: blur(24px) saturate(170%);
}
@supports not ((-webkit-backdrop-filter: blur(1px)) or (backdrop-filter: blur(1px))) { .segmented--glass { background: rgba(30, 30, 36, .74); } }
.segmented--glass button {
  padding: 0 22px; color: rgba(255, 255, 255, .88); font-size: 15px;
  transition: background-color var(--dur-2), color var(--dur-2), transform var(--dur-2) var(--ease-calm);
}
.segmented--glass button[aria-pressed="true"] { background: #fff; color: #000; }
@media (hover: hover) and (pointer: fine) { .segmented--glass button:not([aria-pressed="true"]):hover { background: rgba(255, 255, 255, .14); color: #fff; } }
.segmented--glass button:focus-visible { outline: 2px solid #fff; outline-offset: 2px; box-shadow: 0 0 0 2px var(--focus-halo); }
html.is-tv .segmented--glass {
  height: calc(var(--control) + 8px * var(--tvu)); padding: calc(4px * var(--tvu)); overflow: visible;
  background: rgba(30, 30, 36, .72); -webkit-backdrop-filter: none; backdrop-filter: none;
}
html.is-tv .segmented--glass button { padding: 0 calc(36px * var(--tvu)); font-size: var(--fs-callout); }
html.is-tv .segmented--glass button:focus-visible { outline: 4px solid var(--focus); outline-offset: 4px; transform: scale(1.05); }
@media (prefers-reduced-motion: reduce) { html.is-tv .segmented--glass button:focus-visible { transform: none; } }

/* ------------------------------------------------------------ footer credit */
/* TMDB's terms: a small, quiet line under the footer (main.js). */
.footer__credit { flex: 0 0 100%; margin-top: 4px; color: var(--text-3); font-size: 12px; line-height: 1.45; }
html.is-tv .footer__credit { font-size: calc(16px * var(--tvu)); }
