/**
 * Mobile Simple CSS - Pure CSS Mobile UI
 * Version: 5.4.0
 * Date: 2025-11-09
 *
 * Chỉ dùng CSS để tạo mobile UI - không cần JavaScript phức tạp
 * v5.4.0: Force show connection button, add connection to More menu
 */

@media (max-width: 768px) {

    /* ========== GLOBAL MOBILE FIXES ========== */

    /* Force hide old mobile nav elements */
    #mobile-nav-modal,
    #mobile-nav-menu-btn,
    #mobile-nav-backdrop,
    #mobile-nav-panel {
        display: none !important;
        visibility: hidden !important;
    }

    /* Header compact - FORCE minimal height */
    body > div:first-child > div:first-child,
    body > div > div > header,
    header {
        height: 48px !important;
        max-height: 48px !important;
        min-height: 48px !important;
        padding: 0.25rem 0.5rem !important;
        overflow: hidden !important;
    }

    header * {
        font-size: 0.75rem !important;
    }

    header img,
    header img[src*="logo"] {
        height: 20px !important;
        max-height: 20px !important;
    }

    #app-header-title {
        font-size: 0.75rem !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
    }

    /* Hide ALL non-essential header elements */
    #selected-device-info,
    #header-visualization,
    header .border-l,
    #network-traffic-popup,
    #data-sync-toggle-btn,
    #api-sync-timeline-btn,
    #alarm-btn,
    #alarm-container,
    #api-sync-container,
    header button:not(#connection-modal-btn):not(#user-menu-btn),
    header > div:first-child > div:not(:first-child):not(:last-child) {
        display: none !important;
        visibility: hidden !important;
    }

    /* Force show connection button */
    #connection-modal-btn {
        display: flex !important;
        visibility: visible !important;
        opacity: 1 !important;
        pointer-events: auto !important;
    }

    /* ========== BOTTOM TAB BAR ========== */

    /* Container cho các tab panels */
    #right-column-content-wrapper {
        padding-bottom: 60px !important; /* Space for bottom nav */
    }

    /* Hide desktop tab title and tab bar completely */
    #desktop-tab-title,
    #tab-bar-container,
    #tab-bar,
    #new-tab-btn,
    .tab-row,
    #breadcrumb-nav,
    #breadcrumb-container,
    .breadcrumb-navigation,
    #right-column-content-wrapper > div:first-child:not(.tab-content),
    #panel-placeholders > div > div:first-child:not(#dynamic-form-container):not(#ui-builder-panel) {
        display: none !important;
        visibility: hidden !important;
        height: 0 !important;
        max-height: 0 !important;
        overflow: hidden !important;
    }

    /* Hide dashboard view header (with breadcrumb, selector, toolbar) */
    #dashboard-view-header,
    .dashboard-header,
    #dashboard-breadcrumb,
    #dashboard-selector,
    .view-header {
        display: none !important;
        visibility: hidden !important;
        height: 0 !important;
    }

    /* Mobile Bottom Navigation Bar */
    nav#mobile-bottom-nav.mobile-bottom-nav {
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        height: 60px !important;
        max-height: 60px !important;
        min-height: 60px !important;
        background: rgba(255, 255, 255, 0.98) !important;
        backdrop-filter: blur(20px) !important;
        -webkit-backdrop-filter: blur(20px) !important;
        border-top: 1px solid rgba(0, 0, 0, 0.1) !important;
        display: flex !important;
        flex-direction: row !important;
        justify-content: space-around !important;
        align-items: center !important;
        z-index: 9999 !important;
        padding: 0 !important;
        margin: 0 !important;
        gap: 0 !important;
        box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1) !important;
    }

    html.dark nav#mobile-bottom-nav.mobile-bottom-nav,
    .dark nav#mobile-bottom-nav.mobile-bottom-nav {
        background: rgba(17, 24, 39, 0.98) !important;
        border-top-color: rgba(255, 255, 255, 0.1) !important;
    }

    /* Mobile nav buttons */
    nav#mobile-bottom-nav button.mobile-nav-btn {
        flex: 1 !important;
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        justify-content: center !important;
        gap: 0.25rem !important;
        padding: 0.5rem 0.25rem !important;
        border: none !important;
        border-radius: 0 !important;
        background: transparent !important;
        color: rgb(107, 114, 128) !important;
        font-size: 0.625rem !important;
        line-height: 1.2 !important;
        min-height: 60px !important;
        max-height: 60px !important;
        height: 60px !important;
        cursor: pointer !important;
        transition: all 0.2s ease !important;
        outline: none !important;
        -webkit-tap-highlight-color: transparent !important;
    }

    nav#mobile-bottom-nav button.mobile-nav-btn svg {
        width: 1.5rem !important;
        height: 1.5rem !important;
        min-width: 1.5rem !important;
        min-height: 1.5rem !important;
        stroke-width: 2 !important;
        flex-shrink: 0 !important;
    }

    nav#mobile-bottom-nav button.mobile-nav-btn span {
        display: block !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        max-width: 100% !important;
    }

    nav#mobile-bottom-nav button.mobile-nav-btn.active {
        color: rgb(59, 130, 246) !important;
        background: rgba(59, 130, 246, 0.1) !important;
    }

    nav#mobile-bottom-nav button.mobile-nav-btn.active svg {
        color: rgb(59, 130, 246) !important;
    }

    nav#mobile-bottom-nav button.mobile-nav-btn:hover {
        background: rgba(0, 0, 0, 0.05) !important;
    }

    html.dark nav#mobile-bottom-nav button.mobile-nav-btn,
    .dark nav#mobile-bottom-nav button.mobile-nav-btn {
        color: rgb(156, 163, 175) !important;
    }

    html.dark nav#mobile-bottom-nav button.mobile-nav-btn.active,
    .dark nav#mobile-bottom-nav button.mobile-nav-btn.active {
        color: rgb(96, 165, 250) !important;
        background: rgba(96, 165, 250, 0.1) !important;
    }

    html.dark nav#mobile-bottom-nav button.mobile-nav-btn:hover,
    .dark nav#mobile-bottom-nav button.mobile-nav-btn:hover {
        background: rgba(255, 255, 255, 0.05) !important;
    }

    /* ========== DASHBOARD TABS ========== */

    /* Hide desktop dashboard tabs */
    #dashboard-tabs-container {
        display: none !important;
    }

    /* Hide left sidebar completely on mobile */
    #left-column,
    #sidebar,
    #project-sidebar,
    .sidebar,
    nav:not(#mobile-bottom-nav) {
        display: none !important;
        width: 0 !important;
        visibility: hidden !important;
    }

    /* Main layout - full width on mobile */
    #main-layout,
    main,
    body > div,
    body > div > div {
        width: 100% !important;
        max-width: 100vw !important;
        overflow-x: hidden !important;
    }

    /* ========== MOBILE HEADER REDESIGN ========== */

    /* Ultra-minimal header: just Logo | App Title | Connection Status */
    header > div:first-child {
        display: flex !important;
        align-items: center !important;
        gap: 0.75rem !important;
        width: 100% !important;
        justify-content: space-between !important;
    }

    /* Logo - small */
    header img[src*="logo"] {
        height: 24px !important;
        max-height: 24px !important;
        order: 1 !important;
        flex-shrink: 0 !important;
    }

    /* App title - center, prominent */
    #app-header-title {
        flex: 1 !important;
        order: 2 !important;
        font-size: 0.875rem !important;
        font-weight: 600 !important;
        text-align: center !important;
        color: rgb(59, 130, 246) !important;
    }

    .dark #app-header-title {
        color: rgb(96, 165, 250) !important;
    }

    /* Connection status - last item */
    #connection-modal-btn {
        order: 3 !important;
        padding: 0.375rem !important;
        flex-shrink: 0 !important;
    }

    #connection-modal-btn svg {
        width: 20px !important;
        height: 20px !important;
    }

    /* Hide ALL other header items */
    #dashboard-selector-container,
    #user-menu-container,
    #status-led,
    header > div:last-child,
    header .flex.items-center.gap-3 {
        display: none !important;
        visibility: hidden !important;
    }

    /* ========== CONTENT AREA ========== */

    #main-content {
        padding: 0 !important;
        height: calc(100vh - 48px - 60px) !important; /* viewport - header - bottom nav */
        overflow-x: hidden !important;
        overflow-y: auto !important;
    }

    #right-column {
        padding: 0.25rem !important;
        width: 100% !important;
        max-width: 100vw !important;
        overflow-x: hidden !important;
    }

    #right-column-content-wrapper {
        padding: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        overflow-x: hidden !important;
    }

    /* Tab content */
    .tab-content {
        padding: 0.5rem !important;
        width: 100% !important;
        max-width: 100% !important;
        overflow-x: hidden !important;
    }

    /* ========== DASHBOARD TOOLBAR ========== */

    /* Hide entire dashboard toolbar and all navigation elements on mobile */
    #dashboard-toolbar,
    .dashboard-toolbar,
    #dashboard-controls,
    .widget-toolbox,
    #widget-toolbox,
    #add-widget-btn,
    #dashboard-settings-btn,
    #dashboard-header-controls,
    .dashboard-actions,
    .toolbar-container,
    #dashboard-tabs,
    #dashboard-tabs-wrapper,
    .view-toolbar,
    .dashboard-breadcrumb-container,
    #enhanced-header,
    .enhanced-header,
    #view-dashboard-toolbar,
    #dashboard-action-buttons,
    .chart-controls {
        display: none !important;
        visibility: hidden !important;
        height: 0 !important;
        max-height: 0 !important;
        overflow: hidden !important;
        padding: 0 !important;
        margin: 0 !important;
    }

    /* Create mobile FAB (Floating Action Button) for dashboard actions */
    #mobile-dashboard-fab {
        position: fixed !important;
        bottom: 80px !important; /* Above bottom nav */
        right: 1rem !important;
        width: 56px !important;
        height: 56px !important;
        border-radius: 50% !important;
        background: rgb(59, 130, 246) !important;
        color: white !important;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3) !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        z-index: 999 !important;
        cursor: pointer !important;
        border: none !important;
        outline: none !important;
    }

    .dark #mobile-dashboard-fab {
        background: rgb(96, 165, 250) !important;
    }

    #mobile-dashboard-fab svg {
        width: 24px !important;
        height: 24px !important;
    }

    /* ========== WIDGETS ========== */

    .grid-stack {
        margin: 0 !important;
        padding: 0 0.5rem !important;
        width: 100% !important;
        max-width: 100% !important;
    }

    .grid-stack-item {
        margin-bottom: 0.5rem !important;
        width: 100% !important;
        max-width: 100% !important;
        left: 0 !important;
        right: 0 !important;
    }

    .grid-stack-item-content {
        width: 100% !important;
        max-width: 100% !important;
        overflow-x: hidden !important;
    }

    /* Widget container - force single column */
    .widget-container {
        min-height: 150px !important;
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        box-sizing: border-box !important;
    }

    /* Widget canvas */
    .widget-canvas,
    canvas {
        max-width: 100% !important;
        width: 100% !important;
        height: auto !important;
    }

    /* ========== MODALS ========== */

    /* Full screen modals */
    .modal-dialog,
    [id$="-modal"] > div:first-child {
        max-width: 100vw !important;
        margin: 0 !important;
        border-radius: 0 !important;
    }

    .modal-body {
        padding: 1rem !important;
    }

    /* ========== FORMS & INPUTS ========== */

    input[type="text"],
    input[type="number"],
    input[type="password"],
    select,
    textarea {
        font-size: 16px !important; /* Prevent iOS zoom */
    }

    button {
        min-height: 44px !important; /* Touch target */
    }

    /* ========== HIDE ELEMENTS ========== */

    /* Hide widget toolbox by default */
    #widget-toolbox {
        display: none !important;
    }

    /* Hide desktop-only elements */
    .desktop-only {
        display: none !important;
    }

    /* ========== SCROLLBAR ========== */

    *::-webkit-scrollbar {
        width: 3px !important;
        height: 3px !important;
    }

    *::-webkit-scrollbar-thumb {
        background: rgba(156, 163, 175, 0.3) !important;
    }
}

/* ========== VERY SMALL MOBILE ========== */

@media (max-width: 390px) {
    .tab-navigation button,
    .tab-navigation .tab-btn {
        font-size: 0.5625rem !important;
        gap: 0.125rem !important;
    }

    .tab-navigation button svg,
    .tab-navigation .tab-btn svg {
        width: 1.25rem !important;
        height: 1.25rem !important;
    }
}
