/* ============================================
   MOBILE RESPONSIVE STYLES - Dalexor
   Complete mobile-first redesign
   ============================================ */

/* ============================================
   MOBILE HEADER & NAVIGATION
   ============================================ */

/* Show mobile header on mobile devices */
@media (max-width: 768px) {

    .mobile-app-header,
    .mobile-main-header {
        display: flex;
    }

    /* Hide desktop top nav on mobile */
    nav {
        display: none !important;
    }

    /* Hide welcome text on mobile */
    #nav-auth {
        display: none !important;
    }
}

/* Hide welcome text on tablets */
@media (max-width: 1024px) {
    #nav-auth {
        display: none !important;
    }
}

.mobile-app-header,
.mobile-main-header {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 60px;
    background: transparent;
    z-index: 2001;
    padding: 0 1rem;
    align-items: center;
    justify-content: flex-start;
}

.menu-toggle {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    width: 44px;
    height: 44px;
    background: rgba(139, 92, 246, 0.2);
    border: 1px solid rgba(139, 92, 246, 0.3);
    border-radius: 8px;
    cursor: pointer;
    gap: 5px;
    padding: 0;
    transition: all 0.3s ease;
}

.menu-toggle:hover {
    background: rgba(139, 92, 246, 0.3);
}

.menu-toggle span {
    display: block;
    width: 24px;
    height: 3px;
    background: #fff;
    border-radius: 2px;
    transition: all 0.3s ease;
}

.menu-toggle.active span:nth-child(1) {
    transform: rotate(45deg) translate(6px, 6px);
}

.menu-toggle.active span:nth-child(2) {
    opacity: 0;
}

.menu-toggle.active span:nth-child(3) {
    transform: rotate(-45deg) translate(6px, -6px);
}

/* Sidebar Overlay */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 60px;
    left: 0;
    width: 100%;
    height: calc(100% - 60px);
    background: rgba(0, 0, 0, 0.8);
    z-index: 1000;
}

.sidebar-overlay.active {
    display: block;
}

