:root {
  color-scheme: light;
  --bg: #f4f5f7;
  --card: #ffffff;
  --ink: #171a21;
  --muted: #747986;
  --line: #dedfe4;
  --line-soft: #eceef2;
  --accent: #3457d5;
  --accent-soft: #e9edff;
  --danger: #b64b4b;
  --shadow: 0 10px 30px rgba(28, 34, 47, .06);
  --ui-font-size: 12px;
  --title-font-size: 24px;
}

* {
  box-sizing: border-box;
}

html {
  max-width: 100%;
  overflow-x: auto;
  overscroll-behavior-x: none;
}

body {
  margin: 0;
  max-width: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, "SF Pro Display", "Segoe UI", system-ui, sans-serif;
  font-size: var(--ui-font-size);
  overflow-x: auto;
  overscroll-behavior-x: none;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.screen {
  width: calc(100vw - 28px);
  margin: 0 auto;
  padding: 22px 0 34px;
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: nowrap;
  gap: 20px;
  margin-bottom: 12px;
}

.top > div {
  min-width: 0;
}

.top h1 {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: var(--title-font-size);
  font-weight: 650;
}

h2 {
  font-size: var(--ui-font-size);
  font-weight: 650;
}

.hint {
  max-width: 440px;
  margin: 0;
  color: var(--muted);
  font-size: var(--ui-font-size);
  line-height: 1.4;
}

.chart-panel,
.table-section {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.window-shell {
  position: relative;
  min-width: 260px;
  min-height: 120px;
}

.window-shell > .chart-panel,
.window-shell > .table-section {
  width: 100%;
  height: 100%;
}

.window-shell > .chart-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.window-shell > .table-section {
  display: flex;
  flex-direction: column;
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
}

.workbench {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 12px;
  align-items: start;
}

.history-toggle {
  min-height: 26px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #f1f3f6;
  padding: 0 10px;
  color: var(--ink);
  font-size: var(--ui-font-size);
  font-weight: 650;
  cursor: pointer;
}

.undo-button {
  min-height: 26px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--ink);
  padding: 0 11px;
  color: #fff;
  font: inherit;
  font-size: var(--ui-font-size);
  font-weight: 750;
  cursor: pointer;
}

.undo-button:disabled {
  background: #f1f3f6;
  color: var(--muted);
  cursor: default;
  opacity: .62;
}

.history-toggle input {
  width: 14px;
  height: 14px;
  accent-color: var(--accent);
}

.charts-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  min-width: 0;
}

.side-editor {
  min-width: 0;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.side-editor .window-shell {
  min-width: 0;
}

.chart-panel {
  padding: 0;
  min-width: 0;
}

.chart-tools {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  flex: 0 0 auto;
  margin-left: auto;
  max-width: none;
  white-space: nowrap;
}

.chart-scale-control {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: var(--ui-font-size);
  font-weight: 700;
}

.chart-scale-button {
  width: 26px;
  height: 26px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--ink);
  padding: 0;
  font: inherit;
  font-size: var(--ui-font-size);
  font-weight: 750;
  line-height: 1;
  outline: none;
}

.chart-scale-button:hover:not(:disabled) {
  background: #f7f8fb;
}

.chart-scale-button:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(52, 87, 213, .11);
}

.chart-scale-button:disabled {
  color: var(--muted);
  cursor: default;
  opacity: .48;
}

.chart-frame {
  position: relative;
  flex: 1 1 auto;
  container-type: inline-size;
  min-width: 0;
  min-height: 0;
  max-height: 500px;
  margin-bottom: 30px;
  overflow: visible;
  overscroll-behavior: none;
}

.chart-y-axis {
  position: absolute;
  inset: 0 auto 0 0;
  z-index: 4;
  width: 76px;
  height: 100%;
  background: linear-gradient(90deg, var(--card) 0 86%, rgba(255, 255, 255, 0) 100%);
  pointer-events: none;
}

