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

:root {
  --green-dark: #075e54;
  --green: #128c7e;
  --green-light: #25d366;
  --bg-chat: #efeae2;
  --bubble-out: #d9fdd3;
  --bubble-in: #ffffff;
  --panel-bg: #f0f2f5;
  --border: #d1d7db;
  --text: #111b21;
  --text-soft: #667781;
}

body {
  font-family: "Segoe UI", Helvetica, Arial, sans-serif;
  background: #d9dbd5;
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

.hidden {
  display: none !important;
}

/* ---------- Login ---------- */
.login-screen {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--green-dark), var(--green));
}
.login-box {
  background: #fff;
  padding: 40px;
  border-radius: 16px;
  width: 360px;
  max-width: 90vw;
  text-align: center;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
}
.login-logo {
  font-size: 56px;
  margin-bottom: 8px;
}
.login-box h1 {
  font-size: 22px;
  margin-bottom: 4px;
}
.login-box p {
  color: var(--text-soft);
  margin-bottom: 24px;
}
.login-box input,
.login-box button {
  width: 100%;
  padding: 13px 16px;
  border-radius: 10px;
  border: 1px solid var(--border);
  font-size: 15px;
  margin-bottom: 12px;
}
.login-box button {
  background: var(--green);
  color: #fff;
  border: none;
  cursor: pointer;
  font-weight: 600;
}
.login-box button:hover {
  background: var(--green-dark);
}
.login-error {
  color: #d32f2f;
  font-size: 13px;
  display: block;
  min-height: 16px;
}

/* ---------- App layout ---------- */
.app {
  display: flex;
  height: 100vh;
  max-width: 1600px;
  margin: 0 auto;
  background: var(--panel-bg);
}

/* ---------- Sidebar ---------- */
.sidebar {
  width: 380px;
  min-width: 300px;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  background: #fff;
}
.sidebar-header {
  background: var(--panel-bg);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 60px;
}
.me {
  display: flex;
  align-items: center;
  gap: 12px;
}
.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--green);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  color: #fff;
  flex-shrink: 0;
}
.me-info {
  display: flex;
  flex-direction: column;
  line-height: 1.3;
}
.conn-status {
  font-size: 12px;
  color: var(--text-soft);
}
.conn-status.online {
  color: var(--green-light);
}
.conn-status.offline {
  color: #d32f2f;
}
.icon-btn {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--text-soft);
  padding: 8px;
  border-radius: 50%;
}
.icon-btn:hover {
  background: #e9edef;
}
.search {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}
.search input {
  width: 100%;
  padding: 9px 14px;
  border-radius: 8px;
  border: none;
  background: var(--panel-bg);
  font-size: 14px;
}

.chat-list {
  flex: 1;
  overflow-y: auto;
}
.chat-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  cursor: pointer;
  border-bottom: 1px solid #f0f0f0;
}
.chat-item:hover {
  background: var(--panel-bg);
}
.chat-item.active {
  background: #e9edef;
}
.chat-item .avatar {
  background: #6b7c85;
}
.chat-item-info {
  flex: 1;
  min-width: 0;
}
.chat-item-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}
.chat-item-name {
  font-weight: 600;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-item-time {
  font-size: 11px;
  color: var(--text-soft);
  flex-shrink: 0;
  margin-left: 8px;
}
.chat-item-last {
  font-size: 13px;
  color: var(--text-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- Conversation ---------- */
.conversation {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
  background: var(--bg-chat);
}
.center-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px;
  background: var(--panel-bg);
  border-bottom: 4px solid var(--green-light);
}
.center-pane h2 {
  margin-bottom: 10px;
}
.center-pane p {
  color: var(--text-soft);
  max-width: 420px;
  line-height: 1.5;
}
.empty-logo {
  font-size: 80px;
  margin-bottom: 16px;
  opacity: 0.5;
}
#qr-img {
  margin: 24px 0 12px;
  border: 8px solid #fff;
  border-radius: 8px;
}
.hint {
  font-size: 13px;
}

.chat-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.chat-header {
  background: var(--panel-bg);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  height: 60px;
  border-left: 1px solid var(--border);
}
.chat-header-info {
  display: flex;
  flex-direction: column;
  line-height: 1.3;
}
.active-jid {
  font-size: 12px;
  color: var(--text-soft);
}
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 8%;
  display: flex;
  flex-direction: column;
  gap: 4px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='40'%3E%3Crect width='40' height='40' fill='%23efeae2'/%3E%3Ccircle cx='20' cy='20' r='1' fill='%23d8d0c4'/%3E%3C/svg%3E");
}
.bubble {
  max-width: 65%;
  padding: 7px 12px;
  border-radius: 8px;
  font-size: 14px;
  line-height: 1.4;
  position: relative;
  word-wrap: break-word;
  box-shadow: 0 1px 0.5px rgba(0, 0, 0, 0.1);
}
.bubble.out {
  align-self: flex-end;
  background: var(--bubble-out);
}
.bubble.in {
  align-self: flex-start;
  background: var(--bubble-in);
}
.bubble-time {
  font-size: 10px;
  color: var(--text-soft);
  display: block;
  text-align: right;
  margin-top: 2px;
}

/* ---------- Mídias na bolha ---------- */
.bubble.has-media {
  padding: 4px;
}
.media-img {
  max-width: 280px;
  max-height: 320px;
  border-radius: 6px;
  cursor: pointer;
  display: block;
}
.media-sticker {
  width: 130px;
  height: 130px;
  object-fit: contain;
  display: block;
}
.media-video {
  max-width: 280px;
  border-radius: 6px;
  display: block;
}
.media-audio {
  width: 250px;
  display: block;
  margin: 2px 0;
}
.media-doc {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: rgba(0, 0, 0, 0.05);
  border-radius: 6px;
  color: var(--green-dark);
  text-decoration: none;
  font-size: 14px;
  min-width: 180px;
}
.media-doc:hover {
  background: rgba(0, 0, 0, 0.1);
}
.media-fail {
  font-size: 13px;
  color: #b54708;
  font-style: italic;
}
.bubble-text {
  margin-top: 4px;
  padding: 0 6px;
}

.attach-btn {
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  color: var(--text-soft);
  padding: 6px 8px;
  flex-shrink: 0;
}
.attach-btn:hover {
  color: var(--green);
}

.composer {
  background: var(--panel-bg);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.composer input {
  flex: 1;
  padding: 11px 16px;
  border-radius: 22px;
  border: none;
  font-size: 15px;
  outline: none;
}
.send-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: var(--green);
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  flex-shrink: 0;
}
.send-btn:hover {
  background: var(--green-dark);
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #323232;
  color: #fff;
  padding: 12px 22px;
  border-radius: 8px;
  font-size: 14px;
  z-index: 1000;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}
.toast.error {
  background: #d32f2f;
}

/* ---------- Responsivo ---------- */
@media (max-width: 768px) {
  .sidebar {
    width: 100%;
  }
  .app.chat-open .sidebar {
    display: none;
  }
  .app:not(.chat-open) .conversation {
    display: none;
  }
}
