/* === Reset & Base === */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --text-primary: #000000;
  --text-secondary: #8E8E93;
  --danger: #e74c3c;
  /* Unified glass effect tokens */
  --glass-blur: blur(40px) saturate(180%);
  --glass-bg: rgba(255, 255, 255, 0.82);
  --glass-border: 0.5px solid rgba(255, 255, 255, 0.6);
  --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.12), inset 0 0.5px 0 rgba(255, 255, 255, 0.8);
  --glass-overlay-blur: blur(8px);
}

/* 全屏毛玻璃遮罩顶部白色渐变：与系统状态栏白色融合 */
.modal-overlay::before,
.todo-modal-overlay::before,
.todo-action-overlay::before,
.msg-action-overlay::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: calc(env(safe-area-inset-top, 12px) + 64px);
  background: linear-gradient(
    to bottom,
    rgba(255, 255, 255, 1) 0%,
    rgba(255, 255, 255, 0.85) 30%,
    rgba(255, 255, 255, 0.5) 55%,
    rgba(255, 255, 255, 0.2) 78%,
    rgba(255, 255, 255, 0) 100%
  );
  pointer-events: none;
  z-index: 1;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 16px;
  color: var(--text-primary);
  background: linear-gradient(135deg, #1e3a5f 0%, #2563eb 40%, #3b82f6 60%, #1e40af 100%);
  background-attachment: fixed;
  overflow: hidden;
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
}

.hidden { display: none !important; }

/* === Pages === */
.page {
  display: none;
  width: 100%;
  height: 100dvh;
}
.page.active {
  display: flex;
}
#page-chat {
  background: #FFFFFF;
}

/* === Login Page === */
.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(248, 250, 252, 0.6);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.login-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
}

.ecg-wrap {
  width: 180px;
  height: 36px;
  overflow: hidden;
  opacity: 0;
  animation: ecgFadeIn 0.8s ease 0.2s forwards;
  -webkit-mask-image: linear-gradient(to right, transparent 0%, black 15%, black 85%, transparent 100%);
  mask-image: linear-gradient(to right, transparent 0%, black 15%, black 85%, transparent 100%);
}

@keyframes ecgFadeIn {
  to { opacity: 1; }
}

.login-ecg {
  width: 360px;
  height: 36px;
  animation: ecgScroll 2.4s linear infinite;
}

.ecg-line {
  stroke: #2563eb;
  filter: drop-shadow(0 0 3px rgba(37, 99, 235, 0.5));
}

@keyframes ecgScroll {
  from { transform: translateX(0); }
  to   { transform: translateX(-50%); }
}

.login-title-anim {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: 4px;
  color: #2563eb;
  display: flex;
  gap: 2px;
}

.login-title-anim span {
  display: inline-block;
  animation: letterPop 0.4s cubic-bezier(0.22, 1, 0.36, 1) forwards;
  transform-origin: center bottom;
  opacity: 0;
  transform: translateY(10px);
}

@keyframes letterPop {
  0%   { transform: translateY(10px); opacity: 0; }
  60%  { transform: translateY(-2px); opacity: 1; }
  100% { transform: translateY(0); opacity: 1; }
}

.login-input-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: 260px;
  opacity: 0;
  animation: inputSlideUp 0.5s cubic-bezier(0.22, 1, 0.36, 1) 0.5s forwards;
}

@keyframes inputSlideUp {
  from { opacity: 0; transform: translateY(24px) scale(0.95); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.login-pw-input {
  width: 100%;
  padding: 11px 16px;
  border: 1px solid rgba(37, 99, 235, 0.15);
  border-radius: 10px;
  font-size: 15px;
  background: rgba(255, 255, 255, 0.55);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: var(--text-primary);
  text-align: center;
  letter-spacing: 2px;
  transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
  animation: inputPulse 2s ease-in-out 1.2s 2;
}

.login-pw-input:focus {
  outline: none;
  border-color: #2563eb;
  background: rgba(255, 255, 255, 0.75);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
  animation: none;
}

@keyframes inputPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(37, 99, 235, 0); }
  50%      { box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.12); }
}

.login-pw-input.shake {
  animation: inputShake 0.4s ease;
}

@keyframes inputShake {
  0%, 100% { transform: translateX(0); }
  20%      { transform: translateX(-8px); }
  40%      { transform: translateX(8px); }
  60%      { transform: translateX(-5px); }
  80%      { transform: translateX(5px); }
}

.login-error {
  font-size: 13px;
  color: var(--danger);
  min-height: 18px;
  text-align: center;
}

/* === PIN Pad & Lock Screen === */
/* === iOS 26 Lock Screen === */
.lock-screen {
  position: fixed;
  inset: 0;
  z-index: 10001;
  background:
    linear-gradient(to bottom, #ffffff 0%, transparent 12%),
    linear-gradient(145deg, #e8ecf4 0%, #d5dce8 30%, #c9d6e8 60%, #dfe5ef 100%);
  display: flex;
  align-items: center;
  justify-content: center;
}

#page-pin-setup .login-overlay {
  background: linear-gradient(145deg, #e8ecf4 0%, #d5dce8 30%, #c9d6e8 60%, #dfe5ef 100%);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

.pin-title {
  font-size: 17px;
  font-weight: 400;
  color: #1C1C1E;
  letter-spacing: 0.3px;
  text-align: center;
}

.pin-dots {
  display: flex;
  gap: 16px;
  justify-content: center;
}

.pin-dots span {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  border: 1.5px solid rgba(0, 0, 0, 0.3);
  background: transparent;
  transition: background 0.15s, border-color 0.15s;
}

.pin-dots span.filled {
  background: #1C1C1E;
  border-color: #1C1C1E;
}

.pin-pad {
  display: grid;
  grid-template-columns: repeat(3, 80px);
  gap: 14px;
  justify-content: center;
}

.pin-key {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.45);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08), inset 0 1px 0 rgba(255, 255, 255, 0.6);
  font-size: 34px;
  font-weight: 300;
  color: #1C1C1E;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0;
  transition: background 0.1s;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}

.pin-key .pin-sub {
  font-size: 9px;
  font-weight: 500;
  letter-spacing: 2px;
  color: rgba(0, 0, 0, 0.4);
  margin-top: -2px;
  text-transform: uppercase;
}

.pin-key:active {
  background: rgba(255, 255, 255, 0.7);
}

.pin-key.pin-delete {
  background: transparent;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  box-shadow: none;
  color: #1C1C1E;
}

.pin-key.pin-delete:active {
  background: rgba(0, 0, 0, 0.06);
}

.pin-key.pin-empty {
  visibility: hidden;
  background: transparent;
  box-shadow: none;
}

.pin-dots.shake {
  animation: inputShake 0.4s ease;
}

.pin-dots.shake span.filled {
  background: #ff453a;
  border-color: #ff453a;
}

.lock-screen .login-error,
#page-pin-setup .login-error {
  color: #ff453a;
}

