:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --panel-soft: #f9fafc;
  --text: #172033;
  --muted: #667085;
  --quiet: #98a2b3;
  --line: #e4e7ec;
  --line-strong: #d0d5dd;
  --blue: #006cff;
  --blue-deep: #0958d9;
  --green: #12b76a;
  --pink: #e83e8c;
  --yellow: #fdb022;
  --shadow: 0 18px 48px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
}

body {
  min-width: 1100px;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  height: 72px;
  display: grid;
  grid-template-columns: 260px minmax(280px, 1fr) auto;
  align-items: center;
  gap: 24px;
  padding: 0 28px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(14px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  width: 36px;
  height: 36px;
  border: 1px solid rgba(0, 108, 255, 0.18);
  border-radius: 8px;
  background:
    linear-gradient(90deg, transparent 11px, rgba(255, 255, 255, 0.7) 11px 13px, transparent 13px),
    linear-gradient(0deg, transparent 11px, rgba(255, 255, 255, 0.7) 11px 13px, transparent 13px),
    linear-gradient(135deg, #006cff, #00a6ff 55%, #12b76a);
  box-shadow: inset 0 0 0 5px rgba(255, 255, 255, 0.32);
}

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

.brand strong {
  font-size: 17px;
  line-height: 22px;
  font-weight: 760;
  letter-spacing: 0;
}

.brand em {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
}

.search {
  height: 42px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.search-icon {
  width: 15px;
  height: 15px;
  border: 2px solid var(--quiet);
  border-radius: 50%;
  position: relative;
  flex: none;
}

.search-icon::after {
  content: "";
  position: absolute;
  right: -6px;
  bottom: -4px;
  width: 7px;
  height: 2px;
  border-radius: 2px;
  background: var(--quiet);
  transform: rotate(45deg);
}

.search input {
  width: 100%;
  border: 0;
  outline: 0;
  color: var(--text);
  background: transparent;
}

.search input::placeholder {
  color: var(--quiet);
}

.header-meta {
  display: flex;
  align-items: center;
  gap: 14px;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.connection-status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.connection-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--quiet);
}

.connection-status.connected {
  color: #027a48;
}

.connection-status.connected .connection-dot {
  background: var(--green);
}

.workspace {
  height: calc(100vh - 72px);
  min-height: 680px;
  display: grid;
  grid-template-columns: 240px minmax(460px, 1fr) 360px;
  gap: 18px;
  padding: 18px;
}

.sidebar,
.library-panel,
.preview-panel {
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.sidebar {
  display: flex;
  flex-direction: column;
  padding: 18px;
}

.sidebar-head {
  padding: 4px 2px 18px;
}

.eyebrow,
.sidebar-head p {
  margin: 0 0 5px;
  color: var(--blue);
  font-size: 11px;
  font-weight: 760;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.sidebar-head h1,
.panel-toolbar h2,
.preview-head h2 {
  margin: 0;
  color: var(--text);
  letter-spacing: 0;
}

.sidebar-head h1 {
  font-size: 24px;
  line-height: 32px;
}

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

.category-button {
  width: 100%;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 10px 0 12px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  text-align: left;
}

.category-button:hover {
  background: var(--panel-soft);
  color: var(--text);
}

.category-button.active {
  border-color: rgba(0, 108, 255, 0.22);
  background: rgba(0, 108, 255, 0.08);
  color: var(--blue-deep);
}

.category-button span:first-child {
  font-weight: 650;
}

.category-button span:last-child {
  min-width: 24px;
  padding: 2px 7px;
  border-radius: 999px;
  background: #eef2f6;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.sidebar-note {
  margin-top: auto;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, #fbfcff, #f2f6ff);
}

.sidebar-note strong {
  display: block;
  margin-bottom: 7px;
  font-size: 14px;
}

.sidebar-note p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 18px;
}

.library-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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

.panel-toolbar h2,
.preview-head h2 {
  font-size: 20px;
  line-height: 28px;
}

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

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
}

.component-grid {
  overflow: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 14px;
  padding: 18px;
}

.component-card {
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  text-align: left;
  transition:
    border-color 0.16s ease,
    box-shadow 0.16s ease,
    transform 0.16s ease;
}

.component-card:hover,
.component-card:focus-visible,
.component-card.active {
  border-color: rgba(0, 108, 255, 0.45);
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.1);
  transform: translateY(-1px);
  outline: 0;
}

.component-preview {
  height: 152px;
  display: grid;
  place-items: center;
  padding: 18px;
  border-bottom: 1px solid var(--line);
  background:
    linear-gradient(45deg, #f7f8fb 25%, transparent 25%),
    linear-gradient(-45deg, #f7f8fb 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #f7f8fb 75%),
    linear-gradient(-45deg, transparent 75%, #f7f8fb 75%);
  background-color: #fff;
  background-position:
    0 0,
    0 8px,
    8px -8px,
    -8px 0;
  background-size: 16px 16px;
}

.component-preview svg {
  max-width: 100%;
  max-height: 100%;
  display: block;
}

.component-info {
  padding: 13px 14px 14px;
}

.component-title-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 9px;
}

.component-title-row strong {
  min-width: 0;
  color: var(--text);
  font-size: 14px;
  line-height: 20px;
}

.component-title-row span {
  color: var(--quiet);
  font-size: 12px;
  line-height: 20px;
  white-space: nowrap;
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag,
.category-pill {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #f2f4f7;
  color: var(--muted);
  font-size: 12px;
}

.empty-state {
  margin: 18px;
  padding: 34px;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--muted);
  text-align: center;
}

.empty-state strong {
  display: block;
  margin-bottom: 8px;
  color: var(--text);
}

.empty-state p {
  margin: 0;
}

.preview-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.preview-canvas {
  height: 220px;
  display: grid;
  place-items: center;
  margin: 18px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    radial-gradient(circle at 20% 20%, rgba(0, 108, 255, 0.07), transparent 30%),
    linear-gradient(180deg, #ffffff, #f7f9fd);
}

.preview-canvas svg {
  max-width: 100%;
  max-height: 100%;
}

.spec-list {
  display: grid;
  grid-template-columns: 96px 1fr;
  gap: 10px;
  margin: 0 18px 18px;
}

.spec-list div {
  display: contents;
}

.spec-list dt,
.spec-list dd {
  min-height: 34px;
  display: flex;
  align-items: center;
  margin: 0;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}

.spec-list dt {
  color: var(--quiet);
}

.spec-list dd {
  min-width: 0;
  color: var(--muted);
}

.action-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  padding: 0 18px 18px;
}

.primary-button,
.secondary-button,
.ghost-button,
.danger-button {
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 7px;
  font-weight: 650;
}

.primary-button {
  border: 1px solid var(--blue);
  background: var(--blue);
  color: #fff;
}

.primary-button:hover {
  background: var(--blue-deep);
}

.secondary-button,
.ghost-button {
  border: 1px solid var(--line-strong);
  background: #fff;
  color: var(--text);
}

.secondary-button:hover,
.ghost-button:hover {
  border-color: var(--blue);
  color: var(--blue-deep);
}

.ghost-button {
  padding: 0 13px;
}

.header-upload {
  padding: 0 14px;
  white-space: nowrap;
}

.danger-button {
  margin: 0 18px 18px;
  border: 1px solid #fda29b;
  background: #fff;
  color: #b42318;
}

.danger-button[hidden] {
  display: none;
}

.danger-button:hover {
  border-color: #f04438;
  background: #fef3f2;
}

.dialog-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(15, 23, 42, 0.42);
  backdrop-filter: blur(2px);
}

.dialog-backdrop[hidden] {
  display: none;
}

.confirm-dialog {
  width: min(420px, calc(100vw - 32px));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 24px 80px rgba(15, 23, 42, 0.24);
}

.dialog-body {
  padding: 22px 22px 18px;
}

.dialog-body h2 {
  margin: 3px 0 10px;
  font-size: 20px;
  line-height: 28px;
}

.dialog-body > p:last-child {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 22px;
}

.upload-dialog {
  width: min(520px, calc(100vw - 32px));
}

.upload-description {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 14px;
  line-height: 22px;
}

.upload-dropzone {
  min-height: 132px;
  display: grid;
  place-content: center;
  gap: 6px;
  padding: 20px;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--muted);
  text-align: center;
  cursor: pointer;
  transition: border-color 0.16s ease, background 0.16s ease;
}

.upload-dropzone:hover,
.upload-dropzone.dragging {
  border-color: var(--blue);
  background: #f2f7ff;
}

.upload-dropzone strong {
  color: var(--text);
  font-size: 15px;
}

.upload-dropzone span {
  font-size: 12px;
}

.upload-file-list {
  max-height: 94px;
  overflow: auto;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 12px 0 16px;
}

.upload-file-list span {
  max-width: 100%;
  overflow: hidden;
  padding: 5px 8px;
  border-radius: 5px;
  background: #f2f4f7;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.upload-fields {
  display: grid;
  grid-template-columns: 150px 1fr;
  gap: 12px;
}

.upload-fields label > span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.upload-fields select,
.upload-fields input {
  width: 100%;
  height: 38px;
  padding: 0 10px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  outline: 0;
  background: #fff;
  color: var(--text);
}

.upload-fields select:focus,
.upload-fields input:focus {
  border-color: var(--blue);
}

.dialog-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 14px 22px;
  border-top: 1px solid var(--line);
  background: var(--panel-soft);
}

