/* ==========================================================================
   App Drawer — unified side sheet for forms, confirms, and detail panels
   Change styles here to update every drawer across the application.
   ========================================================================== */

.app-drawer-root {
  position: fixed;
  inset: 0;
  z-index: 100060;
  pointer-events: none;
}

.app-drawer-root[hidden] {
  display: none !important;
}

.app-drawer-root.is-open {
  pointer-events: auto;
}

.app-drawer-backdrop {
  position: absolute;
  inset: 0;
  z-index: 1;
  /* Light dim only — no blur (softens drawer text in Chromium). */
  background: rgba(15, 23, 42, 0.22);
  opacity: 0;
  transition: opacity 0.34s cubic-bezier(0.16, 1, 0.3, 1);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  filter: none;
}

/* Legacy modal overlay hosts drawer panel content — must not stack a second backdrop. */
.is-drawer-host,
.is-drawer-host.modal-overlay,
.is-drawer-host.ce-modal-overlay,
.is-drawer-host.ki-modal-overlay,
.is-drawer-host.cgp-modal,
.is-drawer-host[style*="display: flex"],
.is-drawer-host[style*="display:flex"] {
  display: none !important;
  background: transparent !important;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
  pointer-events: none !important;
  z-index: auto !important;
}

.app-drawer-root.is-open .app-drawer-backdrop {
  opacity: 1;
}

.app-drawer {
  position: absolute;
  top: 0;
  right: 0;
  z-index: 2;
  height: 100%;
  width: min(480px, 100vw);
  background: #ffffff;
  border-left: 1px solid #e2e8f0;
  box-shadow: -20px 0 56px rgba(15, 23, 42, 0.12);
  display: flex;
  flex-direction: column;
  transform: translate3d(104%, 0, 0);
  transition: transform 0.34s cubic-bezier(0.16, 1, 0.3, 1);
  /* Keep panel text crisp against any page/backdrop filters */
  isolation: isolate;
  filter: none !important;
  -webkit-backdrop-filter: none !important;
  backdrop-filter: none !important;
  -webkit-font-smoothing: antialiased;
}

.app-drawer-root.is-open .app-drawer {
  transform: translate3d(0, 0, 0);
}

.app-drawer-root.is-open .app-drawer__header,
.app-drawer-root.is-open .app-drawer__body,
.app-drawer-root.is-open .app-drawer__footer {
  opacity: 1;
}

.app-drawer--sm {
  width: min(400px, 100vw);
}

.app-drawer--md {
  width: min(480px, 100vw);
}

.app-drawer--lg {
  width: min(640px, 100vw);
}

.app-drawer--xl {
  width: min(760px, 100vw);
}

/* Header */
.app-drawer__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 22px 22px 18px;
  border-bottom: 1px solid #e2e8f0;
  flex-shrink: 0;
  background: #ffffff;
  opacity: 0;
  /* Avoid translateY on text stacks — softens glyphs in Chromium with delayed opacity. */
  transition: opacity 0.22s cubic-bezier(0.16, 1, 0.3, 1) 0.05s;
}

.app-drawer__header-main {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.app-drawer__header-icon {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: rgba(var(--admin-primary-rgb, 37, 99, 235), 0.1);
  border: 1px solid rgba(var(--admin-primary-rgb, 37, 99, 235), 0.18);
  color: var(--admin-primary, #2563eb);
}

.app-drawer__header-icon svg,
.app-drawer__header-icon .ti {
  width: 18px;
  height: 18px;
}

.app-drawer__title-wrap {
  min-width: 0;
}

.app-drawer__title {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  line-height: 1.25;
  color: #0f172a;
  letter-spacing: -0.02em;
}

.app-drawer__subtitle {
  margin: 4px 0 0;
  font-size: 13px;
  line-height: 1.45;
  color: #64748b;
}

.app-drawer__close {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  border: none;
  border-radius: 10px;
  background: #f8fafc;
  color: #64748b;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.app-drawer__close:hover {
  background: #f1f5f9;
  color: #0f172a;
}

.app-drawer__close svg {
  width: 18px;
  height: 18px;
}

/* Legacy modal bridge: actions lifted from .modal-header (e.g. Refresh Points) */
.app-drawer-legacy-header-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 0 0 16px;
  padding: 0 0 4px;
}

/* Body */
.app-drawer__body {
  flex: 1;
  overflow-y: auto;
  padding: 22px;
  background: #ffffff;
  opacity: 0;
  transition: opacity 0.22s cubic-bezier(0.16, 1, 0.3, 1) 0.08s;
}

.app-drawer__message {
  margin: 0;
  font-size: 14px;
  line-height: 1.6;
  color: #475569;
}

/* Footer */
.app-drawer__footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 22px 22px;
  border-top: 1px solid #e2e8f0;
  background: #f8fafc;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity 0.22s cubic-bezier(0.16, 1, 0.3, 1) 0.1s;
}

