/* KallioBEM 2D: editor shell styles. Tokens follow version 1 (same visual family). */
:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface2: #eef0f3;
  --text: #1b1f24;
  --muted: #5b6470;
  --grid: #e3e6ea;
  --axis: #8d96a1;
  --border: #d3d8de;
  --accent: #0a5ea8;
  --on-accent: #ffffff;
  --warn: #c24a00;
  --warn-bg: #fff4d6;
  --warn-text: #6b4a00;
  --danger: #b42318;
  --c1: #0072B2;
  --c2: #C27800;
  --c3: #B5338A;
  /* the rock mass behind the openings */
  --rock: #d9d6cd;
  --rock-grid: rgba(40, 36, 28, 0.08);
  --rock-grid-major: rgba(40, 36, 28, 0.18);
  --rock-axis: rgba(40, 36, 28, 0.5);
  --rock-text: #3a3f45;
  --outline: #2a2f36;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121214;
    --surface: #1a1a19;
    --surface2: #25262a;
    --text: #e8eaed;
    --muted: #a0a8b3;
    --grid: #2f3237;
    --axis: #6f7782;
    --border: #3a3d43;
    --accent: #6cb4f0;
    --on-accent: #0b1620;
    --warn: #ff9a4d;
    --warn-bg: #3b2f10;
    --warn-text: #f3d48a;
    --danger: #ff8a80;
    --c1: #3898D4;
    --c2: #C48200;
    --c3: #CC6AA2;
    --rock: #3b3c40;
    --rock-grid: rgba(255, 255, 255, 0.06);
    --rock-grid-major: rgba(255, 255, 255, 0.14);
    --rock-axis: rgba(255, 255, 255, 0.45);
    --rock-text: #c4c9d0;
    --outline: #d5d9df;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ------------------------------------------------------------------ header */
header.top {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: 8px 20px; padding: 10px 12px 4px;
}
header.top h1 { margin: 0; font-size: 20px; }
header.top p { margin: 2px 0 0; color: var(--muted); }
.filebar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.dirty { color: var(--warn-text); background: var(--warn-bg); border-radius: 10px; padding: 1px 8px; font-size: 12.5px; }
.switch { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }

/* ------------------------------------------------------------------ layout */
.layout {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr) 320px;
  gap: 12px;
  padding: 8px 12px 16px;
  align-items: start;
}
.layout.no-results { grid-template-columns: 300px minmax(0, 1fr); }
.layout > * { min-width: 0; }
.inputs, .results { position: sticky; top: 8px; max-height: calc(100vh - 16px); overflow: auto; }
.results { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; }
.maincol { display: flex; flex-direction: column; gap: 8px; }
@media (max-width: 1100px) {
  .layout, .layout.no-results { grid-template-columns: minmax(0, 1fr); }
  .maincol { order: 1; }
  .inputs { order: 2; }
  .results { order: 3; }
  .inputs, .results { position: static; max-height: none; overflow: visible; }
}

/* ------------------------------------------------------------------ buttons, forms */
button {
  font: inherit; cursor: pointer; padding: 4px 10px; min-height: 28px;
  color: var(--text); background: var(--surface2);
  border: 1px solid var(--border); border-radius: 4px;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: 0.5; cursor: default; }
input[type=text], select {
  font: inherit; padding: 3px 6px; min-height: 28px;
  color: var(--text); background: var(--surface2);
  border: 1px solid var(--border); border-radius: 4px;
}
input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--accent); }
.err { color: var(--danger); font-size: 12.5px; }
.err:empty { display: none; }
input.bad { border-color: var(--danger); outline: 1px solid var(--danger); }
.hint { color: var(--muted); font-size: 12.5px; margin: 4px 0; }
.subhead { font-weight: 600; font-size: 13px; margin: 10px 0 4px; }

details.group, .notes details {
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 6px 12px; margin: 0 0 8px;
}
details.group > summary, .notes summary { cursor: pointer; font-weight: 600; padding: 3px 0; }
details.group > .body { margin: 6px 0 4px; }
details.sub { margin: 8px 0 0; border-top: 1px solid var(--border); padding-top: 6px; }
details.sub > summary { cursor: pointer; font-size: 13px; color: var(--muted); }

.row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 4px 0; }
.row label { flex: 1; min-width: 0; }
.row input[type=text], .row select { width: 108px; flex: none; }
.row.check input { margin-right: 6px; }
.fld .err { margin: -2px 0 4px; }
.crit { margin: 0; }
.derived-hb { margin-top: 2px; }
.btnrow { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 2px; }
.shapewarn { background: var(--warn-bg); color: var(--warn-text); border-radius: 6px; padding: 5px 8px; margin: 4px 0; font-size: 13px; }
.shapewarn button { margin-top: 4px; }

