:root {
  --bg: #F3F4F7;
  --card: #FFFFFF;
  --ink: #141B2D;
  --ink2: #475067;
  --mute: #7B8497;
  --line: #E2E5EC;
  --line2: #CDD2DC;
  --soft: #F7F8FA;
  --navy: #141B2D;
  --navy2: #1E2740;
  --accent: #F2B705;
  --primary: #1D4ED8;
  --primary-ink: #fff;
  --ok: #137A4B;
  --ok-bg: #E7F6EE;
  --warn: #9A5B00;
  --warn-bg: #FFF4DC;
  --bad: #B42318;
  --bad-bg: #FDECEA;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 27, 45, .06), 0 4px 14px rgba(20, 27, 45, .05);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 400 14px/1.5 Inter, "Segoe UI", system-ui, -apple-system, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); }
h1, h2, h3 { margin: 0; letter-spacing: -.01em; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ---------- Botões ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  min-height: 38px; padding: 8px 14px; border-radius: 8px;
  border: 1px solid var(--line2); background: var(--card); color: var(--ink);
  font-weight: 600; font-size: 13.5px; cursor: pointer; white-space: nowrap; text-decoration: none;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { background: var(--soft); border-color: #B9C0CD; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; flex: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn-primary:hover { background: #1A43BD; border-color: #1A43BD; }
.btn-dark { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn-dark:hover { background: var(--navy2); border-color: var(--navy2); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--ink2); }
.btn-ghost:hover { background: rgba(20, 27, 45, .05); border-color: transparent; }
.btn-danger { color: var(--bad); }
.btn-danger:hover { background: var(--bad-bg); border-color: #F3B7B1; }
.btn-wa { background: #128C4A; border-color: #128C4A; color: #fff; }
.btn-wa:hover { background: #0F7A40; border-color: #0F7A40; }
.btn-sm { min-height: 32px; padding: 5px 10px; font-size: 13px; }
.btn-block { width: 100%; }
.icon-btn { display: inline-grid; place-items: center; width: 36px; height: 36px; border: 0; border-radius: 8px; background: transparent; color: var(--ink2); cursor: pointer; }
.icon-btn:hover { background: rgba(20, 27, 45, .06); color: var(--ink); }
.icon-btn svg { width: 18px; height: 18px; }

/* ---------- Formulários ---------- */
label, .fld { display: block; font-size: 12.5px; font-weight: 600; color: var(--ink2); min-width: 0; }
label > input, label > select, label > textarea, label > div, .fld > div + div { margin-top: 5px; }
.fld > .fld-h + .days { margin-top: 5px; }
label .hint { font-weight: 400; color: var(--mute); }
input, select, textarea {
  width: 100%; min-height: 38px; padding: 8px 10px;
  border: 1px solid var(--line2); border-radius: 8px; background: #fff;
  font-size: 14px; font-weight: 400; color: var(--ink);
}
textarea { min-height: 80px; resize: vertical; line-height: 1.45; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(29, 78, 216, .15); }
input[readonly] { background: var(--soft); color: var(--ink2); }
input.invalid { border-color: var(--bad); box-shadow: 0 0 0 3px rgba(180, 35, 24, .12); }
input[type=checkbox] { width: 18px; height: 18px; min-height: 0; accent-color: var(--primary); margin: 0; }
input[type=color] { display: block; padding: 3px; width: 54px; height: 38px; cursor: pointer; }
.check { display: flex; flex-direction: row; align-items: center; gap: 8px; font-weight: 500; color: var(--ink); cursor: pointer; }
.grid { display: grid; gap: 12px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span2 { grid-column: span 2; }
.span3 { grid-column: span 3; }
.span-all { grid-column: 1 / -1; }
.money-in { position: relative; }
.money-in::before { content: "R$"; position: absolute; left: 10px; bottom: 10px; font-size: 13px; color: var(--mute); pointer-events: none; }
.money-in input { padding-left: 32px; }
.pct-in { position: relative; }
.pct-in::after { content: "%"; position: absolute; right: 10px; bottom: 10px; font-size: 13px; color: var(--mute); pointer-events: none; }
.pct-in input { padding-right: 26px; }

/* ---------- Login ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; background: radial-gradient(1200px 600px at 80% -10%, #25305A 0%, var(--navy) 55%); }
.auth-card { width: 100%; max-width: 410px; background: #fff; border-radius: 16px; padding: 28px; box-shadow: 0 20px 60px rgba(0, 0, 0, .35); }
.auth-brand { display: flex; gap: 14px; align-items: center; margin-bottom: 22px; }
.auth-brand h1 { font-size: 20px; }
.auth-brand p { margin: 2px 0 0; color: var(--mute); font-size: 12.5px; }
.auth-help { margin: 0 0 16px; color: var(--ink2); font-size: 13.5px; }
.auth form { display: grid; gap: 14px; }
.auth-err { margin: 0; min-height: 1.2em; color: var(--bad); font-size: 13px; font-weight: 500; }
.auth-foot { margin: 6px 0 0; text-align: center; color: var(--mute); font-size: 12.5px; }

/* ---------- Layout ---------- */
.app { display: flex; min-height: 100vh; }
.side { position: sticky; top: 0; height: 100vh; width: 236px; flex: none; display: flex; flex-direction: column; background: var(--navy); color: #C9CFDB; padding: 16px 12px; z-index: 30; }
.side-brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; color: #fff; }
.side-brand b { display: block; font-size: 15px; }
.side-brand span { display: block; font-size: 11.5px; color: #8E97AB; line-height: 1.3; }
.side-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.side-nav .sep { margin: 14px 10px 6px; font-size: 10.5px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: #6B7590; }
.side-nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; color: #C9CFDB; text-decoration: none; font-weight: 500; }
.side-nav a svg { width: 18px; height: 18px; flex: none; opacity: .85; }
.side-nav a:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.side-nav a.on { background: rgba(255, 255, 255, .1); color: #fff; box-shadow: inset 3px 0 0 var(--accent); }
.side-nav a.cta { margin-bottom: 8px; background: var(--accent); color: var(--navy); font-weight: 700; justify-content: center; }
.side-nav a.cta:hover { background: #FFC62B; }
.side-user { border-top: 1px solid rgba(255, 255, 255, .08); padding: 12px 8px 0; font-size: 12.5px; }
.side-user b { display: block; color: #fff; font-size: 13.5px; }
.side-user span { color: #8E97AB; }
.side-user .row { display: flex; gap: 6px; margin-top: 8px; }
.side-user button { flex: 1; background: rgba(255, 255, 255, .06); border: 0; color: #C9CFDB; border-radius: 6px; padding: 6px; cursor: pointer; font-size: 12px; }
.side-user button:hover { background: rgba(255, 255, 255, .12); color: #fff; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px; min-height: 62px; padding: 10px 24px; background: rgba(243, 244, 247, .92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.topbar h1 { font-size: 18px; font-weight: 700; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.menu-btn { display: none; }
.view { padding: 22px 24px 80px; max-width: 1360px; width: 100%; }
.view:focus { outline: none; }

/* ---------- Cards ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-h { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.card-h h2 { font-size: 15px; font-weight: 700; flex: 1; display: flex; align-items: center; gap: 8px; }
.card-h h2 .n { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 6px; background: var(--navy); color: #fff; font-size: 12px; }
.card-h p { margin: 0; color: var(--mute); font-size: 12.5px; }
.card-b { padding: 16px 18px; }
.stack { display: grid; gap: 16px; }
.stack > *, .grid > * { min-width: 0; }
.muted { color: var(--mute); }
.small { font-size: 12.5px; }

/* ---------- Editor ---------- */
.editor { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 20px; align-items: start; }
.summary { position: sticky; top: 80px; }
.sum-total { padding: 18px; background: var(--navy); color: #fff; border-radius: var(--radius) var(--radius) 0 0; }
.sum-total span { font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: #A9B1C4; }
.sum-total strong { display: block; font-size: 28px; font-weight: 800; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.sum-total em { font-style: normal; color: #C9CFDB; font-size: 12.5px; }
.sum-rows { padding: 10px 18px; }
.sum-row { display: flex; justify-content: space-between; gap: 10px; padding: 6px 0; border-bottom: 1px dashed var(--line); font-variant-numeric: tabular-nums; font-size: 13.5px; }
.sum-row:last-child { border-bottom: 0; }
.sum-row span { color: var(--ink2); }
.sum-row .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: 1px; }
.sum-row.good b { color: var(--ok); }
.sum-actions { display: grid; gap: 8px; padding: 14px 18px 18px; border-top: 1px solid var(--line); }
.sum-actions .row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.meter { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; margin-top: 4px; }
.meter i { display: block; height: 100%; background: var(--ok); border-radius: 3px; transition: width .2s; }
.meter.hot i { background: #D98E04; }

.add-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.add-bar .lbl { font-size: 12.5px; font-weight: 600; color: var(--ink2); margin-right: 4px; }
.radio-btn { display: inline-flex; align-items: center; gap: 8px; min-height: 38px; padding: 7px 12px; border: 1px solid var(--line2); border-radius: 8px; background: #fff; cursor: pointer; font-weight: 600; font-size: 13.5px; }
.radio-btn:hover { border-color: var(--rc, var(--ink)); background: var(--soft); }
.radio-btn i { width: 10px; height: 10px; border-radius: 50%; background: var(--rc, var(--ink)); }
.radio-btn small { color: var(--mute); font-weight: 500; }

.items { display: grid; gap: 12px; }
.item { border: 1px solid var(--line); border-left: 4px solid var(--rc, var(--ink)); border-radius: 8px; background: #fff; }
.item-h { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--line); background: var(--soft); border-radius: 0 8px 0 0; flex-wrap: wrap; }
.item-h .rname { font-weight: 700; font-size: 13px; color: var(--rc, var(--ink)); white-space: nowrap; }
.item-h select { width: auto; min-width: 200px; flex: 1; font-weight: 600; }
.item-h .tools { display: flex; gap: 2px; margin-left: auto; }
.item-b { padding: 12px; display: grid; gap: 12px; }
.item-calc { display: flex; flex-wrap: wrap; gap: 6px 16px; align-items: center; padding: 8px 10px; background: var(--soft); border-radius: 6px; font-size: 13px; color: var(--ink2); font-variant-numeric: tabular-nums; }
.item-calc b { color: var(--ink); }
.item-calc .tot { margin-left: auto; font-size: 15px; }
.item-calc .tot b { font-size: 16px; }
.lim { font-size: 11.5px; font-weight: 600; padding: 2px 7px; border-radius: 99px; background: var(--ok-bg); color: var(--ok); white-space: nowrap; }
.lim.hot { background: var(--warn-bg); color: var(--warn); }
.lim.over { background: var(--bad-bg); color: var(--bad); }
.days { display: flex; gap: 4px; flex-wrap: wrap; }
.days button { min-width: 42px; height: 38px; padding: 0 6px; border: 1px solid var(--line2); border-radius: 7px; background: #fff; font-size: 12.5px; font-weight: 600; color: var(--ink2); cursor: pointer; }
.days button.on { background: var(--navy); border-color: var(--navy); color: #fff; }
.fld-h { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.presets { display: flex; gap: 2px; }
.preset { border: 0; background: none; padding: 0 6px; font-size: 12px; font-weight: 600; color: var(--primary); cursor: pointer; border-radius: 4px; }
.preset:hover { background: #EEF3FF; }
.empty { padding: 28px 16px; text-align: center; color: var(--mute); border: 1px dashed var(--line2); border-radius: 8px; }
.empty b { display: block; color: var(--ink2); margin-bottom: 4px; }

/* ---------- Tabelas ---------- */
.tbl-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl th { text-align: left; font-size: 11.5px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--mute); padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; background: var(--soft); }
.tbl td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tbody tr:hover td { background: #FAFBFC; }
.tbl .n { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tbl .acts { white-space: nowrap; text-align: right; }
.tbl input, .tbl select { min-height: 34px; padding: 6px 8px; font-size: 13.5px; }
.tbl .money-in::before { bottom: 8px; }
.tbl .pct-in::after { bottom: 8px; }
.tbl .money-in input { padding-left: 30px; }
.tbl .pct-in input { padding-right: 24px; }
.tbl select[data-pk="calc"] { min-width: 132px; }
.tbl td:first-child a { white-space: nowrap; }
.client-cell b { display: block; }
.client-cell span { color: var(--mute); font-size: 12.5px; }
.chips { display: flex; gap: 4px; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 99px; background: var(--soft); border: 1px solid var(--line); font-size: 11.5px; font-weight: 600; color: var(--ink2); white-space: nowrap; }
.chip i { width: 7px; height: 7px; border-radius: 50%; background: var(--rc, var(--ink)); }

.st { display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.st::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.st-rascunho { background: #EEF0F4; color: #5B6478; }
.st-enviado { background: #E6EEFE; color: #1D4ED8; }
.st-negociacao { background: var(--warn-bg); color: var(--warn); }
.st-aprovado { background: var(--ok-bg); color: var(--ok); }
.st-recusado { background: var(--bad-bg); color: var(--bad); }
.st-expirado { background: #F1EDF8; color: #6B4BA1; }
select.st-select { width: auto; min-height: 30px; padding: 3px 26px 3px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; border: 0; cursor: pointer; }

.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { padding: 14px 16px; }
.kpi span { font-size: 12px; color: var(--mute); font-weight: 600; }
.kpi b { display: block; font-size: 22px; font-weight: 800; letter-spacing: -.02em; font-variant-numeric: tabular-nums; margin-top: 2px; }
.kpi em { font-style: normal; font-size: 12px; color: var(--mute); }
.filters { display: flex; gap: 8px; flex-wrap: wrap; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.filters input { flex: 1; min-width: 200px; }
.filters select { width: auto; min-width: 150px; }
.seen { font-size: 11.5px; color: var(--ok); font-weight: 600; }

/* ---------- Config ---------- */
.radio-cfg { display: grid; grid-template-columns: 120px minmax(0, 1fr); gap: 16px; padding: 14px; border: 1px solid var(--line); border-left: 4px solid var(--rc); border-radius: 8px; }
.logo-box { display: grid; place-items: center; width: 120px; height: 84px; border: 1px dashed var(--line2); border-radius: 8px; background: var(--soft); overflow: hidden; text-align: center; font-size: 11.5px; color: var(--mute); padding: 6px; }
.logo-box img { max-width: 100%; max-height: 100%; object-fit: contain; }
.logo-acts { display: flex; gap: 4px; margin-top: 6px; justify-content: center; }
.modelos { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.modelo-opt { display: inline-flex; align-items: center; gap: 8px; padding: 8px 14px; border: 1px solid var(--line2); border-radius: 8px; cursor: pointer; font-weight: 600; color: var(--ink); }
.modelo-opt input { width: 16px; height: 16px; min-height: 0; margin: 0; accent-color: var(--primary); }
.modelo-opt.on { border-color: var(--primary); background: #EEF3FF; }
.note { padding: 10px 12px; border-radius: 8px; background: #EEF3FF; color: #1E3A8A; font-size: 13px; }
.note.warn { background: var(--warn-bg); color: var(--warn); }

/* ---------- Modal e toast ---------- */
.modal { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 16px; background: rgba(12, 16, 28, .55); backdrop-filter: blur(2px); }
.modal-card { width: 100%; max-width: 520px; max-height: calc(100vh - 32px); overflow: auto; background: #fff; border-radius: 14px; box-shadow: 0 24px 60px rgba(0, 0, 0, .3); }
.modal.wide .modal-card { max-width: 980px; background: #E9ECF1; }
.modal-h { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; gap: 8px; padding: 14px 18px; background: #fff; border-bottom: 1px solid var(--line); }
.modal-h h3 { flex: 1; font-size: 16px; }
.modal-b { padding: 18px; }
.modal-f { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 18px; border-top: 1px solid var(--line); background: #fff; }
.modal .pp { box-shadow: none; margin: 18px auto; }

.toast-wrap { position: fixed; right: 16px; bottom: 16px; z-index: 200; display: grid; gap: 8px; max-width: min(420px, calc(100vw - 32px)); }
.toast { padding: 12px 14px; border-radius: 10px; background: var(--navy); color: #fff; box-shadow: 0 10px 30px rgba(0, 0, 0, .25); font-size: 13.5px; white-space: pre-line; animation: tin .2s ease-out; }
.toast.err { background: var(--bad); }
.toast.ok { background: #0F6B41; }
@keyframes tin { from { opacity: 0; transform: translateY(8px); } }

.loading { padding: 60px 0; text-align: center; color: var(--mute); }

/* ---------- Responsivo ---------- */
@media (max-width: 1120px) {
  .editor { grid-template-columns: minmax(0, 1fr); }
  .summary { position: static; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
  .side { position: fixed; left: 0; top: 0; transform: translateX(-100%); transition: transform .2s; box-shadow: 0 0 40px rgba(0, 0, 0, .4); }
  .side.open { transform: none; }
  .menu-btn { display: inline-grid; }
  .topbar { padding: 10px 16px; }
  .view { padding: 16px 16px 80px; }
  .g3, .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .topbar-actions .btn span { display: none; }
}
@media (max-width: 560px) {
  .g2, .g3, .g4 { grid-template-columns: minmax(0, 1fr); }
  .span2, .span3 { grid-column: auto; }
  .kpis { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .kpi b { font-size: 18px; }
  .radio-cfg { grid-template-columns: minmax(0, 1fr); }
  .item-h select { min-width: 0; width: 100%; }
  .item-calc .tot { margin-left: 0; width: 100%; }
  .card-h, .card-b { padding-left: 14px; padding-right: 14px; }
}
