:root {
  --bg: #0e1116;
  --panel: #151a21;
  --panel-2: #1b222b;
  --line: #262f3a;
  --text: #dbe3ec;
  --dim: #8793a1;
  --accent: #4cc2ff;
  --accent-ink: #06202e;
  --danger: #ff6b6b;
  --radius: 7px;
  font-size: 13px;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  overflow: hidden; user-select: none;
}
[hidden] { display: none !important; }
#app {
  display: grid; height: 100vh;
  grid-template-columns: 176px minmax(0, 1fr) 304px;
  grid-template-rows: 48px minmax(0, 1fr) auto 26px;
  grid-template-areas: "top top top" "tools stage side" "tools dock side" "status status status";
}

/* top bar */
#topbar {
  grid-area: top; overflow: hidden; display: flex; align-items: center; gap: 14px; padding: 0 12px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 14px; letter-spacing: .2px; margin-right: 6px; white-space: nowrap; flex: none; }
.logo { width: 22px; height: 22px; fill: none; stroke: var(--accent); stroke-width: 2; stroke-linecap: round; }
.group { display: flex; align-items: center; gap: 6px; }
.spacer { flex: 1; min-width: 0; }
.btn, .select, .seg button, .chips button {
  font: inherit; color: var(--text); background: var(--panel-2); border: 1px solid var(--line);
  border-radius: var(--radius); height: 30px; padding: 0 11px; cursor: pointer; white-space: nowrap; flex: none;
  transition: background .12s, border-color .12s;
}
.btn:hover, .select:hover, .seg button:hover, .chips button:hover { border-color: #3a4757; background: #212a35; }
.btn:active, .seg button:active, .chips button:active { background: #18202a; }
.btn:disabled { opacity: .4; cursor: default; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn.primary:hover { background: #6fd0ff; }
.btn.icon { width: 30px; padding: 0; display: grid; place-items: center; }
.btn.icon svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.btn.small { height: 24px; padding: 0 9px; font-size: 12px; }
.btn.play { display: flex; align-items: center; gap: 6px; min-width: 82px; justify-content: center; }
.btn.play svg { width: 12px; height: 12px; fill: currentColor; }
.btn.play #icoPlay { display: none; }
.btn.play.paused { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn.play.paused #icoPlay { display: block; }
.btn.play.paused #icoPause { display: none; }
.select { padding: 0 8px; max-width: 150px; }
.seg { display: flex; }
.seg button { border-radius: 0; margin-left: -1px; padding: 0 10px; }
.seg button:first-child { border-radius: var(--radius) 0 0 var(--radius); margin-left: 0; }
.seg button:last-child { border-radius: 0 var(--radius) var(--radius) 0; }
.seg button.on, .chips button.on { background: #24384a; border-color: var(--accent); color: #fff; position: relative; z-index: 1; }
.clock { display: flex; align-items: baseline; gap: 6px; font-variant-numeric: tabular-nums; min-width: 86px; padding-left: 6px; font-size: 14px; }
.dim { color: var(--dim); font-size: 12px; }
button:focus-visible, select:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
@media (max-width: 1320px) {
  .brand span { display: none; }
  #topbar { gap: 8px; padding: 0 8px; }
  .select { max-width: 104px; }
  .clock { min-width: 74px; }
}
@media (max-width: 1160px) {
  #btnOpen, #btnSave { display: none; }
  .seg button, .btn { padding: 0 7px; }
  #topbar { gap: 6px; }
  .select { max-width: 86px; }
  .clock { min-width: 0; }
}

/* tool strip: two columns so every tool is always in view */
#tools {
  grid-area: tools; background: var(--panel); border-right: 1px solid var(--line);
  display: grid; grid-template-columns: 1fr 1fr; align-content: start; gap: 3px; padding: 7px 6px; overflow-y: auto;
  scrollbar-width: thin; scrollbar-color: #2c3642 transparent;
}
#tools button {
  height: 44px; border: 1px solid transparent; border-radius: var(--radius); background: none; color: #a6b1be;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; cursor: pointer; font: inherit; font-size: 10.5px;
  min-width: 0; white-space: nowrap; transition: background .12s, color .12s;
}
#tools button.wide { grid-column: 1 / -1; flex-direction: row; gap: 7px; height: 32px; font-size: 12px; }
#tools button svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
#tools button svg .fill { fill: currentColor; stroke-width: 1; }
#tools button:hover { color: var(--text); background: var(--panel-2); }
#tools button.on { color: #fff; background: #24384a; border-color: var(--accent); }
/* the things to place: a list by name, in groups that fold */
#tools button.item { grid-column: 1 / -1; flex-direction: row; justify-content: flex-start; gap: 8px; height: 27px; padding: 0 7px; font-size: 12px; }
#tools button.item svg { width: 17px; height: 17px; }
#tools button.item span { overflow: hidden; text-overflow: ellipsis; }
#tools button.cap.fold { height: auto; display: block; text-align: left; background: none; border: 0; border-top: 1px solid var(--line); border-radius: 0; cursor: pointer; font-size: 9.5px; }
#tools button.cap.fold::after { content: '▾'; float: right; font-size: 11px; color: #66727f; }
#tools button.cap.fold[aria-expanded="false"]::after { content: '▸'; }
#tools button.cap.fold:hover { color: var(--text); background: none; }
#tools .cap { grid-column: 1 / -1; font-size: 9.5px; letter-spacing: .7px; text-transform: uppercase; color: #66727f; margin: 7px 2px 1px; padding-top: 7px; border-top: 1px solid var(--line); }

/* stage */
#stage { grid-area: stage; position: relative; background: #0a0c10; min-width: 0; min-height: 0; overflow: hidden; }
#view { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#legend {
  position: absolute; left: 12px; bottom: 12px; width: 258px; padding: 8px 10px 8px;
  background: rgba(14, 17, 22, .84); border: 1px solid var(--line); border-radius: var(--radius); backdrop-filter: blur(4px);
  pointer-events: none;
}
.legend-title { font-size: 12px; font-weight: 600; color: var(--text); margin-bottom: 6px; }
.legend-help { font-size: 11px; color: #a3aebb; margin-top: 6px; line-height: 1.4; }
#legendBar { width: 100%; height: 9px; border-radius: 3px; display: block; }
.legend-ticks { display: flex; justify-content: space-between; font-size: 11px; margin-top: 4px; font-variant-numeric: tabular-nums; }
#zoomBox {
  position: absolute; right: 12px; bottom: 40px; display: flex;
  background: rgba(14, 17, 22, .84); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; backdrop-filter: blur(4px);
}
#zoomBox button { font: inherit; color: var(--text); background: none; border: 0; height: 28px; min-width: 30px; padding: 0 8px; cursor: pointer; font-size: 13px; }
#zoomBox button + button { border-left: 1px solid var(--line); }
#zoomBox button:hover { background: #212a35; }
#toast {
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); padding: 8px 14px; max-width: 60%; z-index: 6;
  background: rgba(21, 26, 33, .96); border: 1px solid #3a4757; border-radius: var(--radius); box-shadow: 0 6px 24px rgba(0,0,0,.45);
}
#note { position: relative; }
#noteTitle { font-weight: 600; margin-bottom: 3px; }
#noteText { color: #bcc6d2; font-size: 12px; line-height: 1.5; margin-bottom: 10px; }
#noteClose { position: absolute; right: 8px; top: 6px; width: 24px; height: 24px; border: 0; border-radius: 5px; background: none; color: var(--dim); font-size: 17px; line-height: 1; cursor: pointer; }
#noteClose:hover { background: var(--panel-2); color: var(--text); }
#legend.compact .legend-help { display: none; }
#tip, #uitip, #chartTip {
  position: absolute; left: 0; top: 0; pointer-events: none; max-width: 270px; padding: 7px 10px 8px; z-index: 5;
  background: rgba(12, 15, 20, .96); border: 1px solid #364353; border-radius: 6px; box-shadow: 0 6px 20px rgba(0, 0, 0, .45);
  font-size: 12px; line-height: 1.4;
}
#uitip { position: fixed; z-index: 30; max-width: 240px; }
.tip-title { font-weight: 600; }
.tip-line { color: #c3ccd7; }
.tip-hint { color: var(--accent); font-size: 11px; margin-top: 3px; }
.tip-key { color: var(--dim); font-weight: 400; margin-left: 6px; }

/* sensor chart dock */
#dock { grid-area: dock; background: var(--panel); border-top: 1px solid var(--line); min-width: 0; }
#dockHead { display: flex; align-items: center; gap: 10px; height: 34px; padding: 0 10px 0 4px; overflow: hidden; }
#dockToggle { display: flex; align-items: center; gap: 4px; font: inherit; font-weight: 600; color: var(--text); background: none; border: 0; height: 28px; padding: 0 8px 0 4px; border-radius: 6px; cursor: pointer; flex: none; }
#dockToggle:hover { background: var(--panel-2); }
#dockToggle svg { width: 16px; height: 16px; fill: none; stroke: var(--dim); stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; transition: transform .15s; }
#dock:not(.closed) #dockToggle svg { transform: rotate(90deg); }
#dockHead .chips { margin: 0; flex-wrap: nowrap; }
#dockHead .chips button { height: 24px; }
#dock.closed #chartChips, #dock.closed #btnCsv { display: none; }
#dockHead .chips button { padding: 0 8px; }
#chartLegend { position: absolute; left: 58px; right: 12px; top: 5px; display: flex; flex-wrap: wrap; align-items: center; gap: 2px 14px; overflow: hidden; max-height: 34px; font-size: 12px; color: #c3ccd7; pointer-events: none; font-variant-numeric: tabular-nums; }
#chartLegend span { display: flex; align-items: center; gap: 5px; }
#chartLegend i { width: 14px; height: 0; border-top: 2px solid; flex: none; }
#dockBody { position: relative; height: 176px; border-top: 1px solid var(--line); }
#dock.closed #dockBody { display: none; }
#chart { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#chartEmpty { position: absolute; inset: 0; display: grid; place-items: center; padding: 0 24px; text-align: center; color: var(--dim); line-height: 1.5; }
#chartEmpty b { color: var(--text); font-weight: 600; }
#chartEmpty p { margin: 0; max-width: 520px; }
.ct-time { color: var(--dim); font-size: 11px; margin-bottom: 3px; }
.ct-row { display: flex; align-items: center; gap: 7px; white-space: nowrap; }
.ct-row i { width: 12px; height: 0; border-top: 2px solid; flex: none; }
.ct-row b { font-weight: 600; font-variant-numeric: tabular-nums; }
.ct-row span { color: #a3aebb; }

/* side panel */
#side { grid-area: side; background: var(--panel); border-left: 1px solid var(--line); overflow-y: auto; padding-bottom: 12px; scrollbar-width: thin; scrollbar-color: #2c3642 transparent; }
#side section { padding: 12px 14px 4px; border-bottom: 1px solid var(--line); }
#side h2 { margin: 0 0 9px; font-size: 11px; font-weight: 600; letter-spacing: .6px; text-transform: uppercase; color: var(--dim); }
.chips { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 9px; }
.chips button { height: 26px; padding: 0 9px; font-size: 12px; }
.check { display: flex; align-items: center; gap: 7px; margin-bottom: 8px; cursor: pointer; }
.check input { accent-color: var(--accent); width: 14px; height: 14px; margin: 0; }
.row3 { display: grid; grid-template-columns: 1fr 62px 62px; gap: 6px; align-items: center; margin-bottom: 8px; }
.row3 .check { margin: 0; }
.field { display: grid; grid-template-columns: minmax(0, 1fr) 104px; gap: 4px 8px; align-items: center; margin-bottom: 8px; }
.field > label { color: var(--text); }
.field .with-unit { display: flex; align-items: center; gap: 5px; }
.field .unit { color: var(--dim); font-size: 11px; min-width: 30px; }
.field input[type=range] { grid-column: 1 / -1; width: 100%; accent-color: var(--accent); margin: 0; height: 16px; }
.num, .field select, .field input[type=number], .field input[type=text] {
  font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 5px; height: 26px;
  padding: 0 6px; width: 100%; min-width: 0; user-select: text;
}
.num:disabled { opacity: .45; }
.field select { padding: 0 4px; }
.field.wide { grid-template-columns: minmax(0, 1fr) 162px; }
.hintline { color: var(--dim); line-height: 1.45; margin: 0 0 10px; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.actions .btn { height: 26px; padding: 0 9px; font-size: 12px; }
.btn.danger:hover { border-color: var(--danger); color: var(--danger); }
.readings { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 5px 10px; margin: 0 0 10px; font-variant-numeric: tabular-nums; }
.readings dt { color: var(--dim); }
.readings dd { margin: 0; text-align: right; }
.live { background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px 3px; margin-bottom: 10px; }
.live .readings { margin-bottom: 5px; }
.live-title { font-size: 11px; color: var(--dim); margin-bottom: 6px; }
/* a heat pump's data sheet: one small table for each outdoor temperature */
.sheet { background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px 10px; margin-bottom: 10px; }
.sheet-title { font-size: 11px; font-weight: 600; letter-spacing: .5px; text-transform: uppercase; color: var(--dim); margin: 2px 0 7px; }
.sheet-add + .sheet-title { margin-top: 14px; }
.sheet-at { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; }
.sheet .sheet-at input[type=number] { width: 58px; flex: none; }
.sheet-at .unit { color: var(--dim); font-size: 11px; flex: 1; }
.sheet-x { font: inherit; width: 22px; height: 22px; padding: 0; line-height: 1; color: var(--dim); background: none; border: 1px solid transparent; border-radius: 5px; cursor: pointer; }
.sheet-x:hover { color: var(--danger); border-color: var(--line); }
.sheet-grid { display: grid; grid-template-columns: minmax(0, 1fr) repeat(3, 58px); gap: 4px; align-items: center; margin-bottom: 10px; }
.sheet-grid .col { color: var(--dim); font-size: 11px; text-align: center; }
.sheet-grid .rowl { color: var(--dim); font-size: 11px; }
.sheet input[type=number] {
  font: inherit; color: var(--text); background: var(--panel-2); border: 1px solid var(--line); border-radius: 5px; height: 24px;
  padding: 0 5px; width: 100%; min-width: 0; user-select: text; -moz-appearance: textfield; appearance: textfield; font-variant-numeric: tabular-nums;
}
.sheet input[type=number]::-webkit-outer-spin-button, .sheet input[type=number]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.sheet-add { height: 24px; padding: 0 8px; font-size: 12px; }
.sheet-name { font: inherit; color: var(--text); background: var(--panel-2); border: 1px solid var(--line); border-radius: 5px; height: 24px; padding: 0 6px; width: 100%; min-width: 0; margin-bottom: 8px; user-select: text; }
.sheet-name::placeholder { color: var(--dim); }

/* status bar */
#status {
  grid-area: status; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 0 12px;
  background: var(--panel); border-top: 1px solid var(--line); color: var(--dim); font-size: 12px; white-space: nowrap; overflow: hidden;
}
#probe { font-variant-numeric: tabular-nums; color: var(--text); }
#hint { overflow: hidden; text-overflow: ellipsis; }

/* guide */
#guide { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 16px; background: rgba(5, 7, 10, .68); }
.guide-card {
  width: min(800px, 100%); max-height: 100%; overflow: auto; padding: 22px 24px 18px; user-select: text;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 20px 60px rgba(0, 0, 0, .6);
}
.guide-card h1 { margin: 0 0 6px; font-size: 19px; }
.guide-card .lead { margin: 0 0 16px; color: #bcc6d2; line-height: 1.5; font-size: 13.5px; }
.guide-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
@media (max-width: 720px) { .guide-cols { grid-template-columns: 1fr; } }
.guide-card h2 { margin: 0 0 7px; font-size: 11px; font-weight: 600; letter-spacing: .6px; text-transform: uppercase; color: var(--dim); }
.guide-card ul + h2 { margin-top: 15px; }
.guide-card ul { margin: 0; padding-left: 17px; line-height: 1.5; }
.guide-card li { margin-bottom: 5px; }
.guide-card ul.after-key { margin-top: 9px; }
.key { display: grid; grid-template-columns: 1fr 1fr; gap: 5px 12px; margin: 6px 0 0 17px; }
.key div { display: flex; align-items: center; gap: 7px; }
.key i { width: 14px; height: 14px; border-radius: 3px; flex: none; border: 1px solid rgba(0, 0, 0, .45); }
/* the tool card: what the picked tool makes and how to use it */
#toolCard {
  position: absolute; top: 10px; right: 12px; width: 322px; padding: 10px 13px 9px; z-index: 3; pointer-events: none;
  background: rgba(17, 22, 29, 0.94); border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .45); font-size: 12px; line-height: 1.45;
}
.tc-head { display: flex; align-items: center; gap: 8px; font-size: 13.5px; color: #fff; }
.tc-head svg { width: 18px; height: 18px; fill: none; stroke: var(--accent); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.tc-what { margin: 5px 0 6px; color: #b9c4d0; }
.tc-steps { margin: 0; padding-left: 18px; color: var(--text); }
.tc-steps li { margin-bottom: 2px; }
.tc-steps li::marker { color: var(--accent); font-weight: 600; }
.tc-warn { margin: 6px 0 0; color: #ffcf7a; }
.tc-then { margin: 6px 0 0; color: #b9c4d0; }
.tc-keys { margin: 6px 0 0; color: var(--dim); font-size: 11px; }
.guide-foot { display: flex; align-items: center; gap: 12px; margin-top: 18px; }
.guide-about { margin: 14px 0 0; padding-top: 11px; border-top: 1px solid var(--line); color: var(--dim); font-size: 12px; line-height: 1.5; }
.guide-about a { color: var(--accent); }
.hintline.warn { color: #ffcf6b; }
#view3d, #view3dLabels { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#view3dLabels { pointer-events: none; }
#view[hidden], #view3d[hidden], #view3dLabels[hidden] { display: none; }
#btn3d.on { background: #24384a; border-color: var(--accent); color: #fff; }
#viewCut { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#viewCut[hidden] { display: none; }
.seg button:disabled { opacity: 0.4; cursor: default; }
