:root {
  --bg: #f4f1ec;
  --surface: #ffffff;
  --surface-2: #faf8f5;
  --ink: #221d17;
  --muted: #776c5f;
  --line: #e4ddd2;
  --line-strong: #cfc5b6;
  --accent: #b4532a;
  --accent-ink: #ffffff;
  --accent-soft: #f6e5dc;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --ok: #2f7d4f;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(40, 30, 20, 0.06), 0 4px 16px rgba(40, 30, 20, 0.05);
  --sans: 'IBM Plex Sans', 'Segoe UI', system-ui, sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, Consolas, monospace;
  color-scheme: light;
}

/* Tema escuro: pelo sistema (se a pessoa não escolheu "claro") ou escolhido no botão */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #171411;
    --surface: #211d19;
    --surface-2: #1b1815;
    --ink: #efe8de;
    --muted: #a59a8c;
    --line: #342e27;
    --line-strong: #4a4238;
    --accent: #e0794a;
    --accent-ink: #1b120c;
    --accent-soft: #3a2519;
    --danger: #f2877c;
    --danger-soft: #3a1d1a;
    --ok: #6cc28f;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    color-scheme: dark;
  }
}

:root[data-theme='dark'] {
  --bg: #171411;
  --surface: #211d19;
  --surface-2: #1b1815;
  --ink: #efe8de;
  --muted: #a59a8c;
  --line: #342e27;
  --line-strong: #4a4238;
  --accent: #e0794a;
  --accent-ink: #1b120c;
  --accent-soft: #3a2519;
  --danger: #f2877c;
  --danger-soft: #3a1d1a;
  --ok: #6cc28f;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 var(--sans);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

h1, h2, h3 { margin: 0; line-height: 1.2; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); font-size: 0.92em; }

/* ---------- Topo ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand { display: flex; align-items: center; gap: 12px; flex: none; }
.brand svg { width: 34px; height: 34px; flex: none; }
.brand svg rect { fill: var(--accent); }
.brand svg path { stroke: var(--surface); stroke-width: 2; fill: none; }
.brand h1 { font-size: 18px; font-weight: 700; letter-spacing: -0.01em; white-space: nowrap; }
.brand p { margin: 0; font-size: 12.5px; color: var(--muted); white-space: nowrap; }

/* Alternar entre os sites (Otimizador de Cortes / Orçamentos) */
.app-switch { display: inline-flex; align-items: center; gap: 2px; padding: 3px; flex: none; border: 1px solid var(--line); border-radius: 99px; background: var(--surface-2); }
.app-switch a { display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; border-radius: 99px; color: var(--muted); font-size: 13px; font-weight: 500; text-decoration: none; white-space: nowrap; }
.app-switch a[href]:hover { color: var(--ink); background: var(--surface); }
.app-switch a.on { background: var(--surface); color: var(--accent); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1); cursor: default; }
.app-switch svg { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* Projeto: nome + ações, na mesma linha */
.project { display: flex; align-items: center; gap: 4px; flex: 1 1 auto; min-width: 0; }
.project .project-name { flex: 0 1 240px; min-width: 120px; width: 240px; font-weight: 500; margin-right: 6px; }
.tb-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  padding: 0 11px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--muted);
  font-weight: 500;
  font-size: 14px;
  white-space: nowrap;
  cursor: pointer;
  list-style: none;
}
.tb-btn:hover, .dropdown[open] > summary.tb-btn { background: var(--surface-2); color: var(--ink); }
.tb-btn svg { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tb-btn .caret { width: 14px; height: 14px; margin-left: -2px; }
.tb-btn .ico-more { display: none; fill: currentColor; stroke: none; }

.top-right { display: flex; align-items: center; gap: 10px; margin-left: auto; flex: none; }

/* Status do salvamento (como no orcamento-marcenaria) */
.sync {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border: 0;
  border-radius: 99px;
  background: var(--surface-2);
  color: var(--muted);
  font: 500 12.5px var(--sans);
  white-space: nowrap;
  cursor: pointer;
}
.sync::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex: none; }
.sync[data-state='saved'] { color: var(--ok); }
.sync[data-state='saving'] { color: var(--muted); }
.sync[data-state='error'] { color: var(--danger); background: var(--danger-soft); }
.sync[data-state='offline'] { color: var(--danger); background: var(--danger-soft); }

