/**
 * Mobile Responsive Styles
 * Common mobile optimizations for all templates
 */

/* CSS Variables for safe areas */
:root {
    --safe-area-inset-top: env(safe-area-inset-top, 0px);
    --safe-area-inset-bottom: env(safe-area-inset-bottom, 0px);
    --safe-area-inset-left: env(safe-area-inset-left, 0px);
    --safe-area-inset-right: env(safe-area-inset-right, 0px);
}

/* Base mobile optimizations */
* {
    -webkit-tap-highlight-color: transparent;
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
}

body {
    min-height: 100vh;
    min-height: 100dvh;
    padding-top: var(--safe-area-inset-top);
    padding-bottom: var(--safe-area-inset-bottom);
    padding-left: var(--safe-area-inset-left);
    padding-right: var(--safe-area-inset-right);
    overflow-x: hidden;
    overscroll-behavior-y: none;
}

/* Touch-friendly buttons */
.btn {
    min-height: 44px;
    touch-action: manipulation;
}

.btn-sm {
    min-height: 36px;
}

.btn-lg {
    min-height: 52px;
}

/* Touch-friendly form controls */
.form-control,
.form-select {
    min-height: 44px;
    font-size: 16px !important; /* Prevents iOS zoom on focus */
    touch-action: manipulation;
}

/* Prevent auto-scroll to focused inputs on page load */
input:not(:focus),
select:not(:focus),
textarea:not(:focus) {
    scroll-margin-top: 0;
    scroll-margin-bottom: 0;
}

/* When user explicitly focuses - allow normal scroll behavior */
input:focus,
select:focus,
textarea:focus {
    scroll-margin-top: 100px;
}

/* Improved touch targets for navbar */
.navbar-toggler {
    min-width: 44px;
    min-height: 44px;
    padding: 8px;
}

.nav-link {
    padding: 12px 16px !important;
}

/* Improved dropdown touch targets */
.dropdown-item {
    padding: 12px 16px;
}

/* Card improvements for mobile */
.card {
    overflow: hidden;
}

/* Progress bar improvements */
.progress {
    min-height: 20px;
}

/* Table responsive improvements */
.table-responsive {
    -webkit-overflow-scrolling: touch;
}

/* ============================================
   TABLET STYLES (576px - 991px)
   ============================================ */
@media (min-width: 576px) and (max-width: 991px) {
    .dashboard-container {
        padding: 15px;
    }

    .header-card {
        padding: 25px 20px;
    }

    .header-card h1 {
        font-size: 1.8rem;
    }

    .stat-box h3 {
        font-size: 1.8rem;
    }

    /* Two column layout for stats on tablet */
    .stats-card .row .col-md-3,
    .stats-card .row .col-md-4 {
        flex: 0 0 50%;
        max-width: 50%;
        margin-bottom: 15px;
    }
}

/* ============================================
   TABLET STYLES for content-container
   ============================================ */
@media (max-width: 991px) {
    .content-container {
        flex-direction: column;
    }

    .control-card {
        flex: 1 1 auto;
        width: 100%;
    }
}

/* ============================================
   MOBILE STYLES (< 576px)
   ============================================ */
