/* ElevenLabs v4 compatibility: shared controls keep their states and keyboard
   affordances when the CRM loads a module. Load after elevenlabs-v4-theme.css. */
:root {
  --el-ink-secondary: var(--dt-muted);
  --el-ink-muted: var(--dt-faint);
  --el-cta-bg: var(--dt-cta);
  --el-cta-fg: var(--dt-cta-fg);
  --el-cta-hover: var(--dt-cta-hover);
  --el-font-sans: var(--font-sans);
  --el-card-stone-hover: var(--dt-surface-3, var(--dt-hover));
  --el-shadow-card: var(--dt-card-shadow);
  --el-focus-visible: var(--dt-focus);
}
/* Keyboard navigation keeps an indicator on actions. Fields use their shared
   surface state; including text inputs here draws a frame even after a click. */
:root[data-bs-theme] :is(a, button, [role="button"], [tabindex]):not(:where(input, select, textarea, .dui-select__trigger, .dui-tabs-underline__tab, .ai-tab, .el-aset-subtab)):focus-visible {
  outline: 2px solid var(--el-focus-visible) !important;
  outline-offset: -2px;
}
/* Composite fields use their surface for focus. Do not
   surround their wrapper and inner input with a second outline or outer halo. */
@media (forced-colors: none) {
:root[data-bs-theme] body :is(
  .dt-search-field, .pn-service-search, .sb-picker-searchbox, .pbx-voice-search,
  .dui-dt-search, .salesn-search, .tts-vpicker-search-box, .aivs-avatar-search,
  .aivs-voice-search, .aivs-tts-history-search, .vp-search, .vp-field,
  .rt-search, .rt-field, .ce-search, .el-arch-composer, .ovc-composer,
  .dalia-chat__form, .dalia-composer, .ai-lang-search, .el-studio-inline-chatbar,
  .el-tpl-search-box, .ai-search-box, .el-aset-md-editor-wrap,
  .inbox-search-wrapper, .sb-el-cmd-search
):focus-within {
  border-color: transparent;
  outline: none !important;
  box-shadow: none !important;
}
:root[data-bs-theme] body :is(
  .dt-search-field, .pn-service-search, .sb-picker-searchbox, .pbx-voice-search,
  .dui-dt-search, .salesn-search, .tts-vpicker-search-box, .aivs-avatar-search,
  .aivs-voice-search, .aivs-tts-history-search, .vp-search, .vp-field,
  .rt-search, .rt-field, .ce-search, .el-arch-composer, .ovc-composer,
  .dalia-chat__form, .dalia-composer, .ai-lang-search, .el-studio-inline-chatbar,
  .el-tpl-search-box, .ai-search-box, .el-aset-md-editor-wrap,
  .inbox-search-wrapper, .sb-el-cmd-search
) :is(input, select, textarea):focus {
  outline: none !important;
  box-shadow: none !important;
}
}

/* Validation must survive the generic input border and hover resets. Native
   :valid/:invalid are styled only after the form opts into .was-validated. */
.was-validated :is(.form-control, .form-select, .form-check-input):valid {
  --el-control-validation: var(--dt-success);
}
.was-validated :is(.form-control, .form-select, .form-check-input):invalid {
  --el-control-validation: var(--dt-danger);
}
:root[data-bs-theme] :is(.form-control, .form-select, .form-check-input).is-valid {
  --el-control-validation: var(--dt-success);
}
:root[data-bs-theme] :is(.form-control, .form-select, .form-check-input):is(.is-invalid, [aria-invalid="true"]),
:root[data-bs-theme] :is(input, select, textarea)[aria-invalid="true"] {
  --el-control-validation: var(--dt-danger);
}
:root[data-bs-theme] body :is(.form-control, .form-select, .form-check-input):is(.is-valid, .is-invalid, [aria-invalid="true"]),
:root[data-bs-theme] body :is(.form-control, .form-select, .form-check-input):is(.is-valid, .is-invalid, [aria-invalid="true"]):is(:hover, :focus),
:root[data-bs-theme] body .was-validated :is(.form-control, .form-select, .form-check-input):is(:valid, :invalid),
:root[data-bs-theme] body :is(input, select, textarea)[aria-invalid="true"],
:root[data-bs-theme] body :is(input, select, textarea)[aria-invalid="true"]:is(:hover, :focus) {
  border-color: var(--el-control-validation) !important;
}
:root[data-bs-theme] body :is(.form-control, .form-select, .form-check-input):is(.is-valid, .is-invalid, [aria-invalid="true"]):focus,
:root[data-bs-theme] body .was-validated :is(.form-control, .form-select, .form-check-input):is(:valid, :invalid):focus,
:root[data-bs-theme] body :is(input, select, textarea)[aria-invalid="true"]:focus {
  box-shadow: inset 0 0 0 1px var(--el-control-validation) !important;
}

