/**
 * System-wide modal design — Removal Order look.
 * Loaded in header + footer, and re-injected last by afsp-modals.js.
 */

/* ——— Stacking: demote navbar / AI chrome while any modal is open ———
   Modals often live inside transformed/z-indexed page shells, so raising
   .modal alone cannot beat .apple-navbar. Lower the nav instead. */
html body.modal-open .apple-navbar,
html body.modal-open .apple-nav-menu-container,
html body.modal-open .apple-nav-menu-container.show,
html body.modal-open .apple-notification-dropdown,
html body.modal-open .apple-chat-preview,
html body.modal-open .apple-profile-dropdown,
html body.modal-open .ai-assistant-layer,
html body.modal-open .ai-buddy-wanderer,
html body.modal-open .ai-link-preview,
html body.modal-open .ai-reminder-toast,
html body.modal-open .ai-briefing-bar,
html body.modal-open .global-chat-notification {
    z-index: 0 !important;
    pointer-events: none !important;
}

/* High enough to clear leftover page chrome / AI layer when modal is on body */
html body .modal-backdrop,
html body .modal-backdrop.fade,
html body .modal-backdrop.show,
html body.modal-open .modal-backdrop,
html body.modal-open .modal-backdrop.show {
    z-index: 20040 !important;
}

html body .modal,
html body .modal.fade,
html body .modal.show,
html body .modal.fade.show,
html body.modal-open .modal,
html body.modal-open .modal.show {
    z-index: 20050 !important;
}

/*
 * theme.css (older Bootstrap) sets .modal-dialog { pointer-events: none }
 * without restoring auto on content — modals open but nothing is clickable.
 * Force interactive stack on all viewports (not only mobile).
 */
html body .modal .modal-dialog,
html body .modal.show .modal-dialog,
html body.modal-open .modal .modal-dialog {
    z-index: 20051 !important;
    position: relative;
    pointer-events: auto !important;
}

html body .modal .modal-content,
html body .modal .apple-modal-content,
html body.modal-open .modal .modal-content {
    z-index: 20052 !important;
    position: relative;
    pointer-events: auto !important;
}

html body .modal .modal-body,
html body .modal .apple-modal-body,
html body .modal .modal-header,
html body .modal .modal-footer,
html body .modal input,
html body .modal select,
html body .modal textarea,
html body .modal button,
html body .modal label,
html body .modal .form-control,
html body .modal .form-select,
html body .modal .apple-input,
html body .modal .apple-btn,
html body .modal a {
    pointer-events: auto !important;
}

/* ——— Shell (Removal Order) ——— */
html body .modal .modal-content,
html body .modal .apple-modal-content,
html body .apple-modal .modal-content,
html body .apple-modal .apple-modal-content,
html body .modal-content.apple-modal-content {
    background: rgba(255, 255, 255, 0.98) !important;
    background-color: rgba(255, 255, 255, 0.98) !important;
    background-image: none !important;
    backdrop-filter: blur(40px) saturate(180%) !important;
    -webkit-backdrop-filter: blur(40px) saturate(180%) !important;
    border: 0.5px solid rgba(0, 0, 0, 0.08) !important;
    border-radius: 20px !important;
    box-shadow:
        0 20px 60px rgba(0, 0, 0, 0.12),
        0 8px 24px rgba(0, 0, 0, 0.08),
        inset 0 1px 0 rgba(255, 255, 255, 0.9) !important;
    overflow: hidden;
}

/* ——— Header ——— */
html body .modal .modal-header,
html body .modal .apple-modal-header,
html body .apple-modal .modal-header,
html body .apple-modal .apple-modal-header {
    background: rgba(248, 248, 250, 0.5) !important;
    background-color: rgba(248, 248, 250, 0.5) !important;
    background-image: none !important;
    backdrop-filter: blur(20px) !important;
    -webkit-backdrop-filter: blur(20px) !important;
    border-bottom: 0.5px solid rgba(0, 0, 0, 0.06) !important;
    border-radius: 20px 20px 0 0 !important;
    padding: 1.25rem 1.5rem 1rem !important;
    box-shadow: none !important;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: relative;
    flex-shrink: 0;
}