@media (max-width: 575px) {
    body {
        padding: 10px;
    }

    .dashboard-container {
        padding: 0;
    }

    .control-card {
        padding: 15px;
        border-radius: 12px;
    }

    .control-card h5 {
        font-size: 1rem;
        margin-bottom: 15px;
    }

    /* Header adjustments */
    .header-card {
        padding: 20px 15px;
        border-radius: 12px;
        margin-bottom: 15px;
    }

    .header-card h1 {
        font-size: 1.4rem;
        margin-bottom: 8px;
    }

    .header-card p {
        font-size: 0.9rem;
    }

    /* Navbar mobile adjustments */
    .navbar-custom {
        padding: 10px 12px;
        border-radius: 12px;
        margin-bottom: 15px;
    }

    .navbar-brand {
        font-size: 1rem;
    }

    .navbar-collapse {
        margin-top: 10px;
    }

    .navbar-nav {
        gap: 5px;
    }

    .nav-link {
        padding: 10px 12px !important;
        font-size: 0.9rem;
        border-radius: 8px;
    }

    /* Cards mobile adjustments */
    .card {
        border-radius: 12px;
        margin-bottom: 15px;
    }

    .card-header {
        padding: 12px 15px;
        font-size: 0.95rem;
    }

    .card-header h5 {
        font-size: 1rem;
    }

    .card-body {
        padding: 15px;
    }

    /* Stats boxes - single column on mobile */
    .stats-card .row .col-md-3,
    .stats-card .row .col-md-4,
    .stats-card .col-md-3,
    .stats-card .col-md-4 {
        flex: 0 0 100%;
        max-width: 100%;
        margin-bottom: 10px;
    }

    .stat-box {
        padding: 15px;
        margin: 5px 0;
    }

    .stat-box h3 {
        font-size: 1.5rem;
    }

    .stat-box p {
        font-size: 0.85rem;
    }

    /* Buttons full width on mobile */
    .btn-test,
    .btn-primary,
    .btn-secondary {
        width: 100%;
        margin-bottom: 8px;
    }

    .d-flex.gap-2 {
        flex-direction: column;
    }

    .d-flex.gap-2 > * {
        width: 100%;
    }

    /* Form adjustments */
    .form-control,
    .form-select {
        padding: 12px;
    }

    .form-label {
        font-size: 0.9rem;
        margin-bottom: 6px;
    }

    .mb-3 {
        margin-bottom: 1rem !important;
    }

    /* Progress bars */
    .progress {
        height: 18px;
        border-radius: 6px;
    }

    /* Tables */
    .table {
        font-size: 0.85rem;
    }

    .table th,
    .table td {
        padding: 8px 10px;
    }

    /* Telemetry grid adjustments */
    .telemetry-grid {
        grid-template-columns: 1fr !important;
        gap: 12px;
    }

    .telemetry-card {
        padding: 12px;
    }

    .telemetry-card h6 {
        font-size: 0.9rem;
    }

    /* GPIO pinout responsive */
    .gpio-pinout-css {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .gpio-grid {
        min-width: min(500px, calc(100vw - 40px));
    }

    .gpio-pin {
        min-width: 50px;
        font-size: 0.7rem;
    }

    /* RC channels responsive */
    .rc-channels {
        grid-template-columns: repeat(4, 1fr) !important;
        gap: 6px;
    }

    .rc-channels-16 {
        grid-template-columns: repeat(4, 1fr) !important;
    }

    .rc-channel {
        padding: 10px 8px;
        font-size: 0.75rem;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* Module cards */
    .module-card {
        padding: 12px;
    }

    .module-card h5 {
        font-size: 0.95rem;
    }

    /* Test output */
    .test-output {
        font-size: 0.8rem;
        max-height: 300px;
    }

    /* Telemetry console mobile - prevent page scroll */
    .telemetry-console {
        max-height: 250px;
        font-size: 0.75rem;
        padding: 12px;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
    }

    /* Dropdown menus */
    .dropdown-menu {
        width: calc(100vw - 24px);
        max-width: 300px;
    }

    /* IP Addresses dropdown */
    #ipAddressesList {
        min-width: auto !important;
        width: min(280px, calc(100vw - 48px));
        max-width: 300px;
    }

    /* Hidden cards dropdown */
    .hidden-cards-dropdown {
        flex-direction: column;
        gap: 8px;
    }

    .hidden-cards-dropdown select {
        width: 100%;
    }

    /* Alert boxes */
    .alert {
        padding: 12px;
        font-size: 0.9rem;
    }

    /* Ensure minimum readable font size on mobile for inline-styled elements */
    .telemetry-card [style*="font-size: 11px"],
    .telemetry-card [style*="font-size: 9px"] {
        font-size: 12px !important;
    }

    /* Hotspot controls */
    .hotspot-config .row {
        flex-direction: column;
    }

    .hotspot-config .col-md-6 {
        width: 100%;
        margin-bottom: 10px;
    }

    /* NAT diagram mobile */
    .nat-diagram .row {
        flex-direction: column;
    }

    .nat-diagram .col-md-2,
    .nat-diagram .col-md-3 {
        width: 100%;
        margin-bottom: 10px;
    }

    .nat-diagram .col-md-1 {
        display: none !important;
    }

    .nat-node {
        padding: 12px;
    }

    /* Video player */
    #thermalVideoPlayer {
        width: 100%;
        height: auto;
    }

    /* Thermal controls */
    .thermal-controls-section {
        padding: 10px;
    }

    .thermal-controls {
        width: 100%;
    }

    /* Coverage bar */
    .coverage-bar {
        height: 20px;
    }

    .coverage-fill {
        font-size: 0.75rem;
    }
}

