/* Reset & Global Styles */
*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    font-size: 16px;
}

body {
    background-color: #e9ecef;
    font-family: 'Segoe UI', Arial, sans-serif;
    margin: 0;
    padding: 0;
    /* Gunakan dynamic viewport height untuk iOS */
    height: 100dvh;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Override container if needed */
main.container {
    padding: 0;
    height: 100dvh;
    overflow: hidden;
    max-height: 100dvh;
}

/* ==================== DESKTOP (≥1025px) ==================== */
@media (min-width: 1025px) {
    body {
        margin: 0;
        padding: 0;
        width: 100vw;
        height: 100vh;
        display: flex;
        align-items: center;
        justify-content: center;
        overflow: hidden;
    }
    
    main.container {
        position: fixed;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        width: 100%;
        height: auto;
        padding: 20px;
        margin: 0;
        display: block;
        box-sizing: border-box;
    }
    
    main.container > .container {
        width: 100%;
        max-width: none;
        padding: 0;
        margin: 0;
        display: block;
    }
    
    /* Fix footer position for desktop */
    footer {
        position: fixed !important;
        bottom: 10px !important;
        left: 50% !important;
        transform: translateX(-50%) !important;
        width: auto !important;
        margin: 0 !important;
        z-index: 1000 !important;
    }
    
    footer .footer-text {
        font-size: 12px !important;
        margin: 0 !important;
    }
}

/* ==================== TABLET LANDSCAPE (769px - 1024px) ==================== */
@media (min-width: 769px) and (max-width: 1024px) {
    body {
        margin: 0;
        padding: 0;
        width: 100vw;
        height: 100vh;
        display: flex;
        align-items: center;
        justify-content: center;
        overflow: hidden;
        background-color: #e9ecef;
    }
    
    main.container {
        position: fixed;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        width: 95%;
        max-width: 900px;
        height: auto;
        padding: 15px;
        margin: 0;
        display: block;
        box-sizing: border-box;
    }
    
    main.container > .container {
        width: 100%;
        max-width: none;
        padding: 0;
        margin: 0;
        display: block;
    }
    
    /* Login container untuk tablet landscape */
    .login-container {
        width: 100%;
        max-width: 100%;
        height: 480px;
        margin: 0 auto;
        box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
        border-radius: 10px;
        overflow: hidden;
    }
    
    /* Form container untuk tablet landscape */
    .login-form-container {
        padding: 35px 25px;
        border-radius: 10px 0 0 10px;
    }
    
    /* Ukuran font untuk tablet landscape */
    .welcome-back {
        font-size: 21px;
        gap: 5px;
    }
    
    .user-name-display {
        font-size: 13px;
    }
    
    /* Form elements untuk tablet landscape */
    .form-control {
        padding: 11px 13px;
        font-size: 14px;
    }
    
    .form-group {
        margin-bottom: 16px;
    }
    
    .form-group label {
        font-size: 13px;
        margin-bottom: 7px;
    }
    
    .btn-primary {
        padding: 11px;
        font-size: 15px;
    }
    
    /* Social login untuk tablet landscape */
    .social-login {
        margin-top: 25px;
    }
    
    .social-login-text {
        font-size: 13px;
    }
    
    .btn-social {
        width: 38px;
        height: 38px;
        font-size: 17px;
    }
    
    /* Logo untuk tablet landscape */
    .logo-desktop {
        width: 70px;
        height: auto;
        top: 15px;
        right: 15px;
    }
    
    /* Footer untuk tablet landscape */
    footer {
        position: fixed !important;
        bottom: 8px !important;
        left: 50% !important;
        transform: translateX(-50%) !important;
        width: auto !important;
        margin: 0 !important;
        z-index: 1000 !important;
    }
    
    footer .footer-text {
        font-size: 11px !important;
        margin: 0 !important;
    }
}

/* ==================== TABLET PORTRAIT (769px - 1024px) ==================== */
@media (min-width: 769px) and (max-width: 1024px) and (orientation: portrait) {
    .login-container {
        height: 520px;
        max-width: 85%;
    }
    
    .login-form-container {
        padding: 40px 30px;
    }
    
    .welcome-back {
        font-size: 22px;
    }
    
    /* Sedikit lebih compact untuk portrait */
    .form-group {
        margin-bottom: 18px;
    }
    
    .social-login {
        margin-top: 28px;
    }
    
    .form-control {
        padding: 12px 14px;
    }
}

/* ==================== SMALL TABLET (769px - 834px) ==================== */
@media (min-width: 769px) and (max-width: 834px) {
    .login-container {
        height: 500px;
        max-width: 92%;
    }
    
    .login-form-container {
        padding: 35px 25px;
    }
    
    .welcome-back {
        font-size: 20px;
    }
    
    .form-control {
        padding: 10px 12px;
        font-size: 13px;
    }
    
    .btn-primary {
        padding: 10px;
        font-size: 14px;
    }
}

/* ==================== MEDIUM TABLET (835px - 900px) ==================== */
@media (min-width: 835px) and (max-width: 900px) {
    .login-container {
        height: 530px;
    }
    
    .login-form-container {
        padding: 40px 30px;
    }
}

/* ==================== LARGE TABLET (901px - 1024px) ==================== */
@media (min-width: 901px) and (max-width: 1024px) {
    .login-container {
        height: 540px;
        max-width: 88%;
    }
    
    .login-form-container {
        padding: 45px 35px;
    }
}

/* Remove nested container padding/margin for login page - mobile only */
@media (max-width: 768px) {
    /* Override Bootstrap container completely for login page */
    body main.container {
        padding: 0 !important;
        margin: 0 !important;
        max-width: none !important;
        width: 100vw !important;
        height: 100dvh !important;
        overflow: hidden !important;
    }
    
    body main.container > .container {
        padding: 0 !important;
        margin: 0 !important;
        max-width: none !important;
        width: 100% !important;
        height: 100% !important;
        display: block !important;
    }
    
    /* Hide the message div that comes from header.php */
    body main.container > .container > .message {
        display: none !important;
    }
    
    /* Ensure mobile login container takes full space */
    .mobile-only {
        position: absolute !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        margin: 0 !important;
        padding: 0 !important;
        width: 100vw !important;
        height: 100dvh !important;
    }
}

/* Prevent any scrolling on desktop and tablet */
@media (min-width: 769px) {
    html, body {
        overflow: hidden;
        max-height: 100vh;
    }
}

/* Allow scrolling on mobile if needed */
@media (max-width: 768px) {
    html, body {
        overflow: visible;
        max-height: none;
    }
}

/* ==================== DESKTOP & TABLET (≥769px) ==================== */
.login-container {
    display: flex;
    flex-direction: row;
    width: 100%;
    max-width: 1000px;
    height: 560px;
    margin: 0 auto;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
    border-radius: 12px;
    overflow: hidden;
    align-items: stretch;
}

.login-form-container {
    flex: 0.5;
    padding: 60px 40px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    background-color: rgba(255, 255, 255, 0.95);
    border-radius: 12px 0 0 12px;
    height: 100%;
}

.login-image {
    flex: 0.5;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    height: 100%;
    border-radius: 0 12px 12px 0;
    position: relative;
}

.logo-desktop {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 80px;
    height: 80px;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    z-index: 10;
}

/* ==================== MOBILE & SMALL SCREENS (<769px) ==================== */
@media (max-width: 768px) {
    body {
        background-color: #f5f5f5;
        height: 100dvh;
    }

    .login-container {
        flex-direction: column;
        width: 100%;
        height: 100dvh;
        max-width: none;
        border-radius: 0;
        box-shadow: none;
    }

    .login-image {
        height: 50dvh;
        border-radius: 0;
        background-position: center center;
        display: flex;
        justify-content: center;
        align-items: center;
        position: relative;
    }

    .mobile-logo {
        position: absolute !important;
        top: 10px !important;
        right: 10px !important;
        width: 70px !important;
        height: 70px !important;
        background-size: contain !important;
        background-repeat: no-repeat !important;
        background-position: center !important;
        z-index: 999 !important;
    }

    .login-form-container {
        flex: 1;
        padding: 25px 20px 30px 20px; /* Added bottom padding */
        background-color: #fff;
        border-radius: 24px 24px 0 0;
        margin-top: -30px;
        display: flex;
        flex-direction: column;
        justify-content: flex-start;
        overflow-y: auto; /* Allow scrolling if needed */
        overflow-x: hidden;
        position: relative;
        z-index: 10;
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.08);
        min-height: 50dvh; /* Changed from max-height to min-height */
    }

    .welcome-back {
        font-size: 20px;
        margin-bottom: 10px;
        gap: 4px;
    }

    .form-control {
        font-size: 16px; /* Mencegah zoom di iOS */
        padding: 12px 14px;
    }

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

    .btn-primary {
        padding: 12px;
        font-size: 15px;
        margin-top: 10px;
        margin-bottom: 15px; /* Ensure space below button */
        position: relative;
        z-index: 100; /* Ensure button is above other elements */
    }

    .social-login {
        margin-top: 15px;
        margin-bottom: 20px; /* Add bottom margin */
    }

    footer {
        display: none !important;
    }
}

