/*
 * MakerBuddy V1.0 - Web Dashboard Styles
 *
 * Copyright (C) 2024 Muhammad Afzal
 * Website: https://makerbuddy.cc
 * Email: info@makerbuddy.cc
 * Version: 1.0
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
 */

:root {
    --primary-color: #2563eb;
    --primary-dark: #1e40af;
    --primary-light: #60a5fa;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    --bg-primary: #f0f4f8;
    --bg-secondary: #ffffff;
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.07);
    --shadow-lg: 0 10px 20px rgba(0, 0, 0, 0.1);
    --glass-bg: rgba(255, 255, 255, 0.7);
    --glass-border: rgba(255, 255, 255, 0.18);
}

[data-theme="dark"] {
    --primary-color: #3b82f6;
    --primary-dark: #2563eb;
    --primary-light: #60a5fa;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --border-color: #334155;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 20px rgba(0, 0, 0, 0.5);
    --glass-bg: rgba(30, 41, 59, 0.7);
    --glass-border: rgba(255, 255, 255, 0.1);
}

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

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

body.sidebar-open {
    overflow: hidden;
}

/* Sidebar Styles */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 300px;
    height: 100vh;
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-right: 1px solid var(--glass-border);
    box-shadow: var(--shadow-lg);
    padding: 20px;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1000;
    overflow-y: auto;
}

.sidebar.collapsed {
    transform: translateX(-300px);
}

.sidebar-header {
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-logo {
    text-align: center;
    margin-bottom: 20px;
}

.sidebar-logo img {
    max-width: 200px;
    height: auto;
}

.sidebar-section {
    margin-bottom: 30px;
}

.sidebar-title {
    font-size: 14px;
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 16px;
}

.sidebar-input {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 14px;
    transition: all 0.3s;
}

.sidebar-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.sidebar-toggle {
    position: fixed;
    top: 20px;
    left: 254px;
    width: 46px;
    height: 46px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 0 12px 12px 0;
    font-size: 18px;
    font-weight: bold;
    cursor: pointer;
    transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1002;
    box-shadow: var(--shadow-md);
    display: flex;
    align-items: center;
    justify-content: center;
}

.sidebar-toggle:hover {
    background: var(--primary-dark);
    box-shadow: var(--shadow-lg);
}

/* Mobile Backdrop */
.sidebar-backdrop {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
    opacity: 0;
    transition: opacity 0.3s;
}

.sidebar-backdrop.active {
    display: block;
    opacity: 1;
}

.status-display {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 12px;
    background: var(--bg-secondary);
    border-radius: 10px;
    border: 1px solid var(--border-color);
}

.container {
    max-width: 1600px;
    margin: 0 auto;
    padding: 20px;
    margin-left: 300px;
    transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.container.expanded {
    margin-left: 0;
}

.sidebar .theme-toggle {
    width: 100%;
    justify-content: center;
    margin-bottom: 10px;
}

/* Glass Card Effect */
.glass-card {
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: 20px;
    border: 1px solid var(--glass-border);
    box-shadow: var(--shadow-lg);
    padding: 24px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.glass-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.15);
}

/* Header Styles */
.header {
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: 20px;
    padding: 20px 30px;
    margin-bottom: 20px;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 20px;
    border: 1px solid var(--glass-border);
    box-shadow: var(--shadow-lg);
}

.header-left {
    display: flex;
    flex-direction: column;
}

.header-left h1 {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.header-left p {
    font-size: 13px;
    color: var(--text-secondary);
}

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

.status-indicator {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--danger-color);
    transition: all 0.3s;
}

.status-indicator.active {
    background: var(--success-color);
    box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.2);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.2); }
    50% { box-shadow: 0 0 0 8px rgba(16, 185, 129, 0.1); }
}

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

.header-right {
    display: flex;
    justify-content: flex-end;
}

.theme-toggle {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 10px 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
    transition: all 0.3s;
}

.theme-toggle:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

/* Connection Section */
.connection-section {
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: 20px;
    padding: 20px;
    margin-bottom: 20px;
    border: 1px solid var(--glass-border);
    box-shadow: var(--shadow-md);
}

.connection-grid {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
}

.connection-grid input {
    flex: 1;
    min-width: 250px;
    padding: 12px 16px;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 14px;
    transition: all 0.3s;
}

