@layer components {
  .cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(320px, 100%), 1fr));
    gap: 1rem;
    margin-bottom: 4rem;

    @media (max-width: 480px) {
      grid-template-columns: 1fr;
      gap: 0.6rem;
    }
  }

  .card {
    position: relative;
    background: white;
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 5px 0 5px 5px;
    display: flex;
    align-items: center;
    gap: 8px;
  }

  .card-transparent {
    position: relative;
    padding: 5px 0 5px 5px;
    display: flex;
    align-items: center;
    gap: 8px;
  }

  .card:hover {
    border: 1px solid #a9a4a4;
  }

  .card-content {
    flex: 1;
    min-width: 0;
    margin-right: 0;
    display: flex;
    flex-direction: column;
    & > a {
      display: flex;
      align-items: center;

    }
  }

  .card-content-subtitle {
    font-size: .8em;
    color: #a0a0a0;
    font-style: italic;
  }

  .card-actions-dropdown {
    --dropdown-menu-left: auto;
    --dropdown-menu-right: -10px;
  }

  /* While this card's menu is open, lift its stacking context above the
     sibling cards (whose favorite/menu controls sit at z-index 2) so the
     next card's three-dots can't show through the open menu. Also clears
     the footer nav (z-index 40). Kept as two rules on purpose: :popover-open
     is unknown to Safari < 17, and an invalid selector in a shared list
     would drop the whole rule — breaking the .show fallback on old iPads. */
  .card-actions-dropdown:has(.dropdown-menu.show) {
    position: relative;
    z-index: 60;
  }

  .card-actions-dropdown:has(.dropdown-menu:popover-open) {
    position: relative;
    z-index: 60;
  }

  /* View + sort controls */
  .view-and-sort {
    display: flex;
    align-items: center;
    gap: 0.5rem;
  }

  .view-and-sort .list-filter {
    order: 20;
  }

  .sort-dropdown {
    --icon-size: 1.25rem;
    --dropdown-menu-left: auto;
    --dropdown-menu-right: 0;
  }

  .channel-dropdown {
    --icon-size: 1.25rem;
    --dropdown-menu-left: auto;
    --dropdown-menu-right: 0;
  }

  .sort-toggle-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    height: 2.5rem;
    padding: 0 0.75rem;
    border-radius: 6px;
    color: #6b7280;
    font-size: 0.9rem;
    white-space: nowrap;
    transition: background-color 0.15s ease, color 0.15s ease;
  }

  .sort-toggle-btn:hover {
    background-color: #f0f0f0;
  }

  .sort-toggle-label {
    line-height: 1;
  }

  .channel-toggle-btn {
    max-width: min(18rem, 45vw);
  }

  .channel-toggle-btn .sort-toggle-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* Favorites filter switch */
  .favorites-switch {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    height: 2.5rem;
    margin: 0;
    white-space: nowrap;
  }

  .favorites-switch .switch-control {
    margin: 0;
  }

  .favorites-switch__label {
    color: #6b7280;
    font-size: 0.9rem;
    font-weight: 400;
    line-height: 1;
    margin: 0;
    white-space: nowrap;
    cursor: pointer;
  }

  /* View toggle */
  .view-toggle {
    --icon-size: 2rem;
    display: flex;
    gap: 0.25rem;
  }

  .view-toggle-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 6px;
    color: #6b7280;
    transition: background-color 0.15s ease, color 0.15s ease;
  }

  .view-toggle-btn:hover {
    background-color: #f0f0f0;
  }

  .view-toggle-btn.is-active {
    color: #0f766e;
  }

  @media (max-width: 760px) {
    .view-and-sort {
      display: grid;
      grid-template-columns: auto auto minmax(0, 1fr) auto;
      flex: 1 1 100%;
      min-width: 0;
      align-items: center;
      row-gap: 0.3rem;
      column-gap: 0.2rem;
    }

    .view-and-sort .list-filter {
      order: 1;
      grid-column: 1 / -1;
      height: 2.25rem;
      min-width: 0;
      padding: 0 0.55rem;
    }

    .view-toggle {
      order: 2;
      grid-column: 1;
    }

    .sort-dropdown {
      order: 3;
      grid-column: 2;
    }

    .favorites-switch {
      order: 4;
      grid-column: 3;
      min-width: 0;
    }

    .channel-dropdown {
      order: 5;
      grid-column: 4;
    }

    .view-toggle {
      --icon-size: 1.45rem;
      gap: 0.1rem;
    }

    .view-toggle-btn {
      width: 1.9rem;
      height: 2rem;
      padding: 0;
      justify-content: center;
    }

    .sort-toggle-btn {
      height: 2rem;
      padding: 0 0.25rem;
      gap: 0.2rem;
      font-size: 0.78rem;
    }

    .favorites-switch {
      gap: 0.25rem;
      height: 2rem;
    }

    .favorites-switch__label {
      min-width: 0;
      overflow: hidden;
      text-overflow: ellipsis;
      font-size: 0.78rem;
    }

    .favorites-switch .switch-control {
      --switch-width: 1.9rem;
      --switch-height: 1.1rem;
      --switch-knob-size: 0.8rem;
      --switch-knob-offset: 0.12rem;
      --switch-knob-translate: 0.78rem;
      flex-shrink: 0;
    }

    .channel-toggle-btn {
      width: 1.85rem;
      max-width: none;
      padding: 0;
      justify-content: center;
    }

    .channel-dropdown .sort-toggle-label {
      position: absolute;
      inline-size: 1px;
      block-size: 1px;
      margin: -1px;
      padding: 0;
      overflow: hidden;
      clip: rect(0 0 0 0);
      white-space: nowrap;
      border: 0;
    }

    .view-and-sort .list-filter-input {
      width: 100%;
      min-width: 0;
      font-size: 0.85rem;
    }
  }
}
