:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-soft: #eef3f7;
  --surface-strong: #101820;
  --ink: #1b2733;
  --muted: #64748b;
  --line: #d8e0e8;
  --line-strong: #b9c7d4;
  --teal: #176f6b;
  --teal-strong: #0f5754;
  --blue: #2f6fa3;
  --amber: #b27a20;
  --rose: #9f3f52;
  --green-soft: #e4f4ef;
  --blue-soft: #e5f0fa;
  --amber-soft: #fff2d8;
  --shadow: 0 18px 46px rgba(19, 31, 44, 0.12);
  --radius: 8px;
  --max: 1480px;
}

* {
  box-sizing: border-box;
}

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

body {
  background:
    linear-gradient(180deg, rgba(245, 247, 251, 0.96), rgba(239, 244, 248, 0.98)),
    repeating-linear-gradient(90deg, rgba(47, 111, 163, 0.05) 0 1px, transparent 1px 84px);
  color: var(--ink);
  font-family:
    Inter, "Helvetica Neue", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "PingFang SC", "Microsoft YaHei", sans-serif;
  line-height: 1.5;
}

button,
textarea,
select {
  font: inherit;
}

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

button {
  cursor: pointer;
}

a {
  color: inherit;
  text-decoration: none;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 12px max(18px, calc((100vw - var(--max)) / 2));
  border-bottom: 1px solid rgba(16, 24, 32, 0.12);
  background: rgba(255, 255, 255, 0.86);
  backdrop-filter: blur(18px);
}

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  background: var(--surface-strong);
  color: #ffffff;
  font-size: 14px;
  font-weight: 800;
}

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

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

.brand small {
  color: var(--muted);
  font-size: 12px;
}

.top-actions,
.button-row,
.status-bar,
.connector-group,
.sample-switcher,
.toolbar {
  display: flex;
  align-items: center;
}

.top-actions {
  gap: 8px;
}

.link-button,
.icon-text-button,
.primary-action,
.secondary-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
  transition: border-color 160ms ease, background 160ms ease, transform 160ms ease;
}

.link-button:hover,
.icon-text-button:hover,
.primary-action:hover,
.secondary-action:hover {
  border-color: var(--teal);
  transform: translateY(-1px);
}

.primary-action {
  border-color: var(--teal);
  background: var(--teal);
  color: #ffffff;
}

.primary-action:hover {
  background: var(--teal-strong);
}

.secondary-action {
  background: #f8fafc;
}

.link-button svg,
.icon-text-button svg,
.primary-action svg,
.secondary-action svg,
.status-bar svg {
  width: 16px;
  height: 16px;
}

.workbench {
  width: min(100% - 28px, var(--max));
  margin: 0 auto;
  padding: 28px 0 46px;
}

.app-title {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 22px;
  margin-bottom: 18px;
}

.eyebrow,
.panel-kicker {
  margin: 0 0 5px;
  color: var(--teal);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 34px;
  line-height: 1.15;
}

h2 {
  font-size: 16px;
  line-height: 1.2;
}

.status-bar {
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.status-bar span,
.local-pill,
.connector-group span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.status-bar span:first-child {
  border-color: rgba(23, 111, 107, 0.28);
  background: var(--green-soft);
  color: var(--teal-strong);
}

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

.metric-strip div {
  min-height: 78px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.8) inset;
}

.metric-strip span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.metric-strip strong {
  display: block;
  margin-top: 5px;
  font-size: 27px;
  line-height: 1;
}

.agent-layout {
  display: grid;
  grid-template-columns: minmax(320px, 390px) minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

.side-panel,
.main-panel,
.mapping-panel,
.preview-panel,
.table-preview {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}

.side-panel {
  display: grid;
  gap: 14px;
  padding: 16px;
}

.main-panel {
  display: grid;
  gap: 14px;
  padding: 14px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel-head.compact {
  padding: 0;
}

#source-file {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.sample-switcher {
  gap: 8px;
}

.chip,
.segmented-control button {
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.chip.active,
.segmented-control button.active {
  border-color: rgba(23, 111, 107, 0.36);
  background: var(--green-soft);
  color: var(--teal-strong);
}

.data-input,
.template-input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfdff;
  color: var(--ink);
  resize: vertical;
  outline: none;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
  line-height: 1.55;
}

.data-input {
  min-height: 210px;
  padding: 12px;
}

.template-input {
  min-height: 245px;
  padding: 14px;
}

.data-input:focus,
.template-input:focus,
select:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(23, 111, 107, 0.12);
}

.button-row {
  flex-wrap: wrap;
  gap: 8px;
}

