/* =========================================================
   MF LAR - CRM Caixa Aqui
   Tema Claro / Escuro (variáveis CSS) e componentes visuais
   ========================================================= */

:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --surface-3: rgba(226, 232, 240, 0.7);
  --hover: #f1f5f9;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #1e293b;
  --text-strong: #0f172a;
  --text-muted: #64748b;
  --text-faint: #94a3b8;
  --accent-text: #005ca9;
  --ring: #005ca9;
  --selected: rgba(0, 92, 169, 0.07);
}

.dark {
  --bg: #0d1017;
  --surface: #151922;
  --surface-2: #11151d;
  --surface-3: #1a202c;
  --hover: #1f2633;
  --border: #252d3d;
  --border-strong: #333d52;
  --text: #e2e8f0;
  --text-strong: #f8fafc;
  --text-muted: #94a3b8;
  --text-faint: #64748b;
  --accent-text: #60a5fa;
  --ring: #3b82f6;
  --selected: rgba(96, 165, 250, 0.1);
  color-scheme: dark;
}

html, body {
  background: var(--bg);
  color: var(--text);
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  transition: background-color 0.2s ease, color 0.2s ease;
}

/* ---------- Utilitários de tema ---------- */
.surface      { background: var(--surface); }
.surface-2    { background: var(--surface-2); }
.col-bg       { background: var(--surface-3); }
.bd           { border-color: var(--border) !important; }
.bd-strong    { border-color: var(--border-strong) !important; }
.txt          { color: var(--text); }
.txt-strong   { color: var(--text-strong); }
.txt-muted    { color: var(--text-muted); }
.txt-faint    { color: var(--text-faint); }
.txt-accent   { color: var(--accent-text); }
.hover-surface:hover { background: var(--hover); }
.track        { background: var(--border); }