/* Joined controls keep only their outside corners rounded. The date/select
   adapters wrap the native field, so restore its inner corners too. */
:root .input-group > :is(.form-control, .form-select, .input-group-text, .btn):not(:first-child),
:root .input-group > :is(.dui-date, .dui-select):not(:first-child) > :is(input, .dui-select__trigger) {
  border-top-left-radius: 0 !important;
  border-bottom-left-radius: 0 !important;
}
:root .input-group > :is(.form-control, .form-select, .input-group-text, .btn):has(~ :is(.form-control, .form-select, .input-group-text, .btn, .dui-date, .dui-select)),
:root .input-group > :is(.dui-date, .dui-select):has(~ :is(.form-control, .form-select, .input-group-text, .btn, .dui-date, .dui-select)) > :is(input, .dui-select__trigger) {
  border-top-right-radius: 0 !important;
  border-bottom-right-radius: 0 !important;
}
:root .btn-group > .btn:not(:last-child):not(.dropdown-toggle),
:root .btn-group > .btn-group:not(:last-child) > .btn {
  border-top-right-radius: 0 !important;
  border-bottom-right-radius: 0 !important;
}
:root .btn-group > .btn:nth-child(n+3),
:root .btn-group > :not(.btn-check) + .btn,
:root .btn-group > .btn-group:not(:first-child) > .btn {
  border-top-left-radius: 0 !important;
  border-bottom-left-radius: 0 !important;
}
:root .btn-group-vertical > .btn:not(:last-child),
:root .btn-group-vertical > .btn-group:not(:last-child) > .btn {
  border-bottom-left-radius: 0 !important;
  border-bottom-right-radius: 0 !important;
}
:root .btn-group-vertical > .btn ~ .btn,
:root .btn-group-vertical > .btn-group:not(:first-child) > .btn {
  border-top-left-radius: 0 !important;
  border-top-right-radius: 0 !important;
}

:root[data-bs-theme] :is(button, .btn, .dui-select__trigger, .dui-seg__opt):is(:disabled, .disabled, [aria-disabled="true"]) {
  opacity: .5 !important;
  cursor: not-allowed;
  transform: none !important;
}
:root[data-bs-theme] :is(.form-control, .form-select):disabled {
  background-color: var(--dt-surface-2) !important;
  color: var(--dt-muted) !important;
  cursor: not-allowed;
}

/* Keep status spinners running; reduce decorative orb motion and control
   transitions without changing call/chat state or click behavior. */
.sb-more-searchbox {
  flex-shrink: 0;
  margin: 2px 2px 8px;
}
:root[data-bs-theme] body #sb-more-popover .sb-more-searchbox,
:root[data-bs-theme] body #sb-more-popover .sb-more-searchbox input {
  background: transparent !important;
}
.sb-more-empty {
  margin: 0;
  padding: 18px 10px;
  color: var(--dt-muted);
  font-size: 13px;
}
.sb-more-customize {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  gap: 10px;
  margin-top: 6px;
  padding: 10px;
  border: 0;
  border-top: 1px solid var(--dt-border);
  border-radius: 0 0 6px 6px;
  background: transparent;
  color: var(--dt-muted);
  font: inherit;
  font-size: 13px;
  text-align: left;
}
.sb-more-customize:is(:hover, :focus-visible) {
  background: var(--dt-hover);
  color: var(--dt-text);
}

