:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #17202a;
  --muted: #667085;
  --line: #d9dee7;
  --line-strong: #b8c0cc;
  --brand: #2563eb;
  --brand-dark: #174ec4;
  --ok: #12805c;
  --shadow: 0 18px 50px rgba(22, 34, 51, 0.10);
}

* {
  box-sizing: border-box;
}

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

body {
  background: var(--bg);
  color: var(--ink);
  font-family:
    Inter, "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button,
input,
select {
  font: inherit;
}

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

.workspace,
.control-panel {
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 14px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--brand);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0;
}

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

h1 {
  margin-bottom: 0;
  font-size: 30px;
  line-height: 1.15;
}

h2 {
  margin-bottom: 0;
  font-size: 16px;
}

.status-pill {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--muted);
  padding: 9px 13px;
  font-size: 13px;
}

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

.preview-panel {
  overflow: hidden;
}

.canvas-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding: 14px 16px;
}

.canvas-toolbar strong,
.canvas-toolbar span {
  display: block;
}

.canvas-toolbar span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 13px;
}

.toolbar-actions {
  display: flex;
  gap: 10px;
  white-space: nowrap;
}

button {
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 700;
  transition:
    transform 160ms ease,
    background-color 160ms ease,
    opacity 160ms ease;
}

button:active {
  transform: translateY(1px);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.46;
}

.primary-btn {
  background: var(--brand);
  color: #fff;
  padding: 10px 14px;
}

.primary-btn:hover:not(:disabled) {
  background: var(--brand-dark);
}

.ghost-btn {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  padding: 9px 13px;
}

.ghost-btn:hover {
  background: #f0f4fb;
}

.canvas-stage {
  position: relative;
  display: grid;
  min-height: calc(100vh - 128px);
  place-items: center;
  overflow: auto;
  padding: 18px;
  background:
    linear-gradient(45deg, #eef1f6 25%, transparent 25%),
    linear-gradient(-45deg, #eef1f6 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #eef1f6 75%),
    linear-gradient(-45deg, transparent 75%, #eef1f6 75%);
  background-color: #fafbfc;
  background-position:
    0 0,
    0 10px,
    10px -10px,
    -10px 0;
  background-size: 20px 20px;
}

canvas {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 10px 34px rgba(20, 31, 47, 0.15);
}

.empty-state {
  position: absolute;
  inset: 18px;
  display: grid;
  place-content: center;
  justify-items: center;
  border: 2px dashed #c7cfdb;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.82);
  padding: 28px;
  text-align: center;
}

.empty-state.is-hidden {
  display: none;
}

.upload-icon {
  display: grid;
  width: 54px;
  height: 54px;
  place-items: center;
  border-radius: 999px;
  background: #eaf1ff;
  color: var(--brand);
  font-size: 34px;
  font-weight: 400;
}

.empty-state h2 {
  margin: 16px 0 8px;
  font-size: 22px;
}

.empty-state p {
  max-width: 560px;
  color: var(--muted);
  line-height: 1.7;
}

.control-panel {
  align-self: start;
  max-height: calc(100vh - 36px);
  overflow: auto;
  padding: 14px;
}

.upload-card {
  border: 2px dashed #c7cfdb;
  border-radius: 8px;
  background: #f9fbff;
  margin-bottom: 14px;
  transition:
    border-color 160ms ease,
    background-color 160ms ease;
}

.upload-card.is-over {
  border-color: var(--brand);
  background: #edf4ff;
}

.upload-card input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.upload-card label {
  display: grid;
  gap: 6px;
  padding: 22px 16px;
  text-align: center;
  cursor: pointer;
}

.upload-card span {
  color: var(--brand);
  font-size: 18px;
  font-weight: 800;
}

.upload-card small,
.muted {
  color: var(--muted);
}

.control-group {
  border-top: 1px solid var(--line);
  padding: 16px 0 2px;
}

.group-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.group-title span {
  color: var(--muted);
  font-size: 13px;
}

label {
  display: grid;
  gap: 7px;
  margin-bottom: 12px;
  color: #344054;
  font-size: 13px;
  font-weight: 700;
}

input[type="number"],
input[type="text"],
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  outline: 0;
  padding: 10px 11px;
}

input:focus,
select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

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

.switch-row {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-weight: 600;
}

.switch-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--brand);
}

.legend-list {
  display: grid;
  gap: 8px;
  max-height: 260px;
  overflow: auto;
  padding-right: 3px;
}

.legend-item {
  display: grid;
  grid-template-columns: 18px 1fr auto;
  gap: 9px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  font-size: 13px;
}

.swatch {
  width: 18px;
  height: 18px;
  border: 1px solid rgba(0, 0, 0, 0.16);
  border-radius: 5px;
}

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

.legend-count {
  color: var(--ok);
  font-weight: 800;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 10;
  max-width: min(420px, calc(100vw - 36px));
  border-radius: 8px;
  background: #17202a;
  color: #fff;
  padding: 12px 14px;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition:
    opacity 180ms ease,
    transform 180ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

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

  .control-panel {
    max-height: none;
  }

  .canvas-stage {
    min-height: 560px;
  }
}

@media (max-width: 640px) {
  .app-shell {
    padding: 10px;
  }

  .topbar,
  .canvas-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  h1 {
    font-size: 25px;
  }

  .toolbar-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }
}
