:root {
  color-scheme: light;
  --bg: #f5f2ee;
  --panel: #fffdf9;
  --ink: #17201c;
  --muted: #66736d;
  --line: #e5ded5;
  --brand: #c91523;
  --brand-dark: #991b1f;
  --brand-light: #fff0ed;
  --accent: #0f766e;
  --accent-light: #e7f6f2;
  --gold: #a96818;
  --green: #0f9f6e;
  --shadow: 0 2px 8px rgba(60, 48, 38, 0.04);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
}

button, input { font: inherit; }
button { cursor: pointer; }

.app-shell {
  width: 100%;
  height: 100vh;
  margin: 0;
  display: grid;
  grid-template-columns: 1.5fr 1fr;
  grid-template-rows: minmax(0, 1fr);
  gap: 8px;
  padding: 4px;
  overflow: hidden;
}

/* === 左栏：AI 对话 === */
.chat-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  gap: 8px;
  min-width: 0;
  min-height: 0;
  height: 100%;
}

.page-head {
  display: flex;
  align-items: center;
  min-height: 48px;
  padding: 10px 16px;
  border-radius: 6px;
  background: rgba(255, 253, 249, 0.96);
  border: 1px solid rgba(229, 222, 213, 0.82);
  box-shadow: var(--shadow);
}

.page-head h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 800;
  letter-spacing: 0;
  color: var(--ink);
}

.page-head .hero-copy {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.chat-thread {
  min-height: 0;
  overflow-y: auto;
  padding: 8px 10px;
  border-radius: 6px;
  background: rgba(255, 253, 249, 0.92);
  border: 1px solid rgba(229, 222, 213, 0.72);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.message { display: flex; }
.message.user { justify-content: flex-end; }
.message.assistant { justify-content: flex-start; }

.bubble {
  max-width: 85%;
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 14px;
  line-height: 1.6;
  word-break: break-word;
}

.message.user .bubble {
  background: linear-gradient(135deg, var(--brand), #9f1239);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.bubble-img {
  display: block;
  width: 120px;
  height: auto;
  max-width: 120px;
  max-height: 80px;
  object-fit: cover;
  border-radius: 6px;
  margin-bottom: 6px;
  border: 1px solid rgba(255,255,255,0.3);
}

.message.assistant .bubble {
  background: #f4f1ec;
  border: 1px solid #ebe3d9;
  color: var(--ink);
  border-bottom-left-radius: 4px;
}

.message.assistant .bubble p {
  margin: 0 0 8px 0;
}
.message.assistant .bubble p:last-child {
  margin-bottom: 0;
}
.message.assistant .bubble h2,
.message.assistant .bubble h3,
.message.assistant .bubble h4,
.message.assistant .bubble h5 {
  margin: 14px 0 6px;
  font-size: 14px;
  font-weight: 700;
  color: #1e293b;
  line-height: 1.4;
}
.message.assistant .bubble h2 { font-size: 15px; }
.message.assistant .bubble h2:first-child,
.message.assistant .bubble h3:first-child,
.message.assistant .bubble h4:first-child {
  margin-top: 0;
}
.message.assistant .bubble hr {
  border: none;
  border-top: 1px solid var(--line);
  margin: 12px 0;
}
.message.assistant .bubble ul,
.message.assistant .bubble ol {
  margin: 6px 0;
  padding-left: 20px;
}
.message.assistant .bubble li {
  margin-bottom: 4px;
}
.message.assistant .bubble strong {
  color: #1e293b;
}

.message.assistant .bubble .md-table-wrap {
  margin: 8px 0;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}
.message.assistant .bubble .md-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}
.message.assistant .bubble .md-table th,
.message.assistant .bubble .md-table td {
  padding: 6px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
  vertical-align: top;
}
.message.assistant .bubble .md-table th {
  background: #f4f1ec;
  font-weight: 600;
  color: #1e293b;
}
.message.assistant .bubble .md-table tr:last-child td {
  border-bottom: none;
}

.message.assistant .bubble .msg-img {
  display: block;
  max-width: 100%;
  max-height: 220px;
  border-radius: 8px;
  margin: 6px 0;
  object-fit: contain;
  background: #faf7f2;
  cursor: zoom-in;
}
.message.assistant .bubble .md-table .msg-img {
  max-height: 80px;
  margin: 0;
}

.product-images {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}
.product-thumb {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.product-thumb-link {
  color: inherit;
  text-decoration: none;
}

.product-thumb-link:hover .msg-img {
  border-color: var(--brand);
  box-shadow: 0 6px 18px rgba(201, 21, 35, 0.14);
}

.product-thumb .msg-img {
  width: 160px;
  height: 120px;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}
.thumb-label {
  font-size: 11px;
  color: var(--muted);
  text-align: center;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.thumb-link-text,
.cell-link {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  min-height: 24px;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--brand-light);
  color: var(--brand);
  font-size: 12px;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}

.cell-link:hover,
.product-thumb-link:hover .thumb-link-text {
  background: #ffe2dc;
}

.data-table .cell-img {
  display: block;
  max-width: 180px;
  max-height: 140px;
  object-fit: contain;
  border-radius: 6px;
  background: #faf7f2;
  cursor: zoom-in;
  transition: transform 0.15s;
}
.data-table .cell-img:hover {
  transform: scale(1.05);
}

/* 图片灯箱 */
.lightbox-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: zoom-out;
  animation: fadeIn 0.15s ease;
}
.lightbox-overlay img {
  max-width: 90vw;
  max-height: 90vh;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.4);
}
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* === 进度条 === */
.progress-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-radius: 10px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.step {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  opacity: 0.5;
  transition: all 0.3s;
}

.step .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--line);
  transition: all 0.3s;
}

