/* =====================================================================
   Sidebar do CRM - paleta e tipografia herdadas do /restrito do site.
   Menu vertical fixo à esquerda, com user card flutuante no rodapé.
   ===================================================================== */

:root {
  --sb-w: 218px;
  --sb-primary: #4b2cff;
  --sb-primary-hover: #0a6a40;
  --sb-secondary: #00c7a8;
  --sb-bg: #ffffff;
  --sb-surface: #f4f6f5;
  --sb-surface-2: #eef1ef;
  --sb-text: #232323;
  --sb-muted: #6f7772;
  --sb-border: rgba(35, 35, 35, .08);
  --sb-border-strong: rgba(75, 44, 255, .22);
  --sb-active-soft: rgba(75, 44, 255, .08);
  --sb-danger: #c2414a;
  --sb-shadow: none;
}

/* ---------- Container ----------
   Escopado em .crm-aside (e não em .sidebar puro) porque o chat usa
   <aside class="sidebar"> interno; sem esse escopo, as regras vazavam. */

.crm-aside {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sb-w);
  background: var(--sb-bg);
  color: var(--sb-text);
  font-family: 'Manrope', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--sb-border);
  box-shadow: none;
  z-index: 50;
  overflow-y: auto;
}
.crm-aside::-webkit-scrollbar { width: 6px; }
.crm-aside::-webkit-scrollbar-thumb { background: rgba(0,0,0,.12); border-radius: 4px; }

/* ---------- Brand (logo + busca) ---------- */

.sidebar__brand {
  padding: 16px 12px 14px;
  border-bottom: 0;
  /* Degrade espelhado do footer: cor de surface no topo → branco na base (funde com o nav) */
  background: linear-gradient(
    to bottom,
    var(--sb-surface) 0%,
    var(--sb-surface) 45%,
    var(--sb-bg) 100%
  );
  display: flex;
  align-items: center;
  gap: 8px;
  position: relative; /* ancora o .sb-brand-dropdown */
}
.sidebar__brand-logo {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--sb-primary);
  text-decoration: none;
  font-weight: 700;
  font-size: 14px;
}
.sidebar__brand-logo img {
  max-height: 32px;
  max-width: 100%;
  width: auto;
  display: block;
  object-fit: contain;
}

/* ---------- Cartão de identidade da unidade (substitui logo) ---------- */
.sb-brand-card {
  display: flex !important;
  flex-direction: column !important;
  align-items: stretch !important;
  gap: 2px !important;
  padding: 2px 0;
  line-height: 1.2;
  min-width: 0;
}
.sb-brand-card:hover { text-decoration: none; }

/* Cada linha: conteúdo principal + chip/info compacta ao lado */
.sb-brand-card__row {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}
.sb-brand-card__row--sub { gap: 5px; }

.sb-brand-card__name {
  font: 800 20px 'Manrope', system-ui, sans-serif;
  color: var(--sb-primary);
  letter-spacing: -0.8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1 1 auto;
  min-width: 0;
}
.sb-brand-card__name--fallback { color: var(--sb-text); }

.sb-brand-card__razao {
  font: 500 10px 'Manrope', system-ui, sans-serif;
  color: var(--sb-text);
  opacity: .60;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1 1 auto;
  min-width: 0;
}

/* CNPJ inline na segunda linha — 1px menor que a razão, fonte tabular */
.sb-brand-card__cnpj {
  font: 600 9px 'Manrope', system-ui, sans-serif;
  color: var(--sb-text);
  opacity: .55;
  letter-spacing: .15px;
  font-feature-settings: "tnum" 1;
  white-space: nowrap;
  flex: 0 0 auto;
}

/* Pílula de Tipo (Matriz/Filial) — virou ícone-only com tooltip pra economizar espaço.
 * Texto fica escondido visualmente mas continua acessível por screen readers. */
