/* 短剧库 — page layouts: search, library grid with overlay poster cards,
   detail, rankings, history, downloads, admin, login. */

/* ------------------------------------------------------------------ search (top bar) */
.search { position: relative; width: min(100%, 520px); min-width: 0; display: flex; align-items: center; height: 40px; padding-left: 14px; border: 1.5px solid transparent; border-radius: var(--radius); background: var(--fill-strong); transition: border-color 150ms ease, background-color 150ms ease; }
.search:focus-within { border-color: var(--accent); background: var(--page-surface); }
.search__icon { width: 18px; height: 18px; color: var(--muted); }
.search__input { flex: 1 1 auto; min-width: 0; height: 100%; padding: 0 8px; border: 0; outline: 0; background: transparent; color: var(--foreground); font-size: 14px; }
.search__input::-webkit-search-cancel-button { display: none; }
.search__input::placeholder { color: var(--faint); }
.search__clear { width: 28px; height: 28px; display: inline-flex; align-items: center; justify-content: center; border: 0; border-radius: var(--radius-pill); background: transparent; color: var(--muted); }
.search__clear .icon { width: 16px; height: 16px; }
.search__submit { position: relative; height: 100%; display: inline-flex; align-items: center; gap: 6px; padding: 0 16px; border: 0; border-radius: 0 var(--radius) var(--radius) 0; background: transparent; color: var(--foreground); font-size: 14px; font-weight: 500; white-space: nowrap; }
.search__submit::before { content: ''; position: absolute; left: 0; top: 11px; bottom: 11px; width: 1px; background: var(--border); }
@media (hover: hover) and (pointer: fine) { .search__submit:hover { color: var(--accent); } .search__clear:hover { color: var(--foreground); } }
.search-field { height: 38px; }
.popover--suggest { padding: 6px; }
.popover__heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 10px; color: var(--muted); font-size: 12px; font-weight: 500; }
.popover-block { display: grid; gap: 10px; }
.option mark { background: transparent; color: var(--accent); font-weight: 600; }
.link-button { border: 0; padding: 0; background: transparent; color: var(--accent); font-size: 12px; font-weight: 500; }

/* ------------------------------------------------------------------ library toolbar */
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-width: 0; }
.toolbar .filter-bar { flex: 1 1 auto; min-width: 0; }
.toolbar__actions { display: flex; flex: none; align-items: center; gap: 8px; }
.toolbar__actions .btn { height: 32px; padding: 0 12px; border-radius: var(--radius-pill); font-size: 13px; background: var(--fill); }
.status-line { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; color: var(--muted); font-size: 13px; line-height: 1.5; }
.status-line.is-error .status-line__text { color: var(--danger); }
.status-line__actions { display: inline-flex; gap: 8px; }
.filter-more { display: inline-flex; align-items: center; gap: 4px; height: 32px; padding: 0 10px; border: 0; border-radius: var(--radius-pill); background: transparent; color: var(--muted); font-size: 13px; font-weight: 500; white-space: nowrap; }
.filter-more .icon { width: 16px; height: 16px; }
.filter-more[aria-expanded="true"] { color: var(--accent); }
@media (hover: hover) and (pointer: fine) { .filter-more:hover { color: var(--foreground); } }
.batch-bar { position: sticky; top: calc(var(--topbar-height) + env(safe-area-inset-top) + 8px); z-index: 4; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 14px; box-shadow: var(--shadow-pop); }
/* short screens (phone landscape): a wrapped sticky bar would be taller than the gap above the tab bar */
@media (max-height: 560px) { .batch-bar { position: static; } }
.batch-bar__count { font-size: 14px; font-weight: 600; }
.batch-bar__actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.batch-bar .toggle { min-height: 34px; padding: 0; align-items: center; }

