:root {
    --bg-dark: #0f172a;
    --bg-darker: #020617;
    --surface: #1e293b;
    --surface-hover: #334155;
    --primary: #3b82f6;
    --primary-glow: rgba(59, 130, 246, 0.5);
    --secondary: #8b5cf6;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --success: #10b981;
    --danger: #ef4444;
    --border: rgba(255, 255, 255, 0.08);
}

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

body {
    font-family: 'Outfit', sans-serif;
    background-color: var(--bg-darker);
    color: var(--text-primary);
    overflow: hidden;
}

.app-container {
    display: flex;
    height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 260px;
    background-color: var(--bg-dark);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 24px;
}

.brand {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 48px;
}

.brand i {
    color: var(--primary);
    font-size: 28px;
}

.nav-menu {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 14px 16px;
    text-decoration: none;
    color: var(--text-secondary);
    border-radius: 12px;
    font-weight: 500;
    transition: all 0.3s ease;
}

.nav-item i {
    font-size: 20px;
    width: 24px;
    text-align: center;
}

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

.nav-item.active {
    background: linear-gradient(135deg, rgba(59,130,246,0.1) 0%, rgba(139,92,246,0.1) 100%);
    color: var(--primary);
    border: 1px solid rgba(59, 130, 246, 0.2);
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 12px;
    padding-top: 24px;
    border-top: 1px solid var(--border);
}

.avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}

.user-profile .info {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.user-profile .name {
    font-weight: 600;
    font-size: 14px;
}

.user-profile .role {
    font-size: 12px;
    color: var(--text-secondary);
}

#logoutBtn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    transition: color 0.3s;
}

#logoutBtn:hover {
    color: var(--danger);
}

/* Main Content */
.main-content {
    flex: 1;
    padding: 40px;
    overflow-y: auto;
    background: radial-gradient(circle at top right, rgba(59, 130, 246, 0.05), transparent 40%),
                radial-gradient(circle at bottom left, rgba(139, 92, 246, 0.05), transparent 40%);
}

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

.greeting h1 {
    font-size: 32px;
    font-weight: 600;
    margin-bottom: 4px;
}

.greeting p {
    color: var(--text-secondary);
    font-size: 15px;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 16px;
}

.weather-widget {
    background: rgba(255,255,255,0.03);
    border: 1px solid var(--border);
    padding: 10px 16px;
    border-radius: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
    font-weight: 500;
    backdrop-filter: blur(10px);
}

.weather-widget i {
    color: #f59e0b;
}

.icon-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.icon-btn:hover {
    background: var(--surface-hover);
    transform: translateY(-2px);
}

/* Sections */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

.section-header h2 {
    font-size: 22px;
    font-weight: 600;
}

.add-btn {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.3s;
}

.add-btn:hover {
    color: var(--primary);
    border-color: var(--primary);
}

/* Rooms */
.rooms-container {
    display: flex;
    gap: 20px;
    overflow-x: auto;
    padding-bottom: 20px;
    margin-bottom: 20px;
    scrollbar-width: none; /* Firefox */
}

.rooms-container::-webkit-scrollbar {
    display: none;
}

.room-card {
    min-width: 140px;
    height: 140px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 16px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.room-card i {
    font-size: 32px;
    color: var(--text-secondary);
    transition: color 0.3s;
}

.room-card span {
    font-weight: 500;
    color: var(--text-secondary);
    transition: color 0.3s;
}

.room-card:hover {
    background: var(--surface-hover);
    transform: translateY(-4px);
    box-shadow: 0 10px 20px rgba(0,0,0,0.2);
}

.room-card.active {
    background: linear-gradient(135deg, rgba(59,130,246,0.15) 0%, rgba(139,92,246,0.15) 100%);
    border-color: rgba(59, 130, 246, 0.3);
}

.room-card.active i {
    color: var(--primary);
}

.room-card.active span {
    color: var(--primary);
}

/* Devices Grid */
.devices-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 24px;
}

/* Glassmorphism Device Card */
.device-card {
    background: rgba(30, 41, 59, 0.6);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 24px;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    position: relative;
    overflow: hidden;
}

.device-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, rgba(255,255,255,0.05) 0%, transparent 100%);
    pointer-events: none;
}

.device-card.active {
    background: rgba(30, 41, 59, 0.9);
    border-color: rgba(59, 130, 246, 0.3);
    box-shadow: 0 15px 30px rgba(0,0,0,0.3), 0 0 20px rgba(59, 130, 246, 0.1);
}

.device-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    z-index: 1;
}

.device-icon {
    width: 52px;
    height: 52px;
    border-radius: 16px;
    background: rgba(255,255,255,0.05);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    color: var(--text-secondary);
    transition: all 0.3s;
}

.device-card.active .device-icon {
    background: var(--primary);
    color: white;
    box-shadow: 0 0 15px var(--primary-glow);
}

/* Custom Switch */
.switch {
    position: relative;
    display: inline-block;
    width: 52px;
    height: 28px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(255,255,255,0.1);
    transition: .4s;
    border-radius: 34px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 4px;
    bottom: 4px;
    background-color: var(--text-secondary);
    transition: .4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    border-radius: 50%;
}