.sb-brand-card__pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  padding: 0;
  border-radius: 50%;
  flex: 0 0 auto;
  background: rgba(75, 44, 255, .07);
  color: var(--sb-primary);
  border: 1px solid rgba(75, 44, 255, .10);
  cursor: help;
  transition: transform .12s, background .12s, border-color .12s;
}
.sb-brand-card__pill:hover { transform: scale(1.08); }
.sb-brand-card__pill i { font-size: 10px; opacity: .9; }
/* Esconde o texto visualmente mas mantém acessível ao screen reader */
.sb-brand-card__pill__sr {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Matriz: cor visual destacada (âmbar). Sem hover fica "limpo" (fundo e borda
 * transparentes); no hover destaca o fundo âmbar mas continua sem borda. */
.sb-brand-card__pill--matriz {
  background: transparent;
  border-color: transparent;
  color: #b8841a;
}
.sb-brand-card__pill--matriz:hover {
  background: rgba(184, 132, 26, .22);
  border-color: transparent;
}

/* Filial: opaca, em tom cinza pra ficar menos protagonista */
.sb-brand-card__pill--filial {
  background: rgba(110, 119, 128, .10);
  border-color: rgba(110, 119, 128, .22);
  color: #6f7772;
  opacity: .75;
}
.sb-brand-card__pill--filial:hover {
  background: rgba(110, 119, 128, .18);
  border-color: rgba(110, 119, 128, .40);
  color: #495157;
  opacity: 1;
}

/* ---------- Brand switcher (toggle + dropdown de troca de unidade) ---------- */
.sb-brand-toggle {
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  border-radius: 6px;
  border: 0;
  background: transparent;
  color: var(--sb-text);
  opacity: .50;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  transition: opacity .15s, background .15s, transform .2s;
  padding: 0;
}
.sb-brand-toggle:hover { opacity: 1; background: rgba(0,0,0,.05); }
body.sb-switcher-open .sb-brand-toggle {
  opacity: 1;
  background: rgba(0,199,168,.14);
  color: var(--sb-primary);
  transform: rotate(180deg);
}

.sb-brand-dropdown {
  position: absolute;
  top: calc(100% - 1px);
  left: 8px;
  right: 8px;
  margin-top: 6px;
  background: #fff;
  border: 1px solid rgba(0,0,0,.10);
  border-radius: 10px;
  box-shadow: 0 8px 28px rgba(0,0,0,.10), 0 2px 6px rgba(0,0,0,.04);
  padding: 6px;
  max-height: 60vh;
  overflow-y: auto;
  z-index: 90;
}
.sb-brand-dropdown[hidden] { display: none; }
.sb-brand-dropdown__title {
  font: 800 9.5px 'Manrope', system-ui, sans-serif;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--sb-muted);
  padding: 8px 10px 6px;
}
.sb-brand-dropdown__list {
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin: 0;
}
.sb-brand-dropdown__item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 10px;
  cursor: pointer;
  color: var(--sb-text);
  font-family: inherit;
  line-height: 1.2;
  transition: background .12s, border-color .12s;
}
.sb-brand-dropdown__item:hover {
  background: rgba(0,199,168,.10);
  border-color: rgba(0,199,168,.22);
}
.sb-brand-dropdown__item.is-current {
  background: rgba(0,199,168,.14);
  border-color: rgba(0,199,168,.38);
  cursor: default;
}
.sb-brand-dropdown__item.is-current:hover { background: rgba(0,199,168,.14); }
.sb-brand-dropdown__check {
  font-size: 10px;
  color: var(--sb-primary);
  margin-left: 2px;
  flex: 0 0 auto;
}
/* Diminui levemente o nome dentro dos itens do dropdown — não compete com o card principal */
.sb-brand-dropdown__item .sb-brand-card__name { font-size: 13px; }

