:root {
  --chart-ink: #29251f;
  --chart-paper: #fbf7ef;
  --chart-surface: #fff;
  --chart-line: #ded6c8;
  --chart-line-strong: #bcb3a5;
  --chart-accent: #b84931;
  --chart-teal: #285544;
  --chart-muted: #6f685e;
  --chart-error: #8b3525;
}

.chart-app {
  box-sizing: border-box;
  width: min(100%, 1440px);
  margin: 0 auto;
  padding: 42px 28px 72px;
  color: var(--chart-ink);
}

.chart-intro {
  max-width: 720px;
  margin-bottom: 30px;
}

.chart-kicker,
.eyebrow {
  margin: 0;
  color: var(--chart-accent);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: .16em;
}

.chart-intro h1 {
  margin: 7px 0;
  font-size: clamp(30px, 4vw, 46px);
  line-height: 1.25;
  letter-spacing: -.03em;
}

.chart-intro > p:last-child {
  margin: 0;
  color: var(--chart-muted);
  font-size: 16px;
}

.chart-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 430px;
  gap: 30px;
  align-items: start;
}

.chart-preview {
  position: sticky;
  top: 20px;
  min-width: 0;
}

.preview-bar {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: end;
  margin-bottom: 12px;
}

.preview-bar > div {
  display: grid;
  gap: 2px;
}

.preview-bar strong {
  font-size: 20px;
}

.preview-bar > span,
.preview-note {
  color: var(--chart-muted);
  font-size: 13px;
}

.canvas-frame {
  overflow: hidden;
  border: 1px solid var(--chart-line);
  border-radius: 6px;
  background: var(--chart-paper);
  box-shadow: 0 14px 34px rgba(50, 42, 31, .1);
}

#chart {
  display: block;
  width: 100%;
  height: auto;
  background: var(--chart-paper);
}

.preview-note {
  margin: 10px 0 0;
}

.chart-editor {
  border-top: 4px solid var(--chart-teal);
  background: var(--chart-surface);
  box-shadow: 0 12px 32px rgba(50, 42, 31, .08);
}

.editor-section {
  padding: 22px 24px;
  border-top: 1px solid var(--chart-line);
}

.editor-section-first {
  border-top: 0;
}

.editor-section h2 {
  margin: 0 0 14px;
  font-size: 16px;
  line-height: 1.4;
}

.mode {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
}

.mode button {
  min-height: 44px;
  border: 1px solid var(--chart-line-strong);
  border-right-width: 0;
  background: #fff;
  color: var(--chart-ink);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.mode button:first-child {
  border-radius: 7px 0 0 7px;
}

.mode button:last-child {
  border-right-width: 1px;
  border-radius: 0 7px 7px 0;
}

.mode button[aria-pressed="true"] {
  border-color: var(--chart-teal);
  background: var(--chart-teal);
  color: #fff;
}

.field {
  display: grid;
  gap: 7px;
  margin-bottom: 15px;
  font-size: 13px;
  font-weight: 700;
}

.field:last-child {
  margin-bottom: 0;
}

.chart-editor input,
.chart-editor textarea,
.chart-editor select {
  box-sizing: border-box;
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--chart-line-strong);
  border-radius: 6px;
  padding: 9px 11px;
  background: #fff;
  color: var(--chart-ink);
  font: inherit;
}

.chart-editor textarea {
  line-height: 1.55;
  resize: vertical;
}

.chart-editor input:focus-visible,
.chart-editor textarea:focus-visible,
.chart-editor select:focus-visible,
.chart-editor button:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--chart-accent) 36%, transparent);
  outline-offset: 2px;
}

.meta-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.color-control {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 4px 10px 4px 5px;
  border: 1px solid var(--chart-line-strong);
  border-radius: 6px;
}

.color-control input[type="color"] {
  width: 45px;
  min-height: 34px;
  padding: 0;
  border: 0;
  cursor: pointer;
}

.color-control output {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .03em;
}

.help,
.section-note,
.save-note {
  color: var(--chart-muted);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.55;
}

.help {
  margin: -8px 0 15px;
}

.section-heading {
  display: flex;
  justify-content: space-between;
  gap: 15px;
  align-items: start;
  margin-bottom: 12px;
}

.section-heading h2,
.section-heading p {
  margin: 0;
}

.secondary-button,
.compact-primary,
.text-button,
.add-row,
.remove-row {
  font: inherit;
  cursor: pointer;
}