/* ==================== EXTRA SMALL MOBILE (<480px) ==================== */
@media (max-width: 480px) {
    .login-form-container {
        padding: 20px 16px 25px 16px; /* Added bottom padding */
        margin-top: -25px;
        min-height: 55dvh; /* Ensure enough height */
    }

    .welcome-back {
        font-size: 18px;
    }

    .form-control {
        padding: 11px 12px;
    }

    .btn-primary {
        padding: 11px;
        font-size: 14px;
        margin-top: 8px;
        margin-bottom: 12px; /* Ensure space below button */
        position: relative;
        z-index: 100;
    }

    .social-buttons {
        gap: 12px;
    }

    .btn-social {
        width: 36px;
        height: 36px;
        font-size: 16px;
    }
}

/* ==================== COMMON STYLES (APPLY TO ALL) ==================== */
.welcome-back {
    font-size: 24px;
    font-weight: 600;
    margin-bottom: 5px;
    color: #333;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.user-name-display {
    font-size: 14px;
    font-weight: 400;
    color: #666;
    text-align: center;
    min-height: 1.2em;
}

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

.form-group.form-check {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 15px;
    background-color: #f8f9fa;
    padding: 10px 15px;
    border-radius: 8px;
    transition: all 0.3s ease;
}

.form-check-input {
    appearance: none;
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    border: 2px solid #007bff;
    border-radius: 4px;
    margin-right: 10px;
    position: relative;
    cursor: pointer;
    transition: all 0.2s ease;
}

