/* ==========================================================================
   Movie Haus — Mobile-First Tab Screens (Search, Lists, You / Profile)
   Shared layout + screen-specific components. Token-only (zero raw hex).
   Uses css/tokens.css (--bg, --surface-1..3, --text-1..3, --space-1..16, etc.)
   ========================================================================== */

.m-screen {
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  box-sizing: border-box;
  padding-top: var(--safe-t, 0px);
  padding-bottom: calc(var(--tabbar-total, 72px) + var(--space-8));
  padding-inline: max(var(--page-x, 16px), var(--safe-l, 0px))
                  max(var(--page-x, 16px), var(--safe-r, 0px));
  color: var(--text-1);
}

.m-screen__header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-4) 0 var(--space-3);
}

.m-screen__title {
  margin: 0;
  font-size: var(--fs-28);
  line-height: var(--lh-28);
  font-weight: var(--fw-semibold);
  letter-spacing: var(--tracking-tight);
  color: var(--text-1);
}

/* ---------- Shared Primitives Overrides Inside Mobile Screens ---------- */

/* Full-width segmented control with 44px touch targets */
.m-screen .segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  width: 100%;
  gap: 4px;
  padding: 4px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-sizing: border-box;
}

.m-screen .segmented__item {
  min-height: 44px;
  min-width: 44px;
  height: 44px;
  padding: 0 var(--space-3);
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-2);
  font-family: var(--font-sans);
  font-size: var(--fs-14);
  line-height: var(--lh-14);
  font-weight: var(--fw-medium);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.m-screen .segmented__item.is-active,
.m-screen .segmented__item[aria-checked='true'],
.m-screen .segmented__item[aria-selected='true'] {
  background: var(--surface-3);
  color: var(--text-1);
  font-weight: var(--fw-semibold);
  box-shadow: inset 0 0 0 1px var(--border-strong);
}

.m-screen .segmented__count {
  color: var(--text-3);
  font-size: var(--fs-12);
  line-height: var(--lh-12);
  font-variant-numeric: tabular-nums;
}

.m-screen .segmented__item.is-active .segmented__count,
.m-screen .segmented__item[aria-checked='true'] .segmented__count {
  color: var(--accent);
}

/* Section headings: 24px above, 8px below, 14px, --text-2, weight 600 */
.m-screen .list-group {
  margin-top: var(--space-6);
  gap: 0;
}

.m-screen .list-group__title {
  margin: 0 0 var(--space-2);
  padding: 0 var(--space-1);
  color: var(--text-2);
  font-size: var(--fs-14);
  line-height: var(--lh-14);
  font-weight: var(--fw-semibold);
}

.m-screen .list-row {
  min-height: 52px;
  padding: var(--space-2) var(--space-4);
}

/* Stacked full-width segmented rows in You -> Display */
.m-screen .list-row--segmented {
  flex-direction: column;
  align-items: stretch;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
}

.m-screen .list-row--segmented .list-row__end {
  max-width: 100%;
  width: 100%;
}

/* Switch inside list-row: 44x44 hit target with crisp 40x24 pill track in ::before and 18x18 thumb in ::after */
.m-screen .switch {
  position: relative;
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  border: 0;
  border-radius: var(--radius-full);
  background: transparent;
  box-shadow: none;
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  cursor: pointer;
}

.m-screen .switch::before {
  content: '';
  position: absolute;
  top: 10px;
  right: 0;
  width: 42px;
  height: 24px;
  border-radius: var(--radius-full);
  background: var(--surface-3);
  box-shadow: inset 0 0 0 1px var(--border-strong);
  transition: background-color var(--dur-fast) var(--ease),
              box-shadow var(--dur-fast) var(--ease);
}

.m-screen .switch::after {
  content: '';
  position: absolute;
  top: 13px;
  right: 21px;
  left: auto;
  width: 18px;
  height: 18px;
  border-radius: var(--radius-full);
  background: var(--text-2);
  transition: transform var(--dur-fast) var(--ease),
              background-color var(--dur-fast) var(--ease);
}

.m-screen .switch[aria-checked='true'] {
  background: transparent;
  box-shadow: none;
}

.m-screen .switch[aria-checked='true']::before {
  background: var(--accent);
  box-shadow: none;
}