/* ---------- Cabeçalho e Barra Lateral Esquerda ---------- */
.app-header {
  background: linear-gradient(90deg, #003666 0%, #005ca9 55%, #1d4ed8 100%);
}
.dark .app-header {
  background: linear-gradient(90deg, #0b101b 0%, #111a2e 55%, #162440 100%);
  border-bottom: 1px solid #252d3d;
}

.app-sidebar {
  width: 248px;
  min-width: 248px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  transition: width 0.2s ease, min-width 0.2s ease;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  z-index: 25;
}

.app-sidebar.collapsed {
  width: 68px;
  min-width: 68px;
}

.app-sidebar.collapsed .sidebar-label,
.app-sidebar.collapsed .sidebar-section-title,
.app-sidebar.collapsed .sidebar-footer-text,
.app-sidebar.collapsed .nav-badge,
.app-sidebar.collapsed .nav-badge-soft {
  display: none;
}

.app-sidebar.collapsed .nav-tab {
  justify-content: center;
  padding-left: 0.5rem;
  padding-right: 0.5rem;
}

.nav-tab {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  gap: 0.65rem;
  padding: 0.65rem 0.85rem;
  border-radius: 0.65rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
  border: 1px solid transparent;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.nav-tab:hover {
  background: var(--hover);
  color: var(--text-strong);
}
.nav-tab.active {
  background: linear-gradient(90deg, #005ca9 0%, #1d4ed8 100%);
  color: #ffffff;
  box-shadow: 0 4px 12px -2px rgba(0, 92, 169, 0.35);
}
.dark .nav-tab.active {
  background: linear-gradient(90deg, #0b4a8b 0%, #1d4ed8 100%);
  color: #ffffff;
}

.nav-badge {
  background: #ef4444;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 0.05rem 0.45rem;
  border-radius: 999px;
  min-width: 1.25rem;
  text-align: center;
  line-height: 1.15rem;
}
.nav-badge-soft {
  background: var(--surface-3);
  color: var(--text);
  font-size: 10px;
  font-weight: 700;
  padding: 0.05rem 0.45rem;
  border-radius: 999px;
  line-height: 1.15rem;
}
.nav-tab.active .nav-badge-soft {
  background: rgba(255, 255, 255, 0.22);
  color: #ffffff;
}

/* ---------- Botões ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.45rem 0.8rem;
  border-radius: 0.5rem;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  white-space: nowrap;
  border: 1px solid transparent;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: #005ca9; color: #fff; }
.btn-primary:hover:not(:disabled) { background: #004a8a; }
.btn-orange { background: #f37021; color: #fff; }
.btn-orange:hover:not(:disabled) { background: #dc5f12; }
.btn-ghost { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-ghost:hover:not(:disabled) { background: var(--hover); }
.btn-danger-ghost { background: transparent; color: #dc2626; border-color: rgba(220, 38, 38, 0.35); }
.btn-danger-ghost:hover { background: rgba(220, 38, 38, 0.08); }
.dark .btn-danger-ghost { color: #f87171; }
.btn-header {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #fff;
  padding: 0.5rem;
  border-radius: 0.5rem;
  transition: background 0.15s;
}
.btn-header:hover { background: rgba(255, 255, 255, 0.22); }
.btn-icon-sm {
  padding: 0.3rem;
  border-radius: 0.375rem;
  color: var(--text-faint);
  transition: background 0.15s, color 0.15s;
}
.btn-icon-sm:hover { background: var(--hover); color: var(--accent-text); }

.btn-add-col {
  margin-top: 0.5rem;
  width: 100%;
  padding: 0.5rem;
  border: 2px dashed var(--border-strong);
  border-radius: 0.5rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  background: transparent;
  transition: all 0.15s;
}
.btn-add-col:hover { border-color: #005ca9; color: var(--accent-text); background: var(--surface); }

/* Controle segmentado (Kanban | Lista) */
.seg {
  display: inline-flex;
  border: 1px solid var(--border-strong);
  border-radius: 0.6rem;
  padding: 2px;
  background: var(--surface-2);
}
.seg button {
  padding: 0.35rem 0.75rem;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: 0.45rem;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  transition: all 0.15s;
}
.seg button.active {
  background: var(--surface);
  color: var(--accent-text);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
}

/* ---------- Campos de formulário ---------- */
.field {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  color: var(--text);
  border-radius: 0.5rem;
  padding: 0.5rem 0.625rem;
  font-size: 0.875rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.field:focus { outline: none; border-color: var(--ring); box-shadow: 0 0 0 2px rgba(0, 92, 169, 0.25); }
.field::placeholder { color: var(--text-faint); }
.field-sm { padding: 0.375rem 0.5rem; font-size: 0.75rem; }
.field-auto { width: auto; }
.label { display: block; font-size: 0.75rem; font-weight: 600; color: var(--text-muted); margin-bottom: 0.25rem; }
.dark select option { background: #151922; color: #e2e8f0; }
.dark input[type="date"]::-webkit-calendar-picker-indicator { filter: invert(0.85); }
input[type="checkbox"] { accent-color: #005ca9; cursor: pointer; }
.chk-green { accent-color: #059669; }
.chk-orange { accent-color: #f37021; }

/* ---------- Tons (badges/caixas) com variante escura ---------- */
.tone-red    { background: #fef2f2; color: #991b1b; border-color: #fecaca; }
.tone-amber  { background: #fffbeb; color: #92400e; border-color: #fde68a; }
.tone-yellow { background: #fefce8; color: #854d0e; border-color: #fef08a; }
.tone-orange { background: #fff7ed; color: #9a3412; border-color: #fed7aa; }
.tone-green  { background: #ecfdf5; color: #065f46; border-color: #a7f3d0; }
.tone-blue   { background: #eff6ff; color: #1e40af; border-color: #bfdbfe; }
.tone-indigo { background: #eef2ff; color: #3730a3; border-color: #c7d2fe; }
.tone-purple { background: #f5f3ff; color: #5b21b6; border-color: #ddd6fe; }
.tone-slate  { background: #f1f5f9; color: #475569; border-color: #e2e8f0; }

.dark .tone-red    { background: rgba(239, 68, 68, 0.12);  color: #fca5a5; border-color: rgba(239, 68, 68, 0.35); }
.dark .tone-amber  { background: rgba(245, 158, 11, 0.12); color: #fcd34d; border-color: rgba(245, 158, 11, 0.35); }
.dark .tone-yellow { background: rgba(234, 179, 8, 0.12);  color: #fde047; border-color: rgba(234, 179, 8, 0.35); }
.dark .tone-orange { background: rgba(249, 115, 22, 0.13); color: #fdba74; border-color: rgba(249, 115, 22, 0.35); }
.dark .tone-green  { background: rgba(16, 185, 129, 0.12); color: #6ee7b7; border-color: rgba(16, 185, 129, 0.35); }
.dark .tone-blue   { background: rgba(59, 130, 246, 0.13); color: #93c5fd; border-color: rgba(59, 130, 246, 0.35); }
.dark .tone-indigo { background: rgba(99, 102, 241, 0.15); color: #a5b4fc; border-color: rgba(99, 102, 241, 0.38); }
.dark .tone-purple { background: rgba(139, 92, 246, 0.14); color: #c4b5fd; border-color: rgba(139, 92, 246, 0.38); }
.dark .tone-slate  { background: rgba(148, 163, 184, 0.1); color: #cbd5e1; border-color: rgba(148, 163, 184, 0.25); }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 10px;
  font-weight: 700;
  padding: 0.125rem 0.4rem;
  border-radius: 0.375rem;
  border: 1px solid;
  white-space: nowrap;
  line-height: 1.1rem;
}
.count-pill {
  background: var(--border-strong);
  color: var(--text);
  font-size: 11px;
  padding: 0 0.5rem;
  border-radius: 999px;
  font-weight: 600;
  line-height: 1.25rem;
}

.panel-blue { background: rgba(0, 92, 169, 0.05); border-color: rgba(0, 92, 169, 0.18) !important; }
.dark .panel-blue { background: rgba(96, 165, 250, 0.06); border-color: rgba(96, 165, 250, 0.2) !important; }

/* ---------- Scrollbars ---------- */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }

/* ---------- Kanban ---------- */
.kanban-col { min-height: calc(100vh - 300px); }
.kanban-card {
  transition: transform 0.22s cubic-bezier(0.16, 1, 0.3, 1),
              box-shadow 0.22s cubic-bezier(0.16, 1, 0.3, 1),
              border-color 0.2s ease,
              background-color 0.2s ease;
  user-select: none;
  will-change: transform;
  animation: cardFadeIn 0.22s cubic-bezier(0.16, 1, 0.3, 1) both;
}
.kanban-card:hover {
  transform: translateY(-2px);
  border-color: rgba(0, 92, 169, 0.45) !important;
  box-shadow: 0 10px 22px -6px rgba(15, 23, 42, 0.08), 0 4px 8px -4px rgba(15, 23, 42, 0.04);
}
.dark .kanban-card:hover {
  border-color: rgba(96, 165, 250, 0.45) !important;
  box-shadow: 0 12px 24px -8px rgba(0, 0, 0, 0.45);
}
.kanban-card.dragging {
  opacity: 0.65;
  transform: scale(0.97) rotate(1deg);
  box-shadow: 0 16px 32px -8px rgba(0, 92, 169, 0.25);
}
.kanban-drop-zone, .ws-drop-zone {
  transition: background-color 0.2s ease, outline-color 0.2s ease;
}
.kanban-drop-zone.drag-over, .ws-drop-zone.drag-over {
  background-color: rgba(2, 132, 199, 0.08) !important;
  outline: 2px dashed #0284c7;
  outline-offset: -2px;
  border-radius: 0.75rem;
}
.ws-card.dragging {
  opacity: 0.6;
  transform: scale(0.98) rotate(1deg);
  box-shadow: 0 16px 32px -8px rgba(0, 92, 169, 0.3);
}

/* ---------- Animações Fluidas (Páginas, Cards, Modais e Abas) ---------- */
@keyframes pageFadeSlide {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes cardFadeIn {
  from {
    opacity: 0;
    transform: translateY(5px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes modalPopIn {
  from {
    opacity: 0;
    transform: scale(0.96) translateY(8px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

@keyframes backdropFadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.page-transition {
  animation: pageFadeSlide 0.24s cubic-bezier(0.16, 1, 0.3, 1) both;
}

#modal-processo:not(.hidden) > div:last-child,
#modal-tarefa:not(.hidden) > div:last-child,
#modal-usuarios-sistema:not(.hidden) > div:last-child {
  animation: modalPopIn 0.24s cubic-bezier(0.16, 1, 0.3, 1) both;
}

#modal-processo:not(.hidden) .modal-backdrop,
#modal-tarefa:not(.hidden) .modal-backdrop,
#modal-usuarios-sistema:not(.hidden) {
  animation: backdropFadeIn 0.18s ease-out both;
}

.tab-content:not(.hidden) {
  animation: pageFadeSlide 0.18s cubic-bezier(0.16, 1, 0.3, 1) both;
}

/* Transição suave para gaveta de filtros avançados */
.filter-drawer {
  overflow: hidden;
  transition: max-height 0.26s cubic-bezier(0.16, 1, 0.3, 1),
              opacity 0.2s ease,
              padding-top 0.2s ease,
              margin-top 0.2s ease;
  max-height: 260px;
  opacity: 1;
}
.filter-drawer.collapsed-drawer {
  max-height: 0;
  opacity: 0;
  padding-top: 0 !important;
  margin-top: 0 !important;
  border-top-width: 0 !important;
  pointer-events: none;
}

/* Pills rápidas de etapa minimalistas */
.stage-quick-pill {
  padding: 0.3rem 0.65rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  transition: all 0.18s cubic-bezier(0.16, 1, 0.3, 1);
  cursor: pointer;
  white-space: nowrap;
}
.stage-quick-pill:hover {
  color: var(--text-strong);
  border-color: var(--border-strong);
}
.stage-quick-pill.active {
  background: #005ca9;
  color: #ffffff;
  border-color: #005ca9;
  box-shadow: 0 2px 8px -2px rgba(0, 92, 169, 0.35);
}

/* ---------- Lista (planilha) ---------- */
.data-table { border-collapse: separate; border-spacing: 0; }
.data-table thead th {
  position: sticky;
  top: 0;
  background: var(--surface-2);
  z-index: 2;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  font-weight: 700;
  color: var(--text-muted);
  padding: 0.6rem 0.75rem;
  white-space: nowrap;
  user-select: none;
}
.data-table th.th-sort { cursor: pointer; }
.data-table th.th-sort:hover { color: var(--accent-text); }
.data-table td, .data-table th { border-bottom: 1px solid var(--border); }
.data-table tbody tr:hover td { background: var(--hover); }
.data-table tbody tr.selecionada td { background: var(--selected); }
.data-table tr.grupo td {
  background: var(--surface-2);
  font-weight: 700;
  color: var(--text-strong);
  padding: 0.55rem 0.75rem;
  font-size: 12px;
}
.data-table tfoot td {
  position: sticky;
  bottom: 0;
  background: var(--surface-2);
  border-top: 2px solid var(--border-strong);
}

.cell-input {
  width: 100%;
  min-width: 100px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  padding: 0.25rem 0.4rem;
  color: var(--text);
  font-size: 0.75rem;
}
.cell-input:hover { border-color: var(--border-strong); }
.cell-input:focus { outline: none; border-color: var(--ring); background: var(--surface); box-shadow: 0 0 0 2px rgba(0, 92, 169, 0.2); }
.cell-select {
  font-size: 11px;
  font-weight: 600;
  border-radius: 0.375rem;
  padding: 0.2rem 0.3rem;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
.cell-select.chip { padding: 0.15rem 0.3rem; }

.popover {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 20;
  min-width: 220px;
  max-height: 360px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  box-shadow: 0 12px 32px -8px rgba(0, 0, 0, 0.25);
  padding: 0.5rem;
}

/* ---------- Abas do modal (Estilo Botões Separados e Maiores) ---------- */
.tab-btn {
  padding: 0.85rem 1.25rem;
  min-height: 48px;
  border-radius: 0.75rem;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  white-space: nowrap;
  font-size: 0.875rem;
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
  cursor: pointer;
  transition: all 0.18s cubic-bezier(0.4, 0, 0.2, 1);
  user-select: none;
}

.tab-btn i,
.tab-btn svg {
  width: 1.125rem;
  height: 1.125rem;
  flex-shrink: 0;
}

.tab-btn:hover:not(.active) {
  color: var(--text-strong);
  background: var(--hover);
  border-color: var(--accent);
  transform: translateY(-1px);
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.08);
}

.tab-btn.active {
  background: #005ca9;
  border-color: #004a8a;
  color: #ffffff !important;
  font-weight: 700;
  box-shadow: 0 2px 8px rgba(0, 92, 169, 0.35);
  transform: translateY(-1px);
}

.dark .tab-btn.active {
  background: #0284c7;
  border-color: #38bdf8;
  color: #ffffff !important;
  box-shadow: 0 2px 10px rgba(2, 132, 199, 0.4);
}

.tab-btn.active i,
.tab-btn.active svg {
  color: #ffffff !important;
  stroke: #ffffff !important;
}

.tab-btn.active .chip {
  background: rgba(255, 255, 255, 0.25) !important;
  color: #ffffff !important;
  border-color: rgba(255, 255, 255, 0.35) !important;
}

/* ---------- Checklist diário ---------- */
.check-item { transition: border-color 0.15s, background 0.15s, opacity 0.15s; }
.check-item.concluido { border-color: rgba(16, 185, 129, 0.45) !important; }
.check-item.concluido .check-titulo { text-decoration: line-through; color: var(--text-faint); }
.check-big { width: 1.35rem; height: 1.35rem; }

/* ---------- Modais ---------- */
.modal-backdrop { backdrop-filter: blur(4px); }

/* ---------- Arrastar Arquivos (WhatsApp -> Processo / Supabase) ---------- */
.file-drop-active {
  border-color: #10b981 !important;
  background: rgba(16, 185, 129, 0.12) !important;
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.28) !important;
}

/* ---------- Controle de Visibilidade por Perfil (Administrador vs Membro) ---------- */
body[data-user-role="membro"] [data-admin-only="true"] {
  display: none !important;
}

body:not([data-user-role="admin"]) #btn-open-users-modal,
body:not([data-user-role="admin"]) #modal-usuarios-sistema {
  display: none !important;
}

@keyframes modalPopIn {
  from { opacity: 0; transform: scale(0.96) translateY(8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

#modal-novo-processo-wizard:not(.hidden) > div:last-child,
#modal-pendencias-avanco:not(.hidden) > div:last-child {
  animation: modalPopIn 0.22s cubic-bezier(0.16, 1, 0.3, 1) both;
}

/* ---------- Impressão ---------- */
@media print {
  body * { visibility: hidden; }
  #printable-sheet, #printable-sheet * { visibility: visible; }
  #printable-sheet { display: block !important; position: absolute; left: 0; top: 0; width: 100%; background: #fff; color: #000; }
}
