/*
 * Unified modal template.
 * New pages should use:
 * .modal-backdrop > .modal-card > .modal-header + .modal-form/.modal-body
 * Add .modal-actions only for business actions, not a duplicate close button.
 * PDF previews use .modal-card-document so the viewer fills the remaining space.
 *
 * Compatibility aliases are kept for existing OA and System pages:
 * .approval-modal-* and .system-modal-*.
 */

.modal-backdrop,
.approval-modal-backdrop,
.system-modal {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: rgba(6, 30, 22, 0.46);
    backdrop-filter: blur(4px);
}

.modal-backdrop.open,
.approval-modal-backdrop.open,
.system-modal.open {
    display: flex;
}

/* Content watermarks create an isolated stacking context. While a shared
 * backdrop is open, lift that context above the mobile application header. */
.content:has(.modal-backdrop.open) {
    z-index: 100;
}

/* On mobile, html owns overflow-x and therefore the viewport scroller.
 * Lock that root too, not only body, while a dialog is actually open. */
html:has(> body.modal-dialog-open),
body.modal-dialog-open {
    overflow: hidden;
}

.system-modal-backdrop {
    position: absolute;
    inset: 0;
}

.modal-card,
.approval-modal-card,
.system-modal-panel {
    position: relative;
    z-index: 1;
    width: min(760px, 100%);
    max-height: min(86vh, 820px);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 10px;
    box-shadow: 0 24px 70px rgba(0, 36, 26, 0.22);
}

.approval-modal-card {
    width: min(620px, 100%);
}

.modal-card-wide {
    width: min(980px, 100%);
}

.modal-card-extra-wide {
    width: min(1380px, 100%);
    max-width: 1380px;
    max-height: min(92dvh, 960px, calc(100dvh - 48px));
}

.modal-card.modal-card-document {
    height: min(900px, calc(100dvh - 48px));
    max-height: calc(100dvh - 48px);
}

.modal-card.modal-card-document > .modal-body {
    display: flex;
    flex: 1 1 0;
    flex-direction: column;
    min-height: 0;
    padding: 0;
    overflow: hidden;
}

.modal-card.modal-card-document > .modal-body > iframe {
    display: block;
    flex: 1 1 0;
    width: 100%;
    height: 100%;
    min-height: 0;
    border: 0;
    border-radius: 0;
    background: #eef3f0;
}

.modal-header-actions {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    gap: 12px;
}

.modal-header,
.approval-modal-header,
.system-modal-panel > header {
    flex: 0 0 auto;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
    padding: 20px 22px;
    border-bottom: 1px solid var(--line);
    background: linear-gradient(135deg, #fff, #f5faf7);
}

.modal-header h2,
.approval-modal-header h2 {
    margin: 0;
    color: var(--green-950);
    font-size: 20px;
    line-height: 1.3;
}

.modal-header p,
.approval-modal-header p {
    margin: 6px 0 0;
    color: var(--muted);
    line-height: 1.5;
}

.system-modal-panel > header span {
    display: block;
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
}

.system-modal-panel > header strong {
    display: block;
    margin-top: 4px;
    color: var(--green-950);
    font-size: 18px;
    line-height: 1.3;
}

.modal-close,
.approval-modal-close {
    flex: 0 0 auto;
    width: 36px;
    height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--green-900);
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 50%;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
}

.system-modal-panel > header button {
    min-height: 36px;
    padding: 0 14px;
    color: var(--green-950);
    background: #fff;
    border: 1px solid var(--line-strong);
    border-radius: 7px;
    font-weight: 800;
    cursor: pointer;
}

.modal-form,
.modal-body,
.approval-modal-body,
.system-modal-body {
    min-height: 0;
    overflow: auto;
    padding: 16px 18px 18px;
}

.modal-actions,
.approval-modal-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    flex-direction: row;
    gap: 10px;
    padding-top: 14px;
}

/* Keep shell actions outside the scrolling content visible at short heights. */
.modal-card > .modal-actions,
.approval-modal-card > .approval-modal-actions,
.system-modal-panel > .modal-actions {
    flex: 0 0 auto;
}

.crm-form .modal-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    flex-direction: row;
    gap: 10px;
}

.modal-actions button,
.approval-modal-actions button,
.crm-form .modal-actions button {
    width: auto;
    min-width: 104px;
    min-height: 40px;
    padding: 0 18px;
    white-space: nowrap;
}

/* Modal submit actions must not rely on the surrounding business module for
 * their primary appearance.  System and future modules can use the shared
 * modal shell without falling back to the browser's bevelled button. */
.modal-actions button:not(.secondary-button):not(.secondary-action):not(.danger-button):not(.danger-outline-button) {
    color: #fff;
    background: var(--green-900);
    border: 1px solid var(--green-900);
    border-radius: 6px;
    font: inherit;
    font-weight: 800;
    cursor: pointer;
}

.modal-actions button:not(.secondary-button):not(.secondary-action):not(.danger-button):not(.danger-outline-button):hover,
.modal-actions button:not(.secondary-button):not(.secondary-action):not(.danger-button):not(.danger-outline-button):focus-visible {
    background: var(--green-800);
    border-color: var(--green-800);
}

.modal-actions button:focus-visible {
    outline: 3px solid rgba(11, 107, 79, 0.16);
    outline-offset: 2px;
}

.approval-modal-actions button {
    color: #fff;
    background: var(--green-900);
    border: 0;
    border-radius: 6px;
    font-weight: 800;
    cursor: pointer;
}

.approval-modal-actions .secondary-button {
    color: var(--green-900);
    background: #fff;
    border: 1px solid var(--line-strong);
}

.approval-modal-actions .danger-button {
    background: var(--danger);
}

@media (max-width: 720px) {
    .modal-card.modal-card-document {
        height: calc(100dvh - 20px);
        max-height: calc(100dvh - 20px);
    }

    .modal-header-actions {
        gap: 8px;
    }

    .modal-backdrop,
    .approval-modal-backdrop,
    .system-modal {
        align-items: flex-end;
        padding: 10px;
    }

    .modal-card,
    .approval-modal-card,
    .system-modal-panel {
        max-height: calc(100dvh - 20px);
        border-radius: 10px 10px 8px 8px;
    }

    .modal-header,
    .approval-modal-header,
    .system-modal-panel > header,
    .modal-form,
    .modal-body,
    .approval-modal-body,
    .system-modal-body {
        padding-left: 16px;
        padding-right: 16px;
    }

    .modal-actions,
    .approval-modal-actions,
    .crm-form .modal-actions {
        align-items: stretch;
        flex-direction: column-reverse;
        gap: 10px;
    }

    .modal-actions button,
    .approval-modal-actions button,
    .crm-form .modal-actions button {
        width: 100%;
        min-height: 42px;
    }
}
