/* Shared modal comfort, scoped to partner/admin/media panels. No form logic. */
:root body.panel-compact :is(dialog, [role="dialog"]) {
  --panel-modal-field: var(--compact-field);
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
/* A lighter hierarchy for all panel dialogs, without changing form behavior. */
:root body.panel-compact :is(dialog, [role="dialog"]) :is(h1, h2, h3) {
  font-size: 15px !important;
  font-weight: 500 !important;
  line-height: 1.35 !important;
  letter-spacing: -.15px !important;
}
:root body.panel-compact :is(dialog, [role="dialog"]) :is(label, legend) {
  font-size: 12px !important;
  font-weight: 500 !important;
  line-height: 1.4 !important;
}
:root body.panel-compact :is(dialog, [role="dialog"]) :is(p, small) {
  font-weight: 500;
  line-height: 1.45 !important;
}
:root body.panel-compact :is(dialog, [role="dialog"]) :is(.btn, .media-btn,
  .confirm-modal-cancel, .confirm-modal-submit) { font-weight: 500 !important; }
:root body.panel-compact :is(dialog, [role="dialog"]) :is(.cash-modal-fields,
  .cash-modal-card > header, .cash-modal-card > footer, .service-credit-modal-copy,
  .service-credit-modal-form, .receipt-preview-card > header) { padding: 12px; gap: 10px; }
:root body.panel-compact :is(dialog, [role="dialog"]) .confirm-modal-card { padding: 22px 16px 16px; }
:root body.panel-compact :is(dialog, [role="dialog"]) .confirm-modal-icon {
  width: 42px; height: 42px; margin-bottom: 12px; border-radius: 12px; font-size: 20px;
}
:root body.panel-compact .timeline-create-surface { border-radius: 14px; border-color: #d6e0db; }
:root body.panel-compact .timeline-create-dialog .timeline-create-header {
  padding: 8px 12px;
  gap: 10px;
  background: #fff;
  border-bottom-color: #edf2ef;
}
:root body.panel-compact .timeline-create-dialog .timeline-create-close {
  width: 36px; height: 36px; min-height: 36px; flex-basis: 36px;
  font-size: 22px !important; background: #f3f6f4; color: #52615a;
}
:root body.panel-compact .timeline-create-dialog .timeline-create-fields { padding: 12px; gap: 10px; }
:root body.panel-compact .timeline-create-dialog .timeline-create-footer {
  padding: 10px 12px; gap: 8px; background: #f8faf9; border-top-color: #edf2ef;
}
:root body.panel-compact .timeline-create-dialog .timeline-create-fields :is(input:not([type="file"]):not([type="checkbox"]):not([type="radio"]), select, textarea) {
  margin-top: 4px; border-color: #d6e0db; background: #fbfcfb;
}
:root body.panel-compact .timeline-create-dialog .timeline-create-fields label > small {
  margin-top: 4px; color: #617069; font-size: 12px !important; font-weight: 500;
}
:root body.panel-compact .timeline-create-dialog .custom-file-control { padding: 5px; border-color: #d6e0db; border-radius: 10px; }
:root body.panel-compact .timeline-create-dialog .timeline-unlabelled-field > :is(input, textarea, .custom-file-control) { margin-top: 0 !important; }
/* Custom select controls display the same medium-weight value as native fields. */
:root body.panel-compact :is(.enhanced-select-button, .enhanced-select-button > span) { font-weight: var(--compact-field-weight) !important; }
/* A heading receives initial screen-reader focus, not a keyboard-focus ring. */
:root body.panel-compact :is(dialog, [role="dialog"]) :is(h1, h2, h3)[tabindex="-1"]:focus {
  outline: none !important;
  outline-offset: 0 !important;
  box-shadow: none !important;
}
:root body.panel-compact :is(dialog, [role="dialog"]) :is(
  input:not(:is([type="hidden"], [type="checkbox"], [type="radio"], [type="file"],
    [type="range"], [type="color"], [type="button"], [type="submit"], [type="reset"])),
  select:not(.enhanced-select-native), textarea, [contenteditable="true"]
),
:root body.panel-compact :is(dialog, [role="dialog"]) :is(input, select, textarea, [contenteditable="true"]):focus {
  font-size: var(--panel-modal-field) !important;
  transition: border-color 120ms ease, background-color 120ms ease;
  scroll-margin-block: 12px;
}
/* Modal fields inherit the same compact scale and padding as the panel form. */
:root body.panel-compact dialog::backdrop {
  background: rgba(20, 32, 28, .42);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}
:root body.panel-compact .timeline-modal-backdrop {
  background: rgba(20, 32, 28, .42);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}
:root body.panel-compact :is(dialog, [role="dialog"]) :is(.confirm-modal-card, .cash-modal-card,
  .timeline-create-surface, .receipt-preview-card) {
  animation: panel-modal-reveal 160ms ease-out;
}
:root body.panel-compact .timeline-create-dialog[open]::backdrop,
:root body.panel-compact .timeline-create-dialog[data-modal-fallback][open],
:root body.panel-compact :is(.topic-edit-menu, .timeline-settings-menu)[open] > form,
:root body.panel-compact .timeline-modal-backdrop {
  animation: panel-modal-reveal 160ms ease-out;
}
:root body.panel-compact .timeline-create-dialog.is-closing .timeline-create-surface,
:root body.panel-compact .timeline-create-dialog.is-closing::backdrop,
:root body.panel-compact .timeline-create-dialog[data-modal-fallback].is-closing,
:root body.panel-compact :is(.topic-edit-menu, .timeline-settings-menu).is-closing > form {
  animation: panel-modal-dismiss 140ms ease-in forwards;
}
@keyframes panel-modal-reveal { from { opacity: 0; } to { opacity: 1; } }
@keyframes panel-modal-dismiss { from { opacity: 1; } to { opacity: 0; } }
@media (max-width: 800px) {
  /* Keep the top edge stable. Only the usable height shrinks for the keyboard. */
  :root body.panel-compact dialog:not(.timeline-create-dialog) {
    position: fixed;
    inset: var(--panel-viewport-top, 0px) 0 auto;
    margin: 12px auto;
    max-height: calc(var(--panel-viewport-height, 100dvh) - 24px);
    transform: none;
    overflow-y: auto;
  }
}
@media (prefers-reduced-motion: reduce) {
  :root body.panel-compact :is(dialog, [role="dialog"]),
  :root body.panel-compact dialog::backdrop,
  :root body.panel-compact .timeline-modal-backdrop,
  :root body.panel-compact :is(dialog, [role="dialog"]) * {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}

/* One clipped modal surface replaces the mismatched outer/inner rounded frames. */
:root body.panel-compact dialog.cash-setup-modal {
  padding: 0;
  border: 1px solid var(--compact-line);
  border-radius: 14px !important;
  background: #fff;
  overflow: hidden;
  max-height: calc(var(--panel-viewport-height, 100dvh) - 24px);
}
:root body.panel-compact dialog.cash-setup-modal .cash-modal-card {
  box-sizing: border-box;
  margin: 0;
  border: 0;
  border-radius: 0;
  max-height: calc(var(--panel-viewport-height, 100dvh) - 26px);
  overflow-x: hidden;
  overflow-y: auto;
  scrollbar-gutter: auto;
}
:root body.panel-compact dialog.cash-setup-modal :is(.cash-modal-card > header,
  .cash-modal-card > footer, .cash-modal-fields, .cash-transaction-modal-fields,
  .cash-category-create, .cash-category-list) { padding: 12px; gap: 10px; }
:root body.panel-compact dialog.cash-setup-modal .cash-modal-card > header p {
  font-size: 12px !important;
  margin: 4px 0 0;
}
:root body.panel-compact dialog.cash-setup-modal .cash-modal-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 36px;
  width: 36px;
  height: 36px;
  min-height: 36px;
  padding: 0;
  border-radius: 10px;
  background: #f3f6f4;
  color: #52615a;
}
:root body.panel-compact dialog.cash-setup-modal :is(input, select, textarea) { margin-top: 5px; }
/* Transaction/account forms scroll only their fields. The footer has its own row,
   so it cannot cover a focused input when the software keyboard reduces height. */
:root body.panel-compact dialog.cash-setup-modal > form.cash-modal-card {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
}
:root body.panel-compact dialog.cash-setup-modal > form.cash-modal-card > :is(.cash-modal-fields, .cash-transaction-modal-fields) {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
:root body.panel-compact dialog.cash-setup-modal .cash-modal-card > footer { position: static; }
