/* ============================================================
   OMNI PORTAL - Main CSS
   ============================================================ */

:root {
  --sidebar-w: 240px;
  --topbar-h: 60px;
  --primary: #0d6efd;
  --success: #198754;
  --warning: #ffc107;
  --danger:  #dc3545;
  --sidebar-bg: #1a1d23;
  --sidebar-text: rgba(255,255,255,.75);
  --sidebar-active: rgba(13,110,253,.15);
  --topbar-bg: #fff;
  --content-bg: #f4f6fa;
  --card-bg: #fff;
  --border: #dee2e6;
  --radius: 12px;
  --shadow: 0 2px 12px rgba(0,0,0,.08);
}

[data-bs-theme="dark"] {
  --sidebar-bg: #0f1117;
  --topbar-bg: #1a1d23;
  --content-bg: #12151c;
  --card-bg: #1a1d23;
  --border: rgba(255,255,255,.1);
  --sidebar-text: rgba(255,255,255,.7);
}

* { box-sizing: border-box; }

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--content-bg);
  color: var(--bs-body-color);
  overflow-x: hidden;
}

/* ── Sidebar ─────────────────────────────────────────────── */
.sidebar {
  position: fixed;
  top: 0; left: 0;
  width: var(--sidebar-w);
  height: 100vh;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  z-index: 1030;
  transition: transform .3s ease;
  overflow: hidden;
}

.sidebar-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid rgba(255,255,255,.07);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: .75rem;
  text-decoration: none;
}

.logo-mark {
  width: 36px; height: 36px;
  background: linear-gradient(135deg, #0d6efd, #6f42c1);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 1.1rem;
  flex-shrink: 0;
}

.logo-text {
  color: #fff;
  font-weight: 700;
  font-size: .95rem;
  white-space: nowrap;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: .75rem 0;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,.1) transparent;
}

.nav-section-label {
  font-size: .65rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: rgba(255,255,255,.35);
  padding: .5rem 1.25rem .25rem;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .55rem 1.25rem;
  color: var(--sidebar-text);
  text-decoration: none;
  border-radius: 0;
  font-size: .875rem;
  font-weight: 500;
  transition: all .2s;
  position: relative;
  margin: 1px 0;
}

.sidebar-link i { font-size: 1.05rem; flex-shrink: 0; }

.sidebar-link:hover {
  background: rgba(255,255,255,.07);
  color: #fff;
}

.sidebar-link.active {
  background: var(--sidebar-active);
  color: var(--primary);
  font-weight: 600;
}

.sidebar-link.active::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--primary);
  border-radius: 0 3px 3px 0;
}

.badge-count {
  margin-left: auto;
  background: var(--danger);
  color: #fff;
  font-size: .65rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 20px;
  min-width: 20px;
  text-align: center;
}

.sidebar-footer {
  padding: 1rem 1.25rem;
  border-top: 1px solid rgba(255,255,255,.07);
}

