/* =========================================
   Hydroponic Farm System - Design System
   ========================================= */

:root {
    /* Core Colors */
    --bg-body: #050506;
    --bg-card: #131315;
    --bg-input: #1e1e21;
    --bg-input-hover: #26262a;

    --accent-primary: #6B4CFF;
    --accent-glow: rgba(107, 76, 255, 0.4);
    --accent-light: #B4A0FF;

    --text-primary: #F0F0F2;
    --text-secondary: #888890;
    --text-tertiary: #55555A;

    --border-subtle: rgba(255, 255, 255, 0.06);
    --border-highlight: rgba(255, 255, 255, 0.1);

    --radius-lg: 24px;
    --radius-md: 12px;
    --radius-sm: 8px;

    --shadow-card: 0 20px 40px -10px rgba(0, 0, 0, 0.5);
    --shadow-float: 0 10px 30px -5px rgba(0, 0, 0, 0.6);

    --font-family: 'SF Pro Display', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;

    /* Legacy Variables Mapping (for backward compatibility if needed) */
    --primary-teal: var(--accent-primary);
    --primary-teal-light: var(--accent-light);
    --primary-teal-dark: #5438CC;
    --accent-blue: var(--accent-primary);
    --bg-glass: var(--bg-card);
    --glass-border: var(--border-subtle);
    --glass-blur: blur(10px);
    --glass-shadow: var(--shadow-card);
    --bg-primary: var(--bg-body);
    --bg-secondary: #0a0e1a;
    --bg-tertiary: var(--bg-input);
    --text-muted: var(--text-secondary);
    --text-dim: var(--text-tertiary);
    --glow-white: 0 0 10px rgba(255, 255, 255, 0.3);
    --success: #10b981;
    --error: #ef4444;
}

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

body {
    background-color: var(--bg-body);
    color: var(--text-primary);
    font-family: var(--font-family);
    height: 100vh;
    overflow: hidden;
    /* display: flex; - Removed to allow normal flow if needed, but app-container handles grid */

    background-image:
        radial-gradient(circle at 80% 10%, rgba(107, 76, 255, 0.08) 0%, transparent 40%),
        radial-gradient(circle at 20% 90%, rgba(107, 76, 255, 0.05) 0%, transparent 40%);
}

/* Layout */
.app-container {
    display: grid;
    grid-template-columns: 260px 1fr;
    width: 100%;
    height: 100%;
}

.sidebar {
    padding: 32px 24px;
    display: flex;
    flex-direction: column;
    gap: 40px;
    border-right: 1px solid var(--border-subtle);
    background: transparent;
    /* Override old sidebar */
    position: static;
    /* Override fixed */
    width: auto;
    height: auto;
    box-shadow: none;
}

.brand {
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    text-transform: uppercase;
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
}

.brand-dot {
    width: 8px;
    height: 8px;
    background: var(--accent-primary);
    border-radius: 50%;
    box-shadow: 0 0 10px var(--accent-glow);
}

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

.nav-label {
    font-size: 11px;
    color: var(--text-tertiary);
    font-weight: 600;
    text-transform: uppercase;
    margin-bottom: 8px;
    padding-left: 12px;
}

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

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

.nav-item.active {
    color: var(--text-primary);
    background: var(--bg-input);
    box-shadow: inset 0 0 0 1px var(--border-highlight);
}

.nav-icon {
    width: 18px;
    height: 18px;
    opacity: 0.7;
    display: flex;
    align-items: center;
    justify-content: center;
}

.nav-icon svg {
    width: 100%;
    height: 100%;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.5;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.nav-icon i {
    font-size: 14px;
    color: currentColor;
}

.main-content {
    padding: 32px 40px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 32px;
    margin-left: 0;
    /* Reset */
    margin-top: 0;
    /* Reset */
    min-height: auto;
}

/* Header */
.header {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
}

.header-title h1 {
    font-size: 24px;
    font-weight: 500;
    letter-spacing: -0.5px;
    margin-bottom: 4px;
    color: var(--text-primary);
}

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

.status-badge {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background: rgba(107, 76, 255, 0.1);
    border: 1px solid rgba(107, 76, 255, 0.2);
    border-radius: 20px;
    font-size: 12px;
    color: var(--accent-light);
}

.indicator {
    width: 8px;
    height: 8px;
    background: #4CAF50;
    border-radius: 50%;
    box-shadow: 0 0 8px rgba(76, 175, 80, 0.4);
}

/* Dashboard Grid */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: auto;
    /* Changed to auto for flexibility */
    gap: 24px;
}

