:root {
  color-scheme: light;
  --bg: #f6f8fb;
  --surface: #ffffff;
  --surface-strong: #eef4f8;
  --text: #15202b;
  --muted: #667085;
  --line: #d9e2ea;
  --accent: #1f7a8c;
  --accent-strong: #155e6f;
  --danger: #b42318;
  --shadow: 0 16px 40px rgba(21, 32, 43, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", Arial, sans-serif;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  padding: 28px 40px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

h1 {
  margin: 0;
  font-size: 28px;
  line-height: 1.25;
  font-weight: 750;
}

p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 14px;
}

button,
.file-button {
  border: 0;
  border-radius: 6px;
  padding: 10px 14px;
  color: #fff;
  background: var(--accent);
  font: inherit;
  font-size: 14px;
  font-weight: 650;
  cursor: pointer;
  transition: background 140ms ease, transform 140ms ease;
}

button:hover,
.file-button:hover {
  background: var(--accent-strong);
}

button:active,
.file-button:active {
  transform: translateY(1px);
}

.secondary {
  background: #284b63;
}

.secondary:hover {
  background: #1e3a4f;
}

.ghost {
  color: #284b63;
  background: #e8eef3;
}

.ghost:hover {
  color: #15202b;
  background: #dce7ee;
}

.topbar-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.topbar-actions,
.summary {
  display: none !important;
}

.file-button input {
  display: none;
}

main {
  width: min(1480px, calc(100% - 48px));
  margin: 24px auto 44px;
}

.summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.summary div {
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.summary span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.summary strong {
  display: block;
  margin-top: 8px;
  font-size: 22px;
}

.chart-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 18px;
}

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

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}

.panel-head > div:first-child {
  flex: 1;
  min-width: 0;
}

.download-btn {
  min-width: 88px;
  white-space: nowrap;
}

.title-input {
  width: 100%;
  border: 1px solid #c7d7e3;
  border-radius: 8px;
  outline: 0;
  color: var(--text);
  background: #f8fbfd;
  padding: 12px 14px;
  font-size: 20px;
  font-weight: 750;
  transition: border-color 140ms ease, box-shadow 140ms ease, background 140ms ease;
  cursor: text;
}

.title-input:hover {
  border-color: #8fb2c7;
  background: #ffffff;
}

.title-input:focus {
  border-color: #1f7a8c;
  background: #ffffff;
  box-shadow: 0 0 0 3px rgba(31, 122, 140, 0.14);
}

.title-input::placeholder {
  color: #7a8da1;
  font-weight: 600;
}

.type-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 12px;
}

label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

select,
input {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  color: var(--text);
  background: #fff;
  font: inherit;
}

.unit-input {
  width: 72px;
}

.chart-body {
  display: grid;
  grid-template-columns: minmax(360px, 1fr) minmax(360px, 0.9fr);
  gap: 20px;
  padding: 20px;
  min-width: 0;
}

.chart-canvas {
  min-height: 420px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, #ffffff 0%, #f8fbfd 100%);
  overflow: hidden;
  min-width: 0;
  cursor: zoom-in;
}

.chart-canvas svg {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 420px;
}

.data-editor {
  overflow: auto;
  min-width: 0;
}

table {
  width: 100%;
  min-width: 560px;
  border-collapse: collapse;
  table-layout: fixed;
}

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

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

td input {
  width: 100%;
}

.percent-input {
  color: var(--muted);
  background: #f8fafc;
  cursor: default;
}

th:nth-child(2),
td:nth-child(2),
th:nth-child(3),
td:nth-child(3) {
  width: 96px;
}

th:last-child,
td:last-child {
  width: 48px;
  text-align: right;
}

.delete-row {
  width: 34px;
  height: 34px;
  padding: 0;
  color: var(--danger);
  background: #fff1f0;
}

.delete-row:hover {
  color: #fff;
  background: var(--danger);
}

.add-row {
  margin-top: 12px;
}

.axis {
  stroke: #98a2b3;
  stroke-width: 1;
}

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

.chart-title {
  fill: #15202b;
  font-size: 18px;
  font-weight: 750;
}

.chart-label {
  fill: #344054;
  font-size: 12px;
}

.chart-muted {
  fill: #667085;
  font-size: 12px;
}

.preview-modal[hidden] {
  display: none;
}

.preview-modal {
  position: fixed;
  inset: 0;
  z-index: 50;
}

.preview-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.48);
  backdrop-filter: blur(4px);
}

.preview-dialog {
  position: relative;
  display: flex;
  flex-direction: column;
  width: min(1240px, calc(100vw - 40px));
  height: min(88vh, 920px);
  margin: 4vh auto 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 28px 80px rgba(15, 23, 42, 0.26);
  overflow: hidden;
}

.preview-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
}

.preview-title {
  font-size: 18px;
  font-weight: 750;
}

.preview-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.preview-viewport {
  flex: 1;
  overflow: auto;
  padding: 24px;
  background: #eef4f8;
}

.preview-canvas {
  display: grid;
  place-items: center;
  min-width: 100%;
  min-height: 100%;
}

.preview-canvas svg {
  display: block;
  width: min(100%, 1100px);
  height: auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 16px 40px rgba(21, 32, 43, 0.12);
  transform-origin: center center;
  transition: transform 160ms ease;
}

@media (max-width: 980px) {
  .topbar,
  .panel-head,
  .chart-body {
    grid-template-columns: 1fr;
    flex-direction: column;
  }

  .summary {
    grid-template-columns: repeat(2, minmax(140px, 1fr));
  }

  .preview-dialog {
    width: calc(100vw - 24px);
    height: calc(100vh - 24px);
    margin-top: 12px;
  }

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

@media (max-width: 640px) {
  .topbar {
    padding: 22px 18px;
  }

  main {
    width: min(100% - 24px, 1480px);
  }

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

  .chart-body {
    padding: 14px;
  }

  .panel-head {
    padding: 16px 14px;
    gap: 12px;
  }

  .title-input {
    width: 100%;
    font-size: 16px;
    line-height: 1.4;
  }

  .data-editor {
    overflow-x: hidden;
  }

  table {
    min-width: 0;
    table-layout: fixed;
  }

  th,
  td {
    padding: 8px 4px;
  }

  th:first-child,
  td:first-child {
    width: auto;
  }

  th:nth-child(2),
  td:nth-child(2),
  th:nth-child(3),
  td:nth-child(3) {
    width: 72px;
  }

  th:last-child,
  td:last-child {
    width: 40px;
  }

  td input {
    min-width: 0;
    padding: 8px 8px;
  }

  .delete-row {
    width: 30px;
    height: 30px;
  }
}
