:root {
  --bg: #f4f2ed;
  --surface: #fffdf8;
  --surface2: #f1eee6;
  --surface3: #e8edf0;
  --border: #d3cec1;
  --border-strong: #a7b0ac;
  --green-dark: #315f43;
  --green-mid: #557d63;
  --green-pale: #e5efe7;
  --amber: #b9752d;
  --text: #282823;
  --text-mid: #5f5d52;
  --text-light: #888273;
  --danger: #b43b30;
  --radius: 8px;
  --shadow: 0 2px 14px rgba(42, 42, 32, .10);
  --font-display: 'Playfair Display', Georgia, serif;
  --font-body: 'Rubik', Arial, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
}

.header {
  height: 60px;
  padding: 0 28px;
  background: var(--green-dark);
  color: #fff;
  display: flex;
  align-items: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .18);
}

.header-inner {
  width: 100%;
  max-width: 1360px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
}

.logo-icon { font-size: 20px; opacity: .9; }

.logo-text {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 20px;
}

.logo-text em {
  color: #b8d0bd;
  font-style: italic;
}

.step-indicator {
  display: flex;
  gap: 8px;
  align-items: center;
  overflow-x: auto;
  padding: 8px 0;
}

.step-dot {
  flex: 0 0 auto;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .32);
}

.step-dot.active {
  background: #fff;
  transform: scale(1.3);
}

.step-dot.done { background: #b8d0bd; }

.layout {
  max-width: 1360px;
  margin: 28px auto;
  padding: 0 24px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 24px;
  align-items: start;
}

.form-area {
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 30px 32px 24px;
  box-shadow: var(--shadow);
}

.loading {
  color: var(--text-mid);
  font-size: 14px;
}

.step {
  display: none;
  animation: fadeIn .22s ease;
}

.step.active { display: block; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.step-title {
  margin: 0 0 4px;
  color: var(--green-dark);
  font-family: var(--font-display);
  font-size: 28px;
  line-height: 1.2;
}

.step-sub {
  margin: 0 0 24px;
  color: var(--text-light);
  font-size: 13px;
}

.section-nav {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  gap: 8px;
  margin: -8px -6px 24px;
  padding: 8px 6px 10px;
  overflow-x: auto;
  background: linear-gradient(180deg, var(--surface) 0%, var(--surface) 78%, rgba(255, 253, 248, 0) 100%);
  scrollbar-width: thin;
}

.section-nav:empty {
  display: none;
}

.section-nav-tab {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  max-width: 260px;
  min-height: 34px;
  padding: 7px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  color: var(--text-mid);
  cursor: pointer;
  font: inherit;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}

.section-nav-tab span:last-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.section-nav-index {
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface2);
  color: var(--text-light);
  font-size: 11px;
}

.section-nav-tab:hover {
  border-color: var(--green-mid);
  color: var(--green-dark);
}

.section-nav-tab.done {
  border-color: var(--green-pale);
  background: #f6faf7;
}

.section-nav-tab.active {
  border-color: var(--green-dark);
  background: var(--green-dark);
  color: #fff;
}

.section-nav-tab.active .section-nav-index {
  background: rgba(255, 255, 255, .18);
  color: #fff;
}

.section-note {
  margin: 0 0 18px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #f8f7f1;
  color: var(--text-mid);
  font-size: 13px;
}

.field-group {
  margin-bottom: 18px;
  max-width: 560px;
}

.resource-bundle {
  display: block;
}

.revenue-products {
  display: grid;
  gap: 14px;
}

.revenue-product-card {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
}

.revenue-product-head {
  display: grid;
  grid-template-columns: minmax(96px, 120px) minmax(0, 1fr);
  gap: 8px;
  align-items: end;
}

.revenue-product-index {
  color: var(--green-dark);
  font-size: 13px;
  font-weight: 600;
  align-self: start;
  padding-top: 2px;
}

.revenue-product-meta {
  display: grid;
  grid-template-columns: minmax(200px, 1.4fr) minmax(110px, .6fr) minmax(160px, .9fr);
  gap: 8px;
}

.revenue-field {
  display: grid;
  gap: 5px;
  min-width: 0;
  color: var(--text-mid);
  font-size: 12px;
  font-weight: 500;
}

.revenue-field span {
  color: var(--text-mid);
}

.revenue-price-field .field-input {
  max-width: 240px;
}

.revenue-volume-table {
  width: max-content;
  min-width: 0;
}

.revenue-volume-table .sticky-col {
  width: 88px;
  min-width: 88px;
  max-width: 88px;
}

.revenue-volume-table thead .sticky-col,
.revenue-volume-table tbody .sticky-col {
  left: 0;
  width: 88px;
  min-width: 88px;
  max-width: 88px;
}

.revenue-volume-table .year-cell {
  min-width: 96px;
}

.unit-label {
  display: block;
  margin-top: 4px;
  color: var(--text-light);
  font-size: 11px;
  font-weight: 400;
}

.group-card {
  margin: 0 0 22px;
  padding: 18px 18px 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface2);
}

