/* ==========================================================================
   Shared Primitives, Scrollbars, Context Menus, Toasts & Native Dialog Modals
   ========================================================================== */

[hidden] {
  display: none !important;
}

/* Desktop Floating Overlay Scrollbar (.bm-overlay-sb) — zero gutter, 1.2s auto-hide */
.scroller {
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.scroller::-webkit-scrollbar {
  width: 0;
  height: 0;
  display: none;
}

.timeline-scroller {
  scrollbar-width: thin;
  scrollbar-color: light-dark(rgba(100, 116, 139, 0.5), rgba(113, 113, 122, 0.55)) transparent;
}

.timeline-scroller::-webkit-scrollbar {
  display: block;
  height: 5px;
}

.timeline-scroller::-webkit-scrollbar-button {
  display: none;
}

.timeline-scroller::-webkit-scrollbar-thumb {
  background: light-dark(rgba(100, 116, 139, 0.5), rgba(113, 113, 122, 0.55));
  border-radius: 999px;
}

.timeline-scroller::-webkit-scrollbar-track {
  background: transparent;
}

.bm-overlay-sb {
  position: fixed;
  z-index: 95;
  width: 10px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.28s ease-out;
}

.bm-overlay-sb.is-visible {
  opacity: 1;
  pointer-events: auto;
}

.bm-overlay-sb-thumb {
  position: absolute;
  top: 0;
  right: 2px;
  width: 4px;
  min-height: 36px;
  border-radius: 999px;
  background: light-dark(rgba(100, 116, 139, 0.72), rgba(113, 113, 122, 0.72));
  transition: width 0.14s ease, background-color 0.14s ease;
  will-change: transform;
}

.bm-overlay-sb:hover .bm-overlay-sb-thumb,
.bm-overlay-sb.is-dragging .bm-overlay-sb-thumb {
  width: 6px;
  right: 1px;
  background: light-dark(rgba(71, 85, 105, 0.92), rgba(161, 161, 170, 0.92));
}

@keyframes spinSlow {
  to {
    transform: rotate(360deg);
  }
}

.spin-icon {
  animation: spinSlow 0.9s linear infinite;
}

/* Segmented controls (support both aria-pressed and .is-active) */
.segmented .seg-btn.is-active,
.segmented button[aria-pressed="true"] {
  background-color: var(--surface);
  color: var(--fg);
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.14);
}

/* Shared button helpers */
.btn-sm {
  height: 30px;
  padding: 0 12px;
  font-size: 12.5px;
  border-radius: 7px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn-secondary {
  border: 1px solid var(--border);
  background: var(--surface-low);
  color: var(--fg);
  font-family: inherit;
  font-weight: 500;
  cursor: pointer;
}

.btn-secondary:hover {
  background: var(--pill-hover);
}

.btn-danger {
  border: 1px solid color-mix(in srgb, var(--danger) 40%, var(--border));
  background: var(--surface);
  color: var(--danger);
  font-family: inherit;
  font-weight: 500;
  cursor: pointer;
}

.btn-danger:hover {
  background: var(--danger-bg);
}

.btn-danger-solid {
  border: 1px solid var(--danger);
  background: var(--danger);
  color: #ffffff;
  font-family: inherit;
  font-weight: 600;
  border-radius: 8px;
  padding: 8px 16px;
  cursor: pointer;
}

.btn-danger-solid:hover {
  filter: brightness(0.92);
}

/* Toggle Switch (.bm-switch) */
.bm-switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  cursor: pointer;
}

.bm-switch input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.bm-switch-track {
  width: 38px;
  height: 22px;
  border-radius: 999px;
  background: var(--surface-high);
  border: 1px solid var(--border);
  position: relative;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.bm-switch-track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--fg-muted);
  transition: transform 0.15s ease, background-color 0.15s ease;
}

.bm-switch input:checked + .bm-switch-track {
  background: var(--primary);
  border-color: var(--primary);
}

.bm-switch input:checked + .bm-switch-track::after {
  transform: translateX(16px);
  background: #ffffff;
}

/* Context Menu Popover */
.ctx-menu {
  position: fixed;
  margin: 0;
  padding: 5px;
  min-width: 210px;
  max-width: 290px;
  background: var(--surface);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 9px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.32);
  z-index: 200;
}

.ctx-item {
  width: 100%;
  padding: 7px 10px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--fg);
  font-family: inherit;
  font-size: 12.5px;
  display: flex;
  align-items: center;
  gap: 9px;
  cursor: pointer;
  text-align: left;
}

