/* ==================== RESET & BASE ==================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* Color System - Professional Dark Theme */
    --bg-base: #0d1117;
    --bg-elevated: #161b22;
    --bg-hover: #1c2128;
    --bg-active: #21262d;
    
    --border-base: #30363d;
    --border-hover: #484f58;
    
    --text-primary: #f0f6fc;
    --text-secondary: #8b949e;
    --text-tertiary: #6e7681;
    
    /* Accent Colors - Subtle & Professional */
    --accent-blue: #58a6ff;
    --accent-green: #3fb950;
    --accent-orange: #f85149;
    --accent-purple: #bc8cff;
    
    /* Status Colors */
    --status-online: #238636;
    --status-offline: #da3633;
    --status-warning: #d29922;
    
    /* Metric Colors */
    --metric-temp: #ff6b35;
    --metric-hum: #4dabf7;
    
    /* Spacing Scale */
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.25rem;
    --space-6: 1.5rem;
    --space-8: 2rem;
    --space-10: 2.5rem;
    --space-12: 3rem;
    
    /* Typography */
    --font-sans: 'Space Grotesk', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
    
    /* Shadows */
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1), 0 2px 4px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 20px rgba(0, 0, 0, 0.15), 0 3px 6px rgba(0, 0, 0, 0.1);
    
    /* Transitions */
    --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-base: 250ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 350ms cubic-bezier(0.4, 0, 0.2, 1);
}

body {
    font-family: var(--font-sans);
    background: var(--bg-base);
    color: var(--text-primary);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ==================== LAYOUT ==================== */
.app-container {
    display: flex;
    min-height: 100vh;
    background: var(--bg-base);
}

/* ==================== SIDEBAR ==================== */
.sidebar {
    width: 260px;
    background: var(--bg-elevated);
    border-right: 1px solid var(--border-base);
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    z-index: 100;
    transition: transform var(--transition-base);
    left: 0;
    top: 0;
}

.sidebar.collapsed {
    transform: translateX(-100%);
}

.sidebar-header {
    padding: var(--space-6);
    border-bottom: 1px solid var(--border-base);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;
    gap: var(--space-3); /* Add gap between brand and close button */
}

.sidebar-toggle-header {
    position: absolute;
    right: var(--space-6);
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: var(--space-2);
    border-radius: 6px;
    transition: all var(--transition-base);
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sidebar-toggle-header:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.sidebar-toggle-header svg {
    width: 18px;
    height: 18px;
}

@media (min-width: 769px) {
    .sidebar-toggle-header {
        display: flex !important;
    }
    
    .sidebar-close {
        display: none;
    }
}

.brand {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    flex: 1;
    min-width: 0; /* Allow text to shrink/truncate if needed */
}

.brand-icon {
    width: 40px;
    height: 40px;
    object-fit: contain;
    flex-shrink: 0;
}

.brand-name {
    height: 45px; /* Larger, more prominent brand name */
    width: auto;
    object-fit: contain;
    flex-shrink: 1;
    min-width: 0; /* Allow it to shrink if needed */
}

.brand-text {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: -0.02em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.brand-highlight {
    color: var(--accent-blue);
    font-weight: 700;
}

.sidebar-nav {
    flex: 1;
    padding: var(--space-4);
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
}

.nav-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: 6px;
    transition: all var(--transition-base);
    font-size: 0.9375rem;
    font-weight: 500;
}

.nav-item svg {
    width: 20px;
    height: 20px;
    stroke-width: 2;
}

.nav-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.nav-item.active {
    background: var(--bg-active);
    color: var(--text-primary);
}

.sidebar-footer {
    padding: var(--space-4);
    border-top: 1px solid var(--border-base);
}

.connection-status {
    padding: var(--space-3);
    background: var(--bg-hover);
    border-radius: 6px;
    border: 1px solid var(--border-base);
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: 0.875rem;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--status-offline);
    transition: background var(--transition-base);
}

.status-dot.online {
    background: var(--status-online);
    box-shadow: 0 0 8px var(--status-online);
}

.status-text {
    color: var(--text-secondary);
    font-weight: 500;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.05em;
}

/* ==================== MAIN CONTENT ==================== */
.main-content {
    flex: 1;
    margin-left: 260px;
    height: 100vh;
    max-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: margin-left var(--transition-base);
}

.sidebar.collapsed ~ .main-content {
    margin-left: 0;
}

/* ==================== TOPBAR ==================== */
.topbar {
    background: var(--bg-elevated);
    border-bottom: 1px solid var(--border-base);
    padding: var(--space-3) var(--space-8);
    padding-left: var(--space-8);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 10;
    backdrop-filter: blur(10px);
    margin-bottom: 0;
    flex-shrink: 0;
    transition: padding-left var(--transition-base);
}

/* Adjust topbar padding when sidebar is collapsed to avoid button overlap */
.app-container.sidebar-collapsed .topbar {
    padding-left: calc(var(--space-8) + 56px); /* space-8 + button width (40px) + gap (16px) */
}

.page-title {
    font-size: 1.375rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.125rem;
    letter-spacing: -0.02em;
}

.page-subtitle {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    font-weight: 400;
    line-height: 1.4;
}

.timestamp {
    font-family: var(--font-mono);
    font-size: 0.875rem;
    color: var(--text-tertiary);
    padding: var(--space-2) var(--space-4);
    background: var(--bg-hover);
    border-radius: 6px;
    border: 1px solid var(--border-base);
}

/* ==================== CONTENT AREA ==================== */
.view-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

/* Dashboard view - no scroll, fit on screen */
#dashboardView {
    height: 100vh;
    max-height: 100vh;
    overflow: hidden;
}

