:root {
  --bg: #eef3f7;
  --sidebar: #17212c;
  --sidebar-2: #222d39;
  --surface: #ffffff;
  --surface-2: #f7fafc;
  --ink: #102033;
  --muted: #637286;
  --line: #d8e1ea;
  --line-strong: #bdcbd8;
  --teal: #009b8a;
  --blue: #2563eb;
  --red: #de4350;
  --amber: #f59e0b;
  --green: #14a36f;
  --purple: #7c3aed;
  --shadow: 0 16px 38px rgba(21, 35, 51, 0.09);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 292px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: 24px;
  height: 100vh;
  padding: 26px 20px;
  background: var(--sidebar);
  color: #f8fafc;
}

.brand {
  display: flex;
  align-items: center;
  gap: 13px;
}

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  background:
    linear-gradient(135deg, #009b8a 0 49%, transparent 50%),
    linear-gradient(315deg, #f59e0b 0 48%, #de4350 49%);
  flex: 0 0 auto;
}

.brand p,
.eyebrow,
.panel-head p {
  margin: 0;
  color: var(--muted);
}

.brand p {
  color: #9eb0c3;
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.brand h1,
.topbar h2,
.panel h3 {
  margin: 0;
  letter-spacing: 0;
}

.brand h1 {
  margin-top: 4px;
  font-size: 1.13rem;
  line-height: 1.15;
}

.control-stack {
  display: grid;
  gap: 14px;
}

.control {
  display: grid;
  gap: 7px;
}

.control span {
  color: #d7e1ec;
  font-size: 0.78rem;
  font-weight: 800;
}

select,
input {
  width: 100%;
  min-height: 40px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: var(--radius);
  background: var(--sidebar-2);
  color: #f8fafc;
  padding: 9px 10px;
  outline: none;
}

select:focus,
input:focus {
  border-color: #70d6c9;
  box-shadow: 0 0 0 3px rgba(0, 155, 138, 0.18);
}

input.input-draft {
  border-color: #f8c7cc;
  box-shadow: 0 0 0 3px rgba(222, 67, 80, 0.18);
}

.input-unit {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 46px;
  align-items: center;
  border-radius: var(--radius);
  background: var(--sidebar-2);
}

.input-unit input {
  border-radius: var(--radius) 0 0 var(--radius);
}

.input-unit strong {
  display: grid;
  place-items: center;
  min-height: 40px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-left: 0;
  border-radius: 0 var(--radius) var(--radius) 0;
  color: #d7e1ec;
  font-size: 0.8rem;
}

.danger-control {
  margin: 6px -2px 0;
  border: 1px solid #f6a6ad;
  border-radius: var(--radius);
  background: #df4350;
  padding: 13px 12px;
}

.danger-control span {
  color: #ffffff;
}

.danger-control .input-unit,
.danger-control input {
  background: #8d202a;
  color: #ffffff;
}

.danger-control input {
  border-color: #ffbec4;
  font-weight: 900;
}

.danger-control .input-unit strong {
  border-color: #ffbec4;
  color: #ffffff;
}

.sidebar-status {
  margin-top: auto;
  color: #9eb0c3;
  font-size: 0.76rem;
  line-height: 1.45;
}

.workspace {
  display: grid;
  align-content: start;
  gap: 18px;
  min-width: 0;
  padding: 24px;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  min-width: 0;
}

.eyebrow {
  margin-bottom: 6px;
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.topbar h2 {
  font-size: clamp(1.7rem, 2.6vw, 2.45rem);
  line-height: 1.05;
}

.status-pills {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
}

.status-pills span {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 8px 11px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
  box-shadow: 0 8px 22px rgba(21, 35, 51, 0.06);
}

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

.tab {
  min-height: 38px;
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: var(--radius) var(--radius) 0 0;
  background: #f9fbfd;
  color: var(--muted);
  padding: 9px 14px;
  font-size: 0.9rem;
  font-weight: 850;
}

.tab.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 -1px 0 var(--surface) inset;
}

.tab-panel {
  display: none;
  min-width: 0;
}

.tab-panel.active {
  display: grid;
  gap: 18px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(128px, 1fr));
  gap: 12px;
}

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

.metric-card {
  min-height: 104px;
  padding: 14px;
}

.metric-card p {
  margin: 0;
}

.metric-label {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 900;
  text-transform: uppercase;
}

.metric-value {
  margin-top: 8px;
  font-size: clamp(1.2rem, 2vw, 1.85rem);
  font-weight: 900;
  line-height: 1.05;
}

.metric-note {
  margin-top: 7px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.grid {
  display: grid;
  gap: 16px;
  min-width: 0;
}

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

.two-one {
  grid-template-columns: minmax(0, 1.72fr) minmax(300px, 0.78fr);
}

.scenario-grid {
  grid-template-columns: minmax(0, 1.7fr) minmax(300px, 0.65fr);
  align-items: stretch;
}

.panel {
  min-width: 0;
  overflow: hidden;
}

.panel-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 14px;
  min-height: 68px;
  border-bottom: 1px solid var(--line);
  padding: 15px 18px 12px;
}

.panel-head.compact {
  min-height: 54px;
  align-items: center;
}

.panel h3 {
  font-size: 1rem;
  line-height: 1.2;
}

.panel-head p {
  margin-top: 5px;
  font-size: 0.78rem;
  font-weight: 650;
}

.chart-frame {
  min-width: 0;
  overflow-x: auto;
  padding: 14px 14px 18px;
}

.ranking-frame {
  min-height: 400px;
}

#rankingChart,
.sensitivity-chart,
.scatter-chart {
  display: block;
  width: 100%;
  height: 360px;
  min-width: 780px;
}

.sensitivity-chart,
.scatter-chart {
  min-width: 520px;
  padding: 10px;
}

.legend,
.point-legend {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px 12px;
}

.legend-item,
.point-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
}