.lock-screen .login-content,
#page-pin-setup .login-content {
  gap: 28px;
}

/* === Identity Page === */
.identity-container {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(248, 250, 252, 0.6);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  gap: 20px;
  padding: 24px;
}

.identity-title {
  color: #2563eb;
  font-size: 24px;
  font-weight: 600;
}

.identity-options {
  display: flex;
  gap: 20px;
}

.identity-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  width: 160px;
  height: 160px;
  background: white;
  border: none;
  border-radius: 16px;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  box-shadow: 0 4px 16px rgba(0,0,0,0.1);
}

.identity-btn:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 24px rgba(0,0,0,0.18);
}

.identity-btn:active {
  transform: translateY(-2px);
}

.identity-name {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
}

@media (max-width: 767px) {
  .identity-options {
    flex-direction: column;
    gap: 16px;
    width: 100%;
    max-width: 280px;
  }

  .identity-btn {
    width: 100%;
    height: 140px;
  }
}

/* === Avatars === */
.avatar-placeholder {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background-size: cover;
  background-position: center;
  font-size: 0;
  color: transparent;
  flex-shrink: 0;
}

.claire-avatar { background-image: url('/public/assets/claire.png'); }
.sunshine-avatar { background-image: url('/public/assets/sunshine.png'); }

/* Mirror partner avatar in header so they face towards the chat */
#partner-avatar { transform: scaleX(-1); }

/* === Chat Layout — iOS 26 Liquid Glass base === */
.chat-layout {
  width: 100%;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  position: relative;
  background: #FFFFFF;
}

/* === iOS 26: Profile Card (floating overlay with gradient fade) === */
.chat-profile-card {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: env(safe-area-inset-top, 4px) 0 36px;
  gap: 2px;
  background: linear-gradient(
    to bottom,
    rgba(255, 255, 255, 1) 0%,
    rgba(255, 255, 255, 1) 4px,
    rgba(255, 255, 255, 0.8) 25%,
    rgba(255, 255, 255, 0.4) 60%,
    rgba(255, 255, 255, 0.1) 85%,
    rgba(255, 255, 255, 0) 100%
  );
  pointer-events: none;
}

.chat-profile-card > * {
  pointer-events: auto;
}

.avatar-lg {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background-size: cover;
  background-position: center;
  position: relative;
  z-index: 2;
  box-shadow:
    0 4px 16px rgba(0, 0, 0, 0.10),
    inset 0 1px 0 rgba(255, 255, 255, 0.6);
}

.profile-name {
  font-size: 16px;
  font-weight: 600;
  color: #000;
  margin-top: -8px;
  position: relative;
  z-index: 1;
  padding: 3px 14px;
  border-radius: 18px;
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.06),
              inset 0 1px 0 rgba(255, 255, 255, 0.7);
  cursor: pointer;
}

/* === Status Dot (green/yellow/gray) === */
.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 4px;
  vertical-align: middle;
  position: relative;
  top: -1px;
  transition: background 0.3s;
}

.status-dot.online {
  background: #34C759;
  box-shadow: 0 0 4px rgba(52, 199, 89, 0.5);
}

.status-dot.recent {
  background: #FFCC00;
  box-shadow: 0 0 4px rgba(255, 204, 0, 0.5);
}

.status-dot.offline {
  background: #C7C7CC;
}

/* === Last-seen in switch modal === */
.switch-last-seen {
  font-size: 12px;
  color: #8E8E93;
  text-align: center;
  padding: 0 0 12px;
  min-height: 18px;
}

/* === WebSocket Connection Status Overlay === */
.ws-status-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(255, 255, 255, 0.55);
  backdrop-filter: var(--glass-overlay-blur);
  -webkit-backdrop-filter: var(--glass-overlay-blur);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.3s;
}

.ws-status-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}
body.keyboard-open .ws-status-overlay {
  opacity: 0 !important;
  pointer-events: none !important;
}

.ws-status-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 32px 48px;
  border-radius: 20px;
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  box-shadow: var(--glass-shadow);
}

.ws-status-spinner {
  width: 28px;
  height: 28px;
  border: 3px solid rgba(0, 0, 0, 0.1);
  border-top-color: #007AFF;
  border-radius: 50%;
  animation: wsSpinnerSpin 0.8s linear infinite;
}

.ws-status-text {
  font-size: 15px;
  font-weight: 500;
  color: #1C1C1E;
}

@keyframes wsSpinnerSpin {
  to { transform: rotate(360deg); }
}

/* === iOS 26: Floating Glass Action Buttons === */
.floating-actions {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 12px);
  right: 16px;
  display: flex;
  gap: 10px;
  z-index: 20;
}

.glass-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 0.5px solid rgba(0, 0, 0, 0.04);
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  box-shadow:
    0 2px 12px rgba(0, 0, 0, 0.12),
    0 0 0 0.5px rgba(0, 0, 0, 0.06),
    inset 0 1px 0 rgba(255, 255, 255, 0.8);
  color: #1C1C1E;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s, box-shadow 0.15s;
  touch-action: manipulation;
  padding: 0;
}

