/* ============================================================
   CRM — estilos complementares ao Tailwind CDN
   Sidebar escura fixa, layout, cards, toasts, modais, chat.
   ============================================================ */

:root {
  --sidebar-w: 240px;
}

/* ---------- Layout geral ---------- */
body {
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  background-color: #f8fafc; /* slate-50 */
  color: #1e293b; /* slate-800 — texto padrão no modo claro */
}

#app-layout {
  min-height: 100vh;
}

/* ---------- Sidebar fixa escura ---------- */
#sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-w);
  background-color: #0f172a; /* slate-900 */
  color: #e2e8f0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  transition: transform 0.25s ease;
}

#sidebar .nav-link {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.6rem 1rem;
  margin: 0.15rem 0.75rem;
  border-radius: 0.5rem;
  color: #cbd5e1;
  font-size: 0.875rem;
  font-weight: 500;
  transition: background-color 0.15s, color 0.15s;
}

#sidebar .nav-link:hover {
  background-color: #1e293b;
  color: #ffffff;
}

#sidebar .nav-link.active {
  background-color: #2563eb;
  color: #ffffff;
}

#sidebar .nav-link .icon {
  width: 1.15rem;
  text-align: center;
  flex-shrink: 0;
}

/* Conteúdo principal compensa a sidebar */
.main-content {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Botão hamburger (só aparece no mobile) */
#sidebar-toggle {
  display: none;
}

#sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  z-index: 40;
}

/* ---------- Cards ---------- */
.card {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 0.75rem; /* rounded-xl */
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.05);
}

/* ---------- Toasts ---------- */
#toast-container {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.toast {
  min-width: 260px;
  max-width: 360px;
  padding: 0.75rem 1rem;
  border-radius: 0.5rem;
  color: #ffffff;
  font-size: 0.875rem;
  box-shadow: 0 10px 15px -3px rgba(15, 23, 42, 0.25);
  animation: toast-in 0.2s ease;
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
}

