/* Tokens belong to the dialog, including dialogs appended directly to body. */
dialog.ft-modal {
    --ft-modal-danger: #b42318;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    border: 0;
    padding: 0;
    margin: auto;
    inset: 0;
    width: min(480px, calc(100vw - 32px));
    max-width: none;
    max-height: min(90vh, 720px);
    border-radius: 12px;
    background: var(--color-background, #fff);
    color: var(--color-text, #1c1c1c);
    box-shadow: 0 24px 60px rgb(0 0 0 / 20%);
    overflow: auto;
}
dialog.ft-modal:not([open]) { display: none; }
dialog.ft-modal::backdrop { background: rgb(28 28 28 / 55%); }
dialog.ft-modal--wide { width: min(720px, calc(100vw - 32px)); }
.ft-modal__header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding: 24px 24px 0; }
.ft-modal .ft-modal__title { font: 700 20px/1.3 var(--font-heading, sans-serif); margin: 0; }
.ft-modal__close { flex: 0 0 44px; width: 44px; height: 44px; margin: -10px -10px 0 0; border: 0; background: transparent; font-size: 22px; cursor: pointer; }
.ft-modal__body { padding: 8px 24px 24px; overflow: auto; min-height: 0; }
.ft-modal__body p { color: var(--color-muted, #6b7280); white-space: pre-line; }
.ft-modal__body label { display: block; }
.ft-modal__body input:not([type=checkbox]):not([type=radio]) { max-width: 100%; }
.ft-modal__footer { display: flex; justify-content: flex-end; gap: 8px; padding: 16px 24px; border-top: 1px solid var(--color-border, #ede4d9); }
.ft-modal button, .ft-modal .btn { min-height: 44px; }
.ft-modal :focus-visible { outline: 2px solid var(--color-primary, #d4922a); outline-offset: 3px; }
.ft-modal .btn-danger { background: var(--ft-modal-danger); color: #fff; }
.ft-modal .btn-danger:disabled { opacity: .5; cursor: not-allowed; }
@media (max-width: 480px) {
    dialog.ft-modal { width: 100%; margin: auto 0 0; max-height: 85svh; border-radius: 16px 16px 0 0; }
    .ft-modal__header { padding-top: 28px; }
    .ft-modal__header::before { content: ''; position: absolute; top: 8px; left: calc(50% - 20px); width: 40px; height: 4px; border-radius: 2px; background: var(--color-border, #d1d5db); }
    /* Primary remains last in DOM and focus order (v2 independent review #6). */
    .ft-modal__footer { flex-direction: column; padding-bottom: calc(16px + env(safe-area-inset-bottom)); }
    .ft-modal__footer > .btn { width: 100%; }
}
@media (prefers-reduced-motion: reduce) { .ft-modal, .ft-modal * { scroll-behavior: auto; transition: none !important; animation: none !important; } }
.ft-modal__body { max-height: calc(min(90vh, 720px) - 160px); }
@media (max-width: 480px) { .ft-modal__body { max-height: calc(85svh - 180px); } }
.ft-modal .ft-modal__footer form { display: contents; }

.ft-modal .cropper-actions { display: contents; }
.ft-modal .cropper-controls { flex-wrap: wrap; margin-top: 16px; }
.ft-modal__body > label > input {
    display: block;
    width: 100%;
    min-height: 44px;
    margin-top: 8px;
    padding: 8px 12px;
    border: 1px solid var(--color-border, #ede4d9);
    border-radius: var(--radius-control, 8px);
}
/* Keep the footer visible while long forms and previews scroll inside. */
dialog.ft-modal[open] { display: flex; flex-direction: column; }
.ft-modal__header, .ft-modal__footer { flex-shrink: 0; }
.ft-modal__body { flex: 1 1 auto; }
.ft-modal > form { display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.ft-modal__close svg { display: block; width: 20px; height: 20px; margin: auto; }

/* Deletion actions outside dialogs use the same AA-safe destructive color. */
.ft-danger-action { --ft-modal-danger: #b42318; }
.ft-danger-action.btn-danger { background: var(--ft-modal-danger); color: #fff; }
.ft-modal__link { color: var(--color-text, #1c1c1c); text-decoration: underline; text-underline-offset: 2px; }
