:root {
  --orange: #ff8f1f;
  --orange-dark: #df6f00;
  --orange-soft: #fff2e2;
  --ink: #17202c;
  --muted: #6d7785;
  --line: #e1e6ec;
  --panel: #ffffff;
  --canvas: #f3f5f7;
  --green: #1d9a67;
  --red: #d94b4b;
  --blue: #3578e5;
  --shadow: 0 12px 30px rgba(29, 42, 58, .08);
  --radius: 14px;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  overflow: hidden;
  background: var(--canvas);
  color: var(--ink);
  font-family: "Microsoft YaHei", "PingFang SC", "Noto Sans CJK SC", Arial, sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

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

button {
  color: inherit;
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  position: relative;
  z-index: 4;
  height: 68px;
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 0 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, .96);
  box-shadow: 0 3px 16px rgba(25, 35, 48, .05);
}

.brand {
  min-width: 260px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: linear-gradient(145deg, #ffad55, #f17800);
  color: #fff;
  box-shadow: 0 8px 18px rgba(241, 120, 0, .24);
  font: 900 17px/1 Arial, sans-serif;
}

.brand strong,
.brand span {
  display: block;
}

.brand strong {
  font-size: 16px;
}

.brand span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
}

.save-state {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-right: auto;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.save-state span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 4px rgba(29, 154, 103, .11);
}

