:root {
  --brand: #4caf75;
  --brand-dark: #3b9962;
  --bg: #eef1f5;
  --card: #ffffff;
  --text: #22262e;
  --muted: #6c7583;
  --border: #eaedf1;
  --bubble-agent: #f1f2f5;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

.hidden {
  display: none !important;
}

.app-shell {
  max-width: 540px;
  margin: 0 auto;
  height: 100%;
  background: var(--bg);
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

@media (min-width: 560px) {
  .app-shell {
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
  }
}

.view {
  display: none;
  flex-direction: column;
  height: 100%;
  width: 100%;
}

.view.active {
  display: flex;
}

/* Home View */
.home-header {
  background: linear-gradient(135deg, var(--brand) 0%, #60bd7f 100%);
  color: #fff;
  padding: 18px 16px 46px;
  flex-shrink: 0;
}

.home-header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand-badge {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: #fff;
  color: var(--brand-dark);
  font-weight: 700;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}

.brand-name {
  font-size: 17px;
  font-weight: 600;
}

.home-presence {
  font-size: 12px;
  opacity: 0.92;
}

.icon-btn-light {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: none;
  background: rgba(255, 255, 255, 0.9);
  color: var(--brand-dark);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}

.home-body {
  flex: 1;
  overflow-y: auto;
  padding: 0 12px 24px;
  margin-top: -28px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card {
  background: var(--card);
  border-radius: 10px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
  overflow: hidden;
}

.card-header-title {
  font-size: 15px;
  font-weight: 600;
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}

.card-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 12px 6px 16px;
  border-bottom: 1px solid var(--border);
}

.card-header-row .card-header-title {
  padding: 7px 0;
  border-bottom: none;
}

.icon-btn-muted {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.faq-search-wrap {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: #fafbfc;
}

.faq-search-wrap input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid #dce1e8;
  border-radius: 6px;
  font-size: 14px;
  outline: none;
}

.faq-search-wrap input:focus {
  border-color: var(--brand);
}

.list-group {
  display: flex;
  flex-direction: column;
}

.topic-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 16px;
  border: none;
  border-bottom: 1px solid var(--border);
  background: #fff;
  text-align: left;
  width: 100%;
  cursor: pointer;
  transition: background 0.15s;
}

.topic-item:last-child {
  border-bottom: none;
}

.topic-item:active, .topic-item:hover {
  background: #f7f9fb;
}

.topic-avatar {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  color: #fff;
  font-weight: 700;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.topic-info {
  flex: 1;
  min-width: 0;
}

.topic-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.topic-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.topic-time {
  font-size: 11px;
  color: #9aa2b1;
  flex-shrink: 0;
}

.topic-sub {
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.unread-pill {
  background: #e53935;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  padding: 0 5px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.faq-item {
  border-bottom: 1px solid var(--border);
}

.faq-item:last-child {
  border-bottom: none;
}

.faq-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 13px 16px;
  border: none;
  background: #fff;
  text-align: left;
  cursor: pointer;
}

.faq-btn:hover {
  background: #fafbfc;
}

.faq-badge {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  background: #7c695d;
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.faq-q {
  flex: 1;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
}

.faq-chevron {
  color: #a0a8b5;
  font-size: 14px;
  transition: transform 0.2s;
}

.faq-item.open .faq-chevron {
  transform: rotate(90deg);
}

.faq-answer {
  display: none;
  padding: 0 16px 14px 60px;
  font-size: 13px;
  color: #4a5260;
  white-space: pre-wrap;
  line-height: 1.65;
}

.faq-item.open .faq-answer {
  display: block;
}

.error-banner {
  background: #ffebee;
  color: #c62828;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
}

/* Chat View */
.chat-header {
  background: linear-gradient(135deg, var(--brand) 0%, #60bd7f 100%);
  color: #fff;
  padding: 12px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.header-square-btn {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: none;
  background: rgba(255, 255, 255, 0.88);
  color: var(--brand-dark);
  font-size: 20px;
  font-weight: 700;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}

.chat-header-info {
  flex: 1;
  min-width: 0;
}

.chat-topic-title {
  font-size: 16px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-presence-text {
  font-size: 12px;
  opacity: 0.92;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ws-banner {
  background: #fff8e1;
  color: #8d6e00;
  font-size: 12px;
  text-align: center;
  padding: 5px 10px;
  border-bottom: 1px solid #ffe082;
}

.message-list {
  flex: 1;
  overflow-y: auto;
  background: #fff;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.msg-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  max-width: 88%;
}

.msg-row.visitor {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.msg-row.agent, .msg-row.system {
  align-self: flex-start;
}

.msg-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: #e39d24;
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 18px;
}

.msg-col {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.msg-row.visitor .msg-col {
  align-items: flex-end;
}

.msg-sender {
  font-size: 12px;
  color: #7d8694;
  margin-bottom: 4px;
}

.msg-bubble {
  padding: 10px 13px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg-row.agent .msg-bubble,
.msg-row.system .msg-bubble {
  background: var(--bubble-agent);
  color: var(--text);
  border-top-left-radius: 4px;
}

.msg-row.visitor .msg-bubble {
  background: var(--brand);
  color: #fff;
  border-top-right-radius: 4px;
}

.msg-image {
  max-width: 220px;
  max-height: 280px;
  border-radius: 8px;
  display: block;
  cursor: zoom-in;
  object-fit: cover;
}

.msg-time {
  font-size: 11px;
  color: #a3abb8;
  margin-top: 4px;
}

.composer {
  background: #fff;
  border-top: 1px solid var(--border);
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  display: flex;
  align-items: flex-end;
  gap: 8px;
  flex-shrink: 0;
}

.composer-icon-btn {
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  color: #6c7583;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border-radius: 8px;
  flex-shrink: 0;
}

.composer-icon-btn:hover {
  background: #f2f4f7;
}

.composer textarea {
  flex: 1;
  border: 1px solid #e2e6ec;
  background: #f8f9fb;
  border-radius: 18px;
  padding: 8px 14px;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.4;
  max-height: 110px;
  resize: none;
  outline: none;
}

.composer textarea:focus {
  border-color: var(--brand);
  background: #fff;
}

.send-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: var(--brand);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: opacity 0.15s;
}

.send-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

/* Lightbox */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.88);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.lightbox img {
  max-width: 100%;
  max-height: 100%;
  border-radius: 6px;
}

.lightbox-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
  font-size: 18px;
  cursor: pointer;
}
