/* Medidas da folha em pontos (pt), espelhando o layout do PDF em app.js.
   --u = 1pt no desktop (A4 em tamanho real); no celular vira px para ficar legível. */

@font-face { font-family: "Roboto PDF"; src: url("fonts/Roboto_400Regular.ttf") format("truetype"); font-weight: 400; font-display: block; }
@font-face { font-family: "Roboto PDF"; src: url("fonts/Roboto_500Medium.ttf") format("truetype"); font-weight: 500; font-display: block; }
@font-face { font-family: "Roboto PDF"; src: url("fonts/Roboto_700Bold.ttf") format("truetype"); font-weight: 700; font-display: block; }

:root {
  --u: 1pt;
  --ink: #1a1a1a;
  --text: #333333;
  --muted: #666666;
  --label: #555555;
  --sub: #444444;
  --line: #dcdcdc;
  --card-line: #e2e2e2;
  --head-body: #f5f5f5;
  --total-bg: #f3f3f3;
  --obs-bg: #fafafa;
  --obs-line: #c8c8c8;
  --foot-line: #e0e0e0;
  --shell: #e9e9e6;
  --focus: #e0a800;
  --edit-bg: #fff6d6;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--shell);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
button { font: inherit; cursor: pointer; }

/* ---------- Barra superior ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 20px; background: #fff; border-bottom: 1px solid #ddd;
}
.topbar__text { display: flex; flex-direction: column; gap: 2px; font-size: 14px; }
.topbar__text span { color: #666; font-size: 13px; }

.btn { border-radius: 8px; padding: 10px 16px; font-size: 14px; font-weight: 600; border: 1px solid transparent; }
.btn--ghost { background: #fff; border-color: #ccc; color: #333; }
.btn--ghost:hover { background: #f4f4f4; }
.btn--primary { background: var(--ink); color: #fff; padding: 12px 22px; }
.btn--primary:hover { background: #000; }
.btn:disabled { opacity: .5; cursor: progress; }
.btn:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ---------- Palco + folha A4 ---------- */
.stage { flex: 1; display: flex; justify-content: center; padding: 32px 16px 40px; }

.sheet {
  width: calc(var(--u) * 595.28);
  min-height: calc(var(--u) * 841.89);
  padding: calc(var(--u) * 51) calc(var(--u) * 52) calc(var(--u) * 34);
  background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.08), 0 8px 30px rgba(0,0,0,.08);
  display: flex; flex-direction: column;
  font-family: "Roboto PDF", Roboto, Arial, sans-serif;
  font-kerning: none;
  font-variant-ligatures: none;
  color: var(--text);
  overflow-wrap: anywhere;
}
.sheet.is-loading { opacity: .4; pointer-events: none; }

.content { flex: 1; display: flex; flex-direction: column; gap: calc(var(--u) * 14); }

