/* ══════════════════════════════════════════════════════════════════════════
   Companion Chat — iMessage style, mobile-first
   ══════════════════════════════════════════════════════════════════════════ */

*, *::before, *::after {
  box-sizing: border-box;
  -webkit-font-smoothing: antialiased;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: #fff;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", sans-serif;
  font-size: 16px;
  color: #1c1c1e;
  overflow: hidden;
}

/* ── Layout Shell ──────────────────────────────────────────────────────── */

.chat-shell {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 600px;
  margin: 0 auto;
  position: relative;
}

/* ── Header ────────────────────────────────────────────────────────────── */

.chat-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top));
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid rgba(0,0,0,0.08);
  flex-shrink: 0;
  z-index: 10;
}

.header-back {
  font-size: 22px;
  color: #007aff;
  cursor: pointer;
  padding: 4px 8px 4px 0;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  text-decoration: none;
  line-height: 1;
}

.header-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: linear-gradient(135deg, #e8d5ff 0%, #c5b3f9 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}

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

.header-name {
  font-size: 16px;
  font-weight: 600;
  color: #1c1c1e;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-status {
  font-size: 12px;
  color: #34c759;
  margin-top: 1px;
}

/* ── Message List ───────────────────────────────────────────────────────── */

.message-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.date-divider {
  text-align: center;
  font-size: 12px;
  color: #8e8e93;
  margin: 10px 0 6px;
  font-weight: 500;
}

/* ── Message Row ────────────────────────────────────────────────────────── */

.msg-row {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  animation: msgIn 0.2s ease;
}

.msg-row.sent { flex-direction: row-reverse; }

@keyframes msgIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.msg-row + .msg-row.recv,
.msg-row.recv + .msg-row.recv { margin-top: 2px; }
.msg-row + .msg-row.sent,
.msg-row.sent  + .msg-row.sent { margin-top: 2px; }
.msg-row.recv + .msg-row.sent,
.msg-row.sent  + .msg-row.recv { margin-top: 10px; }

.msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, #e8d5ff 0%, #c5b3f9 100%);
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  align-self: flex-end;
}
.msg-row.sent .msg-avatar { display: none; }
.msg-avatar.hidden { visibility: hidden; }

/* ── Bubble ─────────────────────────────────────────────────────────────── */

.bubble {
  max-width: 72%;
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 16px;
  line-height: 1.45;
  word-break: break-word;
  position: relative;
}

.msg-row.recv .bubble {
  background: #e5e5ea;
  color: #1c1c1e;
  border-bottom-left-radius: 5px;
}

.msg-row.sent .bubble {
  background: #007aff;
  color: #fff;
  border-bottom-right-radius: 5px;
  margin-left: auto;
}

.bubble.recall-notice {
  background: transparent;
  color: #8e8e93;
  font-size: 13px;
  font-style: italic;
  padding: 4px 0;
}

/* ── Typing Indicator ────────────────────────────────────────────────────── */

.typing-row {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  animation: msgIn 0.15s ease;
}

.typing-bubble {
  background: #e5e5ea;
  border-radius: 18px;
  border-bottom-left-radius: 5px;
  padding: 12px 16px;
  display: flex;
  gap: 5px;
  align-items: center;
}

.typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #8e8e93;
  animation: typingBounce 1.2s ease-in-out infinite;
}
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); }
  30%           { transform: translateY(-6px); }
}

/* ── Toast ─────────────────────────────────────────────────────────────── */