.chart-x-axis {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
}

.y-axis-label {
  position: absolute;
  right: 19px;
  color: var(--muted);
  font-size: var(--ui-font-size);
  line-height: 1;
  transform: translateY(-50%);
  white-space: nowrap;
}

.x-axis-label {
  position: absolute;
  color: var(--muted);
  font-size: var(--ui-font-size);
  line-height: 1;
  transform: translate(-50%, -100%);
  white-space: nowrap;
}

.y-axis-title {
  position: absolute;
  left: 10px;
  color: var(--muted);
  font-size: var(--ui-font-size);
  line-height: 1;
  white-space: nowrap;
}

.chart {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1500 / 540;
  min-height: 300px;
  max-height: 500px;
  touch-action: none;
  user-select: none;
}

.grid-line {
  stroke: var(--line-soft);
  stroke-width: 1;
}

.grid-line.vertical {
  stroke: #eef0f4;
  stroke-dasharray: none;
  stroke-width: .8;
}

.axis {
  stroke: #aeb3bf;
  stroke-width: 1.4;
}

.axis-label,
.axis-title {
  fill: var(--muted);
  font-size: var(--ui-font-size);
}

.point-group {
  cursor: grab;
}

.point-group:active {
  cursor: grabbing;
}

.point-group.history-offer,
.point-group.history-offer:active {
  cursor: pointer;
}

.point-group.is-hovered .point-label,
.point-group.is-hovered .point-hover-meta {
  paint-order: stroke;
  stroke-width: 5px;
}

.point-halo {
  display: none;
}

.point {
  fill: #d1a21d;
  stroke: none;
  filter: drop-shadow(0 4px 4px rgba(28, 34, 47, .16));
}

.point-group.above-average .point {
  fill: #cc2f2f;
}

.point-group.below-average .point {
  fill: #26965c;
}

.point-group.near-average .point {
  fill: #d5a51f;
}

.point-group.history-offer .point {
  fill: #fff;
  stroke: #818896;
  stroke-width: 3;
}

.point-group.excluded-average .point {
  fill: #818896;
}

.point-group.history-offer.above-average .point,
.point-group.above-average .point {
  fill: #cc2f2f;
}

.point-group.history-offer.below-average .point,
.point-group.below-average .point {
  fill: #26965c;
}

.point-group.history-offer.near-average .point,
.point-group.near-average .point {
  fill: #d5a51f;
}

.point-group.history-offer.above-average .point {
  fill: #fff;
  stroke: #cc2f2f;
}

.point-group.history-offer.below-average .point {
  fill: #fff;
  stroke: #26965c;
}

.point-group.history-offer.near-average .point {
  fill: #fff;
  stroke: #d5a51f;
}

.point-group.selected .point {
  fill: var(--accent);
}

.point-group.history-offer.selected .point {
  fill: #fff;
  stroke: var(--accent);
}

.point-label {
  fill: var(--ink);
  font-size: var(--ui-font-size);
  font-weight: 400;
  paint-order: stroke;
  stroke: var(--card);
  stroke-width: 3px;
  stroke-linejoin: round;
}

.point-meta {
  display: none;
}

.point-hover-meta,
.anchor-hover-meta {
  display: none;
  fill: var(--muted);
  font-size: var(--ui-font-size);
  font-weight: 400;
  paint-order: stroke;
  stroke: var(--card);
  stroke-width: 3px;
  stroke-linejoin: round;
}

.point-group:hover .point-hover-meta,
.anchor-point:hover .anchor-hover-meta {
  display: block;
}

.point-group.selected .point-label,
.point-group.selected .point-hover-meta {
  fill: var(--accent);
}

.point-group.selected .point-halo {
  display: none;
}

.average-curve {
  pointer-events: none;
}

.decision-line-layer {
  pointer-events: all;
}

.decision-band {
  fill: rgba(213, 165, 31, .12);
  stroke: none;
  pointer-events: none;
}

