/* ========== RESET & VARIÁVEIS ========== */
:root {
    --bg-dark: #111;
    --card-bg: rgba(0,0,0,0.65);
    --text: #f0f0f0;
    --text-muted: #c9c9c9;
    --danger: #ff4757;
    --success: #2ed573;
    --accent: #e50914;
    --input-bg: #ffffff;
    --input-text: #111;
    --input-border: #70706f;
    --modal-text: #333;
    --safe-area-bottom: env(safe-area-inset-bottom, 0px);
    --vh: 1vh; /* Fallback for viewport height */
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

/* ========== BASE LAYOUT ========== */
html {
    height: 100%;
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
    overflow-x: hidden;
}

body {    
    min-height: 100vh;
    min-height: calc(var(--vh, 1vh) * 100);
    background-image: url('../images/background-mod.png');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    background-attachment: fixed;
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
    position: relative;
    -webkit-overflow-scrolling: touch;
    overflow-x: hidden;
    margin: 0;
    padding: 0;
}

/* ========== BACKGROUND FIXES ========== */
/* Ensure background image is always visible and fixed */
body {
    background-image: url('../images/background-mod.png') !important;
    background-size: cover !important;
    background-position: center !important;
    background-repeat: no-repeat !important;
    background-attachment: fixed !important;
    -webkit-background-size: cover !important;
    -moz-background-size: cover !important;
    -o-background-size: cover !important;
}

/* Fallback for browsers that don't support background-attachment: fixed */
@supports not (background-attachment: fixed) {
    body {
        background-attachment: scroll !important;
    }
}

/* iOS Safari specific background fix */
@supports (-webkit-touch-callout: none) {
    body {
        background-attachment: scroll !important;
        background-size: cover !important;
        background-position: center !important;
        background-repeat: no-repeat !important;
        -webkit-background-size: cover !important;
        position: relative;
        min-height: -webkit-fill-available;
        min-height: calc(var(--vh, 1vh) * 100);
        -webkit-overflow-scrolling: touch;
        height: auto;
        overflow-y: auto;
    }
    
    input {
        font-size: 16px !important;
    }
    
    .modal-content {
        margin-bottom: calc(var(--safe-area-bottom) + 20px);
        max-height: calc(var(--vh, 1vh) * 85);
    }
    
    .auth-container {
        min-height: -webkit-fill-available;
        min-height: calc(var(--vh, 1vh) * 100);
        -webkit-overflow-scrolling: touch;
        flex-direction: column;
        height: auto;
        overflow-y: auto;
        align-items: flex-start;
        justify-content: flex-start;
        background: transparent;
    }
    
    .auth-card {
        flex-shrink: 0;
        height: auto;
        min-height: auto;
        margin: 20px auto;
    }
}

/* ========== CONTAINER & CARD ========== */
.auth-container {
    min-height: 100vh;
    min-height: calc(var(--vh, 1vh) * 100);
    padding: 16px;
    padding-bottom: calc(var(--safe-area-bottom) + 16px);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    position: relative;
    flex-direction: column;
    height: auto;
    background: transparent;
}

.auth-card {
    width: 100%;
    max-width: 460px;
    background: var(--card-bg);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 16px;
    padding: 24px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.3);
    margin: 20px auto;
    flex-shrink: 0;
    height: auto;
    min-height: auto;
}

/* ========== HEADER ========== */
.auth-header {
    text-align: center;
    margin-bottom: 24px;
}

.auth-header h1 {
    font-size: 1.75rem;
    margin-bottom: 8px;
    color: var(--text);
}

.auth-header p {
    color: var(--text-muted);
    font-size: 0.95rem;
}

/* ========== ALERTS ========== */
.alert {
    background: rgba(255,71,87,0.1);
    border: 1px solid rgba(255,71,87,0.3);
    color: var(--danger);
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 20px;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 10px;
    animation: slideIn 0.3s ease;
}

.alert::before {
    content: "⚠";
    font-size: 1.2rem;
}

/* ========== FORM ========== */
.auth-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-bottom: 20px;
    height: auto;
    min-height: auto;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 8px;
    height: auto;
    min-height: auto;
}

.form-group label {
    font-size: 0.95rem;
    color: var(--text);
    font-weight: 500;
}

.form-group input {
    width: 100%;
    padding: 12px 14px;
    background: var(--input-bg);
    color: var(--input-text);
    border: 1.5px solid var(--input-border);
    border-radius: 8px;
    font-size: 16px;
    font-weight: 500;
    transition: all 0.2s ease;
    -webkit-appearance: none;
    appearance: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.form-group input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(229,9,20,0.1);
}

