/* ==============================================================================
   ANTI-AI-SLOP UI: PROFESSIONAL AGRICULTURAL MONITORING DESIGN SYSTEM
   Standard: Canvas #090d16, Surface #111827, Elevated #1f2937, Border 1px rgba(255,255,255,0.08)
   Accent: Primary Blue #3b82f6, Normal #10b981, Warning #f59e0b, Critical #ef4444
   Typography: Inter & JetBrains Mono (tabular-nums enforced)
   Icons: SVG Lucide (stroke-width: 1.75px), Zero Emojis
   Responsive: Tested 320x720, 360x800, 390x844, 430x932, 768x1024, 1024x768, 1366x768, 1920x1080
   ============================================================================== */

:root {
    --bg-canvas: #090d16;
    --bg-surface: #111827;
    --bg-surface-elevated: #1f2937;
    --bg-surface-glass: rgba(17, 24, 39, 0.88);
    --bg-surface-sunken: #050811;
    --bg-surface-sunken-alpha: rgba(5, 8, 17, 0.45);
    --bg-surface-elevated-alpha: rgba(17, 24, 39, 0.9);
    --bg-terminal: #030712;
    --bg-hover: rgba(255, 255, 255, 0.05);
    --border-subtle: rgba(255, 255, 255, 0.08);
    --border-hover: rgba(255, 255, 255, 0.16);
    --border-focus: rgba(59, 130, 246, 0.5);

    /* Primary Accent: Crisp Linear Blue */
    --accent-blue: #3b82f6;
    --accent-blue-hover: #60a5fa;
    --accent-blue-glow: rgba(59, 130, 246, 0.22);
    --accent-blue-subtle: rgba(59, 130, 246, 0.12);

    /* Agricultural State Indicators */
    --accent-emerald: #10b981;
    --accent-emerald-glow: rgba(16, 185, 129, 0.18);
    --accent-amber: #f59e0b;
    --accent-amber-glow: rgba(245, 158, 11, 0.18);
    --accent-rose: #ef4444;
    --accent-rose-glow: rgba(239, 68, 68, 0.18);

    /* Typography Hierarchy */
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --text-invert: #090d16;

    /* Chart Semantic Tokens */
    --chart-grid-line: rgba(255, 255, 255, 0.06);
    --chart-axis-text: #94a3b8;
    --chart-crosshair: rgba(255, 255, 255, 0.4);
    --chart-tooltip-bg: rgba(9, 13, 22, 0.94);
    --chart-tooltip-border: rgba(59, 130, 246, 0.4);
    --chart-tooltip-shadow: rgba(0, 0, 0, 0.65);
    --chart-band: rgba(16, 185, 129, 0.06);
    --chart-dot-stroke: #090d16;

    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;

    --radius-xs: 4px;
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --radius-xl: 18px;

    --sidebar-width: 240px;
    --header-height: 58px;
    --bottom-nav-height: 58px;
    --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-base: 220ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* Light Theme Tokens */
:root[data-theme="light"] {
    --bg-canvas: #f8fafc;
    --bg-surface: #ffffff;
    --bg-surface-elevated: #f1f5f9;
    --bg-surface-glass: rgba(255, 255, 255, 0.92);
    --bg-surface-sunken: #f1f5f9;
    --bg-surface-sunken-alpha: rgba(241, 245, 249, 0.9);
    --bg-surface-elevated-alpha: rgba(241, 245, 249, 0.95);
    --bg-terminal: #0f172a;
    --bg-hover: rgba(15, 23, 42, 0.05);

    --border-subtle: rgba(15, 23, 42, 0.12);
    --border-hover: rgba(15, 23, 42, 0.22);
    --border-focus: rgba(37, 99, 235, 0.55);

    --accent-blue: #2563eb;
    --accent-blue-hover: #1d4ed8;
    --accent-blue-glow: rgba(37, 99, 235, 0.16);
    --accent-blue-subtle: rgba(37, 99, 235, 0.08);

    --accent-emerald: #059669;
    --accent-emerald-glow: rgba(5, 150, 105, 0.16);
    --accent-amber: #d97706;
    --accent-amber-glow: rgba(217, 119, 6, 0.16);
    --accent-rose: #dc2626;
    --accent-rose-glow: rgba(220, 38, 38, 0.16);

    --text-primary: #0f172a;
    --text-secondary: #334155;
    --text-muted: #64748b;
    --text-invert: #f8fafc;

    --chart-grid-line: rgba(15, 23, 42, 0.08);
    --chart-axis-text: #475569;
    --chart-crosshair: rgba(15, 23, 42, 0.45);
    --chart-tooltip-bg: rgba(255, 255, 255, 0.98);
    --chart-tooltip-border: rgba(37, 99, 235, 0.35);
    --chart-tooltip-shadow: rgba(15, 23, 42, 0.15);
    --chart-band: rgba(5, 150, 105, 0.08);
    --chart-dot-stroke: #ffffff;
}

@media (prefers-color-scheme: light) {
    :root:not([data-theme="dark"]) {
        --bg-canvas: #f8fafc;
        --bg-surface: #ffffff;
        --bg-surface-elevated: #f1f5f9;
        --bg-surface-glass: rgba(255, 255, 255, 0.92);
        --bg-surface-sunken: #f1f5f9;
        --bg-surface-sunken-alpha: rgba(241, 245, 249, 0.9);
        --bg-surface-elevated-alpha: rgba(241, 245, 249, 0.95);
        --bg-terminal: #0f172a;
        --bg-hover: rgba(15, 23, 42, 0.05);

        --border-subtle: rgba(15, 23, 42, 0.12);
        --border-hover: rgba(15, 23, 42, 0.22);
        --border-focus: rgba(37, 99, 235, 0.55);

        --accent-blue: #2563eb;
        --accent-blue-hover: #1d4ed8;
        --accent-blue-glow: rgba(37, 99, 235, 0.16);
        --accent-blue-subtle: rgba(37, 99, 235, 0.08);

        --accent-emerald: #059669;
        --accent-emerald-glow: rgba(5, 150, 105, 0.16);
        --accent-amber: #d97706;
        --accent-amber-glow: rgba(217, 119, 6, 0.16);
        --accent-rose: #dc2626;
        --accent-rose-glow: rgba(220, 38, 38, 0.16);

        --text-primary: #0f172a;
        --text-secondary: #334155;
        --text-muted: #64748b;
        --text-invert: #f8fafc;

        --chart-grid-line: rgba(15, 23, 42, 0.08);
        --chart-axis-text: #475569;
        --chart-crosshair: rgba(15, 23, 42, 0.45);
        --chart-tooltip-bg: rgba(255, 255, 255, 0.98);
        --chart-tooltip-border: rgba(37, 99, 235, 0.35);
        --chart-tooltip-shadow: rgba(15, 23, 42, 0.15);
        --chart-band: rgba(5, 150, 105, 0.08);
        --chart-dot-stroke: #ffffff;
    }
}

/* Universal box-sizing and boundary containment */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    width: 100%;
    min-height: 100%;
    background-color: var(--bg-canvas);
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 13px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden;
    position: relative;
}

/* Enforce tabular numerals across metrics and dates */
.tabular-nums, .mono, [data-tabular] {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
}