.glass-btn:active {
  transform: scale(0.92);
  background: rgba(255, 255, 255, 0.85);
  box-shadow:
    0 1px 6px rgba(0, 0, 0, 0.10),
    0 0 0 0.5px rgba(0, 0, 0, 0.06),
    inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

.icon-btn {
  background: none;
  border: none;
  color: #007AFF;
  cursor: pointer;
  padding: 8px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  touch-action: manipulation;
}

.icon-btn:hover {
  background: rgba(0, 122, 255, 0.06);
}

/* === Full-screen Overlay Panels (Search / Favorites) === */
.overlay-panel {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: #FFFFFF;
  display: flex;
  flex-direction: column;
  animation: overlaySlideIn 0.25s ease;
}

@keyframes overlaySlideIn {
  from { transform: translateX(100%); }
  to { transform: translateX(0); }
}

@keyframes overlaySlideOut {
  from { transform: translateX(0); }
  to { transform: translateX(100%); }
}

.overlay-header {
  display: flex;
  align-items: center;
  padding: 10px 16px;
  padding-top: calc(env(safe-area-inset-top, 10px) + 10px);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-bottom: var(--glass-border);
  box-shadow: 0 1px 8px rgba(0, 0, 0, 0.04);
  color: #000;
  min-height: 44px;
  gap: 8px;
}


/* === Overlay Tabs (Liquid Glass pill switcher) === */
.overlay-tabs {
  display: flex;
  flex: 1;
  background: rgba(142, 142, 147, 0.12);
  border-radius: 9px;
  padding: 2px;
}

.overlay-tab {
  flex: 1;
  padding: 6px 0;
  border: none;
  background: transparent;
  font-size: 13px;
  font-weight: 500;
  color: #8E8E93;
  border-radius: 7px;
  cursor: pointer;
  transition: all 0.25s ease;
  touch-action: manipulation;
}

.overlay-tab.active {
  background: rgba(255, 255, 255, 0.85);
  color: #000;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08),
              inset 0 1px 0 rgba(255, 255, 255, 0.9);
}

.overlay-tab-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.overlay-back {
  color: #007AFF;
  flex-shrink: 0;
}

.overlay-search-bar {
  padding: 8px 16px;
  flex-shrink: 0;
}

.overlay-search-bar input {
  width: 100%;
  padding: 9px 16px;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  outline: none;
  background: rgba(118, 118, 128, 0.12);
  color: #000;
}

.overlay-search-bar input:focus {
  background: rgba(118, 118, 128, 0.18);
}

.overlay-search-bar input::placeholder {
  color: #8E8E93;
}

.overlay-results {
  flex: 1;
  overflow-y: auto;
  padding: 8px 12px;
}

.overlay-result-item {
  padding: 12px 14px;
  border-bottom: 0.5px solid rgba(60, 60, 67, 0.12);
  cursor: pointer;
  border-radius: 10px;
  transition: background 0.15s;
  color: #000;
  margin-bottom: 2px;
}

.overlay-result-item:hover {
  background: rgba(118, 118, 128, 0.08);
}

.overlay-result-item:active {
  background: rgba(118, 118, 128, 0.12);
}

.overlay-result-sender {
  font-size: 12px;
  font-weight: 600;
  color: #007AFF;
  margin-bottom: 3px;
}

.overlay-result-content {
  font-size: 14px;
  color: #000;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.overlay-result-time {
  font-size: 11px;
  color: #8E8E93;
  margin-top: 3px;
}

.overlay-result-fav {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.overlay-unfav-btn {
  background: none;
  border: none;
  color: #FFD60A;
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
  touch-action: manipulation;
}

.overlay-no-results {
  text-align: center;
  padding: 40px 20px;
  color: #8E8E93;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.search-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(0,0,0,0.1);
  border-top-color: #8E8E93;
  border-radius: 50%;
  display: inline-block;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* === iOS 26 Long-press Action Overlay === */
.msg-action-overlay {
  position: fixed;
  inset: 0;
  z-index: 150;
  background: rgba(0, 0, 0, 0.25);
  backdrop-filter: var(--glass-overlay-blur);
  -webkit-backdrop-filter: var(--glass-overlay-blur);
  animation: actionFadeIn 0.2s ease;
}

@keyframes actionFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.msg-action-menu {
  position: fixed;
  z-index: 152;
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-radius: 14px;
  padding: 4px 0;
  min-width: 200px;
  box-shadow: var(--glass-shadow);
  animation: actionMenuPop 0.22s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes actionMenuPop {
  from { opacity: 0; transform: scale(0.85); }
  to { opacity: 1; transform: scale(1); }
}

.msg-action-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 16px;
  border: none;
  background: none;
  font-size: 16px;
  color: #000;
  cursor: pointer;
  touch-action: manipulation;
  transition: background 0.12s;
}

.msg-action-item:active {
  background: rgba(0, 0, 0, 0.06);
}

.msg-action-item + .msg-action-item {
  border-top: 0.5px solid rgba(60, 60, 67, 0.1);
}

.msg-action-item svg {
  flex-shrink: 0;
  color: #000;
}

.msg-action-danger {
  color: #FF3B30;
}
.msg-action-danger svg {
  color: #FF3B30;
}

@keyframes bubblePopOut {
  from { transform: scale(1); }
  50% { transform: scale(1.04); }
  to { transform: scale(1.02); }
}

/* === Favorite star on message === */
.message-fav-star {
  color: #FFD60A;
  font-size: 10px;
  margin-left: 4px;
}

/* === Chat Messages — White background === */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 0 10px 4px;
  padding-top: calc(env(safe-area-inset-top, 0px) + 100px);
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: transparent;
}

.load-more-area {
  text-align: center;
  padding: 8px 0;
}

.btn-load-more {
  background: #FFFFFF;
  border: none;
  padding: 8px 20px;
  border-radius: 18px;
  font-size: 13px;
  color: #007AFF;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-load-more:hover {
  background: #E5E5EA;
}

.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid #E5E5EA;
  border-top-color: #007AFF;
  border-radius: 50%;
  animation: wsSpinnerSpin 0.8s linear infinite;
  margin: 0 auto;
}


/* === Date Separator === */
.date-separator {
  text-align: center;
  padding: 12px 0 4px;
}

.date-separator span {
  background: transparent;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  padding: 4px 12px;
  border-radius: 12px;
  font-size: 12px;
  color: #8E8E93;
  border: none;
  font-weight: 500;
}

/* === Time Separator (iMessage-style group timestamp) === */
.time-separator {
  text-align: center;
  padding: 6px 0 2px;
  font-size: 11px;
  color: #8E8E93;
  font-weight: 400;
}

/* === Message Row — iMessage style === */
.message-row {
  display: flex;
  align-items: flex-end;
  max-width: 70%;
  animation: fadeIn 0.2s ease;
  position: relative;
}

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

.message-row.sent {
  align-self: flex-end;
  flex-direction: row-reverse;
  margin-right: 8px;
}

.message-row.received {
  align-self: flex-start;
  margin-left: 8px;
}

/* Grouping: larger gap when sender changes */
.message-row.group-start {
  margin-top: 8px;
}

/* === Message Bubble — iMessage === */
.message-bubble {
  padding: 7px 12px;
  border-radius: 18px;
  position: relative;
  max-width: 100%;
  min-width: 0;
  word-wrap: break-word;
  overflow-wrap: break-word;
  overflow: visible;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.message-row.sent .message-bubble {
  background: #007AFF;
  color: #FFFFFF;
  border: none;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

.message-row.received .message-bubble {
  background: #E5E5EA;
  color: #000000;
  border: none;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

/* === Bubble Tails — iMessage signature feature === */
/* Sent tail - bottom right */
.message-row.sent.tail .message-bubble {
  border-bottom-right-radius: 3px;
}
.message-row.sent.tail .message-bubble::after {
  content: '';
  position: absolute;
  bottom: 0;
  right: -7px;
  height: 18px;
  width: 18px;
  background-color: #007AFF;
  border-bottom-left-radius: 14px;
}
.message-row.sent.tail .message-bubble::before {
  content: '';
  position: absolute;
  bottom: 0;
  right: -9px;
  width: 9px;
  height: 18px;
  background-color: #FFFFFF;
  border-bottom-left-radius: 9px;
  z-index: 1;
}

/* Received tail - bottom left */
.message-row.received.tail .message-bubble {
  border-bottom-left-radius: 3px;
}
.message-row.received.tail .message-bubble::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: -7px;
  height: 18px;
  width: 18px;
  background-color: #E5E5EA;
  border-bottom-right-radius: 14px;
}
.message-row.received.tail .message-bubble::before {
  content: '';
  position: absolute;
  bottom: 0;
  left: -9px;
  width: 9px;
  height: 18px;
  background-color: #FFFFFF;
  border-bottom-right-radius: 9px;
  z-index: 1;
}

/* === Stacked grouping corners — iMessage signature look === */
/* Sent: non-tail (not last in group) → reduced bottom-right */
.message-row.sent:not(.tail) .message-bubble {
  border-bottom-right-radius: 5px;
}
/* Sent: continuation (not first in group) → reduced top-right */
.message-row.sent:not(.group-start) .message-bubble {
  border-top-right-radius: 5px;
}
/* Received: non-tail → reduced bottom-left */
.message-row.received:not(.tail) .message-bubble {
  border-bottom-left-radius: 5px;
}
/* Received: continuation → reduced top-left */
.message-row.received:not(.group-start) .message-bubble {
  border-top-left-radius: 5px;
}

/* === AI Message Bubble === */
.message-row.ai .message-bubble {
  background: #E8DEF8;
  color: #1C1C1E;
}

/* AI tail override */
.message-row.ai.tail .message-bubble {
  border-bottom-left-radius: 3px;
}
.message-row.ai.tail .message-bubble::after {
  background-color: #E8DEF8;
}

/* AI Markdown rendering */
.ai-markdown .md-p {
  margin: 2px 0;
  line-height: 1.6;
}
.ai-markdown .md-p + .md-p {
  margin-top: 4px;
}
.ai-markdown br {
  display: block;
  content: "";
  margin: 4px 0;
}
.ai-markdown strong {
  font-weight: 600;
}
.ai-markdown em {
  font-style: italic;
}
.ai-markdown .md-code-inline {
  background: rgba(124, 58, 237, 0.1);
  color: #7C3AED;
  padding: 1px 5px;
  border-radius: 4px;
  font-family: 'SF Mono', 'Menlo', 'Consolas', monospace;
  font-size: 0.9em;
}
.ai-markdown .md-code-block {
  background: #1e1e2e;
  color: #cdd6f4;
  padding: 10px 12px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 6px 0;
  font-family: 'SF Mono', 'Menlo', 'Consolas', monospace;
  font-size: 0.85em;
  line-height: 1.5;
  white-space: pre;
}
.ai-markdown .md-list {
  margin: 4px 0;
  padding-left: 20px;
}
.ai-markdown .md-list li {
  margin: 2px 0;
  line-height: 1.5;
}
.ai-markdown .md-heading {
  font-weight: 600;
  margin: 6px 0 2px;
}
.ai-markdown h2.md-heading { font-size: 1.1em; }
.ai-markdown h3.md-heading { font-size: 1.05em; }
.ai-markdown h4.md-heading { font-size: 1em; }

/* Partner typing indicator */
#partner-typing-row .typing-dots span {
  background: #8E8E93;
}

/* AI typing indicator */
.ai-typing-bubble {
  padding: 7px 12px !important;
  min-height: 36px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.ai-thinking-text {
  font-size: 13px;
  color: #7C3AED;
  white-space: nowrap;
}

.typing-dots {
  display: flex;
  gap: 4px;
  align-items: center;
}

.typing-dots span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #9E8EC0;
  animation: typingBounce 1.4s ease-in-out infinite;
}

.typing-dots span:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-dots span:nth-child(3) {
  animation-delay: 0.4s;
}

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

/* === Message Text === */
.message-bubble * {
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.message-text {
  font-size: 17px;
  line-height: 1.35;
  min-height: 18px;
}

.message-link {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
  word-break: break-all;
}

.link-preview-card {
  display: block;
  margin-top: 8px;
  padding: 10px 12px;
  background: rgba(0,0,0,0.06);
  border-radius: 10px;
  border-left: 3px solid rgba(0,0,0,0.15);
  text-decoration: none;
  color: inherit;
  cursor: pointer;
}
.message-row.sent .link-preview-card {
  background: rgba(255,255,255,0.15);
  border-left-color: rgba(255,255,255,0.4);
}
.link-preview-title {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.3;
  margin-bottom: 3px;
}
.link-preview-summary {
  font-size: 12px;
  opacity: 0.75;
  line-height: 1.4;
  margin-bottom: 4px;
}
.link-preview-domain {
  font-size: 11px;
  opacity: 0.5;
}

/* === Image Bubble — iOS 26 iMessage: all corners equally rounded, no tail === */
.message-bubble.image-bubble {
  padding: 0;
  overflow: hidden;
  border-radius: 20px !important;
  background: transparent;
}

/* Hide tail on image bubbles */
.message-row.tail .image-bubble::before,
.message-row.tail .image-bubble::after {
  display: none;
}

/* Hide tail on sticker bubbles */
.message-row.tail .sticker-bubble::before,
.message-row.tail .sticker-bubble::after {
  display: none;
}

/* === Message Image === */
.message-image {
  max-width: 280px;
  max-height: 360px;
  height: auto;
  border-radius: 0;
  cursor: pointer;
  display: block;
  object-fit: cover;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  pointer-events: none;
}

/* === Message Meta — hidden in iMessage style (time shown via separators) === */
.message-meta {
  display: none;
}

.message-time {
  font-size: 11px;
}

/* Sent: white semi-transparent time on blue bg */
.message-row.sent .message-time {
  color: rgba(255, 255, 255, 0.6);
}

/* Received: gray time on light bg */
.message-row.received .message-time {
  color: #8E8E93;
}

/* === Read Status === */
.message-read-status {
  font-size: 14px;
  line-height: 1;
  display: inline-flex;
}

/* === Reply Bar (above input) === */
.reply-bar {
  display: flex;
  align-items: center;
  padding: 8px 14px;
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-top: 0.5px solid rgba(0, 0, 0, 0.08);
}

.reply-bar-content {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  overflow: hidden;
}

.reply-bar-line {
  width: 3px;
  height: 32px;
  border-radius: 2px;
  background: #007AFF;
  flex-shrink: 0;
}

.reply-bar-text {
  display: flex;
  flex-direction: column;
  gap: 1px;
  overflow: hidden;
}

.reply-bar-sender {
  font-size: 12px;
  font-weight: 600;
  color: #007AFF;
}

.reply-bar-preview {
  font-size: 13px;
  color: #8E8E93;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.reply-bar-close {
  background: none;
  border: none;
  font-size: 20px;
  color: #8E8E93;
  cursor: pointer;
  padding: 4px 8px;
  line-height: 1;
}

/* === Quoted Message (inside bubble) === */
.bubble-reply {
  padding: 4px 8px;
  margin-bottom: 4px;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: flex-start;
  gap: 6px;
}

.message-row.sent .bubble-reply {
  background: rgba(255, 255, 255, 0.18);
}

.message-row.received .bubble-reply {
  background: rgba(0, 0, 0, 0.05);
}

.bubble-reply-line {
  width: 2px;
  min-height: 20px;
  border-radius: 1px;
  flex-shrink: 0;
}

.message-row.sent .bubble-reply-line { background: rgba(255, 255, 255, 0.5); }
.message-row.received .bubble-reply-line { background: #007AFF; }

.bubble-reply-body {
  overflow: hidden;
}

.bubble-reply-sender {
  font-size: 11px;
  font-weight: 600;
}

.message-row.sent .bubble-reply-sender { color: rgba(255, 255, 255, 0.7); }
.message-row.received .bubble-reply-sender { color: #007AFF; }

.bubble-reply-text {
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}

.message-row.sent .bubble-reply-text { color: rgba(255, 255, 255, 0.6); }
.message-row.received .bubble-reply-text { color: #8E8E93; }

.read-receipt {
  font-size: 12px;
  font-weight: 400;
  color: #8E8E93;
  text-align: right;
  padding: 2px 14px 2px 0;
  letter-spacing: -0.1px;
}

/* === Input Area — iOS 26 style === */
.chat-input-area {
  display: flex;
  align-items: center;
  gap: 6px;
  position: relative;
  padding: 8px 10px;
  padding-bottom: calc(env(safe-area-inset-bottom, 8px) + 12px);
  background: #FFFFFF;
  border-top: none;
  box-shadow: none;
  touch-action: manipulation;
}

.attach-btn {
  color: #8E8E93;
  width: 36px;
  height: 36px;
  padding: 0;
  position: relative;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(142, 142, 147, 0.12);
  border-radius: 50%;
}

.attach-btn:hover {
  color: #636366;
  background: rgba(142, 142, 147, 0.18);
}

.attach-btn:active {
  background: rgba(142, 142, 147, 0.28);
}

.hidden-input {
  position: absolute;
  width: 0;
  height: 0;
  opacity: 0;
  pointer-events: none;
}

/* === Input Wrapper (holds textarea + @AI button) === */
.input-wrapper {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  border: 1px solid rgba(60, 60, 67, 0.18);
  border-radius: 20px;
  padding: 0 4px 0 4px;
  transition: border-color 0.2s;
}

.input-wrapper:focus-within {
  border-color: rgba(60, 60, 67, 0.28);
}

/* === @AI Toggle Button (inside input) === */
.ai-toggle-btn {
  flex-shrink: 0;
  background: none;
  border: none;
  font-size: 12px;
  font-weight: 600;
  color: rgba(142, 142, 147, 0.3);
  cursor: pointer;
  padding: 0 4px 0 1px;
  transition: color 0.2s;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

.ai-toggle-btn.active {
  color: #7C3AED;
}

#message-input {
  -webkit-appearance: none;
  appearance: none;
  flex: 1;
  min-width: 0;
  margin: 0;
  padding: 7px 4px 9px 8px;
  border: none;
  border-radius: 0;
  font-size: 17px;
  line-height: 1.35;
  resize: none;
  outline: none;
  max-height: 120px;
  overflow-y: auto;
  font-family: inherit;
  background: transparent;
  color: #000;
  box-shadow: none;
  touch-action: manipulation;
}

#message-input::-webkit-scrollbar { display: none; }
#message-input { scrollbar-width: none; -ms-overflow-style: none; }

#message-input::placeholder {
  color: #8E8E93;
}

.send-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #007AFF;
  color: #FFFFFF;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: none;
  cursor: pointer;
  transition: transform 0.15s, opacity 0.15s;
  box-shadow: none;
}

.send-btn:hover {
  background: #0066D6;
}

.send-btn:active {
  transform: scale(0.9);
}

.send-btn.hidden-btn {
  transform: scale(0);
  opacity: 0;
  width: 0;
  padding: 0;
  margin: 0;
  overflow: hidden;
}

/* === Lightbox === */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.lightbox-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.9);
}

.lightbox-content {
  position: relative;
  z-index: 1;
  max-width: 95vw;
  max-height: 95vh;
}

.lightbox-close {
  position: fixed;
  top: env(safe-area-inset-top, 12px);
  right: 12px;
  z-index: 1001;
  background: rgba(255, 255, 255, 0.2);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: none;
  color: white;
  font-size: 28px;
  cursor: pointer;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  line-height: 1;
}

#lightbox-img {
  max-width: 95vw;
  max-height: 90vh;
  object-fit: contain;
  border-radius: 4px;
  transform-origin: center center;
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-user-drag: none;
}

#lightbox-progress {
  position: fixed;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%);
  width: 44px;
  height: 44px;
  z-index: 10;
  filter: drop-shadow(0 1px 4px rgba(0,0,0,0.4));
}