html body .modal .modal-header::before,
html body .modal .modal-header::after,
html body .modal .apple-modal-header::before,
html body .modal .apple-modal-header::after,
html body .apple-modal .apple-modal-header::before,
html body .apple-modal .apple-modal-header::after {
    display: none !important;
    content: none !important;
    background: none !important;
}

html body .modal .modal-title,
html body .modal .apple-modal-title,
html body .apple-modal .modal-title,
html body .apple-modal .apple-modal-title {
    font-size: 1.375rem !important;
    font-weight: 600 !important;
    color: #1d1d1f !important;
    letter-spacing: -0.022em !important;
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, sans-serif !important;
    text-shadow: none !important;
    line-height: 1.2 !important;
    display: flex !important;
    align-items: center !important;
    gap: 0.5rem !important;
}

html body .modal .modal-title i,
html body .modal .apple-modal-title i,
html body .apple-modal .modal-title i,
html body .apple-modal .apple-modal-title i {
    color: #007aff !important;
    filter: none !important;
    text-shadow: none !important;
}

html body .modal .modal-header .btn-close,
html body .modal .apple-modal-header .btn-close,
html body .apple-modal .apple-modal-header .btn-close,
html body .modal-header .btn-close {
    background-color: rgba(142, 142, 147, 0.12) !important;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='%231d1d1f'%3e%3cpath d='M.293.293a1 1 0 011.414 0L8 6.586 14.293.293a1 1 0 111.414 1.414L9.414 8l6.293 6.293a1 1 0 01-1.414 1.414L8 9.414l-6.293 6.293a1 1 0 01-1.414-1.414L6.586 8 .293 1.707a1 1 0 010-1.414z'/%3e%3c/svg%3e") !important;
    background-size: 0.85em auto !important;
    background-position: center !important;
    background-repeat: no-repeat !important;
    border: 0.5px solid rgba(0, 0, 0, 0.06) !important;
    border-radius: 50% !important;
    width: 32px !important;
    height: 32px !important;
    opacity: 1 !important;
    box-shadow: none !important;
    transform: none !important;
    padding: 0 !important;
}

html body .modal .modal-header .btn-close:hover,
html body .modal .apple-modal-header .btn-close:hover,
html body .modal-header .btn-close:hover {
    background-color: rgba(142, 142, 147, 0.22) !important;
    transform: none !important;
    box-shadow: none !important;
}

/* ——— Body ——— */
html body .modal .modal-body,
html body .modal .apple-modal-body,
html body .apple-modal .modal-body,
html body .apple-modal .apple-modal-body {
    background: rgba(250, 250, 252, 0.5) !important;
    background-color: rgba(250, 250, 252, 0.5) !important;
    background-image: none !important;
    backdrop-filter: blur(20px) !important;
    -webkit-backdrop-filter: blur(20px) !important;
    padding: 1.5rem !important;
}

/* ——— Footer ——— */
html body .modal .modal-footer,
html body .modal .apple-modal-footer,
html body .apple-modal .modal-footer,
html body .apple-modal .apple-modal-footer {
    background: rgba(248, 248, 250, 0.95) !important;
    background-color: rgba(248, 248, 250, 0.95) !important;
    background-image: none !important;
    backdrop-filter: blur(20px) !important;
    -webkit-backdrop-filter: blur(20px) !important;
    border-top: 0.5px solid rgba(0, 0, 0, 0.06) !important;
    border-radius: 0 0 20px 20px !important;
    padding: 1rem 1.5rem 1.25rem !important;
    display: flex !important;
    flex-wrap: wrap;
    gap: 0.75rem !important;
    flex-shrink: 0 !important;
}

/* ——— Buttons ——— */
html body .modal .apple-btn,
html body .modal .btn.apple-btn,
html body .apple-modal .apple-btn,
html body .modal .modal-footer .btn:not(.btn-close),
html body .apple-modal-footer .btn:not(.btn-close),
html body .modal-footer .btn:not(.btn-close) {
    border-radius: 12px !important;
    padding: 0.75rem 1.5rem !important;
    font-weight: 590 !important;
    font-size: 0.9375rem !important;
    letter-spacing: -0.011em !important;
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif !important;
    border: 0.5px solid transparent !important;
}

