/*
 * THE PARAMETER BAR — the look of parameter-bar.js, for every host
 * (interactive-parameter-bar.md). Insight keeps a byte-identical copy.
 *
 * Every colour, size and font is a --pb-* variable with a default here; a host
 * sets the ones it brands (its accent, its fonts) on .pb or any ancestor, and
 * its dark theme by redefining them. Nothing below uses a literal colour.
 *
 * THE DEFAULTS ARE UNDER :where(.pb) — specificity zero — so a host's own
 * .pb { --pb-accent: … } wins WHATEVER ORDER the two sheets load in. Declared
 * on plain .pb they tied with the host's rule, and this sheet, loaded last,
 * silently took the brand and the dark theme away (review finding).
 */
:where(.pb) {
  --pb-accent: #b0004f;
  --pb-accent-ink: #ffffff;
  --pb-surface: #ffffff;
  --pb-bg: #f6f3f5;
  --pb-ink: #23161d;
  --pb-muted: #6d5f67;
  --pb-line: #ddd3d9;
  --pb-chip: #f7e6ee;
  --pb-chip-ink: #8a003e;
  --pb-focus: rgba(176, 0, 79, 0.28);
  --pb-danger: #c0262d;
  --pb-shadow: 0 10px 30px rgba(35, 22, 29, 0.16);
  --pb-font: inherit;
  --pb-display: inherit;
  --pb-radius: 10px;
  --pb-height: 44px;
}
.pb {
  font-family: var(--pb-font);
  color: var(--pb-ink);
}
.pb *, .pb *::before, .pb *::after { box-sizing: border-box; }
.pb-form { margin: 0; }