/* Settings view - allow scrolling */
#settingsView {
    height: auto;
    min-height: 100vh;
    overflow-y: auto;
    overflow-x: hidden;
}

.view-content > section {
    padding: var(--space-8);
    max-width: 1400px;
    width: 100%;
    margin: 0 auto;
}

/* Legacy support for direct section children */
.main-content > section {
    padding: var(--space-8);
    max-width: 1400px;
    width: 100%;
    margin: 0 auto;
}

.section-header {
    margin-bottom: var(--space-4);
}

.section-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: var(--space-2);
    letter-spacing: -0.01em;
}

.section-description {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* ==================== METRICS GRID ==================== */
.metrics-grid {
    display: grid;
    grid-template-columns: 1.5fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr;
    grid-template-rows: 1fr 1fr;
    gap: var(--space-2);
    margin-bottom: var(--space-2);
    padding: var(--space-3) var(--space-6);
    max-width: 1400px;
    width: 100%;
    margin-left: auto;
    margin-right: auto;
    flex-shrink: 0;
}


.metric-card {
    background: var(--bg-elevated);
    border: 1px solid var(--border-base);
    border-radius: 10px;
    padding: var(--space-4);
    transition: all var(--transition-base);
    position: relative;
    overflow: hidden;
}

/* Smaller cards (temp, humidity, pressure, light, rain, wind speed, wind dir, fan) */
.temp-card,
.hum-card,
.press-card,
.light-card,
.rain-card,
.wind-speed-card,
.wind-dir-card {
    padding: var(--space-2);
    min-height: 0;
}

.fan-card {
    padding: var(--space-2);
    min-height: 0;
    grid-column: 1 / 9;  /* Span all columns */
}

/* Smaller metric values in compact cards */
.temp-card .metric-value,
.hum-card .metric-value,
.press-card .metric-value,
.light-card .metric-value,
.rain-card .metric-value,
.wind-speed-card .metric-value,
.wind-dir-card .metric-value,
.fan-card .metric-value {
    font-size: 1.25rem;
}

.temp-card .metric-unit,
.hum-card .metric-unit,
.press-card .metric-unit,
.light-card .metric-unit,
.rain-card .metric-unit,
.wind-speed-card .metric-unit,
.wind-dir-card .metric-unit {
    font-size: 0.75rem;
}

.temp-card .metric-label,
.hum-card .metric-label,
.press-card .metric-label,
.light-card .metric-label,
.rain-card .metric-label,
.wind-speed-card .metric-label,
.wind-dir-card .metric-label,
.fan-card .metric-label {
    font-size: 0.6875rem;
}

.temp-card .metric-icon,
.hum-card .metric-icon,
.press-card .metric-icon,
.light-card .metric-icon,
.rain-card .metric-icon,
.wind-speed-card .metric-icon,
.wind-dir-card .metric-icon,
.fan-card .metric-icon {
    width: 24px;
    height: 24px;
    border-radius: 8px;
}

.temp-card .metric-icon svg,
.hum-card .metric-icon svg,
.press-card .metric-icon svg,
.light-card .metric-icon svg,
.rain-card .metric-icon svg,
.wind-speed-card .metric-icon svg,
.wind-dir-card .metric-icon svg,
.fan-card .metric-icon svg {
    width: 14px;
    height: 14px;
    border-radius: 3px;
}

/* Compact headers and footers */
.temp-card .metric-header,
.hum-card .metric-header,
.press-card .metric-header,
.light-card .metric-header,
.rain-card .metric-header,
.wind-speed-card .metric-header,
.wind-dir-card .metric-header,
.fan-card .metric-header {
    margin-bottom: var(--space-1);
}

.temp-card .metric-footer,
.hum-card .metric-footer,
.press-card .metric-footer,
.light-card .metric-footer,
.rain-card .metric-footer,
.wind-speed-card .metric-footer,
.wind-dir-card .metric-footer,
.fan-card .metric-footer {
    margin-top: var(--space-1);
}

.temp-card .metric-value-group,
.hum-card .metric-value-group,
.press-card .metric-value-group,
.light-card .metric-value-group,
.rain-card .metric-value-group,
.wind-speed-card .metric-value-group,
.wind-dir-card .metric-value-group,
.fan-card .metric-value-group {
    padding: var(--space-1) 0;
}

/* Weather card - spans both rows, left side - Clock widget style */
.weather-card {
    padding: var(--space-4);
    grid-row: 1 / 3;
    grid-column: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
    min-height: 0;
    text-align: center;
    position: relative;
}

/* Other metric cards - arranged in grid */
.temp-card {
    grid-row: 1;
    grid-column: 2;
}

.hum-card {
    grid-row: 1;
    grid-column: 3;
}

.press-card {
    grid-row: 1;
    grid-column: 4;
}

.light-card {
    grid-row: 1;
    grid-column: 5;
}

.rain-card {
    grid-row: 1;
    grid-column: 6;
}

.wind-speed-card {
    grid-row: 1;
    grid-column: 7;
}

.wind-dir-card {
    grid-row: 1;
    grid-column: 8;
}

.fan-card {
    grid-row: 2;
    grid-column: 1 / 9;
}

.metric-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--metric-temp);
    transform: scaleX(0);
    transition: transform var(--transition-base);
}