.app-drawer__footer--stacked {
  flex-direction: column;
  align-items: stretch;
}

.app-drawer__footer--stacked .app-drawer-btn {
  width: 100%;
  justify-content: center;
}

/* Form fields */
.app-drawer-form {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.app-drawer-form__group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.app-drawer-form__label {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #64748b;
}

.app-drawer-form__required {
  color: #dc2626;
}

.app-drawer-form__input,
.app-drawer-form__textarea,
.app-drawer-form__select {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  background: #f8fafc;
  color: #0f172a;
  font-size: 14px;
  font-family: inherit;
  line-height: 1.45;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.app-drawer-form__textarea {
  min-height: 110px;
  resize: vertical;
}

.app-drawer-form__input:focus,
.app-drawer-form__textarea:focus,
.app-drawer-form__select:focus {
  outline: none;
  border-color: var(--admin-primary, #2563eb);
  box-shadow: 0 0 0 3px rgba(var(--admin-primary-rgb, 37, 99, 235), 0.12);
  background: #ffffff;
}

.app-drawer-form__hint {
  font-size: 12px;
  color: #94a3b8;
  line-height: 1.4;
}

.app-drawer-form__group .ui-check {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  gap: 10px;
  width: auto;
  min-height: 0;
  padding: 2px 0;
  font-size: 14px;
  font-weight: 500;
  letter-spacing: normal;
  text-transform: none;
  color: #334155;
}

.app-drawer-form__group .ui-check input[type="checkbox"] {
  width: 16px;
  height: 16px;
  min-height: 0;
  margin: 0;
  border: 0;
  border-radius: 4px;
  background: transparent;
  box-shadow: none;
}

.app-drawer-form__group .ui-check > span {
  line-height: 1.4;
}

/* Buttons */
.app-drawer-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: 10px;
  border: 1px solid transparent;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.app-drawer-btn--ghost {
  background: #ffffff;
  border-color: #e2e8f0;
  color: #475569;
}

.app-drawer-btn--ghost:hover {
  background: #f8fafc;
  color: #0f172a;
}

.app-drawer-btn--primary {
  background: var(--admin-primary, #2563eb);
  border-color: var(--admin-primary, #2563eb);
  color: #ffffff;
}

.app-drawer-btn--primary:hover {
  background: var(--admin-primary-dark, #1d4ed8);
  border-color: var(--admin-primary-dark, #1d4ed8);
}

.app-drawer-btn--danger {
  background: #dc2626;
  border-color: #dc2626;
  color: #ffffff;
}

.app-drawer-btn--danger:hover {
  background: #b91c1c;
  border-color: #b91c1c;
}

/* Body scroll lock */
body.app-drawer-open {
  overflow: hidden;
}

/* Mobile */
@media (max-width: 640px) {
  .app-drawer,
  .app-drawer--sm,
  .app-drawer--md,
  .app-drawer--lg,
  .app-drawer--xl {
    width: 100vw;
  }

  .app-drawer__header,
  .app-drawer__body,
  .app-drawer__footer {
    padding-left: 16px;
    padding-right: 16px;
  }

  .app-drawer__footer {
    flex-direction: column-reverse;
    align-items: stretch;
  }

  .app-drawer__footer .app-drawer-btn {
    width: 100%;
    justify-content: center;
  }
}

[data-theme="dark"] .app-drawer,
[data-theme="dark"] .app-drawer__header,
[data-theme="dark"] .app-drawer__body {
  background: #ffffff !important;
  border-color: #e2e8f0 !important;
}

[data-theme="dark"] .app-drawer__title {
  color: #0f172a !important;
}

[data-theme="dark"] .app-drawer__footer {
  background: #f8fafc !important;
}

/* Loading state */
.app-drawer-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 48px 24px;
  text-align: center;
}

.app-drawer-loading__spinner {
  width: 40px;
  height: 40px;
  border: 3px solid #e2e8f0;
  border-top-color: var(--admin-primary, #2563eb);
  border-radius: 50%;
  animation: app-drawer-spin 0.8s linear infinite;
}

.app-drawer-loading__text {
  margin: 0;
  font-size: 14px;
  color: #64748b;
}

@keyframes app-drawer-spin {
  to { transform: rotate(360deg); }
}

/* Legacy modal/panel content ported into drawer — flatten nested card chrome */
.app-drawer-legacy-content {
  color: inherit;
  width: 100% !important;
  max-width: none !important;
  min-width: 0 !important;
  margin: 0 !important;
  border: none !important;
  border-radius: 0 !important;
  box-shadow: none !important;
  background: transparent !important;
  background-image: none !important;
  max-height: none !important;
  height: auto !important;
  overflow: visible !important;
  animation: none !important;
  transform: none !important;
}

/* Nested titles / close buttons — drawer chrome already has these */
.app-drawer-legacy-content > .modal-header,
.app-drawer-legacy-content > .ki-modal-header,
.app-drawer-legacy-content > .ce-modal-header,
.app-drawer-legacy-content > .ce-modal__header,
.app-drawer-legacy-content > .shield-modal-header,
.app-drawer-legacy-content > .vax-modal-header,
.app-drawer-legacy-content > .vac-modal-head,
.app-drawer-legacy-content > .vcp-modal-header,
.app-drawer-legacy-content > .vpt-modal-head,
.app-drawer-legacy-content > .leads-modal-header,
.app-drawer-legacy-content > .rp-modal-h,
.app-drawer-legacy-content > .view-offering-header,
.app-drawer-legacy-content > .trk-modal-header-top,
.app-drawer-legacy-content > .bdm-collateral-modal-head,
.app-drawer-legacy-content > .bdm-session-break-modal__head,
.app-drawer-legacy-content > .bdm-work-report-modal__head,
.app-drawer-legacy-content > .ob-modal-header,
.app-drawer-legacy-content > .pa-bulk-modal__header,
.app-drawer-legacy-content .modal-header,
.app-drawer-legacy-content .view-offering-header {
  display: none !important;
}

.app-drawer-legacy-content > .modal-close,
.app-drawer-legacy-content > .ki-modal-close,
.app-drawer-legacy-content > .ce-modal-close,
.app-drawer-legacy-content .modal-header .modal-close,
.app-drawer-legacy-content .ki-modal-header .ki-modal-close,
.app-drawer-legacy-content .modal-close {
  display: none !important;
}

/* Body padding belongs to the drawer, not a nested card */
.app-drawer-legacy-content > .modal-body,
.app-drawer-legacy-content > .ki-modal-body,
.app-drawer-legacy-content > .ce-modal-body,
.app-drawer-legacy-content > .shield-modal-body,
.app-drawer-legacy-content > .vax-modal-body,
.app-drawer-legacy-content > .leads-modal-body {
  padding: 0 !important;
  margin: 0 !important;
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
}

/* Legacy embedded footers — flex column so content scrolls and footer stays pinned */
.app-drawer__body:has(> .app-drawer-legacy-content .modal-footer),
.app-drawer__body:has(> .app-drawer-legacy-content .ce-modal-footer),
.app-drawer__body:has(> .app-drawer-legacy-content .ki-modal-footer),
.app-drawer__body:has(> .app-drawer-legacy-content .shield-modal-footer) {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 0;
}

.app-drawer__body > .app-drawer-legacy-content:has(.modal-footer),
.app-drawer__body > .app-drawer-legacy-content:has(.ce-modal-footer),
.app-drawer__body > .app-drawer-legacy-content:has(.ki-modal-footer),
.app-drawer__body > .app-drawer-legacy-content:has(.shield-modal-footer) {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  height: 100% !important;
  overflow: hidden !important;
}

.app-drawer-legacy-content:has(.modal-footer) > .modal-body,
.app-drawer-legacy-content:has(.ce-modal-footer) > .ce-modal-body,
.app-drawer-legacy-content:has(.ki-modal-footer) > .ki-modal-body,
.app-drawer-legacy-content:has(.shield-modal-footer) > .shield-modal-body,
.app-drawer-legacy-content .ce-modal-body:has(.modal-footer),
.app-drawer-legacy-content .modal-body:has(.modal-footer) {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  padding: 22px 22px 0 !important;
}

.app-drawer-legacy-content form:has(.modal-footer),
.app-drawer-legacy-content form:has(.ce-modal-footer),
.app-drawer-legacy-content form:has(.ki-modal-footer),
.app-drawer-legacy-content form:has(.shield-modal-footer) {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.app-drawer-legacy-content form:has(.modal-footer) > :not(.modal-footer):not(.ce-modal-footer):not(.ki-modal-footer):not(.shield-modal-footer),
.app-drawer-legacy-content .ce-modal-body:has(> .modal-footer) > :not(.modal-footer):not(.ce-modal-footer),
.app-drawer-legacy-content .modal-body:has(> .modal-footer) > :not(.modal-footer):not(.ce-modal-footer) {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding-bottom: 22px;
}

.app-drawer-legacy-content .modal-footer,
.app-drawer-legacy-content .ce-modal-footer,
.app-drawer-legacy-content .ki-modal-footer,
.app-drawer-legacy-content .shield-modal-footer,
.app-drawer-legacy-content .leads-modal-footer,
.app-drawer-legacy-content .ob-modal-footer {
  flex-shrink: 0;
  position: static !important;
  margin: 0;
  padding: 16px 22px 22px;
  border-top: 1px solid #e2e8f0;
  background: #f8fafc;
  z-index: auto;
}

/* Any direct child still carrying card chrome */
.app-drawer__body > .modal-content,
.app-drawer__body > .ki-modal-content,
.app-drawer__body > .ce-modal-content,
.app-drawer__body > .ob-modal,
.app-drawer__body > .rp-modal,
.app-drawer__body > .shield-modal,
.app-drawer__body > .vax-modal,
.app-drawer__body > .vac-modal-dialog,
.app-drawer__body > .vcp-modal,
.app-drawer__body > .vpt-modal,
.app-drawer__body > .leads-modal,
.app-drawer__body > .trk-modal-box,
.app-drawer__body > .bdm-collateral-modal-dialog,
.app-drawer__body > .bdm-session-break-modal__dialog,
.app-drawer__body > .bdm-work-report-modal__dialog,
.app-drawer__body > .bdm-preview-dialog,
.app-drawer__body > .bdm-pay-modal-dialog,
.app-drawer__body > .rs-checkout-modal,
.app-drawer__body > .verification-popup-content,
.app-drawer__body > .pa-bulk-modal {
  width: 100% !important;
  max-width: none !important;
  margin: 0 !important;
  border: none !important;
  border-radius: 0 !important;
  box-shadow: none !important;
  background: transparent !important;
  max-height: none !important;
  overflow: visible !important;
  animation: none !important;
}

/* Dialog variant */
.app-drawer-dialog {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 14px;
  padding: 8px 0;
}

.app-drawer-dialog__icon {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 22px;
  font-weight: 700;
}

.app-drawer-dialog__icon--success { background: rgba(34, 197, 94, 0.12); color: #16a34a; }
.app-drawer-dialog__icon--warning { background: rgba(217, 119, 6, 0.12); color: #d97706; }
.app-drawer-dialog__icon--error { background: rgba(220, 38, 38, 0.12); color: #dc2626; }
.app-drawer-dialog__icon--info { background: rgba(var(--admin-primary-rgb, 37, 99, 235), 0.12); color: var(--admin-primary, #2563eb); }

@media (prefers-reduced-motion: reduce) {
  .app-drawer-backdrop,
  .app-drawer,
  .app-drawer__header,
  .app-drawer__body,
  .app-drawer__footer {
    transition: none !important;
  }

  .app-drawer-root.is-open .app-drawer__header,
  .app-drawer-root.is-open .app-drawer__body,
  .app-drawer-root.is-open .app-drawer__footer {
    opacity: 1;
    transform: none;
  }
}