/* ============================================
   EXTRA SMALL SCREENS (< 400px)
   ============================================ */
@media (max-width: 399px) {
    body {
        padding: 8px;
    }

    .card {
        border-radius: 10px;
        margin-bottom: 12px;
    }

    .card-header {
        padding: 10px 12px;
        font-size: 0.9rem;
    }

    .card-body {
        padding: 12px;
    }

    /* RC channels - 3 columns instead of 4 */
    .rc-channels,
    .rc-channels-16 {
        grid-template-columns: repeat(3, 1fr) !important;
        gap: 4px;
    }

    /* Telemetry - single column */
    .telemetry-grid {
        grid-template-columns: 1fr !important;
    }

    /* GPIO compact */
    .gpio-grid {
        min-width: min(360px, calc(100vw - 30px));
        padding: 0 6px;
    }

    /* Dropdowns */
    #ipAddressesList {
        width: calc(100vw - 20px);
        max-width: 260px;
    }

    .dropdown-menu {
        width: calc(100vw - 20px);
        max-width: 260px;
    }

    /* Compact header */
    .header-card {
        padding: 15px 12px;
    }

    .header-card h1 {
        font-size: 1.3rem;
    }

    /* Buttons */
    .btn {
        font-size: 0.9rem;
        padding: 10px 16px;
    }
}

/* ============================================
   LANDSCAPE MOBILE (height < 500px)
   ============================================ */
@media (max-height: 500px) and (orientation: landscape) {
    body {
        padding: 5px;
    }

    .header-card {
        padding: 10px 15px;
        margin-bottom: 10px;
    }

    .header-card h1 {
        font-size: 1.2rem;
        margin-bottom: 4px;
    }

    .header-card p {
        font-size: 0.8rem;
        margin: 0;
    }

    .navbar-custom {
        padding: 8px 12px;
        margin-bottom: 10px;
    }

    .card {
        margin-bottom: 10px;
    }

    .card-header {
        padding: 8px 12px;
    }

    .card-body {
        padding: 10px;
    }

    .stat-box {
        padding: 10px;
    }

    .stat-box h3 {
        font-size: 1.2rem;
    }

    .stat-box p {
        font-size: 0.75rem;
        margin: 0;
    }

    /* Two columns for stats in landscape */
    .stats-card .row .col-md-3,
    .stats-card .row .col-md-4 {
        flex: 0 0 50%;
        max-width: 50%;
    }

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

/* ============================================
   PRINT STYLES
   ============================================ */
@media print {
    body {
        padding: 0;
        background: white;
    }

    .navbar-custom,
    .btn,
    .hidden-cards-dropdown {
        display: none !important;
    }

    .card {
        break-inside: avoid;
        box-shadow: none;
        border: 1px solid #ddd;
    }
}
