/* Horizontal Settings Bar - compact horizontal scrolling settings with dropdowns
 * Each setting type is a button that opens a dropdown menu
 * Similar to overlay tag bar but with dropdown functionality
 */

/* Settings Bar Container */
.horizontal-settings-bar {
  position: relative;
  background: transparent;
  border-bottom: none;
  padding: 6px 0;
  position: sticky;
  top: 0;
  z-index: 10001;
}

/* Horizontal Scrollable Button Container */
.settings-scroll-container {
  display: flex;
  overflow-x: auto;
  gap: 8px;
  padding: 4px 10px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.settings-scroll-container::-webkit-scrollbar {
  display: none;
}

/* Setting Button Wrapper (contains button + dropdown) */

/* Setting Button */
.setting-button {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--mobile-surface, var(--bg-primary));
  border: 1px solid var(--mobile-border, var(--border-color));
  color: var(--mobile-text-primary, var(--text-primary));
  padding: 6px 12px;
  border-radius: 16px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
  flex-shrink: 0;
  min-width: fit-content;
}

.setting-button:hover {
  background: var(--mobile-surface-hover, var(--bg-hover));
  border-color: var(--mobile-accent, var(--accent-color));
}

.setting-button.active {
  background: var(--mobile-accent, var(--accent-color));
  color: white;
  border-color: var(--mobile-accent, var(--accent-color));
}

.setting-button i {
  font-size: 11px;
}

.setting-button .setting-value {
  font-size: 11px;
  opacity: 0.8;
}

/* Dropdown Menu */
.dropdown-menu {
  position: fixed;
  background: var(--mobile-surface, var(--bg-secondary));
  border: 1px solid var(--mobile-border, var(--border-color));
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  min-width: 200px;
  max-width: 320px;
  max-height: 400px;
  overflow-y: auto;
  display: none;
  z-index: 20000;
}

/* iOS Safari draws an inline `<video>` in a native compositing layer, and that
   layer can paint above web content that has not itself been promoted to a layer
   — z-index says nothing about it. A 3D transform gives an open dropdown its own
   composited layer so the ordering is settled in the compositor rather than only
   in paint order. It does not move the element: the dropdowns are positioned by
   `style.left`/`style.top` (horizontal_settings_controller.js#positionDropdown on
   /videos, `toggleSocialDropdown` in social_feed/index.html.erb on /social_feed),
   and a transform composes on top of that without changing it.

   Applied on `.open` only, so nothing is promoted while it is `display: none`.

   ⚠️ This half of the iPhone dropdown fix is REASONED, NOT OBSERVED — no iOS
   device here, and Playwright's WebKit will not launch on this host. The other
   half, and the one with a mechanism that can be pointed at in the CSS, is the
   header's backdrop-filter — see `.mobile-header::before` in
   vertical_video_scroll.css. */
.dropdown-menu.open {
  display: block;
  /* `will-change: transform` is the declaration that actually asks for the layer;
     the 3D transform is the older incantation, kept because WebKit has honoured
     it for far longer. ⚠️ Neither can be confirmed from `getComputedStyle`: a
     zero 3D translate is 2D-representable, so Chromium resolves both forms to
     `matrix(1, 0, 0, 1, 0, 0)` (measured). Promotion is a compositor decision,
     not a computed value — check it in a devtools layer view, not in the CSSOM. */
  transform: translate3d(0, 0, 0);
  -webkit-transform: translate3d(0, 0, 0);
  will-change: transform;
}

@keyframes dropdownSlideIn {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.dropdown-content {
  padding: 8px;
}

/* Prevent clicks inside dropdown from bubbling to button */
.dropdown-menu {
  pointer-events: auto;
}

.dropdown-menu * {
  pointer-events: auto;
}

/* Dropdown Search */
.dropdown-search {
  padding: 8px;
  border-bottom: 1px solid var(--mobile-border, var(--border-color));
  position: sticky;
  top: 0;
  background: var(--mobile-surface, var(--bg-secondary));
  z-index: 1;
}

.dropdown-search-input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--mobile-border, var(--border-color));
  border-radius: 8px;
  background: var(--mobile-background, var(--bg-primary));
  color: var(--mobile-text-primary, var(--text-primary));
  font-size: 13px;
  outline: none;
  transition: border-color 0.2s ease;
}

