:root {
  --fundo: #eef0f3;
  --superficie: #ffffff;
  --texto: #1c2430;
  --texto-2: #5b6573;
  --borda: #d5dae1;
  --pri: #1f4e8c;
  --pri-texto: #ffffff;
  --perigo: #b42318;
  --sombra: 0 1px 3px rgba(16, 24, 40, .12), 0 4px 12px rgba(16, 24, 40, .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --fundo: #14181e; --superficie: #1e242c; --texto: #e7ebf0; --texto-2: #9aa4b1;
    --borda: #343c47; --pri: #5b8fd6; --pri-texto: #0d1420; --perigo: #f97066;
    --sombra: 0 1px 3px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --fundo: #14181e; --superficie: #1e242c; --texto: #e7ebf0; --texto-2: #9aa4b1;
  --borda: #343c47; --pri: #5b8fd6; --pri-texto: #0d1420; --perigo: #f97066;
  --sombra: 0 1px 3px rgba(0, 0, 0, .5);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--fundo); color: var(--texto);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; }

.barra {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(8px + env(safe-area-inset-top)) 16px 8px;
  background: var(--superficie); border-bottom: 1px solid var(--borda);
}
.marca { display: flex; align-items: center; gap: 8px; font-weight: 650; }
.marca img { width: 28px; height: 28px; border-radius: 7px; }
.botoes { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }

.bt {
  border: 1px solid var(--borda); background: var(--superficie);
  border-radius: 10px; padding: 8px 12px; cursor: pointer; font-size: 15px;
}
.bt:hover { border-color: var(--texto-2); }
.bt.pri { background: var(--pri); color: var(--pri-texto); border-color: var(--pri); font-weight: 600; }
.bt.grande { padding: 14px 20px; font-size: 17px; }
.bt:disabled { opacity: .5; cursor: default; }

.inicio { max-width: 520px; margin: 48px auto; padding: 0 16px; text-align: center; }
.inicio-icone { width: 72px; height: 72px; border-radius: 18px; box-shadow: var(--sombra); }
.inicio h1 { font-size: 26px; margin: 16px 0 8px; }
.inicio p { color: var(--texto-2); }
.inicio-botoes { display: flex; flex-direction: column; gap: 10px; margin: 24px 0; }
.nota { font-size: 14px; }

.documento { padding: 16px 12px 110px; }
.pagina {
  position: relative; width: min(100%, 900px); margin: 0 auto 16px;
  background: #fff; box-shadow: var(--sombra);
}
.pagina canvas { display: block; width: 100%; height: 100%; }
.camada { position: absolute; inset: 0; }
.num {
  position: absolute; right: 6px; bottom: 6px; font-size: 12px;
  background: rgba(0, 0, 0, .55); color: #fff; padding: 1px 7px; border-radius: 8px;
  pointer-events: none;
}

