:root {
  color-scheme: light;
  --ink: #18212d;
  --muted: #657184;
  --line: #dce3eb;
  --line-strong: #cbd5e1;
  --surface: #ffffff;
  --surface-soft: #f7f9fc;
  --page: #eef2f7;
  --header-start: #173f5a;
  --header-middle: #22577a;
  --header-end: #2f6f8f;
  --header-text: #f8fbff;
  --header-copy: #d7e8f2;
  --header-eyebrow: #91d7e8;
  --accent: #22577a;
  --accent-soft: #e8f1f7;
  --accent-hover: #dcebf4;
  --section-accent: #3b7c9f;
  --danger: #b42318;
  --danger-soft: rgba(180, 35, 24, 0.11);
  --danger-soft-hover: rgba(180, 35, 24, 0.17);
  --shadow: 0 14px 38px rgba(31, 48, 68, 0.08);
  --radius: 18px;
  --content-width: 1400px;
  --desktop-viewport-height: calc(133.333333vh - 36px);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 10% 0%, rgba(116, 164, 196, 0.17), transparent 28rem),
    var(--page);
}

button,
input,
select {
  font: inherit;
}

button,
select,
input[type="checkbox"],
input[type="color"],
input[type="range"] {
  cursor: pointer;
}

.site-header {
  padding: 28px clamp(22px, 4vw, 64px) 24px;
  color: var(--header-text);
  background: linear-gradient(
    120deg,
    var(--header-start) 0%,
    var(--header-middle) 58%,
    var(--header-end) 100%
  );
}

.site-header > div,
.app-shell {
  width: min(var(--content-width), 100%);
  margin: 0 auto;
}

.eyebrow,
.section-kicker {
  margin: 0 0 7px;
  color: var(--header-eyebrow);
  font-size: 0.84rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 10px;
  font-size: clamp(2.45rem, 4vw, 3.55rem);
  line-height: 1;
  letter-spacing: -0.045em;
}

h2 {
  margin-bottom: 0;
  font-size: 1.3rem;
  letter-spacing: -0.02em;
}

.header-copy {
  max-width: 860px;
  margin-bottom: 0;
  color: var(--header-copy);
  font-size: 1.08rem;
  line-height: 1.48;
}

.app-shell {
  padding: 18px clamp(16px, 2.4vw, 32px) 36px;
}

.surface {
  border: 1px solid rgba(203, 213, 225, 0.82);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 16px;
  margin-bottom: 18px;
  padding: 15px 17px;
}

.toolbar-field {
  display: grid;
  gap: 7px;
  min-width: 225px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 700;
}

.toolbar-field.compact-field {
  min-width: 118px;
  max-width: 128px;
}

.toolbar-field.time-unit-field {
  min-width: 130px;
  max-width: 142px;
}

select,
input[type="number"],
input[type="text"] {
  min-height: 44px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  color: var(--ink);
  background: #fff;
  outline: none;
}

select,
.toolbar-field input {
  padding: 0 12px;
  font-size: 0.96rem;
  font-weight: 650;
}

select:focus,
input:focus-visible,
button:focus-visible,
summary:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(34, 87, 122, 0.16);
  outline: none;
}

.toggle-field {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 44px;
  color: #445064;
  font-size: 0.94rem;
  font-weight: 650;
}

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

.toolbar-actions {
  display: flex;
  flex: 1 1 470px;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.button {
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: 10px;
  font-size: 0.96rem;
  font-weight: 750;
}

.button.secondary {
  border-color: #9bb8ca;
  color: #194563;
  background: var(--accent-soft);
}

.button.secondary:hover {
  background: var(--accent-hover);
}

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

.button.ghost:hover {
  background: var(--surface-soft);
}

.button.ghost.time-unit-toggle {
  width: 100%;
  color: var(--ink);
  background: #fff;
  white-space: nowrap;
}

#reset-button {
  border-color: var(--danger);
  color: var(--danger);
  background: var(--danger-soft);
}

#reset-button:hover {
  background: var(--danger-soft-hover);
}

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

.plots-column {
  position: sticky;
  top: 18px;
  display: grid;
  grid-template-rows: auto minmax(240px, 1fr);
  gap: 18px;
  height: var(--desktop-viewport-height);
  min-width: 0;
  min-height: 680px;
}

.plot-surface {
  padding: 19px 20px 9px;
}

.section-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
}

.section-heading .section-kicker,
.controls-panel-header .section-kicker {
  color: var(--section-accent);
}

.component-count,
.components-heading > p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.combined-legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  column-gap: 28px;
  row-gap: 8px;
  padding: 11px 22px 0 68px;
  color: #526073;
  font-size: 0.8rem;
}

.combined-legend[hidden] {
  display: none;
}

.combined-legend-item {
  display: inline-flex;
  min-width: 0;
  max-width: 220px;
  align-items: center;
  gap: 8px;
}

.combined-legend-swatch {
  width: 30px;
  flex: 0 0 30px;
  border-top-style: solid;
}

.combined-legend-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chart {
  position: relative;
  width: 100%;
  min-height: 290px;
}

.chart::after {
  position: absolute;
  right: 22px;
  bottom: 4px;
  left: 68px;
  z-index: 2;
  color: #475467;
  content: attr(data-axis-title);
  font-size: 15px;
  line-height: 20px;
  text-align: center;
  pointer-events: none;
}