/* Mobile Sidebar - slides from LEFT */
@media (max-width: 768px) {
    .mobile-sidebar {
        display: block;
        position: fixed;
        top: 60px;
        left: -300px;
        width: 280px;
        height: calc(100vh - 60px);
        background: linear-gradient(180deg, #0a0a1a 0%, #0a0a1f 100%);
        border-right: 1px solid rgba(139, 92, 246, 0.1);
        z-index: 1001;
        transition: left 0.3s ease;
        padding: 1.5rem;
        overflow-y: auto;
    }

    .mobile-sidebar.active {
        left: 0;
    }

    .mobile-nav {
        display: flex;
        flex-direction: column;
        gap: 20px;
        list-style: none;
        padding: 0;
        margin: 0;
    }

    .mobile-nav .nav-link {
        color: #f8fafc;
        font-size: 1.1rem;
        padding: 10px 0;
        display: block;
        text-decoration: none;
        transition: color 0.3s ease;
    }

    .mobile-nav .nav-link:hover {
        color: #8b5cf6;
    }
}

/* ============================================
   MOBILE BREAKPOINT (768px and below)
   ============================================ */
@media (max-width: 768px) {

    /* Show mobile header */
    .mobile-app-header,
    .mobile-main-header {
        display: flex !important;
    }

    /* Show sidebar overlay when active */
    .sidebar-overlay.active {
        display: block;
    }

    /* Body adjustments */
    body {
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
    }

    /* No margin needed - transparent header */
    .hero {
        padding-top: 6rem !important;
    }

    .page-hero {
        padding-top: 6rem !important;
    }

    /* ============================================
       SIDEBAR - Mobile Slide-in
       ============================================ */
    .sidebar {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        width: 280px !important;
        height: 100vh !important;
        z-index: 2000 !important;
        transition: transform 0.3s ease !important;
        padding-top: 1rem !important;
        overflow-y: auto !important;
        background: #0a0a1a !important;
    }

    @media (max-width: 768px) {
        .sidebar {
            left: -280px !important;
        }

        .sidebar.active {
            left: 0 !important;
        }
    }

    /* ============================================
       MAIN CONTENT - Mobile Layout
       ============================================ */
    .dashboard-layout {
        flex-direction: column !important;
        min-height: 100vh;
    }

    .main-content {
        margin-left: 0 !important;
        margin-top: 60px !important;
        padding: 1rem !important;
        width: 100% !important;
        min-height: calc(100vh - 60px);
    }

    /* ============================================
       APP HEADER - Mobile
       ============================================ */
    .app-header {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 1rem !important;
        padding-bottom: 1rem !important;
    }

    /* ============================================
       STATS GRID - Mobile
       ============================================ */
    .stats-grid {
        display: grid !important;
        grid-template-columns: 1fr 1fr !important;
        gap: 0.75rem !important;
    }

    .stat-card {
        padding: 1rem !important;
    }

    .stat-value {
        font-size: 1.5rem !important;
    }

    .stat-label {
        font-size: 0.75rem !important;
    }

    /* ============================================
       PROJECTS GRID - Mobile
       ============================================ */
    .projects-grid {
        display: flex !important;
        flex-direction: column !important;
        gap: 1rem !important;
    }

    .project-card {
        width: 100% !important;
        padding: 1.25rem !important;
        margin: 0 !important;
    }

    .project-card-header {
        flex-direction: column !important;
        gap: 0.5rem !important;
    }

    .project-card-title {
        font-size: 1.1rem !important;
    }

    .project-card-description {
        font-size: 0.85rem !important;
        -webkit-line-clamp: 2;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        overflow: hidden;
    }

    .project-card-stats {
        grid-template-columns: repeat(3, 1fr) !important;
        gap: 0.5rem !important;
    }

    .project-stat-value {
        font-size: 1.25rem !important;
    }

    .project-stat-label {
        font-size: 0.65rem !important;
    }

    .project-card-actions {
        display: flex !important;
        flex-wrap: wrap !important;
        gap: 0.5rem !important;
        margin-top: 1rem !important;
    }

    .project-card-actions .btn {
        flex: 1 !important;
        min-width: 80px !important;
        padding: 0.6rem 0.75rem !important;
        font-size: 0.8rem !important;
    }

    .project-tags {
        flex-wrap: wrap !important;
        gap: 0.25rem !important;
    }

    .project-tag {
        font-size: 0.7rem !important;
        padding: 0.2rem 0.5rem !important;
    }

    /* ============================================
       THREADS LIST - Mobile
       ============================================ */
    .threads-list {
        padding: 0 !important;
    }

    .thread-item {
        flex-direction: column !important;
        align-items: stretch !important;
        padding: 1rem !important;
        gap: 0.75rem !important;
    }

    .thread-content {
        width: 100% !important;
    }

    .thread-title {
        font-size: 0.95rem !important;
        line-height: 1.4 !important;
    }

    .thread-meta {
        font-size: 0.75rem !important;
        flex-wrap: wrap !important;
        gap: 0.5rem !important;
    }

    .thread-actions {
        display: flex !important;
        width: 100% !important;
        gap: 0.5rem !important;
        margin-top: 0.5rem !important;
    }

    .thread-actions .btn {
        flex: 1 !important;
        padding: 0.6rem !important;
        font-size: 0.8rem !important;
    }

    /* ============================================
       TOOLS GRID - Mobile
       ============================================ */
    .tools-grid {
        display: flex !important;
        flex-direction: column !important;
        gap: 1rem !important;
    }

    .tool-card {
        width: 100% !important;
        padding: 1.25rem !important;
    }

    .tool-card h3 {
        font-size: 1.1rem !important;
    }

    .tool-card p {
        font-size: 0.85rem !important;
    }

    /* ============================================
       SETTINGS PAGE - Mobile
       ============================================ */
    .settings-grid {
        display: flex !important;
        flex-direction: column !important;
        gap: 1rem !important;
    }

    .settings-section {
        padding: 1.25rem !important;
    }

    .settings-section h3 {
        font-size: 1.1rem !important;
    }

    /* ============================================
       BILLING PAGE - Mobile
       ============================================ */
    .billing-grid {
        display: flex !important;
        flex-direction: column !important;
        gap: 1rem !important;
    }

    .subscription-card {
        padding: 1.25rem !important;
    }

    /* ============================================
       RSS FEEDS PAGE - Mobile
       ============================================ */
    .feeds-grid {
        display: flex !important;
        flex-direction: column !important;
        gap: 1rem !important;
    }

    .feed-card {
        width: 100% !important;
        padding: 1.25rem !important;
    }

    /* ============================================
       BUTTONS - Mobile Touch Friendly
       ============================================ */
    .btn {
        min-height: 44px !important;
        padding: 0.75rem 1rem !important;
        font-size: 0.9rem !important;
        touch-action: manipulation;
    }

    .btn-small {
        min-height: 38px !important;
        padding: 0.5rem 0.75rem !important;
        font-size: 0.8rem !important;
    }

    .btn-full {
        width: 100% !important;
    }

    .btn-group {
        display: flex !important;
        flex-direction: column !important;
        gap: 0.5rem !important;
    }

    /* ============================================
       FORMS - Mobile
       ============================================ */
    .form-group {
        margin-bottom: 1rem !important;
    }

    .form-control,
    input,
    textarea,
    select {
        width: 100% !important;
        min-height: 44px !important;
        padding: 0.75rem 1rem !important;
        font-size: 16px !important;
        /* Prevents iOS zoom */
        border-radius: 8px !important;
    }

    .form-label {
        font-size: 0.9rem !important;
        margin-bottom: 0.5rem !important;
    }

    /* ============================================
       MODALS - Mobile Full Screen
       ============================================ */
    .modal {
        padding: 0 !important;
    }

    .modal-content {
        width: 100% !important;
        max-width: 100% !important;
        min-height: 100vh !important;
        margin: 0 !important;
        border-radius: 0 !important;
        padding: 1rem !important;
    }

    .modal-header {
        padding-bottom: 1rem !important;
        margin-bottom: 1rem !important;
    }

    .modal-header h2 {
        font-size: 1.25rem !important;
    }

    .modal-close {
        width: 44px !important;
        height: 44px !important;
        font-size: 1.5rem !important;
    }

    .modal-body {
        padding: 0 !important;
    }

    .modal-footer {
        padding-top: 1rem !important;
        flex-direction: column !important;
        gap: 0.5rem !important;
    }

    .modal-footer .btn {
        width: 100% !important;
    }

    /* ============================================
       TABLES - Mobile Scroll
       ============================================ */
    .table-container {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }

    table {
        min-width: 600px !important;
    }

    th,
    td {
        padding: 0.75rem 0.5rem !important;
        font-size: 0.85rem !important;
    }

    /* ============================================
       CHARTS - Mobile
       ============================================ */
    .chart-container {
        width: 100% !important;
        overflow-x: auto !important;
    }

    canvas {
        max-height: 250px !important;
    }

    /* ============================================
       PAGE HEADERS - Mobile
       ============================================ */
    .page-header {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 1rem !important;
        padding: 1rem 0 !important;
    }

    .page-title {
        font-size: 1.5rem !important;
    }

    .page-subtitle {
        font-size: 0.9rem !important;
    }

    /* ============================================
       CARDS - Mobile
       ============================================ */
    .card {
        padding: 1rem !important;
        border-radius: 12px !important;
    }

    .card-header {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 0.75rem !important;
    }

    .card-title {
        font-size: 1.1rem !important;
    }

    /* ============================================
       NAVIGATION ITEMS - Mobile
       ============================================ */
    .nav-item {
        padding: 0.875rem 1rem !important;
        font-size: 0.95rem !important;
        min-height: 48px !important;
    }

    .nav-item svg {
        width: 20px !important;
        height: 20px !important;
    }

    /* ============================================
       SIDEBAR USER - Mobile
       ============================================ */
    .sidebar-user {
        padding: 0.875rem !important;
        margin-bottom: 1.5rem !important;
    }

    .sidebar-avatar {
        width: 40px !important;
        height: 40px !important;
        font-size: 1rem !important;
    }

    .sidebar-user-email {
        font-size: 0.85rem !important;
    }

    .sidebar-user-plan {
        font-size: 0.75rem !important;
    }

    /* ============================================
       ALERTS - Mobile
       ============================================ */
    .alert {
        padding: 0.875rem 1rem !important;
        font-size: 0.9rem !important;
        border-radius: 8px !important;
    }

    /* ============================================
       TABS - Mobile Scroll
       ============================================ */
    .tabs {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        flex-wrap: nowrap !important;
        gap: 0 !important;
    }

    .tab {
        flex-shrink: 0 !important;
        padding: 0.75rem 1rem !important;
        font-size: 0.85rem !important;
        white-space: nowrap !important;
    }

    /* ============================================
       DROPDOWNS - Mobile
       ============================================ */
    .dropdown-menu {
        position: fixed !important;
        left: 1rem !important;
        right: 1rem !important;
        bottom: 1rem !important;
        top: auto !important;
        max-height: 60vh !important;
        overflow-y: auto !important;
        border-radius: 12px !important;
    }

    .dropdown-item {
        padding: 0.875rem 1rem !important;
        min-height: 48px !important;
    }

    /* ============================================
       USAGE BAR - Mobile
       ============================================ */
    #usage-bar {
        width: 100% !important;
        max-width: 100% !important;
    }

    /* ============================================
       EMPTY STATES - Mobile
       ============================================ */
    .empty-state {
        padding: 2rem 1rem !important;
    }

    .empty-state h3 {
        font-size: 1.25rem !important;
    }

    .empty-state p {
        font-size: 0.9rem !important;
    }

    /* ============================================
       LOADING STATES - Mobile
       ============================================ */
    .loading-spinner {
        width: 40px !important;
        height: 40px !important;
    }

    /* ============================================
       HIDE ON MOBILE
       ============================================ */
    .hide-mobile {
        display: none !important;
    }

    .show-mobile {
        display: block !important;
    }
}