#lightbox-progress.hidden {
  display: none;
}

/* === Responsive === */
@media (min-width: 768px) {
  .chat-messages {
    padding: 0 10% 8px;
    padding-top: calc(env(safe-area-inset-top, 0px) + 100px);
  }

  .message-row {
    max-width: 55%;
  }

  .message-image {
    max-width: 320px;
    max-height: 420px;
  }

  .chat-input-area {
    padding: 8px 10%;
    padding-bottom: calc(env(safe-area-inset-bottom, 8px) + 12px);
  }
}

@media (min-width: 1400px) {
  .chat-messages {
    padding: 0 18% 8px;
    padding-top: calc(env(safe-area-inset-top, 0px) + 100px);
  }

  .message-row {
    max-width: 50%;
  }

  .message-image {
    max-width: 380px;
    max-height: 480px;
  }

  .chat-input-area {
    padding: 8px 18%;
    padding-bottom: calc(env(safe-area-inset-bottom, 8px) + 12px);
  }
}

/* === Scrollbar === */
.chat-messages::-webkit-scrollbar,
.overlay-results::-webkit-scrollbar {
  width: 6px;
}

.chat-messages::-webkit-scrollbar-track,
.overlay-results::-webkit-scrollbar-track {
  background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb,
.overlay-results::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.15);
  border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover,