.item { position: absolute; touch-action: none; cursor: move; outline: 1.5px dashed transparent; }
.item img { display: block; width: 100%; pointer-events: none; user-select: none; -webkit-user-drag: none; }
.item.sel { outline-color: #1f4e8c; background: rgba(31, 78, 140, .06); }
.item .alca {
  display: none; position: absolute; right: -15px; bottom: -15px; width: 30px; height: 30px;
  border-radius: 50%; background: #1f4e8c; border: 3px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.4);
  cursor: nwse-resize; touch-action: none;
}
.item .acoes {
  display: none; position: absolute; bottom: 100%; left: 50%; transform: translate(-50%, -10px);
  gap: 4px; padding: 4px; background: #1c2430; border-radius: 10px; white-space: nowrap; z-index: 5;
}
.item .acoes button {
  border: 0; background: transparent; color: #fff; padding: 6px 10px; border-radius: 7px; cursor: pointer; font-size: 14px;
}
.item .acoes button:hover { background: rgba(255, 255, 255, .14); }
.item.sel .alca { display: block; }
.item.sel .acoes { display: flex; }

/* texto editável */
.item.texto { cursor: text; touch-action: auto; line-height: 1.2; white-space: pre; padding: 0; }
.item.texto .txt { outline: none; min-width: 1ch; min-height: 1.2em; white-space: pre; caret-color: #1f4e8c; }
.item.texto.sel { outline-offset: 2px; background: rgba(31, 78, 140, .05); }
.item.texto .sonda { position: absolute; left: 0; top: 0; visibility: hidden; pointer-events: none; white-space: pre; }
.item.texto .sonda i { display: inline-block; width: 0; height: 0; vertical-align: baseline; }
.item .mover {
  display: none; position: absolute; left: -2px; top: 100%; margin-top: 6px; width: 30px; height: 30px; padding: 0;
  border-radius: 50%; border: 3px solid #fff; background: #1f4e8c; color: #fff; font: 15px/1 system-ui, sans-serif;
  box-shadow: 0 1px 4px rgba(0,0,0,.4); cursor: move; touch-action: none;
}
.item.sel .mover { display: block; }
.item .acoes { font: 14px/1.2 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: #fff; font-style: normal; font-weight: 400; }
.item .acoes .cor { display: inline-grid; place-items: center; padding: 0 6px; cursor: pointer; }
.item .acoes .cor input { width: 26px; height: 22px; border: 0; padding: 0; background: transparent; cursor: pointer; }

/* alvos do modo Editar */
.alvo { position: absolute; outline: 1.5px dashed rgba(31, 78, 140, .55); background: rgba(31, 78, 140, .07); cursor: text; border-radius: 2px; }
.alvo:hover { background: rgba(31, 78, 140, .18); }
.alvo.imagem { outline-color: rgba(180, 90, 0, .7); background: rgba(240, 150, 30, .08); cursor: pointer; }
.alvo.imagem:hover { background: rgba(240, 150, 30, .2); }
.mascara { position: absolute; cursor: pointer; }
.mascara.desenhando { background: rgba(180, 35, 24, .15); outline: 1.5px dashed #b42318; }
body[data-modo="borracha"] .camada, body[data-modo="texto"] .camada { touch-action: none; cursor: crosshair; }
body[data-modo="borracha"] .mascara.borracha:not(.desenhando) { outline: 1px dashed rgba(180, 35, 24, .5); }

.ferramentas {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 15;
  bottom: calc(14px + env(safe-area-inset-bottom));
  display: flex; gap: 2px; padding: 5px; border-radius: 16px;
  background: var(--superficie); border: 1px solid var(--borda); box-shadow: 0 6px 18px rgba(0, 0, 0, .22);
  max-width: calc(100vw - 16px);
}
.ferramentas[hidden] { display: none; }
.ferramentas button {
  border: 0; background: transparent; border-radius: 11px; cursor: pointer; min-width: 62px;
  display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 6px 8px; font-size: 12.5px; color: var(--texto);
}
.ferramentas button span { font-size: 19px; line-height: 1.15; }
.ferramentas button .tt { font: 700 19px/1.15 Georgia, "Times New Roman", serif; }
.ferramentas button:hover { background: var(--fundo); }
.ferramentas button.ativo { background: var(--pri); color: var(--pri-texto); }
#btnAssinar { color: var(--pri); font-weight: 650; }
.creditos { font-size: 12px; }
.creditos a { color: inherit; }

.modal {
  width: min(560px, calc(100vw - 24px)); max-height: calc(100dvh - 32px);
  border: 1px solid var(--borda); border-radius: 16px; padding: 16px;
  background: var(--superficie); color: var(--texto); box-shadow: var(--sombra);
}
.modal::backdrop { background: rgba(10, 15, 25, .55); }
.modal-topo { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.modal h2 { font-size: 19px; margin: 0; }
.fechar { border: 0; background: transparent; font-size: 20px; cursor: pointer; padding: 4px 8px; color: var(--texto-2); }
.dica { color: var(--texto-2); font-size: 14px; margin: 0 0 12px; }

.grade { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-bottom: 14px; }
.cartao { border: 1px solid var(--borda); border-radius: 12px; overflow: hidden; display: flex; flex-direction: column; }
.cartao .usar { border: 0; padding: 10px; background: #fff; cursor: pointer; height: 96px; display: grid; place-items: center; }
.cartao .usar img { max-width: 100%; max-height: 76px; }
.cartao .rodape { display: flex; align-items: center; justify-content: space-between; gap: 4px; padding: 4px 4px 4px 10px; font-size: 13px; border-top: 1px solid var(--borda); }
.cartao .nome { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mini { border: 0; background: transparent; cursor: pointer; padding: 4px 6px; border-radius: 6px; }
.mini:hover { background: var(--fundo); }
.vazio { grid-column: 1 / -1; color: var(--texto-2); text-align: center; margin: 12px 0; }

.linha-botoes { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.linha-botoes.fim { justify-content: flex-end; margin-top: 16px; }
.mais { margin-top: 6px; font-size: 14px; color: var(--texto-2); }
.mais summary { cursor: pointer; }

.previa { border: 1px solid var(--borda); border-radius: 12px; min-height: 120px; display: grid; place-items: center; padding: 12px; position: relative; }
.previa canvas { max-width: 100%; max-height: 220px; }
.xadrez {
  background-color: #fff;
  background-image: linear-gradient(45deg, #e9ecef 25%, transparent 25%), linear-gradient(-45deg, #e9ecef 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #e9ecef 75%), linear-gradient(-45deg, transparent 75%, #e9ecef 75%);
  background-size: 18px 18px; background-position: 0 0, 0 9px, 9px -9px, -9px 0;
}
.sem-tinta { position: absolute; color: #b42318; font-size: 14px; margin: 0; }
.campo { display: block; margin-top: 12px; font-size: 14px; color: var(--texto-2); }
.campo input[type="range"] { width: 100%; display: block; margin-top: 4px; }
.campo input[type="text"] {
  display: block; width: 100%; margin-top: 4px; padding: 9px 10px; font: inherit; color: var(--texto);
  border: 1px solid var(--borda); border-radius: 10px; background: var(--superficie);
}
.escala { display: flex; justify-content: space-between; font-size: 12px; }
.seg { display: inline-flex; margin-top: 4px; border: 1px solid var(--borda); border-radius: 10px; overflow: hidden; }
.seg button { border: 0; background: transparent; padding: 7px 14px; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--borda); }
.seg button.ativo { background: var(--pri); color: var(--pri-texto); }

.quadro { display: block; width: 100%; height: 220px; background: #fff; border: 1px solid var(--borda); border-radius: 12px; touch-action: none; }

.aviso {
  position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  max-width: calc(100vw - 32px); background: #1c2430; color: #fff; padding: 10px 16px; border-radius: 10px;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 50; font-size: 15px;
}
.aviso.ver { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 520px) {
  .barra { padding-left: 12px; padding-right: 12px; }
  .marca span { display: none; }
  .bt { padding: 7px 10px; font-size: 14px; }
  .documento { padding-left: 6px; padding-right: 6px; }
  .ferramentas button { min-width: 0; flex: 1; padding: 6px 4px; font-size: 11.5px; }
}
