/* Sidebar */
.sidebar {
  width: 360px;
  min-width: 320px;
  height: 100%;
  display: flex;
  flex-direction: column;
  position: relative;
  z-index: 10;
}

.sidebar-header {
  padding: 16px 20px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sidebar-title {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: var(--bg-input);
  color: var(--text-blue);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--duration-fast) var(--spring-smooth);
}

.icon-btn:hover {
  background: var(--bg-item-active);
  transform: scale(1.06);
}

.icon-btn:active {
  transform: scale(0.94);
}

.icon-btn svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

#logout-btn {
  color: var(--text-secondary);
}

#logout-btn:hover {
  color: var(--badge-bg);
  background: rgba(255, 59, 48, 0.12);
}

#sound-toggle-btn.muted {
  color: var(--text-secondary);
}

#sound-toggle-btn.muted .sound-icon-on {
  display: none !important;
}

#sound-toggle-btn.muted .sound-icon-off {
  display: block !important;
}

/* Search bar */
.search-bar-container {
  padding: 0 16px 12px;
}

.search-pill {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--bg-input);
  border-radius: 12px;
  border: 1px solid var(--border-glass);
}

.search-pill svg {
  width: 16px;
  height: 16px;
  fill: var(--text-secondary);
  flex-shrink: 0;
}

.search-pill input {
  width: 100%;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-size: 15px;
}

.search-pill input::placeholder {
  color: var(--text-secondary);
}

.search-shortcut-badge {
  font-size: 11px;
  font-family: var(--font-system);
  font-weight: 600;
  color: var(--text-secondary);
  background: var(--bg-item-active);
  padding: 2px 6px;
  border-radius: 6px;
  border: 1px solid var(--border-glass);
  pointer-events: none;
  flex-shrink: 0;
  letter-spacing: 0.5px;
}

/* Conversation list */
.conversations-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.conv-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 14px;
  cursor: pointer;
  transition: background var(--duration-fast) var(--spring-smooth);
  position: relative;
}

.conv-item:hover {
  background: var(--bg-item-hover);
}

.conv-item.active {
  background: var(--bg-item-active);
}

