:root {
  color: #172033;
  background: #f3f5f7;
  font-family: "Avenir Next", "SF Pro Display", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  --ink: #172033;
  --muted: #617085;
  --line: #d8e0ea;
  --paper: #ffffff;
  --surface: #f3f5f7;
  --blue: #2563eb;
  --green: #10b981;
  --coral: #ef5b3f;
  --amber: #f59e0b;
  --shadow: 0 16px 38px rgba(23, 32, 51, 0.09);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(243, 245, 247, 0.96) 0%, rgba(239, 245, 246, 0.96) 48%, rgba(248, 246, 240, 0.96) 100%);
}

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

button,
a {
  -webkit-tap-highlight-color: transparent;
}

.app {
  min-height: 100vh;
}

.topbar {
  min-height: 70px;
  padding: 14px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.91);
  backdrop-filter: blur(16px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  text-decoration: none;
  font-weight: 900;
}

.brand img {
  width: 36px;
  height: 36px;
  border-radius: 8px;
}

.topnav {
  display: flex;
  align-items: center;
  gap: 10px;
}

.topnav a,
.language-button,
.primary-action,
.secondary-action {
  min-height: 40px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-decoration: none;
  font-weight: 850;
  white-space: nowrap;
}

.topnav a,
.language-button {
  padding: 0 12px;
  border: 1px solid transparent;
  color: var(--muted);
  background: transparent;
}

.language-button,
.primary-action,
.secondary-action,
.preview-tabs button {
  cursor: pointer;
}

.topnav a:hover,
.language-button:hover {
  color: var(--ink);
  border-color: var(--line);
  background: #fff;
}

main {
  max-width: 1480px;
  margin: 0 auto;
  padding: 26px 28px 52px;
}

.studio-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 18px;
  align-items: end;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.studio-header h1,
.studio-header p,
.eyebrow,
h2 {
  margin: 0;
  letter-spacing: 0;
}

.studio-header h1 {
  margin-top: 8px;
  font-size: 44px;
  line-height: 1.05;
  font-weight: 950;
  max-width: 100%;
  overflow-wrap: anywhere;
}

.studio-header p:not(.eyebrow) {
  max-width: 760px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.65;
  overflow-wrap: anywhere;
}

.eyebrow {
  color: var(--coral);
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.header-actions,
.action-stack {
  display: grid;
  gap: 10px;
}

.primary-action,
.secondary-action {
  min-width: 160px;
  padding: 0 16px;
  border: 1px solid transparent;
}

.primary-action {
  color: #fff;
  background: #172033;
}

.primary-action:hover {
  background: #26324a;
}

.secondary-action {
  color: var(--ink);
  background: #fff;
  border-color: var(--line);
}

.secondary-action:hover {
  border-color: #aab8c8;
}

.full {
  width: 100%;
}

.status-strip {
  margin-top: 14px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.status-strip span {
  min-height: 44px;
  padding: 0 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.8);
  font-size: 13px;
  font-weight: 750;
}

.status-strip svg {
  color: var(--green);
  flex: 0 0 auto;
}

.value-strip {
  margin-top: 14px;
  display: grid;
  grid-template-columns: minmax(280px, 0.75fr) minmax(0, 1.25fr);
  gap: 14px;
  align-items: stretch;
}

.value-intro,
.value-grid article {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
}

.value-intro {
  padding: 20px;
}

.value-intro h2 {
  margin-top: 8px;
  font-size: 28px;
  line-height: 1.15;
  font-weight: 950;
}

.value-intro p:not(.eyebrow) {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.65;
}

.value-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.value-grid article {
  min-height: 156px;
  padding: 16px;
  display: grid;
  align-content: start;
  gap: 10px;
}

.value-grid article span {
  width: 34px;
  height: 26px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  color: #fff;
  background: var(--ink);
  font-size: 12px;
  font-weight: 900;
}

.value-grid article strong {
  color: var(--ink);
  font-size: 15px;
  line-height: 1.25;
}

.value-grid article p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.studio-grid {
  display: grid;
  grid-template-columns: minmax(360px, 0.9fr) minmax(330px, 0.8fr) minmax(300px, 0.65fr);
  gap: 16px;
  align-items: start;
  margin-top: 16px;
}

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

.source-panel,
.structure-panel,
.handoff-panel,
.provider-panel,
.web-preview-panel,
.preview-panel {
  padding: 20px;
}

.panel-heading {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 16px;
}

.panel-heading svg {
  color: var(--blue);
  flex: 0 0 auto;
}

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

.control-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 850;
}

select,
input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #fff;
  outline: none;
}

