/* ============================================
   SeeTogether - Styles
   Tema: Preto, Azul e Lilás
   ============================================ */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --color-primary: #6C5CE7; /* Lilás */
    --color-primary-dark: #5A4FCF;
    --color-primary-light: #A29BFE;
    --color-secondary: #0984E3; /* Azul */
    --color-secondary-dark: #0770C4;
    --color-dark: #2D3436;
    --color-darker: #1E1E1E;
    --color-darkest: #0A0A0A;
    --color-light: #DFE6E9;
    --color-white: #FFFFFF;
    --color-success: #00B894;
    --color-error: #D63031;
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.2);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.3);
    --shadow-glow: 0 0 20px rgba(108, 92, 231, 0.5);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: linear-gradient(135deg, var(--color-darkest) 0%, var(--color-darker) 50%, var(--color-dark) 100%);
    color: var(--color-light);
    min-height: 100vh;
    line-height: 1.6;
    margin: 0;
    padding: 0;
    /* PWA optimizations */
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    /* Allow vertical scrolling, prevent horizontal bounce */
    overscroll-behavior-y: auto;
    overscroll-behavior-x: none;
    /* Allow touch scrolling */
    -webkit-overflow-scrolling: touch;
}

/* PWA safe area for devices with notches */
@supports (padding: max(0px)) {
    body {
        padding-top: max(0px, env(safe-area-inset-top));
        padding-bottom: max(0px, env(safe-area-inset-bottom));
        padding-left: max(0px, env(safe-area-inset-left));
        padding-right: max(0px, env(safe-area-inset-right));
    }
}

/* ============================================
   Auth Pages (Login/Registo)
   ============================================ */

.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
}

.auth-container {
    width: 100%;
    max-width: 450px;
}

.auth-card {
    background: rgba(30, 30, 30, 0.95);
    border-radius: 20px;
    padding: 40px;
    box-shadow: var(--shadow-lg);
    border: 1px solid rgba(108, 92, 231, 0.3);
    backdrop-filter: blur(10px);
}

.auth-title {
    font-size: 2.5em;
    text-align: center;
    margin-bottom: 10px;
    background: linear-gradient(135deg, var(--color-primary), var(--color-secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.auth-subtitle {
    font-size: 1.5em;
    text-align: center;
    margin-bottom: 30px;
    color: var(--color-light);
    font-weight: 300;
}

.auth-form {
    margin-top: 30px;
}

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

.form-group label {
    display: block;
    margin-bottom: 8px;
    color: var(--color-light);
    font-weight: 500;
}

.form-group input {
    width: 100%;
    padding: 12px 16px;
    background: rgba(45, 52, 54, 0.8);
    border: 2px solid rgba(108, 92, 231, 0.3);
    border-radius: 10px;
    color: var(--color-white);
    font-size: 1em;
    transition: all 0.3s ease;
}

.form-group input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(108, 92, 231, 0.2);
}

.form-group input::placeholder {
    color: rgba(223, 230, 233, 0.5);
}

.form-control {
    width: 100%;
    padding: 12px 16px;
    background: rgba(45, 52, 54, 0.8);
    border: 2px solid rgba(108, 92, 231, 0.3);
    border-radius: 10px;
    color: var(--color-light);
    font-size: 1em;
    box-sizing: border-box;
    transition: all 0.3s ease;
}

.form-control:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(108, 92, 231, 0.2);
}

.form-control::placeholder {
    color: rgba(223, 230, 233, 0.5);
}

.alert {
    padding: 12px 16px;
    border-radius: 10px;
    margin-bottom: 20px;
    font-size: 0.9em;
}

.alert-error {
    background: rgba(214, 48, 49, 0.2);
    border: 1px solid var(--color-error);
    color: #FF6B6B;
}

.alert-success {
    background: rgba(0, 184, 148, 0.2);
    border: 1px solid var(--color-success);
    color: #55EFC4;
}

.auth-footer {
    text-align: center;
    margin-top: 30px;
    color: var(--color-light);
}

.auth-footer a {
    color: var(--color-primary-light);
    text-decoration: none;
    font-weight: 500;
    transition: color 0.3s ease;
}

.auth-footer a:hover {
    color: var(--color-primary);
}

/* ============================================
   Buttons
   ============================================ */

.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 10px;
    font-size: 1em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    box-sizing: border-box;
}