.dropdown-search-input:focus {
  border-color: var(--mobile-accent, var(--accent-color));
}

.dropdown-items-container {
  max-height: 320px;
  overflow-y: auto;
}

/* Dropdown Items */
.dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 10px 12px;
  background: transparent;
  border: none;
  color: var(--mobile-text-primary, var(--text-primary));
  text-align: left;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s ease;
  font-size: 14px;
}

.dropdown-item:hover {
  background: var(--mobile-surface-hover, var(--bg-hover));
}

.dropdown-item.active {
  background: var(--mobile-accent, var(--accent-color));
  color: white;
}

.dropdown-item i {
  font-size: 14px;
  width: 16px;
  text-align: center;
}

/* Checkbox Items */
.dropdown-checkbox {
  display: flex;
  align-items: center;
  padding: 8px 12px;
  cursor: pointer;
  border-radius: 6px;
  transition: background 0.2s ease;
}

.dropdown-checkbox:hover {
  background: var(--mobile-surface-hover, var(--bg-hover));
}

.dropdown-checkbox input[type="checkbox"] {
  margin-right: 8px;
  cursor: pointer;
}

.dropdown-checkbox i {
  font-size: 14px;
  width: 16px;
  margin-right: 8px;
  text-align: center;
}

.dropdown-checkbox span {
  font-size: 14px;
  color: var(--mobile-text-primary, var(--text-primary));
}

/* Quick Topics shortcuts (curated SuggestedTopic buttons) in the Tags dropdown */
.topics-shortcuts {
  padding: 8px 0;
  border-bottom: 1px solid var(--mobile-border);
}

.topics-shortcuts-label {
  display: block;
  margin-bottom: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--mobile-text-secondary, var(--text-secondary));
  text-transform: uppercase;
}