.group-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.group-head h3 {
  margin: 0 0 4px;
  color: var(--green-dark);
  font-family: var(--font-display);
  font-size: 20px;
  line-height: 1.2;
}

.group-head p {
  margin: 0;
  color: var(--text-light);
  font-size: 12px;
}

.group-note {
  max-width: 280px;
  padding: 8px 10px;
  border-radius: calc(var(--radius) - 2px);
  background: #fff;
  border: 1px solid var(--border);
  color: var(--text-mid);
  font-size: 12px;
}

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

.group-grid .field-group {
  margin-bottom: 0;
  max-width: none;
}

.field-label {
  display: block;
  margin-bottom: 6px;
  color: var(--text-mid);
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
}

.field-input {
  width: 100%;
  min-width: 0;
  height: 38px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface2);
  color: var(--text);
  font: inherit;
  outline: none;
}

.field-input:focus {
  border-color: var(--green-mid);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(85, 125, 99, .14);
}

.field-input::placeholder { color: var(--text-light); }

.field-input.compact {
  height: 32px;
  margin-top: 7px;
  font-size: 13px;
}

.year-input {
  width: 82px;
  height: 32px;
  padding: 6px 8px;
  text-align: right;
  font-size: 13px;
}

.table-block {
  margin: 0 0 22px;
}

.table-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 9px;
  color: var(--text-mid);
  font-size: 13px;
  font-weight: 500;
}

.row-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.mini-btn {
  min-height: 30px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  color: var(--text-mid);
  cursor: pointer;
  font: inherit;
  font-size: 12px;
}

.mini-btn:hover {
  border-color: var(--green-mid);
  color: var(--green-dark);
}

.mini-btn:disabled {
  cursor: default;
  opacity: .55;
  filter: none;
}

.table-scroll {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
}

.year-table {
  width: max-content;
  border-collapse: separate;
  border-spacing: 0;
}

.year-table th,
.year-table td {
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding: 7px;
  vertical-align: middle;
  background: #fff;
}

.year-table .year-col,
.year-table .year-cell {
  width: 96px;
  min-width: 96px;
  max-width: 96px;
}

.year-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--surface3);
  color: var(--text-mid);
  font-size: 12px;
  font-weight: 500;
  text-align: center;
}

.metric-header-row th {
  background: var(--surface3);
  color: var(--text-mid);
  font-size: 12px;
  font-weight: 500;
  text-align: center;
}

.metric-header-row .sticky-col {
  z-index: 8;
  text-align: left;
}

.year-add-btn {
  min-width: 72px;
  padding-left: 6px;
  padding-right: 6px;
}

.revenue-volume-table .year-input {
  width: 100%;
}

.year-table > tbody:last-of-type tr:last-child td,
.year-table > tbody:last-of-type tr:last-child th {
  border-bottom: none;
}

.sticky-col {
  position: sticky;
  left: 0;
  z-index: 3;
  min-width: 190px;
  max-width: 240px;
  background: var(--surface);
  color: var(--text-mid);
  text-align: left;
  font-size: 13px;
  font-weight: 500;
  box-shadow: 8px 0 10px -10px rgba(42, 42, 32, .55);
}

thead .sticky-col {
  position: sticky;
  left: 0;
  z-index: 6;
  background: var(--surface3);
}

.sticky-corner {
  z-index: 8;
  background: var(--surface3);
}

.multi-table .sticky-col {
  width: 240px;
  min-width: 240px;
  max-width: 240px;
}

.multi-table .sticky-metric-col {
  position: sticky;
  left: 240px;
  z-index: 4;
  min-width: 76px;
  width: 76px;
  max-width: 76px;
  box-shadow: 8px 0 10px -10px rgba(42, 42, 32, .45);
}

.multi-table .metric-header-row .sticky-metric-col {
  z-index: 7;
  background: var(--surface3);
}

.metric-label {
  min-width: 76px;
  color: var(--text-light);
  font-size: 12px;
  font-weight: 500;
  text-align: center;
}

.item-heading span {
  display: block;
  color: var(--green-dark);
}

