:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --panel: #ffffff;
  --text: #172033;
  --muted: #6a7282;
  --border: #dfe5ef;
  --accent: #0f766e;
  --accent-dark: #0b5f59;
  --danger: #b42318;
  --danger-bg: #fff1f0;
  --success: #067647;
  --success-bg: #ecfdf3;
  --shadow: 0 10px 30px rgba(23, 32, 51, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 14px;
  line-height: 1.45;
}

.shell {
  width: min(1240px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 44px;
}

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

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin: 0;
}

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

h2 {
  font-size: 18px;
}

h3 {
  font-size: 15px;
  margin-bottom: 10px;
}

.api-status {
  min-width: 260px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  color: var(--muted);
}

.api-status span,
.muted {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.api-status strong {
  display: block;
  margin-top: 2px;
  color: var(--text);
  overflow-wrap: anywhere;
}

.alert {
  margin-bottom: 16px;
  padding: 12px 14px;
  border-radius: 8px;
  border: 1px solid;
}

.alert--success {
  background: var(--success-bg);
  border-color: #abefc6;
  color: var(--success);
}

.alert--error {
  background: var(--danger-bg);
  border-color: #fecdca;
  color: var(--danger);
}

.stats {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

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

.stat {
  padding: 16px;
}

.stat span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.stat strong {
  display: block;
  margin-top: 6px;
  font-size: 26px;
}

.layout {
  display: grid;
  grid-template-columns: minmax(320px, 0.8fr) minmax(520px, 1.2fr);
  gap: 16px;
  margin-bottom: 16px;
}

.panel {
  padding: 18px;
}

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.panel-head p {
  color: var(--muted);
  max-width: 520px;
}

.form {
  display: grid;
  gap: 12px;
}

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

input {
  width: 100%;
  min-height: 40px;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font: inherit;
}

input:focus {
  outline: 2px solid rgba(15, 118, 110, 0.18);
  border-color: var(--accent);
}

button {
  min-height: 40px;
  padding: 9px 14px;
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: #ffffff;
  cursor: pointer;
  font: inherit;
  font-weight: 700;
}

button:hover {
  background: var(--accent-dark);
}

.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #ffffff;
  color: var(--text);
  font-weight: 700;
  text-decoration: none;
}

.button-link:hover {
  background: #eef4f8;
}

.button-link--small {
  min-height: 32px;
  padding: 6px 10px;
  font-size: 13px;
}

.button-secondary {
  min-height: 34px;
  padding: 7px 10px;
  border: 1px solid var(--border);
  background: #ffffff;
  color: var(--text);
}

.button-secondary:hover {
  background: #eef4f8;
}

.inline-form {
  margin: 0;
}

.feature-toggle {
  display: grid;
  gap: 6px;
  justify-items: start;
}

.credentials {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.copy-field {
  margin-bottom: 10px;
}

.copy-field div {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.copy-field button {
  min-width: 86px;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 11px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

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

.empty {
  padding: 18px;
  color: var(--muted);
  text-align: center;
}

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

.conversation {
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fbfcff;
}

.conversation-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 12px;
}

.conversation-meta strong {
  color: var(--text);
  font-size: 13px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #eef7ff;
  color: #175cd3;
  font-weight: 700;
}

.badge--success {
  background: #ecfdf3;
  color: #067647;
}

.badge--ai {
  background: #fef3c7;
  color: #92400e;
}

.messages-preview {
  display: grid;
  gap: 8px;
}

.messages-preview p {
  display: grid;
  grid-template-columns: 82px minmax(0, 1fr);
  gap: 10px;
}

.messages-preview span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.conversation-actions {
  margin-top: 12px;
}

.conversation-detail-panel {
  max-width: 980px;
  margin: 0 auto;
}

.conversation-thread {
  display: grid;
  gap: 14px;
}

.conversion-strip {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
  margin: -2px 0 18px;
}

.conversion-strip div {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fbfcff;
}

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

.conversion-strip strong {
  display: block;
  margin-top: 3px;
  font-size: 15px;
}

.ai-call-strip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: -8px 0 18px;
  padding: 10px 12px;
  border: 1px solid #fde68a;
  border-radius: 8px;
  background: #fffbeb;
  color: #78350f;
  font-size: 12px;
}

.thread-message {
  display: grid;
  gap: 6px;
  max-width: 76%;
}

.thread-message--user {
  justify-self: end;
}

.thread-message--assistant {
  justify-self: start;
}

.thread-message--ai {
  justify-self: center;
  max-width: 92%;
}

.thread-message-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

.thread-message-head strong {
  color: var(--text);
}

.thread-message--user .thread-message-head {
  justify-content: flex-end;
}

.thread-bubble {
  padding: 12px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #ffffff;
  white-space: normal;
  overflow-wrap: anywhere;
}

.thread-message--user .thread-bubble {
  background: #e7f7f4;
  border-color: #b7e4dc;
}

.thread-message--assistant .thread-bubble {
  background: #f8fafc;
}

.thread-message--ai .thread-message-head {
  justify-content: center;
}

.thread-message--ai .thread-bubble {
  border-color: #fde68a;
  background: #fffbeb;
}

.ai-call-bubble {
  display: grid;
  gap: 10px;
  min-width: min(620px, 100%);
}

.ai-call-bubble > div:first-child {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.ai-call-bubble > div:first-child span {
  color: #92400e;
  font-size: 12px;
  font-weight: 700;
}

.ai-call-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.button-secondary--tiny {
  min-height: 30px;
  padding: 5px 9px;
  font-size: 12px;
}

.json-panel {
  max-height: 380px;
  margin: 0;
  padding: 10px;
  overflow: auto;
  border: 1px solid #fcd34d;
  border-radius: 6px;
  background: #ffffff;
  color: #1f2937;
  font-family: Menlo, Consolas, Monaco, monospace;
  font-size: 12px;
  line-height: 1.45;
  white-space: pre-wrap;
}

.ai-payload-panel {
  display: grid;
  gap: 10px;
}

.ai-payload-panel[hidden] {
  display: none;
}

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

.ai-payload-metric {
  padding: 8px 9px;
  border: 1px solid #fde68a;
  border-radius: 6px;
  background: #ffffff;
}

.ai-payload-metric span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.ai-payload-metric strong {
  display: block;
  margin-top: 2px;
  overflow-wrap: anywhere;
}

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

.ai-message-card {
  display: grid;
  gap: 7px;
  padding: 10px;
  border: 1px solid #f3d47a;
  border-radius: 8px;
  background: #ffffff;
}

.ai-message-card > strong {
  color: #92400e;
  font-size: 12px;
  text-transform: uppercase;
}

.ai-message-card div,
.ai-message-card pre,
.ai-raw-json pre {
  max-height: 360px;
  margin: 0;
  overflow: auto;
  color: #1f2937;
  font-family: Menlo, Consolas, Monaco, monospace;
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
}

.ai-message-card--decoded {
  border-color: #bfdbfe;
  background: #eff6ff;
}

.ai-message-card--normalized {
  border-color: #bbf7d0;
  background: #f0fdf4;
}

.ai-raw-json {
  padding: 8px 10px;
  border: 1px dashed #f3d47a;
  border-radius: 8px;
  background: #fffdf5;
}

.ai-raw-json summary {
  cursor: pointer;
  color: #92400e;
  font-weight: 800;
}

.ai-raw-json pre {
  margin-top: 8px;
}

.empty-payload {
  padding: 10px;
  border: 1px dashed #f3d47a;
  border-radius: 8px;
  background: #ffffff;
  color: var(--muted);
}

.thread-flags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.thread-flags span {
  display: inline-flex;
  min-height: 22px;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  background: #fff7ed;
  color: #9a3412;
  font-size: 12px;
  font-weight: 700;
}

.thread-details {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid #e6edf6;
  border-radius: 8px;
  background: #ffffff;
}

.detail-block {
  display: grid;
  gap: 7px;
}

.detail-block > strong {
  color: #344054;
  font-size: 12px;
  text-transform: uppercase;
}

.detail-line {
  padding: 8px 10px;
  border-radius: 6px;
  background: #f6f8fb;
  color: var(--text);
}

.choice-list,
.product-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.choice-chip,
.product-tags span {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 28px;
  padding: 4px 8px;
  border: 1px solid #d7e7f7;
  border-radius: 999px;
  background: #f3f9ff;
  color: #184e77;
  font-size: 12px;
  font-weight: 700;
}

.choice-chip img {
  width: 28px;
  height: 28px;
  margin: -4px 0 -4px -8px;
  border-radius: 999px;
  object-fit: cover;
}

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

.product-mini {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr);
  gap: 10px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fbfcff;
}

.product-mini > img {
  width: 52px;
  height: 52px;
  border-radius: 6px;
  object-fit: cover;
  background: #ffffff;
}

.product-mini-placeholder {
  width: 52px;
  height: 52px;
  border-radius: 6px;
  background: #eef2f7;
}

.product-mini-body {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.product-mini-title {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px;
  font-weight: 700;
}

.product-mini-title a {
  color: var(--text);
  text-decoration: none;
}

.product-mini-title a:hover {
  color: var(--accent);
  text-decoration: underline;
}

.product-mini-title span {
  color: var(--accent);
}

.product-mini-meta,
.product-reason {
  color: var(--muted);
  font-size: 12px;
}

.product-tags--soft span {
  border-color: #ecdfc4;
  background: #fff8eb;
  color: #8a4b08;
}

@media (max-width: 1180px) {
  .stats {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

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

@media (max-width: 880px) {
  .topbar,
  .panel-head {
    display: grid;
  }

  .stats,
  .layout,
  .conversion-strip {
    grid-template-columns: 1fr;
  }

  .ai-payload-grid {
    grid-template-columns: 1fr;
  }

  .messages-preview p {
    grid-template-columns: 1fr;
    gap: 2px;
  }

  .thread-message {
    max-width: 100%;
  }

  .product-mini {
    grid-template-columns: 44px minmax(0, 1fr);
  }

  .product-mini > img {
    width: 44px;
    height: 44px;
  }

  .product-mini-placeholder {
    width: 44px;
    height: 44px;
  }
}
