:root {
  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  --brand: #2563eb;
  --brand-dark: #1d4ed8;
  --ink: #172033;
  --muted: #718096;
  --line: #e8edf5;
  --surface: #ffffff;
  --soft: #f5f7fb;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; background: transparent; }
button, input, textarea { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

.launcher {
  position: fixed;
  right: 6px;
  bottom: 6px;
  width: 58px;
  height: 58px;
  border: 0;
  border-radius: 20px;
  color: #fff;
  background: linear-gradient(145deg, #3478f6, #1556d9);
  box-shadow: 0 15px 35px rgba(26, 86, 210, .36);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: transform .2s ease, box-shadow .2s ease;
}
.launcher:hover { transform: translateY(-2px); box-shadow: 0 18px 38px rgba(26, 86, 210, .44); }
.launcher svg { width: 27px; fill: currentColor; }
.launcher-dot {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 13px;
  height: 13px;
  border: 3px solid #fff;
  border-radius: 50%;
  background: #22c55e;
}

.panel {
  position: absolute;
  inset: 7px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid rgba(213, 222, 236, .9);
  border-radius: 24px;
  background: var(--surface);
  box-shadow: 0 22px 70px rgba(20, 34, 64, .22);
  opacity: 1;
  transform: scale(1);
  transform-origin: right bottom;
  transition: opacity .18s ease, transform .18s ease;
}
.is-collapsed .panel { pointer-events: none; opacity: 0; transform: scale(.85); }
:not(.is-collapsed) .launcher { pointer-events: none; opacity: 0; }

.chat-header {
  min-height: 76px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  color: #fff;
  background:
    radial-gradient(circle at 85% -30%, rgba(255,255,255,.3), transparent 45%),
    linear-gradient(135deg, #2563eb, #1d4ed8);
}
.brand-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border: 1px solid rgba(255,255,255,.5);
  border-radius: 15px;
  background: rgba(255,255,255,.18);
  font-weight: 800;
  font-size: 20px;
}
.brand-copy { min-width: 0; display: grid; gap: 5px; }
.brand-copy strong { font-size: 17px; letter-spacing: .02em; }
#presence { display: flex; align-items: center; gap: 6px; font-size: 12px; color: rgba(255,255,255,.82); }
#presence i { width: 8px; height: 8px; border-radius: 50%; background: #fbbf24; }
#presence.online i { background: #4ade80; }
#presence b { font-weight: 500; }
.icon-button {
  margin-left: auto;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 12px;
  background: rgba(255,255,255,.12);
  color: #fff;
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
}
.icon-button:hover { background: rgba(255,255,255,.22); }

.welcome-view {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 28px 24px 20px;
  background: linear-gradient(180deg, #f6f9ff 0, #fff 38%);
}
.welcome-art { font-weight: 800; font-size: 25px; color: var(--brand); }
.welcome-view h1 { margin: 10px 0 6px; color: var(--ink); font-size: 22px; }
.welcome-view > p { margin: 0 0 22px; color: var(--muted); font-size: 14px; line-height: 1.6; }
.welcome-view label { display: grid; gap: 7px; margin: 14px 0; color: #526079; font-size: 13px; }
.welcome-view input {
  width: 100%;
  height: 45px;
  border: 1px solid var(--line);
  border-radius: 13px;
  outline: 0;
  padding: 0 13px;
  color: var(--ink);
  background: #fff;
  transition: border-color .2s, box-shadow .2s;
}
.welcome-view input:focus { border-color: #8fb3ff; box-shadow: 0 0 0 4px rgba(37,99,235,.09); }
.primary-button {
  width: 100%;
  height: 47px;
  margin-top: 8px;
  border: 0;
  border-radius: 14px;
  color: #fff;
  background: linear-gradient(135deg, var(--brand), var(--brand-dark));
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 10px 24px rgba(37,99,235,.24);
}
.primary-button:disabled { opacity: .55; cursor: wait; }
.welcome-view small { display: block; margin: 14px 4px 0; color: #9aa5b8; font-size: 11px; line-height: 1.5; text-align: center; }

.chat-view { flex: 1; min-height: 0; display: flex; flex-direction: column; background: var(--soft); }
.messages { flex: 1; min-height: 0; overflow-y: auto; padding: 18px 15px 10px; scroll-behavior: smooth; }
.message { display: flex; gap: 8px; align-items: flex-end; margin: 0 0 14px; }
.message.visitor { justify-content: flex-end; }
.message-avatar {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 10px;
  color: #fff;
  background: #4f78d6;
  font-size: 12px;
  font-weight: 700;
}
.message-card { max-width: 76%; }
.message-name { margin: 0 3px 4px; color: #8b96aa; font-size: 10px; }
.message.visitor .message-name { text-align: right; }
.message-bubble {
  padding: 10px 12px;
  border: 1px solid #e6ebf3;
  border-radius: 7px 16px 16px 16px;
  color: var(--ink);
  background: #fff;
  box-shadow: 0 3px 10px rgba(30,45,78,.05);
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 14px;
  line-height: 1.55;
}
.message.visitor .message-bubble { border: 0; border-radius: 16px 7px 16px 16px; color: #fff; background: var(--brand); }
.message-time { margin: 4px 3px 0; color: #a1aabc; font-size: 9px; }
.message.visitor .message-time { text-align: right; }
.empty-message { margin: 32px 18px; color: #8a96aa; text-align: center; font-size: 13px; line-height: 1.7; }
.closed-banner { padding: 8px 12px; color: #8b5d17; background: #fff4d8; text-align: center; font-size: 11px; }

.composer { display: flex; align-items: flex-end; gap: 9px; padding: 10px 12px 12px; border-top: 1px solid var(--line); background: #fff; }
.composer textarea { flex: 1; min-height: 42px; max-height: 105px; resize: none; border: 1px solid var(--line); border-radius: 14px; outline: 0; padding: 10px 12px; color: var(--ink); line-height: 1.45; }
.composer textarea:focus { border-color: #9ab9fb; }
.composer button { width: 42px; height: 42px; flex: 0 0 auto; display: grid; place-items: center; border: 0; border-radius: 14px; color: #fff; background: var(--brand); cursor: pointer; }
.composer button:disabled { opacity: .45; }
.composer svg { width: 20px; fill: currentColor; }

.toast { position: absolute; left: 50%; bottom: 78px; z-index: 4; transform: translateX(-50%); max-width: 85%; padding: 9px 13px; border-radius: 10px; color: #fff; background: rgba(25,34,51,.88); font-size: 12px; text-align: center; }

@media (max-width: 420px), (max-height: 570px) {
  .panel { inset: 0; border: 0; border-radius: 0; }
  .chat-header { min-height: 68px; }
  .welcome-view { padding-top: 22px; }
}
