:root {
  color-scheme: light;
  --bg: #f7f7f8;
  --surface: #ffffff;
  --surface-soft: #f3f5f4;
  --text: #171717;
  --muted: #6b7280;
  --line: #e5e7eb;
  --line-strong: #d1d5db;
  --primary: #0f766e;
  --primary-dark: #115e59;
  --accent: #c2410c;
  --danger: #b42318;
  --shadow: 0 18px 44px rgba(15, 23, 42, 0.13);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  min-width: 320px;
  overflow: hidden;
}

body {
  margin: 0;
  color: var(--text);
  background: var(--bg);
  font-family: Inter, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", Arial, sans-serif;
}

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

button {
  cursor: pointer;
}

button:disabled {
  cursor: wait;
  opacity: 0.64;
}

h1,
h2,
p {
  margin: 0;
}

.app-shell {
  height: 100dvh;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.topbar {
  height: 64px;
  padding: 0 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex: 0 0 auto;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(18px);
  z-index: 20;
}

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

.brand-mark {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: #fff;
  background: var(--primary);
  font-weight: 900;
}

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

.brand strong {
  font-size: 16px;
  line-height: 1.15;
}

.brand span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.top-actions {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.model-field {
  width: clamp(178px, 22vw, 280px);
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 7px;
  padding-left: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.model-field span,
.credit-pill span {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.select,
input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: var(--surface);
  outline: none;
  transition: border-color 140ms ease, box-shadow 140ms ease, background 140ms ease;
}

.select {
  height: 38px;
  min-width: 0;
  padding: 0 30px 0 8px;
  border: 0;
  background: transparent;
}

input,
select,
textarea {
  padding: 11px 12px;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.11);
}

textarea {
  resize: none;
  line-height: 1.55;
}

.credit-pill {
  height: 38px;
  min-width: 88px;
  padding: 0 11px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.credit-pill:hover {
  border-color: var(--primary);
  background: #ecfdf5;
}

.credit-pill strong {
  font-size: 15px;
}

.button,
.icon-button {
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0 13px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  background: transparent;
  font-weight: 700;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background 140ms ease, border-color 140ms ease, color 140ms ease;
}

.button:hover,
.icon-button:hover {
  background: var(--surface-soft);
}

.button.primary {
  color: #fff;
  border-color: var(--primary);
  background: var(--primary);
}

.button.primary:hover {
  border-color: var(--primary-dark);
  background: var(--primary-dark);
}

.button.secondary {
  color: #fff;
  border-color: var(--accent);
  background: var(--accent);
}

.button.secondary:hover {
  background: #9a3412;
}

.button.ghost,
.icon-button {
  border-color: var(--line);
  background: var(--surface);
}

.conversation-toggle {
  display: none;
}

.button.wide {
  width: 100%;
}

.workspace {
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  min-height: 0;
  flex: 1;
  display: grid;
  grid-template-columns: 272px minmax(0, 1fr);
  gap: 18px;
  padding: 0 18px;
}

.conversation-sidebar {
  min-height: 0;
  padding: 18px 0 16px;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line);
}

.sidebar-head {
  padding: 0 14px 12px 0;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  flex: 0 0 auto;
}

.sidebar-head h2 {
  font-size: 16px;
  line-height: 1.25;
}

.sidebar-head span {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
}

.conversation-sidebar .conversation-list {
  min-height: 0;
  overflow-y: auto;
  padding-right: 12px;
}

.chat-panel {
  width: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.chat-head {
  min-height: 78px;
  padding: 16px 4px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex: 0 0 auto;
}

.chat-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.head-stack {
  min-width: 0;
}

h1 {
  font-size: 24px;
  line-height: 1.25;
  letter-spacing: 0;
}

.chat-head p,
.modal-head p {
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.messages {
  min-height: 0;
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  scroll-behavior: smooth;
  padding: 16px 4px 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.messages::-webkit-scrollbar,
.sheet-card::-webkit-scrollbar {
  width: 10px;
}

.messages::-webkit-scrollbar-thumb,
.sheet-card::-webkit-scrollbar-thumb {
  border: 3px solid transparent;
  border-radius: 999px;
  background: rgba(107, 114, 128, 0.36);
  background-clip: content-box;
}

.empty-state {
  margin: auto;
  width: min(620px, 100%);
  padding: 0 14px;
  color: var(--muted);
  text-align: center;
  line-height: 1.7;
}

.empty-state strong {
  display: block;
  margin-bottom: 10px;
  color: var(--text);
  font-size: 28px;
  line-height: 1.25;
}

.message {
  width: fit-content;
  max-width: min(78%, 720px);
  padding: 12px 15px;
  border-radius: 18px;
  line-height: 1.68;
  white-space: pre-wrap;
}

.message.user {
  align-self: flex-end;
  color: #fff;
  border-bottom-right-radius: 6px;
  background: var(--primary);
}

.message.assistant {
  align-self: flex-start;
  width: min(100%, 760px);
  max-width: 100%;
  padding-left: 0;
  background: transparent;
}

.message-meta {
  margin-top: 9px;
  color: var(--muted);
  font-size: 12px;
}

.evidence-strip {
  margin-top: 12px;
  padding: 9px 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f8fafc;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
  white-space: normal;
}

.evidence-strip strong {
  color: var(--primary-dark);
}

.evidence-strip span {
  padding-left: 7px;
  border-left: 1px solid var(--line);
}

.composer-wrap {
  flex: 0 0 auto;
  padding: 10px 0 16px;
  background: linear-gradient(to top, var(--bg) 72%, rgba(247, 247, 248, 0));
}

.prompt-rail {
  margin-bottom: 10px;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 0 2px 2px;
}

.prompt-rail button {
  min-height: 34px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: #374151;
  background: var(--surface);
  font-size: 13px;
  white-space: nowrap;
}

.prompt-rail button:hover {
  border-color: var(--primary);
  color: var(--primary-dark);
}

.composer {
  min-height: 64px;
  padding: 9px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: end;
  border: 1px solid var(--line-strong);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: 0 14px 38px rgba(15, 23, 42, 0.09);
}

.composer textarea {
  min-height: 44px;
  max-height: 142px;
  border: 0;
  padding: 10px 8px;
  background: transparent;
  box-shadow: none;
}

.composer textarea:focus {
  box-shadow: none;
}

.composer .button {
  min-width: 74px;
  min-height: 44px;
  border-radius: 12px;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(17, 24, 39, 0.38);
  backdrop-filter: blur(8px);
}

.modal-card,
.sheet-card {
  width: min(480px, 100%);
  max-height: min(760px, calc(100dvh - 36px));
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 18px;
}

.sheet-card {
  width: min(560px, 100%);
}

.wallet-card {
  width: min(720px, 100%);
}

.compare-card {
  width: min(620px, 100%);
}

.report-card {
  width: min(960px, 100%);
}

.admin-card {
  width: min(760px, 100%);
}

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

.modal-head h2 {
  font-size: 18px;
  line-height: 1.25;
}

.modal-actions {
  display: flex;
  gap: 8px;
}

.wallet-summary {
  margin-bottom: 18px;
  padding: 18px;
  display: grid;
  gap: 6px;
  border: 1px solid #99f6e4;
  border-radius: 14px;
  background: linear-gradient(135deg, #ecfdf5, #f8fafc);
}

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

.wallet-summary strong {
  color: var(--primary-dark);
  font-size: 34px;
  line-height: 1;
}

.wallet-section {
  margin-top: 18px;
}

.wallet-section h3 {
  margin: 0 0 10px;
  font-size: 15px;
  line-height: 1.3;
}

.report-body {
  display: grid;
  gap: 18px;
}

.report-cover,
.report-section {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
}

.report-cover {
  padding: 18px;
  background: #f8fafc;
}

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

.report-cover h3,
.report-section h3 {
  margin: 0;
  font-size: 17px;
  line-height: 1.35;
}

.report-cover p {
  margin-top: 10px;
  color: #374151;
  line-height: 1.7;
}

.report-section {
  padding: 16px;
}

.profile-grid,
.report-options,
.source-grid {
  margin-top: 12px;
  display: grid;
  gap: 10px;
}

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

.profile-row,
.source-item,
.report-option {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  background: #ffffff;
}

.profile-row.missing {
  border-style: dashed;
  background: #fffbeb;
}

.profile-row strong,
.source-item strong {
  display: block;
  font-size: 13px;
}

.profile-row span,
.source-item span,
.source-item em {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
  line-height: 1.45;
}

.report-options {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

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

.option-head span {
  padding: 4px 8px;
  border-radius: 999px;
  color: #fff;
  background: var(--primary);
  font-size: 12px;
  font-weight: 800;
}

.option-head strong {
  min-width: 0;
  font-size: 15px;
  line-height: 1.35;
}

.report-option p,
.report-option small {
  display: block;
  color: #374151;
  line-height: 1.65;
}

.report-option small {
  margin-top: 8px;
  color: var(--muted);
}

.report-list {
  margin-top: 12px;
  display: grid;
  gap: 6px;
}

.report-list b {
  font-size: 12px;
}

.report-list span {
  padding: 7px 8px;
  border-radius: 8px;
  background: var(--surface-soft);
  color: #374151;
  font-size: 12px;
  line-height: 1.45;
}

.matrix-wrap {
  margin-top: 12px;
  overflow-x: auto;
}

.report-matrix {
  width: 100%;
  min-width: 720px;
  border-collapse: collapse;
  font-size: 13px;
}

.report-matrix th,
.report-matrix td {
  padding: 11px;
  border: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  line-height: 1.55;
}

.report-matrix th {
  background: var(--surface-soft);
}

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

.check-list {
  margin: 12px 0 0;
  padding-left: 22px;
  color: #374151;
  line-height: 1.75;
}

.caveat p {
  margin-top: 8px;
  color: var(--muted);
  line-height: 1.65;
}

.admin-auth {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
}

.admin-overview {
  margin-top: 16px;
  display: grid;
  gap: 14px;
}

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

.admin-stat,
.admin-section,
.admin-row {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
}

.admin-stat {
  padding: 12px;
}

.admin-stat span,
.admin-row span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.admin-stat strong {
  display: block;
  margin-top: 6px;
  font-size: 22px;
  line-height: 1.2;
}

.admin-section {
  padding: 14px;
  display: grid;
  gap: 9px;
}

.admin-section h3 {
  margin: 0 0 2px;
  font-size: 15px;
}

.admin-row {
  padding: 10px;
}

.admin-row strong {
  display: block;
  font-size: 13px;
}

.profile-form,
.auth-form {
  display: grid;
  gap: 12px;
}

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

.profile-form .wide,
.profile-form label:last-of-type,
.profile-form button {
  grid-column: 1 / -1;
}

label span {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.segmented {
  margin-bottom: 16px;
  padding: 4px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  border-radius: 10px;
  background: var(--surface-soft);
}

.segmented button {
  height: 36px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
}

.segmented button.active {
  color: var(--text);
  background: var(--surface);
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.08);
}

.conversation-list,
.compare-list,
.product-list,
.ledger-list,
.pay-grid {
  display: grid;
  gap: 10px;
}

.wallet-card .pay-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.conversation-item,
.compare-item,
.product-item,
.ledger-item,
.pay-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 13px;
  background: var(--surface);
}

.conversation-item {
  width: 100%;
  text-align: left;
}

.compare-item {
  width: 100%;
  text-align: left;
}

.conversation-item:hover {
  border-color: var(--primary);
  background: #f0fdfa;
}

.compare-item:hover {
  border-color: var(--primary);
  background: #f0fdfa;
}

.conversation-item.active {
  border-color: var(--primary);
  background: #ccfbf1;
}

.compare-item.selected {
  border-color: var(--primary);
  background: #ccfbf1;
}

.conversation-item strong,
.compare-item strong,
.product-item strong,
.ledger-item strong,
.pay-card strong {
  display: block;
  font-size: 14px;
  line-height: 1.4;
}

.conversation-item span,
.compare-item span,
.product-item span,
.ledger-item span,
.pay-card span {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.compare-footer {
  margin-top: 14px;
  padding-top: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-top: 1px solid var(--line);
}

.compare-footer span {
  min-width: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.product-item,
.pay-card {
  display: grid;
  grid-template-columns: 1fr;
  align-items: center;
  gap: 12px;
}

.pay-card .button {
  width: 100%;
}

.ledger-item.credit strong {
  color: var(--primary);
}

.ledger-item.debit strong {
  color: var(--danger);
}

.order-box {
  margin-top: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff7ed;
}

.order-box p {
  margin: 8px 0 12px;
  color: var(--muted);
  line-height: 1.6;
}

.empty-small {
  padding: 18px 12px;
  border: 1px dashed var(--line-strong);
  border-radius: 12px;
  color: var(--muted);
  background: var(--surface-soft);
  font-size: 13px;
  text-align: center;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 80;
  max-width: min(520px, calc(100vw - 28px));
  padding: 12px 16px;
  border-radius: 999px;
  color: #fff;
  background: rgba(17, 24, 39, 0.94);
  box-shadow: var(--shadow);
  font-weight: 700;
}

.hidden {
  display: none !important;
}

@media (max-width: 1180px) {
  .topbar {
    padding: 0 14px;
    gap: 12px;
  }

  .brand {
    min-width: 156px;
  }

  .model-field {
    width: 220px;
  }

  .button,
  .icon-button {
    padding: 0 11px;
  }

  .workspace {
    max-width: none;
    grid-template-columns: 232px minmax(0, 1fr);
    gap: 14px;
    padding: 0 14px;
  }

  .conversation-sidebar {
    padding-top: 16px;
  }

  .chat-head {
    min-height: 72px;
  }
}

@media (max-width: 760px) {
  .topbar {
    height: auto;
    min-height: 64px;
    padding: 10px 12px;
    align-items: stretch;
    flex-direction: column;
    gap: 10px;
  }

  .brand {
    min-width: 0;
  }

  .top-actions {
    justify-content: flex-start;
    overflow-x: auto;
    padding-bottom: 2px;
  }

  .model-field {
    width: 230px;
    flex: 0 0 230px;
  }

  .workspace {
    padding: 0 12px;
    display: flex;
    justify-content: center;
  }

  .conversation-sidebar {
    display: none;
  }

  .conversation-toggle {
    display: inline-flex;
  }

  .wallet-card .pay-grid {
    grid-template-columns: 1fr;
  }

  .profile-grid,
  .report-options,
  .source-grid,
  .admin-grid {
    grid-template-columns: 1fr 1fr;
  }

  .chat-head {
    min-height: 66px;
    padding-top: 12px;
  }

  .chat-actions {
    gap: 6px;
  }

  h1 {
    font-size: 21px;
  }

  .message {
    max-width: 88%;
  }
}

@media (max-width: 620px) {
  .brand span,
  .chat-head p,
  .credit-pill span {
    display: none;
  }

  .credit-pill {
    min-width: 54px;
    justify-content: center;
  }

  .chat-head {
    align-items: flex-start;
    gap: 10px;
  }

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

  .chat-actions .button {
    min-height: 34px;
    padding: 0 10px;
  }

  .message {
    max-width: 94%;
  }

  .composer-wrap {
    padding-bottom: 10px;
  }

  .composer {
    grid-template-columns: 1fr;
  }

  .composer .button {
    width: 100%;
  }

  .profile-form {
    grid-template-columns: 1fr;
  }

  .profile-grid,
  .report-options,
  .source-grid,
  .admin-grid {
    grid-template-columns: 1fr;
  }

  .admin-auth {
    grid-template-columns: 1fr;
  }

  .compare-footer {
    align-items: stretch;
    flex-direction: column;
  }

  .compare-footer .button {
    width: 100%;
  }

  .modal {
    align-items: end;
    padding: 10px;
  }

  .modal-card,
  .sheet-card {
    max-height: min(86dvh, 760px);
    border-radius: 16px;
  }
}

@media print {
  body {
    overflow: visible;
    background: #fff;
  }

  .app-shell,
  .modal:not(#reportModal),
  #toast,
  #reportModal .modal-head {
    display: none !important;
  }

  #reportModal {
    position: static;
    display: block !important;
    padding: 0;
    background: #fff;
    backdrop-filter: none;
  }

  #reportModal .sheet-card {
    width: 100%;
    max-height: none;
    overflow: visible;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .report-options,
  .profile-grid,
  .source-grid {
    grid-template-columns: 1fr;
  }
}
