/* message.css - WhatsApp-Style Messaging for LaoVerse (Responsive) */
:root {
  --neon-blue: #66f0ff;
  --wa-dark-bg: #0b141a;
  --wa-item-bg: #111b21;
  --wa-chat-bg: #0b141a;
  --wa-header-bg: #202c33;
  --wa-input-bg: #2a3942;
  --wa-msg-left: #202c33;
  --wa-msg-right: #005c4b;
  --wa-text: #e9edef;
  --wa-dim: #8696a0;
  --wa-online: #00a884;
  --black: #000000;
  --white: #ffffff;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: 'Noto Sans Lao', sans-serif;
}

/* ===== FIX 1: ให้ body ใช้ flex: 1 ได้ ===== */
html,
body {
  height: 100%;
}

body.whatsapp-mode {
  background-color: var(--black);
  color: var(--wa-text);
  display: flex;
  /* เปลี่ยน min-height: 100vh → flex แทน */
  flex-direction: column;
  padding-top: 80px;
  overflow: hidden;
}

/* --- Notification Message (Center of screen) --- */
.message {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(0, 0, 0, 0.9);
  color: var(--neon-blue);
  padding: 1.2rem 2.5rem;
  border-radius: 15px;
  border: 2px solid var(--neon-blue);
  box-shadow: 0 0 30px rgba(102, 240, 255, 0.6);
  z-index: 9999;
  text-align: center;
  font-weight: bold;
  font-size: 1.1rem;
  display: none;
  min-width: 280px;
  max-width: 90%;
  pointer-events: none;
  animation: messagePop 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes messagePop {
  from {
    transform: translate(-50%, -50%) scale(0.8);
    opacity: 0;
  }

  to {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
  }
}

.message.success {
  border-color: #00ff88;
  color: #00ff88;
  box-shadow: 0 0 30px rgba(0, 255, 136, 0.5);
}

.message.error {
  border-color: #ff4444;
  color: #ff4444;
  box-shadow: 0 0 30px rgba(255, 68, 68, 0.5);
}

/* --- Navigation Bar (Same as other pages) --- */
.main-header {
  width: 100%;
  padding: 1rem 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: var(--black);
  border-bottom: 1px solid var(--neon-blue);
  box-shadow: 0 0 15px var(--neon-blue);
  position: fixed;
  top: 0;
  left: 0;
  z-index: 2000;
}

.logo img {
  width: 180px;
}

.main-nav ul {
  display: flex;
  list-style: none;
  gap: 1.5rem;
}

.main-nav a {
  color: var(--white);
  text-decoration: none;
  transition: all 0.3s ease;
  padding: 10px;
  border-radius: 10px;
  border: 2px solid var(--neon-blue);
  background-color: var(--black);
  font-size: 0.9rem;
}

.main-nav a:hover {
  color: var(--neon-blue);
  background-color: var(--white);
}

.main-nav a.active {
  background-color: var(--neon-blue);
  color: var(--black);
  font-weight: bold;
}

/* --- App Container --- */
.app-container {
  display: flex;
  flex: 1;
  /* ===== FIX 2: เอา height: calc() ออก ใช้ flex: 1 แทน ===== */
  max-width: 1200px;
  width: 95%;
  margin: 1rem auto 1.5rem auto;
  background-color: var(--wa-dark-bg);
  border: 1px solid rgba(102, 240, 255, 0.3);
  border-radius: 12px;
  overflow: hidden;
  position: relative;
}

.view {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-width: 0;
  /* ===== FIX 3: ป้องกัน flex children overflow ===== */
}

#friends-view {
  width: 350px;
  border-right: 1px solid rgba(255, 255, 255, 0.1);
  background-color: var(--wa-item-bg);
  z-index: 10;
  flex-shrink: 0;
  /* ===== FIX 4: ไม่หด ===== */
}

#chat-view {
  flex: 1;
  background-color: var(--wa-chat-bg);
  display: flex;
  flex-direction: column;
  min-width: 0;
  /* ===== FIX 5: ป้องกัน overflow ===== */
}