/* ── Equal-height controls on a grid that wraps (§3.1) ── */
.pb-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
  align-items: end;
}
.pb-field { position: relative; display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.pb-label {
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.07em; color: var(--pb-muted);
  display: flex; gap: 6px; align-items: baseline; min-width: 0; min-height: 14px;
}
.pb-req { color: var(--pb-accent); }
.pb-scope {
  text-transform: none; letter-spacing: 0; font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0;
}
.pb-trigger {
  height: var(--pb-height); width: 100%;
  display: flex; align-items: center; gap: 8px; justify-content: space-between;
  padding: 0 12px; border: 1px solid var(--pb-line); border-radius: var(--pb-radius);
  background: var(--pb-surface); color: var(--pb-ink); font: inherit; font-size: 14px; font-weight: 500;
  cursor: pointer; text-align: left;
}
.pb-trigger:hover { border-color: var(--pb-muted); }
.pb-trigger:focus-visible, .pb-trigger[aria-expanded="true"] {
  outline: none; border-color: var(--pb-accent); box-shadow: 0 0 0 3px var(--pb-focus);
}
.pb-value { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; flex: 1; }
.pb-dim { color: var(--pb-muted); }
.pb-count {
  background: var(--pb-chip); color: var(--pb-chip-ink); border-radius: 999px; padding: 1px 8px;
  font-size: 12px; font-weight: 600; flex: none;
}
.pb-caret {
  flex: none; width: 9px; height: 9px;
  border-right: 2px solid var(--pb-muted); border-bottom: 2px solid var(--pb-muted);
  transform: rotate(45deg) translateY(-2px);
}
.pb-lead input, .pb-lead select {
  height: var(--pb-height); width: 100%; padding: 0 12px; border: 1px solid var(--pb-line);
  border-radius: var(--pb-radius); background: var(--pb-surface); color: var(--pb-ink); font: inherit; font-size: 14px;
}
.pb-lead label, .pb-lead .iv-label {
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.07em; color: var(--pb-muted);
}
.pb-buttons { display: flex; gap: 10px; }
.pb-buttons > * { flex: 1; }
.pb-run {
  height: var(--pb-height); border: 0; border-radius: var(--pb-radius);
  background: var(--pb-accent); color: var(--pb-accent-ink);
  font-family: var(--pb-display); font-size: 14px; font-weight: 700; cursor: pointer; padding: 0 22px;
}
.pb-run:hover { filter: brightness(1.08); }
.pb-run:disabled { opacity: 0.55; cursor: progress; }
.pb-more {
  height: var(--pb-height); border: 1px dashed var(--pb-line); border-radius: var(--pb-radius);
  background: transparent; color: var(--pb-ink); font: inherit; font-size: 14px; cursor: pointer;
}
.pb-run:focus-visible, .pb-more:focus-visible, .pb-link:focus-visible, .pb-chip-x:focus-visible,
.pb-btn:focus-visible, .pb-preset:focus-visible {
  outline: 3px solid var(--pb-focus); outline-offset: 2px;
}

/* ── What is chosen ── */
.pb-chosen { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 12px; min-height: 26px; }
.pb-lead-text { color: var(--pb-muted); font-size: 12px; }
.pb-chip {
  display: inline-flex; align-items: center; gap: 4px; max-width: 100%;
  background: var(--pb-chip); color: var(--pb-chip-ink);
  border-radius: 999px; padding: 3px 4px 3px 11px; font-size: 12.5px; font-weight: 500;
}
.pb-chip-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.pb-chip-x {
  border: 0; background: transparent; color: inherit; cursor: pointer;
  width: 22px; height: 22px; border-radius: 50%; font-size: 15px; line-height: 1; flex: none;
}
.pb-chip-x:hover { background: var(--pb-focus); }
.pb-link {
  border: 0; background: none; color: var(--pb-accent); font: inherit; font-size: 12.5px; font-weight: 500;
  cursor: pointer; padding: 2px 4px;
}
.pb-error { margin: 10px 0 0; color: var(--pb-danger); font-size: 13px; }

/* ── Popovers ── */
.pb-pop {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 30;
  width: min(340px, calc(100vw - 32px));
  background: var(--pb-surface); color: var(--pb-ink);
  border: 1px solid var(--pb-line); border-radius: 12px; box-shadow: var(--pb-shadow);
  display: flex; flex-direction: column; max-height: 420px;
}
.pb-pop-head { padding: 12px 12px 8px; display: flex; flex-direction: column; gap: 8px; border-bottom: 1px solid var(--pb-line); }
.pb-pop-title { font-family: var(--pb-display); font-size: 13px; font-weight: 700; }
.pb-search {
  height: 36px; width: 100%; border: 1px solid var(--pb-line); border-radius: 8px; padding: 0 10px;
  background: var(--pb-bg); color: var(--pb-ink); font: inherit; font-size: 14px;
}
.pb-search:focus { outline: none; border-color: var(--pb-accent); box-shadow: 0 0 0 3px var(--pb-focus); }
.pb-tools { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 12px; color: var(--pb-muted); }
.pb-list { overflow-y: auto; padding: 6px 4px; flex: 1; min-height: 0; }
.pb-opt { display: flex; gap: 10px; align-items: center; padding: 7px 10px; border-radius: 7px; cursor: pointer; font-size: 14px; }
.pb-opt:hover { background: var(--pb-bg); }
.pb-opt input { accent-color: var(--pb-accent); width: 16px; height: 16px; flex: none; margin: 0; }
.pb-opt-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pb-opt mark { background: var(--pb-chip); color: var(--pb-chip-ink); border-radius: 3px; padding: 0 1px; }
.pb-empty { padding: 18px 12px; color: var(--pb-muted); text-align: center; font-size: 13px; }
.pb-pop-foot { padding: 10px 12px; border-top: 1px solid var(--pb-line); display: flex; justify-content: flex-end; gap: 8px; }
.pb-btn {
  height: 32px; padding: 0 14px; border-radius: 8px; font: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
  border: 1px solid var(--pb-line); background: var(--pb-surface); color: var(--pb-ink);
}
.pb-btn.pb-primary { background: var(--pb-accent); border-color: var(--pb-accent); color: var(--pb-accent-ink); }
.pb-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.pb-presets { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; padding: 10px 12px; }
.pb-preset {
  height: 34px; border: 1px solid var(--pb-line); border-radius: 8px; background: var(--pb-surface); color: var(--pb-ink);
  font: inherit; font-size: 13px; font-weight: 500; cursor: pointer;
}
.pb-preset[aria-pressed="true"] { border-color: var(--pb-accent); background: var(--pb-chip); color: var(--pb-chip-ink); }
.pb-dates { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 4px 12px 12px; }
.pb-dates label {
  display: flex; flex-direction: column; gap: 4px; font-size: 11px; color: var(--pb-muted);
  text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600;
}
.pb-dates input {
  height: 36px; border: 1px solid var(--pb-line); border-radius: 8px; padding: 0 8px; min-width: 0;
  background: var(--pb-bg); color: var(--pb-ink); font: inherit; font-size: 14px;
}
.pb-limit { padding: 0 12px 10px; font-size: 12px; color: var(--pb-muted); min-height: 14px; }
.pb-limit.pb-bad { color: var(--pb-danger); }

/* ── Phone width: one column, popovers as wide as the screen ── */
@media (max-width: 520px) {
  .pb-grid { grid-template-columns: 1fr; }
  .pb-buttons { flex-direction: column; }
  .pb-pop { width: calc(100vw - 32px); }
}
@media (prefers-reduced-motion: reduce) { .pb * { transition: none !important; } }