.card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-subtle);
    padding: 24px;
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    gap: 20px;
    box-shadow: var(--shadow-card);
}

.card.wide {
    grid-column: span 2;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0;
    /* Reset from old */
    padding-bottom: 0;
    /* Reset */
    border-bottom: none;
    /* Reset */
}

.card-title {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
}

.card-action {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    background: var(--bg-input);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-secondary);
    border: 1px solid transparent;
    transition: all 0.2s;
}

.card-action:hover {
    color: var(--text-primary);
    border-color: var(--border-highlight);
}

/* Controls */
.control-group {
    background: var(--bg-input);
    border-radius: var(--radius-md);
    padding: 16px;
    border: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.control-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

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

.value {
    font-size: 13px;
    color: var(--text-primary);
    font-feature-settings: "tnum";
    font-weight: 500;
}

/* Slider */
.slider-container {
    width: 100%;
    height: 20px;
    display: flex;
    align-items: center;
}

input[type=range] {
    appearance: none;
    -webkit-appearance: none;
    width: 100%;
    background: transparent;
}

input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    height: 14px;
    width: 14px;
    border-radius: 50%;
    background: var(--text-primary);
    cursor: pointer;
    margin-top: -6px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
}

input[type=range]::-webkit-slider-runnable-track {
    width: 100%;
    height: 2px;
    cursor: pointer;
    background: var(--border-highlight);
    border-radius: 1px;
}

/* Toggle */
.toggle {
    position: relative;
    display: inline-block;
    width: 36px;
    height: 20px;
}

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

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--bg-input);
    border: 1px solid var(--border-highlight);
    transition: .4s;
    border-radius: 20px;
}

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

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

input:checked+.slider:before {
    transform: translateX(16px);
    background-color: #fff;
}

/* Metrics */
.metric-large {
    font-size: 32px;
    font-weight: 400;
    color: var(--text-primary);
    letter-spacing: -1px;
}

.metric-unit {
    font-size: 14px;
    color: var(--text-secondary);
    margin-left: 2px;
}

/* Graph */
.wave-graph {
    width: 100%;
    height: 60px;
    background: linear-gradient(180deg, rgba(107, 76, 255, 0.1) 0%, rgba(107, 76, 255, 0) 100%);
    border-top: 1px solid var(--accent-primary);
    border-radius: 4px;
    position: relative;
    margin-top: auto;
    mask-image: linear-gradient(to bottom, black, transparent);
}

/* Stats */
.stat-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.stat-item {
    background: var(--bg-input);
    padding: 12px;
    border-radius: var(--radius-sm);
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.stat-label {
    font-size: 11px;
    color: var(--text-secondary);
    text-transform: uppercase;
}

.stat-value {
    font-size: 16px;
    color: var(--text-primary);
}

/* Inputs */
.input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.input-styled {
    background: var(--bg-input);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    padding: 10px 12px;
    font-size: 13px;
    width: 100%;
    outline: none;
    transition: 0.2s;
}

.input-styled:focus {
    border-color: var(--text-secondary);
    background: var(--bg-input-hover);
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--bg-input);
    border-radius: 4px;
}

/* Toast */
.toast {
    position: fixed;
    bottom: 32px;
    right: 32px;
    background: var(--bg-card);
    border: 1px solid var(--border-highlight);
    padding: 16px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: var(--shadow-float);
    z-index: 100;
    backdrop-filter: blur(10px);
    font-size: 13px;
}

/* SVG Base */
svg {
    stroke: currentColor;
    stroke-width: 1.5;
    stroke-linecap: round;
    stroke-linejoin: round;
    fill: none;
}