.form-check-input:checked {
    background-color: #007bff;
}

.form-check-input:checked::after {
    content: '✓';
    position: absolute;
    color: white;
    font-size: 12px;
    top: -2px;
    left: 3px;
}

.form-check-label {
    font-size: 14px;
    color: #495057;
    font-weight: 500;
    margin-bottom: 0;
    cursor: pointer;
    transition: color 0.2s ease;
}

.form-group label {
    font-weight: 500;
    margin-bottom: 8px;
    margin-top: 8px;
    display: block;
    color: #333;
    font-size: 14px;
}

.form-control {
    padding: 12px 15px;
    border: 1px solid #ddd;
    border-radius: 8px;
    width: 100%;
    font-size: 14px;
    transition: all 0.3s ease;
}

.form-control:focus {
    border-color: #4a6cf7;
    box-shadow: 0 0 0 3px rgba(74, 108, 247, 0.1);
    outline: none;
}

.btn-primary {
    background-color: #1e293b;
    border: none;
    color: white;
    padding: 12px;
    font-weight: 600;
    border-radius: 8px;
    width: 100%;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 16px;
}

.btn-primary:hover {
    background-color: #0f172a;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(30, 41, 59, 0.2);
}

.social-login {
    margin-top: 30px;
    text-align: center;
}

.social-login-text {
    color: #666;
    margin-bottom: 15px;
    font-size: 14px;
    position: relative;
    display: inline-block;
    padding: 0 20px;
}

