:root {
  color-scheme: light;
  --bg: #eef2f5;
  --panel: #ffffff;
  --panel-2: #f8fafb;
  --control: #ffffff;
  --ink: #182127;
  --muted: #64717c;
  --line: #d5dde3;
  --line-strong: #b8c4cc;
  --accent: #c97619;
  --accent-dark: #8b4a0b;
  --accent-soft: #fff2df;
  --ok: #167a44;
  --warn: #b56a05;
  --bad: #bd2e2e;
  --blue: #2369c9;
  --green: #24935a;
  --red: #dc352e;
  --shadow: 0 12px 28px rgba(27, 39, 47, 0.08);
  --radius: 8px;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #101417;
  --panel: #171d22;
  --panel-2: #11171c;
  --control: #11171c;
  --ink: #e7edf2;
  --muted: #9aa7b1;
  --line: #2d3841;
  --line-strong: #44515c;
  --accent: #d99034;
  --accent-dark: #f1b25c;
  --accent-soft: #302417;
  --ok: #63c98d;
  --warn: #e1a64f;
  --bad: #e06d6d;
  --blue: #75aaff;
  --green: #70d99f;
  --red: #ff7771;
  --shadow: 0 12px 28px rgba(0, 0, 0, 0.34);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", Arial, sans-serif;
  font-size: 13px;
  line-height: 1.42;
}

button,
input,
select,
textarea {
  font: inherit;
}

button,
.file-button {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--control);
  color: var(--ink);
  padding: 7px 11px;
  cursor: pointer;
}

button:hover,
.file-button:hover {
  border-color: var(--accent);
}

button.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

input,
select,
textarea {
  width: 100%;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--control);
  color: var(--ink);
  padding: 7px 9px;
}