.connection-grid input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* Button Styles */
.btn {
    padding: 12px 24px;
    border-radius: 12px;
    border: none;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

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

.btn-primary:hover {
    background: var(--primary-dark);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

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

.btn-danger:hover {
    background: #dc2626;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* Grid Layouts */
.grid-5 {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 20px;
}

.grid-4 {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
}

.grid-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
}

.grid-2 {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
}

/* Sensor Card */
.sensor-card {
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: 20px;
    padding: 24px;
    border: 1px solid var(--glass-border);
    box-shadow: var(--shadow-md);
    transition: all 0.3s;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    min-height: 180px;
}

.sensor-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.15);
}

.sensor-icon {
    width: 60px;
    height: 60px;
    border-radius: 16px;
    background: linear-gradient(135deg, var(--primary-color), var(--primary-light));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    margin-bottom: 16px;
    box-shadow: 0 8px 16px rgba(37, 99, 235, 0.3);
}

.sensor-label {
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 500;
    margin-bottom: 8px;
}

.sensor-value {
    font-size: 32px;
    font-weight: 700;
    color: var(--primary-color);
    margin-bottom: 4px;
}

.sensor-unit {
    font-size: 16px;
    color: var(--text-secondary);
}

/* Control Card */
.control-card {
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: 20px;
    padding: 28px;
    border: 1px solid var(--glass-border);
    box-shadow: var(--shadow-md);
    transition: all 0.3s;
}

.control-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 15px 30px rgba(0, 0, 0, 0.15);
}

.control-header {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-color);
}

.control-icon {
    width: 48px;
    height: 48px;
    border-radius: 14px;
    background: linear-gradient(135deg, var(--primary-color), var(--primary-light));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    box-shadow: 0 6px 12px rgba(37, 99, 235, 0.25);
}

.control-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
}

.control-group {
    margin-bottom: 20px;
}

.control-label {
    display: block;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 12px;
}

.control-row {
    display: flex;
    align-items: center;
    gap: 16px;
}

/* Switch Toggle */
.switch {
    position: relative;
    display: inline-block;
    width: 56px;
    height: 30px;
}

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

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--border-color);
    transition: 0.4s;
    border-radius: 30px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 22px;
    width: 22px;
    left: 4px;
    bottom: 4px;
    background: white;
    transition: 0.4s;
    border-radius: 50%;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

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

input:checked + .slider:before {
    transform: translateX(26px);
}

/* Range Slider */
.range-slider {
    width: 100%;
    height: 8px;
    border-radius: 4px;
    background: var(--border-color);
    outline: none;
    margin: 12px 0;
    cursor: pointer;
}

.range-slider::-webkit-slider-thumb {
    appearance: none;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--primary-color);
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.4);
    transition: all 0.3s;
}

.range-slider::-webkit-slider-thumb:hover {
    transform: scale(1.1);
}

.range-value {
    text-align: center;
    font-size: 14px;
    color: var(--text-secondary);
    font-weight: 600;
}

/* Color Preview */
.color-preview {
    width: 80px;
    height: 80px;
    border-radius: 16px;
    border: 3px solid var(--border-color);
    margin: 0 auto 16px;
    box-shadow: var(--shadow-md);
}

.rgb-controls {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
}

.rgb-control {
    text-align: center;
}

.rgb-control label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.rgb-number-input {
    width: 100%;
    padding: 8px;
    margin-top: 8px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 14px;
    text-align: center;
    font-weight: 600;
    transition: all 0.3s;
}

.rgb-number-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* Table Styles */
.table-container {
    overflow-x: auto;
    border-radius: 12px;
}

table {
    width: 100%;
    border-collapse: collapse;
}

thead {
    background: var(--bg-secondary);
}

th {
    text-align: left;
    padding: 14px 16px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    border-bottom: 2px solid var(--border-color);
}

td {
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
    font-size: 14px;
    color: var(--text-primary);
}

tbody tr {
    transition: all 0.2s;
}

tbody tr:hover {
    background: var(--bg-secondary);
}

/* Badge */
.badge {
    display: inline-block;
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
}

.badge-success {
    background: rgba(16, 185, 129, 0.15);
    color: var(--success-color);
}

.badge-danger {
    background: rgba(239, 68, 68, 0.15);
    color: var(--danger-color);
}

/* Form Styles */
.form-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    margin-bottom: 20px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.form-group label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
}

.form-group input,
.form-group select {
    padding: 12px 14px;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 14px;
    transition: all 0.3s;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* Device Info */
.device-info {
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 16px;
    margin-top: 16px;
    border: 1px solid var(--border-color);
}

.info-row {
    display: flex;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid var(--border-color);
}

.info-row:last-child {
    border-bottom: none;
}

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

.info-value {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}

/* LCD Preview */
.lcd-preview {
    background: #1a472a;
    border-radius: 12px;
    padding: 24px;
    border: 4px solid #2c5f3d;
    font-family: 'Courier New', monospace;
    margin-top: 16px;
    box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.4);
}

