/* =========================================================
   USER APP — MODAL SYSTEM
   File: user_app/assets/css/modal.css
   Purpose: Shared modal/dialog styles
   ========================================================= */


/* =========================================================
   1. MODAL ROOT
   ========================================================= */

.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;

    display: none;
    align-items: center;
    justify-content: center;

    width: 100%;
    height: 100%;

    padding: 20px;

    background: rgba(15, 23, 42, 0.55);

    opacity: 0;
    visibility: hidden;

    transition:
        opacity 0.2s ease,
        visibility 0.2s ease;
}


/* Open states supported by JS */

.modal.is-open,
.modal.open,
.modal[aria-hidden="false"] {
    display: flex;
    opacity: 1;
    visibility: visible;
}


/* =========================================================
   2. MODAL BACKDROP
   ========================================================= */

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

    width: 100%;
    height: 100%;

    background: transparent;

    cursor: default;
}


/* Optional stronger backdrop */

.modal-backdrop-dark {
    background: rgba(15, 23, 42, 0.72);
}

.modal-backdrop-light {
    background: rgba(255, 255, 255, 0.72);
}


/* =========================================================
   3. MODAL DIALOG
   ========================================================= */

.modal-dialog {
    position: relative;
    z-index: 1;

    display: flex;
    flex-direction: column;

    width: min(100%, 560px);
    max-height: calc(100vh - 40px);

    margin: auto;

    overflow: hidden;

    background: var(--color-surface, #ffffff);
    color: var(--color-text, #111827);

    border: 1px solid var(--color-border, #e5e7eb);
    border-radius: var(--radius-lg, 12px);

    box-shadow:
        0 20px 40px rgba(15, 23, 42, 0.16),
        0 8px 16px rgba(15, 23, 42, 0.08);

    transform: translateY(12px) scale(0.98);

    transition:
        transform 0.2s ease,
        opacity 0.2s ease;
}

.modal.is-open .modal-dialog,
.modal.open .modal-dialog,
.modal[aria-hidden="false"] .modal-dialog {
    transform: translateY(0) scale(1);
}


/* =========================================================
   4. MODAL SIZES
   ========================================================= */

.modal-sm .modal-dialog {
    width: min(100%, 400px);
}

.modal-md .modal-dialog {
    width: min(100%, 560px);
}

.modal-lg .modal-dialog {
    width: min(100%, 760px);
}

.modal-xl .modal-dialog {
    width: min(100%, 1000px);
}

.modal-xxl .modal-dialog {
    width: min(100%, 1200px);
}

.modal-full .modal-dialog {
    width: calc(100% - 40px);
    max-width: none;
    height: calc(100vh - 40px);
    max-height: none;
}


/* =========================================================
   5. MODAL HEADER
   ========================================================= */

.modal-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;

    gap: 16px;

    padding: 18px 20px;

    border-bottom: 1px solid var(--color-border, #e5e7eb);

    background: var(
        --color-surface,
        #ffffff
    );

    flex-shrink: 0;
}

.modal-header-content {
    min-width: 0;
    flex: 1;
}

.modal-title {
    margin: 0;

    color: var(--color-text, #111827);

    font-size: var(--font-size-lg, 18px);
    font-weight: 700;
    line-height: 1.35;
}

.modal-subtitle {
    margin: 4px 0 0;

    color: var(--color-text-secondary, #6b7280);

    font-size: var(--font-size-sm, 14px);
    line-height: 1.5;
}


/* =========================================================
   6. MODAL CLOSE BUTTON
   ========================================================= */

.modal-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;

    flex: 0 0 auto;

    width: 36px;
    height: 36px;

    padding: 0;

    border: 1px solid transparent;
    border-radius: var(--radius-md, 8px);

    background: transparent;

    color: var(--color-text-secondary, #6b7280);

    font-size: 22px;
    line-height: 1;

    cursor: pointer;

    transition:
        background-color 0.15s ease,
        color 0.15s ease,
        border-color 0.15s ease;
}

.modal-close:hover {
    background: var(--color-surface-hover, #f3f4f6);
    color: var(--color-text, #111827);
}

.modal-close:focus-visible {
    outline: 2px solid var(--color-primary, #2563eb);
    outline-offset: 2px;
}

.modal-close:active {
    transform: translateY(1px);
}


/* =========================================================
   7. MODAL BODY
   ========================================================= */

.modal-body {
    position: relative;

    flex: 1 1 auto;

    min-height: 0;

    padding: 20px;

    overflow-y: auto;
    overflow-x: hidden;

    color: var(--color-text, #111827);

    -webkit-overflow-scrolling: touch;
}


/* =========================================================
   8. MODAL BODY VARIANTS
   ========================================================= */

.modal-body-flush {
    padding: 0;
}

.modal-body-compact {
    padding: 14px 16px;
}

.modal-body-spacious {
    padding: 28px;
}


/* =========================================================
   9. MODAL FOOTER
   ========================================================= */

.modal-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;

    gap: 8px;

    padding: 16px 20px;

    border-top: 1px solid var(--color-border, #e5e7eb);

    background: var(--color-surface, #ffffff);

    flex-shrink: 0;
}

.modal-footer-left {
    margin-right: auto;

    display: flex;
    align-items: center;
    gap: 8px;
}

.modal-footer-right {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
}


/* =========================================================
   10. SCROLLABLE MODAL
   ========================================================= */

.modal-scrollable .modal-dialog {
    max-height: calc(100vh - 40px);
}

.modal-scrollable .modal-body {
    overflow-y: auto;
}


/* =========================================================
   11. STATIC / NON-DISMISSIBLE MODAL
   ========================================================= */

.modal-static .modal-dialog {
    animation: modal-static-shake 0.25s ease;
}

@keyframes modal-static-shake {

    0%,
    100% {
        transform: translateX(0);
    }

    25% {
        transform: translateX(-5px);
    }

    75% {
        transform: translateX(5px);
    }
}


/* =========================================================
   12. CONFIRMATION MODAL
   ========================================================= */

.modal-confirm .modal-dialog {
    width: min(100%, 440px);
}

.modal-confirm .modal-body {
    text-align: center;
}

.modal-confirm-icon {
    display: flex;
    align-items: center;
    justify-content: center;

    width: 52px;
    height: 52px;

    margin: 0 auto 14px;

    border-radius: 50%;

    background: var(--color-primary-light, #eff6ff);
    color: var(--color-primary, #2563eb);

    font-size: 22px;
}

.modal-confirm-title {
    margin: 0 0 6px;

    color: var(--color-text, #111827);

    font-size: 18px;
    font-weight: 700;
}

.modal-confirm-message {
    margin: 0;

    color: var(--color-text-secondary, #6b7280);

    font-size: 14px;
    line-height: 1.6;
}

.modal-confirm .modal-footer {
    justify-content: center;
}


/* =========================================================
   13. DANGER CONFIRMATION
   ========================================================= */

.modal-danger .modal-confirm-icon {
    background: var(--color-danger-light, #fee2e2);
    color: var(--color-danger, #dc2626);
}


/* =========================================================
   14. WARNING CONFIRMATION
   ========================================================= */

.modal-warning .modal-confirm-icon {
    background: var(--color-warning-light, #fef3c7);
    color: var(--color-warning, #d97706);
}


/* =========================================================
   15. SUCCESS CONFIRMATION
   ========================================================= */

.modal-success .modal-confirm-icon {
    background: var(--color-success-light, #dcfce7);
    color: var(--color-success, #16a34a);
}


/* =========================================================
   16. INFO MODAL
   ========================================================= */

.modal-info .modal-confirm-icon {
    background: var(--color-info-light, #dbeafe);
    color: var(--color-info, #2563eb);
}


/* =========================================================
   17. FORM MODAL
   ========================================================= */

.modal-form .modal-body {
    padding-bottom: 8px;
}

.modal-form .form-group:last-child {
    margin-bottom: 0;
}


/* =========================================================
   18. MODAL DIVIDER
   ========================================================= */

.modal-divider {
    height: 1px;

    margin: 16px 0;

    background: var(--color-border, #e5e7eb);

    border: 0;
}


/* =========================================================
   19. MODAL LOADING
   ========================================================= */

.modal-loading {
    position: relative;
}

.modal-loading::after {
    content: "";

    position: absolute;
    inset: 0;

    z-index: 10;

    background: rgba(255, 255, 255, 0.72);

    backdrop-filter: blur(1px);
}

.modal-loading-indicator {
    position: absolute;

    top: 50%;
    left: 50%;

    z-index: 11;

    width: 38px;
    height: 38px;

    margin: -19px 0 0 -19px;

    border: 3px solid var(--color-border, #e5e7eb);
    border-top-color: var(--color-primary, #2563eb);

    border-radius: 50%;

    animation: modal-spinner 0.75s linear infinite;
}

@keyframes modal-spinner {
    to {
        transform: rotate(360deg);
    }
}


/* =========================================================
   20. MODAL ALERT
   ========================================================= */

.modal-alert {
    display: flex;
    align-items: flex-start;

    gap: 12px;

    padding: 12px 14px;

    margin-bottom: 16px;

    border: 1px solid var(--color-border, #e5e7eb);
    border-radius: var(--radius-md, 8px);

    background: var(--color-surface-secondary, #f9fafb);
}

.modal-alert-icon {
    flex: 0 0 auto;

    width: 20px;
    height: 20px;

    color: var(--color-primary, #2563eb);
}

.modal-alert-content {
    min-width: 0;
    flex: 1;
}

.modal-alert-title {
    margin: 0 0 2px;

    font-weight: 600;
}

.modal-alert-message {
    margin: 0;

    color: var(--color-text-secondary, #6b7280);

    font-size: 13px;
    line-height: 1.5;
}


/* =========================================================
   21. MODAL ALERT VARIANTS
   ========================================================= */

.modal-alert-success {
    border-color: var(--color-success-border, #bbf7d0);
    background: var(--color-success-light, #f0fdf4);
}

.modal-alert-success .modal-alert-icon {
    color: var(--color-success, #16a34a);
}

.modal-alert-danger {
    border-color: var(--color-danger-border, #fecaca);
    background: var(--color-danger-light, #fef2f2);
}

.modal-alert-danger .modal-alert-icon {
    color: var(--color-danger, #dc2626);
}

.modal-alert-warning {
    border-color: var(--color-warning-border, #fde68a);
    background: var(--color-warning-light, #fffbeb);
}

.modal-alert-warning .modal-alert-icon {
    color: var(--color-warning, #d97706);
}

.modal-alert-info {
    border-color: var(--color-info-border, #bfdbfe);
    background: var(--color-info-light, #eff6ff);
}

.modal-alert-info .modal-alert-icon {
    color: var(--color-info, #2563eb);
}


/* =========================================================
   22. MODAL IMAGE / MEDIA
   ========================================================= */

.modal-media {
    width: 100%;
    overflow: hidden;
    background: var(--color-surface-secondary, #f3f4f6);
}

.modal-media img,
.modal-media video {
    display: block;

    width: 100%;
    height: auto;

    max-height: 70vh;

    object-fit: contain;
}


/* =========================================================
   23. MODAL LIST
   ========================================================= */

.modal-list {
    display: flex;
    flex-direction: column;

    margin: 0;
    padding: 0;

    list-style: none;
}

.modal-list-item {
    display: flex;
    align-items: center;

    gap: 12px;

    padding: 12px 0;

    border-bottom: 1px solid var(--color-border, #e5e7eb);
}

.modal-list-item:last-child {
    border-bottom: 0;
}

.modal-list-content {
    min-width: 0;
    flex: 1;
}

.modal-list-title {
    display: block;

    color: var(--color-text, #111827);

    font-weight: 600;
}

.modal-list-description {
    display: block;

    margin-top: 2px;

    color: var(--color-text-secondary, #6b7280);

    font-size: 13px;
}


/* =========================================================
   24. MODAL TABS
   ========================================================= */

.modal-tabs {
    display: flex;

    gap: 4px;

    padding: 0 20px;

    border-bottom: 1px solid var(--color-border, #e5e7eb);

    overflow-x: auto;
}

.modal-tab {
    position: relative;

    flex: 0 0 auto;

    padding: 12px 10px;

    border: 0;

    background: transparent;

    color: var(--color-text-secondary, #6b7280);

    font-size: 14px;
    font-weight: 500;

    cursor: pointer;
}

.modal-tab:hover {
    color: var(--color-text, #111827);
}

.modal-tab.is-active,
.modal-tab[aria-selected="true"] {
    color: var(--color-primary, #2563eb);
}

.modal-tab.is-active::after,
.modal-tab[aria-selected="true"]::after {
    content: "";

    position: absolute;

    right: 8px;
    bottom: -1px;
    left: 8px;

    height: 2px;

    background: var(--color-primary, #2563eb);

    border-radius: 2px 2px 0 0;
}


/* =========================================================
   25. DRAWER MODAL — RIGHT
   ========================================================= */

.modal-drawer-right {
    align-items: stretch;
    justify-content: flex-end;
}

.modal-drawer-right .modal-dialog {
    width: min(100%, 480px);

    height: 100%;
    max-height: none;

    margin: 0;

    border-radius: var(--radius-lg, 12px) 0 0 var(--radius-lg, 12px);

    transform: translateX(100%);
}

.modal-drawer-right.is-open .modal-dialog,
.modal-drawer-right.open .modal-dialog,
.modal-drawer-right[aria-hidden="false"] .modal-dialog {
    transform: translateX(0);
}


/* =========================================================
   26. DRAWER MODAL — LEFT
   ========================================================= */

.modal-drawer-left {
    align-items: stretch;
    justify-content: flex-start;
}

.modal-drawer-left .modal-dialog {
    width: min(100%, 480px);

    height: 100%;
    max-height: none;

    margin: 0;

    border-radius: 0 var(--radius-lg, 12px)
        var(--radius-lg, 12px) 0;

    transform: translateX(-100%);
}

.modal-drawer-left.is-open .modal-dialog,
.modal-drawer-left.open .modal-dialog,
.modal-drawer-left[aria-hidden="false"] .modal-dialog {
    transform: translateX(0);
}


/* =========================================================
   27. BOTTOM SHEET
   ========================================================= */

.modal-bottom-sheet {
    align-items: flex-end;
}

.modal-bottom-sheet .modal-dialog {
    width: min(100%, 760px);

    max-height: 90vh;

    margin: 0;

    border-radius:
        var(--radius-lg, 12px)
        var(--radius-lg, 12px)
        0
        0;

    transform: translateY(100%);
}

.modal-bottom-sheet.is-open .modal-dialog,
.modal-bottom-sheet.open .modal-dialog,
.modal-bottom-sheet[aria-hidden="false"] .modal-dialog {
    transform: translateY(0);
}


/* =========================================================
   28. FULL SCREEN MODAL
   ========================================================= */

.modal-fullscreen {
    padding: 0;
}

.modal-fullscreen .modal-dialog {
    width: 100%;
    height: 100%;

    max-width: none;
    max-height: none;

    border: 0;
    border-radius: 0;
}

.modal-fullscreen .modal-header {
    padding-left: 24px;
    padding-right: 24px;
}

.modal-fullscreen .modal-body {
    padding: 24px;
}


/* =========================================================
   29. MODAL NESTING
   ========================================================= */

.modal-nested {
    z-index: 1100;
}


/* =========================================================
   30. BODY LOCK
   ========================================================= */

body.modal-open {
    overflow: hidden;
}


/* =========================================================
   31. MODAL BACKGROUND VARIANTS
   ========================================================= */

.modal-transparent .modal-dialog {
    background: transparent;
    border: 0;
    box-shadow: none;
}

.modal-transparent .modal-body {
    padding: 0;
}


/* =========================================================
   32. MODAL CARD
   ========================================================= */

.modal-card {
    padding: 20px;

    border: 1px solid var(--color-border, #e5e7eb);
    border-radius: var(--radius-lg, 12px);

    background: var(--color-surface, #ffffff);
}


/* =========================================================
   33. MODAL FOOTER STACK
   ========================================================= */

.modal-footer-stack {
    align-items: stretch;
    flex-direction: column;
}

.modal-footer-stack .btn {
    width: 100%;
}


/* =========================================================
   34. MOBILE
   ========================================================= */

@media (max-width: 768px) {

    .modal {
        padding: 12px;
    }

    .modal-dialog {
        width: 100%;
        max-height: calc(100vh - 24px);

        border-radius: var(--radius-md, 10px);
    }

    .modal-header {
        padding: 14px 16px;
    }

    .modal-body {
        padding: 16px;
    }

    .modal-footer {
        padding: 12px 16px;
    }

    .modal-title {
        font-size: 17px;
    }

    .modal-full .modal-dialog {
        width: calc(100% - 24px);
        height: calc(100vh - 24px);
    }

    .modal-fullscreen {
        padding: 0;
    }

    .modal-fullscreen .modal-dialog {
        width: 100%;
        height: 100%;
        border-radius: 0;
    }

    .modal-fullscreen .modal-header,
    .modal-fullscreen .modal-body {
        padding-left: 16px;
        padding-right: 16px;
    }

    .modal-footer {
        flex-wrap: wrap;
    }

    .modal-footer-right {
        width: 100%;
    }

    .modal-footer-right .btn {
        flex: 1 1 auto;
    }

    .modal-confirm .modal-dialog {
        width: 100%;
    }

    .modal-bottom-sheet .modal-dialog {
        width: 100%;
        max-height: 92vh;
    }
}


/* =========================================================
   35. SMALL MOBILE
   ========================================================= */

@media (max-width: 480px) {

    .modal {
        padding: 0;
        align-items: flex-end;
    }

    .modal-dialog {
        width: 100%;
        max-height: 94vh;

        border-radius:
            var(--radius-lg, 12px)
            var(--radius-lg, 12px)
            0
            0;
    }

    .modal-header {
        gap: 10px;
    }

    .modal-close {
        width: 34px;
        height: 34px;
    }

    .modal-footer {
        flex-direction: column;
        align-items: stretch;
    }

    .modal-footer-left,
    .modal-footer-right {
        width: 100%;
        margin: 0;
    }

    .modal-footer-right {
        flex-direction: column-reverse;
    }

    .modal-footer .btn {
        width: 100%;
    }

    .modal-list-item {
        align-items: flex-start;
    }
}


/* =========================================================
   36. REDUCED MOTION
   ========================================================= */

@media (prefers-reduced-motion: reduce) {

    .modal,
    .modal-dialog,
    .modal-close,
    .modal-tab {
        transition: none;
    }

    .modal-loading-indicator {
        animation: none;
    }

    .modal-static .modal-dialog {
        animation: none;
    }
}


/* =========================================================
   37. PRINT
   ========================================================= */

@media print {

    .modal {
        position: static;

        display: none !important;

        width: auto;
        height: auto;

        padding: 0;

        background: transparent;

        opacity: 1;
        visibility: visible;
    }

    .modal.is-print-visible {
        display: block !important;
    }

    .modal-dialog {
        width: 100%;
        max-width: none;
        max-height: none;

        border: 0;
        border-radius: 0;

        box-shadow: none;

        transform: none;
    }

    .modal-header,
    .modal-body,
    .modal-footer {
        padding-left: 0;
        padding-right: 0;
    }

    .modal-close {
        display: none;
    }
}