.social-login-text::before,
.social-login-text::after {
    content: "";
    position: absolute;
    height: 1px;
    background-color: #ddd;
    top: 50%;
    width: 35%;
}

.social-login-text::before {
    left: 0;
    transform: translateY(-50%);
}

.social-login-text::after {
    right: 0;
    transform: translateY(-50%);
}

.social-buttons {
    display: flex;
    justify-content: center;
    gap: 15px;
}

.btn-social {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 8px;
    border: 1px solid #ddd;
    background-color: white;
    transition: all 0.3s ease;
    color: #333;
    text-decoration: none;
    font-size: 18px;
}

.btn-social:hover {
    background-color: #f8f9fa;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
}

.alert {
    padding: 12px 15px;
    border-radius: 6px;
    margin-bottom: 20px;
    font-size: 14px;
}

.alert-danger {
    background-color: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

/* Visibility Helpers */
.desktop-only {
    display: flex;
}

.mobile-only {
    display: none;
}

@media (max-width: 768px) {
    .desktop-only {
        display: none !important;
    }

    .mobile-only {
        display: flex !important;
        flex-direction: column !important;
        width: 100vw !important;
        height: 100dvh !important;
        position: absolute !important;
        top: 0 !important;
        left: 0 !important;
        z-index: 1000 !important;
    }
}

/* ==================== TABLET DENSITY TINGGI (Pixel Ratio > 1) ==================== */
@media (min-width: 769px) and (max-width: 1024px) and (-webkit-min-device-pixel-ratio: 2) {
    .login-container {
        box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
    }
    
    .form-control {
        border-width: 1.5px;
    }
    
    .btn-primary {
        font-weight: 600;
    }
}

/* ==================== TABLET DARK MODE SUPPORT ==================== */
@media (min-width: 769px) and (max-width: 1024px) and (prefers-color-scheme: dark) {
    .login-form-container {
        background-color: rgba(30, 30, 30, 0.95);
    }
    
    .welcome-back {
        color: #f0f0f0;
    }
    
    .user-name-display {
        color: #ccc;
    }
    
    .form-control {
        background-color: #2d2d2d;
        border-color: #444;
        color: #f0f0f0;
    }
    
    .form-control:focus {
        border-color: #4a6cf7;
        box-shadow: 0 0 0 3px rgba(74, 108, 247, 0.2);
    }
    
    .form-group.form-check {
        background-color: #2d2d2d;
    }
    
    .form-check-label {
        color: #ccc;
    }
}

/* ==================== OVERRIDE BOOTSTRAP CONTAINER FOR TABLET ==================== */
@media (min-width: 769px) and (max-width: 1024px) {
    /* Override Bootstrap container untuk tablet */
    body main.container {
        padding: 0 !important;
        margin: 0 !important;
        max-width: none !important;
        width: 100vw !important;
        height: 100vh !important;
        overflow: hidden !important;
    }
    
    body main.container > .container {
        padding: 0 !important;
        margin: 0 !important;
        max-width: none !important;
        width: 100% !important;
        height: 100% !important;
        display: block !important;
    }
    
    /* Hide the message div that comes from header.php */
    body main.container > .container > .message {
        display: none !important;
    }
    
    /* Pastikan mobile-only tetap tersembunyi di tablet */
    .mobile-only {
        display: none !important;
    }
}

/* ==================== FIX FOR VERY SMALL TABLET HEIGHTS ==================== */
@media (min-width: 769px) and (max-width: 1024px) and (max-height: 700px) {
    .login-container {
        height: 420px;
    }
    
    .login-form-container {
        padding: 25px 20px;
    }
    
    .form-group {
        margin-bottom: 12px;
    }
    
    .social-login {
        margin-top: 20px;
    }
    
    .welcome-back {
        font-size: 20px;
        margin-bottom: 8px;
    }
}

/* ==================== FIX FOR VERY LARGE TABLET HEIGHTS ==================== */
@media (min-width: 769px) and (max-width: 1024px) and (min-height: 1000px) {
    .login-container {
        height: 580px;
    }
    
    .login-form-container {
        padding: 50px 40px;
    }
}