:root {
  color-scheme: light;
  --bg: #f4f6f3;
  --panel: #ffffff;
  --ink: #17201c;
  --muted: #66736c;
  --line: #dce3dd;
  --customer: #0f7b6c;
  --agent: #3658a8;
  --self: #132a2f;
  --other: #ffffff;
  --other-border: #d8e0db;
  --focus: #c37c2b;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
  line-height: 1.5;
}

button,
input,
textarea {
  font: inherit;
}

.chat-shell {
  display: grid;
  grid-template-columns: minmax(240px, 320px) minmax(0, 1fr);
  gap: 16px;
  width: min(1180px, calc(100vw - 32px));
  height: min(860px, calc(100vh - 32px));
  min-height: 560px;
  margin: 16px auto;
}

.customer-chat-shell {
  grid-template-columns: minmax(220px, 280px) minmax(0, 1fr);
  width: min(920px, calc(100vw - 32px));
}

.profile-panel,
.chat-panel {
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: 0 18px 48px rgba(23, 32, 28, 0.08);
}

.profile-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 24px;
  border-radius: 8px;
  min-height: 0;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 13px;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(28px, 3vw, 42px);
  line-height: 1.12;
}

h2 {
  font-size: 22px;
}

.status-card {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8faf8;
}

.status-card strong,
.status-card span {
  display: block;
}

.status-card span:last-child {
  margin-top: 2px;
  color: var(--muted);
  font-size: 14px;
}

.status-dot {
  width: 10px;
  height: 10px;
  margin-top: 7px;
  border-radius: 50%;
  flex: 0 0 auto;
}

.status-dot.is-connected {
  background: #2c9f59;
  box-shadow: 0 0 0 4px rgba(44, 159, 89, 0.14);
}

.status-dot.is-connecting {
  background: #c37c2b;
  box-shadow: 0 0 0 4px rgba(195, 124, 43, 0.16);
}

.status-dot.is-error {
  background: #c83f3f;
  box-shadow: 0 0 0 4px rgba(200, 63, 63, 0.14);
}

.name-field {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
}

.name-field input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 11px 12px;
  color: var(--ink);
  background: #fff;
  outline: none;
}

.name-field input[readonly] {
  color: var(--muted);
  background: #f8faf8;
}

.name-field input:focus,
.composer textarea:focus {
  border-color: var(--focus);
  box-shadow: 0 0 0 3px rgba(195, 124, 43, 0.16);
}

.session-info {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
}

.session-info div {
  min-width: 0;
}

.session-info dt {
  color: var(--muted);
  font-size: 12px;
}

.session-info dd {
  margin: 2px 0 0;
  color: var(--ink);
  font-weight: 700;
  word-break: break-word;
}

.conversation-panel {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  min-height: 180px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
}

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

.conversation-panel-header h2 {
  font-size: 16px;
}

.conversation-panel-header span {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 12px;
}

.conversation-empty {
  margin: 0;
  padding: 14px 12px;
  color: var(--muted);
  font-size: 14px;
}

.conversation-empty[hidden] {
  display: none;
}

.conversation-list {
  min-height: 0;
  margin: 0;
  padding: 8px;
  overflow-y: auto;
  list-style: none;
}

.conversation-list li + li {
  margin-top: 6px;
}

.conversation-item {
  display: grid;
  gap: 4px;
  width: 100%;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 10px;
  color: var(--ink);
  background: transparent;
  cursor: pointer;
  text-align: left;
}

.conversation-item:hover,
.conversation-item[aria-pressed="true"] {
  border-color: var(--line);
  background: #f2f6f3;
}

.conversation-item[aria-pressed="true"] {
  box-shadow: inset 3px 0 0 var(--customer);
}

.conversation-item-header,
.conversation-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.conversation-item-header strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-item-header time,
.conversation-footer,
.conversation-user-id {
  color: var(--muted);
  font-size: 12px;
}

.conversation-item-header time {
  flex: 0 0 auto;
}

.conversation-user-id,
.conversation-preview {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-preview {
  color: var(--ink);
  font-size: 13px;
}

.chat-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-width: 0;
  overflow: hidden;
  border-radius: 8px;
}

.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
}

.message-count {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 14px;
}

.message-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  margin: 0;
  padding: 20px 22px;
  overflow-y: auto;
  list-style: none;
  background: #f7f9f7;
}

.message {
  display: grid;
  max-width: min(74%, 680px);
}

.message.is-self {
  align-self: flex-end;
  justify-items: end;
}

.message.is-other {
  align-self: flex-start;
  justify-items: start;
}

.system-message {
  align-self: center;
  max-width: min(520px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--muted);
  background: #fff;
  text-align: center;
}

.bubble {
  min-width: 0;
  border-radius: 8px;
  padding: 10px 12px;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.is-self .bubble {
  color: #fff;
  background: var(--self);
}

.is-other .bubble {
  border: 1px solid var(--other-border);
  color: var(--ink);
  background: var(--other);
}

.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 12px;
}

.role-tag {
  font-weight: 700;
}

.role-tag.is-customer {
  color: var(--customer);
}

.role-tag.is-agent {
  color: var(--agent);
}

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  padding: 16px 22px;
  border-top: 1px solid var(--line);
  background: var(--panel);
}

.composer textarea {
  min-height: 48px;
  max-height: 160px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 11px 12px;
  color: var(--ink);
  outline: none;
}

.composer textarea:disabled {
  cursor: not-allowed;
  background: #f0f3f0;
}

.composer button {
  align-self: end;
  min-width: 88px;
  height: 48px;
  border: 0;
  border-radius: 6px;
  color: #fff;
  background: var(--self);
  cursor: pointer;
  font-weight: 700;
}

.composer button:disabled {
  cursor: wait;
  opacity: 0.66;
}

@media (max-width: 760px) {
  .chat-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
    width: 100vw;
    height: 100vh;
    min-height: 0;
    margin: 0;
    gap: 0;
  }

  .customer-chat-shell {
    grid-template-rows: minmax(0, 1fr);
  }

  .profile-panel {
    border-radius: 0;
    box-shadow: none;
    padding: 16px;
    gap: 12px;
    max-height: 46vh;
    overflow-y: auto;
  }

  .profile-panel h1 {
    font-size: 26px;
  }

  .status-card {
    display: none;
  }

  .conversation-panel {
    min-height: 150px;
  }

  .chat-panel {
    border-radius: 0;
    border-left: 0;
    border-right: 0;
    box-shadow: none;
  }

  .chat-header,
  .message-list,
  .composer {
    padding-left: 14px;
    padding-right: 14px;
  }

  .message {
    max-width: 86%;
  }

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

  .composer button {
    width: 100%;
  }
}
