:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1e222b;
  --border: #2a2f3a;
  --text: #e7eaf0;
  --muted: #9aa3b2;
  --accent: #6ea8fe;
  --accent-2: #4ade80;
  --warn: #f59e0b;
  --danger: #ef4444;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.45;
}

header {
  padding: 28px 24px 8px;
  max-width: 1100px;
  margin: 0 auto;
}

header h1 {
  margin: 0 0 4px;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

header .sub {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 16px 24px 48px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 18px;
}

.panel h2 {
  margin: 0 0 12px;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.panel.full-width {
  grid-column: 1 / -1;
}

.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 12px;
}

label {
  display: flex;
  flex-direction: column;
  font-size: 12px;
  color: var(--muted);
  gap: 4px;
}

label.inline {
  flex-direction: row;
  align-items: center;
  gap: 6px;
  color: var(--text);
}

.hint {
  font-size: 10px;
  color: var(--muted);
  opacity: 0.7;
}

input[type="number"] {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 7px 9px;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  outline: none;
  transition: border-color 0.1s ease;
  width: 100%;
}

input[type="number"]:focus {
  border-color: var(--accent);
}

input[type="text"],
input[type="url"] {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 7px 9px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.1s ease;
  width: 100%;
}

input[type="text"]:focus,
input[type="url"]:focus {
  border-color: var(--accent);
}

input[type="checkbox"] {
  accent-color: var(--accent);
}

textarea {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 13px;
  font-family: inherit;
  line-height: 1.5;
  resize: vertical;
  width: 100%;
  min-height: 60px;
  outline: none;
  transition: border-color 0.1s ease;
}

textarea:focus { border-color: var(--accent); }

select {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 7px 9px;
  font-size: 14px;
  outline: none;
  min-width: 220px;
  cursor: pointer;
}

select:focus { border-color: var(--accent); }

button {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 7px 12px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease;
}

button:hover {
  background: #252a35;
  border-color: var(--accent);
}

button:active { transform: translateY(1px); }

.scenarios-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 12px;
}

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

.link-row input { flex: 1; }

#scenarioLinkOpen {
  color: var(--accent);
  text-decoration: none;
  font-size: 12px;
  white-space: nowrap;
}

#scenarioLinkOpen:hover { text-decoration: underline; }

label.full { grid-column: 1 / -1; }

.tooltip {
  position: absolute;
  z-index: 200;
  background: #0a0d12;
  color: var(--text);
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: 10px 14px;
  font-size: 12px;
  line-height: 1.55;
  max-width: 380px;
  white-space: pre-line;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  font-variant-numeric: tabular-nums;
  animation: tip-in 0.12s ease;
  pointer-events: none;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

@keyframes tip-in {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

[data-calc]:hover { cursor: help; }

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--accent);
  color: #0b1018;
  padding: 9px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  z-index: 100;
  box-shadow: 0 6px 18px rgba(0,0,0,0.35);
  animation: toast-in 0.16s ease;
}

@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}

.kv-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px 16px;
  margin-top: 10px;
}

.kv-grid > div {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}

.kv-grid > div.total {
  border-top: 1px solid var(--accent);
  border-bottom: none;
  margin-top: 6px;
  padding-top: 10px;
  font-weight: 600;
  color: var(--accent-2);
}

.kv-grid > div.cf-row.good {
  border-top-color: var(--accent-2);
  color: var(--accent-2);
}

.kv-grid > div.cf-row.bad {
  border-top-color: var(--danger);
  color: var(--danger);
}

.returns-value.bad { color: var(--danger); }
.returns-value.good { color: var(--accent-2); }

.kv-grid .k {
  color: var(--muted);
  font-size: 12px;
}

.kv-grid .v {
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}

.controls {
  display: flex;
  gap: 18px;
  margin-bottom: 10px;
}

body.op-simple-mode .detail-row { display: none; }

.scope {
  font-size: 11px;
  color: var(--muted);
  text-transform: none;
  letter-spacing: 0;
  font-weight: 400;
  margin-left: 6px;
}

.subhead {
  margin: 18px 0 4px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.returns-grid {
  display: grid;
  grid-template-columns: 1.1fr 1fr 1.1fr;
  gap: 12px;
  margin: 4px 0 10px;
}

.returns-item {
  padding: 14px 16px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.returns-item.primary { border-color: var(--accent); }

.returns-label {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 500;
}

.returns-value {
  font-size: 26px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--accent-2);
  line-height: 1.1;
}

.returns-item.primary .returns-value {
  font-size: 32px;
  color: var(--accent);
}

.returns-sub {
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

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

.table-wrap {
  max-height: 420px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 6px;
}

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

thead th {
  position: sticky;
  top: 0;
  background: var(--panel-2);
  text-align: right;
  padding: 8px 10px;
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

thead th:nth-child(1),
thead th:nth-child(2) {
  text-align: left;
}

tbody td {
  padding: 6px 10px;
  text-align: right;
  border-bottom: 1px solid #20242d;
}

tbody td:nth-child(1),
tbody td:nth-child(2) {
  text-align: left;
  color: var(--muted);
}

tbody tr:hover {
  background: #1b1f28;
}

tbody tr.subtotal {
  background: #1a2030;
  font-weight: 600;
  border-top: 1px solid var(--accent);
}

tbody tr.subtotal td:nth-child(1) {
  color: var(--accent);
}

tbody tr.subtotal:hover {
  background: #1f2638;
}

.note {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

footer {
  max-width: 1100px;
  margin: 0 auto;
  padding: 12px 24px 36px;
  color: var(--muted);
  font-size: 12px;
}

@media (max-width: 800px) {
  main { grid-template-columns: 1fr; }
  .panel.full-width { grid-column: auto; }
}
