:root {
  --paper: #ffffff;
  --bench: #e9ecef;          /* mesa onde a folha fica */
  --ink: #000000;            /* preto da marca */
  --text: #26292d;
  --muted: #6a7077;
  --rule: #d4d8dd;
  --field: #f7f8f9;
  --ok: #1d6a44;
  --danger: #a3261c;
  --chrome: linear-gradient(100deg, #f8f9fa 0%, #b9bfc6 22%, #fdfdfd 38%, #9aa1a9 58%, #eef0f2 76%, #b4bac1 100%);

  --font: 'Archivo', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --radius-s: 4px;
  --radius-m: 8px;
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
img { max-width: 100%; }

h1, h2, h3 {
  color: var(--ink);
  font-stretch: 125%;
  letter-spacing: -0.01em;
  line-height: 1.15;
  margin: 0;
}
h1 { font-size: 1.85rem; font-weight: 750; }
h2 { font-size: 1.25rem; font-weight: 700; }
h3 { font-size: 0.95rem; font-weight: 700; margin: 1.75rem 0 0.6rem; }

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

/* ---------- Botões ---------- */
.btn {
  font: inherit;
  font-weight: 600;
  font-size: 0.92rem;
  border: 1px solid var(--ink);
  background: var(--paper);
  color: var(--ink);
  padding: 0.62rem 1.1rem;
  border-radius: var(--radius-s);
  cursor: pointer;
  transition: background-color .15s, color .15s;
}
.btn:hover { background: var(--field); }
.btn.primary { background: var(--ink); color: #fff; }
.btn.primary:hover { background: #2b2f34; }
.btn.ghost { border-color: var(--rule); color: var(--text); }
.btn.small { padding: 0.4rem 0.8rem; font-size: 0.85rem; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; cursor: progress; }
.btn.danger { color: var(--danger); border-color: transparent; }
.btn.danger:hover { background: #fbeeed; }

.link-btn {
  font: inherit; background: none; border: 0; padding: 0;
  color: var(--ink); text-decoration: underline; text-underline-offset: 3px; cursor: pointer;
}

/* ---------- Campos ---------- */
.label, .field > span {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.35rem;
}
input[type=text], input[type=email], input[type=password], input[type=search], select, textarea {
  font: inherit;
  font-size: 0.92rem;
  color: var(--ink);
  width: 100%;
  background: var(--field);
  border: 1px solid var(--rule);
  border-radius: var(--radius-s);
  padding: 0.55rem 0.7rem;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--ink); background: #fff; }
textarea { resize: vertical; line-height: 1.45; }
.field { display: block; }

/* ---------- Login ---------- */
.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem 1rem;
  background: var(--bench);
}
.login-card {
  width: min(400px, 100%);
  background: var(--paper);
  padding: 2.25rem 2rem 2rem;
  border-radius: var(--radius-m);
  box-shadow: 0 1px 2px rgba(0,0,0,.06), 0 12px 32px rgba(20,24,28,.10);
  position: relative;
  overflow: hidden;
}
.login-card::before { content: ""; position: absolute; inset: 0 0 auto; height: 4px; background: var(--chrome); }
.login-logo { width: 190px; display: block; margin-bottom: 1.5rem; }
.login-card h1 { font-size: 1.5rem; }
.login-card p { margin: 0.4rem 0 1.4rem; }
.login-card .field { margin-bottom: 1rem; }
.form-error { color: var(--danger); font-size: 0.88rem; margin: -0.2rem 0 1rem; }

/* ---------- Topo ---------- */
.topbar { position: relative; border-bottom: 1px solid var(--rule); background: var(--paper); }
.topbar::before { content: ""; position: absolute; inset: 0 0 auto; height: 3px; background: var(--chrome); }
.topbar-inner {
  max-width: 1440px; margin: 0 auto;
  display: flex; align-items: center; gap: 1rem;
  padding: 0.9rem clamp(1rem, 3vw, 2.5rem) 0.8rem;
}
.topbar-logo { height: 34px; width: auto; }
.topbar-title {
  font-stretch: 125%; font-weight: 700; color: var(--ink);
  padding-left: 1rem; border-left: 1px solid var(--rule);
}
.who { margin-left: auto; display: flex; gap: 1rem; align-items: center; font-size: 0.88rem; color: var(--muted); }

/* ---------- Área de trabalho ---------- */
.workspace {
  max-width: 1440px; margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(420px, 46%);
  align-items: start;
}
.compose { padding: 2.25rem clamp(1rem, 3vw, 2.5rem) 3rem; max-width: 760px; }
.lede { color: var(--muted); max-width: 60ch; margin: 0.5rem 0 1.5rem; }
.raw {
  min-height: 220px;
  font-size: 0.86rem;
  tab-size: 4;
  white-space: pre;
  overflow-x: auto;
}
.actions { display: flex; gap: 0.6rem; margin-top: 0.8rem; flex-wrap: wrap; }

.editing {
  display: flex; gap: 1rem; justify-content: space-between; align-items: center; flex-wrap: wrap;
  background: var(--field); border-left: 3px solid var(--ink);
  padding: 0.7rem 1rem; margin-bottom: 1.5rem; font-size: 0.9rem;
}

.review { margin-top: 2.5rem; padding-top: 2rem; border-top: 1px solid var(--rule); }
.review > h2 { margin-bottom: 1.2rem; }
.meta-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.9rem 1rem; }
.span-2 { grid-column: span 2; }
.hint { font-size: 0.86rem; margin: 0.7rem 0 0; color: var(--muted); }
.hint.warn { color: #8a4a00; }

.hl-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0.5rem; }
.hl { display: grid; gap: 0.3rem; background: var(--field); padding: 0.5rem; border-radius: var(--radius-s); }
.hl input { background: #fff; padding: 0.4rem 0.5rem; font-size: 0.85rem; }
.hl input:first-child { color: var(--muted); }

.rows { display: grid; gap: 0.35rem; }
.group-title {
  font-size: 0.8rem; font-weight: 700; color: var(--muted);
  margin: 0.9rem 0 0.1rem; padding-bottom: 0.25rem; border-bottom: 1px solid var(--rule);
}
.group-title:first-child { margin-top: 0; }
.row {
  display: grid;
  grid-template-columns: 172px minmax(0, 0.8fr) minmax(0, 1.4fr) 2rem;
  gap: 0.4rem; align-items: start;
}
.row select, .row input, .row textarea { padding: 0.42rem 0.55rem; font-size: 0.86rem; }
.row textarea { min-height: 2.15rem; overflow: hidden; resize: none; }
.icon-btn {
  font: inherit; font-size: 1.1rem; line-height: 1;
  width: 2rem; height: 2.15rem; border: 0; background: none; color: var(--muted);
  border-radius: var(--radius-s); cursor: pointer;
}
.icon-btn:hover { background: #fbeeed; color: var(--danger); }
#btn-add-row { margin-top: 0.7rem; }

.generate-bar {
  position: sticky; bottom: 0; z-index: 2;
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  margin-top: 2rem; padding: 1rem 0;
  background: linear-gradient(to bottom, rgba(255,255,255,0), #fff 30%);
}
.generate-bar .btn { padding: 0.75rem 1.6rem; font-size: 1rem; }

/* ---------- Imagem do produto ---------- */
.optional { font-stretch: 100%; font-weight: 500; font-size: 0.8rem; color: var(--muted); margin-left: 0.35rem; }
.image-drop {
  display: grid; place-items: center;
  min-height: 140px; padding: 1rem;
  background: var(--field);
  border: 1.5px dashed var(--rule);
  border-radius: var(--radius-m);
  text-align: center; cursor: pointer;
  transition: border-color .15s, background-color .15s;
}
.image-drop:hover, .image-drop.over { border-color: var(--ink); background: #fff; }
.image-drop.has-image { border-style: solid; background: #fff; }
.image-empty { display: grid; gap: 0.3rem; max-width: 40ch; font-size: 0.9rem; }
.image-empty strong { font-weight: 600; color: var(--ink); }
.image-drop img { max-height: 200px; max-width: 100%; object-fit: contain; }
.image-actions { display: flex; gap: 0.5rem; margin-top: 0.5rem; }

/* ---------- Prévia: a folha sobre a mesa ---------- */
.bench {
  position: sticky; top: 0;
  height: 100vh;
  background: var(--bench);
  padding: clamp(1rem, 2.5vw, 2rem);
  display: grid; place-items: center;
}
.sheet {
  position: relative;
  height: 100%;
  max-height: calc((100vw * 0.46 - 4rem) * 1.414);
  aspect-ratio: 210 / 297;
  max-width: 100%;
  background: var(--paper);
  box-shadow: 0 1px 1px rgba(0,0,0,.08), 0 10px 30px rgba(30,36,42,.16);
}
.sheet iframe { width: 100%; height: 100%; border: 0; display: block; background: #fff; }
.sheet-empty {
  position: absolute; inset: 0;
  display: grid; place-content: center; justify-items: center; gap: 1rem;
  text-align: center; padding: 2rem; color: var(--muted); background: var(--paper);
}
.sheet-empty img { width: 160px; opacity: .35; filter: grayscale(1); }
.sheet-empty p { max-width: 26ch; margin: 0; font-size: 0.9rem; }

/* ---------- Histórico ---------- */
.history {
  max-width: 1440px; margin: 0 auto;
  padding: 2.75rem clamp(1rem, 3vw, 2.5rem) 4rem;
  border-top: 1px solid var(--rule);
}
.history-head { display: flex; gap: 1rem; align-items: end; justify-content: space-between; flex-wrap: wrap; margin-bottom: 1rem; }
.history-head input { max-width: 360px; }
.count { font-stretch: 100%; font-weight: 500; color: var(--muted); font-size: 0.95rem; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th {
  text-align: left; font-size: 0.8rem; font-weight: 600; color: var(--muted);
  padding: 0.55rem 0.75rem; border-bottom: 1px solid var(--ink);
}
td { padding: 0.75rem; border-bottom: 1px solid var(--rule); vertical-align: middle; }
td.sku { font-weight: 700; color: var(--ink); white-space: nowrap; font-variant-numeric: tabular-nums; }
td .sub { display: block; color: var(--muted); font-size: 0.82rem; }
td.when { white-space: nowrap; color: var(--muted); }
td.acts { white-space: nowrap; text-align: right; }
td.acts .btn { padding: 0.35rem 0.7rem; font-size: 0.84rem; }
tbody tr:hover { background: #fafbfb; }
.empty { color: var(--muted); padding: 1.5rem 0; }

/* ---------- Diálogo ---------- */
.dialog {
  border: 0; padding: 0; border-radius: var(--radius-m);
  width: min(480px, calc(100vw - 2rem));
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.dialog::backdrop { background: rgba(15,18,21,.45); }
.dialog form { padding: 1.75rem; }
.dialog h2 { font-size: 1.15rem; margin-bottom: 0.6rem; }
.dialog p { margin: 0 0 0.8rem; }
.dialog-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 1.25rem; }

/* ---------- Aviso ---------- */
.toast {
  position: fixed; left: 50%; bottom: 1.5rem; transform: translate(-50%, 1rem);
  background: var(--ink); color: #fff; padding: 0.75rem 1.2rem; border-radius: var(--radius-s);
  font-size: 0.9rem; max-width: calc(100vw - 2rem);
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 50;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--danger); }

/* ---------- Responsivo ---------- */
@media (max-width: 1080px) {
  .workspace { grid-template-columns: 1fr; }
  .compose { max-width: none; }
  .bench { position: static; height: auto; }
  .sheet { height: auto; width: min(620px, 100%); max-height: none; }
}
@media (max-width: 640px) {
  h1 { font-size: 1.5rem; }
  .meta-grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .hl-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .row { grid-template-columns: minmax(0, 1fr) 2rem; }
  .row select, .row input, .row textarea { grid-column: 1; }
  .row .icon-btn { grid-column: 2; grid-row: 1; }
  .topbar-title { display: none; }
  .who span { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
