html {
    touch-action: manipulation;
    height: 100%;
    scroll-behavior: smooth;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

body {
    background-image: url('https://images.unsplash.com/photo-1483728642387-6c3bdd6c93e5?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=2076&q=80');
    background-size: cover;
    background-position: center;
    background-attachment: fixed;
    color: #333333;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    padding: 0;
    margin: 0;
    transition: background-color 0.3s ease;
    overflow-x: hidden;
}

body.dark-mode {
    background-color: #121212;
    color: #f0f0f0;
}

/* Loading Indicator */
.loader-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(255, 255, 255, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    transition: opacity 0.3s ease;
}

body.dark-mode .loader-container {
    background-color: rgba(0, 0, 0, 0.8);
}

.loader {
    width: 48px;
    height: 48px;
    border: 5px solid #e67e22;
    border-bottom-color: transparent;
    border-radius: 50%;
    display: inline-block;
    box-sizing: border-box;
    animation: rotation 1s linear infinite;
}

body.dark-mode .loader {
    border-color: #f39c12;
    border-bottom-color: transparent;
}

@keyframes rotation {
    0% {
        transform: rotate(0deg);
    }
    100% {
        transform: rotate(360deg);
    }
}

/* Main Content Container */
.container {
    background-color: rgba(255, 255, 255, 0.9);
    color: #333333;
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    padding-bottom: 70px; /* Space for bottom nav */
    width: 100%;
    max-width: 100vw;
    box-sizing: border-box;
    transition: background-color 0.3s ease, color 0.3s ease;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

body.dark-mode .container {
    background-color: rgba(30, 30, 30, 0.9);
    color: #f0f0f0;
}

.dashboard {
    max-width: 100%;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

/* Header Styles */
.header-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.greeting-container {
    display: flex;
    flex-direction: column;
    flex-grow: 1;
}

.greeting-name {
    font-size: 22px;
    font-weight: 600;
    color: #333333;
    transition: color 0.3s ease;
}

body.dark-mode .greeting-name {
    color: #f0f0f0;
}

.greeting-time {
    font-size: 14px;
    color: #666666;
    margin-top: 5px;
    transition: color 0.3s ease;
}

body.dark-mode .greeting-time {
    color: #aaaaaa;
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 10px;
}

.theme-toggle {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background-color: rgba(0, 0, 0, 0.05);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #e67e22;
    cursor: pointer;
    transition: all 0.3s ease;
    border: none;
}

.theme-toggle:hover {
    background-color: rgba(0, 0, 0, 0.1);
}

body.dark-mode .theme-toggle {
    background-color: rgba(255, 255, 255, 0.1);
    color: #f39c12;
}

body.dark-mode .theme-toggle:hover {
    background-color: rgba(255, 255, 255, 0.2);
}

.datetime-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin: 10px 0;
}

.current-date {
    font-size: 14px;
    color: #e67e22;
    font-weight: 500;
    transition: color 0.3s ease;
}

body.dark-mode .current-date {
    color: #f39c12;
}

.current-time {
    font-size: 16px;
    font-weight: 600;
    color: #333333;
    transition: color 0.3s ease;
}

body.dark-mode .current-time {
    color: #f0f0f0;
}

.profile-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-color: #e67e22;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    font-weight: bold;
    flex-shrink: 0;
    cursor: pointer;
    transition: background-color 0.3s ease;
}

body.dark-mode .profile-avatar {
    background-color: #f39c12;
}

/* Card Styles */
.card {
    background-color: #ffffff;
    border-radius: 20px;
    padding: 20px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    transition: background-color 0.3s ease, box-shadow 0.3s ease;
    width: 100%;
    box-sizing: border-box;
}

body.dark-mode .card {
    background-color: #2d2d2d;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

/* Weather Card */
.weather-card {
    position: relative;
}

.weather-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 5px;
}

.weather-location-container {
    display: flex;
    flex-direction: column;
}

.weather-location {
    font-size: 18px;
    font-weight: 600;
    color: #333333;
    transition: color 0.3s ease;
}

body.dark-mode .weather-location {
    color: #f0f0f0;
}

.weather-city {
    font-size: 14px;
    color: #666666;
    transition: color 0.3s ease;
}

body.dark-mode .weather-city {
    color: #aaaaaa;
}

.weather-temp {
    font-size: 28px;
    font-weight: 600;
    color: #e67e22;
    transition: color 0.3s ease;
}

body.dark-mode .weather-temp {
    color: #f39c12;
}

.weather-stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    text-align: center;
    margin-top: 15px;
}

.weather-stat-value {
    font-size: 16px;
    font-weight: 600;
    color: #333333;
    margin-bottom: 3px;
    transition: color 0.3s ease;
}

