:root {
  color-scheme: light;
  --bg: #f5f7f4;
  --surface: #ffffff;
  --surface-strong: #fdf8ed;
  --ink: #17201b;
  --muted: #627069;
  --line: #d9e0db;
  --accent: #1f7a5a;
  --accent-dark: #15583f;
  --amber: #bc7d14;
  --danger: #ad3434;
  --shadow: 0 18px 50px rgba(28, 45, 36, 0.12);
  font-family: Tahoma, "Segoe UI", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
}

button,
input,
select {
  font: inherit;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 22px clamp(16px, 4vw, 42px);
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-weight: 700;
}

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

h1 {
  margin-bottom: 0;
  font-size: clamp(1.35rem, 2.5vw, 2.2rem);
}

.topbar-actions,
.section-heading {
  display: flex;
  align-items: center;
  gap: 12px;
}

.section-heading {
  justify-content: space-between;
  padding: 20px 22px 14px;
}

.section-heading h2 {
  margin-bottom: 6px;
  font-size: 1.25rem;
}

.section-heading p {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.8;
}

button {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  font-weight: 700;
  transition: 150ms ease;
}

button:hover {
  transform: translateY(-1px);
}

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

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

.ghost {
  background: #fff;
  color: var(--ink);
  border-color: var(--line);
}

.icon-btn {
  width: 36px;
  min-height: 36px;
  padding: 0;
  border-color: #efd1d1;
  background: #fff7f7;
  color: var(--danger);
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(280px, 350px) minmax(0, 1fr);
  gap: 22px;
  padding: 22px clamp(16px, 4vw, 42px) 36px;
}

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

.summary-panel {
  align-self: start;
  position: sticky;
  top: 16px;
  padding: 18px;
}

.field {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.88rem;
  min-width: 130px;
}

.field.wide {
  min-width: 100%;
}

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

input:focus,
select:focus {
  outline: 2px solid rgba(31, 122, 90, 0.22);
  border-color: var(--accent);
}

.total-box {
  display: grid;
  gap: 10px;
  margin: 18px 0;
  padding: 18px;
  border-radius: 8px;
  background: var(--surface-strong);
  border: 1px solid #edd7ad;
}

.total-box span,
.metric-list span,
.share-bars span,
.controls dt {
  color: var(--muted);
}

.total-box strong {
  font-size: clamp(1.45rem, 4vw, 2.05rem);
  color: var(--accent-dark);
}

.metric-list {
  display: grid;
  gap: 10px;
}

.metric-list div,
.controls div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding: 11px 0;
}

.metric-list strong,
.controls dd {
  margin: 0;
  white-space: nowrap;
}

.share-bars {
  display: grid;
  gap: 12px;
  margin-top: 18px;
}

.bar {
  height: 9px;
  margin-top: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: #e6ebe7;
}

.bar i {
  display: block;
  width: 0%;
  height: 100%;
  background: var(--accent);
}

.controls {
  margin: 18px 0 0;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.tab {
  background: transparent;
  color: var(--muted);
  border-color: var(--line);
}

.tab.active {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}

.tab-page {
  display: none;
}

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

.table-wrap {
  overflow-x: auto;
  padding: 0 14px 18px;
}

table {
  width: 100%;
  min-width: 980px;
  border-collapse: separate;
  border-spacing: 0;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px 8px;
  text-align: right;
  vertical-align: middle;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f0f4f1;
  color: #33443a;
  font-size: 0.85rem;
}

td output,
.readonly {
  display: block;
  min-width: 110px;
  color: var(--ink);
  font-weight: 700;
}

.muted-cell {
  color: var(--muted);
  font-size: 0.86rem;
}

.warning {
  color: var(--amber);
  font-weight: 700;
}

.reference-grid {
  display: grid;
  grid-template-columns: minmax(260px, 0.9fr) minmax(320px, 1.4fr);
  gap: 18px;
  padding: 0 22px 22px;
}

.reference-grid section {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.reference-grid h3 {
  margin: 0;
  padding: 12px 14px;
  background: #f0f4f1;
}

.reference-list {
  display: grid;
  max-height: 520px;
  overflow: auto;
}

.reference-item {
  display: grid;
  gap: 5px;
  padding: 12px 14px;
  border-top: 1px solid var(--line);
}

.reference-item:first-child {
  border-top: 0;
}

.reference-item b {
  color: var(--accent-dark);
}

.reference-item span {
  color: var(--muted);
  line-height: 1.7;
}

@media (max-width: 980px) {
  .topbar,
  .app-shell,
  .section-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .app-shell,
  .reference-grid {
    grid-template-columns: 1fr;
  }

  .summary-panel {
    position: static;
  }

  .topbar-actions {
    justify-content: stretch;
  }

  .topbar-actions button,
  .section-heading button {
    flex: 1;
  }
}

@media (max-width: 640px) {
  :root {
    font-size: 12px;
  }

  .topbar {
    gap: 12px;
    padding: 12px;
  }

  .eyebrow {
    margin-bottom: 3px;
    font-size: 0.78rem;
  }

  h1 {
    font-size: 1.18rem;
    line-height: 1.45;
  }

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

  button {
    min-height: 34px;
    border-radius: 7px;
    padding: 6px 8px;
    font-size: 0.86rem;
  }

  .app-shell {
    gap: 12px;
    padding: 12px 10px 22px;
  }

  .summary-panel {
    padding: 12px;
  }

  .field {
    gap: 5px;
    font-size: 0.78rem;
  }

  input,
  select {
    min-height: 32px;
    border-radius: 7px;
    padding: 5px 7px;
    font-size: 0.86rem;
  }

  .total-box {
    gap: 6px;
    margin: 12px 0;
    padding: 12px;
  }

  .total-box strong {
    font-size: 1.32rem;
  }

  .metric-list div,
  .controls div {
    gap: 8px;
    padding: 8px 0;
    font-size: 0.82rem;
  }

  .metric-list strong,
  .controls dd {
    font-size: 0.84rem;
  }

  .share-bars {
    gap: 8px;
    margin-top: 12px;
    font-size: 0.8rem;
  }

  .tabs {
    gap: 6px;
    padding: 10px;
  }

  .tab {
    min-height: 32px;
    padding: 5px 8px;
    font-size: 0.82rem;
  }

  .section-heading {
    gap: 10px;
    padding: 14px 12px 10px;
  }

  .section-heading h2 {
    margin-bottom: 4px;
    font-size: 1rem;
  }

  .section-heading p {
    font-size: 0.78rem;
    line-height: 1.65;
  }

  .table-wrap {
    padding: 0 8px 12px;
  }

  table {
    min-width: 760px;
  }

  th,
  td {
    padding: 6px 5px;
    font-size: 0.76rem;
  }

  td output,
  .readonly {
    min-width: 82px;
    font-size: 0.78rem;
  }

  .muted-cell {
    font-size: 0.7rem;
  }

  .icon-btn {
    width: 30px;
    min-height: 30px;
  }

  .reference-grid {
    gap: 10px;
    padding: 0 12px 12px;
  }

  .reference-grid h3 {
    padding: 9px 10px;
    font-size: 0.92rem;
  }

  .reference-item {
    gap: 3px;
    padding: 9px 10px;
    font-size: 0.78rem;
  }
}

@media print {
  body {
    background: #fff;
  }

  .topbar-actions,
  .tabs,
  .icon-btn {
    display: none;
  }

  .app-shell {
    display: block;
    padding: 0;
  }

  .summary-panel,
  .workspace {
    box-shadow: none;
    border: 0;
  }

  .tab-page {
    display: block;
    break-inside: avoid;
  }
}
