:root {
  --blue: #1565c0; --blue2: #1976d2; --ink: #1f2733; --muted: #4b5563;
  --line: #cfd6e0; --bg: #eef1f5; --panel: #ffffff;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Segoe UI", Arial, sans-serif; color: var(--ink);
  background: var(--bg); display: flex; flex-direction: column; height: 100vh;
}
header {
  background: #25303f; color: #fff; padding: 8px 16px; display: flex;
  align-items: baseline; gap: 14px; flex: none;
}
header .logo { display: block; border-radius: 6px; flex: none; }
header h1 { font-size: 17px; margin: 0; letter-spacing: .3px; }
header .sub { color: #9fb4c8; font-size: 12px; }

#layout {
  flex: 1; display: grid; min-height: 0;
  grid-template-columns: var(--left-w, 300px) 7px minmax(0, 1fr) 7px var(--right-w, 330px);
}
.splitter { background: #dbe2ec; cursor: col-resize; }
.splitter:hover, .splitter:active { background: #9db2ca; }
#left, #right { overflow-y: auto; padding: 10px; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
#center { min-width: 0; padding: 10px; overflow: auto; display: flex; flex-direction: column; gap: 8px; }
#plotWrap { flex: 1; min-height: 0; display: flex; align-items: flex-start; justify-content: center;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px; overflow: auto; }
#plot { width: 100%; min-height: 420px; }

/* appearance bar: the active plot's cosmetics, below the plot; collapsible so it
   never permanently eats plot height. Controls flow in fixed-width groups. */
#appearance { flex: none; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; }
.appbar-head { display: flex; align-items: baseline; gap: 10px; padding: 4px 8px; }
#appearance:not(.collapsed) .appbar-head { border-bottom: 1px solid var(--line); }
.appbar-toggle { flex: none; background: transparent; color: var(--blue); font-weight: 700;
  text-transform: uppercase; letter-spacing: .4px; font-size: 12px; padding: 2px 6px; border-radius: 4px; }
.appbar-toggle:hover { background: #eef4fc; }
.appbar-hint { color: var(--muted); font-size: 11px; }
#appearance.collapsed .appbar-body { display: none; }
.appbar-body { display: flex; flex-wrap: wrap; gap: 4px 14px; padding: 8px 10px 10px;
  max-height: 320px; overflow: auto; align-items: flex-start; }
.app-group { flex: 0 0 auto; width: 150px; display: flex; flex-direction: column; gap: 0; }
.app-group .app-title { font-size: 10.5px; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: .3px; margin: 0 0 3px; }
.app-group input, .app-group select { padding: 3px 5px; font-size: 11.5px; }
.app-group .row { gap: 5px; }
/* label text and its control sit on ONE line (dense) — except checkboxes */
.app-group label:not(.chk) { display: flex; align-items: center; gap: 5px; margin: 1px 0; white-space: nowrap; }
.app-group label:not(.chk) > input, .app-group label:not(.chk) > select { flex: 1 1 40px; width: auto; min-width: 0; }
.app-group .row label { flex: 1; }

/* tab bar: one chip per plot; datasets on the left panel are shared across all */
.tabbar { display: flex; align-items: center; gap: 4px; flex: none; overflow-x: auto; padding-bottom: 2px; }
.tabbar.busy { pointer-events: none; opacity: 0.55; }   /* locked while a project loads */
.tab { display: inline-flex; align-items: center; gap: 6px; flex: none; cursor: pointer;
  background: #e6ecf5; color: #35404e; border: 1px solid var(--line); border-bottom: none;
  border-radius: 7px 7px 0 0; padding: 5px 8px 5px 10px; font-size: 12px; font-weight: 600;
  max-width: 200px; }
.tab:hover { background: #dbe6f5; }
.tab.active { background: var(--panel); color: var(--blue); box-shadow: inset 0 2px 0 var(--blue); }
.tab .tab-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tab .x { flex: none; color: #90a0b3; font-size: 12px; line-height: 1; padding: 0 2px; border-radius: 3px; }
.tab .x:hover { color: #fff; background: #c0392b; }
.tab-add { flex: none; cursor: pointer; background: transparent; color: var(--blue); border: 1px solid var(--line);
  border-radius: 6px; padding: 4px 9px; font-size: 14px; font-weight: 700; line-height: 1; }
.tab-add:hover { background: #e6ecf5; }
.tab .tab-rename { width: 96px; font-size: 12px; padding: 1px 3px; border: 1px solid var(--blue);
  border-radius: 3px; background: #fff; }

/* right-click menu on a tab */
.ctxmenu { position: fixed; z-index: 1000; background: var(--panel); border: 1px solid var(--line);
  border-radius: 6px; box-shadow: 0 4px 16px rgba(0, 0, 0, .18); padding: 4px; min-width: 132px;
  display: flex; flex-direction: column; }
.ctxmenu button { background: transparent; color: var(--ink); text-align: left; font-weight: 500;
  padding: 6px 10px; border-radius: 4px; flex: none; font-size: 12px; }
.ctxmenu button:hover { background: #eef4fc; color: var(--blue); }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.panel h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .4px;
  color: var(--blue); margin: 0 0 8px; }
.sub-h { font-size: 11px; color: var(--muted); margin: 8px 0 4px; font-weight: 600; }

label { display: block; font-size: 12px; margin: 4px 0; color: #35404e; }
label.chk { display: inline-flex; align-items: center; gap: 4px; margin-right: 6px; }
input[type=text], input[type=number], select {
  width: 100%; padding: 4px 6px; border: 1px solid var(--line); border-radius: 4px;
  background: #f7f9fc; font-size: 12px; color: var(--ink);
}
label.chk input, .row.wrap select { width: auto; }
.row { display: flex; gap: 6px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.row label { flex: 1; margin: 4px 0; }
.row.wrap label { flex: none; }

button {
  background: var(--blue); color: #fff; border: none; border-radius: 5px;
  padding: 6px 10px; font-weight: 600; font-size: 12px; cursor: pointer; flex: 1;
}
button:hover { background: var(--blue2); }
button.ghost { background: #e6ecf5; color: var(--blue); }
button.ghost:hover { background: #d6e2f3; }
button.warn { background: #c0392b; }
button.warn:hover { background: #d6493a; }
button.active { background: #0d4a92; box-shadow: inset 0 0 0 2px #8fd0ff; }
button.mini { flex: none; background: transparent; color: #90a0b3; padding: 0 4px; font-size: 12px; }
button.mini:hover { color: #c0392b; background: transparent; }

/* the tree scrolls both ways WITHIN itself; padding-bottom keeps a horizontal
   scrollbar from covering the last row */
.tree { max-height: 46vh; overflow: auto; font-size: 12px; margin-top: 8px; padding-bottom: 10px; }
.tree-file-hdr { display: flex; justify-content: space-between; align-items: center; gap: 6px;
  font-weight: 700; color: #35404e; padding: 4px 2px; border-bottom: 1px solid var(--line); }
.tree-file-hdr span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-var { display: flex; justify-content: space-between; gap: 10px; padding: 3px 6px;
  border-radius: 4px; cursor: pointer; }
.tree-var:hover { background: #eef4fc; }
.tree-var.sel { background: #d6e2f3; }
.tree-var.nonnum .vn { color: #9aa6b4; }
.tree-var .vn { white-space: nowrap; }
.tree-var .vd { color: #90a0b3; font-family: Consolas, monospace; font-size: 10px; white-space: nowrap; }
.info { background: #fff; font-family: Consolas, monospace; font-size: 10.5px; color: #35404e;
  white-space: pre-wrap; max-height: 26vh; overflow: auto; margin: 0; }

.trace-list { max-height: 260px; overflow-y: auto; border: 1px solid var(--line); border-radius: 4px; }
.trace-row { display: flex; gap: 6px; align-items: center; padding: 3px 6px; cursor: pointer; font-size: 12px; }
.trace-row:hover { background: #eef4fc; }
.trace-row.sel { background: #d6e2f3; }
.trace-row span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.sliders { display: flex; flex-direction: column; gap: 4px; }
.slider-row { display: flex; align-items: center; gap: 6px; }
.sl-name { min-width: 54px; font-size: 11px; }
.slider-row input[type=range] { flex: 1; }
.sl-val { min-width: 92px; font-family: Consolas, monospace; font-size: 10.5px; color: var(--muted); }
.muted { color: #90a0b3; font-size: 12px; }
.hint { color: var(--muted); font-size: 10.5px; margin: 6px 0 0; }

footer#status { flex: none; background: #25303f; color: #e6ecf5; font-size: 12px;
  padding: 5px 14px; font-family: Consolas, monospace; }

@media (max-width: 1100px) {
  #layout { grid-template-columns: 1fr; grid-auto-rows: min-content; overflow-y: auto; }
  #left, #right { overflow: visible; }
  #center { min-height: 60vh; }
  .splitter { display: none; }
}
