html, body {
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  width: 100%;
  margin: 0;
  padding: 0;
}

/* ==================== DM Badge ==================== */
.dm-badge {
  background: #e91e63;
  color: white;
  font-size: 10px;
  font-weight: bold;
  padding: 2px 6px;
  border-radius: 10px;
  margin-left: auto;
  flex-shrink: 0;
  animation: badge-pop 0.3s ease;
}

@keyframes badge-pop {
  0% { transform: scale(0); }
  60% { transform: scale(1.3); }
  100% { transform: scale(1); }
}

/* ==================== Explosion Animation ==================== */
.explosion-particle {
  position: fixed;
  pointer-events: none;
  z-index: 9999;
  font-size: 20px;
  animation: explode 0.6s ease-out forwards;
}

@keyframes explode {
  0% {
    transform: translate(0, 0) scale(1);
    opacity: 1;
  }
  100% {
    transform: translate(var(--tx, 50px), var(--ty, -50px)) scale(0.2);
    opacity: 0;
  }
}

/* ==================== Message Dissolve ==================== */
.message-dissolve {
  animation: dissolve 0.5s ease-out forwards;
}

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

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

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Auth Container */
.auth-container {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  overflow-y: auto;
}

.auth-form-container {
  background: white;
  padding: 40px;
  border-radius: 10px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
  max-width: 400px;
  width: 90%;
}

.auth-form-container h1 {
  text-align: center;
  margin-bottom: 30px;
  color: #333;
  font-size: 28px;
}

.auth-tabs {
  display: flex;
  margin-bottom: 30px;
  border-bottom: 2px solid #eee;
}

.tab-button {
  flex: 1;
  padding: 12px;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  color: #999;
  border-bottom: 3px solid transparent;
  transition: all 0.3s ease;
}

.tab-button.active {
  color: #667eea;
  border-bottom-color: #667eea;
}

.auth-form {
  display: none;
}

.auth-form.active {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.auth-form input {
  padding: 12px;
  border: 1px solid #ddd;
  border-radius: 5px;
  font-size: 14px;
  transition: border-color 0.3s ease;
}

.auth-form input:focus {
  outline: none;
  border-color: #667eea;
  box-shadow: 0 0 5px rgba(102, 126, 234, 0.3);
}

.btn-primary {
  padding: 12px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: none;
  border-radius: 5px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

.error-message {
  color: #d32f2f;
  font-size: 13px;
  text-align: center;
  min-height: 20px;
}

/* Chat Container */
.chat-container {
  width: 100%;
  height: 100%;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: #f5f5f5;
  overflow: hidden;
  position: relative;
}

.chat-header {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 10px 15px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  flex-shrink: 0;
}

.chat-header h1 {
  font-size: 24px;
  margin: 0;
}

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

#currentUser {
  font-weight: 600;
}

.btn-logout {
  background: rgba(255, 255, 255, 0.2);
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.5);
  padding: 8px 16px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.3s ease;
}

.btn-logout:hover {
  background: rgba(255, 255, 255, 0.3);
  border-color: white;
}

.chat-content {
  display: flex;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

/* Toggle sidebar button - hidden on desktop */
.toggle-sidebar-btn {
  display: none;
}

.users-panel {
  width: 200px;
  background: white;
  border-right: 1px solid #ddd;
  padding: 20px;
  overflow-y: auto;
}

.users-panel h3 {
  margin-bottom: 15px;
  color: #333;
  font-size: 14px;
  text-transform: uppercase;
  color: #999;
}

#usersList {
  list-style: none;
}

#usersList li {
  padding: 8px 12px;
  background: #f0f0f0;
  border-radius: 5px;
  margin-bottom: 8px;
  font-size: 14px;
  color: #333;
  display: flex;
  align-items: center;
}

#usersList li::before {
  content: '●';
  color: #4caf50;
  margin-right: 8px;
  font-size: 12px;
}

.messages-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: white;
}

.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.message {
  display: flex;
  margin-bottom: 10px;
  animation: slideIn 0.3s ease;
}

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

.message.own {
  justify-content: flex-end;
}

.message-content {
  max-width: 60%;
  padding: 10px 15px;
  border-radius: 8px;
  word-wrap: break-word;
}

.message.own .message-content {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
}

.message.other .message-content {
  background: #f0f0f0;
  color: #333;
}

.message-username {
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 4px;
  opacity: 0.7;
}

.message-text {
  font-size: 14px;
  line-height: 1.4;
}

.message-encrypted {
  font-style: italic;
  opacity: 0.8;
  font-size: 12px;
  margin-top: 4px;
}

.message-timer {
  font-size: 11px;
  opacity: 0.6;
  margin-top: 2px;
}

.message-input-area {
  padding: 10px 15px;
  background: white;
  border-top: 1px solid #ddd;
  flex-shrink: 0;
}

.encryption-toggle {
  display: flex;
  align-items: center;
  margin-bottom: 12px;
  font-size: 13px;
  color: #666;
}

