:root {
    --primary-color: #4CAF50;
    --secondary-color: #8BC34A;
    --accent-color: #FF9800;
    --dark-color: #2E7D32;
    --light-color: #F1F8E9;
    --danger-color: #f44336;
    --success-color: #4CAF50;
    --warning-color: #ff9800;
    --text-color: #333;
    --bg-color: #f8f9fa;
    --card-bg: #ffffff;
    --border-color: #e0e0e0;
    --shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    --shadow-hover: 0 8px 25px rgba(0, 0, 0, 0.15);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Roboto', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 20px;
}

/* Header Styles */
.dashboard-header {
    background: linear-gradient(135deg, var(--primary-color), var(--dark-color));
    color: white;
    padding: 20px 0;
    margin-bottom: 30px;
    border-radius: 0 0 15px 15px;
    box-shadow: var(--shadow);
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 20px;
}

.header-title h1 {
    font-size: 2.2rem;
    margin-bottom: 5px;
    font-weight: 700;
}

.header-title p {
    font-size: 1.1rem;
    opacity: 0.9;
}

.header-title i {
    margin-right: 10px;
}

/* User Info Styles */
.user-info {
    display: flex;
    align-items: center;
    gap: 20px;
}

.user-welcome {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-welcome i {
    font-size: 2rem;
    opacity: 0.9;
}

.user-details {
    display: flex;
    flex-direction: column;
}

.welcome-text {
    font-size: 1rem;
    font-weight: 500;
}

.role-badge {
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
}

.role-badge.admin {
    background: rgba(255, 255, 255, 0.2);
    color: white;
}

.role-badge.user {
    background: rgba(255, 255, 255, 0.15);
    color: white;
}

.role-badge.farmer {
    background: rgba(255, 255, 255, 0.1);
    color: white;
}

.header-actions {
    display: flex;
    gap: 10px;
}

.profile-btn, .logout-btn {
    padding: 8px 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 8px;
    color: white;
    text-decoration: none;
    font-weight: 500;
    transition: all 0.3s ease;
    background: rgba(255, 255, 255, 0.1);
}

.profile-btn:hover, .logout-btn:hover {
    background: white;
    color: var(--primary-color);
    transform: translateY(-2px);
}

/* ESP Selector */
.esp-selector {
    display: flex;
    gap: 10px;
    margin-bottom: 30px;
    background: white;
    padding: 15px;
    border-radius: 12px;
    box-shadow: var(--shadow);
}

.esp-tab {
    flex: 1;
    padding: 12px 20px;
    border: none;
    border-radius: 8px;
    background: #f5f5f5;
    color: #666;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 500;
    font-size: 0.9rem;
}

.esp-tab.active {
    background: linear-gradient(135deg, var(--primary-color), var(--dark-color));
    color: white;
    box-shadow: var(--shadow);
}

.esp-tab:hover:not(.active) {
    background: #e0e0e0;
    transform: translateY(-2px);
}

/* Main Content */
.dashboard-content {
    margin-bottom: 40px;
}

.esp-section {
    display: none;
    margin-bottom: 40px;
}

.esp-section.active {
    display: block;
    animation: fadeInUp 0.6s ease;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Section Header */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 25px;
    padding: 20px;
    background: white;
    border-radius: 12px;
    box-shadow: var(--shadow);
}

.section-header h2 {
    color: var(--dark-color);
    font-size: 1.5rem;
}

.section-header i {
    margin-right: 10px;
    color: var(--primary-color);
}

.location-tag {
    background: var(--light-color);
    padding: 8px 15px;
    border-radius: 20px;
    color: var(--dark-color);
    font-size: 0.9rem;
    font-weight: 500;
}

.location-tag i {
    margin-right: 5px;
}

/* Sensor Grid */
.sensor-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

/* Sensor Card */
.sensor-card {
    background: white;
    border-radius: 15px;
    padding: 25px;
    box-shadow: var(--shadow);
    transition: all 0.3s ease;
    border-left: 4px solid var(--primary-color);
}

.sensor-card:hover {
    transform: translateY(-5px);
    box-shadow: var(--shadow-hover);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 15px;
}

.card-header h3 {
    color: var(--dark-color);
    font-size: 1.1rem;
    font-weight: 600;
}

.sensor-tag {
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
}

.sensor-tag.dht22 {
    background: #e3f2fd;
    color: #1976d2;
}

.sensor-tag.yl69 {
    background: #e8f5e9;
    color: #388e3c;
}

.card-value {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--dark-color);
    margin: 15px 0;
    text-align: center;
}

.card-progress {
    height: 20px;
    background: #f0f0f0;
    border-radius: 10px;
    overflow: hidden;
    margin: 20px 0;
}

