/* ==========================================================================
   tool.css
   Purpose:
   - Page layout (dashboard columns)
   - Tool-specific views: scope stage, HUD overlays, cursor readout
   - XY / Lissajous stage
   - KPI strip (compact layout) + metrics width fix
   - Footer + formula reference + signature
   - Responsive rules for THIS tool
   ========================================================================== */

html, body{
  overflow-x: hidden;
}

/* --- main layout grid --- */
.layoutDash{
  display:grid;
  grid-template-columns: 420px 1fr;
  gap:16px;
  padding:12px 12px;     /* slightly tighter */
  width: 100%;
  max-width: none;       /* <-- IMPORTANT: use full screen */
  margin: 0;             /* <-- no centering gutter */
  transition: grid-template-columns .22s ease, gap .22s ease, padding .22s ease;
}

.rightCol{
  display:flex;
  flex-direction:column;
  gap:14px;
  min-width: 0;
}

/* --- left control panel behavior --- */
.controlPanel{
  position: sticky;
  top: 76px;
  align-self: start;
  max-height: calc(100vh - 92px);
  overflow: auto;
  scrollbar-gutter: stable both-edges;

  /* focus transition */
  transition: opacity .18s ease, transform .22s ease;
}

.controlPanel::-webkit-scrollbar{ width: 10px; }
.controlPanel::-webkit-scrollbar-track{ background: rgba(0,0,0,.12); border-radius: 999px; }
.controlPanel::-webkit-scrollbar-thumb{
  background: rgba(151,166,178,.22);
  border-radius: 999px;
  border: 2px solid rgba(0,0,0,.18);
}
.controlPanel::-webkit-scrollbar-thumb:hover{ background: rgba(151,166,178,.30); }

/* ---------- Focus Mode (Scope + Dock) ---------- */

/* CSS vars (JS updates these in focus mode) */
:root{
  --topbarH: 110px;     /* fallback */
  --focusDockH: 190px;  /* fallback */
}

/* Collapse left column and remove gutter */
body.focusMode .layoutDash{
  grid-template-columns: 1fr;
  gap: 0;
  padding: 8px 10px 10px;
  padding-top: calc(var(--topbarH) + 8px);
}

/* Remove left panel from layout */
body.focusMode .controlPanel{
  display: none !important;
}

/* Instrument feel: no page scroll in focus mode */
body.focusMode{
  overflow: hidden;
}

body.focusMode .stageTop{
  /* Viewport minus header minus dock, plus a little safety for paddings/margins */
  height: calc(100vh - var(--topbarH) - var(--focusDockH) - 32px);
  min-height: 320px;
}

/* Dock is hidden normally */
.focusDock{ display:none; }

/* Dock visible in focus mode */
body.focusMode .focusDock{
  display:block;
  height: var(--focusDockH);
  overflow: auto;
  padding: 12px 14px;
  margin-top: 10px;
  border-radius: 16px;
}

/* Dock scrollbars */
body.focusMode .focusDock::-webkit-scrollbar{ width: 10px; }
body.focusMode .focusDock::-webkit-scrollbar-track{ background: rgba(0,0,0,.12); border-radius: 999px; }
body.focusMode .focusDock::-webkit-scrollbar-thumb{
  background: rgba(151,166,178,.22);
  border-radius: 999px;
  border: 2px solid rgba(0,0,0,.18);
}

/* Hide dashboard below in focus mode (dock replaces it) */
body.focusMode .dashBelow{ display:none; }

/* ---------- Focus Dock: FULL-WIDTH CONTROLS ---------- */

/* Dock spans full width */
body.focusMode #focusDock{
  width: 100%;
  max-width: none;
  margin: 0;
}

/* Rows become label | controls (instrument style) */
body.focusMode #focusDock .row{
  display: grid;
  grid-template-columns: 140px 1fr;
  align-items: center;
  column-gap: 16px;
  justify-content: initial !important;
}

/* Labels align consistently */
body.focusMode #focusDock .row > label{
  min-width: 0 !important;
  text-align: left;
}

/* Control block fills width */
body.focusMode #focusDock .ctl{
  width: 100%;
  flex: none !important;
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Sliders take the space */
body.focusMode #focusDock input[type="range"]{
  flex: 1 1 auto;
  width: 100%;
  min-width: 240px;
}

/* Numeric fields stay compact */
body.focusMode #focusDock input[type="number"],
body.focusMode #focusDock input[type="text"]{
  width: 96px;
}

/* Channel checkboxes fill the row */
body.focusMode #focusDock .checkRow{
  grid-template-columns: repeat(4, 1fr);
  gap: 6px 14px;
}

