:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #17202a;
  --muted: #667085;
  --line: #d9dee7;
  --accent: #0f766e;
  --accent-strong: #115e59;
  --danger: #b42318;
  --code: #111827;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
}

.app-shell {
  width: min(1280px, 100%);
  margin: 0 auto;
  padding: 24px;
}

.workbench {
  display: grid;
  grid-template-columns: minmax(320px, 0.72fr) minmax(520px, 1.28fr);
  gap: 16px;
  align-items: stretch;
  min-height: calc(100vh - 48px);
}

.input-pane,
.result-pane {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  min-width: 0;
}

.input-pane {
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 14px;
}

.topbar,
.result-head,
.actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 24px;
  line-height: 1.2;
}

h2 {
  font-size: 18px;
}

p,
#status {
  color: var(--muted);
  font-size: 14px;
}

select,
textarea,
button {
  font: inherit;
}

select {
  min-width: 148px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 0 10px;
}

textarea {
  width: 100%;
  min-height: 360px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  line-height: 1.5;
  color: var(--text);
}

button {
  min-height: 40px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: 0 14px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}

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

button:disabled {
  cursor: wait;
  opacity: 0.65;
}

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

.result-pane {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  gap: 14px;
}

pre {
  margin: 0;
  white-space: pre-wrap;
  overflow: auto;
  min-width: 0;
  line-height: 1.5;
  font-family: Consolas, "Courier New", monospace;
}

#result {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  color: var(--code);
  background: #fbfcfe;
  max-height: 320px;
}

.costing-sheet {
  min-height: 520px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 12px;
}

.costing-sheet h2 {
  margin: 0 0 10px;
  padding: 8px 10px;
  border: 1px solid #b8c0cc;
  background: #edf1f5;
  font-size: 18px;
  text-align: center;
  letter-spacing: 0;
}

.costing-sheet h3 {
  margin: 18px 0 0;
  padding: 7px 9px;
  border: 1px solid #9ea8b5;
  border-bottom: 0;
  background: #dfe5ec;
  color: #1f2937;
  font-size: 14px;
  text-transform: uppercase;
}

.costing-sheet p {
  margin: 8px 0;
  color: var(--muted);
  font-size: 13px;
}

.sheet-empty {
  display: grid;
  min-height: 220px;
  place-items: center;
  color: var(--muted);
  text-align: center;
  border: 1px dashed var(--line);
  border-radius: 6px;
  padding: 18px;
}

.sheet-table-wrap {
  overflow-x: auto;
  border: 1px solid #9ea8b5;
  border-top: 0;
}

.sheet-table-wrap + .sheet-table-wrap {
  margin-top: 12px;
  border-top: 1px solid #9ea8b5;
}

.costing-sheet table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
  table-layout: auto;
  font-size: 12px;
}

.costing-sheet th,
.costing-sheet td {
  border: 1px solid #b8c0cc;
  padding: 6px 7px;
  vertical-align: top;
  line-height: 1.35;
  background: #fff;
}

.costing-sheet th {
  background: #f2f4f7;
  color: #111827;
  font-weight: 700;
  text-align: center;
}

.costing-sheet td.num {
  text-align: right;
  white-space: nowrap;
}

.costing-sheet tr:last-child td:first-child,
.costing-sheet td:first-child:only-child {
  font-weight: 700;
}

details {
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

summary {
  cursor: pointer;
  color: var(--muted);
}

#retrieval {
  max-height: 220px;
  margin-top: 10px;
  color: var(--muted);
}

@media (max-width: 860px) {
  .app-shell {
    padding: 12px;
  }

  .workbench {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .topbar,
  .actions,
  .result-head {
    align-items: stretch;
    flex-direction: column;
  }

  select,
  button {
    width: 100%;
  }
}