.mobile-only { display: none; }
.mobile-only[hidden] { display: none !important; }

/* Botão de tema claro/escuro */
.theme-btn {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  flex: none;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.theme-btn:hover { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.theme-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.theme-btn .moon { display: none; }
.theme-dark .theme-btn .sun { display: none; }
.theme-dark .theme-btn .moon { display: block; }

/* Conta */
.account { display: flex; align-items: center; gap: 4px; padding-left: 8px; margin-left: 4px; border-left: 1px solid var(--line); }
.account[hidden] { display: none; }
.user { display: inline-flex; align-items: center; gap: 8px; min-width: 0; }
.avatar {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
  font-size: 14px;
  object-fit: cover;
  flex: none;
}
.user-email { max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13.5px; }

/* ---------- Controles ---------- */

input, select, button { font: inherit; color: inherit; }

input[type='text'], input[type='email'], input[type='number'], select {
  width: 100%;
  min-width: 0;
  height: 34px;
  padding: 0 9px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: var(--surface);
  transition: border-color 0.15s, box-shadow 0.15s;
}
input[type='number'] { font-family: var(--mono); font-size: 14px; text-align: right; padding-right: 6px; }
input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
select:disabled { opacity: 0.45; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 34px;
  padding: 0 14px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: var(--surface);
  font-weight: 500;
  font-size: 14px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s;
}
.btn:hover { background: var(--surface-2); border-color: var(--muted); }
.btn.ghost { border-color: transparent; color: var(--muted); }
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.btn.primary:hover { filter: brightness(1.07); background: var(--accent); }
.btn.big { height: 46px; font-size: 16px; font-weight: 600; width: 100%; }
.btn:disabled { opacity: 0.7; cursor: progress; }

.icon {
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}
.icon:hover { background: var(--danger-soft); color: var(--danger); }

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

/* Menu Arquivo */
.dropdown { position: relative; }
.dropdown summary { list-style: none; }
.dropdown summary::-webkit-details-marker { display: none; }
.dropdown .menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 230px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
  z-index: 20;
}
.dropdown .menu button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  border: 0;
  border-radius: 6px;
  background: none;
  cursor: pointer;
  font-size: 14px;
}
.dropdown .menu button:hover { background: var(--surface-2); }
.dropdown hr { border: 0; border-top: 1px solid var(--line); margin: 6px 0; }

/* ---------- Layout ---------- */

.layout {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 560px) minmax(0, 1fr);
  gap: 24px;
  padding: 24px;
  align-items: start;
}

.inputs { display: flex; flex-direction: column; gap: 16px; position: sticky; top: 84px; max-height: calc(100vh - 100px); overflow-y: auto; padding-bottom: 4px; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.card-head h2 { font-size: 15px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; }
.card-head .muted { font-size: 13px; }
.card-actions { display: flex; gap: 8px; margin-top: 10px; }

/* ---------- Tabelas ---------- */

.table-wrap { overflow-x: auto; margin: 0 -4px; padding: 0 4px; }
.grid { width: 100%; border-collapse: collapse; }
.grid th {
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  text-align: left;
  padding: 0 3px 6px;
  white-space: nowrap;
}
.grid td { padding: 3px; vertical-align: middle; }
.grid .c-n { width: 30px; }
.grid .c-on { width: 26px; text-align: center; }
.grid .c-on input { width: 17px; height: 17px; margin: 0; accent-color: var(--accent); cursor: pointer; vertical-align: middle; }
.grid tr.off td:not(.c-on) { opacity: 0.4; }
.grid tr.off input[type='text'] { text-decoration: line-through; }
.grid .c-num { width: 82px; min-width: 74px; }
.grid .c-qty { width: 58px; min-width: 52px; }
.grid .c-grain { width: 92px; min-width: 86px; }
.grid .c-stock { width: 120px; min-width: 110px; }
.pieces.one-stock .c-stock { display: none; }
.grid .c-del { width: 32px; }
.grid th.c-num, .grid th.c-qty { text-align: right; padding-right: 9px; }
.grid td:nth-child(2) input, .stocks td:first-child input { min-width: 96px; }
.grid select { padding: 0 4px; font-size: 13px; }

.swatch {
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 6px;
  font: 500 11px var(--mono);
  color: #1d1712;
}

/* ---------- Opções ---------- */

.options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.check { display: flex; gap: 10px; align-items: flex-start; grid-column: 1 / -1; font-size: 14px; cursor: pointer; }
.check input { width: 17px; height: 17px; margin: 2px 0 0; accent-color: var(--accent); flex: none; }
.check small { display: block; color: var(--muted); font-size: 12.5px; }
.check.inline { display: inline-flex; align-items: center; gap: 6px; font-size: 13.5px; }
.check.inline input { margin: 0; }

/* ---------- Resultados ---------- */

.results { min-width: 0; transition: opacity 0.2s; }
.results.stale { opacity: 0.55; }

.empty {
  display: grid;
  place-items: center;
  min-height: 300px;
  border: 1.5px dashed var(--line-strong);
  border-radius: var(--radius);
  color: var(--muted);
  text-align: center;
  padding: 24px;
}

.results-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.results-head h2 { font-size: 22px; letter-spacing: -0.01em; }
.results-head p { margin: 4px 0 0; font-size: 13.5px; }
.results-actions { display: flex; gap: 8px; }

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.stat-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.stat-value { font: 600 22px var(--mono); letter-spacing: -0.02em; }
.stat-sub { font-size: 12.5px; color: var(--muted); }
.bar { display: block; height: 5px; margin-top: 6px; background: var(--line); border-radius: 3px; overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--ok); border-radius: 3px; }

