:root {
  color-scheme: light;
  --bg: #f6f7f4;
  --ink: #17201c;
  --muted: #62706a;
  --line: #dfe5df;
  --panel: #ffffff;
  --primary: #0f766e;
  --primary-dark: #115e59;
  --accent: #d97706;
  --soft: #eef7f4;
  --shadow: 0 18px 40px rgba(22, 36, 32, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--bg);
  font-family: Arial, "Microsoft YaHei", sans-serif;
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  border-radius: 6px;
  color: #fff;
  background: var(--primary);
  cursor: pointer;
  font-weight: 700;
  min-height: 40px;
  padding: 0 16px;
}

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

input {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 14px;
  outline: none;
}

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

.customer-page {
  display: grid;
  place-items: center;
  padding: 24px;
}

.chat-shell {
  display: grid;
  grid-template-columns: minmax(260px, 0.8fr) minmax(320px, 1fr);
  width: min(960px, 100%);
  min-height: 620px;
  max-height: 88vh;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.brand-panel {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 34px;
  background: #153f3b;
  color: #fff;
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: 32px;
  line-height: 1.12;
}

.lead {
  color: rgba(255, 255, 255, 0.78);
  font-size: 15px;
  line-height: 1.7;
}

.status-card {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  gap: 10px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 8px;
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.08);
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #22c55e;
}

.chat-panel {
  display: grid;
  grid-template-rows: auto auto 1fr auto auto;
  min-height: 0;
  background: var(--panel);
}

.desk {
  position: relative;
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  min-height: 0;
  background: var(--panel);
}

.login-overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(246, 247, 244, 0.94);
}

.login-overlay[hidden] {
  display: none;
}

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

.login-box h2 {
  margin: 0;
  font-size: 22px;
}

.login-box span {
  min-height: 18px;
  color: #b91c1c;
  font-size: 13px;
}

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

.chat-panel > .panel-header,
.desk > .panel-header {
  grid-row: 1;
}

.start-box {
  grid-row: 2;
}

.chat-panel > .messages {
  grid-row: 3;
}

.chat-panel > .emoji-panel {
  grid-row: 4;
}

.chat-panel > .composer {
  grid-row: 5;
}

.desk > .messages {
  grid-row: 2;
}

.desk > .emoji-panel {
  grid-row: 3;
}

.desk > .composer {
  grid-row: 4;
}

.panel-header div {
  display: grid;
  gap: 4px;
}

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

.start-box {
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}

.start-box label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.start-row,
.composer {
  display: grid;
  gap: 10px;
}

.start-row {
  grid-template-columns: 1fr auto;
}

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

.messages {
  min-height: 0;
  overflow: auto;
  padding: 18px;
  background: #fbfcfa;
}

.message {
  display: grid;
  gap: 6px;
  max-width: 78%;
  margin-bottom: 14px;
}

.message.agent {
  margin-left: auto;
  justify-items: end;
}

.message strong {
  color: var(--muted);
  font-size: 12px;
}

.read-status {
  color: var(--muted);
  font-size: 12px;
}

.bubble {
  border-radius: 8px;
  padding: 11px 13px;
  line-height: 1.55;
  overflow-wrap: anywhere;
  background: #e8eee9;
}

.bubble p {
  margin: 0;
}

.message-image {
  display: block;
  width: min(260px, 100%);
  max-height: 220px;
  margin-top: 8px;
  border-radius: 6px;
  object-fit: cover;
}

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

.customer-page .message.agent {
  margin-left: 0;
  justify-items: start;
}

.customer-page .message.agent .bubble {
  color: var(--ink);
  background: #e8eee9;
}

.customer-page .message.customer {
  margin-left: auto;
  justify-items: end;
}

.customer-page .message.customer .bubble {
  color: #fff;
  background: var(--primary);
}

.composer {
  padding: 8px 12px;
  border-top: 1px solid var(--line);
  background: var(--panel);
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 40px;
  min-width: 40px;
  padding: 0;
  color: var(--ink);
  background: #eef2ee;
}

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

.file-button {
  min-height: 40px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 800;
}

.emoji-panel {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 12px;
  border-top: 1px solid var(--line);
  background: #fff;
}

.emoji-panel[hidden] {
  display: none;
}

.emoji-panel button {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  min-height: 34px;
  padding: 0;
  color: var(--ink);
  background: #f4f6f3;
}

.emoji-panel button:hover {
  background: #e4ece8;
}

.admin-page {
  display: grid;
  place-items: center;
  padding: 18px;
}

.admin-layout {
  display: grid;
  grid-template-columns: 280px minmax(360px, 1fr);
  width: min(980px, 100%);
  height: min(720px, calc(100vh - 36px));
  margin: 0 auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.sidebar {
  min-height: 0;
  border-right: 1px solid var(--line);
  background: #f9faf7;
}

.sidebar-header {
  padding: 22px;
  border-bottom: 1px solid var(--line);
}

.sidebar h1 {
  font-size: 24px;
}

.conversation-list {
  overflow: auto;
  height: calc(100% - 91px);
}

.conversation-item {
  display: grid;
  gap: 6px;
  width: 100%;
  min-height: 72px;
  padding: 12px 14px;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  color: var(--ink);
  background: transparent;
  text-align: left;
}

.conversation-item:hover,
.conversation-item.active {
  color: var(--ink);
  background: var(--soft);
}

.conversation-item strong,
.conversation-item span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-item span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 400;
}

.unread-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: fit-content;
  min-height: 20px;
  padding: 0 8px;
  border-radius: 999px;
  color: #fff !important;
  background: #dc2626;
  font-size: 12px !important;
  font-weight: 800 !important;
}

.empty-state {
  display: grid;
  place-items: center;
  color: var(--muted);
}

@media (max-width: 760px) {
  .customer-page,
  .admin-page {
    padding: 0;
  }

  .admin-layout {
    grid-template-columns: 1fr;
    width: 100%;
    min-height: 100vh;
    height: 100vh;
    max-height: none;
    border: 0;
    border-radius: 0;
  }

  .customer-page {
    padding: 12px;
  }

  .chat-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
    width: min(100%, 430px);
    min-height: min(740px, calc(100vh - 24px));
    height: min(740px, calc(100vh - 24px));
    max-height: calc(100vh - 24px);
    border-radius: 8px;
  }

  .brand-panel {
    min-height: 100px;
    padding: 14px 16px;
  }

  h1 {
    font-size: 22px;
  }

  .lead {
    display: none;
  }

  .status-card {
    display: none;
  }

  .panel-header {
    min-height: 58px;
    padding: 12px 14px;
  }

  .admin-layout {
    grid-template-rows: 240px 1fr;
    width: min(100%, 430px);
    height: min(760px, calc(100vh - 24px));
    min-height: min(760px, calc(100vh - 24px));
    border-radius: 8px;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .conversation-list {
    height: 149px;
  }

  .start-row,
  .composer {
    grid-template-columns: auto auto minmax(0, 1fr) auto;
    gap: 6px;
  }

  .start-row {
    grid-template-columns: 1fr;
  }

  .messages {
    padding: 14px;
  }

  .message {
    max-width: 86%;
  }

  .message-image {
    max-height: 180px;
  }
}