.lcd-line {
    color: #00ff00;
    font-size: 16px;
    height: 22px;
    letter-spacing: 2px;
    text-shadow: 0 0 8px #00ff00;
}

/* Utility Classes */
.hidden {
    display: none !important;
}

.text-center {
    text-align: center;
}

.mb-20 {
    margin-bottom: 20px;
}

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
}

.empty-state-icon {
    font-size: 64px;
    margin-bottom: 16px;
    opacity: 0.4;
}

.action-buttons {
    display: flex;
    gap: 8px;
}

.icon-btn {
    padding: 8px 14px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    cursor: pointer;
    font-size: 14px;
    transition: all 0.3s;
}

.icon-btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-sm);
}

/* Social Media Links */
.social-links {
    display: flex;
    justify-content: center;
    gap: 15px;
    flex-wrap: wrap;
}

.social-links a {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    font-size: 20px;
    transition: all 0.3s;
    text-decoration: none;
}

.social-links a:hover {
    background: var(--primary-color);
    color: white;
    transform: translateY(-3px);
    box-shadow: 0 6px 12px rgba(37, 99, 235, 0.3);
    border-color: var(--primary-color);
}

.social-links a:active {
    transform: translateY(-1px);
}

/* Responsive Design */
@media (max-width: 1400px) {
    .grid-5 {
        grid-template-columns: repeat(4, 1fr);
    }
}

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

    .header {
        grid-template-columns: 1fr;
        text-align: center;
    }

    .header-center,
    .header-right {
        justify-content: center;
    }
}

@media (max-width: 768px) {
    .grid-5,
    .grid-3,
    .grid-2,
    .grid-4,
    .form-grid,
    .rgb-controls {
        grid-template-columns: 1fr;
    }

    .container {
        padding: 12px;
        margin-left: 0;
    }

    .sensor-card {
        min-height: 150px;
    }

    .sidebar {
        width: 280px;
        transform: translateX(-280px);
    }

    .sidebar.collapsed {
        transform: translateX(-280px);
    }

    /* Show sidebar when not collapsed on mobile */
    .sidebar:not(.collapsed) {
        transform: translateX(0);
    }

    .sidebar-toggle {
        left: 0px;
        border-radius: 12px;
        top: 15px;
    }

    /* When sidebar is open on mobile */
    .sidebar:not(.collapsed) ~ button.sidebar-toggle {
        left: 234px;
    }

    .tab-btn {
        font-size: 13px;
        padding: 12px 16px;
    }

    /* Make firmware version grid stack on mobile */
    #settingsTab .control-group > div[style*="grid-template-columns: 1fr 1fr 1fr"] {
        grid-template-columns: 1fr !important;
    }
}

@media (max-width: 480px) {
    .sensor-value {
        font-size: 28px;
    }

    .sidebar {
        width: 85%;
        max-width: 320px;
        transform: translateX(-100%);
    }

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

    /* Show sidebar when not collapsed on small mobile */
    .sidebar:not(.collapsed) {
        transform: translateX(0);
    }

    .sidebar-toggle {
        left: 10px;
        border-radius: 12px;
        top: 15px;
        z-index: 1003;
    }
}

/* Tab Navigation Styles */
.tab-buttons {
    display: flex;
    gap: 12px;
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: 16px;
    padding: 8px;
    border: 1px solid var(--glass-border);
    box-shadow: var(--shadow-md);
}

.tab-btn {
    flex: 1;
    padding: 14px 24px;
    border: none;
    border-radius: 12px;
    background: transparent;
    color: var(--text-secondary);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.tab-btn:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
    transform: translateY(-2px);
}

.tab-btn.active {
    background: var(--primary-color);
    color: white;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

.tab-content {
    animation: fadeIn 0.3s ease-in-out;
}

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

/* Automation Warning Styles */
.automation-warning {
    background: rgba(245, 158, 11, 0.1);
    border: 2px solid var(--warning-color);
    border-radius: 12px;
    padding: 12px;
    margin-bottom: 15px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    color: var(--warning-color);
    font-weight: 500;
}

/* Disabled Control Card */
.control-card.disabled {
    opacity: 0.6;
    pointer-events: none;
    filter: grayscale(0.3);
}

.control-card.disabled input,
.control-card.disabled button,
.control-card.disabled .slider {
    cursor: not-allowed !important;
}