.panel-divider {
  height: 1px;
  background: var(--line);
}

.toolbar {
  justify-content: space-between;
  gap: 12px;
  padding: 2px;
}

.segmented-control {
  display: inline-flex;
  gap: 6px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f7fafc;
}

.connector-group {
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.connector-group span:first-child {
  background: var(--blue-soft);
  color: var(--blue);
}

.connector-group span:last-child {
  background: var(--amber-soft);
  color: var(--amber);
}

.split-view {
  display: grid;
  grid-template-columns: minmax(360px, 0.92fr) minmax(360px, 1.08fr);
  gap: 14px;
}

.mapping-panel,
.preview-panel,
.table-preview {
  display: grid;
  gap: 14px;
  padding: 14px;
  box-shadow: none;
}

.table-shell {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 560px;
}

th,
td {
  padding: 10px 11px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
  font-size: 13px;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f2f6fa;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

tr:last-child td {
  border-bottom: 0;
}

td select,
#record-select {
  width: 100%;
  min-height: 36px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
}

.token-name {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 8px;
  border-radius: 7px;
  background: var(--surface-soft);
  color: var(--ink);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  font-weight: 800;
}

.sample-value {
  max-width: 170px;
  overflow: hidden;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.issue-list {
  display: grid;
  gap: 8px;
}

.issue-list p {
  padding: 10px 12px;
  border: 1px solid rgba(159, 63, 82, 0.24);
  border-radius: 8px;
  background: #fff0f3;
  color: var(--rose);
  font-size: 13px;
  font-weight: 700;
}

.issue-list .ok {
  border-color: rgba(23, 111, 107, 0.22);
  background: var(--green-soft);
  color: var(--teal-strong);
}

.preview-surface {
  min-height: 475px;
  max-height: 640px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    linear-gradient(90deg, #eef3f7 1px, transparent 1px) 0 0 / 24px 24px,
    linear-gradient(#eef3f7 1px, transparent 1px) 0 0 / 24px 24px,
    #f8fafc;
  padding: 20px;
}

.doc-page {
  width: min(100%, 660px);
  min-height: 430px;
  margin: 0 auto 18px;
  padding: 36px 42px;
  border: 1px solid #d6dee7;
  border-radius: 6px;
  background: #ffffff;
  box-shadow: 0 16px 38px rgba(19, 31, 44, 0.13);
}

.doc-page h3 {
  margin: 0 0 22px;
  text-align: center;
  font-size: 24px;
}

.doc-page pre {
  margin: 0;
  color: #233142;
  font-family: "Times New Roman", "Songti SC", serif;
  font-size: 16px;
  line-height: 1.85;
  white-space: pre-wrap;
}

.slide-deck {
  display: grid;
  gap: 16px;
}

.slide {
  aspect-ratio: 16 / 9;
  display: grid;
  align-content: space-between;
  min-height: 260px;
  padding: 24px;
  border: 1px solid #c9d4de;
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(23, 111, 107, 0.12), transparent 45%),
    #ffffff;
  box-shadow: 0 12px 28px rgba(19, 31, 44, 0.1);
}

.slide h3 {
  margin: 0;
  color: var(--surface-strong);
  font-size: 27px;
}

.slide ul {
  display: grid;
  gap: 9px;
  margin: 18px 0 0;
  padding: 0;
  list-style: none;
}

.slide li {
  padding: 10px 12px;
  border-left: 4px solid var(--teal);
  background: #f5f9fb;
  color: #263646;
  font-weight: 700;
}

.slide-footer {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.compact-table {
  max-height: 290px;
}

.compact-table table {
  min-width: 720px;
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 240px;
  color: var(--muted);
  text-align: center;
  font-weight: 700;
}

@media (max-width: 1180px) {
  .agent-layout,
  .split-view {
    grid-template-columns: 1fr;
  }

  .side-panel {
    position: static;
  }
}

@media (max-width: 760px) {
  .app-header,
  .app-title,
  .toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions,
  .status-bar,
  .connector-group {
    justify-content: flex-start;
  }

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

  .workbench {
    width: min(100% - 18px, var(--max));
    padding-top: 18px;
  }

  h1 {
    font-size: 28px;
  }

  .doc-page {
    padding: 24px 20px;
  }

  .preview-surface {
    padding: 12px;
  }
}

@media (max-width: 500px) {
  .metric-strip {
    grid-template-columns: 1fr;
  }

  .button-row,
  .sample-switcher {
    align-items: stretch;
    flex-direction: column;
  }

  .button-row button,
  .sample-switcher button,
  .link-button,
  .icon-text-button {
    width: 100%;
  }
}
