:root {
  --bg: #f0f2f5;
  --sidebar-bg: #ffffff;
  --chat-bg: #e5ddd5;
  --primary: #00a884;
  --primary-dark: #008069;
  --text: #111b21;
  --text-secondary: #667781;
  --border: #e9edef;
  --message-out: #d9fdd3;
  --message-in: #ffffff;
  --hover: #f5f6f6;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
}

[data-theme="dark"] {
  --bg: #0b141a;
  --sidebar-bg: #111b21;
  --chat-bg: #0b141a;
  --text: #e9edef;
  --text-secondary: #8696a0;
  --border: #222d34;
  --message-out: #005c4b;
  --message-in: #202c33;
  --hover: #202c33;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

body {
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

.screen {
  height: 100vh;
  width: 100%;
}

.hidden { display: none !important; }

/* ========== AUTH ========== */
#auth-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #00a884, #008069);
}

.auth-box {
  background: white;
  padding: 2.5rem;
  border-radius: 12px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.2);
  text-align: center;
}

.logo {
  font-size: 2.2rem;
  font-weight: 700;
  color: #00a884;
  margin-bottom: 0.3rem;
}

.subtitle {
  color: #667781;
  margin-bottom: 1.5rem;
  font-size: 0.95rem;
}

#auth-tabs {
  display: flex;
  margin-bottom: 1.5rem;
  border-bottom: 1px solid #e9edef;
}

#auth-tabs .tab {
  flex: 1;
  padding: 0.75rem;
  background: none;
  border: none;
  font-size: 1rem;
  cursor: pointer;
  color: #667781;
  border-bottom: 3px solid transparent;
}

#auth-tabs .tab.active {
  color: #00a884;
  border-bottom-color: #00a884;
  font-weight: 600;
}

.auth-form input {
  width: 100%;
  padding: 0.85rem 1rem;
  margin-bottom: 0.9rem;
  border: 1px solid #d1d7db;
  border-radius: 8px;
  font-size: 1rem;
  outline: none;
}

.auth-form input:focus {
  border-color: #00a884;
}

.btn-primary {
  width: 100%;
  padding: 0.9rem;
  background: #00a884;
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-primary:hover { background: #008069; }

.btn-secondary {
  padding: 0.7rem 1.2rem;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  color: var(--text);
}

.btn-warning {
  background: #f59e0b;
  color: white;
  border: none;
  padding: 0.7rem 1.2rem;
  border-radius: 8px;
  cursor: pointer;
  width: 100%;
  font-weight: 500;
}

.btn-warning:hover {
  background: #d97706;
}

.btn-danger {
  background: #ea4335;
  color: white;
  border: none;
  padding: 0.7rem 1.2rem;
  border-radius: 8px;
  cursor: pointer;
  width: 100%;
}

.btn-small {
  padding: 0.3rem 0.7rem;
  font-size: 0.8rem;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
}

.error {
  color: #ea4335;
  margin-top: 1rem;
  font-size: 0.9rem;
}

/* ========== APP LAYOUT ========== */
#app {
  display: flex;
  height: 100vh;
}

#sidebar {
  width: 380px;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  background: var(--sidebar-bg);
  border-bottom: 1px solid var(--border);
}

.user-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  cursor: pointer;
}

.user-info img {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
}

.user-info span {
  font-weight: 500;
  font-size: 1rem;
  max-width: 140px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-actions {
  display: flex;
  gap: 0.5rem;
}

.header-actions button {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 0.4rem;
  border-radius: 50%;
}

.header-actions button:hover {
  background: var(--hover);
  color: var(--text);
}

.search-box {
  padding: 8px 12px;
  position: relative;
  background: var(--sidebar-bg);
}

.search-box i {
  position: absolute;
  left: 24px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.search-box input {
  width: 100%;
  padding: 10px 12px 10px 40px;
  border: none;
  border-radius: 8px;
  background: var(--hover);
  color: var(--text);
  outline: none;
  font-size: 0.95rem;
}

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

.tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  background: var(--sidebar-bg);
}

.tab-btn {
  flex: 1;
  padding: 0.9rem 0.5rem;
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-weight: 500;
  font-size: 0.95rem;
  border-bottom: 3px solid transparent;
  transition: all 0.2s ease;
  letter-spacing: 0.3px;
}

.tab-btn:hover {
  background: var(--hover);
  color: var(--text);
}

.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 600;
}

.list {
  flex: 1;
  overflow-y: auto;
  background: var(--sidebar-bg);
}