.alert {
  background: var(--danger-soft);
  border: 1px solid var(--danger);
  color: var(--ink);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 14px;
  font-size: 14px;
}
.alert strong { color: var(--danger); }
.alert ul { margin: 6px 0; padding-left: 20px; }
.alert p { margin: 0; color: var(--muted); }

/* Painel "Estatísticas" */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}
.panel > summary, .cuts > summary {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  list-style: none;
  font-weight: 600;
}
.panel > summary::-webkit-details-marker, .cuts > summary::-webkit-details-marker { display: none; }
.panel > summary::after, .cuts > summary::after {
  content: '';
  width: 7px;
  height: 7px;
  margin-left: auto;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(45deg) translateY(-2px);
  transition: transform 0.15s;
}
details[open] > summary::after { transform: rotate(-135deg) translateY(-2px); }
.panel > summary { padding: 12px 16px; font-size: 15px; text-transform: uppercase; letter-spacing: 0.06em; }
.panel[open] > summary { border-bottom: 1px solid var(--line); }

.kv { width: 100%; border-collapse: collapse; font-size: 14px; }
.kv th, .kv td { padding: 8px 16px; text-align: left; vertical-align: top; }
.kv th { font-weight: 500; color: var(--muted); width: 42%; }
.kv tr:nth-child(odd) { background: var(--surface-2); }
.kv td { line-height: 1.7; }

/* Estatísticas por chapa (navegação ‹ 1 / N ›) */
.pager { display: inline-flex; align-items: center; gap: 4px; margin-left: 12px; text-transform: none; letter-spacing: 0; font-weight: 500; }
.pager-label { font-family: var(--mono); font-size: 14px; min-width: 52px; text-align: center; }
.pager-btn {
  width: 30px;
  height: 30px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: var(--surface);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}
.pager-btn:hover:not(:disabled) { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.pager-btn:disabled { opacity: 0.4; cursor: default; }
.link { border: 0; background: none; padding: 0; margin-left: 8px; color: var(--accent); font-size: 13px; cursor: pointer; text-decoration: underline; }

/* Sequência de cortes */
.cuts { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 10px; }
.cuts > summary { font-size: 14px; padding: 4px 0; }
.cuts-help { font-size: 12.5px; margin: 6px 0 8px; }
.cut-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.cut-table th { text-align: left; font-size: 12px; font-weight: 500; color: var(--muted); padding: 6px 8px; border-bottom: 1px solid var(--line-strong); white-space: nowrap; }
.cut-table td { padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; white-space: nowrap; }
.cut-table td.num { font-family: var(--mono); color: var(--muted); }
.cut-res { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 6px; white-space: normal; }
.cut-res .dot { display: inline-block; }
.sep-bar { color: var(--line-strong); }
.tag { font-size: 11px; padding: 1px 6px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); }

/* Barra de visualização das chapas */
.viewbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 18px;
  padding: 10px 12px;
  margin-bottom: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.vb-group { display: inline-flex; align-items: center; gap: 6px; }
