/* ============================================================
   MAGIC LEADS — "Command Deck" Premium Skin
   Camada 100% visual. Não altera comportamento, IDs ou JS.
   Para reverter: remova o <link> deste arquivo do index.php.
   ============================================================ */

:root {
  --pc-obsidian: #0a0f1d;
  --pc-panel: #0c1324;
  --pc-hairline: rgba(148, 163, 184, 0.10);
  --pc-hairline-strong: rgba(148, 163, 184, 0.18);
  --pc-glow: 0 0 0 1px rgba(148, 163, 184, 0.06);
  --pc-ease: cubic-bezier(0.22, 1, 0.36, 1);
  --pc-num: 'Inter', ui-sans-serif, system-ui, sans-serif;
}

/* ============================================================
   1. MINI CARDS DE MÉTRICA / FILTRO  (Total, Ativos, Inativos…)
   Conceito: "tiles" com barra luminosa superior, rótulo em
   micro-caps e número tabular. Ativo = tile acende por inteiro.
   ============================================================ */

.controls-bar.dashboard-view {
  gap: 0.75rem;
  padding-bottom: 0.15rem;
  scroll-snap-type: x proximity;
}

.clientes-count-pill {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  min-width: 156px;
  min-height: 4.35rem;
  flex: 1 1 0;
  scroll-snap-align: start;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 0.3rem;
  padding: 0.85rem 1rem 0.8rem;
  border: 1px solid var(--pc-hairline);
  border-radius: 14px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.035), rgba(255, 255, 255, 0) 62%),
    var(--pc-panel);
  box-shadow:
    0 1px 0 0 rgba(255, 255, 255, 0.04) inset,
    0 8px 22px -18px rgba(0, 0, 0, 0.9);
  text-align: left;
  transition:
    transform 0.35s var(--pc-ease),
    border-color 0.25s ease,
    box-shadow 0.35s var(--pc-ease),
    background-color 0.25s ease;
}