@media (prefers-reduced-motion: reduce) {
  :root :is(.aag-conic-orb, .aag-big-conic-orb, .aag-big-conic-orb-wrap,
    .aag-orb-ring, .aag-chat-avatar, .el-studio-conic-orb, .el-prv-big-orb, .el-prv-orb-ring),
  :root :is(.aag-conic-orb, .aag-big-conic-orb, .aag-big-conic-orb-wrap,
    .el-studio-conic-orb, .el-prv-big-orb)::before,
  :root :is(.aag-conic-orb, .aag-big-conic-orb, .aag-big-conic-orb-wrap,
    .el-studio-conic-orb, .el-prv-big-orb)::after {
    animation: none !important;
    transition: none !important;
  }
  :root :is(.btn, .nav-link, .dui-seg__opt, .dui-seg__thumb, .dui-select__trigger),
  :root :is(.aag, .ai-agent-editor) :is(button, input, select, textarea, [role="button"]) {
    transition: none !important;
  }
}

@media (forced-colors: active) {
  :root { --el-focus-visible: var(--dt-focus); }
  :root[data-bs-theme="dark"] { --el-focus-visible: var(--dt-focus); }
}

/* Command palette: the search, actions and recent items share one surface. */
:root[data-bs-theme] body .sb-el-cmd-overlay {
  background: color-mix(in srgb, var(--dt-app) 65%, transparent);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  padding: min(8vh, 72px) 16px 24px;
  padding-top: min(8dvh, 72px);
}
:root[data-bs-theme] body .sb-el-cmd-modal {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 720px;
  min-height: min(470px, calc(100dvh - 100px));
  max-height: calc(100vh - 100px);
  max-height: calc(100dvh - 100px);
  background: var(--dt-surface);
  color: var(--dt-text);
  border: 0;
  border-radius: var(--dt-radius-lg);
  box-shadow: var(--dt-pop-shadow);
  animation: sb-command-enter var(--dt-dur-2) var(--dt-ease-out);
}
:root[data-bs-theme] body .sb-el-cmd-search {
  min-height: 54px;
  flex-shrink: 0;
  gap: 12px;
  padding: 10px 18px;
  background: var(--dt-surface);
  border-bottom: 1px solid var(--dt-border-soft);
}
:root[data-bs-theme] body .sb-el-cmd-search > i { color: var(--dt-text); font-size: 20px; }
:root[data-bs-theme] body .sb-el-cmd-search input,
:root[data-bs-theme] body .sb-el-cmd-search input:is(:hover, :focus, :focus-visible) {
  min-width: 0;
  height: 32px;
  padding: 0 !important;
  background: transparent !important;
  color: var(--dt-text) !important;
  border: 0 !important;
  border-radius: 0 !important;
  box-shadow: none !important;
  outline: 0 !important;
  font-size: 14px;
}
:root[data-bs-theme] body .sb-el-cmd-search input::placeholder { color: var(--dt-faint) !important; opacity: 1; }
:root[data-bs-theme] body .sb-el-cmd-search:focus-within { border-bottom-color: var(--dt-border-strong); }
:root[data-bs-theme] body .sb-el-cmd-body {
  flex: 1;
  min-height: 0;
  max-height: none;
  padding: 6px 8px 16px;
  background: var(--dt-surface);
  overscroll-behavior: contain;
}
:root[data-bs-theme] body .sb-cmd-sec { padding: 8px 6px 4px; color: var(--dt-muted); font-size: 12px; font-weight: 400; }
:root[data-bs-theme] body .sb-cmd-item { min-height: 52px; padding: 6px; gap: 12px; border-radius: 12px; color: var(--dt-text); }
:root[data-bs-theme] body .sb-cmd-item:is(:hover, :focus-visible, .is-selected) { background: var(--dt-surface-2); }
:root[data-bs-theme] body .sb-cmd-ico {
  width: 40px; height: 40px; border-radius: 12px;
  background: var(--dt-surface-2); border: 0; color: var(--dt-muted); font-size: 20px;
}
:root[data-bs-theme] body .sb-cmd-item.is-selected .sb-cmd-ico { background: var(--dt-surface-3); color: var(--dt-text); }
:root[data-bs-theme] body .sb-cmd-recent .sb-cmd-ico { width: 32px; height: 32px; border-radius: 50%; margin: 4px; font-size: 16px; }
:root[data-bs-theme] body .sb-cmd-txt b { color: var(--dt-text); font-size: 14px; font-weight: 500; }
:root[data-bs-theme] body .sb-cmd-txt small { color: var(--dt-muted); font-size: 13px; }
:root[data-bs-theme] body .sb-cmd-right { display: none; align-items: center; gap: 7px; padding-right: 4px; color: var(--dt-muted); font-size: 12px; }
:root[data-bs-theme] body .sb-cmd-item:is(:hover, :focus-visible, .is-selected) .sb-cmd-right { display: inline-flex; }
:root[data-bs-theme] body .sb-cmd-right kbd { display: inline-flex; padding: 3px; border-radius: 6px; background: var(--dt-surface); color: var(--dt-muted); box-shadow: none; }
:root[data-bs-theme] body .sb-el-cmd-esc { display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; width: 26px; height: 26px; padding: 0; border: 0; border-radius: 7px; background: transparent; color: var(--dt-muted); }
:root[data-bs-theme] body .sb-el-cmd-esc i { color: inherit; font-size: 16px; }
:root[data-bs-theme] body .sb-el-cmd-esc:hover { background: var(--dt-surface-2); color: var(--dt-text); }
:root[data-bs-theme] body .sb-cmd-more { display: flex; align-items: center; gap: 6px; margin: 12px 6px 0; padding: 8px; border: 0; border-radius: 8px; background: transparent; color: var(--dt-muted); font: inherit; font-size: 12px; cursor: pointer; }
:root[data-bs-theme] body .sb-cmd-more:is(:hover, .is-selected) { background: var(--dt-surface-2); color: var(--dt-text); }
.sb-cmd-empty { padding: 40px 18px; text-align: center; color: var(--dt-muted); font-size: 14px; }
@keyframes sb-command-enter { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: translateY(0); } }
@media (max-width: 560px) {
  :root[data-bs-theme] body .sb-el-cmd-overlay { padding: 16px 12px; }
  :root[data-bs-theme] body .sb-el-cmd-modal { max-height: calc(100dvh - 32px); }
  :root[data-bs-theme] body .sb-el-cmd-search input { font-size: 16px; }
  :root[data-bs-theme] body .sb-cmd-right { font-size: 0; gap: 0; }
}
@media (prefers-reduced-motion: reduce) { :root[data-bs-theme] body .sb-el-cmd-modal { animation: none; } }
@media (forced-colors: active) {
  :root[data-bs-theme] body .sb-el-cmd-search:focus-within { outline: 2px solid Highlight; outline-offset: -2px; }
  :root[data-bs-theme] body .sb-cmd-item.is-selected { outline: 1px solid Highlight; outline-offset: -1px; }
}

