:root {
  --wa-green: #00a884;
  --wa-green-dark: #008069;
  --wa-teal: #008069;
  --wa-out: #d9fdd3;
  --wa-in: #ffffff;
  --wa-bg: #efeae2;
  --wa-panel: #ffffff;
  --wa-side: #ffffff;
  --wa-head: #f0f2f5;
  --wa-line: #e9edef;
  --wa-muted: #667781;
  --wa-ink: #111b21;
  --blue: #1877f2;
  --blue-dark: #166fe5;
  --ok: #16a34a;
  --wait: #d97706;
  --danger: #dc2626;
  --shadow: 0 18px 50px rgba(17, 24, 39, 0.12);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--wa-ink);
  background: #d1d7db;
}
body.in-chat {
  position: fixed;
  inset: 0;
  width: 100%;
  overflow: hidden;
  height: 100%;
  height: 100svh;
}

button, input, textarea { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.landing {
  min-height: 100vh;
  background:
    radial-gradient(1200px 500px at 10% -10%, #dbeafe 0%, transparent 55%),
    linear-gradient(180deg, #ffffff 0%, #eef2ff 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.hero {
  width: min(560px, 100%);
  background: #fff;
  border-radius: 24px;
  box-shadow: var(--shadow);
  padding: 36px 28px 28px;
}
.badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: #eff6ff;
  color: var(--blue);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 600;
}
.badge i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ok);
}
.hero h1 { margin: 16px 0 10px; font-size: 34px; line-height: 1.15; }
.hero p { margin: 0 0 22px; color: #6b7280; line-height: 1.6; }
.field { margin-bottom: 14px; }
.field label { display: block; margin-bottom: 6px; font-size: 13px; color: #374151; }
.field input {
  width: 100%;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  padding: 12px 14px;
  outline: none;
}
.field input:focus { border-color: var(--wa-green); }
.primary {
  width: 100%;
  border: 0;
  background: var(--wa-green);
  color: #fff;
  border-radius: 14px;
  padding: 14px 16px;
  font-size: 16px;
  font-weight: 700;
}
.primary:hover { background: var(--wa-green-dark); }
.primary:disabled { opacity: 0.65; cursor: wait; }
.hint { margin-top: 14px; text-align: center; color: var(--wa-muted); font-size: 12px; }
.error { color: var(--danger); font-size: 13px; min-height: 18px; margin: 8px 0 0; }

.agent-app { height: 100%; overflow: hidden; background: #d1d7db; }
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(180deg, #00a884 0 28%, #d1d7db 28%);
}
.login-card {
  width: min(400px, 100%);
  background: #fff;
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 28px;
}
.login-card h1 { margin: 0 0 8px; font-size: 24px; }
.login-card p { margin: 0 0 20px; color: var(--wa-muted); }

.inbox {
  --side-width: 280px;
  display: flex;
  height: 100%;
  width: 100%;
  background: #fff;
  overflow: hidden;
}

.side {
  width: var(--side-width);
  flex: 0 0 var(--side-width);
  background: var(--wa-side);
  border-right: 0;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}
.side-resizer {
  flex: 0 0 6px;
  cursor: col-resize;
  background: #d1d7db;
  position: relative;
  z-index: 3;
}
.side-resizer:hover,
.side-resizer.dragging {
  background: #00a884;
}
.side-head {
  background: var(--wa-head);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 60px;
}
.side-user { display: flex; align-items: center; gap: 10px; min-width: 0; }
.side-user h1 { margin: 0; font-size: 16px; }
.row { display: flex; align-items: center; gap: 8px; }
.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #6a7175;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  flex-shrink: 0;
}
.avatar.green { background: #00a884; }
.toggle {
  border: 0;
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 700;
}
.toggle.on { background: #d9fdd3; color: #046c4e; }
.toggle.off { background: #e9edef; color: #667781; }
.ghost {
  border: 0;
  background: transparent;
  color: var(--wa-muted);
  padding: 0;
  font-size: 13px;
}

.session-list { flex: 1; overflow: auto; background: #fff; }
.session-item {
  width: 100%;
  text-align: left;
  border: 0;
  background: #fff;
  color: var(--wa-ink);
  padding: 12px 16px;
  border-bottom: 1px solid #f0f2f5;
  display: flex;
  gap: 12px;
  align-items: center;
}
.session-item.active { background: #f0f2f5; }
.session-item:hover { background: #f5f6f6; }
.session-item .meta { min-width: 0; flex: 1; }
.session-item .meta-top,
.session-item .meta-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.session-item b {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 0;
  font-size: 16px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.return-tag {
  display: inline-block;
  font-size: 11px;
  font-style: normal;
  font-weight: 700;
  color: #9a3412;
  background: #ffedd5;
  border-radius: 4px;
  padding: 1px 5px;
  line-height: 1.4;
}
.session-item .session-time {
  flex-shrink: 0;
  font-size: 12px;
  color: var(--wa-muted);
}
.session-item .preview {
  min-width: 0;
  flex: 1;
  font-size: 13px;
  color: var(--wa-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.session-item.has-unread .preview { color: #111b21; font-weight: 600; }
.session-item.has-unread .session-time { color: #25d366; font-weight: 600; }
.session-item .unread {
  flex-shrink: 0;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: #25d366;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  font-style: normal;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.panel {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  background: var(--wa-bg);
}
.empty {
  margin: auto;
  color: var(--wa-muted);
  text-align: center;
  max-width: 360px;
}

.wa-shell {
  flex: 1;
  min-height: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background:
    linear-gradient(rgba(239,234,226,.92), rgba(239,234,226,.92)),
    repeating-linear-gradient(45deg, transparent, transparent 12px, rgba(0,0,0,.015) 12px, rgba(0,0,0,.015) 13px);
}
.visitor-shell {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  width: 100%;
  height: 100%;
  height: 100svh;
  max-height: 100svh;
  overflow: hidden;
  background: #efeae2;
}
.visitor-shell::before {
  content: "";
  position: absolute;
  inset: -16px;
  background: url("/img/handmade-kit.jpg") center/cover no-repeat;
  filter: blur(7px);
  transform: scale(1.06);
  pointer-events: none;
  z-index: 0;
}
.visitor-shell::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(255, 248, 240, 0.28);
  pointer-events: none;
  z-index: 0;
}
.visitor-shell > * {
  position: relative;
  z-index: 1;
}

.wa-top {
  flex-shrink: 0;
  background: var(--wa-head);
  min-height: 60px;
  padding: 8px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--wa-line);
}
.wa-top-user { display: flex; align-items: center; gap: 12px; min-width: 0; }
.wa-top h2 { margin: 0; font-size: 16px; }
.wa-sub { font-size: 13px; color: var(--wa-muted); }
.status {
  font-size: 12px;
  font-weight: 600;
  border-radius: 999px;
  padding: 3px 8px;
}
.status.waiting { background: #fff7ed; color: var(--wait); }
.status.active { background: #d9fdd3; color: #046c4e; }
.status.closed { background: #fee2e2; color: var(--danger); }
.close-btn {
  border: 0;
  background: transparent;
  color: #54656f;
  font-size: 13px;
}
.convert-btn, .lead-btn, .phone-btn, .dup-btn {
  border: 0;
  font-size: 13px;
  font-weight: 600;
  border-radius: 8px;
  padding: 6px 10px;
}
.convert-btn {
  background: #d9fdd3;
  color: #046c4e;
}
.convert-btn:hover { background: #c3f0bb; }
.lead-btn {
  background: #dbeafe;
  color: #1d4ed8;
}
.lead-btn:hover { background: #bfdbfe; }
.phone-btn {
  background: #f3f4f6;
  color: #374151;
}
.phone-btn:hover { background: #e5e7eb; }
.dup-btn {
  background: #ffedd5;
  color: #c2410c;
}
.dup-btn:hover { background: #fed7aa; }
.convert-btn:disabled, .lead-btn:disabled, .dup-btn:disabled {
  background: #e9edef;
  color: #667781;
}
.fb-modal {
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 39, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 80;
}
.fb-modal.hidden { display: none; }
.fb-dialog {
  width: min(420px, 92vw);
  background: #fff;
  border-radius: 14px;
  padding: 20px 20px 16px;
  box-shadow: 0 16px 40px rgba(0,0,0,0.18);
}
.fb-dialog h3 { margin: 0 0 8px; font-size: 18px; }
.fb-hint { margin: 0 0 14px; color: #667781; font-size: 13px; line-height: 1.5; }
.fb-label { display: block; font-size: 13px; color: #54656f; margin-bottom: 10px; }
.fb-label input {
  display: block;
  width: 100%;
  margin-top: 6px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 14px;
}
.dup-check {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  font-size: 14px;
  color: #374151;
}
.fb-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.fb-actions .ghost {
  border: 0;
  background: transparent;
  color: #54656f;
  padding: 6px 10px;
}
.wa-top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.translate-switch {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: #54656f;
  user-select: none;
  white-space: nowrap;
}
.translate-switch input { accent-color: var(--wa-green); }
.translate-panel {
  margin: 0 12px 8px;
  background: #fff;
  border: 1px solid #e9edef;
  border-radius: 10px;
  padding: 10px 12px;
  box-shadow: 0 6px 18px rgba(17, 24, 39, 0.08);
}
.translate-loading { font-size: 13px; color: var(--wa-muted); }
.translate-kicker {
  font-size: 12px;
  color: var(--wa-muted);
  margin-bottom: 6px;
}
.translate-kicker span { color: #027a5a; }
.translate-preview textarea {
  width: 100%;
  border: 1px solid #e9edef;
  border-radius: 8px;
  padding: 8px 10px;
  resize: vertical;
  min-height: 56px;
  outline: none;
  font: inherit;
}
.translate-origin {
  margin-top: 6px;
  font-size: 12px;
  color: var(--wa-muted);
  word-break: break-word;
}
.translate-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}
.translate-actions button {
  border: 0;
  border-radius: 8px;
  padding: 8px 12px;
  background: var(--wa-green);
  color: #fff;
  font-weight: 600;
}
.translate-actions .ghost {
  background: #f0f2f5;
  color: #111b21;
}
.translate-fail-title { font-weight: 700; color: var(--danger); }
.translate-fail-reason { margin-top: 4px; font-size: 13px; color: #54656f; }
.wa-trans {
  margin-top: 4px;
  padding: 4px 6px;
  border-left: 2px solid rgba(0, 168, 132, 0.45);
  font-size: 12.5px;
  color: #54656f;
  word-break: break-word;
}
.wa-trans-fail {
  margin-top: 4px;
  padding: 4px 6px;
  border-left: 2px solid #dc2626;
  font-size: 12.5px;
  color: #b42318;
}
.wa-trans-retry {
  margin-left: 6px;
  border: 0;
  background: #fee2e2;
  color: #b42318;
  border-radius: 6px;
  padding: 2px 8px;
  font-size: 12px;
}

.messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 10px 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.wa-system {
  align-self: center;
  background: #ffeeba;
  color: #54656f;
  font-size: 12.5px;
  border-radius: 8px;
  padding: 6px 12px;
  margin: 6px 0;
  box-shadow: 0 1px 0 rgba(0,0,0,.04);
}

.wa-row {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  max-width: 92%;
}
.wa-row.in { align-self: flex-start; }
.wa-row.out { align-self: flex-end; }
.msg-avatar {
  width: 32px;
  height: 32px;
  font-size: 13px;
}
.wa-row .wa-bubble { max-width: none; flex: 1; min-width: 0; }

.wa-bubble {
  max-width: 65%;
  padding: 6px 8px 4px;
  border-radius: 8px;
  box-shadow: 0 1px 0.5px rgba(11,20,26,.13);
  position: relative;
}
.wa-bubble.in {
  align-self: flex-start;
  background: var(--wa-in);
  border-top-left-radius: 0;
}
.wa-bubble.out {
  align-self: flex-end;
  background: var(--wa-out);
  border-top-right-radius: 0;
}
.wa-text { white-space: pre-wrap; word-break: break-word; line-height: 1.45; padding: 0 4px; }
.wa-link {
  color: #027eb5;
  text-decoration: underline;
  word-break: break-all;
}
.wa-bubble.out .wa-link { color: #027a5a; }
.link-card {
  display: block;
  margin: 6px 2px 4px;
  border-radius: 8px;
  overflow: hidden;
  background: rgba(0, 0, 0, 0.05);
  text-decoration: none;
  color: inherit;
}
.link-card:hover { background: rgba(0, 0, 0, 0.08); }
.link-card-media img {
  display: block;
  width: 100%;
  max-height: 160px;
  object-fit: cover;
  background: #d1d7db;
}
.link-card-body { padding: 8px 10px 9px; }
.link-card-site {
  font-size: 11px;
  color: #667781;
  text-transform: lowercase;
}
.link-card-title {
  font-weight: 600;
  font-size: 14px;
  line-height: 1.35;
  margin-top: 2px;
}
.link-card-desc {
  font-size: 12px;
  color: #667781;
  margin-top: 3px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.wa-time {
  display: block;
  text-align: right;
  font-size: 11px;
  color: #667781;
  margin-top: 2px;
}
.wa-image img {
  display: block;
  max-width: 260px;
  max-height: 280px;
  border-radius: 6px;
}
.wa-caption { padding: 6px 4px 0; }
.wa-file {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 180px;
  padding: 8px;
  background: rgba(0,0,0,.04);
  border-radius: 6px;
  color: inherit;
  text-decoration: none;
}
.wa-file-name { word-break: break-all; }

.composer-wrap {
  position: relative;
  flex-shrink: 0;
  min-width: 0;
}
.composer {
  background: #f0f2f5;
  padding: 10px 12px calc(12px + env(safe-area-inset-bottom, 0px));
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  width: 100%;
}
.icon-btn {
  border: 0;
  background: transparent;
  color: #54656f;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-size: 22px;
  line-height: 1;
  flex-shrink: 0;
}
.icon-btn:hover { background: rgba(0,0,0,.06); }
.composer input[type="text"] {
  flex: 1 1 0;
  min-width: 0;
  width: auto;
  border: 0;
  background: #fff;
  border-radius: 8px;
  padding: 10px 14px;
  outline: none;
}
.send-btn {
  border: 0;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--wa-green);
  color: #fff;
  font-size: 18px;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.send-btn svg { display: block; }
.send-btn:disabled { opacity: .5; }

.emoji-panel {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 64px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,.16);
  padding: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  max-height: 220px;
  overflow: auto;
  z-index: 5;
}
.emoji-item {
  border: 0;
  background: transparent;
  font-size: 22px;
  width: 36px;
  height: 36px;
  border-radius: 8px;
}
.emoji-item:hover { background: #f0f2f5; }

.phrase-panel {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 64px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,.16);
  padding: 10px;
  z-index: 6;
  display: flex;
  flex-direction: column;
  max-height: 280px;
}
.phrase-panel input[type="search"] {
  width: 100%;
  border: 1px solid #e9edef;
  border-radius: 8px;
  padding: 8px 10px;
  outline: none;
  margin-bottom: 8px;
}
.phrase-list {
  overflow: auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.phrase-item {
  border: 0;
  background: #f8fafc;
  text-align: left;
  border-radius: 8px;
  padding: 8px 10px;
  color: inherit;
}
.phrase-item:hover { background: #eef6f3; }
.phrase-item b {
  display: block;
  font-size: 14px;
  font-weight: 600;
}
.phrase-item span {
  display: block;
  margin-top: 2px;
  font-size: 12px;
  color: var(--wa-muted);
}
.phrase-empty {
  padding: 16px 8px;
  text-align: center;
  color: var(--wa-muted);
  font-size: 13px;
}

.wa-choice-card {
  align-self: center;
  width: min(340px, calc(100% - 16px));
  margin: 10px 0 6px;
  background: #fff;
  border-radius: 14px;
  padding: 16px 14px 12px;
  text-align: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}
.wa-choice-card h3 {
  margin: 0 0 12px;
  font-size: 15px;
  font-weight: 700;
  color: #111b21;
}
.wa-choice-wa {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  border: 0;
  background: #25d366;
  color: #fff;
  padding: 12px 14px;
  border-radius: 24px;
  font-weight: 700;
  text-decoration: none;
  font-size: 15px;
}
.wa-choice-wa:disabled { opacity: 0.7; }
.wa-choice-wa svg { flex-shrink: 0; }
.wa-choice-stay {
  display: block;
  width: 100%;
  margin-top: 10px;
  border: 0;
  background: transparent;
  color: #8696a0;
  font-size: 13px;
  padding: 6px;
}
.wa-choice-note {
  margin: 10px 0 0;
  font-size: 11px;
  color: #adb5bd;
}
.wa-tag {
  display: inline-block;
  font-size: 11px;
  font-style: normal;
  font-weight: 700;
  color: #166534;
  background: #dcfce7;
  border-radius: 4px;
  padding: 1px 5px;
  line-height: 1.4;
}

@media (max-width: 800px) {
  .inbox { flex-direction: column; }
  .side {
    width: 100%;
    flex: 0 0 auto;
    max-height: 32vh;
  }
  .side-resizer { display: none; }
  .messages { padding: 8px 6px; }
  .wa-bubble { max-width: 86%; }
  .visitor-shell .wa-top {
    padding-top: calc(8px + env(safe-area-inset-top, 0px));
  }
  .visitor-shell .composer {
    padding: 8px 8px calc(8px + env(safe-area-inset-bottom, 0px));
    gap: 6px;
  }
  .visitor-shell .icon-btn {
    width: 36px;
    height: 36px;
    font-size: 20px;
  }
  .visitor-shell .send-btn {
    width: 40px;
    height: 40px;
  }
  .visitor-shell .composer input[type="text"] {
    font-size: 16px;
    padding: 10px 12px;
  }
  .visitor-shell .wa-row {
    max-width: calc(100% - 8px);
  }
}