.dialog-actions button {
  width: 100%;
  margin: 0;
}

.dialog-danger {
  border-color: #d92d20;
  background: #d92d20;
  color: #fff;
}

.dialog-danger:hover {
  border-color: #b42318;
  background: #b42318;
}

.code-label {
  display: block;
  margin: 0 18px 8px;
  color: var(--quiet);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

textarea {
  min-height: 0;
  flex: 1;
  resize: none;
  margin: 0 18px 18px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: 0;
  background: #111827;
  color: #e5e7eb;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  line-height: 18px;
}

textarea:focus {
  border-color: rgba(0, 108, 255, 0.6);
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 20;
  max-width: 340px;
  padding: 12px 14px;
  border: 1px solid rgba(18, 183, 106, 0.25);
  border-radius: 8px;
  background: #ecfdf3;
  color: #027a48;
  box-shadow: 0 18px 42px rgba(15, 23, 42, 0.16);
  font-size: 14px;
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition:
    opacity 0.18s ease,
    transform 0.18s ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 1180px) {
  body {
    min-width: 0;
  }

  .app-header {
    position: static;
    height: auto;
    grid-template-columns: 1fr;
    padding: 16px;
  }

  .workspace {
    height: auto;
    min-height: 0;
    grid-template-columns: 1fr;
    padding: 12px;
  }

  .preview-panel {
    min-height: 720px;
  }

  .component-grid {
    max-height: none;
  }
}
