:root {
  --wa-green: #00a884;
  --wa-green-dark: #008069;
  --wa-bg-chat: #efeae2;
  --wa-bg-panel: #ffffff;
  --wa-bg-sidebar: #f0f2f5;
  --wa-text: #111b21;
  --wa-text-light: #667781;
  --wa-border: #e9edef;
  --wa-bubble-mine: #d9fdd3;
  --wa-bubble-other: #ffffff;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  color: var(--wa-text);
  background: #d1d7db;
}

/* ===================== AUTH ===================== */
.auth-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, var(--wa-green-dark), var(--wa-green));
}
.auth-card {
  background: #fff;
  padding: 36px 32px;
  border-radius: 14px;
  width: 360px;
  max-width: 90vw;
  box-shadow: 0 10px 40px rgba(0,0,0,.25);
}
.auth-logo { font-size: 22px; font-weight: 700; color: var(--wa-green-dark); margin-bottom: 4px;}
.auth-card h2 { margin: 4px 0 18px; color: var(--wa-text); }
.auth-form { display: flex; flex-direction: column; gap: 12px; }
.auth-form input {
  padding: 12px 14px;
  border: 1px solid #d1d7db;
  border-radius: 8px;
  font-size: 14px;
  outline: none;
}
.auth-form input:focus { border-color: var(--wa-green); }
.btn-primary {
  background: var(--wa-green);
  color: #fff;
  border: none;
  padding: 12px;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 4px;
}
.btn-primary:hover { background: var(--wa-green-dark); }
.auth-link { margin-top: 16px; font-size: 14px; text-align: center; color: var(--wa-text-light); }
.auth-link a { color: var(--wa-green-dark); font-weight: 600; text-decoration: none; }
.alert { padding: 10px 12px; border-radius: 8px; font-size: 13px; margin-bottom: 10px; }
.alert-error { background: #fde2e1; color: #c0392b; }

/* ===================== APP LAYOUT ===================== */
#app {
  display: flex;
  height: 100vh;
  max-width: 1600px;
  margin: 0 auto;
  background: var(--wa-bg-panel);
}

/* ---------- Sidebar ---------- */
.sidebar {
  width: 380px;
  min-width: 300px;
  display: flex;
  flex-direction: column;
  background: var(--wa-bg-panel);
  border-right: 1px solid var(--wa-border);
}
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--wa-bg-sidebar);
}
.my-avatar {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--wa-green); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
}
.sidebar-actions { display: flex; gap: 6px; }
.sidebar-actions button {
  background: transparent; border: none; font-size: 18px; cursor: pointer;
  width: 38px; height: 38px; border-radius: 50%;
}
.sidebar-actions button:hover { background: #00000010; }

.search-box { padding: 8px 12px; background: var(--wa-bg-panel); }
.search-box input {
  width: 100%; padding: 9px 14px; border-radius: 20px; border: none;
  background: var(--wa-bg-sidebar); font-size: 14px; outline: none;
}

.conv-list { flex: 1; overflow-y: auto; }
.conv-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; cursor: pointer; border-bottom: 1px solid #f5f5f5;
  position: relative;
}
.conv-item:hover, .conv-item.active { background: var(--wa-bg-sidebar); }
.conv-avatar {
  width: 49px; height: 49px; border-radius: 50%; flex-shrink: 0;
  background: #8696a0; color: #fff; display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 18px; object-fit: cover;
}
.conv-info { flex: 1; min-width: 0; }
.conv-top { display: flex; justify-content: space-between; align-items: center; }
.conv-name { font-weight: 600; font-size: 15px; }
.conv-time { font-size: 12px; color: var(--wa-text-light); }
.conv-bottom { display: flex; justify-content: space-between; align-items: center; margin-top: 2px;}
.conv-last { font-size: 13px; color: var(--wa-text-light); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 230px; }
.conv-badge {
  background: var(--wa-green); color: #fff; font-size: 11px; font-weight: 700;
  border-radius: 999px; padding: 2px 7px; min-width: 18px; text-align: center;
}
.online-dot {
  width: 9px; height: 9px; border-radius: 50%; background: #2ecc71;
  border: 2px solid #fff; position: absolute; left: 50px; bottom: 12px;
}

/* ---------- Chat area ---------- */
.chat-area { flex: 1; display: flex; flex-direction: column; background: var(--wa-bg-chat);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='100' height='100'%3E%3Crect width='100' height='100' fill='%23efeae2'/%3E%3C/svg%3E");
}
.chat-empty { flex: 1; display: flex; align-items: center; justify-content: center; }
.chat-empty-inner { text-align: center; color: var(--wa-text-light); }
.chat-empty-icon { font-size: 64px; margin-bottom: 12px; }

