:root {
  --bg: #f4f4f4;
  --panel: #e7e7e7;
  --panel-line: #d7d7d7;
  --card: #ffffff;
  --card-soft: #f7f7f7;
  --text: #1e1e1e;
  --text-soft: #666666;
  --accent: #d9d9d9;
  --accent-strong: #cfcfcf;
  --active: #bdbdbd;
  --danger: #d06a5d;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.06);
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
}

* {
  box-sizing: border-box;
}

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

body {
  color: var(--text);
  font-family: "Avenir Next", "PingFang SC", sans-serif;
  background: var(--bg);
  overflow: hidden;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--panel-line);
  border-radius: 10px;
  padding: 10px 12px;
  background: #fff;
  color: var(--text);
}

textarea {
  min-height: 92px;
  resize: vertical;
}

input[type="color"] {
  padding: 4px;
  min-height: 42px;
}

.app-shell {
  height: 100vh;
  display: grid;
  grid-template-rows: 72px 1fr;
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  padding: 0 24px 0 36px;
  background: #ffffff;
  border-bottom: 1px solid #ececec;
}

.app-header h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 600;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 16px;
}

.app-main {
  display: grid;
  grid-template-columns: 464px minmax(0, 1fr);
  height: calc(100vh - 72px);
  min-height: 0;
}

.sidebar {
  display: grid;
  grid-template-rows: auto 1fr;
  background: #e9e9e9;
  border-right: 1px solid #e0e0e0;
  min-height: 0;
}

.tab-strip {
  display: flex;
  gap: 14px;
  padding: 14px 14px 12px;
  flex-wrap: wrap;
}

.tab-btn,
.pill-btn,
.zoom-btn {
  padding: 12px 18px;
  border-radius: 18px;
  background: var(--accent);
  color: var(--text);
  transition: background 120ms ease, transform 120ms ease;
}

.tab-btn:hover,
.pill-btn:hover,
.zoom-btn:hover {
  background: var(--accent-strong);
  transform: translateY(-1px);
}

.pill-btn:disabled,
.zoom-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

.pill-btn:disabled:hover,
.zoom-btn:disabled:hover {
  background: var(--accent);
  transform: none;
}

.tab-btn.active {
  background: var(--active);
}

.pill-btn.strong {
  background: #d3d3d3;
}

.pill-btn.danger {
  color: #fff;
  background: var(--danger);
}

.sidebar-body {
  padding: 0 14px 18px;
  overflow: auto;
  min-height: 0;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.section-block {
  margin-bottom: 14px;
  padding: 12px;
  border: 1px solid var(--panel-line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.45);
}

.section-title {
  margin-bottom: 8px;
}

.section-title h2 {
  margin: 0 0 4px;
  font-size: 16px;
  font-weight: 600;
}

.section-title p {
  margin: 0;
  color: var(--text-soft);
  font-size: 12px;
  line-height: 1.5;
}

.field-stack,
.properties-panel,
.card-list {
  display: grid;
  gap: 8px;
}

#elements-list.card-list {
  gap: 6px;
}

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

.field {
  display: grid;
  gap: 6px;
}

.field span,
.property-stack label span,
.property-grid label span {
  font-size: 12px;
  color: var(--text-soft);
}

.preset-row,
.tool-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.align-tool-row {
  margin-top: 8px;
}

.property-subtitle {
  margin-top: 10px;
  font-size: 12px;
  color: var(--text-soft);
}

.mini-action-btn {
  padding: 8px 12px;
  border-radius: 10px;
  background: #f1f1f1;
  color: var(--text);
  font-size: 12px;
  line-height: 1;
}

.mini-action-btn:hover {
  background: #e6e6e6;
}

.compact-tool-row {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
}

.compact-tool-row .pill-btn {
  padding: 10px 0;
  font-size: 12px;
  white-space: nowrap;
}

.inline-check {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
}

.inline-check input {
  width: 18px;
  height: 18px;
  margin: 0;
}

.full-width {
  width: 100%;
}

.card-list {
  min-height: 28px;
}

.element-card,
.field-card,
.layer-item,
.row-card,
.property-section {
  padding: 10px 12px;
  border: 1px solid var(--panel-line);
  border-radius: 12px;
  background: var(--card);
}

.element-card,
.layer-item,
.row-card {
  width: 100%;
  text-align: left;
}

.element-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 8px;
}

.element-card.active,
.layer-item.active,
.row-card.active {
  border-color: #bcbcbc;
  background: #fafafa;
}

.element-card-head,
.field-card-head,
.row-card-head,
.layer-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.meta-stack {
  display: grid;
  gap: 1px;
}

.element-card-main {
  flex: 1;
  min-width: 0;
  padding: 0;
  background: transparent;
  text-align: left;
}