.metric-card:hover {
    border-color: var(--border-hover);
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.metric-card:hover::before {
    transform: scaleX(1);
}

.hum-card::before {
    background: var(--metric-hum);
}

.press-card::before {
    background: var(--accent-purple);
}

.light-card::before {
    background: #ffd700;
}

.rain-card::before {
    background: #4a90e2;
}

.wind-speed-card::before {
    background: #7c3aed;
}

.wind-dir-card::before {
    background: #06b6d4;
}

.metric-header {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin-bottom: var(--space-3);
}

.metric-icon {
    width: 32px;
    height: 32px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-hover);
    border: 1px solid var(--border-base);
    flex-shrink: 0;
    overflow: hidden;
}

.metric-icon svg {
    width: 18px;
    height: 18px;
    border-radius: 4px;
}

.temp-icon {
    color: var(--metric-temp);
}

.hum-icon {
    color: var(--metric-hum);
}

.press-icon {
    color: var(--accent-purple);
}

.light-icon {
    color: #ffd700;  /* Gold/yellow for light */
}

.rain-icon {
    color: #4a90e2;  /* Blue for rain */
}

.wind-speed-icon {
    color: #7c3aed;  /* Purple for wind speed */
}

.wind-dir-icon {
    color: #06b6d4;  /* Cyan for wind direction */
}

.fan-icon {
    color: var(--accent-blue);
    transition: transform var(--transition-base);
}

.fan-card::before {
    background: var(--accent-blue);
}

.fan-card.fan-on::before {
    background: var(--accent-green);
    transform: scaleX(1);
}

.fan-card.fan-on {
    border-color: rgba(63, 185, 80, 0.3);
}

.fan-card.fan-on:hover {
    border-color: rgba(63, 185, 80, 0.5);
    box-shadow: 0 4px 12px rgba(63, 185, 80, 0.15);
}

.fan-card.fan-on .fan-icon {
    color: var(--accent-green);
    animation: fanSpin 2s linear infinite;
}