.swatch,
.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: 0 0 auto;
}

.dot.white {
  border: 2px solid #51d7ff;
  background: #ffffff;
}

.dot.red {
  background: var(--red);
}

.axis-line {
  stroke: #8795a6;
  stroke-width: 1;
}

.grid-line {
  stroke: #e3eaf1;
  stroke-width: 1;
}

.axis-label,
.bar-label,
.value-label,
.svg-label {
  fill: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.bar-label.focused,
.value-label.focused {
  fill: var(--ink);
}

.bar-hit {
  fill: transparent;
}

.bar-group {
  cursor: pointer;
}

.svg-hit-layer {
  fill: transparent;
  cursor: crosshair;
  pointer-events: all;
}

.line-path {
  fill: none;
  stroke-width: 2.2;
  pointer-events: none;
}

.line-path.dim {
  opacity: 0.46;
}

.line-point {
  stroke: #ffffff;
  stroke-width: 1.5;
  pointer-events: none;
}

.contribution-list {
  display: grid;
  gap: 12px;
  padding: 16px 18px 18px;
}

.contribution-row {
  display: grid;
  grid-template-columns: 82px minmax(0, 1fr) 86px;
  align-items: center;
  gap: 11px;
  border-radius: 7px;
  cursor: pointer;
  padding: 2px 3px;
  transition: background 0.14s ease, transform 0.14s ease;
}

.contribution-row:hover {
  background: #f4f7fa;
  transform: translateX(2px);
}

.contribution-row strong {
  font-size: 0.82rem;
}

.contribution-track {
  position: relative;
  height: 12px;
  border-radius: 999px;
  background:
    linear-gradient(90deg, transparent 49%, #a9b6c4 50%, transparent 51%),
    #eef3f7;
  overflow: hidden;
}

.contribution-fill {
  position: absolute;
  top: 0;
  height: 100%;
  border-radius: 999px;
}

.contribution-value {
  text-align: right;
  font-size: 0.82rem;
  font-weight: 900;
}

.matrix-wrap,
.table-wrap {
  overflow: auto;
  max-width: 100%;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

th,
td {
  border-bottom: 1px solid #e7edf3;
  padding: 9px 11px;
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f7fafc;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 900;
  text-transform: uppercase;
}

td.number,
th.number {
  text-align: right;
}

.matrix-table td,
.matrix-table th {
  min-width: 84px;
}

.matrix-table th:first-child,
.matrix-table td:first-child {
  position: sticky;
  left: 0;
  z-index: 2;
  background: #ffffff;
  box-shadow: 1px 0 0 #e7edf3;
}

.matrix-table th:first-child {
  background: #f7fafc;
  z-index: 3;
}

.heat-cell {
  border-radius: 6px;
  color: #ffffff;
  font-weight: 900;
  text-align: center;
}

.surface-panel {
  min-height: 560px;
}

.surface3d {
  position: relative;
  height: 486px;
  background: #101a28;
  cursor: crosshair;
  touch-action: none;
}

.surface3d.is-dragging {
  cursor: grabbing;
}

.surface3d canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.sweet-panel {
  display: grid;
  align-content: start;
}

#sweetSpot {
  display: grid;
  gap: 12px;
  padding: 16px;
}

.sweet-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
  padding: 12px;
}

.sweet-card span {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 900;
  text-transform: uppercase;
}

.sweet-card strong {
  display: block;
  margin-top: 4px;
  font-size: 1.08rem;
}

.mini-scale {
  display: grid;
  gap: 6px;
  padding: 0 16px 16px;
}

.winner-strip-row {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr) 40px;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
}

