:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ink: #14202b;
  --muted: #667382;
  --line: #d9e0e7;
  --accent: #0c7c59;
  --accent-dark: #075f45;
  --warn: #a15c00;
  --soft: #eef3f7;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.shell {
  display: grid;
  grid-template-columns: minmax(360px, 460px) minmax(0, 1fr);
  gap: 0;
  min-height: 100vh;
}

.control-panel {
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 24px;
}

.brand-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 22px;
  font-weight: 700;
}

h2 {
  font-size: 15px;
}

.brand-row p,
.tier-row p,
.empty {
  color: var(--muted);
}

.formula-note {
  margin-top: 4px;
  font-size: 12px;
}

.status-pill {
  min-width: 78px;
  text-align: center;
  padding: 5px 10px;
  border-radius: 6px;
  background: var(--soft);
  color: var(--muted);
  font-weight: 600;
}

.status-pill.running {
  color: var(--warn);
}

.status-pill.done {
  color: var(--accent-dark);
}

.grid-form,
.simple-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.simple-form {
  grid-template-columns: 1fr;
  gap: 16px;
}

.span-2 {
  grid-column: 1 / -1;
}

.segmented {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
}

.segmented label {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 34px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  color: var(--muted);
}

.segmented input {
  position: absolute;
  opacity: 0;
}

.segmented label:has(input:checked) {
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 1px 3px rgba(20, 32, 43, 0.12);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.field span,
.check span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

input,
select {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  background: #fff;
  color: var(--ink);
  font: inherit;
}

input:focus,
select:focus,
button:focus,
.download:focus {
  outline: 2px solid rgba(12, 124, 89, 0.25);
  outline-offset: 1px;
  border-color: var(--accent);
}

.file-drop {
  display: none;
  border: 1px dashed #9facba;
  border-radius: 8px;
  min-height: 64px;
  align-items: center;
  justify-content: center;
  background: var(--soft);
  color: var(--muted);
  font-weight: 700;
  cursor: pointer;
}

.file-drop input {
  display: none;
}

.file-drop.visible {
  display: flex;
}

.check {
  display: flex;
  gap: 8px;
  align-items: center;
}

.check input {
  width: 16px;
  min-height: 16px;
}

.primary,
.download {
  min-height: 40px;
  border: 0;
  border-radius: 6px;
  padding: 9px 14px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 700;
  text-decoration: none;
  text-align: center;
  cursor: pointer;
}

.primary:hover,
.download:hover {
  background: var(--accent-dark);
}

.x-link {
  color: var(--accent-dark);
  font-weight: 700;
  text-align: center;
  text-decoration: none;
}

.x-link:hover {
  text-decoration: underline;
}

.results {
  padding: 24px;
  overflow: auto;
}

.empty {
  min-height: calc(100vh - 48px);
  display: grid;
  place-items: center;
  text-align: center;
  font-size: 16px;
  padding: 24px;
}

.hidden {
  display: none;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.summary-grid article {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
}

.summary-grid span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  margin-bottom: 8px;
}

.summary-grid strong {
  font-size: 22px;
}

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

.tables {
  display: grid;
  gap: 18px;
}

.tables section {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.tables h2 {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.table-wrap {
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 680px;
}

th,
td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  background: #f8fafb;
}

td.num,
th.num {
  text-align: right;
  white-space: nowrap;
}

.market-title {
  max-width: 520px;
}

.sub {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

@media (max-width: 980px) {
  .shell {
    grid-template-columns: 1fr;
  }

  .control-panel {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

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

@media (max-width: 560px) {
  .control-panel,
  .results {
    padding: 16px;
  }

  .grid-form,
  .simple-form,
  .summary-grid {
    grid-template-columns: 1fr;
  }

  .span-2 {
    grid-column: auto;
  }

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

  .tier-row {
    align-items: stretch;
    flex-direction: column;
  }
}
