/* ============================================================
   COMPONENTS — Cards, Grids, Tables, Toasts (Foodly Design)
   ============================================================ */

/* ── Metric Cards Grid ── */
.metrics-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 8px;
    margin-bottom: 10px;
}

/* ── Metric Card (Foodly stat-card style) ── */
.metric-card {
    position: relative;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-xl);
    padding: 12px 14px;
    transition: all 0.2s ease;
    overflow: hidden;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
}

/* Top color accent bar */
.metric-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
}

.metric-card:hover {
    background: rgba(255, 255, 255, 0.05);
    box-shadow: 0 0 15px rgba(var(--brand-rgb), 0.15);
    transform: translateY(-2px);
}

/* Sensor top-bar colors */
.metric-card.temp::before {
    background: var(--color-temp);
}

.metric-card.ph::before {
    background: var(--color-ph);
}

.metric-card.tds::before {
    background: var(--color-tds);
}

.metric-card.co2::before {
    background: var(--color-co2);
}

.metric-card.humidity::before {
    background: var(--color-humidity);
}

.metric-card.ambient::before {
    background: var(--color-ambient);
}

/* Per-sensor hover glow */
.metric-card.temp:hover {
    box-shadow: 0 4px 16px rgba(255, 107, 53, 0.12);
}

.metric-card.ph:hover {
    box-shadow: 0 4px 16px rgba(var(--brand-rgb), 0.12);
}

.metric-card.tds:hover {
    box-shadow: 0 4px 16px rgba(251, 191, 36, 0.12);
}

.metric-card.co2:hover {
    box-shadow: 0 4px 16px rgba(56, 189, 248, 0.12);
}

.metric-card.humidity:hover {
    box-shadow: 0 4px 16px rgba(167, 139, 250, 0.12);
}

.metric-card.ambient:hover {
    box-shadow: 0 4px 16px rgba(251, 113, 133, 0.12);
}

.metric-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}

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

.metric-card-icon {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    background: var(--brand-tint-06);
    display: flex;
    align-items: center;
    justify-content: center;
}

.metric-card-icon .material-icons {
    font-size: 18px;
    color: var(--brand-primary);
}

.metric-card-value {
    font-family: 'JetBrains Mono', monospace;
    font-size: 28px;
    font-weight: 800;
    color: var(--text-primary);
    line-height: 1;
    margin-bottom: 2px;
}

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

.metric-card-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 6px;
    padding-top: 5px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.metric-card-range {
    font-size: 10px;
    color: var(--text-muted);
    font-weight: 500;
}

.metric-card-trend {
    font-size: 10px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 2px;
    white-space: nowrap;
}

.metric-card-trend.up {
    color: var(--success);
}

.metric-card-trend.down {
    color: var(--danger);
}

.metric-card-trend.stable {
    color: var(--text-muted);
}

/* ── Chart Cards (Glass) ── */
.chart-card {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-xl);
    padding: 20px;
    transition: all 0.2s ease;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
}

.chart-card:hover {
    background: rgba(255, 255, 255, 0.05);
    box-shadow: 0 0 15px rgba(var(--brand-rgb), 0.15);
}

.chart-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.chart-card-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.3px;
}

.chart-card-subtitle {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}

/* Charts grid — two side by side */
.charts-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

/* Chart canvas — FIXED HEIGHT (prevents infinite scroll) */
.chart-card canvas {
    width: 100% !important;
    max-height: 260px;
}

/* ── Combined Live Header + Process Bar ── */
.live-header-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 12px 20px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-xl);
    margin-bottom: 12px;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
}

.live-header-left {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-shrink: 0;
}

.live-header-process {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    justify-content: flex-end;
}

.live-header-process .process-bar-item {
    text-align: center;
    padding: 0 10px;
    border-left: 1px solid rgba(255, 255, 255, 0.06);
}

.process-bar-item {
    text-align: center;
}

.process-bar-label {
    font-size: 10px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 4px;
}

.process-bar-value {
    font-family: 'JetBrains Mono', monospace;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}

/* ── Data Tables (Foodly dark glass) ── */
.data-table-wrapper {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-xl);
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-x pan-y;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
}

.data-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
}

.data-table th {
    background: var(--brand-tint-04);
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-subtle);
    text-align: left;
}

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

.data-table tr:hover td {
    background: var(--brand-tint-04);
}

/* Zebra stripe */
.data-table tbody tr:nth-child(even) td {
    background: rgba(255, 255, 255, 0.015);
}

.data-table tbody tr:nth-child(even):hover td {
    background: var(--brand-tint-04);
}

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

/* ── Table actions ── */
.table-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    border-bottom: 1px solid var(--border-subtle);
    gap: 10px;
    flex-wrap: wrap;
}

.table-toolbar-left {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    min-width: 0;
}

.table-toolbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

/* ── Search Box (Foodly) ── */
.search-box {
    position: relative;
    display: flex;
    align-items: center;
    max-width: 320px;
    width: 100%;
}

.search-box .search-icon {
    position: absolute;
    left: 14px;
    color: var(--text-muted) !important;
    font-size: 20px;
    z-index: 1;
    pointer-events: none;
}

.search-box input {
    width: 100%;
    padding: 10px 16px 10px 44px;
    border-radius: var(--radius-xl);
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
    font-size: 13px;
    font-family: var(--font-family);
    transition: all 0.2s ease;
    min-height: 40px;
}

.search-box input::placeholder {
    color: var(--slate-500);
}