.progress-bar {
    height: 100%;
    border-radius: 10px;
    transition: width 0.5s ease;
}

#esp1-air-temperature-bar,
#esp2-air-temperature-bar {
    background: linear-gradient(90deg, #ff6b6b, #ffa726);
}

#esp1-soil-moisture-bar,
#esp2-soil-moisture-bar {
    background: linear-gradient(90deg, #4facfe, #00f2fe);
}

#esp1-soil-temperature-bar,
#esp2-soil-temperature-bar {
    background: linear-gradient(90deg, #a1c4fd, #c2e9fb);
}

.card-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 15px;
    font-size: 0.9rem;
}

.status-indicator {
    font-weight: 600;
    padding: 4px 12px;
    border-radius: 15px;
    font-size: 0.8rem;
}

.status-indicator:not([class*="status-"]) {
    background: var(--light-color);
    color: var(--success-color);
}

.status-optimal {
    background: #e8f5e9;
    color: var(--success-color);
}

.status-warning {
    background: #fff3e0;
    color: var(--warning-color);
}

.status-danger {
    background: #ffebee;
    color: var(--danger-color);
}

.update-time {
    color: #666;
    font-size: 0.8rem;
}

/* Control Card */
.control-card {
    background: white;
    border-radius: 15px;
    padding: 25px;
    box-shadow: var(--shadow);
    border-left: 4px solid var(--accent-color);
    text-align: center;
}

.control-tag {
    background: #fff3e0;
    color: var(--accent-color);
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
}

.control-status {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 15px;
    margin: 20px 0;
}

.pump-state {
    font-size: 1.2rem;
    font-weight: 600;
    padding: 8px 16px;
    border-radius: 20px;
    background: #ffebee;
    color: var(--danger-color);
}

.pump-state.active {
    background: #e8f5e9;
    color: var(--success-color);
}

/* Toggle Switch */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 60px;
    height: 34px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: .4s;
    border-radius: 34px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 26px;
    width: 26px;
    left: 4px;
    bottom: 4px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked + .slider {
    background-color: var(--success-color);
}

input:checked + .slider:before {
    transform: translateX(26px);
}

.mode-indicator {
    margin: 15px 0;
    font-size: 1rem;
}

.control-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-color), var(--dark-color));
    color: white;
}

.btn-secondary {
    background: #f5f5f5;
    color: #666;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

/* Charts Section */
.charts-section {
    background: white;
    border-radius: 15px;
    padding: 25px;
    box-shadow: var(--shadow);
    margin-top: 30px;
}

.charts-section h3 {
    color: var(--dark-color);
    margin-bottom: 20px;
    font-size: 1.3rem;
}

.charts-section i {
    margin-right: 10px;
    color: var(--primary-color);
}

.charts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
    gap: 20px;
}

.chart-wrapper {
    background: #fafafa;
    border-radius: 10px;
    padding: 15px;
    border: 1px solid var(--border-color);
}

.chart-title {
    text-align: center;
    font-weight: 600;
    margin-bottom: 10px;
    color: var(--dark-color);
}

.chart-wrapper canvas {
    width: 100% !important;
    height: 200px !important;
}

/* Notification System */
.notification {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: var(--success-color);
    color: white;
    padding: 15px 20px;
    border-radius: 10px;
    box-shadow: var(--shadow-hover);
    transform: translateX(400px);
    transition: transform 0.3s ease;
    z-index: 1000;
    max-width: 350px;
}

.notification.show {
    transform: translateX(0);
}

.notification.error {
    background: var(--danger-color);
}

.notification.warning {
    background: var(--warning-color);
}

.notification-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 15px;
}

.notification-close {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    font-size: 1.1rem;
    padding: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Responsive Design */
@media (max-width: 1200px) {
    .container {
        max-width: 100%;
        padding: 0 15px;
    }
    
    .sensor-grid {
        grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    }
    
    .charts-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .header-content {
        flex-direction: column;
        text-align: center;
    }
    
    .user-info {
        flex-direction: column;
        gap: 15px;
    }
    
    .esp-selector {
        flex-direction: column;
    }
    
    .section-header {
        flex-direction: column;
        gap: 15px;
        text-align: center;
    }
    
    .sensor-grid {
        grid-template-columns: 1fr;
    }
    
    .control-buttons {
        flex-direction: column;
    }
    
    .card-value {
        font-size: 2rem;
    }
}

@media (max-width: 480px) {
    .header-title h1 {
        font-size: 1.8rem;
    }
    
    .header-title p {
        font-size: 1rem;
    }
    
    .sensor-card, .control-card {
        padding: 20px;
    }
    
    .charts-section {
        padding: 20px;
    }
}