.conv-item-content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.conv-item-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.conv-item-name {
  font-size: 16px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-item-time {
  font-size: 13px;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.conv-item-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.conv-item-preview {
  font-size: 14px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Sidebar footer */
.sidebar-footer {
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-top: 1px solid var(--border-glass);
}

.user-profile-summary {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-profile-info {
  display: flex;
  flex-direction: column;
}

.user-profile-name {
  font-size: 15px;
  font-weight: 600;
}

.user-profile-status {
  font-size: 12px;
  color: var(--status-online);
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Chat pane */
.chat-pane {
  flex: 1;
  height: 100%;
  display: flex;
  flex-direction: column;
  position: relative;
}

/* Chat header */
.chat-header {
  height: 64px;
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 5;
}

.chat-header-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.chat-header-details {
  display: flex;
  flex-direction: column;
}

.chat-header-name {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.3px;
}

.chat-header-subtitle {
  font-size: 12px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 4px;
}

.e2e-lock-icon {
  width: 12px;
  height: 12px;
  fill: var(--status-online);
}

.btn-back {
  display: none;
  margin-right: 4px;
}

/* Messages */
.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.date-divider {
  align-self: center;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  margin: 14px 0 8px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.message-row {
  display: flex;
  flex-direction: column;
  max-width: 68%;
  position: relative;
  content-visibility: auto;
  contain-intrinsic-size: 0 45px;
  animation: bubblePop 0.28s var(--spring-bounce) forwards;
}

@keyframes bubblePop {
  0% {
    opacity: 0;
    transform: scale(0.85) translateY(10px);
  }
  100% {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.message-row.sent {
  align-self: flex-end;
  align-items: flex-end;
}

.message-row.received {
  align-self: flex-start;
  align-items: flex-start;
}

/* Bubbles */
.bubble {
  padding: 10px 16px;
  font-size: 15.5px;
  line-height: 1.38;
  word-break: break-word;
  user-select: text;
  position: relative;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

.message-row.sent .bubble {
  background: linear-gradient(180deg, var(--imessage-blue-start) 0%, var(--imessage-blue-end) 100%);
  color: var(--imessage-blue-text);
  border-radius: 19px 19px 4px 19px;
  box-shadow: 0 2px 8px rgba(0, 122, 255, 0.22);
}

.message-row.received .bubble {
  background: var(--bg-bubble-received);
  color: var(--text-bubble-received);
  border-radius: 19px 19px 19px 4px;
  border: 1px solid rgba(255, 255, 255, 0.06);
}

/* Clustered messages (middle/top of a group from the same sender) */
.message-row.clustered.sent .bubble {
  border-radius: 19px 19px 19px 19px;
}

.message-row.clustered.received .bubble {
  border-radius: 19px 19px 19px 19px;
}

.message-row.clustered {
  margin-bottom: 2px;
}

.message-row.clustered .bubble-meta {
  display: none;
}

/* Authentic iMessage Bubble Tails */
.bubble-tail {
  position: absolute;
  bottom: 0;
  width: 9px;
  height: 16px;
  pointer-events: none;
  z-index: 1;
}

.message-row.sent .bubble-tail {
  right: -7px;
  fill: var(--imessage-blue-end);
}

.message-row.received .bubble-tail {
  left: -7px;
  transform: scaleX(-1);
  fill: var(--bg-bubble-received);
}

.bubble-meta {
  font-size: 11px;
  margin-top: 4px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 4px;
  opacity: 0.9;
}

.delivery-badge {
  display: inline-flex;
  align-items: center;
  color: var(--imessage-blue-start);
}

.delivery-badge.failed {
  color: var(--badge-bg);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-weight: 600;
  transition: transform var(--duration-fast);
}

.delivery-badge.failed:hover {
  transform: scale(1.05);
  text-decoration: underline;
}

.message-row.failed .bubble {
  opacity: 0.92;
  border: 1px solid rgba(255, 59, 48, 0.4);
}

.message-row.sent .bubble-meta {
  justify-content: flex-end;
}

/* Message Content Wrapper & Quick Actions */
.message-content-wrapper {
  display: flex;
  align-items: center;
  gap: 8px;
  position: relative;
  max-width: 100%;
}

.message-row.sent .message-content-wrapper {
  flex-direction: row-reverse;
}

.message-row.received .message-content-wrapper {
  flex-direction: row;
}

.message-actions {
  display: flex;
  align-items: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--duration-fast) var(--spring-smooth), transform var(--duration-fast) var(--spring-smooth);
  transform: scale(0.85);
}

.message-row:hover .message-actions,
.message-actions.active {
  opacity: 1;
  pointer-events: auto;
  transform: scale(1);
}

.message-action-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid var(--border-glass);
  background: var(--bg-modal);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
  transition: all var(--duration-fast) var(--spring-smooth);
}

.message-action-btn:hover {
  color: var(--text-blue);
  background: var(--bg-item-hover);
  transform: scale(1.1);
}

.message-action-btn:active {
  transform: scale(0.92);
}

.message-action-btn svg {
  width: 14px;
  height: 14px;
  fill: currentColor;
}

.message-action-btn.copied {
  color: var(--status-online);
  border-color: rgba(52, 199, 89, 0.3);
}

/* Linkification */
.bubble-link {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
  word-break: break-all;
  transition: opacity var(--duration-fast);
}

.message-row.sent .bubble-link {
  color: #ffffff;
  text-decoration-color: rgba(255, 255, 255, 0.65);
}

.message-row.received .bubble-link {
  color: var(--text-blue);
  text-decoration-color: rgba(0, 122, 255, 0.5);
}

.bubble-link:hover {
  opacity: 0.82;
  text-decoration-color: currentColor;
}

/* Jumbomoji (1-3 big emojis) */
.message-row .bubble.is-emoji-only {
  background: transparent !important;
  box-shadow: none !important;
  border: none !important;
  font-size: 42px;
  line-height: 1.2;
  padding: 4px 6px;
  user-select: text;
}

.message-row .bubble.is-emoji-only .bubble-tail {
  display: none !important;
}

/* Typing indicator */
.typing-bubble {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 12px 18px;
  background: var(--bg-bubble-received);
  border-radius: 19px 19px 19px 4px;
  width: fit-content;
  margin-bottom: 6px;
  animation: bubblePop 0.25s var(--spring-bounce) forwards;
}

.typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-secondary);
  opacity: 0.6;
  animation: typingDot 1.4s infinite ease-in-out;
}

.typing-dot:nth-child(1) { animation-delay: 0s; }
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

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

/* Skeleton Placeholders */
.skeleton-bubble-row {
  display: flex;
  flex-direction: column;
  width: 100%;
  animation: bubblePop 0.28s var(--spring-bounce) forwards;
  margin-bottom: 8px;
}

.skeleton-bubble-row.sent {
  align-items: flex-end;
}

.skeleton-bubble-row.received {
  align-items: flex-start;
}

.skeleton-bubble {
  border-radius: 19px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.skeleton-conv-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 14px;
}

.skeleton-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  flex-shrink: 0;
}

.skeleton-lines {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.skeleton-line {
  height: 12px;
  border-radius: 6px;
}

.skeleton-line.title {
  width: 42%;
}

.skeleton-line.subtitle {
  width: 70%;
}

/* Composer */
.chat-composer {
  padding: 12px 20px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  z-index: 5;
}

.composer-pill {
  flex: 1;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--bg-input);
  border: 1px solid var(--border-glass);
  border-radius: 22px;
  padding: 6px 10px 6px 14px;
  min-height: 44px;
}

.composer-input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-size: 16px;
  line-height: 1.35;
  resize: none;
  max-height: 120px;
  padding: 8px 0;
  field-sizing: content;
}

.composer-input::placeholder {
  color: var(--text-secondary);
}

.btn-send {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: var(--imessage-blue-end);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  margin-bottom: 3px;
  transition: all var(--duration-fast) var(--spring-bounce);
  opacity: 0.4;
  pointer-events: none;
}

.btn-send.active {
  opacity: 1;
  pointer-events: auto;
  transform: scale(1.05);
}

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

.btn-send svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
  transform: translateY(-0.5px);
}

/* Empty state */
.empty-chat-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px;
  gap: 16px;
}

.empty-state-icon {
  width: 80px;
  height: 80px;
  border-radius: 24px;
  background: linear-gradient(135deg, rgba(0, 122, 255, 0.2), rgba(175, 82, 222, 0.2));
  border: 1px solid var(--border-glass);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-blue);
}

