﻿/* Mobile Responsiveness Improvements */

/* Tablet & Smaller Laptops */
@media (max-width: 992px) {
    .container {
        padding: 0 20px;
    }

    h1 {
        font-size: 2.75rem;
    }

    .grid-2 {
        gap: 24px;
    }

    /* Stack download button and format selector on tablet-sized preview sections */
    .preview-section .input-group {
        flex-direction: column !important;
        gap: 10px !important;
    }

    .preview-section .input-group>select,
    .preview-section .input-group>button {
        width: 100% !important;
        flex: none !important;
    }

    /* Ensure color picker input is always visible */
    .color-picker-wrapper {
        display: flex !important;
        align-items: center !important;
        gap: 10px !important;
    }

    input[type="color"] {
        width: 40px !important;
        min-width: 40px !important;
        height: 32px !important;
        padding: 0 !important;
        border: none !important;
        cursor: pointer !important;
        flex-shrink: 0 !important;
    }
}

/* Mobile Devices (Landscape & Portrait) */
@media (max-width: 768px) {

    /* Header */
    header {
        height: auto;
        padding: 20px 0;
    }

    .header-content {
        flex-direction: column;
        gap: 20px;
        text-align: center;
    }

    .brand {
        font-size: 1.75rem;
        width: 100%;
        /* Full width for centering */
    }

    /* Wrap nav links for easier extensive menu handling */
    .nav-links {
        width: 100%;
        justify-content: center;
        flex-wrap: wrap;
        gap: 10px;
    }

    .nav-links a {
        margin: 0;
        font-size: 0.9rem;
        padding: 8px 12px;
        background: rgba(0, 0, 0, 0.03);
        /* Subtle button-like look */
        border-radius: 20px;
    }

    /* Dark mode adjustment for nav links */
    [data-theme="dark"] .nav-links a {
        background: rgba(255, 255, 255, 0.05);
    }

    /* Theme Toggle Position */
    .theme-toggle {
        position: absolute;
        top: 20px;
        right: 20px;
        margin-left: 0;
    }

    /* Typography */
    h1 {
        font-size: 2.25rem;
        line-height: 1.25;
        word-wrap: break-word;
        /* Prevent overflow */
    }

    h2 {
        font-size: 1.75rem;
        line-height: 1.3;
    }

    p {
        font-size: 1rem;
    }

    /* Cards */
    .glass-card,
    .use-case-card {
        padding: 24px;
    }

    /* Tool Specifics */
    .comparison-container {
        min-height: 250px;
    }

    .preview-section {
        padding: 15px;
    }

    .size-comparison {
        flex-direction: column;
        gap: 16px;
        align-items: stretch;
        text-align: center;
    }

    .size-arrow {
        transform: rotate(90deg);
        /* Point down */
        margin: 5px 0;
    }

    .drop-zone {
        padding: 20px;
    }

    /* Fix Grid Overflow */
    .grid-2,
    .generator-grid {
        grid-template-columns: 100% !important;
        /* Force stack */
        display: flex;
        /* Flex is often safer for stacking */
        flex-direction: column;
        width: 100%;
        min-width: 0;
    }

    /* Stack download button and format selector on tablet */
    .preview-section .input-group {
        flex-direction: column !important;
        gap: 10px;
    }

    .preview-section .input-group>select,
    .preview-section .input-group>button {
        width: 100% !important;
        flex: none !important;
    }
}

