:root {
  color-scheme: light;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Microsoft YaHei", sans-serif;
  --bg: #f6f7f3;
  --surface: #ffffff;
  --text: #22231f;
  --muted: #6f726b;
  --line: #dfe3d8;
  --primary: #1e7a5a;
  --primary-dark: #155c43;
  --accent: #b7502a;
  --soft: #eef5e9;
  --warn: #f4c15d;
  --danger: #b63d3d;
  --shadow: 0 20px 60px rgb(31 36 25 / 10%);
}

* {
  box-sizing: border-box;
}

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

.chat-page {
  background:
    linear-gradient(180deg, #edf4ef 0%, #f7f8f4 44%, #eef1e9 100%);
}

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

button {
  border: 0;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.65;
}

a {
  color: inherit;
}

.shell {
  width: min(1180px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 28px 0 48px;
}

.chat-shell {
  width: min(980px, calc(100vw - 24px));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 24px;
}

.chat-topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 16px;
}

.brand-block h1 {
  margin-top: 2px;
}

.chat-subtitle {
  margin: 10px 0 0;
  color: var(--muted);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(2rem, 5vw, 3.8rem);
  line-height: 1;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 6px;
  font-size: 1.35rem;
  letter-spacing: 0;
}

.workspace {
  display: grid;
  gap: 18px;
}

.chat-card {
  display: grid;
  gap: 14px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.customer-grid {
  grid-template-columns: minmax(0, 1.25fr) minmax(320px, 0.75fr);
  align-items: start;
}

.panel,
.thread-panel,
.ticket-list-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.chat-toolbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: end;
}

.chat-identity {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
}

.chat-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.chat-thread {
  display: grid;
  gap: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.chat-thread-head {
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.chat-messages {
  max-height: 62vh;
  background: linear-gradient(180deg, #f9fbf8 0%, #f6f7f3 100%);
}

.chat-composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: end;
}

.composer-label,
.composer-input {
  gap: 6px;
}

.composer-subject {
  display: none;
}

.composer-input span {
  display: block;
  color: #3d4039;
  font-size: 0.92rem;
  font-weight: 700;
}

.composer-send {
  min-width: 110px;
}

.message {
  max-width: min(78%, 680px);
  padding: 0;
  border: 0;
  background: transparent;
}

.message-bubble {
  display: grid;
  gap: 8px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.message.agent .message-bubble {
  border-color: #bdd9cd;
  background: #f2faf6;
}

.message.customer {
  justify-self: end;
}

.message.customer .message-bubble {
  background: #1e7a5a;
  border-color: #1e7a5a;
  color: #fff;
}

.message.customer .message-meta {
  color: rgb(255 255 255 / 75%);
}

.message.customer .message-body {
  color: #fff;
}

.message.customer .message-bubble {
  box-shadow: 0 12px 28px rgb(30 122 90 / 18%);
}

.panel {
  padding: 24px;
}

.panel-head p,
.thread-head p,
.status-line {
  margin-bottom: 0;
  color: var(--muted);
}

.form-stack {
  display: grid;
  gap: 14px;
  margin-top: 20px;
}

label {
  display: grid;
  gap: 7px;
  color: #3d4039;
  font-size: 0.92rem;
  font-weight: 700;
}

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

input,
select {
  min-height: 44px;
  padding: 0 12px;
}

textarea {
  resize: vertical;
  min-height: 112px;
  padding: 12px;
  line-height: 1.55;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgb(30 122 90 / 14%);
}

.primary,
.secondary,
.ghost,
.link-button {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 6px;
  padding: 0 16px;
  font-weight: 800;
  text-decoration: none;
  white-space: nowrap;
}

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

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

.secondary,
.link-button {
  background: #262821;
  color: #fff;
}

.ghost {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
}

.last-ticket {
  margin-top: 18px;
  padding: 14px;
  border: 1px dashed #bdc7b4;
  border-radius: 8px;
  background: var(--soft);
  color: #394136;
}

.last-ticket button {
  margin-top: 10px;
}

.thread-panel {
  margin-top: 18px;
  overflow: hidden;
}

.thread-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 22px 24px;
  border-bottom: 1px solid var(--line);
}

.status-line {
  margin-bottom: 6px;
  font-size: 0.85rem;
  font-weight: 800;
}

.messages {
  display: grid;
  gap: 12px;
  max-height: 56vh;
  overflow: auto;
  padding: 20px 24px;
  background: #fbfcf8;
}

.message {
  display: grid;
  gap: 6px;
  max-width: min(720px, 92%);
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.message.agent {
  justify-self: end;
  border-color: #bdd9cd;
  background: #f2faf6;
  color: var(--text);
}

.message.customer {
  justify-self: start;
  color: var(--text);
}

.admin-workspace .message.agent,
.admin-workspace .message.customer,
.admin-workspace .message.agent .message-body,
.admin-workspace .message.customer .message-body,
.admin-workspace .message.agent .message-meta,
.admin-workspace .message.customer .message-meta {
  color: var(--text);
}

.admin-workspace .message-meta {
  color: var(--muted);
}

.message-meta {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.message-body {
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.6;
}

.message-bubble .message-body {
  white-space: pre-wrap;
}

.reply-box {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  padding: 18px 24px 22px;
  border-top: 1px solid var(--line);
}

.reply-box textarea {
  min-height: 86px;
}

.reply-box button {
  align-self: end;
  min-width: 104px;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 20;
  max-width: min(420px, calc(100vw - 40px));
  border-radius: 8px;
  background: #22231f;
  color: #fff;
  padding: 12px 14px;
  box-shadow: var(--shadow);
  line-height: 1.45;
}

.hidden {
  display: none !important;
}

.support-shell {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.support-chat {
  display: grid;
  grid-template-rows: auto minmax(320px, 1fr) auto;
  width: min(820px, 100%);
  height: min(760px, calc(100vh - 48px));
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.support-header {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.agent-avatar {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-weight: 900;
}

.support-header h1 {
  margin: 0 0 4px;
  font-size: 1.28rem;
  line-height: 1.2;
}

.support-header p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.icon-text-button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 0 12px;
  font-weight: 800;
}

.support-messages {
  display: grid;
  align-content: start;
  gap: 12px;
  overflow: auto;
  padding: 22px 20px;
  background: #f7f8f4;
}

.welcome-card {
  display: grid;
  gap: 6px;
  justify-self: center;
  max-width: 360px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  text-align: center;
}

.welcome-card strong {
  color: var(--text);
}

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

.support-message.customer {
  justify-self: end;
}

.support-message.agent {
  justify-self: start;
}

.support-bubble {
  display: grid;
  gap: 8px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.support-message.customer .support-bubble {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
  box-shadow: 0 12px 28px rgb(30 122 90 / 18%);
}

.support-body {
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.55;
}

.support-meta {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
}

.support-message.customer .support-meta {
  color: rgb(255 255 255 / 74%);
}

.support-composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: end;
  padding: 14px;
  border-top: 1px solid var(--line);
  background: #fff;
}

.support-composer textarea {
  min-height: 52px;
  max-height: 150px;
  resize: vertical;
  border-radius: 8px;
}

.send-button {
  min-width: 92px;
  min-height: 52px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgb(34 35 31 / 42%);
}

.email-modal {
  display: grid;
  gap: 18px;
  width: min(420px, 100%);
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.email-modal h2 {
  margin-bottom: 8px;
}

.email-modal p:not(.eyebrow) {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.55;
}

.admin-shell {
  width: min(1380px, calc(100vw - 32px));
}

.login-panel {
  width: min(520px, 100%);
}

.admin-workspace {
  display: grid;
  grid-template-columns: 420px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.ticket-list-panel {
  overflow: hidden;
}

.list-toolbar {
  display: grid;
  grid-template-columns: 120px 1fr auto auto;
  gap: 8px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.ticket-list {
  display: grid;
  max-height: calc(100vh - 190px);
  overflow: auto;
}

.ticket-item {
  display: grid;
  gap: 7px;
  width: 100%;
  border-bottom: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  padding: 14px;
  text-align: left;
}

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

.ticket-title-line,
.ticket-meta-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.ticket-title-line strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ticket-meta-line,
.ticket-preview {
  color: var(--muted);
  font-size: 0.84rem;
}

.ticket-preview {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.badge {
  display: inline-flex;
  min-width: 64px;
  justify-content: center;
  border-radius: 999px;
  padding: 3px 9px;
  color: #1f241d;
  font-size: 0.76rem;
  font-weight: 800;
}

.badge.open {
  background: var(--warn);
}

.badge.waiting {
  background: #bfe0cf;
}

.badge.closed {
  background: #d9dbd3;
}

.admin-thread-empty {
  min-height: 430px;
}

.empty-state {
  display: grid;
  min-height: 430px;
  place-items: center;
  color: var(--muted);
  font-weight: 800;
}

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

.admin-actions select {
  width: 130px;
}

@media (max-width: 880px) {
  .customer-grid,
  .admin-workspace {
    grid-template-columns: 1fr;
  }

  .chat-topbar,
  .chat-toolbar,
  .chat-composer {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .chat-identity {
    grid-template-columns: 1fr;
  }

  .topbar,
  .thread-head,
  .reply-box {
    align-items: stretch;
    flex-direction: column;
  }

  .reply-box {
    grid-template-columns: 1fr;
  }

  .list-toolbar {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 560px) {
  .shell,
  .admin-shell {
    width: min(100% - 20px, 1380px);
    padding-top: 18px;
  }

  .topbar {
    display: grid;
  }

  .panel,
  .thread-head,
  .messages,
  .reply-box {
    padding-left: 16px;
    padding-right: 16px;
  }

  .chat-card {
    padding: 14px;
  }

  .message {
    max-width: 100%;
  }

  .list-toolbar {
    grid-template-columns: 1fr;
  }
}