.m-screen .switch[aria-checked='true']::after {
  transform: translateX(18px);
  background: var(--on-accent);
}

/* ==========================================================================
   §7 Search Screen (.m-search)
   ========================================================================== */

.m-search {
  padding-top: var(--safe-t, 0px);
}

.m-search__header {
  position: sticky;
  top: 0;
  z-index: var(--z-sticky, 20);
  min-height: 60px;
  padding: var(--space-2) 0;
  background: var(--bg);
  border-bottom: 1px solid var(--hairline);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.m-search__field {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
}

.m-search__icon {
  position: absolute;
  left: 14px;
  color: var(--text-3);
  pointer-events: none;
  display: inline-flex;
  align-items: center;
}

.m-search__input {
  width: 100%;
  min-height: 44px;
  height: 44px;
  padding: 0 44px 0 42px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-1);
  font-family: var(--font-sans);
  font-size: var(--fs-16);
  line-height: var(--lh-16);
  outline: none;
  box-sizing: border-box;
  transition: border-color var(--dur-fast) var(--ease),
              box-shadow var(--dur-fast) var(--ease),
              background-color var(--dur-fast) var(--ease);
}

.m-search__input::placeholder {
  color: var(--text-3);
}

.m-search__input:focus {
  border-color: var(--accent);
  box-shadow: var(--focus-ring);
  background: var(--surface-2);
}

/* Hide WebKit's native search cancel X so only our 44x44 clear button appears */
.m-search__input::-webkit-search-cancel-button,
.m-search__input::-webkit-search-decoration,
.m-search__input::-webkit-search-results-button,
.m-search__input::-webkit-search-results-decoration {
  display: none !important;
  -webkit-appearance: none;
  appearance: none;
}

.m-search__clear {
  position: absolute;
  right: 0;
  top: 0;
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  border: 0;
  border-radius: var(--radius-full);
  background: transparent;
  color: var(--text-3);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.m-search__clear:hover {
  color: var(--text-1);
}

.m-search__clear[hidden] {
  display: none !important;
}

.m-search__cancel {
  flex: 0 0 auto;
  min-height: 44px;
  min-width: 56px;
  padding: 0 var(--space-3);
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-2);
  font-family: var(--font-sans);
  font-size: var(--fs-14);
  line-height: var(--lh-14);
  font-weight: var(--fw-medium);
  cursor: pointer;
}

.m-search__cancel:hover {
  color: var(--text-1);
  background: var(--surface-2);
}

.m-search__body {
  padding-top: var(--space-1);
}

.m-search__sec {
  margin-top: var(--space-6);
  overflow: hidden;
}

.m-search__sec:first-child {
  margin-top: var(--space-4);
}

.m-search__sec-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
}

.m-search__sec-title {
  margin: 0;
  padding: 0 var(--space-1);
  font-size: var(--fs-14);
  line-height: var(--lh-14);
  font-weight: var(--fw-semibold);
  color: var(--text-2);
}

.m-search__sec-action {
  min-height: 44px;
  min-width: 44px;
  padding: 0 var(--space-2);
  margin: -10px 0;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-2);
  font-family: var(--font-sans);
  font-size: var(--fs-14);
  line-height: var(--lh-14);
  font-weight: var(--fw-medium);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.m-search__sec-action:hover {
  color: var(--text-1);
}

/* Horizontally scrolling Browse-by chip rail: 1 row (no wrap), 8px gap, 16px edge padding */
.m-search__chips {
  display: flex;
  flex-wrap: nowrap;
  overflow-x: auto;
  gap: var(--space-2);
  padding: 2px 0;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.m-search__chips::-webkit-scrollbar {
  display: none;
}

html .m-screen .m-search__chip.chip {
  flex: 0 0 auto;
  min-height: 44px;
  min-width: 44px;
  height: 44px;
  padding: 0 var(--space-4);
  border-radius: var(--radius-full);
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-1);
  font-size: var(--fs-14);
  line-height: var(--lh-14);
  font-weight: var(--fw-medium);
  cursor: pointer;
}

.m-search__chip.chip:hover {
  background: var(--surface-2);
  border-color: var(--border-strong);
}

/* 2-column Genres grid with padded tiles and 8px gap */
.m-search__genres {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-2);
}

