:root {
  --paper: #ffffff;
  --soft: #f7f5f0;
  --ink: #282824;
  --muted: #68675f;
  --line: #e4e0d6;
  --line-strong: #b6b0a4;
  --gold: #8d7450;
  --danger: #a3412f;
  --ok: #4f6b46;
  --sidebar: 232px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--soft);
  color: var(--ink);
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: 30px; font-weight: 300; letter-spacing: -.04em; }
h2 { font-size: 20px; font-weight: 400; letter-spacing: -.02em; }
h3 { font-size: 12px; font-weight: 500; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

/* ---------- login */
.login {
  min-height: 100vh; display: grid; place-items: center; padding: 24px; background: var(--paper);
}
.login-card { width: 100%; max-width: 360px; }
.login-card .logo { height: 54px; margin-bottom: 36px; overflow: hidden; }
.login-card .logo img { height: 64px; mix-blend-mode: multiply; filter: grayscale(1); margin-left: -16px; }
.login-card h1 { margin-bottom: 8px; }
.login-card > p { color: var(--muted); margin-bottom: 28px; }

/* ---------- layout */
.shell { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }
.sidebar {
  background: var(--paper); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 24px 18px; position: sticky; top: 0; height: 100vh;
}
.sidebar .brand { font-size: 30px; font-weight: 300; letter-spacing: -.06em; padding: 0 10px; }
.sidebar .brand small { display: block; font-size: 9px; letter-spacing: .2em; color: var(--gold); margin-top: 2px; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; margin-top: 36px; }
.sidebar nav a {
  text-decoration: none; padding: 10px; border-radius: 6px; color: var(--muted); display: flex; justify-content: space-between;
}
.sidebar nav a:hover { background: var(--soft); color: var(--ink); }
.sidebar nav a.active { background: var(--soft); color: var(--ink); font-weight: 500; }
.sidebar nav .badge { font-size: 11px; background: var(--gold); color: #fff; border-radius: 10px; padding: 1px 7px; }
.sidebar .me { margin-top: auto; border-top: 1px solid var(--line); padding: 16px 10px 0; }
.sidebar .me strong { display: block; font-weight: 500; }
.sidebar .me span { color: var(--muted); font-size: 12px; }
.sidebar .me .links { display: flex; gap: 14px; margin-top: 12px; }
.main { padding: 32px 40px 60px; min-width: 0; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.page-head p { color: var(--muted); margin-top: 6px; }
.topbar { display: none; }

/* ---------- elements */
.btn {
  display: inline-flex; align-items: center; gap: 10px; justify-content: center;
  background: var(--ink); color: #fff; border: 1px solid var(--ink); padding: 10px 16px; border-radius: 6px;
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: #4b493f; }
.btn.secondary { background: var(--paper); color: var(--ink); border-color: var(--line-strong); }
.btn.secondary:hover { background: var(--soft); }
.btn.danger { background: var(--paper); color: var(--danger); border-color: var(--danger); }
.btn[disabled] { opacity: .55; cursor: wait; }
.link { background: none; border: 0; padding: 0; cursor: pointer; color: var(--muted); text-decoration: underline; text-underline-offset: 3px; font-size: 12px; }
.link:hover { color: var(--ink); }
label, .label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.descricao-fixa { white-space: pre-wrap; line-height: 1.6; background: var(--soft); border: 1px solid var(--line); border-radius: 6px; padding: 12px 14px; }
input, select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line-strong); border-radius: 6px; background: var(--paper);
}
textarea { resize: vertical; line-height: 1.55; }
.field { margin-bottom: 16px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.card { background: var(--paper); border: 1px solid var(--line); border-radius: 10px; padding: 20px; }
.card + .card { margin-top: 16px; }
.card h3 { margin-bottom: 16px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--danger); font-size: 13px; margin-top: 10px; }
.empty { padding: 48px 20px; text-align: center; color: var(--muted); }

/* ---------- status */
.pill { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 12px; white-space: nowrap; border: 1px solid transparent; }
.st-nova_solicitacao { background: #fbf1df; color: #7a5a1f; border-color: #eedcb8; }
.st-em_conversa { background: #eef1f6; color: #3f5170; }
.st-proposta_enviada { background: #f2edf6; color: #5f4673; }
.st-aprovado { background: #eaf3ec; color: #3d6b47; }
.st-em_producao { background: #f4efe7; color: #6e5634; }
.st-entregue { background: #ecece8; color: #4f4f48; }
.st-cancelado { background: #f7ecea; color: #8e3f31; }

.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.tab {
  border: 1px solid var(--line); background: var(--paper); border-radius: 20px; padding: 6px 12px; cursor: pointer; color: var(--muted); font-size: 13px;
}
.tab b { font-weight: 500; color: var(--ink); margin-left: 4px; }
.tab.active { background: var(--ink); border-color: var(--ink); color: #fff; }
.tab.active b { color: #fff; }
.toolbar { display: flex; gap: 10px; margin-bottom: 14px; }
.toolbar input { max-width: 340px; }

table { width: 100%; border-collapse: collapse; background: var(--paper); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
th { text-align: left; font-size: 11px; font-weight: 500; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); padding: 12px 14px; border-bottom: 1px solid var(--line); background: #fcfbf8; }
td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover td { background: #fcfbf8; }
td .sub { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
.num { font-variant-numeric: tabular-nums; color: var(--muted); }

/* ---------- pedido */
.back { display: inline-block; color: var(--muted); text-decoration: none; margin-bottom: 14px; font-size: 13px; }
.back:hover { color: var(--ink); }
.detail { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(280px, 1fr); gap: 16px; align-items: start; }
.kv { display: grid; grid-template-columns: 90px 1fr; gap: 8px 12px; }
.kv dt { color: var(--muted); font-size: 12px; padding-top: 2px; }
.kv dd { margin: 0; word-break: break-word; }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { position: relative; padding: 0 0 16px 18px; border-left: 1px solid var(--line); margin-left: 4px; }
.timeline li:last-child { padding-bottom: 0; }
.timeline li::before { content: ''; position: absolute; left: -4px; top: 4px; width: 7px; height: 7px; border-radius: 50%; background: var(--gold); }
.timeline .when { font-size: 11px; color: var(--muted); }
.timeline .what { margin-top: 2px; }
.timeline .note { white-space: pre-wrap; background: var(--soft); border-radius: 6px; padding: 8px 10px; margin-top: 6px; }
.descricao { white-space: pre-wrap; line-height: 1.6; }
.save-row { display: flex; gap: 10px; align-items: center; justify-content: flex-end; }
.saved { color: var(--ok); font-size: 12px; }
.cliente-pick { position: relative; }
.sugestoes { position: absolute; z-index: 5; left: 0; right: 0; top: 100%; background: var(--paper); border: 1px solid var(--line-strong); border-radius: 6px; margin-top: 4px; max-height: 240px; overflow: auto; }
.sugestoes button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 10px 12px; cursor: pointer; }
.sugestoes button:hover { background: var(--soft); }
.cliente-escolhido { display: flex; justify-content: space-between; align-items: center; border: 1px solid var(--line-strong); border-radius: 6px; padding: 10px 12px; }

/* ---------- cliente (CRM) */
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--paper); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; }
.kpi span { display: block; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.kpi strong { display: block; font-size: 24px; font-weight: 300; letter-spacing: -.03em; margin-top: 6px; font-variant-numeric: tabular-nums; }
.kpi small { display: block; font-size: 11px; color: var(--muted); margin-top: 2px; }
.pedidos-cliente { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.pedidos-cliente a { display: block; text-decoration: none; border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; }
.pedidos-cliente a:hover { background: #fcfbf8; border-color: var(--line-strong); }
.pc-top { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.pc-title { margin-top: 6px; font-weight: 500; }
.pc-desc { color: var(--muted); margin-top: 4px; line-height: 1.5; }
.pc-meta { font-size: 12px; color: var(--muted); margin-top: 8px; }
.timeline .when a { color: var(--gold); text-decoration: none; font-weight: 500; }
@media (max-width: 760px) { .kpis { grid-template-columns: 1fr 1fr; } }

/* ---------- configurações */
.lista-emails { list-style: none; margin: 0 0 16px; padding: 0; border: 1px solid var(--line); border-radius: 8px; }
.lista-emails li { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--line); word-break: break-all; }
.lista-emails li:last-child { border-bottom: 0; }
.lista-emails li.vazio { color: var(--muted); }
.add-email { display: flex; gap: 10px; }
.add-email input { flex: 1; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- histórico */
.filtro-hist { margin: 4px 0 16px; }
.filtro-hist .tab { padding: 4px 10px; font-size: 12px; }
.timeline[data-f="andamento"] li:not(.h-andamento),
.timeline[data-f="notas"] li:not(.h-notas),
.timeline[data-f="alteracoes"] li:not(.h-alteracoes) { display: none; }
.timeline .what b { font-weight: 500; }
.timeline .de { color: var(--muted); text-decoration: line-through; text-decoration-color: var(--line-strong); }
.timeline .vazio { color: var(--muted); font-style: italic; text-decoration: none; }
.timeline .antes summary { font-size: 12px; color: var(--muted); cursor: pointer; margin-top: 6px; padding: 0; }
.timeline .antes summary::after { content: none; }
.timeline .antes .note { color: var(--muted); }

/* ---------- pedido: layout */
.topo-pedido { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(380px, 1fr); gap: 16px; margin-bottom: 16px; align-items: stretch; }
.topo-pedido .card + .card { margin-top: 0; }
.detail-pedido { grid-template-columns: minmax(0, 1.2fr) minmax(380px, 1fr); }

.andamento-meta { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.andamento-meta span { display: block; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin-bottom: 3px; }

/* ---------- valores e composição */
.valor-estimado { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 16px; padding: 2px 0 16px; border-bottom: 1px solid var(--line); }
.valor-estimado .label, .valor-estimado > div > label:first-child { margin-bottom: 2px; }
.valor-estimado strong { display: block; font-size: 28px; font-weight: 300; letter-spacing: -.035em; font-variant-numeric: tabular-nums; }
.valor-estimado strong.custo { color: var(--muted); }
.valor-estimado .ve-nota { grid-column: 1 / -1; display: block; font-size: 12px; color: var(--muted); margin-top: 4px; }
.secao-titulo { display: flex; align-items: baseline; gap: 8px; margin: 18px 0 8px; }
.secao-titulo span { font-size: 12px; font-weight: 500; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.secao-titulo small { font-size: 12px; color: var(--muted); }

.ghost { border: 1px solid transparent; background: transparent; border-radius: 6px; padding: 6px 8px; font-size: 14px; width: 100%; transition: border-color .15s, background .15s; }
.ghost:hover { border-color: var(--line); }
.ghost:focus { border-color: var(--gold); background: var(--paper); outline: none; }
.money { display: flex; align-items: center; gap: 2px; margin: 0; color: var(--muted); font-size: 12px; }
.money input { text-align: right; font-variant-numeric: tabular-nums; color: var(--ink); }
.money.grande { font-size: 16px; }
.money.grande input { font-size: 26px; font-weight: 300; letter-spacing: -.03em; text-align: left; padding: 2px 6px; border-color: var(--line); }

.comp-head, .comp-linha, .comp-total { display: grid; grid-template-columns: minmax(0, 1fr) 100px 100px 20px; gap: 4px; align-items: center; }
.comp-head { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); padding: 0 0 6px; border-bottom: 1px solid var(--line); }
.comp-head span:nth-child(2), .comp-head span:nth-child(3) { text-align: right; padding-right: 8px; }
.comp-linha { padding: 6px 0; border-bottom: 1px solid var(--line); row-gap: 0; }
.comp-linha .cat { font-weight: 500; appearance: none; -webkit-appearance: none; cursor: pointer; }
.comp-linha .desc { grid-column: 1 / 3; font-size: 13px; color: var(--muted); padding-top: 2px; padding-bottom: 2px; }
.comp-linha .desc:focus { color: var(--ink); }
.comp-linha .mk { grid-column: 3 / 4; text-align: right; font-size: 12px; color: var(--muted); padding-right: 8px; font-variant-numeric: tabular-nums; }
.comp-linha .remover { border: 0; background: none; color: var(--line-strong); cursor: pointer; font-size: 13px; padding: 0; }
.comp-linha .remover:hover { color: var(--danger); }
.comp-total { padding: 10px 0 0; font-weight: 500; font-variant-numeric: tabular-nums; }
.comp-total span:nth-child(2), .comp-total span:nth-child(3) { text-align: right; padding-right: 8px; }
.comp-vazia { color: var(--muted); padding: 10px 0 4px; border-top: 1px solid var(--line); }
.link-add { border: 0; background: none; color: var(--gold); cursor: pointer; padding: 12px 0 4px; font-weight: 500; }
.link-add:hover { text-decoration: underline; text-underline-offset: 3px; }
.link-add[disabled] { opacity: .6; cursor: wait; }
.indicadores { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.indicadores:empty { display: none; }
.indicadores > div { background: var(--soft); border-radius: 8px; padding: 12px 14px; }
.indicadores span { display: block; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.indicadores strong { display: block; font-size: 20px; font-weight: 300; margin-top: 4px; font-variant-numeric: tabular-nums; }
.indicadores small { font-size: 11px; color: var(--muted); }
.negativo { color: var(--danger); }

/* ---------- pagamento */
.card-titulo { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.card-titulo h3 { margin: 0; }
.situacao { font-size: 12px; padding: 3px 10px; border-radius: 20px; }
.situacao.pendente { background: #fbf1df; color: #7a5a1f; }
.situacao.parcial { background: #eef1f6; color: #3f5170; }
.situacao.quitado { background: #eaf3ec; color: #3d6b47; }
.pg-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.pg-grid.um { grid-template-columns: 1fr; }
.pg-linhas { border-top: 1px solid var(--line); }
.pg-linha { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.pg-linha .money { max-width: 170px; font-size: 13px; }
.pg-linha .money input { text-align: left; font-size: 16px; }
.pg-linha .saldo { display: block; font-size: 16px; font-weight: 400; padding: 6px 0 0; font-variant-numeric: tabular-nums; }
.check { display: inline-flex; align-items: center; gap: 6px; margin: 0; font-size: 13px; color: var(--ink); cursor: pointer; white-space: nowrap; }
.check input { width: auto; accent-color: var(--ok); }

/* ---------- dialog */
dialog { border: 0; border-radius: 12px; padding: 0; width: min(460px, calc(100vw - 32px)); box-shadow: 0 20px 60px rgba(0,0,0,.18); }
dialog::backdrop { background: rgba(40, 40, 36, .35); }
dialog form { padding: 24px; }
dialog h2 { margin-bottom: 18px; }
dialog .actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 8px; z-index: 50; font-size: 13px;
}
.toast.erro { background: var(--danger); }

/* ---------- responsive */
@media (max-width: 960px) {
  .detail { grid-template-columns: 1fr; }
  .main { padding: 24px 20px 60px; }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 20; left: 0; top: 0; width: 260px; transform: translateX(-100%); transition: transform .2s; box-shadow: 0 0 40px rgba(0,0,0,.15); }
  .sidebar.open { transform: none; }
  .topbar { display: flex; align-items: center; justify-content: space-between; padding: 14px 20px; background: var(--paper); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
  .topbar .brand { font-size: 24px; font-weight: 300; letter-spacing: -.06em; }
  .topbar button { background: none; border: 0; font-size: 13px; cursor: pointer; }
  .main { padding: 20px 16px 60px; }
  .grid-2 { grid-template-columns: 1fr; }
  .toolbar input { max-width: none; }
  table.responsive thead { display: none; }
  table.responsive, table.responsive tbody, table.responsive tr, table.responsive td { display: block; width: 100%; }
  table.responsive tr { border-bottom: 1px solid var(--line); padding: 10px 0; }
  table.responsive td { border: 0; padding: 4px 14px; }
  table.responsive td[data-label]::before { content: attr(data-label); display: block; font-size: 10px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