select,
input {
  height: 42px;
  padding: 0 11px;
}

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

textarea {
  resize: vertical;
  padding: 11px;
  line-height: 1.55;
}

.medium-input {
  min-height: 90px;
}

.large-input {
  min-height: 160px;
}

.drop-zone {
  margin-top: 14px;
  padding: 18px;
  display: grid;
  justify-items: center;
  gap: 8px;
  text-align: center;
  border: 1px dashed #94a3b8;
  border-radius: 8px;
  background: #f8fafc;
}

.drop-zone svg {
  color: var(--blue);
}

.drop-zone strong {
  color: var(--ink);
  font-size: 15px;
}

.drop-zone span {
  max-width: 420px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.file-button {
  min-height: 36px;
  margin-top: 4px;
  padding: 0 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #fff;
  cursor: pointer;
}

.file-button input {
  display: none;
}

.url-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
  margin-top: 12px;
}

.source-list-ui,
.provider-grid,
.agent-grid {
  display: grid;
  gap: 10px;
}

.source-list-ui {
  margin-top: 12px;
}

.source-chip {
  min-width: 0;
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr) 30px;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.source-chip > svg {
  color: var(--blue);
}

.source-chip strong,
.source-chip span {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.source-chip strong {
  color: var(--ink);
  font-size: 13px;
}

.source-chip span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.source-chip button,
.bridge-card button {
  width: 30px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 8px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
}

.source-chip button:hover,
.bridge-card button:hover {
  color: var(--ink);
  background: #eef2f7;
}

.empty-source,
.error-text {
  margin-top: 12px;
  padding: 12px;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.45;
}

.empty-source {
  color: var(--muted);
  background: #fff;
  border: 1px solid var(--line);
}

.error-text {
  color: #991b1b;
  background: #fef2f2;
  border: 1px solid #fecaca;
}

.notes-label {
  margin-top: 12px;
}

.field-stack {
  display: grid;
  gap: 12px;
  margin-top: 14px;
}

.split-fields {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 112px;
  gap: 10px;
}

.readiness {
  padding: 16px;
  border: 1px solid rgba(16, 185, 129, 0.3);
  border-radius: 8px;
  background: #f0fdf4;
}

.readiness > div:first-child {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.readiness span {
  color: #14532d;
  font-size: 13px;
  font-weight: 850;
}

.readiness strong {
  color: #14532d;
  font-size: 28px;
  line-height: 1;
}

.meter {
  height: 8px;
  margin-top: 12px;
  border-radius: 999px;
  background: rgba(20, 83, 45, 0.12);
  overflow: hidden;
}

.meter span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--green), var(--blue));
}