/* Slightly tighter sections */
body.focusMode #focusDock .panelSection{
  padding: 8px 8px;
}

/* ---------- Scope: View + Background selectors inline (requires .scopeSelRow HTML) ---------- */
.scopeSelRow{
  margin-top: 6px;
}
.scopeSelRow > label{ display:none !important; }

.scopeSelRow .ctl{
  width: 100%;
  display:flex;
  gap:12px;
  align-items:center;
}

.scopeSelRow select{
  min-width: 180px;
}

/* Dock spans full width */
body.focusMode #focusDock{
  width: 100%;
  max-width: none;
  margin: 10px 0 0 0;
}

/* Dock container */
body.focusMode .focusDock{
  height: var(--focusDockH);
  overflow: auto;
  padding: 12px 14px;
  border-radius: 16px;
}

/* Row layout: label | controls */
body.focusMode #focusDock .row{
  display: grid;
  grid-template-columns: 140px 1fr;
  align-items: center;
  column-gap: 16px;
  justify-content: initial !important; /* override old flex */
}

/* Labels */
body.focusMode #focusDock .row > label{
  min-width: 0 !important;
  text-align: left;
}

/* Controls fill available space */
body.focusMode #focusDock .ctl{
  width: 100%;
  flex: none !important;
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Sliders fill remaining space */
body.focusMode #focusDock input[type="range"]{
  flex: 1 1 auto;
  width: 100%;
  min-width: 240px;
}

/* Numeric fields stay compact */
body.focusMode #focusDock input[type="number"],
body.focusMode #focusDock input[type="text"]{
  width: 96px;
}

/* Channels use full width */
body.focusMode #focusDock .checkRow{
  grid-template-columns: repeat(4, 1fr) !important;
  gap: 6px 14px !important;
}

/* Slightly tighter sections */
body.focusMode #focusDock .panelSection{
  padding: 8px 8px;
}

/* ==========================================
   Scope: View + Background combined row (NO :has)
   Requires HTML wrapper: .scopeSelRow (we already discussed)
   ========================================== */

body.focusMode #focusDock .scopeSelRow{
  display:block;                 /* inside dock: treat as one full row */
}

.scopeSelRow{
  margin-top: 6px;
}

.scopeSelRow > label{
  display:none !important;
}

.scopeSelRow .ctl{
  width: 100%;
  display:flex;
  gap: 12px;
  align-items:center;
}

.scopeSelRow select{
  min-width: 180px;
}

/* Make selector compact */
#viewMode,
#bgMode{
  min-width:180px;
}

/* ==========================================================================
   XY / Lissajous
   ========================================================================== */
.xyRow{
  display:flex;
  gap:8px;
  align-items:center;
  flex-wrap:wrap;
  margin-bottom:10px;
}
.xyLbl{ color: var(--muted); font-weight: 950; font-size: 12px; }
.xySel{
  border-radius: 999px;
  border:1px solid rgba(151,166,178,.18);
  background: rgba(0,0,0,.16);
  color: var(--text);
  padding: 6px 10px;
  font-weight: 900;
  font-size: 12px;
  outline: none;
}

.xyStage{
  position:relative;
  height: 260px;
  border-radius: 16px;
  border: 1px solid rgba(151,166,178,.16);
  background: linear-gradient(180deg, rgba(14,20,28,.62), rgba(10,14,20,.62));
  overflow:hidden;
  box-shadow: var(--shadow2);
}
#xyPlot{ width:100%; height:100%; display:block; }

.xyHint{
  position:absolute;
  left:12px;
  bottom:56px;
  color: rgba(151,166,178,.78);
  font-size: 11px;
  font-weight: 900;
  background: rgba(0,0,0,.18);
  border: 1px solid rgba(151,166,178,.14);
  padding: 6px 10px;
  border-radius: 999px;
  pointer-events:none;
}

