:root {
  --bg: var(--tg-theme-bg-color, #f5f7f8);
  --surface: var(--tg-theme-secondary-bg-color, #ffffff);
  --line: rgba(92, 111, 126, 0.22);
  --text: var(--tg-theme-text-color, #14212a);
  --muted: var(--tg-theme-hint-color, #63717c);
  --buyer: var(--tg-theme-link-color, #2878d8);
  --seller: #14946f;
  --accent: var(--tg-theme-button-color, #111827);
  --button-text: var(--tg-theme-button-text-color, #ffffff);
  --link: var(--tg-theme-link-color, #226fbe);
  --soft-blue: #eaf3ff;
  --soft-green: #e9f8f2;
  --warning: #fff6df;
  --shadow: 0 18px 55px rgba(31, 43, 55, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Microsoft YaHei", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: var(--button-text);
  padding: 0 16px;
  cursor: pointer;
  transition:
    transform 0.18s ease,
    opacity 0.18s ease,
    background 0.18s ease;
}

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

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

.secondary,
.ghost-button {
  background: #eef3f6;
  color: var(--text);
}

.shell {
  max-width: 1440px;
  margin: 0 auto;
  padding: 28px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.top-actions {
  display: flex;
  align-items: stretch;
  gap: 10px;
}

.language-select {
  display: grid;
  gap: 4px;
  min-width: 132px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

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

.language-select select {
  min-height: 28px;
  border: 0;
  padding: 0;
  background: transparent;
  font-weight: 700;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 13px;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

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

h2 {
  font-size: 18px;
}

.trade-id {
  display: grid;
  gap: 4px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.trade-id span,
.section-title span {
  color: var(--muted);
  font-size: 12px;
}

.status-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

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

.view-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 18px;
}

.tab-button {
  background: #e9f0f4;
  color: var(--muted);
}

.tab-button.active {
  background: var(--accent);
  color: #fff;
}

.view-panel {
  display: none;
}

.view-panel.active.workspace,
.view-panel.active.details-grid,
.view-panel.active.template-section,
.view-panel.active.admin-layout {
  display: grid;
}

.status-copy {
  display: grid;
  gap: 4px;
}

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

.status-copy strong {
  font-size: 16px;
}

.mini-switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfe;
  color: var(--muted);
  padding: 0 12px;
  font-size: 13px;
  white-space: nowrap;
}

.mini-switch input {
  width: 16px;
  min-height: 16px;
  accent-color: var(--accent);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(340px, 440px) minmax(260px, 1fr);
  gap: 18px;
  align-items: start;
}

.panel,
.phone-frame,
.summary,
.record-box,
.api-box {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.panel {
  padding: 18px;
}

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

.role-badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  padding: 0 10px;
  color: #fff;
  font-size: 13px;
}

.role-badge.buyer {
  background: var(--buyer);
}

.role-badge.seller {
  background: var(--seller);
}

.field-group {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
}

.shortcut-card {
  display: grid;
  gap: 5px;
  margin: -2px 0 16px;
  border: 1px solid #cfe0ef;
  border-radius: 8px;
  background: #f2f8ff;
  padding: 10px;
}

.shortcut-card span {
  color: #4d6d88;
  font-size: 12px;
}

.shortcut-card strong {
  font-size: 13px;
  line-height: 1.45;
}

.seller-shortcut {
  border-color: #cce8dc;
  background: #f0fbf6;
}

.compact-field {
  margin-bottom: 8px;
}

label {
  color: var(--muted);
  font-size: 13px;
}

input,
select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfe;
  color: var(--text);
  padding: 0 12px;
  outline: none;
}

.tiny-link {
  width: fit-content;
  color: var(--link);
  font-size: 13px;
  text-decoration: none;
}

.tiny-link:hover {
  text-decoration: underline;
}

.checkline {
  display: grid;
  grid-template-columns: 18px 1fr;
  gap: 8px;
  align-items: start;
  margin: 4px 0 16px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.checkline input {
  width: 16px;
  min-height: 16px;
  margin: 2px 0 0;
  accent-color: var(--accent);
}

input:focus,
select:focus {
  border-color: #92b7e8;
  box-shadow: 0 0 0 3px rgba(40, 120, 216, 0.12);
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f2f6f8;
}

.segment {
  min-height: 36px;
  background: transparent;
  color: var(--muted);
}

.segment.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 4px 14px rgba(31, 43, 55, 0.08);
}

.button-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}

.upload-box {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 12px;
  align-items: center;
  padding: 12px;
  border: 1px dashed #b9c7d1;
  border-radius: 8px;
  background: #fbfdfe;
}

.upload-box span {
  color: var(--muted);
  font-size: 13px;
}

.upload-box strong {
  font-size: 14px;
}

.upload-box button {
  grid-row: span 2;
}

.proof-actions {
  display: grid;
  grid-row: span 2;
  grid-template-columns: 1fr;
  gap: 8px;
  min-width: 128px;
}

.proof-actions button {
  grid-row: auto;
}

.phone-frame {
  overflow: hidden;
}

.phone-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: #eff6fb;
}

.phone-header div {
  display: grid;
  gap: 2px;
}

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

.online-dot {
  min-height: 24px;
  border-radius: 999px;
  padding: 4px 9px;
  background: #dff8ed;
  color: #0c7758 !important;
}

.chat-feed {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 520px;
  max-height: 620px;
  overflow: auto;
  padding: 16px;
  background:
    linear-gradient(rgba(255, 255, 255, 0.78), rgba(255, 255, 255, 0.78)),
    repeating-linear-gradient(135deg, #edf4f7 0 10px, #f8fbfc 10px 20px);
}

.message {
  width: fit-content;
  max-width: 88%;
  padding: 11px 12px;
  border-radius: 8px;
  line-height: 1.55;
  font-size: 14px;
  white-space: pre-line;
}

.message a {
  color: var(--link);
  font-weight: 700;
  text-decoration: none;
  word-break: break-all;
}

.message a:hover {
  text-decoration: underline;
}

.message.bot {
  align-self: flex-start;
  background: #fff;
  border: 1px solid var(--line);
}

.message.buyer {
  align-self: flex-end;
  background: var(--soft-blue);
  border: 1px solid #c7ddf7;
}

.message.seller {
  align-self: flex-end;
  background: var(--soft-green);
  border: 1px solid #bfe9d8;
}

.message.notice {
  align-self: center;
  background: var(--warning);
  border: 1px solid #f1dfad;
  color: #6b5522;
}

.quick-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 12px;
  border-top: 1px solid var(--line);
}

.details-grid {
  display: grid;
  grid-template-columns: 0.9fr 1.3fr 0.8fr;
  gap: 18px;
  margin-top: 18px;
}

.summary,
.record-box,
.api-box {
  padding: 18px;
}

.template-section {
  margin-top: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 18px;
}

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

.template-grid article {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfe;
  padding: 12px;
}

.template-grid span {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
}

.template-grid p {
  margin: 0;
  color: #24313a;
  font-size: 14px;
  line-height: 1.55;
}

.admin-layout {
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}

.admin-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 18px;
}

.wide-card {
  grid-column: 1 / -1;
}

.admin-note {
  margin-bottom: 14px;
  border: 1px solid #f0dcaa;
  border-radius: 8px;
  background: #fff8e8;
  color: #675322;
  padding: 12px;
  font-size: 14px;
  line-height: 1.55;
}

.table-wrap {
  overflow: auto;
}

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

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

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.module-list {
  display: grid;
  gap: 10px;
  margin-bottom: 14px;
}

.module-list label {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfe;
  color: var(--text);
  padding: 0 12px;
}

.module-list input {
  width: 16px;
  min-height: 16px;
  accent-color: var(--accent);
}

.strategy-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.strategy-grid div {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfe;
  padding: 12px;
}

.strategy-grid strong {
  display: block;
  margin-bottom: 8px;
}

.strategy-grid p {
  margin: 0;
  color: #4b5b66;
  font-size: 14px;
  line-height: 1.55;
}

dl {
  display: grid;
  gap: 10px;
  margin: 0;
}

dl div {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

dt {
  color: var(--muted);
}

dd {
  margin: 0;
  font-weight: 700;
  text-align: right;
}

pre {
  min-height: 160px;
  margin: 0;
  overflow: auto;
  border-radius: 8px;
  background: #111827;
  color: #edf5f8;
  padding: 14px;
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 13px;
  line-height: 1.55;
  white-space: pre-wrap;
}

.api-list {
  display: grid;
  gap: 10px;
}

.principle-list {
  display: grid;
  gap: 10px;
}

.principle-list p {
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7fafb;
  padding: 10px;
  color: #40505b;
  font-size: 14px;
  line-height: 1.5;
}

.record-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.record-links a {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  border: 1px solid #bfdbf7;
  border-radius: 8px;
  background: #edf6ff;
  color: #1d69b3;
  padding: 0 10px;
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
}

.hidden {
  display: none !important;
}

code {
  display: block;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7fafb;
  padding: 10px;
  color: #24313a;
  white-space: nowrap;
  overflow: auto;
}

@media (max-width: 1060px) {
  .workspace,
  .details-grid,
  .template-grid,
  .admin-layout,
  .strategy-grid {
    grid-template-columns: 1fr;
  }

  .wide-card {
    grid-column: auto;
  }

  .phone-frame {
    order: -1;
  }
}

@media (max-width: 680px) {
  .shell {
    padding: 16px;
  }

  .topbar,
  .status-strip {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions {
    flex-direction: column;
  }

  .status-actions {
    align-items: stretch;
    flex-direction: column;
  }

  h1 {
    font-size: 24px;
  }

  .button-row,
  .quick-actions {
    grid-template-columns: 1fr;
  }
}