@keyframes fanSpin {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

/* Weather Card Styles */
.weather-card {
    position: relative;
}

.weather-card::before {
    background: var(--accent-blue);
}

.weather-icon {
    color: var(--accent-blue);
    transition: color var(--transition-base);
}

.weather-card.weather-sunny .weather-icon {
    color: #ffa500;
}

.weather-card.weather-cloudy .weather-icon {
    color: #6c757d;
}

.weather-card.weather-rainy .weather-icon {
    color: #4a90e2;
}

.weather-card.weather-foggy .weather-icon {
    color: #9e9e9e;
}

.weather-card.weather-hot .weather-icon {
    color: #ff6b6b;
}

.weather-card.weather-cold .weather-icon {
    color: #87ceeb;
}

/* Weather location (top) - like "Athens" in clock widget */
.weather-location {
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-primary);
    text-align: center;
    margin-bottom: auto;
    padding-top: var(--space-2);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Weather time (center) - large digital clock style */
.weather-time {
    font-size: 3.5rem;
    font-weight: 600;
    color: var(--text-primary);
    font-family: var(--font-mono);
    text-align: center;
    padding: var(--space-3) 0;
    margin: var(--space-4) 0;
    line-height: 1;
    letter-spacing: 0.05em;
}

/* Weather status (bottom) - like date in clock widget */
.weather-status {
    font-size: 0.8125rem;
    font-weight: 400;
    color: var(--text-secondary);
    text-align: center;
    margin-top: auto;
    padding-bottom: var(--space-3);
    text-transform: capitalize;
    line-height: 1.4;
}

/* Weather icon container - positioned absolutely or as overlay */
.weather-icon-container {
    position: absolute;
    top: var(--space-3);
    right: var(--space-3);
    opacity: 0.3;
    transition: opacity var(--transition-base);
}

.weather-card:hover .weather-icon-container {
    opacity: 0.5;
}

/* Weather icon - smaller, decorative, soft edges */
.weather-card .weather-icon {
    width: 48px;
    height: 48px;
    border-radius: 16px;
    overflow: hidden;
}

.weather-card .weather-icon svg {
    width: 48px;
    height: 48px;
    color: var(--text-tertiary);
    border-radius: 12px;
}

#weatherStatus {
    color: var(--text-secondary);
    font-size: 0.8125rem;
    text-transform: capitalize;
}

.metric-label {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Fan Status Indicator */
.fan-status-indicator {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    justify-content: center;
    padding: var(--space-2) 0;
}

.fan-status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--text-tertiary);
    transition: all var(--transition-base);
    position: relative;
}

.fan-status-dot::before {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: inherit;
    opacity: 0.6;
    animation: pulse 2s ease-in-out infinite;
}

.fan-status-dot.fan-on {
    background: var(--accent-green);
    box-shadow: 0 0 12px rgba(63, 185, 80, 0.5);
}

.fan-status-dot.fan-on::before {
    animation: pulseActive 2s ease-in-out infinite;
}

.fan-status-dot.fan-off {
    background: var(--text-tertiary);
}

@keyframes pulse {
    0%, 100% {
        transform: scale(1);
        opacity: 0.6;
    }
    50% {
        transform: scale(1.5);
        opacity: 0;
    }
}

@keyframes pulseActive {
    0%, 100% {
        transform: scale(1);
        opacity: 0.6;
    }
    50% {
        transform: scale(2);
        opacity: 0;
    }
}

.fan-status-text {
    font-size: 1.25rem;
    font-weight: 700;
    font-family: var(--font-mono);
    color: var(--text-secondary);
    transition: color var(--transition-base);
    letter-spacing: 0.05em;
}

.fan-status-text.fan-on {
    color: var(--accent-green);
}

.fan-status-text.fan-off {
    color: var(--text-tertiary);
}

.metric-value-group {
    display: flex;
    align-items: baseline;
    gap: var(--space-1);
    margin-bottom: var(--space-2);
}

.metric-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.02em;
    line-height: 1.1;
}

.metric-unit {
    font-size: 1rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.metric-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: var(--space-1);
}

.metric-trend {
    display: flex;
    align-items: center;
    gap: var(--space-1);
    font-size: 0.6875rem;
    color: var(--text-tertiary);
    font-weight: 500;
}

.metric-trend svg {
    width: 12px;
    height: 12px;
    color: var(--accent-green);
}

/* ==================== CHART SECTION ==================== */
.chart-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 0 var(--space-8) var(--space-4) var(--space-8);
    max-width: 1400px;
    width: 100%;
    margin-left: auto;
    margin-right: auto;
    min-height: 0;
    overflow: hidden;
    padding-bottom: var(--space-4);
}

.chart-section .section-header {
    margin-bottom: var(--space-2);
    flex-shrink: 0;
}

