/* ===================================================================
   HydroOptimizer — Main Stylesheet
   Modular Automated Hydroponic Unit Control & Monitoring Dashboard
   Optimized Proportions (Calibrated for crisp standard 100% zoom)
   =================================================================== */

/* --- CSS Variables (Theme) --- */
:root {
    --bg-primary: #0f1923;
    --bg-secondary: #162331;
    --bg-card: #1a2d40;
    --bg-card-hover: #1f3549;
    --border-color: #2a4158;
    --text-primary: #e8edf2;
    --text-secondary: #8899aa;
    --text-muted: #5a6e7f;
    --accent-green: #00e676;
    --accent-green-dark: #00c853;
    --accent-blue: #42a5f5;
    --accent-orange: #ffab40;
    --accent-red: #ef5350;
    --accent-purple: #ab47bc;
    --accent-teal: #26a69a;
    --accent-yellow: #ffc107;
    --shadow: 0 4px 16px rgba(0,0,0,0.3);
    --radius: 10px;
    --radius-sm: 6px;
    --transition: all 0.25s ease;
    --sidebar-width: 224px;
    --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
    --font-mono: 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
}

/* --- Reset & Base --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* Calibrated base font size matching comfortable 90% viewing ratio */
html {
    font-size: 13.5px;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font);
    background: var(--bg-primary);
    color: var(--text-primary);
    display: flex;
    min-height: 100vh;
    overflow-x: hidden;
}

a { color: var(--accent-blue); text-decoration: none; }
a:hover { color: var(--accent-green); }

/* --- Sidebar --- */
.sidebar {
    position: fixed;
    left: 0; top: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    z-index: 100;
    transition: var(--transition);
}

.sidebar-brand {
    padding: 18px 16px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 10px;
}

.sidebar-brand .logo {
    font-size: 24px;
    line-height: 1;
}

.sidebar-brand h1 {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--accent-green);
    letter-spacing: 0.3px;
}

.sidebar-brand small {
    display: block;
    font-size: 0.68rem;
    color: var(--text-muted);
    font-weight: 400;
    margin-top: 1px;
}

.sidebar-nav {
    flex: 1;
    padding: 12px 0;
    overflow-y: auto;
}

.nav-section {
    padding: 8px 16px 4px;
    font-size: 0.62rem;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    color: var(--text-muted);
    font-weight: 600;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 16px;
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 500;
    transition: var(--transition);
    border-left: 3px solid transparent;
}

.nav-link:hover {
    color: var(--text-primary);
    background: rgba(0,230,118,0.05);
    border-left-color: var(--accent-green);
}

.nav-link.active {
    color: var(--accent-green);
    background: rgba(0,230,118,0.08);
    border-left-color: var(--accent-green);
}

.nav-link .icon { font-size: 1.05rem; width: 22px; text-align: center; }

/* --- Main Content --- */
.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    padding: 20px 24px;
    min-height: 100vh;
    max-width: calc(100vw - var(--sidebar-width));
}

/* --- Page Header --- */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 10px;
}

.page-header h2 {
    font-size: 1.45rem;
    font-weight: 700;
    color: var(--text-primary);
}

.page-header .subtitle {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 3px;
}

/* --- Cards --- */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    transition: var(--transition);
    overflow: hidden;
}

.card:hover { border-color: rgba(0,230,118,0.2); }

.card-header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.card-header h3 {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.card-body { padding: 16px; }

.card-footer {
    padding: 10px 16px;
    border-top: 1px solid var(--border-color);
    background: rgba(0,0,0,0.1);
}

/* --- Grid Layouts --- */
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }

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

/* Mobile Navigation Header & Slide-out Drawer */
.mobile-header {
    display: none;
}

.btn-sidebar-close {
    display: none;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.15rem;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
}

.btn-sidebar-close:hover {
    color: var(--accent-red);
}

.sidebar-backdrop {
    display: none;
}

