
/* ============================================================================ */
/* MOBILE OPTIMIZATION - Comprehensive Mobile-First Design */
/* ============================================================================ */

/* Mobile Base Styles */
@media screen and (max-width: 768px) {

    /* Base Typography with Safe Area */
    body {
        font-size: 14px;
        line-height: 1.5;
        overflow-x: hidden;
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
        padding-left: env(safe-area-inset-left);
        padding-right: env(safe-area-inset-right);
    }

    /* Container Adjustments */
    .container {
        padding: 10px;
        width: 100%;
        max-width: 100%;
    }

    /* Header Mobile with Safe Area */
    .header {
        padding: max(15px, env(safe-area-inset-top)) 10px 15px 10px;
        flex-wrap: wrap;
    }

    .logo {
        font-size: 18px;
        margin-bottom: 10px;
        width: 100%;
        text-align: center;
    }

    /* Navigation - Mobile Hamburger Style */
    .nav {
        width: 100%;
        flex-direction: column;
        gap: 5px;
    }

    .nav-link {
        padding: 12px 15px;
        font-size: 13px;
        width: 100%;
        text-align: center;
        border-bottom: 1px solid #00ff00;
    }

    .nav-link:last-child {
        border-bottom: none;
    }

    /* Stats Bar - Stack Vertically */
    .stats-bar {
        flex-direction: column;
        gap: 10px;
    }

    .stat-item {
        width: 100%;
        padding: 15px;
    }

    .stat-label {
        font-size: 11px;
    }

    .stat-value {
        font-size: 20px;
    }

    /* Search Container */
    .search-container {
        flex-direction: column;
        gap: 10px;
    }

    .search-input {
        width: 100%;
        font-size: 16px !important; /* Prevent iOS zoom */
        padding: 15px;
    }

    .btn {
        width: 100%;
        padding: 15px;
        font-size: 14px;
    }

    .btn-small {
        padding: 10px 12px;
        font-size: 11px;
        white-space: nowrap;
    }

    /* Table Container - Horizontal Scroll */
    .table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin: 0 -10px;
        padding: 0 10px;
    }

    .table-header {
        flex-direction: column;
        gap: 10px;
        align-items: flex-start;
    }

    .table-header h2 {
        font-size: 16px;
    }

    /* Data Table - Card Layout for Mobile */
    .data-table {
        min-width: 100%;
        font-size: 12px;
        display: block;
    }

    .data-table thead {
        display: none;
    }

    .data-table tbody {
        display: block;
    }

    .data-table tr {
        display: block;
        margin-bottom: 15px;
        border: 2px solid #00ff00;
        background: #1a1a2e;
        padding: 15px;
        position: relative;
    }

    .data-table td {
        display: block;
        text-align: left !important;
        padding: 8px 0;
        border: none;
        position: relative;
        padding-left: 50%;
    }

    .data-table td:before {
        content: attr(data-label);
        position: absolute;
        left: 0;
        width: 45%;
        padding-right: 10px;
        font-weight: bold;
        color: #00ff66;
        text-align: left;
    }

    .data-table td:first-child {
        border-top: 2px solid #00ff00;
        padding-top: 12px;
    }

    /* Horizontal Scroll Table Alternative */
    .data-table.scroll-table {
        display: table;
        width: 100%;
        min-width: 800px;
    }

    .data-table.scroll-table thead {
        display: table-header-group;
    }

    .data-table.scroll-table tbody {
        display: table-row-group;
    }

    .data-table.scroll-table tr {
        display: table-row;
        border: none;
        margin: 0;
        padding: 0;
    }

    .data-table.scroll-table td {
        display: table-cell;
        padding: 12px 8px;
    }

    .data-table.scroll-table td:before {
        display: none;
    }

    /* Forms - Mobile Friendly */
    .form-group {
        margin-bottom: 20px;
    }

    .form-input,
    input[type="text"],
    input[type="password"],
    input[type="email"],
    textarea,
    select {
        width: 100%;
        padding: 15px;
        font-size: 16px !important;
    }

    /* User Info Bar */
    .user-info-bar {
        flex-direction: column;
        gap: 10px;
        padding: 15px 10px;
    }

    .user-info,
    .live-status {
        width: 100%;
        justify-content: center;
    }

    /* Login Container */
    .login-container {
        padding: 10px;
    }

    .login-box {
        padding: 25px 20px;
        max-width: 100%;
    }

    .login-logo {
        font-size: 24px;
    }

    /* Footer with Safe Area */
    .footer {
        padding: 20px 10px max(20px, env(safe-area-inset-bottom)) 10px;
        font-size: 11px;
    }

    /* No Data Message */
    .no-data {
        padding: 30px 15px;
    }

    .no-data p {
        font-size: 14px;
    }

    /* Auto Refresh */
    .auto-refresh {
        font-size: 11px;
    }

    /* Analytics Grid */
    .analytics-grid {
        grid-template-columns: 1fr !important;
        gap: 15px;
    }

    .analytics-card {
        padding: 20px 15px;
    }

    /* Database Viewer */
    .db-controls {
        flex-direction: column;
        gap: 10px;
    }

    .db-controls .btn {
        width: 100%;
    }

    /* Source Detail */
    .source-header {
        flex-direction: column;
        gap: 10px;
    }

    .source-info {
        width: 100%;
    }

    /* Filters */
    .filters {
        flex-direction: column;
        gap: 10px;
    }

    .filter-group {
        width: 100%;
    }

    /* Modal Adjustments */
    .modal-content {
        width: 95%;
        max-width: 95%;
        padding: 20px 15px;
    }

    /* Scrollbar Styling for Mobile */
    .table-container::-webkit-scrollbar {
        height: 8px;
    }

    .table-container::-webkit-scrollbar-track {
        background: #0a0e27;
    }

    .table-container::-webkit-scrollbar-thumb {
        background: #00ff00;
        border-radius: 4px;
    }

    /* Touch Feedback */
    .btn:active,
    .nav-link:active,
    button:active,
    a:active {
        transform: scale(0.98);
        opacity: 0.8;
    }

    /* File Upload */
    .upload-area {
        padding: 30px 15px;
        min-height: 150px;
    }

    /* Charts */
    .chart-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    canvas {
        max-width: 100%;
        height: auto !important;
    }
}