.xyPresets{
  position:absolute;
  left:10px;
  right:10px;
  bottom:10px;
  display:flex;
  gap:8px;
  justify-content:center;
  flex-wrap:wrap;
  padding: 8px 10px;
  border-radius: 999px;
  background: rgba(0,0,0,.22);
  border: 1px solid rgba(151,166,178,.14);
  box-shadow: 0 0 0 1px rgba(255,255,255,.02) inset;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.xyPresetBtn{
  border-radius: 999px;
  border:1px solid rgba(151,166,178,.18);
  background: rgba(0,0,0,.16);
  color: var(--text);
  padding: 6px 10px;
  font-weight: 950;
  font-size: 12px;
  cursor:pointer;
}
.xyPresetBtn:hover{ background: rgba(0,0,0,.26); }
.xyPresetBtn.active{
  background: rgba(77,227,255,.12);
  border-color: rgba(77,227,255,.30);
  box-shadow: 0 0 0 1px rgba(77,227,255,.08) inset;
}

/* ==========================================================================
   Scope
   ========================================================================== */
.stage{
  position:relative;
  background: linear-gradient(180deg, rgba(14,20,28,.62), rgba(10,14,20,.62));
  border:1px solid rgba(151,166,178,.16);
  border-radius:18px;
  overflow:hidden;
  box-shadow: var(--shadow);
}

.stageTop{
  height: min(52vh, 620px);
  background: transparent; /* video shows through */
  position: relative;
}

#scope{
  width:100%;
  height:100%;
  display:block;
  position:relative;
  z-index:2; /* above video */
}

/* HUD */
.scopeHud{
  position:absolute;
  inset: 14px 14px auto 14px;
  display:flex;
  align-items:flex-start;
  justify-content:space-between;
  pointer-events:none;
  z-index:10;
}
.hudLeft{ display:flex; gap:8px; flex-wrap:wrap; }
.hudRight{
  color: var(--muted);
  font-size:12px;
  display:flex;
  gap:10px;
  flex-wrap:wrap;
  justify-content:flex-end;
}

.chip{
  display:flex;
  align-items:center;
  gap:8px;
  border:1px solid rgba(151,166,178,.18);
  background: rgba(0,0,0,.18);
  padding:6px 10px;
  border-radius:999px;
  color: var(--muted);
  font-weight:900;
  box-shadow: 0 0 0 1px rgba(255,255,255,.02) inset;
}
.swatch{ width:12px; height:12px; border-radius:4px; display:inline-block; }
.swatch.v{ background: var(--e); box-shadow: 0 0 18px rgba(77,227,255,.20); }
.swatch.i{ background: var(--p); box-shadow: 0 0 18px rgba(255,210,77,.16); }
.swatch.vl{ background: var(--b); box-shadow: 0 0 18px rgba(178,123,255,.18); }
.swatch.vc{ background: rgba(120,255,160,0.90); box-shadow: 0 0 18px rgba(120,255,160,.16); }


/* Cursor readout */
.cursorReadout{
  position:absolute;
  left: 18px;
  bottom: 18px;
  min-width: 260px;
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid rgba(151,166,178,.18);
  background: rgba(0,0,0,.22);
  box-shadow: 0 0 0 1px rgba(255,255,255,.03) inset;
  pointer-events:none;
  z-index:10;
}
.crTitle{
  font-size: 11px;
  font-weight: 950;
  letter-spacing: .25px;
  color: rgba(151,166,178,.85);
  margin-bottom: 6px;
}
.crBody{
  font-size: 12px;
  font-weight: 900;
  color: var(--text);
  line-height:1.35;
  white-space: pre;
}

/* Video background behind scope */
.scopeBgVideo{
  position:absolute;
  inset:0;
  width:100%;
  height:100%;
  object-fit:cover;
  z-index:0;
  pointer-events:none;
  filter: brightness(0.72) contrast(1.1) blur(2.5px);
}
.scopeBgOverlay{
  position:absolute;
  inset:0;
  background: rgba(0,0,0,.28);
  z-index:1;
  pointer-events:none;
}

/* =========================
   Scope background modes
   ========================= */

/* Dark background mode: hide the video + overlay */
body.bgDark .scopeBgVideo{ display:none; }
body.bgDark .scopeBgOverlay{ display:none; }

/* Provide a clean "instrument dark" backdrop */
body.bgDark .stageTop{
  background:
    radial-gradient(1200px 600px at 70% 20%, rgba(77,227,255,.06), rgba(0,0,0,0) 55%),
    radial-gradient(900px 520px at 20% 75%, rgba(178,123,255,.06), rgba(0,0,0,0) 55%),
    linear-gradient(180deg, rgba(10,14,20,.90), rgba(6,8,12,.94));
}

/* ==========================================================================
   KPI Strip (compact) + metrics behavior
   ========================================================================== */
.kpiStrip{
  grid-column: 1 / -1;
  display:grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  align-items: stretch;
}

.kpiMini{
  background: linear-gradient(180deg, var(--glass2), var(--glass));
  border: 1px solid rgba(151,166,178,.16);
  border-radius: 18px;
  padding: 10px 12px;
  box-shadow: var(--shadow2);
  min-width: 0;
}