body.dark-mode .weather-stat-value {
    color: #f0f0f0;
}

.weather-stat-label {
    font-size: 12px;
    color: #666666;
    transition: color 0.3s ease;
}

body.dark-mode .weather-stat-label {
    color: #aaaaaa;
}

/* Tabs */
.tabs-container {
    overflow-x: auto;
    white-space: nowrap;
    padding-bottom: 8px;
    -webkit-overflow-scrolling: touch;
    margin: 10px 0;
    touch-action: pan-x;
    width: 100%;
}

.tabs-container::-webkit-scrollbar {
    display: none;
}

.tabs {
    display: inline-flex;
    gap: 25px;
    padding: 0 15px;
}

.tab {
    font-size: 16px;
    font-weight: 600;
    color: #999999;
    position: relative;
    transition: all 0.3s ease;
    padding: 5px 0;
    flex-shrink: 0;
    cursor: pointer;
}

.tab.active {
    color: #e67e22;
    transform: scale(1.05);
}

body.dark-mode .tab.active {
    color: #f39c12;
}

.tab.active:after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 2px;
    background-color: #e67e22;
    transition: background-color 0.3s ease;
}

body.dark-mode .tab.active:after {
    background-color: #f39c12;
}

/* Devices */
.devices-card {
    margin-top: 5px;
}

.devices {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    width: 100%;
}

.device {
    background-color: #f0f0f0;
    border-radius: 12px;
    padding: 15px;
    transition: all 0.2s ease;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    width: 100%;
    box-sizing: border-box;
    position: relative;
}

body.dark-mode .device {
    background-color: #3a3a3a;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
}

.device-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 10px;
}

.device-icon {
    font-size: 20px;
    color: #e67e22;
    margin-bottom: 8px;
    transition: color 0.3s ease;
}

body.dark-mode .device-icon {
    color: #f39c12;
}

.device-info {
    flex: 1;
}

.device-name {
    font-size: 16px;
    font-weight: 600;
    color: #333333;
    margin-bottom: 3px;
    transition: color 0.3s ease;
}

body.dark-mode .device-name {
    color: #f0f0f0;
}

.device-type {
    font-size: 14px;
    color: #777777;
    transition: color 0.3s ease;
}

body.dark-mode .device-type {
    color: #aaaaaa;
}

.device-status {
    font-size: 14px;
    margin-top: 8px;
    padding: 3px 0;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 5px;
}

.device-status.on {
    color: #e67e22;
}

body.dark-mode .device-status.on {
    color: #f39c12;
}

.device-status.off {
    color: #999999;
}

body.dark-mode .device-status.off {
    color: #777777;
}

/* AC Specific Styles */
.device[data-type="air-conditioner"] .device-status {
    display: flex;
    justify-content: space-between;
    width: 100%;
}

/* Updated Temperature Display and Controls */
.temp-display-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    margin-top: 10px;
}

