/* Mobile-friendly styles for image search & admin */

/* ── Safe area (notched phones) ── */
@supports (padding: env(safe-area-inset-bottom)) {
    .lens-detail {
        padding-bottom: calc(1rem + env(safe-area-inset-bottom));
    }

    .camera-modal-footer {
        padding-bottom: calc(1.25rem + env(safe-area-inset-bottom));
    }
}

/* ── Image search results (lens) ── */
@media (max-width: 768px) {
    .lens {
        margin-top: 0.5rem;
        border-radius: 12px;
    }

    .lens-header {
        padding: 0.75rem 1rem;
        gap: 0.75rem;
    }

    .lens-back-btn {
        min-height: 44px;
        padding: 0.625rem 1.125rem;
    }

    .lens-count {
        font-size: 0.8125rem;
        flex: 1;
        justify-content: flex-end;
    }

    .lens-count span:last-child {
        display: none;
    }

    .lens-count::after {
        content: 'matches';
        color: var(--lens-muted);
    }

    .lens-body {
        min-height: auto;
    }

    .lens-ref {
        padding: 0.875rem 1rem;
    }

    .lens-ref-label {
        margin-bottom: 0.35rem;
    }

    .lens-ref-img-wrap {
        width: 88px;
        max-width: 28vw;
    }

    .lens-main {
        padding: 0.875rem 1rem 1rem;
        max-height: none;
        overflow: visible;
    }

    .lens-grid-label {
        font-size: 0.625rem;
        letter-spacing: 0.05em;
        margin-bottom: 0.75rem;
        line-height: 1.4;
    }

    .lens-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 0.5rem;
    }

    .lens-card:hover {
        transform: none;
        box-shadow: none;
    }

    .lens-card.is-active {
        transform: scale(1.02);
    }

    .lens-card-overlay {
        opacity: 1;
    }

    .lens-badge {
        font-size: 0.625rem;
        padding: 0.15rem 0.4rem;
        top: 0.35rem;
        right: 0.35rem;
    }

    .lens-detail {
        flex-direction: column;
        align-items: stretch;
        padding: 1rem;
        gap: 0.875rem;
        position: sticky;
        bottom: 0;
        z-index: 5;
        box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.35);
    }

    .lens-detail-preview {
        display: none;
    }

    .lens-detail-info {
        min-width: 0;
    }

    .lens-meter {
        max-width: 100%;
    }

    .lens-detail-actions {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 0.5rem;
        width: 100%;
    }

    .lens-detail-actions .lens-btn--primary {
        grid-column: 1 / -1;
    }

    .lens-detail-actions .lens-btn {
        width: 100%;
        justify-content: center;
        min-height: 44px;
        padding: 0.75rem 1rem;
        font-size: 0.8125rem;
    }

    .lens-empty {
        padding: 2.5rem 1.25rem;
    }

    .lens-lightbox {
        padding: 0.5rem;
    }

    .lens-lightbox-close {
        top: max(0.75rem, env(safe-area-inset-top, 0.75rem));
        right: max(0.75rem, env(safe-area-inset-right, 0.75rem));
        width: 44px;
        height: 44px;
    }

    .lens-lightbox img {
        max-height: 85vh;
    }
}

@media (max-width: 380px) {
    .lens-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.4rem;
    }

    .lens-header {
        flex-wrap: nowrap;
    }
}

/* ── Camera & upload area ── */
@media (max-width: 768px) {
    .camera-search {
        margin-bottom: 0.75rem;
    }

    .camera-search-actions {
        flex-direction: column;
        align-items: stretch;
        gap: 0.625rem;
    }

    .camera-btn--primary {
        width: 100%;
        min-height: 48px;
        padding: 0.875rem 1.5rem;
        font-size: 1rem;
    }

    .camera-search-or {
        text-align: center;
        width: 100%;
    }

    .camera-modal {
        padding: 0;
        align-items: stretch;
    }

    .camera-modal-panel {
        max-width: none;
        width: 100%;
        height: 100%;
        max-height: 100dvh;
        border-radius: 0;
        display: flex;
        flex-direction: column;
        border: none;
    }

    .camera-modal-header {
        padding-top: max(0.875rem, env(safe-area-inset-top, 0.875rem));
    }

    .camera-video-wrap {
        flex: 1;
        aspect-ratio: auto;
        min-height: 0;
    }

    .camera-video {
        width: 100%;
        height: 100%;
        min-height: 50dvh;
        object-fit: cover;
    }

    .camera-modal-footer {
        padding: 1rem 1.5rem;
        padding-bottom: max(1.25rem, env(safe-area-inset-bottom, 1.25rem));
    }

    .camera-btn--capture {
        width: 4.5rem;
        height: 4.5rem;
    }

    .camera-btn--ghost {
        min-height: 44px;
        min-width: 64px;
    }

    .lens-browse-toggle {
        text-align: center;
        margin-bottom: 0.5rem;
    }

    .lens-browse-link {
        min-height: 44px;
        padding: 0.5rem;
    }

    .lens-search-loading-box {
        margin: 1rem;
        padding: 1.5rem 2rem;
        max-width: calc(100vw - 2rem);
    }
}