.status-dot {
  position: absolute;
  bottom: 0; right: 0;
  width: 10px; height: 10px;
  border-radius: 50%;
  border: 2px solid var(--sidebar-bg);
}
.status-online  { background: #22c55e; }
.status-away    { background: #f59e0b; }
.status-busy    { background: #ef4444; }
.status-offline { background: #9ca3af; }

/* ── Main wrapper ────────────────────────────────────────── */
.main-wrapper {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: margin-left .3s;
}

/* ── Topbar ──────────────────────────────────────────────── */
.topbar {
  height: var(--topbar-h);
  background: var(--topbar-bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  position: sticky;
  top: 0;
  z-index: 1020;
}

.topbar-search {
  background: var(--content-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .4rem .75rem;
  display: flex;
  align-items: center;
  gap: .5rem;
  width: 260px;
}

.topbar-search i { color: #9ca3af; font-size: .875rem; }

.topbar-search input {
  border: none;
  background: transparent;
  outline: none;
  font-size: .875rem;
  width: 100%;
  color: inherit;
}

.btn-icon {
  width: 36px; height: 36px;
  background: transparent;
  border: none;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: inherit;
  transition: background .2s;
}

.btn-icon:hover { background: var(--content-bg); }
.btn-icon i { font-size: 1.1rem; }

.notif-badge {
  position: absolute;
  top: 2px; right: 2px;
  width: 8px; height: 8px;
  background: var(--danger);
  border-radius: 50%;
  border: 1px solid #fff;
}

/* ── Content ─────────────────────────────────────────────── */
.main-content {
  flex: 1;
  padding: 1.5rem;
  overflow-y: auto;
}

/* ── Cards ───────────────────────────────────────────────── */
.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.card-header {
  background: transparent;
  border-bottom: 1px solid var(--border);
  padding: 1rem 1.25rem;
}

/* ── Stat Cards ──────────────────────────────────────────── */
.stat-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: .5rem;
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--accent, var(--primary));
}

.stat-icon {
  width: 44px; height: 44px;
  background: color-mix(in srgb, var(--accent, var(--primary)) 12%, transparent);
  color: var(--accent, var(--primary));
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
}

.stat-value {
  font-size: 2rem;
  font-weight: 800;
  line-height: 1;
}

.stat-label {
  font-size: .8rem;
  color: #6c757d;
}

/* ── Auth ────────────────────────────────────────────────── */
.auth-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  padding: 1rem;
}

.auth-container { width: 100%; max-width: 420px; }

.auth-card {
  background: var(--card-bg);
  border-radius: 20px;
  padding: 2.5rem;
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
}

.auth-logo {
  text-align: center;
  margin-bottom: 2rem;
}

.auth-logo-icon {
  width: 64px; height: 64px;
  background: linear-gradient(135deg, #0d6efd, #6f42c1);
  border-radius: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 2rem;
  margin: 0 auto 1rem;
}

/* ── Botões sidebar mobile ───────────────────────────────── */
.btn-sidebar-toggle, .btn-topbar-toggle {
  background: none;
  border: none;
  color: #fff;
  font-size: 1.25rem;
  cursor: pointer;
  padding: .25rem;
}

.btn-topbar-toggle { color: inherit; }

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 1029;
}

/* ── Chat ────────────────────────────────────────────────── */
.chat-wrapper {
  display: flex;
  height: calc(100vh - var(--topbar-h));
  margin: -1.5rem;
  background: var(--content-bg);
}

.chat-sidebar {
  width: 340px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  background: var(--card-bg);
  overflow: hidden;
}

.chat-sidebar-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.chat-filters { border-bottom: 1px solid var(--border); }

.filter-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: .75rem;
  padding: .2rem .65rem;
  color: #6c757d;
  cursor: pointer;
  transition: all .2s;
}

.filter-btn.active, .filter-btn:hover {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.chat-filter-row { border-bottom: 1px solid var(--border); }

.conversation-list {
  flex: 1;
  overflow-y: auto;
  scrollbar-width: thin;
}

.conv-item {
  display: flex;
  align-items: flex-start;
  gap: .75rem;
  padding: .875rem 1.25rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background .15s;
  position: relative;
}

.conv-item:hover { background: var(--content-bg); }
.conv-item.active { background: color-mix(in srgb, var(--primary) 8%, transparent); }

.conv-avatar { position: relative; flex-shrink: 0; }
.conv-avatar img { width: 42px; height: 42px; border-radius: 50%; object-fit: cover; }

.channel-badge {
  position: absolute;
  bottom: -2px; right: -2px;
  width: 18px; height: 18px;
  border-radius: 50%;
  border: 2px solid var(--card-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .55rem;
  color: #fff;
}

.ch-whatsapp    { background: #25d366; }
.ch-instagram   { background: #e1306c; }
.ch-facebook    { background: #1877f2; }
.ch-telegram    { background: #0088cc; }
.ch-webchat     { background: #6c757d; }

.conv-body { flex: 1; min-width: 0; }

.conv-name {
  font-weight: 600;
  font-size: .875rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-last {
  font-size: .78rem;
  color: #6c757d;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.conv-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  flex-shrink: 0;
}

.conv-time { font-size: .7rem; color: #9ca3af; }

.conv-unread {
  background: var(--primary);
  color: #fff;
  font-size: .65rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 20px;
  min-width: 20px;
  text-align: center;
}

.priority-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #9ca3af;
  flex-shrink: 0;
}
.priority-high, .priority-urgent { background: var(--danger); }
.priority-normal { background: var(--primary); }

/* ── Chat main ───────────────────────────────────────────── */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  position: relative;
}

.chat-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  opacity: .5;
}

.chat-header {
  padding: .875rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--card-bg);
  display: flex;
  align-items: center;
  gap: .75rem;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: .5rem;
  scrollbar-width: thin;
}

.msg-bubble-wrap {
  display: flex;
  gap: .5rem;
  max-width: 72%;
}

.msg-bubble-wrap.outgoing {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.msg-bubble {
  padding: .5rem .875rem;
  border-radius: 16px;
  font-size: .875rem;
  line-height: 1.5;
  position: relative;
  word-break: break-word;
}

.msg-bubble-wrap.incoming .msg-bubble {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.msg-bubble-wrap.outgoing .msg-bubble {
  background: var(--primary);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.msg-bubble.note {
  background: #fff9c4;
  border: 1px dashed #ffc107;
  color: #856404;
  font-style: italic;
}

.msg-bubble.event {
  background: transparent;
  border: none;
  color: #9ca3af;
  font-size: .75rem;
  font-style: italic;
  text-align: center;
  align-self: center;
  padding: .25rem;
}

.msg-time {
  font-size: .65rem;
  color: rgba(255,255,255,.65);
  margin-top: .25rem;
  text-align: right;
}

.msg-bubble-wrap.incoming .msg-time { color: #9ca3af; }

.msg-status { font-size: .7rem; }
.status-read { color: #60a5fa; }

.msg-image { max-width: 220px; border-radius: 10px; cursor: pointer; }
.msg-audio { max-width: 260px; }
.msg-file {
  display: flex;
  align-items: center;
  gap: .5rem;
  text-decoration: none;
  color: inherit;
}

/* Typing indicator */
.typing-indicator {
  display: flex;
  gap: 4px;
  align-items: center;
  padding: .5rem .875rem;
}
.typing-dot {
  width: 8px; height: 8px;
  background: #9ca3af;
  border-radius: 50%;
  animation: typing 1.4s infinite;
}
.typing-dot:nth-child(2) { animation-delay: .2s; }
.typing-dot:nth-child(3) { animation-delay: .4s; }
@keyframes typing { 0%,60%,100%{transform:translateY(0)} 30%{transform:translateY(-6px)} }

/* ── Chat input ──────────────────────────────────────────── */
.chat-input-area {
  border-top: 1px solid var(--border);
  background: var(--card-bg);
  padding: .875rem 1.25rem;
}

.chat-toolbar {
  display: flex;
  gap: .5rem;
  margin-bottom: .5rem;
  padding-bottom: .5rem;
  border-bottom: 1px solid var(--border);
}

.chat-toolbar .btn-icon { color: #6c757d; }
.chat-toolbar .btn-icon:hover { color: var(--primary); }

.chat-input-box {
  display: flex;
  gap: .75rem;
  align-items: flex-end;
}

.chat-input-box textarea {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: .625rem .875rem;
  resize: none;
  font-size: .875rem;
  max-height: 120px;
  background: var(--content-bg);
  color: inherit;
  outline: none;
  transition: border .2s;
}
.chat-input-box textarea:focus { border-color: var(--primary); }

.btn-send {
  width: 42px; height: 42px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.1rem;
  flex-shrink: 0;
  transition: background .2s;
}
.btn-send:hover { background: #0b5ed7; }

/* ── Detail panel ────────────────────────────────────────── */
.chat-detail {
  width: 300px;
  flex-shrink: 0;
  border-left: 1px solid var(--border);
  background: var(--card-bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-detail-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.chat-detail-body { flex: 1; overflow-y: auto; padding: 1.25rem; }

/* ── Status badges ───────────────────────────────────────── */
.badge-status-waiting   { background: #ffc107; color: #000; }
.badge-status-attending { background: #0d6efd; }
.badge-status-finished  { background: #198754; }
.badge-status-paused    { background: #6c757d; }
.badge-status-bot       { background: #6f42c1; }

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 991.98px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .sidebar-overlay.show { display: block; }
  .main-wrapper { margin-left: 0; }
  .chat-detail  { display: none !important; }
}

@media (max-width: 767.98px) {
  .chat-sidebar { width: 100%; }
  .chat-main    { display: none; }
  .chat-sidebar.chat-view-open { display: none; }
  .chat-main.chat-view-open    { display: flex; }
}

/* ── Toast ───────────────────────────────────────────────── */
.toast { border-radius: 10px; }

/* ── Quick replies dropdown ──────────────────────────────── */
.quick-replies {
  position: absolute;
  bottom: 100%;
  left: 0;
  right: 0;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 -8px 24px rgba(0,0,0,.1);
  max-height: 220px;
  overflow-y: auto;
  z-index: 100;
}

.quick-reply-item {
  padding: .625rem 1rem;
  cursor: pointer;
  font-size: .875rem;
  border-bottom: 1px solid var(--border);
}
.quick-reply-item:hover { background: var(--content-bg); }
.quick-reply-item:last-child { border-bottom: none; }

/* ── Scrollbar ───────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-thumb { background: rgba(0,0,0,.15); border-radius: 3px; }
[data-bs-theme="dark"] ::-webkit-scrollbar-thumb { background: rgba(255,255,255,.15); }

/* ── Utilitários ─────────────────────────────────────────── */
.text-truncate-2 {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.avatar-sm { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; }
.avatar-md { width: 48px; height: 48px; border-radius: 50%; object-fit: cover; }
.avatar-lg { width: 64px; height: 64px; border-radius: 50%; object-fit: cover; }

.notif-dropdown .dropdown-item { padding: .75rem 1rem; }

.sla-gauge { position: relative; }
.sla-pct {
  position: absolute;
  bottom: 0; left: 50%;
  transform: translateX(-50%);
  font-size: 1.75rem;
}