.save-state.saving span {
  background: var(--orange);
  box-shadow: 0 0 0 4px rgba(255, 143, 31, .12);
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.button {
  min-height: 38px;
  padding: 8px 14px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: #fff;
  font-weight: 700;
  font-size: 12px;
  cursor: pointer;
  transition: border-color .2s, background .2s, color .2s, transform .2s, box-shadow .2s;
}

.button:hover {
  transform: translateY(-1px);
}

.button-ghost {
  border-color: var(--line);
  color: #4d5866;
}

.button-ghost:hover {
  border-color: #c9d0d9;
  background: #f8f9fb;
  color: var(--ink);
}

.button-primary {
  background: var(--orange);
  color: #fff;
  box-shadow: 0 7px 16px rgba(255, 143, 31, .22);
}

.button-primary:hover {
  background: var(--orange-dark);
}

.button-ai {
  border-color: #d7ccff;
  background: #f7f3ff;
  color: #6548c9;
}

.button-ai span {
  margin-left: 5px;
  padding: 2px 5px;
  border-radius: 8px;
  background: #e9e0ff;
  font-size: 9px;
}

.button-small {
  min-height: 32px;
  padding: 6px 10px;
}

.workspace {
  height: calc(100vh - 68px);
  display: grid;
  grid-template-columns: 284px minmax(500px, 1fr) 330px;
  overflow: hidden;
}

.panel {
  background: var(--panel);
}

.left-panel,
.right-panel {
  height: 100%;
  overflow-y: auto;
  padding: 22px 18px 40px;
  scrollbar-width: thin;
  scrollbar-color: #cfd5dc transparent;
}

.left-panel {
  border-right: 1px solid var(--line);
}

.right-panel {
  border-left: 1px solid var(--line);
}

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

.panel-heading.compact {
  margin-bottom: 6px;
}

.section-kicker {
  display: block;
  margin-bottom: 3px;
  color: #a2611f;
  font: 800 9px/1.2 Arial, sans-serif;
  letter-spacing: .15em;
  text-transform: uppercase;
}

.panel-heading h2,
.preview-toolbar h1,
.modal-header h2 {
  margin: 0;
  line-height: 1.25;
}

.panel-heading h2 {
  font-size: 17px;
}

.icon-button {
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  cursor: pointer;
}

.icon-button:hover {
  border-color: #c9d0d9;
  color: var(--ink);
}

.count-badge {
  min-width: 24px;
  height: 24px;
  display: inline-grid;
  place-items: center;
  padding: 0 6px;
  border-radius: 12px;
  background: var(--orange-soft);
  color: var(--orange-dark);
  font-size: 11px;
  font-weight: 800;
}

.helper-text {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.55;
}

.divider {
  height: 1px;
  margin: 22px 0;
  background: var(--line);
}

.theme-controls {
  display: grid;
  gap: 13px;
}

.control {
  display: grid;
  gap: 7px;
  color: #4f5967;
  font-size: 11px;
  font-weight: 700;
}

.control > span {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.control b {
  color: var(--muted);
  font-size: 10px;
  font-weight: 600;
}

.control input[type="text"],
.control input[type="url"],
.control input[type="number"],
.control textarea,
.control select {
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid #d8dee6;
  border-radius: 8px;
  outline: none;
  background: #fff;
  color: var(--ink);
  font-weight: 500;
  transition: border-color .2s, box-shadow .2s;
}

.control textarea {
  min-height: 82px;
  resize: vertical;
  line-height: 1.5;
}

.control input:focus,
.control textarea:focus,
.control select:focus {
  border-color: var(--orange);
  box-shadow: 0 0 0 3px rgba(255, 143, 31, .11);
}

.control input[type="range"] {
  width: 100%;
  accent-color: var(--orange);
}

.color-control {
  grid-template-columns: 1fr auto;
  align-items: center;
}

.color-control > span:first-child {
  grid-column: 1;
}

.color-control .color-value {
  grid-column: 1;
  justify-self: start;
  color: var(--muted);
  font: 600 10px/1 Consolas, monospace;
}

.color-control input[type="color"] {
  grid-column: 2;
  grid-row: 1 / span 2;
  width: 46px;
  height: 38px;
  padding: 3px;
  border: 1px solid #d8dee6;
  border-radius: 9px;
  background: #fff;
  cursor: pointer;
}

.template-list {
  display: grid;
  gap: 9px;
}

.template-card {
  position: relative;
  width: 100%;
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) 24px;
  align-items: center;
  gap: 11px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #fff;
  text-align: left;
  cursor: pointer;
  transition: border-color .2s, box-shadow .2s, transform .2s;
}

.template-card:hover {
  border-color: #f0b878;
  box-shadow: 0 7px 18px rgba(52, 43, 33, .08);
  transform: translateY(-1px);
}

.template-thumb {
  width: 48px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: linear-gradient(145deg, #fff8ef, #ffead0);
  color: var(--orange-dark);
  font-size: 19px;
  overflow: hidden;
}

.template-copy strong,
.template-copy span {
  display: block;
}

.template-copy strong {
  margin-bottom: 3px;
  font-size: 12px;
}

.template-copy span {
  overflow: hidden;
  color: var(--muted);
  font-size: 10px;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.template-plus {
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--orange-soft);
  color: var(--orange-dark);
  font-weight: 900;
}

.preview-column {
  min-width: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background:
    linear-gradient(45deg, rgba(205, 211, 218, .24) 25%, transparent 25%) 0 0 / 20px 20px,
    linear-gradient(-45deg, rgba(205, 211, 218, .24) 25%, transparent 25%) 0 10px / 20px 20px,
    linear-gradient(45deg, transparent 75%, rgba(205, 211, 218, .24) 75%) 10px -10px / 20px 20px,
    linear-gradient(-45deg, transparent 75%, rgba(205, 211, 218, .24) 75%) -10px 0 / 20px 20px,
    #edf0f3;
}

.preview-toolbar {
  min-height: 66px;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
}

.preview-toolbar > div:first-child {
  min-width: 158px;
}

.preview-toolbar h1 {
  font-size: 16px;
}

.toolbar-center {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 auto;
}

.device-switcher {
  display: flex;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #f4f6f8;
}

.device-button {
  min-width: 58px;
  min-height: 28px;
  padding: 4px 8px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 10px;
  cursor: pointer;
}

.device-button.active {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 2px 7px rgba(29, 42, 58, .12);
}

.preview-meta {
  min-width: 104px;
  display: grid;
  justify-items: end;
  gap: 2px;
  color: var(--muted);
  font-size: 10px;
}

.preview-stage {
  min-height: 0;
  flex: 1;
  overflow: auto;
  padding: 30px;
}

.preview-frame-wrap {
  min-height: calc(100% - 2px);
  margin: 0 auto;
  overflow: hidden;
  border: 1px solid #cfd6de;
  background: #fff;
  box-shadow: 0 18px 45px rgba(26, 37, 50, .15);
  transition: width .25s;
}

.preview-frame-wrap.device-desktop {
  width: 100%;
  max-width: 1280px;
}

.preview-frame-wrap.device-tablet {
  width: 768px;
  max-width: 100%;
}

.preview-frame-wrap.device-mobile {
  width: 390px;
  max-width: 100%;
}

#previewFrame {
  width: 100%;
  min-height: 760px;
  display: block;
  border: 0;
  background: #fff;
}

.preview-tip {
  margin: 0;
  padding: 8px 16px;
  border-top: 1px solid rgba(206, 213, 221, .8);
  background: rgba(255, 255, 255, .9);
  color: var(--muted);
  text-align: center;
  font-size: 10px;
}

.module-list {
  display: grid;
  gap: 7px;
}

.module-row {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  cursor: pointer;
}

.module-row:hover {
  border-color: #d2d8df;
}

.module-row.selected {
  border-color: #f0a454;
  background: #fff9f1;
  box-shadow: 0 0 0 2px rgba(255, 143, 31, .08);
}

.module-index {
  width: 27px;
  height: 27px;
  display: grid;
  place-items: center;
  border-radius: 7px;
  background: #f1f3f5;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
}

.module-row.selected .module-index {
  background: var(--orange);
  color: #fff;
}

.module-name strong,
.module-name span {
  display: block;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.module-name strong {
  margin-bottom: 2px;
  font-size: 11px;
}

.module-name span {
  color: var(--muted);
  font-size: 9px;
}

.module-quick-actions {
  display: flex;
  gap: 2px;
}

.mini-action {
  width: 23px;
  height: 23px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #8993a0;
  font-size: 11px;
  cursor: pointer;
}

.mini-action:hover {
  background: #eef1f4;
  color: var(--ink);
}

.empty-structure {
  padding: 22px 12px;
  border: 1px dashed #cfd6de;
  border-radius: 10px;
  color: var(--muted);
  text-align: center;
  font-size: 11px;
  line-height: 1.6;
}

.empty-inspector {
  padding: 30px 12px;
  text-align: center;
}

.empty-icon {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  margin: 0 auto 12px;
  border-radius: 16px;
  background: var(--orange-soft);
  color: var(--orange-dark);
  font-size: 23px;
}

.empty-inspector h3 {
  margin: 0 0 7px;
  font-size: 14px;
}

.empty-inspector p {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.65;
}

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

.inspector-heading h3 {
  margin: 2px 0 0;
  font-size: 16px;
}

.inspector-toolbar {
  display: flex;
  gap: 3px;
}

.inspector-section {
  margin-top: 18px;
}

.inspector-section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 11px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.inspector-section-title::after {
  content: "";
  height: 1px;
  flex: 1;
  background: var(--line);
}

.field-grid {
  display: grid;
  gap: 12px;
}

.field-grid.two {
  grid-template-columns: 1fr 1fr;
}

.danger-zone {
  margin-top: 22px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.delete-button {
  width: 100%;
  border-color: #f0c4c4;
  background: #fff7f7;
  color: var(--red);
}

.delete-button:hover {
  background: #fff0f0;
}

.toast {
  position: fixed;
  z-index: 10;
  left: 50%;
  bottom: 24px;
  max-width: min(460px, calc(100% - 32px));
  padding: 10px 16px;
  border-radius: 9px;
  background: #1c2633;
  color: #fff;
  box-shadow: 0 12px 28px rgba(20, 29, 40, .24);
  font-size: 12px;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 12px);
  transition: opacity .2s, transform .2s;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.modal {
  width: min(720px, calc(100% - 30px));
  max-height: calc(100vh - 40px);
  padding: 0;
  border: 0;
  border-radius: 16px;
  background: transparent;
  box-shadow: 0 24px 70px rgba(18, 27, 38, .26);
}

.modal::backdrop {
  background: rgba(15, 23, 34, .58);
  backdrop-filter: blur(4px);
}

.modal-card {
  margin: 0;
  padding: 24px;
  border-radius: 16px;
  background: #fff;
}

.modal-large {
  min-height: min(760px, calc(100vh - 40px));
  display: flex;
  flex-direction: column;
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
}

.modal-header h2 {
  font-size: 22px;
}

.modal-header p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 11px;
}

.modal-close {
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  color: var(--muted);
  font-size: 20px;
  cursor: pointer;
}

.export-summary {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.summary-chip {
  padding: 5px 9px;
  border-radius: 12px;
  background: #f1f3f5;
  color: #55606e;
  font-size: 10px;
  font-weight: 700;
}

.summary-chip.success {
  background: #e8f7f1;
  color: #167a53;
}

.summary-chip.warning {
  background: #fff2e2;
  color: #a85a07;
}

.code-output {
  width: 100%;
  min-height: 420px;
  flex: 1;
  resize: none;
  padding: 16px;
  border: 1px solid #263445;
  border-radius: 11px;
  outline: none;
  background: #14202c;
  color: #e5edf5;
  font: 12px/1.6 Consolas, "SFMono-Regular", Menlo, monospace;
  tab-size: 2;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}

.validation-score {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 18px;
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #f8fafb;
}

.score-circle {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #e8f7f1;
  color: var(--green);
  font-size: 18px;
  font-weight: 900;
}

.score-circle.warning {
  background: #fff2e2;
  color: var(--orange-dark);
}

.score-copy strong,
.score-copy span {
  display: block;
}

.score-copy strong {
  margin-bottom: 4px;
  font-size: 14px;
}

.score-copy span {
  color: var(--muted);
  font-size: 11px;
}

.validation-list {
  max-height: 52vh;
  display: grid;
  gap: 8px;
  overflow-y: auto;
}

.validation-item {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 9px;
}

.validation-icon {
  width: 27px;
  height: 27px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #e8f7f1;
  color: var(--green);
  font-size: 12px;
  font-weight: 900;
}

.validation-item.warning .validation-icon {
  background: #fff2e2;
  color: var(--orange-dark);
}

.validation-item.error .validation-icon {
  background: #fff0f0;
  color: var(--red);
}

.validation-copy strong,
.validation-copy span {
  display: block;
}

.validation-copy strong {
  margin-bottom: 3px;
  font-size: 11px;
}

.validation-copy span {
  color: var(--muted);
  font-size: 10px;
  line-height: 1.5;
}

@media (max-width: 1180px) {
  .workspace {
    grid-template-columns: 250px minmax(420px, 1fr) 300px;
  }

  .top-actions .button-ghost:nth-of-type(-n+3) {
    display: none;
  }

  .brand {
    min-width: 220px;
  }
}

@media (max-width: 900px) {
  body {
    overflow: auto;
  }

  .topbar {
    height: auto;
    min-height: 68px;
    flex-wrap: wrap;
    padding: 10px 14px;
  }

  .brand {
    min-width: 0;
    margin-right: auto;
  }

  .save-state {
    display: none;
  }

  .top-actions {
    width: 100%;
    overflow-x: auto;
  }

  .top-actions .button-ghost:nth-of-type(-n+3) {
    display: block;
  }

  .workspace {
    height: auto;
    display: grid;
    grid-template-columns: 1fr;
    overflow: visible;
  }

  .left-panel,
  .right-panel {
    height: auto;
    max-height: none;
    border: 0;
    border-bottom: 1px solid var(--line);
  }

  .preview-column {
    min-height: 760px;
    order: 2;
  }

  .left-panel {
    order: 1;
  }

  .right-panel {
    order: 3;
  }

  .template-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 560px) {
  .brand span {
    display: none;
  }

  .button {
    white-space: nowrap;
  }

  .button-ai {
    display: none;
  }

  .theme-controls,
  .field-grid.two {
    grid-template-columns: 1fr;
  }

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

  .preview-toolbar {
    flex-wrap: wrap;
  }

  .preview-toolbar > div:first-child {
    min-width: 0;
  }

  .toolbar-center {
    width: 100%;
    order: 3;
    justify-content: space-between;
  }

  .preview-meta {
    margin-left: auto;
  }

  .preview-stage {
    padding: 16px 8px;
  }

  .device-button span,
  #refreshPreviewButton {
    display: none;
  }

  .device-button {
    min-width: 42px;
  }

  .modal-card {
    padding: 18px;
  }
}