/* Tables (Adapted to new style) */
.table {
    width: 100%;
    border-collapse: collapse;
    color: var(--text-primary);
}

.table th {
    text-align: left;
    padding: 12px;
    color: var(--text-tertiary);
    font-size: 12px;
    text-transform: uppercase;
    font-weight: 600;
    border-bottom: 1px solid var(--border-subtle);
}

.table td {
    padding: 14px 12px;
    border-bottom: 1px solid var(--border-subtle);
    font-size: 14px;
    color: var(--text-secondary);
}

.table tr:last-child td {
    border-bottom: none;
}

.table tr:hover td {
    background: var(--bg-input);
    color: var(--text-primary);
}

/* Buttons (Adapted) */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    text-decoration: none;
    transition: all 0.2s;
    border: 1px solid transparent;
    cursor: pointer;
}

.btn-primary {
    background: var(--accent-primary);
    color: white;
    box-shadow: 0 0 10px var(--accent-glow);
}

.btn-primary:hover {
    background: #7B61FF;
}

.btn-outline {
    background: transparent;
    border-color: var(--border-highlight);
    color: var(--text-secondary);
}

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

.btn-link {
    color: var(--accent-light);
    text-decoration: none;
    font-size: 13px;
    background: transparent;
    border: none;
    padding: 4px 8px;
    border-radius: 4px;
}

.btn-link:hover {
    background: rgba(107, 76, 255, 0.1);
    color: white;
}

/* Responsive */
@media (max-width: 1024px) {
    .dashboard-grid {
        grid-template-columns: 1fr 1fr;
    }
}

/* Mobile Styling */
.mobile-menu-btn {
    display: none;
    /* Hidden on desktop */
    background: var(--bg-input);
    border: 1px solid var(--border-subtle);
    color: var(--text-secondary);
    width: 40px;
    height: 40px;
    border-radius: var(--radius-sm);
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 18px;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(2px);
    z-index: 99;
    opacity: 0;
    transition: opacity 0.3s ease;
}

@media (max-width: 768px) {
    .app-container {
        grid-template-columns: 1fr;
    }

    /* Sidebar - Off-canvas on mobile */
    .sidebar {
        display: flex;
        /* Restore flex from none */
        position: fixed;
        top: 0;
        left: -280px;
        /* Hide off-screen */
        width: 280px;
        height: 100vh;
        background: var(--bg-body);
        z-index: 100;
        border-right: 1px solid var(--border-highlight);
        transition: transform 0.3s ease;
        box-shadow: 10px 0 30px rgba(0, 0, 0, 0.5);
    }

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

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

    /* Main Content Adjustments */
    .main-content {
        padding: 20px;
        width: 100%;
    }

    .header {
        margin-bottom: 24px;
        align-items: center;
    }

    .mobile-menu-btn {
        display: flex;
        /* Show on mobile */
    }

    /* Header Title adjustments */
    .header-title h1 {
        font-size: 20px;
    }

    .header-subtitle {
        font-size: 12px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 200px;
    }

    .status-badge .status-text {
        display: none;
        /* Hide text on very small screens to save space */
    }

    .status-badge {
        padding: 6px;
        border-radius: 50%;
    }

    /* Grid Adjustments */
    .dashboard-grid {
        grid-template-columns: 1fr;
        gap: 16px;
        /* Smaller gap on mobile */
    }

    .dashboard-grid>* {
        grid-column: 1 / -1 !important;
    }

    /* Force inner grids to stack */
    .form-row,
    form [style*="grid-template-columns"] {
        grid-template-columns: 1fr !important;
        gap: 16px !important;
    }

    .card.wide {
        grid-column: span 1 !important;
    }

    .card {
        padding: 16px;
        /* Smaller padding on mobile */
    }

    /* Table Responsive */
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .table th,
    .table td {
        white-space: nowrap;
        padding: 12px 8px;
        /* Compact padding */
    }

    /* Modal Adjustments */
    .modal-content {
        width: 95%;
        margin: 10px;
        max-height: 85vh;
    }
}