/* Flex and Grid Child Boundary Enforcement (No Chart/Flex blowout) */
.col, .panel, .metric-card, .chart-svg-wrap, .table-responsive, .app-main, .metrics-kpi-grid, .panel-card, .analytics-grid, .chart {
    min-width: 0;
    max-width: 100%;
}


/* Page Switching */
.page[hidden] {
    display: none !important;
}

.page {
    display: flex;
    flex-direction: column;
    gap: 20px;
    animation: fadeIn 150ms ease-in-out;
}

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

/* Common Panels & Grid */
.grid {
    display: grid;
    grid-template-columns: 1fr 340px;
    gap: 20px;
}

.col {
    display: flex;
    flex-direction: column;
    gap: 16px;
    min-width: 0;
}

.panel {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 20px 22px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    position: relative;
}

.panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
}

.panel-head h2 {
    font-size: 15px;
    font-weight: 700;
    color: var(--text-primary);
}

.toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.seg {
    display: inline-flex;
    background-color: var(--bg-surface-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    padding: 2px;
}

.seg button {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 600;
    font-family: var(--font-mono);
    padding: 4px 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.seg button[aria-pressed="true"],
.seg button.active,
.btn-seg.active {
    background-color: var(--accent-blue);
    color: #ffffff;
    box-shadow: 0 0 10px var(--accent-blue-glow);
}

/* Sidebar Brand & Header Classes */
.sidebar-brand {
    padding: 20px 18px 16px;
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.brand-icon-wrap {
    width: 34px;
    height: 34px;
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, var(--accent-blue), #1d4ed8);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    flex-shrink: 0;
}

.brand-icon-wrap svg {
    width: 18px;
    height: 18px;
}

.brand-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
    flex: 1;
}

.brand-info .brand-name {
    font-size: 14px;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
}

.brand-info .brand-sub {
    font-size: 11px;
    color: var(--text-muted);
}

.sideclose {
    display: none;
    background: transparent;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    padding: 4px;
    cursor: pointer;
}

.header-title-block h1 {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text-primary);
}

.header-title-block p {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 2px;
}

.header-meta-group {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

/* Sensor Detail Stats & Charts */
.stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
    gap: 8px;
    background-color: var(--bg-surface-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 10px 14px;
}

.stat {
    display: flex;
    flex-direction: column;
}

.stat .label {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-muted);
}

.stat b {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
}

.stat small {
    font-size: 10.5px;
    color: var(--text-faint);
    font-family: var(--font-mono);
}

.readout {
    font-size: 12px;
    color: var(--text-secondary);
    min-height: 18px;
}

.readout b {
    color: var(--text-primary);
    font-family: var(--font-mono);
}

.chart {
    width: 100%;
    height: 220px;
    position: relative;
}

.chart svg {
    width: 100%;
    height: 100%;
    overflow: hidden;
}

/* Zone Share Bar */
.zones-bar {
    display: flex;
    height: 18px;
    border-radius: 9999px;
    overflow: hidden;
    background-color: var(--bg-surface-elevated);
    border: 1px solid var(--border-subtle);
    margin: 8px 0;
}

.zones-bar-seg {
    height: 100%;
    transition: width 0.3s ease;
}

.zones-legend {
    display: flex;
    justify-content: space-between;
    font-size: 11px;
    color: var(--text-secondary);
}

/* Scatter Plot */
.scatter svg circle.sc-dot {
    fill: var(--accent-blue);
    opacity: 0.65;
    transition: r 0.2s;
}

.scatter svg line.sc-reg {
    stroke: var(--accent-rose);
    stroke-width: 1.5;
    stroke-dasharray: 3 3;
}

/* Camera Viewer */
.camview {
    width: 100%;
    aspect-ratio: 16 / 9;
    max-height: 480px;
    background-color: var(--bg-terminal);
    border-radius: var(--radius-md);
    overflow: hidden;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border-subtle);
}

.camview img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    transform-origin: center center;
    user-select: none;
    pointer-events: none;
}

.camview.pseudo-full {
    position: fixed;
    inset: 0;
    max-height: 100vh;
    z-index: 1000;
    border-radius: 0;
}

.livebadge {
    position: absolute;
    top: 12px;
    left: 12px;
    background: rgba(244, 63, 94, 0.85);
    color: #ffffff;
    font-size: 10px;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: var(--radius-sm);
    letter-spacing: 0.05em;
    font-family: var(--font-mono);
}

.camstate {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 8px;
    color: var(--text-secondary);
    padding: 24px;
}

.camstate b {
    font-size: 14px;
    color: var(--text-primary);
}

.camstate p {
    font-size: 12px;
    color: var(--text-muted);
    max-width: 320px;
}

.camhint {
    position: absolute;
    bottom: 10px;
    left: 12px;
    font-size: 10px;
    color: rgba(255, 255, 255, 0.4);
    pointer-events: none;
}

.camzoom {
    position: absolute;
    bottom: 10px;
    right: 12px;
    display: flex;
    background: var(--bg-surface-glass);
    backdrop-filter: blur(8px);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.camzoom button {
    background: transparent;
    border: none;
    color: var(--text-primary);
    padding: 6px 9px;
    font-size: 11px;
    font-family: var(--font-mono);
    cursor: pointer;
    border-right: 1px solid var(--border-subtle);
}

.camzoom button:last-child {
    border-right: none;
}

.camzoom button:hover {
    background-color: var(--bg-hover);
}

.camtools {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 8px;
}

.gallery img {
    width: 100%;
    aspect-ratio: 4 / 3;
    object-fit: cover;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-subtle);
    cursor: pointer;
}

/* History Table & Pager */
.tablewrap {
    width: 100%;
    overflow-x: auto;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
}

.tablewrap table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

.tablewrap th {
    background-color: var(--bg-surface-elevated);
    color: var(--text-secondary);
    padding: 9px 12px;
    font-weight: 600;
    text-align: left;
    border-bottom: 1px solid var(--border-subtle);
}

.tablewrap th[data-k] button {
    background: none;
    border: none;
    color: inherit;
    font: inherit;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.tablewrap td {
    padding: 8px 12px;
    border-bottom: 1px solid var(--border-subtle);
}

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

.tablewrap tr:hover td {
    background-color: var(--bg-hover);
}

.pager {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 12px;
    color: var(--text-secondary);
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
}

/* Events & Rules List */
.events {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 480px;
    overflow-y: auto;
}

.ev {
    background-color: var(--bg-surface-elevated);
    border: 1px solid var(--border-subtle);
    border-left: 3px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}

.ev.alert { border-left-color: var(--accent-rose); }
.ev.warn { border-left-color: var(--accent-amber); }
.ev.info { border-left-color: var(--accent-blue); }

.ev-content b {
    font-size: 13px;
    color: var(--text-primary);
}

.ev-content p {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 2px;
}

.ev-time {
    font-size: 10.5px;
    color: var(--text-muted);
    font-family: var(--font-mono);
    white-space: nowrap;
}

.rule {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid var(--border-subtle);
}

.rule:last-child {
    border-bottom: none;
}

.rule-info b {
    font-size: 13px;
    color: var(--text-primary);
}

.rule-info p {
    font-size: 11px;
    color: var(--text-muted);
}

/* Settings Form Controls */
.field {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border-subtle);
}

.field:last-child {
    border-bottom: none;
}

.field .t {
    display: flex;
    flex-direction: column;
}

.field .t b {
    font-size: 13px;
    color: var(--text-primary);
}