/* One menu surface across Bootstrap, dUI and the legacy select adapters.
   Engines retain control of placement, scrolling and keyboard selection. */
:root[data-bs-theme] body :is(
  .dropdown-menu, .dui-select__dropdown, .dui-dropdown__menu,
  .select2-dropdown, .choices__list--dropdown, .choices__list[aria-expanded],
  ul.menu.is-visible, ul.menu--select.is-visible, ul.menusearchmarccmenu.is-visible
):not(:where(.dui-select__dropdown--clean)) {
  background: var(--dt-overlay) !important;
  color: var(--dt-text);
  border: 0 !important;
  border-radius: 10px !important;
  box-shadow: none !important;
}
:root[data-bs-theme] body :is(
  .dui-select__search, .select2-dropdown .select2-search__field,
  .choices__list--dropdown .choices__input, li.menusearchmarcc input
) {
  background: transparent !important;
  color: var(--dt-text) !important;
  border: 0 !important;
  border-radius: 0 !important;
  box-shadow: none !important;
}
:root[data-bs-theme] body :is(
  .dui-select__search-wrap, .select2-search--dropdown, li.menusearchmarcc
):not(:where(.dui-select__dropdown--clean .dui-select__search-wrap)) {
  border-color: transparent !important;
  background: var(--dt-overlay) !important;
}
@media (forced-colors: none) {
  :root[data-bs-theme] body :is(
    .dui-select__search, .select2-dropdown .select2-search__field,
    .choices__list--dropdown .choices__input, li.menusearchmarcc input
  ):focus {
    outline: none !important;
  }
  :root[data-bs-theme] body :is(
    .dui-select__search-wrap, .select2-search--dropdown, li.menusearchmarcc
  ):not(:where(.dui-select__dropdown--clean .dui-select__search-wrap)):focus-within {
    background: var(--dt-field-hover) !important;
    outline: none !important;
    box-shadow: none !important;
  }
  :root[data-bs-theme] body :is(
    .dropdown-item, .dui-menu__item, .dui-select__option,
    .select2-results__option, .choices__item--selectable, .sb-cmd-item
  ):focus-visible {
    outline: none !important;
  }
}
@media (forced-colors: active) {
  :root[data-bs-theme] body :is(
    .dui-select__search-wrap, .select2-search--dropdown, li.menusearchmarcc
  ):focus-within {
    outline: 2px solid Highlight !important;
    outline-offset: -2px;
  }
}