.overlay-results::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.25);
}

/* === Upload Progress Overlay === */
.upload-progress-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 20px;
}

.upload-progress-ring {
  width: 44px;
  height: 44px;
  transform: rotate(-90deg);
}

.upload-progress-circle {
  stroke-linecap: round;
  transition: stroke-dashoffset 0.15s ease;
}

/* === Sending spinner (text message in-flight) === */
.msg-sending-spinner {
  display: inline-block;
  width: 10px;
  height: 10px;
  border: 1.5px solid rgba(255,255,255,0.4);
  border-top-color: rgba(255,255,255,0.9);
  border-radius: 50%;
  animation: msgSpin 0.7s linear infinite;
  flex-shrink: 0;
  margin-left: 5px;
  margin-bottom: 1px;
}

.msg-sending-text {
  display: inline;
}

.message-bubble:has(.msg-sending-spinner) {
  display: flex;
  align-items: center;
}

@keyframes msgSpin {
  to { transform: rotate(360deg); }
}

/* === Image loading placeholder === */
.message-image.image-placeholder {
  background: rgba(118, 118, 128, 0.12) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='28' height='28' viewBox='0 0 24 24' fill='none' stroke='rgba(142,142,147,0.6)' stroke-width='2'%3E%3Cpath d='M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4'/%3E%3Cpolyline points='7 10 12 15 17 10'/%3E%3Cline x1='12' y1='15' x2='12' y2='3'/%3E%3C/svg%3E") no-repeat center;
  border-radius: 0;
  object-position: -9999px;
}