.topics-shortcuts-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.topic-chip-btn {
  padding: 5px 12px;
  border-radius: 14px;
  border: 1px solid var(--mobile-border, var(--border-color));
  background: var(--mobile-background, var(--bg-primary));
  color: var(--mobile-text-primary, var(--text-primary));
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.topic-chip-btn:hover {
  border-color: var(--mobile-accent, var(--accent-color));
}

.topic-chip-btn.active {
  background: var(--mobile-accent, var(--accent-color));
  border-color: var(--mobile-accent, var(--accent-color));
  color: #fff;
}

/* Tags Section in Dropdown */
.tags-section {
  padding: 8px 0;
  border-bottom: 1px solid var(--mobile-border);
}

.tags-section:last-child {
  border-bottom: none;
}

/* Text Input Section */
.text-input-section {
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.text-input-section label {
  font-size: 12px;
  font-weight: 600;
  color: var(--mobile-text-secondary, var(--text-secondary));
  text-transform: uppercase;
}

.text-input-section input {
  width: 100%;
}

.text-input-section button {
  align-self: flex-start;
}

.tags-header {
  margin-bottom: 6px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.tags-header label {
  font-size: 12px;
  font-weight: 600;
  color: var(--mobile-text-secondary, var(--text-secondary));
  text-transform: uppercase;
}

.tags-logic-toggle {
  padding: 4px 10px;
  border-radius: 12px;
  border: 1px solid var(--mobile-border, var(--border-color));
  background: var(--mobile-background, var(--bg-primary));
  color: var(--mobile-text-primary, var(--text-primary));
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s ease;
  letter-spacing: 0.5px;
}

.tags-logic-toggle:hover {
  background: var(--mobile-accent, var(--accent-color));
  color: white;
  border-color: var(--mobile-accent, var(--accent-color));
}

.tags-logic-toggle[data-logic="and"] {
  background: rgba(76, 175, 80, 0.2);
  color: #4caf50;
  border-color: #4caf50;
}

.tags-logic-toggle[data-logic="and"]:hover {
  background: #4caf50;
  color: white;
}

.tags-logic-toggle[data-logic="or"] {
  background: rgba(33, 150, 243, 0.2);
  color: #2196f3;
  border-color: #2196f3;
}

.tags-logic-toggle[data-logic="or"]:hover {
  background: #2196f3;
  color: white;
}

.selected-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 6px;
  min-height: 24px;
}

.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 10px;
  font-size: 12px;
  background: var(--mobile-surface-hover, var(--bg-hover));
  color: var(--mobile-text-primary, var(--text-primary));
}

.tag-chip.include {
  background: rgba(76, 175, 80, 0.2);
  color: #4caf50;
}

.tag-chip.exclude {
  background: rgba(244, 67, 54, 0.2);
  color: #f44336;
}

.tag-chip button {
  background: none;
  border: none;
  color: inherit;
  font-size: 14px;
  cursor: pointer;
  padding: 0;
  line-height: 1;
  opacity: 0.7;
}

.tag-chip button:hover {
  opacity: 1;
}

.tag-input {
  width: 100%;
  padding: 6px 10px;
  border: 1px solid var(--mobile-border, var(--border-color));
  border-radius: 8px;
  background: var(--mobile-background, var(--bg-primary));
  color: var(--mobile-text-primary, var(--text-primary));
  font-size: 13px;
  outline: none;
}

.tag-input:focus {
  border-color: var(--mobile-accent, var(--accent-color));
}

.tag-suggestions {
  margin-top: 4px;
  background: var(--mobile-background, var(--bg-primary));
  border: 1px solid var(--mobile-border, var(--border-color));
  border-radius: 6px;
  max-height: 150px;
  overflow-y: auto;
}

.tag-suggestion {
  padding: 6px 10px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.2s ease;
  color: var(--mobile-text-primary, var(--text-primary));
}

.tag-suggestion:hover {
  background: var(--mobile-surface-hover, var(--bg-hover));
}

/* Apply Button in Dropdown */
.apply-btn {
  width: 100%;
  margin-top: 8px;
  padding: 8px 12px;
  background: var(--mobile-accent, var(--accent-color));
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s ease;
}

.apply-btn:hover {
  opacity: 0.9;
}

/* Empty Message */
.empty-message {
  padding: 20px;
  text-align: center;
  color: var(--mobile-text-secondary, var(--text-secondary));
  font-size: 13px;
}

/* On mobile the long select value (e.g. full sort label / podcast title) makes
   buttons very wide. Hide it and rely on the .active highlight to show the
   setting is non-default. Short counts like "(2)" stay visible. */
@media (max-width: 768px) {
  .setting-button .setting-value-text {
    display: none;
  }
}

/* Narrow viewports: the bar SCROLLS sideways, and SAYS SO.
   ------------------------------------------------------------------
   History. Trello 304 was "top bar not working": at a 414px viewport the button
   set is ~1026px wide on /videos and ~735px on /social_feed against a 358px
   container, so more than half of it — Min Likes, Date, Sort, Clear — is
   off-screen at any moment, and nothing on screen said so. The first fix
   (054c4fd) wrapped the bar. That reached every control but cost four rows on
   /videos and pushed the mobile header from 127px to 249px, roughly a quarter of
   the screen before the video starts. The owner asked for the scroll back.

   So: scroll restored, plus the affordance the wrap was standing in for.

   1. `flex-wrap: nowrap` — explicit, so it survives anyone re-adding a wrap rule.

   2. Edge fades on .horizontal-settings-bar::before/::after (below). Content
      visibly dissolves at the edge it continues past, which is what tells a user
      there is more without them having to discover it by swiping.

   3. `padding-inline` is deliberately the SAME width as those fades
      (--settings-bar-fade-w). At either end of the scroll range the first/last
      button therefore sits clear of its own fade, so a fade is only ever drawn
      over content that really does continue. That is what makes a static
      gradient behave like a direction-aware one, with no JS and no
      scroll-driven-animation support to depend on (which is the point — none of
      it can be tested against Safari on this host).

   4. `scroll-snap-type: x proximity` + `scroll-snap-align: start` on the items,
      so a swipe settles with whole buttons in view instead of a half-clipped one
      (a half-clipped button is what reads as "cut off" rather than "scrollable").

   5. The scroll region is inset from the two screen edges (`margin-inline`) and
      carries `overscroll-behavior-x: contain`. iOS Safari's back/forward swipe
      starts in roughly the outer ~16px of the screen; a horizontal scroller that
      reaches the edge competes with it. Inset, a touch that starts in that strip
      lands on the non-scrolling bar and Safari gets its gesture unambiguously,
      and `overscroll-behavior` stops a swipe that runs off the end of the bar
      from chaining outwards. ⚠️ This REDUCES the contention, it does not remove
      it — a horizontal drag that starts inside the bar is still a horizontal
      drag inside a `position: fixed` header. Not verified on a device.

   The 768px cut-off matches the rest of this file's mobile block. */
:root {
  --settings-bar-fade-w: 16px;  /* width of each edge fade == the scroller's inline padding */
  --settings-bar-inset: 12px;   /* the scroller's margin: how far in from the bar's edges it starts */
}

@media (max-width: 768px) {
  .settings-scroll-container {
    flex-wrap: nowrap;
    margin-inline: var(--settings-bar-inset);
    padding-inline: var(--settings-bar-fade-w);
    scroll-snap-type: x proximity;
    scroll-padding-inline: var(--settings-bar-fade-w);
    overscroll-behavior-x: contain;
  }

  /* Direct children, because the two bars nest differently: /videos appends
     bare .setting-button elements, the social feed wraps each in a
     .social-filter-wrapper alongside its dropdown. */
  .settings-scroll-container > * {
    scroll-snap-align: start;
  }

  /* The fades. Drawn on the bar, NOT as a mask on the scroll container:
     mask-image would make the container a containing block for its
     `position: fixed` descendants, and on the social feed the filter dropdowns
     ARE `position: fixed` descendants of it — they would be clipped to a ~34px
     tall box. That is the same trap as the header's backdrop-filter; see
     vertical_video_scroll.css `.mobile-header`. */
  .horizontal-settings-bar::before,
  .horizontal-settings-bar::after {
    content: "";
    position: absolute;
    top: 0;
    bottom: 0;
    width: var(--settings-bar-fade-w);
    pointer-events: none;
    z-index: 2;
  }

  .horizontal-settings-bar::before {
    left: var(--settings-bar-inset);
    background: linear-gradient(
      to right,
      var(--settings-bar-fade, var(--mobile-bg, #0d1824)),
      transparent
    );
  }

  .horizontal-settings-bar::after {
    right: var(--settings-bar-inset);
    background: linear-gradient(
      to left,
      var(--settings-bar-fade, var(--mobile-bg, #0d1824)),
      transparent
    );
  }

  /* Inside the mobile header the bar is NOT on the themed page background: the
     header's own gradient has already fallen to ~0.15 alpha by the time it
     reaches the settings row, so what is actually behind the bar there measures
     rgb(3, 6, 9) — near-black — on both feeds. Fading to --mobile-bg (#0d1824)
     there paints a *lighter* rectangle over the empty padding at rest, which
     reads as a rendering glitch; fading to black is invisible at rest and still
     dissolves a pill as it scrolls under. Elsewhere (overlay grid, money glitch
     and training samples render the bar outside the header) --mobile-bg is
     correct and follows the light/dark theme. */
  .mobile-header .horizontal-settings-bar {
    --settings-bar-fade: #000;
  }
}

/* Mobile Responsive */
@media (max-width: 480px) {
  .horizontal-settings-bar {
    padding: 5px 0;
  }

  .settings-scroll-container {
    gap: 6px;
    /* Block padding only — the inline padding is the fade width and is set in
       the scroll block above. Overriding it here would let a button come to rest
       under its own fade at the end of the scroll range. */
    padding-block: 3px;
  }

  .setting-button {
    padding: 5px 10px;
    font-size: 12px;
    border-radius: 14px;
  }

  .dropdown-menu {
    min-width: 180px;
    max-width: 90vw;
    max-height: 60vh;
  }

  .dropdown-item {
    padding: 8px 10px;
    font-size: 13px;
  }
}

/* Desktop Styles */
@media (min-width: 769px) {
  .horizontal-settings-bar {
    padding: 8px 0;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    top: 60px; /* Position below navbar which is 60px tall */
  }

  /* Only on desktop pages with navbar */
  body:has(.desktop-video-app) .horizontal-settings-bar {
    top: 60px;
  }

  .settings-scroll-container {
    gap: 10px;
    padding: 6px 24px;
    justify-content: flex-start;
  }

  .setting-button {
    padding: 8px 16px;
    font-size: 14px;
    border-radius: 18px;
  }

  .setting-button i {
    font-size: 13px;
  }

  .setting-button .setting-value {
    font-size: 12px;
  }

  .dropdown-menu {
    min-width: 240px;
    max-width: 400px;
  }

  .dropdown-item {
    padding: 12px 14px;
    font-size: 15px;
  }

  .dropdown-checkbox {
    padding: 10px 14px;
  }

  .dropdown-checkbox span {
    font-size: 15px;
  }
}

/* Dark mode adjustments */
@media (prefers-color-scheme: dark) {
  .dropdown-menu {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
  }
}

/* Social Feed Filter Bar */
.social-feed-filter-bar {
  position: sticky;
  top: 0;
  z-index: 200;
}

body:has(.desktop-video-app) .social-feed-filter-bar {
  top: 0;
}

.social-filter-wrapper {
  position: relative;
  flex-shrink: 0;
}

.social-filter-dropdown {
  position: fixed;
  z-index: 20000;
}

.social-filter-presets {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin: 4px 0;
}

.social-preset-btn {
  padding: 4px 10px;
  border-radius: 12px;
  border: 1px solid var(--mobile-border, var(--border-color));
  background: var(--mobile-background, var(--bg-primary));
  color: var(--mobile-text-primary, var(--text-primary));
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.social-preset-btn:hover,
.social-preset-btn.active {
  background: var(--mobile-accent, var(--accent-color));
  color: white;
  border-color: var(--mobile-accent, var(--accent-color));
}

/* Topics (tag) filter list inside the social/viral feed filter bar */
.social-tag-list {
  max-height: 240px;
  overflow-y: auto;
}

.social-tag-option span:first-of-type {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.social-tag-count {
  margin-left: 8px;
  font-size: 11px;
  opacity: 0.6;
  flex-shrink: 0;
}

/* Separates the tags you've picked from the searchable list below them */
.social-tag-selected:not(:empty) {
  border-bottom: 1px solid var(--border-color, rgba(128, 128, 128, 0.25));
  margin-bottom: 4px;
  padding-bottom: 4px;
}

.social-tag-hint {
  padding: 6px 10px;
  font-size: 11px;
  opacity: 0.55;
  line-height: 1.4;
}

.social-clear-btn {
  color: #e74c3c !important;
  border-color: rgba(231, 76, 60, 0.4) !important;
  text-decoration: none;
}

.social-clear-btn:hover {
  background: rgba(231, 76, 60, 0.12) !important;
  border-color: #e74c3c !important;
}

/* Delete All Clips danger button */
.delete-all-clips-btn {
  border-color: rgba(231, 76, 60, 0.4) !important;
  color: #e74c3c !important;
}

.delete-all-clips-btn:hover {
  background: rgba(231, 76, 60, 0.15) !important;
  border-color: #e74c3c !important;
}
