/**
 * Vantage responsive layer.
 * Breakpoints: 1440+ desktop (base CSS), 1024–1439 laptop, 768–1023 tablet,
 * below 768 mobile, below 480 small mobile.
 * Does not replace component styles; only adapts layout at those widths.
 */

html {
    overflow-x: clip;
}

body {
    max-width: 100%;
    overflow-x: clip;
}

/* -------------------------------------------------------------------------- */
/* Laptop / small desktop: 1024px–1439px — compact header, keep sidebar       */
/* -------------------------------------------------------------------------- */
@media (max-width: 1439px) {
    .header-inner {
        height: auto;
        min-height: 64px;
        padding: 8px 20px;
        flex-wrap: wrap;
        row-gap: 8px;
    }

    .header-status {
        flex: 1 1 auto;
        min-width: 0;
        flex-wrap: wrap;
    }

    .header-status-item {
        width: auto;
        min-width: 0;
        max-width: 100%;
        flex: 1 1 140px;
    }

    .header-status-item:last-child,
    .header-status-item.header-stats-compact {
        width: auto;
        max-width: 100%;
        flex: 1 1 200px;
    }

    .header-actions {
        flex: 1 1 auto;
        min-width: 0;
        flex-wrap: wrap;
        justify-content: flex-end;
    }

    .container {
        padding: 24px 20px 48px;
    }

    .boxed-panel {
        padding: 18px 18px;
    }

    .gallery-grid {
        grid-template-columns: repeat(auto-fill, minmax(min(100%, 150px), 1fr));
        gap: 12px;
    }
}