.inline-select-label {
  display: grid;
  gap: 4px;
  margin-top: 7px;
  color: var(--text-mid);
  font-size: 12px;
  font-weight: 400;
}

.inline-select-label span {
  color: var(--text-mid);
}

.inline-select-label .field-input {
  height: 32px;
  font-size: 13px;
}

.investment-heading {
  overflow: visible;
  position: sticky;
  vertical-align: top;
}

.investment-meta {
  margin-top: 6px;
  position: relative;
}

.investment-meta summary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 28px;
  padding: 4px 9px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #fff;
  color: var(--green-dark);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  user-select: none;
}

.investment-meta summary::marker,
.investment-meta summary::-webkit-details-marker {
  display: none;
  content: "";
}

.investment-meta summary::after {
  content: "⌄";
  color: var(--green-mid);
  font-size: 14px;
  line-height: 1;
  transition: transform .16s ease;
}

.investment-meta[open] summary {
  border-color: var(--green-mid);
  box-shadow: 0 0 0 3px rgba(79, 125, 82, .12);
}

.investment-meta[open] summary::after {
  transform: rotate(180deg);
}

.investment-meta-fields {
  display: grid;
  gap: 6px;
  position: fixed;
  left: var(--investment-menu-left, 12px);
  top: var(--investment-menu-top, 80px);
  z-index: 1000;
  width: var(--investment-menu-width, min(320px, calc(100vw - 24px)));
  max-height: 320px;
  overflow: auto;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  box-shadow: 0 14px 30px rgba(43, 48, 34, .18);
}

.investment-meta-fields label {
  display: grid;
  gap: 3px;
  min-width: 0;
  color: var(--text-mid);
  font-size: 12px;
  font-weight: 400;
}

.investment-meta-fields .field-input {
  width: 100%;
}

.table-footer {
  display: flex;
  justify-content: flex-start;
  padding-top: 10px;
}

.nav-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 28px;
  padding-top: 22px;
  border-top: 1px solid var(--border);
}

.btn {
  min-height: 42px;
  padding: 10px 22px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  font: inherit;
  font-weight: 500;
}

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text-mid);
}

.btn-primary {
  margin-left: auto;
  background: var(--green-dark);
  color: #fff;
}

.btn-success {
  margin-left: auto;
  background: var(--amber);
  color: #fff;
}

.btn-debug {
  background: #fff7e8;
  border-color: #e3bf78;
  color: #745220;
  font-size: 13px;
}

.btn:hover { filter: brightness(1.04); }

.status-bar {
  min-height: 22px;
  margin-top: 12px;
  color: var(--text-light);
  font-size: 13px;
  text-align: center;
}

.status-bar.ok { color: var(--green-mid); }
.status-bar.error { color: var(--danger); }

.hint-panel {
  position: sticky;
  top: 24px;
}

.hint-card {
  display: none;
  padding: 22px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.hint-card.active { display: block; }

.hint-icon {
  width: 28px;
  height: 28px;
  margin-bottom: 10px;
  border-radius: 50%;
  background: var(--green-pale);
  color: var(--green-dark);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
}

.hint-card h3 {
  margin: 0 0 9px;
  color: var(--green-dark);
  font-family: var(--font-display);
  font-size: 18px;
}

.hint-card p {
  margin: 0 0 10px;
  color: var(--text-mid);
  font-size: 13.5px;
}

.hint-card p:last-child { margin-bottom: 0; }

@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
    margin-top: 18px;
    padding: 0 14px;
  }

  .form-area { padding: 24px 18px 20px; }
  .section-nav {
    top: 0;
    margin-right: -10px;
    margin-left: -10px;
    padding-right: 10px;
    padding-left: 10px;
  }
  .hint-panel { position: static; }
  .btn-primary, .btn-success { margin-left: 0; }
  .btn-debug { flex: 1 1 220px; }
}

@media (max-width: 560px) {
  .header { padding: 0 16px; }
  .logo-text { font-size: 18px; }
  .step-title { font-size: 24px; }
  .section-nav-tab { max-width: 220px; }
  .sticky-col { min-width: 160px; }
  .multi-table .sticky-col {
    width: 160px;
    min-width: 160px;
    max-width: 160px;
  }
  .multi-table .sticky-metric-col { left: 160px; }
  .revenue-product-head {
    grid-template-columns: 1fr;
  }

  .revenue-product-meta {
    grid-template-columns: 1fr;
  }

  .revenue-price-field .field-input {
    max-width: none;
  }

  .nav-row .btn {
    flex: 1 1 100%;
    padding-left: 14px;
    padding-right: 14px;
  }

  .group-head {
    flex-direction: column;
  }

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