/* Small Mobile Devices (iPhone SE, Older Androids) - 320px target */
@media (max-width: 480px) {

    /* GLOBAL SAFETY NET */
    * {
        box-sizing: border-box !important;
    }

    html,
    body {
        overflow-x: hidden !important;
        width: 100% !important;
        max-width: 100vw !important;
        position: relative;
    }

    .container {
        padding: 0 12px !important;
        width: 100% !important;
        max-width: 100vw !important;
    }

    main.container {
        padding-top: 10px !important;
    }

    /* Safe area for notched phones and to ensure header is visible */
    body {
        padding-top: env(safe-area-inset-top, 0) !important;
    }

    /* HEADER */
    header {
        height: auto !important;
        min-height: auto !important;
        padding: 20px 12px 12px 12px !important;
        position: relative !important;
        margin-top: 0 !important;
        display: block !important;
        contain: none !important;
        padding-top: max(20px, env(safe-area-inset-top, 20px)) !important;
    }

    .header-content {
        display: flex !important;
        flex-direction: column !important;
        align-items: flex-start !important;
        width: 100% !important;
        position: static !important;
        padding-top: 0 !important;
        min-height: auto !important;
    }

    .brand {
        font-size: 1.5rem !important;
        max-width: calc(100% - 50px) !important;
        text-align: left !important;
        display: block !important;
        margin-bottom: 12px !important;
        margin-top: 0 !important;
        padding-top: 0 !important;
        position: relative !important;
        z-index: 5 !important;
    }

    /* Theme Toggle - Fixed Size */
    .theme-toggle {
        position: absolute !important;
        top: 10px !important;
        right: 12px !important;
        padding: 0 !important;
        width: 30px !important;
        height: 30px !important;
        font-size: 14px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        background: var(--bg-surface) !important;
        border-radius: 50% !important;
        z-index: 10;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    }

    .nav-links {
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: wrap !important;
        justify-content: center !important;
        width: 100% !important;
        gap: 6px !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    .nav-links a {
        font-size: 0.75rem !important;
        padding: 6px 10px !important;
        margin: 0 !important;
        width: auto !important;
        background: rgba(0, 0, 0, 0.05);
        border-radius: 16px;
        text-align: center !important;
        display: inline-block !important;
        white-space: nowrap !important;
    }

    /* Share buttons on mobile */
    #hero-share {
        margin-top: 25px !important;
        padding: 0 10px !important;
        flex-direction: column !important;
        gap: 10px !important;
    }

    #hero-share>div {
        justify-content: center !important;
        flex-wrap: wrap !important;
        gap: 8px !important;
        max-width: 100% !important;
    }

    .share-btn {
        width: 36px !important;
        height: 36px !important;
        min-width: 36px !important;
        border-radius: 8px !important;
        background: var(--bg-surface) !important;
        border: 1px solid var(--border-color) !important;
        flex-shrink: 0 !important;
    }

    .share-btn svg {
        width: 16px !important;
        height: 16px !important;
    }

    /* Mode Switch - Visual Fixes */
    .mode-switch {
        width: 100% !important;
        max-width: 100% !important;
        display: flex !important;
        flex-direction: row !important;
        border-radius: 25px !important;
        margin-bottom: 20px !important;
        padding: 4px !important;
        background: var(--input-bg) !important;
        box-sizing: border-box !important;
    }

    .mode-btn {
        flex: 1 !important;
        text-align: center !important;
        padding: 8px 4px !important;
        font-size: 0.85rem !important;
        border-radius: 20px !important;
        width: auto !important;
        min-width: 0 !important;
    }

    /* Glass Cards */
    .glass-card {
        padding: 15px !important;
        width: 100% !important;
        margin: 0 0 20px 0 !important;
        border-radius: 12px !important;
        overflow: hidden !important;
    }

    /* Form Elements */
    .input-group {
        width: 100% !important;
        margin-bottom: 15px !important;
        display: flex !important;
        flex-direction: column !important;
        gap: 8px !important;
    }

    /* Force inputs/buttons in preview section to stack and shrink */
    .preview-section .input-group {
        flex-direction: column !important;
        gap: 10px !important;
        width: 100% !important;
        /* Allow full width */
        max-width: 100% !important;
        margin: 15px 0 0 0 !important;
        align-items: stretch !important;
        padding: 0 5px !important;
        /* Internal padding */
    }

    .preview-section .input-group>select,
    .preview-section .input-group>button,
    .preview-section .input-group>input {
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        flex: none !important;
    }

    input,
    select,
    textarea,
    button,
    .btn {
        width: 100% !important;
        max-width: 100% !important;
        font-size: 16px !important;
        padding: 12px !important;
        height: auto !important;
        box-sizing: border-box !important;
    }

    /* SLIDER VISIBILITY FIX */
    .slider {
        -webkit-appearance: none !important;
        appearance: none !important;
        width: 100% !important;
        height: 8px !important;
        background: #d3d3d3 !important;
        outline: none !important;
        opacity: 0.7 !important;
        transition: opacity .2s !important;
        border-radius: 5px !important;
        display: block !important;
        margin: 10px 0 !important;
        padding: 0 !important;
    }

    .slider:hover {
        opacity: 1 !important;
    }

    .slider::-webkit-slider-thumb {
        -webkit-appearance: none !important;
        appearance: none !important;
        width: 25px !important;
        height: 25px !important;
        border-radius: 50% !important;
        background: var(--primary-color, #FF6B6B) !important;
        cursor: pointer !important;
        border: 2px solid white !important;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2) !important;
    }

    .slider::-moz-range-thumb {
        width: 25px !important;
        height: 25px !important;
        border-radius: 50% !important;
        background: var(--primary-color, #FF6B6B) !important;
        cursor: pointer !important;
        border: 2px solid white !important;
    }

    /* QR CANVAS / PREVIEW SIZING */
    .preview-section {
        width: 100% !important;
        padding: 15px !important;
        overflow: hidden !important;
    }

    .qr-canvas {
        width: 100% !important;
        max-width: 100% !important;
        padding: 15px !important;
        overflow: hidden !important;
    }

    /* Force internal canvas/img to SCALE (not clip) */
    .qr-canvas>*,
    #qr-code canvas,
    #qr-code img,
    #qr-code svg,
    .qr-canvas canvas,
    .qr-canvas img,
    .qr-canvas svg,
    .preview-section svg,
    #barcode {
        width: 100% !important;
        height: auto !important;
        max-width: 100% !important;
    }

    /* Color Picker Row */
    .color-picker-wrapper {
        width: 100% !important;
        display: flex !important;
        flex-direction: row !important;
        justify-content: flex-start !important;
        align-items: center !important;
        background: var(--input-bg);
        padding: 8px 12px !important;
        border-radius: 8px;
        gap: 12px !important;
    }

    input[type="color"] {
        width: 40px !important;
        min-width: 40px !important;
        height: 30px !important;
        padding: 0 !important;
        border: none !important;
        background: transparent !important;
        flex: 0 0 auto !important;
    }

    /* Color Hex Value Display */
    .color-picker-wrapper span {
        font-family: 'Monaco', 'Consolas', monospace !important;
        font-size: 0.85rem !important;
        font-weight: 600 !important;
        color: var(--text-main) !important;
        flex: 1 !important;
    }

    #limit-badge-container {
        width: 100% !important;
        flex-direction: row !important;
        flex-wrap: wrap !important;
        align-items: center !important;
        justify-content: center !important;
        text-align: center !important;
        padding: 8px !important;
    }

    h1 {
        font-size: 1.6rem !important;
        margin-bottom: 15px !important;
        line-height: 1.3 !important;
    }

    .drop-zone {
        padding: 20px 10px;
        width: 100%;
        box-sizing: border-box;
    }

    /* Color Picker Tool */
    .color-display-area {
        padding: 20px !important;
    }

    .main-swatch {
        width: 120px !important;
        height: 120px !important;
    }

    .values-grid {
        grid-template-columns: 1fr !important;
        gap: 12px !important;
    }

    .value-card {
        padding: 12px 15px !important;
    }

    .color-value {
        font-size: 0.95rem !important;
        word-break: break-all !important;
    }

    .shades-grid {
        height: 50px !important;
    }

    /* WiFi QR Generator - Checkbox wrapper */
    .checkbox-wrapper {
        flex-wrap: wrap !important;
    }

    .checkbox-wrapper label {
        font-size: 0.9rem !important;
    }
}