/* Sidebar popovers share the same surface as dUI menus. These rules only style
   the existing markup; category membership, favorites and navigation stay owned
   by the sidebar renderer. */
:root[data-bs-theme] body :is(.sb-switch-pop, .sb-section-picker, .sb-more-popover) {
  --sn-bg: var(--dt-overlay);
  --sn-ink: var(--dt-text);
  --sn-muted: var(--dt-muted);
  --sn-border: var(--dt-border-strong);
  --sn-hover: var(--dt-hover);
  background: var(--dt-overlay);
  color: var(--dt-text);
  border-color: var(--dt-border-strong);
  box-shadow: none;
}
:root[data-bs-theme] body .sb-more-popover {
  width: min(244px, calc(100vw - 24px));
  max-height: min(460px, calc(100dvh - 24px));
}
:root[data-bs-theme] body :is(.sb-switch-head, .sb-switch-head span, .sb-switch-optxt small, .sb-more-tip-txt) {
  color: var(--dt-muted);
}
:root[data-bs-theme] body :is(.sb-switch-presets, .sb-switch-dot, .sb-more-tip, .sb-picker-subsec) {
  background: var(--dt-surface-2);
  border-color: var(--dt-border);
  color: var(--dt-muted);
}
:root[data-bs-theme] body .sb-more-tip-ico {
  background: var(--dt-active);
  color: var(--dt-text);
}
:root[data-bs-theme] body .sb-picker-mini-btn {
  min-height: 28px;
  background: var(--dt-surface-2);
  color: var(--dt-text);
  border-color: var(--dt-border);
}
:root[data-bs-theme] body :is(.sb-picker-star, .sb-more-pin) { color: var(--dt-muted); }
:root[data-bs-theme] body :is(.sb-picker-star[aria-pressed="true"], .sb-more-pin.is-on) {
  background: var(--dt-active);
  color: var(--dt-text);
}
:root[data-bs-theme] body :is(.sb-picker-star, .sb-more-pin, .sb-cat-move, .sb-picker-move, .sb-picker-mini-btn):hover:not(:disabled) {
  background: var(--dt-hover);
  color: var(--dt-text);
}
:root[data-bs-theme] body :is(.sb-more-row:hover, .sb-more-row:focus-within, .sb-switch-row:focus-within) {
  background: var(--dt-hover);
}
:root[data-bs-theme] body .sb-more-row:focus-within .sb-more-pin,
:root[data-bs-theme] body .sb-more-pin:focus-visible,
:root[data-bs-theme] body .sb-switch-row:focus-within .sb-switch-order { opacity: 1; }
:root[data-bs-theme] body :is(#sbTopFixed, #sbBottomFixed) .sb-switch-btn:is(:hover, [aria-expanded="true"]) {
  border-color: var(--dt-border-strong);
  box-shadow: none;
}