.field .t span {
    font-size: 11px;
    color: var(--text-muted);
}

.ctl {
    display: flex;
    align-items: center;
    gap: 8px;
}

.ctl input[type="text"],
.ctl input[type="number"],
.ctl select {
    background-color: var(--bg-surface-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    padding: 6px 10px;
    font-size: 12px;
    outline: none;
}

.ctl input[type="text"]:focus,
.ctl input[type="number"]:focus,
.ctl select:focus {
    border-color: var(--border-focus);
}

.input-invalid {
    border-color: var(--accent-rose) !important;
}

/* Switch */
.sw {
    appearance: none;
    width: 38px;
    height: 20px;
    background-color: var(--bg-surface-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: 9999px;
    position: relative;
    cursor: pointer;
    transition: background-color var(--transition-fast);
}

.sw::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background-color: var(--text-secondary);
    transition: transform var(--transition-fast), background-color var(--transition-fast);
}

.sw:checked {
    background-color: var(--accent-blue);
    border-color: var(--accent-blue);
}

.sw:checked::after {
    transform: translateX(18px);
    background-color: #ffffff;
}

/* Guide Flow & Steps */
.flow {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    background-color: var(--bg-surface-elevated);
    padding: 12px 14px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-subtle);
    font-size: 12px;
}

.flow .node {
    font-weight: 600;
    color: var(--text-primary);
}

.flow .arrow {
    color: var(--accent-blue);
    font-family: var(--font-mono);
}

.steps {
    padding-left: 18px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    font-size: 13px;
    color: var(--text-secondary);
}

.steps b {
    color: var(--text-primary);
}

details {
    background-color: var(--bg-surface-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 12px 14px;
}

details summary {
    font-weight: 600;
    color: var(--text-primary);
    cursor: pointer;
    user-select: none;
}

details p {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 8px;
    line-height: 1.6;
}

pre {
    background-color: var(--bg-terminal);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 12px;
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--accent-blue-hover);
    overflow-x: auto;
}

.msg {
    font-size: 11px;
    color: var(--text-muted);
}

.msg.good { color: var(--accent-emerald); }
.msg.err { color: var(--accent-rose); }

.hint {
    font-size: 11.5px;
    color: var(--text-muted);
    line-height: 1.5;
}

.count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background-color: var(--accent-rose);
    color: #ffffff;
    font-size: 10px;
    font-weight: 700;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    border-radius: 9999px;
    margin-left: auto;
}

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

.btn.ghost:hover {
    color: var(--text-primary);
    border-color: var(--border-hover);
    background-color: var(--bg-hover);
}

.btn.small {
    padding: 4px 8px;
    font-size: 11px;
}

.app-shell,
.app-layout {
    display: flex;
    min-height: 100vh;
    width: 100%;
    background-color: var(--bg-canvas);
    position: relative;
}

/* Sidebar Navigation */
.app-sidebar {
    width: var(--sidebar-width);
    background-color: var(--bg-surface);
    border-right: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 50;
    transition: transform var(--transition-base);
}

.sidebar-header {
    height: 64px;
    padding: 0 18px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid var(--border-subtle);
}

.brand-icon {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.2), rgba(16, 185, 129, 0.2));
    border: 1px solid var(--border-hover);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent-blue);
    flex-shrink: 0;
}

.brand-title {
    display: flex;
    flex-direction: column;
}

.brand-title .title-name {
    font-size: 14px;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: var(--text-primary);
}

.brand-title .title-sub {
    font-size: 11px;
    font-weight: 500;
    color: var(--accent-blue);
    letter-spacing: 0.04em;
    text-transform: uppercase;
    font-family: var(--font-mono);
}

.sidebar-nav {
    flex: 1;
    padding: 16px 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    overflow-y: auto;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
    transition: all var(--transition-fast);
    border: 1px solid transparent;
}

.nav-link:hover {
    color: var(--text-primary);
    background-color: var(--bg-hover);
    border-color: var(--border-subtle);
}

.nav-link.active {
    color: #ffffff;
    background-color: var(--accent-blue-subtle);
    border-color: rgba(59, 130, 246, 0.35);
    box-shadow: 0 0 16px -4px var(--accent-blue-glow);
}

.nav-link svg {
    width: 17px;
    height: 17px;
    flex-shrink: 0;
    stroke-width: 1.75;
}

.sidebar-footer {
    padding: 14px 16px;
    border-top: 1px solid var(--border-subtle);
    background-color: var(--bg-surface-elevated);
}

.system-status-box {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.status-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    font-weight: 600;
    color: var(--accent-emerald);
}

.pulse-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background-color: var(--accent-emerald);
    box-shadow: 0 0 8px var(--accent-emerald);
    animation: pulseGlow 2s infinite ease-in-out;
}

@keyframes pulseGlow {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.3); opacity: 0.6; }
}

.status-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-primary);
}

.status-sub {
    font-size: 11px;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

/* Mobile Header */
.mobile-header {
    display: none;
    height: var(--header-height);
    background-color: var(--bg-surface-glass);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border-subtle);
    padding: 0 16px;
    align-items: center;
    justify-content: space-between;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 40;
}

.menu-toggle {
    background: transparent;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    padding: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.menu-toggle svg {
    width: 20px;
    height: 20px;
    stroke-width: 1.75;
}

/* Main Content Workspace */
.app-main {
    flex: 1;
    width: calc(100% - var(--sidebar-width));
    margin-left: var(--sidebar-width);
    padding: 20px 26px 56px;
    max-width: 1680px;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 18px;
}

/* Top Action Header */
.content-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 16px;
    padding-bottom: 8px;
}

.page-intro h1 {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.02em;
}

.page-intro p {
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 2px;
}

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

.badge-tag {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    border-radius: 9999px;
    font-size: 11px;
    font-weight: 600;
    border: 1px solid var(--border-subtle);
    background-color: var(--bg-surface);
    color: var(--text-secondary);
    font-family: var(--font-mono);
}

.badge-tag.blue {
    background-color: var(--accent-blue-subtle);
    border-color: rgba(59, 130, 246, 0.3);
    color: var(--accent-blue-hover);
}

.badge-tag.emerald {
    background-color: rgba(16, 185, 129, 0.1);
    border-color: rgba(16, 185, 129, 0.3);
    color: var(--accent-emerald);
}

/* Plant Age Banner (Banner Umur Tanaman) */
.plant-age-banner {
    background: linear-gradient(135deg, var(--bg-surface-elevated-alpha), var(--bg-surface));
    border: 1px solid var(--border-subtle);
    border-left: 4px solid var(--accent-blue);
    border-radius: var(--radius-lg);
    padding: 20px 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    box-shadow: 0 8px 24px -6px rgba(0, 0, 0, 0.4);
    position: relative;
    overflow: hidden;
}

.plant-age-banner::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 260px;
    height: 100%;
    background: radial-gradient(circle at right, rgba(59, 130, 246, 0.08), transparent 70%);
    pointer-events: none;
}

.banner-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 16px;
}

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

.plant-icon-wrap {
    width: 48px;
    height: 48px;
    background-color: rgba(59, 130, 246, 0.15);
    border: 1px solid rgba(59, 130, 246, 0.3);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent-blue);
    flex-shrink: 0;
}

.plant-icon-wrap svg {
    width: 24px;
    height: 24px;
    stroke-width: 1.75;
}