.secondary-button {
  min-height: 38px;
  border: 1px solid var(--chart-teal);
  border-radius: 6px;
  padding: 7px 11px;
  background: #fff;
  color: var(--chart-teal);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.paste-panel {
  margin-bottom: 16px;
  padding: 15px;
  border: 1px solid var(--chart-line);
  background: var(--chart-paper);
}

.paste-panel .field {
  margin-bottom: 8px;
}

.paste-panel .help {
  margin: 6px 0 10px;
}

.paste-actions {
  display: flex;
  gap: 9px;
  align-items: center;
}

.compact-primary {
  min-height: 38px;
  border: 0;
  border-radius: 6px;
  padding: 7px 13px;
  background: var(--chart-teal);
  color: #fff;
  font-weight: 700;
}

.text-button {
  min-height: 38px;
  border: 0;
  padding: 7px;
  background: transparent;
  color: var(--chart-muted);
  text-decoration: underline;
}

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

.data-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.data-table th {
  padding: 0 5px 6px;
  color: var(--chart-muted);
  font-size: 11px;
  text-align: left;
}

.data-table th:nth-child(2) {
  width: 112px;
}

.data-table th:last-child {
  width: 108px;
}

.data-table td {
  padding: 4px;
  vertical-align: middle;
}

.data-table td:first-child {
  padding-left: 0;
}

.data-table td:last-child {
  padding-inline: 0;
}

.data-table input {
  min-height: 40px;
  padding: 7px 9px;
}

.data-table tr[aria-invalid="true"] input {
  border-color: var(--chart-error);
  background: #fff8f5;
}

.add-row {
  width: 100%;
  min-height: 42px;
  margin-top: 8px;
  border: 1px dashed var(--chart-line-strong);
  border-radius: 6px;
  background: #fff;
  color: var(--chart-teal);
  font-weight: 700;
}

.add-row:disabled {
  cursor: not-allowed;
  opacity: .45;
}

.errors:empty {
  display: none;
}

.errors {
  margin-top: 12px;
  padding: 10px 12px;
  border-left: 3px solid var(--chart-accent);
  background: #fff2ee;
  color: var(--chart-error);
  font-size: 12px;
  line-height: 1.6;
  white-space: pre-line;
}

.save-area {
  padding: 22px 24px 24px;
  border-top: 1px solid var(--chart-line);
}

.save {
  width: 100%;
  min-height: 50px;
  border: 0;
  border-radius: 7px;
  background: var(--chart-accent);
  color: #fff;
  font: inherit;
  font-size: 16px;
  font-weight: 900;
  cursor: pointer;
}

.save:hover {
  filter: brightness(.93);
}

.save-note {
  margin: 8px 0 0;
  text-align: center;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 980px) {
  .chart-layout {
    grid-template-columns: minmax(0, 1fr) 390px;
    gap: 20px;
  }

  .chart-app {
    padding-inline: 18px;
  }
}

@media (max-width: 780px) {
  .chart-app {
    padding: 28px 12px 54px;
  }

  .chart-intro {
    margin-bottom: 20px;
  }

  .chart-layout {
    display: flex;
    flex-direction: column;
  }

  .chart-preview,
  .chart-editor {
    width: 100%;
  }

  .chart-preview {
    position: static;
  }

  .save-mobile {
    display: block;
    margin-top: 12px;
  }

  .preview-note {
    margin-bottom: 0;
  }
}

@media (max-width: 420px) {
  .chart-app {
    padding-inline: 8px;
  }

  .chart-intro {
    padding-inline: 4px;
  }

  .editor-section,
  .save-area {
    padding-inline: 16px;
  }

  .meta-grid {
    grid-template-columns: 1fr;
    gap: 0;
  }

  .section-heading {
    align-items: center;
  }

  .data-table th:nth-child(2) {
    width: 94px;
  }

  .canvas-frame {
    border-radius: 3px;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    scroll-behavior: auto !important;
  }
}

.chart-editor,
.data-table input,
.meta-grid > * {
  min-width: 0;
}

.row-actions {
  display: flex;
}

.save-mobile {
  display: none;
}

.row-actions button {
  cursor: pointer;
  flex: 1 1 0;
  min-width: 0;
  min-height: 40px;
  padding: 0;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--chart-teal);
  font-size: 1rem;
}

.row-actions button:hover:not(:disabled) {
  background: #f2eee7;
}

.row-actions .remove-row:hover {
  color: var(--chart-error);
}

.row-actions button:disabled {
  cursor: default;
  opacity: .4;
}

.unit-note,
.sample-note {
  margin-top: 4px;
}

.save:disabled {
  opacity: .55;
  cursor: not-allowed;
}

.save-area .secondary-button {
  margin-top: 16px;
}

.save-note:empty {
  display: none;
}
