/**
 * Kangra Hub - Mobile Responsive Styles
 * Comprehensive mobile-first responsive CSS
 * Fixes: zoomed-out layout, navbar toggle visibility, chatbot, and all section responsiveness
 */

/* ===== GLOBAL MOBILE FIXES ===== */

/* Prevent horizontal overflow on all devices */
html,
body {
    overflow-x: hidden;
    width: 100%;
    scroll-behavior: smooth;
}

/* Ensure proper box sizing */
*,
*::before,
*::after {
    box-sizing: border-box;
}

/* Container responsiveness */
.container {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding-left: 1rem;
    padding-right: 1rem;
}

/* ===== HAMBURGER / TOGGLE BUTTON VISIBILITY FIX ===== */

/* Base hamburger styles - Hidden on desktop */
.hamburger {
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 5px;
    width: 44px;
    height: 44px;
    padding: 8px;
    background: transparent;
    border: 2px solid transparent;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    z-index: 9999;
}

.hamburger span {
    width: 24px;
    height: 3px;
    border-radius: 2px;
    transition: all 0.3s ease;
    background-color: var(--text-primary, #333);
}

/* Hero section (top of page) - White for visibility on dark hero */
.navbar:not(.scrolled) .hamburger span {
    background-color: #fff;
}

/* After scroll - uses theme color */
.navbar.scrolled .hamburger span {
    background-color: var(--text-primary, #333);
}

/* Dark mode hamburger */
[data-theme="dark"] .hamburger span {
    background-color: #fff;
}



/* ===== MOBILE DRAWER ===== */

.mobile-drawer {
    position: fixed;
    top: 0;
    right: -100%;
    width: 100%;
    max-width: 320px;
    height: 100vh;
    background: linear-gradient(180deg, #1a1a2e 0%, #16213e 100%);
    padding: 80px 24px 24px;
    transition: right 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1000;
    overflow-y: auto;
    box-shadow: -10px 0 40px rgba(0, 0, 0, 0.3);
}

.mobile-drawer.active {
    right: 0;
}

.mobile-drawer a {
    display: block;
    padding: 14px 16px;
    color: #e0e0e0;
    text-decoration: none;
    font-size: 1rem;
    font-weight: 500;
    border-radius: 8px;
    margin-bottom: 4px;
    transition: all 0.2s ease;
}

.mobile-drawer a:hover,
.mobile-drawer a.active {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

.mobile-drawer .close-btn {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    border-radius: 50%;
    color: #fff;
    font-size: 1.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.mobile-drawer .close-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.nav-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    z-index: 999;
}

.nav-overlay.active {
    opacity: 1;
    visibility: visible;
}

/* ===== CHATBOT - Do not override visibility, let JS control ===== */
/* Chatbot positioning only - no visibility overrides */
.chatbot-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
}

/* Chatbot Mobile Fullscreen Fix */
@media (max-width: 768px) {
    #chatbot-window.open {
        position: fixed;
        inset: 0;
        width: 100vw !important;
        height: 100vh !important;
        max-width: none !important;
        max-height: none !important;
        bottom: 0 !important;
        right: 0 !important;
        border-radius: 0 !important;
        z-index: 99999 !important;
        display: flex;
        flex-direction: column;
    }

    #chatbot-window.open .chatbot-messages {
        flex: 1;
        height: auto;
    }
}

/* ===== TABLET BREAKPOINT (768px - 1024px) ===== */

@media (max-width: 1024px) {

    /* Grid adjustments */
    .grid-cols-3 {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    .grid-cols-4 {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    /* Section spacing */
    .section {
        padding: 3rem 0;
    }

    /* Typography scaling */
    .hero-title {
        font-size: 2.5rem !important;
    }

    .section-title {
        font-size: 2rem !important;
    }
}

/* ===== MOBILE/TABLET BREAKPOINT (max-width: 1024px) ===== */

@media (max-width: 1024px) {

    /* Show hamburger on mobile and tablet */
    .hamburger {
        display: flex !important;
    }

    /* Strict Mobile Auth Visibility */
    .mobile-drawer .auth-user-only {
        display: none !important;
    }

    body.user-logged-in .mobile-drawer .auth-user-only {
        display: flex !important;
    }

    body.user-logged-in .mobile-drawer .auth-guest-only {
        display: none !important;
    }

    /* Hide desktop navigation */
    .nav-links.desktop-only,
    .desktop-only {
        display: none !important;
    }

    /* Navbar adjustments */
    .navbar {
        padding: 0.75rem 0;
    }

    .nav-container {
        padding: 0 1rem;
    }

    /* Logo sizing */
    .logo {
        height: 36px;
        width: auto;
    }

    .brand-name {
        font-size: 1.1rem;
    }

    /* Hero section */
    .hero {
        min-height: 70vh;
        padding: 100px 0 60px;
    }

    .hero-title {
        font-size: 2rem !important;
        line-height: 1.2;
    }

    .hero-description {
        font-size: 1rem !important;
        padding: 0 1rem;
    }

    .hero-btns {
        flex-direction: column;
        gap: 1rem;
        width: 100%;
        padding: 0 1rem;
    }

    .hero-btns .btn {
        width: 100%;
        justify-content: center;
    }

    /* Grid layouts */
    .grid-cols-2,
    .grid-cols-3,
    .grid-cols-4 {
        grid-template-columns: 1fr !important;
        gap: 1.5rem !important;
    }

    /* Cards */
    .card {
        padding: 1.5rem;
    }

    /* Sections */
    .section {
        padding: 2.5rem 0;
    }

    .section-title {
        font-size: 1.75rem !important;
        margin-bottom: 1rem;
    }

    .section-description {
        font-size: 0.95rem;
        padding: 0 0.5rem;
    }

    /* Footer */
    .footer-grid {
        grid-template-columns: 1fr !important;
        gap: 2rem;
        text-align: center;
    }

    .footer-links ul {
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
        gap: 0.75rem 1.5rem;
    }

    .footer-bottom {
        flex-direction: column;
        gap: 1rem;
        text-align: center;
    }

    /* Forms */
    .form-group {
        margin-bottom: 1rem;
    }

    .form-input,
    .form-textarea,
    .form-select {
        font-size: 16px !important;
        /* Prevent iOS zoom */
        padding: 1rem;
    }

    /* Buttons */
    .btn {
        padding: 0.875rem 1.5rem;
        font-size: 1rem;
    }

    .btn-lg {
        padding: 1rem 1.75rem;
    }

    /* Tables */
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    table {
        width: 100%;
    }

    /* Modals */
    .modal-content,
    .auth-modal {
        width: 95% !important;
        max-width: none !important;
        margin: 1rem;
        border-radius: 16px !important;
    }

    /* Chatbot adjustment for mobile */
    .chatbot-container,
    .chatbot-widget,
    .chat-widget {
        bottom: 15px !important;
        right: 15px !important;
    }

    .chatbot-toggle,
    .chat-toggle {
        width: 56px !important;
        height: 56px !important;
    }

    /* TDL/Excel cards grid */
    .tdl-grid,
    .utility-grid,
    .downloads-grid {
        grid-template-columns: 1fr !important;
    }

    /* Pricing cards */
    .pricing-grid {
        grid-template-columns: 1fr !important;
    }

    .pricing-card {
        max-width: 400px;
        margin: 0 auto;
    }

    /* Stats/Features grid */
    .stats-grid,
    .features-grid {
        grid-template-columns: 1fr !important;
        gap: 1.5rem;
    }

    /* Contact form */
    .contact-grid {
        grid-template-columns: 1fr !important;
    }

    /* Profile dropdown on mobile */
    .auth-profile-dropdown .auth-profile-menu {
        right: -50px;
        min-width: 200px;
    }
}

/* ===== SMALL MOBILE (max-width: 480px) ===== */

@media (max-width: 480px) {

    /* Container padding */
    .container {
        padding-left: 0.75rem;
        padding-right: 0.75rem;
    }

    /* Typography further scaling */
    .hero-title {
        font-size: 1.75rem !important;
    }

    .section-title {
        font-size: 1.5rem !important;
    }

    /* Cards tighter padding */
    .card {
        padding: 1.25rem;
    }

    /* Hero badge */
    .hero-badge {
        font-size: 0.75rem;
        padding: 0.5rem 1rem;
    }

    /* Stats grid single column on very small screens */
    .stats-grid {
        grid-template-columns: 1fr !important;
    }

    /* Drawer width */
    .mobile-drawer {
        max-width: 280px;
    }

    /* Auth buttons in mobile drawer */
    .mobile-drawer .auth-login-btn,
    .mobile-drawer .auth-logout-btn {
        display: block;
        text-align: center;
        margin-top: 0.5rem;
    }

    /* Success page card */
    .success-card {
        padding: 1.5rem 1rem;
    }

    .success-title {
        font-size: 1.25rem;
    }

    .success-icon {
        width: 80px;
        height: 80px;
    }

    .success-icon i {
        font-size: 2.5rem;
    }
}

/* ===== LANDSCAPE MOBILE FIX ===== */

@media (max-width: 768px) and (orientation: landscape) {
    .hero {
        min-height: 100vh;
        padding-top: 80px;
    }

    .hero-title {
        font-size: 1.75rem !important;
    }
}

/* ===== LARGE DESKTOP (min-width: 1440px) ===== */

@media (min-width: 1440px) {
    .container {
        max-width: 1320px;
    }
}

/* ===== PRINT STYLES ===== */

@media print {

    .navbar,
    .hamburger,
    .mobile-drawer,
    .nav-overlay,
    .chatbot-container,
    .theme-toggle {
        display: none !important;
    }

    .hero {
        min-height: auto;
        padding: 2rem 0;
    }
}

/* ===== ACCESSIBILITY - REDUCED MOTION ===== */

@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    .mobile-drawer {
        transition: none;
    }
}

/* ===== HIGH CONTRAST MODE ===== */

@media (prefers-contrast: high) {
    .hamburger span {
        height: 4px;
    }

    .navbar:not(.scrolled) .hamburger span {
        background-color: #fff;
    }

    .mobile-drawer a {
        border-bottom: 1px solid rgba(255, 255, 255, 0.3);
    }
}

/* ===== FIX FOR iOS SAFARI ===== */

@supports (-webkit-touch-callout: none) {

    /* iOS specific fixes */
    .mobile-drawer {
        height: -webkit-fill-available;
    }

    .hero {
        min-height: -webkit-fill-available;
    }

    /* Fix for input zoom on iOS */
    input[type="text"],
    input[type="email"],
    input[type="tel"],
    input[type="password"],
    textarea,
    select {
        font-size: 16px !important;
    }
}

/* ===== FIX FOR NOTCHED DEVICES ===== */

@supports (padding: max(0px)) {
    .navbar {
        padding-left: max(1rem, env(safe-area-inset-left));
        padding-right: max(1rem, env(safe-area-inset-right));
    }

    .mobile-drawer {
        padding-bottom: max(24px, env(safe-area-inset-bottom));
    }

    .chatbot-container {
        bottom: max(20px, env(safe-area-inset-bottom)) !important;
        right: max(20px, env(safe-area-inset-right)) !important;
    }
}

/* ===== DASHBOARD & PROFILE RESPONSIVE STYLES ===== */

/* Dashboard main container */
main[style*="padding-top: 100px"] .container {
    max-width: 100%;
    padding-left: 1rem;
    padding-right: 1rem;
}

/* Dashboard grid - Tablet breakpoint */
@media (max-width: 1024px) {

    /* Convert dashboard 2-column grid to single column */
    main[style*="padding-top: 100px"] .grid,
    .dashboard-grid,
    [style*="grid-template-columns: 300px 1fr"] {
        display: flex !important;
        flex-direction: column !important;
        gap: 1.5rem !important;
    }

    /* Profile sidebar - Full width on tablet */
    main[style*="padding-top: 100px"] .grid>.card:first-child {
        width: 100% !important;
        max-width: 500px !important;
        margin: 0 auto !important;
    }

    /* Main content area */
    main[style*="padding-top: 100px"] .grid>div:last-child {
        width: 100% !important;
    }

    /* Dashboard padding */
    main[style*="padding-top: 100px"] {
        padding-top: 80px !important;
        padding-bottom: 2rem !important;
    }

    /* Profile avatar size */
    #profileAvatarLarge,
    [id="profileAvatarLarge"] {
        width: 80px !important;
        height: 80px !important;
        font-size: 2rem !important;
    }

    /* Profile form improvements */
    #profileForm input,
    #profileForm .form-input {
        font-size: 16px !important;
        padding: 0.875rem !important;
    }

    /* Cards in dashboard */
    main[style*="padding-top: 100px"] .card {
        padding: 1.5rem !important;
    }

    /* Download history list */
    #downloadList {
        max-height: 300px;
        overflow-y: auto;
    }
}