.toast {
  position: fixed;
  top: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(-8px);
  background: rgba(0,0,0,0.72);
  color: #fff;
  font-size: 14px;
  padding: 8px 18px;
  border-radius: 20px;
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
  z-index: 999;
  white-space: nowrap;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── Meme Toggle ───────────────────────────────────────────────────────── */

.meme-toggle {
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  flex-shrink: 0;
  padding: 4px 8px;
  border-radius: 12px;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.meme-toggle input[type="checkbox"] {
  display: none;
}
.meme-toggle-label {
  font-size: 12px;
  color: #999;
  padding: 2px 8px;
  border-radius: 10px;
  background: #e8e8e8;
  transition: all 0.2s;
}
.meme-toggle input:checked + .meme-toggle-label {
  color: #fff;
  background: #007aff;
}

/* ── Export Button ──────────────────────────────────────────────────────── */

.export-btn {
  background: none;
  border: none;
  font-size: 20px;
  color: #007aff;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 8px;
  -webkit-tap-highlight-color: transparent;
  line-height: 1;
  flex-shrink: 0;
}
.export-btn:active { opacity: 0.5; }

/* ── Input Bar ───────────────────────────────────────────────────────────── */

.input-bar {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 14px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid rgba(0,0,0,0.08);
  flex-shrink: 0;
}

.input-wrap {
  flex: 1;
  background: #f2f2f7;
  border-radius: 20px;
  padding: 8px 14px;
  min-height: 38px;
  display: flex;
  align-items: center;
}

.input-field {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-family: inherit;
  font-size: 16px;
  color: #1c1c1e;
  resize: none;
  max-height: 120px;
  line-height: 1.4;
  overflow-y: auto;
}
.input-field::placeholder { color: #c7c7cc; }

.send-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #007aff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.15s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}
.send-btn:disabled { background: #c7c7cc; cursor: default; }
.send-btn:not(:disabled):active { transform: scale(0.92); }
.send-btn svg { width: 18px; height: 18px; fill: #fff; }

/* ── Emoji bubble ─────────────────────────────────────────────────────── */

.emoji-bubble {
  background: transparent !important;
  padding: 0 !important;
  border-radius: 12px !important;
  overflow: hidden;
  max-width: 55%;
}

.emoji-img {
  display: block;
  max-width: 120px;
  max-height: 120px;
  width: auto;
  height: auto;
  border-radius: 12px;
  object-fit: contain;
}

/* ── Rich Card — Article ────────────────────────────────────────────── */

.card-article {
  background: #fff;
  border-radius: 4px;
  overflow: hidden;
  max-width: 280px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.card-article:active { opacity: 0.8; }
.card-article-body { padding: 12px; }

.card-article-title {
  font-size: 15px;
  font-weight: 600;
  color: #1c1c1e;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: 6px;
}

.card-article-content { display: flex; gap: 8px; align-items: flex-start; }

.card-article-desc {
  flex: 1;
  font-size: 12px;
  color: #8e8e93;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-article-thumb {
  width: 52px; height: 52px;
  border-radius: 3px;
  flex-shrink: 0;
  object-fit: cover;
  background: #f2f2f7;
}

.card-article-thumb-placeholder {
  width: 52px; height: 52px;
  border-radius: 3px;
  flex-shrink: 0;
  background: linear-gradient(135deg, #58d68d, #07c160);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
}

.card-article-footer {
  display: flex; align-items: center; gap: 4px;
  padding: 8px 12px;
  border-top: 0.5px solid rgba(0,0,0,0.06);
  font-size: 12px;
  color: #8e8e93;
}

/* ── Rich Card — Music ─────────────────────────────────────────────── */

.card-music {
  background: #2b2b2b;
  border-radius: 4px;
  overflow: hidden;
  max-width: 280px;
  display: flex;
  align-items: stretch;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.card-music:active { opacity: 0.8; }

.card-music-cover { width: 72px; height: 72px; flex-shrink: 0; overflow: hidden; }
.card-music-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card-music-cover-placeholder {
  width: 100%; height: 100%;
  background: linear-gradient(135deg, #333, #555);
  display: flex; align-items: center; justify-content: center;
  font-size: 28px;
}

.card-music-info {
  flex: 1; padding: 12px;
  display: flex; flex-direction: column; justify-content: center;
  min-width: 0;
}

.card-music-title {
  font-size: 14px; font-weight: 500; color: #fff;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.card-music-artist {
  font-size: 12px; color: #999; margin-top: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.card-music-play {
  width: 36px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.card-music-play::after {
  content: '';
  width: 0; height: 0;
  border-style: solid;
  border-width: 8px 0 8px 14px;
  border-color: transparent transparent transparent #fff;
}

.card-music-source {
  font-size: 12px; color: #8e8e93; margin-top: 4px;
  display: flex; align-items: center; gap: 3px;
}

/* ── Rich Card — Video ────────────────────────────────────────────── */

.card-video {
  border-radius: 4px; overflow: hidden; max-width: 220px;
  cursor: pointer; position: relative;
  -webkit-tap-highlight-color: transparent;
}
.card-video:active { opacity: 0.8; }

.card-video-thumb {
  width: 100%; aspect-ratio: 3 / 4; object-fit: cover;
  display: block; background: #1c1c1e;
}

.card-video-thumb-placeholder {
  width: 100%; aspect-ratio: 3 / 4;
  background: linear-gradient(135deg, #69f0d2, #fe2c55);
  display: flex; align-items: center; justify-content: center;
  font-size: 48px;
}

.card-video-play {
  position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 48px; height: 48px;
  background: rgba(0,0,0,0.5); border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.9);
  display: flex; align-items: center; justify-content: center;
}
.card-video-play::after {
  content: '';
  width: 0; height: 0;
  border-style: solid;
  border-width: 9px 0 9px 16px;
  border-color: transparent transparent transparent #fff;
  margin-left: 3px;
}

.card-video-footer {
  position: absolute; bottom: 0; left: 0; right: 0;
  padding: 24px 10px 8px;
  background: linear-gradient(transparent, rgba(0,0,0,0.7));
  display: flex; align-items: center; gap: 4px;
  font-size: 12px; color: rgba(255,255,255,0.9);
}

/* ══════════════════════════════════════════════════════════════════════════
   Auth Overlay
   ══════════════════════════════════════════════════════════════════════════ */

.auth-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.auth-overlay.hidden { display: none; }

.auth-card {
  width: 100%;
  max-width: 360px;
  text-align: center;
}

.auth-logo { font-size: 48px; margin-bottom: 8px; }

.auth-title {
  font-size: 22px;
  font-weight: 600;
  color: #1c1c1e;
  margin: 0 0 20px;
}

/* ── Auth Tabs ─────────────────────────────────────────────────────────── */

.auth-tabs {
  display: flex;
  margin-bottom: 20px;
  border-bottom: 1px solid #e5e5ea;
}

.auth-tab {
  flex: 1;
  text-align: center;
  padding: 10px 0;
  font-size: 14px;
  font-weight: 500;
  color: #8e8e93;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.auth-tab.active {
  color: #007aff;
  border-bottom-color: #007aff;
}
.auth-tab.disabled {
  color: #c7c7cc;
  cursor: default;
}

/* ── Auth Panels ───────────────────────────────────────────────────────── */

.auth-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: left;
}
.auth-panel.hidden { display: none; }

/* ── Auth Input ────────────────────────────────────────────────────────── */

.auth-input {
  width: 100%;
  padding: 12px 16px;
  border: 1.5px solid #d1d1d6;
  border-radius: 12px;
  font-size: 16px;
  font-family: inherit;
  color: #1c1c1e;
  background: #f2f2f7;
  outline: none;
  transition: border-color 0.15s, background 0.15s;
}
.auth-input:focus {
  border-color: #007aff;
  background: #fff;
}
.auth-input.error {
  border-color: #ff3b30;
  background: #fff5f5;
}
.auth-input.valid {
  border-color: #34c759;
  background: #f0fff4;
}

/* ── Field hints ───────────────────────────────────────────────────────── */

.auth-field-hint {
  font-size: 12px;
  color: #8e8e93;
  min-height: 16px;
  margin-top: -4px;
  padding-left: 4px;
}
.auth-field-hint.error {
  color: #ff3b30;
}

.auth-note {
  font-size: 12px;
  color: #8e8e93;
  text-align: center;
  margin: 4px 0 0;
}

/* ── Auth Submit ───────────────────────────────────────────────────────── */

.auth-submit {
  width: 100%;
  padding: 12px;
  border: none;
  border-radius: 12px;
  background: #007aff;
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: opacity 0.15s;
}
.auth-submit:active { opacity: 0.7; }
.auth-submit:disabled { background: #c7c7cc; cursor: default; }

.auth-switch {
  margin-top: 14px;
  font-size: 14px;
  color: #8e8e93;
  text-align: center;
}
.auth-switch a {
  color: #007aff;
  text-decoration: none;
  font-weight: 500;
}
.auth-switch a:active { opacity: 0.5; }

/* ── SMS row ───────────────────────────────────────────────────────────── */

.sms-row {
  display: flex;
  gap: 8px;
}

.sms-code-input { flex: 1; }

.sms-code-btn {
  flex-shrink: 0;
  min-width: 110px;
  padding: 0 14px;
  border: none;
  border-radius: 12px;
  background: #007aff;
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  transition: opacity 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.sms-code-btn:active { opacity: 0.7; }
.sms-code-btn:disabled { background: #c7c7cc; cursor: default; }

/* ── CAPTCHA container ─────────────────────────────────────────────────── */

.captcha-container {
  min-height: 0;
}

/* ── Password wrap (input + eye toggle) ────────────────────────────────── */

.password-wrap {
  position: relative;
  display: flex;
  align-items: center;
}
.password-wrap.hidden { display: none; }

.password-wrap .auth-input {
  padding-right: 44px;
}

.password-toggle {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  opacity: 0.4;
  transition: opacity 0.15s;
}
.password-toggle:hover,
.password-toggle.active { opacity: 0.8; }

.eye-icon {
  width: 20px;
  height: 20px;
  fill: #8e8e93;
}

/* ── Password rules ────────────────────────────────────────────────────── */

.password-rules {
  list-style: none;
  padding: 0;
  margin: -4px 0 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.password-rules.hidden { display: none; }

.password-rule {
  font-size: 12px;
  color: #8e8e93;
  padding-left: 18px;
  position: relative;
}
.password-rule::before {
  content: '○';
  position: absolute;
  left: 0;
  font-size: 10px;
}
.password-rule.pass {
  color: #34c759;
}
.password-rule.pass::before {
  content: '✓';
  color: #34c759;
  font-weight: 700;
}
.password-rule.fail {
  color: #ff3b30;
}
.password-rule.fail::before {
  content: '✗';
  color: #ff3b30;
  font-weight: 700;
}

/* ── WeChat coming soon ────────────────────────────────────────────────── */

.wechat-coming-soon {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 0;
  color: #c7c7cc;
}
.wechat-coming-soon .wechat-icon {
  font-size: 48px;
  margin-bottom: 12px;
  opacity: 0.4;
}
.wechat-coming-soon p {
  font-size: 14px;
  margin: 0;
}