.m-search__genre {
  min-height: 52px;
  min-width: 44px;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-1);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  cursor: pointer;
  text-align: left;
  font-family: var(--font-sans);
  box-sizing: border-box;
  transition: background-color var(--dur-fast) var(--ease),
              border-color var(--dur-fast) var(--ease);
}

.m-search__genre:hover {
  background: var(--surface-2);
  border-color: var(--border-strong);
}

.m-search__genre-name {
  font-size: var(--fs-14);
  line-height: var(--lh-14);
  font-weight: var(--fw-medium);
  color: var(--text-1);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.m-search__genre-count {
  font-size: var(--fs-12);
  line-height: var(--lh-12);
  font-variant-numeric: tabular-nums;
  color: var(--text-3);
  flex-shrink: 0;
}

/* Instant result rows & Recent search rows */
.m-search__list {
  display: flex;
  flex-direction: column;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.m-search__row {
  width: 100%;
  min-height: 56px;
  min-width: 44px;
  padding: var(--space-2) var(--space-4);
  border: 0;
  border-bottom: 1px solid var(--hairline);
  background: transparent;
  color: var(--text-1);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  text-align: left;
  cursor: pointer;
  font-family: var(--font-sans);
  box-sizing: border-box;
  transition: background-color var(--dur-fast) var(--ease);
}

.m-search__row:last-child {
  border-bottom: 0;
}

.m-search__row:hover,
.m-search__row.is-active {
  background: var(--surface-2);
}

.m-search__row--see-all {
  color: var(--accent);
}

.m-search__row--see-all .m-search__row-title {
  color: var(--accent);
  font-weight: var(--fw-semibold);
}

.m-search__icon-box {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-2);
  flex: 0 0 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.m-search__row--see-all .m-search__icon-box {
  background: var(--accent-soft);
  border-color: transparent;
  color: var(--accent);
}

.m-search__avatar {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  background: var(--surface-3);
  border: 1px solid var(--border);
  color: var(--text-1);
  flex: 0 0 40px;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: var(--fs-14);
  line-height: var(--lh-14);
  font-weight: var(--fw-semibold);
  position: relative;
}

.m-search__avatar img {
  width: 40px;
  height: 40px;
  object-fit: cover;
  display: block;
}

.m-search__poster {
  width: 40px;
  height: 60px;
  border-radius: var(--radius-sm);
  background: var(--surface-3);
  border: 1px solid var(--border);
  color: var(--text-3);
  flex: 0 0 40px;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: var(--fs-12);
  line-height: var(--lh-12);
}

.m-search__poster img {
  width: 40px;
  height: 60px;
  object-fit: cover;
  display: block;
}

.m-search__row-body {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.m-search__row-title {
  font-size: var(--fs-16);
  line-height: var(--lh-16);
  font-weight: var(--fw-medium);
  color: var(--text-1);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.m-search__row-sub {
  font-size: var(--fs-12);
  line-height: var(--lh-12);
  color: var(--text-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.m-search__row-trail {
  flex: 0 0 auto;
  color: var(--text-3);
  font-size: var(--fs-12);
  line-height: var(--lh-12);
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
}

/* ==========================================================================
   §10 Lists Screen (.m-lists)
   ========================================================================== */

.m-lists__tabs {
  margin-top: var(--space-2);
}

.m-lists__toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin: var(--space-4) 0;
  flex-wrap: wrap;
}

.m-lists__play.btn {
  min-height: 44px;
  min-width: 44px;
  height: 44px;
  padding: 0 var(--space-4);
  border-radius: var(--radius-full);
  font-size: var(--fs-14);
  line-height: var(--lh-14);
  font-weight: var(--fw-semibold);
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}

/* Quiet surface for disabled Play All button */
.m-lists__play.btn:disabled,
.m-lists__play.btn[disabled] {
  background: var(--surface-2);
  color: var(--text-disabled);
  border-color: transparent;
  opacity: 1;
  cursor: default;
}

.m-lists__sort-btn.btn {
  min-height: 44px;
  min-width: 44px;
  height: 44px;
  padding: 0 var(--space-4);
  border-radius: var(--radius-full);
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-1);
  font-size: var(--fs-14);
  line-height: var(--lh-14);
  font-weight: var(--fw-medium);
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}

.m-lists__sort-btn.btn:hover {
  background: var(--surface-2);
  border-color: var(--border-strong);
}

.m-lists__sort-prefix {
  color: var(--text-2);
}

.m-lists__nudge {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-4);
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.m-lists__nudge-body {
  flex: 1 1 auto;
  min-width: 0;
}

.m-lists__nudge-title {
  margin: 0;
  font-size: var(--fs-14);
  line-height: var(--lh-14);
  font-weight: var(--fw-semibold);
  color: var(--text-1);
}

.m-lists__nudge-sub {
  margin: 2px 0 0;
  font-size: var(--fs-12);
  line-height: var(--lh-12);
  color: var(--text-2);
}

.m-lists__nudge-actions {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  flex-shrink: 0;
}

.m-lists__nudge-cta {
  min-height: 44px;
  min-width: 44px;
  padding: 0 var(--space-3);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--accent);
  font-family: var(--font-sans);
  font-size: var(--fs-14);
  line-height: var(--lh-14);
  font-weight: var(--fw-semibold);
  cursor: pointer;
}

.m-lists__nudge-dismiss {
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-3);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

/* Ensure 3-column grid on phone portrait and >=12px text / no tiny hover buttons */
.m-lists .card__actions {
  display: none !important;
}

.m-lists .card__badge,
.m-lists .card__sub,
.m-lists .card__title {
  font-size: var(--fs-12);
  line-height: var(--lh-12);
}

.m-lists .empty-state {
  padding: var(--space-12) var(--space-4);
}

@media (max-width: 599px) {
  .m-lists .grid,
  .m-lists .poster-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    gap: 14px 10px;
  }
}

/* ==========================================================================
   §11 You / Profile Screen (.m-profile)
   ========================================================================== */

.m-profile__account {
  width: 100%;
  min-height: 76px;
  min-width: 44px;
  padding: var(--space-3) var(--space-4);
  margin: var(--space-2) 0 var(--space-6);
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  color: var(--text-1);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  text-align: left;
  cursor: pointer;
  font-family: var(--font-sans);
  box-sizing: border-box;
  transition: background-color var(--dur-fast) var(--ease),
              border-color var(--dur-fast) var(--ease);
}

.m-profile__account:hover {
  background: var(--surface-2);
  border-color: var(--border-strong);
}

.m-profile__avatar {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-full);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--accent);
  flex: 0 0 48px;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: var(--fs-16);
  line-height: var(--lh-16);
  font-weight: var(--fw-semibold);
}