/* Tipografia (mesmos valores do PDF) */
.t-headLabel  { font-size: calc(var(--u) * 8);    line-height: calc(var(--u) * 9.5);  font-weight: 700; color: #fff; letter-spacing: calc(var(--u) * .4); }
.t-headName   { font-size: calc(var(--u) * 9);    line-height: calc(var(--u) * 13);   font-weight: 700; color: var(--ink); }
.t-headDetail { font-size: calc(var(--u) * 9);    line-height: calc(var(--u) * 13);   font-weight: 400; color: var(--muted); }
.t-title      { font-size: calc(var(--u) * 17);   line-height: calc(var(--u) * 20);   font-weight: 700; color: var(--ink); }
.t-subtitle   { font-size: calc(var(--u) * 10);   line-height: calc(var(--u) * 12);   font-weight: 700; color: var(--sub); }
.t-secTitle   { font-size: calc(var(--u) * 9.5);  line-height: calc(var(--u) * 12);   font-weight: 700; color: var(--ink); letter-spacing: calc(var(--u) * .38); }
.t-body       { font-size: calc(var(--u) * 9);    line-height: calc(var(--u) * 14.25); font-weight: 400; color: var(--text); }
.t-totalLabel { font-size: calc(var(--u) * 7.5);  line-height: calc(var(--u) * 9);    font-weight: 500; color: var(--label); letter-spacing: calc(var(--u) * .45); }
.t-totalValue { font-size: calc(var(--u) * 15.5); line-height: calc(var(--u) * 18.5); font-weight: 700; color: var(--ink); }
.t-cardLabel  { font-size: calc(var(--u) * 8.5);  line-height: calc(var(--u) * 10.5); font-weight: 700; color: var(--ink); }
.t-cardValue  { font-size: calc(var(--u) * 10.5); line-height: calc(var(--u) * 12.5); font-weight: 700; color: var(--ink); }
.t-obs        { font-size: calc(var(--u) * 8);    line-height: calc(var(--u) * 12.6); font-weight: 400; color: var(--label); }
.t-foot       { font-size: calc(var(--u) * 8);    line-height: calc(var(--u) * 9.5);  font-weight: 400; color: var(--muted); }
.lead { font-weight: 700; color: var(--ink); }
.t-obs .lead { color: var(--label); }
p { margin: 0; }

/* Campos editáveis */
.ed { outline: 1px dashed transparent; outline-offset: 2px; border-radius: 2px; transition: outline-color .15s, background-color .15s; white-space: pre-wrap; cursor: text; }
.ed:hover { outline-color: rgba(0,0,0,.28); }
.ed:focus { outline: 2px solid var(--focus); background: var(--edit-bg); }
.t-headLabel.ed:hover { outline-color: rgba(255,255,255,.6); }
.t-headLabel.ed:focus { background: #333; }
span.ed { display: inline; }
.ed:empty::before { content: attr(data-ph); color: #aaa; font-weight: 400; }
input.ed {
  font: inherit; color: inherit; letter-spacing: inherit; background: transparent;
  border: 0; padding: 0; margin: 0; border-radius: 2px; min-width: 0;
}

/* Cabeçalho (Artista / Projeto) */
.head { display: grid; grid-template-columns: 1fr 1fr; border: calc(var(--u) * 1) solid var(--line); }
.head__label { background: var(--ink); padding: calc(var(--u) * 8.5) calc(var(--u) * 9) calc(var(--u) * 7.5); }
.head__body { background: var(--head-body); padding: calc(var(--u) * 9); display: flex; flex-direction: column; gap: calc(var(--u) * 2); }
.head__body--2 { border-left: calc(var(--u) * 1) solid var(--line); }

/* Título */
.title-block { display: flex; flex-direction: column; padding-top: calc(var(--u) * 5); gap: calc(var(--u) * 6); }
.title-block .rule { margin-top: calc(var(--u) * 2.5); height: calc(var(--u) * 2); background: var(--ink); }

/* Seções */
.sec { position: relative; display: flex; flex-direction: column; gap: calc(var(--u) * 6); }
.sec-title { display: flex; gap: calc(var(--u) * 7); align-items: stretch; }
.sec-title::before { content: ""; flex: none; width: calc(var(--u) * 2.5); background: var(--ink); }
.sec-title .ed { flex: 1; }
.paras { display: flex; flex-direction: column; gap: calc(var(--u) * 6); }
.paras .ed:empty { min-height: calc(var(--u) * 14.25); }

.sec-tools {
  position: absolute; top: -4px; right: 0; display: flex; gap: 4px;
  opacity: 0; transition: opacity .15s; z-index: 2;
}
.sec:hover .sec-tools, .sec:focus-within .sec-tools { opacity: 1; }
@media (hover: none) { .sec-tools { opacity: 1; } }
.tool {
  width: 26px; height: 26px; display: grid; place-items: center;
  background: #fff; border: 1px solid #d4d4d4; border-radius: 6px; color: #444; padding: 0;
}
.tool:hover { background: #f2f2f2; }
.tool--danger:hover { color: #b42318; border-color: #e7b4ae; background: #fff4f2; }
.tool svg { width: 14px; height: 14px; }
.tool:disabled { opacity: .35; cursor: default; }

.add-sec {
  align-self: flex-start; display: inline-flex; align-items: center; gap: 6px;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif; font-size: 12px; font-weight: 600;
  color: #555; background: transparent; border: 1px dashed #bdbdbd; border-radius: 6px; padding: 6px 12px;
}
.add-sec:hover { background: #f6f6f6; color: #222; border-color: #999; }

/* Valor total */
.total {
  background: var(--total-bg); border: calc(var(--u) * 1) solid var(--line); border-radius: calc(var(--u) * 4);
  padding: calc(var(--u) * 11.5) calc(var(--u) * 12); display: flex; flex-direction: column; gap: calc(var(--u) * 5);
}
.total input.ed { width: 100%; display: block; }

/* Parcelas */
.cards { display: flex; gap: calc(var(--u) * 9); }
.card {
  flex: 1 1 0; min-width: 0; background: #fff; border: calc(var(--u) * 1) solid var(--card-line); border-radius: calc(var(--u) * 3);
  padding: calc(var(--u) * 9) calc(var(--u) * 8); display: flex; flex-direction: column; gap: calc(var(--u) * 4);
}
.card input.pct { width: 2.15ch; font-variant-numeric: tabular-nums; }
.card .auto { color: var(--ink); }

/* Observação */
.obs {
  background: var(--obs-bg); border: calc(var(--u) * 1) dashed var(--obs-line); border-radius: calc(var(--u) * 3);
  padding: calc(var(--u) * 7.5) calc(var(--u) * 9);
}

/* Rodapé */
.foot {
  display: flex; justify-content: space-between; gap: calc(var(--u) * 12);
  border-top: calc(var(--u) * 1) solid var(--foot-line); padding-top: calc(var(--u) * 13); margin-top: calc(var(--u) * 12);
}

/* ---------- Barra inferior ---------- */
.bottombar {
  position: sticky; bottom: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 12px 20px calc(12px + env(safe-area-inset-bottom));
  background: #fff; border-top: 1px solid #ddd;
}
.meter { width: min(320px, 55%); display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: #555; }
.meter__label { display: flex; justify-content: space-between; gap: 8px; }
.meter__label strong { color: #222; font-variant-numeric: tabular-nums; }
.meter__track { height: 6px; border-radius: 3px; background: #eee; overflow: hidden; }
.meter__fill { height: 100%; width: 0; background: #2e7d32; transition: width .2s, background-color .2s; }
.meter.is-warn .meter__fill { background: #e0a800; }
.meter.is-full .meter__fill { background: #c62828; }

.toast {
  position: fixed; left: 50%; bottom: 96px; transform: translate(-50%, 12px);
  max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 8px;
  background: var(--ink); color: #fff; font-size: 14px; line-height: 1.4; text-align: center;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 20;
}
.toast.is-on { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Celular / telas estreitas ---------- */
@media (max-width: 840px) {
  :root { --u: 1.6px; }
  .topbar { padding: 10px 16px; }
  .topbar .btn { padding: 8px 12px; font-size: 13px; white-space: nowrap; }
  .topbar__text span { font-size: 12px; }
  .sec:not(.sec--fixed) .sec-title { padding-right: 104px; }
  .stage { padding: 12px 8px 24px; }
  .sheet { width: 100%; min-height: 0; padding: 22px 16px 18px; }
  .head { grid-template-columns: 1fr; }
  .head__label--1 { order: 1; } .head__body--1 { order: 2; }
  .head__label--2 { order: 3; } .head__body--2 { order: 4; border-left: 0; }
  .cards { flex-direction: column; }
  .foot { flex-wrap: wrap; gap: 4px 12px; }
  .bottombar { padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); }
  .meter { width: auto; flex: 1; }
  .btn--primary { padding: 12px 18px; }
  .tool { width: 30px; height: 30px; }
  .sec-tools { top: -6px; }
}
