/* SaraHome — 通用對話窗 (`.modal` markup + `js/modal.js`) 皮膚 (v1.13, 2026-10-15)
 *
 * 根因: 呢套皮膚原本喺 `pages/account.css` 同 `pages/agent-new-listing.css` 各寫一份
 * (兩份數值已經漂: z-index 100 vs 1000、radius 12 vs 16、overflow auto vs flex column)。
 * 結果 `super_admin/audit_log` 用同一個 markup 但兩份 CSS 都冇載入 → `.modal` 冇任何
 * position/backdrop 規則, 開窗時變成**內嵌喺頁面流內**的一塊 (無遮罩、唔置中),
 * 「點窗以外關閉」亦無從谈起 (§R-N+416 單一來源守則: 同一 selector 嘅 layout 屬性只准一處定義)。
 *
 * 而家: 呢檔 = `.modal` 系列嘅唯一來源 (base.html `_CSS_CHAIN` 核心層載入, 全站可用);
 * 頁面部 CSS 只准保留自己專屬嘅變體 (例 `.modal-card-danger` 嘅紅色 header),
 * 唔准再對 `.modal` / `.modal-card` / `.modal-body` 落 position / max-width / overflow。
 * 對位 §R-N+372.13 (純 CSS 化) + §R-N+78.7 (base.html 用 v=timestamp cache-bust)。
 */

.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    animation: modal-fade-in 0.18s ease-out;
}

/* `hidden` attribute 必須贏過上面嘅 `display: flex` (無 JS 都唔會露出) */
.modal[hidden] {
    display: none;
}

.modal-overlay {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
    backdrop-filter: blur(2px);
    cursor: pointer;
}

/* 卡片 = flex column, 內容超出由 `.modal-body` 自己滾 (header/footer 固定) */
.modal-card {
    position: relative;
    z-index: 1;
    background: var(--sarahome-v3-color-bg);
    border-radius: 16px;
    max-width: 560px;
    width: 100%;
    max-height: min(85vh, calc(100vh - 40px));
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 24px 60px rgba(15, 23, 42, 0.25), 0 8px 16px rgba(15, 23, 42, 0.12);
    animation: modal-slide-up 0.22s ease-out;
}

/* focus 由 JS 移到卡片本身 (a11y), 唔顯示預設 outline */
.modal-card:focus {
    outline: none;
}

.modal-card--wide {
    max-width: 720px;
}

.modal-card--narrow {
    max-width: 480px;
}

@keyframes modal-fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes modal-slide-up {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 20px 24px 16px 24px;
    border-bottom: 1px solid rgba(15, 23, 42, 0.06);
}

.modal-title {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 700;
    color: #0F172A;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* 兩種 close button class 都係本 repo 現有 markup (account = `-btn`, 其他 = 無後綴) */
.modal-close,
.modal-close-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 4px;
    color: #64748B;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease, color 0.15s ease;
}

.modal-close:hover,
.modal-close-btn:hover {
    background: rgba(15, 23, 42, 0.06);
    color: #0F172A;
}

.modal-close:focus-visible,
.modal-close-btn:focus-visible {
    outline: 2px solid var(--sarahome-v3-color-info-blue);
    outline-offset: 2px;
}

.modal-body {
    padding: 20px 24px;
    overflow-y: auto;
    flex: 1;
    outline: none;
}

.modal-empty {
    text-align: center;
    padding: 24px;
    color: #64748B;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding: 16px 24px;
    border-top: 1px solid rgba(15, 23, 42, 0.06);
    background: rgba(248, 250, 252, 0.5);
}

.modal-footer .btn-secondary-lavender,
.modal-footer .btn-lavender {
    margin: 0;
}

/* 手機: 卡片改貼邊 sheet (留 12px 縫, 唔做全螢幕 — 短內容嘅確認窗全螢幕反而睇唔清)
 * 對位 §R-N+290 ≤768 stack + 44px touch target */
@media (max-width: 768px) {
    .modal {
        padding: 12px;
    }

    .modal-card,
    .modal-card--wide,
    .modal-card--narrow {
        max-width: 100%;
        max-height: calc(100vh - 24px);
    }

    .modal-header {
        padding: 16px 18px 12px 18px;
    }

    .modal-body {
        padding: 18px;
    }

    .modal-footer {
        padding: 14px 18px;
    }
}