.winner-strip {
  height: 10px;
  border-radius: 999px;
  overflow: hidden;
  background: #edf2f7;
}

.winner-strip span {
  display: block;
  height: 100%;
}

.decision-map {
  display: block;
  width: 100%;
  height: 360px;
  cursor: crosshair;
  touch-action: none;
}

.chart-tooltip {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 1000000;
  display: grid;
  gap: 4px;
  min-width: 188px;
  max-width: 280px;
  border: 1px solid rgba(16, 32, 51, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 18px 42px rgba(16, 32, 51, 0.2);
  color: var(--ink);
  opacity: 0;
  padding: 10px 11px;
  pointer-events: none;
  transform: translate(-999px, -999px);
  transition: opacity 0.08s ease;
}

.chart-tooltip.visible {
  opacity: 1;
}

.chart-tooltip strong {
  font-size: 1rem;
  line-height: 1.1;
}

.chart-tooltip span {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 900;
  text-transform: uppercase;
}

.chart-tooltip hr {
  width: 100%;
  border: 0;
  border-top: 1px solid #e4ebf2;
  margin: 4px 0;
}

.chart-tooltip b {
  display: inline-block;
  min-width: 94px;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 900;
}

.density-point,
.matrix-crude-row,
.product-row {
  cursor: pointer;
}

.density-point circle,
.bar-group rect,
.product-row,
.matrix-crude-row {
  transition: opacity 0.14s ease, filter 0.14s ease, background 0.14s ease;
}

.density-point:hover circle,
.bar-group:hover rect:not(.bar-hit) {
  filter: brightness(1.08);
}

.product-row:hover,
.matrix-crude-row:hover {
  background: #f4f8fb;
}

.positive {
  color: var(--green);
}

.negative {
  color: var(--red);
}

.neutral {
  color: var(--ink);
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 0.74rem;
  font-weight: 900;
}

.badge.ok {
  background: #e8f8f1;
  color: #08764f;
}

.badge.warn {
  background: #fff1f3;
  color: #b51f32;
}

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

.audit-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
  padding: 13px;
}

.audit-card span {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 900;
  text-transform: uppercase;
}

.audit-card strong {
  display: block;
  margin-top: 5px;
  font-size: 1.25rem;
}

.empty-state {
  color: var(--muted);
  text-align: center;
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: relative;
    height: auto;
  }

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

  .danger-control {
    margin: 0;
  }

  .kpi-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .two,
  .two-one,
  .scenario-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .workspace {
    padding: 16px;
  }

  .topbar {
    align-items: start;
    flex-direction: column;
  }

  .control-stack,
  .kpi-grid,
  .audit-grid {
    grid-template-columns: 1fr;
  }

  .surface3d {
    height: 390px;
  }
}