@media (max-width: 768px) {
    body {
        flex-direction: column !important;
        min-height: 100vh;
    }

    .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }

    .mobile-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 8px 14px;
        background: var(--bg-card);
        border-bottom: 1px solid var(--border-color);
        position: sticky;
        top: 0;
        left: 0;
        width: 100%;
        z-index: 1050;
        box-shadow: 0 2px 10px rgba(0, 0, 0, 0.4);
    }

    .btn-mobile-menu {
        background: rgba(0, 230, 118, 0.12);
        border: 1px solid rgba(0, 230, 118, 0.35);
        color: var(--accent-green);
        padding: 6px 11px;
        border-radius: 6px;
        font-size: 1.15rem;
        cursor: pointer;
        transition: all 0.2s ease;
    }

    .btn-mobile-menu:hover {
        background: rgba(0, 230, 118, 0.22);
    }

    .mobile-brand {
        display: flex;
        flex-direction: column;
        align-items: flex-start;
        justify-content: center;
        line-height: 1.15;
    }

    .mobile-brand strong {
        color: var(--accent-green);
    }

    .mobile-brand-subtitle {
        font-size: 0.65rem;
        color: var(--text-muted);
        font-weight: 500;
        letter-spacing: 0.3px;
        margin-top: 1px;
    }

    .btn-sidebar-close {
        display: block;
    }

    .sidebar {
        position: fixed !important;
        left: -290px !important;
        top: 0 !important;
        width: 270px !important;
        height: 100vh !important;
        z-index: 1200 !important;
        box-shadow: none;
        transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
        background: var(--bg-secondary) !important;
        overflow-y: auto !important;
        margin-top: 0 !important;
    }

    .sidebar.open {
        left: 0 !important;
        box-shadow: 10px 0 35px rgba(0, 0, 0, 0.85) !important;
    }

    .sidebar-backdrop {
        position: fixed;
        top: 0;
        left: 0;
        width: 100vw;
        height: 100vh;
        background: rgba(0, 0, 0, 0.65);
        backdrop-filter: blur(3px);
        z-index: 1150;
        display: none;
    }

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

    .main-content {
        margin-left: 0 !important;
        padding: 12px !important;
        max-width: 100vw !important;
    }
}

/* --- Metric Cards (Dashboard KPIs) --- */
.metric-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    transition: var(--transition);
}

.metric-card:hover {
    transform: translateY(-2px);
    border-color: rgba(0,230,118,0.3);
    box-shadow: 0 6px 20px rgba(0,0,0,0.35);
}

.metric-card .metric-icon {
    font-size: 1.4rem;
    margin-bottom: 2px;
}

.metric-card .metric-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-muted);
    font-weight: 600;
}

.metric-card .metric-value {
    font-size: 1.55rem;
    font-weight: 700;
    font-family: var(--font-mono);
}

.metric-card .metric-sub {
    font-size: 0.74rem;
    color: var(--text-secondary);
}

.metric-green .metric-value { color: var(--accent-green); }
.metric-blue .metric-value { color: var(--accent-blue); }
.metric-orange .metric-value { color: var(--accent-orange); }
.metric-red .metric-value { color: var(--accent-red); }
.metric-purple .metric-value { color: var(--accent-purple); }
.metric-teal .metric-value { color: var(--accent-teal); }

/* --- Tables --- */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82rem;
}

.data-table thead th {
    padding: 8px 10px;
    text-align: left;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    font-size: 0.66rem;
    letter-spacing: 0.8px;
    border-bottom: 2px solid var(--border-color);
    white-space: nowrap;
}

.data-table tbody td {
    padding: 8px 10px;
    border-bottom: 1px solid rgba(42,65,88,0.5);
    color: var(--text-primary);
    vertical-align: middle;
}

.data-table tbody tr:hover {
    background: rgba(0,230,118,0.03);
}

.data-table .num {
    font-family: var(--font-mono);
    text-align: right;
}

.data-table .highlight { color: var(--accent-green); font-weight: 600; }

/* Dedicated compact matrix table styling */
#crop-matrix-table th {
    padding: 7px 6px;
    font-size: 0.65rem;
    text-align: center;
}
#crop-matrix-table td {
    padding: 6px 5px;
    font-size: 0.78rem;
}

/* --- Forms & Inputs --- */
.form-group {
    margin-bottom: 12px;
}

