/* =========================================================================
 * NWF Interactive — Dashboard layout + components
 * -------------------------------------------------------------------------
 * Built on the OneGrid design tokens: bg_two rounded shells, context_color
 * accents, Proxima Nova, 8-px pill scrollbars, tooltip-pill chrome.
 * =======================================================================*/

*, *::before, *::after { box-sizing: border-box; }

html, body { margin: 0; padding: 0; min-height: 100%; }

body {
    background: var(--bg-one);
    color: var(--text-foreground);
    font-family: var(--font-family);
    font-size: 14px;
    font-weight: 400;
    line-height: 1.45;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

[hidden] { display: none !important; }

.nwf-app {
    min-height: 100vh;
    display: grid;
    grid-template-rows: auto 1fr auto;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    max-width: 1680px;
    margin: 0 auto;
}

/* ---------- Shared shell --------------------------------------------------- */
.nwf-shell {
    background: var(--bg-two);
    border-radius: var(--radius-shell);
    box-shadow: var(--shadow-card);
}

/* ---------- Header --------------------------------------------------------- */
.nwf-header__shell {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
    padding: var(--space-2) var(--space-5);
    min-height: var(--header-height);
}

.nwf-brand { display: flex; align-items: center; gap: var(--space-3); }

.nwf-brand__titles { display: flex; flex-direction: column; gap: 0; }
.nwf-brand__title {
    font-size: 17px;
    font-weight: 700;
    color: var(--text-title);
    line-height: 1.1;
}
.nwf-brand__accent { color: var(--context-color); }
.nwf-brand__sub {
    font-size: 14px;
    font-weight: 400;
    color: var(--text-description);
    line-height: var(--eyebrow-line-height);
}

.nwf-header__meta { display: flex; align-items: center; gap: var(--space-3); }

.nwf-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 30px;
    padding: 0 12px;
    border-radius: var(--radius-pill);
    background: var(--dark-one);
    color: var(--text-active);
    font-size: 12px;
    font-weight: 700;
    border-right: 3px solid var(--context-color);
    white-space: nowrap;
}
.nwf-badge__dot {
    width: 8px; height: 8px; border-radius: 50%;
    background: var(--green);
    box-shadow: 0 0 6px var(--green);
}
.nwf-badge--muted { color: var(--text-foreground); border-right-color: var(--bg-three); }
.nwf-badge--muted .nwf-badge__dot { background: var(--text-description); box-shadow: none; }

.nwf-iconbtn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 32px;
    min-width: 32px;
    padding: 0 12px;
    border: none;
    border-radius: var(--radius-shell);
    background: var(--dark-one);
    color: var(--text-active);
    font-family: var(--font-family);
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    transition: background 120ms ease, box-shadow 120ms ease;
}
.nwf-iconbtn:hover { background: var(--dark-four); }
.nwf-iconbtn:active { background: var(--context-color); color: var(--white); }
.nwf-iconbtn:focus-visible { outline: none; box-shadow: var(--shadow-focus); }

/* ---------- Main grid: controls | plot ------------------------------------- */
.nwf-main {
    display: grid;
    grid-template-columns: 288px 1fr;
    grid-template-rows: auto auto;
    grid-template-areas:
        "controls plot"
        "controls stats";
    gap: var(--space-3);
    min-height: 0;
}
.nwf-controls { grid-area: controls; }
.nwf-plotwrap { grid-area: plot; }
.nwf-stats    { grid-area: stats; }

/* ---------- Controls panel ------------------------------------------------- */
.nwf-controls {
    padding: var(--space-3);
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    max-height: calc(100vh - 160px);
    min-height: 0;
    overflow: hidden;
}
.nwf-controls__head {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.nwf-controls__title {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-title);
    letter-spacing: 0.02em;
}
.nwf-controls__actions { display: flex; gap: 6px; }
.nwf-chip {
    border: none;
    border-radius: var(--radius-pill);
    background: var(--bg-three);
    color: var(--text-active);
    font-family: var(--font-family);
    font-size: 11px;
    font-weight: 600;
    padding: 4px 10px;
    cursor: pointer;
    transition: background 120ms ease;
}
.nwf-chip:hover { background: var(--row-hover); }
.nwf-chip:active { background: var(--context-color); color: var(--white); }

.nwf-groups {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    overflow-y: auto;
    padding-right: 2px;
}

