/* =========================================================================
 * Sistema visual — tokens (cores, raio, sombra) usados em todo o app.
 * ======================================================================= */
:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --ink: #16181d;
  --ink-muted: #6b7280;
  --ink-faint: #9ca3af;
  --border: #eceef1;
  --accent: #b3121b;
  --accent-dark: #8f0f17;
  --accent-soft: #fdeceb;
  --sidebar-bg: #17181c;
  --sidebar-ink: #c9cad0;
  --good-bg: #e6f7ef; --good-ink: #0f8a4f;
  --warn-bg: #fff6e0; --warn-ink: #96700a;
  --danger-bg: #fdeceb; --danger-ink: #b3121b;
  --info-bg: #eef4ff; --info-ink: #3457d5;
  --purple-bg: #f3e8fb; --purple-ink: #7a1fa2;
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(16,24,40,.04), 0 1px 3px rgba(16,24,40,.06);
  --shadow-md: 0 4px 10px rgba(16,24,40,.06), 0 2px 4px rgba(16,24,40,.04);
  --shadow-lift: 0 12px 24px rgba(16,24,40,.10), 0 4px 8px rgba(16,24,40,.05);
}

body {
  background-color: var(--bg);
  color: var(--ink);
  font-family: 'Inter', 'Segoe UI', Roboto, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* Icones inline (Lucide) sem cor propria herdam a cor de texto do elemento pai */
svg[data-lucide], svg.lucide { stroke: currentColor; }

.auth-bg {
  background: linear-gradient(135deg, #1a1a1a, #3a0000);
}

/* =========================================================================
 * Sidebar — menu agrupado com estado ativo em "pill" e chip de usuario.
 * ======================================================================= */
.sidebar {
  width: 258px;
  min-height: 100vh;
  background-color: var(--sidebar-bg);
  color: #fff;
  display: flex;
  flex-direction: column;
  padding: 18px 12px;
}

.sidebar .logo {
  padding: 8px 10px 20px;
  font-weight: 700;
  font-size: 1.02rem;
  border-bottom: none;
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar .logo .logo-mark {
  width: 34px; height: 34px; border-radius: 10px; background: var(--accent);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}

.sidebar .logo .logo-mark svg { width: 18px; height: 18px; stroke: #fff; }

.nav-group-label {
  color: #6b6d76;
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  padding: 16px 12px 6px;
}

.sidebar a {
  display: flex;
  align-items: center;
  gap: 11px;
  color: var(--sidebar-ink);
  text-decoration: none;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  margin: 1px 0;
  font-size: .875rem;
  font-weight: 500;
  transition: background .15s ease, color .15s ease;
}

.sidebar a svg { width: 17px; height: 17px; stroke-width: 2px; flex-shrink: 0; opacity: .85; }

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

.sidebar a.ativo {
  background-color: var(--accent);
  color: #fff;
  box-shadow: 0 2px 8px rgba(179,18,27,.35);
}

.sidebar a.ativo svg { opacity: 1; }

.sidebar .user-chip {
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,.04);
}

.sidebar .user-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  color: #fff; font-weight: 700; font-size: .78rem;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}

.sidebar .user-meta { line-height: 1.2; min-width: 0; flex: 1; }
.sidebar .user-name { color: #fff; font-size: .82rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar .user-role { color: #8b8d94; font-size: .72rem; }

.sidebar #btn-sair {
  border: none;
  background: transparent;
  color: #8b8d94;
  width: 30px; height: 30px;
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
  transition: background .15s ease, color .15s ease;
}
.sidebar #btn-sair svg { width: 16px; height: 16px; stroke-width: 2px; }
.sidebar #btn-sair:hover { background: rgba(255,255,255,.08); color: #fff; }

.conteudo {
  flex: 1;
  padding: 28px 30px 60px;
  min-width: 0; /* evita a coluna de conteudo espremer/estourar com tabelas largas */
}

/* =========================================================================
 * Cards e cartoes de indicador (KPI)
 * ======================================================================= */
.card,
.card-metrica {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.card-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  font-weight: 700;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow .18s ease, transform .18s ease;
}

.stat-card:hover { box-shadow: var(--shadow-lift); transform: translateY(-2px); }

.stat-icon {
  width: 38px; height: 38px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 12px;
}
.stat-icon svg { width: 19px; height: 19px; stroke-width: 2px; }
.stat-icon.tom-verde  { background: var(--good-bg); }   .stat-icon.tom-verde svg  { stroke: var(--good-ink); }
.stat-icon.tom-azul   { background: var(--info-bg); }   .stat-icon.tom-azul svg   { stroke: var(--info-ink); }
.stat-icon.tom-vermelho{ background: var(--danger-bg); } .stat-icon.tom-vermelho svg { stroke: var(--danger-ink); }
.stat-icon.tom-amarelo{ background: var(--warn-bg); }   .stat-icon.tom-amarelo svg { stroke: var(--warn-ink); }
.stat-icon.tom-roxo   { background: var(--purple-bg); } .stat-icon.tom-roxo svg   { stroke: var(--purple-ink); }

.stat-label { color: var(--ink-muted); font-size: .8rem; font-weight: 500; margin-bottom: 2px; }
.stat-value { font-size: 1.5rem; font-weight: 800; letter-spacing: -.02em; }

/* =========================================================================
 * Tabelas com coluna ordenavel (crud.js / comandas)
 * ======================================================================= */
.th-ordenavel { cursor: pointer; user-select: none; white-space: nowrap; }
.th-ordenavel:hover { color: var(--accent); }
.th-ordenavel .icone-ordenar { opacity: .35; }
.th-ordenavel-ativo, .th-ordenavel-ativo .icone-ordenar { color: var(--accent); opacity: 1; }

/* =========================================================================
 * Graficos do Dashboard — legenda dos graficos de pizza/doughnut e mapa de
 * calor de horarios (grafico F). Paleta categorica fixa fica em dashboard.js
 * (PALETA_CATEGORICA), reaproveitada aqui so pelas classes de layout.
 * ======================================================================= */
.grafico-legenda { list-style: none; margin: 12px 0 0; padding: 0; display: flex; flex-direction: column; gap: 7px; }
.grafico-legenda li { display: flex; align-items: center; gap: 8px; font-size: .85rem; }
.grafico-legenda .swatch { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.grafico-legenda .nome { flex: 1; color: var(--ink-muted); }
.grafico-legenda .valor { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }

.heatmap-tabela { width: 100%; border-collapse: separate; border-spacing: 4px; font-size: .78rem; }
.heatmap-tabela th { font-weight: 500; color: var(--ink-muted); text-align: center; padding: 2px 2px 6px; white-space: nowrap; }
.heatmap-tabela th:first-child, .heatmap-tabela td:first-child { text-align: left; }
.heatmap-tabela th:first-child { color: var(--ink-muted); }
.heatmap-celula { min-width: 46px; height: 30px; border-radius: 6px; display: flex; align-items: center; justify-content: center; font-variant-numeric: tabular-nums; font-weight: 600; color: var(--ink); }

/* =========================================================================
 * Botoes
 * ======================================================================= */
.btn {
  border-radius: var(--radius-sm);
  font-weight: 600;
  transition: transform .1s ease, box-shadow .15s ease, background .15s ease, border-color .15s ease;
}

.btn svg { width: 15px; height: 15px; stroke-width: 2.2px; vertical-align: -2px; }

.btn-danger {
  background-color: var(--accent);
  border-color: var(--accent);
  box-shadow: var(--shadow-sm);
}
.btn-danger:hover {
  background-color: var(--accent-dark);
  border-color: var(--accent-dark);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.btn-outline-secondary,
.btn-outline-danger {
  border-color: var(--border);
  color: var(--ink-muted);
}
.btn-outline-secondary:hover,
.btn-outline-danger:hover {
  background: var(--bg);
  border-color: #d7d9de;
  color: var(--ink);
}
.btn-outline-danger:hover { color: var(--danger-ink); border-color: var(--danger-ink); background: var(--danger-bg); }

/* =========================================================================
 * Tabelas
 * ======================================================================= */
.table thead th {
  color: var(--ink-faint);
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  border-bottom: 1px solid var(--border) !important;
  background: transparent !important;
}

.table td {
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  font-size: .875rem;
}

.table tbody tr {
  transition: background .12s ease;
}
.table-hover tbody tr:hover {
  background-color: #fafafa;
}

.avatar-mini {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent);
  font-size: .72rem; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0; margin-right: 9px; vertical-align: middle;
}

/* =========================================================================
 * Badges / pills de status
 * ======================================================================= */
.badge {
  border-radius: 20px;
  font-weight: 700;
  padding: .42em .75em;
  font-size: .74rem;
}

.badge-status {
  font-weight: 700;
  padding: .4em .7em;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border-radius: 20px;
  font-size: .78rem;
}
.badge-status svg { width: 12px; height: 12px; stroke-width: 3px; }

.badge-em-dia      { background-color: var(--good-bg); color: var(--good-ink); }
.badge-atencao     { background-color: var(--warn-bg); color: var(--warn-ink); }
.badge-alerta      { background-color: var(--danger-bg); color: var(--danger-ink); }
.badge-aniversario { background-color: var(--purple-bg); color: var(--purple-ink); }
.badge-info        { background-color: var(--info-bg); color: var(--info-ink); }

/* =========================================================================
 * Formularios
 * ======================================================================= */
.form-control,
.form-select {
  border-radius: 10px;
  border-color: var(--border);
  font-size: .875rem;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.form-control:focus,
.form-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(179,18,27,.12);
}
.form-label {
  font-size: .8rem;
  font-weight: 600;
  color: var(--ink-muted);
  margin-bottom: 6px;
}
.form-check-input:checked {
  background-color: var(--accent);
  border-color: var(--accent);
}

/* =========================================================================
 * Modais
 * ======================================================================= */
.modal-content {
  border: none;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lift);
}
.modal-header {
  border-bottom: 1px solid var(--border);
  padding: 18px 22px;
}
.modal-header .modal-title { font-weight: 700; font-size: 1.05rem; }
.modal-body { padding: 20px 22px; }
.modal-footer { border-top: 1px solid var(--border); padding: 16px 22px; }

/* =========================================================================
 * Abas (nav-tabs)
 * ======================================================================= */
.nav-tabs { border-bottom: 1px solid var(--border); }
.nav-tabs .nav-link {
  border: none;
  color: var(--ink-muted);
  font-weight: 600;
  font-size: .875rem;
  padding: 8px 4px;
  margin-right: 22px;
  border-radius: 0;
  transition: color .15s ease;
}
.nav-tabs .nav-link:hover { color: var(--ink); border-color: transparent; }
.nav-tabs .nav-link.active {
  color: var(--accent);
  background: transparent;
  border-bottom: 2px solid var(--accent);
}

/* =========================================================================
 * Layout mobile: abaixo do breakpoint lg a sidebar vira um menu "gaveta"
 * (off-canvas), acionado pelo botao hamburguer da topbar mobile.
 * ------------------------------------------------------------------- */
.topbar-mobile {
  display: none;
}

.sidebar-backdrop {
  display: none;
}

@media (max-width: 991.98px) {
  .topbar-mobile {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background-color: var(--sidebar-bg);
    color: #fff;
    padding: 10px 14px;
    position: sticky;
    top: 0;
    z-index: 1030;
  }

  .topbar-mobile .logo-mobile {
    font-weight: 700;
    font-size: 1rem;
    display: flex;
    align-items: center;
    gap: 8px;
  }

  .topbar-mobile button {
    background: transparent;
    border: none;
    color: #fff;
    width: 34px; height: 34px;
    display: flex; align-items: center; justify-content: center;
    border-radius: var(--radius-sm);
  }
  .topbar-mobile button svg { width: 20px; height: 20px; }
  .topbar-mobile button:hover { background: rgba(255,255,255,.08); }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 270px;
    max-width: 80vw;
    height: 100vh;
    z-index: 1045;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: 2px 0 12px rgba(0,0,0,0.25);
  }

  .sidebar.aberta {
    transform: translateX(0);
  }

  .sidebar-backdrop.aberta {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1040;
  }

  .conteudo {
    padding: 18px;
  }

  .stat-card:hover { transform: none; } /* sem hover em touch */
}

/* ---------------------------------------------------------------------
 * Select com busca (autocomplete): usado nos campos de Cliente e
 * Profissional para permitir digitar e filtrar em vez de rolar uma lista
 * longa de cadastros.
 * ------------------------------------------------------------------- */
.select-busca {
  position: relative;
}

.select-busca .select-busca-limpar {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 34px;
  border: none;
  background: transparent;
  color: var(--ink-muted);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
}

.select-busca .select-busca-limpar:hover {
  color: var(--accent);
}

.select-busca-lista {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 1071; /* acima do conteudo do modal (bootstrap usa 1055-1060) */
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lift);
  max-height: 220px;
  overflow-y: auto;
  padding: 4px;
}

.select-busca-item {
  padding: 8px 10px;
  cursor: pointer;
  font-size: 0.88rem;
  border-radius: var(--radius-sm);
}

.select-busca-item:hover,
.select-busca-item.ativo {
  background-color: var(--accent-soft);
  color: var(--accent-dark);
}

.select-busca-vazio {
  padding: 10px 12px;
  color: var(--ink-muted);
  font-size: 0.85rem;
}

@media (max-width: 991.98px) {
  .select-busca-item {
    padding: 11px 12px; /* alvo de toque maior no celular */
  }
}

/* ---------------------------------------------------------------------
 * Recorrência de Clientes: chips de variavel e previa de mensagem.
 * ------------------------------------------------------------------- */
.chip-variavel {
  display: inline-block;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 3px 10px;
  font-size: .78rem;
  margin: 2px;
  cursor: pointer;
  user-select: none;
  transition: background .15s ease, color .15s ease, border-color .15s ease;
}

.chip-variavel:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.chip-variavel svg { width: 12px; height: 12px; stroke-width: 2.5px; margin-right: 3px; vertical-align: -1px; }

/* Editor de mensagem com "etiquetas" de variável embutidas no texto (em vez
 * de sintaxe {{crua}}) — visual de campo de texto normal, mas o conteúdo é
 * editável (contenteditable) para permitir as etiquetas inline. */
.editor-mensagem {
  min-height: 92px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: .95rem;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

.editor-mensagem:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(179,18,27,.12);
}

.editor-mensagem:empty::before {
  content: attr(data-placeholder);
  color: var(--ink-muted);
}

.var-pill {
  display: inline-block;
  background: var(--accent-soft);
  color: var(--accent-dark);
  border-radius: 20px;
  padding: 1px 10px 2px;
  font-size: .84rem;
  font-weight: 600;
  white-space: nowrap;
  user-select: none;
  cursor: default;
}

.preview-mensagem {
  background: var(--info-bg);
  border: 1px solid #cddcfb;
  border-radius: var(--radius-md) var(--radius-md) var(--radius-md) 2px;
  padding: 12px 14px;
  font-size: .92rem;
  white-space: pre-wrap;
  position: relative;
}

.preview-mensagem::before {
  content: "Pré-visualização";
  position: absolute;
  top: -10px;
  left: 12px;
  background: var(--info-bg);
  padding: 0 6px;
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .03em;
  color: var(--info-ink);
  text-transform: uppercase;
}

.regra-card .card-header { background: var(--surface); border-bottom: 1px solid var(--border); }
.regra-inativa { opacity: .55; }