.banner-title-block h2 {
    font-size: 17px;
    font-weight: 700;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.banner-title-block p {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 2px;
}

.age-stat-group {
    display: flex;
    align-items: baseline;
    gap: 6px;
}

.age-stat-group .age-number {
    font-size: 32px;
    font-weight: 700;
    font-family: var(--font-mono);
    color: var(--accent-blue-hover);
    line-height: 1;
}

.age-stat-group .age-unit {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
}

.banner-progress-wrap {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.progress-labels {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    color: var(--text-muted);
}

.progress-track {
    width: 100%;
    height: 8px;
    background-color: rgba(255, 255, 255, 0.06);
    border-radius: 9999px;
    overflow: hidden;
    position: relative;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #2563eb, #38bdf8);
    border-radius: 9999px;
    transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 0 10px rgba(59, 130, 246, 0.5);
}

/* Metric Cards Grid */
.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 16px;
}

.metric-card {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 18px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    transition: border-color var(--transition-fast), transform var(--transition-fast);
    position: relative;
}

.metric-card:hover {
    border-color: var(--border-hover);
}

.card-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.metric-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.metric-title svg {
    width: 16px;
    height: 16px;
    stroke-width: 1.75;
    color: var(--accent-blue);
}

.metric-badge {
    font-size: 11px;
    font-weight: 600;
    padding: 2px 7px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
}

.metric-badge.ok {
    background-color: rgba(16, 185, 129, 0.12);
    border-color: rgba(16, 185, 129, 0.3);
    color: var(--accent-emerald);
}

.metric-badge.warn {
    background-color: rgba(245, 158, 11, 0.12);
    border-color: rgba(245, 158, 11, 0.3);
    color: var(--accent-amber);
}

.metric-badge.alert {
    background-color: rgba(244, 63, 94, 0.12);
    border-color: rgba(244, 63, 94, 0.3);
    color: var(--accent-rose);
}

.card-body {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
}

.metric-value-wrap {
    display: flex;
    align-items: baseline;
    gap: 4px;
}

.metric-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1;
}

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

.metric-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-top: 10px;
    border-top: 1px solid var(--border-subtle);
    font-size: 11px;
    color: var(--text-muted);
}

.sparkline-container {
    height: 28px;
    width: 88px;
}

/* Prediction Card (Prediksi Pertumbuhan) */
.prediction-card {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 22px 24px;
    display: flex;
    flex-direction: column;
    gap: 18px;
    position: relative;
}

.prediction-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
}

.pred-title-group h3 {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.pred-title-group p {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 2px;
}

.pred-forecast-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px;
}

.forecast-item {
    background-color: var(--bg-surface-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    transition: border-color var(--transition-fast);
}

.forecast-item:hover {
    border-color: rgba(59, 130, 246, 0.4);
}

.forecast-day-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
}

.forecast-maturity {
    display: flex;
    align-items: baseline;
    gap: 6px;
}

.forecast-pct {
    font-size: 22px;
    font-weight: 700;
    color: var(--accent-blue-hover);
}

.forecast-state-pill {
    display: inline-block;
    padding: 3px 8px;
    border-radius: var(--radius-sm);
    font-size: 11px;
    font-weight: 600;
}

.forecast-state-pill.veg {
    background-color: rgba(59, 130, 246, 0.12);
    color: #60a5fa;
    border: 1px solid rgba(59, 130, 246, 0.3);
}

.forecast-state-pill.near {
    background-color: rgba(245, 158, 11, 0.12);
    color: #fbbf24;
    border: 1px solid rgba(245, 158, 11, 0.3);
}

.forecast-state-pill.ready {
    background-color: rgba(16, 185, 129, 0.12);
    color: #34d399;
    border: 1px solid rgba(16, 185, 129, 0.3);
}

/* Telemetry Chart Section */
.telemetry-section {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 20px 22px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.chart-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
}

.chart-title-area h3 {
    font-size: 15px;
    font-weight: 700;
    color: var(--text-primary);
}

.chart-title-area p {
    font-size: 12px;
    color: var(--text-secondary);
}

