:root {
  --primary: #1f2937;
  --primary-dark: #111827;
  --bg: #f7f7f8;
  --sidebar-bg: #ffffff;
  --sidebar-text: #4b5563;
  --sidebar-active: #111827;
  --card-bg: #ffffff;
  --border: #e5e7eb;
  --text: #1a1c20;
  --text-muted: #6b7280;
  --success: #2f7d4f;
  --warning: #a6752c;
  --danger: #b3413b;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

a { color: inherit; text-decoration: none; }

.app-layout { display: flex; min-height: 100vh; }

/* ---------- Sidebar ---------- */
.sidebar {
  width: 236px;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  padding: 22px 0;
  border-right: 1px solid var(--border);
}
.sidebar .brand {
  font-size: 18px;
  font-weight: 700;
  color: var(--sidebar-active);
  padding: 0 20px 24px;
}
.sidebar .brand img { max-height: 38px; max-width: 100%; display: block; }
.sidebar nav a { display: flex; align-items: center; gap: 10px; margin: 1px 12px; padding: 9px 12px; border-radius: 8px; color: var(--sidebar-text); font-size: 13.5px; }
.sidebar nav a svg { flex-shrink: 0; opacity: .8; }
.nav-section { padding: 16px 20px 6px; font-size: 10.5px; color: #9ca3af; text-transform: uppercase; letter-spacing: .6px; font-weight: 700; }
.sidebar nav a:hover { background: #f3f4f6; }
.sidebar nav a.active {
  background: #eef0f3;
  color: var(--sidebar-active);
  font-weight: 600;
}
.sidebar .user-box {
  margin-top: auto;
  padding: 16px 20px 4px;
  border-top: 1px solid var(--border);
  font-size: 13px;
  color: var(--text);
}
.sidebar .user-box a { color: var(--danger); }

/* ---------- Main ---------- */
.main { flex: 1; padding: 24px 28px; overflow-x: auto; }
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}
.page-header h1 { font-size: 22px; margin: 0; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 9px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
}
.btn:hover { background: var(--primary-dark); }
.btn-secondary { background: #fff; color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: #f3f4f6; }
.btn-danger { background: var(--danger); }
.btn-sm { padding: 5px 10px; font-size: 12px; }

/* ---------- Cards / Tables ---------- */
.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 20px;
}
a.card { display: block; text-decoration: none; color: inherit; transition: box-shadow .15s, transform .15s; }
a.card:hover { box-shadow: 0 4px 14px rgba(0,0,0,.08); transform: translateY(-2px); }
.grid-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card { background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.stat-card .label { color: var(--text-muted); font-size: 13px; margin-bottom: 6px; }
.stat-card .value { font-size: 26px; font-weight: 700; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); font-size: 13.5px; }
th { color: var(--text-muted); font-weight: 600; font-size: 12.5px; text-transform: uppercase; letter-spacing: .3px; }
tr:hover td { background: #fafafa; }

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}
.badge-lead { background: #eef0f2; color: #374151; }

/* ---------- Icon buttons (ações de linha em tabelas) ---------- */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text-muted);
  cursor: pointer;
  margin-right: 4px;
}
.icon-btn:hover { background: var(--bg); color: var(--text); }
.icon-btn-danger:hover { background: #f3e9e8; color: var(--danger); border-color: #e2c9c7; }
.icon-btn-whatsapp { color: #25d366; border-color: #bfe8cf; }
.icon-btn-whatsapp:hover { background: #25d36622; color: #1da851; }

/* ---------- KPI cards (borda colorida lateral + ícone) ---------- */
.kpi-card {
  background: #fff; border-radius: 10px; padding: 18px 20px; border: 1px solid var(--border);
  border-left: 4px solid var(--accent, #3b82f6); position: relative;
}
.kpi-card .kpi-icon { position: absolute; top: 16px; right: 16px; color: var(--accent, #3b82f6); opacity: .55; }
.kpi-card .kpi-value { font-size: 30px; font-weight: 700; line-height: 1.1; }
.kpi-card .kpi-label { font-size: 13.5px; color: var(--text); margin-top: 4px; font-weight: 500; }
.kpi-card .kpi-sub { font-size: 12px; color: var(--text-muted); margin-top: 3px; }

/* ---------- KPI card compacto (empilhado ao lado da Agenda) ---------- */
.kpi-card-compact {
  display: flex; align-items: center; gap: 12px; background: #fff; border: 1px solid var(--border);
  border-left: 4px solid var(--accent, #3b82f6); border-radius: 10px; padding: 12px 14px; margin-bottom: 10px;
}
.kpi-card-compact:last-child { margin-bottom: 0; }
.kpi-compact-icon { color: var(--accent, #3b82f6); flex-shrink: 0; }
.kpi-compact-value { font-size: 19px; font-weight: 700; line-height: 1.2; }
.kpi-compact-label-inline { font-size: 12.5px; font-weight: 500; color: var(--text-muted); margin-left: 3px; }
.kpi-compact-sub { font-size: 11.5px; color: var(--text-muted); margin-top: 1px; }

/* ---------- Cards financeiros (cotações/receita) ---------- */
.finance-card {
  background: #fff; border-radius: 10px; padding: 18px 20px; border: 1px solid var(--border);
  border-left: 4px solid var(--accent, #a6752c); display: flex; justify-content: space-between; align-items: flex-end; gap: 10px;
}
.finance-card .label { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--text-muted); font-weight: 700; margin-bottom: 10px; }
.finance-card .value { font-size: 26px; font-weight: 700; }
.finance-card .sub { font-size: 12.5px; color: var(--text-muted); margin-top: 2px; }
.finance-card .right-value { font-size: 19px; font-weight: 700; text-align: right; white-space: nowrap; }
.finance-card .right-sub { font-size: 12px; color: var(--text-muted); text-align: right; }
.finance-progress { grid-column: 1 / -1; height: 6px; background: #e5e7eb; border-radius: 3px; margin-top: 12px; overflow: hidden; }
.finance-progress-bar { height: 100%; background: var(--accent, #3b82f6); }
.finance-card-wrap { display: flex; flex-direction: column; }

/* ---------- Filtro de período em pills ---------- */
.pill-filter-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.pill-filter {
  display: inline-flex; align-items: center; padding: 9px 16px; border-radius: 999px;
  background: #f3f4f6; color: #374151; font-size: 13px; font-weight: 500; border: none; cursor: pointer; white-space: nowrap;
}
.pill-filter:hover { background: #e5e7eb; }
.pill-filter.active { background: #111827; color: #fff; }
.pill-date-input { padding: 8px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 13px; }

/* ---------- Canais com cor de marca (Dashboard) ---------- */
.channel-chip-colored {
  flex: 1 1 0; min-width: 100px; border-radius: 10px; padding: 16px 10px; text-align: center; border: 1px solid transparent;
}
.channel-chip-colored .channel-chip-icon { margin-bottom: 8px; }
.channel-chip-colored .channel-chip-value { display: block; font-size: 22px; font-weight: 700; }
.channel-chip-colored .channel-chip-label { display: block; font-size: 12.5px; margin-top: 2px; }

/* ---------- Mini-calendário (Dashboard > Agenda) ---------- */
.mini-cal-header { display:flex; align-items:center; justify-content:center; gap:14px; text-align: center; font-size: 13px; font-weight: 700; text-transform: capitalize; margin-bottom: 10px; max-width: 300px; margin-left:auto; margin-right:auto; }
.mini-cal-nav { background:none; border:1px solid var(--border); border-radius:6px; width:24px; height:24px; cursor:pointer; font-size:14px; color:var(--text); }
.mini-cal-nav:hover { background:var(--bg); }
.mini-cal-weekdays, .mini-cal-days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; text-align: center; max-width: 300px; margin-left: auto; margin-right: auto; }
.mini-cal-weekdays div { font-size: 10.5px; color: #9ca3af; font-weight: 700; padding-bottom: 4px; }
.mini-cal-day { aspect-ratio: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; border-radius: 6px; font-size: 12px; color: var(--text); background: var(--bg); cursor: default; position: relative; }
.mini-cal-day.has-items { cursor: help; }
.mini-cal-day.is-today { background: #111827; color: #fff; font-weight: 700; }
.mini-cal-markers { display: flex; gap: 3px; margin-top: 3px; height: 8px; }
.mini-cal-marker { width: 10px; height: 10px; border-radius: 50%; box-shadow: 0 0 0 1.5px #fff; }
.mini-cal-day.is-today .mini-cal-marker { box-shadow: 0 0 0 1.5px #111827; }
.mini-cal-tooltip {
  display: none; position: absolute; z-index: 999; background: #111827; color: #fff;
  font-size: 11.5px; padding: 8px 10px; border-radius: 6px; white-space: pre-line;
  max-width: 220px; text-align: left; line-height: 1.5; box-shadow: 0 4px 14px rgba(0,0,0,.25);
  transform: translateX(-50%); pointer-events: none;
}

/* ---------- Barra de seleção em lote ---------- */
.bulk-action-bar {
  position: sticky; top: 0; z-index: 5; display: none; align-items: center; gap: 14px;
  background: #111827; color: #fff; padding: 10px 16px; border-radius: 8px; margin-bottom: 12px; font-size: 13px;
}
.bulk-action-bar.visible { display: flex; }
.bulk-action-bar .btn-danger { padding: 6px 14px; font-size: 12.5px; }
.row-checkbox, .select-all-checkbox { width: 16px; height: 16px; cursor: pointer; }

/* ---------- Toast de aviso (tarefa/reunião próxima) ---------- */
#reminderToastContainer {
  position: fixed; bottom: 20px; right: 20px; z-index: 999;
  display: flex; flex-direction: column; gap: 10px; max-width: 320px;
}
.reminder-toast {
  background: #1f2937; color: #fff; border-radius: 10px; padding: 14px 16px;
  box-shadow: 0 8px 24px rgba(0,0,0,.25); animation: reminderSlideIn .25s ease-out;
  cursor: pointer;
}
.reminder-toast:hover { background: #111827; }
.reminder-toast .kind { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: #a5b4fc; font-weight: 700; margin-bottom: 4px; }
.reminder-toast .title { font-size: 13.5px; font-weight: 600; margin-bottom: 3px; }
.reminder-toast .meta { font-size: 12px; color: #d1d5db; }
.reminder-toast .close-x { float: right; color: #9ca3af; background: none; border: none; cursor: pointer; font-size: 15px; margin-left: 8px; }
@keyframes reminderSlideIn { from { transform: translateX(20px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
.badge-qualificado { background: #f2ede2; color: #92662f; }
.badge-cliente { background: #e8f0ea; color: #2f7d4f; }
.badge-perdido { background: #f3e9e8; color: #b3413b; }

/* ---------- Channel chips (linha única) ---------- */
.channel-row {
  display: flex;
  flex-wrap: nowrap;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 4px;
}
.channel-chip {
  flex: 1 1 0;
  min-width: 100px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 8px;
  text-align: center;
}
.channel-chip-icon { display: flex; align-items: center; justify-content: center; color: var(--text-muted); margin-bottom: 4px; }
.channel-chip-label { display: block; font-size: 11px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.channel-chip-value { display: block; font-size: 18px; font-weight: 700; color: var(--text); margin-top: 2px; }

/* ---------- Dashboard chart cards (compactos) ---------- */
.chart-card { padding: 16px; }
.chart-card h4 { margin: 0 0 10px; font-size: 13px; font-weight: 600; color: var(--text); }
.chart-box { position: relative; height: 150px; }

/* ---------- Forms ---------- */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; margin-bottom: 6px; font-weight: 500; font-size: 13.5px; }
.form-control {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
}
.form-control:focus { outline: none; border-color: var(--primary); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, #1a1c20, #2b2e35);
}
.login-box {
  background: #fff;
  padding: 40px;
  border-radius: 14px;
  width: 360px;
  box-shadow: 0 20px 50px rgba(0,0,0,.25);
}
.login-box h1 { font-size: 22px; margin: 0 0 4px; }
.login-box p { color: var(--text-muted); margin: 0 0 24px; font-size: 13.5px; }

/* ---------- Kanban ---------- */
.kanban { display: flex; gap: 14px; overflow-x: auto; padding-bottom: 12px; }
.kanban-col {
  background: #eef0f7;
  border-radius: var(--radius);
  min-width: 260px;
  max-width: 260px;
  flex-shrink: 0;
  padding: 10px;
}
.kanban-col-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 6px 12px;
  font-weight: 600;
  font-size: 13px;
}
.kanban-col-header .count { color: var(--text-muted); font-weight: 400; }
.kanban-cards { min-height: 40px; display: flex; flex-direction: column; gap: 8px; }
.deal-card {
  background: #fff;
  border-radius: 8px;
  padding: 12px;
  border: 1px solid var(--border);
  box-shadow: 0 1px 2px rgba(0,0,0,.04);
  cursor: grab;
  position: relative;
}
.deal-card:active { cursor: grabbing; }
.deal-card.dragging { opacity: .4; }
.deal-discard-link {
  display: block; width: 100%; text-align: right; margin-top: 8px; padding-top: 6px;
  border-top: 1px solid var(--border); background: none; border-left: none; border-right: none; border-bottom: none;
  color: #9ca3af; font-size: 11px; cursor: pointer;
}
.deal-discard-link:hover { color: #dc2626; text-decoration: underline; }
.deal-card .title { font-weight: 600; font-size: 13.5px; margin-bottom: 4px; }
.deal-card .value { color: var(--success); font-weight: 700; font-size: 13px; }
.deal-card .contact { color: var(--text-muted); font-size: 12.5px; margin-top: 4px; }
.deal-card-link { display: block; color: inherit; text-decoration: none; }
.kanban-col.drag-over { background: #e5e7eb; }

/* ---------- Alerts ---------- */
.alert { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; font-size: 13.5px; }
.alert-success { background: #dcfce7; color: #15803d; }
.alert-error { background: #fee2e2; color: #b91c1c; }

.modal-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.4);
  align-items: center; justify-content: center;
  z-index: 100;
}
.modal-overlay.open { display: flex; }
.modal-box {
  background: #fff;
  border-radius: 12px;
  padding: 24px;
  width: 480px;
  max-width: 92vw;
  max-height: 88vh;
  overflow-y: auto;
}
.modal-box h2 { margin-top: 0; font-size: 18px; }
.modal-close { float: right; cursor: pointer; color: var(--text-muted); font-size: 20px; background: none; border: none; }

/* =====================================================================
   RESPONSIVO — celular e tablet
   ===================================================================== */

/* Botão hambúrguer e fundo escurecido: escondidos por padrão (só aparecem no celular) */
.mobile-menu-toggle {
  display: none; position: fixed; top: 14px; left: 14px; z-index: 200;
  width: 40px; height: 40px; border-radius: 8px; background: #fff; border: 1px solid var(--border);
  color: var(--text); align-items: center; justify-content: center; box-shadow: 0 2px 8px rgba(0,0,0,.08);
}
.sidebar-backdrop {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 149;
}
.sidebar-backdrop.visible { display: block; }

@media (max-width: 860px) {
  .mobile-menu-toggle { display: flex; }

  .app-layout { display: block; }
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 150;
    width: 250px; max-width: 82vw;
    transform: translateX(-100%);
    transition: transform .22s ease-out;
    box-shadow: 2px 0 16px rgba(0,0,0,.15);
  }
  .sidebar.mobile-open { transform: translateX(0); }
  .sidebar .brand { padding-left: 60px; } /* não fica atrás do botão hambúrguer */

  .main { padding: 70px 14px 24px; overflow-x: hidden; }

  /* Título de página + botões de ação: empilha em vez de espremer numa linha só */
  .page-header { flex-direction: column; align-items: flex-start; gap: 10px; }
  .page-header > div { width: 100%; }
  .page-header > div a, .page-header > div button { flex: 1; justify-content: center; }

  /* Qualquer grade de 2+ colunas (cards, telas de detalhe, dashboard) vira 1 coluna só.
     Usamos o seletor de atributo porque várias páginas definem a grade direto no style=""
     do HTML — isso alcança todas de uma vez, sem precisar editar cada página. */
  [style*="grid-template-columns"] { grid-template-columns: 1fr !important; }
  .grid-cards { grid-template-columns: 1fr !important; }

  /* Tabelas: em vez de espremer as colunas, permite rolar horizontalmente */
  .card { overflow-x: auto; }
  table { min-width: 560px; }

  /* Formulários lado a lado viram empilhados */
  .form-row { display: block !important; }
  .form-row .form-group { margin-bottom: 14px; }

  /* Editores de e-mail/landing page (drag-and-drop): a grade de 3 colunas (paleta, tela,
     preview) vira empilhada. !important porque essas páginas definem a própria grade
     num <style> local, que teria prioridade sobre essa regra sem isso. */
  .builder-layout { grid-template-columns: 1fr !important; }
  .builder-palette { position: static !important; }

  /* Modais ocupam quase a tela toda, sem sobrar espaço nas bordas */
  .modal-box { width: 100%; padding: 20px; }

  /* Kanban do Funil de Vendas: mantém rolagem horizontal (já tinha), só ajusta a largura
     de cada coluna pra caber melhor numa tela de celular */
  .kanban-col { min-width: 220px; max-width: 220px; }

  /* Mini-calendário do Dashboard: garante que não estoura a largura da tela */
  .mini-cal-day { font-size: 10.5px; }

  /* Filtro de período do Dashboard (pills): permite quebrar linha em vez de cortar */
  .pill-filter-row { flex-wrap: wrap; }
}

@media (max-width: 480px) {
  .grid-cards { gap: 10px; }
  .kpi-card, .finance-card, .stat-card { padding: 14px; }
  h1 { font-size: 20px; }
}

/* ---------- Campo de busca com lupa (searchable-select) ---------- */
.searchable-select { position: relative; }
.ss-input-wrap { position: relative; }
.ss-icon { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--text-muted); pointer-events: none; }
.ss-input { padding-left: 30px !important; }
.ss-dropdown {
  position: absolute; top: 100%; left: 0; right: 0; z-index: 50; background: #fff;
  border: 1px solid var(--border); border-radius: 8px; margin-top: 4px; max-height: 220px;
  overflow-y: auto; box-shadow: 0 4px 14px rgba(0,0,0,.1);
}
.ss-option { padding: 8px 12px; font-size: 13.5px; cursor: pointer; }
.ss-option:hover { background: var(--bg); }
.ss-empty { padding: 10px 12px; font-size: 12.5px; color: var(--text-muted); }

/* ---------- Impressão / Exportar PDF (usado em Relatórios) ---------- */
.print-header { text-align: center; margin-bottom: 20px; }
@media print {
  .sidebar, .mobile-menu-toggle, .no-print, #reminderToastContainer { display: none !important; }
  .app-layout { display: block !important; }
  .main { padding: 0 !important; margin: 0 !important; }
  .print-header { display: block !important; }
  .card { box-shadow: none !important; border: 1px solid #ddd !important; break-inside: avoid; page-break-inside: avoid; margin-bottom: 14px !important; }
  body { background: #fff !important; }
  a { color: inherit !important; text-decoration: none !important; }
}
