﻿/* =============================================================================
 * kvtable.css - theme-aware refactor
 *
 * Was: hardcoded dark palette in :root (generic names like --bg0 leaking
 * into global scope). Now: --kv-* namespaced tokens defined per theme
 * class (.dark-theme / .light-theme, matching themes.css and themes_v2.css),
 * consuming the v2 tokens with hardcoded fallbacks so the component still
 * renders standalone. Companion edits in kvtable.js replace inline hex
 * colors with var() references so live values retheme with the page.
 *
 * DATA-DRIVEN COLORS NOT COVERED HERE: config JSON supplies per-group
 * header colors (config.color) and per-band alarm colors (row.range) -
 * those are applied inline by JS from data and may need light-tuned
 * values in the configs themselves.
 *
 * CONFIGURABLE COLUMNS (NEW): when a config supplies a "columns" array,
 * JS renders a .kv-colhdr header row and .kv-cell data cells whose width
 * and alignment are applied inline from the config. The rules below only
 * provide typography and layout defaults; sizing comes from the data.
 * ========================================================================== */

:root {
    --kv-mono: 'Courier New', Courier, monospace;
    --kv-sans: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

.dark-theme {
    --kv-bg: var(--surface-page, #0d1117);
    --kv-hdr-bg: var(--surface-raised, #111927);
    --kv-zebra: rgba(148, 163, 184, .045);
    --kv-brd: var(--border-default, #1e2a3a);
    --kv-brd-strong: var(--border-strong, #2a3a4e);
    --kv-key: var(--text-secondary, #8b9ab5);
    --kv-val: var(--text-primary, #c8d4e8);
    --kv-muted: var(--text-faint, #3d4f6b);
    --kv-accent: var(--brand-2, #00d4d4);
    --kv-ok: #1ea870;
    --kv-bad: #ff3b3b;
    --kv-hover: var(--state-hover-bg, rgba(255, 255, 255, .05));
}

.light-theme {
    --kv-bg: var(--surface-card, #ffffff);
    --kv-hdr-bg: var(--surface-raised, #f7f9fc);
    --kv-zebra: rgba(20, 40, 75, .035);
    --kv-brd: var(--border-default, rgba(20, 40, 75, .10));
    --kv-brd-strong: var(--border-strong, rgba(20, 40, 75, .22));
    --kv-key: var(--text-secondary, #566782);
    --kv-val: var(--text-primary, #13213B);
    --kv-muted: var(--text-faint, #8694AC);
    --kv-accent: var(--brand2-ui, #0a8f8f);
    --kv-ok: #0e8a55; /* deepened for white surfaces */
    --kv-bad: #d63030;
    --kv-hover: var(--state-hover-bg, rgba(20, 40, 75, .05));
}

/* Column wrapper */
.kv-col {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid var(--kv-brd-strong);
    border-radius: var(--radius-control, 8px);
    margin: 5px;
    font-family: var(--kv-sans);
    background: var(--kv-bg);
    height:100%;
}

/* Column header (group title: dot + label + point count) */
.kv-hdr {
    flex-shrink: 0;
    padding: 4px 11px;
    background: var(--kv-hdr-bg);
    border-bottom: 1px solid var(--kv-brd);
    display: flex;
    align-items: center;
    gap: 7px;
}

.kv-hdr-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    flex-shrink: 0;
}

.kv-hdr-lbl {
    font-size: 9px;
    font-weight: 700;
    letter-spacing: .14em;
    text-transform: uppercase;
}

.kv-hdr-cnt {
    font-family: var(--kv-mono);
    font-size: 9px;
    color: var(--kv-muted);
    margin-left: auto;
}

/* Configurable column-title row (e.g. Name / Severity / Time).
   Only rendered when the config supplies a "columns" array. Widths and
   alignment are applied inline by JS so the titles line up with data cells. */
.kv-colhdr {
    flex-shrink: 0;
    display: flex;
    padding: 3px 9px;
    gap: 4px;
    background: var(--kv-hdr-bg);
    border-bottom: 1px solid var(--kv-brd-strong);
}

.kv-colhdr-cell {
    display: flex;
    align-items: center;
    font-family: var(--kv-sans);
    font-size: 8px;
    font-weight: 700;
    letter-spacing: .12em;
    text-transform: uppercase;
    color: var(--kv-key);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

/* Scrollable row area */
.kv-scroll {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    background: var(--kv-bg);
}

/* Individual row. Zebra = translucent tint over the SAME base, and
   hover REPLACES the tint entirely, so both parities hover to the
   same visible color (the alarm-tables compositing lesson). */
.kv-row {
    display: flex;
    padding: 3px 9px;
    gap: 4px;
    align-items: baseline;
    border-bottom: 1px solid var(--kv-brd);
    cursor: default;
    transition: background .1s;
}

    .kv-row:nth-child(even) {
        background: var(--kv-zebra);
    }

    .kv-row:nth-child(odd) {
        background: transparent;
    }

    .kv-row:hover {
        background: var(--kv-hover);
    }

/* Configurable data cell (wraps kv-key / kv-val / kv-time / kv-u).
   Width + alignment are applied inline by JS from the columns config. */
.kv-cell {
    display: flex;
    align-items: baseline;
    gap: 4px;
    overflow: hidden;
    min-width: 0;
}

    /* Inside a configurable cell the key fills its column and ellipsizes,
       instead of using the legacy fixed 60% basis. */
    .kv-cell .kv-key {
        flex: 1 1 auto;
        min-width: 0;
    }

    /* Cell alignment drives value placement, so drop the legacy auto-margin. */
    .kv-cell .kv-val {
        margin-left: 0;
    }

.kv-key {
    font-family: var(--kv-mono);
    font-size: 10px;
    color: var(--kv-key);
    flex: 0 0 60%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.kv-sep {
    display: none;
}

.kv-val {
    font-family: var(--kv-mono);
    font-size: 11px;
    font-weight: 700;
    color: var(--kv-val);
    text-align: right;
    white-space: nowrap;
    flex-shrink: 0;
    margin-left: auto;
}

/* Time column value */
.kv-time {
    font-family: var(--kv-mono);
    font-size: 10px;
    font-weight: 700;
    color: var(--kv-key);
    white-space: nowrap;
    flex-shrink: 0;
}

/* extra breathing room between the Value and Time columns
   (applies to both the data cell and its header cell) */
.kv-cell-time,
.kv-colhdr-time {
    margin-left: 10px;
}

.kv-u {
    font-family: var(--kv-mono);
    font-size: 9px;
    color: var(--kv-muted);
    flex-shrink: 0;
    min-width: 24px;
}

/* Scrollbar */
.kv-scroll::-webkit-scrollbar {
    width: 3px;
}

.kv-scroll::-webkit-scrollbar-track {
    background: transparent;
}

.kv-scroll::-webkit-scrollbar-thumb {
    background: var(--kv-brd-strong);
    border-radius: 2px;
}

    .kv-scroll::-webkit-scrollbar-thumb:hover {
        background: var(--kv-accent);
    }

/* Clickable row */
.kv-row-clickable {
    cursor: pointer;
}

    .kv-row-clickable:hover {
        background: var(--kv-hover) !important;
        border-left: 2px solid var(--kv-accent);
        padding-left: 7px;
    }

.kv-container {
    display: flex;
    gap: 12px;
    padding: 8px;
    border: 1px solid var(--kv-brd);
}

.kv-divider {
    padding-right: 12px;
}


/*kv card css*/

.kv-card {
    background: var(--kv-bg, #0b1220);
    border: 1px solid var(--kv-border, #1e293b);
    border-radius: 10px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 180px;
}

.kv-card-title {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.05em;
    color: var(--kv-muted, #94a3b8);
}

.kv-card-value-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.kv-card-icon {
    font-size: 18px;
    line-height: 1;
    display: inline-flex;
    align-items: center;
}

.kv-card-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--kv-val, #f1f5f9);
}

.kv-card-unit {
    font-size: 14px;
    color: var(--kv-muted, #94a3b8);
    align-self: flex-end;
    margin-bottom: 4px; /* aligns baseline with big number */
}