/**
 * Shared glass modal shell — Create document, Quick Add, and other app dialogs.
 * Pair: .td-glass-modal-backdrop on .backdrop + .td-glass-modal on .modal
 */

.td-glass-modal-backdrop.backdrop {
  background: rgba(15, 23, 42, 0.44) !important;
  -webkit-backdrop-filter: blur(16px) saturate(1.15);
  backdrop-filter: blur(16px) saturate(1.15);
  padding: 14px;
}

.td-glass-modal-backdrop .td-glass-modal.modal {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  margin: auto;
  padding: 0 !important;
  border-radius: 16px;
  background: linear-gradient(
    165deg,
    rgba(255, 255, 255, 0.88) 0%,
    rgba(248, 250, 252, 0.78) 45%,
    rgba(241, 245, 249, 0.82) 100%
  ) !important;
  -webkit-backdrop-filter: blur(22px) saturate(1.12);
  backdrop-filter: blur(22px) saturate(1.12);
  border: 1px solid rgba(255, 255, 255, 0.72);
  box-shadow:
    0 0 0 1px rgba(15, 23, 42, 0.04) inset,
    0 28px 72px rgba(15, 23, 42, 0.2),
    0 12px 28px rgba(15, 23, 42, 0.1);
}

/* Default form dialogs (Quick Add, etc.) */
.td-glass-modal--md {
  width: min(580px, 94vw);
  max-height: min(90vh, 820px);
  height: auto;
}

/* Tall chooser-style dialogs (Create new document) */
.td-glass-modal--lg {
  width: min(680px, 96vw);
  height: calc(100vh - 40px);
  max-height: calc(100vh - 40px);
}

.td-doc-create-chooser-backdrop.td-glass-modal-backdrop {
  padding: 20px 14px;
  align-items: center;
}

.td-doc-create-chooser.td-glass-modal--lg.modal {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 40px);
  max-height: calc(100vh - 40px);
}

/* Document chooser: body fills modal; templates section grows */
.td-doc-create-chooser.td-glass-modal--lg .td-glass-modal__body {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.td-doc-create-chooser .td-glass-modal__content {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
}

.td-doc-create-chooser .td-glass-modal__content > .td-glass-modal__panel {
  flex-shrink: 0;
}

.td-doc-create-chooser .td-glass-modal__foot {
  flex-shrink: 0;
}

.td-glass-modal--wide {
  width: min(780px, 96vw) !important;
  max-height: min(92vh, 880px);
  height: auto;
}

/* Create hub (Quick Add / Deal / Booking + more) */
.td-glass-modal--compose {
  width: min(760px, 94vw) !important;
  max-height: min(94vh, 820px);
  height: auto;
}

.td-glass-modal-backdrop .td-glass-modal__head,
.td-glass-modal-backdrop .modalHead.td-glass-modal__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  min-height: 0;
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.42) !important;
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(148, 163, 184, 0.28) !important;
}

.td-glass-modal-backdrop .td-glass-modal__head .modalTitle,
.td-glass-modal-backdrop .td-glass-modal__title {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: -0.02em;
  color: #0f172a;
}

.td-glass-modal-backdrop .td-glass-modal__head .iconBtn,
.td-glass-modal-backdrop .td-glass-modal__head .td-glass-modal__icon-btn {
  width: 32px;
  height: 32px;
  font-size: 14px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.55);
  border: 1px solid rgba(226, 232, 240, 0.8);
  transition: background 0.15s, border-color 0.15s;
}

.td-glass-modal-backdrop .td-glass-modal__head .iconBtn:hover,
.td-glass-modal-backdrop .td-glass-modal__head .td-glass-modal__icon-btn:hover {
  background: rgba(255, 255, 255, 0.9);
  border-color: rgba(148, 163, 184, 0.65);
}

.td-glass-modal__head-copy {
  min-width: 0;
  flex: 1 1 auto;
}

.td-glass-modal__head-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.td-glass-modal__lede {
  margin: 4px 0 0;
  font-size: 12px;
  color: #64748b;
  line-height: 1.35;
  font-weight: 500;
  max-width: 42em;
}

