/* Shared popup appearance. Placement, visibility and menu behavior stay with
   each component. Optional theme seeds are background + foreground, not an
   assumed accent pair. Existing site themes remain the default source of truth. */
:root {
  --zb-popup-surface: color-mix(in srgb, var(--zb-theme-background, var(--bg-100, #fff)) 97%, var(--zb-theme-foreground, var(--text-100, #171717)));
  --zb-popup-text: var(--zb-theme-foreground, var(--text-100, #171717));
  --zb-popup-muted: color-mix(in srgb, var(--zb-popup-text) 72%, var(--zb-popup-surface));
  --zb-popup-border: color-mix(in srgb, var(--zb-popup-text) 18%, var(--zb-popup-surface));
  --zb-popup-hover: color-mix(in srgb, var(--zb-popup-text) 8%, var(--zb-popup-surface));
  --zb-popup-selected: color-mix(in srgb, var(--zb-popup-text) 12%, var(--zb-popup-surface));
  --zb-popup-shadow: 0 8px 24px rgb(0 0 0 / 20%);
  --zb-popup-radius: 14px;
  --zb-popup-item-radius: 8px;
  --zb-popup-padding: 6px;
  --zb-popup-item-padding: 8px 10px;
}

/* Deliberately scoped migration adapter: old templates have !important color
   utilities, pt-0, inline padding and late page rules. Do not broaden these to
   global .dropdown-item/.dropdown-menu selectors or override display/position. */
html body :is(#models, #cmpMenuA, #cmpMenuB, #attachDropdown, #cmpAttachDropdown, #zbSidebarMoreMenu, #settingsCont, .stats-popup) {
  background: var(--zb-popup-surface) !important;
  color: var(--zb-popup-text) !important;
  border: 1px solid var(--zb-popup-border) !important;
  border-radius: var(--zb-popup-radius) !important;
  box-shadow: var(--zb-popup-shadow) !important;
  padding: var(--zb-popup-padding) !important;
  font-size: 14px;
  line-height: 1.5;
  text-align: left;
  box-sizing: border-box;
}
html body :is(#models, #cmpMenuA, #cmpMenuB, #attachDropdown, #cmpAttachDropdown, #zbSidebarMoreMenu, #settingsCont) {
  max-width: calc(100vw - 16px);
}
html body :is(#models, #cmpMenuA, #cmpMenuB) .dropdown-model,
html body :is(#attachDropdown, #cmpAttachDropdown) .attach-item,
html body #zbSidebarMoreMenu [role="menuitem"],
html body #settingsCont .setting_link {
  min-height: 38px;
  padding: var(--zb-popup-item-padding) !important;
  margin: 0 !important;
  background: transparent;
  color: var(--zb-popup-text) !important;
  font-size: 14px !important;
  line-height: 22px;
  text-decoration: none;
}
/* All popup rows share corner geometry, including the model action footer.
   Keep this separate from row sizing so footer spacing/actions stay unchanged. */
html body :is(#models, #cmpMenuA, #cmpMenuB) :is(.dropdown-model, .dropdown-extra),
html body :is(#attachDropdown, #cmpAttachDropdown) .attach-item,
html body #zbSidebarMoreMenu [role="menuitem"],
html body #settingsCont .setting_link {
  border-radius: var(--zb-popup-item-radius) !important;
}
html body :is(#models, #cmpMenuA, #cmpMenuB) .dropdown-model :is(.row, .menuDesc) {
  padding: 0 !important;
  color: inherit;
  font-size: inherit;
}
html body :is(#models, #cmpMenuA, #cmpMenuB) .dropdown-model .row {
  margin: 0 !important;
}
html body :is(#models, #cmpMenuA, #cmpMenuB) .dropdown-model:has(.model-provider) {
  min-height: 30px;
  cursor: default;
}
html body :is(#models, #cmpMenuA, #cmpMenuB) .model-provider:hover { background: transparent !important; }
html body :is(#models, #cmpMenuA, #cmpMenuB) :is(.model-provider, .modelDescS),
html body :is(#models, #cmpMenuA, #cmpMenuB) .fa-lock {
  color: var(--zb-popup-muted) !important;
}
html body :is(#models, #cmpMenuA, #cmpMenuB) .dropdown-model:not(:has(.model-provider)):is(:hover, :focus-visible),
html body #models .dropdown-extra:is(:hover, :focus-visible),
html body #attachDropdown .attach-item:is(:hover, :focus-visible, .active),
html body #attachDropdown.kbd-nav .attach-item.active,
html body #attachDropdown.kbd-nav .attach-item.active:hover,
html body #zbSidebarMoreMenu [role="menuitem"]:is(:hover, :focus-visible),
html body #settingsCont .setting_link:is(:hover, :focus),
html body #settingsCont .theme-btn:is(:hover, :focus-visible) {
  background: var(--zb-popup-hover) !important;
}
html body #attachDropdown.kbd-nav .attach-item:hover:not(.active),
html body #cmpAttachDropdown .attach-item:hover,
html body :is(#models, #cmpMenuA, #cmpMenuB) .dropdown-model:has(.model-provider):hover {
  background: transparent !important;
}
html body #zbSidebarMoreMenu [aria-current="page"],
html body #settingsCont .theme-btn.active {
  background: var(--zb-popup-selected) !important;
}
html body :is(#models, #cmpMenuA, #cmpMenuB) :is(input, .dropdown-search) {
  /* The legacy header has negative side margins. An opaque rectangular fill
     here paints over the popup's curved border where it meets the sides.
     Let the popup own its surface; search controls only supply text. */
  background: transparent !important;
  color: var(--zb-popup-text) !important;
}
html body :is(#models, #cmpMenuA, #cmpMenuB) input {
  border-color: var(--zb-popup-border) !important;
  border-radius: var(--zb-popup-item-radius);
}
html body :is(#models, #cmpMenuA, #cmpMenuB) input::placeholder { color: var(--zb-popup-muted); opacity: 1; }
html body :is(#models, #cmpMenuA, #cmpMenuB, #settingsCont) hr {
  background: var(--zb-popup-border) !important;
  border-color: var(--zb-popup-border) !important;
  margin: 6px 0;
}
html body :is(#models, #cmpMenuA, #cmpMenuB) :is(#modelList, .cmp-model-list) {
  scrollbar-color: var(--zb-popup-border) transparent;
}
html body #modelList::-webkit-scrollbar-track { background: transparent; }
html body #modelList::-webkit-scrollbar-thumb { background: var(--zb-popup-border); }
html body #modelList::-webkit-scrollbar-thumb:hover { background: var(--zb-popup-muted); }
html body :is(#models, #cmpMenuA, #cmpMenuB) :is([data-tier="plus"] .menuDesc, [data-tier="plus"] .cmp-model-name) {
  color: var(--zb-popup-text) !important;
}
html body :is(#attachDropdown, #cmpAttachDropdown) .attach-item i { color: var(--zb-popup-text); }
html body :is(#attachDropdown, #cmpAttachDropdown) .attach-separator { background: var(--zb-popup-border) !important; }
html body :is(#attachDropdown, #cmpAttachDropdown) :is(.attach-item.enabled, .attach-item.enabled svg, .attach-check, .checkmark) {
  color: var(--zb-popup-text) !important;
}
html body #attachDropdown .attach-item.enabled::after { background: var(--zb-popup-text) !important; }
html body #settingsCont .setting_link {
  display: flex;
  align-items: center;
  gap: 12px;
}
html body #settingsCont .setting_link .icon { margin: 0; flex: 0 0 20px; text-align: center; }
html body #settingsCont .theme-switcher { margin-top: 6px; padding: 6px 4px !important; }
html body #settingsCont .theme-buttons { margin-top: 0; }
html body :is(#models, #cmpMenuA, #cmpMenuB, #attachDropdown, #zbSidebarMoreMenu, #settingsCont) :is(a, button, input, [tabindex]):focus-visible {
  outline: 2px solid var(--zb-popup-text);
  outline-offset: -2px;
}
