/* 33-sheets.css — windows: every .modal-overlay window is a bottom sheet on phones (≤ 768px); desktop keeps the centred card.
   Loaded last on purpose: it wins over the per-screen modal tweaks in earlier files. Tokens: 00-tokens.css. */

/* The save / confirm button in every window is the one primary colour (also on desktop).
   !important because some windows are built with an inline background on their button. */
.modal-overlay .btn-primary, .ai-modal .btn-primary {
    background-color: var(--c-primary) !important;
    color: var(--c-on-primary) !important;
    border-color: transparent !important;
}
@media (hover: hover) and (pointer: fine) {
    .modal-overlay .btn-primary:hover, .ai-modal .btn-primary:hover { background-color: var(--c-primary-hover) !important; }
}

@media (max-width: 768px) {
    .modal-overlay {
        align-items: flex-end !important;
        padding: 0 !important;
        overflow: hidden !important;
        background: var(--c-overlay);
    }
    /* The bulk import stays full screen (30-review.css); the screenshot sheet has its own card (31-screenshot.css). */
    .modal-overlay:not(#bulk-import-modal) > .modal-card,
    .modal-overlay:not(#bulk-import-modal) > .modal-card-sm,
    .modal-overlay > .modal-content {
        position: relative;
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        max-height: calc(100dvh - 24px - env(safe-area-inset-top, 0px)) !important;
        overflow-y: auto !important;
        overscroll-behavior: contain;
        border-radius: var(--radius-lg) var(--radius-lg) 0 0 !important;
        padding-bottom: env(safe-area-inset-bottom, 0px) !important;
        background: var(--c-surface);
        box-shadow: var(--el-3);
        animation: sheetUp var(--mo-slow) var(--ease-out);
    }
    /* .modal-content (AI scan) has no header element: keep its own padding plus the safe area. */
    .modal-overlay > .modal-content { padding: 20px 16px calc(16px + env(safe-area-inset-bottom, 0px)) !important; }

    /* Grab handle */
    .modal-overlay:not(#bulk-import-modal) > .modal-card::before,
    .modal-overlay:not(#bulk-import-modal) > .modal-card-sm::before,
    .modal-overlay > .modal-content::before,
    .ai-modal::before {
        content: '';
        position: absolute;
        top: 7px; left: 50%;  /* physical on purpose: centred with translateX(-50%) */
        width: 40px; height: 4px;
        transform: translateX(-50%);
        border-radius: var(--radius-pill);
        background: var(--c-border-strong);
        z-index: 3;
        pointer-events: none;
    }

    /* Header stays at the top while the window scrolls, so the close button is always reachable. */
    .modal-overlay:not(#bulk-import-modal) .modal-header {
        position: sticky; top: 0; z-index: 2;
        background: var(--c-surface);
        padding: 18px 16px 10px !important;
    }
    .modal-overlay:not(#bulk-import-modal) .modal-body { padding: 12px 16px 16px !important; overflow: visible !important; max-height: none !important; }
    #loan-history-modal .modal-body { padding: 0 !important; }

    /* Sticky save: the window's last full-width primary button (or a .sheet-actions row) stays visible at the bottom. */
    .modal-overlay form > .btn-primary.btn-full:last-child,
    .modal-overlay form > button[type="submit"]:last-child,
    .modal-overlay .modal-body > .btn-primary.btn-full:last-child,
    .modal-overlay .sheet-actions {
        position: sticky;
        bottom: 12px;
        z-index: 1;
        box-shadow: 0 0 0 12px var(--c-surface);
    }
    .modal-overlay .sheet-actions { display: flex; gap: var(--sp-2); background: var(--c-surface); }
    .modal-overlay .sheet-actions > .btn { flex: 1; }
}

@keyframes sheetUp { from { transform: translateY(32px); opacity: .4; } to { transform: none; opacity: 1; } }