.td-glass-modal-backdrop .td-glass-modal__body,
.td-glass-modal-backdrop .modalBody.td-glass-modal__body {
  padding: 0 !important;
  padding-bottom: 0 !important;
  overflow-x: hidden;
  overflow-y: hidden;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, rgba(248, 250, 252, 0.35) 0%, rgba(255, 255, 255, 0.12) 100%);
}

.td-glass-modal--md .td-glass-modal__body,
.td-glass-modal--md.modal .td-glass-modal__body {
  overflow-y: auto;
}

/* Auto-applied dialogs: scroll body when content is not in __content wrapper */
.td-glass-modal-backdrop .modalBody.td-glass-modal__body:not(:has(.td-glass-modal__content)) {
  padding: 12px 16px 16px !important;
  overflow-y: auto;
}

.td-glass-modal__content {
  width: 100%;
  box-sizing: border-box;
  margin-block: 0;
  padding: 12px 16px 10px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  scrollbar-gutter: stable;
}

.td-glass-modal__section-label,
.td-glass-modal__panel > .td-glass-modal__section-label:first-child {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #475569;
  margin: 0 0 6px;
}

.td-glass-modal__panel {
  padding: 10px 12px 8px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.78);
  background: rgba(255, 255, 255, 0.48);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.92),
    0 8px 32px rgba(15, 23, 42, 0.05);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  flex-shrink: 0;
}

.td-glass-modal-backdrop .td-glass-modal__foot,
.td-glass-modal-backdrop .modalFoot.td-glass-modal__foot {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 10px 16px !important;
  margin-top: 0;
  background: rgba(255, 255, 255, 0.42) !important;
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border-top: 1px solid rgba(148, 163, 184, 0.28) !important;
}

.td-glass-modal-backdrop .td-glass-modal__foot .btn {
  padding: 7px 14px;
  font-size: 13px;
  border-radius: 10px;
}

.td-glass-modal-backdrop .td-glass-modal__foot .btn.secondary,
.td-glass-modal-backdrop .td-glass-modal__foot .btn:not(.primary) {
  color: #475569;
  border-color: rgba(226, 232, 240, 0.95);
  background: rgba(255, 255, 255, 0.72);
  font-weight: 600;
}

html[data-theme="dark"] .td-glass-modal-backdrop .td-glass-modal {
  border-color: rgba(148, 163, 184, 0.22);
  background: linear-gradient(
    165deg,
    rgba(30, 41, 59, 0.92) 0%,
    rgba(15, 23, 42, 0.88) 100%
  ) !important;
}

html[data-theme="dark"] .td-glass-modal-backdrop .td-glass-modal__head {
  border-bottom-color: rgba(148, 163, 184, 0.2) !important;
  background: rgba(30, 41, 59, 0.55) !important;
}

html[data-theme="dark"] .td-glass-modal-backdrop .td-glass-modal__body {
  background: linear-gradient(180deg, rgba(15, 23, 42, 0.4) 0%, rgba(15, 23, 42, 0.2) 100%);
}

html[data-theme="dark"] .td-glass-modal-backdrop .td-glass-modal__foot {
  border-top-color: rgba(148, 163, 184, 0.2) !important;
  background: rgba(30, 41, 59, 0.55) !important;
}

html[data-theme="dark"] .td-glass-modal__panel {
  border-color: rgba(148, 163, 184, 0.2);
  background: rgba(30, 41, 59, 0.45);
}

html[data-theme="dark"] .td-glass-modal__title {
  color: #f1f5f9 !important;
}

html[data-theme="dark"] .td-glass-modal__lede,
html[data-theme="dark"] .td-glass-modal__section-label {
  color: #94a3b8;
}

@media (prefers-reduced-transparency: reduce) {
  .td-glass-modal-backdrop,
  .td-glass-modal-backdrop .td-glass-modal,
  .td-glass-modal-backdrop .td-glass-modal__head,
  .td-glass-modal-backdrop .td-glass-modal__foot,
  .td-glass-modal__panel {
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }

  .td-glass-modal-backdrop .td-glass-modal {
    background: #fff !important;
  }

  .td-glass-modal__panel {
    background: #f8fafc;
  }
}
