/* CREMP — paleta sóbria (mesma direção do redesign do Salim): texto simples, pouca cor, cor só onde carrega significado. */
:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface2: #f0f2f5;
  --border: #e2e5ea;
  --text: #1b1f24;
  --text-soft: #5b6470;
  --muted: #8a929c;
  --accent: #2f5bea;
  --accent-soft: #e8eeff;
  --ok: #1d7a46;
  --ok-soft: #e4f4ea;
  --warn: #9a6200;
  --warn-soft: #fdf2dc;
  --bad: #b42318;
  --bad-soft: #fde8e6;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 8px;
  --mono: 'JetBrains Mono', ui-monospace, Consolas, monospace;
  color-scheme: light;
}
:root.dark {
  --bg: #111317;
  --surface: #181b20;
  --surface2: #1f232a;
  --border: #2b3038;
  --text: #e6e8eb;
  --text-soft: #a7aeb8;
  --muted: #747c87;
  --accent: #7c9cff;
  --accent-soft: #1d2747;
  --ok: #4cc488;
  --ok-soft: #14301f;
  --warn: #e4b04a;
  --warn-soft: #3a2c10;
  --bad: #ff7b6e;
  --bad-soft: #3d1a17;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 14px;
  line-height: 1.45;
  background: var(--bg);
  color: var(--text);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 20px; margin: 0; font-weight: 600; }
h2 { font-size: 15px; margin: 0 0 12px; font-weight: 600; }
h3 { font-size: 13px; margin: 0 0 8px; font-weight: 600; color: var(--text-soft); text-transform: uppercase; letter-spacing: .04em; }
.mono, .num { font-family: var(--mono); font-size: 12.5px; }
.num { text-align: right; white-space: nowrap; }
.soft { color: var(--text-soft); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.ok { color: var(--ok); }
.bad { color: var(--bad); }
.warn { color: var(--warn); }
.hidden { display: none !important; }

/* ---------- Layout */
.app { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 16px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.marca { font-weight: 700; font-size: 18px; padding: 4px 10px 16px; letter-spacing: -.01em; }
.marca small { display: block; font-weight: 400; font-size: 11px; color: var(--muted); letter-spacing: 0; }
.nav-grupo { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 14px 10px 4px; }
.nav a {
  display: block;
  padding: 7px 10px;
  border-radius: 6px;
  color: var(--text-soft);
}
.nav a:hover { background: var(--surface2); text-decoration: none; color: var(--text); }
.nav a.ativo { background: var(--accent-soft); color: var(--accent); font-weight: 500; }
.sidebar-rodape { margin-top: auto; padding: 12px 10px 0; border-top: 1px solid var(--border); font-size: 12px; }
.sidebar-rodape .usuario { font-weight: 500; }
.sidebar-rodape .links { display: flex; gap: 10px; margin-top: 6px; flex-wrap: wrap; }
.sidebar-rodape button { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; font: inherit; }

.main { padding: 24px 28px 48px; min-width: 0; }
.topo { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.topo .acoes { display: flex; gap: 8px; flex-wrap: wrap; }
.subtitulo { color: var(--text-soft); margin-top: 2px; }
.voltar { font-size: 12px; display: inline-block; margin-bottom: 6px; }

.menu-mobile { display: none; }
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 30; width: 240px; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow); }
  .sidebar.aberta { transform: none; }
  .menu-mobile { display: inline-flex; margin-bottom: 12px; }
  .main { padding: 16px; }
}