.chat-window { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.chat-header {
  display: flex; align-items: center; gap: 12px; padding: 10px 16px;
  background: var(--wa-bg-sidebar); border-bottom: 1px solid var(--wa-border);
}
.chat-header-avatar {
  width: 40px; height: 40px; border-radius: 50%; background: #8696a0; color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 700;
}
.chat-header-info { flex: 1; min-width: 0; }
.chat-header-name { font-weight: 600; font-size: 15px; }
.chat-header-sub { font-size: 12px; color: var(--wa-text-light); }
.chat-header-actions button { background: none; border: none; font-size: 18px; cursor: pointer; }

.messages {
  flex: 1; overflow-y: auto; padding: 16px 8%; display: flex; flex-direction: column; gap: 4px;
}
.msg-row { display: flex; }
.msg-row.mine { justify-content: flex-end; }
.bubble {
  max-width: 65%; padding: 6px 9px 8px 9px; border-radius: 8px; font-size: 14.2px;
  position: relative; line-height: 1.4; box-shadow: 0 1px 0.5px rgba(0,0,0,.1);
}
.msg-row.mine .bubble { background: var(--wa-bubble-mine); border-top-right-radius: 0; }
.msg-row:not(.mine) .bubble { background: var(--wa-bubble-other); border-top-left-radius: 0; }
.bubble .sender-name { font-size: 12.5px; font-weight: 700; color: var(--wa-green-dark); margin-bottom: 2px; display: block; }
.bubble .body { white-space: pre-wrap; word-break: break-word; }
.bubble .time { font-size: 11px; color: var(--wa-text-light); float: right; margin-left: 8px; margin-top: 4px; }
.bubble .file-attach {
  display: flex; align-items: center; gap: 8px; background: #00000008;
  padding: 8px; border-radius: 6px; margin-bottom: 4px; text-decoration: none; color: inherit;
}
.bubble .file-icon { font-size: 22px; }
.bubble .file-meta { font-size: 12px; color: var(--wa-text-light); }
.bubble img.img-attach { max-width: 260px; border-radius: 6px; display: block; margin-bottom: 4px; }

.chat-input-bar {
  display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: var(--wa-bg-sidebar);
}
.chat-input-bar input[type=text] {
  flex: 1; padding: 11px 16px; border-radius: 20px; border: none; outline: none; font-size: 14.5px;
}
.chat-input-bar button { background: none; border: none; font-size: 20px; cursor: pointer; color: var(--wa-text-light); }
.chat-input-bar button#btnSend { color: var(--wa-green-dark); }
.file-preview {
  display: flex; align-items: center; gap: 10px; padding: 8px 16px; background: #fff;
  border-top: 1px solid var(--wa-border); font-size: 13px;
}
.file-preview button { background: none; border: none; cursor: pointer; font-size: 14px; }

/* ---------- Modals ---------- */
.modal-overlay {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,.5);
  align-items: center; justify-content: center; z-index: 100;
}
.modal-overlay.open { display: flex; }
.modal {
  background: #fff; width: 420px; max-width: 92vw; max-height: 80vh;
  border-radius: 10px; padding: 16px; display: flex; flex-direction: column; overflow: hidden;
}
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.modal-header h3 { margin: 0; }
.modal-close { background: none; border: none; font-size: 16px; cursor: pointer; }
.modal-search {
  width: 100%; padding: 10px 14px; border-radius: 8px; border: 1px solid var(--wa-border);
  margin-bottom: 8px; font-size: 14px; outline: none;
}
.user-list { overflow-y: auto; flex: 1; }
.user-item {
  display: flex; align-items: center; gap: 10px; padding: 8px 6px; cursor: pointer; border-radius: 8px;
}
.user-item:hover { background: var(--wa-bg-sidebar); }
.user-item.selected { background: #d9fdd3; }
.user-avatar {
  width: 38px; height: 38px; border-radius: 50%; background: #8696a0; color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 700; flex-shrink: 0;
}
.user-meta-name { font-weight: 600; font-size: 14px; }
.user-meta-username { font-size: 12px; color: var(--wa-text-light); }
.selected-members { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip {
  background: var(--wa-bg-sidebar); padding: 4px 10px; border-radius: 14px; font-size: 12.5px;
  display: flex; align-items: center; gap: 6px;
}
.chip button { background: none; border: none; cursor: pointer; font-size: 11px; }

.member-row { display: flex; align-items: center; gap: 10px; padding: 8px 4px; }
.member-row .admin-tag { font-size: 11px; color: var(--wa-green-dark); margin-left: auto; font-weight: 600; }
.member-row .btn-remove-member {
  background: none; border: none; cursor: pointer; font-size: 13px; color: #c0392b;
  margin-left: 8px; padding: 4px 8px; border-radius: 6px;
}
.member-row .btn-remove-member:hover { background: #fde2e1; }
.group-info-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.btn-secondary {
  background: var(--wa-bg-sidebar); color: var(--wa-text); border: none; padding: 10px;
  border-radius: 8px; font-size: 14px; font-weight: 600; cursor: pointer;
}
.btn-secondary:hover { background: #e3e6e8; }
.btn-danger {
  background: #fde2e1; color: #c0392b; border: none; padding: 10px;
  border-radius: 8px; font-size: 14px; font-weight: 600; cursor: pointer;
}
.btn-danger:hover { background: #f8c9c7; }

/* Scrollbar */
.conv-list::-webkit-scrollbar, .messages::-webkit-scrollbar, .user-list::-webkit-scrollbar { width: 6px; }
.conv-list::-webkit-scrollbar-thumb, .messages::-webkit-scrollbar-thumb, .user-list::-webkit-scrollbar-thumb {
  background: #c0c4c8; border-radius: 4px;
}

/* Responsivo */
@media (max-width: 820px) {
  .sidebar { width: 100%; min-width: 0; }
  .chat-area { display: none; }
  #app.show-chat .sidebar { display: none; }
  #app.show-chat .chat-area { display: flex; }
}