.chart-action-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.btn-pill-group {
    display: inline-flex;
    background-color: var(--bg-surface-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    padding: 2px;
}

.btn-pill {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 600;
    font-family: var(--font-mono);
    padding: 4px 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
}

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

.btn-pill.active {
    background-color: var(--accent-blue);
    color: #ffffff;
    box-shadow: 0 0 10px var(--accent-blue-glow);
}

.chart-svg-wrap {
    width: 100%;
    height: 240px;
    position: relative;
    user-select: none;
}

.chart-svg-wrap svg {
    width: 100%;
    height: 100%;
    overflow: hidden;
}

/* SVG Chart Elements */
.chart-svg-wrap .grid-line {
    stroke: rgba(255, 255, 255, 0.05);
    stroke-dasharray: 3 3;
}

.chart-svg-wrap .threshold-line {
    stroke: rgba(244, 63, 94, 0.4);
    stroke-dasharray: 4 4;
}

.chart-svg-wrap .axis-text {
    fill: var(--text-muted);
    font-size: 10px;
    font-family: var(--font-mono);
}

.chart-svg-wrap .data-area {
    fill: url(#blueGradient);
    opacity: 0.15;
}

.chart-svg-wrap .data-line {
    fill: none;
    stroke: var(--accent-blue);
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.chart-svg-wrap .data-dot {
    fill: var(--accent-blue);
    stroke: var(--bg-surface);
    stroke-width: 1.5;
}

.chart-svg-wrap .crosshair-line {
    stroke: rgba(255, 255, 255, 0.25);
    stroke-dasharray: 2 2;
}

.chart-svg-wrap .normal-band {
    fill: rgba(59, 130, 246, 0.06);
}

/* Dataset Table Section */
.dataset-section {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 20px 22px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.dataset-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
}

.dataset-title h3 {
    font-size: 15px;
    font-weight: 700;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.dataset-title p {
    font-size: 12px;
    color: var(--text-secondary);
}

.dataset-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 12px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
    border: 1px solid transparent;
}

.btn svg {
    width: 14px;
    height: 14px;
    stroke-width: 1.75;
}

.btn-secondary {
    background-color: var(--bg-surface-elevated);
    border-color: var(--border-subtle);
    color: var(--text-secondary);
}

.btn-secondary:hover {
    color: var(--text-primary);
    border-color: var(--border-hover);
    background-color: var(--bg-hover);
}

.btn-primary {
    background-color: var(--accent-blue);
    color: #ffffff;
    box-shadow: 0 0 14px -2px var(--accent-blue-glow);
}

.btn-primary:hover {
    background-color: var(--accent-blue-hover);
}

.table-responsive {
    width: 100%;
    overflow-x: auto;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
    text-align: left;
}

.data-table th {
    background-color: var(--bg-surface-elevated);
    color: var(--text-secondary);
    font-weight: 600;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border-subtle);
    text-transform: uppercase;
    font-size: 11px;
    letter-spacing: 0.04em;
}

.data-table td {
    padding: 10px 14px;
    border-bottom: 1px solid var(--border-subtle);
    color: var(--text-primary);
}

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

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

/* AI Assistant Section */
.ai-assistant-section {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 22px 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    position: relative;
}

.ai-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
}

.ai-intro h3 {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.ai-intro p {
    font-size: 12px;
    color: var(--text-secondary);
}

.ai-chips-container {
    display: flex;
    align-items: center;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 4px;
}

.ai-chip {
    background-color: var(--bg-surface-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: 9999px;
    padding: 5px 12px;
    font-size: 11px;
    font-weight: 500;
    color: var(--text-secondary);
    white-space: nowrap;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.ai-chip:hover {
    color: var(--accent-blue-hover);
    border-color: rgba(59, 130, 246, 0.4);
    background-color: var(--accent-blue-subtle);
}

.ai-chat-thread {
    background-color: var(--bg-surface-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 16px;
    max-height: 380px;
    min-height: 220px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.chat-bubble {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-width: 85%;
    font-size: 13px;
    line-height: 1.6;
}

.chat-bubble.ai {
    align-self: flex-start;
}

.chat-bubble.user {
    align-self: flex-end;
}

.bubble-content {
    padding: 12px 16px;
    border-radius: var(--radius-md);
}

.chat-bubble.ai .bubble-content {
    background-color: var(--bg-surface-elevated-alpha);
    border: 1px solid rgba(59, 130, 246, 0.25);
    color: var(--text-primary);
}

.chat-bubble.user .bubble-content {
    background-color: var(--accent-blue);
    color: #ffffff;
}

.bubble-meta {
    font-size: 10px;
    color: var(--text-muted);
    font-family: var(--font-mono);
    display: flex;
    align-items: center;
    gap: 6px;
}

.chat-bubble.user .bubble-meta {
    justify-content: flex-end;
}

.ai-input-bar {
    display: flex;
    gap: 8px;
}

.ai-input-bar input {
    flex: 1;
    background-color: var(--bg-surface-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    padding: 10px 14px;
    font-size: 13px;
    outline: none;
    transition: border-color var(--transition-fast);
}

.ai-input-bar input:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 2px var(--accent-blue-subtle);
}

/* ================= LIVE CAMERA INLINE IP & MICROSD SYNC GRID ================= */
.cam-inline-ip-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 10px;
    padding: 8px 10px;
    background-color: var(--bg-surface-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
}

.cam-ip-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    white-space: nowrap;
}

.cam-ip-input {
    flex: 1;
    min-width: 120px;
    background-color: var(--bg-canvas);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    padding: 5px 10px;
    font-size: 12px;
    font-family: var(--font-mono);
    outline: none;
}

.cam-ip-input:focus {
    border-color: var(--accent-emerald);
}

.cam-hw-status-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin-top: 10px;
}

.cam-hw-status-item {
    background-color: var(--bg-surface-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.cam-hw-status-item .hw-label {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
}

.cam-hw-status-item .hw-val {
    font-size: 12px;
    font-weight: 700;
    color: var(--text-primary);
    word-break: break-word;
}

.cam-hw-status-item .hw-sub {
    font-size: 10px;
    color: var(--text-secondary);
    line-height: 1.35;
}

.growth-campaign-banner {
    margin-bottom: 16px;
}

.dual-progress-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
    margin-top: 12px;
}

.progress-block {
    background-color: var(--bg-surface-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
}

.progress-fill.blue {
    background: linear-gradient(90deg, var(--accent-blue), #38bdf8);
}

@media (max-width: 768px) {
    .cam-hw-status-grid,
    .dual-progress-grid {
        grid-template-columns: 1fr;
    }
}



/* ================= KPI CARDS GRID ================= */
.metrics-kpi-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 14px;
    width: 100%;
}

.metric-card {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 16px 18px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 12px;
    transition: border-color var(--transition-fast), transform var(--transition-fast);
    position: relative;
}

.metric-card:hover {
    border-color: var(--border-hover);
    transform: translateY(-1px);
}

.metric-card.alert-border {
    border-color: rgba(239, 68, 68, 0.4);
}

.card-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.metric-title {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
}

.metric-title svg {
    width: 15px;
    height: 15px;
    stroke-width: 1.75px;
    color: var(--accent-blue);
}

.metric-badge {
    font-size: 10px;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: var(--radius-xs);
    font-family: var(--font-mono);
    text-transform: uppercase;
}

.metric-badge.ok {
    background-color: var(--accent-emerald-glow);
    color: var(--accent-emerald);
    border: 1px solid rgba(16, 185, 129, 0.3);
}

.metric-badge.warn {
    background-color: var(--accent-amber-glow);
    color: var(--accent-amber);
    border: 1px solid rgba(245, 158, 11, 0.3);
}

.metric-badge.alert {
    background-color: var(--accent-rose-glow);
    color: var(--accent-rose);
    border: 1px solid rgba(239, 68, 68, 0.3);
}

.metric-body {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 8px;
}

.metric-value {
    font-size: 26px;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1;
}

.metric-unit {
    font-size: 13px;
    color: var(--text-muted);
    font-weight: 500;
    margin-left: 2px;
}

.metric-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 11px;
    color: var(--text-muted);
    border-top: 1px solid rgba(255, 255, 255, 0.04);
    padding-top: 8px;
}

/* ================= BALANCED 2-COLUMN DASHBOARD COMPOSITION PANELS ================= */
.dashboard-main-composition {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
    width: 100%;
    align-items: stretch;
}

.dashboard-bottom-split {
    display: grid;
    grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr);
    gap: 16px;
    width: 100%;
    align-items: start;
}

.sensor-panels-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
    width: 100%;
}

/* Device, Camera, microSD, Sync & Campaign Summary Strip */
.device-status-strip {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 10px;
    width: 100%;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border-subtle);
}

.status-strip-item {
    background-color: var(--bg-surface-sunken-alpha);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    padding: 8px 11px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.status-strip-item .strip-k {
    font-size: 10px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.status-strip-item .strip-v {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.status-strip-item .strip-sub {
    font-size: 10px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Interactive Chart Legend & Tooltip */
.chart-legend-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
    padding: 8px 12px;
    background-color: var(--bg-surface-sunken-alpha);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
}

.legend-items {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 14px;
}

.legend-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
}

.legend-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}

.legend-dot.emerald { background-color: #10b981; box-shadow: 0 0 6px rgba(16,185,129,0.5); }
.legend-dot.blue { background-color: #3b82f6; box-shadow: 0 0 6px rgba(59,130,246,0.5); }
.legend-dot.amber { background-color: #f59e0b; box-shadow: 0 0 6px rgba(245,158,11,0.5); }
.legend-dot.rose { background-color: #f43f5e; box-shadow: 0 0 6px rgba(244,63,94,0.5); }

.legend-source {
    font-size: 11px;
    color: var(--text-muted);
}

.chart-tooltip {
    position: absolute;
    z-index: 20;
    pointer-events: none;
    background-color: var(--chart-tooltip-bg);
    border: 1px solid var(--chart-tooltip-border);
    border-radius: var(--radius-sm);
    padding: 8px 10px;
    min-width: 175px;
    box-shadow: 0 8px 24px var(--chart-tooltip-shadow);
    font-size: 11px;
}

.chart-tooltip .tt-time {
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 4px;
    padding-bottom: 4px;
    border-bottom: 1px solid var(--border-subtle);
}

.chart-tooltip .tt-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    line-height: 1.5;
    color: var(--text-secondary);
}

/* Dashboard Capture Gallery Strip */
.dash-mini-gallery {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
    width: 100%;
}

.dash-gallery-empty {
    grid-column: 1 / -1;
    padding: 12px;
    border-radius: var(--radius-sm);
    background-color: var(--bg-surface-sunken-alpha);
    border: 1px dashed var(--border-subtle);
    color: var(--text-muted);
    font-size: 11px;
    text-align: center;
}

.dash-gallery-thumb {
    position: relative;
    height: 68px;
    border-radius: var(--radius-sm);
    overflow: hidden;
    border: 1px solid var(--border-subtle);
    background-color: var(--bg-surface-sunken);
    cursor: pointer;
}

.dash-gallery-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.dash-thumb-placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

.dash-thumb-meta {
    position: absolute;
    bottom: 3px;
    right: 4px;
    background: rgba(9, 13, 22, 0.85);
    color: var(--accent-emerald);
    font-size: 9px;
    padding: 1px 4px;
    border-radius: 3px;
}

.panel-card {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
    max-width: 100%;
}

.panel-card-header {
    padding: 14px 18px;
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
    background-color: rgba(255, 255, 255, 0.015);
}

.panel-card-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    font-weight: 700;
    color: var(--text-primary);
}

.panel-card-title svg {
    width: 16px;
    height: 16px;
    color: var(--accent-blue);
}

.panel-card-body {
    padding: 16px 18px;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

/* Live Camera View */
.cam-preview-box {
    width: 100%;
    aspect-ratio: 16 / 10;
    background-color: var(--bg-surface-sunken);
    border-radius: var(--radius-md);
    overflow: hidden;
    position: relative;
    border: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    justify-content: center;
}

.cam-preview-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.cam-overlay-badges {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.cam-controls-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    flex-wrap: wrap;
}

/* Plant Health Analysis */
.plant-health-view {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.plant-health-visual-wrap {
    width: 100%;
    aspect-ratio: 16 / 10;
    background-color: var(--bg-surface-sunken);
    border-radius: var(--radius-md);
    overflow: hidden;
    position: relative;
    border: 1px solid var(--border-subtle);
}

.plant-health-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.health-metrics-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.health-mini-stat {
    background-color: var(--bg-surface-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.health-mini-stat .lbl {
    font-size: 11px;
    color: var(--text-muted);
}

.health-mini-stat .val {
    font-size: 14px;
    font-weight: 700;
    color: var(--text-primary);
}

/* AI Recommendations */
.ai-recom-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    flex: 1;
}

.ai-recom-card {
    background-color: var(--bg-surface-elevated);
    border: 1px solid var(--border-subtle);
    border-left: 3px solid var(--accent-blue);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.ai-recom-card.emerald { border-left-color: var(--accent-emerald); }
.ai-recom-card.amber { border-left-color: var(--accent-amber); }
.ai-recom-card.rose { border-left-color: var(--accent-rose); }

.ai-recom-card h4 {
    font-size: 12px;
    font-weight: 700;
    color: var(--text-primary);
}

.ai-recom-card p {
    font-size: 11px;
    color: var(--text-secondary);
    line-height: 1.4;
}

/* ================= ANALYTICS & CHARTS SECTION ================= */
.analytics-section {
    display: flex;
    flex-direction: column;
    gap: 16px;
    width: 100%;
}

.telemetry-section {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 20px 22px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    min-width: 0;
    max-width: 100%;
}

.chart-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
}

.chart-title-area h3 {
    font-size: 15px;
    font-weight: 700;
    color: var(--text-primary);
}

.chart-title-area p {
    font-size: 12px;
    color: var(--text-secondary);
}

.chart-action-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.btn-pill-group {
    display: inline-flex;
    background-color: var(--bg-surface-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    padding: 2px;
}

.btn-pill {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 600;
    font-family: var(--font-mono);
    padding: 5px 11px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
}

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

.btn-pill.active {
    background-color: var(--accent-blue);
    color: #ffffff;
    box-shadow: 0 0 10px var(--accent-blue-glow);
}

/* Bulletproof Chart SVG Wrap */
.chart-svg-wrap {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    height: 250px;
    position: relative;
    user-select: none;
    overflow: hidden;
    border-radius: var(--radius-sm);
    background-color: var(--bg-surface-sunken-alpha);
}

.chart-svg-wrap svg {
    width: 100%;
    height: 100%;
    max-width: 100%;
    display: block;
    overflow: hidden;
}

.chart-svg-wrap .grid-line {
    stroke: var(--chart-grid-line);
    stroke-dasharray: 4 4;
}

.chart-svg-wrap .threshold-line {
    stroke: rgba(239, 68, 68, 0.45);
    stroke-dasharray: 4 4;
    stroke-width: 1.5;
}

.chart-svg-wrap .axis-text {
    fill: var(--chart-axis-text);
    font-size: 10px;
    font-family: var(--font-mono);
}

.chart-svg-wrap .data-area {
    fill: url(#blueGradient);
}

.chart-svg-wrap .data-line {
    fill: none;
    stroke: var(--accent-blue);
    stroke-width: 2.25;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.chart-svg-wrap .data-dot {
    fill: var(--accent-blue);
    stroke: var(--chart-dot-stroke);
    stroke-width: 2;
}

.normal-band {
    fill: var(--chart-band);
}

/* Multi-analytics 2-column grid */
.analytics-subgrid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    width: 100%;
    min-width: 0;
}

.sub-chart-box {
    background-color: var(--bg-surface-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
}

.sub-chart-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    flex-wrap: wrap;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
}

.sub-chart-wrap {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    height: 140px;
    position: relative;
    overflow: hidden;
    border-radius: var(--radius-sm);
    background-color: var(--bg-surface-sunken-alpha);
}

.sub-chart-wrap.tall {
    height: 175px;
}

.sub-chart-wrap svg {
    width: 100%;
    height: 100%;
    max-width: 100%;
    display: block;
    overflow: hidden;
}

/* ================= LEAF GROWTH 42-DAY CAMPAIGN SECTION ================= */
.leaf-growth-banner {
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.12), rgba(16, 185, 129, 0.08));
    border: 1px solid rgba(59, 130, 246, 0.25);
    border-radius: var(--radius-lg);
    padding: 18px 22px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.banner-stats-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 14px;
}

.progress-track {
    width: 100%;
    height: 8px;
    background-color: rgba(255, 255, 255, 0.06);
    border-radius: 4px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-blue), var(--accent-emerald));
    border-radius: 4px;
    transition: width var(--transition-base);
}

.gallery-filter-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    padding: 12px 16px;
    background-color: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
}

.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 240px), 1fr));
    gap: 16px;
    width: 100%;
    min-width: 0;
}

.gallery-card {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transition: border-color var(--transition-fast), transform var(--transition-fast);
}

.gallery-card:hover {
    border-color: var(--border-hover);
    transform: translateY(-2px);
}

.gallery-img-wrap,
.gallery-card-thumb {
    width: 100%;
    aspect-ratio: 4 / 3;
    background-color: var(--bg-surface-sunken);
    position: relative;
    overflow: hidden;
}

.gallery-img-wrap img,
.gallery-card-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.gallery-badge,
.gallery-card-badge {
    position: absolute;
    top: 8px;
    left: 8px;
    font-size: 10px;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.gallery-card-badge.emerald {
    background: rgba(16, 185, 129, 0.2);
    color: #10b981;
    border: 1px solid rgba(16, 185, 129, 0.4);
}

.gallery-card-badge.rose {
    background: rgba(244, 63, 94, 0.2);
    color: #f43f5e;
    border: 1px solid rgba(244, 63, 94, 0.4);
}

.gallery-info,
.gallery-card-info {
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.gallery-card-info .title {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-primary);
}

.gallery-card-info .sub {
    font-size: 11px;
    color: var(--text-secondary);
}

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

.gallery-title-row h5 {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-primary);
}

.gallery-metric-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 11px;
    color: var(--text-secondary);
}