.form-group label {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

.form-control {
    width: 100%;
    padding: 7px 10px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 0.84rem;
    transition: var(--transition);
}

.form-control:focus {
    outline: none;
    border-color: var(--accent-green);
    box-shadow: 0 0 0 2px rgba(0,230,118,0.15);
}

.form-control-sm {
    padding: 5px 8px;
    font-size: 0.78rem;
}

.matrix-input {
    padding: 4px 6px !important;
    font-size: 0.78rem !important;
    border-radius: 4px;
}

.input-group {
    display: flex;
    align-items: center;
    gap: 6px;
}

.input-unit {
    font-size: 0.74rem;
    color: var(--text-muted);
    white-space: nowrap;
}

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

.btn-primary {
    background: var(--accent-green);
    color: var(--bg-primary);
}
.btn-primary:hover {
    background: var(--accent-green-dark);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0,230,118,0.3);
}

.btn-secondary {
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}
.btn-secondary:hover {
    background: var(--bg-card-hover);
    border-color: var(--accent-blue);
}

.btn-danger {
    background: rgba(239,83,80,0.15);
    color: var(--accent-red);
    border: 1px solid rgba(239,83,80,0.3);
}
.btn-danger:hover { background: rgba(239,83,80,0.25); }

.btn-sm { padding: 5px 10px; font-size: 0.74rem; }

.btn-group { display: flex; gap: 8px; flex-wrap: wrap; }

/* --- Badges & Tags --- */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 16px;
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

.badge-green { background: rgba(0,230,118,0.15); color: var(--accent-green); }
.badge-blue { background: rgba(66,165,245,0.15); color: var(--accent-blue); }
.badge-orange { background: rgba(255,171,64,0.15); color: var(--accent-orange); }
.badge-red { background: rgba(239,83,80,0.15); color: var(--accent-red); }

/* --- Charts Container --- */
.chart-container {
    position: relative;
    width: 100%;
    max-height: 340px;
}

.chart-container canvas {
    max-height: 340px;
}

/* --- Loading Spinner --- */
.spinner {
    display: inline-block;
    width: 16px; height: 16px;
    border: 2px solid var(--border-color);
    border-top-color: var(--accent-green);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* --- Status Indicators --- */
.status-dot {
    display: inline-block;
    width: 7px; height: 7px;
    border-radius: 50%;
    margin-right: 5px;
}
.status-dot.green { background: var(--accent-green); box-shadow: 0 0 6px var(--accent-green); }
.status-dot.red { background: var(--accent-red); box-shadow: 0 0 6px var(--accent-red); }
.status-dot.orange { background: var(--accent-orange); box-shadow: 0 0 6px var(--accent-orange); }

/* --- Tooltip --- */
.tooltip-text {
    font-size: 0.68rem;
    color: var(--text-muted);
    font-style: italic;
    margin-top: 2px;
}

/* --- Crop Color Swatch --- */
.crop-swatch {
    display: inline-block;
    width: 10px; height: 10px;
    border-radius: 2px;
    margin-right: 6px;
    vertical-align: middle;
}

/* --- Tab System --- */
.tabs {
    display: flex;
    gap: 4px;
    border-bottom: 2px solid var(--border-color);
    margin-bottom: 16px;
}

.tab-btn {
    padding: 8px 14px;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-family: var(--font);
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: var(--transition);
}

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

.tab-btn.active {
    color: var(--accent-green);
    border-bottom-color: var(--accent-green);
}

.tab-content { display: none; }
.tab-content.active { display: block; }

/* --- Scrollbar --- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-primary); }
::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* --- Parameter Editor Grid --- */
.param-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}

@media (max-width: 900px) {
    .param-grid { grid-template-columns: 1fr; }
}

.param-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    background: rgba(0,0,0,0.15);
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    transition: var(--transition);
}

.param-item:hover { border-color: var(--border-color); }

.param-item .param-name {
    flex: 1;
    font-size: 0.78rem;
    color: var(--text-secondary);
    line-height: 1.25;
}

.param-item .param-symbol {
    font-family: var(--font-mono);
    font-size: 0.74rem;
    color: var(--accent-blue);
    min-width: 60px;
}

.param-item input {
    width: 80px;
    padding: 4px 6px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--accent-green);
    font-family: var(--font-mono);
    font-size: 0.8rem;
    text-align: right;
}

.param-item input:focus {
    outline: none;
    border-color: var(--accent-green);
}

/* --- Alerts --- */
.alert {
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    margin-bottom: 14px;
    font-size: 0.8rem;
    display: flex;
    align-items: center;
    gap: 8px;
}

.alert-success {
    background: rgba(0,230,118,0.1);
    border: 1px solid rgba(0,230,118,0.3);
    color: var(--accent-green);
}

