:root {
  --bg: #f3f6f4;
  --surface: #ffffff;
  --surface-2: #eef3f1;
  --ink: #18211f;
  --muted: #60706b;
  --line: #d8e1dd;
  --accent: #087f68;
  --accent-strong: #006852;
  --coral: #c8553d;
  --gold: #b98318;
  --blue: #386fa4;
  --shadow: 0 14px 40px rgba(24, 33, 31, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  height: 100%;
}

body {
  margin: 0;
  font-family: "Segoe UI", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  height: 100%;
  overflow: hidden;
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  padding: 0 11px;
}

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

.icon-button {
  width: 32px;
  min-width: 32px;
  height: 32px;
  min-height: 32px;
  display: inline-grid;
  place-items: center;
  border-radius: 50%;
  padding: 0;
  font-weight: 700;
  line-height: 1;
}

button:disabled,
input:disabled {
  opacity: 0.62;
  cursor: not-allowed;
}

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

.primary-button:hover {
  background: var(--accent-strong);
}

.shell {
  height: 100vh;
  padding: 10px 12px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 10px;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin: 0 auto;
  max-width: 1440px;
  width: 100%;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background:
    linear-gradient(90deg, transparent 43%, #fff 43% 57%, transparent 57%),
    linear-gradient(180deg, var(--accent) 0 48%, var(--coral) 48% 100%);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.55);
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 20px;
  line-height: 1.1;
  letter-spacing: 0;
}

.brand p {
  font-size: 12px;
}

.brand p,
.muted,
.chart-header p,
.sources {
  color: var(--muted);
}

.source-status {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  padding: 6px 10px;
  max-width: min(50vw, 520px);
  min-width: 150px;
  text-align: center;
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.source-status[data-mode="ok"] {
  border-color: rgba(8, 127, 104, 0.35);
  color: var(--accent-strong);
}

.source-status[data-mode="bad"] {
  border-color: rgba(200, 85, 61, 0.35);
  color: var(--coral);
}

.source-status[data-mode="working"] {
  border-color: rgba(185, 131, 24, 0.35);
  color: var(--gold);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(360px, 410px) minmax(0, 1fr);
  gap: 10px;
  max-width: 1440px;
  width: 100%;
  height: 100%;
  margin: 0 auto;
  align-items: stretch;
  min-height: 0;
  overflow: hidden;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.controls-panel,
.result-panel,
.details-panel {
  padding: 10px;
  min-height: 0;
  overflow: hidden;
}

.controls-panel {
  position: relative;
  padding-bottom: 48px;
}

.result-panel,
.details-panel {
  height: 100%;
}

.details-panel {
  position: relative;
  padding-bottom: 48px;
}

.controls-panel form {
  display: grid;
  grid-template-rows: auto auto auto auto auto auto auto;
  gap: 6px;
  height: 100%;
  min-height: 0;
}

.results-column {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(290px, 340px);
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 10px;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

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

.section-title:not(:first-child) {
  margin-top: 2px;
}

h2 {
  font-size: 13px;
  line-height: 1.2;
}

.lookup-grid {
  display: grid;
  grid-template-columns: 104px minmax(0, 1fr) 74px;
  gap: 7px;
  align-items: end;
}

.lookup-grid button {
  grid-column: auto;
}

.field-grid {
  display: grid;
  gap: 6px;
}

.field-grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

label {
  display: grid;
  gap: 3px;
  color: var(--muted);
  font-size: 11px;
  min-width: 0;
}

input,
select {
  width: 100%;
  height: 30px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  padding: 0 8px;
  font-size: 13px;
  min-width: 0;
}

input:focus,
select:focus,
button:focus {
  outline: 3px solid rgba(8, 127, 104, 0.16);
  outline-offset: 1px;
}

.compound-summary {
  display: grid;
  grid-template-columns: 58px 1fr;
  gap: 9px;
  align-items: center;
  min-height: 62px;
  margin-top: 0;
  padding-top: 7px;
  border-top: 1px solid var(--line);
  min-width: 0;
}

.compound-image {
  width: 52px;
  height: 52px;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.compound-image.empty {
  display: block;
}

.compound-text h3 {
  font-size: 13px;
  line-height: 1.25;
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
}

.chips span {
  display: inline-flex;
  align-items: center;
  min-height: 21px;
  border-radius: 999px;
  background: var(--surface-2);
  padding: 0 7px;
  font-size: 11px;
  color: var(--ink);
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 0;
}

.controls-panel .button-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 10px;
}

.details-panel .button-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 10px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 0 10px;
  font-size: 12px;
  background: var(--surface-2);
  color: var(--muted);
}

.badge.ok {
  background: rgba(8, 127, 104, 0.11);
  color: var(--accent-strong);
}

.badge.warn {
  background: rgba(185, 131, 24, 0.13);
  color: #7b540d;
}

.badge.bad {
  background: rgba(200, 85, 61, 0.13);
  color: var(--coral);
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
  margin: 8px 0;
}

.stat {
  min-height: 70px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  background: #fbfcfc;
  display: grid;
  align-content: space-between;
  gap: 3px;
}

.stat span,
.stat small {
  color: var(--muted);
  font-size: 11px;
}

.stat strong {
  font-size: 15px;
  line-height: 1.1;
  overflow-wrap: anywhere;
}

.chart-frame {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #fbfcfc;
  height: calc(100% - 104px);
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.chart-header {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: start;
  padding: 9px 10px 0;
}

.chart-header h3 {
  font-size: 13px;
}

.chart-header p {
  font-size: 11px;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  color: var(--muted);
  font-size: 11px;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.line {
  width: 16px;
  height: 3px;
  border-radius: 99px;
  background: var(--accent);
}

.line.low {
  background: var(--blue);
}

.line.high {
  background: var(--coral);
}

.curve-chart {
  min-height: 0;
  padding: 0 8px 6px;
  display: flex;
  align-items: stretch;
}

.curve-chart svg {
  width: 100%;
  height: 100%;
  display: block;
}

.plot-bg {
  fill: #fff;
}

.grid-line {
  stroke: #dfe7e3;
  stroke-width: 1;
}

.grid-line.vertical {
  stroke-dasharray: 4 5;
}

.axis-label,
.axis-title {
  fill: var(--muted);
  font-size: 12px;
}

.max-c-line {
  stroke: var(--coral);
  stroke-width: 2;
  stroke-dasharray: 7 6;
  opacity: 0.85;
}

.max-c-label {
  fill: var(--coral);
  font-size: 12px;
  font-weight: 700;
}

.allowed-c-line {
  stroke: var(--gold);
  stroke-width: 2;
  stroke-dasharray: 3 5;
  opacity: 0.95;
}

.allowed-c-label {
  fill: #7b540d;
  font-size: 12px;
  font-weight: 700;
}

.curve {
  fill: none;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.curve.nominal {
  stroke: var(--accent);
}

.curve.low {
  stroke: var(--blue);
  opacity: 0.72;
}

.curve.high {
  stroke: var(--coral);
  opacity: 0.72;
}

.details-table {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.details-table div {
  display: grid;
  gap: 3px;
  min-height: 31px;
  padding: 5px;
  background: #fff;
}

.details-table span {
  color: var(--muted);
  font-size: 10px;
}

.details-table strong {
  font-size: 11px;
  line-height: 1.25;
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.note-list {
  display: grid;
  gap: 5px;
  margin-top: 6px;
}

.note-list p {
  border-left: 3px solid var(--gold);
  background: #fff8e8;
  border-radius: 6px;
  padding: 6px 7px;
  color: #654608;
  font-size: 11px;
  line-height: 1.28;
}

.sources {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  grid-column: 1 / -1;
  padding: 0 2px;
  font-size: 11px;
  align-self: end;
}

.sources a {
  color: var(--accent-strong);
}

.app-credit {
  margin-left: auto;
  color: var(--muted);
  font-size: 10px;
  white-space: nowrap;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(24, 33, 31, 0.38);
}

.modal-backdrop[hidden] {
  display: none;
}

.modal-panel {
  width: min(940px, calc(100vw - 36px));
  max-height: min(680px, calc(100vh - 36px));
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 20px 70px rgba(24, 33, 31, 0.24);
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfc;
}

.modal-header h2 {
  font-size: 18px;
}

.modal-header p {
  color: var(--muted);
  font-size: 12px;
  margin-top: 3px;
}

.modal-body {
  min-height: 0;
  overflow: auto;
  padding: 14px 16px 16px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.modal-body section {
  display: grid;
  gap: 7px;
  align-content: start;
  min-width: 0;
}

.modal-body h3 {
  font-size: 13px;
}

.modal-body p {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.42;
}

.modal-body pre {
  margin: 0;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #f7faf8;
  overflow: auto;
}

.modal-body code {
  font-family: Consolas, "Courier New", monospace;
  font-size: 11px;
  line-height: 1.42;
  color: #20312d;
}

@media (max-width: 1080px) {
  body {
    overflow: auto;
  }

  .shell {
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }

  .workspace {
    grid-template-columns: 1fr;
    height: auto;
    overflow: visible;
  }

  .controls-panel {
    position: static;
  }

  .controls-panel,
  .result-panel,
  .details-panel {
    overflow: visible;
  }

  .controls-panel form,
  .results-column {
    height: auto;
  }

  .results-column {
    grid-template-columns: 1fr;
  }

  .chart-frame {
    height: auto;
  }

  .curve-chart {
    min-height: 280px;
  }

  .modal-body {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .shell {
    padding: 14px;
  }

  .topbar,
  .chart-header {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar-actions {
    width: 100%;
  }

  .source-status {
    max-width: none;
    flex: 1;
  }

  .field-grid.two,
  .stat-grid,
  .details-table {
    grid-template-columns: 1fr;
  }

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

  .modal-backdrop {
    padding: 10px;
  }

  .modal-panel {
    width: calc(100vw - 20px);
    max-height: calc(100vh - 20px);
  }
}
