/**
 * Guest Web Interface - Find My Photos
 * Mobile-first responsive design
 * Optimized for iOS Safari 14+ and Android Chrome 90+
 */

/* ===== RESET & BASE ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body, #app {
    height: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #000;
    color: #fff;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    overscroll-behavior: none;
}

html.gallery-document-scroll-root {
    min-height: 100%;
    overflow-x: hidden;
    overflow-y: auto;
}

body.gallery-document-scroll {
    position: static;
    width: auto;
    height: auto;
    min-height: 100%;
    overflow: visible;
    overscroll-behavior-y: auto;
}

body.gallery-document-scroll #app {
    height: auto;
    min-height: 100vh;
    overflow: visible;
}

/* Prevent zoom on input focus (iOS) */
input, textarea, select {
    font-size: 16px;
}

/* ===== LAYOUT ===== */
.landing-container,
.capture-container,
.searching-container,
.results-container,
.no-matches-container,
.error-container {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    height: 100%;
    padding: 20px;
    padding-bottom: max(20px, env(safe-area-inset-bottom));
}

/* ===== LANDING PAGE ===== */
.landing-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    text-align: center;
}

.logo-placeholder {
    font-size: 80px;
    margin-bottom: 20px;
}

.landing-content h1 {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 10px;
}

.landing-content #start-btn {
    margin: 0 0 18px;
}

.tagline {
    font-size: 16px;
    color: #aaa;
    margin-bottom: 30px;
    max-width: 280px;
}

.privacy-note {
    background: #1a1a1a;
    border: 1px solid #333;
    border-radius: 12px;
    padding: 16px;
    margin: 20px 0 30px;
    font-size: 14px;
    text-align: left;
    max-width: 320px;
}

.privacy-note strong {
    display: block;
    margin-bottom: 6px;
    color: #22c55e;
}

.event-status-card {
    width: 100%;
    max-width: 320px;
    background: #111827;
    border: 1px solid #263244;
    border-radius: 12px;
    padding: 12px 14px;
    margin: 0 0 18px;
    text-align: left;
}

.event-status-card strong,
.event-status-card span {
    display: block;
}

.event-status-card strong {
    font-size: 16px;
    line-height: 1.25;
}

.event-status-card span {
    color: #9ca3af;
    font-size: 13px;
    margin-top: 3px;
}

.event-status-card.muted {
    color: #9ca3af;
    border-color: #303846;
}

/* ===== CAPTURE PAGE ===== */
.camera-container,
.file-input-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    margin-bottom: 20px;
    background: #111;
    border-radius: 16px;
    overflow: hidden;
    position: relative;
    min-height: 300px;
}

#camera-video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transform: scaleX(-1); /* Mirror for selfie */
}

.face-guide-circle {
    position: absolute;
    width: 200px;
    height: 200px;
    border: 3px solid rgba(255, 255, 255, 0.6);
    border-radius: 50%;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.4);
}

.camera-hint {
    position: absolute;
    bottom: 20px;
    left: 0;
    right: 0;
    font-size: 14px;
    color: rgba(255, 255, 255, 0.8);
    text-align: center;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
}

/* File input styling */
#file-input {
    position: absolute;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
}

.file-input-label {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: #aaa;
}

.file-input-icon {
    font-size: 60px;
    margin-bottom: 16px;
}

.file-input-label span {
    font-size: 16px;
}

