* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Microsoft YaHei", Arial, sans-serif;
  background: #f5f7fb;
  color: #1f2937;
}

.container {
  max-width: 1080px;
  margin: 0 auto;
  padding: 20px;
}

.card {
  background: #ffffff;
  border-radius: 12px;
  box-shadow: 0 6px 20px rgba(17, 24, 39, 0.08);
  padding: 16px;
}

h1, h2, h3 {
  margin: 0 0 12px;
}

.row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

button, input, select {
  font-size: 14px;
}

button {
  border: none;
  border-radius: 8px;
  padding: 10px 14px;
  cursor: pointer;
  background: #2563eb;
  color: #fff;
}

button.secondary {
  background: #4b5563;
}

input, select {
  width: 100%;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  padding: 10px;
}

.chat-layout {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 12px;
}

.messages {
  height: 420px;
  overflow-y: auto;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 10px;
  background: #fafafa;
}

.msg {
  margin-bottom: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  max-width: 80%;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg.customer {
  background: #e0ecff;
  margin-left: auto;
}

.msg.admin {
  background: #dcfce7;
  margin-right: auto;
}

.msg.system {
  background: #f3f4f6;
  margin-left: auto;
  margin-right: auto;
}

.msg-image {
  display: block;
  max-width: 220px;
  width: 100%;
  border-radius: 8px;
  border: 1px solid #e5e7eb;
}

.meta {
  font-size: 12px;
  color: #6b7280;
  margin-bottom: 4px;
}

.sessions {
  max-height: 500px;
  overflow-y: auto;
}

.session-item {
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 10px;
  margin-bottom: 8px;
  cursor: pointer;
}

.session-item.active {
  border-color: #2563eb;
  background: #eff6ff;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  background: #e5e7eb;
}

.badge.online {
  background: #dcfce7;
  color: #166534;
}

.badge.offline {
  background: #fee2e2;
  color: #991b1b;
}

.admin-body {
  height: 100dvh;
  min-height: 100dvh;
}

.admin-container {
  max-width: none;
  width: 100%;
  margin: 0;
  padding: 16px;
  height: 100dvh;
  min-height: 100dvh;
}

.admin-app {
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.admin-chat-layout {
  flex: 1;
  min-height: 0;
  height: 100%;
  align-items: stretch;
  grid-template-columns: 320px minmax(0, 1fr);
  grid-auto-rows: minmax(0, 1fr);
}

.admin-session-card,
.admin-message-card {
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
}

.admin-session-card .sessions,
.admin-message-card .messages {
  flex: 1;
  min-height: 0;
  max-height: none;
  height: auto;
}

.admin-composer {
  flex-wrap: nowrap;
}

.admin-composer input#text {
  flex: 1;
}

.admin-message-card .messages {
  border-radius: 8px;
}

@media (max-width: 860px) {
  .container {
    padding: 10px;
  }

  .admin-container {
    padding: 10px;
  }

  .chat-layout {
    grid-template-columns: 1fr;
  }

  .messages {
    height: 320px;
  }

  .admin-app {
    min-height: 0;
  }

  .admin-chat-layout {
    grid-template-columns: 1fr;
    height: auto;
  }

  .admin-session-card .sessions {
    max-height: 220px;
    min-height: 140px;
  }

  .admin-message-card .messages {
    min-height: 280px;
  }

  .admin-composer {
    flex-wrap: wrap;
  }
}

.customer-app {
  max-width: 420px;
  margin: 0 auto;
  height: var(--customer-app-height, 100dvh);
  background: #ffffff;
  display: flex;
  flex-direction: column;
}

.customer-header {
  padding: 12px;
  background: linear-gradient(90deg, #4f7cf5 0%, #16c7b9 100%);
  color: #ffffff;
}

.customer-topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}

.customer-user {
  display: flex;
  align-items: center;
  gap: 10px;
}

.customer-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.85);
  display: block;
  object-fit: cover;
  padding: 4px;
}

.customer-title {
  font-size: 22px;
  font-weight: 700;
  line-height: 1;
}

.customer-subtitle {
  margin-top: 4px;
  font-size: 14px;
  opacity: 0.95;
}

.customer-room {
  margin-top: 8px;
  font-size: 12px;
  opacity: 0.95;
}

.customer-actions {
  margin-top: 8px;
  display: flex;
  gap: 8px;
}

.return-entry {
  text-decoration: none;
}

.return-entry button {
  padding: 6px 10px;
  font-size: 12px;
  border-radius: 999px;
  background: rgba(31, 41, 55, 0.4);
}

.customer-actions button {
  padding: 6px 10px;
  font-size: 12px;
  border-radius: 999px;
  background: rgba(31, 41, 55, 0.4);
}

.customer-messages {
  flex: 1;
  height: auto;
  border: none;
  border-radius: 0;
  background: #ececec;
  padding: 12px;
}

.customer-composer {
  display: flex;
  gap: 8px;
  padding: 10px;
  border-top: 1px solid #e5e7eb;
  background: #ffffff;
  z-index: 20;
}

.customer-composer input {
  flex: 1;
  border-radius: 20px;
}

.customer-composer button {
  border-radius: 20px;
  padding: 8px 16px;
}

@media (min-width: 861px) {
  .customer-app {
    margin-top: 20px;
    margin-bottom: 20px;
    border-radius: 14px;
    overflow: hidden;
    box-shadow: 0 8px 24px rgba(17, 24, 39, 0.12);
    height: calc(100dvh - 40px);
  }
}

@media (max-width: 860px) {
  .customer-messages {
    padding-bottom: 12px;
  }

  .customer-composer {
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
  }
}