dl.derived { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; margin: 8px 0; font-size: 13px; }
dl.derived dt { color: var(--muted); }
dl.derived dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }

/* shapes group */
.addgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(86px, 1fr)); gap: 6px; }
.addbtn { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 4px; font-size: 12.5px; line-height: 1.2; }
.shapelist { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 4px; }
.shapelist li {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto; gap: 4px; align-items: center;
  border: 1px solid transparent; border-radius: 6px; padding: 2px;
}
.shapelist li.selected { border-color: var(--accent); background: var(--surface2); }
.shapelist li.invalid { border-color: var(--warn); }
.shapelist .pick { padding: 2px 4px; min-height: 28px; display: inline-flex; border-color: transparent; background: transparent; }
.shapelist .nameinput { width: 100%; min-width: 0; background: transparent; border-color: transparent; }
.shapelist .nameinput:hover, .shapelist .nameinput:focus { border-color: var(--border); background: var(--surface2); }
.shapelist .shapemsg { grid-column: 1 / -1; font-size: 12px; color: var(--warn-text); background: var(--warn-bg); border-radius: 4px; padding: 2px 6px; }
.iconbtn { padding: 2px 5px; min-height: 26px; display: inline-flex; align-items: center; background: transparent; border-color: transparent; }
.iconbtn:hover:not(:disabled) { border-color: var(--border); }