.capture-footer {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.capture-privacy-note {
    align-self: stretch;
    max-width: none;
    margin: 6px 0 0;
}

/* ===== SEARCHING PAGE ===== */
.searching-container {
    justify-content: center;
}

.searching-content {
    text-align: center;
    padding: 0 20px;
}

.spinner-large {
    width: 60px;
    height: 60px;
    border: 4px solid #333;
    border-top-color: #3b82f6;
    border-radius: 50%;
    margin: 0 auto 24px;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.searching-container h2 {
    font-size: 24px;
    margin-bottom: 10px;
}

.searching-text {
    font-size: 16px;
    color: #aaa;
    margin-bottom: 24px;
}

.progress-bar-container {
    width: 100%;
    max-width: 280px;
    height: 6px;
    background: #333;
    border-radius: 3px;
    overflow: hidden;
    margin: 0 auto 24px;
}

.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, #3b82f6, #60a5fa);
    width: 0%;
    transition: width 0.1s ease;
    border-radius: 3px;
}

.searching-hint {
    font-size: 13px;
    color: #666;
}

/* ===== RESULTS PAGE ===== */
.results-container {
    height: auto;
    min-height: 100%;
    justify-content: flex-start;
}

.photo-selection-actions {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 16px;
}

.photo-selection-actions .btn,
.photo-selection-bar .btn { min-height: 44px; }

.photo-selection-bar {
    position: sticky;
    bottom: 0;
    z-index: 10;
    flex-shrink: 0;
    margin: 12px 0;
    padding: 12px;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
    background: #161616;
    border: 1px solid #555;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.photo-selection-bar p { font-size: 14px; color: #ddd; }
.photo-selection-bar p:empty { display: none; }
.photo-selection-actions [hidden],
.photo-selection-bar[hidden],
.photo-selection-bar [hidden] { display: none; }

.gallery-item.photo-selectable::after {
    content: '';
    position: absolute;
    top: 8px;
    left: 8px;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: 2px solid white;
    background: rgba(0, 0, 0, 0.6);
    text-align: center;
    line-height: 22px;
    font-weight: bold;
}

.gallery-item.photo-selected { outline: 3px solid #60a5fa; outline-offset: -3px; }
.gallery-item.photo-selected::after { content: '✓'; background: #2563eb; }

.results-header {
    text-align: center;
    margin-bottom: 20px;
    padding-top: 10px;
}

.results-header h2 {
    font-size: 24px;
    margin-bottom: 4px;
}

.results-header p {
    font-size: 16px;
    color: #aaa;
}

.gallery-whatsapp-share {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    padding: 6px 10px;
    color: #25d366;
    font-size: 16px;
    font-weight: 700;
    text-decoration: underline;
    text-decoration-color: rgba(37, 211, 102, 0.62);
    text-underline-offset: 4px;
}

.gallery-whatsapp-share:active {
    color: #86efac;
}

.gallery-whatsapp-share:focus-visible {
    outline: 2px solid #60a5fa;
    outline-offset: 2px;
    border-radius: 6px;
}

.badge {
    display: inline-block;
    background: #3b82f6;
    padding: 2px 10px;
    border-radius: 6px;
    font-weight: 700;
}

.gallery-grid {
    flex: 1;
    min-height: 0;
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 20px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    align-content: flex-start;
    align-items: flex-start;
}

.gallery-page .gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(128px, 1fr));
    margin-top: 12px;
    flex: none;
    min-height: auto;
    overflow: visible;
}

body.gallery-document-scroll .gallery-page {
    width: 100%;
    max-width: 1440px;
    margin: 0 auto;
    height: auto;
    min-height: 100vh;
    justify-content: flex-start;
}

.gallery-page .results-header,
.gallery-page .gallery-actions,
.gallery-page .results-footer {
    width: min(100%, 520px);
    align-self: center;
}

.gallery-page .results-footer {
    padding-top: 28px;
}

.gallery-actions {
    display: grid;
    gap: 8px;
    margin-bottom: 12px;
}

.gallery-item {
    position: relative;
    flex: 0 0 calc((100% - 16px) / 3);
    max-width: calc((100% - 16px) / 3);
    width: 100%;
    height: auto;
    min-width: 0;
    background: #1a1a1a;
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    border: 1px solid rgba(255, 255, 255, 0.06);
}

.gallery-page .gallery-item {
    flex: none;
    width: 100%;
    max-width: none;
}

.gallery-item::before {
    content: "";
    display: block;
    padding-top: 100%;
}

.gallery-item-error {
    outline: 2px solid #dc2626;
}

.gallery-item:focus-visible {
    outline: 2px solid #3b82f6;
    outline-offset: 3px;
}

.gallery-image {
    position: absolute;
    inset: 0;
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center top;
    background: #222;
}

.match-badge {
    position: absolute;
    top: 7px;
    right: 7px;
    background: rgba(15, 23, 42, 0.30);
    color: rgba(255, 255, 255, 0.62);
    border-radius: 999px;
    padding: 2px 6px;
    font-size: 10px;
    font-weight: 600;
    line-height: 1.2;
    backdrop-filter: blur(4px);
    border: 1px solid rgba(255, 255, 255, 0.12);
}

.photo-modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(0, 0, 0, 0.92);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 48px 16px 96px;
    touch-action: pan-y;
}

.photo-modal-image {
    max-width: 100%;
    max-height: 78vh;
    object-fit: contain;
    border-radius: 10px;
    box-shadow: 0 18px 70px rgba(0, 0, 0, 0.45);
}

.photo-modal-close {
    position: fixed;
    top: calc(env(safe-area-inset-top, 0px) + 14px);
    right: 16px;
    min-height: 42px;
    border: none;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    padding: 0 14px;
    font-size: 14px;
    font-weight: 800;
    line-height: 1;
}

.photo-modal-counter {
    position: fixed;
    top: calc(env(safe-area-inset-top, 0px) + 22px);
    left: 50%;
    transform: translateX(-50%);
    padding: 5px 10px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.12);
    color: rgba(255, 255, 255, 0.86);
    font-size: 13px;
    font-weight: 700;
    line-height: 1;
}