.m-profile__avatar img {
  width: 48px;
  height: 48px;
  object-fit: cover;
  display: block;
}

.m-profile__account-body {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.m-profile__account-title {
  font-size: var(--fs-16);
  line-height: var(--lh-16);
  font-weight: var(--fw-semibold);
  color: var(--text-1);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.m-profile__account-sub {
  font-size: var(--fs-12);
  line-height: var(--lh-12);
  color: var(--text-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.m-profile__sync-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  background: var(--surface-2);
  color: var(--text-2);
  font-size: var(--fs-12);
  line-height: var(--lh-12);
  font-weight: var(--fw-medium);
  flex-shrink: 0;
}

.m-profile__sync-badge[data-status='synced'] {
  color: var(--seen);
}

.m-profile__sync-badge[data-status='error'] {
  color: var(--danger);
}

.m-profile__danger {
  width: 100%;
  min-height: 52px;
  min-width: 44px;
  padding: var(--space-3) var(--space-4);
  margin: var(--space-6) 0 var(--space-4);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--danger);
  font-family: var(--font-sans);
  font-size: var(--fs-16);
  line-height: var(--lh-16);
  font-weight: var(--fw-semibold);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  box-sizing: border-box;
  transition: background-color var(--dur-fast) var(--ease);
}

.m-profile__danger:hover {
  background: var(--surface-2);
}

.m-profile__footer {
  margin-top: var(--space-6);
  padding-top: var(--space-4);
  border-top: 1px solid var(--hairline);
  color: var(--text-3);
  font-size: var(--fs-12);
  line-height: var(--lh-14);
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.m-profile__footer-meta {
  font-size: var(--fs-12);
  line-height: var(--lh-12);
  color: var(--text-2);
  font-weight: var(--fw-medium);
}