/* Fallback size for old images without stored dimensions */
.message-image.image-placeholder:not([style*="width"]) {
  width: 200px;
  height: 150px;
}

/* === Custom Modal (Toast / Alert) === */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 10002;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: var(--glass-overlay-blur);
  -webkit-backdrop-filter: var(--glass-overlay-blur);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: modalFadeIn 0.25s ease;
}

@keyframes modalFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-card {
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: var(--glass-border);
  border-radius: 16px;
  padding: 28px 24px 20px;
  max-width: 320px;
  width: 85%;
  text-align: center;
  box-shadow: var(--glass-shadow);
  animation: modalSlideUp 0.3s ease;
}

@keyframes modalSlideUp {
  from { opacity: 0; transform: translateY(20px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto 14px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 122, 255, 0.1);
  color: #007AFF;
}

.modal-title {
  font-size: 17px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.modal-body {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.5;
  margin-bottom: 20px;
}

.modal-btn {
  width: 100%;
  padding: 11px 0;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}

.modal-btn:active {
  transform: scale(0.97);
}

.modal-btn-primary {
  background: #007AFF;
  color: white;
}

.modal-btn-primary:hover {
  background: #0066D6;
}

/* === Unread Messages Floating Button (Top) === */
.btn-unread-top {
  position: absolute;
  top: 52px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 16px;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: none;
  border-radius: 20px;
  color: white;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  z-index: 20;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.2);
  animation: unreadSlideDown 0.25s ease;
  touch-action: manipulation;
}

.btn-unread-top:active {
  transform: translateX(-50%) scale(0.95);
}

@keyframes unreadSlideDown {
  from { opacity: 0; transform: translateX(-50%) translateY(-10px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* === New Messages Floating Button (Bottom) === */
.btn-new-msg {
  position: absolute;
  bottom: 72px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 16px;
  background: #007AFF;
  border: none;
  border-radius: 20px;
  color: white;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  z-index: 20;
  box-shadow: 0 2px 12px rgba(0, 122, 255, 0.4);
  animation: unreadSlideUp 0.25s ease;
  touch-action: manipulation;
}

.btn-new-msg:active {
  transform: translateX(-50%) scale(0.95);
}

@keyframes unreadSlideUp {
  from { opacity: 0; transform: translateX(-50%) translateY(10px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* === Image Preview === */
.image-preview {
  display: flex;
  align-items: center;
  padding: 8px 12px;
  background: rgba(249, 249, 249, 0.94);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-top: 0.5px solid rgba(60, 60, 67, 0.29);
  gap: 10px;
}

.image-preview-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  flex: 1;
  padding-top: 8px;
  overflow: visible;
}

.image-preview-item {
  position: relative;
  flex-shrink: 0;
}

.image-preview-item img {
  width: 72px;
  height: 72px;
  border-radius: 8px;
  object-fit: cover;
  display: block;
}

.image-preview-item-del {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: rgba(0,0,0,0.5);
  border: none;
  color: white;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.image-preview img {
  max-height: 80px;
  max-width: 140px;
  border-radius: 8px;
  object-fit: cover;
}

.preview-cancel {
  background: rgba(0, 0, 0, 0.35);
  border: none;
  color: white;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  touch-action: manipulation;
}

.preview-cancel:active {
  background: rgba(0, 0, 0, 0.5);
}

/* Drag-over highlight on the whole page */
body.drag-over .chat-input-area,
body.drag-over .image-preview {
  outline: 2px dashed #007AFF;
  outline-offset: -2px;
  background: rgba(0, 122, 255, 0.06);
}

/* === Privacy Mask === */
.privacy-mask {
  position: fixed;
  inset: 0;
  z-index: 20000;
  background: rgba(255, 255, 255, 0.3);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.privacy-mask.visible {
  opacity: 1;
  pointer-events: auto;
}

/* === Switch Account Modal === */
.switch-card {
  background: #fff;
  border-radius: 22px;
  padding: 28px 24px 24px;
  text-align: center;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.18);
  animation: modalSlideUp 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}

.switch-options {
  display: flex;
  gap: 20px;
  justify-content: center;
}

.switch-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: 130px;
  padding: 22px 0 18px;
  background: #f8f9fb;
  border: 2.5px solid transparent;
  border-radius: 18px;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.2s, box-shadow 0.2s, background 0.2s;
}

.switch-btn:active {
  transform: scale(0.96);
}

.switch-btn .avatar-placeholder {
  width: 56px;
  height: 56px;
  font-size: 24px;
}

.switch-avatar-wrap {
  position: relative;
  display: inline-block;
}

.switch-status-dot {
  position: absolute;
  top: 0;
  left: 0;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  border: 2.5px solid #fff;
  background: #C7C7CC;
}
.switch-status-dot.online  { background: #34C759; }
.switch-status-dot.recent  { background: #FF9500; }
.switch-status-dot.offline { background: #C7C7CC; }

.switch-btn .claire-avatar,
.identity-btn .claire-avatar { transform: scaleX(-1); }

.switch-btn span {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}

.switch-btn-info {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  margin-top: -4px;
}

.switch-btn-info span {
  font-size: 10px;
  color: #AEAEB2;
  font-weight: 400;
  text-align: center;
  line-height: 1.3;
}

.switch-btn-offline {
  font-size: 9px !important;
  color: #C7C7CC !important;
  font-style: italic;
}

.switch-btn.active {
  border-color: #007AFF;
  background: rgba(0, 122, 255, 0.04);
  box-shadow: 0 0 0 4px rgba(0, 122, 255, 0.1);
}

.switch-btn-lastseen {
  font-size: 10px;
  color: #AEAEB2;
  margin-top: -6px;
}

.switch-logout {
  margin-top: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  background: #f8f9fb;
  color: #9ca3af;
  font-size: 13px;
  cursor: pointer;
  padding: 10px 0;
  width: 100%;
  border-radius: 12px;
  transition: background 0.15s, color 0.15s;
}

.switch-logout:active {
  background: #fee2e2;
  color: #ef4444;
}

/* === Toast === */
.toast-msg {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.75);
  color: white;
  padding: 8px 20px;
  border-radius: 20px;
  font-size: 14px;
  z-index: 9999;
  animation: toastIn 0.25s ease;
  pointer-events: none;
}

.toast-fade {
  opacity: 0;
  transition: opacity 0.3s ease;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(10px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* === Todo Feature === */
#todo-view {
  overflow-y: auto;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.todo-toolbar {
  display: flex;
  gap: 8px;
  padding: 10px 14px;
  flex-shrink: 0;
}

.todo-toolbar-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 7px 14px;
  border: none;
  border-radius: 10px;
  background: rgba(0, 122, 255, 0.1);
  color: #007AFF;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
  touch-action: manipulation;
}

.todo-toolbar-btn:active {
  background: rgba(0, 122, 255, 0.2);
}

.todo-groups-container {
  flex: 1;
  overflow-y: auto;
  padding: 0 10px 20px;
}

.todo-group {
  margin-bottom: 10px;
}

.todo-group-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  transition: background 0.15s;
}

.todo-group-header:active {
  background: rgba(240, 240, 244, 0.9);
}

.todo-arrow {
  transition: transform 0.2s;
  flex-shrink: 0;
  color: #8E8E93;
}

.todo-arrow.collapsed {
  transform: rotate(-90deg);
}

.todo-group-name {
  flex: 1;
  font-size: 15px;
  font-weight: 600;
  color: #000;
}

.todo-group-count {
  font-size: 12px;
  color: #8E8E93;
  font-weight: 500;
}

.todo-group-items {
  padding: 4px 0 0 4px;
}

.todo-empty-hint {
  text-align: center;
  padding: 16px;
  color: #C7C7CC;
  font-size: 13px;
}

.todo-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  margin: 3px 0;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.9);
  transition: background 0.15s, opacity 0.2s;
}

.todo-item:active {
  background: rgba(240, 240, 244, 0.95);
}

.todo-item.done {
  opacity: 0.5;
}

.todo-item.done .todo-text {
  text-decoration: line-through;
  color: #8E8E93;
}

.todo-checkbox {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid #C7C7CC;
  background: transparent;
  flex-shrink: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background 0.15s, border-color 0.15s;
  touch-action: manipulation;
}

.todo-checkbox.checked {
  background: #007AFF;
  border-color: #007AFF;
}

.todo-content {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 6px;
}

.todo-text {
  flex: 1;
  font-size: 15px;
  color: #000;
  line-height: 1.35;
  word-break: break-word;
}

.todo-creator-avatar {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background-size: cover;
  background-position: center;
}

/* Todo toolbar secondary button */
.todo-toolbar-btn-secondary {
  background: rgba(142, 142, 147, 0.1);
  color: #636366;
}

.todo-toolbar-btn-secondary:active {
  background: rgba(142, 142, 147, 0.18);
}

/* === Todo Modal (shared by add/edit/rename/delete) === */
.todo-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 10002;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: var(--glass-overlay-blur);
  -webkit-backdrop-filter: var(--glass-overlay-blur);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 18vh;
  animation: modalFadeIn 0.25s ease;
}

.todo-modal-overlay.closing {
  animation: todoModalFadeOut 0.2s ease forwards;
}

.todo-modal-overlay.closing .todo-modal-card {
  animation: todoModalCardOut 0.2s ease forwards;
}

@keyframes todoModalFadeOut {
  to { opacity: 0; }
}

@keyframes todoModalCardOut {
  to { opacity: 0; transform: translateY(10px) scale(0.97); }
}

.todo-modal-card {
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: var(--glass-border);
  border-radius: 20px;
  padding: 28px 24px 22px;
  max-width: 320px;
  width: 85%;
  box-shadow: var(--glass-shadow);
  animation: modalSlideUp 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}

.todo-modal-compact {
  text-align: center;
}

.todo-modal-title {
  font-size: 17px;
  font-weight: 600;
  color: #1C1C1E;
  text-align: center;
  margin-bottom: 20px;
}

.todo-modal-body {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-bottom: 24px;
}

.todo-modal-label {
  font-size: 12px;
  font-weight: 600;
  color: #8E8E93;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: -8px;
}

.todo-modal-message {
  font-size: 14px;
  color: #8E8E93;
  line-height: 1.5;
  margin-bottom: 20px;
}

.todo-modal-input {
  width: 100%;
  padding: 12px 16px;
  border: none;
  border-radius: 14px;
  font-size: 16px;
  font-family: inherit;
  outline: none;
  background: rgba(118, 118, 128, 0.08);
  color: #000;
  transition: background 0.2s, box-shadow 0.2s;
}

.todo-modal-input:focus {
  background: rgba(118, 118, 128, 0.14);
  box-shadow: 0 0 0 3.5px rgba(0, 122, 255, 0.15);
}

.todo-modal-input::placeholder {
  color: #C7C7CC;
}

/* Group pills */
.todo-group-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.todo-group-pill {
  padding: 7px 16px;
  border: none;
  border-radius: 20px;
  background: rgba(118, 118, 128, 0.08);
  color: #636366;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  touch-action: manipulation;
}

.todo-group-pill.active {
  background: #007AFF;
  color: #fff;
  box-shadow: 0 2px 10px rgba(0, 122, 255, 0.35);
}

.todo-group-pill:active {
  transform: scale(0.95);
}

/* Modal buttons — full-width stacked for cleaner look */
.todo-modal-btns {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.todo-modal-btn {
  width: 100%;
  padding: 13px 0;
  border: none;
  border-radius: 14px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  touch-action: manipulation;
}

.todo-modal-btn:active {
  transform: scale(0.97);
}

.todo-modal-btn:disabled {
  opacity: 0.5;
}

.todo-modal-btn.primary {
  background: #007AFF;
  color: #fff;
}

.todo-modal-btn.primary:active {
  background: #0066D6;
}

.todo-modal-btn.secondary {
  background: transparent;
  color: #007AFF;
}

.todo-modal-btn.secondary:active {
  background: rgba(0, 122, 255, 0.06);
}

.todo-modal-btn.danger {
  background: #FF3B30;
  color: #fff;
}

.todo-modal-btn.danger:active {
  background: #E63329;
}

/* === Todo Action Sheet (iOS style) === */
.todo-action-overlay {
  position: fixed;
  inset: 0;
  z-index: 10002;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: var(--glass-overlay-blur);
  -webkit-backdrop-filter: var(--glass-overlay-blur);
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  padding: 0 8px calc(env(safe-area-inset-bottom, 8px) + 8px);
  animation: modalFadeIn 0.25s ease;
}

.todo-action-sheet {
  width: 100%;
  max-width: 400px;
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-radius: 14px;
  overflow: hidden;
  box-shadow: var(--glass-shadow);
  animation: todoSheetSlideUp 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}

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

.todo-action-btn {
  display: block;
  width: 100%;
  padding: 17px;
  border: none;
  background: none;
  font-size: 18px;
  color: #007AFF;
  cursor: pointer;
  text-align: center;
  touch-action: manipulation;
  transition: background 0.12s;
  -webkit-user-select: none;
  user-select: none;
}

.todo-action-btn:active {
  background: rgba(0, 0, 0, 0.06);
}

.todo-action-btn + .todo-action-btn {
  border-top: 0.5px solid rgba(60, 60, 67, 0.1);
}

.todo-action-btn.danger {
  color: #FF3B30;
}

.todo-action-btn.cancel {
  font-weight: 600;
}

.todo-action-cancel-wrap {
  width: 100%;
  max-width: 400px;
  margin-top: 8px;
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-radius: 14px;
  overflow: hidden;
  box-shadow: var(--glass-shadow);
  animation: todoSheetSlideUp 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}

/* === Sticker Button === */
.sticker-btn {
  color: #8E8E93;
  width: 36px;
  height: 36px;
  padding: 0;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(142, 142, 147, 0.12);
  border-radius: 50%;
  transition: background 0.15s, color 0.15s;
}
.sticker-btn:hover { background: rgba(142, 142, 147, 0.18); }
.sticker-btn:active { background: rgba(142, 142, 147, 0.28); }
.sticker-btn.active {
  background: rgba(0, 122, 255, 0.12);
  color: #007AFF;
}

/* === Sticker Panel === */
.sticker-panel {
  position: fixed;
  left: 0;
  transform: none;
  bottom: 0;
  width: 100%;
  max-width: 480px;
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-top: var(--glass-border);
  border-radius: 0 20px 0 0;
  box-shadow: 0 -4px 24px rgba(0,0,0,0.08);
  padding: 12px 10px;
  padding-bottom: calc(env(safe-area-inset-bottom, 8px) + 12px);
  animation: stickerPanelIn 0.22s cubic-bezier(0.22, 1, 0.36, 1);
  z-index: 200;
  pointer-events: auto;
}
.sticker-panel.hidden { display: none; }

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

.sticker-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.sticker-item {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  background: transparent;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.12s, transform 0.1s;
  touch-action: manipulation;
  padding: 4px;
}
.sticker-item:hover  { transform: scale(1.15); }
.sticker-item:active { transform: scale(0.95); }

.sticker-item-meme {
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
}

.sticker-item-meme img {
  display: none;
}

/* === Sticker Suggest Bar — image item === */
.sticker-suggest-item img {
  width: 32px;
  height: 32px;
  object-fit: contain;
  display: block;
}

/* === Sticker Suggest Bar === */
.sticker-suggest {
  position: fixed;
  bottom: 0;
  left: 10px;
  display: flex;
  gap: 4px;
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: var(--glass-border);
  border-radius: 14px;
  box-shadow: var(--glass-shadow);
  padding: 6px 8px;
  animation: stickerPanelIn 0.18s cubic-bezier(0.22, 1, 0.36, 1);
  z-index: 110;

.sticker-suggest-item {
  font-size: 26px;
  background: transparent;
  border: none;
  border-radius: 8px;
  padding: 4px 6px;
  cursor: pointer;
  transition: background 0.12s, transform 0.1s;
  touch-action: manipulation;
}
.sticker-suggest-item:hover  { background: rgba(0,0,0,0.06); }
.sticker-suggest-item:active { background: rgba(0,0,0,0.1); transform: scale(0.88); }
.sticker-suggest-item.selected { background: rgba(0,0,0,0.08); transform: scale(1.15); }

/* === Sticker Message Bubble === */
.message-sticker {
  font-size: 64px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
  margin-bottom: 6px;
  user-select: none;
  flex-shrink: 0;
}