/* ------------------------------------------------------------------ poster grid */
.grid-host { min-width: 0; }
.drama-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 24px 14px; }
.grid-sentinel { height: 1px; }
.grid-state:empty { display: none; }
.grid-state { margin-top: 8px; border-radius: var(--radius-lg); background: var(--page-surface); }
.drama-card { position: relative; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.drama-card.is-selected .drama-card__poster { box-shadow: 0 0 0 2px var(--accent); }
.drama-card__poster { position: relative; display: block; width: 100%; padding: 0; overflow: hidden; border: 0; border-radius: var(--radius); background: transparent; cursor: pointer; isolation: isolate; }
.poster-art { position: relative; display: block; width: 100%; aspect-ratio: 3 / 4; overflow: hidden; background: var(--fill-strong); }
.poster-art img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: center top; transition: transform 300ms ease; }
@media (hover: hover) and (pointer: fine) { .drama-card__poster:hover .poster-art img { transform: scale(1.04); } }
.poster-art[data-state="failed"] img, .poster-art[data-state="loading"] img { opacity: 0; }
.poster-art[data-state="loaded"] .poster-fallback { visibility: hidden; }
.poster-fallback { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--faint); }
.poster-fallback__char { font-size: 40px; font-weight: 600; line-height: 1; }
/* bottom gradient with play count / heat on the left and episodes on the right */
.drama-card__overlay { position: absolute; z-index: 1; left: 0; right: 0; bottom: 0; display: flex; align-items: flex-end; justify-content: space-between; gap: 6px; min-height: 44px; padding: 16px 8px 7px; background: linear-gradient(transparent, rgba(0, 0, 0, .62)); pointer-events: none; }
.drama-card__overlay .drama-meta__item { color: #fff; font-size: 12px; font-weight: 500; text-shadow: 0 1px 2px rgba(0, 0, 0, .4); }
.drama-card__overlay .drama-meta__item .icon { width: 13px; height: 13px; color: #fff; }
.drama-card__overlay .drama-card__stat .icon { fill: currentColor; stroke-width: 0; }
.drama-card__count { margin-left: auto; }
/* thin accent progress on the poster's bottom edge */
.drama-card__progress { position: absolute; z-index: 2; left: 0; right: 0; bottom: 0; height: 3px; background: rgba(255, 255, 255, .28); }
.drama-card__progress > span { display: block; height: 100%; background: var(--accent); }
.drama-card__select { position: absolute; top: 8px; left: 8px; z-index: 3; display: inline-flex; padding: 3px; border-radius: var(--radius-pill); background: rgba(0, 0, 0, .35); }
.drama-card__select .check { border-color: #fff; }
.drama-card__body { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.drama-card__title { min-width: 0; padding: 0; border: 0; background: transparent; color: var(--foreground); font-size: 14px; font-weight: 500; line-height: 1.4; text-align: left; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; overflow-wrap: anywhere; min-height: 2.8em; }
@media (hover: hover) and (pointer: fine) { .drama-card__title:hover { color: var(--accent); } }
.drama-card__foot { display: flex; align-items: center; justify-content: space-between; gap: 6px; min-width: 0; min-height: 24px; }
.drama-card__download { --icon-button: 24px; background: transparent; color: var(--muted); }
.drama-card__download .icon { width: 16px; height: 16px; }
@media (hover: hover) and (pointer: fine) { .drama-card__download:hover:not(:disabled) { color: var(--accent); background: transparent; } }
.drama-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 10px; min-width: 0; }
.drama-meta__item { display: inline-flex; align-items: center; gap: 4px; min-width: 0; color: var(--muted); font-size: 12px; line-height: 1.3; white-space: nowrap; font-variant-numeric: tabular-nums; }
.drama-meta__item span { overflow: hidden; text-overflow: ellipsis; }
.drama-meta__item .icon { width: 14px; height: 14px; }
.drama-meta__item--watched { color: var(--accent); }

/* ------------------------------------------------------------------ detail */
.modal--detail { width: min(900px, 100%); }
.detail__head { display: grid; grid-template-columns: 180px minmax(0, 1fr); gap: 22px; align-items: start; }
.detail__poster { border-radius: var(--radius); }
.detail__info { display: grid; gap: 14px; min-width: 0; }
.detail__progress { display: inline-flex; align-items: center; gap: 6px; color: var(--accent); font-size: 13px; font-weight: 500; }
.detail__progress .icon { width: 16px; height: 16px; }
.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.fact { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 40px; padding: 8px 12px; border-radius: var(--radius); background: var(--fill); font-size: 12px; }
.fact__label { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }
.fact__label .icon { width: 16px; height: 16px; }
.fact__value { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { display: inline-flex; align-items: center; min-height: 24px; padding: 0 10px; border: 0; border-radius: var(--radius-sm); background: var(--fill); color: var(--muted); font-size: 12px; font-weight: 500; }
.detail__actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.detail__actions .btn--primary { min-width: 120px; }
.detail__section { display: grid; gap: 10px; margin-top: 20px; }
.detail__section-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.detail__synopsis { color: var(--muted); font-size: 14px; line-height: 1.75; white-space: pre-line; }
.range-tabs { display: flex; flex-wrap: wrap; gap: 6px; }
.range-tabs > button { height: 30px; padding: 0 12px; border: 0; border-radius: var(--radius-pill); background: var(--fill); color: var(--muted); font-size: 13px; font-weight: 500; }
.range-tabs > button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }
@media (hover: hover) and (pointer: fine) { .range-tabs > button:hover:not([aria-pressed="true"]) { color: var(--foreground); } }
.episode-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(48px, 1fr)); gap: 8px; }
.episode-cell { height: 40px; min-width: 0; padding: 0; border: 0; border-radius: var(--radius); background: var(--fill); color: var(--foreground); font-size: 14px; font-weight: 500; font-variant-numeric: tabular-nums; }
.episode-cell[aria-current="true"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; box-shadow: inset 0 0 0 1px var(--accent); }
.episode-cell.is-done:not([aria-current="true"]) { color: var(--muted); }
@media (hover: hover) and (pointer: fine) { .episode-cell:hover:not([aria-current="true"]) { background: var(--fill-strong); } }

/* ------------------------------------------------------------------ rankings */
.rank-head { display: grid; gap: 8px; }
.rank-head__row { display: flex; align-items: center; gap: 10px; }
.rank-tabs { flex: 0 1 520px; min-width: 0; }
.rank-card { padding: 6px 4px; }
.rank-list { margin: 0; padding: 0; list-style: none; }
.rank-row { display: grid; grid-template-columns: 44px 66px minmax(0, 1fr) auto; align-items: center; gap: 14px; min-height: 104px; padding: 10px 12px; border-radius: var(--radius); transition: background-color 150ms ease; }
@media (hover: hover) and (pointer: fine) { .rank-row:hover { background: var(--fill); } }
.rank-row__rank { color: var(--muted); font-size: 20px; font-weight: 600; font-style: italic; text-align: center; font-variant-numeric: tabular-nums; }
.rank-row__rank.is-top { color: var(--accent); font-size: 24px; }
.rank-row__art { width: 66px; padding: 0; border: 0; background: transparent; }
.rank-row__poster { border-radius: var(--radius-sm); }
.rank-row__main { display: grid; gap: 6px; min-width: 0; }
.rank-row__title { min-width: 0; padding: 0; border: 0; background: transparent; color: var(--foreground); font-size: 15px; font-weight: 600; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (hover: hover) and (pointer: fine) { .rank-row__title:hover { color: var(--accent); } }
.rank-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; padding: 12px; border-top: 1px solid var(--divider); }
.rank-card > .note--error { padding: 0 12px 12px; }
.icon-btn--row { --icon-button: 32px; }
.icon-btn--danger { color: var(--danger); }

/* ------------------------------------------------------------------ page head (history / downloads) */
.page-head { display: grid; gap: 12px; padding: 4px 0; background: transparent; }
.page-head__row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; }
.page-head__title { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.page-foot { padding: 0 4px; font-size: 12px; }
.list-card { padding: 4px; }
.history-row { grid-template-columns: 56px minmax(0, 1fr) auto; border-radius: var(--radius); border-top: 0; }
.history-row__art { width: 56px; padding: 0; border: 0; background: transparent; }
.history-row__poster { border-radius: var(--radius-sm); }
.history-row__bar { height: 3px; margin-top: 6px; max-width: 280px; }

/* ------------------------------------------------------------------ downloads */
.download-summary { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.download-summary .metric { min-height: 56px; padding: 10px 14px; border-radius: var(--radius); background: var(--page-surface); }
.downloads__dir { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; min-width: 0; font-size: 13px; color: var(--muted); }
.downloads__dir > .icon { width: 16px; height: 16px; }
.downloads__dir-path { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--foreground); font-weight: 500; }
.download-groups { display: grid; gap: 12px; }
.download-group { display: grid; gap: 10px; padding: 14px 16px; }
.download-group__head { display: flex; align-items: center; gap: 12px; min-width: 0; }
.download-group__head .list-main { flex: 1 1 auto; }
.download-group__head .row-actions { flex-wrap: wrap; }
.download-group__progress { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 12px; }
.download-group__progress .note { font-size: 12px; }
.download-group__foot { display: flex; }
.episode-list { border-top: 1px solid var(--divider); }
.episode-row { grid-template-columns: minmax(0, 1fr) auto; min-height: 56px; padding: 8px 4px; }
.episode-row__main { display: flex; align-items: center; gap: 10px; min-width: 0; }
.episode-row__main .list-main { flex: 1 1 auto; gap: 4px; }
.episode-row__title { display: flex; align-items: center; gap: 8px; min-width: 0; }
.list-main .episode-row__title strong { font-size: 14px; }
.episode-row .bar { height: 3px; max-width: 360px; }

/* ------------------------------------------------------------------ admin */
.admin-shell { padding: 4px 20px 20px; min-height: 360px; display: grid; gap: 18px; align-content: start; }
.admin-nav { width: 100%; }
.admin-panel { display: grid; gap: 18px; }
.admin-card { display: grid; gap: 12px; padding-top: 18px; border-top: 1px solid var(--divider); }
.admin-card:first-child { padding-top: 4px; border-top: 0; }
.admin-card__head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; }
.admin-card__title { display: inline-flex; align-items: center; gap: 8px; font-size: 16px; font-weight: 600; }
.admin-card__title .note { font-size: 13px; font-weight: 400; }
.admin-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding-top: 4px; }
.admin-actions .note { flex: 1 1 200px; }
.admin-inline { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; }
.toggle--inline { min-height: 34px; padding: 0; align-items: center; white-space: nowrap; gap: 10px; }
.toggle--inline .toggle__text { order: 0; }
.network-list { border-top: 1px solid var(--divider); }
.emby-summary { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.emby-summary .metric { min-height: 56px; padding: 10px 14px; border-radius: var(--radius); background: var(--fill); }
.emby-summary .note { grid-column: 1 / -1; }
.library-status { display: grid; gap: 12px; }
.library-status__metrics { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.library-status__metrics .metric { min-height: 56px; padding: 10px 14px; border-radius: var(--radius); background: var(--fill); }

/* ------------------------------------------------------------------ account / login */
.account-head { display: grid; gap: 6px; }
.account-head__name { display: flex; align-items: center; gap: 10px; }
.account-head__name strong { font-size: 18px; font-weight: 600; }
.shell--login, .shell--state { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; justify-content: center; padding: max(24px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); background: var(--background); }
:root[data-theme="dark"] .shell--login { background: radial-gradient(circle at 18% 12%, rgba(37, 244, 238, .12), transparent 34%), radial-gradient(circle at 82% 88%, rgba(254, 44, 85, .16), transparent 38%), var(--background); }
:root[data-theme="light"] .shell--login { background: radial-gradient(circle at 18% 12%, rgba(37, 244, 238, .14), transparent 34%), radial-gradient(circle at 82% 88%, rgba(254, 44, 85, .1), transparent 38%), var(--background); }
.state-card { width: min(100%, 480px); margin: 0 auto; }
.login-card { width: min(100%, 400px); margin: 0 auto; display: grid; gap: 18px; padding: 28px 28px 24px; border-radius: var(--radius-xl); box-shadow: var(--shadow-pop); }
.login-card .top-nav { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.login__heading { display: grid; gap: 6px; }
.login__heading .page-title { font-size: 22px; }
.login-card .slider--compact { --selector-height: 34px; }
.login__submit { height: 44px; width: 100%; font-size: 15px; font-weight: 600; }
.login__cookie { display: flex; align-items: flex-start; gap: 8px; font-size: 12px; }
.login__cookie .icon { color: var(--warning); width: 16px; height: 16px; margin-top: 1px; }
.login__guest { color: var(--accent); font-size: 13px; text-decoration: none; justify-self: start; }
.login__footer { display: flex; justify-content: flex-end; }

/* ------------------------------------------------------------------ responsive */
@media (min-width: 1280px) {
  .drama-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); }
}
@media (max-width: 767px) {
  .topbar .search { height: 36px; padding-left: 12px; }
  .topbar .search__submit { padding: 0 12px; }
  .toolbar { flex-direction: column; align-items: stretch; gap: 8px; }
  .toolbar__actions { justify-content: flex-start; overflow-x: auto; scrollbar-width: none; }
  .toolbar__actions .select-trigger--compact { flex: none; }
  .drama-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 10px; }
  .drama-card__title { font-size: 14px; }
  .detail__head { grid-template-columns: 112px minmax(0, 1fr); gap: 14px; }
  .facts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .rank-head__row { flex-wrap: wrap; }
  .rank-tabs { flex-basis: 100%; }
  .rank-row { grid-template-columns: 30px 56px minmax(0, 1fr); grid-template-areas: 'rank art main' 'rank art actions'; gap: 4px 10px; min-height: 0; padding: 10px 6px; }
  .rank-row__rank { grid-area: rank; font-size: 16px; }
  .rank-row__rank.is-top { font-size: 19px; }
  .rank-row__art { grid-area: art; width: 56px; }
  .rank-row__main { grid-area: main; }
  .rank-row .row-actions { grid-area: actions; justify-content: flex-start; }
  .history-row { grid-template-columns: 48px minmax(0, 1fr); grid-template-areas: 'art main' 'art actions'; gap: 4px 10px; }
  .history-row__art { grid-area: art; width: 48px; }
  .history-row .list-main { grid-area: main; }
  .history-row .row-actions { grid-area: actions; justify-content: flex-start; }
  .download-summary { gap: 6px; }
  .download-summary .metric { padding: 8px; flex-direction: column; align-items: flex-start; }
  .download-group { padding: 12px; }
  .download-group__head { flex-wrap: wrap; }
  .download-group__head .list-main { flex-basis: calc(100% - 40px); }
  .download-group__head .row-actions { width: 100%; justify-content: flex-start; }
  .episode-row { grid-template-columns: minmax(0, 1fr); }
  .episode-row .row-actions { justify-content: flex-start; }
  .admin-shell { padding: 0 12px 14px; }
  .admin-nav > button { padding: 0 2px; font-size: 13px; }
  .emby-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .library-status__metrics { grid-template-columns: minmax(0, 1fr); }
  .admin-panel .list-row { grid-template-columns: minmax(0, 1fr); }
  .admin-panel .list-row .row-actions { justify-content: flex-start; }
  .login-card { padding: 22px 18px 18px; }
}