/* vertex table */
.tablewrap { overflow-x: auto; margin-bottom: 6px; }
table.vtable { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
table.vtable th, table.vtable td { padding: 2px 3px; text-align: left; border-bottom: 1px solid var(--grid); }
table.vtable th { font-weight: 600; color: var(--muted); font-size: 12.5px; }
table.vtable input { width: 74px; min-height: 24px; padding: 1px 4px; }

/* stress box: sides proportional to the stress magnitudes */
.stressfig { text-align: center; }
.stresssvg { width: 100%; max-width: 250px; display: block; margin: 6px auto 0; }
.stresssvg .el { fill: var(--surface2); stroke: var(--muted); stroke-width: 1.2; }
.stresssvg .axisx { stroke: var(--axis); stroke-width: 0.8; stroke-dasharray: 3 3; }
.stresssvg .arc { stroke: var(--muted); stroke-width: 1; fill: none; }
.stresssvg .axtext { fill: var(--muted); font-size: 9px; }
.stresssvg .stxt { fill: var(--text); paint-order: stroke; stroke: var(--surface); stroke-width: 3px; stroke-linejoin: round; }
.stresssvg .s1 { stroke: var(--c1); stroke-width: 2.2; fill: none; }
.stresssvg .s3 { stroke: var(--c2); stroke-width: 2.2; fill: none; }
.stresssvg .head { stroke-linejoin: round; stroke-linecap: round; }
.stressnote { text-align: center; margin-top: 2px; }

/* ------------------------------------------------------------------ toolbar and map */
.toolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 5px 8px;
}
.tgroup { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
button.tool { display: inline-flex; align-items: center; gap: 5px; }
button.tool[aria-pressed=true] { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.inl { display: inline-flex; align-items: center; gap: 5px; }
input.gridstep { width: 64px; }
.zoom { margin-left: auto; color: var(--muted); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.mapwrap {
  position: relative; height: max(60vh, 380px); overflow: hidden;
  background: var(--rock); border: 1px solid var(--border); border-radius: 8px;
}
.mapwrap canvas { position: absolute; left: 0; top: 0; display: block; touch-action: none; outline: none; }
.mapwrap canvas:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.toolhint {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 4px 10px;
  color: var(--muted); font-size: 13px;
}
.statusline {
  display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 16px;
  min-height: 1.9em; padding: 3px 10px; border-radius: 6px;
  color: var(--muted); font-size: 13px; background: var(--surface); border: 1px solid var(--border);
}
.statusline[data-kind=warn] { color: var(--warn-text); background: var(--warn-bg); border-color: var(--warn); }
.statusline[data-kind=error] { color: var(--danger); border-color: var(--danger); }
#readout { font-variant-numeric: tabular-nums; margin-left: auto; }

/* ------------------------------------------------------------------ notes */
.notes { padding: 0 12px 24px; }
.notes .body { margin-top: 8px; }
.notes h2 { font-size: 15px; margin: 0 0 6px; }
.notes ul { margin: 0; padding-left: 20px; }
.notes li { margin: 3px 0; }
code { background: var(--surface2); padding: 0 4px; border-radius: 3px; }

/* ======================================================================
   Part B: results (right column, colour bar, charts, notes)
   ====================================================================== */
/* the groups of the right column carry their own frame, like the left column */
.results { background: none; border: none; padding: 0; border-radius: 0; }
.fullrow { margin: 4px 0; }
.fullrow label { display: block; margin-bottom: 2px; }
.fullrow select { width: 100%; }
.results .row input[type=text] { width: 80px; }
.rangerow { display: grid; grid-template-columns: auto minmax(0, 1fr) auto minmax(0, 1fr); gap: 6px; align-items: center; margin: 4px 0; }
.rangerow input[type=text] { width: 100%; min-width: 0; }
.results details.group > .body .btnrow { margin: 8px 0 2px; }
button.qtool[aria-pressed=true] { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }

.busy {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 8px; align-items: center;
  background: var(--surface); border: 1px solid var(--accent); border-radius: 8px; padding: 6px 10px; margin: 0 0 8px;
}
.busy progress { width: 100%; height: 10px; accent-color: var(--accent); }

.cbar { background: var(--surface); border: 1px solid var(--border); border-radius: 6px; overflow: hidden; line-height: 0; }
.cbar canvas { display: block; width: 100%; height: 52px; }

.sumcard { border: 1px solid var(--border); border-radius: 6px; padding: 4px 8px; margin: 0 0 6px; }
.sumcard.selected { border-color: var(--accent); background: var(--surface2); }
.sumcard h3 { margin: 0 0 2px; font-size: 13px; }
dl.sumlist { grid-template-columns: minmax(0, 1fr); gap: 0; margin: 2px 0; font-size: 12.5px; }
dl.sumlist dt { margin-top: 3px; }
dl.sumlist dd { text-align: left; }
#r-summary.stale { opacity: 0.5; }
dl.derived dd { overflow-wrap: anywhere; }

table.qtable { border-collapse: collapse; width: 100%; font-size: 12px; font-variant-numeric: tabular-nums; }
table.qtable th, table.qtable td { padding: 2px 3px; text-align: right; border-bottom: 1px solid var(--grid); white-space: nowrap; }
table.qtable th:first-child, table.qtable td:first-child { text-align: left; }
table.qtable th { color: var(--muted); font-weight: 600; }
table.qtable td.muted { text-align: left; color: var(--muted); }
table.qtable tbody tr:hover { background: var(--surface2); }
table.qtable .iconbtn { min-height: 20px; padding: 0 5px; }
ul.linelist { list-style: none; margin: 4px 0; padding: 0; display: grid; gap: 3px; }
ul.linelist li { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px; align-items: center; border: 1px solid transparent; border-radius: 6px; padding: 1px; }
ul.linelist li.selected { border-color: var(--accent); background: var(--surface2); }
ul.linelist .pick { text-align: left; border-color: transparent; background: transparent; font-size: 12.5px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
ul.linelist li.hint { display: block; }

#charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 8px; }
.chartcard { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px 4px; min-width: 0; }
.chartcard header { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; margin-bottom: 4px; }
.chartcard h2 { font-size: 14px; margin: 0; margin-right: auto; }
.chartcard select { max-width: 220px; }
.chartcanvas { display: block; width: 100%; height: 240px; }
.chartempty { padding: 24px 4px; text-align: center; }
.charttip {
  position: fixed; display: none; z-index: 30; pointer-events: none; max-width: 260px;
  background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 4px;
  padding: 4px 8px; font-size: 12px; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}
.notes h2 { margin-top: 14px; }
.notes h2:first-child { margin-top: 0; }
.notes .body { max-width: 980px; }

/* run statistics under the map: elements, degrees of freedom, times */
.mapstats {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 8px; min-height: 1.9em;
  padding: 3px 10px; border-radius: 6px; background: var(--surface); border: 1px solid var(--border);
  color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums;
}
.mapstats .stat { white-space: nowrap; }
.mapstats .stat:not(:last-child)::after { content: "|"; margin-left: 8px; color: var(--axis); }

/* table shape editor */
table.tbltable input { width: 64px; }
table.vtable tr.cur td { background: var(--surface2); }
table.vtable tr.badrow td { background: var(--warn-bg); }
table.vtable tr.badrow input { border-color: var(--warn); }
.pastearea {
  width: 100%; font: 12.5px/1.35 ui-monospace, SFMono-Regular, Consolas, monospace; padding: 4px 6px;
  color: var(--text); background: var(--surface2); border: 1px solid var(--border); border-radius: 4px; resize: vertical;
}
ul.pasteerrs { margin: 4px 0; padding-left: 18px; }
ul.pasteerrs:empty { display: none; }
.arcrule { margin-top: 0; }
