/**
 * Responsive CSS - Mobile-first responsive design
 * Breakpoints: Mobile (<640px), Tablet (640px-1024px), Desktop (>1024px)
 */

/* ========== MOBILE FIRST BASE STYLES ========== */

/* Hamburger Menu Button */
.hamburger-menu {
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    width: 44px;
    height: 44px;
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    z-index: 1001;
}

.hamburger-menu span {
    display: block;
    width: 24px;
    height: 2px;
    background: var(--text-primary);
    margin: 3px 0;
    transition: all 0.3s ease;
}

.hamburger-menu.active span:nth-child(1) {
    transform: rotate(45deg) translate(5px, 5px);
}

.hamburger-menu.active span:nth-child(2) {
    opacity: 0;
}

.hamburger-menu.active span:nth-child(3) {
    transform: rotate(-45deg) translate(7px, -6px);
}

/* Mobile Navigation Overlay */
.mobile-nav-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 999;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.mobile-nav-overlay.active {
    opacity: 1;
}

/* Mobile Navigation Menu */
.mobile-nav-menu {
    position: fixed;
    top: 0;
    right: -300px;
    width: 280px;
    height: 100%;
    background: var(--bg-card);
    border-left: 1px solid var(--border-color);
    padding: 2rem 1.5rem;
    overflow-y: auto;
    transition: right 0.3s ease;
    z-index: 1000;
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.3);
}

.mobile-nav-menu.active {
    right: 0;
}

.mobile-nav-menu .nav-link {
    display: block;
    padding: 1rem;
    margin: 0.5rem 0;
    color: var(--text-primary);
    text-decoration: none;
    border-radius: 8px;
    transition: all 0.3s ease;
    font-size: 1.1rem;
}

.mobile-nav-menu .nav-link:hover {
    background: rgba(99, 102, 241, 0.1);
    color: var(--color-primary-400);
}

.mobile-nav-menu .nav-link.active {
    background: linear-gradient(135deg, var(--color-primary-600), var(--color-primary-500));
    color: white;
}

/* ========== MOBILE STYLES (< 640px) ========== */
@media (max-width: 639px) {
    /* Show hamburger menu */
    .hamburger-menu {
        display: flex;
    }
    
    .mobile-nav-overlay {
        display: block;
    }

    /* Hide desktop navigation */
    #mainNav {
        display: none !important;
    }

    /* Header adjustments */
    .header-content {
        padding: 0 1rem !important;
    }

    .header-logo {
        flex: 1;
    }

    .header-title {
        font-size: 1.1rem !important;
    }

    .header-logo img {
        height: 28px !important;
    }

    /* Control bars - Stack elements vertically */
    .ds-control-bar > div {
        flex-direction: column !important;
        gap: 1rem !important;
    }

    .ds-search-bar {
        flex: 1 1 100% !important;
        max-width: 100% !important;
        width: 100% !important;
    }

    .ds-filter-tabs {
        width: 100% !important;
        flex-direction: row !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
    }

    .ds-filter-tab {
        flex: 0 0 auto !important;
        white-space: nowrap !important;
        padding: 0.5rem 1rem !important;
        font-size: 0.875rem !important;
    }

    /* Tables - Make scrollable and reduce font size */
    .ds-responses-table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .ds-responses-table-container table {
        min-width: 600px;
        font-size: 0.8rem;
    }

    .ds-responses-table-container th,
    .ds-responses-table-container td {
        padding: 0.5rem !important;
        font-size: 0.75rem !important;
    }

    /* Hide less important columns on mobile */
    .ds-responses-table-container th:nth-child(3),
    .ds-responses-table-container td:nth-child(3) {
        display: none; /* Hide Questions Answered on mobile */
    }

    /* Buttons */
    .ds-btn {
        padding: 0.75rem 1rem !important;
        font-size: 0.875rem !important;
        width: 100%;
    }

    .table-action-btn {
        padding: 0.25rem 0.5rem !important;
        font-size: 0.7rem !important;
    }

    /* Cards/Grids - Single column on mobile */
    .ds-stats-grid,
    .ds-forms-grid,
    .ds-response-grid {
        grid-template-columns: 1fr !important;
        gap: 1rem !important;
    }

    .ds-form-card,
    .ds-response-card {
        width: 100%;
    }

    /* Section headers */
    .ds-section-header {
        padding: 1.5rem !important;
        flex-direction: column !important;
        text-align: center;
    }

    .ds-section-title {
        font-size: 1.5rem !important;
    }

    /* Main content padding */
    .app-content {
        padding: 1rem !important;
    }

    .ds-dashboard-container,
    .ds-forms-container,
    .ds-clients-container,
    .ds-responses-container {
        padding: 1rem !important;
    }

    /* Form dropdowns */
    .ds-form-filter-dropdown {
        width: 100% !important;
        min-width: unset !important;
    }

    /* Toast notifications */
    .ds-toast {
        bottom: 1rem !important;
        right: 1rem !important;
        left: 1rem !important;
        max-width: unset !important;
    }

    /* Dashboard specific */
    .ds-dashboard-header {
        padding: 1.5rem !important;
    }

    .ds-dashboard-header h1 {
        font-size: 1.75rem !important;
    }

    .ds-stat-card {
        padding: 1rem !important;
    }

    .ds-stat-value {
        font-size: 1.5rem !important;
    }

    /* Mode panel */
    .mode-panel {
        flex-direction: column !important;
        padding: 0.5rem !important;
    }

    .mode-btn {
        width: 100% !important;
    }
}

