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

:root {
  --green: #00A884;
  --green-dark: #008069;
  --bg-general: #F0F2F5;
  --bg-chat: #EFE7DE;
  --sidebar: #FFFFFF;
  --msg-in: #FFFFFF;
  --msg-out: #D9FDD3;
  --text-main: #111B21;
  --text-secondary: #667781;
  --text-disabled: #8696A0;
  --border: #E9EDEF;
  --hover: #F5F6F6;
  --active: #F0F2F5;
  --shadow: 0 1px 1px rgba(0,0,0,0.08);
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  color: var(--text-main);
  background: #111B21;
  overflow: hidden;
}

.hidden { display: none !important; }

/* ===== Tela de token ===== */
#token-screen {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0b141a 0%, #1f2c34 100%);
}
.token-box {
  background: #fff;
  padding: 44px 40px;
  border-radius: 16px;
  width: 380px;
  text-align: center;
  box-shadow: 0 12px 40px rgba(0,0,0,0.4);
}
.token-logo {
  width: 72px;
  height: 72px;
  margin: 0 auto 20px;
  background: var(--green);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 34px;
  box-shadow: 0 4px 12px rgba(0,168,132,0.3);
}
.token-box h1 { font-size: 22px; margin-bottom: 6px; }
.token-box p { color: var(--text-secondary); font-size: 14px; margin-bottom: 24px; }
.token-box input {
  width: 100%;
  padding: 13px 14px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-size: 15px;
  margin-bottom: 14px;
  transition: border-color 0.2s;
}
.token-box input:focus { outline: none; border-color: var(--green); }
.token-box button {
  width: 100%;
  padding: 13px;
  background: var(--green);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}
.token-box button:hover { background: var(--green-dark); }
.error { color: #d32f2f; font-size: 13px; margin-top: 12px; }

/* ===== Layout principal ===== */
#main-screen { display: flex; height: 100vh; }

/* ===== Sidebar ===== */
.sidebar {
  width: 30%;
  min-width: 320px;
  max-width: 420px;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}
.sidebar-header {
  padding: 12px 16px;
  background: var(--bg-general);
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border);
}
.sidebar-user { display: flex; align-items: center; gap: 12px; }
.user-avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--green);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}
.user-info { display: flex; flex-direction: column; }
.user-name { font-size: 15px; font-weight: 600; }
.user-status { font-size: 12px; color: var(--text-secondary); }
#upload-btn {
  width: 40px; height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--green);
  color: #fff;
  font-size: 22px;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  box-shadow: 0 2px 6px rgba(0,168,132,0.3);
}
#upload-btn:hover { background: var(--green-dark); }
#upload-btn:active { transform: scale(0.95); }

