:root {
  --ink: #16211e;
  --muted: #6e7c77;
  --line: #e3eae7;
  --canvas: #f5f8f7;
  --g950: #073f36;
  --g900: #075e54;
  --g800: #087466;
  --g700: #0b8f70;
  --g600: #10a977;
  --g100: #e6f8f0;
  --g50: #f2fbf7;
  --sidebar-top: #063f37;
  --sidebar-bottom: #052f2a;
  --logo-a: #baffdf;
  --logo-b: #3ee6a2;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Inter', sans-serif;
  -webkit-font-smoothing: antialiased;
  background: var(--canvas);
  color: var(--ink);
}

@keyframes pulseDot { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }
@keyframes toastIn { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: translateY(0); } }
[data-pulse="true"] { animation: pulseDot 2s ease-in-out infinite; }
@media (prefers-reduced-motion: reduce) { *, [data-pulse="true"] { animation: none !important; transition-duration: 0.01ms !important; } }

::selection { background: rgba(16,169,119,0.25); }

[data-scroll="sidebar"] { scrollbar-width: thin; scrollbar-color: rgba(50,217,149,0.45) transparent; }
[data-scroll="sidebar"]::-webkit-scrollbar { width: 8px; }
[data-scroll="sidebar"]::-webkit-scrollbar-track { background: transparent; }
[data-scroll="sidebar"]::-webkit-scrollbar-thumb { background: rgba(50,217,149,0.4); border-radius: 999px; }
[data-scroll="sidebar"]::-webkit-scrollbar-thumb:hover { background: rgba(50,217,149,0.6); }

[data-scroll="content"] { scrollbar-width: thin; scrollbar-color: rgba(11,143,112,0.35) transparent; }
[data-scroll="content"]::-webkit-scrollbar { width: 9px; }
[data-scroll="content"]::-webkit-scrollbar-track { background: transparent; }
[data-scroll="content"]::-webkit-scrollbar-thumb { background: rgba(11,143,112,0.3); border-radius: 999px; }
[data-scroll="content"]::-webkit-scrollbar-thumb:hover { background: rgba(11,143,112,0.5); }

.app-sidebar {
  background: radial-gradient(circle at 15% 8%, rgba(46,213,152,0.16), transparent 24%),
              linear-gradient(180deg, var(--sidebar-top) 0%, var(--sidebar-bottom) 100%);
  color: #e7f6f1;
  transition: width 180ms ease;
}
.app-sidebar.collapsed { width: 84px; }
.app-sidebar:not(.collapsed) { width: 320px; }
.app-sidebar.collapsed .sidebar-label { display: none; }
.app-sidebar.collapsed .cat-item { justify-content: center; }
.app-sidebar.collapsed .cat-item .cat-name,
.app-sidebar.collapsed .cat-item .cat-count { display: none; }
.app-sidebar.collapsed .sidebar-section { display: none; }