.nwf-group { flex: 0 0 auto; border-radius: var(--radius-shell); background: var(--bg-three); overflow: hidden; }
.nwf-group__head {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 10px;
    cursor: pointer;
    user-select: none;
}
.nwf-group__caret {
    width: 0; height: 0;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 6px solid var(--text-foreground);
    transition: transform 150ms ease;
}
.nwf-group[data-collapsed="true"] .nwf-group__caret { transform: rotate(-90deg); }
.nwf-group__name { font-size: 12.5px; font-weight: 700; color: var(--text-title); flex: 1; }
.nwf-group__count {
    font-size: 11px; font-weight: 600; color: var(--text-description);
    background: var(--dark-two); border-radius: var(--radius-pill); padding: 1px 8px;
}
.nwf-group__eye {
    border: none; background: transparent; cursor: pointer; padding: 2px 4px;
    color: var(--text-foreground); font-size: 11px; font-weight: 700;
}
.nwf-group__eye:hover { color: var(--context-color); }

.nwf-group__body {
    display: flex; flex-direction: column;
    max-height: 240px; overflow-y: auto;
    padding: 2px 4px 6px;
}
.nwf-group[data-collapsed="true"] .nwf-group__body { display: none; }

.nwf-member {
    display: flex; align-items: center; gap: 8px;
    padding: 3px 6px; border-radius: 6px;
    cursor: pointer; transition: background 100ms ease;
}
.nwf-member:hover { background: var(--row-hover); }
.nwf-member[data-off="true"] { opacity: 0.5; }
.nwf-member[data-off="true"] .nwf-swatch { filter: grayscale(0.85); opacity: 0.55; }
.nwf-member[data-off="true"] .nwf-member__label,
.nwf-member[data-off="true"] .nwf-member__val { color: var(--text-description); }
.nwf-swatch { width: 11px; height: 11px; border-radius: 50%; flex: 0 0 auto; box-shadow: 0 0 0 1px rgba(0,0,0,0.25); }
.nwf-member__label { flex: 1; font-size: 12px; color: var(--text-active); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nwf-member__val { font-size: 12px; font-weight: 700; color: var(--text-title); font-variant-numeric: tabular-nums; min-width: 42px; text-align: right; }

/* ---------- Plot ----------------------------------------------------------- */
.nwf-plotwrap { padding: var(--space-3); display: flex; flex-direction: column; min-width: 0; }
.nwf-plot-head {
    display: flex; align-items: baseline; justify-content: space-between;
    margin-bottom: var(--space-2); gap: var(--space-3);
}
.nwf-plot-title { font-size: 14px; font-weight: 700; color: var(--text-title); }
.nwf-plot-hint { font-size: 11px; color: var(--text-description); }
.nwf-plot { position: relative; width: 100%; min-height: 420px; }

/* uPlot dark-theme chrome (canvas colors are set in plot.js) */
.uplot, .u-wrap { width: 100% !important; }
.u-title { color: var(--text-title); font-family: var(--font-family); }
.nwf-plot .u-legend { display: none; } /* custom tooltip + panel replace the legend */
.u-cursor-x, .u-cursor-y { border-color: var(--text-description) !important; }
.u-select { background: rgba(86, 138, 242, 0.14) !important; }

/* ---------- Custom hover tooltip (OneGrid tooltip-pill chrome) -------------- */
.nwf-tip {
    position: absolute;
    z-index: 40;
    pointer-events: none;
    min-width: 150px;
    max-width: 260px;
    background: var(--dark-one);
    color: var(--text-active);
    border-radius: 12px;
    border-right: 3px solid var(--context-color);
    box-shadow: 0 10px 26px rgba(0, 0, 0, 0.5);
    padding: 8px 10px;
    font-size: 12px;
    display: none;
}
.nwf-tip__time {
    font-size: 11.5px; font-weight: 700; color: var(--text-title);
    margin-bottom: 6px; white-space: nowrap;
    border-bottom: 1px solid var(--bg-three); padding-bottom: 5px;
}
.nwf-tip__rows { display: flex; flex-direction: column; gap: 2px; max-height: 320px; overflow: hidden; }
.nwf-tip__row { display: flex; align-items: center; gap: 7px; }
.nwf-tip__row--auto .nwf-tip__label { color: var(--white); font-weight: 800; }
.nwf-tip__sw { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto; }
.nwf-tip__label { flex: 1; color: var(--text-foreground); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nwf-tip__val { font-weight: 700; color: var(--text-title); font-variant-numeric: tabular-nums; }
.nwf-tip__more { color: var(--text-description); font-size: 11px; margin-top: 4px; }
.nwf-tip__pin {
    font-size: 9px; font-weight: 800; color: var(--white);
    background: var(--context-color); border-radius: 6px; padding: 1px 5px; margin-left: 6px;
    vertical-align: middle;
}

/* ---------- Frozen-cursor marker (#5) -------------------------------------- */
.nwf-freeze-line {
    position: absolute; top: 0; bottom: 0; width: 0;
    border-left: 1px dashed var(--context-color);
    pointer-events: none; display: none; z-index: 30;
}
.nwf-plot.is-frozen .u-cursor-x,
.nwf-plot.is-frozen .u-cursor-y { display: none !important; }
/* Default per-series cursor dots stay in the DOM (so uPlot's hide-series path
 * doesn't crash) but are hidden -- the custom tooltip is the readout. */
.nwf-plot .u-cursor-pt { display: none !important; }

/* ---------- Stats table ---------------------------------------------------- */
.nwf-stats { padding: var(--space-3); display: flex; flex-direction: column; min-width: 0; }
.nwf-stats__head {
    display: flex; align-items: baseline; justify-content: space-between;
    margin-bottom: var(--space-2);
}
.nwf-stats__title { font-size: 13px; font-weight: 700; color: var(--text-title); }
.nwf-stats__hint { font-size: 11px; color: var(--text-description); }
.nwf-table-wrap { max-height: 300px; overflow: auto; border-radius: var(--radius-shell); }
.nwf-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.nwf-table thead th {
    position: sticky; top: 0; z-index: 1;
    background: var(--dark-two);
    color: var(--text-title);
    font-weight: 700;
    text-align: center;
    padding: 0 12px;
    height: 30px;
    white-space: nowrap;
}
.nwf-table thead th:first-child { text-align: left; border-top-left-radius: var(--radius-shell); }
.nwf-table thead th:last-child { border-top-right-radius: var(--radius-shell); }
.nwf-table thead th[data-sortable] { cursor: pointer; user-select: none; }
.nwf-table thead th[data-sortable]:hover { color: var(--context-color); }
.nwf-table thead th[data-sort]::after { font-size: 9px; margin-left: 4px; color: var(--context-color); }
.nwf-table thead th[data-sort="asc"]::after { content: "▲"; }
.nwf-table thead th[data-sort="desc"]::after { content: "▼"; }
.nwf-table tbody td {
    padding: 0 12px; height: 28px; text-align: center;
    color: var(--text-active); font-variant-numeric: tabular-nums;
    border-bottom: 1px solid var(--table-outline);
}
.nwf-table tbody td:first-child { text-align: left; }
.nwf-table tbody tr:nth-child(even) { background: rgba(255,255,255,0.02); }
.nwf-table tbody tr:hover { background: var(--row-hover); }
.nwf-table tbody tr[data-off="true"] { opacity: 0.4; }
.nwf-cell-name { display: flex; align-items: center; gap: 8px; }
.nwf-cell-name .nwf-swatch { width: 10px; height: 10px; }

/* ---------- Footer --------------------------------------------------------- */
.nwf-footer__shell {
    display: flex; align-items: center; justify-content: space-between;
    min-height: var(--footer-height);
    padding: var(--space-2) var(--space-5);
    color: var(--text-description); font-size: 12px;
}
.nwf-footer__status { display: flex; align-items: center; gap: 4px; }

/* ---------- Toast (quiet refresh notice) ----------------------------------- */
.nwf-toast {
    position: fixed; right: 18px; bottom: 18px; z-index: 60;
    background: var(--dark-one); color: var(--text-active);
    border-radius: 17px; border-right: 3px solid var(--green);
    padding: 0 14px; min-height: 34px;
    display: flex; align-items: center; gap: 8px;
    font-size: 12px; font-weight: 700;
    box-shadow: 0 10px 26px rgba(0,0,0,0.5);
    opacity: 0; transform: translateY(8px);
    transition: opacity 220ms ease, transform 220ms ease;
}
.nwf-toast.is-visible { opacity: 1; transform: translateY(0); }

.nwf-loading {
    display: flex; align-items: center; justify-content: center;
    min-height: 420px; color: var(--text-description); font-size: 13px;
}

/* ---------- Responsive ----------------------------------------------------- */
@media (max-width: 1080px) {
    .nwf-main {
        grid-template-columns: 1fr;
        grid-template-areas: "controls" "plot" "stats";
    }
    .nwf-controls { max-height: none; }
    .nwf-groups { max-height: 320px; }
}
@media (max-width: 720px) {
    .nwf-header__shell { flex-direction: column; align-items: flex-start; gap: var(--space-2); }
    .nwf-header__meta { flex-wrap: wrap; }
}