.alert-warning {
    background: rgba(255,171,64,0.1);
    border: 1px solid rgba(255,171,64,0.3);
    color: var(--accent-orange);
}

.alert-error {
    background: rgba(239,83,80,0.1);
    border: 1px solid rgba(239,83,80,0.3);
    color: var(--accent-red);
}

/* --- Pathway comparison cards --- */
.pathway-card {
    border-left: 3px solid var(--accent-green);
    position: relative;
}

.pathway-card.pathway-2 { border-left-color: var(--accent-blue); }
.pathway-card.pathway-3 { border-left-color: var(--accent-orange); }

.pathway-label {
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-muted);
    margin-bottom: 6px;
}

/* --- Two-column layout --- */
.layout-split {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

@media (max-width: 1100px) {
    .layout-split { grid-template-columns: 1fr; }
}

/* --- Animation --- */
.fade-in {
    animation: fadeIn 0.4s ease-out;
}

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

/* --- Print Styles --- */
@media print {
    .sidebar { display: none; }
    .main-content { margin-left: 0; padding: 0; }
    .btn { display: none; }
}

/* --- Modal Components --- */
.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(10, 20, 30, 0.75);
    backdrop-filter: blur(4px);
    z-index: 1100;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.modal-backdrop.open {
    display: flex !important;
}

.modal-dialog {
    background: var(--card-bg, #1e293b);
    border: 1px solid var(--border-color, #334155);
    border-radius: var(--radius-md, 8px);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6);
    width: 100%;
    max-width: 580px;
    max-height: 90vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    animation: modalSlide 0.25s ease-out;
}

@keyframes modalSlide {
    from { opacity: 0; transform: scale(0.96) translateY(-10px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
    padding: 14px 18px;
    border-bottom: 1px solid var(--border-color, #334155);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    margin: 0;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    gap: 8px;
}

.modal-close {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.2rem;
    cursor: pointer;
    line-height: 1;
}

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

.modal-body {
    padding: 18px;
    font-size: 0.88rem;
}

.modal-footer {
    padding: 12px 18px;
    border-top: 1px solid var(--border-color, #334155);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    background: rgba(0,0,0,0.15);
}

/* --- Interactive Tray Cards --- */
.tray-slot {
    height: 64px;
    border-radius: 6px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 600;
    transition: all 0.2s ease;
    cursor: pointer;
    position: relative;
    user-select: none;
    padding: 4px;
    text-align: center;
}

.tray-slot:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    filter: brightness(1.1);
}

.tray-ready {
    animation: readyPulse 2s infinite ease-in-out;
    border: 2px solid #00e676 !important;
}

@keyframes readyPulse {
    0% { box-shadow: 0 0 4px rgba(0, 230, 118, 0.4); }
    50% { box-shadow: 0 0 16px rgba(0, 230, 118, 0.85); }
    100% { box-shadow: 0 0 4px rgba(0, 230, 118, 0.4); }
}

.tray-badge-pill {
    font-size: 0.62rem;
    padding: 1px 5px;
    border-radius: 10px;
    background: rgba(0, 0, 0, 0.35);
    margin-top: 2px;
    font-weight: 500;
}

.preset-card {
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 14px;
    margin-bottom: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    background: rgba(0, 0, 0, 0.15);
}

.preset-card:hover {
    border-color: var(--accent-green);
    background: rgba(0, 230, 118, 0.05);
    transform: translateY(-1px);
}

.preset-card.selected {
    border-color: var(--accent-green);
    background: rgba(0, 230, 118, 0.1);
    box-shadow: 0 0 0 1px var(--accent-green);
}

/* 8-Channel Relay Module Controller Styles */
.btn-relay {
    border: 1px solid var(--border-color);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    width: 100%;
}

.btn-relay:hover {
    transform: translateY(-1px);
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.3);
}

.btn-relay-on {
    background: rgba(0, 230, 118, 0.12) !important;
    border-color: var(--accent-green) !important;
    color: var(--accent-green) !important;
    box-shadow: 0 0 8px rgba(0, 230, 118, 0.25);
}

.btn-relay-off {
    background: rgba(255, 255, 255, 0.04) !important;
    border-color: var(--border-color) !important;
    color: var(--text-muted) !important;
}

.relay-desc {
    font-size: 0.65rem;
    opacity: 0.8;
    display: block;
    margin-top: 2px;
}