textarea {
  resize: vertical;
  font-family: Consolas, "Courier New", monospace;
  font-size: 12px;
  line-height: 1.35;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  outline: 2px solid rgba(201, 118, 25, 0.24);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

th,
td {
  border: 1px solid var(--line);
  padding: 7px 8px;
  text-align: right;
}

th:first-child,
td:first-child {
  text-align: left;
}

th {
  background: var(--panel-2);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-logo {
  width: 150px;
  height: 40px;
  flex: 0 0 auto;
  object-fit: contain;
}

.brand h1 {
  margin: 0;
  font-size: 19px;
  line-height: 1.1;
}

.brand p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
}

.topbar-actions > button,
.topbar .file-button {
  height: 34px;
  min-height: 34px;
  display: inline-flex;
  align-items: center;
}

.file-button {
  position: relative;
  display: inline-flex;
  align-items: center;
  overflow: hidden;
}

.topbar .file-button {
  justify-content: center;
  margin: 0;
  color: var(--ink);
  font-weight: 600;
  line-height: 1;
}

.file-button input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.icon-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.theme-swatch {
  width: 15px;
  height: 15px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: linear-gradient(90deg, var(--ink) 0 50%, var(--bg) 50% 100%);
}

.workspace {
  display: grid;
  grid-template-columns: 360px minmax(620px, 1fr) 390px;
  gap: 12px;
  padding: 12px;
  min-height: 0;
}

.config-panel,
.analysis-panel {
  position: sticky;
  top: 12px;
  align-self: start;
  max-height: calc(100vh - 24px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.graph-panel {
  min-width: 0;
  display: grid;
  align-content: start;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.panel-section,
.analysis-block {
  padding: 12px;
  border-bottom: 1px solid var(--line);
}

.panel-section:last-child,
.analysis-block:last-child {
  border-bottom: 0;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

h2,
h3 {
  margin: 0;
}

h2 {
  font-size: 15px;
}

h3 {
  margin-bottom: 10px;
  font-size: 13px;
}

label {
  display: grid;
  grid-template-columns: 138px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

label span {
  min-width: 0;
}

.button-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 8px;
}

.status-message,
.mini-status {
  min-height: 22px;
  display: inline-flex;
  align-items: center;
  border-radius: 6px;
  padding: 3px 7px;
  background: var(--panel-2);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.status-message.ok {
  color: var(--ok);
}

.status-message.error {
  color: var(--bad);
}

.tabbar {
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
}

.tab {
  min-width: 132px;
  min-height: 42px;
  border: 0;
  border-right: 1px solid var(--line);
  border-radius: 0;
  background: var(--panel);
  color: var(--ink);
  font-weight: 700;
}

.tab.active {
  box-shadow: inset 0 -3px 0 var(--accent);
  color: var(--accent-dark);
  background: var(--panel-2);
}

.graph-controls {
  display: grid;
  grid-template-columns: repeat(8, minmax(92px, 1fr));
  gap: 10px;
  align-items: end;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}

.graph-controls label {
  display: grid;
  grid-template-columns: 1fr;
  gap: 4px;
  margin: 0;
}

.graph-controls .checkbox-label {
  min-height: 34px;
  grid-template-columns: auto 1fr;
  align-items: center;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--control);
  color: var(--ink);
}

.checkbox-label input {
  width: auto;
  min-height: 0;
}

.canvas-frame {
  padding: 12px 12px 8px;
  min-width: 0;
}

#mainChart {
  display: block;
  width: 100%;
  height: min(56vh, 620px);
  min-height: 420px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  cursor: crosshair;
  touch-action: none;
}

.summary-grid {
  display: grid;
  grid-template-columns: 1.05fr 1fr 1.05fr;
  gap: 12px;
  padding: 12px;
  border-top: 1px solid var(--line);
}

.summary-grid section {
  min-width: 0;
}

.metric-list {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 7px 10px;
  margin: 0;
  font-variant-numeric: tabular-nums;
}

.metric-list dt {
  color: var(--muted);
  font-weight: 700;
}

.metric-list dd {
  margin: 0;
  text-align: right;
}

.warning-list,
.assumption-list {
  margin: 0;
  padding-left: 18px;
}

.warning-list li,
.assumption-list li {
  margin-bottom: 7px;
}

.warning-list .ok {
  color: var(--ok);
}

.warning-list .warn {
  color: var(--warn);
}

.warning-list .bad {
  color: var(--bad);
}

.guide-summary {
  margin: 0 0 10px;
  color: var(--muted);
}

.guide-details {
  display: grid;
  grid-template-columns: 96px 1fr;
  gap: 6px 10px;
  margin: 0 0 10px;
  font-size: 12px;
}

.guide-details dt {
  color: var(--muted);
  font-weight: 700;
}

.guide-details dd {
  margin: 0;
}

.point-table th,
.point-table td {
  padding: 5px 6px;
  font-size: 12px;
}

.point-table tr.active-point td {
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-weight: 700;
}

.point-table td:last-child {
  font-family: Consolas, "Courier New", monospace;
}

.snippet-block pre {
  min-height: 360px;
  max-height: 52vh;
  margin: 0;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #11171c;
  color: #d7e1e8;
  padding: 11px;
  font: 12px/1.48 Consolas, "Courier New", monospace;
  white-space: pre;
}

.num-good {
  color: var(--ok);
  font-weight: 700;
}

.num-warn {
  color: var(--warn);
  font-weight: 700;
}

.num-bad {
  color: var(--bad);
  font-weight: 700;
}

@media (max-width: 1360px) {
  .workspace {
    grid-template-columns: 320px minmax(0, 1fr);
  }

  .analysis-panel {
    position: static;
    grid-column: 1 / -1;
    max-height: none;
  }
}

@media (max-width: 980px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar-actions {
    justify-content: flex-start;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .config-panel {
    position: static;
    max-height: none;
  }

  .graph-controls,
  .summary-grid {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 640px) {
  .workspace {
    padding: 8px;
  }

  label,
  .graph-controls,
  .summary-grid {
    grid-template-columns: 1fr;
  }

  .tab {
    min-width: 118px;
  }

  #mainChart {
    min-height: 360px;
  }
}
