/* ===== Base Touch & Accessibility ===== */
@media (max-width: 1024px) {
    /* Ensure minimum touch target size */
    button, a, .btn, .filter-btn, .nav-item, .mobile-nav-item,
    input[type="submit"], input[type="button"] {
        min-height: 44px;
    }

    /* Prevent horizontal overflow on all pages */
    .main-content {
        overflow-x: hidden;
    }

    /* Tables: ensure parent wrappers allow horizontal scroll */
    /* Individual table wrappers handle overflow-x */

    /* Reduce body font for readability */
    body {
        -webkit-text-size-adjust: 100%;
    }
}

/* ===== Startup Dashboard (db-*) ===== */
@media (max-width: 992px) {
    .db-stats-row {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    .db-grid-2,
    .db-grid-3 {
        grid-template-columns: 1fr !important;
    }
}

@media (max-width: 576px) {
    .db-stats-row {
        grid-template-columns: 1fr !important;
    }

    .db-page {
        padding: 0.5rem !important;
    }

    .db-hero {
        padding: 1.5rem 1rem !important;
    }

    .db-hero h1 {
        font-size: 1.5rem !important;
    }

    /* Fix table horizontal overflow */
    .db-table {
        min-width: 650px;
    }

    div:has(> .db-table) {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
}

/* ===== Startup Details (sd-*) ===== */
@media (max-width: 992px) {
    .sd-body {
        grid-template-columns: 1fr !important;
    }

    .sd-sidebar {
        order: -1;
    }
}

@media (max-width: 576px) {
    .sd-metrics {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    .sd-header {
        padding: 1.5rem 1rem !important;
    }

    .sd-header h1 {
        font-size: 1.5rem !important;
    }

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

    .sd-actions {
        flex-direction: column;
    }

    .sd-actions a,
    .sd-actions button {
        width: 100%;
        text-align: center;
        justify-content: center;
    }
}

/* ===== Startup Explorer (se-*) ===== */
@media (max-width: 480px) {
    .se-stats-bar {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 0.5rem !important;
    }

    .se-cards {
        grid-template-columns: 1fr !important;
    }

    .se-container {
        padding: 0.75rem !important;
    }

    .se-hero h1 {
        font-size: 1.5rem !important;
    }
}

/* ===== Corporate Dashboard ===== */
@media (max-width: 768px) {
    .dashboard-container {
        padding: 0.75rem !important;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    /* Fix dead media query selectors - target actual classes */
    .recommended-grid {
        grid-template-columns: 1fr !important;
    }

    .event-meta {
        flex-wrap: wrap;
    }
}

@media (max-width: 480px) {
    .stats-grid {
        grid-template-columns: 1fr !important;
    }

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

    .stat-card .stat-icon,
    .stat-icon {
        font-size: 2rem !important;
    }

    .stat-card .stat-number,
    .stat-number {
        font-size: 1.75rem !important;
    }
}

/* ===== Corporate Browse ===== */
@media (max-width: 768px) {
    .browse-page {
        padding: 0.75rem !important;
    }

    .browse-page-header {
        flex-direction: column;
        gap: 1rem;
    }

    .browse-filters {
        padding: 1rem !important;
    }

    .browse-filters .form-row,
    .browse-filters .filter-row {
        grid-template-columns: 1fr !important;
    }

    .startup-grid {
        grid-template-columns: 1fr !important;
    }
}

@media (max-width: 480px) {
    .su-card {
        padding: 1rem !important;
    }
}

/* ===== Corporate Profile ===== */
@media (max-width: 768px) {
    .profile-container {
        padding: 0.75rem !important;
    }

    .profile-stats {
        grid-template-columns: repeat(2, 1fr) !important;
    }
}

@media (max-width: 480px) {
    .profile-stats {
        grid-template-columns: 1fr !important;
    }

    .stat-mini {
        padding: 0.75rem !important;
    }
}

/* ===== Corporate Saved Startups ===== */
@media (max-width: 768px) {
    .saved-container {
        padding: 0.75rem !important;
    }

    .startup-grid {
        grid-template-columns: 1fr !important;
    }

    .startup-actions {
        flex-wrap: wrap;
    }

    .startup-actions button,
    .startup-actions a {
        flex: 1;
        min-width: 120px;
        text-align: center;
        justify-content: center;
    }
}

/* ===== Admin Dashboard (admin-dash, dash-*) ===== */
@media (max-width: 900px) {
    .admin-dash {
        padding: 1rem 0.5rem !important;
    }

    .stats-row {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    .quick-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    .charts-row,
    .invest-row,
    .activity-row {
        grid-template-columns: 1fr !important;
    }

    .dash-hero {
        padding: 1.5rem 1rem !important;
    }

    .dash-hero h1 {
        font-size: 1.75rem !important;
    }
}

@media (max-width: 600px) {
    .stats-row,
    .quick-grid {
        grid-template-columns: 1fr !important;
    }

    .dash-table {
        font-size: 0.85rem;
    }

    .dash-table th,
    .dash-table td {
        padding: 0.5rem 0.4rem !important;
    }
}

/* ===== Admin Users (users-*) ===== */
@media (max-width: 768px) {
    .users-page {
        padding: 0 0.5rem !important;
    }

    .users-stats {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    .users-controls {
        flex-direction: column;
        gap: 0.75rem;
    }

    .users-table-wrap {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .users-table {
        min-width: 700px;
    }

    .users-hero h1 {
        font-size: 1.5rem !important;
    }
}

@media (max-width: 480px) {
    .users-stats {
        grid-template-columns: 1fr !important;
    }
}

/* ===== Event MyEvents ===== */
@media (max-width: 768px) {
    .events-container {
        padding: 0.75rem !important;
    }

    .events-grid {
        grid-template-columns: 1fr !important;
    }

    .event-actions {
        flex-wrap: wrap;
    }

    .event-actions a,
    .event-actions button {
        flex: 1;
        min-width: 100px;
        text-align: center;
        justify-content: center;
    }

    .event-card-header {
        flex-direction: column;
        gap: 0.5rem;
    }
}

/* ===== Public Events (events-page) ===== */
@media (max-width: 768px) {
    .events-page .events-hero {
        padding: 2rem 0 1.5rem;
    }

    .events-page .hero-title {
        font-size: 1.75rem !important;
    }

    .events-page .hero-subtitle {
        font-size: 0.95rem;
    }

    .events-page .filters-section {
        padding: 1rem;
    }

    .events-page .events-grid {
        grid-template-columns: 1fr !important;
    }

    /* Fix JS inline-styled pagination */
    .events-page div[style*="display: flex"][style*="justify-content: center"] {
        flex-wrap: wrap !important;
    }

    .events-page div[style*="display: flex"][style*="justify-content: center"] a {
        min-width: 36px !important;
        padding: 0.4rem 0.6rem !important;
        font-size: 0.85rem !important;
    }
}

/* ===== Public Event Details (ed-*) ===== */
@media (max-width: 992px) {
    .ed-body {
        grid-template-columns: 1fr !important;
    }

    .ed-sidebar {
        order: -1;
    }
}

@media (max-width: 576px) {
    .ed-header-content {
        flex-direction: column !important;
    }

    .ed-banner-thumb {
        width: 120px !important;
        height: 120px !important;
    }

    .ed-header h1 {
        font-size: 1.5rem !important;
    }

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

    .ed-share {
        flex-wrap: wrap;
    }
}

/* ===== Event Details Page (event-details-page) ===== */
@media (max-width: 768px) {
    .event-details-page .event-body {
        grid-template-columns: 1fr !important;
    }

    .event-details-page .sidebar {
        position: static;
        order: -1;
    }

    .event-details-page .event-name {
        font-size: 1.5rem;
    }

    .event-details-page .content-section {
        padding: 1rem;
    }
}

/* ===== Business Idea Generator ===== */
@media (max-width: 640px) {
    .generator-page {
        padding: 0 0.5rem !important;
    }

    .generator-card {
        padding: 1.25rem !important;
    }

    .generator-features {
        grid-template-columns: 1fr !important;
    }

    .generator-hero h1 {
        font-size: 1.5rem !important;
    }

    .result-actions {
        flex-direction: column;
    }

    .result-actions a,
    .result-actions button {
        width: 100%;
        text-align: center;
    }
}

/* ===== Auth Pages (Login/Register) ===== */
@media (max-width: 968px) {
    .auth-container {
        grid-template-columns: 1fr !important;
    }

    .auth-info-panel {
        order: -1;
    }
}

@media (max-width: 640px) {
    .auth-section {
        padding: 1.5rem 0.75rem !important;
    }

    .auth-card {
        padding: 1.5rem 1.25rem !important;
        border-radius: 16px;
    }

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

    .auth-icon {
        width: 56px !important;
        height: 56px !important;
        font-size: 1.75rem !important;
    }

    .form-options {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }

    .info-stats {
        grid-template-columns: repeat(3, 1fr);
        gap: 0.75rem;
    }

    .info-title {
        font-size: 1.3rem !important;
    }
}

/* ===== Create/Edit Startup Form ===== */
@media (max-width: 768px) {
    .form-row {
        grid-template-columns: 1fr !important;
    }

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

    .robot-flex {
        flex-direction: column;
        gap: 0.75rem;
    }

    .robot-side {
        flex-direction: row;
        gap: 0.75rem;
    }
}

@media (max-width: 480px) {
    .form-btn,
    .dashboard-btn {
        font-size: 0.95rem !important;
        padding: 0.85rem 1rem !important;
    }
}

/* ===== Global Modal/Popup Mobile Fix ===== */
@media (max-width: 640px) {
    .compact-popup,
    .password-popup,
    .modal-content {
        max-width: 95vw !important;
        padding: 1.5rem 1rem !important;
        margin: 0 0.5rem;
    }

    .popup-title,
    .password-title {
        font-size: 1.5rem !important;
    }
}

/* ===== Global Card/Panel Spacing ===== */
@media (max-width: 768px) {
    .ui-card,
    .form-section {
        padding: 1rem !important;
        border-radius: 14px !important;
        margin-bottom: 1rem !important;
    }

    .main-container,
    .container {
        padding: 1rem 0.75rem !important;
    }
}

@media (max-width: 480px) {
    .ui-card,
    .form-section {
        padding: 0.75rem !important;
        border-radius: 12px !important;
    }

    .main-container,
    .container {
        padding: 0.75rem 0.5rem !important;
    }

    h1 {
        font-size: 1.75rem !important;
    }

    h2 {
        font-size: 1.4rem !important;
    }

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

/* ===== Homepage ===== */
/* homepage.css has its own responsive rules at 1024px, 768px, 480px */
/* Only add supplementary rules not covered there */
@media (max-width: 480px) {
    .stats-section .stats-grid {
        grid-template-columns: 1fr !important;
    }

    .cta-buttons .btn-cta {
        width: 100%;
        justify-content: center;
    }
}

/* ===== Toast container mobile fix ===== */
@media (max-width: 640px) {
    .toast-container {
        left: 0.5rem !important;
        right: 0.5rem !important;
        max-width: none !important;
    }

    .toast {
        min-width: auto !important;
    }
}

/* ===== PublicEvent Pagination Buttons ===== */
@media (max-width: 480px) {
    #paginationContainer button,
    #paginationContainer a {
        padding: 0.4rem 0.6rem !important;
        font-size: 0.8rem !important;
        min-width: 36px;
    }
}

/* ===== MyEvents - event stats flex ===== */
@media (max-width: 480px) {
    .event-stats {
        flex-wrap: wrap;
        gap: 0.5rem !important;
    }

    .stat-mini {
        min-width: calc(33% - 0.5rem);
    }

    .stat-mini-value {
        font-size: 1.2rem !important;
    }
}

/* ===== Corporate Dashboard event/application items ===== */
@media (max-width: 576px) {
    .event-item,
    .application-item {
        flex-direction: column !important;
        align-items: flex-start !important;
    }

    .event-actions,
    .application-status {
        width: 100%;
    }
}

/* ===== Create/Edit Event Forms ===== */
@media (max-width: 768px) {
    .create-event-container,
    .edit-event-container {
        padding: 0.75rem !important;
    }
}

/* ===== Event Details (corporate) ===== */
@media (max-width: 768px) {
    .details-container {
        padding: 1rem 0.75rem !important;
    }

    .details-container .detail-grid {
        grid-template-columns: 1fr !important;
    }
}

/* ===== Fix grid minmax overflow on very small screens ===== */
@media (max-width: 400px) {
    [style*="minmax(340px"],
    [style*="minmax(350px"],
    [style*="minmax(320px"],
    [style*="minmax(280px"],
    [style*="minmax(260px"],
    [style*="minmax(240px"] {
        grid-template-columns: 1fr !important;
    }

    .startup-grid,
    .events-grid,
    .recommended-grid {
        grid-template-columns: 1fr !important;
    }
}

/* ===== Safe area insets for notched phones ===== */
@supports (padding: env(safe-area-inset-bottom)) {
    .main-footer {
        padding-bottom: calc(1.25rem + env(safe-area-inset-bottom));
    }

    .main-navbar {
        padding-top: env(safe-area-inset-top);
    }
}

/* ===== Smooth scrolling globally ===== */
@media (prefers-reduced-motion: no-preference) {
    html {
        scroll-behavior: smooth;
    }
}

/* ===== Reduce animations on preference ===== */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}