/* ── CHART WINDOW ───────────────────────────────────────────── */
.chart-window {
    position: absolute;
    min-width: 240px;
    min-height: 160px;
    background: var(--bg1);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: var(--shadow);
    transition: border-color var(--transition);
    will-change: transform;
}

.chart-window:hover { border-color: rgba(255,255,255,0.1); }
.chart-window.active {
    border-color: var(--border-accent);
    box-shadow: var(--shadow), var(--shadow-accent);
    z-index: 50 !important;
}

/* ── TITLEBAR ── only title + 3 window buttons ──────────────── */
.chart-titlebar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 28px;
    padding: 0 6px 0 10px;
    background: var(--bg2);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    cursor: grab;
    user-select: none;
}
.chart-titlebar:active { cursor: grabbing; }

.chart-title {
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 500;
    color: var(--text1);
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chart-titlebar-btns {
    display: flex; align-items: center; gap: 2px;
    flex-shrink: 0;
}

.titlebar-btn {
    width: 22px; height: 22px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 3px;
    color: var(--text2);
    font-size: 11px;
    line-height: 1;
    transition: all var(--transition);
}
.titlebar-btn:hover { background: var(--bg3); color: var(--text0); }
.titlebar-btn.close-btn-tb:hover { background: rgba(255,59,92,0.2); color: var(--red); }

/* ── CHART BODY ─────────────────────────────────────────────── */
.chart-body {
    flex: 1;
    display: flex;
    overflow: hidden;
    min-height: 0;
}

.chart-content {
    flex: 1;
    overflow: hidden;
    position: relative;
    min-width: 0;
}

.chart-legend {
    width: 130px;
    flex-shrink: 0;
    border-left: 1px solid var(--border);
    overflow-y: auto;
    padding: 4px 0;
    display: none;
}
.chart-legend.visible { display: block; }

/* ── FOOTER ─────────────────────────────────────────────────── */
.chart-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 28px;
    padding: 0 6px;
    background: var(--bg2);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
    gap: 4px;
}

.chart-footer-left,
.chart-footer-center,
.chart-footer-right {
    display: flex; align-items: center; gap: 3px;
}

.chart-footer-center { flex: 1; justify-content: center; }

.footer-btn {
    display: flex; align-items: center; gap: 4px;
    height: 20px;
    padding: 0 6px;
    border-radius: 3px;
    background: var(--bg3);
    border: 1px solid var(--border);
    color: var(--text2);
    font-family: var(--font-mono);
    font-size: 10px;
    transition: all var(--transition);
    white-space: nowrap;
}
.footer-btn:hover { color: var(--text0); border-color: rgba(255,255,255,0.15); }
.footer-btn.active { color: var(--accent); border-color: var(--border-accent); background: rgba(0,229,255,0.06); }

.zoom-btn { min-width: 24px; padding: 0 5px; justify-content: center; }

.footer-delta {
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--text1);
    padding: 0 6px;
}

/* ── LEGEND ITEMS ───────────────────────────────────────────── */
.legend-item {
    display: flex; align-items: center; gap: 6px;
    padding: 3px 8px;
    cursor: pointer;
    transition: background var(--transition);
    border-radius: 2px;
    margin: 1px 3px;
}
.legend-item:hover { background: var(--bg3); }
.legend-item.hidden { opacity: 0.35; }

.legend-color {
    width: 10px; height: 2px;
    border-radius: 1px;
    flex-shrink: 0;
}

.legend-name {
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--text1);
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.legend-value {
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--text0);
    white-space: nowrap;
}

/* ── RESIZE HANDLE ──────────────────────────────────────────── */
.chart-resize-handle {
    position: absolute;
    bottom: 0; right: 0;
    width: 16px; height: 16px;
    cursor: nwse-resize;
    z-index: 5;
}

.chart-resize-handle::after {
    content: '';
    position: absolute;
    bottom: 4px; right: 4px;
    width: 5px; height: 5px;
    border-right: 2px solid var(--text3);
    border-bottom: 2px solid var(--text3);
    transition: border-color var(--transition);
}
.chart-resize-handle:hover::after { border-color: var(--accent); }

/* ── UPLOT OVERRIDES ────────────────────────────────────────── */
.uplot { width: 100% !important; height: 100% !important; }
.uplot canvas { background: transparent !important; }
.u-wrap { width: 100% !important; height: 100% !important; }
.u-legend { display: none !important; }
.u-cursor-x, .u-cursor-y { border-color: rgba(0,229,255,0.3) !important; }

/* ── TREND TABLE ────────────────────────────────────────────── */
.trend-table-wrap {
    width: 100%; height: 100%;
    overflow: auto;
}

.trend-table {
    width: 100%;
    border-collapse: collapse;
    font-family: var(--font-mono);
    font-size: 11px;
}

.trend-table th {
    position: sticky; top: 0;
    background: var(--bg2);
    color: var(--text2);
    font-size: 9px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    padding: 5px 8px;
    text-align: right;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    z-index: 1;
}
.trend-table th:first-child { text-align: left; }

.trend-table td {
    padding: 4px 8px;
    text-align: right;
    border-bottom: 1px solid rgba(255,255,255,0.03);
    color: var(--text0);
    white-space: nowrap;
}
.trend-table td:first-child { text-align: left; color: var(--text1); }
.trend-table tr:hover td { background: var(--bg2); }
.trend-table .zero { color: var(--text3); }

.channel-color {
    display: inline-block;
    width: 6px; height: 6px;
    border-radius: 50%;
    margin-right: 5px;
    vertical-align: middle;
}

/* ── SETTINGS PANEL ─────────────────────────────────────────── */
.settings-panel {
    position: absolute;
    bottom: 28px; right: 0;
    width: 200px;
    background: var(--bg2);
    border: 1px solid var(--border-accent);
    border-radius: var(--radius) var(--radius) 0 0;
    box-shadow: var(--shadow);
    z-index: 200;
    animation: slideUp 150ms ease;
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

.settings-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 6px 10px;
    border-bottom: 1px solid var(--border);
    font-family: var(--font-mono);
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.1em;
    color: var(--text2);
}

.settings-close {
    width: 16px; height: 16px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 2px;
    color: var(--text2);
    font-size: 10px;
}
.settings-close:hover { background: var(--bg3); color: var(--red); }

.settings-body { padding: 8px; }

.settings-row {
    display: flex; align-items: center; justify-content: space-between;
    padding: 4px 0;
    border-bottom: 1px solid rgba(255,255,255,0.03);
}

.settings-label {
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--text2);
}

.settings-select, .settings-input {
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: 2px;
    color: var(--text0);
    font-family: var(--font-mono);
    font-size: 10px;
    padding: 2px 6px;
    height: 20px;
    outline: none;
    max-width: 100px;
}
.settings-select:focus, .settings-input:focus { border-color: var(--accent); }

/* ── NO DATA ────────────────────────────────────────────────── */
.chart-no-data {
    position: absolute; inset: 0;
    display: flex; align-items: center; justify-content: center;
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text3);
    pointer-events: none;
}