.search-box input:focus {
    outline: none;
    border-color: var(--brand-primary);
    box-shadow: 0 0 0 1px var(--brand-primary);
    background: rgba(255, 255, 255, 0.1);
}

.table-search {
    max-width: 320px;
    border-radius: var(--radius-xl);
}

.table-pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 20px;
    border-top: 1px solid var(--border-subtle);
}

.table-page-info {
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 500;
}

/* ── Page Header (Foodly) ── */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 14px;
    padding: 10px 16px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-lg);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.page-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 18px;
    font-weight: 800;
    color: var(--text-primary);
    letter-spacing: -0.03em;
    line-height: 1.2;
    margin: 0;
    white-space: nowrap;
}

.page-title .material-icons {
    font-size: 22px;
}

/* ── Compare Selector ── */
.compare-selector {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    padding: 16px 20px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-xl);
    margin-bottom: 14px;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
}

.compare-slot {
    flex: 1;
    min-width: 0;
}

.compare-slot-label {
    font-size: 10px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 6px;
    display: block;
}

.compare-vs {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding-bottom: 10px;
    flex-shrink: 0;
}

/* ── Toast / Alert ── */
.toast-container {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: 380px;
    pointer-events: none;
}

.toast {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 14px 20px;
    border-radius: var(--radius-lg);
    background: rgba(15, 23, 42, 0.95);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: var(--shadow-lg);
    animation: slideInRight 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
    min-width: 280px;
    backdrop-filter: blur(12px);
    pointer-events: auto;
}

.toast-success {
    border-left: 4px solid var(--success);
}

.toast-warning {
    border-left: 4px solid var(--warning);
}

.toast-danger {
    border-left: 4px solid var(--danger);
}

.toast-info {
    border-left: 4px solid var(--info);
}

.toast-icon {
    font-size: 20px;
    flex-shrink: 0;
    margin-top: 1px;
}

.toast-body {
    flex: 1;
}

.toast-title {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 2px;
}

.toast-message {
    font-size: 12px;
    color: var(--text-secondary);
}

.toast-close {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 18px;
    padding: 0;
    line-height: 1;
    transition: color 0.2s;
}

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

/* ── Modal ── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(2, 6, 23, 0.8);
    backdrop-filter: blur(8px);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s ease;
}

.modal {
    background: var(--slate-900);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-xl);
    padding: 24px;
    max-width: 500px;
    width: 90%;
    animation: fadeInScale 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    box-shadow: var(--shadow-lg);
}

/* ============================================================
   RESPONSIVE
   ============================================================ */

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

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

    .metric-card-value {
        font-size: 22px;
    }

    /* Hide page-header on mobile — title already in mobile header */
    .page-header {
        display: none !important;
    }

    /* Live view: hide only title, keep process metrics */
    .live-header-bar {
        padding: 10px 12px;
        gap: 0;
    }

    .live-header-left {
        display: none;
    }

    .live-header-process {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 6px;
        width: 100%;
    }

    .live-header-process .process-bar-item {
        border-left: none;
        padding: 0;
    }

    .toast-container {
        right: 12px;
        left: 12px;
        max-width: none;
    }

    .compare-selector {
        flex-direction: column;
        align-items: stretch;
    }

    .compare-vs {
        flex-direction: row;
        justify-content: center;
        padding-bottom: 0;
    }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .data-table-wrapper {
        overflow-x: auto;
    }

    .table-toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .table-toolbar-left {
        width: 100%;
    }

    .table-toolbar-right {
        width: 100%;
        justify-content: flex-end;
    }

    .search-box {
        max-width: 100%;
    }
}

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

    .data-table th,
    .data-table td {
        padding: 10px 8px;
        font-size: 11px;
    }
}

/* ============================================================
   REPORTS MODULE — Layout & Controls
   ============================================================ */

.rpt-kpi-grid {
    grid-template-columns: repeat(4, 1fr);
    margin: 14px 0px;
}

.rpt-secondary-grid {
    grid-template-columns: repeat(3, 1fr);
    margin: 14px 0px;
}

.rpt-chart-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
    flex-wrap: wrap;
    gap: 8px;
}

.rpt-chart-controls-left {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-secondary);
}

.rpt-chart-controls-right {
    display: flex;
    align-items: center;
    gap: 6px;
}

.rpt-select {
    font-size: 12px;
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
    font-family: inherit;
}

.rpt-select:focus {
    outline: none;
    border-color: var(--brand-primary);
    box-shadow: 0 0 0 2px rgba(var(--brand-rgb), 0.15);
}

.rpt-select-full {
    flex: 1;
    min-width: 0;
}

.rpt-chart-wrap {
    position: relative;
    height: 260px;
    width: 100%;
}

.rpt-export-card {
    margin-bottom: 14px;
}

.rpt-export-actions {
    display: flex;
    gap: 10px;
    align-items: center;
    padding: 0 20px 20px;
}

@media (max-width: 768px) {
    .rpt-kpi-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .rpt-secondary-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .rpt-export-actions {
        flex-direction: column;
        padding: 0 14px 14px;
    }

    .rpt-select-full {
        width: 100%;
    }

    .rpt-export-actions .btn-neon {
        width: 100%;
        justify-content: center;
    }

    .rpt-chart-wrap {
        height: 220px;
    }
}

@media (max-width: 480px) {

    .rpt-kpi-grid,
    .rpt-secondary-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .rpt-chart-wrap {
        height: 180px;
    }
}