/* ================= ALERTS & NOTIFICATIONS ================= */
.alerts-list-wrap {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.alert-item {
    background-color: var(--bg-surface-elevated);
    border: 1px solid var(--border-subtle);
    border-left: 4px solid var(--accent-rose);
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
}

.alert-item.warn { border-left-color: var(--accent-amber); }
.alert-item.info { border-left-color: var(--accent-blue); }

.alert-content h4 {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-primary);
}

.alert-content p {
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 2px;
}

/* ================= BOTTOM PLANT & SYSTEM STATISTICS BAR ================= */
.stats-footer-bar {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 16px 22px;
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 14px;
    align-items: center;
}

.footer-stat-item,
.footer-stat-card {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.footer-stat-item .lbl,
.footer-stat-card .lbl {
    font-size: 11px;
    color: var(--text-muted);
}

.footer-stat-item .val,
.footer-stat-card .val {
    font-size: 15px;
    font-weight: 700;
    color: var(--text-primary);
    overflow-wrap: anywhere;
}

/* ================= TABLES & DATASET ================= */
.table-responsive {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-subtle);
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
    text-align: left;
    white-space: nowrap;
}

.data-table th {
    background-color: var(--bg-surface-elevated);
    padding: 11px 14px;
    font-weight: 600;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-subtle);
}

