/* ENVLP web — a light, cool palette matching the desktop theme. */
:root {
  --chrome: #f4f6fa;
  --surface: #ffffff;
  --muted: #edf0f6;
  --border: #e2e6ee;
  --text: #1f2430;
  --dim: #6b7284;
  --accent: #2f6fed;
  --accent-soft: #e8f0fe;
  --mono: "Cascadia Mono", "Consolas", "SF Mono", monospace;
  /* the widths of the two side panels and the height of the results pane;
     they are dragged by the gutters and remembered in localStorage */
  /* Three columns of 74px symbol tiles plus their labels; all palette parts
     are visible without widening the panel first. */
  --palette-w: 300px;
  --dock-w: 340px;
  --results-h: 34%;
  --plot-w: 46%;
}

* { box-sizing: border-box; }
/* `hidden` has to win over the layout rules below (.check and .inline set
   their own display), so the per-analysis fields really do disappear. */
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--chrome); color: var(--text);
  font: 14px/1.45 "Segoe UI", system-ui, sans-serif;
  display: flex; flex-direction: column; height: 100vh; overflow: hidden;
}

header {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 14px; background: var(--surface);
  border-bottom: 1px solid var(--border);
}
header h1 { font-size: 15px; margin: 0; letter-spacing: .02em; }
header .brand { display: flex; align-items: center; gap: 8px; }
.env-icon { width: 19px; height: 19px; color: var(--accent); flex: 0 0 auto; }
.tag { color: var(--dim); font-size: 12px; }
.spacer { flex: 1 1 auto; }
footer {
  padding: 6px 14px; color: var(--dim); font-size: 11.5px;
  border-top: 1px solid var(--border); background: var(--surface);
}

main {
  display: grid;
  grid-template-columns: var(--palette-w) 7px minmax(0, 1fr) 7px var(--dock-w);
  grid-template-rows: minmax(0, 1fr);
  grid-template-areas: "palette pgutter centre dgutter dock";
  padding: 10px; min-height: 0; flex: 1 1 auto;
}
.palette { grid-area: palette; }
.gutter-v.pgutter { grid-area: pgutter; }
.center { grid-area: centre; }
.gutter-v.dgutter { grid-area: dgutter; }
.dock { grid-area: dock; }

.ttl {
  font-size: 10.5px; font-weight: 600; letter-spacing: .06em;
  text-transform: uppercase; color: #8890a0; margin: 2px 0 6px;
}

/* --- the draggable dividers -------------------------------------------- */
.gutter { background: transparent; }
.gutter-v { cursor: col-resize; }
.gutter-h { cursor: row-resize; }
.gutter::after {
  content: ""; display: block; width: 3px; height: 100%; margin: 0 auto;
  border-radius: 2px; background: transparent; transition: background .12s;
}
.gutter-v::after { width: 3px; height: 100%; }
.gutter-h::after { width: 100%; height: 3px; }
.gutter:hover::after, .gutter.dragging::after { background: var(--accent); }

