:root {
  --bg: #f4f1ea;
  --panel: #fffdf8;
  --ink: #1e2523;
  --muted: #65716d;
  --line: #d8d0c2;
  --line-strong: #b9ae9d;
  --green: #176f55;
  --green-dark: #0f4c3a;
  --rust: #b3532a;
  --gold: #c79a35;
  --blue: #315f8f;
  --soft-green: #e5f1ea;
  --soft-rust: #f3e4da;
  --soft-blue: #e3edf6;
  --shadow: 0 12px 32px rgba(38, 33, 24, 0.09);
  font-family: "Iowan Old Style", "Songti SC", "Noto Serif CJK SC", Georgia, serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 1120px;
  background:
    linear-gradient(180deg, rgba(255, 253, 248, 0.76), rgba(244, 241, 234, 0.96)),
    var(--bg);
  color: var(--ink);
}

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

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

.app-shell {
  min-height: 100vh;
  padding: 18px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 14px 18px 18px;
  border: 1px solid var(--line);
  background: rgba(255, 253, 248, 0.9);
  box-shadow: var(--shadow);
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  color: #fffdf8;
  background: var(--green-dark);
  border-radius: 8px;
  font-weight: 800;
}

h1,
h2,
p {
  margin: 0;
}

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

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

p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.topbar-actions,
.quick-row,
.form-grid,
.market-columns,
.summary-grid,
.message-form {
  display: flex;
  gap: 10px;
}

.workspace {
  display: grid;
  grid-template-columns: 340px minmax(500px, 1fr) 430px;
  gap: 14px;
  margin-top: 14px;
  align-items: start;
}

.panel {
  min-height: calc(100vh - 112px);
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.panel-header {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  width: 126px;
  padding: 3px;
  border: 1px solid var(--line);
  background: #f7f3ea;
  border-radius: 8px;
}

.segment {
  height: 30px;
  border: 0;
  color: var(--muted);
  background: transparent;
  border-radius: 6px;
  cursor: pointer;
}

.segment.active {
  color: #fffdf8;
  background: var(--green);
}

.entry-form {
  display: none;
  padding: 16px;
}

.smart-intake {
  display: grid;
  gap: 10px;
  padding: 14px 16px 16px;
  border-bottom: 1px solid var(--line);
  background: #faf6ee;
}

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

.file-button {
  width: auto;
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line-strong);
  background: #fffaf0;
  color: var(--ink);
  border-radius: 6px;
  padding: 0 12px;
  cursor: pointer;
}

.file-button input {
  display: none;
}

.intake-status {
  min-height: 18px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.file-list {
  display: grid;
  gap: 6px;
}

.file-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border: 1px solid var(--line);
  background: #fffaf0;
  color: #38423f;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12px;
  line-height: 1.35;
}

.file-chip span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.parsed-results {
  display: grid;
  gap: 8px;
}

.parsed-card {
  border: 1px solid var(--line);
  background: #fffdf8;
  border-radius: 8px;
  padding: 10px;
}

.parsed-card.supply {
  border-left: 4px solid var(--green);
}

.parsed-card.request {
  border-left: 4px solid var(--blue);
}

.parsed-card.process,
.parsed-card.config {
  border-left: 4px solid var(--rust);
}

.parsed-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 8px;
}

.parsed-type {
  flex: 0 0 auto;
  color: #fffdf8;
  background: var(--green);
  border-radius: 999px;
  padding: 4px 7px;
  font-size: 11px;
}

.parsed-type.request {
  background: var(--blue);
}

.parsed-type.process,
.parsed-type.config {
  background: var(--rust);
}

.parsed-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
}

.parsed-field {
  min-width: 0;
  overflow-wrap: anywhere;
}

.parsed-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.entry-form.active {
  display: grid;
  gap: 12px;
}

label {
  display: grid;
  gap: 6px;
  color: #38423f;
  font-size: 13px;
  line-height: 1.2;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line-strong);
  background: #fffaf0;
  color: var(--ink);
  border-radius: 6px;
  padding: 9px 10px;
  outline: none;
}

textarea {
  resize: vertical;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(23, 111, 85, 0.13);
}

.form-grid {
  align-items: end;
}

.form-grid > label {
  flex: 1;
  min-width: 0;
}

.primary-button,
.ghost-button,
.text-button {
  min-height: 36px;
  border-radius: 6px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
}

.primary-button {
  border: 1px solid var(--green-dark);
  background: var(--green);
  color: #fffdf8;
  padding: 0 14px;
}

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

