:root {
  --bg: #f3f6fa;
  --surface: #ffffff;
  --line: #dbe3ee;
  --ink: #172033;
  --muted: #64748b;
  --blue: #2563eb;
  --blue-soft: #eaf1ff;
  --green: #137a4b;
  --green-soft: #e9f8f0;
  --amber: #9a5b00;
  --amber-soft: #fff5d9;
  --red: #b42318;
  --red-soft: #fff0ee;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", sans-serif;
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  font: inherit;
  letter-spacing: 0;
}

button,
.button {
  cursor: pointer;
}

.topbar {
  display: flex;
  min-height: 76px;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  padding: 14px 24px;
}

.brand,
.top-actions,
.pane-head,
.chat-head,
.section-head,
.assign-row {
  display: flex;
  align-items: center;
}

.brand {
  gap: 12px;
}

.brand h1,
.pane-head h2,
.chat-head h2,
.detail-section h2 {
  margin: 0;
}

.brand h1 {
  font-size: 20px;
}

.brand p,
.pane-head span,
.chat-head span {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.back-link {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 7px;
  background: var(--blue);
  color: #fff;
  font-size: 20px;
  font-weight: 800;
  text-decoration: none;
}

.top-actions {
  gap: 10px;
}

.button {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 0 14px;
  font-weight: 700;
  text-decoration: none;
}

.button:disabled,
.text-button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

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

.secondary {
  border-color: var(--line);
  background: #fff;
  color: var(--ink);
}

.text-button {
  border: 0;
  background: transparent;
  color: var(--red);
  font-weight: 700;
}

.summary-strip {
  display: grid;
  grid-template-columns: repeat(5, minmax(120px, 1fr));
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  padding: 0 24px;
}

.summary-strip > div {
  display: flex;
  min-height: 72px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-right: 1px solid var(--line);
  padding: 0 22px;
}

.summary-strip > div:first-child {
  padding-left: 0;
}

.summary-strip > div:last-child {
  border-right: 0;
}

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

.summary-strip strong {
  font-size: 24px;
}

.summary-strip .off,
.integration-checks .off {
  color: var(--red);
  font-size: 14px;
}

.workspace {
  display: grid;
  min-height: calc(100vh - 149px);
  grid-template-columns: minmax(250px, 310px) minmax(420px, 1fr) minmax(300px, 360px);
}

.session-pane,
.chat-pane,
.detail-pane {
  min-width: 0;
  background: var(--surface);
}

.session-pane,
.chat-pane {
  border-right: 1px solid var(--line);
}

.pane-head,
.chat-head {
  min-height: 66px;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  padding: 14px 18px;
}

.pane-head h2,
.chat-head h2,
.detail-section h2 {
  font-size: 16px;
}

.new-session-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  border-bottom: 1px solid var(--line);
  padding: 12px;
}

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

input,
select {
  min-height: 40px;
  padding: 0 11px;
}

textarea {
  min-height: 52px;
  resize: vertical;
  padding: 9px 11px;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.session-list {
  overflow-y: auto;
  max-height: calc(100vh - 267px);
}

.session-item {
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: #fff;
  padding: 14px 16px;
  text-align: left;
}

.session-item:hover,
.session-item.active {
  background: var(--blue-soft);
}

.session-item.active {
  box-shadow: inset 3px 0 0 var(--blue);
}

.session-item-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.session-item strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session-item p {
  display: -webkit-box;
  overflow: hidden;
  margin: 8px 0;
  color: #334155;
  font-size: 13px;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.session-item small {
  color: var(--muted);
}

.status-badge {
  display: inline-flex;
  min-height: 28px;
  align-items: center;
  border-radius: 5px;
  padding: 0 9px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.status-badge.neutral {
  background: #eef2f7;
  color: #536174;
}

.status-badge.active {
  background: var(--green-soft);
  color: var(--green);
}

.status-badge.pending {
  background: var(--amber-soft);
  color: var(--amber);
}

.status-badge.assigned {
  background: var(--blue-soft);
  color: var(--blue);
}

.status-badge.closed {
  background: #eef2f7;
  color: #64748b;
}

.chat-pane {
  display: grid;
  grid-template-rows: auto minmax(320px, 1fr) auto;
}

.message-list {
  overflow-y: auto;
  padding: 22px;
}

.message-row {
  display: flex;
  margin-bottom: 18px;
}

.message-row.customer {
  justify-content: flex-end;
}

.message-bubble {
  width: fit-content;
  max-width: min(78%, 680px);
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  padding: 10px 12px;
}

.message-row.customer .message-bubble {
  border-color: #c8d8ff;
  background: var(--blue-soft);
}

.message-bubble header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 11px;
}

.message-bubble p {
  margin: 0;
  line-height: 1.65;
  white-space: pre-wrap;
}

.composer {
  display: grid;
  grid-template-columns: 110px minmax(0, 1fr) auto;
  align-items: end;
  gap: 10px;
  border-top: 1px solid var(--line);
  padding: 14px 16px;
}

.detail-pane {
  overflow-y: auto;
  max-height: calc(100vh - 149px);
}

.detail-section {
  border-bottom: 1px solid var(--line);
  padding: 18px;
}

.section-head {
  justify-content: space-between;
}

.fact-list {
  margin: 16px 0 0;
}

.fact-list > div {
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr);
  gap: 12px;
  border-top: 1px solid #edf1f6;
  padding: 11px 0;
}

.fact-list dt {
  color: var(--muted);
  font-size: 13px;
}

.fact-list dd {
  margin: 0;
  line-height: 1.55;
}

.handoff-summary {
  min-height: 72px;
  margin: 14px 0;
  border-left: 3px solid var(--blue);
  background: var(--blue-soft);
  padding: 10px 12px;
  color: #26354e;
  line-height: 1.6;
}

.assign-row {
  gap: 8px;
}

.integration-checks {
  display: grid;
  gap: 12px;
}

.check-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

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

.check-row strong {
  color: var(--amber);
  font-size: 13px;
}

.check-row strong.ready {
  color: var(--green);
}

.empty-state {
  display: grid;
  min-height: 260px;
  place-items: center;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 1100px) {
  .workspace {
    grid-template-columns: 260px minmax(400px, 1fr);
  }

  .detail-pane {
    grid-column: 1 / -1;
    display: grid;
    max-height: none;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    border-top: 1px solid var(--line);
  }

  .detail-section {
    border-right: 1px solid var(--line);
  }
}

@media (max-width: 760px) {
  .topbar,
  .top-actions {
    align-items: flex-start;
  }

  .topbar {
    flex-direction: column;
  }

  .summary-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    padding: 0 12px;
  }

  .summary-strip > div {
    min-height: 58px;
    padding: 0 10px;
  }

  .workspace,
  .detail-pane {
    display: block;
  }

  .session-list,
  .detail-pane {
    max-height: none;
  }

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

  .chat-pane {
    min-height: 640px;
  }
}