.empty-state-icon svg {
  width: 40px;
  height: 40px;
  fill: currentColor;
}

/* Modals & forms */
.auth-card {
  width: 90%;
  max-width: 400px;
  padding: 32px 28px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.auth-header {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.auth-logo {
  width: 60px;
  height: 60px;
  border-radius: 18px;
  background: linear-gradient(135deg, #0a84ff, #007aff);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  box-shadow: 0 8px 20px rgba(0, 122, 255, 0.35);
}

.auth-logo svg {
  width: 32px;
  height: 32px;
  fill: currentColor;
}

.auth-tabs {
  display: flex;
  background: var(--bg-input);
  padding: 3px;
  border-radius: 12px;
  border: 1px solid var(--border-glass);
}

.auth-tab {
  flex: 1;
  padding: 8px 0;
  text-align: center;
  font-size: 14px;
  font-weight: 600;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  border-radius: 9px;
  cursor: pointer;
  transition: all var(--duration-fast);
}

.auth-tab.active {
  background: var(--bg-modal);
  color: var(--text-primary);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  padding-left: 2px;
}

.form-input {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border-glass);
  border-radius: 12px;
  color: var(--text-primary);
  font-size: 15px;
  transition: border-color var(--duration-fast);
}

.form-input:focus {
  border-color: var(--text-blue);
}

.crypto-status-indicator {
  font-size: 12px;
  color: var(--text-secondary);
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

/* User search */
.search-results-list {
  max-height: 260px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 8px;
}

.search-result-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--bg-input);
  border: 1px solid var(--border-glass);
  cursor: pointer;
  transition: all var(--duration-fast);
}

.search-result-item:hover {
  background: var(--bg-item-active);
  border-color: var(--text-blue);
}

/* Floating Scroll-to-Bottom Pill */
.scroll-bottom-pill {
  position: absolute;
  bottom: 74px;
  left: 50%;
  transform: translateX(-50%) translateY(0);
  z-index: 25;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 20px;
  background: var(--bg-modal);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border: 1px solid var(--border-glass);
  border-top: 1px solid var(--border-highlight);
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.16);
  color: var(--text-blue);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--duration-fast) var(--spring-smooth);
  user-select: none;
}

.scroll-bottom-pill:hover {
  transform: translateX(-50%) translateY(-2px) scale(1.03);
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.22);
}

.scroll-bottom-pill:active {
  transform: translateX(-50%) translateY(0) scale(0.96);
}

.scroll-bottom-pill.hidden {
  opacity: 0;
  transform: translateX(-50%) translateY(16px) scale(0.85);
  pointer-events: none;
}

.scroll-bottom-arrow {
  width: 16px;
  height: 16px;
  fill: currentColor;
  flex-shrink: 0;
  transition: transform var(--duration-fast);
}

.scroll-bottom-pill:hover .scroll-bottom-arrow {
  transform: translateY(1.5px);
}

.scroll-bottom-badge {
  background: var(--badge-bg);
  color: #ffffff;
  font-size: 11px;
  font-weight: 700;
  border-radius: 10px;
  padding: 1px 6px;
  min-width: 18px;
  line-height: 15px;
  text-align: center;
}

.scroll-bottom-badge.hidden {
  display: none;
}

/* Responsive */
@media (max-width: 768px) {
  .app-container {
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    position: relative;
    overflow: hidden;
  }

  .sidebar {
    width: 100%;
    position: absolute;
    inset: 0;
    z-index: 20;
    transform: translateX(0);
    transition: transform var(--duration-normal) var(--spring-smooth);
    pointer-events: auto;
  }

  .chat-pane {
    width: 100%;
    position: absolute;
    inset: 0;
    z-index: 30;
    transform: translateX(100%);
    transition: transform var(--duration-normal) var(--spring-smooth), visibility 0s linear var(--duration-normal);
    pointer-events: none;
    visibility: hidden;
  }

  body.chat-active .sidebar {
    transform: translateX(-25%);
    pointer-events: none;
  }

  body.chat-active .chat-pane {
    transform: translateX(0);
    pointer-events: auto;
    visibility: visible;
    transition: transform var(--duration-normal) var(--spring-smooth), visibility 0s linear 0s;
  }

  .btn-back {
    display: flex;
  }

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