.form-group input::placeholder {
    color: rgba(0,0,0,0.4);
}

.form-group input.error {
    border-color: var(--danger);
}

/* ========== ERROR STATES ========== */
.field-error,
.email-match-error,
.password-match-error,
.cpf-validation-error {
    color: var(--danger);
    font-size: 0.8rem;
    margin-top: 4px;
    display: none;
    animation: fadeIn 0.3s ease;
}

.field-error.visible,
.email-match-error.visible,
.password-match-error.visible,
.cpf-validation-error.visible {
    display: block;
}

/* ========== TERMS CHECKBOX ========== */
.terms-container {
    margin-top: 8px;
    padding: 12px;
    background: rgba(255,255,255,0.05);
    border-radius: 8px;
}

.terms-label {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

.terms-checkbox {
    width: 20px;
    height: 20px;
    min-width: 20px;
    margin-top: 2px;
    accent-color: var(--accent);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.terms-text {
    font-size: 0.85rem;
    line-height: 1.4;
    color: var(--text);
}

.terms-link {
    color: var(--accent);
    text-decoration: underline;
    font-weight: 600;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    padding: 2px 0;
}

/* ========== BUTTONS ========== */
.btn-primary {
    width: 100%;
    padding: 14px 20px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-top: 8px;
    margin-bottom: 16px;
    -webkit-tap-highlight-color: transparent;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none; 
    touch-action: manipulation;    
}



/* ========== AUTH LINKS ========== */
.auth-links {
    text-align: center;
    margin-top: 16px;
    margin-bottom: 20px;
    padding-bottom: 20px;
}

.auth-links a {
    color: var(--text-muted);
    font-size: 0.9rem;
    text-decoration: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    padding: 4px 0;
}

.auth-links a:hover {
    text-decoration: underline;
}

/* ========== MODAL ========== */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.8);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 9999;
    padding: 16px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.modal.active {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    animation: fadeIn 0.3s ease;
}

.modal-content {
    background: white;
    border-radius: 12px;
    width: 100%;
    max-width: 600px;
    margin: 40px auto;
    max-height: 85vh;
    max-height: calc(var(--vh, 1vh) * 85);
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    animation: slideUp 0.3s ease;
}

.modal-header {
    padding: 20px;
    border-bottom: 1px solid #eee;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    background: white;
    border-radius: 12px 12px 0 0;
    z-index: 10;
}

.modal-header h2 {
    font-size: 1.25rem;
    color: var(--modal-text);
    margin: 0;
}

.close-modal {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #f5f5f5;
    border: none;
    font-size: 1.5rem;
    color: #666;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.close-modal:hover {
    background: #e0e0e0;
    color: var(--modal-text);
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    color: var(--modal-text);
    flex: 1;
}

.modal-body h3 {
    color: var(--modal-text);
    margin: 20px 0 10px;
    font-size: 1.1rem;
}

.modal-body p {
    margin-bottom: 12px;
    line-height: 1.6;
}

.modal-body ul {
    margin: 10px 0 10px 20px;
}

.modal-body li {
    margin-bottom: 8px;
}

.modal-footer {
    padding: 20px;
    border-top: 1px solid #eee;
    position: sticky;
    bottom: 0;
    background: white;
    border-radius: 0 0 12px 12px;
}

#accept-terms {
    width: 100%;
    padding: 12px 20px;
    background: #ccc;
    color: #666;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: not-allowed;
    transition: all 0.2s ease;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

#accept-terms.active {
    background: var(--accent);
    color: white;
    cursor: pointer;
}

#accept-terms.active:hover {
    background: #c70813;
}

/* Force accept-terms button to always be active and visible */
#accept-terms {
    background: var(--accent) !important;
    color: white !important;
    cursor: pointer !important;
    opacity: 1 !important;
    visibility: visible !important;
    transition: all 0.2s ease !important;
}

#accept-terms:hover {
    background: #c70813 !important;
    transform: translateY(-1px) !important;
    box-shadow: 0 4px 12px rgba(229,9,20,0.3) !important;
}

/* Force submit button to always be active and visible */
#submit-btn {
    background: var(--accent) !important;
    color: white !important;
    cursor: pointer !important;
    opacity: 1 !important;
    visibility: visible !important;
    transition: all 0.2s ease !important;
}

#submit-btn:hover {
    background: #c70813 !important;
    transform: translateY(-1px) !important;
    box-shadow: 0 4px 12px rgba(229,9,20,0.3) !important;
}