/* ---------- Sidebar accordion sections (Contatos / Assuntos / Buscas salvas) ---------- */
.sidebar-section { flex: 0 0 auto; border-top: 1px solid rgba(255,255,255,0.1); }
.sidebar-section:first-child { border-top: none; }
.sidebar-section-header {
  width: 100%; display: flex; align-items: center; gap: 8px; padding: 12px 16px;
  border: 0; background: none; cursor: pointer; font-family: inherit; text-align: left;
}
.sidebar-section-header:hover { background: rgba(255,255,255,0.06); }
.sidebar-section-title { font-size: 10px; font-weight: 800; color: #8cc7b8; text-transform: uppercase; letter-spacing: 0.08em; flex: 1; }
.sidebar-section-count { font-size: 10.5px; font-weight: 700; color: #d9f8e9; background: rgba(50,217,149,0.16); padding: 1px 8px; border-radius: 999px; }
.sidebar-section-chevron { color: #8cc7b8; flex-shrink: 0; transition: transform 160ms ease; }
.sidebar-section.collapsed .sidebar-section-chevron { transform: rotate(-90deg); }
.sidebar-section-body { overflow: hidden; }
.sidebar-section.collapsed .sidebar-section-body { display: none; }

.sidebar-selection-chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 16px 8px; }
.sidebar-selection-chips:empty { display: none; }
.selection-chip { cursor: default; }
.chip-x { cursor: pointer; margin-left: 2px; opacity: 0.75; }
.chip-x:hover { opacity: 1; }

.sidebar-search-input {
  width: 100%; padding: 8px 10px; border-radius: 9px; border: 1px solid rgba(255,255,255,0.18);
  background: rgba(255,255,255,0.06); color: #e7f6f1; font-size: 12px; font-family: inherit; margin-bottom: 8px;
}
.sidebar-search-input::placeholder { color: #8cc7b8; }
.sidebar-quick-filters { display: flex; gap: 6px; margin-bottom: 8px; }
.quick-filter {
  padding: 5px 10px; border-radius: 999px; border: 1px solid rgba(255,255,255,0.18); background: transparent;
  color: #bfe6d8; font-size: 10.5px; font-weight: 700; cursor: pointer; font-family: inherit;
}
.quick-filter.active { background: rgba(50,217,149,0.18); border-color: rgba(50,217,149,0.4); color: #d9f8e9; }

.contact-item { display: flex; align-items: center; gap: 10px; padding: 9px 8px; border-radius: 12px; cursor: pointer; }
.contact-item:hover { background: rgba(255,255,255,0.08); }
.contact-item.selected { background: rgba(50,217,149,0.14); }
.contact-item .contact-avatar { position: relative; width: 34px; height: 34px; flex-shrink: 0; }
.contact-item .contact-avatar-circle { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-size: 12px; font-weight: 800; }
.contact-item .contact-check { position: absolute; right: -2px; bottom: -2px; width: 14px; height: 14px; border-radius: 50%; background: #32d995; border: 2px solid #0c3a32; color: #073f36; font-size: 9px; font-weight: 900; display: grid; place-items: center; }
.contact-item .contact-body { min-width: 0; flex: 1; }
.contact-item .contact-name { font-size: 12.5px; font-weight: 600; color: #fff; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.contact-item .contact-meta { font-size: 10.5px; color: #8cc7b8; }
#noContacts { padding: 8px; font-size: 11.5px; color: #8cc7b8; }

.logo-mark {
  background: linear-gradient(145deg, var(--logo-a), var(--logo-b));
  color: var(--g950);
}

.kpi-card, .panel-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
  transition: transform 200ms ease, box-shadow 200ms ease, border-color 200ms ease;
}
.kpi-card:hover, .panel-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(20,51,42,0.08);
  border-color: #c8ddd5;
}

.cat-item, .live-contact, .day-block .day-header, .saved-item {
  cursor: pointer;
}

.day-block { border: 1px solid var(--line); border-radius: 13px; overflow: hidden; margin-bottom: 10px; background: #fff; }
.day-block .day-header { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; background: #fff; }
.day-block .day-header:hover { background: var(--g50); }
.day-block .msgs { display: none; flex-direction: column; gap: 8px; padding: 4px 16px 16px; background: var(--canvas); }
.day-block.open .msgs { display: flex; }
.day-block .badge { display: inline-block; padding: 2px 9px; border-radius: 999px; color: #fff; font-size: 11px; font-weight: 700; margin-left: 8px; }
.day-block .date { font-weight: 700; font-size: 13px; }
.msg { padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; font-size: 13px; }
.msg.me { background: var(--g50); border-color: #c8ddd5; }
.msg.sistema { color: var(--muted); font-style: italic; background: transparent; border: none; padding: 4px 0; }
.msg .meta { display: block; margin-top: 4px; color: var(--muted); font-size: 10.5px; }
.msg mark { background: #ffe58a; border-radius: 3px; padding: 0 2px; }
.msg .mark-me { margin-left: 8px; font-size: 10.5px; font-weight: 600; color: var(--g700); cursor: pointer; opacity: 0.7; }
.msg .mark-me:hover { opacity: 1; text-decoration: underline; }

.chip { display: inline-flex; align-items: center; gap: 4px; padding: 5px 10px; border-radius: 999px; background: var(--g100); color: var(--g900); font-size: 11.5px; font-weight: 600; }

.cat-item { display: flex; align-items: center; gap: 10px; padding: 9px 8px; border-radius: 12px; }
.cat-item:hover { background: rgba(255,255,255,0.08); }
.cat-item.active { background: rgba(50,217,149,0.14); }
.cat-item .cat-name { flex: 1; font-size: 12.5px; color: #fff; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat-item .cat-count { font-size: 10.5px; color: #8cc7b8; }
.cat-item .dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }

.saved-item { display: flex; align-items: center; gap: 8px; padding: 8px; border-radius: 9px; }
.saved-item:hover { background: rgba(255,255,255,0.08); }
.saved-item .sname { flex: 1; font-size: 12px; color: #e7f6f1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.saved-item .sdel { color: #8cc7b8; }

.live-modal { display: none; position: fixed; inset: 0; z-index: 1000; background: rgba(7,31,26,0.55); align-items: center; justify-content: center; }
.live-modal-content { background: #fff; border-radius: 16px; padding: 24px; width: 380px; max-width: 90vw; max-height: 85vh; overflow-y: auto; position: relative; box-shadow: 0 24px 60px rgba(7,31,26,0.35); }
.live-close { position: absolute; top: 14px; right: 14px; border: none; background: var(--canvas); width: 28px; height: 28px; border-radius: 8px; cursor: pointer; color: var(--muted); }
.live-status { margin: 8px 0 14px; font-size: 13px; color: var(--muted); }
.live-qr { display: none; width: 220px; height: 220px; margin: 0 auto 14px; border-radius: 12px; }
.live-contact-list { display: flex; flex-direction: column; gap: 6px; }
.live-contact { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 10px; background: var(--canvas); }
.live-contact:hover { background: var(--g50); }
.live-avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-size: 12px; font-weight: 800; flex-shrink: 0; }
.live-contact-name { font-size: 12.5px; font-weight: 600; }
.live-contact-preview { font-size: 11px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.live-progress { margin-top: 6px; }
.live-progress-track { height: 8px; border-radius: 999px; background: var(--canvas); overflow: hidden; }
.live-progress-bar { height: 100%; border-radius: 999px; background: var(--g600); transition: width 200ms ease; }
.live-progress-text { margin-top: 8px; font-size: 12px; color: var(--muted); text-align: center; }

.dropzone { border: 2px dashed var(--line); border-radius: 13px; padding: 22px; text-align: center; cursor: pointer; transition: border-color 160ms ease, background 160ms ease; }
.dropzone:hover, .dropzone.dragover { border-color: var(--g600); background: var(--g50); }
#uploadStatus.ok { color: #0b8f70; }
#uploadStatus.err { color: #e8877a; }

.gate-screen {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(circle at 18% 12%, rgba(50,217,149,0.28), transparent 45%),
    radial-gradient(circle at 85% 88%, rgba(11,143,112,0.28), transparent 50%),
    linear-gradient(160deg, var(--sidebar-top) 0%, var(--sidebar-bottom) 55%, #03150f 100%);
}
.gate-card {
  width: 100%;
  max-width: 560px;
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.22);
  border-radius: 24px;
  backdrop-filter: blur(22px) saturate(160%);
  -webkit-backdrop-filter: blur(22px) saturate(160%);
  box-shadow: 0 24px 70px rgba(3,20,16,0.45);
  padding: 44px 40px;
  text-align: center;
  color: #eafaf3;
}
.gate-btn { padding: 13px 22px; border-radius: 13px; font-size: 13.5px; font-weight: 700; cursor: pointer; font-family: inherit; border: 1px solid transparent; transition: transform 160ms ease, box-shadow 160ms ease, background 160ms ease; }
.gate-btn-primary { background: var(--g600); color: #fff; box-shadow: 0 10px 24px rgba(16,169,119,0.35); }
.gate-btn-primary:hover { transform: translateY(-1px); box-shadow: 0 14px 30px rgba(16,169,119,0.45); }
.gate-btn-secondary { background: rgba(255,255,255,0.1); color: #fff; border-color: rgba(255,255,255,0.35); }
.gate-btn-secondary:hover { background: rgba(255,255,255,0.18); }
.gate-card .dropzone { border-color: rgba(255,255,255,0.3); background: rgba(255,255,255,0.06); }
.gate-card .dropzone:hover, .gate-card .dropzone.dragover { border-color: #fff; background: rgba(255,255,255,0.14); }

.toast { position: fixed; right: 24px; bottom: 24px; z-index: 1200; padding: 12px 16px; border-radius: 12px; color: #fff; background: #123f36; font-size: 12.5px; font-weight: 600; animation: toastIn 220ms ease both; }

#loadingScreen { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: var(--canvas); color: var(--g800); font-weight: 700; z-index: 2000; }
#app { visibility: hidden; }

@media print { [data-print-hide="true"] { display: none !important; } }