/* -------------------------------------------------------------------------- */
/* Tablet: 768px–1023px — sidebar as top nav, viewport-aware modals           */
/* -------------------------------------------------------------------------- */
@media (max-width: 1023px) {
    .app-shell {
        flex-direction: column;
        height: 100dvh;
        max-width: 100%;
    }

    .sidebar {
        width: 100%;
        min-width: 0;
        max-width: 100%;
        height: auto;
        max-height: 40dvh;
        border-right: none;
        border-bottom: 1px solid var(--border-sidebar);
        flex-shrink: 0;
    }

    .app-shell.sidebar-collapsed .sidebar {
        width: 100%;
        min-width: 0;
    }

    .sidebar-nav {
        flex-direction: row;
        flex-wrap: wrap;
        padding: 12px 14px;
        gap: 6px;
    }

    .sidebar-nav-label {
        display: none;
    }

    .sidebar-nav .nav-btn {
        width: auto;
        flex: 1 1 auto;
        min-width: 0;
        justify-content: center;
    }

    .sidebar-footer-storage {
        display: none;
    }

    .main-wrapper {
        min-height: 0;
        height: auto;
        flex: 1 1 auto;
        overflow-y: auto;
    }

    .header-status-divider {
        display: none;
    }

    .main-header .primary-btn,
    .main-header .secondary-btn {
        width: auto;
        min-height: 40px;
    }

    .gallery-grid {
        grid-template-columns: repeat(auto-fill, minmax(min(100%, 140px), 1fr));
    }

    .gallery-grid img,
    .culling-card-thumb img {
        height: auto;
        aspect-ratio: 4 / 3;
        object-fit: cover;
        max-width: 100%;
    }

    .culling-card-thumb {
        min-height: 0;
    }

    .identity-card {
        height: auto;
        max-width: 100%;
    }

    .modal,
    .export-popup {
        padding: 12px;
        align-items: flex-start;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .modal-content,
    .export-card,
    .settings-modal-content {
        width: min(100%, 720px);
        max-width: 100%;
        max-height: min(90dvh, 100%);
        min-width: 0;
    }

    #upload-index-popup .upload-index-card {
        min-height: 0;
        max-height: min(90dvh, 680px);
        width: min(100%, 680px);
    }

    .upload-preset-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .settings-form {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .culling-action-bar {
        flex-wrap: wrap;
        padding: 10px 14px;
        gap: 8px;
    }

    .culling-toolbar-stack .toolbar-left,
    .culling-toolbar-stack .toolbar-right {
        min-width: 0;
        flex-wrap: wrap;
    }

    .cloud-provider-list {
        flex-wrap: wrap;
    }
}

/* -------------------------------------------------------------------------- */
/* Mobile: below 768px                                                        */
/* -------------------------------------------------------------------------- */
@media (max-width: 767px) {
    .container {
        padding: 16px 12px 88px;
    }

    .boxed-panel {
        padding: 14px 12px;
        margin-bottom: 14px;
        border-radius: 12px;
    }

    .header-inner {
        padding: 8px 12px;
        gap: 8px;
    }

    .header-status-item {
        height: auto;
        min-height: 44px;
        padding: 8px 10px;
        flex: 1 1 100%;
    }

    .header-actions {
        width: 100%;
        justify-content: stretch;
    }

    .header-actions .primary-btn,
    .header-actions .secondary-btn {
        flex: 1 1 auto;
        min-height: 44px;
        justify-content: center;
    }

    .main-header .primary-btn,
    .main-header .secondary-btn,
    .culling-toolbar .primary-btn,
    .culling-toolbar .secondary-btn,
    .culling-toolbar .btn,
    .wizard-modal-footer .primary-btn,
    .wizard-modal-footer .secondary-btn,
    .sidebar-nav .nav-btn,
    .upload-preset-card,
    .upload-filter-pill,
    .export-option-btn,
    .cloud-provider-row {
        min-height: 44px;
        width: auto;
    }

    .gallery-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 10px;
    }

    .gallery-grid img,
    .culling-card-thumb img {
        aspect-ratio: 3 / 4;
    }

    .settings-form {
        grid-template-columns: 1fr;
        padding: 14px 12px;
        gap: 12px;
    }

    .settings-tabs {
        width: 100%;
        display: flex;
        flex-wrap: wrap;
    }

    .settings-tab-btn {
        flex: 1 1 auto;
        min-height: 40px;
    }

    .modal-actions,
    .settings-actions,
    .wizard-modal-footer {
        flex-wrap: wrap;
        gap: 8px;
    }

    .wizard-modal-footer .primary-btn,
    .wizard-modal-footer .secondary-btn {
        flex: 1 1 auto;
    }

    .culling-action-bar {
        padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
    }

    .culling-toolbar-stack select,
    .culling-toolbar-stack input,
    .settings-field input,
    .settings-field select,
    .gdrive-url-input {
        max-width: 100%;
        min-width: 0;
        width: 100%;
    }

    table,
    .memzo-table-wrap {
        display: block;
        max-width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .upload-filter-pills {
        gap: 8px;
    }

    .image-processing-summary .summary-row {
        flex-wrap: wrap;
    }
}

/* -------------------------------------------------------------------------- */
/* Small mobile: below 480px                                                  */
/* -------------------------------------------------------------------------- */
@media (max-width: 479px) {
    .container {
        padding: 12px 10px 96px;
    }

    .gallery-grid {
        grid-template-columns: minmax(0, 1fr);
        gap: 8px;
    }

    .gallery-grid img,
    .culling-card-thumb img {
        aspect-ratio: 4 / 3;
    }

    .upload-preset-grid {
        grid-template-columns: minmax(0, 1fr);
    }

    .header-stats-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 4px;
    }

    .dialog-header__row h2,
    #upload-index-popup .export-card-header h2,
    .settings-modal-content .modal-header h2 {
        font-size: 16px;
    }

    .boxed-panel {
        padding: 12px 10px;
    }

    .sidebar-nav .nav-btn span:not(.btn-icon) {
        font-size: 12px;
    }

    .export-option-grid {
        grid-template-columns: 1fr;
    }
}

/* Large desktop: keep base layout; slightly roomier gallery only */
@media (min-width: 1440px) {
    .gallery-grid {
        grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    }
}

