:root {
  color-scheme: light;
  --bg: #eeeeee;
  --panel: #f7f7f7;
  --border: #aaaaaa;
  --border-soft: #cccccc;
  --text: #202020;
  --muted: #5f5f5f;
  --button: #f4f4f4;
  --accent: #3b73b9;
  --accent-dark: #285b96;
  --error: #9a1d1d;
  --warning: #7a5500;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: Arial, Helvetica, sans-serif; color: var(--text); background: var(--bg); font-size: 13px; }
.app-header { min-height: 58px; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 8px 14px; background: #f5f5f5; border-bottom: 1px solid #b7b7b7; }
.app-title-line { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.app-title { font-size: 22px; font-weight: 700; }
.version-badge { font-size: 10px; font-weight: 700; color: #555; background: #e7e7e7; border: 1px solid #aaa; border-radius: 10px; padding: 1px 6px; white-space: nowrap; }
.app-subtitle { color: var(--muted); margin-top: 2px; }
.header-actions { display: flex; align-items: center; justify-content: flex-end; gap: 10px; flex-wrap: wrap; }
.header-link { color: #2f5f98; text-decoration: none; border: 1px solid #a8b6c7; background: #fbfbfb; border-radius: 3px; padding: 4px 8px; font-size: 12px; white-space: nowrap; }
.header-link:hover { background: #eef4fb; text-decoration: underline; }
.runtime-header { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12px; text-align: right; }
.runtime-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; background: #999; }
.runtime-dot.ready { background: #2d8a42; }
.runtime-dot.loading { background: #c68b22; }
.runtime-dot.error { background: #b02b2b; }
.tabbar { display: flex; align-items: end; gap: 2px; padding: 5px 8px 0; background: #dedede; border-bottom: 1px solid #999; overflow-x: auto; }
.tab-button { border: 1px solid #aaa; border-bottom: 0; border-radius: 3px 3px 0 0; background: #e8e8e8; padding: 7px 13px; cursor: pointer; white-space: nowrap; color: #222; }
.tab-button.active { background: #fafafa; font-weight: 600; position: relative; top: 1px; }
.app-main { background: #fafafa; min-height: calc(100vh - 94px); }
.tab-panel { display: none; padding: 8px 10px 12px; }
.tab-panel.active { display: block; }
.settings-grid { display: grid; grid-template-columns: repeat(4, minmax(225px, 1fr)); gap: 10px; align-items: start; }
.groupbox, .subgroup { background: #f7f7f7; border: 1px solid #aaa; padding: 9px 9px 8px; min-width: 0; }
.groupbox legend, .subgroup legend { padding: 0 5px; font-weight: 600; }
.row { display: grid; grid-template-columns: minmax(120px, 1fr) minmax(82px, 105px); gap: 8px; align-items: center; margin: 5px 0; }
.row input, .row select { width: 100%; }
input, select, button { font: inherit; }
input, select { background: white; border: 1px solid #999; border-radius: 2px; padding: 3px 5px; min-height: 25px; }
input[readonly] { background: #eeeeee; color: #333; }
.button { border: 1px solid #888; border-radius: 3px; padding: 5px 10px; background: linear-gradient(#fff, #e7e7e7); cursor: pointer; color: #222; }
.button:hover:not(:disabled) { background: linear-gradient(#fff, #dddddd); }
.button:disabled { opacity: .55; cursor: default; }
.button.primary { font-weight: 700; border-color: #5c7190; }
.button.small { padding: 4px 8px; font-size: 12px; }
.button-row { margin: 7px 0; display: flex; gap: 8px; }
.button-row.centered { justify-content: center; }
.small-note { color: var(--muted); font-size: 11px; line-height: 1.3; margin-top: 8px; }
.plot-grid { display: grid; gap: 7px; margin-top: 7px; }
.plot-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.plot-grid.six { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.plot-panel {
  min-width: 0;
  min-height: 290px;
  height: 34vh;
  position: relative;
  overflow: hidden;
  background: transparent;
  border: 0;
  border-radius: 0;
  padding: 0;
  box-shadow: none;
}
.plot-grid.six .plot-panel { min-height: 265px; height: 32vh; }
.phase-grid .plot-panel, .compressor-grid .plot-panel { min-height: 430px; height: 62vh; }
.sweep-plot { min-height: 380px; height: 52vh; }
.results-control-layout { display: grid; grid-template-columns: 330px minmax(420px, 1fr) 255px; gap: 12px; align-items: start; }
.output-summary label { display: grid; grid-template-columns: 210px 105px; gap: 5px; margin: 3px 0; align-items: center; }
.output-summary output { display: inline-block; background: white; border: 1px solid #aaa; padding: 3px 6px; min-height: 24px; text-align: right; }
.output-summary .button { margin-top: 5px; }
.result-actions { display: grid; gap: 5px; }
.inline, .inline-line { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
.inline-line input.short, input.short { width: 78px; }
input.medium { width: 110px; }
input.tiny { width: 58px; }
progress { width: 150px; height: 16px; }
.subgroup { margin-top: 2px; }
.terms-box { display: flex; flex-direction: column; gap: 5px; }
.terms-box hr { width: 100%; border: 0; border-top: 1px solid #bbb; }
.terms-box select { width: 100%; margin-top: 3px; }
.message { margin: 6px 0; padding: 6px 8px; border: 1px solid #a7a7a7; background: #f5f5f5; }
.message.error { border-color: #be8181; background: #fff0f0; color: var(--error); white-space: pre-wrap; }
.message.warning { border-color: #d1b46a; background: #fff9e7; color: var(--warning); }
.compact-controls { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 5px 2px; }
.compact-controls label { display: flex; align-items: center; gap: 5px; }
.equation-text { margin-left: 8px; }
.coefficient-line, .metrics-text, .status-line { margin: 5px 2px; line-height: 1.45; }
.sweep-controls { display: grid; gap: 5px; }
.sweep-row { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }
.sweep-row label { display: flex; align-items: center; gap: 5px; }
#sweep-preview { color: var(--muted); }
.table-wrap { margin-top: 6px; overflow-x: auto; border: 1px solid #bbb; background: white; max-height: 180px; overflow-y: auto; }
table { border-collapse: collapse; width: 100%; font-size: 12px; }
th, td { border-right: 1px solid #d0d0d0; border-bottom: 1px solid #dedede; padding: 4px 6px; text-align: center; white-space: nowrap; }
th { position: sticky; top: 0; background: #ececec; z-index: 1; }
tr.warning td { background: #fff4da; }
dialog { width: min(880px, 92vw); max-height: 82vh; border: 1px solid #777; border-radius: 4px; padding: 0; }
dialog::backdrop { background: rgba(0,0,0,.25); }
.dialog-head { position: sticky; top: 0; display: flex; justify-content: space-between; align-items: center; padding: 8px 10px; background: #ededed; border-bottom: 1px solid #aaa; }
dialog pre { padding: 10px 14px; margin: 0; white-space: pre-wrap; font-family: Consolas, "Courier New", monospace; font-size: 12px; line-height: 1.4; }
@media (max-width: 1100px) {
  .settings-grid { grid-template-columns: repeat(2, minmax(230px, 1fr)); }
  .results-control-layout { grid-template-columns: 1fr 1fr; }
  .terms-box { grid-column: 1 / -1; flex-direction: row; flex-wrap: wrap; }
  .plot-grid.six { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 700px) {
  .app-header {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    align-items: start;
    gap: 7px;
    padding: 8px 10px 9px;
    width: 100%;
    overflow: visible;
  }
  .app-header > div:first-child { min-width: 0; width: 100%; }
  .app-title { font-size: 20px; }
  .app-subtitle { font-size: 11px; line-height: 1.25; white-space: normal; overflow-wrap: anywhere; }
  .header-actions {
    width: 100%;
    min-width: 0;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
    justify-content: stretch;
    align-items: stretch;
  }
  .header-link {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-width: 0;
    min-height: 30px;
    padding: 4px 6px;
    font-size: 11px;
    white-space: normal;
    text-align: center;
    line-height: 1.15;
  }
  .runtime-header {
    grid-column: 1 / -1;
    display: flex;
    width: 100%;
    min-width: 0;
    align-items: flex-start;
    justify-content: flex-start;
    text-align: left;
    gap: 7px;
    padding: 2px 1px 0;
  }
  .runtime-dot { flex: 0 0 9px; margin-top: 2px; }
  #runtime-status {
    min-width: 0;
    white-space: normal;
    overflow-wrap: anywhere;
    word-break: normal;
  }
  .tabbar { padding-left: 6px; padding-right: 6px; }
  .settings-grid, .plot-grid.two, .plot-grid.six, .results-control-layout { grid-template-columns: 1fr; }
  .plot-panel, .plot-grid.six .plot-panel { height: 360px; }
}

.alert-dialog { width: min(650px, 90vw); }
.alert-dialog .dialog-head { border-top: 5px solid var(--error); }
.alert-dialog.warning-dialog .dialog-head { border-top-color: #c08a16; }
.alert-dialog-content { padding: 16px 18px; white-space: pre-wrap; font-size: 13px; line-height: 1.45; }
.alert-dialog.error-dialog .alert-dialog-content { color: var(--error); }
.alert-dialog.warning-dialog .alert-dialog-content { color: #654600; }
.alert-dialog-details { margin: 0 18px 16px; border-top: 1px solid #ccc; padding-top: 8px; }
.alert-dialog-details summary { cursor: pointer; color: var(--muted); }
.alert-dialog-details pre { max-height: 220px; overflow: auto; background: #f5f5f5; border: 1px solid #ddd; padding: 8px; font-size: 11px; }

/* Keep Plotly's compact toolbar in the reserved upper-right strip. */
.js-plotly-plot .modebar-container { top: 5px !important; right: 6px !important; z-index: 10001 !important; }
.js-plotly-plot .modebar { background: rgba(255,255,255,0.78) !important; border: 1px solid rgba(100,100,100,0.18); border-radius: 3px; }


/* The outer plot container is deliberately invisible; only the axes frame is shown. */
.plot-panel > .js-plotly-plot,
.plot-panel > .plot-container,
.plot-panel .plot-container {
  border-radius: 0;
}

@media (max-width: 430px) {
  .tab-button { padding: 7px 10px; }
  .plot-panel, .plot-grid.six .plot-panel { height: 350px; }
}

/* Documentation page */
.doc-body { background: #f1f1f1; }
.doc-shell { max-width: 1120px; margin: 0 auto; background: white; min-height: 100vh; box-shadow: 0 0 0 1px #d3d3d3; }
.doc-header { padding: 20px 28px 16px; border-bottom: 1px solid #bbb; background: #f7f7f7; }
.doc-title { font-size: 28px; font-weight: 700; margin: 0; }
.doc-subtitle { color: var(--muted); margin-top: 4px; }
.doc-nav { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.doc-main { padding: 24px 30px 42px; font-size: 15px; line-height: 1.55; }
.doc-main h2 { margin-top: 1.8em; border-bottom: 1px solid #ccc; padding-bottom: 5px; color: #244f82; }
.doc-main h3 { margin-top: 1.4em; color: #333; }
.doc-main table { font-size: 14px; margin: 10px 0 18px; }
.doc-main th { position: static; text-align: left; }
.doc-main td { text-align: left; white-space: normal; vertical-align: top; }
.doc-main .equation { overflow-x: auto; padding: 9px 12px; background: #fafafa; border-left: 3px solid #8aa9cc; margin: 12px 0; }
.doc-main .scope-box { border: 1px solid #b7c8dc; background: #f4f8fc; padding: 12px 15px; margin: 14px 0; }
.doc-main .warning-box { border: 1px solid #d1b46a; background: #fff9e7; padding: 12px 15px; margin: 14px 0; }
.doc-main code { background: #f1f1f1; padding: 1px 4px; border-radius: 2px; }
.doc-footer { border-top: 1px solid #ccc; color: var(--muted); padding: 14px 30px 24px; font-size: 12px; }
@media (max-width: 700px) {
  .doc-main { padding: 18px 16px 30px; }
  .doc-header { padding: 16px; }
}