.step.active {
  opacity: 1;
  color: var(--brand);
  font-weight: 600;
}

.step.active .dot {
  background: var(--brand);
  box-shadow: 0 0 8px rgba(201, 21, 35, 0.34);
  animation: pulse 1s infinite;
}

.step.done {
  opacity: 1;
  color: var(--green);
}

.step.done .dot {
  background: var(--green);
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.4); }
}

.step + .step::before {
  content: "";
  width: 24px;
  height: 2px;
  background: var(--line);
  margin-right: 8px;
}

.step.done + .step::before,
.step.active + .step::before {
  background: var(--green);
}

/* === 输入框 === */
.ask-form {
  display: flex;
  gap: 8px;
  padding: 7px 8px;
  border-radius: 6px;
  background: rgba(255, 253, 249, 0.96);
  border: 1px solid rgba(229, 222, 213, 0.76);
  box-shadow: var(--shadow);
}

.ask-form input {
  flex: 1;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}

.ask-form input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(201, 21, 35, 0.08);
}

.ask-form button {
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  background: var(--brand);
  color: #fff;
  font-weight: 600;
  font-size: 14px;
  transition: background 0.2s, transform 0.2s;
}

.ask-form button:not(:disabled):hover {
  background: var(--brand-dark);
  transform: translateY(-1px);
}

.ask-form button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.ask-form {
  flex-wrap: wrap;
}
.ask-form.drag-over {
  outline: 2px dashed var(--brand);
  outline-offset: -2px;
}

.progress-bar,
.ask-form {
  align-self: end;
}

.img-preview {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0;
  padding-bottom: 6px;
  overflow: hidden;
}
.img-preview[hidden] {
  display: none;
}
#imgThumb {
  display: block;
  width: 48px;
  height: 48px;
  max-width: 48px;
  max-height: 48px;
  min-width: 48px;
  min-height: 48px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--line);
  cursor: pointer;
}
#imgThumb[src=""],
#imgThumb:not([src]) {
  display: none;
}
.img-remove {
  width: 18px; height: 18px;
  border: none; border-radius: 50%;
  background: rgba(0,0,0,0.45);
  color: #fff; font-size: 12px; line-height: 1;
  cursor: pointer;
  position: relative;
  top: -18px;
  left: -14px;
  margin-right: -14px;
}

.img-lightbox {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.7);
  cursor: zoom-out;
}
.img-lightbox img {
  max-width: 90vw;
  max-height: 90vh;
  border-radius: 8px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.4);
}
.table-panel {
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 10px 12px;
  border-radius: 6px;
  background: rgba(255, 253, 249, 0.96);
  border: 1px solid rgba(229, 222, 213, 0.76);
  box-shadow: var(--shadow);
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
}

.table-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex: 0 0 auto;
  margin-bottom: 2px;
  position: relative;
  z-index: 4;
  background: transparent;
}

.table-header h2 {
  margin: 0;
  font-size: 15px;
  color: #1f2a24;
}

.source-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  padding: 0;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
}

.source-badge::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.1);
}

.table-hint {
  flex: 0 0 auto;
  margin: 0 0 6px;
  font-size: 12px;
  color: var(--muted);
  position: relative;
  z-index: 4;
  background: transparent;
}

.page-switcher {
  display: flex;
  gap: 16px;
  margin: 0 0 6px;
  padding: 0;
  border: none;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  overflow-x: auto;
  scrollbar-width: none;
  flex: 0 0 auto;
  position: relative;
  z-index: 4;
}

.page-switcher::-webkit-scrollbar {
  display: none;
}

.page-step {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  flex: 0 0 auto;
  min-height: 30px;
  padding: 0 0 6px;
  border: none;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  position: relative;
}

.page-no,
.page-step em {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  height: auto;
  padding: 0;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  line-height: 18px;
  text-align: center;
  font-style: normal;
}

.page-no {
  border: none;
  color: var(--gold);
}

.page-step.active {
  background: transparent;
  color: var(--brand);
  box-shadow: none;
}

.page-step.active::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 2px;
  border-radius: 999px;
  background: var(--brand);
}

.page-step.active .page-no,
.page-step.active em {
  background: transparent;
  color: var(--brand);
  border-color: rgba(201, 21, 35, 0.34);
}

