.aibos-code-studio,
.aibos-code-studio * {
  box-sizing: border-box;
}

.aibos-code-studio {
  --code-brand: #a8244f;
  --code-brand-dark: #7f1738;
  --code-ink: #2d2024;
  --code-muted: #75686c;
  --code-line: #eadfdd;
  --code-soft: #fbf7f5;
  display: grid;
  gap: 18px;
  color: var(--code-ink);
  font: 14px/1.5 "Microsoft YaHei", "PingFang SC", "Segoe UI", Arial, sans-serif;
}

.aibos-code-studio button,
.aibos-code-studio input,
.aibos-code-studio select,
.aibos-code-studio textarea {
  font: inherit;
}

.code-studio-tabs {
  display: flex;
  gap: 48px;
  min-height: 56px;
  padding: 0 18px;
  overflow-x: auto;
  border-bottom: 1px solid var(--code-line);
}

.code-studio-tabs button {
  position: relative;
  min-width: 96px;
  padding: 0 8px;
  color: #332d2d;
  border: 0;
  background: transparent;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}

.code-studio-tabs button.active {
  color: var(--code-brand);
}

.code-studio-tabs button.active::after {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  height: 3px;
  border-radius: 3px 3px 0 0;
  background: var(--code-brand);
  content: "";
}

.code-studio-workspace {
  display: grid;
  grid-template-columns: minmax(380px, .8fr) minmax(560px, 1.25fr);
  min-height: 570px;
  margin: 0 18px;
  border: 1px solid var(--code-line);
  border-radius: 14px;
  background: rgba(255, 255, 255, .72);
  box-shadow: 0 12px 34px rgba(80, 45, 50, .045);
}

.code-studio-settings-panel,
.code-studio-preview-panel {
  min-width: 0;
  padding: 28px 32px;
}

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

.code-studio-settings-panel h2,
.code-studio-preview-panel h2,
.code-studio-history h2 {
  margin: 0 0 20px;
  font-size: 20px;
  line-height: 1.3;
}

.code-studio-field {
  display: grid;
  gap: 8px;
  margin-bottom: 22px;
}

.code-studio-field > span,
.code-studio-toggle-row > span {
  font-size: 14px;
  font-weight: 600;
}

.code-studio-field input:not([type="color"]),
.code-studio-field select,
.code-studio-field textarea {
  width: 100%;
  min-height: 48px;
  padding: 10px 14px;
  color: var(--code-ink);
  border: 1px solid #d8cecc;
  border-radius: 8px;
  background: #fff;
  outline: none;
  font-size: 14px;
  transition: border-color .15s ease, box-shadow .15s ease;
}

.code-studio-field textarea {
  min-height: 118px;
  resize: vertical;
}

.code-studio-field input:focus,
.code-studio-field select:focus,
.code-studio-field textarea:focus {
  border-color: #c4768e;
  box-shadow: 0 0 0 3px rgba(168, 36, 79, .09);
}

.code-studio-field small {
  min-height: 18px;
  color: var(--code-muted);
  font-size: 12px;
}

.code-studio-field small.success {
  color: #23945f;
  font-weight: 600;
}

.code-studio-field small.error {
  color: #c74343;
  font-weight: 600;
}

.code-studio-section-divider {
  height: 1px;
  margin: 30px 0 26px;
  background: var(--code-line);
}

.code-studio-toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 42px;
  margin-bottom: 14px;
}

.code-studio-toggle-row input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.code-studio-toggle-row i {
  position: relative;
  width: 48px;
  height: 28px;
  border-radius: 999px;
  background: #d8d0d1;
  cursor: pointer;
  transition: background .15s ease;
}

.code-studio-toggle-row i::after {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .18);
  content: "";
  transition: transform .15s ease;
}

.code-studio-toggle-row input:checked + i {
  background: var(--code-brand);
}

.code-studio-toggle-row input:checked + i::after {
  transform: translateX(20px);
}