/* Extra Small Mobile (320px - 480px) */
@media screen and (max-width: 480px) {

    body {
        font-size: 13px;
    }

    .logo {
        font-size: 16px;
    }

    .nav-link {
        font-size: 12px;
        padding: 10px;
    }

    .stat-value {
        font-size: 18px;
    }

    .stat-label {
        font-size: 10px;
    }

    .data-table {
        font-size: 11px;
    }

    .btn-small {
        font-size: 10px;
        padding: 8px 10px;
    }

    .login-logo {
        font-size: 20px;
    }

    .login-box {
        padding: 20px 15px;
    }
}

/* Tablet Portrait (768px - 1024px) */
@media screen and (min-width: 769px) and (max-width: 1024px) {

    .container {
        padding: 20px;
    }

    .stats-bar {
        grid-template-columns: repeat(2, 1fr);
    }

    .data-table {
        font-size: 13px;
    }

    .nav {
        flex-direction: row;
        flex-wrap: wrap;
    }

    .nav-link {
        width: auto;
        min-width: 120px;
    }
}

/* Landscape Mobile (Small Height) */
@media screen and (max-height: 500px) and (orientation: landscape) {

    .login-container {
        min-height: auto;
        padding: 20px 10px;
    }

    .header {
        padding: 10px;
    }

    .stats-bar {
        display: none;
    }
}

/* Touch Device Optimizations */
@media (hover: none) and (pointer: coarse) {

    .btn,
    .nav-link,
    a,
    button {
        min-height: 44px;
        min-width: 44px;
    }

    .btn:hover,
    .nav-link:hover {
        transform: none;
    }

    * {
        -webkit-overflow-scrolling: touch;
    }
}

/* Reduced Motion Support */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Print Styles */
@media print {
    .header,
    .nav,
    .footer,
    .search-container,
    .btn {
        display: none;
    }

    .data-table {
        page-break-inside: avoid;
    }

    body {
        background: white;
        color: black;
    }
}

/* Hide on Mobile */
@media screen and (max-width: 768px) {
    .hide-mobile {
        display: none !important;
    }
}

/* Show only on Mobile */
.show-mobile {
    display: none;
}

@media screen and (max-width: 768px) {
    .show-mobile {
        display: block;
    }
}

/* Responsive Images */
img {
    max-width: 100%;
    height: auto;
}

/* Responsive Iframes */
iframe {
    max-width: 100%;
}