/* ========== TABLET STYLES (640px - 1024px) ========== */
@media (min-width: 640px) and (max-width: 1024px) {
    /* Show hamburger on tablets too for better touch experience */
    .hamburger-menu {
        display: flex;
    }
    
    .mobile-nav-overlay {
        display: block;
    }

    /* Hide desktop navigation */
    #mainNav {
        display: none !important;
    }

    /* Control bars - Partial stacking */
    .ds-control-bar > div {
        flex-wrap: wrap !important;
        gap: 1rem !important;
    }

    .ds-search-bar {
        flex: 1 1 60% !important;
        min-width: 300px !important;
    }

    .ds-filter-tabs {
        flex: 1 1 auto !important;
    }

    /* Cards/Grids - 2 columns on tablet */
    .ds-stats-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    .ds-forms-grid,
    .ds-response-grid {
        grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)) !important;
    }

    /* Tables - Slightly larger than mobile */
    .ds-responses-table-container table {
        font-size: 0.875rem;
    }

    .ds-responses-table-container th,
    .ds-responses-table-container td {
        padding: 0.75rem !important;
    }

    /* Section headers */
    .ds-section-header {
        flex-wrap: wrap !important;
    }

    .ds-section-title {
        font-size: 1.75rem !important;
    }

    /* Main content */
    .app-content {
        padding: 1.5rem !important;
    }
}

/* ========== DESKTOP ENHANCEMENTS (> 1024px) ========== */
@media (min-width: 1025px) {
    /* Ensure desktop navigation is visible */
    #mainNav {
        display: block !important;
    }

    /* Wider max widths for large screens */
    .app-content {
        max-width: 1400px;
    }

    /* 3+ columns for grids on desktop */
    .ds-stats-grid {
        grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)) !important;
    }

    .ds-forms-grid {
        grid-template-columns: repeat(auto-fill, minmax(380px, 1fr)) !important;
    }

    .ds-response-grid {
        grid-template-columns: repeat(auto-fill, minmax(400px, 1fr)) !important;
    }

    /* Larger click targets for desktop */
    .ds-filter-tab {
        padding: 0.75rem 1.5rem !important;
    }
}

/* ========== LANDSCAPE MOBILE ADJUSTMENTS ========== */
@media (max-width: 639px) and (orientation: landscape) {
    /* Reduce vertical padding in landscape */
    .app-header {
        padding: 0.5rem 1rem !important;
    }

    .ds-section-header {
        padding: 1rem !important;
    }

    /* Adjust card heights */
    .ds-stat-card {
        padding: 0.75rem !important;
    }
}

/* ========== PRINT STYLES ========== */
@media print {
    /* Hide navigation and controls for printing */
    .app-header,
    .ds-control-bar,
    .mode-panel,
    .table-action-btn,
    .ds-filter-tabs {
        display: none !important;
    }

    /* Ensure tables fit on page */
    .ds-responses-table-container {
        overflow: visible !important;
    }

    table {
        font-size: 10pt !important;
        page-break-inside: auto;
    }

    tr {
        page-break-inside: avoid;
        page-break-after: auto;
    }
}

/* ========== ACCESSIBILITY IMPROVEMENTS ========== */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .ds-btn,
    .ds-filter-tab,
    .ds-card {
        border-width: 2px !important;
    }
}

/* Dark mode adjustments for responsive elements */
@media (prefers-color-scheme: dark) {
    .mobile-nav-menu {
        background: var(--bg-card);
        border-left-color: var(--border-color);
    }
}