.element-inline {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.element-inline strong {
  font-size: 13px;
  line-height: 1.3;
}

.element-note {
  min-width: 0;
  color: var(--text-soft);
  font-size: 11px;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.element-tools {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.layer-order-btn {
  width: 24px;
  height: 24px;
  padding: 0;
  border: 1px solid var(--panel-line);
  border-radius: 8px;
  background: #f4f4f4;
  color: #4f4f4f;
  font-size: 12px;
}

.layer-order-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.meta-stack small,
.field-card small,
.row-card small,
.status-text,
.muted-text {
  color: var(--text-soft);
  font-size: 11px;
  line-height: 1.5;
}

.source-doc-list {
  gap: 6px;
}

.source-doc-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--panel-line);
  border-radius: 12px;
  background: var(--card);
}

.source-doc-meta {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.source-doc-meta strong {
  min-width: 0;
  font-size: 12px;
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.source-doc-meta small {
  color: var(--text-soft);
  font-size: 11px;
}

.source-doc-remove-btn {
  flex-shrink: 0;
  padding: 6px 10px;
  border: 1px solid var(--panel-line);
  border-radius: 10px;
  background: #f6f6f6;
  color: #5d5d5d;
  font-size: 12px;
}

.source-doc-remove-btn:hover {
  background: #ededed;
}

.badge,
.binding-pill,
.error-badge,
.warning-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 6px;
  border-radius: 999px;
  font-size: 10px;
}

.badge,
.binding-pill {
  background: #efefef;
  color: #555;
}

.error-badge {
  background: #f0c8c3;
  color: #7c2e24;
}

.warning-badge {
  background: #f4e2b6;
  color: #7d5b16;
}

.danger-link {
  padding: 0;
  color: #b3574c;
  background: transparent;
}

.property-section h3 {
  margin: 0 0 10px;
  font-size: 14px;
}

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

.property-stack {
  display: grid;
  gap: 10px;
}

.checkbox-line {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
}

.checkbox-line input {
  width: 18px;
  height: 18px;
  margin: 0;
}

.toggle-field {
  display: grid;
  gap: 8px;
  align-content: start;
}

.toggle-label {
  gap: 8px;
}

.toggle-field.disabled {
  opacity: 0.62;
}

.toggle-field input[type="color"]:disabled,
.property-grid input:disabled {
  cursor: not-allowed;
}

.batch-preview {
  display: grid;
  gap: 10px;
}

.batch-preview img {
  width: 100%;
  min-height: 180px;
  object-fit: contain;
  background: #fff;
  border: 1px solid var(--panel-line);
  border-radius: 12px;
}

.download-link {
  color: #2f2f2f;
  font-weight: 600;
}

.workspace-panel {
  display: flex;
  flex-direction: column;
  background: #ffffff;
  min-height: 0;
}

.workspace {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: #ffffff;
  min-height: 0;
}

.canvas-stage {
  position: absolute;
  inset: 0;
  transform-origin: 0 0;
}

.design-canvas {
  position: absolute;
  left: 50%;
  top: 48%;
  transform: translate(-50%, -50%);
  background: #d8d8d8;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.06);
}

.canvas-element {
  position: absolute;
  user-select: none;
  cursor: move;
}

.canvas-element.selected {
  outline: 2px solid #8f8f8f;
  outline-offset: 3px;
}

.shape-element {
  width: 100%;
  height: 100%;
}

.text-element {
  width: 100%;
  height: 100%;
  overflow: hidden;
  white-space: pre-wrap;
  word-break: break-word;
}

.text-box-element {
  position: absolute;
  box-sizing: border-box;
}

.image-element,
.image-element img {
  width: 100%;
  height: 100%;
}

.image-element {
  overflow: hidden;
  background: transparent;
}

.image-element img {
  object-fit: contain;
}

.image-placeholder {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  color: #8a8a8a;
  font-size: 12px;
  border: 1px dashed #bcbcbc;
}

.binding-pill {
  position: absolute;
  left: 0;
  top: -26px;
}

.resize-handle {
  position: absolute;
  right: -7px;
  bottom: -7px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #8f8f8f;
  cursor: nwse-resize;
}

.zoom-dock {
  position: absolute;
  right: 22px;
  bottom: 18px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
}

.zoom-btn {
  padding: 6px 10px;
  border-radius: 10px;
}

@media (max-width: 1200px) {
  .app-main {
    grid-template-columns: 1fr;
    height: auto;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid #e0e0e0;
  }

  .workspace {
    min-height: 760px;
  }

  body {
    overflow: auto;
  }
}

@media (max-width: 720px) {
  .app-header {
    padding: 12px 18px;
    align-items: flex-start;
    flex-direction: column;
  }

  .sidebar-body {
    padding: 0 10px 14px;
  }

  .header-actions {
    flex-wrap: wrap;
    gap: 10px;
  }

  .field-row,
  .property-grid {
    grid-template-columns: 1fr;
  }
}