.chart-container {
    background: var(--bg-elevated);
    border: 1px solid var(--border-base);
    border-radius: 12px;
    padding: var(--space-4);
    flex: 1;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

/* High-tech glow effect overlay */
.chart-container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: 
        radial-gradient(circle at 20% 50%, rgba(255, 107, 53, 0.03) 0%, transparent 50%),
        radial-gradient(circle at 80% 50%, rgba(77, 171, 247, 0.03) 0%, transparent 50%);
    pointer-events: none;
    z-index: 1;
}

.chart-container canvas {
    position: relative;
    z-index: 2;
}

#dataChart {
    max-height: 100%;
    width: 100% !important;
    height: auto !important;
    filter: drop-shadow(0 0 8px rgba(255, 107, 53, 0.2)) 
            drop-shadow(0 0 8px rgba(77, 171, 247, 0.2));
    animation: chartGlow 3s ease-in-out infinite alternate;
}

@keyframes chartGlow {
    0% {
        filter: drop-shadow(0 0 6px rgba(255, 107, 53, 0.15)) 
                drop-shadow(0 0 6px rgba(77, 171, 247, 0.15));
    }
    100% {
        filter: drop-shadow(0 0 12px rgba(255, 107, 53, 0.25)) 
                drop-shadow(0 0 12px rgba(77, 171, 247, 0.25));
    }
}

/* ==================== CONTROL PANEL ==================== */
.control-panel {
    margin-bottom: var(--space-8);
    padding: var(--space-8);
    max-width: 1400px;
    width: 100%;
    margin-left: auto;
    margin-right: auto;
}

.control-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: var(--space-6);
}

.control-card {
    background: var(--bg-elevated);
    border: 1px solid var(--border-base);
    border-radius: 12px;
    padding: var(--space-6);
    transition: all var(--transition-base);
}

.control-card:hover {
    border-color: var(--border-hover);
    box-shadow: var(--shadow-md);
}

.control-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-6);
    padding-bottom: var(--space-4);
    border-bottom: 1px solid var(--border-base);
}

.control-label {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--text-primary);
}

.control-label svg {
    width: 20px;
    height: 20px;
    color: var(--text-secondary);
}

.control-state {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.state-indicator {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--status-offline);
    transition: all var(--transition-base);
}

.state-indicator.active {
    background: var(--status-online);
    box-shadow: 0 0 8px var(--status-online);
}

.state-text {
    font-size: 0.875rem;
    color: var(--text-secondary);
    font-weight: 500;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.05em;
}

.control-actions {
    display: flex;
    gap: var(--space-3);
}

.control-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-4);
    border: 1px solid var(--border-base);
    border-radius: 8px;
    background: var(--bg-hover);
    color: var(--text-primary);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-base);
    font-family: var(--font-sans);
}

.control-btn svg {
    width: 16px;
    height: 16px;
}

.control-btn:hover {
    background: var(--bg-active);
    border-color: var(--border-hover);
    transform: translateY(-1px);
}

.control-btn:active {
    transform: translateY(0);
}

.btn-activate {
    color: var(--accent-green);
    border-color: rgba(63, 185, 80, 0.3);
}

.btn-activate:hover {
    background: rgba(63, 185, 80, 0.1);
    border-color: var(--accent-green);
}

.btn-deactivate {
    color: var(--accent-orange);
    border-color: rgba(248, 81, 73, 0.3);
}

.btn-deactivate:hover {
    background: rgba(248, 81, 73, 0.1);
    border-color: var(--accent-orange);
}

/* ==================== SETTINGS PANEL ==================== */
.settings-panel {
    margin-bottom: var(--space-8);
    padding: var(--space-8);
    max-width: 1400px;
    width: 100%;
    margin-left: auto;
    margin-right: auto;
}

.settings-form {
    background: var(--bg-elevated);
    border: 1px solid var(--border-base);
    border-radius: 12px;
    padding: var(--space-6);
    display: flex;
    flex-direction: column;
    gap: var(--space-6);
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.form-label {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.form-label svg {
    width: 16px;
    height: 16px;
}

.form-input {
    padding: var(--space-3) var(--space-4);
    background: var(--bg-base);
    border: 1px solid var(--border-base);
    border-radius: 8px;
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 0.875rem;
    transition: all var(--transition-base);
}

.form-input:focus {
    outline: none;
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 3px rgba(88, 166, 255, 0.1);
}

.form-input::placeholder {
    color: var(--text-tertiary);
}

.form-actions {
    display: flex;
    gap: var(--space-3);
    margin-top: var(--space-2);
}

.form-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-5);
    border: 1px solid var(--border-base);
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-base);
    font-family: var(--font-sans);
}