/* ---------- Aviso de impersonação (rodapé da sidebar) ---------- */
.sb-impersonation {
  margin-top: 10px;
  padding: 10px 12px;
  background: rgba(184, 132, 26, .07);
  border: 1px solid rgba(184, 132, 26, .22);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  line-height: 1.2;
}
.sb-impersonation__top {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.sb-impersonation__icon {
  font-size: 10px;
  color: #b8841a;
}
.sb-impersonation__label {
  font: 800 9.5px 'Manrope', system-ui, sans-serif;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: #b8841a;
}
.sb-impersonation__name {
  display: flex;
  align-items: baseline;
  gap: 5px;
  min-width: 0;
}
.sb-impersonation__apelido {
  font: 800 13px 'Manrope', system-ui, sans-serif;
  color: var(--sb-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 0 1 auto;
  min-width: 0;
}
.sb-impersonation__razao {
  font: 500 10px 'Manrope', system-ui, sans-serif;
  color: var(--sb-text);
  opacity: .55;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 0 1 auto;
  min-width: 0;
}
.sb-impersonation__back { margin: 2px 0 0; }
.sb-impersonation__back button {
  width: 100%;
  background: #b8841a;
  color: #fff;
  border: 0;
  padding: 6px 10px;
  border-radius: 7px;
  font: 700 11px 'Manrope', system-ui, sans-serif;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  transition: background .15s;
}
.sb-impersonation__back button:hover { background: #a07417; }
.sb-impersonation__back button i { font-size: 10px; }

.sb-search-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background: #fff;
  color: var(--sb-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 13px;
  transition: background .15s, color .15s, border-color .15s, transform .05s;
}
.sb-search-btn:hover {
  background: var(--sb-active-soft);
  color: var(--sb-primary);
  border-color: var(--sb-border-strong);
}
.sb-search-btn:active { transform: scale(.96); }

/* ---------- Nav principal ---------- */

.sidebar__nav {
  padding: 12px 10px 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.sidebar__nav a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 9px;
  color: var(--sb-text);
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  transition: background .15s ease, color .15s ease;
}
.sidebar__nav a i {
  width: 18px;
  text-align: center;
  color: var(--sb-muted);
  font-size: 12px;
}
.sidebar__nav a:hover {
  background: var(--sb-active-soft);
  color: var(--sb-primary);
  text-decoration: none;
}
.sidebar__nav a:hover i { color: var(--sb-primary); }
.sidebar__nav a.is-active {
  background: var(--sb-primary);
  color: #fff;
  font-weight: 700;
  box-shadow: none;
}
.sidebar__nav a.is-active i { color: var(--sb-secondary); }
.sidebar__nav a.is-active:hover { background: var(--sb-primary-hover); color: #fff; }
.sidebar__nav a.is-active:hover i { color: var(--sb-secondary); }

/* ---------- Rodapé: instâncias + user card ---------- */

.sidebar__footer {
  margin-top: auto;
  padding: 12px 10px 12px;
  border-top: 0;
  /* Degrade suave do branco (topo, integra com o nav) até a cor de surface (base) */
  background: linear-gradient(
    to bottom,
    var(--sb-bg) 0%,
    var(--sb-surface) 55%,
    var(--sb-surface) 100%
  );
}

.sb-instances {
  display: flex;
  flex-direction: column;
  margin-bottom: 10px;
}
.sb-inst__title {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--sb-muted);
  padding: 0 6px 8px;
  font-weight: 700;
}
.sb-inst {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 9px;
  border: 0;
  text-decoration: none;
  color: var(--sb-text);
  margin-bottom: 3px;
  background: #fff;
  transition: background .15s, transform .05s;
}
.sb-inst:hover {
  background: var(--sb-active-soft);
  text-decoration: none;
}
.sb-inst:active { transform: translateY(1px); }
.sb-inst.is-active {
  background: rgba(0, 199, 168, .14);
  color: var(--sb-text);
}
.sb-inst.is-active .sb-inst__name { color: var(--sb-primary); font-weight: 800; }
.sb-inst.is-active:hover { background: rgba(0, 199, 168, .20); }

.sb-inst__dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--sb-muted);
}
.sb-inst__dot.on {
  background: var(--sb-secondary);
  box-shadow: none;
}
.sb-inst__dot.off { background: var(--sb-danger); }
.sb-inst__dot.all {
  background: linear-gradient(135deg, var(--sb-secondary), var(--sb-primary));
}
.sb-inst.is-active .sb-inst__dot { box-shadow: none; }

.sb-inst__body { display: flex; flex-direction: column; flex: 1; min-width: 0; line-height: 1.2; }
.sb-inst__name {
  font-size: 13px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sb-inst__meta {
  font-size: 11px;
  color: var(--sb-muted);
  margin-top: 2px;
}
.sb-inst.is-active .sb-inst__meta { color: var(--sb-muted); }
.sb-inst__check { font-size: 11px; color: var(--sb-primary); }

/* ---------- User bar (avatar + nome + nível + ...) ---------- */

.sb-userbar {
  position: relative;
  margin-top: 8px;
}
.sb-userbar > summary {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 6px 8px 10px;
  border-radius: 10px;
  background: #fff;
  border: 0;
  cursor: pointer;
  list-style: none;
  user-select: none;
  transition: background .15s ease;
}
.sb-userbar > summary::-webkit-details-marker,
.sb-userbar > summary::marker { display: none; }
.sb-userbar > summary:hover {
  background: var(--sb-active-soft);
}
.sb-userbar[open] > summary {
  background: var(--sb-active-soft);
}

.sb-userbar__avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--sb-primary);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 12px;
  flex-shrink: 0;
}
.sb-userbar__avatar img {
  width: 100%; height: 100%;
  border-radius: 50%;
  object-fit: cover;
}
.sb-userbar__info {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column;
  line-height: 1.2;
}
.sb-userbar__name {
  font-size: 12px;
  font-weight: 700;
  color: var(--sb-text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sb-userbar__role {
  font-size: 10px;
  color: var(--sb-muted);
}
.sb-userbar__icon {
  color: var(--sb-muted);
  font-size: 13px;
  padding: 6px 8px;
  border-radius: 6px;
  transition: background .15s ease, color .15s ease;
}
.sb-userbar:hover .sb-userbar__icon,
.sb-userbar[open] .sb-userbar__icon {
  color: var(--sb-primary);
  background: rgba(75, 44, 255, .12);
}

/* Dropdown abrindo PARA CIMA */
.sb-userbar__menu {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 0;
  right: 0;
  /* Fundo levemente off-white + borda mais marcada + sombra subindo pra destacar
     do menu (que também é branco) — evita o efeito "nada aconteceu". */
  background: #f4f7f4;
  border: 1px solid rgba(75, 44, 255, .14);
  border-radius: 10px;
  box-shadow: 0 -10px 28px rgba(15, 23, 42, .12), 0 -2px 8px rgba(15, 23, 42, .04);
  padding: 8px;
  z-index: 70;
  animation: sbUserbarPop .14s ease-out;
}
@keyframes sbUserbarPop {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.sb-userbar__group {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--sb-muted);
  padding: 8px 10px 4px;
  font-weight: 700;
}
.sb-userbar__menu a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 7px;
  color: var(--sb-text);
  text-decoration: none;
  font-size: 13px;
  transition: background .15s, color .15s;
}
.sb-userbar__menu a i {
  width: 16px;
  text-align: center;
  color: var(--sb-muted);
  font-size: 13px;
}
.sb-userbar__menu a:hover {
  /* Branco no hover sobre fundo off-white = "card flutuante" — contraste claro */
  background: #ffffff;
  color: var(--sb-primary);
  text-decoration: none;
}
.sb-userbar__menu a:hover i { color: var(--sb-primary); }
.sb-userbar__sep {
  height: 1px;
  background: var(--sb-border);
  margin: 8px 4px;
}
.sb-userbar__sair { color: var(--sb-danger) !important; }
.sb-userbar__sair i { color: var(--sb-danger) !important; }
.sb-userbar__sair:hover {
  background: rgba(194, 65, 74, .08) !important;
  color: var(--sb-danger) !important;
}
.sb-userbar__sair:hover i { color: var(--sb-danger) !important; }

/* ---------- Modal de busca ---------- */

.search-modal {
  width: min(560px, 92vw);
  max-width: 100%;
  border: 1px solid var(--sb-border);
  border-radius: 14px;
  padding: 0;
  box-shadow: none;
  background: #fff;
  color: var(--sb-text);
  font-family: 'Manrope', system-ui, sans-serif;
  margin-top: 18vh;
}
.search-modal::backdrop {
  background: rgba(8, 14, 12, .55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.search-modal__form {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 14px;
}
.search-modal__icon {
  color: var(--sb-muted);
  font-size: 16px;
  margin-left: 4px;
}
.search-modal__form input {
  flex: 1;
  border: 0;
  outline: none;
  background: transparent;
  font-family: inherit;
  font-size: 16px;
  color: var(--sb-text);
  padding: 8px 0;
}
.search-modal__form input::placeholder { color: var(--sb-muted); }
.search-modal__close {
  width: 32px; height: 32px;
  border: 0;
  background: var(--sb-surface);
  color: var(--sb-muted);
  border-radius: 8px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  font-size: 13px;
}
.search-modal__close:hover {
  background: var(--sb-surface-2);
  color: var(--sb-text);
}

/* ---------- Empurra e alinha o conteúdo principal ---------- */
/*
 * app.css já define para .container--app:
 *   margin: 16px 16px 16px 0; padding: 28px 34px 42px; min-height: calc(100vh - 32px);
 * Aqui reescrevemos a margem-esquerda para encaixar no sidebar e ajustamos
 * a largura para evitar overflow horizontal (margens contam fora do width).
 */
body.app-body { padding: 0 !important; }
body.app-body main.container--app {
  margin: 0px 0px 0px var(--sb-w);
  width: calc(100% - var(--sb-w));
  min-height: 100vh;
}

/* Esconde o antigo topbar caso ainda esteja renderizando em alguma tela */
body.app-body > header.topbar { display: none !important; }

/* ---------- Mobile ---------- */

@media (max-width: 980px) {
  body.app-body { padding: 0 !important; }
  body.app-body main.container--app {
    margin: 16px;
    width: calc(100% - 32px);
  }
  .sidebar {
    transform: translateX(-100%);
    transition: transform .25s ease;
  }
  body.sb-open .sidebar { transform: translateX(0); }
  .sb-toggle {
    position: fixed; top: 12px; left: 12px;
    width: 40px; height: 40px;
    border-radius: 8px;
    background: var(--sb-primary); color: #fff;
    border: 0; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    z-index: 60; font-size: 16px;
    box-shadow: none;
  }
}
@media (min-width: 981px) {
  .sb-toggle { display: none; }
}

/* Garante que os ícones do FA dentro do sidebar fiquem visíveis e do tamanho certo
   (alguns resets globais com `i { display: ... }` poderiam interferir). */
.sidebar i,
.sb-userbar i,
.sb-inst i,
.search-modal i { font-style: normal !important; line-height: 1; }

/* ===== Alerta de WhatsApp desconectado (reconexão) ===== */
.sb-disc{
  display:flex;align-items:center;gap:10px;
  margin:10px 12px 4px;
  padding:10px 12px;
  border-radius:12px;
  background:linear-gradient(180deg, rgba(248,81,73,.20), rgba(248,81,73,.12));
  border:1px solid rgba(216,63,53,.50);
  color:#8a1c12;
  text-decoration:none;
  transition:background .15s, border-color .15s, transform .06s;
  animation:sbDiscPulse 2.4s ease-in-out infinite;
}
.sb-disc:hover{background:rgba(248,81,73,.28);border-color:rgba(216,63,53,.70);}
.sb-disc:active{transform:scale(.985);}
.sb-disc__ico{
  flex:0 0 auto;width:30px;height:30px;border-radius:50%;
  display:inline-flex;align-items:center;justify-content:center;
  background:#e5443b;color:#fff;font-size:14px;
}
.sb-disc__body{display:flex;flex-direction:column;min-width:0;flex:1;}
.sb-disc__title{font:800 12px 'Manrope',system-ui,sans-serif;color:#7a160d;line-height:1.2;}
.sb-disc__sub{font:600 11px 'Manrope',system-ui,sans-serif;color:#9a3b33;
  white-space:nowrap;overflow:hidden;text-overflow:ellipsis;margin-top:1px;}
.sb-disc__arrow{flex:0 0 auto;color:#b5564e;font-size:11px;}
@keyframes sbDiscPulse{
  0%,100%{box-shadow:0 0 0 0 rgba(248,81,73,.0);}
  50%{box-shadow:0 0 0 3px rgba(248,81,73,.14);}
}
