:root {
  --red: #E31B3C;
  --red-dark: #B81530;
  --ink: #17140F;
  --muted: #6E6A64;
  --line: #E8E4DE;
  --bg: #F6F4F1;
  --surface: #FFFFFF;
  --soft: #FBE9ED;
  --green: #25D366;
  --green-dark: #1AAB52;
  --radius: 12px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: 'Plus Jakarta Sans', system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
}
body.locked { visibility: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 16px;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-size: 15px; white-space: nowrap; }
.brand strong { color: var(--red); }
.actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.user { color: var(--muted); font-size: 12px; margin-right: 4px; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 0; border-radius: 8px; padding: 9px 14px;
  background: var(--red); color: #fff; font-weight: 600; cursor: pointer;
  min-height: 38px;
}
.btn:hover { background: var(--red-dark); }
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn.ghost:hover { background: var(--bg); }
.btn.wa { background: var(--green); }
.btn.wa:hover { background: var(--green-dark); }
.btn[disabled] { opacity: .6; cursor: progress; }
.btn.block { width: 100%; justify-content: center; }

.tabs { display: none; background: var(--bg); border-radius: 8px; padding: 3px; }
.tab { border: 0; background: transparent; padding: 6px 12px; border-radius: 6px; cursor: pointer; font-weight: 600; color: var(--muted); }
.tab.active { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }

/* ---------- Layout ---------- */
.layout {
  display: grid;
  grid-template-columns: minmax(380px, 520px) 1fr;
  gap: 20px;
  padding: 20px;
  align-items: start;
}
.editor { display: flex; flex-direction: column; gap: 14px; }
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.card h2 { margin: 0 0 12px; font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--red); }
.hint { margin: -6px 0 12px; color: var(--muted); font-size: 12px; }

.grid { display: grid; gap: 10px 12px; }
.g2 { grid-template-columns: 1fr 1fr; }
.g3 { grid-template-columns: repeat(3, 1fr); }
.span2 { grid-column: span 2; }

label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; font-weight: 600; color: var(--muted); }
label em { color: var(--red); font-style: normal; }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 10px; background: var(--surface);
  font-size: 14px; font-weight: 500; color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(227,27,60,.25); border-color: var(--red); }
input.invalid { border-color: var(--red); background: var(--soft); }
textarea { resize: vertical; }
.inline { display: flex; gap: 6px; }
.inline select { width: 72px; flex: none; }

/* ---------- Sistemas ---------- */
.sys { border: 1px solid var(--line); border-radius: 10px; margin-bottom: 10px; overflow: hidden; }
.sys:last-child { margin-bottom: 0; }
.sys-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px; cursor: pointer; font-weight: 700; font-size: 15px; color: var(--ink); flex-direction: row; }
.sys-head input { width: 18px; height: 18px; accent-color: var(--red); flex: none; }
.sys.on { border-color: var(--red); }
.sys.on .sys-head { background: var(--soft); }
.sys-body { display: none; padding: 14px; border-top: 1px solid var(--line); }
.sys.on .sys-body { display: block; }
.sys-body .grid { margin-bottom: 12px; }
.sub { font-size: 12px; font-weight: 700; color: var(--muted); margin: 4px 0 6px; text-transform: uppercase; letter-spacing: .06em; }
.extra { display: grid; grid-template-columns: 18px 1fr 110px; gap: 8px; align-items: center; padding: 5px 0; font-weight: 500; color: var(--ink); font-size: 13px; }
.extra input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--red); }
.extra input[type=number] { padding: 6px 8px; font-size: 13px; }
.plan-info { font-size: 12px; color: var(--muted); margin: -4px 0 10px; }