.form-btn svg {
    width: 18px;
    height: 18px;
}

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

.btn-primary:hover {
    background: #4a9eff;
    border-color: #4a9eff;
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

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

.btn-secondary:hover {
    background: var(--bg-active);
    border-color: var(--border-hover);
    transform: translateY(-1px);
}

/* ==================== TOGGLE SWITCH ==================== */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 26px;
}

.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: var(--bg-hover);
    border: 1px solid var(--border-base);
    transition: var(--transition-base);
    border-radius: 26px;
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: var(--text-secondary);
    transition: var(--transition-base);
    border-radius: 50%;
}

.toggle-switch input:checked + .toggle-slider {
    background-color: var(--accent-green);
    border-color: var(--accent-green);
}

.toggle-switch input:checked + .toggle-slider:before {
    transform: translateX(24px);
    background-color: white;
}

.toggle-switch input:focus + .toggle-slider {
    box-shadow: 0 0 1px var(--accent-green);
}

/* ==================== SIDEBAR TOGGLE (Desktop) ==================== */
.sidebar-toggle {
    display: none !important; /* Hidden by default */
    position: fixed;
    top: var(--space-4);
    left: var(--space-4);
    z-index: 1001;
    background: var(--bg-elevated);
    border: 1px solid var(--border-base);
    border-radius: 8px;
    padding: var(--space-3);
    color: var(--text-primary);
    cursor: pointer;
    transition: all var(--transition-base);
    width: 40px;
    height: 40px;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* Adjust topbar padding when sidebar is collapsed to avoid button overlap */
.app-container.sidebar-collapsed .topbar {
    padding-left: calc(var(--space-8) + 56px); /* space-8 + button width + gap */
}

/* Show floating toggle button when sidebar is collapsed */
@media (min-width: 769px) {
    .sidebar.collapsed ~ .main-content .sidebar-toggle,
    .sidebar.collapsed ~ * .sidebar-toggle {
        display: flex !important;
    }
}

.sidebar-toggle:hover {
    background: var(--bg-hover);
    border-color: var(--border-hover);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.sidebar-toggle svg {
    width: 20px;
    height: 20px;
}

/* ==================== MOBILE MENU TOGGLE ==================== */
.mobile-menu-toggle {
    display: none;
    position: fixed;
    top: var(--space-4);
    left: var(--space-4);
    z-index: 1000;
    background: var(--bg-elevated);
    border: 1px solid var(--border-base);
    border-radius: 8px;
    padding: var(--space-3);
    color: var(--text-primary);
    cursor: pointer;
    transition: all var(--transition-base);
    width: 44px;
    height: 44px;
    align-items: center;
    justify-content: center;
}

.mobile-menu-toggle:hover {
    background: var(--bg-hover);
    border-color: var(--border-hover);
}

.mobile-menu-toggle svg {
    width: 24px;
    height: 24px;
}

.sidebar-close {
    display: none;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: var(--space-2);
    border-radius: 6px;
    transition: all var(--transition-base);
    width: 32px;
    height: 32px;
    align-items: center;
    justify-content: center;
    flex-shrink: 0; /* Prevent button from shrinking */
}

.sidebar-close:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.sidebar-close svg {
    width: 20px;
    height: 20px;
}

/* ==================== RESPONSIVE ==================== */
@media (min-width: 769px) {
    /* Desktop: Show floating sidebar toggle ONLY when sidebar is collapsed */
    .app-container.sidebar-collapsed .sidebar-toggle {
        display: flex !important;
    }
    
    /* Hide floating toggle when sidebar is NOT collapsed */
    .app-container:not(.sidebar-collapsed) .sidebar-toggle {
        display: none !important;
    }
    
    /* Also show toggle button in sidebar header when not collapsed */
    .sidebar:not(.collapsed) .sidebar-header {
        position: relative;
    }
}

@media (max-width: 1024px) {
    .sidebar {
        width: 240px;
    }
    
    .sidebar.collapsed {
        transform: translateX(-240px);
    }
    
    .main-content {
        margin-left: 240px;
    }
    
    .sidebar.collapsed ~ .main-content {
        margin-left: 0;
    }
    
    .metrics-grid {
        grid-template-columns: 1.5fr 1fr;
        gap: var(--space-4);
    }
    
    .weather-card {
        grid-row: 1 / 3;
        min-height: 280px;
    }
}

@media (max-width: 768px) {
    /* Hide desktop sidebar toggle on mobile */
    .sidebar-toggle {
        display: none !important;
    }
    
    .sidebar-toggle-header {
        display: none !important;
    }
    
    /* Mobile Menu Toggle */
    .mobile-menu-toggle {
        display: flex;
    }
    
    .sidebar-close {
        display: flex;
    }
    
    /* Sidebar - Hidden by default on mobile, slides in when toggled */
    .sidebar {
        width: 280px;
        position: fixed;
        left: -280px;
        top: 0;
        height: 100vh;
        z-index: 999;
        transition: left var(--transition-base);
        border-right: 1px solid var(--border-base);
        transform: none; /* Override desktop transform */
    }
    
    .sidebar.collapsed {
        transform: none; /* Override desktop collapsed transform on mobile */
    }
    
    .sidebar.mobile-open {
        left: 0;
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.5);
    }
    
    /* Overlay when sidebar is open */
    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 998;
        backdrop-filter: blur(4px);
    }
    
    .sidebar-overlay.active {
        display: block;
    }
    
    .main-content {
        margin-left: 0;
        width: 100%;
        padding-top: 0;
    }
    
    /* Topbar adjustments - ensure padding accounts for mobile menu button */
    .topbar {
        padding: var(--space-3) var(--space-4);
        margin-left: 0;
        padding-left: calc(var(--space-4) + 44px + var(--space-3)); /* Space for hamburger menu */
        margin-top: 0;
    }
    
    /* Reset topbar padding when sidebar is collapsed (not applicable on mobile but prevent conflicts) */
    .app-container.sidebar-collapsed .topbar {
        padding-left: calc(var(--space-4) + 44px + var(--space-3)); /* Keep mobile menu spacing */
    }
    
    .page-title {
        font-size: 1.125rem;
    }
    
    .page-subtitle {
        font-size: 0.75rem;
    }
    
    .timestamp {
        font-size: 0.75rem;
        padding: var(--space-2) var(--space-3);
    }
    
    /* Metrics Grid - Single column on mobile */
    .metrics-grid {
        grid-template-columns: 1fr;
        grid-template-rows: auto;
        gap: var(--space-3);
        padding: var(--space-3);
        margin-bottom: var(--space-3);
    }
    
    .weather-card {
        grid-row: auto;
        grid-column: 1;
        min-height: 240px;
        padding: var(--space-4);
    }
    
    .temp-card,
    .hum-card,
    .fan-card {
        grid-column: 1;
        grid-row: auto;
    }
    
    /* Weather card mobile adjustments */
    .weather-card .weather-icon {
        width: 40px;
        height: 40px;
    }
    
    .weather-card .weather-icon svg {
        width: 40px;
        height: 40px;
    }
    
    .weather-time {
        font-size: 2.5rem;
    }
    
    .weather-location {
        font-size: 0.875rem;
    }
    
    .weather-status {
        font-size: 0.75rem;
    }
    
    .weather-icon-container {
        top: var(--space-2);
        right: var(--space-2);
    }
    
    .metric-card {
        padding: var(--space-5);
    }
    
    /* View content - allow scrolling on mobile */
    .view-content {
        height: auto;
        min-height: calc(100vh - 60px);
        overflow-y: auto;
        overflow-x: hidden;
    }
    
    /* Dashboard view - scrollable on mobile */
    #dashboardView {
        height: auto;
        max-height: none;
        overflow-y: auto;
        overflow-x: hidden;
    }
    
    /* Settings view - scrollable on mobile */
    #settingsView {
        height: auto;
        min-height: calc(100vh - 60px);
        overflow-y: auto;
        overflow-x: hidden;
    }
    
    /* Chart Section */
    .chart-section {
        padding: var(--space-4);
        padding-bottom: calc(var(--space-8) + 80px); /* Extra space for mobile scrolling */
        margin-bottom: calc(var(--space-6) + 40px); /* Extra margin to ensure full visibility */
        min-height: 300px;
        flex-shrink: 0;
    }
    
    .chart-container {
        padding: var(--space-4);
        padding-bottom: calc(var(--space-6) + 40px); /* Extra padding for mobile */
        min-height: 300px;
        flex-shrink: 0;
    }
    
    /* Control Grid */
    .control-grid {
        grid-template-columns: 1fr;
        gap: var(--space-4);
    }
    
    .control-card {
        padding: var(--space-5);
    }
    
    /* Settings Panel */
    .settings-panel {
        padding: var(--space-4);
        margin-top: var(--space-6);
    }
    
    .settings-form {
        padding: 0;
        margin-top: var(--space-4);
    }
    
    /* Form Elements */
    .form-group {
        margin-bottom: var(--space-4);
    }
    
    .form-input {
        font-size: 16px; /* Prevents zoom on iOS */
        padding: var(--space-3) var(--space-4);
    }
    
    .form-actions {
        flex-direction: column;
        gap: var(--space-3);
    }
    
    .form-btn {
        width: 100%;
        padding: var(--space-4);
        font-size: 0.9375rem;
    }
    
    /* View Content */
    .view-content {
        min-height: calc(100vh - 60px);
        max-height: calc(100vh - 60px);
        padding-top: 0;
        overflow-y: auto;
        overflow-x: hidden;
    }
    
    .view-content > section {
        padding: var(--space-4);
        margin-top: 0;
        margin-bottom: var(--space-6);
    }
    
    .view-content > section:last-child {
        margin-bottom: calc(var(--space-4) + 100px); /* Extra bottom margin for mobile scrolling */
    }
    
    /* Control Panel and Settings Panel spacing */
    .control-panel {
        margin-top: var(--space-4);
        margin-bottom: var(--space-6);
        padding: var(--space-4);
    }
    
    .settings-panel {
        margin-top: var(--space-6);
        margin-bottom: var(--space-4);
        padding: var(--space-4);
    }
    
    .control-panel .section-header,
    .settings-panel .section-header {
        margin-bottom: var(--space-4);
    }
    
    /* Ensure sections don't overlap */
    .view-content > .control-panel + .settings-panel {
        margin-top: var(--space-6);
    }
    
    /* Section Headers */
    .section-header {
        margin-bottom: var(--space-4);
    }
    
    .section-title {
        font-size: 1.125rem;
    }
    
    .section-description {
        font-size: 0.8125rem;
    }
}