html body .modal .apple-btn-primary,
html body .modal .btn.apple-btn-primary,
html body .modal .btn-primary:not(.btn-outline-primary):not(.btn-close),
html body .apple-modal .apple-btn-primary,
html body .apple-modal-footer .apple-btn-primary,
html body .modal-footer .btn-primary:not(.btn-outline-primary),
html body .modal .modal-footer .btn-primary {
    background: #007aff !important;
    background-image: none !important;
    color: #fff !important;
    -webkit-text-fill-color: #fff !important;
    border-color: #007aff !important;
    box-shadow:
        0 2px 8px rgba(0, 122, 255, 0.3),
        0 1px 2px rgba(0, 0, 0, 0.1) !important;
}

html body .modal .apple-btn-primary:hover,
html body .modal .btn.apple-btn-primary:hover,
html body .modal .btn-primary:hover:not(.btn-outline-primary),
html body .apple-modal .apple-btn-primary:hover,
html body .apple-modal-footer .apple-btn-primary:hover,
html body .modal-footer .btn-primary:hover {
    background: #0051d5 !important;
    border-color: #0051d5 !important;
    color: #fff !important;
    -webkit-text-fill-color: #fff !important;
    box-shadow:
        0 4px 16px rgba(0, 122, 255, 0.4),
        0 2px 4px rgba(0, 0, 0, 0.1) !important;
}

html body .modal .apple-btn-secondary,
html body .modal .btn.apple-btn-secondary,
html body .modal .btn-secondary,
html body .modal .btn-light,
html body .apple-modal .apple-btn-secondary,
html body .apple-modal-footer .apple-btn-secondary,
html body .modal-footer .btn-secondary,
html body .modal-footer .btn-light,
html body .modal .modal-footer .btn-secondary {
    background: rgba(142, 142, 147, 0.12) !important;
    background-image: none !important;
    color: #1d1d1f !important;
    -webkit-text-fill-color: #1d1d1f !important;
    border-color: rgba(0, 0, 0, 0.08) !important;
    box-shadow: none !important;
}

html body .modal .apple-btn-secondary:hover,
html body .modal .btn.apple-btn-secondary:hover,
html body .apple-modal .apple-btn-secondary:hover,
html body .modal-footer .btn-secondary:hover {
    background: rgba(142, 142, 147, 0.2) !important;
    border-color: rgba(0, 0, 0, 0.12) !important;
    color: #1d1d1f !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08) !important;
}

html body .modal .apple-btn-danger,
html body .modal .btn.apple-btn-danger,
html body .modal .btn-danger,
html body .apple-modal .apple-btn-danger,
html body .apple-modal-footer .apple-btn-danger,
html body .modal-footer .btn-danger {
    background: #ff3b30 !important;
    background-image: none !important;
    color: #fff !important;
    -webkit-text-fill-color: #fff !important;
    border-color: #ff3b30 !important;
    box-shadow:
        0 2px 8px rgba(255, 59, 48, 0.3),
        0 1px 2px rgba(0, 0, 0, 0.1) !important;
}

html body .modal .apple-btn-danger:hover,
html body .modal .btn-danger:hover,
html body .apple-modal .apple-btn-danger:hover {
    background: #cc2e24 !important;
    border-color: #cc2e24 !important;
    color: #fff !important;
}

html body .modal .form-control:focus,
html body .modal .form-select:focus,
html body .modal .apple-input:focus,
html body .apple-modal .form-control:focus,
html body .apple-modal .form-select:focus,
html body .apple-modal .apple-input:focus {
    border-color: #007aff !important;
    box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.15) !important;
}

html body .modal .form-check-input:checked,
html body .apple-modal .form-check-input:checked {
    background-color: #007aff !important;
    border-color: #007aff !important;
}

/* ——— Confirm dialogs (showAppleConfirm) — same Removal Order shell ——— */
.apple-confirm {
    position: fixed !important;
    top: 50% !important;
    left: 50% !important;
    transform: translate(-50%, -50%) scale(0.96) !important;
    z-index: 20060 !important;
    padding: 0 !important;
    min-width: min(420px, calc(100vw - 2rem)) !important;
    max-width: min(480px, calc(100vw - 2rem)) !important;
    background: transparent !important;
    border: 0 !important;
    box-shadow: none !important;
    backdrop-filter: none !important;
}

.apple-confirm.show {
    transform: translate(-50%, -50%) scale(1) !important;
}

