:root {
  color-scheme: light;
  --ink: #17202a;
  --muted: #667085;
  --line: #d8dee8;
  --paper: #ffffff;
  --background: #f5f7fa;
  --blue: #1769e0;
  --green: #14845f;
  --coral: #ba4d31;
  --amber: #8a6414;
  --shadow: 0 16px 40px rgba(23, 32, 42, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background: var(--background);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 12px;
  color: var(--ink);
  background: var(--paper);
  cursor: pointer;
}

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

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

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

.app-header h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 760;
  letter-spacing: 0;
}

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

.header-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(260px, 0.75fr) minmax(360px, 1.1fr);
  grid-template-areas:
    "intake assumptions"
    "results results";
  gap: 16px;
  width: min(1400px, 100%);
  margin: 0 auto;
  padding: 16px;
}

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

.intake-panel {
  grid-area: intake;
  padding: 16px;
}

.assumptions-panel {
  grid-area: assumptions;
  padding: 16px;
}

.result-panel {
  grid-area: results;
  padding: 16px;
}

.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 36px;
  margin-bottom: 14px;
}

.panel-title h2,
.split-output h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 720;
  letter-spacing: 0;
}

.panel-title span,
.upload-zone small {
  color: var(--muted);
  font-size: 12px;
}

.upload-zone {
  display: grid;
  place-items: center;
  gap: 6px;
  min-height: 148px;
  margin-bottom: 14px;
  border: 1px dashed #9aa7b8;
  border-radius: 8px;
  color: var(--muted);
  background: #fbfcfe;
  cursor: pointer;
}

.upload-zone input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  opacity: 0;
}

.upload-zone strong {
  color: var(--ink);
}

.upload-icon {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  color: var(--blue);
  background: #eaf2ff;
  font-weight: 800;
}

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

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

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

input:focus,
select:focus {
  border-color: var(--blue);
  outline: 3px solid rgba(23, 105, 224, 0.14);
}

.tabs {
  display: inline-grid;
  grid-template-columns: repeat(3, minmax(58px, 1fr));
  gap: 2px;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f1f4f8;
}

.tab {
  min-height: 30px;
  border: 0;
  background: transparent;
}

.tab.active {
  color: var(--blue);
  background: var(--paper);
  box-shadow: 0 1px 3px rgba(23, 32, 42, 0.1);
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.series-block {
  display: grid;
  gap: 12px;
  margin-top: 14px;
}

.series-block span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.series-row {
  display: grid;
  grid-template-columns: repeat(5, minmax(72px, 1fr));
  gap: 8px;
}

.series-row label {
  gap: 4px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.metric-grid article {
  min-height: 88px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfe;
}

.metric-grid span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.metric-grid strong {
  display: block;
  margin-top: 10px;
  overflow-wrap: anywhere;
  font-size: 22px;
  letter-spacing: 0;
}

.metric-grid article:nth-child(1) strong {
  color: var(--blue);
}

.metric-grid article:nth-child(2) strong {
  color: var(--green);
}

.metric-grid article:nth-child(3) strong {
  color: var(--coral);
}

.metric-grid article:nth-child(4) strong {
  color: var(--amber);
}

.split-output {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 16px;
  overflow: hidden;
}

.split-output > div {
  min-width: 0;
}

table {
  width: 100%;
  margin-top: 10px;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 13px;
}

th,
td {
  height: 38px;
  border-bottom: 1px solid var(--line);
  padding: 6px 8px;
  text-align: right;
  overflow-wrap: anywhere;
}

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

th {
  color: var(--muted);
  font-weight: 650;
  background: #fbfcfe;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-areas:
      "intake"
      "assumptions"
      "results";
  }

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

@media (max-width: 640px) {
  .app-header {
    align-items: flex-start;
    flex-direction: column;
    padding: 14px;
  }

  .header-actions {
    width: 100%;
    justify-content: stretch;
  }

  .header-actions button {
    flex: 1 1 0;
  }

  .app-shell {
    padding: 10px;
  }

  .compact-grid,
  .form-grid,
  .metric-grid,
  .split-output {
    grid-template-columns: 1fr;
  }

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