.encryption-toggle input {
  margin-right: 8px;
  cursor: pointer;
  width: 16px;
  height: 16px;
}

.input-group {
  display: flex;
  gap: 10px;
}

#messageInput {
  flex: 1;
  padding: 12px;
  border: 1px solid #ddd;
  border-radius: 5px;
  font-size: 14px;
  transition: border-color 0.3s ease;
}

#messageInput:focus {
  outline: none;
  border-color: #667eea;
  box-shadow: 0 0 5px rgba(102, 126, 234, 0.3);
}

.btn-send {
  padding: 12px 24px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: none;
  border-radius: 5px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.btn-send:hover {
  transform: translateY(-2px);
  box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

.btn-send:active {
  transform: translateY(0);
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-track {
  background: #f1f1f1;
}

::-webkit-scrollbar-thumb {
  background: #888;
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: #555;
}

/* Responsive */
@media (max-width: 768px) {
  .chat-header h1 {
    font-size: 18px;
  }

  .chat-content {
    flex-direction: column;
  }

  .users-panel {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid #ddd;
    padding: 0;
    flex-shrink: 0;
    overflow: visible;
  }

  .toggle-sidebar-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
    padding: 10px;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    border: none;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    user-select: none;
    z-index: 10;
  }

  .toggle-sidebar-btn #toggleArrow {
    font-size: 10px;
    transition: transform 0.2s;
  }

  .toggle-sidebar-btn.open #toggleArrow {
    transform: rotate(180deg);
  }

  .sidebar-content {
    display: none;
    padding: 8px 10px;
    max-height: 250px;
    overflow-y: auto;
    overflow-x: visible;
    background: white;
  }

  .sidebar-content.showing-suggestions {
    overflow: visible;
  }

  .sidebar-content.open {
    display: block;
  }

  .users-panel h3 {
    margin-bottom: 4px;
    font-size: 12px;
  }

  #usersList {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
  }

  #usersList li {
    padding: 4px 8px;
    font-size: 12px;
    margin-bottom: 0;
  }

  .messages-container {
    padding: 10px;
  }

  .message-content {
    max-width: 85%;
  }

  .header-info {
    flex-direction: row;
    align-items: center;
    gap: 8px;
  }

  #currentUser {
    font-size: 12px;
  }

  .btn-logout {
    padding: 5px 10px;
    font-size: 12px;
  }

  .chat-header {
    padding: 10px 15px;
  }

  .message-input-area {
    padding: 8px 10px;
  }

  .encryption-toggle {
    margin-bottom: 6px;
    font-size: 12px;
  }

  #messageInput {
    padding: 10px;
    font-size: 14px;
  }

  .btn-send {
    padding: 10px 16px;
  }

  .emoji-picker {
    grid-template-columns: repeat(8, 1fr);
  }

  .btn-icon {
    padding: 8px;
    font-size: 18px;
  }

  .image-preview {
    padding: 4px;
    margin-bottom: 4px;
  }

  .image-preview img {
    max-height: 40px;
    max-width: 60px;
  }

  .btn-cancel-img {
    width: 20px;
    height: 20px;
    font-size: 14px;
  }
}

/* ==================== Emoji Picker ==================== */
.emoji-picker {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 4px;
  padding: 10px;
  background: white;
  border: 1px solid #ddd;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  max-height: 200px;
  overflow-y: auto;
  position: absolute;
  bottom: 100%;
  left: 0;
  right: 0;
  margin-bottom: 5px;
  z-index: 100;
}

.emoji-item {
  font-size: 22px;
  cursor: pointer;
  text-align: center;
  padding: 4px;
  border-radius: 4px;
  transition: background 0.15s;
  user-select: none;
}

.emoji-item:hover {
  background: #f0f0f0;
  transform: scale(1.2);
}

/* ==================== Image ==================== */
.btn-icon {
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  padding: 8px 6px;
  border-radius: 5px;
  transition: background 0.2s;
  flex-shrink: 0;
  line-height: 1;
  display: flex;
  align-items: center;
}

.btn-icon:hover {
  background: #f0f0f0;
}

.image-preview {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  background: #f9f9f9;
  border-radius: 8px;
  margin-bottom: 8px;
  border: 1px solid #ddd;
}

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

.btn-cancel-img {
  background: #d32f2f;
  color: white;
  border: none;
  border-radius: 50%;
  width: 24px;
  height: 24px;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.message-image {
  max-width: 100%;
  max-height: 300px;
  border-radius: 8px;
  margin: 6px 0;
  cursor: pointer;
  transition: opacity 0.2s;
}

.message-image:hover {
  opacity: 0.9;
}

.message-input-area {
  position: relative;
}

.ttl-selector {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
  font-size: 13px;
  color: #666;
}

.ttl-selector select {
  padding: 4px 8px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 13px;
  background: white;
  color: #333;
  cursor: pointer;
}

/* ==================== Friends Section ==================== */
#friendsSection {
  margin-top: 15px;
  border-top: 1px solid #eee;
  padding-top: 10px;
}