#submit-btn:disabled {
    opacity: 0.6 !important;
    cursor: not-allowed !important;
    background: #999 !important;
    transform: none !important;
    box-shadow: none !important;
    pointer-events: none !important;
}

/* ========== ANIMATIONS ========== */
@keyframes slideIn {
    from { transform: translateY(-10px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideUp {
    from { transform: translateY(50px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* ========== MOBILE OPTIMIZATIONS ========== */
@media (max-width: 480px) {
    .auth-container {
        padding: 12px;
        align-items: flex-start;
        padding-top: 20px;
        padding-bottom: 20px;
        overflow-y: auto;
        min-height: 100vh;
        min-height: calc(var(--vh, 1vh) * 100);
        -webkit-overflow-scrolling: touch;
        flex-direction: column;
        height: auto;
        justify-content: flex-start;
        background: transparent;
    }
    
    .auth-card {
        padding: 20px;
        border-radius: 12px;
        margin: 10px auto;
        max-width: 100%;
        flex-shrink: 0;
        height: auto;
        min-height: auto;
    }
    
    .auth-header h1 {
        font-size: 1.5rem;
    }
    
    .form-group input {
        padding: 14px;
        font-size: 16px;
    }
    
    .modal {
        padding: 0;
    }
    
    .modal-content {
        margin: 0;
        max-height: 100vh;
        max-height: calc(var(--vh, 1vh) * 100);
        border-radius: 0;
    }
    
    .modal-header {
        border-radius: 0;
    }
    
    .modal-footer {
        border-radius: 0;
        padding-bottom: calc(var(--safe-area-bottom) + 20px);
    }
    
    .modal-body {
        -webkit-overflow-scrolling: touch;
        overflow-y: auto;
    }
}

/* Extra small screens */
@media (max-width: 360px) {
    .auth-container {
        padding: 8px;
        padding-top: 15px;
        padding-bottom: 15px;
        flex-direction: column;
        height: auto;
        justify-content: flex-start;
        background: transparent;
    }
    
    .auth-card {
        padding: 16px;
        margin: 5px auto;
        flex-shrink: 0;
        height: auto;
        min-height: auto;
    }
    
    .auth-header h1 {
        font-size: 1.3rem;
    }
    
    .form-group input {
        padding: 12px;
        font-size: 16px;
    }
    
    .btn-primary {
        padding: 12px 16px;
        font-size: 0.95rem;
    }
}

/* Small heights (landscape mobile) */
@media (max-height: 600px) {
    .auth-container {
        align-items: flex-start;
        padding-top: 10px;
        padding-bottom: 10px;
        overflow-y: auto;
        min-height: auto;
        flex-direction: column;
        height: auto;
        justify-content: flex-start;
        background: transparent;
    }
    
    .auth-header {
        margin-bottom: 16px;
    }
    
    .auth-form {
        gap: 12px;
    }
    
    .auth-card {
        margin: 5px auto;
        padding: 16px;
        flex-shrink: 0;
        height: auto;
        min-height: auto;
    }
}

/* Android Keyboard Compensation */
@media (max-height: 500px) {
    .auth-container {
        min-height: auto;
        overflow-y: auto;
        padding-top: 5px;
        padding-bottom: 5px;
        flex-direction: column;
        height: auto;
        justify-content: flex-start;
        background: transparent;
    }
    
    .auth-card {
        margin: 5px auto;
        padding: 12px;
        flex-shrink: 0;
        height: auto;
        min-height: auto;
    }
    
    .form-group {
        gap: 4px;
    }
    
    .form-group input {
        padding: 10px 12px;
    }
}

/* Android specific fixes */
@media screen and (-webkit-min-device-pixel-ratio: 0) {
    .auth-container {
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
        height: auto !important;
        min-height: 100vh !important;
        display: flex !important;
        flex-direction: column !important;
        align-items: flex-start !important;
        justify-content: flex-start !important;
        background: transparent !important;
    }
    
    .auth-card {
        flex-shrink: 0 !important;
        margin: 20px auto !important;
        width: 100% !important;
        max-width: 460px !important;
        height: auto !important;
        min-height: auto !important;
    }
    
    body {
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
        height: auto !important;
        background-attachment: fixed !important;
        background-size: cover !important;
        background-position: center !important;
        background-repeat: no-repeat !important;
    }
    
    html {
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
        height: auto !important;
    }
}

/* Focus visible for accessibility */
:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}