.ghost-button {
  border: 1px solid var(--line-strong);
  background: #fffaf0;
  color: var(--ink);
  padding: 0 14px;
}

.text-button {
  min-height: 30px;
  border: 0;
  background: transparent;
  color: var(--blue);
  padding: 0;
}

.full {
  width: 100%;
}

.status-pill {
  flex: 0 0 auto;
  color: var(--green-dark);
  background: var(--soft-green);
  border: 1px solid rgba(23, 111, 85, 0.22);
  padding: 7px 9px;
  border-radius: 999px;
  font-size: 12px;
}

.summary-grid {
  padding: 14px 16px 4px;
}

.inventory-visual {
  margin: 10px 16px 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #fffaf0;
}

.inventory-visual img {
  display: block;
  width: 100%;
  height: 138px;
  object-fit: cover;
}

.metric {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--line);
  background: #fffaf0;
  padding: 12px;
  border-radius: 8px;
}

.metric-value {
  font-size: 22px;
  font-weight: 800;
}

.metric-label {
  color: var(--muted);
  font-size: 12px;
}

.market-columns {
  padding: 10px 16px 0;
}

.market-columns > div {
  width: 50%;
  min-width: 0;
}

.section-title {
  color: #38423f;
  font-size: 13px;
  font-weight: 800;
  margin: 6px 0 10px;
}

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

.item-card {
  border: 1px solid var(--line);
  background: #fffaf0;
  border-radius: 8px;
  padding: 12px;
}

.item-title {
  font-size: 15px;
  line-height: 1.35;
  font-weight: 800;
}

.item-meta,
.item-note {
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.tag {
  color: #3d4845;
  border: 1px solid var(--line);
  background: rgba(255, 253, 248, 0.7);
  border-radius: 999px;
  padding: 4px 7px;
  font-size: 12px;
}

.matches-area {
  padding: 12px 16px 16px;
}

.match-card {
  border-left: 4px solid var(--green);
}

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

.score {
  color: #fffdf8;
  background: var(--green);
  border-radius: 999px;
  padding: 5px 8px;
  font-size: 12px;
  font-weight: 800;
}

.reasons {
  margin: 8px 0 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
}

.conversation-layout {
  display: grid;
  grid-template-rows: 170px 1fr;
  min-height: calc(100vh - 185px);
}

.conversation-list {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.conversation-tab {
  flex: 0 0 210px;
  border: 1px solid var(--line);
  background: #fffaf0;
  color: var(--ink);
  border-radius: 8px;
  padding: 10px;
  text-align: left;
  cursor: pointer;
}

.conversation-tab.active {
  border-color: var(--green);
  background: var(--soft-green);
}

.chat-window {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 420px;
}

.chat-title {
  min-height: 48px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
  font-weight: 800;
}

.messages {
  display: grid;
  align-content: start;
  gap: 10px;
  overflow-y: auto;
  padding: 16px;
  background: #f8f4ec;
}

.message {
  max-width: 88%;
  border: 1px solid var(--line);
  background: #fffdf8;
  border-radius: 8px;
  padding: 10px;
}

.message.buyer {
  justify-self: end;
  background: var(--soft-blue);
  border-color: rgba(49, 95, 143, 0.24);
}

.message.seller {
  justify-self: start;
  background: var(--soft-green);
  border-color: rgba(23, 111, 85, 0.22);
}

.message.system {
  justify-self: center;
  max-width: 100%;
  background: var(--soft-rust);
  border-color: rgba(179, 83, 42, 0.24);
}

.message-sender {
  font-size: 12px;
  font-weight: 800;
  margin-bottom: 5px;
}

.message-body {
  font-size: 13px;
  line-height: 1.45;
}

.message-time {
  color: var(--muted);
  font-size: 11px;
  margin-top: 6px;
}

.message-form {
  align-items: end;
  padding: 12px;
  border-top: 1px solid var(--line);
  background: #fffdf8;
}

.message-form select {
  width: 96px;
}

.message-form textarea {
  min-height: 54px;
}

.empty {
  color: var(--muted);
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  padding: 16px;
  font-size: 13px;
  line-height: 1.45;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  min-width: 240px;
  max-width: 420px;
  padding: 12px 14px;
  color: #fffdf8;
  background: #1e2523;
  border-radius: 8px;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 1180px) {
  body {
    min-width: 0;
  }

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

  .panel {
    min-height: auto;
  }

  .conversation-layout {
    min-height: 620px;
  }

  .inventory-visual img {
    height: auto;
  }
}