/* ============================================
   SMALL MOBILE (480px and below)
   ============================================ */
@media (max-width: 480px) {
    .main-content {
        padding: 0.75rem !important;
    }

    .stats-grid {
        grid-template-columns: 1fr !important;
    }

    .project-card-stats {
        grid-template-columns: 1fr 1fr 1fr !important;
    }

    .project-card-actions {
        flex-direction: column !important;
    }

    .project-card-actions .btn {
        width: 100% !important;
    }

    .thread-actions {
        flex-direction: column !important;
    }

    .thread-actions .btn {
        width: 100% !important;
    }

    .page-title {
        font-size: 1.25rem !important;
    }

    .modal-content {
        padding: 0.75rem !important;
    }
}

/* ============================================
   LANDSCAPE MOBILE
   ============================================ */
@media (max-width: 768px) and (orientation: landscape) {
    .mobile-app-header {
        height: 50px !important;
    }

    .main-content {
        margin-top: 50px !important;
    }

    .sidebar {
        width: 240px !important;
    }

    .modal-content {
        min-height: auto !important;
        max-height: 100vh !important;
        overflow-y: auto !important;
    }
}

/* ============================================
   HIDE MOBILE NAVIGATION ON DESKTOP
   ============================================ */
@media (min-width: 769px) {

    .mobile-main-header,
    .mobile-app-header,
    .mobile-sidebar,
    .sidebar-overlay {
        display: none !important;
    }
}

