:root {
  --firma-red: #d3302f;
  --firma-red-dark: #a51f1e;
  --firma-black: #0a0a0a;
  --firma-ink: #171717;

  /* tokens semânticos — TEMA CLARO (default) */
  --bg-app: #f5f5f5;
  --bg-surface: #ffffff;
  --bg-elev: #fafafa;
  --border: #e5e5e5;
  --text: #171717;
  --text-muted: #737373;
  --text-soft: #a3a3a3;
  --sidebar-bg: #0a0a0a;
  --sidebar-text: #cfcfcf;
  --sidebar-muted: #6b6b6b;
  --scroll-thumb: #cbd5e1;
  --table-head: #737373;
}

/* TEMA ESCURO */
[data-theme="dark"] {
  --bg-app: #0a0a0a;
  --bg-surface: #171717;
  --bg-elev: #1f1f1f;
  --border: #2e2e2e;
  --text: #f5f5f5;
  --text-muted: #a3a3a3;
  --text-soft: #6b6b6b;
  --sidebar-bg: #050505;
  --sidebar-text: #cfcfcf;
  --sidebar-muted: #6b6b6b;
  --scroll-thumb: #3a3a3a;
  --table-head: #9a9a9a;
}

* { box-sizing: border-box; }
body { font-family: 'Inter', system-ui, -apple-system, sans-serif; background: var(--bg-app); color: var(--text); }

.firma-red { color: var(--firma-red); }
.bg-firma-red { background-color: var(--firma-red); }
.bg-firma-black { background-color: var(--firma-black); }
.border-firma-red { border-color: var(--firma-red); }

/* superfícies temáticas — sobrescrevem utilitários Tailwind */
.bg-app { background: var(--bg-app) !important; }
.card { background: var(--bg-surface); border-radius: .75rem; box-shadow: 0 1px 3px rgba(0,0,0,.08); color: var(--text); }
[data-theme="dark"] .card { box-shadow: 0 1px 3px rgba(0,0,0,.5); border: 1px solid var(--border); }