.js-plotly-plot .hoverlayer .legend > .bg {
  transform: scaleX(1.24);
  transform-box: fill-box;
  transform-origin: left center;
}

.js-plotly-plot .hoverlayer .legend > .scrollbox {
  clip-path: none !important;
}

.combined-chart {
  min-height: 280px;
}

.components-section {
  display: flex;
  min-height: 0;
  flex-direction: column;
  overflow: hidden;
}

.components-heading {
  flex: 0 0 auto;
  padding: 0 4px 11px;
}

.component-charts {
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
  flex-direction: column;
  gap: 14px;
  padding-right: 7px;
  overflow-y: hidden;
  scrollbar-gutter: stable;
}

.plots-column.is-pinned .component-charts {
  overflow-y: auto;
  overscroll-behavior: contain;
}

.component-chart-card {
  flex: 0 0 auto;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: var(--surface);
  box-shadow: 0 7px 22px rgba(31, 48, 68, 0.055);
}

.component-chart-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 15px 18px 0;
}

.component-chart-title h3 {
  margin: 0;
  font-size: 1.08rem;
}

.component-chart-title span {
  color: var(--muted);
  font-size: 0.84rem;
}

.component-chart {
  min-height: 230px;
}

.controls-panel {
  position: sticky;
  top: 18px;
  display: flex;
  flex-direction: column;
  height: auto;
  max-height: var(--desktop-viewport-height);
  overflow: hidden;
}

.controls-panel-header {
  flex: 0 0 auto;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--line);
}

.component-controls {
  display: grid;
  flex: 0 1 auto;
  min-height: 0;
  align-content: start;
  grid-auto-rows: max-content;
  gap: 12px;
  padding: 14px 15px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}

.component-card {
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface-soft);
}

.component-card-header {
  display: grid;
  grid-template-columns: 10px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
}

.color-marker {
  width: 10px;
  height: 38px;
  border-radius: 999px;
  background: var(--component-color);
}

.component-name {
  width: 100%;
  min-height: 40px;
  padding: 0 10px;
  font-size: 0.96rem;
  font-weight: 750;
}

.component-type {
  padding: 5px 8px;
  border-radius: 999px;
  color: #4d5b6e;
  background: #e7ebf1;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.component-card-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 10px 0 14px;
}

.small-toggle {
  min-height: auto;
  font-size: 0.82rem;
}

.small-toggle input {
  width: 17px;
  height: 17px;
}

.delete-component {
  padding: 5px 9px;
  border: 1px solid var(--danger);
  border-radius: 8px;
  color: var(--danger);
  background: transparent;
  font-size: 0.82rem;
  font-weight: 700;
}

.delete-component:hover {
  background: rgba(180, 35, 24, 0.05);
}

.component-fields,
.advanced-fields {
  display: grid;
  gap: 12px;
}

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

.field-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.field-label-row label,
.color-field span {
  color: #536074;
  font-size: 0.84rem;
  font-weight: 700;
}

.number-input {
  width: 88px;
  min-height: 36px !important;
  padding: 0 8px;
  font-size: 0.92rem;
  text-align: right;
}

.range-input {
  width: 100%;
  min-height: 22px;
  accent-color: var(--component-color);
}

.advanced-settings {
  margin-top: 13px;
  border-top: 1px solid var(--line);
}

.advanced-settings[hidden] {
  display: none;
}

.advanced-settings summary {
  margin: 10px 0;
  color: #596679;
  font-size: 0.83rem;
  font-weight: 750;
  cursor: pointer;
}

.color-field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 13px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.component-color {
  width: 42px;
  height: 28px;
  padding: 2px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #fff;
}

.empty-state {
  padding: 38px 20px;
  border: 1px dashed var(--line-strong);
  border-radius: 14px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.55);
  text-align: center;
}

@media (min-width: 1041px) {
  body {
    zoom: 0.75;
  }
}

@media (max-width: 1040px) {
  .workspace-grid {
    grid-template-columns: 1fr;
  }

  .plots-column {
    position: static;
    display: block;
    height: auto;
    min-height: 0;
  }

  .components-section {
    display: block;
    margin-top: 28px;
    overflow: visible;
  }

  .component-charts {
    overflow: visible;
  }

  .controls-panel {
    position: static;
    display: block;
    grid-row: 1;
    height: auto;
    max-height: none;
  }

  .component-controls {
    grid-template-columns: repeat(auto-fit, minmax(285px, 1fr));
    max-height: none;
  }
}

@media (max-width: 680px) {
  .site-header {
    padding-top: 26px;
  }

  .toolbar {
    align-items: stretch;
  }

  .toolbar-field,
  .toolbar-field.compact-field {
    min-width: 0;
    max-width: none;
    flex: 1 1 145px;
  }

  .toolbar-actions {
    flex-basis: 100%;
    justify-content: stretch;
  }

  .toolbar-actions .button {
    flex: 1 1 100%;
  }

  .plot-surface {
    padding: 18px 10px 8px;
  }

  .combined-legend {
    column-gap: 20px;
    padding-right: 12px;
    padding-left: 68px;
  }

  .section-heading {
    align-items: start;
    flex-direction: column;
    gap: 5px;
  }

  .components-heading {
    padding-inline: 2px;
  }

  .combined-chart {
    min-height: 280px;
  }
}