/* ---------- Preview ---------- */
.preview-pane { position: sticky; top: 78px; }
.preview-scale { transform-origin: top left; }
.preview-scale .page { box-shadow: 0 8px 30px rgba(0,0,0,.10); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 8px;
  font-size: 13px; opacity: 0; pointer-events: none; transition: .2s; max-width: calc(100% - 32px);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Responsivo ---------- */
@media (max-width: 960px) {
  .topbar { flex-wrap: wrap; padding: 10px 16px; }
  .tabs { display: flex; }
  .actions { width: 100%; margin-left: 0; }
  .actions .btn { flex: 1; justify-content: center; }
  .user { width: 100%; }
  .layout { grid-template-columns: 1fr; padding: 16px; }
  .layout[data-view=editor] .preview-pane { display: none; }
  .layout[data-view=preview] .editor { display: none; }
  .preview-pane { position: static; }
}
@media (max-width: 520px) {
  .g2, .g3 { grid-template-columns: 1fr; }
  .span2 { grid-column: auto; }
  .extra { grid-template-columns: 18px 1fr 90px; }
}

/* =====================================================================
   DOCUMENTO DA PROPOSTA (A4 = 794px de largura a 96dpi)
   ===================================================================== */
.page {
  width: 794px; min-height: 1123px;
  background: #fff; color: #1d1b18;
  padding: 44px 56px 40px;
  font-size: 12.5px; line-height: 1.5;
}
.page.exporting { min-height: 0; box-shadow: none; }
.p-head { display: flex; justify-content: space-between; align-items: flex-start; border-bottom: 3px solid var(--red); padding-bottom: 18px; margin-bottom: 22px; }
.p-logo { display: flex; align-items: center; gap: 10px; }
.p-logo img { width: 44px; height: 44px; }
.p-logo b { font-size: 26px; font-weight: 800; letter-spacing: -.02em; }
.p-meta { text-align: right; font-size: 11.5px; color: #6e6a64; }
.p-meta h1 { margin: 0 0 4px; font-size: 20px; color: #1d1b18; letter-spacing: -.01em; }
.p-meta strong { color: #1d1b18; }

.p-block { margin-bottom: 20px; break-inside: avoid; page-break-inside: avoid; }
.p-label { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .1em; color: var(--red); margin-bottom: 8px; }
.p-client { background: #f6f4f1; border-radius: 10px; padding: 14px 16px; display: grid; grid-template-columns: 1fr 1fr; gap: 4px 20px; }
.p-client .name { grid-column: span 2; font-size: 16px; font-weight: 800; margin-bottom: 2px; }
.p-client span { color: #6e6a64; }

.p-sys { border: 1px solid #e8e4de; border-radius: 10px; padding: 14px 16px; }
.p-sys-top { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.p-sys h3 { margin: 0; font-size: 17px; }
.p-sys h3 small { font-size: 12px; font-weight: 600; color: var(--red); margin-left: 6px; }
.p-sys .tag { font-size: 11px; background: #fbe9ed; color: var(--red-dark); padding: 2px 8px; border-radius: 99px; font-weight: 700; white-space: nowrap; }
.p-sys p { margin: 4px 0 10px; color: #6e6a64; }
.p-feats { list-style: none; padding: 0; margin: 0; columns: 3; column-gap: 16px; }
.p-feats li { padding: 2px 0 2px 18px; position: relative; break-inside: avoid; }
.p-feats li::before { content: ''; position: absolute; left: 0; top: 7px; width: 10px; height: 6px; border-left: 2px solid var(--red); border-bottom: 2px solid var(--red); transform: rotate(-45deg); }
.p-extras { margin-top: 10px; padding-top: 8px; border-top: 1px dashed #e8e4de; }
.p-extras b { font-size: 11px; color: #6e6a64; text-transform: uppercase; letter-spacing: .06em; }

table.p-table { width: 100%; border-collapse: collapse; }
.p-table th { text-align: left; font-size: 10.5px; text-transform: uppercase; letter-spacing: .06em; color: #6e6a64; padding: 6px 0; border-bottom: 1px solid #e8e4de; }
.p-table td { padding: 7px 0; border-bottom: 1px solid #f0ede8; }
.p-table td.num, .p-table th.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.p-table tr.sub td { padding-left: 14px; color: #6e6a64; }
.p-table tr.disc td { color: var(--red-dark); }
.p-table tr.total td { border-bottom: 0; padding-top: 10px; font-size: 15px; font-weight: 800; }
.p-table tr.total td.num { color: var(--red); font-size: 18px; }
.p-table tr.once td { font-weight: 600; }

.p-two { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.p-list { margin: 0; padding-left: 16px; }
.p-obs { white-space: pre-wrap; background: #f6f4f1; border-radius: 8px; padding: 10px 12px; }

.p-sign { display: grid; grid-template-columns: 1fr 1fr; gap: 40px; margin-top: 34px; }
.p-sign div { border-top: 1px solid #1d1b18; padding-top: 6px; font-size: 11.5px; }
.p-sign span { color: #6e6a64; }
.p-foot { margin-top: 26px; font-size: 10.5px; color: #9a958e; text-align: center; }
.p-empty { color: #9a958e; text-align: center; padding: 30px 0; border: 1px dashed #e8e4de; border-radius: 10px; }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login {
  width: 100%; max-width: 380px; background: var(--surface);
  border: 1px solid var(--line); border-radius: 16px; padding: 32px 28px;
  display: flex; flex-direction: column; gap: 14px;
}
.login[hidden] { display: none; }
.login .brand { justify-content: center; font-size: 18px; margin-bottom: 6px; }
.login .err { color: var(--red-dark); background: var(--soft); border-radius: 8px; padding: 8px 10px; font-size: 13px; display: none; }
.login .err.show { display: block; }
.login .link { background: none; border: 0; color: var(--muted); font-size: 12px; cursor: pointer; text-decoration: underline; }