.decision-line {
  fill: none;
  stroke: #d5a51f;
  stroke-width: 3;
  stroke-dasharray: 7 7;
  stroke-linecap: round;
  pointer-events: none;
}

.decision-handle {
  cursor: grab;
}

.decision-handle:active {
  cursor: grabbing;
}

.decision-handle .decision-hit {
  fill: transparent;
  stroke: none;
}

.decision-handle line {
  stroke: #d5a51f;
  stroke-width: 4;
  stroke-linecap: round;
  filter: drop-shadow(0 3px 3px rgba(28, 34, 47, .14));
}

.average-curve path {
  fill: none;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: .72;
}

.plan-average-curve path {
  stroke: #1f9d68;
}

.fact-average-curve path {
  stroke: #818896;
}

.average-curve text {
  font-size: var(--ui-font-size);
  font-weight: 400;
  paint-order: stroke;
  stroke: var(--card);
  stroke-width: 3px;
  stroke-linejoin: round;
}

.plan-average-curve text {
  fill: #1f7a54;
}

.fact-average-curve text {
  fill: #68707d;
}

.anchor-point {
  color: #a36a18;
  cursor: grab;
  pointer-events: auto;
}

.anchor-point:active {
  cursor: grabbing;
}

.anchor-point line {
  stroke: currentColor;
  stroke-width: 3;
  stroke-linecap: round;
}

.anchor-point .anchor-hit {
  fill: transparent;
  stroke: transparent;
  stroke-width: 0;
}

.custom-anchor {
  color: #805ad5;
}

.anchor-label {
  fill: currentColor;
  font-size: var(--ui-font-size);
  font-weight: 400;
  paint-order: stroke;
  stroke: var(--card);
  stroke-width: 3px;
  stroke-linejoin: round;
}

.anchor-meta {
  display: none;
}

.history-offer .point-halo {
  fill: rgba(111, 119, 133, .18);
}

.table-section {
  container-type: inline-size;
  overflow: hidden;
}

.table-wrap {
  flex: 1 1 auto;
  min-height: 0;
  max-height: calc(100vh - 120px);
  overflow: auto;
}

.window-shell .table-wrap {
  max-height: none;
}

table {
  width: 100%;
  border-collapse: collapse;
}

thead {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #fafbfc;
}

th,
td {
  border-bottom: 1px solid var(--line-soft);
  padding: 0 8px;
  text-align: left;
}

th {
  height: 38px;
  color: var(--muted);
  font-size: var(--ui-font-size);
  font-weight: 700;
}

.sort-header {
  width: 100%;
  min-height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  border: 0;
  background: transparent;
  color: inherit;
  padding: 0;
  text-align: right;
  font: inherit;
  font-weight: inherit;
}

.sort-title {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  width: 100%;
}

.sort-header.active {
  color: var(--ink);
}

.sort-arrow {
  width: 9px;
  color: var(--accent);
  font-size: var(--ui-font-size);
}

td {
  height: 38px;
}

tr.active td {
  background: var(--accent-soft);
}

tr.active .name-input,
tr.active .number-input,
tr.active .partner-name-cell,
tr.active .summary-value {
  color: var(--accent);
}

.draft-row td {
  background: #fbfcff;
}