/* Ultra-small screens (iPhone SE, 320px width) */
@media (max-width: 400px) {
    .container {
        padding: 0 8px !important;
    }

    /* Compact header for ultra-small screens */
    header {
        padding: 8px 0 !important;
    }

    .brand {
        font-size: 1.2rem !important;
        margin-bottom: 12px !important;
    }

    /* Make nav links more compact */
    .nav-links {
        gap: 6px !important;
    }

    .nav-links a {
        font-size: 0.8rem !important;
        padding: 8px 10px !important;
        white-space: nowrap !important;
    }

    /* Hero section adjustments */
    section[style*="padding: 120px"] {
        padding: 60px 0 40px !important;
    }

    h1 {
        font-size: 1.4rem !important;
        line-height: 1.35 !important;
        margin-bottom: 12px !important;
    }

    /* Reduce description text */
    main.container>section>p {
        font-size: 0.95rem !important;
        line-height: 1.5 !important;
        min-height: auto !important;
        margin-bottom: 20px !important;
    }

    /* Smaller buttons */
    .btn {
        padding: 10px 16px !important;
        font-size: 0.85rem !important;
    }

    /* Tool cards */
    .glass-card {
        padding: 12px !important;
        margin-bottom: 15px !important;
    }

    /* Section headers */
    h2 {
        font-size: 1.3rem !important;
    }

    h3 {
        font-size: 1.1rem !important;
    }

    /* Share component */
    .share-with-friends {
        flex-direction: column !important;
        gap: 10px !important;
        align-items: flex-start !important;
    }

    /* Footer */
    footer {
        padding: 30px 0 !important;
    }

    footer .container>div:first-child {
        gap: 20px !important;
    }
}

/* Prevent horizontal scroll on all mobile */
@media (max-width: 768px) {

    html,
    body {
        overflow-x: hidden;
    }

    * {
        max-width: 100vw;
    }

    /* Ensure images don't cause overflow */
    img,
    svg,
    canvas,
    video {
        max-width: 100% !important;
        height: auto !important;
    }

    /* Footer responsive - 2 columns on tablet */
    .footer-links-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 30px !important;
    }
}

/* Footer responsive - 1 column on mobile */
@media (max-width: 600px) {
    .footer-links-grid {
        grid-template-columns: 1fr !important;
        gap: 25px !important;
        text-align: center;
        padding: 30px 0 !important;
    }

    footer nav {
        align-items: center;
    }

    .footer-social-btn {
        width: 38px !important;
        height: 38px !important;
        min-width: 38px !important;
    }
}