*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg-primary: #000000;
  --bg-secondary: #1a1a1a;
  --bg-tertiary: #262626;
  --bg-hover: #1a1a1a;
  --text-primary: #f5f5f5;
  --text-secondary: #a8a8a8;
  --text-tertiary: #737373;
  --border-color: #363636;
  --sent-bubble: #3797f0;
  --sent-bubble-gradient: linear-gradient(135deg, #5851DB 0%, #833AB4 50%, #C13584 100%);
  --received-bubble: #262626;
  --accent: #0095f6;
  --accent-hover: #1877f2;
  --error: #ed4956;
  --instagram-gradient: linear-gradient(45deg, #f09433 0%, #e6683c 25%, #dc2743 50%, #cc2366 75%, #bc1888 100%);
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ============ LOCK SCREEN ============ */
#lock-screen {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-primary);
  backdrop-filter: blur(20px);
}

.lock-container {
  text-align: center;
  padding: 40px;
  width: 350px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 12px;
}

.lock-logo {
  margin-bottom: 16px;
  animation: lockPulse 2s ease-in-out infinite;
}

@keyframes lockPulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.05); opacity: 0.8; }
}

.lock-title {
  font-family: 'Inter', sans-serif;
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -0.5px;
  background: var(--instagram-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 8px;
}

.lock-subtitle {
  color: var(--text-secondary);
  font-size: 14px;
  margin-bottom: 24px;
}

.input-wrapper {
  position: relative;
  margin-bottom: 12px;
}

#password-input {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
}

#password-input:focus {
  border-color: var(--accent);
}

#password-input::placeholder {
  color: var(--text-tertiary);
}

#login-btn {
  width: 100%;
  padding: 12px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}

#login-btn:hover {
  background: var(--accent-hover);
}

#login-btn:active {
  transform: scale(0.98);
}

.error-msg {
  color: var(--error);
  font-size: 13px;
  margin-top: 12px;
  min-height: 20px;
  transition: opacity 0.3s;
}

/* ============ APP LAYOUT ============ */
.app-layout {
  display: flex;
  height: 100vh;
  width: 100%;
}

/* ============ SIDEBAR ============ */
.sidebar {
  width: 395px;
  min-width: 395px;
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  background: var(--bg-primary);
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  height: 60px;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
}

.sidebar-username {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.chevron-icon {
  color: var(--text-primary);
}

.new-msg-btn {
  background: none;
  border: none;
  color: var(--text-primary);
  cursor: pointer;
  padding: 8px;
  border-radius: 50%;
  transition: background 0.2s;
}

.new-msg-btn:hover {
  background: var(--bg-tertiary);
}

.sidebar-tabs {
  display: flex;
  padding: 0 24px;
  gap: 8px;
  margin-bottom: 8px;
}

.tab-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  padding: 8px 16px;
  border-radius: 10px;
  transition: all 0.2s;
}

.tab-btn.active {
  background: var(--text-primary);
  color: var(--bg-primary);
}

.tab-btn:not(.active):hover {
  background: var(--bg-tertiary);
}

.conversation-list {
  flex: 1;
  overflow-y: auto;
}

.conversation-item {
  display: flex;
  align-items: center;
  padding: 8px 24px;
  cursor: pointer;
  transition: background 0.15s;
  gap: 12px;
}

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

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

.conv-avatar {
  flex-shrink: 0;
}

.avatar-placeholder {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, #5851DB, #C13584);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 600;
  color: white;
  text-transform: uppercase;
}