.apple-confirm-backdrop {
    z-index: 20055 !important;
    background: rgba(0, 0, 0, 0.45) !important;
}

.apple-confirm .apple-confirm-content,
.apple-confirm .apple-modal-content {
    border-radius: 20px !important;
    overflow: hidden !important;
    background: rgba(255, 255, 255, 0.98) !important;
    border: 0.5px solid rgba(0, 0, 0, 0.08) !important;
    box-shadow:
        0 20px 60px rgba(0, 0, 0, 0.12),
        0 8px 24px rgba(0, 0, 0, 0.08) !important;
}

.apple-confirm .apple-confirm-header,
.apple-confirm .apple-modal-header {
    background: rgba(248, 248, 250, 0.5) !important;
    border-bottom: 0.5px solid rgba(0, 0, 0, 0.06) !important;
    padding: 1.1rem 1.35rem 0.95rem !important;
    text-align: left !important;
}

.apple-confirm .apple-confirm-title,
.apple-confirm .apple-modal-title {
    font-size: 1.2rem !important;
    font-weight: 600 !important;
    color: #1d1d1f !important;
    margin: 0 !important;
    text-align: left !important;
    display: flex !important;
    align-items: center !important;
    gap: 0.5rem !important;
}

.apple-confirm .apple-confirm-title i {
    color: #007aff !important;
}

.apple-confirm.apple-confirm-danger .apple-confirm-title i {
    color: #ff3b30 !important;
}

.apple-confirm .apple-confirm-body,
.apple-confirm .apple-modal-body {
    background: rgba(250, 250, 252, 0.5) !important;
    padding: 1.25rem 1.35rem !important;
    text-align: left !important;
}

.apple-confirm .apple-confirm-message {
    margin: 0 !important;
    color: #3a3a3c !important;
    font-size: 0.95rem !important;
    line-height: 1.45 !important;
    text-align: left !important;
}

.apple-confirm .apple-confirm-buttons,
.apple-confirm .apple-modal-footer {
    background: rgba(248, 248, 250, 0.95) !important;
    border-top: 0.5px solid rgba(0, 0, 0, 0.06) !important;
    padding: 0.9rem 1.25rem 1.1rem !important;
    justify-content: flex-end !important;
    gap: 0.65rem !important;
}

.apple-confirm .apple-confirm-button,
.apple-confirm .apple-btn {
    border-radius: 12px !important;
    min-width: 88px !important;
    transform: none !important;
}

.apple-confirm .apple-confirm-button.cancel,
.apple-confirm .apple-btn-secondary {
    background: rgba(142, 142, 147, 0.12) !important;
    color: #1d1d1f !important;
}

.apple-confirm .apple-confirm-button.confirm,
.apple-confirm .apple-btn-primary {
    background: #007aff !important;
    color: #fff !important;
    box-shadow: 0 2px 8px rgba(0, 122, 255, 0.3) !important;
}

.apple-confirm .apple-confirm-button.delete,
.apple-confirm .apple-btn-danger {
    background: #ff3b30 !important;
    color: #fff !important;
    box-shadow: 0 2px 8px rgba(255, 59, 48, 0.3) !important;
}

.apple-confirm-icon {
    display: none !important;
}

@media (max-width: 768px) {
    body.modal-open .apple-navbar,
    body.modal-open .apple-nav-menu-container,
    body.modal-open .apple-nav-menu-container.show {
        z-index: 0 !important;
    }

    .modal,
    .modal.show,
    body.modal-open .modal {
        z-index: 20050 !important;
    }

    .modal-backdrop,
    .modal-backdrop.show,
    body.modal-open .modal-backdrop {
        z-index: 20040 !important;
        pointer-events: auto !important;
        opacity: 0.45 !important;
        background-color: rgba(0, 0, 0, 0.45) !important;
    }

    .modal .modal-dialog,
    .modal.show .modal-dialog {
        z-index: 20051 !important;
        pointer-events: auto !important;
        max-width: calc(100% - 1rem) !important;
        margin: 1rem auto !important;
    }

    .modal .modal-content,
    .modal .apple-modal-content {
        z-index: 20052 !important;
        pointer-events: auto !important;
        border-radius: 20px !important;
        max-height: 85vh !important;
    }
}
