/* ============================================================
   FUNERÁRIA ATENDIMENTO - CSS PRINCIPAL
   ============================================================ */

:root {
  --primary:     #6366f1;
  --primary-d:   #4f46e5;
  --primary-l:   #e0e7ff;
  --success:     #10b981;
  --warning:     #f59e0b;
  --danger:      #ef4444;
  --info:        #3b82f6;

  --bg:          #f1f5f9;
  --surface:     #ffffff;
  --surface-2:   #f8fafc;
  --border:      #e2e8f0;
  --border-2:    #cbd5e1;

  --text:        #0f172a;
  --text-2:      #475569;
  --text-3:      #94a3b8;

  --sidebar-w:   220px;
  --radius:      8px;
  --shadow:      0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --shadow-lg:   0 10px 25px rgba(0,0,0,.12);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
  height: 100vh;
  overflow: hidden;
}

/* ===================== LOGIN ===================== */
.auth-page { display: flex; align-items: center; justify-content: center; }

.login-wrap {
  width: 100%; height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #667eea22, #764ba222);
}

.login-card {
  background: var(--surface);
  border-radius: 16px;
  padding: 40px;
  width: 380px;
  box-shadow: var(--shadow-lg);
}

.login-logo {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 24px;
  font-size: 20px; font-weight: 700; color: var(--primary);
}

.login-card h2 { font-size: 18px; font-weight: 600; margin-bottom: 24px; color: var(--text); }

/* ===================== FORMS ===================== */
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 12px; font-weight: 600; color: var(--text-2); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .04em; }

input[type=text], input[type=email], input[type=password], input[type=search],
textarea, select {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
  outline: none;
  transition: border-color .15s;
}
input:focus, textarea:focus, select:focus { border-color: var(--primary); }
textarea { resize: vertical; min-height: 80px; font-family: inherit; }