.code-studio-field.compact {
  margin-bottom: 16px;
}

.code-studio-number {
  position: relative;
  width: 160px;
}

.code-studio-number input {
  padding-right: 44px !important;
}

.code-studio-number em {
  position: absolute;
  top: 50%;
  right: 14px;
  transform: translateY(-50%);
  color: var(--code-muted);
  font-size: 12px;
  font-style: normal;
}

.code-studio-color-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}

.code-studio-field input[type="color"] {
  width: 92px;
  height: 42px;
  padding: 4px;
  border: 1px solid #d8cecc;
  border-radius: 7px;
  background: #fff;
  cursor: pointer;
}

.code-studio-segments {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  width: min(100%, 360px);
}

.code-studio-segments button {
  min-height: 40px;
  color: var(--code-muted);
  border: 1px solid #ddd3d1;
  border-right: 0;
  background: #fff;
  cursor: pointer;
}

.code-studio-segments button:first-child {
  border-radius: 7px 0 0 7px;
}

.code-studio-segments button:last-child {
  border-right: 1px solid #ddd3d1;
  border-radius: 0 7px 7px 0;
}

.code-studio-segments button.active {
  z-index: 1;
  color: var(--code-brand);
  border-color: var(--code-brand);
  background: #fff7f9;
  font-weight: 700;
}

.code-studio-privacy-note {
  margin: 12px 0 0;
  padding: 12px 14px;
  color: #5b7368;
  border-radius: 8px;
  background: #f2f8f5;
  font-size: 12px;
}

.code-studio-preview-panel {
  display: grid;
  grid-template-rows: auto minmax(320px, 1fr) auto auto;
  align-content: start;
}

.code-studio-preview-canvas {
  display: grid;
  place-items: center;
  min-height: 330px;
  padding: 36px;
  overflow: hidden;
  border: 1px solid #ded6d3;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 8px 22px rgba(43, 35, 37, .08);
}

.code-studio-preview-canvas > svg {
  display: block;
  width: min(100%, 780px);
  max-height: 260px;
}

.code-studio-preview-canvas.is-qr > svg {
  max-height: 320px;
}

.code-studio-preview-empty {
  display: grid;
  place-items: center;
  gap: 8px;
  color: var(--code-muted);
  text-align: center;
}

.code-studio-preview-empty i {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  color: #c79655;
  border-radius: 50%;
  background: #fff5e8;
  font-size: 24px;
  font-style: normal;
  font-weight: 700;
}

.code-studio-preview-empty strong {
  font-size: 16px;
}

.code-studio-preview-empty span {
  font-size: 12px;
}

.code-studio-validation {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 58px;
  margin-top: 18px;
  padding: 12px 16px;
  border-radius: 9px;
}

.code-studio-validation.success {
  color: #23895a;
  background: #edf8f1;
}

.code-studio-validation.error {
  color: #b34848;
  background: #fff1f1;
}

.code-studio-validation > i {
  display: grid;
  flex: 0 0 32px;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  color: #fff;
  font-style: normal;
}

