/* =====================================================================
   Kiteworks Agent Marketplace — Custom Sort menu (catalog toolbar)

   Replaces the catalog toolbar's native <select> — whose option popup can't
   be themed and renders white-on-white in dark mode (Safari/macOS draw the
   option list with the system white background). The native <select> stays as
   the no-JS fallback (hidden once sort_menu.js upgrades the control).

   Adapted from the mockup handoff to this repo's ACTUAL token vocabulary (the
   handoff was written against an abstract --fg-1/--stroke/--r-* / .theme-*
   layer; here the brand tokens kept their legacy --kw-* names — same as
   lang_picker.css / loading.css). Token map:
     --font-mono   -> --kw-font-mono      --r-pill -> --kw-radius-pill
     --font-body   -> --kw-font-body      --r-lg   -> --kw-radius-lg
     --bg-elevated -> --kw-bg-elevated    --r-sm   -> --kw-radius-sm
     --stroke      -> --kw-border-color
     --fg-1 -> --kw-fg   --fg-2 -> --kw-fg-muted   --fg-3 -> --kw-fg-subtle
     --surface-2   -> --kw-bg-subtle      --kw-brand-blue -> --kw-blue

   Theme: .theme-dark/.theme-light -> html.dark/html.light (the token flip in
   tokens.css; the mockup's .theme-* selectors would never match).
   RTL: physical right / text-align:left / margin-left -> logical
   inset-inline-end / text-align:start / margin-inline-start, so the popover
   mirrors under <html dir="rtl"> (enforced by tests/test_rtl_layout.py).
   ===================================================================== */

.sortmenu { position: relative; }

/* Native <select> — shown only as the no-JS fallback (hidden once JS upgrades). */
.sortmenu__native {
  font-family: var(--kw-font-mono); font-size: 12px; padding: 8px 12px; border-radius: var(--kw-radius-pill);
  background: var(--kw-bg-elevated); border: 1px solid var(--kw-border-color); color: var(--kw-fg);
}
html.dark .sortmenu__native { background: var(--kw-midnight-navy); color: #fff; border-color: rgba(77, 96, 251, 0.30); }
.sortmenu.is-enhanced .sortmenu__native { display: none; }

/* Trigger — glass pill, matches the catalog search field. */
.sortmenu__trigger {
  display: inline-flex; align-items: center; gap: 8px; cursor: pointer;
  font-family: var(--kw-font-mono); font-size: 12px; line-height: 1; white-space: nowrap;
  padding: 9px 12px; border-radius: var(--kw-radius-pill); border: 1px solid var(--kw-border-color);
  background: var(--kw-bg-subtle); color: var(--kw-fg-muted); transition: 150ms ease;
}
html.dark .sortmenu__trigger { background: rgba(77, 96, 251, 0.06); border-color: rgba(77, 96, 251, 0.20); color: var(--kw-muted-lavender); }
.sortmenu__trigger:hover { border-color: var(--kw-blue); color: var(--kw-fg); }
html.dark .sortmenu__trigger:hover { border-color: rgba(77, 96, 251, 0.55); color: #fff; }
.sortmenu__trigger [data-lucide] { width: 14px; height: 14px; }
.sortmenu__trigger .lead { color: var(--kw-fg-subtle); }
.sortmenu__trigger .val { color: var(--kw-fg); }
html.dark .sortmenu__trigger .val { color: #fff; }
.sortmenu__trigger .chev { margin-inline-start: 2px; transition: transform 160ms ease; opacity: .7; }
.sortmenu[data-open] .sortmenu__trigger { border-color: var(--kw-blue); }
.sortmenu[data-open] .sortmenu__trigger .chev { transform: rotate(180deg); }

/* Popover listbox — glass on dark, white on light. */
.sortmenu__panel {
  position: absolute; top: calc(100% + 8px); inset-inline-end: 0; z-index: 60; min-width: 220px;
  padding: 6px; border-radius: var(--kw-radius-lg); opacity: 0; visibility: hidden;
  transform: translateY(-4px); transition: opacity 150ms ease, transform 150ms ease, visibility 150ms;
}
html.light .sortmenu__panel { background: #fff; border: 1px solid var(--kw-border-color); box-shadow: 0 16px 44px -12px rgba(11, 14, 36, 0.28); }
html.dark .sortmenu__panel { background: rgba(13, 15, 49, 0.96); border: 1px solid rgba(77, 96, 251, 0.30); box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55), inset 0 0 40px rgba(197, 185, 246, 0.10); -webkit-backdrop-filter: blur(34px); backdrop-filter: blur(34px); }
.sortmenu[data-open] .sortmenu__panel { opacity: 1; visibility: visible; transform: none; }
.sortmenu__menulabel { font-family: var(--kw-font-mono); font-size: 10px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--kw-fg-subtle); padding: 8px 10px 6px; }
.sortmenu__item {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: start; cursor: pointer;
  font-family: var(--kw-font-body); font-size: 14px; color: var(--kw-fg-muted);
  padding: 9px 10px; border: 0; background: transparent; border-radius: var(--kw-radius-sm); transition: background 120ms, color 120ms;
}
.sortmenu__item:hover { background: var(--kw-bg-subtle); color: var(--kw-fg); }
html.dark .sortmenu__item:hover { background: rgba(77, 96, 251, 0.10); color: #fff; }
.sortmenu__item.is-active { color: var(--kw-fg); font-weight: 500; }
html.dark .sortmenu__item.is-active { color: #fff; }
.sortmenu__item .ico { width: 16px; height: 16px; flex-shrink: 0; color: var(--kw-fg-subtle); }
.sortmenu__item .label { flex: 1; }
.sortmenu__item .check { width: 16px; height: 16px; opacity: 0; color: var(--kw-blue); }
html.dark .sortmenu__item .check { color: var(--kw-electric-indigo); }
.sortmenu__item.is-active .check { opacity: 1; }
.sortmenu__item.is-kbd { background: var(--kw-bg-subtle); }
html.dark .sortmenu__item.is-kbd { background: rgba(77, 96, 251, 0.10); }
