/* ===================================================================
   Bottom Sheet Component
   Mobile: swipe-to-dismiss sheet from bottom
   Desktop: centered modal with backdrop
   =================================================================== */

@layer components {
    .bottom-sheet-backdrop {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0);
        z-index: 10000;
        opacity: 0;
        pointer-events: none;
        transition: background 0.3s ease, opacity 0.3s ease;

        &.is-open {
            background: rgba(0, 0, 0, 0.4);
            opacity: 1;
            pointer-events: auto;
        }
    }

    .bottom-sheet {
        position: fixed;
        z-index: 10001;
        background: var(--card-bg, white);
        color: var(--text-primary, #111827);
        overflow: hidden;
        transition: transform 0.35s cubic-bezier(0.32, 0.72, 0, 1);
        will-change: transform;

        /* Mobile: bottom sheet */
        bottom: 0;
        left: 0;
        right: 0;
        max-height: 85vh;
        border-radius: 16px 16px 0 0;
        transform: translateY(100%);
        box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.12);

        &.is-open {
            transform: translateY(0);
        }

        &.is-dragging {
            transition: none;
        }
    }

    .bottom-sheet-handle {
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 12px 0 4px;
        cursor: grab;
        touch-action: none;

        &:active {
            cursor: grabbing;
        }

        &::after {
            content: '';
            width: 36px;
            height: 4px;
            border-radius: 2px;
            background: var(--gray-300, #D1D5DB);
        }
    }

    .bottom-sheet-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 0.5rem 1.5rem 1rem;

        & h3 {
            margin: 0;
            font-size: var(--text-lg, 1.2rem);
            font-weight: 600;
        }
    }

    .bottom-sheet-close {
        appearance: none;
        border: none;
        background: var(--gray-100, #F3F4F6);
        border-radius: 8px;
        width: 36px;
        height: 36px;
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        font-size: 18px;
        color: var(--text-secondary, #374151);
        transition: background 0.15s ease;

        &:hover {
            background: var(--gray-200, #E5E7EB);
        }

        &:focus-visible {
            outline: 2px solid var(--accent-color, #C62828);
            outline-offset: 2px;
        }
    }

    .bottom-sheet-content {
        padding: 0 1.5rem 1.5rem;
        overflow-y: auto;
        max-height: calc(85vh - 100px);
        -webkit-overflow-scrolling: touch;
        padding-bottom: calc(1.5rem + env(safe-area-inset-bottom, 0px));
    }

    /* Desktop: centered modal */
    @media (min-width: 769px) {
        .bottom-sheet {
            bottom: auto;
            left: 50%;
            top: 50%;
            transform: translate(-50%, -50%) scale(0.95);
            opacity: 0;
            max-width: 560px;
            width: 90vw;
            max-height: 70vh;
            border-radius: 16px;
            box-shadow: 0 24px 80px rgba(0, 0, 0, 0.2);
            transition:
                transform 0.3s cubic-bezier(0.32, 0.72, 0, 1),
                opacity 0.3s ease;

            &.is-open {
                transform: translate(-50%, -50%) scale(1);
                opacity: 1;
            }
        }

        .bottom-sheet-handle {
            display: none;
        }

        .bottom-sheet-header {
            padding-top: 1.25rem;
        }

        .bottom-sheet-content {
            max-height: calc(70vh - 100px);
        }
    }

    /* Respect reduced motion */
    @media (prefers-reduced-motion: reduce) {
        .bottom-sheet {
            transition: none;
        }

        .bottom-sheet-backdrop {
            transition: none;
        }
    }
}