.list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.15s ease;
  position: relative;
}

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

.list-item.active {
  background: var(--hover);
}

.list-item img {
  width: 49px;
  height: 49px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  background: #ddd;
}

.list-item .info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.list-item .name {
  font-weight: 500;
  font-size: 1rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}

.list-item .preview {
  font-size: 0.85rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}

.list-item .meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  flex-shrink: 0;
  min-width: 45px;
}

.list-item .meta .time {
  font-size: 0.75rem;
  color: var(--text-secondary);
  white-space: nowrap;
}

/* ========== CHAT AREA ========== */
#chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--chat-bg);
  position: relative;
}

.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
}

.empty-state i {
  font-size: 5rem;
  color: var(--primary);
  margin-bottom: 1rem;
}

#chat-view {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0.6rem 1rem;
  background: var(--sidebar-bg);
  border-bottom: 1px solid var(--border);
}

.chat-header img {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
}

.chat-info {
  flex: 1;
}

.chat-info h3 {
  font-size: 1rem;
  font-weight: 500;
}

.chat-info span {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.chat-actions button {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1.35rem;
  cursor: pointer;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.chat-actions button:hover {
  background: var(--hover);
  color: var(--text);
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23d4d4d4' fill-opacity='0.15'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}

.message {
  max-width: 65%;
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  position: relative;
  box-shadow: var(--shadow);
  word-wrap: break-word;
}

.message.out {
  align-self: flex-end;
  background: var(--message-out);
  border-bottom-right-radius: 2px;
}

.message.in {
  align-self: flex-start;
  background: var(--message-in);
  border-bottom-left-radius: 2px;
}

.message .reply-box {
  background: rgba(0,0,0,0.06);
  border-left: 3px solid var(--primary);
  padding: 0.3rem 0.5rem;
  margin-bottom: 0.3rem;
  border-radius: 4px;
  font-size: 0.85rem;
}

.message .time {
  font-size: 0.7rem;
  color: var(--text-secondary);
  text-align: right;
  margin-top: 0.2rem;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.25rem;
}

.message .status {
  font-size: 0.75rem;
}

.message img.chat-image {
  max-width: 100%;
  max-height: 280px;
  border-radius: 8px;
  margin-top: 4px;
  cursor: pointer;
  display: block;
}

.reply-preview {
  display: flex;
  align-items: center;
  padding: 0.5rem 1rem;
  background: var(--sidebar-bg);
  border-top: 1px solid var(--border);
}

.reply-content {
  flex: 1;
  border-left: 3px solid var(--primary);
  padding-left: 0.6rem;
}

.reply-content span {
  font-size: 0.8rem;
  color: var(--primary);
  font-weight: 500;
}

.reply-content p {
  font-size: 0.85rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.image-preview-container {
  display: none;
  padding: 0.6rem 1rem;
  background: var(--sidebar-bg);
  border-top: 1px solid var(--border);
  align-items: center;
  gap: 0.8rem;
}

.image-preview-container.show {
  display: flex;
}

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

.image-preview-container .preview-info {
  flex: 1;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.image-preview-container button {
  background: none;
  border: none;
  color: #ea4335;
  font-size: 1.1rem;
  cursor: pointer;
}

.chat-input {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 1rem;
  background: var(--sidebar-bg);
  border-top: 1px solid var(--border);
}

.chat-input button {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1.3rem;
  cursor: pointer;
  padding: 0.4rem;
}

#btn-attach:hover {
  color: var(--primary);
}

#message-input {
  flex: 1;
  padding: 0.7rem 1rem;
  border: none;
  border-radius: 24px;
  background: var(--hover);
  color: var(--text);
  outline: none;
  font-size: 0.95rem;
}

#btn-send {
  color: var(--primary);
}

/* ========== MODAL ========== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.2s ease;
}

.modal {
  background: var(--sidebar-bg);
  padding: 1.5rem;
  border-radius: 12px;
  width: 90%;
  max-width: 420px;
  max-height: 85vh;
  overflow-y: auto;
  animation: modalIn 0.25s ease;
  transform-origin: center;
}

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

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

.profile-enlarge {
  transition: transform 0.3s ease;
  cursor: zoom-in;
}

.modal h3 {
  margin-bottom: 1rem;
}

.modal input[type="text"],
.modal input[type="url"],
.modal input[type="email"],
.modal input[type="file"] {
  width: 100%;
  padding: 0.7rem;
  margin-bottom: 0.8rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--hover);
  color: var(--text);
  outline: none;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
  margin-top: 1rem;
}

.member-select {
  max-height: 200px;
  overflow-y: auto;
  margin: 0.5rem 0;
}

.member-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.4rem 0;
}

.member-item input {
  width: auto;
  margin: 0;
}

.profile-big {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  object-fit: cover;
  display: block;
  margin: 0 auto 1rem;
}

.group-member-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--border);
}

.group-member-item .left {
  display: flex;
  align-items: center;
  gap: 0.7rem;
}

.group-member-item img {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
}

.admin-badge {
  background: var(--primary);
  color: white;
  font-size: 0.65rem;
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  margin-left: 0.4rem;
}

.member-actions button {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 0.3rem;
  font-size: 0.9rem;
}

.member-actions button:hover {
  color: var(--primary);
}

.member-actions .danger:hover {
  color: #ea4335;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
  font-weight: 500;
}

/* Typing */
.typing-text {
  color: var(--primary);
  font-style: italic;
  font-weight: 500;
  animation: typingPulse 1.2s ease-in-out infinite;
}

@keyframes typingPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* Emoji */
.emoji-picker {
  position: absolute;
  bottom: 70px;
  left: 20px;
  background: var(--sidebar-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  width: 220px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  z-index: 50;
}

.emoji-picker span {
  font-size: 1.4rem;
  cursor: pointer;
  padding: 0.2rem;
}

.emoji-picker span:hover {
  background: var(--hover);
  border-radius: 4px;
}

.mobile-only { display: none; }

/* Responsive */
@media (max-width: 768px) {
  #sidebar {
    width: 100%;
    position: absolute;
    z-index: 10;
    height: 100%;
  }

  #sidebar.hide-mobile {
    display: none;
  }

  #chat-area {
    width: 100%;
  }

  .mobile-only {
    display: block;
  }

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


/* ========== UNREAD BADGE & DELETE ========== */
.avatar-wrap {
  position: relative;
  flex-shrink: 0;
}

.avatar-wrap img {
  width: 49px;
  height: 49px;
  border-radius: 50%;
  object-fit: cover;
}

/* Badge notifikasi (angka) */
.unread-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  min-width: 18px;
  height: 18px;
  background: #25d366;
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
  border: 2px solid var(--sidebar-bg);
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
  line-height: 1;
}

