* { box-sizing: border-box; }
:root {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #222;
  background: #fff;
}
body { margin: 0; }
header {
  position: sticky; top: 0; z-index: 10;
  background: #fff; border-bottom: 1px solid #ddd;
  padding: 10px 16px;
  display: flex; align-items: baseline; gap: 18px;
}
header h1 { margin: 0; font-size: 22px; }
.status { color: #555; font-size: 13px; }
.app-shell { display: grid; grid-template-columns: 360px minmax(0,1fr); min-height: calc(100vh - 55px); }
.sidebar { border-right: 1px solid #ddd; padding: 12px; overflow-y: auto; max-height: calc(100vh - 55px); }
.sidebar section { border-bottom: 1px solid #eee; padding: 8px 0 14px; }
h2 { font-size: 15px; margin: 8px 0; }
label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; }
input, select, button { font: inherit; padding: 5px; }

/* Compact numeric entry boxes.
   About 5-7 visible characters are enough for the TAS parameters,
   and min-width:0 prevents grid items from forcing horizontal scrolling. */
input[type="number"] {
  width: 10ch;
  min-width: 9ch;
  max-width: 100%;
}

input[type="radio"],
input[type="checkbox"] {
  width: auto;
}

/* Select boxes should use the available sidebar width, but never enlarge it. */
select {
  width: 100%;
  min-width: 0;
  max-width: 100%;
}

label,
.grid2 > *,
.grid3 > *,
.grid4 > *,
.vector-row > *,
.dark-table > * {
  min-width: 0;
}
.inline { display: flex; flex-direction: row; gap: 12px; align-items: center; margin: 5px 0; }
.inline label, .checkbox-label { flex-direction: row; align-items: center; }
.grid2, .grid3, .grid4 { display: grid; gap: 3px; margin: 4px 0; min-width: 0; }
.grid2 { grid-template-columns: repeat(2, 1fr); }
.grid3 { grid-template-columns: repeat(3, 1fr); }
.grid4 { grid-template-columns: repeat(4, 1fr); }
.vector-row { display: grid; grid-template-columns: 24px repeat(3, minmax(0, 1fr)); gap: 3px; margin: 3px 0; align-items: center; }
.dark-table { display: grid; grid-template-columns: 26px repeat(3, minmax(0, 1fr)); gap: 3px; align-items: center; margin: 5px 0; font-size: 11px; min-width: 0; }
main { padding: 10px; min-width: 0; }
.chart-grid { display: grid; grid-template-columns: minmax(500px, 3fr) minmax(250px, 1fr); gap: 10px; }
.plot { width: 100%; min-height: 700px; }
.geometry { min-height: 700px; }
.powder { min-height: 700px; }
.energy-slider-row { display: flex; gap: 12px; align-items: center; padding: 0 20px 12px; }
.energy-slider-row label { flex: 1; }
.energy-slider-row input { width: 100%; }
.error { background: #fee; border: 1px solid #d88; color: #900; padding: 10px; margin-bottom: 10px; white-space: pre-wrap; }
.hidden { display: none !important; }
button { cursor: pointer; margin-top: 5px; }
@media (max-width: 1050px) {
  .app-shell { grid-template-columns: 320px minmax(0,1fr); }
  .chart-grid { grid-template-columns: 1fr; }
  .geometry { min-height: 420px; }
}
@media (max-width: 760px) {
  .app-shell { display: block; }
  .sidebar { max-height: none; border-right: 0; border-bottom: 1px solid #ddd; }
}
