/* ══════════════════════════════════════════════════════════════
   DESKTOP FILTER SIDEBAR + SECONDARY PANEL (shared)

   Used by results.html AND terminal.html. On viewports ≥1100px
   a fixed left sidebar appears with Home, Creative Search pill,
   Sort dropdown, filter categories, + Add criteria, Clear all.

   Page-specific wiring (what happens when a filter is clicked)
   lives in sidebar.js; this file is pure presentation.
   ══════════════════════════════════════════════════════════════ */

/* Default (mobile/tablet): layout wrapper collapses to a normal block flow —
   sidebar, secondary panel, and collapse controls are all hidden. The
   desktop sidebar is a ≥1100px-only feature — on mobile the existing
   picker.js drum-roller handles filter selection instead. */
.filterSidebar,
.filterPanel,
.sidebarShow,
.sidebarToggle { display: none !important; }

@media (min-width: 1100px) {
  /* Sidebar width scales fluidly with the viewport — narrower on small
     desktops (~200px), wider on big monitors (~260px). The main content
     area uses var(--sidebar-w) for its left padding so cards recover the
     space as the sidebar shrinks. Pages set their own left padding using
     this variable. */
  :root {
    --sidebar-w: clamp(200px, 14vw, 260px);
  }

  /* ── Sidebar (fixed to viewport left edge) ─────────────────── */
  .filterSidebar {
    display: block !important;
    position: fixed;
    top: var(--header-h, 56px);
    left: 0;
    width: var(--sidebar-w);
    height: calc(100vh - var(--header-h, 56px));
    overflow-y: auto;
    scrollbar-width: thin;
    background: var(--bg, #ffffff);
    z-index: 50;
  }
  .filterSidebar::-webkit-scrollbar { width: 6px; }
  .filterSidebar::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.12); border-radius: 3px; }

  .filterSidebarInner {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: clamp(10px, 0.85vw, 14px) clamp(8px, 0.72vw, 12px);
  }

  /* ── Collapse toggle (inside sidebar) ─────────────────
     Text-only button reading "Hide ‹‹‹" at the top-right of the sidebar.
     Muted until hover; no border, no background, no boxy feel. */
  .sidebarToggle {
    align-self: flex-end;
    display: inline-flex !important;
    align-items: center;
    gap: 4px;
    margin: -2px -4px 4px 0;
    padding: clamp(3px, 0.3vw, 5px) clamp(5px, 0.45vw, 7px);
    border: 0;
    background: transparent;
    border-radius: 6px;
    font-family: var(--font, Inter, -apple-system, BlinkMacSystemFont, sans-serif);
    font-size: clamp(9.5px, 0.72vw, 11px);
    font-weight: 500;
    color: var(--text-ter, #aeaeb2);
    letter-spacing: 0.02em;
    cursor: pointer;
    transition: color .12s ease, background .12s ease;
    user-select: none;
  }
  .sidebarToggle:hover {
    color: var(--text, #1d1d1f);
    background: rgba(0,0,0,0.04);
  }
  .sidebarToggle:focus-visible {
    outline: 2px solid rgba(0, 113, 227, 0.4);
    outline-offset: 1px;
  }
  .sidebarToggleArrows { letter-spacing: -1px; line-height: 1; }
  .sidebarToggleLabel  { line-height: 1; }

  /* ── Floating "show sidebar" button (outside sidebar) ─────────
     Matches the hide button's visual language — text + chevrons, no box. */
  .sidebarShow {
    display: none;
    position: fixed;
    top: calc(var(--header-h, 56px) + 10px);
    left: 12px;
    z-index: 55;
    align-items: center;
    gap: 4px;
    padding: clamp(4px, 0.38vw, 6px) clamp(7px, 0.58vw, 10px);
    border: 0;
    background: transparent;
    border-radius: 6px;
    font-family: var(--font, Inter, -apple-system, BlinkMacSystemFont, sans-serif);
    font-size: clamp(9.5px, 0.72vw, 11px);
    font-weight: 500;
    color: var(--text-ter, #aeaeb2);
    letter-spacing: 0.02em;
    cursor: pointer;
    transition: color .12s ease, background .12s ease;
    user-select: none;
  }
  .sidebarShow:hover {
    color: var(--text, #1d1d1f);
    background: rgba(0,0,0,0.04);
  }
  .sidebarShow:focus-visible {
    outline: 2px solid rgba(0, 113, 227, 0.4);
    outline-offset: 1px;
  }
  .sidebarShowArrows { letter-spacing: -1px; line-height: 1; }
  .sidebarShowLabel  { line-height: 1; }

  /* ── Collapsed state ─────────────────────────────────
     body.sidebarCollapsed slides the sidebar off-screen, reveals the
     floating show button, and cancels the content's left padding so
     the page reclaims the width. Pages that shift their own content
     (results.html uses .main padding-left, terminal.html uses
     .shell padding-left) both have these padding overrides here. */
  body.sidebarCollapsed .filterSidebar {
    transform: translateX(-100%);
    transition: transform .22s ease;
  }
  body.sidebarCollapsed .filterPanel {
    /* Close the panel too if it was open when the user collapsed */
    display: none !important;
  }
  body.sidebarCollapsed .sidebarShow {
    display: inline-flex !important;
  }
  /* results.html — .main has padding-left: calc(var(--sidebar-w) + 24px) */
  body.sidebarCollapsed .resultsLayout .main {
    padding-left: 32px;
  }
  body.sidebarCollapsed .chipsRow {
    padding-left: 32px;
  }
  body.sidebarCollapsed .beetle-footer {
    padding-left: 32px;
  }
  /* terminal.html — .shell has padding-left: var(--sidebar-w) */
  body.sidebarCollapsed .shell {
    padding-left: 0;
  }

  /* Smooth the sidebar's reappearance when expanding too */
  .filterSidebar {
    transition: transform .22s ease;
  }
  /* ── Home row ─────────────────────────────────────── */
  .filterSidebarHome {
    display: flex;
    align-items: center;
    gap: clamp(8px, 0.72vw, 12px);
    padding: clamp(6px, 0.5vw, 8px) clamp(8px, 0.65vw, 11px);
    border-radius: 8px;
    font-family: var(--font, Inter, -apple-system, BlinkMacSystemFont, sans-serif);
    font-size: clamp(10.5px, 0.82vw, 13px);
    font-weight: 400;
    color: var(--text, #1d1d1f);
    text-decoration: none;
    transition: background .12s ease;
    user-select: none;
  }
  .filterSidebarHome:hover   { background: rgba(0,0,0,0.05); }
  .filterSidebarHomeIcon     { flex-shrink: 0; display: block; }
  .filterSidebarHomeLabel    { line-height: 1; }

  /* ── Sort dropdown (mounted here on desktop by sorting.js) ───── */
  .filterSidebarSort {
    padding: 6px 4px 2px;
  }
  .filterSidebarSort:empty { display: none; }
  .filterSidebarSort .controls { width: 100%; }
  .filterSidebarSort .mini {
    width: 100%;
    height: clamp(26px, 2vw, 30px);
    padding: 0 10px;
    border-radius: 8px;
    background: rgba(0,0,0,0.04);
    border: 1px solid rgba(0,0,0,0.08);
    font-family: var(--font, Inter, -apple-system, BlinkMacSystemFont, sans-serif);
    font-size: clamp(10px, 0.75vw, 12px);
    color: var(--text, #1d1d1f);
    cursor: pointer;
    transition: background .12s ease, border-color .12s ease;
  }
  .filterSidebarSort .mini:hover {
    background: rgba(0,0,0,0.07);
    border-color: rgba(0,0,0,0.14);
  }
  .filterSidebarSort .mini:focus {
    outline: none;
    border-color: rgba(0,0,0,0.22);
  }

  /* Chips-row sort host — hidden on desktop (the sort lives in the
     sidebar now). Re-appears on tablet/mobile where there is no sidebar. */
  .chipsSort { display: none; }

  /* ── Divider between sidebar sections ─────────────── */
  .filterSidebarDivider {
    height: 1px;
    background: rgba(0,0,0,0.08);
    margin: 10px 0;
  }

  /* ── Creative Search pill (styled heading, non-interactive) ─── */
  .filterSidebarPillWrap {
    display: flex;
    justify-content: center;
    padding: 2px 0 12px;
  }
  .filterSidebarPill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: clamp(4px, 0.38vw, 6px) clamp(11px, 1vw, 15px);
    background: #0071e3;
    border: 1px solid #0071e3;
    border-radius: 999px;
    font-family: var(--font, Inter, -apple-system, BlinkMacSystemFont, sans-serif);
    font-size: clamp(10px, 0.75vw, 12px);
    font-weight: 500;
    color: #fff;
    letter-spacing: -0.08px;
    line-height: 1;
    cursor: default;
    user-select: none;
  }

  /* ── Filter category rows (nav) ─────────────────── */
  .filterNav {
    display: flex;
    flex-direction: column;
    gap: 1px;
  }

  .filterNavRow {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    width: 100%;
    padding: clamp(6px, 0.5vw, 8px) clamp(8px, 0.65vw, 11px);
    border: 0;
    background: transparent;
    border-radius: 8px;
    font-family: var(--font, Inter, -apple-system, BlinkMacSystemFont, sans-serif);
    font-size: clamp(10.5px, 0.82vw, 13px);
    font-weight: 400;
    color: var(--text, #1d1d1f);
    cursor: pointer;
    text-align: left;
    transition: background .12s ease;
    user-select: none;
  }
  .filterNavRow:hover   { background: rgba(0,0,0,0.05); }
  .filterNavRow.active  { background: rgba(0,0,0,0.07); }

  .filterNavRowLabel {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 400;
  }
  .filterNavRow.active .filterNavRowLabel { font-weight: 500; }

  /* Applied value badge */
  .filterNavRowValue {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 7px;
    background: var(--text, #1d1d1f);
    color: #fff;
    border-radius: 999px;
    font-size: clamp(8.5px, 0.65vw, 10px);
    font-weight: 500;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .filterNavRowValueClear {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 14px;
    height: 14px;
    margin-right: -4px;
    border: 0;
    border-radius: 50%;
    background: rgba(255,255,255,0.22);
    color: #fff;
    font-size: 11px;
    line-height: 1;
    cursor: pointer;
    padding: 0;
    transition: background .12s ease;
  }
  .filterNavRowValueClear:hover { background: rgba(255,255,255,0.42); }

  .filterNavRowChevron {
    color: var(--text-ter, #aeaeb2);
    font-size: clamp(10px, 0.78vw, 12px);
    line-height: 1;
    flex-shrink: 0;
  }
  .filterNavRow.active .filterNavRowChevron { color: var(--text, #1d1d1f); }

  .filterSidebarFooter {
    display: flex;
    flex-direction: column;
    gap: 1px;
    margin-top: 14px;
    padding-top: 14px;
    border-top: 1px solid rgba(0,0,0,0.08);
  }
  .filterSidebarAction {
    padding: clamp(6px, 0.5vw, 8px) clamp(8px, 0.65vw, 11px);
    border: 0;
    background: transparent;
    border-radius: 8px;
    font-family: var(--font, Inter, -apple-system, BlinkMacSystemFont, sans-serif);
    font-size: clamp(10px, 0.78vw, 12px);
    font-weight: 400;
    color: var(--text, #1d1d1f);
    cursor: pointer;
    text-align: left;
    transition: background .12s ease, color .12s ease;
  }
  .filterSidebarAction:hover { background: rgba(0,0,0,0.05); }
  .filterSidebarAction--muted { color: var(--text-ter, #aeaeb2); }
  .filterSidebarAction--muted:hover { color: var(--text, #1d1d1f); }

  /* ── Secondary panel (fixed, slides out to the right of the sidebar) ── */
  .filterPanel {
    display: none;
    flex-direction: column;
    position: fixed;
    top: calc(var(--header-h, 56px) + 8px);
    left: var(--sidebar-w);
    width: 300px;
    max-height: calc(100vh - var(--header-h, 56px) - 16px);
    background: var(--bg, #ffffff);
    border: 1px solid rgba(0,0,0,0.08);
    border-radius: 14px;
    box-shadow: 0 8px 28px rgba(0,0,0,0.08);
    overflow: hidden;
    z-index: 60;
  }
  .filterPanel.panelOpen,
  .panelOpen .filterPanel,
  body.panelOpen .filterPanel {
    display: flex !important;
    animation: filterPanelSlideIn .18s ease both;
  }
  @keyframes filterPanelSlideIn {
    from { opacity: 0; transform: translateX(-8px); }
    to   { opacity: 1; transform: translateX(0);    }
  }

  .filterPanelHeader {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px 12px;
    border-bottom: 1px solid rgba(0,0,0,0.06);
  }
  .filterPanelTitle {
    font-size: 14px;
    font-weight: 600;
    color: var(--text, #1d1d1f);
  }
  .filterPanelClose {
    width: 26px;
    height: 26px;
    border: 0;
    border-radius: 50%;
    background: rgba(0,0,0,0.05);
    color: var(--text-sec, #6e6e73);
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: background .12s ease, color .12s ease;
  }
  .filterPanelClose:hover {
    background: rgba(0,0,0,0.10);
    color: var(--text, #1d1d1f);
  }

  .filterPanelSearch {
    padding: 10px 12px 8px;
    border-bottom: 1px solid rgba(0,0,0,0.06);
  }
  .filterPanelInput {
    width: 100%;
    height: 32px;
    padding: 0 12px;
    border: 1px solid rgba(0,0,0,0.10);
    border-radius: 8px;
    background: #f5f5f7;
    font-family: var(--font, Inter, -apple-system, BlinkMacSystemFont, sans-serif);
    font-size: 13px;
    color: var(--text, #1d1d1f);
    outline: none;
    transition: border-color .12s ease, background .12s ease;
  }
  .filterPanelInput:focus {
    border-color: rgba(0,0,0,0.25);
    background: #fff;
  }
  .filterPanelInput::placeholder { color: var(--text-ter, #aeaeb2); }

  .filterPanelList {
    flex: 1;
    overflow-y: auto;
    padding: 6px 6px 12px;
    scrollbar-width: thin;
  }
  .filterPanelList::-webkit-scrollbar { width: 6px; }
  .filterPanelList::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.12); border-radius: 3px; }

  .filterPanelOption {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 9px 12px;
    border: 0;
    background: transparent;
    border-radius: 8px;
    font-family: var(--font, Inter, -apple-system, BlinkMacSystemFont, sans-serif);
    font-size: 13px;
    font-weight: 400;
    color: var(--text, #1d1d1f);
    cursor: pointer;
    text-align: left;
    transition: background .1s ease;
  }
  .filterPanelOption:hover { background: rgba(0,0,0,0.05); }
  .filterPanelOption.selected {
    background: var(--text, #1d1d1f);
    color: #fff;
    font-weight: 500;
  }
  .filterPanelOption.selected:hover { background: var(--text, #1d1d1f); }

  /* Dimmed: when /api/valid_options returned valid=false for this label —
     picking it would yield zero results given other active filters.
     Still clickable (user might be swapping context), just visually soft. */
  .filterPanelOption--invalid {
    color: var(--text-ter, #aeaeb2);
  }
  .filterPanelOption--invalid:hover { color: var(--text-sec, #6e6e73); }

  .filterPanelEmpty {
    padding: 20px 12px;
    font-size: 12.5px;
    color: var(--text-ter, #aeaeb2);
    text-align: center;
  }
}