/* ============================================
   TABLET (769px - 1024px)
   ============================================ */
@media (min-width: 769px) and (max-width: 1024px) {
    .projects-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    .tools-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }
}

/* ============================================
   TOUCH DEVICE OPTIMIZATIONS
   ============================================ */
@media (hover: none) and (pointer: coarse) {

    /* Larger touch targets */
    button,
    a,
    .btn,
    input[type="button"],
    input[type="submit"] {
        min-height: 44px;
    }

    /* Remove hover effects */
    .project-card:hover,
    .tool-card:hover,
    .card:hover,
    .btn:hover {
        transform: none !important;
    }

    /* Active state feedback */
    .btn:active,
    .project-card:active,
    .nav-item:active {
        opacity: 0.8;
        transform: scale(0.98);
    }

    /* Disable text selection on buttons */
    button,
    .btn {
        -webkit-user-select: none;
        user-select: none;
    }
}

/* ============================================
   iOS SPECIFIC FIXES
   ============================================ */
@supports (-webkit-touch-callout: none) {

    /* Fix for iOS safe areas */
    .mobile-app-header {
        padding-top: env(safe-area-inset-top);
    }

    .sidebar {
        padding-bottom: env(safe-area-inset-bottom);
    }

    .modal-content {
        padding-bottom: env(safe-area-inset-bottom);
    }

    /* Fix for iOS input zoom */
    input,
    textarea,
    select {
        font-size: 16px !important;
    }
}