.vb-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; margin-right: 2px; }
.vb-val { font: 500 13px var(--mono); min-width: 44px; text-align: center; }
.vb-btn {
  min-width: 32px;
  height: 30px;
  padding: 0 8px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: var(--surface);
  font-weight: 600;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
}
.vb-btn.small-a { font-size: 12px; }
.vb-btn:hover:not(:disabled) { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.vb-btn:disabled { opacity: 0.4; cursor: default; }
.seg { gap: 0; }
.seg-btn {
  height: 30px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  font-size: 13px;
  cursor: pointer;
}
.seg-btn:first-child { border-radius: 7px 0 0 7px; }
.seg-btn:last-child { border-radius: 0 7px 7px 0; border-left: 0; }
.seg-btn.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 500; }

.stepper { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-top: 10px; font-size: 14px; }
.step-label { min-width: 130px; text-align: center; }
.cut-table tr.current td { background: var(--accent-soft); }
.cut-table tr.current td.num { color: var(--accent); font-weight: 600; }

.view-toggles { display: flex; gap: 18px; flex-wrap: wrap; margin-bottom: 12px; }

.sheets { display: flex; flex-direction: column; gap: 16px; }
.sheet {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px 16px;
  break-inside: avoid;
}
.sheet header { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.sheet header > div:first-child { flex: 1; min-width: 0; }
.sheet h3 { font-size: 16px; display: flex; align-items: center; gap: 8px; }
.sheet header p { margin: 2px 0 0; font-size: 13px; }
.badge { font: 500 12px var(--mono); background: var(--accent-soft); color: var(--accent); padding: 2px 7px; border-radius: 99px; }
.sheet-eff { text-align: right; }
.sheet-eff .mono { display: block; font-size: 18px; font-weight: 600; }
.sheet-eff small { color: var(--muted); font-size: 11.5px; }
.sheet header .icon:hover { background: var(--accent-soft); color: var(--accent); }

.svg-wrap { background: #fbf9f6; border-radius: 6px; padding: 8px; overflow: auto; max-height: 85vh; }
.svg-wrap svg { display: block; width: 100%; height: auto; max-width: none; margin: 0 auto; }

.parts-list { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 12px 0 0; padding: 0; list-style: none; font-size: 13px; }
.parts-list li { display: inline-flex; align-items: center; gap: 6px; }
.parts-list .mono { color: var(--muted); }
.dot { width: 10px; height: 10px; border-radius: 3px; flex: none; }

/* ---------- Diálogo de projetos ---------- */

dialog {
  width: min(460px, calc(100vw - 32px));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
}
dialog::backdrop { background: rgba(20, 15, 10, 0.4); }
.dlg { padding: 16px 18px 18px; }
.dlg-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.dlg-head h2 { font-size: 17px; }
.project-list { list-style: none; margin: 0; padding: 0; max-height: 60vh; overflow-y: auto; }
.project-list li { display: flex; align-items: center; gap: 8px; padding: 10px 0; border-top: 1px solid var(--line); }
.project-list li > div { flex: 1; min-width: 0; }
.project-list strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.project-list small { color: var(--muted); font-size: 12px; }
.project-list li.muted { font-size: 14px; }
.project-list li.current strong { color: var(--accent); }
.dlg-section + .dlg-section { margin-top: 18px; }
.dlg-section h3 { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin-bottom: 4px; }
.dlg-text { margin: 0 0 16px; font-size: 14px; }

/* Compartilhar */
.share-row { display: flex; gap: 8px; }
.share-row input { flex: 1; font: 13px var(--mono); }
.share-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
a.btn { text-decoration: none; color: inherit; }
.share-note { font-size: 12.5px; margin: 14px 0 0; }

.btn.google { gap: 10px; }
.btn.google svg { width: 20px; height: 20px; }
.btn[hidden], .sep[hidden], #emailLogin[hidden] { display: none; }
.sep { display: flex; align-items: center; gap: 10px; margin: 16px 0; color: var(--muted); font-size: 13px; }
.sep::before, .sep::after { content: ''; flex: 1; border-top: 1px solid var(--line); }
.email-btn { width: 100%; margin-top: 10px; }
.login-msg { margin: 12px 0 0; font-size: 13.5px; color: var(--ok); min-height: 1em; }
.login-msg.error { color: var(--danger); }
.login-msg:empty { display: none; }

/* ---------- Avisos ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 20px);
  background: var(--ink);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 50;
  max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.footer { padding: 16px 24px 24px; text-align: center; font-size: 12.5px; color: var(--muted); }
.footer a { color: inherit; }
a.brand { color: inherit; text-decoration: none; }
a.brand + .theme-btn { margin-left: auto; }

/* Páginas de texto (política de privacidade) */
.doc { flex: 1; width: 100%; max-width: 720px; margin: 0 auto; padding: 40px 24px; font-size: 16px; line-height: 1.65; }
.doc h1 { font-size: 30px; letter-spacing: -0.02em; margin-bottom: 6px; }
.doc h2 { font-size: 19px; margin: 32px 0 8px; }
.doc p, .doc ul { margin: 0 0 12px; }
.doc a { color: var(--accent); }

/* ---------- Responsivo ---------- */

/* No topo a conta mostra só a foto (o e-mail aparece ao passar o mouse). */
.topbar .user-email { display: none; }

@media (max-width: 1600px) {
  .app-switch span { display: none; }
  .app-switch a { padding: 5px 9px; }
}

@media (max-width: 1440px) {
  .brand p { display: none; }
}

@media (max-width: 1320px) {
  .tb-btn > span { display: none; }
  .tb-btn { padding: 0 9px; }
  .tb-btn .caret { display: none; }
}

@media (max-width: 1100px) {
  .brand-text { display: none; }
  .sync { width: 30px; height: 30px; padding: 0; justify-content: center; }
  .sync .sync-text { display: none; }
  .sync::before { width: 9px; height: 9px; }
}

@media (max-width: 1080px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .inputs { position: static; max-height: none; overflow: visible; }
}

@media (max-width: 640px) {
  .layout { padding: 16px; gap: 16px; }
  .card { padding: 12px; }
  .options { grid-template-columns: minmax(0, 1fr); }
  .sheet { padding: 12px; }
  .svg-wrap { padding: 4px; }
}

/* ---------- App no celular ---------- */

.tabbar { display: none; }
.net-badge {
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 99px;
  background: var(--danger-soft);
  color: var(--danger);
  white-space: nowrap;
}
.net-badge[hidden], .install-btn[hidden] { display: none; }

@media (max-width: 760px) {
  body { padding-bottom: calc(66px + env(safe-area-inset-bottom)); }
  /* Topo numa linha só: logo · nome do projeto · status · tema · menu ⋮ */
  .topbar { padding: 8px 12px; gap: 8px; }
  .brand-text { display: none; }
  .brand svg { width: 30px; height: 30px; }
  .app-switch { order: 0; padding: 0; border: 0; background: none; }
  .app-switch a.on { display: none; }
  .app-switch a { width: 34px; height: 34px; padding: 0; justify-content: center; border: 1px solid var(--line-strong); }
  .app-switch svg { width: 18px; height: 18px; }
  .project { display: contents; }
  .project .project-name { order: 1; flex: 1 1 auto; width: auto; min-width: 0; margin: 0; height: 38px; font-size: 15px; }
  .project > .tb-btn { display: none; }
  .top-right { order: 2; gap: 6px; }
  .dropdown { order: 3; }
  .dropdown > summary.tb-btn { width: 36px; padding: 0; justify-content: center; }
  .dropdown > summary .ico-file, .dropdown > summary .caret { display: none; }
  .dropdown > summary .ico-more { display: block; width: 20px; height: 20px; }
  .sync { width: 30px; height: 30px; padding: 0; justify-content: center; }
  .sync .sync-text { display: none; }
  .sync::before { width: 9px; height: 9px; }
  .theme-btn { width: 34px; height: 34px; }
  .net-badge, .account, .install-btn { display: none !important; }
  .mobile-only { display: block; }
  .dropdown .menu { min-width: 250px; }

  /* Só a seção da aba escolhida aparece */
  .layout [data-tab] { display: none !important; }
  body[data-tab='pieces'] .layout [data-tab~='pieces'],
  body[data-tab='stocks'] .layout [data-tab~='stocks'],
  body[data-tab='options'] .layout [data-tab~='options'],
  body[data-tab='plan'] .layout [data-tab~='plan'] { display: block !important; }
  body[data-tab='pieces'] .layout .calc-btn[data-tab~='pieces'],
  body[data-tab='stocks'] .layout .calc-btn[data-tab~='stocks'],
  body[data-tab='options'] .layout .calc-btn[data-tab~='options'] { display: flex !important; }
  .layout { padding: 12px; gap: 12px; }
  .footer { padding-bottom: 12px; }

  /* Barra de abas */
  .tabbar {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    padding: 4px 6px env(safe-area-inset-bottom);
    background: var(--surface);
    border-top: 1px solid var(--line);
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.08);
  }
  .tabbar button {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 7px 0 6px;
    border: 0;
    background: none;
    color: var(--muted);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
  }
  .tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; stroke-linecap: round; }
  .tabbar button.on { color: var(--accent); }
  .tabbar button.on::before {
    content: '';
    position: absolute;
    top: -4px;
    left: 30%;
    right: 30%;
    height: 3px;
    border-radius: 0 0 3px 3px;
    background: var(--accent);
  }
  .tab-badge {
    position: absolute;
    top: 3px;
    left: 56%;
    padding: 1px 5px;
    border-radius: 99px;
    background: var(--ok);
    color: #fff;
    font: 600 10px var(--mono);
  }
  .tab-badge.warn { background: var(--danger); }
  .tab-badge[hidden] { display: none; }

  .toast { bottom: calc(80px + env(safe-area-inset-bottom)); }

  /* Campos maiores para o dedo */
  input[type='text'], input[type='email'], input[type='number'], select { height: 42px; font-size: 16px; }
  .btn { height: 40px; }
  .btn.big { height: 50px; }

  /* Tabelas de peças e chapas viram cartões */
  .card { padding: 12px; }
  .card .table-wrap { overflow: visible; margin: 0; padding: 0; }
  .grid, .grid tbody { display: block; }
  .grid thead { display: none; }
  .grid tbody tr {
    display: grid;
    grid-template-columns: 28px 30px repeat(4, minmax(0, 1fr)) 34px;
    grid-template-areas:
      'on n name name name name del'
      'len len len wid wid qty qty'
      'grain grain grain stock stock stock stock';
    gap: 8px 6px;
    align-items: end;
    padding: 12px 10px;
    margin-bottom: 10px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface-2);
  }
  .grid.stocks tbody tr { grid-template-areas: 'on name name name name name del' 'len len len wid wid qty qty'; }
  .grid td { display: flex; flex-direction: column; gap: 3px; padding: 0; width: auto !important; min-width: 0 !important; }
  .grid td[data-label]::before { content: attr(data-label); font-size: 11.5px; color: var(--muted); }
  .grid td.c-on { grid-area: on; align-self: center; }
  .grid td.c-n { grid-area: n; align-self: center; }
  .grid td.c-name { grid-area: name; }
  .grid td.c-del { grid-area: del; align-self: center; }
  .grid td.c-len { grid-area: len; }
  .grid td.c-wid { grid-area: wid; }
  .grid td.c-qty { grid-area: qty; }
  .grid td.c-grain { grid-area: grain; }
  .grid td.c-stock { grid-area: stock; }
  .pieces.one-stock tbody tr { grid-template-areas: 'on n name name name name del' 'len len len wid wid qty qty' 'grain grain grain grain . . .'; }
  .grid td input[type='text'] { font-weight: 500; }
  .grid .icon { width: 34px; height: 34px; }
  .grid tr.off { background: transparent; border-style: dashed; }

  /* Resultado */
  .results-head h2 { font-size: 19px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .stat { padding: 10px 12px; }
  .stat-value { font-size: 19px; }
  .kv th, .kv td { padding: 8px 12px; }
  .kv th { width: 46%; }
  .viewbar { gap: 8px 12px; }
  .pager { margin-left: auto; }
  .sheet header { flex-wrap: wrap; }
}

/* App instalado (tela cheia) */
@media (display-mode: standalone) {
  .install-btn { display: none !important; }
}

/* ---------- Impressão / PDF ---------- */

@media print {
  :root { --bg: #fff; --surface: #fff; --ink: #000; --line: #ccc; --shadow: none; color-scheme: light; }
  body { background: #fff; }
  .topbar, .inputs, .footer, .no-print, .toast, .tabbar { display: none !important; }
  .layout [data-tab] { display: block !important; }
  .layout { display: block; padding: 0; }
  .results.stale { opacity: 1; }
  .sheet { break-inside: avoid; page-break-inside: avoid; box-shadow: none; }
  .stats { grid-template-columns: repeat(5, 1fr); }
}