input:checked + .slider {
    background-color: var(--primary);
}

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

.device-info {
    z-index: 1;
}

.device-info h3 {
    font-size: 18px;
    font-weight: 500;
    margin-bottom: 4px;
}

.device-info p {
    color: var(--text-secondary);
    font-size: 14px;
}

.device-card.active .device-info h3 {
    color: var(--primary);
}

/* Toast */
.toast {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--surface);
    border: 1px solid var(--border);
    padding: 12px 24px;
    border-radius: 30px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 1000;
    pointer-events: none;
}

.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

/* Modal */
.modal {
    display: none; 
    position: fixed; 
    z-index: 2000; 
    left: 0;
    top: 0;
    width: 100%; 
    height: 100%; 
    background-color: rgba(0,0,0,0.6); 
    backdrop-filter: blur(5px);
    align-items: center;
    justify-content: center;
}

.modal.show {
    display: flex;
}

.modal-content {
    background-color: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 30px;
    width: 90%;
    max-width: 400px;
    position: relative;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    animation: modalPop 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes modalPop {
    from { transform: scale(0.8); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.close-modal {
    position: absolute;
    top: 20px;
    right: 20px;
    color: var(--text-secondary);
    font-size: 24px;
    font-weight: bold;
    cursor: pointer;
    transition: 0.3s;
}

.close-modal:hover {
    color: var(--danger);
}

.modal-content h2 {
    margin-top: 0;
    margin-bottom: 10px;
    font-size: 20px;
    color: var(--primary);
}

.modal-btn {
    background: var(--primary);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    font-size: 15px;
    transition: 0.3s;
    width: 100%;
}

.modal-btn:hover {
    background: #2563eb;
}

/* Tabs */
.tab-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    padding: 5px 10px;
    border-radius: 6px;
    transition: 0.3s;
}

.tab-btn.active {
    background: rgba(59, 130, 246, 0.2);
    color: var(--primary);
}

.timer-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(255,255,255,0.05);
    padding: 10px;
    border-radius: 8px;
    margin-bottom: 8px;
    font-size: 14px;
}
.timer-item button {
    background: var(--danger);
    border: none;
    color: white;
    padding: 5px 10px;
    border-radius: 5px;
    cursor: pointer;
}

select option {
    background-color: var(--surface);
    color: var(--text-primary);
}

/* Custom Slider for Brightness */
input[type=range] {
    -webkit-appearance: none;
    background: transparent;
}
input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    height: 16px;
    width: 16px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    margin-top: -6px;
    box-shadow: 0 0 10px rgba(59, 130, 246, 0.5);
}
input[type=range]::-webkit-slider-runnable-track {
    width: 100%;
    height: 4px;
    cursor: pointer;
    background: rgba(255,255,255,0.1);
    border-radius: 2px;
}
input[type=range]:focus {
    outline: none;
}

@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7);
    }
    70% {
        box-shadow: 0 0 0 6px rgba(239, 68, 68, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0);
    }
}

/* Sidebar collapsed state */
.sidebar { transition: width 0.3s ease, transform 0.3s ease; overflow-x: hidden; z-index: 1000; }
.sidebar.collapsed { width: 80px; padding-left: 10px; padding-right: 10px; }
.sidebar.collapsed .brand span { display: none; }
.sidebar.collapsed .brand { justify-content: center; }
.sidebar.collapsed .nav-item { justify-content: center; padding: 14px 0; }
.sidebar.collapsed .nav-item span { display: none; }
.sidebar.collapsed .nav-item i { margin: 0; }
.sidebar.collapsed .user-profile .info { display: none; }
.sidebar.collapsed .user-profile #logoutBtn { display: none; }
.sidebar.collapsed .user-profile { justify-content: center; }

/* Responsive Media Queries */
@media (max-width: 1024px) {
    .main-content { padding: 20px; }
    .header { margin-bottom: 30px; }
    .greeting h1 { font-size: 26px; }
}

@media (max-width: 768px) {
    .sidebar { 
        position: absolute; 
        height: 100%; 
        left: 0; 
        top: 0; 
        transform: translateX(0);
        box-shadow: 5px 0 15px rgba(0,0,0,0.5);
    }
    .sidebar.collapsed { 
        transform: translateX(-100%); 
        width: 260px; /* Keep full width when off-screen, or keep it 80px if preferred. Let's make it fully hidden */
    }
    
    .header { flex-direction: column; align-items: flex-start; gap: 15px; }
    .header-actions { width: 100%; justify-content: space-between; }
    .greeting h1 { font-size: 24px; }
    
    .devices-grid { 
        grid-template-columns: 1fr; 
    }
}

@media (max-width: 480px) {
    .weather-widget { font-size: 12px; padding: 8px 12px; }
    .room-card { min-width: 120px; height: 120px; padding: 15px; gap: 10px; }
    .room-card i { font-size: 24px; }
    .room-card span { font-size: 14px; }
    .section-header h2 { font-size: 20px; }
}