.photo-modal-nav {
    position: fixed;
    top: 50%;
    transform: translateY(-50%);
    width: 42px;
    height: 58px;
    border: none;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    font-size: 42px;
    line-height: 1;
}

.photo-modal-nav.prev {
    left: 10px;
}

.photo-modal-nav.next {
    right: 10px;
}

.photo-modal-nav:disabled {
    opacity: 0.22;
}

.photo-modal-actions {
    position: fixed;
    left: 16px;
    right: 16px;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 18px);
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
}

.photo-modal-feedback {
    min-height: 18px;
    color: rgba(255, 255, 255, 0.78);
    font-size: 13px;
    line-height: 1.35;
    text-align: center;
}

.photo-modal-feedback.success {
    color: #86efac;
}

.photo-modal-feedback.error {
    color: #fca5a5;
}

.photo-modal-selfie {
    justify-self: center;
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    border: none;
    background: none;
    color: #bfdbfe;
    padding: 8px 12px;
    font-size: 15px;
    font-weight: 700;
    text-decoration: underline;
    text-underline-offset: 3px;
}

.photo-modal-review {
    display: grid;
    justify-items: center;
    gap: 5px;
    color: rgba(255, 255, 255, 0.9);
    font-size: 14px;
    line-height: 1.35;
    text-align: center;
}

.photo-modal-review[hidden] {
    display: none;
}

.photo-modal-review a {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    padding: 0 10px;
    color: #bfdbfe;
    font-weight: 800;
    text-underline-offset: 3px;
}

.photo-modal-btn {
    border: none;
    border-radius: 10px;
    padding: 15px 18px;
    font-size: 16px;
    font-weight: 800;
}

.photo-modal-btn.primary {
    background: #3b82f6;
    color: #fff;
}

.photo-modal-btn.secondary {
    background: rgba(255, 255, 255, 0.16);
    color: #fff;
}

.photo-modal-btn:disabled {
    opacity: 0.65;
}

.empty-gallery {
    flex: 0 0 100%;
    color: #777;
    text-align: center;
    padding: 40px 20px;
}

.gallery-page .empty-gallery {
    grid-column: 1 / -1;
}

.results-footer {
    padding-top: 10px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* ===== NO MATCHES PAGE ===== */
.no-matches-content,
.error-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    text-align: center;
    padding: 20px;
}

.illustration {
    font-size: 80px;
    margin-bottom: 20px;
}

.error-icon {
    width: 80px;
    height: 80px;
    background: #dc2626;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 48px;
    font-weight: bold;
    margin-bottom: 20px;
}

.no-matches-container h2,
.error-container h2 {
    font-size: 24px;
    margin-bottom: 16px;
}

.explanation {
    font-size: 14px;
    color: #aaa;
    margin-bottom: 8px;
}

.explanation-list {
    list-style: none;
    padding: 0;
    margin-bottom: 30px;
    text-align: left;
}

.explanation-list li {
    font-size: 14px;
    color: #888;
    margin: 8px 0;
    padding-left: 20px;
    position: relative;
}

.explanation-list li:before {
    content: '\2022';
    position: absolute;
    left: 0;
    color: #666;
}

.error-message {
    font-size: 16px;
    color: #aaa;
    margin-bottom: 8px;
}

.error-suggestion {
    font-size: 14px;
    color: #666;
    margin-bottom: 30px;
}

/* ===== BUTTONS ===== */
.btn {
    border: none;
    border-radius: 12px;
    padding: 14px 24px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    touch-action: manipulation;
    min-height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
}

.btn-primary {
    background: #3b82f6;
    color: #fff;
}

.btn-primary:active {
    background: #2563eb;
    transform: scale(0.98);
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.btn-secondary {
    background: #222;
    color: #aaa;
}

.btn-secondary:active {
    background: #333;
}

.btn-outline {
    background: transparent;
    color: #3b82f6;
    border: 1px solid #3b82f6;
}

.btn-outline:active {
    background: rgba(59, 130, 246, 0.1);
}

.or-divider {
    text-align: center;
    color: #555;
    font-size: 13px;
    margin: 2px 0;
}

.btn-large {
    font-size: 17px;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 639px) {
    .gallery-page .gallery-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

@media (min-width: 640px) {
    .landing-container,
    .capture-container,
    .searching-container,
    .results-container,
    .no-matches-container,
    .error-container {
        padding: 40px;
        max-width: 500px;
        margin: 0 auto;
    }

    .gallery-grid {
        gap: 12px;
    }

    .gallery-item {
        flex-basis: calc((100% - 36px) / 4);
        max-width: calc((100% - 36px) / 4);
    }

    .face-guide-circle {
        width: 240px;
        height: 240px;
    }
}

@media (min-width: 640px) and (max-height: 800px) {
    .camera-container,
    .file-input-container {
        min-height: 240px;
    }
}

/* ===== ACCESSIBILITY ===== */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Focus states for keyboard navigation */
.btn:focus-visible {
    outline: 2px solid #60a5fa;
    outline-offset: 2px;
}

/* ===== REGISTRATION GATE ===== */
.register-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    padding: 20px;
}

.register-content {
    width: 100%;
    max-width: 400px;
    text-align: center;
}

.register-content h2 {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 8px;
}

.register-subtext {
    color: #9ca3af;
    margin-bottom: 24px;
    font-size: 14px;
}

.reg-form {
    text-align: left;
}

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 6px;
    color: #e5e7eb;
}

