:root {
            --sidebar-width: 260px;
            --sidebar-collapsed: 80px;
            --header-height: 64px;
            --safe-top: env(safe-area-inset-top, 47px);
            --safe-bottom: env(safe-area-inset-bottom, 34px);
            --safe-left: env(safe-area-inset-left, 0px);
            --safe-right: env(safe-area-inset-right, 0px);
            --primary: #3b82f6;
            --primary-dark: #1d4ed8;
            --success: #22c55e;
            --warning: #f59e0b;
            --danger: #ef4444;
            --bg-dark: #0f172a;
            --bg-card: #1e293b;
            --bg-hover: #334155;
            --border: #334155;
            --text: #f8fafc;
            --text-muted: #94a3b8;
            --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        }

        * { margin: 0; padding: 0; box-sizing: border-box; }

        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
            background: var(--bg-dark);
            color: var(--text);
            min-height: 100vh;
            overflow-x: hidden;
        }

        /* ===== SIDEBAR ===== */
        .sidebar {
            position: fixed;
            left: 0;
            top: 0;
            bottom: 0;
            width: var(--sidebar-width);
            background: var(--bg-card);
            border-right: 1px solid var(--border);
            z-index: 1000;
            transition: var(--transition);
            display: flex;
            flex-direction: column;
        }

        .sidebar.collapsed { width: var(--sidebar-collapsed); }

        .sidebar-header {
            height: var(--header-height);
            display: flex;
            align-items: center;
            padding: 0 16px;
            border-bottom: 1px solid var(--border);
            gap: 12px;
            position: relative;
            min-height: 64px;
        }
        
        .sidebar.collapsed .sidebar-header {
            padding: 0;
            justify-content: center;
            min-height: 80px;
        }

        .logo {
            display: flex;
            align-items: center;
            gap: 12px;
            flex: 1;
            min-width: 0;
        }
        
        .sidebar.collapsed .logo {
            justify-content: center;
            flex: 0;
            padding: 0;
            width: 100%;
        }
        
        .sidebar.collapsed .logo img {
            width: 32px;
            height: 32px;
            margin: 0 auto;
        }

        .logo-icon {
            width: 40px;
            height: 40px;
            background: linear-gradient(135deg, var(--primary), #8b5cf6);
            border-radius: 10px;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 20px;
            flex-shrink: 0;
        }

        .logo-text {
            font-size: 18px;
            font-weight: 700;
            background: linear-gradient(135deg, var(--text), var(--text-muted));
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            white-space: normal;
            overflow: visible;
            line-height: 1.2;
            display: flex;
            flex-direction: column;
        }
        
        .logo-beta {
            font-size: 11px;
            color: var(--text-muted);
            -webkit-text-fill-color: var(--text-muted);
            font-weight: 500;
            letter-spacing: 0.5px;
        }

        .sidebar.collapsed .logo-text { display: none; }
        
        /* Toggle button - hamburger when expanded, right arrow when collapsed */
        .toggle-btn {
            pointer-events: auto !important;
            z-index: 1010 !important;
            width: 36px;
            height: 36px;
            border: none;
            background: transparent;
            color: var(--text-muted);
            cursor: pointer;
            display: flex;
            align-items: center;
            justify-content: center;
            border-radius: 8px;
            transition: var(--transition);
            padding: 0;
            position: relative;
            z-index: 1010;
        }
        
        .toggle-btn svg {
            width: 20px;
            height: 20px;
            stroke: currentColor;
            fill: none;
        }
        
        .toggle-btn:hover { 
            background: var(--bg-hover); 
            color: var(--text); 
        }
        
        /* When sidebar is collapsed, show toggle as a nav-like icon */
        .sidebar.collapsed .toggle-btn {
            pointer-events: auto !important;
            z-index: 1010 !important;
            pointer-events: auto !important;
            cursor: pointer !important;
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            width: 40px;
            height: 40px;
            background: transparent !important;
            border-radius: 10px;
            display: flex;
            z-index: 1010;
            cursor: pointer;
            pointer-events: auto !important;
        }
        
        .sidebar.collapsed .toggle-btn:hover,
        .sidebar.collapsed .toggle-btn:focus,
        .sidebar.collapsed .toggle-btn:active {
            background: transparent !important;
            outline: none;
            box-shadow: none;
        }
        
        .sidebar.collapsed .sidebar-header {
            position: relative;
            min-height: var(--header-height);
            height: var(--header-height);
            display: flex;
            align-items: center;
            justify-content: center;
            flex-direction: column;
            padding: 0;
        }
        
        .sidebar.collapsed .toggle-btn svg {
            width: 24px;
            height: 24px;
        }
        
        /* Icon visibility based on sidebar state */
        .sidebar .toggle-btn .hamburger-icon { display: block; }
        .sidebar .toggle-btn .arrow-icon { display: none; }
        
        .sidebar.collapsed .toggle-btn .hamburger-icon { display: none; }
        .sidebar.collapsed .toggle-btn .arrow-icon { display: block; }

        .sidebar-nav {
            flex: 1;
            padding: 16px 12px;
            overflow-y: auto;
        }

        .nav-section { margin-bottom: 8px; }

        .nav-section-title {
            font-size: 10px;
            text-transform: uppercase;
            color: var(--text-muted);
            padding: 8px 12px;
            letter-spacing: 0.5px;
            font-weight: 600;
        }

        .sidebar.collapsed .nav-section-title { display: none; }

        .nav-item {
            display: flex;
            align-items: center;
            padding: 12px;
            margin-bottom: 4px;
            border-radius: 10px;
            color: var(--text-muted);
            text-decoration: none;
            transition: var(--transition);
            cursor: pointer;
            gap: 12px;
        }

        .nav-item:hover { background: rgba(59, 130, 246, 0.1); color: var(--text); }
        .nav-item.active { background: var(--primary); color: white; }

        .nav-icon {
            font-size: 22px;
            width: 28px;
            height: 28px;
            text-align: center;
            flex-shrink: 0;
            display: flex;
            align-items: center;
            justify-content: center;
        }

        .nav-icon-container {
            position: relative;
            width: 28px;
            height: 28px;
            display: flex;
            align-items: center;
            justify-content: center;
            flex-shrink: 0;
        }

        .nav-text {
            font-size: 14px;
            font-weight: 500;
            white-space: nowrap;
            overflow: hidden;
        }

        .sidebar.collapsed .nav-text { display: none; }

        .sidebar.collapsed .nav-item {
            justify-content: center;
            padding: 12px 0;
        }

        .sidebar.collapsed .nav-icon,
        .sidebar.collapsed .nav-icon-container {
            margin: 0 auto;
        }

        .nav-badge {
            position: absolute;
            top: -6px;
            right: -6px;
            background: var(--danger);
            color: white;
            font-size: 10px;
            min-width: 18px;
            height: 18px;
            padding: 0 4px;
            border-radius: 9px;
            display: flex;
            align-items: center;
            justify-content: center;
            font-weight: 600;
            border: 2px solid var(--bg-card);
            box-shadow: 0 2px 4px rgba(0,0,0,0.2);
            z-index: 10;
        }

        .sidebar.collapsed .nav-badge { display: none; }

        .sidebar-footer {
            padding: 16px 12px;
            border-top: 1px solid var(--border);
        }

        .user-info {
            display: flex;
            align-items: center;
            gap: 12px;
            padding: 8px;
            border-radius: 10px;
            cursor: pointer;
        }

        .user-info:hover { background: var(--bg-hover); }

        .user-avatar {
            width: 36px;
            height: 36px;
            background: linear-gradient(135deg, var(--primary), #8b5cf6);
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 16px;
            flex-shrink: 0;
        }

        .user-details { min-width: 0; }
        .sidebar.collapsed .user-details { display: none; }

        .user-name {
            font-size: 13px;
            font-weight: 600;
            white-space: nowrap;
            overflow: hidden;
        }

        .user-role {
            font-size: 11px;
            color: var(--text-muted);
        }

        /* ===== MAIN LAYOUT ===== */
        .main-wrapper {
            margin-left: var(--sidebar-width);
            min-height: 100vh;
            transition: var(--transition);
        }

        .sidebar.collapsed ~ .main-wrapper { margin-left: var(--sidebar-collapsed); }

        /* ===== TOP BAR ===== */
        .top-bar {
            min-height: var(--header-height);
            height: auto;
            background: var(--bg-card);
            border-bottom: 1px solid var(--border);
            display: flex;
            align-items: center;
            flex-wrap: wrap;
            padding: 8px 24px;
            gap: 12px;
            position: sticky;
            top: 0;
            z-index: 100;
        }

        .page-title {
            font-size: 20px;
            font-weight: 600;
            min-width: 150px;
            flex-shrink: 0;
        }

        .global-filters {
            display: flex;
            align-items: center;
            gap: 16px;
            flex: 1;
            justify-content: center;
            flex-wrap: wrap;
            min-width: 300px;
        }

        .filter-group {
            display: flex;
            align-items: center;
            gap: 8px;
            flex-shrink: 0;
        }

        .filter-label {
            font-size: 11px;
            color: var(--text-muted);
            text-transform: uppercase;
            letter-spacing: 0.5px;
            font-weight: 600;
        }

        .filter-select {
            background: var(--bg-dark);
            border: 1px solid var(--border);
            color: var(--text);
            padding: 8px 12px;
            border-radius: 8px;
            font-size: 13px;
            min-width: 140px;
            cursor: pointer;
        }

        .top-actions {
            display: flex;
            align-items: center;
            gap: 12px;
        }

        .icon-btn {
            width: 40px;
            height: 40px;
            border: none;
            background: var(--bg-dark);
            color: var(--text-muted);
            font-size: 20px;
            border-radius: 10px;
            cursor: pointer;
            display: flex;
            align-items: center;
            justify-content: center;
            transition: var(--transition);
        }

        .icon-btn:hover { background: var(--bg-hover); color: var(--text); }
        .icon-btn.active { background: var(--primary); color: white; }

        /* ===== MAIN CONTENT ===== */
        .main-content {
            padding: 24px;
            min-height: calc(100vh - var(--header-height));
            overflow-y: auto;
            -webkit-overflow-scrolling: touch;
        }

        /* ===== PAGE VIEWS ===== */
        .page-view { display: none; }
        .page-view.active { display: block; }

        /* ===== CARDS ===== */
        .card {
            background: var(--bg-card);
            border-radius: 16px;
            border: 1px solid var(--border);
            overflow: hidden;
        }

        .card-header {
            padding: 20px 24px;
            border-bottom: 1px solid var(--border);
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .card-title {
            font-size: 16px;
            font-weight: 600;
            display: flex;
            align-items: center;
            gap: 8px;
        }

        .card-body { padding: 24px; }

        /* ===== STATS GRID ===== */
        .stats-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
            gap: 20px;
            margin-bottom: 24px;
        }

        .stat-card {
            background: var(--bg-card);
            border-radius: 16px;
            padding: 16px;
            border: 1px solid var(--border);
            transition: var(--transition);
            display: flex;
            flex-direction: column;
            min-height: 140px;
        }

        .stat-card:hover { transform: translateY(-2px); border-color: var(--primary); }

        .stat-card.disabled {
            opacity: 0.4;
            pointer-events: none;
            filter: grayscale(0.5);
        }

        /* Inactive tiles for non-relevant standard parameters */
        .stat-card.standard-inactive {
            opacity: 0.5;
            filter: grayscale(100%);
            border-color: var(--border) !important;
        }
        .stat-card.standard-inactive .stat-title,
        .stat-card.standard-inactive .stat-value,
        .stat-card.standard-inactive .stat-unit,
        .stat-card.standard-inactive .stat-updated {
            color: var(--text-muted) !important;
        }

        .stat-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 12px;
        }

        .stat-title {
            font-size: 13px;
            font-weight: 600;
            color: var(--text-muted);
            text-transform: uppercase;
            letter-spacing: 0.5px;
        }

        .stat-icon {
            width: 32px;
            height: 32px;
            border-radius: 8px;
            display: flex;
            align-items: center;
            justify-content: center;
        }

        .stat-icon img {
            width: 20px;
            height: 20px;
            object-fit: contain;
        }

        .stat-icon.blue { background: rgba(59, 130, 246, 0.2); }
        .stat-icon.green { background: rgba(34, 197, 94, 0.2); }
        .stat-icon.orange { background: rgba(245, 158, 11, 0.2); }
        .stat-icon.red { background: rgba(239, 68, 68, 0.2); }
        .stat-icon.purple { background: rgba(168, 85, 247, 0.2); }

        .stat-reading {
            flex: 1;
            display: flex;
            align-items: baseline;
            gap: 6px;
            margin-bottom: 12px;
        }

        .stat-value {
            font-size: 36px;
            font-weight: 700;
            line-height: 1;
        }

        .stat-unit {
            font-size: 14px;
            color: var(--text-muted);
            font-weight: 500;
        }

        .stat-trend {
            font-size: 11px;
            font-weight: 600;
            padding: 3px 6px;
            border-radius: 4px;
        }

        .stat-trend.up { background: rgba(34, 197, 94, 0.2); color: var(--success); }
        .stat-trend.down { background: rgba(239, 68, 68, 0.2); color: var(--danger); }

        .stat-updated {
            font-size: 11px;
            color: var(--text-muted);
            display: flex;
            align-items: center;
            gap: 4px;
        }

        .stat-updated::before {
            content: '';
            width: 6px;
            height: 6px;
            background: var(--success);
            border-radius: 50%;
            animation: pulse 2s infinite;
        }

        @keyframes pulse {
            0%, 100% { opacity: 1; }
            50% { opacity: 0.5; }
        }

        /* ===== CHARTS ===== */
        .chart-container {
            background: var(--bg-card);
            border-radius: 16px;
            border: 1px solid var(--border);
            padding: 20px;
            margin-bottom: 24px;
        }

        .chart-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 16px;
        }

        .chart-title {
            font-size: 16px;
            font-weight: 600;
        }

        .chart-actions {
            display: flex;
            flex-wrap: wrap;
            gap: 8px;
            margin-bottom: 12px;
            max-width: 100%;
            overflow-x: auto;
            -webkit-overflow-scrolling: touch;
            scrollbar-width: none;
            -ms-overflow-style: none;
        }
        
        .chart-actions::-webkit-scrollbar {
            display: none;
        }

        .chart-btn {
            padding: 6px 12px;
            border: 1px solid var(--border);
            background: var(--bg-dark);
            color: var(--text-muted);
            border-radius: 6px;
            font-size: 12px;
            cursor: pointer;
            transition: var(--transition);
            white-space: nowrap;
            flex-shrink: 0;
        }

        .chart-btn:hover, .chart-btn.active {
            background: var(--primary);
            color: white;
            border-color: var(--primary);
        }

        .chart { height: 400px; }

        /* ===== BUTTONS ===== */
        .btn {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            gap: 8px;
            padding: 10px 20px;
            border: none;
            border-radius: 10px;
            font-size: 14px;
            font-weight: 600;
            cursor: pointer;
            transition: var(--transition);
        }

        .btn-primary {
            background: var(--primary);
            color: white;
        }

        .btn-primary:hover { background: var(--primary-dark); }

        .btn-success {
            background: var(--success);
            color: white;
        }

        .btn-success:hover { background: var(--success-dark, #16a34a); }

        .btn-danger {
            background: var(--danger);
            color: white;
        }

        .btn-outline {
            background: transparent;
            border: 1px solid var(--border);
            color: var(--text);
        }

        .btn-outline:hover { background: var(--bg-hover); }

        /* ===== SETTINGS TABS ===== */
        .settings-tab {
            padding: 10px 20px;
            background: transparent;
            border: 1px solid var(--border);
            border-radius: 8px;
            color: var(--text-muted);
            font-size: 14px;
            font-weight: 500;
            cursor: pointer;
            transition: var(--transition);
            display: flex;
            align-items: center;
            gap: 8px;
        }

        .settings-tab:hover {
            background: var(--bg-hover);
            color: var(--text);
        }

        .settings-tab.active {
            background: var(--primary);
            border-color: var(--primary);
            color: white;
        }

        .settings-content {
            display: none;
        }

        .settings-content.active {
            display: block;
            animation: fadeIn 0.3s ease;
        }

        /* Settings page layout fix - NO SCROLLING */
        #settings .main-content {
            padding: 8px 12px;
        }

        #settings .grid-2 {
            gap: 8px;
            margin-bottom: 8px;
        }

        #settings .card {
            margin-bottom: 0;
        }

        #settings .card-header {
            padding: 8px 12px;
            min-height: auto;
        }

        #settings .card-title {
            font-size: 13px;
        }

        #settings .card-body {
            max-height: calc(100vh - 160px);
            overflow-y: auto;
            padding: 10px 12px;
        }

        #settings .card-body::-webkit-scrollbar {
            width: 4px;
        }

        #settings .card-body::-webkit-scrollbar-thumb {
            background: var(--border);
            border-radius: 2px;
        }

        /* Settings tabs - compact */
        #settings .settings-tab {
            padding: 6px 12px;
            font-size: 12px;
        }

        /* Buildings tab */
        #tab-buildings .grid-2 {
            grid-template-columns: 1fr 1fr;
        }

        #tab-buildings .card-body {
            max-height: calc(100vh - 150px);
        }

        @media (max-width: 1200px) {
            #tab-buildings .grid-2 {
                grid-template-columns: 1fr;
            }
        }

        /* Users tab - full width single column */
        #tab-users .grid-1 {
            grid-template-columns: 1fr;
            width: 100%;
        }
        #tab-users .card {
            width: 100%;
            max-width: 100%;
        }

        /* Data table compact */
        #settings .data-table th,
        #settings .data-table td {
            padding: 8px 10px;
            font-size: 13px;
        }

        /* ===== FLOORPLAN ===== */
        #floorplanMarkers {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            pointer-events: none;
        }

        #floorplanMarkers > div {
            pointer-events: auto;
            transition: transform 0.2s;
        }

        #floorplanMarkers > div:hover {
            transform: translate(-50%, -50%) scale(1.1);
        }

        .draggable-sensor:hover {
            border-color: var(--primary);
            background: rgba(59, 130, 246, 0.1);
        }

        .draggable-sensor.dragging {
            opacity: 0.5;
        }

        /* ===== TABLES ===== */
        .data-table {
            width: 100%;
            border-collapse: collapse;
        }

        .data-table th,
        .data-table td {
            padding: 12px 16px;
            text-align: left;
            border-bottom: 1px solid var(--border);
        }

        .data-table th {
            font-size: 11px;
            text-transform: uppercase;
            letter-spacing: 0.5px;
            color: var(--text-muted);
            font-weight: 600;
        }

        .data-table tbody tr:hover { background: var(--bg-hover); }

        /* ===== BADGES ===== */
        .badge {
            display: inline-flex;
            align-items: center;
            gap: 4px;
            padding: 4px 12px;
            border-radius: 20px;
            font-size: 12px;
            font-weight: 600;
        }

        .badge-success { background: rgba(34, 197, 94, 0.2); color: var(--success); }
        .badge-warning { background: rgba(245, 158, 11, 0.2); color: var(--warning); }
        .badge-danger { background: rgba(239, 68, 68, 0.2); color: var(--danger); }
        .badge-info { background: rgba(59, 130, 246, 0.2); color: var(--primary); }

        /* ===== GRID ===== */
        .grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 24px; }
        .grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 24px; }
        .grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 24px; }

        @media (max-width: 1200px) {
            .grid-4 { grid-template-columns: repeat(2, 1fr); }
        }

        /* Large Monitor Optimization (1920px and above) */
        @media (min-width: 1920px) {
            :root {
                --sidebar-width: 320px;
            }
            .sidebar.collapsed {
                width: var(--sidebar-collapsed);
            }
            .sidebar-nav {
                padding: 20px;
            }
            .sidebar.collapsed .sidebar-nav {
                padding: 16px 12px;
            }
            .nav-item {
                padding: 14px 20px;
                font-size: 15px;
            }
            .sidebar.collapsed .nav-item {
                padding: 12px 0;
            }
            .nav-text {
                font-size: 15px;
            }
            .nav-section-title {
                font-size: 12px;
            }
        }

        /* Medium-Large Monitor (1440px to 1919px) */
        @media (min-width: 1440px) and (max-width: 1919px) {
            :root {
                --sidebar-width: 280px;
            }
            .sidebar.collapsed {
                width: var(--sidebar-collapsed);
            }
        }

        /* iPhone 15 and Mobile Optimization */
        @media (max-width: 768px) {
            .sidebar {
                transform: translateX(-100%);
                width: 100% !important;
                max-width: 320px;
            }
            .sidebar.mobile-open { transform: translateX(0); }
            .main-wrapper {
                margin-left: 0;
                padding-top: 0;
                padding-bottom: var(--safe-bottom);
            }
            .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
            
                /* Settings buildings page - aligned with other settings tabs */
            #tab-buildings .grid-2 {
                grid-template-columns: 1fr !important;
                gap: 8px;
                margin-bottom: 8px;
            }
            #tab-buildings .card {
                min-width: 0 !important;
                width: 100% !important;
                max-width: 100% !important;
                margin-bottom: 0;
            }
            #tab-buildings .card-header {
                flex-wrap: wrap;
                gap: 8px;
                padding: 8px 12px;
                min-height: auto;
            }
            #tab-buildings .card-title {
                font-size: 13px;
            }
            #tab-buildings .card-body {
                max-height: calc(100vh - 160px) !important;
                overflow-y: auto !important;
                padding: 10px 12px !important;
            }
            #tab-buildings .data-table {
                font-size: 12px;
            }
            #tab-buildings .data-table th,
            #tab-buildings .data-table td {
                padding: 8px 6px;
            }
            #tab-buildings table {
                display: block;
                overflow-x: auto;
                white-space: nowrap;
            }

            /* Standards tab - mobile responsive */
            #tab-standards .data-table {
                font-size: 11px;
            }
            #tab-standards .data-table th,
            #tab-standards .data-table td {
                padding: 6px 4px;
                white-space: normal;
                word-wrap: break-word;
                max-width: 150px;
            }
            #tab-standards .data-table td:nth-child(4) {
                max-width: 200px;
                min-width: 100px;
            }
            #tab-standards .badge {
                font-size: 10px;
                padding: 2px 6px;
            }
            #tab-standards table {
                display: block;
                overflow-x: auto;
                white-space: nowrap;
            }

            /* Mobile filters - wrap to new line */
            .global-filters {
                display: flex;
                flex-wrap: wrap;
                overflow-x: visible;
                gap: 8px;
                padding: 8px 0;
                width: 100%;
                order: 3;
                justify-content: flex-start;
            }
            .global-filters.hidden {
                display: none !important;
            }
            .global-filters .filter-group {
                flex: 0 0 auto;
                min-width: 100px;
            }
            .global-filters .filter-label {
                font-size: 11px;
            }
            .global-filters .filter-select {
                padding: 6px 8px;
                font-size: 14px;
                min-width: 100px;
            }

            /* iPhone 15 Specific */
            .top-bar {
                padding: 12px 16px;
                padding-top: max(12px, var(--safe-top));
                min-height: auto;
                flex-wrap: wrap;
                gap: 8px;
                position: relative;
            }
            
            .page-title {
                font-size: 18px;
                min-width: auto;
            }

            .main-wrapper {
                margin-left: 0;
                padding-top: 0;
                padding-bottom: var(--safe-bottom);
            }

            .main-content {
                padding: 12px 16px;
                padding-top: max(12px, var(--safe-top));
                padding-bottom: calc(12px + var(--safe-bottom));
                overflow-y: auto;
                -webkit-overflow-scrolling: touch;
            }
            
            /* Reduce top padding on small screens */
            @media (max-width: 420px) {
                .main-content {
                    padding-top: 8px;
                    padding: 8px 12px;
                }
                .top-bar {
                    padding: 8px 12px;
                    padding-top: max(8px, var(--safe-top));
                }
            }

            /* Touch-friendly */
            .nav-item {
                padding: 16px 12px;
                min-height: 56px;
            }

            .btn {
                min-height: 48px;
                font-size: 16px; /* Prevent zoom on input */
            }

            .filter-select, input, select {
                font-size: 16px; /* Prevent zoom on iOS */
            }

            .mobile-menu-btn {
                display: flex !important;
            }

            /* Stats cards full width on mobile */
            .stats-grid {
                grid-template-columns: 1fr;
                gap: 12px;
            }

            .stat-card {
                padding: 12px;
                min-height: 110px;
            }

            .stat-value {
                font-size: 28px;
            }

            .stat-unit {
                font-size: 12px;
            }

            .stat-title {
                font-size: 11px;
            }

            .stat-updated {
                font-size: 10px;
            }

            /* GO AQS Gauge mobile */
            #goaqsScoreValue {
                font-size: 36px !important;
            }

            #goaqsStatus {
                font-size: 18px !important;
            }

            /* GO AQS scale bar mobile - ensure visibility */
            #goaqsGauge .card-body > div:first-child {
                margin-bottom: 44px !important;
            }

            #goaqsPointer {
                width: 26px !important;
                height: 46px !important;
                padding: 3px 0 6px 0 !important;
                border-radius: 13px !important;
            }

            #goaqsPointerNumber {
                font-size: 11px !important;
            }

            #goaqsPointerLetter {
                font-size: 12px !important;
            }

            /* Bottom sheet for mobile nav overlay */
            .sidebar-overlay {
                display: block;
                position: fixed;
                inset: 0;
                background: rgba(0,0,0,0.5);
                z-index: 999;
                opacity: 0;
                pointer-events: none;
                transition: opacity 0.3s;
            }

            .sidebar-overlay.active {
                opacity: 1;
                pointer-events: auto;
            }
        }

        /* iPhone 15 Pro / Pro Max Dynamic Island */
        @media (max-width: 430px) {
            :root {
                --safe-top: 59px; /* Dynamic Island height */
            }

            .page-title {
                font-size: 18px;
            }

            .icon-btn {
                width: 44px;
                height: 44px;
            }

            /* Standards table - extra compact on small screens */
            #tab-standards .data-table {
                font-size: 10px;
            }
            #tab-standards .data-table th,
            #tab-standards .data-table td {
                padding: 4px 3px;
            }
            #tab-standards .data-table td:nth-child(1) {
                min-width: 60px;
            }
            #tab-standards .data-table td:nth-child(2) {
                min-width: 40px;
            }
            #tab-standards .data-table td:nth-child(3) {
                min-width: 50px;
            }
            #tab-standards .data-table td:nth-child(4) {
                max-width: 120px;
                font-size: 10px;
            }
            #tab-standards .btn {
                padding: 4px 8px;
                font-size: 10px;
            }
        }

        /* Very small screens - under 420px */
        @media (max-width: 420px) {
            /* Settings buildings page - extra compact */
            #tab-buildings .card-header {
                flex-direction: column;
                align-items: flex-start;
                gap: 6px;
                padding: 6px 8px;
            }
            #tab-buildings .card-header button {
                width: 100%;
                font-size: 11px;
                padding: 6px 8px;
            }
            #tab-buildings .card-title {
                font-size: 12px;
            }
            #tab-buildings .card-body {
                padding: 6px 8px !important;
            }
            #tab-buildings .data-table {
                font-size: 10px;
            }
            #tab-buildings .data-table th,
            #tab-buildings .data-table td {
                padding: 4px 3px;
            }
            #tab-buildings select {
                font-size: 11px;
                padding: 4px 6px;
                min-width: 0;
                flex: 1;
            }
            #tab-buildings .card-header > div {
                flex-wrap: wrap;
                gap: 4px;
                width: 100%;
            }
        }

        /* ============================================
           iOS SAFARI COMPATIBILITY FIXES
           ============================================ */
        
        /* iOS flexbox fixes - add webkit prefixes */
        @supports (-webkit-touch-callout: none) {
            /* CSS specific to iOS devices */
            
            .sidebar,
            .main-content,
            .dashboard-grid,
            .stats-grid,
            .form-row,
            .modal-content {
                display: -webkit-flex;
                display: flex;
            }
            
            .sidebar {
                -webkit-flex-direction: column;
                flex-direction: column;
            }
            
            .stat-card {
                -webkit-flex: 1;
                flex: 1;
            }
            
            /* iOS momentum scrolling */
            .sidebar-nav,
            .main-content,
            .modal-body,
            .building-floorplan-content {
                -webkit-overflow-scrolling: touch;
            }
            
            /* iOS button/input resets */
            button,
            .btn,
            input,
            textarea,
            select {
                -webkit-appearance: none;
                appearance: none;
                border-radius: 10px;
            }
            
            /* iOS tap highlight */
            * {
                -webkit-tap-highlight-color: transparent;
            }
            
            /* iOS date input styling */
            input[type="date"] {
                -webkit-appearance: none;
                appearance: none;
                min-height: 44px;
                line-height: 44px;
            }
            
            /* iOS safe area for notch devices */
            @supports (padding-top: env(safe-area-inset-top)) {
                .sidebar {
                    padding-top: env(safe-area-inset-top);
                }
                
                .main-header {
                    padding-top: env(safe-area-inset-top);
                    height: calc(var(--header-height) + env(safe-area-inset-top));
                }
                
                .main-content {
                    padding-bottom: env(safe-area-inset-bottom);
                }
            }
            
            /* iOS sticky hover fix */
            @media (hover: none) {
                .nav-item:hover:not(.active),
                .btn:hover:not(:disabled),
                .stat-card:hover {
                    background: inherit;
                }
                
                .nav-item:active,
                .btn:active:not(:disabled) {
                    opacity: 0.7;
                }
            }
            
            /* iOS 300ms click delay fix */
            a, button, .btn, .nav-item, .stat-card {
                touch-action: manipulation;
            }
        }
        
        /* Passive event listener optimization hint */
        .scroll-container {
            touch-action: pan-y;
            -webkit-overflow-scrolling: touch;
        }

        /* ===== FLOORPLAN SENSOR PLACEMENT ANIMATIONS ===== */
        @keyframes pulse {
            0%, 100% { transform: translate(-50%, -50%) scale(1); }
            50% { transform: translate(-50%, -50%) scale(1.1); }
        }

        @keyframes fadeInDown {
            from {
                opacity: 0;
                transform: translate(-50%, -20px);
            }
            to {
                opacity: 1;
                transform: translate(-50%, 0);
            }
        }

        @keyframes fadeOutUp {
            from {
                opacity: 1;
                transform: translate(-50%, 0);
            }
            to {
                opacity: 0;
                transform: translate(-50%, -20px);
            }
        }

        .sensor-marker.pending {
            animation: pulse 1.5s infinite;
        }