.summary-row td {
  background: #eef1f6;
  color: var(--ink);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.decision-step-row td {
  background: rgba(213, 165, 31, .09);
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.readonly-cell {
  width: 100%;
  min-width: 0;
  height: 30px;
  display: flex;
  align-items: center;
  padding: 0 6px;
}

.number-cell .readonly-cell {
  justify-content: flex-end;
  text-align: right;
}

.summary-value {
  color: inherit;
}

.summary-row .number-cell .summary-value {
  transform: translateX(-18px);
}

.summary-row td:nth-child(3) .summary-value {
  transform: translateX(-18px);
}

.index-cell {
  width: 42px;
  color: var(--muted);
  text-align: center;
  font-size: var(--ui-font-size);
}

.number-cell {
  width: 84px;
}

.action-cell {
  width: 30px;
  text-align: center;
}

.compact-offer-table {
  min-width: 0;
  table-layout: fixed;
}

.compact-offer-table th:nth-child(1) {
  width: auto;
}

.compact-offer-table th:nth-child(2),
.compact-offer-table th:nth-child(3) {
  width: 104px;
  text-align: right;
}

.compact-offer-table th:nth-child(4) {
  width: 30px;
}

.compact-offer-table th,
.compact-offer-table td {
  padding: 5px 6px;
  vertical-align: middle;
}

.compact-offer-table td.number-cell {
  text-align: right;
}

.compact-offer-table td {
  height: auto;
}

.history-offer-row {
  background: #fafbfc;
}

.partner-name-cell {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 6px;
  align-items: center;
}

.name-input {
  font-weight: 650;
}

td input {
  width: 100%;
  min-width: 0;
  height: 30px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  padding: 0 6px;
  outline: none;
}

td select {
  width: 100%;
  min-width: 0;
  height: 30px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  padding: 0 4px;
  outline: none;
}

td input:hover {
  border-color: var(--line);
  background: #fff;
}

td input:focus,
td select:focus {
  border-color: var(--accent);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(52, 87, 213, .11);
}

.number-input {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.compact-anchor-table {
  min-width: 0;
  table-layout: fixed;
}

.compact-anchor-table th:nth-child(1) {
  width: auto;
}

.compact-anchor-table th:nth-child(2),
.compact-anchor-table th:nth-child(3) {
  width: 104px;
}

.compact-anchor-table th:nth-child(4) {
  width: 30px;
}

.compact-anchor-table th,
.compact-anchor-table td {
  padding: 5px 6px;
  vertical-align: middle;
}

.compact-anchor-table td {
  height: auto;
}

.context-menu {
  position: fixed;
  z-index: 20;
  min-width: 170px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  box-shadow: 0 16px 42px rgba(28, 34, 47, .18);
  padding: 6px;
  transform: translate(-8px, -8px);
}

.context-menu-title {
  padding: 7px 8px 6px;
  color: var(--muted);
  font-size: var(--ui-font-size);
  font-weight: 750;
  border-bottom: 1px solid var(--line-soft);
  margin-bottom: 4px;
}

.context-menu button {
  display: block;
  width: 100%;
  min-height: 30px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--ink);
  padding: 0 8px;
  text-align: left;
  font-size: var(--ui-font-size);
  font-weight: 700;
}

.context-menu button:hover {
  background: #f1f3f6;
}

.context-menu .danger-action {
  color: var(--danger);
}

.context-menu .danger-action:hover {
  background: #fff0f0;
}

.action-cell button {
  width: 26px;
  height: 26px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
}

.action-cell button:hover {
  background: #fff0f0;
  color: var(--danger);
}

@container (max-width: 420px) {
  .compact-offer-table th:nth-child(2),
  .compact-offer-table th:nth-child(3),
  .compact-anchor-table th:nth-child(2),
  .compact-anchor-table th:nth-child(3) {
    width: 70px;
  }

  .compact-offer-table th,
  .compact-offer-table td,
  .compact-anchor-table th,
  .compact-anchor-table td {
    padding: 3px 4px;
  }

  td input,
  td select {
    height: 27px;
    padding-inline: 4px;
  }

}

@container (max-width: 330px) {
  .partner-name-cell {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 860px) {
  .screen {
    padding-top: 18px;
  }

  .side-editor {
    gap: 6px;
  }

  .table-wrap {
    max-height: none;
  }

}

@media (max-width: 560px) {
  h1 {
    font-size: var(--title-font-size);
  }

  .chart-panel {
    padding: 0;
  }

  .table-wrap {
    overflow-x: auto;
  }

  table {
    min-width: 0;
  }
}