/* Dot kecil alternatif (kalau tidak ada angka) */
.unread-dot {
  position: absolute;
  bottom: 2px;
  right: 2px;
  width: 13px;
  height: 13px;
  background: #25d366;
  border-radius: 50%;
  border: 2px solid var(--sidebar-bg);
  box-shadow: 0 1px 2px rgba(0,0,0,0.15);
}

/* Unread state */
.list-item.unread .name {
  font-weight: 700;
  color: var(--text);
}

.list-item .preview.unread-text {
  color: var(--text);
  font-weight: 500;
}

.list-item .time.unread-time {
  color: #25d366;
  font-weight: 600;
}

/* Badge di meta (kanan) - gaya WhatsApp */
.unread-count {
  background: #25d366;
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  min-width: 20px;
  height: 20px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 6px;
  line-height: 1;
}

.btn-delete-chat {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px 6px;
  font-size: 0.8rem;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s, background 0.15s;
  border-radius: 50%;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.list-item:hover .btn-delete-chat {
  opacity: 1;
}

.btn-delete-chat:hover {
  color: #ea4335;
  background: rgba(234, 67, 53, 0.12);
}

.list-item .meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  flex-shrink: 0;
  min-width: 52px;
}


/* Tab unread badge */
.tab-btn {
  position: relative;
}

.tab-badge {
  position: absolute;
  top: 6px;
  right: 8px;
  background: #25d366;
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  line-height: 1;
}


/* ========== REACTIONS & SWIPE ========== */
.reaction-picker {
  position: fixed;
  z-index: 2000;
  background: var(--sidebar-bg);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 6px 8px;
  display: flex;
  gap: 4px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.2);
  animation: modalIn 0.15s ease;
}

.reaction-picker button {
  background: none;
  border: none;
  font-size: 1.4rem;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 50%;
  transition: background 0.15s, transform 0.15s;
  line-height: 1;
}

.reaction-picker button:hover {
  background: var(--hover);
  transform: scale(1.2);
}

.msg-reactions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
}

.reaction-chip {
  background: var(--hover);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2px 6px;
  font-size: 0.8rem;
  line-height: 1.2;
}

.message {
  transition: transform 0.15s ease;
  user-select: none;
}