/* Dashboard grid - Mobile breakpoint */
@media (max-width: 768px) {

    /* Further reduce padding on mobile */
    main[style*="padding-top: 100px"] {
        padding-top: 70px !important;
        min-height: auto !important;
    }

    main[style*="padding-top: 100px"] .container {
        padding-left: 0.75rem;
        padding-right: 0.75rem;
    }

    /* Profile sidebar card */
    main[style*="padding-top: 100px"] .grid>.card:first-child {
        padding: 1.25rem !important;
        max-width: 100% !important;
    }

    /* Profile avatar */
    #profileAvatarLarge,
    [id="profileAvatarLarge"] {
        width: 70px !important;
        height: 70px !important;
        font-size: 1.75rem !important;
    }

    /* Profile name and email */
    #profileName,
    [id="profileName"] {
        font-size: 1.25rem !important;
    }

    #profileEmail,
    [id="profileEmail"] {
        font-size: 0.875rem !important;
    }

    /* Profile form */
    #profileForm {
        width: 100%;
    }

    #profileForm label {
        font-size: 0.9rem !important;
    }

    /* Save button full width */
    #profileSaveBtn,
    [id="profileSaveBtn"] {
        width: 100% !important;
    }

    /* Cards */
    main[style*="padding-top: 100px"] .card {
        padding: 1rem !important;
        border-radius: 12px !important;
    }

    /* Card headings */
    main[style*="padding-top: 100px"] .card h3 {
        font-size: 1.1rem !important;
    }

    /* Logout button in sidebar */
    .btn.btn-outline.auth-logout-btn {
        padding: 0.75rem 1rem !important;
        font-size: 0.9rem !important;
    }
}