.temp-display-column {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.temp-controls-column {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

.temp-display {
    display: flex;
    align-items: center;
    gap: 8px;
}

.temp-value {
    font-size: 16px;
    font-weight: 600;
    min-width: 40px;
    text-align: center;
}

.status-indicator {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-right: 5px;
}

.status-indicator.on {
    background-color: #e67e22;
}

body.dark-mode .status-indicator.on {
    background-color: #f39c12;
}

.status-indicator.off {
    background-color: #999999;
}

body.dark-mode .status-indicator.off {
    background-color: #777777;
}

/* Toggle switch styles */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 24px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #7f8c8d;
    transition: all 0.3s ease;
    border-radius: 24px;
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 4px;
    bottom: 4px;
    background-color: white;
    transition: all 0.3s ease;
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

input:checked + .toggle-slider {
    background-color: #e67e22;
}

body.dark-mode input:checked + .toggle-slider {
    background-color: #f39c12;
}

input:checked + .toggle-slider:before {
    transform: translateX(26px);
}

.toggle-switch:hover .toggle-slider {
    box-shadow: 0 0 0 2px rgba(230, 126, 34, 0.2);
}

body.dark-mode .toggle-switch:hover .toggle-slider {
    box-shadow: 0 0 0 2px rgba(243, 156, 18, 0.3);
}

.toggle-switch input:focus + .toggle-slider {
    box-shadow: 0 0 0 2px rgba(230, 126, 34, 0.4);
}

body.dark-mode .toggle-switch input:focus + .toggle-slider {
    box-shadow: 0 0 0 2px rgba(243, 156, 18, 0.5);
}

/* Temperature controls */
.temp-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.temp-btn {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    background-color: #e67e22;
    color: white;
    border: none;
    font-size: 16px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

body.dark-mode .temp-btn {
    background-color: #f39c12;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.temp-btn:active {
    transform: scale(0.95);
}

.temp-btn:hover:not(:disabled) {
    background-color: #d35400;
    transform: scale(1.05);
    box-shadow: 0 3px 6px rgba(0, 0, 0, 0.15);
}

body.dark-mode .temp-btn:hover:not(:disabled) {
    background-color: #e67e22;
    box-shadow: 0 3px 6px rgba(0, 0, 0, 0.3);
}

.temp-btn:active:not(:disabled) {
    transform: scale(0.95);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.temp-btn:disabled {
    background-color: #cccccc;
    cursor: not-allowed;
    transform: none;
}

body.dark-mode .temp-btn:disabled {
    background-color: #555555;
}

/* Bottom Navigation */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    background-color: rgba(255, 255, 255, 0.95);
    border-radius: 0;
    padding: 8px 5px;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
    display: flex;
    justify-content: space-around;
    z-index: 100;
    transition: background-color 0.3s ease;
}

body.dark-mode .bottom-nav {
    background-color: rgba(46, 46, 46, 0.95);
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.3);
}

.nav-btn {
    background: transparent;
    border: none;
    color: #666;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 6px 4px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 500;
    cursor: pointer;
    width: 100%;
    max-width: none;
    flex: 1;
    transition: all 0.3s ease;
}

body.dark-mode .nav-btn {
    color: #aaaaaa;
}

.nav-btn i {
    font-size: 16px;
    margin-bottom: 2px;
    transition: color 0.3s ease;
}

.nav-btn.active {
    color: #e67e22;
    background-color: rgba(230, 126, 34, 0.1);
}

body.dark-mode .nav-btn.active {
    color: #f39c12;
    background-color: rgba(243, 156, 18, 0.2);
}

/* Context Menu */
.context-menu {
    position: absolute;
    right: 0;
    top: 50px;
    background-color: rgba(255, 255, 255, 0.95);
    border-radius: 10px;
    padding: 10px 0;
    min-width: 110px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    font-size: 12px;
    transition: all 0.3s ease;
    z-index: 1000;
}

body.dark-mode .context-menu {
    background-color: rgba(46, 46, 46, 0.95);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}

.avatar-container:hover .context-menu {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.menu-item {
    padding: 10px 20px;
    color: #333;
    cursor: pointer;
    display: flex;
    align-items: center;
    transition: all 0.2s ease;
}

body.dark-mode .menu-item {
    color: #f0f0f0;
}

.menu-item i {
    margin-right: 10px;
    width: 20px;
    text-align: center;
}

.menu-item:hover {
    background-color: rgba(230, 126, 34, 0.1);
    color: #e67e22;
}

body.dark-mode .menu-item:hover {
    background-color: rgba(243, 156, 18, 0.2);
    color: #f39c12;
}

/* Responsive adjustments */
@media (max-width: 480px) {
    .container {
        padding: 15px;
        padding-bottom: 70px;
    }
    
    .greeting-name {
        font-size: 20px;
    }
    
    .greeting-time {
        font-size: 13px;
    }

    .weather-location {
        font-size: 16px;
    }
    
    .weather-city {
        font-size: 13px;
    }
    
    .weather-temp {
        font-size: 24px;
    }

    .tabs {
        gap: 20px;
    }
    
    .tab {
        font-size: 14px;
    }

    .devices {
        gap: 12px;
    }
    
    .device {
        padding: 12px;
    }
    
    .device-name {
        font-size: 15px;
    }
    
    .device-type {
        font-size: 13px;
    }
    
    .temp-btn {
        width: 26px;
        height: 26px;
        font-size: 15px;
    }
    
    .temp-value {
        font-size: 15px;
    }
}

@media (max-width: 350px) {
    .weather-stats {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }
    
    .weather-stat-value {
        font-size: 14px;
    }
    
    .weather-stat-label {
        font-size: 11px;
    }
    
    .tab {
        font-size: 13px;
    }
    
    .nav-btn {
        padding: 5px 8px;
        font-size: 10px;
    }
    
    .nav-btn i {
        font-size: 15px;
    }
    
    .device {
        padding: 10px;
    }
    
    .temp-btn {
        width: 24px;
        height: 24px;
        font-size: 14px;
    }
    
    .temp-value {
        font-size: 14px;
    }
}

/* Very small devices (e.g., iPhone 5/SE) */
@media (max-width: 320px) {
    .greeting-name {
        font-size: 18px;
    }
    
    .weather-stats {
        grid-template-columns: 1fr 1fr;
        row-gap: 15px;
    }
    
    .devices {
        grid-template-columns: 1fr;
    }
    
    .temp-display-controls {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
    
    .temp-controls-column {
        align-items: flex-start;
        width: 100%;
    }
}