.kpiMiniTop{
  display:flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.kpiMiniTitle{
  display:flex;
  align-items:center;
  gap: 8px;
  font-weight: 950;
  letter-spacing: .25px;
  font-size: 12px;
  color: rgba(230,237,243,.92);
  white-space: nowrap;
}

.kpiDot{
  width: 10px;
  height: 10px;
  border-radius: 999px;
  display:inline-block;
  box-shadow: 0 0 18px rgba(0,0,0,.25);
}
.kpiDot.cemf{ background: rgba(178,123,255,.92); box-shadow: 0 0 16px rgba(178,123,255,.20); }
.kpiDot.pkvl{ background: rgba(77,227,255,.92); box-shadow: 0 0 16px rgba(77,227,255,.18); }

.kpiMiniValue{
  font-size: 22px;
  font-weight: 1000;
  letter-spacing: .2px;
  white-space: nowrap;
}

.kpiMiniSub{
  margin-top: 2px;
  color: rgba(151,166,178,.82);
  font-size: 11px;
  font-weight: 900;
  line-height: 1.25;
}

.kpiMiniBar{
  margin-top: 8px;
  height: 7px;
  border-radius: 999px;
  border: 1px solid rgba(30,42,58,.85);
  background: rgba(0,0,0,.18);
  overflow:hidden;
}

.kpiMiniFill{
  height: 100%;
  width: 0%;
  background: rgba(151,166,178,.25);
  box-shadow: 0 0 20px rgba(77,227,255,.22);
}

.kpiMiniMeta{
  margin-top: 8px;
  display:flex;
  flex-direction: column;
  gap: 6px;
}

.kpiMetaRow{
  display:flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: baseline;
}

.kpiMetaRow .k{
  color: rgba(151,166,178,.78);
  font-size: 11px;
  font-weight: 950;
}
.kpiMetaRow .v{
  color: rgba(230,237,243,.95);
  font-size: 11px;
  font-weight: 950;
}
.kpiMetaRow .sep{
  color: rgba(151,166,178,.55);
  font-weight: 900;
  margin: 0 2px;
}

.kpiMiniHint{
  color: rgba(151,166,178,.78);
  font-size: 11px;
  line-height: 1.25;
  border-top: 1px solid rgba(151,166,178,.10);
  padding-top: 6px;
}

/* hover-to-explain */
.kpiMiniHint{ display:none; }
.kpiMini:hover .kpiMiniHint{ display:block; }

/* IMPORTANT: metrics full width under KPI strip */
.dashBelow .metricsCard{ grid-column: 1 / -1; }

/* ==========================================================================
   Footer + Formula panel + Signature
   ========================================================================== */
.labFooter{
  margin-top: 40px;
  padding: 40px 20px;
  border-top: 1px solid rgba(151,166,178,.18);
  background: linear-gradient(180deg, rgba(10,14,20,.5), rgba(10,14,20,.85));
}

.labFooterInner{
  max-width: 1000px;
  margin: 0 auto;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
}

.labFooter h3{
  margin-bottom: 16px;
  color: var(--text);
  font-size: 18px;
}
.labFooter h4{
  margin-top: 22px;
  margin-bottom: 8px;
  color: var(--text);
  font-size: 15px;
}
.labFooter ul{
  padding-left: 18px;
  margin: 6px 0;
}

.labNote{
  margin-top: 18px;
  padding: 12px 16px;
  border-radius: 8px;
  background: rgba(178,123,255,.08);
  border: 1px solid rgba(178,123,255,.18);
}

/* Footer 2-column layout */
.footerGrid{
  display:grid;
  grid-template-columns: 1.25fr 0.95fr;
  gap: 18px;
  align-items:start;
}
.footerCol{ min-width: 0; }

.formulaPanel{
  border: 1px solid rgba(151,166,178,.16);
  border-radius: 18px;
  padding: 14px;
  background: linear-gradient(180deg, rgba(16,23,34,.72), rgba(12,18,26,.72));
  box-shadow: 0 10px 30px rgba(0,0,0,.25);
}

.formulaHead h3{ margin: 0 0 6px; }

.formulaSub{
  margin: 0 0 10px;
  color: rgba(151,166,178,.85);
  font-size: 12px;
  line-height: 1.4;
}

.formulaPanel details{
  border-top: 1px solid rgba(151,166,178,.12);
  padding-top: 10px;
  margin-top: 10px;
}
.formulaPanel details:first-of-type{
  border-top: none;
  padding-top: 0;
  margin-top: 0;
}

.formulaPanel summary{
  cursor: pointer;
  user-select: none;
  font-weight: 950;
  color: rgba(230,237,243,.92);
  letter-spacing: .15px;
  font-size: 13px;
  list-style: none;
}
.formulaPanel summary::-webkit-details-marker{ display:none; }
.formulaPanel summary::before{
  content: "▸";
  display: inline-block;
  margin-right: 8px;
  color: rgba(178,123,255,.85);
  transform: translateY(-1px);
}
.formulaPanel details[open] summary::before{ content: "▾"; }

.eqList{
  margin-top: 10px;
  display:flex;
  flex-direction:column;
  gap: 8px;
}

.eq{
  display:grid;
  grid-template-columns: 140px 1fr;
  gap: 10px;
  align-items: baseline;
  padding: 8px 10px;
  border-radius: 12px;
  background: rgba(0,0,0,.14);
  border: 1px solid rgba(151,166,178,.10);
}

.eqL{
  color: rgba(151,166,178,.85);
  font-size: 12px;
  font-weight: 950;
}

.eqR{
  color: rgba(230,237,243,.92);
  font-size: 12px;
  line-height: 1.35;
  overflow-wrap: anywhere;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-weight: 700;
  letter-spacing: .2px;
}

.formulaBoundary{
  margin-top:16px;
  padding:12px;
  border-radius:14px;
  background: rgba(178,123,255,.06);
  border:1px solid rgba(178,123,255,.18);
  font-size:12px;
  line-height:1.45;
}

.formulaFoot{
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid rgba(151,166,178,.12);
  color: rgba(151,166,178,.85);
  font-size: 12px;
  line-height: 1.35;
}

.toolSignature{
  margin-top: 40px;
  padding: 14px 20px;
  border-top: 1px solid rgba(151,166,178,.12);
  font-size: 12px;
  color: rgba(151,166,178,.75);
  text-align: center;
}
.toolSignatureInner{
  display:flex;
  flex-wrap:wrap;
  justify-content:center;
  gap:6px;
  letter-spacing:.2px;
}
.toolSignature a{
  color: rgba(178,123,255,.85);
  text-decoration:none;
}
.toolSignature a:hover{ text-decoration:underline; }
.toolSep{ opacity:.5; }

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 1100px){
  .layoutDash{ grid-template-columns: 1fr; }

  .controlPanel{
    position: relative;
    top: 0;
    max-height: none;
    overflow: visible;
  }

  .stageTop{
    height: min(48vh, 560px);
  }
}

