:root {
  --page: #f3f5f8;
  --panel: #ffffff;
  --ink: #17202a;
  --muted: #667085;
  --line: #e3e7ed;
  --accent: #1d4ed8;
  --accent-ink: #ffffff;
  --danger: #dc2626;
  --shadow: 0 8px 20px rgba(23, 32, 42, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

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

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 12px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}

.back-link {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.9rem;
  white-space: nowrap;
}

.back-link:hover {
  color: var(--ink);
}

.topbar h1 {
  margin: 0;
  font-size: 1.15rem;
  flex: 1;
}

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

.field-inline {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--muted);
}

.field-inline select {
  padding: 5px 8px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--panel);
  font-size: 0.85rem;
}

.btn {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  padding: 8px 14px;
  border-radius: 7px;
  font-size: 0.88rem;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease, transform 120ms ease;
}

.btn:hover {
  border-color: color-mix(in srgb, var(--accent), transparent 40%);
  transform: translateY(-1px);
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}

.btn-primary:hover {
  background: color-mix(in srgb, var(--accent), #000 12%);
}

.btn-add {
  background: color-mix(in srgb, var(--accent), #fff 88%);
  border-color: color-mix(in srgb, var(--accent), transparent 55%);
  color: var(--accent);
  font-weight: 600;
  white-space: nowrap;
}

.btn-remove {
  padding: 2px 9px;
  font-size: 1.05rem;
  line-height: 1;
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger), transparent 60%);
  background: color-mix(in srgb, var(--danger), #fff 92%);
}

.workspace {
  flex: 1;
  display: flex;
  min-height: 0;
}

.sidebar {
  width: 360px;
  min-width: 360px;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  border-right: 1px solid var(--line);
  background: var(--page);
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px;
  box-shadow: var(--shadow);
}

.panel h2 {
  margin: 0 0 10px;
  font-size: 0.95rem;
  font-weight: 700;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.panel-header h2 {
  margin: 0;
}

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

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 600;
}

.field input[type="text"],
.field input[type="number"],
.field textarea,
.field select {
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 400;
  color: var(--ink);
  padding: 6px 8px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--panel);
  width: 100%;
}

.field textarea {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  resize: vertical;
}

.field input[type="range"] {
  width: 100%;
}

.field input[type="color"] {
  width: 100%;
  height: 32px;
  padding: 2px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--panel);
}

.checkbox-field {
  flex-direction: row;
  align-items: center;
  gap: 8px;
}

.checkbox-field input {
  width: auto;
}

.series-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.series-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: color-mix(in srgb, var(--page), #fff 40%);
}

.series-card-head {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
}

.series-card-head .s-color {
  width: 30px;
  height: 30px;
  padding: 2px;
  border-radius: 6px;
  border: 1px solid var(--line);
  flex: none;
}

.series-card-head .s-name {
  flex: 1;
  min-width: 0;
  padding: 6px 8px;
  border-radius: 6px;
  border: 1px solid var(--line);
  font-size: 0.85rem;
}

.series-card-head .s-type {
  flex: none;
  padding: 6px 8px;
  border-radius: 6px;
  border: 1px solid var(--line);
  font-size: 0.8rem;
}

.series-card-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.labels-config {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 4px;
  padding: 8px;
  border-radius: 6px;
  background: color-mix(in srgb, var(--page), #fff 20%);
}

.labels-config[hidden] {
  display: none;
}

.labels-hint {
  margin: 0;
  font-size: 0.72rem;
  color: var(--muted);
  font-weight: 400;
}

.series-warning {
  font-size: 0.75rem;
  color: #b45309;
  background: #fef3c7;
  border: 1px solid #fde68a;
  padding: 4px 8px;
  border-radius: 6px;
}

.canvas-wrap {
  flex: 1;
  position: relative;
  padding: 20px;
  min-width: 0;
}

#chart {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: 10px;
  touch-action: none;
}

.empty-state {
  position: absolute;
  inset: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 1rem;
  text-align: center;
  pointer-events: none;
}

.empty-state[hidden] {
  display: none;
}

@media (max-width: 900px) {
  .workspace {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    min-width: 0;
    max-height: 45vh;
    border-right: none;
    border-bottom: 1px solid var(--line);
  }
}