/* ---------- Componentes */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.card + .card { margin-top: 16px; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi .rotulo { font-size: 12px; color: var(--text-soft); }
.kpi .valor { font-size: 22px; font-weight: 600; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .detalhe { font-size: 12px; color: var(--muted); margin-top: 2px; }
@media (max-width: 1100px) { .grid-3 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 760px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 7px 12px;
  border-radius: 6px;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--surface2); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primario { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primario:hover { filter: brightness(1.08); }
.btn.perigo { color: var(--bad); }
.btn.pequeno { padding: 3px 8px; font-size: 12px; }
.btn.link { border: 0; background: none; padding: 0; color: var(--accent); font-weight: 400; }

.tag { display: inline-block; font-size: 11.5px; padding: 1px 7px; border-radius: 10px; background: var(--surface2); color: var(--text-soft); white-space: nowrap; }
.tag.ok { background: var(--ok-soft); color: var(--ok); }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.tag.bad { background: var(--bad-soft); color: var(--bad); }
.tag.info { background: var(--accent-soft); color: var(--accent); }

/* ---------- Tabelas */
.tabela-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; font-weight: 500; color: var(--text-soft); background: var(--surface2); white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr.clicavel { cursor: pointer; }
tbody tr.clicavel:hover { background: var(--surface2); }
tfoot td { font-weight: 600; background: var(--surface2); }
td.acoes { white-space: nowrap; text-align: right; }
td.acoes .btn + .btn { margin-left: 4px; }
.vazio { padding: 28px; text-align: center; color: var(--muted); }

/* ---------- Filtros / abas */
.filtros { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.filtros input[type=search] { min-width: 240px; }
.abas { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.abas button {
  background: none; border: 0; border-bottom: 2px solid transparent;
  padding: 8px 12px; font: inherit; color: var(--text-soft); cursor: pointer; white-space: nowrap;
}
.abas button.ativo { color: var(--accent); border-bottom-color: var(--accent); font-weight: 500; }
.abas .contador { font-size: 11px; color: var(--muted); margin-left: 4px; }
.paginacao { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 10px; font-size: 12px; color: var(--text-soft); }

/* ---------- Formulários */
input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 9px;
  width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
textarea { min-height: 70px; resize: vertical; }
.filtros input, .filtros select { width: auto; }
label.campo { display: block; }
label.campo > span { display: block; font-size: 12px; color: var(--text-soft); margin-bottom: 4px; }
.form-grid { display: grid; grid-template-columns: repeat(12, 1fr); gap: 12px; }
.c2 { grid-column: span 2; } .c3 { grid-column: span 3; } .c4 { grid-column: span 4; } .c5 { grid-column: span 5; }
.c6 { grid-column: span 6; } .c8 { grid-column: span 8; } .c9 { grid-column: span 9; } .c12 { grid-column: span 12; }
@media (max-width: 700px) { .form-grid > * { grid-column: span 12; } }
.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.check input { width: auto; }
.secao-form { grid-column: span 12; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-top: 6px; }
input.dinheiro { text-align: right; font-family: var(--mono); }

/* Itens de proposta/contrato */
.itens td { padding: 6px; vertical-align: middle; }
.itens input, .itens select { padding: 5px 7px; }
.itens .col-qtd { width: 80px; } .itens .col-preco { width: 130px; } .itens .col-desc { width: 80px; }
.itens .col-rec { width: 70px; text-align: center; } .itens .col-total { width: 130px; } .itens .col-x { width: 36px; }
.totais { display: flex; gap: 24px; justify-content: flex-end; padding: 12px 4px 0; flex-wrap: wrap; }
.totais div { text-align: right; }
.totais .rotulo { font-size: 12px; color: var(--text-soft); }
.totais .valor { font-size: 18px; font-weight: 600; font-family: var(--mono); }

/* Autocomplete */
.ac { position: relative; }
.ac-lista { position: absolute; z-index: 60; left: 0; right: 0; top: 100%; margin-top: 2px; background: var(--surface); border: 1px solid var(--border); border-radius: 6px; box-shadow: 0 8px 24px rgba(0,0,0,.12); max-height: 260px; overflow-y: auto; }
.ac-lista div { padding: 7px 10px; cursor: pointer; }
.ac-lista div:hover, .ac-lista div.sel { background: var(--accent-soft); }

/* ---------- Modal */
.modal-fundo { position: fixed; inset: 0; background: rgba(10, 12, 16, .45); display: flex; align-items: flex-start; justify-content: center; z-index: 50; padding: 6vh 16px; overflow-y: auto; }
.modal { background: var(--surface); border-radius: 10px; width: 100%; max-width: 640px; box-shadow: 0 20px 50px rgba(0,0,0,.25); border: 1px solid var(--border); }
.modal.largo { max-width: 920px; }
.modal-cab { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.modal-cab h2 { margin: 0; }
.modal-cab button { background: none; border: 0; font-size: 20px; cursor: pointer; color: var(--muted); }
.modal-corpo { padding: 18px; }
.modal-rodape { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--border); background: var(--surface2); border-radius: 0 0 10px 10px; }
.erro-form { color: var(--bad); background: var(--bad-soft); padding: 8px 10px; border-radius: 6px; margin-bottom: 12px; }

/* ---------- Toast */
.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 80; }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow); max-width: 360px; }
.toast.erro { background: var(--bad); color: #fff; }

/* ---------- Detalhes */
.dl { display: grid; grid-template-columns: 140px 1fr; gap: 6px 12px; margin: 0; }
.dl dt { color: var(--text-soft); font-size: 12.5px; }
.dl dd { margin: 0; word-break: break-word; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 10px 0; border-bottom: 1px solid var(--border); }
.timeline li:last-child { border-bottom: 0; }
.timeline .meta { font-size: 12px; color: var(--muted); }
.timeline .prox { font-size: 12.5px; margin-top: 4px; }
.lista-simples { list-style: none; margin: 0; padding: 0; }
.lista-simples li { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.lista-simples li:last-child { border-bottom: 0; }
.alerta { background: var(--warn-soft); color: var(--warn); padding: 10px 14px; border-radius: var(--radius); margin-bottom: 16px; display: flex; justify-content: space-between; align-items: center; gap: 12px; }

/* Barras simples (MRR / fluxo) */
.barras { display: flex; align-items: flex-end; gap: 10px; height: 150px; padding-top: 8px; }
.barras .col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; }
.barras .barra { width: 100%; max-width: 46px; background: var(--accent); border-radius: 4px 4px 0 0; min-height: 2px; }
.barras .rot { font-size: 11px; color: var(--muted); }
.barras .val { font-size: 10.5px; color: var(--text-soft); font-family: var(--mono); }
.fluxo-barras .par { display: flex; gap: 3px; align-items: flex-end; height: 100%; width: 100%; justify-content: center; }
.fluxo-barras .barra.entrada { background: var(--ok); max-width: 22px; }
.fluxo-barras .barra.saida { background: var(--bad); max-width: 22px; opacity: .8; }
.legenda { display: flex; gap: 14px; font-size: 12px; color: var(--text-soft); margin-top: 8px; }
.legenda i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }

/* ---------- Login */
.login-pagina { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-caixa { width: 100%; max-width: 360px; }
.login-caixa .marca { padding: 0 0 18px; text-align: center; font-size: 24px; }
.login-caixa form { display: grid; gap: 12px; }