@media (max-width: 700px){
  .stageTop{
    height: min(44vh, 460px);
  }
}

@media (max-width: 820px){
  .kpiStrip{ grid-template-columns: 1fr; }
  .kpiMiniValue{ font-size: 20px; }

  .dashTitleRow{
    flex-wrap: wrap;
    align-items: flex-start;
  }
}

@media (max-width: 1250px){
  .dashCard{ grid-column: span 12; }
  .metricsCard{ grid-column: 1 / -1; }
}

@media (max-width: 980px){
  .footerGrid{ grid-template-columns: 1fr; }
  .eq{ grid-template-columns: 1fr; }
}

/* --- Fundamental phasor plot (PQ tab / XY tab) --- */
#phasorPlot{ width:100%; height:100%; display:block; }

/* =========================
   Performance HUD (blue dot)
   ========================= */
.perfPanel{
  position: fixed;
  top: 74px;
  left: 14px;
  width: 270px;
  z-index: 9999;

  border-radius: 16px;
  border: 1px solid rgba(151,166,178,.16);
  background: linear-gradient(180deg, rgba(16,23,34,.92), rgba(12,18,26,.88));
  box-shadow: 0 18px 55px rgba(0,0,0,.35);
  padding: 10px 12px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.perfHead{ margin-bottom: 8px; }
.perfTitle{
  font-weight: 950;
  letter-spacing: .2px;
  font-size: 12px;
  color: rgba(230,237,243,.95);
}
.perfSub{
  margin-top: 2px;
  font-weight: 800;
  font-size: 11px;
  color: rgba(151,166,178,.85);
}

.perfGrid{
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px 10px;
  align-items: center;
  font-size: 12px;
}
.perfK{
  font-weight: 900;
  color: rgba(151,166,178,.85);
}
.perfV{
  font-weight: 950;
  color: rgba(230,237,243,.95);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.perfHint{
  margin-top: 10px;
  font-size: 11px;
  font-weight: 800;
  color: rgba(151,166,178,.80);
  line-height: 1.25;
}