/* ── Filament admin — global mobile tweaks ── */
@media (max-width: 768px) {
    .fi-main-ctn {
        padding-left: 0.75rem;
        padding-right: 0.75rem;
    }

    .fi-header-heading {
        font-size: 1.25rem;
        line-height: 1.3;
    }

    .fi-ta-ctn {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .fi-ac-btn-action {
        min-height: 44px;
    }

    .fi-fo-file-upload .filepond--root {
        min-height: 150px;
    }
}

/* ── Image search page (body class set on ListImages) ── */
@media (max-width: 768px) {
    .fi-page-images .fi-section-content {
        padding-left: 0.75rem !important;
        padding-right: 0.75rem !important;
    }

    .fi-page-images .fi-fo-file-upload {
        width: 100%;
    }

    .fi-page-images .filepond--drop-label {
        min-height: 140px;
        font-size: 0.875rem;
    }

    .fi-page-images .fi-ta-table {
        min-width: 480px;
    }
}

/* ── PWA install prompt (iPhone / Android) ── */
#pwa-install-root[hidden] {
    display: none !important;
}

.pwa-install-fab {
    position: fixed;
    right: 1rem;
    bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
    z-index: 60;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.65rem 1rem;
    border: none;
    border-radius: 999px;
    background: #f59e0b;
    color: #111827;
    font-size: 0.875rem;
    font-weight: 600;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
    cursor: pointer;
}

.pwa-install-fab svg {
    width: 1.1rem;
    height: 1.1rem;
}

.pwa-install-fab[hidden] {
    display: none !important;
}

.pwa-install-backdrop {
    position: fixed;
    inset: 0;
    z-index: 70;
    background: rgba(0, 0, 0, 0.45);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

.pwa-install-backdrop.is-open {
    opacity: 1;
    pointer-events: auto;
}

.pwa-install-sheet {
    position: fixed;
    left: 50%;
    bottom: 0;
    z-index: 80;
    width: min(100%, 26rem);
    max-height: 85vh;
    overflow-y: auto;
    padding: 1.25rem 1.25rem calc(1.25rem + env(safe-area-inset-bottom, 0px));
    border-radius: 1rem 1rem 0 0;
    background: #fff;
    color: #111827;
    transform: translate(-50%, 110%);
    transition: transform 0.25s ease;
}

.dark .pwa-install-sheet {
    background: #18181b;
    color: #fafafa;
}

.pwa-install-sheet.is-open {
    transform: translate(-50%, 0);
}

.pwa-install-close {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    border: none;
    background: transparent;
    font-size: 1.5rem;
    line-height: 1;
    color: inherit;
    cursor: pointer;
}

.pwa-install-icon {
    display: flex;
    justify-content: center;
    margin-bottom: 0.75rem;
}

.pwa-install-icon img {
    border-radius: 1rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.pwa-install-title {
    margin: 0 0 0.35rem;
    text-align: center;
    font-size: 1.125rem;
    font-weight: 700;
}

.pwa-install-subtitle {
    margin: 0 0 1rem;
    text-align: center;
    font-size: 0.9rem;
    opacity: 0.8;
}

.pwa-install-steps {
    margin: 0 0 1rem;
    padding-left: 1.25rem;
    font-size: 0.9rem;
    line-height: 1.5;
}

.pwa-install-steps li + li {
    margin-top: 0.5rem;
}

.pwa-share-icon {
    display: inline-block;
    font-size: 1rem;
    vertical-align: middle;
}

.pwa-install-note {
    margin: 0 0 1rem;
    padding: 0.65rem 0.75rem;
    border-radius: 0.5rem;
    background: rgba(245, 158, 11, 0.15);
    font-size: 0.8rem;
    line-height: 1.4;
}

.pwa-install-btn {
    width: 100%;
    min-height: 44px;
    border: none;
    border-radius: 0.65rem;
    background: #f59e0b;
    color: #111827;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
}

@media (min-width: 769px) {
    .pwa-install-fab {
        display: none;
    }
}