.conv-info {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

.conv-name {
  font-size: 15px;
  font-weight: 500;
}

.conv-preview {
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

/* ============ CHAT AREA ============ */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg-primary);
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  height: 60px;
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

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

.chat-header .avatar-placeholder {
  width: 44px;
  height: 44px;
  font-size: 16px;
}

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

.chat-header-name {
  font-size: 16px;
  font-weight: 600;
}

.chat-header-status {
  font-size: 12px;
  color: var(--text-secondary);
}

.chat-header-actions {
  display: flex;
  gap: 4px;
}

.header-btn {
  background: none;
  border: none;
  color: var(--text-primary);
  cursor: pointer;
  padding: 8px;
  border-radius: 50%;
  transition: background 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.header-btn:hover {
  background: var(--bg-tertiary);
}

/* ============ MESSAGES ============ */
.messages-container {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 20px 20px 8px;
  scroll-behavior: auto;
}

.messages-container::-webkit-scrollbar {
  width: 6px;
}

.messages-container::-webkit-scrollbar-track {
  background: transparent;
}

.messages-container::-webkit-scrollbar-thumb {
  background: var(--bg-tertiary);
  border-radius: 3px;
}

.messages-loading {
  display: flex;
  justify-content: center;
  padding: 40px;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--bg-tertiary);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

#messages-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.date-separator {
  text-align: center;
  padding: 16px 0;
  position: relative;
}

.date-separator span {
  display: inline-block;
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
  padding: 4px 12px;
}

.message-row {
  display: flex;
  flex-direction: column;
  max-width: 65%;
  padding: 1px 0;
}

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

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

.message-bubble {
  padding: 8px 12px;
  border-radius: 18px;
  max-width: 100%;
  word-wrap: break-word;
  overflow-wrap: break-word;
  font-size: 14px;
  line-height: 1.4;
  position: relative;
}

.message-row.sent .message-bubble {
  background: var(--sent-bubble);
  color: white;
  border-bottom-right-radius: 4px;
}

.message-row.received .message-bubble {
  background: var(--received-bubble);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
}

/* Consecutive message styling */
.message-row.sent + .message-row.sent .message-bubble {
  border-top-right-radius: 4px;
}

.message-row.received + .message-row.received .message-bubble {
  border-top-left-radius: 4px;
}

.message-bubble.media-bubble {
  padding: 4px;
  background: transparent !important;
  overflow: hidden;
}

.message-media {
  border-radius: 14px;
  overflow: hidden;
  cursor: pointer;
}

.message-media img {
  display: block;
  max-width: 236px;
  max-height: 320px;
  border-radius: 14px;
  object-fit: cover;
  transition: opacity 0.2s;
}

.message-media img:hover {
  opacity: 0.9;
}

.message-media video {
  display: block;
  max-width: 236px;
  max-height: 320px;
  border-radius: 14px;
  object-fit: contain;
  background: #000;
}

.message-text {
  white-space: pre-wrap;
}

.reply-context {
  font-size: 12px;
  color: var(--text-secondary);
  padding: 6px 10px;
  margin-bottom: 2px;
  border-left: 2px solid var(--text-tertiary);
  border-radius: 4px;
  background: rgba(255,255,255,0.05);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.message-reaction {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  font-size: 12px;
  padding: 2px 6px;
  background: var(--bg-tertiary);
  border-radius: 14px;
  border: 2px solid var(--bg-primary);
  margin-top: -6px;
  position: relative;
  z-index: 1;
  cursor: default;
}

.message-reaction .reaction-emoji {
  font-size: 14px;
}

.message-timestamp {
  font-size: 11px;
  color: var(--text-tertiary);
  padding: 2px 4px;
  margin-top: 2px;
  opacity: 0;
  transition: opacity 0.2s;
  white-space: nowrap;
}

.message-row:hover .message-timestamp {
  opacity: 1;
}

.message-timestamp.always-show {
  opacity: 1;
}

/* Reaction notification messages */
.reaction-notification {
  font-style: italic;
  color: var(--text-secondary);
  font-size: 13px;
}

.message-row.reaction-msg .message-bubble {
  background: transparent;
  padding: 4px 8px;
}

/* ============ CHAT INPUT ============ */
.chat-input-area {
  display: flex;
  align-items: center;
  padding: 10px 20px 20px;
  gap: 8px;
  border-top: 1px solid transparent;
}

.message-input {
  flex: 1;
  padding: 10px 16px;
  background: transparent;
  border: 1px solid var(--border-color);
  border-radius: 22px;
  color: var(--text-primary);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
}

.message-input:focus {
  border-color: var(--text-secondary);
}

.message-input::placeholder {
  color: var(--text-tertiary);
}

.input-btn {
  background: none;
  border: none;
  color: var(--text-primary);
  cursor: pointer;
  padding: 4px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s, transform 0.1s;
  flex-shrink: 0;
}

.input-btn:hover {
  color: var(--text-secondary);
}

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

/* ============ LIGHTBOX ============ */
.lightbox {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: rgba(0, 0, 0, 0.95);
  align-items: center;
  justify-content: center;
  cursor: zoom-out;
  animation: fadeIn 0.2s;
}

.lightbox.active {
  display: flex;
}

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

.lightbox-close {
  position: absolute;
  top: 16px;
  right: 24px;
  background: none;
  border: none;
  color: white;
  font-size: 32px;
  cursor: pointer;
  z-index: 1;
  padding: 8px;
  line-height: 1;
  transition: transform 0.2s;
}

.lightbox-close:hover {
  transform: scale(1.1);
}

.lightbox-content img {
  max-width: 90vw;
  max-height: 90vh;
  object-fit: contain;
  border-radius: 4px;
  cursor: default;
}

.lightbox-content video {
  max-width: 90vw;
  max-height: 90vh;
  object-fit: contain;
  border-radius: 4px;
  cursor: default;
}

/* ============ RESPONSIVE ============ */
@media (max-width: 768px) {
  .sidebar {
    display: none;
  }

  .chat-area {
    width: 100%;
  }

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

/* ============ EMOJI FIX ============ */
.emoji-only .message-bubble {
  background: transparent !important;
  font-size: 40px;
  padding: 0;
  line-height: 1.2;
}

/* ============ SCROLL TO BOTTOM BTN ============ */
.scroll-bottom-btn {
  position: absolute;
  bottom: 80px;
  right: 28px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 10;
  transition: transform 0.2s, opacity 0.2s;
  box-shadow: 0 2px 12px rgba(0,0,0,0.4);
}

.scroll-bottom-btn.visible {
  display: flex;
}

.scroll-bottom-btn:hover {
  transform: scale(1.1);
  background: var(--bg-secondary);
}

/* ============ IMAGE LOAD PLACEHOLDER ============ */
.media-loading {
  width: 200px;
  height: 200px;
  background: var(--bg-tertiary);
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: mediaPulse 1.5s ease-in-out infinite;
}

@keyframes mediaPulse {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 0.3; }
}

/* Chat start notice */
.chat-start-notice {
  text-align: center;
  padding: 32px 20px;
}

.chat-start-avatar {
  margin: 0 auto 12px;
}

.chat-start-avatar .avatar-placeholder {
  width: 96px;
  height: 96px;
  font-size: 36px;
  margin: 0 auto;
}

.chat-start-name {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 4px;
}

.chat-start-subtitle {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 16px;
}

.chat-start-btn {
  background: transparent;
  border: none;
  color: var(--accent);
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}