#friendsSection h3 {
  margin-bottom: 8px;
  color: #999;
  font-size: 12px;
  text-transform: uppercase;
}

/* ==================== Add Friend ==================== */
.add-friend-row {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
}

.add-friend-wrapper {
  flex: 1;
  position: relative;
  min-width: 0;
}

.add-friend-row input {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 12px;
  min-width: 0;
  box-sizing: border-box;
}

.add-friend-row input:focus {
  outline: none;
  border-color: #667eea;
}

.friend-suggestions {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: white;
  border: 1px solid #ddd;
  border-top: none;
  border-radius: 0 0 6px 6px;
  list-style: none;
  padding: 0;
  margin: 0;
  max-height: 150px;
  overflow-y: auto;
  z-index: 1000;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.friend-suggestions li {
  padding: 8px 10px;
  cursor: pointer;
  font-size: 13px;
  transition: background 0.15s;
}

.friend-suggestions li:hover {
  background: linear-gradient(135deg, rgba(102,126,234,0.1), rgba(118,75,162,0.1));
  color: #667eea;
}

.btn-add-friend {
  padding: 4px 10px;
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: white;
  border: none;
  border-radius: 4px;
  font-size: 16px;
  font-weight: bold;
  cursor: pointer;
  flex-shrink: 0;
}

/* ==================== Friends List ==================== */
#friendsList {
  list-style: none;
}

.friend-item {
  display: flex;
  align-items: center;
  padding: 6px 10px;
  border-radius: 6px;
  margin-bottom: 4px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.2s;
  gap: 8px;
}

.friend-item:hover {
  background: #f0f0f0;
}

.friend-item.has-notification {
  background: #fff3e0;
  animation: pulse-notify 1.5s infinite;
}

@keyframes pulse-notify {
  0%, 100% { background: #fff3e0; }
  50% { background: #ffe0b2; }
}

.friend-status-dot {
  font-size: 10px;
  flex-shrink: 0;
}

.friend-item.online .friend-status-dot { color: #4caf50; }
.friend-item.offline .friend-status-dot { color: #bbb; }

.friend-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn-remove-friend {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 12px;
  padding: 2px 4px;
  border-radius: 3px;
  color: #bbb;
  opacity: 0;
  transition: all 0.2s;
}

.friend-item:hover .btn-remove-friend {
  opacity: 1;
}

.btn-remove-friend:hover {
  background: #ffcdd2;
  color: #d32f2f;
}

/* ==================== Clickable Online Users ==================== */
#usersList li.clickable-user {
  cursor: pointer;
  transition: background 0.2s;
}

#usersList li.clickable-user:hover {
  background: #e3e0ff;
}

#usersList li {
  display: flex;
  align-items: center;
}

/* Friend highlighted in online list */
#usersList li.friend-online {
  background: linear-gradient(135deg, #e8eaf6, #ede7f6);
  border-left: 3px solid #667eea;
  font-weight: 600;
}

#usersList li.friend-online::after {
  content: '⭐';
  margin-left: auto;
  font-size: 12px;
}

/* Clickable header */
#chatTitle {
  transition: opacity 0.2s;
}

#chatTitle:hover {
  opacity: 0.8;
}

/* ==================== DM Chat ==================== */
.dm-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 15px;
  background: #f5f5f5;
  border-bottom: 1px solid #ddd;
  flex-shrink: 0;
}

.btn-dm-back {
  background: none;
  border: 1px solid #ddd;
  padding: 6px 12px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 13px;
  color: #667eea;
  font-weight: 600;
  transition: all 0.2s;
}

.btn-dm-back:hover {
  background: #667eea;
  color: white;
  border-color: #667eea;
}

#dmPartner {
  font-weight: 600;
  font-size: 15px;
  color: #333;
}

#dmChat {
  flex-direction: column;
}

/* ==================== Mobile Friends ==================== */
@media (max-width: 768px) {
  .users-panel {
    overflow: visible;
  }

  .sidebar-content {
    flex-direction: column;
    padding: 6px 10px;
  }

  .panel-tabs {
    margin-bottom: 4px;
  }

  .panel-tab {
    padding: 4px;
    font-size: 11px;
  }

  .add-friend-row {
    margin-bottom: 4px;
  }

  .add-friend-row input {
    padding: 4px 6px;
    font-size: 11px;
  }

  .btn-add-friend {
    padding: 2px 8px;
    font-size: 14px;
  }

  #friendsSection {
    margin-top: 6px;
    padding-top: 6px;
  }

  #friendsList {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
  }

  .friend-item {
    padding: 4px 6px;
    font-size: 12px;
    margin-bottom: 0;
  }

  .btn-remove-friend {
    opacity: 1;
  }

  .dm-header {
    padding: 8px 10px;
  }

  .btn-dm-back {
    padding: 4px 8px;
    font-size: 12px;
  }

  #dmPartner {
    font-size: 13px;
  }
}