.missing-box,
.kit-box {
  display: grid;
  gap: 8px;
  margin-top: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.engine-section {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.engine-section > strong {
  color: var(--ink);
  font-size: 14px;
}

.engine-grid {
  display: grid;
  gap: 10px;
}

.engine-card {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.engine-card.active {
  border-color: rgba(37, 99, 235, 0.36);
  background: #f8fbff;
}

.engine-card.optional {
  opacity: 0.78;
}

.engine-card > div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.engine-card svg {
  color: var(--blue);
  flex: 0 0 auto;
}

.engine-card span {
  padding: 3px 8px;
  border-radius: 999px;
  color: var(--blue);
  background: rgba(37, 99, 235, 0.09);
  font-size: 11px;
  font-weight: 900;
}

.engine-card strong {
  color: var(--ink);
  font-size: 14px;
}

.engine-card p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.missing-box strong,
.kit-box strong {
  color: var(--ink);
  font-size: 14px;
}

.missing-box span,
.kit-box span {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.story-list {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.story-row {
  display: grid;
  grid-template-columns: 38px 1fr;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.story-row > span {
  color: var(--coral);
  font-size: 13px;
  font-weight: 950;
}

.story-row strong,
.story-row p {
  display: block;
  margin: 0;
}

.story-row strong {
  color: var(--ink);
  font-size: 15px;
}

.story-row p {
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.route-list {
  display: grid;
  gap: 10px;
  margin: 12px 0;
}

.bridge-card {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.bridge-card.online {
  border-color: rgba(16, 185, 129, 0.42);
  background: #f0fdf4;
}

.bridge-card.offline {
  border-color: rgba(245, 158, 11, 0.38);
  background: #fffbeb;
}

.bridge-card > div {
  display: flex;
  align-items: center;
  gap: 8px;
}

.bridge-card > div strong {
  flex: 1;
  color: var(--ink);
  font-size: 14px;
}

.bridge-card svg {
  color: var(--green);
}

.bridge-card.offline svg {
  color: var(--amber);
}

.bridge-card code,
.handoff-result code,
.command-box code,
.agent-card code {
  display: block;
  padding: 8px;
  overflow: auto;
  border-radius: 6px;
  color: #172033;
  background: rgba(255, 255, 255, 0.82);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 12px;
  line-height: 1.4;
}

.bridge-card p,
.bridge-card span {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.bridge-message,
.handoff-result,
.command-box {
  margin-top: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.bridge-message {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.handoff-result,
.command-box {
  display: grid;
  gap: 8px;
}

.handoff-result strong,
.command-box strong {
  color: var(--ink);
  font-size: 13px;
}

.handoff-result span {
  color: var(--muted);
  font-size: 12px;
}

.info-row {
  display: grid;
  grid-template-columns: 24px 1fr;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.info-row svg {
  color: var(--blue);
  margin-top: 2px;
}

.info-row strong,
.info-row span {
  display: block;
}

.info-row span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.hint {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.preview-panel {
  margin-top: 16px;
}

.web-preview-panel {
  margin-top: 16px;
}

.provider-panel {
  margin-top: 16px;
}

.preview-shell-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.preview-shell-heading .panel-heading {
  margin-bottom: 12px;
}

.preview-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.preview-meta span {
  min-height: 30px;
  padding: 0 10px;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: #fff;
  font-size: 12px;
  font-weight: 850;
}

.web-preview-frame {
  position: relative;
  overflow: hidden;
  aspect-ratio: 16 / 9;
  min-height: 360px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: #172033;
}

.web-preview-frame iframe {
  width: 100%;
  height: 100%;
  display: block;
  border: 0;
  background: #fff;
}

.preview-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.preview-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.preview-tabs button {
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: #fff;
  font-weight: 850;
}

.preview-tabs button.active {
  color: #fff;
  background: var(--ink);
  border-color: var(--ink);
}

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

.provider-card,
.agent-card {
  min-width: 0;
  display: grid;
  gap: 8px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.provider-card.configured {
  border-color: rgba(16, 185, 129, 0.34);
}

.provider-card.missing {
  border-color: rgba(245, 158, 11, 0.28);
}

.provider-card > div {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.provider-card strong,
.agent-card strong {
  color: var(--ink);
  font-size: 14px;
}

.provider-card p,
.provider-card span,
.provider-card em {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  overflow-wrap: anywhere;
  font-style: normal;
}

.provider-card em.ok {
  color: #047857;
}

.provider-card em.fail {
  color: #b45309;
}

.provider-card .secondary-action {
  min-width: 0;
  min-height: 34px;
  padding: 0 10px;
}

.agent-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-top: 12px;
}

.status-pill {
  min-height: 24px;
  padding: 0 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 900;
  white-space: nowrap;
}

.status-pill.ok {
  color: #047857;
  background: #d1fae5;
}

.status-pill.fail {
  color: #92400e;
  background: #fef3c7;
}

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

pre {
  min-height: 430px;
  max-height: 620px;
  margin: 0;
  padding: 16px;
  overflow: auto;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  color: #172033;
  background: #f8fafc;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 13px;
  line-height: 1.55;
  white-space: pre-wrap;
}

@media (max-width: 1180px) {
  .studio-header,
  .studio-grid,
  .value-strip {
    grid-template-columns: 1fr;
  }

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

  .status-strip {
    grid-template-columns: 1fr;
  }

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

@media (max-width: 680px) {
  .topbar,
  main {
    padding-left: 16px;
    padding-right: 16px;
  }

  .topbar {
    position: static;
    align-items: flex-start;
    flex-direction: column;
  }

  .topnav {
    width: 100%;
    flex-wrap: wrap;
  }

  .topnav a,
  .language-button {
    flex: 1 1 auto;
  }

  .studio-header,
  .source-panel,
  .structure-panel,
  .handoff-panel,
  .provider-panel,
  .web-preview-panel,
  .preview-panel {
    padding: 18px;
  }

  .studio-header h1 {
    font-size: 30px;
    line-height: 1.1;
  }

  .studio-header p:not(.eyebrow) {
    font-size: 15px;
    line-height: 1.55;
  }

  .header-actions,
  .control-grid,
  .split-fields,
  .url-row,
  .provider-grid,
  .agent-grid,
  .value-grid {
    grid-template-columns: 1fr;
  }

  .primary-action,
  .secondary-action {
    width: 100%;
  }

  .preview-shell-heading {
    display: grid;
  }

  .preview-meta {
    justify-content: flex-start;
  }

  .web-preview-frame {
    min-height: 180px;
  }
}