/* Platform picker: chromatic marks and a gently raised selected option. */
:root[data-bs-theme] body .sb-switch-pop {
  box-shadow: var(--dt-pop-shadow);
}
:root[data-bs-theme] body .sb-switch-pop .sb-switch-list {
  gap: 4px;
  padding: 3px;
}
:root[data-bs-theme] body .sb-switch-pop .sb-switch-opt {
  --sb-hub-color: var(--dt-blue);
  border: 1px solid transparent;
}
:root[data-bs-theme] body .sb-switch-pop .sb-switch-opt[data-mode="creative"] {
  --sb-hub-color: color-mix(in srgb, var(--dt-blue) 50%, var(--dt-coral));
}
:root[data-bs-theme] body .sb-switch-pop .sb-switch-opt[data-mode="hr"] {
  --sb-hub-color: var(--dt-success);
}
:root[data-bs-theme] body .sb-switch-pop .sb-switch-opt[data-mode="broker"] {
  --sb-hub-color: var(--dt-warning);
}
:root[data-bs-theme] body .sb-switch-pop .sb-switch-opt[data-mode="partners"] {
  --sb-hub-color: var(--dt-cyan);
}
:root[data-bs-theme] body .sb-switch-pop .sb-switch-opt > .sb-switch-dot {
  border: 0;
  border-radius: 50%;
  color: var(--dt-cta-fg);
  background: radial-gradient(circle at 28% 20%, color-mix(in srgb, var(--sb-hub-color) 45%, var(--dt-cta-fg)), var(--sb-hub-color) 68%);
}
:root[data-bs-theme] body .sb-switch-pop .sb-switch-dot > .ti { opacity: 1; }
:root[data-bs-theme] body .sb-switch-pop .sb-switch-opt.is-current {
  background: var(--dt-surface-2);
  border-color: var(--dt-border);
  box-shadow: 0 2px 6px color-mix(in srgb, var(--dt-backdrop) 35%, transparent);
}
:root[data-bs-theme] body .sb-switch-pop .sb-switch-check {
  background: transparent;
  border-color: transparent;
  color: var(--dt-muted);
}
:root[data-bs-theme] body .sb-switch-pop .sb-switch-opt:focus-visible {
  outline: 2px solid var(--dt-focus);
  outline-offset: -2px;
}
@media (forced-colors: active) {
  :root[data-bs-theme] body .sb-switch-pop .sb-switch-opt.is-current { border-color: Highlight; }
  :root[data-bs-theme] body .sb-switch-pop .sb-switch-opt:focus-visible { outline-color: Highlight; }
}

/* Long labels and translated actions must not push Close out of the viewport. */
:root[data-bs-theme] body .sb-picker-head { flex-wrap: wrap; align-items: flex-start; }
:root[data-bs-theme] body .sb-picker-head > div:first-child {
  flex: 1 1 140px;
  min-width: 0;
  overflow-wrap: anywhere;
}
:root[data-bs-theme] body .sb-picker-head-btns { flex-wrap: wrap; max-width: 100%; margin-left: auto; }
:root[data-bs-theme] body .sb-picker-head-btns .sb-picker-close { margin-left: auto; width: 28px; height: 28px; }
@media (max-width: 480px) {
  :root[data-bs-theme] body .sb-picker-head-btns { flex-basis: 100%; margin-left: 0; }
}
@media (hover: none), (pointer: coarse) {
  :root[data-bs-theme] body :is(.sb-more-pin, .sb-switch-order) { opacity: 1; }
  :root[data-bs-theme] body :is(.sb-more-pin, .sb-picker-star) { min-width: 32px; min-height: 32px; }
}
@media (prefers-reduced-motion: reduce) {
  :root[data-bs-theme] body :is(.sb-more-popover, .sb-switch-pop, .sb-section-picker) { animation: none !important; }
}