.data-table td {
    padding: 10px 14px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
    color: var(--text-secondary);
}

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

/* ================= BUTTONS & INPUTS ================= */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    font-size: 12px;
    font-weight: 600;
    padding: 7px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    cursor: pointer;
    transition: all var(--transition-fast);
    text-decoration: none;
    min-height: 34px;
}

.btn-primary {
    background-color: var(--accent-blue);
    color: #ffffff;
}

.btn-primary:hover {
    background-color: var(--accent-blue-hover);
    box-shadow: 0 0 12px var(--accent-blue-glow);
}

.btn-secondary {
    background-color: var(--bg-surface-elevated);
    border-color: var(--border-subtle);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background-color: var(--bg-hover);
    border-color: var(--border-hover);
}

/* Mobile Header & Backdrop */
.mobile-header {
    display: none;
    height: var(--header-height);
    background-color: var(--bg-surface);
    border-bottom: 1px solid var(--border-subtle);
    padding: 0 16px;
    align-items: center;
    justify-content: space-between;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 40;
}

.mobile-backdrop {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(4px);
    z-index: 45;
}

.mobile-backdrop.open {
    display: block;
}

/* ================= MODAL DIALOGS ================= */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(5px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 16px;
}

.modal-overlay.open {
    display: flex;
}