/* ===================== BUTTONS ===================== */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 16px;
  border: none; border-radius: var(--radius);
  font-size: 13px; font-weight: 600;
  cursor: pointer; transition: all .15s;
  text-decoration: none;
}
.btn-primary  { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-d); }
.btn-success  { background: var(--success); color: #fff; }
.btn-danger   { background: var(--danger); color: #fff; }
.btn-ghost    { background: transparent; color: var(--text-2); border: 1.5px solid var(--border); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-full     { width: 100%; justify-content: center; }
.btn-sm       { padding: 6px 12px; font-size: 12px; }

.btn-icon {
  background: none; border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  padding: 6px; border-radius: var(--radius);
  color: var(--text-2);
  transition: background .15s;
}
.btn-icon:hover { background: var(--surface-2); }
.btn-icon svg { width: 18px; height: 18px; }

/* ===================== ALERTS ===================== */
.alert { padding: 10px 14px; border-radius: var(--radius); font-size: 13px; margin-bottom: 16px; }
.alert-error  { background: #fef2f2; color: #dc2626; border: 1px solid #fecaca; }
.alert-success { background: #f0fdf4; color: #16a34a; border: 1px solid #bbf7d0; }

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

/* --- SIDEBAR --- */
.sidebar {
  width: var(--sidebar-w);
  background: #1e1b4b;
  display: flex; flex-direction: column;
  flex-shrink: 0;
  padding: 16px 0;
}

.sidebar-logo {
  display: flex; align-items: center; gap: 10px;
  padding: 0 16px 20px;
  color: #fff; font-size: 15px; font-weight: 700;
}

.sidebar-nav { flex: 1; padding: 0 8px; display: flex; flex-direction: column; gap: 2px; }

.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius);
  color: #a5b4fc;
  text-decoration: none;
  font-size: 13px; font-weight: 500;
  transition: all .15s;
  position: relative;
}
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }
.nav-item:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav-item.active { background: rgba(99,102,241,.3); color: #fff; }
.nav-item .badge {
  margin-left: auto;
  background: var(--danger);
  color: #fff;
  border-radius: 99px;
  font-size: 10px; font-weight: 700;
  padding: 1px 6px;
  min-width: 18px; text-align: center;
}

.sidebar-bottom {
  padding: 12px 8px 0;
  border-top: 1px solid rgba(255,255,255,.1);
  margin-top: auto;
  display: flex; align-items: center; gap: 8px;
}

.user-pill { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.user-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 12px;
  flex-shrink: 0;
}
.user-info { display: flex; flex-direction: column; min-width: 0; }
.user-info span:first-child { color: #fff; font-size: 12px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.role-badge { font-size: 10px; color: #a5b4fc; text-transform: capitalize; }

.sidebar-bottom .btn-icon { color: #a5b4fc; }
.sidebar-bottom .btn-icon:hover { background: rgba(255,255,255,.1); color: #fff; }

/* --- MAIN CONTENT --- */
.main-content { flex: 1; overflow: hidden; display: flex; flex-direction: column; }

/* --- VIEWS --- */
.view { display: none; flex: 1; overflow: hidden; flex-direction: column; }
.view.active { display: flex; }

.view-header {
  padding: 20px 24px 0;
  display: flex; align-items: center; justify-content: space-between;
}
.view-header h2 { font-size: 18px; font-weight: 700; }

/* ===================== CONVERSAS ===================== */
.conv-layout { display: flex; flex: 1; overflow: hidden; }

/* --- Lista de conversas --- */
.conv-list-panel {
  width: 340px; flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  overflow: hidden;
}

.panel-header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.panel-header h2 { font-size: 16px; font-weight: 700; }

.online-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--success);
  display: inline-block;
  box-shadow: 0 0 0 2px rgba(16,185,129,.25);
}

.filters { padding: 12px 12px 0; }
.search-input { margin-bottom: 10px; }

.filter-tabs { display: flex; gap: 4px; overflow-x: auto; padding-bottom: 10px; }
.filter-tab {
  padding: 5px 10px; border-radius: 99px;
  background: none; border: 1.5px solid var(--border);
  font-size: 12px; color: var(--text-2);
  cursor: pointer; white-space: nowrap;
  transition: all .15s;
}
.filter-tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }

.conv-list { flex: 1; overflow-y: auto; }

.conv-item {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background .1s;
  display: flex; gap: 10px;
  position: relative;
}
.conv-item:hover { background: var(--surface-2); }
.conv-item.active { background: var(--primary-l); }

.conv-avatar {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 14px; flex-shrink: 0;
}

.conv-info { flex: 1; min-width: 0; }
.conv-name { font-weight: 600; font-size: 13px; margin-bottom: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-preview { font-size: 12px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-meta { display: flex; justify-content: space-between; align-items: center; margin-top: 4px; }
.conv-time { font-size: 11px; color: var(--text-3); }
.conv-dept { font-size: 10px; font-weight: 600; padding: 2px 6px; border-radius: 99px; text-transform: uppercase; letter-spacing: .04em; }

/* Status badges nas conversas */
.status-dot {
  width: 8px; height: 8px; border-radius: 50%;
  position: absolute; top: 14px; right: 14px;
}
.status-dot.waiting     { background: var(--warning); }
.status-dot.in_progress { background: var(--success); }
.status-dot.resolved    { background: var(--text-3); }
.status-dot.sold        { background: var(--info); }
.status-dot.no_sale     { background: var(--danger); }

/* ===================== CHAT ===================== */
.chat-panel {
  flex: 1; display: flex; flex-direction: column;
  background: var(--bg);
  overflow: hidden;
}

.chat-empty {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 12px; color: var(--text-3);
}

.chat-content { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

.chat-header {
  background: var(--surface);
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px;
}

.chat-contact-info { display: flex; align-items: center; gap: 12px; }

.chat-avatar {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; flex-shrink: 0;
}

.chat-contact-name { font-weight: 700; font-size: 15px; }
.chat-contact-meta { font-size: 12px; color: var(--text-2); }

.chat-actions { display: flex; align-items: center; gap: 8px; }

.status-badge {
  padding: 4px 10px; border-radius: 99px;
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
}
.status-badge.waiting     { background: #fef3c7; color: #92400e; }
.status-badge.in_progress { background: #d1fae5; color: #065f46; }
.status-badge.resolved    { background: #f1f5f9; color: #475569; }
.status-badge.sold        { background: #dbeafe; color: #1e40af; }
.status-badge.no_sale     { background: #fee2e2; color: #991b1b; }

.action-btns { display: flex; gap: 6px; flex-wrap: wrap; }

/* Mensagens */
.messages-area {
  flex: 1; overflow-y: auto;
  padding: 20px;
  display: flex; flex-direction: column; gap: 8px;
}

.msg {
  max-width: 70%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.5;
  position: relative;
}
.msg-contact {
  align-self: flex-start;
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}
.msg-user {
  align-self: flex-end;
  background: var(--primary);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.msg-bot {
  align-self: flex-end;
  background: #e0e7ff;
  color: #3730a3;
  border-bottom-right-radius: 4px;
}
.msg-time { font-size: 10px; opacity: .6; margin-top: 4px; text-align: right; }
.msg-sender { font-size: 10px; font-weight: 700; opacity: .7; margin-bottom: 2px; text-transform: uppercase; }

.msg-date-divider {
  text-align: center; font-size: 11px;
  color: var(--text-3); margin: 8px 0;
}

/* Note */
.msg-note {
  align-self: center;
  background: #fffbeb;
  border: 1px dashed #fcd34d;
  color: #92400e;
  border-radius: var(--radius);
  font-size: 12px;
  padding: 8px 12px;
  max-width: 80%;
}

/* Input de mensagem */
.reply-tabs {
  display: flex; gap: 0;
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.reply-tab {
  flex: 1; padding: 10px;
  background: none; border: none;
  border-bottom: 2px solid transparent;
  font-size: 12px; font-weight: 600; color: var(--text-2);
  cursor: pointer; transition: all .15s;
}
.reply-tab.active { color: var(--primary); border-bottom-color: var(--primary); }

.message-input-wrap {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 12px 16px;
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.message-input-wrap textarea {
  flex: 1; min-height: 40px; max-height: 120px;
  resize: none; border-radius: var(--radius);
  padding: 8px 12px;
  font-size: 13px;
}
.btn-send { padding: 9px 18px; flex-shrink: 0; }

/* ===================== DASHBOARD ===================== */
.dashboard-grid {
  padding: 24px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  overflow-y: auto;
  align-content: start;
}

.stat-card {
  background: var(--surface);
  border-radius: 12px;
  padding: 20px;
  box-shadow: var(--shadow);
}
.stat-card .stat-label { font-size: 12px; font-weight: 600; color: var(--text-2); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 8px; }
.stat-card .stat-value { font-size: 36px; font-weight: 800; }
.stat-card .stat-sub { font-size: 12px; color: var(--text-3); margin-top: 4px; }

/* ===================== KNOWLEDGE ===================== */
.knowledge-list { padding: 20px 24px; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 12px; }

.knowledge-card {
  background: var(--surface);
  border-radius: 12px;
  padding: 16px;
  box-shadow: var(--shadow);
}
.knowledge-card-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 8px; }
.knowledge-card h4 { font-size: 14px; font-weight: 700; }
.knowledge-card p { font-size: 13px; color: var(--text-2); line-height: 1.6; }
.knowledge-card-actions { display: flex; gap: 6px; }

/* ===================== USUARIOS ===================== */
.users-list { padding: 20px 24px; overflow-y: auto; flex: 1; }
.users-table { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: 12px; overflow: hidden; box-shadow: var(--shadow); }
.users-table th { background: var(--surface-2); padding: 12px 16px; text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-2); }
.users-table td { padding: 12px 16px; border-top: 1px solid var(--border); font-size: 13px; }
.users-table tr:hover td { background: var(--surface-2); }

.role-pill {
  display: inline-block; padding: 2px 8px; border-radius: 99px;
  font-size: 11px; font-weight: 600; text-transform: capitalize;
}
.role-pill.admin      { background: #ede9fe; color: #5b21b6; }
.role-pill.supervisor { background: #dbeafe; color: #1e40af; }
.role-pill.agent      { background: #d1fae5; color: #065f46; }
.role-pill.seller     { background: #fef3c7; color: #92400e; }

.online-status { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; }
.online-status::before {
  content: ''; width: 8px; height: 8px; border-radius: 50%;
  background: var(--text-3);
}
.online-status.online::before { background: var(--success); }

/* ===================== CONFIGURAÇÕES ===================== */
#settings-content { padding: 24px; overflow-y: auto; flex: 1; }
.settings-section { background: var(--surface); border-radius: 12px; padding: 20px; margin-bottom: 16px; box-shadow: var(--shadow); }
.settings-section h3 { font-size: 15px; font-weight: 700; margin-bottom: 16px; color: var(--text); }
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ===================== MODAL ===================== */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
}
.modal {
  background: var(--surface);
  border-radius: 16px;
  width: 90%; max-width: 520px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}
.modal-header {
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; background: var(--surface); z-index: 1;
}
.modal-header h3 { font-size: 16px; font-weight: 700; }
.modal-close { background: none; border: none; font-size: 18px; cursor: pointer; color: var(--text-2); padding: 4px; }
#modal-body { padding: 20px 24px; }

/* ===================== MISC ===================== */
.empty-state { padding: 40px; text-align: center; color: var(--text-3); font-size: 14px; }

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 99px; }

.skeleton {
  background: linear-gradient(90deg, var(--border) 25%, var(--surface-2) 50%, var(--border) 75%);
  background-size: 200% 100%;
  animation: skeleton-anim 1.2s infinite;
  border-radius: 4px;
}
@keyframes skeleton-anim { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

.ai-badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 99px;
  font-size: 11px; font-weight: 600;
  background: #ede9fe; color: #5b21b6;
}