.toast.success { background: #16a34a; }
.toast.error   { background: #dc2626; }
.toast.info    { background: #2563eb; }
.toast.warning { background: #d97706; }

.toast.hide { animation: toast-out 0.25s ease forwards; }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes toast-out {
  to { opacity: 0; transform: translateY(10px); }
}

/* ---------- Modais ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-hidden {
  display: none !important;
}

.modal-box {
  background: #ffffff;
  border-radius: 0.75rem;
  box-shadow: 0 20px 25px -5px rgba(15, 23, 42, 0.3);
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  animation: modal-in 0.15s ease;
}

@keyframes modal-in {
  from { opacity: 0; transform: scale(0.97) translateY(8px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

/* ---------- Bolhas de chat — estilo WhatsApp ---------- */
.chat-bubble {
  max-width: 65%;
  padding: 0.35rem 0.6rem 0.25rem;
  border-radius: 0.75rem;
  font-size: 0.8125rem; /* 13px */
  line-height: 1.4;
  word-break: break-word;
  white-space: pre-wrap;
  position: relative;
  overflow: hidden; /* evita que o float do chat-time vaze */
}

/* Mensagem recebida — cinza claro WhatsApp */
.chat-in {
  background: #e9edef;
  color: #1e293b;
  border-top-left-radius: 0.15rem;
}

/* Mensagem enviada — verde escuro WhatsApp */
.chat-out {
  background: #075e54;
  color: #ffffff;
  border-top-right-radius: 0.15rem;
}

/* Hora discreta — só HH:mm, flutuando para a direita */
.chat-time {
  display: inline-block;
  font-size: 0.625rem; /* 10px */
  margin-top: 0.05rem;
  margin-left: 0.5rem;
  float: right;
  line-height: 1.8;
  opacity: 0.75;
}

.chat-out .chat-time { color: rgba(255,255,255,0.75); }
.chat-in .chat-time  { color: #64748b; }

/* ---------- Kanban ---------- */
.kanban-column {
  background: #f1f5f9;
  border-radius: 0.75rem;
  padding: 0.75rem;
  min-width: 260px;
  flex: 1;
}

.kanban-deal {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 0.6rem;
  padding: 0.7rem;
  cursor: pointer;
  transition: box-shadow 0.15s, transform 0.1s;
}

.kanban-deal:hover {
  box-shadow: 0 4px 8px rgba(15, 23, 42, 0.12);
  transform: translateY(-1px);
}

.kanban-scroll {
  overflow-x: auto;
  padding-bottom: 0.5rem;
}

/* ---------- Tabelas ---------- */
.table-row-click {
  cursor: pointer;
}

.table-row-click:hover {
  background-color: #f1f5f9; /* slate-100 — hover visível no modo claro */
}

/* ---------- Spinner ---------- */
.spinner {
  border: 3px solid #e2e8f0;
  border-top-color: #2563eb;
  border-radius: 50%;
  width: 2rem;
  height: 2rem;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ---------- Responsivo ---------- */
@media (max-width: 768px) {
  :root { --sidebar-w: 0px; }

  #sidebar {
    transform: translateX(-100%);
  }

  #sidebar.open {
    transform: translateX(0);
  }

  #sidebar-backdrop.show {
    display: block;
  }

  #sidebar-toggle {
    display: inline-flex;
  }

  .main-content {
    margin-left: 0;
  }
}

/* ============================================================
   MODO ESCURO (grafite) — ativado pela classe .dark no <html>
   ============================================================ */

.dark body {
  background-color: #0f172a; /* slate-900 */
  color: #f1f5f9;
}

/* Cards e containers */
.dark .card {
  background-color: #1e293b; /* slate-800 */
  border-color: #334155;     /* slate-700 */
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}

/* Formulários: inputs, selects, textareas */
.dark input,
.dark select,
.dark textarea {
  background-color: rgba(51, 65, 85, 0.6); /* slate-700/60 */
  border-color: #475569;                    /* slate-600 */
  color: #f1f5f9;
}
.dark input::placeholder,
.dark textarea::placeholder {
  color: #64748b; /* slate-500 */
}
.dark select option {
  background-color: #1e293b;
  color: #f1f5f9;
}

/* Botões "fantasma" (borda cinza) */
.dark button.border-slate-300 {
  border-color: #475569;
  color: #e2e8f0;
}
.dark button.border-slate-300:hover {
  background-color: #334155;
}

/* Botões fantasma — hover correto no modo escuro */
.dark .hover\:bg-slate-50:hover  { background-color: #334155 !important; }
.dark button.hover\:bg-slate-50:hover { background-color: #334155; }

/* Botões destrutivos (vermelho) */
.dark .border-red-200 { border-color: #7f1d1d; }
.dark .text-red-600 { color: #f87171; }
.dark button.hover\:bg-red-50:hover { background-color: rgba(127, 29, 29, 0.35); }
.dark .hover\:text-red-600:hover { color: #f87171; }
.dark .text-red-500 { color: #f87171; }
.dark .text-red-500:hover { color: #fca5a5; }

/* Sidebar e header mobile */
.dark #sidebar {
  background-color: #0f172a;
}
.dark #sidebar .nav-link {
  color: #cbd5e1;
}
.dark #sidebar .nav-link:hover {
  background-color: #334155;
  color: #ffffff;
}
.dark #sidebar .nav-link.active {
  background-color: #1d4ed8;
  color: #ffffff;
}
.dark .main-content header {
  background-color: #1e293b;
  border-color: #334155;
  color: #e2e8f0;
}
.dark #sidebar-toggle {
  border-color: #475569;
  color: #e2e8f0;
}

/* Toasts */
.dark .toast {
  background-color: #1e293b;
  border: 1px solid #334155;
  color: #f1f5f9;
}
.dark .toast.success { background-color: #14532d; border-color: #166534; }
.dark .toast.error   { background-color: #7f1d1d; border-color: #991b1b; }
.dark .toast.info    { background-color: #1e3a8a; border-color: #1d4ed8; }
.dark .toast.warning { background-color: #78350f; border-color: #b45309; }

/* Spinner */
.dark .spinner {
  border-color: #334155;
  border-top-color: #3b82f6;
}

/* Modais */
.dark .modal-overlay {
  background: rgba(2, 6, 23, 0.7);
}
.dark .modal-box {
  background-color: #1e293b;
  border: 1px solid #334155;
}

/* Bolhas de chat — dark */
.dark .chat-in  { background: #202c33; color: #e9edef; }
.dark .chat-out { background: #005c4b; color: #ffffff; }
.dark .chat-in  .chat-time { color: #8696a0; }
.dark .chat-out .chat-time { color: rgba(255,255,255,0.6); }

/* Kanban */
.dark .kanban-column {
  background-color: #1e293b;
}
.dark .kanban-deal {
  background-color: #334155;
  border-color: #475569;
}
.dark .kanban-deal:hover {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

/* Tabelas */
.dark thead {
  background-color: rgba(51, 65, 85, 0.5); /* slate-700/50 */
}
.dark thead th {
  color: #cbd5e1;
}
.dark .table-row-click:hover {
  background-color: #334155;
}

/* Scrollbar escura (opcional) */
.dark ::-webkit-scrollbar { width: 10px; height: 10px; }
.dark ::-webkit-scrollbar-track { background: #0f172a; }
.dark ::-webkit-scrollbar-thumb { background: #334155; border-radius: 6px; }
.dark ::-webkit-scrollbar-thumb:hover { background: #475569; }

/* ============================================================
   LAYOUT WHATSAPP — conversation.html
   ============================================================ */

/* Faz .main-content ter altura fixa quando contém layout WA */
.main-content:has(.wa-main) {
  height: 100vh;
  overflow: hidden;
}

/* Container principal que substitui o <main> padrão */
.wa-main {
  flex: 1;
  min-height: 0;
  display: flex;
  overflow: hidden;
  position: relative;
}

/* Painel esquerdo — lista de conversas */
.wa-left {
  width: 320px;
  flex-shrink: 0;
  border-right: 1px solid #e2e8f0;
  display: flex;
  flex-direction: column;
  background: #ffffff;
  overflow: hidden;
}

.dark .wa-left {
  background: #1e293b;
  border-color: #334155;
}

/* Painel direito — chat */
.wa-right {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #f8fafc;
  position: relative;
}

.dark .wa-right {
  background: #0f172a;
}

/* Header do chat */
.wa-chat-header {
  display: flex;
  align-items: center;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid #e2e8f0;
  background: #ffffff;
  flex-shrink: 0;
}

.dark .wa-chat-header {
  background: #1e293b;
  border-color: #334155;
}

/* Avatar circular pequeno */
.wa-avatar {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  background: #e2e8f0;
  color: #475569;
  font-weight: 600;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.dark .wa-avatar {
  background: #334155;
  color: #cbd5e1;
}

/* Avatar maior para o painel info */
.wa-avatar-lg {
  width: 4rem;
  height: 4rem;
  border-radius: 50%;
  background: #e2e8f0;
  color: #475569;
  font-weight: 700;
  font-size: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.dark .wa-avatar-lg {
  background: #334155;
  color: #cbd5e1;
}

/* Item de conversa na lista */
.wa-conv-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 1rem;
  cursor: pointer;
  transition: background-color 0.12s;
  border-bottom: 1px solid #f1f5f9;
  position: relative;
}

.wa-conv-item:hover {
  background: #f1f5f9;
}

.dark .wa-conv-item {
  border-color: #1e293b;
}

.dark .wa-conv-item:hover {
  background: #334155;
}

.wa-conv-item.active {
  background: #eff6ff;
}

.dark .wa-conv-item.active {
  background: #1e3a5f;
}

/* Badge de não-lidas */
.wa-badge {
  background: #2563eb;
  color: #ffffff;
  font-size: 0.65rem;
  font-weight: 700;
  border-radius: 999px;
  padding: 0.1rem 0.45rem;
  min-width: 1.2rem;
  text-align: center;
}

/* Botão arquivar inline */
.wa-archive-btn {
  font-size: 1rem;
  padding: 0.25rem;
  border-radius: 0.375rem;
  color: #94a3b8;
  background: transparent;
  border: none;
  cursor: pointer;
  transition: opacity 0.15s, background-color 0.12s;
  line-height: 1;
  flex-shrink: 0;
}

.wa-archive-btn:hover {
  background: #e2e8f0;
  color: #475569;
}

.dark .wa-archive-btn:hover {
  background: #475569;
  color: #e2e8f0;
}

/* Painel Info — overlay lateral */
.wa-info {
  position: absolute;
  top: 0;
  right: 0;
  width: 300px;
  height: 100%;
  background: #ffffff;
  border-left: 1px solid #e2e8f0;
  display: flex;
  flex-direction: column;
  z-index: 20;
  box-shadow: -4px 0 12px rgba(15, 23, 42, 0.08);
  animation: slide-in-right 0.2s ease;
}

.dark .wa-info {
  background: #1e293b;
  border-color: #334155;
  box-shadow: -4px 0 12px rgba(0, 0, 0, 0.4);
}

@keyframes slide-in-right {
  from { transform: translateX(100%); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

.wa-info-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem;
  border-bottom: 1px solid #e2e8f0;
  flex-shrink: 0;
}

.dark .wa-info-header {
  border-color: #334155;
}

/* Mobile responsivo */
@media (max-width: 768px) {
  .wa-left {
    width: 100%;
    border-right: none;
  }

  .wa-right {
    position: absolute;
    inset: 0;
    z-index: 10;
  }

  .wa-right.mobile-hidden {
    display: none;
  }

  .wa-left.mobile-hidden {
    display: none;
  }

  .wa-info {
    width: 100%;
  }
}

@media (min-width: 769px) {
  .wa-right {
    position: relative;
  }
}

/* Remove o padding padrão do <main> quando em modo WA */
.main-content main.wa-main {
  padding: 0 !important;
}

/* Avatar pequeno ao lado das mensagens recebidas */
.wa-avatar-sm {
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 50%;
  background: #e2e8f0;
  color: #475569;
  font-size: 0.65rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
}
.dark .wa-avatar-sm { background: #334155; color: #cbd5e1; }

/* Botão info no hover da mensagem */
.msg-info-btn {
  font-size: 0.6rem;
  padding: 0.15rem 0.35rem;
  border-radius: 9999px;
  background: rgba(0, 0, 0, 0.08);
  color: #64748b;
  border: none;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s;
  align-self: center;
  flex-shrink: 0;
  line-height: 1.4;
}
.dark .msg-info-btn { background: rgba(255,255,255,0.1); color: #94a3b8; }
.msg-row:hover .msg-info-btn { opacity: 1; }

/* Popover de informações da mensagem */
.msg-popover {
  position: absolute;
  bottom: calc(100% + 4px);
  z-index: 50;
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 0.5rem;
  padding: 0.5rem 0.75rem;
  font-size: 0.75rem;
  color: #1e293b;
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.15);
  white-space: nowrap;
  min-width: 210px;
  pointer-events: none;
}
.msg-row.justify-end  .msg-popover { right: 0; }
.msg-row.justify-start .msg-popover { left: 0; }
.dark .msg-popover {
  background: #1e293b;
  border-color: #334155;
  color: #e2e8f0;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}