.form-group input {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid #374151;
    border-radius: 8px;
    background: #1f2937;
    color: #fff;
    font-size: 16px;
    box-sizing: border-box;
    transition: border-color 0.2s ease;
}

.form-group input:focus {
    outline: none;
    border-color: #3b82f6;
}

.form-group input::placeholder {
    color: #6b7280;
}

.required {
    color: #f87171;
}

.optional {
    color: #6b7280;
    font-weight: 400;
    font-size: 12px;
}

.reg-error {
    background: #1f2937;
    border: 1px solid #ef4444;
    color: #f87171;
    border-radius: 8px;
    padding: 12px 14px;
    margin-bottom: 16px;
    font-size: 14px;
    text-align: left;
}

.reg-error.hidden {
    display: none;
}

.btn-link {
    background: none;
    border: none;
    color: #6b7280;
    cursor: pointer;
    font-size: 14px;
    margin-top: 16px;
    text-decoration: underline;
    padding: 8px;
}

.btn-link:hover {
    color: #9ca3af;
}

.btn-download-locked {
    background: #374151;
    color: #9ca3af;
}

.btn-download-locked:active {
    background: #4b5563;
}

.reg-success-msg {
    color: #4ade80;
    font-size: 14px;
    margin-bottom: 12px;
}

/* ===== DARK MODE (default) ===== */
/* Already dark by default, but ensure consistency */
@media (prefers-color-scheme: light) {
    /* Keep dark theme regardless of system preference for event photos */
    body {
        background: #000;
        color: #fff;
    }
}

/* Arrival shares the gallery's dark surface, system type and blue actions. */
.landing-container{height:auto;min-height:100%;padding:24px 20px max(24px,env(safe-area-inset-bottom))}
.landing-content{width:100%;max-width:400px;margin:auto;padding:16px 0}
.gallery-emblem{width:56px;height:56px;margin-bottom:20px;color:#60a5fa}
.gallery-emblem svg{display:block;width:100%;height:100%}
.landing-content h1{font-size:28px;line-height:1.2;overflow-wrap:anywhere;max-width:100%;margin:0 0 16px}
.landing-event-name{color:#aaa;margin-bottom:8px;overflow-wrap:anywhere}
.landing-content .event-status-card{max-width:400px;text-align:center;margin:0 0 12px;background:#1a1a1a;border-color:#333;padding:16px}
.landing-content .event-status-card strong{font-size:16px}
.landing-content .event-status-card span{color:#aaa;font-size:14px;margin-top:6px}
.landing-content .tagline{margin:0 0 12px;max-width:340px}
.landing-content #start-btn{max-width:340px;margin:0 0 12px}
.landing-content .landing-privacy{max-width:400px;background:none;border:0;border-top:1px solid #333;border-radius:0;padding:16px 0 0;margin:16px 0 0;font-size:12px;color:#aaa}
.landing-content .landing-privacy strong{color:#fff}

/* Balance the side space so WhatsApp stays centered independently of sorting. */
.gallery-share-row{position:relative;display:flex;align-items:center;justify-content:center;min-height:44px;padding:0 140px}
.gallery-share-row .gallery-whatsapp-share{justify-content:center;text-align:center}
.public-photo-order{position:absolute;right:0;top:50%;transform:translateY(-50%);height:44px;color:#e2e8f0}
.public-photo-order button{box-sizing:border-box;min-height:44px;width:138px;padding:6px 8px;border:1px solid #485765;border-radius:5px;background:#17212a;color:inherit;font-family:inherit;font-size:14px;color-scheme:dark;cursor:pointer}
.public-photo-order button:focus-visible{outline:2px solid #60a5fa;outline-offset:2px}
.public-photo-order svg{display:none;pointer-events:none}
@media(max-width:700px){.gallery-share-row{padding:0 48px}.public-photo-order{width:44px}.public-photo-order button{width:44px;appearance:none;color:transparent;font-size:0}.public-photo-order svg{display:block;position:absolute;inset:11px;width:22px;height:22px}.gallery-share-row .gallery-whatsapp-share{font-size:14px;padding:6px 0}}

.public-photo-order[data-sort="oldest"] svg{transform:rotate(180deg)}
.public-photo-order button:disabled{opacity:.6;cursor:wait}
