/* =========================================================================
   Cabinhub News — search palette (Cmd/Ctrl-K)

   Design: THE LETTERHEAD, continued. The page is an ink shell with one cream
   reading sheet; the palette is a second sheet laid on top of it — a printed
   index card, not a floating glass panel. So: square corners, hairline rules,
   serif titles, monospaced folios, one oxidised-red accent used for rules and
   matches (never as a background wash behind text). No gradients, no blur, no
   shadow except the paper lift the site already defines.

   Tokens come only from the shared theme contract so both themes work:
     --bg --surface --fg --fg-2 --fg-3 --line --accent --focus
   with the estate's fallbacks. Where the site already publishes its own
   vocabulary (--paper, --ink, --font-*, --tap, --ease) it is used as the
   PREFERRED source, so the palette sits in the existing design system instead
   of beside it.

   Motion: one 140 ms opacity/translate on open, and nothing else. Everything
   is disabled under prefers-reduced-motion, and no state depends on an
   animation completing.
   ========================================================================= */

.cbn-palette {
  /* The theme contract, resolved once on the sheet. Each name resolves:
     contract (--bg …) -> the site's own token -> the light Ember value, so
     this file works both inside app.cabinhub (tokens.css) and standalone. */
  --cbn-bg: var(--bg, var(--paper, #F7F5F2));
  --cbn-surface: var(--surface, var(--canvas, #FFFFFF));
  --cbn-well: var(--surface-2, var(--paper-2, #F1ECE7));
  --cbn-fg: var(--fg, var(--ink, #1C1714));
  --cbn-fg-2: var(--fg-2, var(--ink-soft, #514942));
  --cbn-fg-3: var(--fg-3, var(--ink-faint, #6D6259));
  --cbn-line: var(--line, var(--rule, #D6CBC2));
  --cbn-accent: var(--accent, #BC3E0D);
  --cbn-focus: var(--focus, #D64221);

  /* Site vocabulary, with fallbacks for a page that does not define it. */
  --cbn-serif: var(--font-display, "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif);
  --cbn-ui: var(--font-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif);
  --cbn-mono: var(--font-mono, ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace);
  --cbn-tap: var(--tap, 44px);
  --cbn-ease: var(--ease, cubic-bezier(0.22, 0.68, 0.16, 1));

  --cbn-fs-title: var(--fs-small, 0.98rem);
  --cbn-fs-body: var(--fs-meta, 0.85rem);
  --cbn-fs-label: var(--fs-micro, 0.75rem);

  position: fixed;
  inset: 0;
  z-index: 90;
  display: none;
  color: var(--cbn-fg);
}

/* Dark: the same sheet, printed on ink stock. tokens.css already flips every
   site token, so this block only supplies the standalone fallbacks. */
:root[data-theme="dark"] .cbn-palette {
  --cbn-bg: var(--bg, var(--paper, #15110E));
  --cbn-surface: var(--surface, var(--canvas, #1E1915));
  --cbn-well: var(--surface-2, var(--paper-3, #2A2320));
  --cbn-fg: var(--fg, var(--ink, #F3EEE9));
  --cbn-fg-2: var(--fg-2, var(--ink-soft, #C9BFB6));
  --cbn-fg-3: var(--fg-3, var(--ink-faint, #9F948A));
  --cbn-line: var(--line, var(--rule, #3A3129));
  --cbn-accent: var(--accent, #FA8054);
  --cbn-focus: var(--focus, #FF9C6B);
}

.cbn-palette.is-open { display: block; }

/* The page behind the sheet must not scroll under a fixed overlay. */
html.cbn-palette-lock,
html.cbn-palette-lock body { overflow: hidden; }

/* ------------------------------------------------------------------ scrim */

.cbn-palette__scrim {
  position: absolute;
  inset: 0;
  /* Warm ink, not a cold slab: the old rgba(15, 24, 34, .55) was a blue-grey
     that read cool over warm newsprint.

     DELIBERATELY A LITERAL, NOT color-mix OVER --cbn-fg. A scrim must DARKEN
     whatever is behind it. --cbn-fg is the TEXT colour, and in
     :root[data-theme="dark"] it resolves near-white (#F3EEE9), so mixing on it
     at 55% over the dark ground #15110E composites to ~rgb(143,138,136) and
     BRIGHTENS the page to mid-grey instead of dimming it — the opposite of a
     scrim, and the one declaration that would win everywhere color-mix is
     supported. A fixed warm-dark ink dims correctly in both themes: over the
     light newsprint it is a warm veil, over the dark stock it is darker still. */
  background: rgba(28, 23, 20, 0.55);
}

/* ------------------------------------------------------------------ sheet */

.cbn-palette__sheet {
  position: relative;
  display: flex;
  flex-direction: column;
  margin: clamp(0.5rem, 6vh, 5rem) auto 0;
  width: min(46rem, calc(100vw - 2rem));
  max-height: min(38rem, calc(100dvh - 2rem));
  background: var(--cbn-surface);
  color: var(--cbn-fg);
  border: 1px solid var(--cbn-fg);
  /* The sheet is the one surface that leaves the page plane entirely, so it
     takes the top of the elevation ramp (tokens.css) instead of a one-off
     rgba. A tinted, stacked shadow in the product's own ink — the old literal
     was a cold #101A26 that belonged to no palette in this system. The bevel
     is the lit near edge that makes a card read as an object.
     The fallbacks are INLINE, not a prior declaration: an unresolved var() in
     a shorthand is invalid at computed-value time and becomes `unset`, it does
     not walk back up the cascade. Each token therefore carries its own
     fallback, for the shells that drop this palette in without tokens.css. */
  box-shadow:
    var(--bevel-top, inset 0 1px 0 rgba(255, 255, 255, 0.6)),
    var(--shadow-3, 0 24px 60px -40px rgba(16, 26, 38, 0.85));
  outline: none;
}

.cbn-palette__sr {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* ------------------------------------------------------------------ field */

.cbn-palette__field {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0 0.7rem 0 0.85rem;
  border-bottom: 1px solid var(--cbn-line);
  min-height: calc(var(--cbn-tap) + 0.6rem);
}

.cbn-palette__glyph {
  display: inline-flex;
  color: var(--cbn-fg-3);
  flex: 0 0 auto;
}

.cbn-palette__input {
  flex: 1 1 auto;
  min-width: 0;
  border: 0;
  background: none;
  color: inherit;
  font-family: var(--cbn-serif);
  font-size: clamp(1.05rem, 0.98rem + 0.4vw, 1.3rem);
  letter-spacing: -0.01em;
  padding: 0.55rem 0;
  appearance: none;
  -webkit-appearance: none;
}
.cbn-palette__input::placeholder { color: var(--cbn-fg-3); opacity: 1; }
.cbn-palette__input:focus { outline: none; }
.cbn-palette__input:focus-visible { outline: none; }
/* The input is borderless by design — the field row owns the edge — so its
   outline was suppressed on both :focus and :focus-visible, leaving a keyboard
   reader no focus indicator at all (WCAG 2.4.7). The field's own bottom rule
   carries the cue instead: it turns the accent while the field holds focus,
   which is the edge the reader's eye is already on, and it is where the design
   wants the field boundary drawn. */
.cbn-palette__field:focus-within { border-bottom-color: var(--cbn-accent); }

.cbn-palette__wipe {
  appearance: none;
  flex: 0 0 auto;
  width: 1.9rem;
  height: 1.9rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: 0;
  color: var(--cbn-fg-3);
  cursor: pointer;
}
.cbn-palette__wipe:hover { color: var(--cbn-fg); }
.cbn-palette__wipe[hidden] { display: none; }

.cbn-palette__kbd,
.cbn-palette-trigger__kbd {
  flex: 0 0 auto;
  font-family: var(--cbn-ui);
  font-size: var(--cbn-fs-label);
  letter-spacing: 0;
  color: var(--cbn-fg-3);
  border: 1px solid var(--cbn-line);
  padding: 0.1rem 0.32rem;
  line-height: 1.25;
}

/* ------------------------------------------------------------------ chips */

/* Two filters that must BOTH stay reachable. Measured 1440x900: the nine
   category chips plus four time chips do not fit on one line, and a horizontally
   scrolling row pushed the time control off the sheet entirely — an invisible
   filter is a missing filter. So the row wraps, and the time group keeps its
   own line whenever it does not fit. */
.cbn-palette__chips {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0 1.2rem;
  padding: 0 0.85rem;
  border-bottom: 1px solid var(--cbn-line);
}

.cbn-palette__chipgroup {
  display: flex;
  align-items: center;
  gap: 0.1rem;
  flex: 0 1 auto;
  flex-wrap: wrap;
}

.cbn-palette__chipgroup:first-child {
  flex: 1 1 auto;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.cbn-palette__chipgroup:first-child::-webkit-scrollbar { display: none; }

/* The time group rides at the far right when it fits, and starts its own
   right-aligned line when it does not. No divider: a rule that spans one chip
   height and floats mid-sheet reads as a mistake, and the chips already say
   what they are. */
.cbn-palette__chipgroup--time {
  margin-left: auto;
  gap: 0.35rem;
}

.cbn-palette__chip {
  appearance: none;
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  color: var(--cbn-fg-3);
  font-family: var(--cbn-ui);
  font-size: var(--cbn-fs-label);
  min-height: 2.35rem;
  padding: 0 0.5rem;
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  white-space: nowrap;
  /* Never shrink below the label: a flex item's automatic floor is its
     min-content width, but any explicit min-width (the 44px thumb rule below)
     REPLACES that floor, and the label then paints over the next chip.
     Measured 2026-11-11 at 390: every chip collapsed to exactly 44px,
     "Commodities" spilling onto "FX" and "Central banks" onto "Corporate".
     The row is a scroller on a phone, so a chip keeps its text width and the
     row scrolls; it must not compress. */
  flex: 0 0 auto;
}
.cbn-palette__chip:hover { color: var(--cbn-fg); }
.cbn-palette__chip.is-on {
  color: var(--cbn-fg);
  border-bottom-color: var(--cbn-accent);
}
.cbn-palette__chip:focus-visible {
  outline: 2px solid var(--cbn-focus);
  outline-offset: -2px;
}

/* ------------------------------------------------------------------- body */

.cbn-palette__body {
  flex: 1 1 auto;
  min-height: 6rem;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.cbn-palette__list { padding: 0.35rem 0 0.5rem; }

.cbn-palette__group {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.7rem 0.85rem 0.3rem;
}

.cbn-palette__group-label {
  font-family: var(--cbn-ui);
  font-size: var(--cbn-fs-label);
  color: var(--cbn-fg-3);
}

.cbn-palette__bulk {
  appearance: none;
  background: none;
  border: 0;
  padding: 0.1rem 0.2rem;
  color: var(--cbn-fg-3);
  font-family: var(--cbn-ui);
  font-size: var(--cbn-fs-label);
  letter-spacing: 0;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}
.cbn-palette__bulk:hover { color: var(--cbn-fg); }

.cbn-palette__opt {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  padding: 0.5rem 0.85rem;
  border-left: 2px solid transparent;
  cursor: pointer;
}
.cbn-palette__opt.is-active {
  border-left-color: var(--cbn-accent);
  background: var(--cbn-bg);
}
.cbn-palette__opt:hover { background: var(--cbn-bg); }

.cbn-palette__ico {
  flex: 0 0 auto;
  display: inline-flex;
  align-self: center;
  color: var(--cbn-fg-3);
  width: 0.9rem;
}

.cbn-palette__text {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  min-width: 0;
  flex: 1 1 auto;
}

.cbn-palette__title {
  font-family: var(--cbn-serif);
  font-size: var(--cbn-fs-title);
  line-height: 1.25;
  color: var(--cbn-fg);
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.cbn-palette__detail {
  font-family: var(--cbn-ui);
  font-size: var(--cbn-fs-body);
  line-height: 1.4;
  color: var(--cbn-fg-2);
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

/* A match is an accent mark on the word, not a highlighter wash: the site's
   one rule is that the accent never sits behind text. */
.cbn-palette__hit {
  background: none;
  color: var(--cbn-accent);
  font-weight: 600;
  border-bottom: 1px solid var(--cbn-accent);
}

.cbn-palette__tag,
.cbn-palette__count {
  flex: 0 0 auto;
  align-self: center;
  font-family: var(--cbn-ui);
  font-size: var(--cbn-fs-label);
  color: var(--cbn-fg-3);
  border: 1px solid var(--cbn-line);
  padding: 0.05rem 0.35rem;
  white-space: nowrap;
}
.cbn-palette__count { border: 0; padding: 0 0.2rem; }

/* -------------------------------------------------------------- empty state */

.cbn-palette__empty {
  padding: 1.6rem 0.85rem 1.9rem;
  max-width: 42ch;
}
.cbn-palette__empty[hidden] { display: none; }

.cbn-palette__empty-title {
  margin: 0 0 0.3rem;
  font-family: var(--cbn-serif);
  font-size: var(--cbn-fs-title);
  color: var(--cbn-fg);
}

.cbn-palette__empty-body {
  margin: 0;
  font-family: var(--cbn-ui);
  font-size: var(--cbn-fs-body);
  line-height: 1.5;
  color: var(--cbn-fg-2);
}

/* ------------------------------------------------------------------- foot */

.cbn-palette__foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.35rem 0.85rem;
  border-top: 1px solid var(--cbn-line);
  background: var(--cbn-bg);
}

.cbn-palette__status,
.cbn-palette__help {
  margin: 0;
  font-family: var(--cbn-ui);
  font-size: var(--cbn-fs-label);
  letter-spacing: 0;
  color: var(--cbn-fg-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cbn-palette__help { flex: 0 0 auto; }

/* ---------------------------------------------------------------- trigger */

/* The trigger lives in the toolbar, OUTSIDE .cbn-palette, so it cannot inherit
   the --cbn-* names resolved on the sheet. It reads the site tokens directly
   (with the light values as fallbacks), which is also why it needs no theme
   block: tokens.css already flips them. */
.cbn-palette-trigger {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-width: var(--tap, 44px);
  /* a11y.css already lifts every toolbar control to the 44px Ember target;
     a shorter trigger beside a 44px field reads as a secondary tool. */
  min-height: var(--tap, 44px);
  padding: 0 0.6rem;
  background: var(--paper-2, #F1ECE7);
  /* The toolbar moved from an ink shell to Ember's light paper (N3 11-07);
     the control reads as the site's search field: single strong rule, same
     radius, same type. */
  border: 1px solid var(--rule-strong, #8F7B6D);
  border-radius: var(--r-md, 8px);
  color: var(--ink-soft, #514942);
  cursor: pointer;
  transition: background-color var(--dur-1, 150ms) var(--ease, cubic-bezier(0.22, 0.68, 0.16, 1)),
              color var(--dur-1, 150ms) var(--ease, cubic-bezier(0.22, 0.68, 0.16, 1));
}
.cbn-palette-trigger:hover { color: var(--ink, #1C1714); }
.cbn-palette-trigger:focus-visible {
  outline: 2px solid var(--focus, #D64221);
  outline-offset: 1px;
}
.cbn-palette-trigger__kbd {
  color: var(--ink-faint, #6D6259);
  border-color: var(--rule, #D6CBC2);
}
/* The chord is a desktop affordance; a phone shows the plain magnifier. */
@media (hover: none) and (pointer: coarse) {
  .cbn-palette-trigger__kbd { display: none; }
}
/* ONE search door per screen. Above the phone breakpoint the toolbar already
   carries the full field — the visible, labelled door — so this button sat
   beside it as a second magnifier with no label of its own (measured in the
   1440 shot: a lone 36px rounded square at x≈683, a 290px gap, then the real
   field). The chord still opens the palette on a keyboard; the phone, where
   the field is hidden, is where the button earns its place. Same rule as the
   phone pass, stated once: the duplicate goes, the door stays.

   NOT the inline variant. The module adds `--inline` to the SAME element when
   it mounts inside the field, and this rule used to hide both: measured
   2026-11-11 on the merged tree (n3_overlay oN50), the in-field ⌘K keycap
   computed display:none at 1440/768 while .searchbar__input reserved 3.4rem of
   right padding for it (chrome.css) — the desk carried a keyboard-only palette
   and an empty inset. The hide is for the standalone button the compact row
   used to carry, so it is scoped to it. */
@media (min-width: 600px) {
  .cbn-palette-trigger:not(.cbn-palette-trigger--inline) { display: none; }
}

/* ---- the inline door: the chord hint INSIDE the search field -----------
   The toolbar carried two search controls side by side (measured 1440: a 76px
   ⌘K button and a 272px field, both opening the same palette). The button is
   gone; its hint now sits inside the field it belongs to, at the field's right
   edge, as the one visible door to the palette. The field still submits the
   plain #/search route on Enter, so a reader can type in it without ever
   meeting the sheet.

   The button is transparent and borderless on a fine pointer: the keycap IS
   the control, and a second box inside the field would be the defect again.
   Its 44px tap box is kept (a11y 2.5.8) — the box is invisible, not absent. */
.cbn-palette-trigger--inline {
  position: absolute;
  right: 2px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 1;
  min-width: var(--tap, 44px);
  min-height: var(--tap, 44px);
  padding: 0 0.45rem;
  background: transparent;
  border: 0;
  border-radius: var(--r-xs, 4px);
  gap: 0.3rem;
}
.cbn-palette-trigger--inline:hover { color: var(--ink, #1C1714); }
.cbn-palette-trigger--inline:focus-visible {
  outline: 2px solid var(--focus, #D64221);
  outline-offset: -1px;
}
/* The field already draws its own magnifier at the left (chrome.css
   .searchbar::before); a second one inside the same box reads as two controls. */
.cbn-palette-trigger--inline > svg { display: none; }
.cbn-palette-trigger--inline .cbn-palette-trigger__kbd {
  border: 1px solid var(--rule, #D6CBC2);
  border-radius: var(--r-xs, 4px);
  background: var(--paper, #F7F5F2);
  padding: 0.05rem 0.3rem;
}
/* Touch: no chord exists, so the glyph is the door and the field's decorative
   magnifier steps aside (one magnifier per field). */
@media (hover: none) and (pointer: coarse) {
  .cbn-palette-trigger--inline > svg { display: block; }
  .cbn-palette-trigger--inline { padding: 0; }
  .searchbar--palette::before { display: none; }
}

/* Touch: the sheet is the phone's search page, and its controls were sized for
   a mouse. Measured 2026-11-11 (n3_overlay oN50, 390 both editions): the query
   field 43px, every category and time chip 38px tall and as narrow as 33 — the
   most-pressed controls in the product, all under the 44px thumb. The category
   row already scrolls on its own line at this width (the max-width: 640 block
   above), so a wider chip costs a swipe, not a wrapped row. */
@media (pointer: coarse) {
  .cbn-palette__input { min-height: var(--tap, 44px); }
  .cbn-palette__chip { min-height: var(--tap, 44px); min-width: var(--tap, 44px); }
}

/* --------------------------------------------------------------- responsive */

/* Phone: the sheet is the screen. Same paper, no scrim margin to waste. */
@media (max-width: 640px) {
  .cbn-palette__scrim { display: none; }
  .cbn-palette__sheet {
    width: 100%;
    max-width: none;
    height: 100%;
    max-height: 100%;
    margin: 0;
    border: 0;
    border-top: 1px solid var(--cbn-fg);
    padding-top: env(safe-area-inset-top, 0px);
  }
  .cbn-palette__foot { padding-bottom: max(0.35rem, env(safe-area-inset-bottom, 0px)); }
  .cbn-palette__help { display: none; }
  /* Phone: categories scroll on their own line, time keeps a fixed second
     line. Both stay visible without a horizontal hunt. */
  .cbn-palette__chips { padding: 0 0.5rem; gap: 0; flex-wrap: wrap; }
  /* A clipped chip reads as a broken control, so the row fades at the edge
     instead of cutting a word in half. */
  .cbn-palette__chipgroup:first-child {
    flex: 1 1 100%;
    flex-wrap: nowrap;
    overflow-x: auto;
    border-bottom: 1px solid var(--cbn-line);
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    -webkit-mask-image: linear-gradient(to right, #000 0, #000 calc(100% - 2.5rem), transparent 100%);
    mask-image: linear-gradient(to right, #000 0, #000 calc(100% - 2.5rem), transparent 100%);
  }
  .cbn-palette__chipgroup:first-child::-webkit-scrollbar { display: none; }
  .cbn-palette__chipgroup--time {
    flex: 1 1 100%;
    margin-left: 0;
    justify-content: space-between;
  }
  .cbn-palette__chip { padding: 0 0.45rem; }
  .cbn-palette__opt { padding: 0.65rem 0.7rem; }
  .cbn-palette__group { padding-inline: 0.7rem; }
}

/* The phone toolbar is one row (responsive.css): nav order 1, trigger order 2,
   the full search field hidden. The trigger is a sibling of the nav, so it
   needs an explicit order or it would jump above the navigation; it belongs on
   the nav's row, at the far end, as the only way in on a phone. */
@media (max-width: 599px) {
  .cbn-palette-trigger { order: 1; margin-left: auto; min-width: var(--tap, 44px); padding: 0; }
  /* 390px cannot hold the nav and a chord badge on one line: the badge alone
     is what pushes the trigger onto a third row. The chord is a desktop
     affordance anyway, so the phone shows the magnifier by itself. */
  .cbn-palette-trigger__kbd { display: none; }
}

/* ------------------------------------------------------------------- motion */

@media (prefers-reduced-motion: no-preference) {
  .cbn-palette.is-open .cbn-palette__sheet {
    animation: cbn-palette-in 140ms var(--cbn-ease) both;
  }
  @keyframes cbn-palette-in {
    from { opacity: 0; transform: translateY(-6px); }
    to { opacity: 1; transform: none; }
  }
}

@media (prefers-reduced-motion: reduce) {
  .cbn-palette,
  .cbn-palette__sheet { animation: none !important; transition: none !important; }
}

/* Forced colours: keep the sheet a real surface, keep the accent visible. */
@media (forced-colors: active) {
  .cbn-palette__sheet { border: 2px solid CanvasText; }
  .cbn-palette__opt.is-active { outline: 2px solid Highlight; outline-offset: -2px; }
  .cbn-palette__hit { border-bottom: 2px solid Highlight; }
}