.detail-view {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding-right: 0;
}

.param-table-wrap {
  height: 100%;
  min-height: 0;
  overflow: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table th,
.data-table td {
  padding: 6px 9px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.data-table th {
  background: #f5efe8;
  font-weight: 600;
  position: sticky;
  top: 0;
  z-index: 2;
  box-shadow: inset 0 -1px 0 var(--line);
}

.param-table th,
.param-table td {
  white-space: nowrap;
}

.param-table td:first-child {
  font-weight: 500;
  color: var(--muted);
  min-width: 140px;
  white-space: normal;
}

.match-pill {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  padding: 1px 6px;
  border-radius: 4px;
  background: #ecfdf5;
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

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

.case-card {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.case-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.case-index {
  display: inline-block;
  margin-bottom: 4px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
}

.case-card h3 {
  margin: 0;
  color: #1e293b;
  font-size: 14px;
  line-height: 1.4;
}

.case-card p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.case-facts {
  display: grid;
  gap: 6px;
}

.case-fact {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  gap: 6px;
  align-items: start;
  font-size: 13px;
  line-height: 1.5;
}

.case-fact span {
  color: var(--muted);
}

.case-fact strong {
  color: var(--ink);
  font-weight: 500;
  word-break: break-word;
}

.case-fact .cell-img {
  max-width: min(220px, 100%);
  max-height: 160px;
}

.card-empty {
  border: 1px dashed var(--line);
  border-radius: 6px;
  background: #faf7f2;
}

.empty-state {
  padding: 18px 12px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}

/* === 表格动画 === */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.data-table tbody tr {
  animation: fadeInUp 0.3s ease both;
}

.data-table tbody tr:nth-child(1) { animation-delay: 0s; }
.data-table tbody tr:nth-child(2) { animation-delay: 0.04s; }
.data-table tbody tr:nth-child(3) { animation-delay: 0.08s; }
.data-table tbody tr:nth-child(4) { animation-delay: 0.12s; }
.data-table tbody tr:nth-child(5) { animation-delay: 0.16s; }
.data-table tbody tr:nth-child(6) { animation-delay: 0.2s; }
.data-table tbody tr:nth-child(7) { animation-delay: 0.24s; }
.data-table tbody tr:nth-child(8) { animation-delay: 0.28s; }
.data-table tbody tr:nth-child(9) { animation-delay: 0.32s; }
.data-table tbody tr:nth-child(10) { animation-delay: 0.36s; }
.data-table tbody tr:nth-child(11) { animation-delay: 0.4s; }
.data-table tbody tr:nth-child(12) { animation-delay: 0.44s; }
.data-table tbody tr:nth-child(13) { animation-delay: 0.48s; }
.data-table tbody tr:nth-child(14) { animation-delay: 0.52s; }
.data-table tbody tr:nth-child(15) { animation-delay: 0.56s; }
.data-table tbody tr:nth-child(16) { animation-delay: 0.6s; }
.data-table tbody tr:nth-child(17) { animation-delay: 0.64s; }
.data-table tbody tr:nth-child(18) { animation-delay: 0.68s; }
.data-table tbody tr:nth-child(n+19) { animation-delay: 0.72s; }

/* === 响应式 === */
@media (max-width: 900px) {
  body {
    min-height: 100dvh;
  }

  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
    height: auto;
    min-height: 100dvh;
    overflow: visible;
    padding: 4px;
    gap: 6px;
  }

  .chat-panel {
    min-height: auto;
    grid-template-rows: auto minmax(240px, 42dvh) auto auto;
    gap: 6px;
  }

  .page-head {
    min-height: 46px;
    padding: 8px 12px;
  }

  .chat-thread {
    padding: 8px;
  }

  .table-panel {
    min-height: 420px;
    height: auto;
    max-height: none;
    overflow: visible;
    padding: 8px;
  }

  .page-switcher {
    margin-bottom: 6px;
  }

  .param-table-wrap {
    max-height: 56dvh;
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 8px;
  }

  .data-table th {
    top: 0;
  }
}

@media (max-width: 640px) {
  .app-shell {
    padding: 3px;
  }

  .page-head h1 {
    font-size: 18px;
  }

  .bubble {
    max-width: 94%;
    font-size: 13px;
  }

  .ask-form {
    padding: 6px;
  }

  .ask-form input {
    min-width: 0;
    flex-basis: 100%;
  }

  .ask-form button {
    width: 100%;
  }

  .table-header {
    align-items: flex-start;
    gap: 8px;
  }

  .page-step {
    min-height: 30px;
    padding: 0 0 6px;
    font-size: 12px;
  }

  .param-table th,
  .param-table td {
    padding: 7px 9px;
    font-size: 12px;
  }

  .case-card {
    padding: 10px;
  }

  .case-card-head {
    flex-direction: column;
    gap: 8px;
  }

  .case-fact {
    grid-template-columns: 1fr;
    gap: 2px;
  }

  .case-fact span {
    font-size: 12px;
  }
}