@media (max-width: 480px) {
    .mobile-menu-toggle {
        top: var(--space-3);
        left: var(--space-3);
    }
    
    /* Ensure sidebar toggle is hidden on small mobile */
    .sidebar-toggle,
    .sidebar-toggle-header {
        display: none !important;
    }
    
    .topbar {
        padding: var(--space-3);
        padding-left: calc(var(--space-3) + 44px + var(--space-2));
        flex-wrap: wrap;
        gap: var(--space-2);
    }
    
    /* Reset topbar padding when sidebar is collapsed (not applicable on mobile but prevent conflicts) */
    .app-container.sidebar-collapsed .topbar {
        padding-left: calc(var(--space-3) + 44px + var(--space-2));
    }
    
    .topbar-left {
        flex: 1;
        min-width: 0;
    }
    
    .topbar-right {
        flex-shrink: 0;
    }
    
    .page-title {
        font-size: 1rem;
    }
    
    .page-subtitle {
        display: none; /* Hide subtitle on very small screens */
    }
    
    .view-content > section {
        padding: var(--space-3);
    }
    
    .control-panel,
    .settings-panel {
        padding: var(--space-3);
        margin-top: var(--space-3);
    }
    
    .metrics-grid {
        padding: var(--space-2);
        gap: var(--space-2);
    }
    
    .weather-card {
        min-height: 200px;
        padding: var(--space-3);
    }
    
    .weather-time {
        font-size: 2rem;
    }
    
    .weather-card .weather-icon {
        width: 36px;
        height: 36px;
    }
    
    .weather-card .weather-icon svg {
        width: 36px;
        height: 36px;
    }
    
    .metric-value {
        font-size: 1.75rem;
    }
    
    .metric-unit {
        font-size: 0.875rem;
    }
    
    .chart-section {
        padding-bottom: calc(var(--space-8) + 100px); /* Extra space for very small mobile screens */
        margin-bottom: calc(var(--space-6) + 60px); /* Extra margin for full chart visibility */
    }
    
    .chart-container {
        padding: var(--space-3);
        padding-bottom: calc(var(--space-6) + 60px); /* Extra padding for very small screens */
        min-height: 250px;
    }
    
    .form-input {
        padding: var(--space-3);
    }
    
    .btn-group {
        flex-direction: column;
        width: 100%;
    }
    
    .btn {
        width: 100%;
    }
}

/* ==================== UTILITIES ==================== */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.metric-card,
.control-card,
.chart-container {
    animation: fadeIn 0.4s ease-out;
}