/* mapeia utilitários neutros usados no app p/ tokens de tema */
[data-theme="dark"] .bg-neutral-100 { background-color: var(--bg-elev) !important; }
[data-theme="dark"] .bg-neutral-50 { background-color: var(--bg-elev) !important; }
[data-theme="dark"] .bg-white { background-color: var(--bg-surface) !important; }
[data-theme="dark"] .hover\:bg-neutral-50:hover { background-color: #262626 !important; }
[data-theme="dark"] .text-neutral-900 { color: var(--text) !important; }
[data-theme="dark"] .text-neutral-800 { color: #e5e5e5 !important; }
[data-theme="dark"] .text-neutral-600 { color: var(--text-muted) !important; }
[data-theme="dark"] .text-neutral-500 { color: var(--text-muted) !important; }
[data-theme="dark"] .text-neutral-400 { color: var(--text-soft) !important; }
[data-theme="dark"] .text-neutral-700 { color: #d4d4d4 !important; }
[data-theme="dark"] .text-neutral-300 { color: var(--text-soft) !important; }
[data-theme="dark"] .text-neutral-200 { color: #e5e5e5 !important; }
[data-theme="dark"] .border, [data-theme="dark"] .border-b, [data-theme="dark"] .border-t { border-color: var(--border) !important; }
[data-theme="dark"] input, [data-theme="dark"] select, [data-theme="dark"] textarea { background: var(--bg-elev); color: var(--text); border-color: var(--border); }
/* pílulas de status neutras (etapa do funil, etc.) */
[data-theme="dark"] .bg-neutral-200 { background-color: #333333 !important; color: #e5e5e5 !important; }
[data-theme="dark"] .bg-neutral-300 { background-color: #3a3a3a !important; color: #e5e5e5 !important; }

/* ===== Botões secundários (contorno) legíveis no modo escuro =====
   Botões que usam "border" + "bg-white" (Dados do orçamento, Mover etapa, PDF, etc.)
   ganham fundo elevado, borda visível e texto claro. */
[data-theme="dark"] button.bg-white,
[data-theme="dark"] a.bg-white {
  background-color: var(--bg-elev) !important;
  color: var(--text) !important;
  border-color: var(--border) !important;
}
[data-theme="dark"] button.bg-white:hover,
[data-theme="dark"] a.bg-white:hover { background-color: #2a2a2a !important; }
/* botão de excluir (contorno vermelho) mantém identidade no escuro */
[data-theme="dark"] button.text-red-600.bg-white,
[data-theme="dark"] a.text-red-600.bg-white { color: #f87171 !important; border-color: rgba(248,113,113,.4) !important; }
[data-theme="dark"] button.text-red-600.bg-white:hover { background-color: rgba(153,27,27,.25) !important; }
/* ícones neutros de ações em tabelas ficam mais visíveis */
[data-theme="dark"] .text-neutral-300.hover\:text-red-600 { color: #6b6b6b !important; }

/* Sidebar */
.sidebar { background: var(--sidebar-bg); }
.sidebar-brand { padding: 22px 16px; display: flex; align-items: center; justify-content: center; border-bottom: 1px solid rgba(255,255,255,.08); }
.sidebar-brand img { width: 85%; max-width: 190px; height: auto; transition: all .2s; }
.sidebar-group-title { color: var(--sidebar-muted); font-size: .68rem; text-transform: uppercase; letter-spacing: .08em; }
.sidebar-link { transition: all .15s; color: var(--sidebar-text); border-left: 3px solid transparent; }
.sidebar-link:hover { background: rgba(255,255,255,.06); color: #fff; }
.sidebar-link.active { background: rgba(211,48,47,.15); color: #fff; border-left-color: var(--firma-red); }

/* Sidebar colapsada */
.sidebar.collapsed { width: 4.5rem !important; }
.sidebar.collapsed .sidebar-label,
.sidebar.collapsed .sidebar-group-title,
.sidebar.collapsed .sidebar-user-info { display: none; }
.sidebar.collapsed .sidebar-brand img { width: 100%; max-width: 46px; height: auto; }
.sidebar.collapsed .sidebar-link { justify-content: center; padding-left: 0; padding-right: 0; }
.sidebar.collapsed .sidebar-brand { padding: 16px 6px; }

.kanban-col { min-width: 300px; }
/* Drag & drop do kanban */
.kanban-card { user-select: none; }
.kanban-card:active { cursor: grabbing; }
.kanban-dragging { transform: rotate(1.5deg); box-shadow: 0 8px 20px rgba(0,0,0,.15); }
.kanban-drop-active { background: #eef2ff !important; outline: 2px dashed #818cf8; outline-offset: -4px; }
.kanban-drop-active .kanban-empty { color: #6366f1; }
.margin-verde { background:#dcfce7; color:#166534; }
.margin-amarelo { background:#fef9c3; color:#854d0e; }
.margin-vermelho { background:#fee2e2; color:#991b1b; }
[data-theme="dark"] .margin-verde { background: rgba(22,101,52,.25); color:#4ade80; }
[data-theme="dark"] .margin-amarelo { background: rgba(133,77,14,.3); color:#fbbf24; }
[data-theme="dark"] .margin-vermelho { background: rgba(153,27,27,.3); color:#f87171; }

.modal-backdrop { background: rgba(10,10,10,.6); }
table.data-table th { font-weight:600; font-size:.72rem; text-transform:uppercase; letter-spacing:.03em; color: var(--table-head); }
table.data-table td, table.data-table th { padding:.5rem .6rem; }

/* Composição da proposta — tabela mais legível */
table.comp-table { border-collapse: separate; border-spacing: 0; }
table.comp-table thead th { background: rgba(0,0,0,.02); padding-top:.6rem; padding-bottom:.6rem; white-space:nowrap; border-bottom:1px solid var(--border, #e5e7eb); }
table.comp-table tbody tr:last-child td { border-bottom: none; }
table.comp-table td, table.comp-table th { padding-left:.75rem; padding-right:.75rem; }
table.comp-table td:first-child, table.comp-table th:first-child { padding-left: .5rem; }
table.comp-table td:last-child, table.comp-table th:last-child { padding-right: .5rem; }

input, select, textarea { outline:none; }
input:focus, select:focus, textarea:focus { border-color: var(--firma-red); box-shadow:0 0 0 2px rgba(211,48,47,.15); }
.btn-primary { background:var(--firma-red); color:#fff; }
.btn-primary:hover { background:var(--firma-red-dark); }
.btn-dark { background:var(--firma-black); color:#fff; }
.btn-dark:hover { background:#262626; }

/* Tabs da proposta */
/* Botões não herdam `color` do body por padrão; definimos explicitamente a cor
   das abas inativas para que fiquem legíveis nos dois temas. */
.prop-tab { color: var(--text-muted); }
.prop-tab:hover { color: var(--text); }
.prop-tab.tab-active { border-bottom-color: var(--firma-red) !important; color: var(--firma-red) !important; }
/* Abas do cadastro de produto (mesmo princípio) */
.prod-tab { color: var(--text-muted); }
.prod-tab:hover { color: var(--text); }
[data-theme="dark"] .prod-tab.text-neutral-500 { color: var(--text-muted) !important; }

/* Popover financeiro (custo total / valor final por item) */
.fin-pop { position: fixed; z-index: 60; background: var(--bg-surface); color: var(--text); border: 1px solid var(--border);
  border-radius: .6rem; box-shadow: 0 8px 30px rgba(0,0,0,.25); padding: 12px 14px; width: 300px; font-size: 12px; }
.fin-pop h4 { font-weight: 600; margin-bottom: 6px; font-size: 12px; }
.fin-pop .row { display:flex; justify-content:space-between; padding: 2px 0; }
.link-num { cursor: pointer; border-bottom: 1px dashed currentColor; }
.link-num:hover { color: var(--firma-red); }

/* painel de filtros genérico */
.filtros-pop { position: fixed; z-index: 60; background: var(--bg-surface); color: var(--text);
  border: 1px solid var(--border); border-radius: .7rem; box-shadow: 0 8px 30px rgba(0,0,0,.25);
  padding: 14px; max-height: 70vh; overflow-y: auto; }
.filtros-pop select, .filtros-pop input { background: var(--bg-surface); color: var(--text); border-color: var(--border); }

/* avatar de usuário */
.avatar-user { line-height: 1; letter-spacing: .3px; }
.avatar-user.avatar-vazio { border-color: var(--border); background: var(--bg-elev); }

::-webkit-scrollbar { height:8px; width:8px; }
::-webkit-scrollbar-thumb { background: var(--scroll-thumb); border-radius:4px; }
.sidebar ::-webkit-scrollbar-thumb { background:#333; }
@media print {
  .no-print { display:none !important; }
  body { background:#fff; }
}

/* ===== Dashboard da Visão Geral ===== */
.chart-box { position: relative; height: 150px; width: 100%; }
.dash-gauge { position: relative; padding-top: 6px; padding-bottom: 26px; }
.dash-gauge-track { height: 10px; border-radius: 999px; background: var(--border, #e5e7eb); overflow: hidden; }
.dash-gauge-fill { height: 100%; border-radius: 999px; transition: width .4s ease; }
.dash-gauge-mark { position: absolute; top: 2px; width: 0; }
.dash-gauge-mark::before { content: ''; position: absolute; top: 0; left: -1px; width: 2px; height: 18px; background: currentColor; opacity: .55; }
.dash-gauge-mark { color: #64748b; }
.dash-gauge-lbl { position: absolute; top: 20px; left: 0; transform: translateX(-50%); font-size: 10px; white-space: nowrap; font-weight: 600; }

/* ===== Calendário de eventos ===== */
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal-head { margin-bottom: 6px; }
.cal-dayname { text-align: center; font-size: 11px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; padding: 4px 0; }
.cal-cell { min-height: 92px; border: 1px solid var(--border); border-radius: .5rem; padding: 4px; background: var(--bg-surface); display: flex; flex-direction: column; }
.cal-empty { background: transparent; border-color: transparent; }
.cal-today { border-color: var(--firma-red); box-shadow: inset 0 0 0 1px var(--firma-red); }
.cal-daynum { font-size: 12px; font-weight: 600; color: var(--text-muted); margin-bottom: 2px; }
.cal-daynum-today { color: var(--firma-red); }
.cal-events { display: flex; flex-direction: column; gap: 3px; overflow: hidden; }
.cal-ev { font-size: 10.5px; line-height: 1.2; text-align: left; padding: 2px 5px; border-radius: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer; border: 0; font-weight: 500; }
/* status do evento (6.7): em_orcamento, aprovado, realizado, cancelado — mantém aliases antigos */
.cal-ev-em_orcamento, .cal-ev-aberto { background: #e0f2fe; color: #0369a1; }
.cal-ev-aprovado, .cal-ev-em_execucao { background: #fef3c7; color: #92400e; }
.cal-ev-realizado, .cal-ev-encerrado { background: #d1fae5; color: #065f46; }
.cal-ev-cancelado { background: #ffe4e6; color: #9f1239; }
.cal-ev:hover { filter: brightness(.95); }
[data-theme="dark"] .cal-ev-em_orcamento, [data-theme="dark"] .cal-ev-aberto { background: rgba(3,105,161,.3); color: #7dd3fc; }
[data-theme="dark"] .cal-ev-aprovado, [data-theme="dark"] .cal-ev-em_execucao { background: rgba(146,64,14,.35); color: #fcd34d; }
[data-theme="dark"] .cal-ev-realizado, [data-theme="dark"] .cal-ev-encerrado { background: rgba(6,95,70,.35); color: #6ee7b7; }
[data-theme="dark"] .cal-ev-cancelado { background: rgba(159,18,57,.35); color: #fda4af; }