.code-studio-validation.success > i { background: #23895a; }
.code-studio-validation.error > i { background: #b34848; }

.code-studio-validation strong {
  font-size: 14px;
}

.code-studio-validation span {
  margin-left: auto;
  color: var(--code-muted);
  font-size: 12px;
}

.code-studio-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

.code-studio-actions button {
  min-height: 42px;
  padding: 8px 16px;
  color: var(--code-brand);
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  font-weight: 600;
  cursor: pointer;
}

.code-studio-actions button.outlined {
  border-color: var(--code-brand);
  background: #fff;
}

.code-studio-actions button.primary {
  color: #fff;
  border-color: var(--code-brand);
  background: var(--code-brand);
}

.code-studio-actions button:disabled {
  opacity: .42;
  cursor: not-allowed;
}

.code-studio-history {
  margin: 0 18px 24px;
  border-top: 1px solid var(--code-line);
}

.code-studio-history > header {
  display: flex;
  align-items: center;
  gap: 16px;
  min-height: 68px;
}

.code-studio-history h2 {
  margin: 0;
  font-size: 18px;
}

.code-studio-history header p {
  margin: 2px 0 0;
  color: var(--code-muted);
  font-size: 12px;
}

.code-studio-history header label {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-left: auto;
  color: var(--code-muted);
  font-size: 12px;
}

.code-studio-history header > button {
  padding: 6px 0;
  color: var(--code-brand);
  border: 0;
  background: transparent;
  font-size: 12px;
  cursor: pointer;
}

.code-studio-history > div {
  border-top: 1px solid #f0e8e6;
}

.code-studio-history > div > button {
  display: grid;
  grid-template-columns: 62px minmax(230px, 1.2fr) minmax(100px, .5fr) minmax(120px, .5fr) auto;
  align-items: center;
  gap: 16px;
  width: 100%;
  min-height: 64px;
  padding: 10px 12px;
  color: var(--code-ink);
  border: 0;
  border-bottom: 1px solid #f0e8e6;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.code-studio-history > div > button:hover {
  background: #fff9fa;
}

.code-studio-history > div > button strong {
  overflow: hidden;
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.code-studio-history > div > button span,
.code-studio-history time {
  color: var(--code-muted);
  font-size: 12px;
}

.code-studio-history > div > button em {
  color: var(--code-brand);
  font-size: 12px;
  font-style: normal;
  font-weight: 600;
}

.code-history-bars {
  display: flex;
  align-items: stretch;
  gap: 3px;
  width: 52px;
  height: 32px;
  padding: 5px;
  color: #516cc9;
  border-radius: 7px;
  background: #eef1ff;
}

.code-history-bars i {
  flex: 1;
  background: currentColor;
}

.code-history-bars i:nth-child(2),
.code-history-bars i:nth-child(5) {
  flex-grow: .45;
  color: #b52f53;
}

.code-history-qr {
  position: relative;
  display: block;
  width: 36px;
  height: 36px;
  color: #7659c4;
  border: 5px solid #f1edff;
  background: currentColor;
  box-shadow: 0 0 0 4px #f1edff;
}

.code-history-qr i {
  position: absolute;
  width: 8px;
  height: 8px;
  border: 2px solid #fff;
}

.code-history-qr i:nth-child(1) { top: 2px; left: 2px; }
.code-history-qr i:nth-child(2) { top: 2px; right: 2px; }
.code-history-qr i:nth-child(3) { bottom: 2px; left: 2px; }
.code-history-qr b { position: absolute; right: 3px; bottom: 3px; width: 5px; height: 5px; background: #fff; }

.code-studio-empty-history {
  margin: 0;
  padding: 22px 12px;
  color: var(--code-muted);
  font-size: 12px;
}

/* Code Studio 1.1 — barcode and QR live together in one two-column workspace. */
.code-studio-page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  min-height: 64px;
  margin: 0 18px;
  padding: 4px 2px 14px;
  border-bottom: 1px solid var(--code-line);
}

.code-studio-page-head h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.25;
}

.code-studio-page-head p {
  margin: 5px 0 0;
  color: var(--code-muted);
  font-size: 13px;
}

.code-studio-page-head > span {
  padding: 7px 12px;
  color: #39765a;
  border-radius: 7px;
  background: #eef8f2;
  font-size: 12px;
  font-weight: 600;
}

.code-studio-dual-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin: 0 18px;
}

.aibos-code-studio.is-embedded {
  gap: 12px;
}

.aibos-code-studio.is-embedded .code-studio-dual-grid {
  margin: 0;
}

.aibos-code-studio.is-embedded .code-studio-tool-card {
  padding: 16px;
  box-shadow: none;
}

.code-studio-archive-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 14px 16px;
  border: 1px solid #efccd5;
  border-radius: 12px;
  background: #fff8fa;
}

.code-studio-archive-bar div {
  display: grid;
  gap: 3px;
}