.btn-primary {
    background: linear-gradient(135deg, var(--color-primary), var(--color-secondary));
    color: var(--color-white);
    box-shadow: var(--shadow-md);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.btn-secondary {
    background: rgba(45, 52, 54, 0.8);
    color: var(--color-light);
    border: 1px solid rgba(108, 92, 231, 0.3);
    flex-shrink: 0;
    white-space: nowrap;
}

.btn-secondary:hover {
    background: rgba(45, 52, 54, 1);
    border-color: var(--color-primary);
}

.btn-block {
    width: 100%;
}

.btn-sm {
    padding: 8px 16px;
    font-size: 0.9em;
    min-height: 36px;
    height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    line-height: 1;
}

/* ============================================
   Main Page
   ============================================ */

.main-page {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    /* Body/main-page is the scroll container - allow it to grow beyond viewport */
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    /* Allow vertical panning for scrolling */
    touch-action: pan-y;
    /* Ensure smooth scrolling */
    scroll-behavior: smooth;
    /* Prevent scroll issues on mobile */
    position: relative;
    width: 100%;
    /* Don't set fixed height - let content determine height for scroll to work */
}

.header {
    background: rgba(30, 30, 30, 0.95);
    border-bottom: 1px solid rgba(108, 92, 231, 0.3);
    padding: 20px;
    backdrop-filter: blur(10px);
    /* Critical: Allow vertical scrolling when touch starts on header */
    /* pan-y allows vertical panning (scrolling) - this is key to fix the bug */
    touch-action: pan-y;
    /* Ensure header doesn't block scroll events but allows interactions */
    pointer-events: auto;
    position: relative;
    z-index: 100;
    /* Prevent header from creating scroll issues */
    flex-shrink: 0;
}

.header-content {
    max-width: 1200px;
    margin: 0 auto;
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 20px;
    width: 100%;
}

.logo-link {
    text-decoration: none;
    display: inline-block;
    cursor: pointer;
}

.logo-link:hover .logo {
    opacity: 0.8;
    transition: opacity 0.3s ease;
}

.logo {
    font-size: 1.8em;
    background: linear-gradient(135deg, var(--color-primary), var(--color-secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    flex-shrink: 0;
    white-space: nowrap;
    margin: 0;
}

.header-actions-left {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
    /* Allow touch events on buttons but allow scroll through header */
    touch-action: manipulation;
    /* Ensure consistent width so buttons don't move */
    min-width: 200px;
}

.header-actions-right {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: nowrap;
    justify-content: flex-end;
    padding-left: 20px;
    border-left: 2px solid rgba(108, 92, 231, 0.4);
    flex-shrink: 0;
    white-space: nowrap;
    /* Allow touch events */
    touch-action: manipulation;
}

/* Ensure all buttons in header-actions-right have same base size */
.header-actions-right .btn {
    flex: 0 0 auto;
    width: auto;
    min-width: fit-content;
}

/* Buttons in header should allow taps but not block scroll gestures */
.header .btn,
.header a {
    /* manipulation allows tap but pan-y on parent allows scroll through */
    touch-action: manipulation;
    /* Prevent buttons from blocking scroll when touch starts on them */
    pointer-events: auto;
    /* Ensure buttons are interactive */
    cursor: pointer;
}

/* Logo and text in header should allow scroll */
.header .logo {
    touch-action: pan-y;
    /* Allow scroll gestures through text areas */
    user-select: none;
    -webkit-user-select: none;
}

.username {
    color: var(--color-light);
    font-weight: 600;
    font-size: 1em;
    white-space: nowrap;
}

.btn-profile {
    background: rgba(108, 92, 231, 0.8);
    color: var(--color-white);
    border: 1px solid rgba(108, 92, 231, 0.5);
    padding: 8px 16px;
    min-height: 36px;
    height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    line-height: 1;
    font-weight: 600;
    transition: all 0.3s ease;
    box-shadow: var(--shadow-md);
    /* Ensure it doesn't grow beyond content */
    flex-shrink: 0;
    max-width: fit-content;
    white-space: nowrap;
}

.btn-profile:hover {
    background: rgba(108, 92, 231, 1);
    border-color: var(--color-primary);
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.btn-profile .username {
    margin: 0;
    padding: 0;
    color: var(--color-white);
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 150px;
    display: block;
}

@media (max-width: 768px) {
    .header-content {
        grid-template-columns: 1fr;
        gap: 15px;
    }
    
    .logo {
        text-align: center;
        width: 100%;
    }
    
    .header-actions-left {
        justify-content: center;
        width: 100%;
        gap: 8px;
    }
    
    .header-actions-right {
        justify-content: center;
        width: 100%;
        margin-left: 0;
        padding-left: 0;
        border-left: none;
        border-top: 2px solid rgba(108, 92, 231, 0.4);
        padding-top: 15px;
        gap: 10px;
        flex-wrap: nowrap;
    }
    
    .btn-update .btn-update-text,
    .btn-likes .btn-likes-text,
    .btn-matches .btn-matches-text,
    .btn-group-text {
        display: none;
    }
    
    .btn-sm {
        padding: 8px 12px;
        min-width: 36px;
        height: 36px;
        flex-shrink: 0;
        width: auto;
    }
    
    .btn-profile {
        padding: 8px 12px;
        min-height: 36px;
        height: 36px;
        max-width: none;
        /* Same size as other buttons, don't grow */
        flex: 0 0 auto;
        min-width: fit-content;
        width: auto;
        /* Prevent it from taking full width */
        max-width: 180px;
    }
    
    .btn-profile .username {
        font-size: 0.9em;
        max-width: 120px;
        overflow: hidden;
        text-overflow: ellipsis;
        display: block;
    }
    
    .header-actions-right .btn-secondary {
        flex: 0 0 auto;
        width: auto;
        min-width: fit-content;
    }
}

@media (max-width: 480px) {
    .header-actions-right {
        flex-direction: row;
        justify-content: center;
        gap: 8px;
        flex-wrap: nowrap;
    }
    
    .btn-profile {
        flex: 0 0 auto;
        min-width: fit-content;
        max-width: 150px;
        width: auto;
    }
    
    .btn-profile .username {
        max-width: 110px;
        text-align: center;
    }
    
    .header-actions-right .btn-secondary {
        flex: 0 0 auto;
        min-width: fit-content;
        width: auto;
    }
}

.btn-update {
    background: rgba(9, 132, 227, 0.8);
    color: var(--color-white);
    border: 1px solid rgba(9, 132, 227, 0.5);
}

.btn-update:hover:not(:disabled) {
    background: rgba(9, 132, 227, 1);
    border-color: var(--color-secondary);
    transform: translateY(-2px);
}

.btn-likes {
    background: rgba(0, 184, 148, 0.8);
    color: var(--color-white);
    border: 1px solid rgba(0, 184, 148, 0.5);
}

.btn-likes:hover {
    background: rgba(0, 184, 148, 1);
    border-color: var(--color-success);
    transform: translateY(-2px);
}

.btn-matches {
    background: rgba(255, 107, 107, 0.8);
    color: var(--color-white);
    border: 1px solid rgba(255, 107, 107, 0.5);
}

.btn-matches:hover {
    background: rgba(255, 107, 107, 1);
    border-color: var(--color-secondary);
    transform: translateY(-2px);
}

.btn-update:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.btn-likes-text,
.btn-matches-text,
.btn-update-text {
    display: inline;
}

.btn-update.loading span:first-child {
    animation: spin 1s linear infinite;
}

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

/* Update Notification */
.update-notification {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1000;
    max-width: 400px;
    animation: slideInRight 0.3s ease;
}

.update-notification.hidden {
    display: none;
}

@keyframes slideInRight {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.update-notification-content {
    background: rgba(30, 30, 30, 0.95);
    border: 2px solid var(--color-secondary);
    border-radius: 10px;
    padding: 20px;
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: 15px;
}

.update-notification-icon {
    font-size: 2em;
    animation: spin 1s linear infinite;
}

.update-notification-message {
    flex: 1;
}

.update-notification-message strong {
    color: var(--color-white);
    display: block;
    margin-bottom: 5px;
}

.update-notification-message p {
    color: var(--color-light);
    font-size: 0.9em;
    margin: 0;
}

.update-notification.success {
    border-color: var(--color-success);
}

.update-notification.success .update-notification-icon {
    animation: none;
}

.update-notification.error {
    border-color: var(--color-error);
}

.update-notification.error .update-notification-icon {
    animation: none;
}

.main-content {
    flex: 1;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 40px 20px;
    /* Main content is part of main-page scroll, not independent */
    overflow: visible;
    /* Allow all touch gestures */
    touch-action: auto;
    /* Ensure proper z-index */
    position: relative;
    z-index: 1;
    /* Allow content to grow and trigger scroll on parent */
    min-height: 0;
    flex-shrink: 0;
}

/* Profile page specific main-content - already handled by align-items: flex-start */

/* ============================================
   Swipe Container
   ============================================ */

.swipe-container {
    position: relative;
    width: 100%;
    max-width: 400px;
    height: 600px;
    margin: 0 auto;
}

.movie-card {
    position: absolute;
    width: 100%;
    height: 100%;
    background: rgba(30, 30, 30, 0.95);
    border-radius: 20px;
    overflow: hidden;
    box-shadow: var(--shadow-lg);
    border: 2px solid rgba(108, 92, 231, 0.3);
    cursor: grab;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    transition: transform 0.3s ease, opacity 0.3s ease;
    touch-action: none; /* Prevent default touch actions on mobile */
    -webkit-touch-callout: none; /* Disable callout on iOS */
}

.movie-card:active {
    cursor: grabbing;
}

/* Swiping states are now handled by JavaScript transform */
/* These classes are kept for border color changes if needed */
.movie-card.swiping-right {
    border-color: var(--color-success);
}

.movie-card.swiping-left {
    border-color: var(--color-error);
}

.movie-image-container {
    position: relative;
    width: 100%;
    height: 60%;
    overflow: hidden;
    background: var(--color-darker);
}

.movie-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

.movie-card:hover .movie-image {
    transform: scale(1.05);
}

.movie-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 50%;
    background: linear-gradient(to top, rgba(30, 30, 30, 0.95), transparent);
}

.movie-info {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 20px;
    z-index: 10;
}

.movie-badge {
    display: inline-block;
    padding: 4px 12px;
    background: var(--color-primary);
    color: var(--color-white);
    border-radius: 20px;
    font-size: 0.75em;
    font-weight: 600;
    margin-bottom: 10px;
    text-transform: uppercase;
}

.movie-title {
    font-size: 1.8em;
    margin-bottom: 8px;
    color: var(--color-white);
    font-weight: 700;
}

.movie-genre {
    font-size: 0.9em;
    color: var(--color-primary-light);
    margin-bottom: 5px;
}

.movie-year {
    font-size: 0.85em;
    color: rgba(223, 230, 233, 0.7);
    margin-bottom: 10px;
}

.movie-description {
    font-size: 0.9em;
    color: var(--color-light);
    line-height: 1.5;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.swipe-indicators {
    position: absolute;
    top: 30px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 30px;
    z-index: 20;
    pointer-events: none;
}

.swipe-like,
.swipe-dislike {
    padding: 12px 24px;
    border-radius: 30px;
    font-weight: 700;
    font-size: 1.3em;
    opacity: 0;
    transform: scale(0.8);
    transition: all 0.3s ease;
    box-shadow: var(--shadow-lg);
    border: 3px solid transparent;
}

.movie-card.swiping-right .swipe-like {
    opacity: 1;
    transform: scale(1);
    background: var(--color-success);
    color: var(--color-white);
    border-color: rgba(255, 255, 255, 0.3);
    animation: pulse 0.5s ease infinite;
}

.movie-card.swiping-left .swipe-dislike {
    opacity: 1;
    transform: scale(1);
    background: var(--color-error);
    color: var(--color-white);
    border-color: rgba(255, 255, 255, 0.3);
    animation: pulse 0.5s ease infinite;
}

@keyframes pulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
    }
}

.swipe-buttons {
    position: absolute;
    bottom: -80px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 20px;
    margin-top: 30px;
}

.btn-swipe {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: none;
    font-size: 1.5em;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-md);
}

.btn-like {
    background: linear-gradient(135deg, var(--color-success), #00A085);
    color: var(--color-white);
}

.btn-like:hover {
    transform: scale(1.1);
    box-shadow: var(--shadow-glow);
}

.btn-dislike {
    background: linear-gradient(135deg, var(--color-error), #B71C1C);
    color: var(--color-white);
}

.btn-dislike:hover {
    transform: scale(1.1);
    box-shadow: 0 0 20px rgba(214, 48, 49, 0.5);
}

.btn-swipe:active {
    transform: scale(0.95);
}

/* ============================================
   Match Popup
   ============================================ */

.match-popup {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(5px);
    animation: fadeIn 0.3s ease;
    overflow-y: auto;
    padding: 20px;
}

.match-popup.hidden {
    display: none;
}

.match-popup-content {
    background: rgba(30, 30, 30, 0.95);
    border-radius: 20px;
    padding: 40px;
    text-align: center;
    max-width: 600px;
    width: 100%;
    border: 2px solid var(--color-primary);
    box-shadow: var(--shadow-glow);
    animation: slideUp 0.4s ease;
    margin: auto;
    max-height: 90vh;
    overflow-y: auto;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideUp {
    from {
        transform: translateY(50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.match-icon {
    font-size: 4em;
    margin-bottom: 20px;
    animation: bounce 0.6s ease;
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-20px); }
}

.match-popup-content h2 {
    font-size: 2em;
    margin-bottom: 15px;
    color: var(--color-primary);
}

.match-popup-content p {
    font-size: 1.1em;
    margin-bottom: 25px;
    color: var(--color-light);
}

.match-movie-card {
    display: flex;
    gap: 20px;
    margin: 20px 0;
    padding: 15px;
    background: rgba(45, 52, 54, 0.5);
    border-radius: 10px;
    border: 1px solid rgba(108, 92, 231, 0.3);
}

.match-poster {
    width: 120px;
    height: 180px;
    object-fit: cover;
    border-radius: 8px;
    box-shadow: var(--shadow-md);
}

.match-movie-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.match-type {
    display: inline-block;
    padding: 4px 12px;
    background: var(--color-primary);
    color: var(--color-white);
    border-radius: 20px;
    font-size: 0.75em;
    font-weight: 600;
    text-transform: uppercase;
    width: fit-content;
}

.match-movie-info h3 {
    font-size: 1.5em;
    color: var(--color-white);
    margin: 0;
}

.match-genre {
    font-size: 0.9em;
    color: var(--color-primary-light);
    margin: 0;
}

.match-year {
    font-size: 0.85em;
    color: rgba(223, 230, 233, 0.7);
    margin: 0;
}

@media (max-width: 768px) {
    .match-movie-card {
        flex-direction: column;
        align-items: center;
        text-align: center;
    }
    
    .match-poster {
        width: 100px;
        height: 150px;
    }
    
    .match-movie-info {
        align-items: center;
    }
}

/* ============================================
   No Content Message
   ============================================ */

.no-content {
    text-align: center;
    padding: 40px;
}

.no-content.hidden {
    display: none;
}

.no-content-message h2 {
    font-size: 4em;
    margin-bottom: 20px;
}

.no-content-message p {
    font-size: 1.2em;
    color: var(--color-light);
    margin-bottom: 10px;
}

.no-content-message .small {
    font-size: 0.9em;
    color: rgba(223, 230, 233, 0.7);
}

/* ============================================
   Responsive
   ============================================ */

@media (max-width: 768px) {
    .auth-card {
        padding: 30px 20px;
    }

    .swipe-container {
        max-width: 100%;
        height: 500px;
    }

    .header-content {
        flex-direction: column;
        gap: 15px;
    }

    .movie-title {
        font-size: 1.5em;
    }

    .swipe-buttons {
        bottom: -70px;
    }

    .btn-swipe {
        width: 50px;
        height: 50px;
        font-size: 1.2em;
    }
}

@media (max-width: 480px) {
    .swipe-container {
        height: 450px;
    }

    .movie-info {
        padding: 15px;
    }

    .movie-title {
        font-size: 1.3em;
    }

    .movie-description {
        font-size: 0.85em;
    }
}

/* PWA specific styles */
@media (display-mode: standalone) {
    .header {
        /* Add safe area padding for standalone mode */
        padding-top: max(20px, env(safe-area-inset-top));
    }
    
    /* Allow text selection in input fields */
    input, textarea, select {
        user-select: text;
        -webkit-user-select: text;
    }
}

/* Prevent pull-to-refresh in PWA but allow normal scrolling */
@media (display-mode: standalone) {
    body {
        /* Allow scroll but prevent pull-to-refresh bounce */
        overscroll-behavior-y: contain;
        overscroll-behavior-x: none;
    }
}

/* Mobile-specific scroll fixes */
@media (max-width: 768px) {
    .main-page {
        /* On mobile, ensure main page can scroll smoothly */
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
        /* Allow vertical scrolling */
        touch-action: pan-y;
        /* Prevent rubber band effect but allow scroll */
        overscroll-behavior-y: contain;
    }
    
    .header {
        /* On mobile, ensure header allows scroll through */
        touch-action: pan-y;
        /* Don't prevent scroll when touch starts here */
        position: relative;
    }
    
    .main-content {
        /* Ensure smooth scrolling on mobile */
        -webkit-overflow-scrolling: touch;
        /* Allow scroll gestures */
        touch-action: pan-y;
    }
    
    /* Prevent buttons from blocking scroll on mobile */
    .header-actions .btn,
    .header-actions a {
        /* Allow tap but don't block scroll gestures */
        /* Parent pan-y allows scroll to work */
        touch-action: manipulation;
    }
    
    /* Ensure header area doesn't block scroll */
    .header-content {
        touch-action: pan-y;
    }
}

/* ============================================
   Loading State
   ============================================ */

.loading {
    opacity: 0.6;
    pointer-events: none;
}

.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 40px;
    height: 40px;
    margin: -20px 0 0 -20px;
    border: 3px solid var(--color-primary);
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* ============================================
   Profile Page
   ============================================ */

.profile-container {
    max-width: 900px;
    width: 100%;
    margin: 0 auto;
    padding: 60px 40px;
}

.profile-title {
    font-size: 2.5em;
    text-align: center;
    margin-bottom: 50px;
    color: var(--color-white);
    background: linear-gradient(135deg, var(--color-primary), var(--color-secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.profile-section {
    background: rgba(30, 30, 30, 0.95);
    border-radius: 15px;
    padding: 35px;
    margin-bottom: 35px;
    border: 1px solid rgba(108, 92, 231, 0.3);
    box-shadow: var(--shadow-md);
}

.profile-section h3 {
    color: var(--color-light);
    font-size: 1.5em;
    margin-bottom: 25px;
    padding-bottom: 15px;
    border-bottom: 2px solid rgba(108, 92, 231, 0.3);
}

.profile-section h4 {
    color: var(--color-light);
    font-size: 1.2em;
    margin-top: 30px;
    margin-bottom: 20px;
}

.profile-form {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.profile-form .form-group {
    margin-bottom: 0;
}

.profile-form .form-group input,
.profile-form .form-control {
    margin-bottom: 0;
}

.profile-form .btn {
    align-self: flex-start;
    margin-top: 5px;
}

.group-members-list {
    margin-top: 20px;
}

.group-member-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    background: rgba(45, 52, 54, 0.5);
    border-radius: 10px;
    margin-bottom: 15px;
    border: 1px solid rgba(108, 92, 231, 0.2);
    transition: all 0.3s ease;
}

.group-member-item:hover {
    background: rgba(45, 52, 54, 0.7);
    border-color: rgba(108, 92, 231, 0.4);
    transform: translateX(5px);
}

.member-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.member-info strong {
    color: var(--color-light);
    font-size: 1em;
}

.member-username {
    color: rgba(223, 230, 233, 0.6);
    font-size: 0.85em;
}

.member-badge {
    background: rgba(108, 92, 231, 0.3);
    color: var(--color-primary-light);
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.85em;
    font-weight: 600;
}

.no-members {
    color: rgba(223, 230, 233, 0.6);
    text-align: center;
    padding: 20px;
    font-style: italic;
}

.btn-remove {
    background: rgba(214, 48, 49, 0.8);
    color: var(--color-white);
    border: 1px solid rgba(214, 48, 49, 0.5);
}

.btn-remove:hover {
    background: rgba(214, 48, 49, 1);
    border-color: var(--color-error);
    transform: translateY(-2px);
}

@media (max-width: 768px) {
    .header-actions-left {
        min-width: auto;
        width: 100%;
    }
    
    .profile-container {
        padding: 30px 20px;
    }
    
    .profile-title {
        font-size: 2em;
        margin-bottom: 30px;
    }
    
    .profile-section {
        padding: 25px 20px;
        margin-bottom: 25px;
    }
    
    .profile-section h3 {
        font-size: 1.3em;
        margin-bottom: 20px;
    }
    
    .profile-form {
        gap: 15px;
    }
    
    .group-member-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
        padding: 15px;
    }
    
    .member-info {
        width: 100%;
    }
}

/* ============================================
   Matches Page
   ============================================ */

.matches-main {
    /* Remove independent scroll - let main-page handle scrolling */
    overflow: visible;
    /* Allow content to grow naturally */
    flex: 1;
    /* Ensure proper touch handling */
    touch-action: pan-y;
    /* Padding for spacing */
    padding-bottom: 20px;
    /* Ensure content can trigger scroll on parent */
    min-height: 0;
}

.matches-container {
    max-width: 1200px;
    width: 100%;
    margin: 0 auto;
    padding: 40px 20px 60px 20px; /* Extra bottom padding for mobile */
    /* Let content determine height - no fixed min-height */
    min-height: 0;
}

.matches-title {
    font-size: 2.5em;
    text-align: center;
    margin-bottom: 30px;
    color: var(--color-white);
    background: linear-gradient(135deg, var(--color-primary), var(--color-secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.matches-filter {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-bottom: 30px;
    flex-wrap: wrap;
}

.filter-btn {
    padding: 10px 20px;
    background: rgba(45, 52, 54, 0.8);
    color: var(--color-light);
    border: 2px solid rgba(108, 92, 231, 0.3);
    border-radius: 25px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 1em;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.filter-btn:hover {
    background: rgba(45, 52, 54, 1);
    border-color: var(--color-primary);
    transform: translateY(-2px);
}

.filter-btn.active {
    background: var(--color-primary);
    border-color: var(--color-primary);
    color: var(--color-white);
    box-shadow: var(--shadow-md);
}

.filter-btn span {
    font-size: 1.2em;
}

.no-matches-filtered {
    text-align: center;
    padding: 60px 20px;
    background: rgba(45, 52, 54, 0.5);
    border-radius: 15px;
    border: 2px solid rgba(108, 92, 231, 0.3);
    margin-top: 20px;
}

.no-matches-filtered.hidden {
    display: none;
}

.matches-grid.hidden {
    display: none;
}

.no-matches {
    text-align: center;
    padding: 60px 20px;
    background: rgba(45, 52, 54, 0.5);
    border-radius: 15px;
    border: 2px solid rgba(108, 92, 231, 0.3);
}

.no-matches-icon {
    font-size: 5em;
    margin-bottom: 20px;
}

.no-matches h3 {
    font-size: 1.8em;
    color: var(--color-white);
    margin-bottom: 15px;
}

.no-matches p {
    font-size: 1.1em;
    color: var(--color-light);
    margin-bottom: 30px;
    max-width: 500px;
    margin-left: auto;
    margin-right: auto;
}

.matches-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 30px;
    padding: 20px 0;
}

.match-card {
    background: rgba(30, 30, 30, 0.9);
    border-radius: 15px;
    overflow: hidden;
    border: 2px solid rgba(108, 92, 231, 0.3);
    transition: all 0.3s ease;
    box-shadow: var(--shadow-md);
    position: relative;
    cursor: pointer;
}

.match-card:hover {
    transform: translateY(-5px);
    box-shadow: var(--shadow-lg);
    border-color: var(--color-primary);
}

.match-card.clickable {
    cursor: pointer;
}

.match-remove-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 35px;
    height: 35px;
    border-radius: 50%;
    background: rgba(214, 48, 49, 0.9);
    border: 2px solid rgba(255, 255, 255, 0.3);
    color: var(--color-white);
    font-size: 1.8em;
    line-height: 1;
    cursor: pointer;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    box-shadow: var(--shadow-md);
}

.match-remove-btn:hover:not(:disabled) {
    background: var(--color-error);
    transform: scale(1.1);
    box-shadow: var(--shadow-lg);
}

.match-remove-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.match-remove-btn span {
    display: block;
    margin-top: -2px;
    font-weight: bold;
    line-height: 0.8;
}

.match-card-poster {
    width: 100%;
    height: 400px;
    overflow: hidden;
    background: var(--color-dark);
    position: relative;
}

.match-card-poster img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.match-card-info {
    padding: 20px;
}

.match-badge {
    display: inline-block;
    padding: 4px 12px;
    background: var(--color-primary);
    color: var(--color-white);
    border-radius: 20px;
    font-size: 0.75em;
    font-weight: 600;
    text-transform: uppercase;
    margin-bottom: 10px;
}

.match-card-title {
    font-size: 1.5em;
    color: var(--color-white);
    margin-bottom: 8px;
    font-weight: 700;
}

.match-card-genre {
    font-size: 0.9em;
    color: var(--color-primary-light);
    margin-bottom: 5px;
}

.match-card-year {
    font-size: 0.85em;
    color: rgba(223, 230, 233, 0.7);
    margin-bottom: 10px;
}

.match-card-description {
    font-size: 0.9em;
    color: var(--color-light);
    line-height: 1.5;
    margin-bottom: 15px;
    min-height: 60px;
    word-wrap: break-word;
    overflow-wrap: break-word;
    white-space: normal;
}

.match-card-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 15px;
    border-top: 1px solid rgba(108, 92, 231, 0.2);
}

.match-users-count {
    font-size: 0.9em;
    color: var(--color-primary-light);
    font-weight: 600;
}

.match-date {
    font-size: 0.85em;
    color: rgba(223, 230, 233, 0.6);
}

@media (max-width: 768px) {
    .matches-main {
        padding-top: 10px; /* Prevent header from cutting first card */
        /* Ensure scroll works on mobile */
        overflow: visible;
        touch-action: pan-y;
    }
    
    .matches-container {
        padding: 20px 15px 40px 15px; /* Reduced padding on mobile, extra bottom */
        /* Ensure container doesn't block scroll */
        min-height: 0;
    }
    
    .matches-title {
        font-size: 1.8em;
        margin-bottom: 20px;
        padding-top: 10px; /* Extra space from header */
    }
    
    .matches-grid {
        grid-template-columns: 1fr;
        gap: 20px;
        padding-top: 10px; /* Extra space to prevent cutting */
    }
    
    .match-card-poster {
        height: 350px;
    }
    
    .match-card-description {
        font-size: 0.85em;
        min-height: 50px;
        line-height: 1.4;
        display: -webkit-box;
        -webkit-line-clamp: 4;
        -webkit-box-orient: vertical;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    
    /* Critical fix: Ensure main-page can scroll when touch starts on header */
    .main-page {
        /* Main page is the scroll container */
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
        touch-action: pan-y;
        /* Ensure it can grow beyond viewport */
        height: auto;
        min-height: 100vh;
    }
    
    /* Ensure header doesn't block scroll */
    .header {
        touch-action: pan-y;
        /* Allow scroll gestures to pass through */
        position: relative;
    }
    
    /* Ensure matches content doesn't create scroll conflicts */
    .matches-main {
        /* No independent scroll - parent handles it */
        overflow: visible;
        touch-action: pan-y;
    }
}