.search-box { padding: 8px 12px; background: var(--sidebar); border-bottom: 1px solid var(--border); }
.search-box input {
  width: 100%;
  padding: 10px 14px;
  border: none;
  border-radius: 8px;
  background: var(--bg-general);
  font-size: 14px;
  transition: background 0.2s;
}
.search-box input:focus { outline: none; background: #fff; box-shadow: 0 0 0 1px var(--green); }

.conversa-list { flex: 1; overflow-y: auto; }
.conversa-list::-webkit-scrollbar { width: 6px; }
.conversa-list::-webkit-scrollbar-thumb { background: #ccc; border-radius: 3px; }
.conversa-item {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.15s;
  display: flex;
  align-items: center;
  gap: 12px;
}
.conversa-item:hover { background: var(--hover); }
.conversa-item.active { background: var(--active); }
.conversa-avatar {
  width: 48px; height: 48px;
  min-width: 48px;
  border-radius: 50%;
  background: var(--green);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 600;
}
.conversa-info { flex: 1; min-width: 0; }
.conversa-info .c-title { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conversa-info .c-meta { color: var(--text-secondary); font-size: 12px; margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conversa-info .c-count { color: var(--text-disabled); font-size: 11px; margin-top: 2px; }

/* ===== Área de chat ===== */
.chat-area { flex: 1; display: flex; flex-direction: column; background: var(--bg-chat); position: relative; }
.chat-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-general);
}
.empty-content { text-align: center; color: var(--text-secondary); }
.empty-icon { font-size: 64px; margin-bottom: 16px; }
.empty-content h3 { font-size: 20px; margin-bottom: 8px; color: var(--text-main); }
.empty-content p { font-size: 14px; }

.chat-view { flex: 1; display: flex; flex-direction: column; }
.chat-header {
  padding: 10px 16px;
  background: var(--bg-general);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 60px;
}
.back-btn {
  display: none;
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  color: var(--text-main);
}
.chat-title { display: flex; align-items: center; gap: 12px; flex: 1; }
.chat-title .avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--green);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  font-weight: 600;
}
.chat-title-info h3 { font-size: 16px; font-weight: 600; }
.chat-title-info span { color: var(--text-secondary); font-size: 12px; display: block; margin-top: 2px; }
.delete-btn {
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  opacity: 0.6;
  transition: opacity 0.2s;
}
.delete-btn:hover { opacity: 1; }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 40px;
  background-image: url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI0MCIgaGVpZ2h0PSI0MCIgdmlld0JveD0iMCAwIDQwIDQwIj48cGF0aCBkPSJNMjAgMjBhMTAgMTAgMCAxIDAgMjAgMCAxMCAxMCAwIDAgMC0yMCAweiIgZmlsbD0iI2U1ZGRkNSIgZmlsbC1vcGFjaXR5PSIwLjUiLz48L3N2Zz4=');
}
.messages::-webkit-scrollbar { width: 6px; }
.messages::-webkit-scrollbar-thumb { background: #ccc; border-radius: 3px; }

/* Separador de data */
.date-separator { text-align: center; margin: 12px 0; }
.date-separator .date-badge {
  background: #fff;
  padding: 5px 14px;
  border-radius: 8px;
  display: inline-block;
  box-shadow: var(--shadow);
  font-size: 12px;
  color: var(--text-secondary);
}

/* Bolhas */
.msg { display: flex; margin-bottom: 2px; }
.msg.out { justify-content: flex-end; }
.msg.in { justify-content: flex-start; }

.bubble {
  max-width: 65%;
  padding: 8px 12px;
  border-radius: 8px;
  position: relative;
  box-shadow: var(--shadow);
  word-wrap: break-word;
  margin-bottom: 2px;
}
.msg.out .bubble { background: var(--msg-out); border-top-right-radius: 0; }
.msg.in .bubble { background: var(--msg-in); border-top-left-radius: 0; }

.bubble .sender {
  font-size: 12px;
  font-weight: 600;
  color: var(--green-dark);
  margin-bottom: 2px;
}
.bubble .text { font-size: 14px; line-height: 1.4; white-space: pre-wrap; }
.bubble .text a { color: var(--green-dark); text-decoration: none; }
.bubble .text a:hover { text-decoration: underline; }
.bubble .time {
  font-size: 11px;
  color: var(--text-secondary);
  text-align: right;
  margin-top: 4px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
}

/* Mídias */
.media-img {
  max-width: 100%;
  max-height: 320px;
  border-radius: 6px;
  display: block;
  cursor: zoom-in;
  transition: opacity 0.2s;
}
.media-img:hover { opacity: 0.9; }
.media-audio { width: 100%; margin-top: 4px; }
.media-video { max-width: 100%; max-height: 320px; border-radius: 6px; }
.media-doc {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  background: var(--bg-general);
  border-radius: 8px;
  text-decoration: none;
  color: var(--text-main);
  transition: background 0.2s;
}
.media-doc:hover { background: #e5e7ea; }
.media-doc .doc-icon { font-size: 26px; }
.media-doc .doc-name { font-size: 13px; word-break: break-all; }

/* Mensagens de sistema */
.msg-system { text-align: center; margin: 10px 0; font-size: 12px; color: var(--text-secondary); }
.msg-system .sys-badge {
  background: #fff;
  padding: 5px 14px;
  border-radius: 8px;
  display: inline-block;
  box-shadow: var(--shadow);
}
.msg-deleted { font-style: italic; color: var(--text-secondary); }
.msg-call { color: var(--green-dark); font-weight: 500; }

/* Rodapé */
.chat-footer {
  padding: 10px 16px;
  background: var(--bg-general);
  border-top: 1px solid var(--border);
  text-align: center;
}
.chat-footer span { font-size: 12px; color: var(--text-disabled); }

/* ===== Lightbox ===== */
.lightbox {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}
.lightbox-img { max-width: 90%; max-height: 90%; border-radius: 4px; }
.lightbox-close {
  position: absolute;
  top: 20px; right: 20px;
  background: none;
  border: none;
  color: #fff;
  font-size: 30px;
  cursor: pointer;
}
.lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(255,255,255,0.2);
  border: none;
  color: #fff;
  font-size: 40px;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.lightbox-nav:hover { background: rgba(255,255,255,0.4); }
.lightbox-prev { left: 20px; }
.lightbox-next { right: 20px; }

/* ===== Modal ===== */
.modal {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(2px);
}
.modal-content {
  background: #fff;
  border-radius: 14px;
  width: 460px;
  max-width: 92%;
  box-shadow: 0 12px 40px rgba(0,0,0,0.3);
  animation: modalIn 0.2s ease;
}
@keyframes modalIn {
  from { transform: scale(0.95); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
.modal-header {
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.modal-header h3 { font-size: 17px; }
.modal-close { background: none; border: none; font-size: 20px; cursor: pointer; color: var(--text-secondary); }
.modal-close:hover { color: var(--text-main); }
.modal-body { padding: 22px; }
.modal-body label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--text-secondary); }
.modal-body input[type="text"] {
  width: 100%;
  padding: 11px 12px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  margin-bottom: 18px;
  font-size: 14px;
  transition: border-color 0.2s;
}
.modal-body input[type="text"]:focus { outline: none; border-color: var(--green); }
.modal-body input[type="file"] {
  width: 100%;
  padding: 14px;
  border: 2px dashed var(--border);
  border-radius: 10px;
  margin-bottom: 12px;
  font-size: 13px;
  cursor: pointer;
  transition: border-color 0.2s;
}
.modal-body input[type="file"]:hover { border-color: var(--green); }
.upload-status { font-size: 13px; color: var(--text-secondary); }
.upload-status.error { color: #d32f2f; }
.upload-status.success { color: var(--green-dark); }
.modal-footer {
  padding: 16px 22px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}
.btn-primary {
  padding: 11px 22px;
  background: var(--green);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}
.btn-primary:hover { background: var(--green-dark); }
.btn-primary:disabled { background: #ccc; cursor: not-allowed; }
.btn-secondary {
  padding: 11px 22px;
  background: var(--bg-general);
  color: var(--text-main);
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.2s;
}
.btn-secondary:hover { background: #e0e2e5; }

/* ===== Responsividade ===== */
@media (max-width: 768px) {
  .sidebar { width: 100%; min-width: 0; max-width: none; }
  .chat-area { display: none; }
  .chat-area.mobile-open { display: flex; }
  .sidebar.mobile-hidden { display: none; }
  .back-btn { display: block; }
  .messages { padding: 12px 16px; }
  .bubble { max-width: 80%; }
}
