:root {
  color: #1f2937;
  background: #f7f7f7;
  font: 12px system-ui, sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 1050px; }
header {
  height: 42px;
  padding: 11px 16px;
  background: #fff;
  border-bottom: 1px solid #b9c0c9;
  display: flex;
  justify-content: space-between;
}
header strong { color: #344054; }
#status { color: #667085; }

#app-shell {
  display: grid;
  grid-template-columns: minmax(410px, 480px) minmax(620px, 1fr);
  gap: 8px;
  height: calc(100vh - 42px);
  padding: 10px 5px 5px;
}
#sidebar {
  min-width: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding-top: 5px;
}
#workspace {
  min-width: 0;
  display: grid;
  grid-template-rows: 290px minmax(0, 1fr);
  gap: 7px;
}

.panel {
  min-width: 0;
  background: #fff;
  border: 1px solid #b9c0c9;
  border-radius: 4px;
  padding: 10px 8px 8px;
}
h2 {
  display: table;
  margin: -19px 0 8px;
  padding: 0 4px;
  color: #344054;
  background: #f7f7f7;
  font-size: 12px;
  font-weight: 600;
}

button,
select,
input,
textarea {
  min-height: 27px;
  padding: 3px 6px;
  color: #182230;
  background: #fff;
  border: 1px solid #aeb6c2;
  border-radius: 3px;
  font: inherit;
}
button { cursor: pointer; }
button:hover:not(:disabled) { border-color: #3e63dd; background: #f0f4ff; }
button:focus-visible,
select:focus-visible,
input:focus-visible,
textarea:focus-visible { outline: 2px solid #8098f9; outline-offset: 1px; }
button:disabled { color: #98a2b3; cursor: default; }
label { color: #344054; }
input[type="number"] { appearance: textfield; -moz-appearance: textfield; }
input[type="number"]::-webkit-inner-spin-button { appearance: none; margin: 0; }

.system-grid,
.controller-workspace { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.system-actions { display: grid; gap: 5px; align-content: start; }
.system-actions > select,
.system-actions > button { width: 100%; }
.file-row { display: flex; gap: 4px; }
.file-row #plant-file { flex: 1; }
.help-button {
  flex: 0 0 24px;
  width: 24px;
  min-width: 24px;
  height: 24px;
  min-height: 24px;
  padding: 0;
  font-weight: 700;
  line-height: 22px;
}
.compact-form {
  display: grid;
  grid-template-columns: 45px 1fr 19px;
  gap: 4px;
  align-items: center;
}
.compact-form label { display: contents; }
.compact-form input { width: 100%; min-width: 0; }

.controller-workspace { grid-template-columns: 3fr 2fr; gap: 16px; }
.controller-main { min-width: 0; }
.controller-detail { min-width: 0; }
.controller-switcher {
  display: grid;
  grid-template-columns: repeat(3, 42px);
  justify-content: center;
  gap: 5px;
  margin-bottom: 10px;
  text-align: center;
}
.controller-choice { display: grid; gap: 3px; }
.controller-choice button { min-height: 32px; font-weight: 600; }
.controller-choice button.active { color: #fff; background: #3e63dd; border-color: #3e63dd; }
.controller-choice label { display: flex; justify-content: center; gap: 3px; font-size: 11px; }
.block-list {
  height: 255px;
  margin-bottom: 5px;
  padding: 2px;
  overflow: auto;
  background: #fff;
  border: 1px solid #b9c0c9;
  border-radius: 3px;
}
.block-list button {
  display: block;
  width: 100%;
  margin: 0;
  padding: 5px;
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: 2px;
}
.block-list button:nth-child(even):not(.selected) { background: #f8fafc; }
.block-list button.selected { background: #dbe4ff; }
#block-type { width: 100%; }
.button-row { display: flex; gap: 4px; margin-top: 4px; }
.button-row button { flex: 1; min-width: 0; }
#optimize { width: 100%; margin-top: 4px; }
.parameter-editor { padding-top: 7px; }
.parameter-title { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }
.parameter-title h3 { flex: 1; margin: 0; font-size: 12px; }
.parameter-editor > label {
  display: grid;
  grid-template-columns: minmax(75px, 1fr) minmax(70px, 1fr);
  gap: 4px;
  align-items: center;
  margin-bottom: 5px;
}
.parameter-editor input { width: 100%; min-width: 0; }

.stability {
  margin-bottom: 6px;
  padding: 5px;
  background: #f2f4f7;
  border-radius: 4px;
  font-weight: 700;
}
.stability.ok { color: #067647; background: #ecfdf3; }
.stability.fail { color: #b42318; background: #fef3f2; }
#targets-form {
  display: grid;
  grid-template-columns: 1fr 62px 12px 1fr 22px;
  gap: 5px;
  align-items: center;
}
#targets-form input { width: 100%; min-width: 0; }
.metric-value.ok { color: #067647; font-weight: 700; }
.metric-value.fail { color: #b42318; font-weight: 700; }

.top-panels {
  display: grid;
  grid-template-columns: 245px minmax(400px, 1fr);
  gap: 7px;
  min-height: 0;
}
.response-panel,
.time-panel { min-height: 0; }
.response-panel #response-options label {
  display: grid;
  grid-template-columns: 76px 18px 1fr;
  align-items: center;
  margin: 5px 0;
  cursor: pointer;
}
.response-panel .formula { margin-right: 7px; color: #475467; text-align: right; }
input[type="radio"] {
  appearance: none;
  width: 15px;
  height: 15px;
  min-height: 15px;
  margin: 0;
  padding: 0;
  border: 1px solid #667085;
  border-radius: 50%;
  background: #fff;
  cursor: pointer;
}
input[type="radio"]:checked {
  border-color: #667085;
  background: radial-gradient(circle, #101828 0 38%, #fff 42% 100%);
}
.check { user-select: none; }
.time-toolbar {
  display: flex;
  gap: 7px;
  align-items: center;
  margin-bottom: 6px;
}
.time-toolbar label { min-width: 0; }
.time-toolbar .transfer-field { flex: 1; }
.time-toolbar select { width: 100%; min-width: 0; }
.time-toolbar .check,
.time-toolbar .duration-field { display: flex; align-items: center; gap: 3px; white-space: nowrap; }
#duration { width: 68px; }
.plot-panel { min-height: 0; padding: 0; overflow: hidden; }
#bode { height: 100%; display: grid; grid-template-rows: 1fr 1fr; }
#complex { display: none; height: 100%; }
#complex.nyquist { width: min(100%, 680px); margin: 0 auto; }
.plot { width: 100%; min-width: 0; }
.time-plot { height: 232px; }

dialog {
  width: min(560px, 90vw);
  color: #1f2937;
  background: #fff;
  border: 1px solid #98a2b3;
  border-radius: 5px;
  box-shadow: 0 8px 28px #0004;
}
dialog::backdrop { background: #18223066; }
.dialog-form { display: grid; gap: 9px; }
.dialog-form h2 {
  margin: 0 0 3px;
  padding: 0;
  background: #fff;
}
.dialog-form > label { display: grid; gap: 3px; }
.dialog-copy p { margin: 0 0 9px; }
.dialog-note { margin: 0; color: #475467; line-height: 1.45; }
textarea { resize: vertical; font-family: ui-monospace, monospace; }
.dialog-actions { display: flex; justify-content: end; gap: 6px; }
.settings-fields { display: grid; gap: 7px; }
.settings-fields label { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; align-items: center; }
.formula-help { font-size: 13px; line-height: 1.6; }
.diagram-dialog { width: min(720px, 94vw); }
.closed-loop-diagram { width: 100%; height: auto; }
.diagram-lines { fill: #fff; stroke: #344054; stroke-width: 1.6; }
.diagram-lines path { fill: none; marker-end: url(#arrow); }
.diagram-lines text,
.diagram-labels { fill: #344054; stroke: none; font: 15px system-ui, sans-serif; }
.diagram-lines text { text-anchor: middle; }
.diagram-key { margin: 0; text-align: center; color: #475467; }
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 1100px) {
  #app-shell { grid-template-columns: 410px minmax(620px, 1fr); }
  .controller-workspace { grid-template-columns: 58% 42%; gap: 10px; }
}