/* --- palette ---------------------------------------------------------- */
.palette, .dock {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px; overflow: auto; min-height: 0;
}
#palette-list {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(84px, 1fr));
  gap: 6px;
}
.part {
  display: flex; flex-direction: column; align-items: center;
  min-width: 0; padding: 4px 2px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 7px; cursor: pointer; font-size: 11px; color: var(--dim);
}
.part span {
  max-width: 100%; text-align: center; line-height: 1.2;
  overflow-wrap: break-word;
}
.part:hover { background: var(--muted); }
.part.armed { border-color: var(--accent); background: var(--accent-soft); }
.part canvas { pointer-events: none; }
.tool { width: 100%; margin-bottom: 4px; text-align: left; }
.tool.armed { border-color: var(--accent); color: var(--accent); font-weight: 600; }
kbd {
  float: right; font: 10px var(--mono); color: var(--dim);
  border: 1px solid var(--border); border-radius: 3px; padding: 0 3px;
}
.hint { color: var(--dim); font-size: 11px; line-height: 1.6; margin-top: 8px; }
.hint b { color: var(--text); font-weight: 600; }
.hint .sep { color: #b9bfcc; }

/* --- centre: canvas + results ---------------------------------------- */
.center {
  display: grid;
  grid-template-rows: minmax(0, 1fr) 7px var(--results-h);
  min-height: 0; min-width: 0;
}
.canvas-wrap {
  position: relative; background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; overflow: hidden;
}
#canvas { display: block; outline: none; cursor: crosshair; }
.hud { position: absolute; right: 8px; top: 6px; color: var(--dim); font-size: 11px; }

.results {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 7px var(--plot-w);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 6px; min-height: 0;
}
.results-left { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.results-right { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.tabs { display: flex; gap: 5px; padding-bottom: 5px; align-items: center; }
.tabs button { border-radius: 6px; padding: 3px 10px; font-size: 12.5px; }
.tabs button.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.tab { display: none; flex: 1 1 auto; min-height: 0; overflow: auto; }
.tab.active { display: block; }
#report { margin: 0; font-family: var(--mono); font-size: 12px; white-space: pre-wrap; }
/* the typeset result is left justified, like the desktop's math panel */
.math, .math .line { text-align: left; }
.math mjx-container[jax="CHTML"][display="true"] { text-align: left !important; }
.math mjx-container[display="true"] { text-align: left !important; }
#plot { flex: 1 1 auto; min-height: 220px; }

/* --- dock ------------------------------------------------------------- */
.dock { display: flex; flex-direction: column; gap: 6px; }
.grid { display: grid; grid-template-columns: max-content 1fr; gap: 5px 8px; align-items: center; }
.grid > label { color: var(--dim); font-size: 12px; }
.inline { display: flex; gap: 5px; }
.check { grid-column: 1 / -1; display: flex; gap: 6px; align-items: center; font-size: 12.5px; }
.check input { width: auto; flex: 0 0 auto; }
.props { font-size: 12.5px; }
.prow { display: flex; gap: 6px; align-items: center; margin-bottom: 4px; }
.prow > span { color: var(--dim); min-width: 54px; }
.prow input, .prow select { flex: 1 1 auto; min-width: 0; }
/* a model parameter: a switch (for the parasitics), a value and its unit */
.prow.param { gap: 4px; }
.prow.param > span { min-width: 52px; font-size: 12px; color: var(--text); }
.prow.param input[type="checkbox"] { flex: 0 0 auto; width: auto; }
.prow.param .mantissa { flex: 0 0 62px; }
/* the coupling coefficient: a plain number between -1 and +1 */
.prow.param .coupling { flex: 0 0 86px; }
.prow.param .suffix { flex: 1 1 auto; min-width: 0; font-size: 11.5px; }
/* a value with its SI suffix */
.prow .si { display: flex; gap: 4px; flex: 1 1 auto; min-width: 0; }
.prow .si .mantissa { flex: 0 0 62px; }
.prow .si .suffix { flex: 1 1 auto; min-width: 0; font-size: 11.5px; }
/* the physical unit after the SI suffix, as on the desktop */
.prow .si .unit, .prow.param .unit {
  flex: 0 0 auto;
  color: var(--dim);
  font-size: 11.5px;
}

/* The operating point lives in its own section: it is a property of the
   circuit, not of the analysis that happens to be selected. */
.dcbox {
  border: 1px solid var(--border); border-radius: 7px; padding: 6px 8px;
  background: var(--surface);
}
.dcbox > summary {
  cursor: pointer; font-size: 11px; font-weight: 600; letter-spacing: .05em;
  text-transform: uppercase; color: #8890a0; list-style: revert;
}
.dcbox[open] > summary { margin-bottom: 6px; }
.dcbox .grid { grid-template-columns: max-content 1fr; }

input, select, textarea, button { font: inherit; color: inherit; }
input, select {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 6px; padding: 4px 7px; min-width: 0; width: 100%;
}
.inline input { flex: 1; }
input:focus, select:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }

button {
  background: var(--muted); border: 1px solid var(--border);
  border-radius: 6px; padding: 5px 11px; cursor: pointer;
}
button:hover { background: #e4e9f2; }
button.primary {
  background: var(--accent); border-color: var(--accent); color: #fff;
  font-weight: 600;
}
button.primary:hover { background: #2a63d4; }
button.ghost { background: var(--surface); }
/* the prominent "How To Use" button */
button.howto {
  background: var(--accent); border-color: var(--accent); color: #fff;
  font-weight: 600; padding: 5px 13px;
}
button.howto:hover { background: #2a63d4; }
/* the link out to the author's site */
a.linkbtn {
  display: inline-block; text-decoration: none; font-size: 13px;
  color: var(--accent); border: 1px solid var(--border); background: var(--surface);
  border-radius: 6px; padding: 5px 11px;
}
a.linkbtn:hover { background: var(--muted); }

/* the app's button bar under the result text */
.copybar { display: flex; gap: 6px; padding-top: 6px; }
.copybar button { font-size: 12.5px; padding: 4px 10px; }

.status { font-size: 12px; color: var(--dim); min-height: 15px; }
.status.err { color: #c03131; white-space: pre-wrap; }

/* --- the help dialog --------------------------------------------------- */
dialog.help {
  border: 1px solid var(--border); border-radius: 10px; padding: 0;
  width: min(760px, 92vw); max-height: 88vh; overflow: auto;
  color: var(--text); background: var(--surface);
}
dialog.help::backdrop { background: rgba(31, 36, 48, .38); }
.help-head {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--surface);
}
.help-head h2 { font-size: 15px; margin: 0; }
.help-head .spacer { flex: 1 1 auto; }
.help section { padding: 4px 16px 12px; }
.help h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em;
  color: #8890a0; margin: 14px 0 6px; }
.help ol { margin: 0; padding-left: 20px; }
.help li { margin-bottom: 4px; }
.help p { margin: 6px 0; }
.help .note { color: var(--dim); font-size: 12px; }
table.keys { border-collapse: collapse; width: 100%; font-size: 12.5px; }
table.keys td { padding: 3px 8px 3px 0; vertical-align: top; }
table.keys td:first-child { white-space: nowrap; width: 1%; }
/* In the help dialog the key sits next to its description, not floated to the
   right -- that made "Wire (W)" read as "Wire ()". */
.help kbd { float: none; background: var(--muted); }
.help code { font-family: var(--mono); font-size: 12px; }

/* the component menu (the I key) */
.components .clist {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 6px; padding: 12px 16px 16px;
}
.citem { text-align: left; }

/* the net-label dialog */
.help-body { padding: 12px 16px 16px; }
.help-body input[type="text"] {
  width: 100%; padding: 7px 9px; border: 1px solid var(--border);
  border-radius: 6px; font-family: var(--mono);
}
.help-actions { margin-top: 10px; display: flex; justify-content: flex-end; }

/* Narrow windows: the side panels shrink but stay usable (the app is often
   embedded in an iframe), and below that they stack above and below the
   canvas instead of disappearing. */
@media (max-width: 1180px) {
  main { grid-template-columns: 168px 7px minmax(0, 1fr) 7px 268px; }
}
@media (max-width: 820px) {
  main {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(200px, 1fr) auto;
    grid-template-areas: "palette" "centre" "dock";
  }
  .gutter-v { display: none; }
  .palette, .dock { max-height: 34vh; }
  .palette #palette-list { grid-template-columns: repeat(4, 1fr); }
}