@media (min-width: 1920px) {
    .gallery-grid {
        grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    }
}

/* -------------------------------------------------------------------------- */
/* Subject in Focus + Moved Images (page-specific; keep global rules above)   */
/* -------------------------------------------------------------------------- */

#focus-people-section .focus-scene {
    position: relative;
    overflow: hidden;
}

#focus-people-section .focus-scene img {
    width: 100%;
    height: 100%;
    max-width: 100%;
    aspect-ratio: auto;
    object-fit: cover;
    display: block;
}

#focus-people-section .focus-overlay {
    pointer-events: none;
    z-index: 3;
}

#focus-people-section .culling-toolbar,
#moved-images-section .culling-toolbar {
    flex-wrap: wrap;
    min-width: 0;
}

#moved-images-section .toolbar-right {
    min-width: 0;
    flex-wrap: wrap;
    gap: 8px;
}

#moved-images-section select.secondary-btn {
    min-width: 0;
    max-width: 100%;
}

@media (max-width: 1023px) {
    #moved-columns-container.moved-columns {
        grid-template-columns: 1fr;
    }

    #focus-people-grid.focus-people-grid {
        grid-template-columns: repeat(auto-fill, minmax(min(100%, 180px), 1fr));
    }

    #moved-images-section .toolbar-right {
        width: 100%;
    }

    #moved-images-section select.secondary-btn,
    #moved-images-section .secondary-btn {
        min-width: 0;
        flex: 1 1 140px;
    }

    #focus-people-subtitle {
        white-space: normal;
        max-width: 100%;
    }
}

@media (max-width: 767px) {
    #moved-images-section .gallery-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    #moved-images-section .image-select-checkbox {
        width: 18px;
        height: 18px;
        min-width: 18px;
    }
}

@media (max-width: 479px) {
    #moved-images-section .gallery-grid {
        grid-template-columns: minmax(0, 1fr);
    }

    #focus-people-grid.focus-people-grid {
        grid-template-columns: minmax(0, 1fr);
    }
}

/* Culling image-action toolbar — keep groups usable; do not stretch every control */
#culling-gallery-section .culling-toolbar-stack {
    overflow: visible;
    max-width: 100%;
}

#culling-gallery-section .culling-toolbar-row--main,
#culling-gallery-section .toolbar-left,
#culling-gallery-section .toolbar-right,
#culling-gallery-section .toolbar-actions-group,
#culling-gallery-section .toolbar-group {
    max-width: 100%;
    min-width: 0;
}

@media (max-width: 1023px) {
    #culling-gallery-section .culling-toolbar-row--main {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }

    #culling-gallery-section .toolbar-left,
    #culling-gallery-section .toolbar-right,
    #culling-gallery-section .toolbar-actions-group,
    #culling-gallery-section .toolbar-group--selection {
        width: 100%;
        justify-content: flex-start;
        flex-wrap: wrap;
    }

    #culling-gallery-section #move-category-select {
        width: 136px;
        min-width: 136px;
        max-width: 136px;
        flex: 0 0 136px;
    }

    #culling-gallery-section #move-selected-btn,
    #culling-gallery-section .filter-wrapper-right,
    #culling-gallery-section .filter-trigger-btn {
        flex: 1 1 auto;
        min-width: 0;
        max-width: 100%;
        width: auto;
    }
}

@media (max-width: 767px) {
    #culling-gallery-section .culling-toolbar .primary-btn,
    #culling-gallery-section .culling-toolbar .secondary-btn,
    #culling-gallery-section .culling-toolbar .btn {
        width: auto;
        max-width: 100%;
        min-height: 44px;
        flex: 0 1 auto;
    }

    #culling-gallery-section #move-category-select {
        width: 136px;
        min-width: 136px;
        max-width: 136px;
        min-height: 44px;
    }

    #culling-gallery-section .filter-panel {
        max-width: min(100vw - 24px, 100%);
        left: 0;
        right: auto;
    }
}