.code-studio-archive-bar strong {
  color: #2d1f23;
  font-size: 14px;
}

.code-studio-archive-bar span {
  color: #78686d;
  font-size: 12px;
}

.code-studio-archive-bar button {
  flex: 0 0 auto;
  min-width: 190px;
  min-height: 38px;
  border: 1px solid #a72c4e;
  border-radius: 9px;
  background: #a72c4e;
  color: #fff;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.code-studio-archive-bar button:disabled {
  cursor: wait;
  opacity: .6;
}

@media (max-width: 760px) {
  .code-studio-archive-bar {
    align-items: stretch;
    flex-direction: column;
  }

  .code-studio-archive-bar button {
    width: 100%;
  }
}

.code-studio-tool-card {
  display: grid;
  grid-template-rows: auto auto minmax(250px, 1fr) auto auto;
  min-width: 0;
  padding: 20px;
  border: 1px solid var(--code-line);
  border-radius: 14px;
  background: rgba(255, 255, 255, .82);
  box-shadow: 0 10px 28px rgba(80, 45, 50, .05);
}

.code-studio-tool-card > header {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 62px;
  margin-bottom: 18px;
  padding-bottom: 14px;
  border-bottom: 1px solid #f0e7e5;
}

.code-studio-tool-card > header > i {
  display: grid;
  flex: 0 0 48px;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 13px;
  background: linear-gradient(145deg, #eef5ff, #e8edff);
  box-shadow: inset 0 1px #fff, 0 6px 14px rgba(71, 94, 180, .12);
}

.code-studio-tool-card.qr > header > i {
  background: linear-gradient(145deg, #f2edff, #ece5ff);
  box-shadow: inset 0 1px #fff, 0 6px 14px rgba(115, 83, 189, .12);
}

.code-studio-tool-card > header h2 {
  margin: 0;
  font-size: 18px;
}

.code-studio-tool-card > header p {
  margin: 4px 0 0;
  color: var(--code-muted);
  font-size: 12px;
}

.code-title-bars {
  width: 28px;
  height: 28px;
  background: repeating-linear-gradient(90deg, #2678cb 0 2px, transparent 2px 5px, #b33159 5px 7px, transparent 7px 10px);
}

.code-title-qr {
  position: relative;
  width: 28px;
  height: 28px;
  color: #7454c4;
  background: currentColor;
}

.code-title-qr b {
  position: absolute;
  width: 8px;
  height: 8px;
  border: 2px solid #fff;
}

.code-title-qr b:nth-child(1) { top: 2px; left: 2px; }
.code-title-qr b:nth-child(2) { top: 2px; right: 2px; }
.code-title-qr b:nth-child(3) { bottom: 2px; left: 2px; }

.code-studio-tool-card .code-studio-settings-panel {
  padding: 0;
  border: 0;
}

.code-studio-top-fields {
  display: grid;
  grid-template-columns: minmax(0, .85fr) minmax(0, 1fr) minmax(0, 1.55fr);
  gap: 12px;
  align-items: start;
}

.code-studio-compact-controls {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.code-studio-background-control {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
}

.code-studio-background-control > input:disabled {
  opacity: .42;
  cursor: not-allowed;
}

.code-studio-background-control > label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  padding: 0 10px;
  color: #584b4d;
  border: 1px solid #ddd3d1;
  border-radius: 7px;
  background: #fff;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
}

.code-studio-background-control > label input {
  width: 16px;
  height: 16px;
  accent-color: var(--code-brand);
}

.code-studio-tool-card .code-studio-field {
  gap: 6px;
  margin-bottom: 14px;
}

.code-studio-tool-card .code-studio-field input:not([type="color"]),
.code-studio-tool-card .code-studio-field select {
  min-height: 40px;
  padding: 7px 10px;
}

.code-studio-tool-card .code-studio-field textarea {
  min-height: 78px;
  padding: 8px 10px;
}

.code-studio-tool-card .code-studio-top-fields input:not([type="color"]),
.code-studio-tool-card .code-studio-top-fields select,
.code-studio-tool-card .code-studio-top-fields textarea {
  height: 40px;
  min-height: 40px;
}

.code-studio-tool-card .code-studio-top-fields textarea {
  padding: 7px 10px;
  overflow: auto;
  resize: none;
}

.code-studio-tool-card .code-studio-toggle-row {
  justify-content: flex-start;
  gap: 14px;
  margin-bottom: 14px;
}

.code-studio-tool-card .code-studio-number {
  width: 100%;
}

.code-studio-tool-card .code-studio-color-grid {
  gap: 10px;
}

.code-studio-tool-card .compact-colors {
  max-width: 360px;
}

.code-studio-tool-card .code-studio-qr-controls {
  grid-template-columns: .8fr 1fr 1.3fr;
}

.code-studio-tool-card .code-studio-segments {
  width: 100%;
}

.code-studio-tool-card .code-studio-privacy-note {
  margin: 0 0 14px;
}

.code-studio-tool-card .code-studio-preview-canvas {
  min-height: 250px;
  padding: 26px;
  box-shadow: 0 7px 18px rgba(43, 35, 37, .06);
}

.code-studio-preview-canvas.has-transparent {
  background-color: #fff;
  background-image:
    linear-gradient(45deg, #edf0f2 25%, transparent 25%),
    linear-gradient(-45deg, #edf0f2 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #edf0f2 75%),
    linear-gradient(-45deg, transparent 75%, #edf0f2 75%);
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  background-size: 16px 16px;
}

.code-studio-tool-card.barcode .code-studio-preview-canvas > svg {
  width: 100%;
  max-height: 190px;
}

.code-studio-tool-card.qr .code-studio-preview-canvas > svg {
  max-width: 250px;
  max-height: 250px;
}

.code-studio-tool-card .code-studio-validation {
  min-height: 52px;
  margin-top: 12px;
  padding: 10px 12px;
}

.code-studio-tool-card .code-studio-validation > i {
  flex-basis: 28px;
  width: 28px;
  height: 28px;
}

.code-studio-tool-card .code-studio-validation span {
  text-align: right;
}

.code-studio-tool-card .code-studio-actions {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, auto));
  margin-top: 12px;
}

.code-studio-tool-card .code-studio-actions button {
  min-height: 38px;
  padding: 6px 10px;
}

@media (max-width: 980px) {
  .code-studio-dual-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 620px) {
  .code-studio-page-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .code-studio-top-fields,
  .code-studio-compact-controls,
  .code-studio-tool-card .code-studio-qr-controls {
    grid-template-columns: 1fr;
  }

  .code-studio-tool-card .code-studio-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 1180px) {
  .code-studio-workspace {
    grid-template-columns: 1fr;
  }

  .code-studio-settings-panel {
    border-right: 0;
    border-bottom: 1px solid var(--code-line);
  }
}

@media (max-width: 760px) {
  .code-studio-workspace,
  .code-studio-history {
    margin-right: 10px;
    margin-left: 10px;
  }

  .code-studio-settings-panel,
  .code-studio-preview-panel {
    padding: 22px 18px;
  }

  .code-studio-preview-canvas {
    min-height: 260px;
    padding: 20px;
  }

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

  .code-studio-validation {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .code-studio-validation span {
    width: 100%;
    margin-left: 42px;
  }

  .code-studio-history > div > button {
    grid-template-columns: 52px minmax(0, 1fr) auto;
  }

  .code-studio-history > div > button span,
  .code-studio-history time {
    display: none;
  }
}

@media (max-width: 480px) {
  .code-studio-color-grid,
  .code-studio-actions {
    grid-template-columns: 1fr;
  }

  .code-studio-history > header {
    align-items: flex-start;
    flex-wrap: wrap;
    padding: 12px 0;
  }

  .code-studio-history header label {
    margin-left: 0;
  }
}