/* --- Headers Inside Views --- */
.view-header,
.chat-header-wa {
  height: 65px;
  padding: 0 1rem;
  background-color: var(--wa-header-bg);
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.view-header {
  justify-content: space-between;
}

.view-header h2 {
  font-size: 1.2rem;
  color: var(--wa-text);
}

.chat-header-wa {
  gap: 1rem;
  border-left: 1px solid rgba(255, 255, 255, 0.05);
}

/* --- Friends List --- */
.scroll-area {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}

.friend-item-wa {
  display: flex;
  padding: 12px 16px;
  cursor: pointer;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  transition: background 0.2s;
}

.friend-item-wa:hover {
  background-color: var(--wa-header-bg);
}

.friend-item-wa.active {
  background-color: var(--wa-input-bg);
}

.avatar-wrapper {
  position: relative;
  width: 50px;
  height: 50px;
  margin-right: 12px;
  flex-shrink: 0;
}

.avatar-wrapper img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.online-dot {
  position: absolute;
  bottom: 2px;
  right: 2px;
  width: 12px;
  height: 12px;
  background-color: var(--wa-online);
  border: 2px solid var(--wa-item-bg);
  border-radius: 50%;
  display: none;
}

.friend-item-wa.online .online-dot {
  display: block;
}

.item-content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.item-top {
  display: flex;
  justify-content: space-between;
  margin-bottom: 4px;
}

.item-name {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--wa-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.item-time {
  font-size: 0.75rem;
  color: var(--wa-dim);
}

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

.item-msg {
  font-size: 0.85rem;
  color: var(--wa-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.unread-badge {
  background-color: var(--wa-online);
  color: white;
  font-size: 0.75rem;
  min-width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2px;
}

/* --- Chat Messages --- */
.chat-bg {
  background-image: url('https://user-images.githubusercontent.com/15075759/28719144-86dc0f70-73b1-11e7-911d-60d70fcded51.png');
  background-repeat: repeat;
  background-size: 400px;
  background-color: #0b141a;
  background-blend-mode: overlay;
  flex: 1;
  /* ===== FIX 6: ยืดเต็มพื้นที่ ===== */
  overflow-y: auto;
  /* ===== FIX 7: เลื่อนข้อความได้ ===== */
  min-height: 0;
  /* ===== FIX 8: Critical สำหรับ flex scroll ===== */
}

#chat-messages {
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.message-wa {
  max-width: 75%;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 0.95rem;
  line-height: 1.4;
  position: relative;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.2);
  word-wrap: break-word;
  /* ===== FIX 9: Text wrap ===== */
  overflow-wrap: break-word;
}

.message-wa.left {
  align-self: flex-start;
  background-color: var(--wa-msg-left);
  color: var(--wa-text);
  border-top-left-radius: 0;
}

.message-wa.right {
  align-self: flex-end;
  background-color: var(--wa-msg-right);
  color: var(--wa-text);
  border-top-right-radius: 0;
}

@import url('shared-styles.css');

/* --- Message Actions (Edit/Delete) --- */
.msg-actions {
  display: flex;
  gap: 4px;
  margin-left: 8px;
  opacity: 0;
  transition: opacity 0.2s;
}

.message-wa:hover .msg-actions {
  opacity: 1;
}

.msg-edit-btn,
.msg-delete-btn {
  background: rgba(255, 255, 255, 0.1);
  border: none;
  color: var(--wa-dim);
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.75rem;
  line-height: 1;
}

.msg-edit-btn:hover {
  background: var(--neon-blue);
  color: var(--black);
}

.msg-delete-btn:hover {
  background: #ff4444;
  color: white;
}

.message-info-bottom {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 4px;
  margin-top: 4px;
}

.message-time {
  font-size: 0.65rem;
  color: var(--wa-dim);
}

/* --- Input Area --- */
.input-area-wa {
  padding: 12px 1rem;
  background-color: var(--wa-header-bg);
  display: flex;
  align-items: center;
  gap: 0.8rem;
  flex-shrink: 0;
}

.input-wrapper {
  flex: 1;
  background-color: var(--wa-input-bg);
  border-radius: 25px;
  padding: 2px 15px;
}

#message-input {
  width: 100%;
  background: transparent;
  border: none;
  color: var(--wa-text);
  padding: 10px 0;
  font-size: 0.95rem;
  outline: none;
  resize: none;
  max-height: 100px;
  font-family: 'Noto Sans Lao', sans-serif;
}

.wa-send-btn {
  background: transparent;
  border: none;
  color: var(--wa-dim);
  font-size: 1.6rem;
  cursor: pointer;
  transition: all 0.3s;
}

.wa-send-btn.active {
  color: var(--neon-blue);
  text-shadow: 0 0 10px var(--neon-blue);
  transform: scale(1.1);
}

/* --- File Preview Bar --- */
.file-preview-bar {
  padding: 10px 15px;
  background-color: var(--wa-header-bg);
  border-top: 1px solid rgba(102, 240, 255, 0.1);
  display: flex;
  align-items: center;
  justify-content: space-between;
  animation: slideUp 0.2s ease-out;
}

@keyframes slideUp {
  from {
    transform: translateY(10px);
    opacity: 0;
  }

  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.preview-info {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--wa-text);
}

.preview-thumb {
  width: 40px;
  height: 40px;
  border-radius: 4px;
  object-fit: cover;
  border: 1px solid var(--neon-blue);
}

.preview-icon {
  font-size: 1.5rem;
}

.preview-name {
  font-size: 0.85rem;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.preview-close {
  background: transparent;
  border: none;
  color: #ff6666;
  font-size: 1.2rem;
  cursor: pointer;
  padding: 5px;
}

/* --- Responsive Hacks (เหมือนเดิมทุกอย่าง) --- */
@media (max-width: 900px) {
  .app-container {
    width: 98%;
    height: calc(100vh - 180px);
  }

  #friends-view {
    width: 280px;
  }
}

@media (max-width: 768px) {
  body.whatsapp-mode {
    padding-top: 140px;
  }

  .main-header {
    flex-direction: column;
    padding: 0.8rem 0.8rem 1.2rem 0.8rem !important;
  }

  .logo img {
    width: 140px;
  }

  .main-nav ul {
    gap: 0.6rem;
    flex-wrap: wrap;
    justify-content: center;
  }

  .main-nav a {
    padding: 6px 10px;
    font-size: 0.75rem;
  }

  .app-container {
    width: 100%;
    margin: 0 0 10px 0;
    border: none;
    border-radius: 0;
    height: calc(100vh - 160px);
  }

  .input-area-wa {
    padding: 12px 1rem 45px 1rem;
    position: relative;
    z-index: 100;
  }

  #friends-view {
    width: 100%;
    position: absolute;
    left: 0;
    top: 0;
    transition: transform 0.3s ease;
  }

  #chat-view {
    width: 100%;
    position: absolute;
    left: 100%;
    top: 0;
    transition: transform 0.3s ease;
    border-left: none;
  }

  body.chat-open #friends-view {
    transform: translateX(-100%);
  }

  body.chat-open #chat-view {
    transform: translateX(-100%);
  }

  .back-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--wa-text);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 5px;
    margin-right: 5px;
    border-radius: 50%;
    transition: background 0.2s;
  }

  .back-btn:hover {
    background-color: rgba(255, 255, 255, 0.1);
  }

  @media (min-width: 769px) {
    .back-btn {
      display: flex;
    }
  }

  .chat-user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    flex: 1;
  }

  .chat-user-info .user-name {
    font-weight: bold;
    display: block;
  }

  .chat-user-info .status-text {
    font-size: 0.75rem;
    color: var(--wa-online);
  }

  .online-toggle-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
  }

  .online-toggle-label input {
    display: none;
  }

  .slider {
    width: 34px;
    height: 18px;
    background-color: #555;
    border-radius: 34px;
    position: relative;
    transition: .4s;
  }

  .slider:before {
    content: "";
    position: absolute;
    width: 14px;
    height: 14px;
    left: 2px;
    bottom: 2px;
    background-color: white;
    border-radius: 50%;
    transition: .4s;
  }

  input:checked+.slider {
    background-color: var(--wa-online);
  }

  input:checked+.slider:before {
    transform: translateX(16px);
  }

  .message-file {
    max-width: 100%;
    border-radius: 8px;
    margin-top: 5px;
    display: block;
  }

  .empty-chat-msg {
    text-align: center;
    color: var(--wa-dim);
    margin: auto;
    padding: 2rem;
  }}