/* Small mobile - 480px and below */
@media (max-width: 480px) {
    main[style*="padding-top: 100px"] {
        padding-top: 65px !important;
    }

    main[style*="padding-top: 100px"] .container {
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }

    /* Profile avatar */
    #profileAvatarLarge,
    [id="profileAvatarLarge"] {
        width: 60px !important;
        height: 60px !important;
        font-size: 1.5rem !important;
    }

    /* Form inputs */
    #profileForm input {
        padding: 0.75rem !important;
        font-size: 16px !important;
    }

    /* Cards tighter */
    main[style*="padding-top: 100px"] .card {
        padding: 0.875rem !important;
    }

    /* Download history */
    #downloadList p,
    #downloadList div {
        font-size: 0.875rem !important;
    }
}

/* ===== PROFILE SETTINGS SPECIFIC ===== */

/* Profile form grid */
@media (max-width: 768px) {
    #profileForm>div {
        margin-bottom: 1rem !important;
    }

    /* Feedback message */
    #profileFeedback {
        font-size: 0.875rem !important;
        padding: 0.625rem !important;
    }
}

/* ===== DOWNLOAD HISTORY TABLE RESPONSIVE ===== */

@media (max-width: 768px) {
    #downloadList {
        font-size: 0.875rem;
    }

    #downloadList table {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
        -webkit-overflow-scrolling: touch;
    }

    #downloadList table td,
    #downloadList table th {
        padding: 0.5rem 0.75rem !important;
        font-size: 0.8rem !important;
    }
}

/* ===== ENSURE BUTTONS DON'T OVERFLOW ===== */

@media (max-width: 480px) {

    .btn,
    button {
        max-width: 100%;
        white-space: normal;
        word-wrap: break-word;
    }
}