.ctx-item:hover:not(:disabled) {
  background: var(--hover);
}

.ctx-item.ctx-danger {
  color: var(--danger);
}

.ctx-icon {
  width: 16px;
  height: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--fg-muted);
  flex-shrink: 0;
}

.ctx-item.ctx-danger .ctx-icon {
  color: var(--danger);
}

.ctx-swatch {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.25);
}

.ctx-label {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ctx-chevron {
  color: var(--fg-muted);
  display: inline-flex;
}

.ctx-sep {
  border: none;
  border-top: 1px solid var(--border-subtle);
  margin: 4px 6px;
}

.ctx-submenu-wrap {
  position: relative;
}

.ctx-submenu {
  display: none;
  position: absolute;
  left: 100%;
  top: -4px;
  min-width: 195px;
  max-height: 320px;
  overflow-y: auto;
  padding: 5px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 9px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.34);
  z-index: 210;
}

.ctx-submenu-wrap:hover > .ctx-submenu,
.ctx-submenu-wrap:focus-within > .ctx-submenu {
  display: block;
}

/* Toast Notifications */
.toast-region {
  position: fixed;
  right: 18px;
  bottom: 36px;
  z-index: 250;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast-item {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  min-width: 240px;
  max-width: 380px;
  border-radius: 9px;
  background: var(--surface);
  color: var(--fg);
  border: 1px solid var(--border);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.28);
  font-size: 13px;
}

.toast-item.toast-error {
  border-left: 4px solid var(--danger);
}

.toast-item.toast-success {
  border-left: 4px solid var(--success);
}

.toast-item.toast-info {
  border-left: 4px solid var(--primary);
}

.toast-msg {
  flex: 1;
}

.toast-close {
  border: none;
  background: transparent;
  color: var(--fg-muted);
  display: inline-flex;
  cursor: pointer;
}

/* Native <dialog> Modals */
dialog.app-modal {
  margin: auto;
  padding: 0;
  width: min(500px, 92vw);
  max-height: 90vh;
  overflow: auto;
  overscroll-behavior: contain;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--fg);
  box-shadow: 0 22px 60px rgba(0, 0, 0, 0.42);
}

dialog.app-modal::backdrop {
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(2px);
}

.app-modal-hdr {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-subtle);
}

.app-modal-hdr-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.app-modal-icon {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: var(--primary-container);
  color: var(--on-primary-container);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.app-modal-title {
  margin: 0;
  font-size: 15.5px;
  font-weight: 700;
}

.app-modal-sub {
  margin: 2px 0 0 0;
  font-size: 12.5px;
  color: var(--fg-muted);
}

.app-modal-close {
  border: none;
  background: transparent;
  color: var(--fg-muted);
  display: inline-flex;
  padding: 4px;
  border-radius: 6px;
  cursor: pointer;
}

.app-modal-close:hover {
  background: var(--hover);
  color: var(--fg);
}

.app-modal-body {
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 11px;
}

.app-modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 20px;
  border-top: 1px solid var(--border-subtle);
  background: var(--surface-low);
}

.modal-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.modal-field label {
  font-size: 12px;
  font-weight: 600;
  color: var(--fg-muted);
}

.modal-input,
.modal-select,
.modal-textarea {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface-low);
  color: var(--fg);
  font-family: inherit;
  font-size: 13px;
}

.input-with-btn {
  display: flex;
  align-items: center;
  gap: 6px;
}

.input-with-btn .modal-input {
  flex: 1;
}

.modal-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.modal-check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.modal-banner-info {
  padding: 9px 12px;
  border-radius: 8px;
  background: var(--primary-container);
  color: var(--on-primary-container);
  font-size: 12.5px;
}

.modal-banner-error {
  padding: 8px 11px;
  border-radius: 7px;
  background: var(--danger-bg);
  color: var(--danger);
  font-size: 12.5px;
}

/* Image Size Choice Cards */
.img-size-preview-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
}

#img-size-preview {
  width: 72px;
  height: 72px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.img-opt-card {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-low);
  color: var(--fg);
  font-family: inherit;
  text-align: left;
  cursor: pointer;
}

.img-opt-card.is-selected {
  border-color: var(--primary);
  background: var(--primary-container);
  color: var(--on-primary-container);
}

.img-opt-title {
  font-size: 13px;
  font-weight: 600;
}

.img-opt-sub {
  font-size: 12px;
  opacity: 0.85;
  margin-top: 2px;
}