/* Fio superior de acento — discreto, sem halo */
.clientes-count-pill::before {
  content: '';
  position: absolute;
  inset: 0 0 auto 0;
  height: 2px;
  background: var(--pc-accent, #60a5fa);
  opacity: 0.22;
  transform: scaleX(0.35);
  transform-origin: left center;
  transition: transform 0.4s var(--pc-ease), opacity 0.25s ease;
}

.filter-count-card:hover {
  transform: translateY(-3px);
  border-color: var(--pc-hairline-strong);
  box-shadow:
    0 1px 0 0 rgba(255, 255, 255, 0.05) inset,
    0 18px 34px -22px rgba(0, 0, 0, 1);
}

.filter-count-card:hover::before {
  transform: scaleX(1);
  opacity: 0.5;
}

.filter-count-card.is-active {
  border-color: color-mix(in srgb, var(--pc-accent, #60a5fa) 42%, transparent);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0) 60%),
    color-mix(in srgb, var(--pc-accent, #60a5fa) 9%, var(--pc-panel));
  box-shadow:
    0 1px 0 0 rgba(255, 255, 255, 0.07) inset,
    0 8px 22px -18px rgba(0, 0, 0, 0.9);
}

.filter-count-card.is-active::before {
  transform: scaleX(1);
  opacity: 0.9;
}

.filter-count-card:active {
  transform: translateY(-1px) scale(0.99);
}

.clientes-count-pill span {
  order: 1;
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-muted);
  line-height: 1.1;
  transition: color 0.25s ease;
}

.filter-count-card.is-active span,
.filter-count-card:hover span {
  color: var(--text-secondary);
}

.clientes-count-pill strong {
  order: 2;
  font-family: var(--pc-num);
  font-size: 1.85rem;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.045em;
  font-variant-numeric: tabular-nums;
  font-feature-settings: 'tnum' 1, 'ss01' 1;
  color: var(--pc-accent, #60a5fa);
}

/* Tokens de cor por métrica — um único ponto de verdade por tile */
.filter-count-card[data-filter-target="todos"]       { --pc-accent: #60a5fa; }
.filter-count-card[data-filter-target="ativos"]      { --pc-accent: #34d399; }
.filter-count-card[data-filter-target="desativados"] { --pc-accent: #f87171; }
.filter-count-card[data-filter-target="matrizes"]    { --pc-accent: #818cf8; }
.filter-count-card[data-filter-target="filiais"]     { --pc-accent: #fbbf24; }

/* Neutraliza as regras de cor antigas, agora dirigidas por --pc-accent */
.filter-count-card[data-filter-target="ativos"],
.filter-count-card[data-filter-target="desativados"],
.filter-count-card[data-filter-target="matrizes"],
.filter-count-card[data-filter-target="filiais"] {
  border-color: var(--pc-hairline);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.035), rgba(255, 255, 255, 0) 62%),
    var(--pc-panel);
}

.filter-count-card[data-filter-target] strong { color: var(--pc-accent); }

.filter-count-card[data-filter-target]:hover,
.filter-count-card[data-filter-target].is-active {
  border-color: color-mix(in srgb, var(--pc-accent) 45%, transparent);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0) 60%),
    color-mix(in srgb, var(--pc-accent) 9%, var(--pc-panel));
}

.filter-count-card[data-filter-target].is-active {
  box-shadow:
    0 1px 0 0 rgba(255, 255, 255, 0.07) inset,
    0 8px 22px -18px rgba(0, 0, 0, 0.9);
}

/* ============================================================
   2. BARRA DE AÇÕES (priority / refresh / lixeira / busca)
   ============================================================ */

.client-search-row .btn-priority-mode,
.client-search-row .btn-refresh-round {
  border-radius: 12px;
  border: 1px solid var(--pc-hairline);
  background: var(--pc-panel);
  box-shadow: 0 1px 0 0 rgba(255, 255, 255, 0.04) inset;
  transition:
    transform 0.3s var(--pc-ease),
    border-color 0.2s ease,
    background-color 0.2s ease,
    color 0.2s ease;
}

.client-search-row .btn-priority-mode:hover,
.client-search-row .btn-refresh-round:hover {
  transform: translateY(-2px);
  border-color: var(--pc-hairline-strong);
  background: #111a30;
}

.client-search-row .header-search-wrapper {
  border-radius: 12px;
}

.client-search-row .btn-search-trigger {
  border-radius: 12px;
}

/* ============================================================
   3. GRADE
   ============================================================ */

.clientes-grid.saas-grid {
  grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
  gap: 1.15rem;
}

/* ============================================================
   4. CARD DE CLIENTE — painel obsidiana com trilho de status
   ============================================================ */

.saas-cliente-card {
  position: relative;
  /* overflow visível de propósito: o tooltip "Matriz: …" do selo Filial
     precisa transbordar o card. */
  overflow: visible;
  padding: 1rem 1.1rem;
  gap: 1rem;
  border-radius: 18px;
  border: 1px solid var(--pc-hairline);
  background:
    linear-gradient(160deg, rgba(255, 255, 255, 0.045) 0%, rgba(255, 255, 255, 0) 34%),
    linear-gradient(180deg, #0d1526 0%, #090e1b 100%);
  box-shadow:
    0 1px 0 0 rgba(255, 255, 255, 0.045) inset,
    0 22px 44px -34px rgba(0, 0, 0, 1);
  transition:
    transform 0.45s var(--pc-ease),
    border-color 0.3s ease,
    box-shadow 0.45s var(--pc-ease);
}

/* Eleva o card sob o cursor para o tooltip não passar por baixo dos vizinhos */
.saas-cliente-card:hover {
  z-index: 5;
  transform: translateY(-4px);
  border-color: var(--pc-hairline-strong);
  box-shadow:
    0 1px 0 0 rgba(255, 255, 255, 0.07) inset,
    0 34px 60px -38px rgba(0, 0, 0, 1);
}

.saas-cliente-card.is-inactive {
  opacity: 1;
  border-style: solid;
  border-color: rgba(148, 163, 184, 0.07);
  background:
    repeating-linear-gradient(135deg,
      rgba(148, 163, 184, 0.022) 0 8px,
      rgba(148, 163, 184, 0) 8px 16px),
    linear-gradient(180deg, #0b1121 0%, #080d18 100%);
}

.saas-cliente-card.is-inactive .saas-indicators-grid,
.saas-cliente-card.is-inactive .saas-client-title {
  filter: saturate(0.35);
}

.saas-cliente-card.is-inactive .saas-client-title::after {
  margin-left: 0.5rem;
  padding: 0.18rem 0.5rem;
  border-radius: 5px;
  background: rgba(148, 163, 184, 0.10);
  border: 1px solid rgba(148, 163, 184, 0.16);
  color: var(--text-muted);
  font-size: 0.6rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

/* ---------- Cabeçalho ---------- */

.saas-card-header {
  align-items: flex-start;
  gap: 0.75rem;
}

.saas-client-info {
  gap: 0.75rem;
  min-width: 0;
}

/* Avatar genérico ocultado a pedido — o elemento continua no DOM,
   basta remover esta regra para trazê-lo de volta. */
.saas-avatar {
  display: none;
}

.saas-client-meta {
  min-width: 0;
  gap: 0.4rem;
}

.saas-client-title {
  font-size: 1.02rem;
  font-weight: 700;
  letter-spacing: -0.015em;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.saas-client-badges {
  margin-top: 0 !important;
  gap: 0.4rem !important;
}

/* ---------- Selos Matriz / Filial ---------- */

.saas-badge-role {
  padding: 0.2rem 0.5rem 0.2rem 0.42rem;
  border-radius: 6px;
  font-size: 0.63rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  line-height: 1.35;
  backdrop-filter: blur(2px);
}

.saas-badge-role.badge-matriz {
  background: linear-gradient(135deg, rgba(129, 140, 248, 0.18), rgba(129, 140, 248, 0.05));
  border: 1px solid rgba(129, 140, 248, 0.26);
  color: #c7d2fe;
}

.saas-badge-role.badge-filial {
  background: linear-gradient(135deg, rgba(251, 191, 36, 0.18), rgba(251, 191, 36, 0.05));
  border: 1px solid rgba(251, 191, 36, 0.26);
  color: #fde68a;
  text-transform: uppercase;
}

.saas-online-indicator {
  padding: 0.2rem 0.5rem;
  border-radius: 6px;
  font-size: 0.63rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.18), rgba(16, 185, 129, 0.05));
  border: 1px solid rgba(16, 185, 129, 0.26);
  color: #6ee7b7;
}

/* ---------- Toggle ---------- */

.saas-client-toggle {
  width: 44px;
  height: 25px;
  padding: 3px;
  border-color: rgba(255, 255, 255, 0.08);
  transition:
    background 0.3s var(--pc-ease),
    border-color 0.25s ease,
    box-shadow 0.3s ease;
}

.saas-client-toggle span {
  width: 17px;
  height: 17px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  transition: transform 0.32s var(--pc-ease);
}

.saas-client-toggle:hover {
  box-shadow: none;
  border-color: rgba(255, 255, 255, 0.18);
}

.saas-client-toggle.on {
  background: linear-gradient(135deg, #059669, #34d399);
  box-shadow: none;
}

.saas-client-toggle.on span {
  transform: translateX(19px);
}

.saas-client-toggle.off {
  background: linear-gradient(135deg, #7f1d1d, #ef4444);
  box-shadow: none;
}

/* ---------- Faixa de indicadores (Hoje / Ontem) ---------- */

.saas-indicators-grid {
  position: relative;
  gap: 0;
  border-radius: 13px;
  border: 1px solid var(--pc-hairline);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.03), rgba(255, 255, 255, 0) 70%),
    rgba(2, 6, 23, 0.55);
  box-shadow: 0 1px 0 0 rgba(255, 255, 255, 0.035) inset;
  overflow: hidden;
}

/* Divisor central em fio de cabelo, esmaecido nas pontas */
.saas-indicators-grid::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 18%;
  bottom: 18%;
  width: 1px;
  background: linear-gradient(180deg, transparent, var(--pc-hairline-strong), transparent);
}

.saas-indicator-box,
.saas-indicator-box.active-box {
  border: 0;
  border-radius: 0;
  background: transparent;
  padding: 0.7rem 0.9rem 0.75rem;
  gap: 0.3rem;
}

.saas-indicator-box.active-box {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.028), transparent 85%);
}

.saas-indicator-label {
  font-size: 0.6rem;
  letter-spacing: 0.15em;
  color: var(--text-muted);
}

.saas-indicator-value {
  font-family: var(--pc-num);
  font-size: 1.6rem;
  font-weight: 800;
  letter-spacing: -0.05em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  font-feature-settings: 'tnum' 1;
  gap: 0.3rem;
}

.saas-indicator-value i {
  font-size: 0.8rem;
  opacity: 0.9;
}

.saas-indicator-value.up {
  color: #34d399;
}

.saas-indicator-value.down {
  color: #f87171;
}

/* Coluna "Ontem" em tom de referência, para o "Hoje" liderar a leitura */
.saas-indicator-box:not(.active-box) .saas-indicator-value {
  color: var(--text-secondary);
  font-weight: 700;
}

/* ---------- Rodapé ---------- */

.saas-card-footer {
  margin-top: 0;
  padding-top: 0.85rem;
  border-top: 1px solid var(--pc-hairline);
  gap: 0.6rem;
}

.saas-action-buttons {
  gap: 0.3rem;
  flex-wrap: nowrap;
}

.saas-circle-btn {
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  font-size: 1.02rem;
  border-radius: 10px;
  border: 1px solid var(--pc-hairline);
  background: rgba(255, 255, 255, 0.018);
  color: #94a3b8;
  transition:
    transform 0.28s var(--pc-ease),
    background-color 0.2s ease,
    border-color 0.2s ease,
    color 0.2s ease,
    box-shadow 0.28s ease;
}

.saas-circle-btn:hover {
  transform: translateY(-2px);
  color: #e2e8f0;
  background: rgba(255, 255, 255, 0.06);
  border-color: var(--pc-hairline-strong);
  box-shadow: 0 8px 18px -12px rgba(0, 0, 0, 1);
}

/* Cor semântica por ação, sem tocar no HTML */
.saas-action-buttons .saas-circle-btn:has(.ph-arrow-square-out):hover {
  color: #93c5fd;
  border-color: rgba(96, 165, 250, 0.4);
  background: rgba(96, 165, 250, 0.1);
}

.saas-action-buttons .saas-circle-btn:has(.ph-pencil-simple):hover {
  color: #c7d2fe;
  border-color: rgba(129, 140, 248, 0.4);
  background: rgba(129, 140, 248, 0.1);
}

.saas-action-buttons .saas-circle-btn:has(.ph-clock):hover {
  color: #fde68a;
  border-color: rgba(251, 191, 36, 0.35);
  background: rgba(251, 191, 36, 0.09);
}

.saas-action-buttons .saas-circle-btn:has(.ph-trash):hover,
.saas-action-buttons .saas-purge-btn:hover {
  color: #fca5a5;
  border-color: rgba(248, 113, 113, 0.4);
  background: rgba(248, 113, 113, 0.1);
}

.saas-action-buttons .saas-circle-btn:has(.ph-arrow-counter-clockwise):hover {
  color: #6ee7b7;
  border-color: rgba(52, 211, 153, 0.4);
  background: rgba(52, 211, 153, 0.1);
}

/* Selo de performance — mesma geometria dos demais botões, sem animação */
.saas-circle-btn.saas-status-badge {
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  border-radius: 10px;
  border-style: solid;
  border-width: 1.5px;
  background: rgba(255, 255, 255, 0.02) !important;
  transform: translateZ(0);
  backface-visibility: hidden;
  box-sizing: border-box;
}

/* ---------- Tooltip premium (status de performance / WhatsApp) ---------- */

.pc-tooltip {
  position: relative;
}

.pc-tooltip::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 9px);
  left: 50%;
  transform: translate(-50%, 3px);
  background: #10162a;
  color: #e2e8f0;
  border: 1px solid var(--pc-hairline-strong);
  padding: 0.4rem 0.7rem;
  border-radius: 8px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s var(--pc-ease);
  box-shadow: 0 10px 24px -10px rgba(0, 0, 0, 0.85);
  z-index: 30;
}

.pc-tooltip::before {
  content: '';
  position: absolute;
  bottom: calc(100% + 4px);
  left: 50%;
  transform: translate(-50%, 3px);
  width: 8px;
  height: 8px;
  background: #10162a;
  border-right: 1px solid var(--pc-hairline-strong);
  border-bottom: 1px solid var(--pc-hairline-strong);
  border-radius: 0 0 2px 0;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s var(--pc-ease);
  z-index: 30;
}

.pc-tooltip:hover::after,
.pc-tooltip:hover::before {
  opacity: 1;
  transform: translate(-50%, 0);
}

.pc-tooltip::before {
  transform: translate(-50%, 3px) rotate(45deg);
}

.pc-tooltip:hover::before {
  transform: translate(-50%, 0) rotate(45deg);
}

/* Variante com elemento real (permite HTML colorido dentro, ex.: WhatsApp) */
.pc-tooltip-host {
  position: relative;
}

.pc-tooltip-bubble {
  position: absolute;
  bottom: calc(100% + 9px);
  left: 50%;
  transform: translate(-50%, 3px);
  background: #10162a;
  color: #e2e8f0;
  border: 1px solid var(--pc-hairline-strong);
  padding: 0.4rem 0.7rem;
  border-radius: 8px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s var(--pc-ease);
  box-shadow: 0 10px 24px -10px rgba(0, 0, 0, 0.85);
  z-index: 30;
}

.pc-tooltip-bubble::before {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  width: 8px;
  height: 8px;
  background: #10162a;
  border-right: 1px solid var(--pc-hairline-strong);
  border-bottom: 1px solid var(--pc-hairline-strong);
  border-radius: 0 0 2px 0;
  transform: translate(-50%, -5px) rotate(45deg);
}

.pc-tooltip-host:hover .pc-tooltip-bubble {
  opacity: 1;
  transform: translate(-50%, 0);
}

.pc-tooltip-bubble .wa-tt-ativo {
  color: #5f9c7f;
}

.pc-tooltip-bubble .wa-tt-inativo {
  color: #e0ac4f;
}

/* ---------- Selo de conexões WhatsApp ---------- */

/* Mesma geometria do selo de status: o ícone inteiro muda de cor
   conforme o estado da conexão. */
.saas-whatsapp-badge {
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  border-radius: 10px;
  border-style: solid;
  border-width: 1.5px;
  font-size: 1.2rem;
  cursor: help;
  background: rgba(255, 255, 255, 0.05) !important;
  transform: translateZ(0);
  backface-visibility: hidden;
  box-sizing: border-box;
}

.saas-whatsapp-badge.wa-none {
  color: var(--text-muted);
  border-color: var(--pc-hairline);
  opacity: 0.55;
}

.saas-whatsapp-badge.wa-off {
  color: #94a3b8;
  border-color: #94a3b8;
}

.saas-whatsapp-badge.wa-partial {
  color: #e0ac4f;
  border-color: #e0ac4f;
}

.saas-whatsapp-badge.wa-on {
  color: #5f9c7f;
  border-color: #5f9c7f;
}

/* ---------- Estado vazio ---------- */

.clientes-grid .empty-state {
  border: 1px dashed var(--pc-hairline-strong);
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.02), transparent);
}

/* ============================================================
   5. RESPONSIVO
   ============================================================ */

@media (max-width: 1100px) {
  .clientes-count-pill {
    min-width: 138px;
    min-height: 4rem;
    padding: 0.75rem 0.85rem;
  }

  .clientes-count-pill strong { font-size: 1.6rem; }
}

@media (max-width: 768px) {
  .controls-bar.dashboard-view {
    gap: 0.6rem;
    margin-left: -0.25rem;
    padding-left: 0.25rem;
  }

  .clientes-count-pill {
    width: auto;
    min-width: 128px;
    flex: 0 0 auto;
  }

  .clientes-grid.saas-grid {
    grid-template-columns: repeat(auto-fill, minmax(268px, 1fr));
    gap: 0.9rem;
  }

  .saas-cliente-card {
    padding: 0.95rem 1rem;
    border-radius: 16px;
  }
}

@media (max-width: 520px) {
  .clientes-grid.saas-grid {
    grid-template-columns: 1fr;
  }

  .clientes-count-pill {
    min-width: 118px;
    min-height: 3.65rem;
  }

  .clientes-count-pill span  { font-size: 0.6rem; letter-spacing: 0.1em; }
  .clientes-count-pill strong { font-size: 1.45rem; }

  .saas-indicator-value { font-size: 1.45rem; }
  .saas-circle-btn,
  .saas-circle-btn.saas-status-badge { width: 32px; height: 32px; flex-basis: 32px; }
}

/* Respeita quem prefere menos movimento */
@media (prefers-reduced-motion: reduce) {
  .saas-cliente-card,
  .clientes-count-pill,
  .saas-circle-btn,
  .saas-client-toggle,
  .saas-client-toggle span {
    transition-duration: 0.01ms !important;
  }

  .saas-cliente-card:hover,
  .filter-count-card:hover { transform: none; }
}