.modal-window {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 720px;
    max-height: 90vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

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

.modal-body {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* Toast Notifications */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 100;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

.toast {
    pointer-events: auto;
    background-color: var(--bg-surface-elevated);
    border: 1px solid var(--border-subtle);
    border-left: 3px solid var(--accent-blue);
    border-radius: var(--radius-sm);
    padding: 10px 16px;
    color: var(--text-primary);
    font-size: 12px;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    gap: 10px;
}

.toast.emerald { border-left-color: var(--accent-emerald); }
.toast.rose { border-left-color: var(--accent-rose); }
.toast.amber { border-left-color: var(--accent-amber); }

/* Skeleton Shimmer */
.skeleton-shimmer {
    background: linear-gradient(90deg, rgba(255, 255, 255, 0.03) 25%, rgba(255, 255, 255, 0.08) 50%, rgba(255, 255, 255, 0.03) 75%);
    background-size: 200% 100%;
    animation: shimmerPulse 1.8s infinite ease-in-out;
    border-radius: var(--radius-sm);
}

@keyframes shimmerPulse {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}



/* ================= RESPONSIVE VIEWPORT BREAKPOINTS ================= */

/* 1. Tablet & Small Laptop (<= 1200px) */
@media (max-width: 1200px) {
    .metrics-kpi-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }

    .device-status-strip {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .stats-footer-bar {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* 2. Tablet Portrait (<= 960px) */
@media (max-width: 960px) {
    .app-sidebar {
        transform: translateX(-100%);
    }

    .app-sidebar.open {
        transform: translateX(0);
        box-shadow: 10px 0 30px rgba(0, 0, 0, 0.7);
    }

    .sideclose {
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .mobile-header {
        display: flex;
    }

    .app-main {
        width: 100%;
        margin-left: 0;
        padding: calc(var(--header-height) + 16px) 16px 48px;
    }

    .metrics-kpi-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .device-status-strip {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .dashboard-main-composition,
    .dashboard-bottom-split,
    .sensor-panels-grid {
        grid-template-columns: 1fr;
    }

    .grid {
        grid-template-columns: 1fr;
    }

    .analytics-subgrid {
        grid-template-columns: 1fr;
    }

    .stats-footer-bar {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* 3. Mobile Standard (360px - 600px) */
@media (max-width: 600px) {
    .metrics-kpi-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }

    .metric-card {
        padding: 12px 14px;
        min-width: 0;
    }

    .metric-value {
        font-size: 20px;
    }

    .chart-controls {
        flex-direction: column;
        align-items: flex-start;
    }

    .chart-svg-wrap {
        height: 200px;
    }

    .field,
    .rule {
        flex-direction: column;
        align-items: flex-start;
    }

    .field .ctl,
    .rule .ctl {
        width: 100%;
    }

    .field input,
    .field select {
        width: 100%;
        min-width: 0;
    }

    .stats-footer-bar {
        grid-template-columns: 1fr 1fr;
        padding: 12px 14px;
    }

    .toast-container {
        left: 16px;
        right: 16px;
        bottom: 16px;
    }
}

/* 4. Compact Mobile (<= 380px: 320px, 360px) */
@media (max-width: 380px) {
    .app-main {
        padding: calc(var(--header-height) + 12px) 8px 40px;
    }

    .metrics-kpi-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
    }

    .metric-card {
        padding: 8px 10px;
        gap: 6px;
    }

    .metric-title {
        font-size: 11px;
    }

    .metric-value {
        font-size: 17px;
    }

    .metric-badge {
        font-size: 9px;
        padding: 1px 4px;
        white-space: nowrap;
    }

    .metric-footer {
        font-size: 10px;
        padding-top: 6px;
    }

    .metric-footer .badge-tag {
        font-size: 8.5px;
        padding: 1px 3px;
        white-space: nowrap;
    }

    .health-metrics-row {
        grid-template-columns: 1fr;
    }

    .stats-footer-bar {
        grid-template-columns: 1fr;
    }

    .header-title-block h1 {
        font-size: 15px;
    }

    .modal-overlay {
        padding: 6px;
    }

    .modal-body {
        padding: 10px;
    }
}

/* ==============================================================================
   ACCESSIBILITY, FOCUS-VISIBLE & PREFERS-REDUCED-MOTION
   ============================================================================== */
:focus-visible {
    outline: 2px solid var(--accent-blue);
    outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* ==============================================================================
   MOBILE BOTTOM NAVIGATION BAR
   ============================================================================== */
.bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--bottom-nav-height);
    background-color: var(--bg-surface-glass);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-top: 1px solid var(--border-subtle);
    z-index: 45;
    justify-content: space-around;
    align-items: center;
    padding: 0 4px;
}

.bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    flex: 1;
    height: 100%;
    color: var(--text-secondary);
    text-decoration: none;
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 10px;
    font-weight: 500;
    padding: 4px;
    transition: color var(--transition-fast);
}

.bottom-nav-item svg {
    width: 18px;
    height: 18px;
    stroke-width: 1.75;
}

.bottom-nav-item:hover,
.bottom-nav-item:focus-visible {
    color: var(--text-primary);
}

.bottom-nav-item.active {
    color: var(--accent-blue);
    font-weight: 700;
}

@media (max-width: 768px) {
    .bottom-nav {
        display: flex;
    }
    .app-main {
        padding-bottom: calc(var(--bottom-nav-height) + 24px) !important;
    }
}

/* ==============================================================================
   REUSABLE UTILITY CLASSES (u-*)
   ============================================================================== */
.u-flex-center { display: flex; align-items: center; }
.u-flex-wrap-center { display: flex; align-items: center; flex-wrap: wrap; }
.u-gap-8 { gap: 8px; }
.u-gap-10 { gap: 10px; }
.u-mb-0 { margin-bottom: 0 !important; }
.u-mb-8 { margin-bottom: 8px !important; }
.u-mb-16 { margin-bottom: 16px !important; }
.u-mt-4 { margin-top: 4px !important; }
.u-mt-6 { margin-top: 6px !important; }
.u-mt-8 { margin-top: 8px !important; }
.u-mt-10 { margin-top: 10px !important; }
.u-mt-14 { margin-top: 14px !important; }
.u-ml-8 { margin-left: 8px !important; }
.u-fs-10 { font-size: 10px !important; }
.u-fs-11 { font-size: 11px !important; }
.u-fs-12 { font-size: 12px !important; }
.u-fs-13 { font-size: 13px !important; }
.u-fs-14 { font-size: 14px !important; }
.u-fs-18 { font-size: 18px !important; }
.u-fs-20 { font-size: 20px !important; }
.u-text-emerald { color: var(--accent-emerald) !important; }
.u-text-blue { color: var(--accent-blue) !important; }
.u-text-amber { color: var(--accent-amber) !important; }
.u-text-rose { color: var(--accent-rose) !important; }
.u-text-muted { color: var(--text-muted) !important; }
.u-nowrap { white-space: nowrap !important; }
.u-w-full { width: 100% !important; }
.u-w-70 { width: 70px !important; }
.u-h-full { height: 100% !important; }
.u-opacity-50 { opacity: 0.5 !important; }
.u-col-span-full { grid-column: 1 / -1 !important; }

/* ==============================================================================
   REFINED COMPONENT STYLES (CLEANED FROM INLINE STYLES)
   ============================================================================== */
.mobile-brand-title {
    font-size: 14px;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
    line-height: 1.2;
}

.mobile-brand-sub {
    font-size: 10px;
    color: var(--text-muted);
    margin: 0;
}

.status-badge-compact {
    font-size: 11px;
    padding: 3px 8px;
}

.pulse-dot-sm {
    width: 7px;
    height: 7px;
    display: inline-block;
    margin-right: 5px;
    background-color: var(--accent-emerald);
}

.pulse-dot-muted {
    width: 9px;
    height: 9px;
    background-color: var(--text-muted);
    box-shadow: none;
}

.badge-stale {
    background-color: rgba(245, 158, 11, 0.15) !important;
    border: 1px solid var(--accent-amber) !important;
    color: var(--accent-amber) !important;
}

.chart-scatter-box {
    height: 180px;
    margin-top: 8px;
}

.toolbar-label {
    font-size: 11px;
    color: var(--text-muted);
}

.select-compact {
    font-size: 12px;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    background: var(--bg-surface-elevated);
    color: var(--text-primary);
    border: 1px solid var(--border-subtle);
}

.csv-export-box {
    width: 100%;
    height: 100px;
    margin-top: 10px;
    font-family: var(--font-mono);
    font-size: 11px;
    background: var(--bg-terminal);
    color: var(--accent-blue-hover);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    padding: 8px;
}

.dss-metric-stack {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 8px;
}

.dss-big-val {
    font-size: 26px;
    font-weight: 700;
}

.dss-meta-sub {
    font-size: 11px;
    color: var(--text-muted);
}

.dss-formula-desc {
    font-size: 12px;
    color: var(--text-secondary);
    line-height: 1.6;
}

.scada-safety-copy {
    font-size: 13px;
    line-height: 1.7;
    color: var(--text-secondary);
}

.scada-safety-list {
    margin-left: 20px;
    margin-top: 6px;
}

.grid-auto-340 {
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr));
}

.ai-chat-thread-page {
    height: 380px;
}

.ctl-url-group {
    flex: 1;
    max-width: 380px;
}

.visual-empty-cam {
    width: 100%;
    height: 220px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    color: var(--text-muted);
    background: var(--bg-surface-sunken);
}

.visual-empty-health {
    width: 100%;
    height: 180px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    color: var(--text-muted);
    background: var(--bg-surface-sunken);
}

.empty-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
}

.empty-sub {
    font-size: 11px;
    text-align: center;
    max-width: 90%;
}

.cam-time-label {
    font-size: 11px;
    color: var(--text-primary);
}

.link-action {
    font-size: 12px;
    font-weight: 700;
    color: var(--accent-blue);
    text-decoration: none;
}

.modal-window-sm {
    max-width: 480px;
}

.modal-compare-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px;
}

.modal-img-col {
    text-align: center;
}

.modal-img-caption {
    font-size: 11px;
    color: var(--text-muted);
    display: block;
    margin-bottom: 4px;
}

.modal-preview-img {
    width: 100%;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-subtle);
    background: var(--bg-terminal);
}

.modal-title-text {
    font-size: 15px;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
}

.modal-actions-row {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 14px;
}

/* Legend items interactive button styles */
.legend-items button.legend-item {
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius-xs);
    padding: 3px 6px;
    cursor: pointer;
    font-family: inherit;
    transition: opacity var(--transition-fast), border-color var(--transition-fast);
}

.legend-items button.legend-item:hover {
    border-color: var(--border-hover);
}

.legend-items button.legend-item.is-muted {
    opacity: 0.35;
    text-decoration: line-through;
}

/* Card Loading / Empty / Error State Variants */
.metric-card.is-loading .metric-value {
    color: transparent !important;
    position: relative;
    overflow: hidden;
    background: linear-gradient(90deg, var(--bg-hover) 25%, var(--border-hover) 50%, var(--bg-hover) 75%);
    background-size: 200% 100%;
    animation: skeletonShimmer 1.5s infinite;
    border-radius: var(--radius-xs);
    width: 60px;
    height: 24px;
    display: inline-block;
}

.metric-card.is-empty .metric-value {
    color: var(--text-muted);
}

.metric-card.is-error {
    border-color: rgba(239, 68, 68, 0.45);
}

.metric-card.is-error .metric-badge {
    background-color: var(--accent-rose-glow);
    color: var(--accent-rose);
    border-color: rgba(239, 68, 68, 0.3);
}

@keyframes skeletonShimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}
