/* Visual aprovado do sistema atual (verde Darsley), adaptado para Mac e iPad. */
:root {
  --canvas: #122221; --panel: #1e302f; --emphasis: #2a4541; --field: #38564f;
  --text: #f0f5f1; --muted: #cedbd4; --border: #7b9b8f; --outline: #62c9aa;
  --gold: #e1b96d; --value: #79d8b5; --negative: #edaaa3; --warning: #efdab5; --warning-panel: #332f23;
  --radius: 12px; --font: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --heading: Georgia, serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--canvas); color: var(--text); font: 16px/1.45 var(--font); }
h1, h2, h3 { font-family: var(--heading); font-weight: 600; margin: 0 0 .6rem; }
h2 { font-size: 1.3rem; } h3 { font-size: 1.05rem; color: var(--gold); }
a { color: var(--value); }
small, .muted { color: var(--muted); }

.top { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: .8rem 1.2rem;
  border-bottom: 2px solid var(--outline); background: var(--panel); position: sticky; top: 0; z-index: 5; }
.brand { text-decoration: none; color: var(--text); display: flex; flex-direction: column; }
.brand small { letter-spacing: .18em; color: var(--gold); font-size: .72rem; }
.brand strong { font-family: var(--heading); font-size: 1.3rem; }
.top-actions { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; justify-content: flex-end; }
.dev-note { margin: 0; padding: .35rem 1.2rem; background: var(--warning-panel); color: var(--warning); font-size: .85rem; }

main { max-width: 1180px; margin: 0 auto; padding: 1rem; display: grid; gap: 1rem; }
section, .card { background: var(--emphasis); border: 2px solid var(--outline); border-top-width: 3px;
  border-radius: var(--radius); padding: 1rem; min-width: 0; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 1rem; }

label { display: grid; gap: .25rem; font-size: .9rem; color: var(--muted); }
input, select, textarea, button { font: inherit; }
input, select, textarea { background: var(--field); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: .6rem .7rem; min-height: 44px; width: 100%; }
input[type=checkbox] { width: 22px; min-height: 22px; accent-color: var(--outline); }
label.check { display: flex; align-items: center; gap: .5rem; color: var(--text); }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--gold); outline-offset: 1px; }
.form { display: grid; gap: .7rem; }
.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .7rem; align-items: end; }

button { background: var(--outline); color: #0d1d1b; border: 0; border-radius: 8px; padding: .6rem 1rem;
  min-height: 44px; font-weight: 600; cursor: pointer; }
button.ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
button.small { min-height: 36px; padding: .35rem .7rem; font-size: .88rem; }
button.danger { background: transparent; color: var(--negative); border: 1px solid var(--negative); }
button:disabled { opacity: .5; cursor: progress; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; }

table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: .8rem; color: var(--muted); font-weight: 600; padding: .4rem; border-bottom: 1px solid var(--border); }
td { padding: .55rem .4rem; border-bottom: 1px solid #3c5650; vertical-align: top; }
td.num, th.num { text-align: right; white-space: nowrap; }
tr.cancelled td, tr.voided td { opacity: .45; text-decoration: line-through; }
tr.cancelled td.acts, tr.voided td.acts { text-decoration: none; }
.tag { display: inline-block; font-size: .75rem; padding: .1rem .5rem; border-radius: 99px; border: 1px solid var(--border);
  color: var(--muted); margin: .15rem .2rem 0 0; white-space: nowrap; }
.tag.gold { border-color: var(--gold); color: var(--gold); }
.tag.ok { border-color: var(--value); color: var(--value); }
.table-wrap { overflow-x: auto; }

.totals { display: grid; grid-template-columns: repeat(4, 1fr); gap: .6rem; position: sticky; top: 64px; z-index: 4;
  background: var(--canvas); padding: .4rem 0; margin: -.4rem 0; }
.metric { background: var(--panel); border: 2px solid var(--outline); border-radius: var(--radius); padding: .6rem .8rem; }
.metric small { display: block; }
.metric strong { font-size: 1.35rem; font-variant-numeric: tabular-nums; }
.metric.balance strong { color: var(--gold); }
.list-item { display: flex; justify-content: space-between; gap: 1rem; padding: .7rem .2rem; border-bottom: 1px solid #3c5650;
  text-decoration: none; color: var(--text); align-items: center; }
.list-item:hover { background: #ffffff0a; }
.hint { font-size: .85rem; color: var(--muted); margin: .2rem 0 .6rem; }
.calc { background: var(--panel); border-radius: 8px; padding: .5rem .7rem; font-size: .9rem; color: var(--value); }
details > summary { cursor: pointer; color: var(--gold); font-weight: 600; margin: .3rem 0; }

#toast { position: fixed; left: 50%; bottom: 1.2rem; transform: translateX(-50%); max-width: min(92vw, 560px);
  background: var(--panel); border: 2px solid var(--gold); color: var(--text); padding: .7rem 1rem; border-radius: 10px;
  display: none; z-index: 20; }
#toast.show { display: block; } #toast.error { border-color: var(--negative); color: var(--negative); }
dialog { background: var(--panel); color: var(--text); border: 2px solid var(--outline); border-radius: var(--radius);
  padding: 1.2rem; width: min(92vw, 520px); }
dialog::backdrop { background: #000a; }

@media (max-width: 760px) {
  .totals { grid-template-columns: repeat(2, 1fr); top: 60px; }
  main { padding: .6rem; }
}

/* Invoice: papel branco, para imprimir */
.invoice { background: #fff; color: #1b2b29; border-radius: 6px; padding: 2rem; max-width: 820px; margin: 0 auto; }
.invoice h1 { font-family: var(--heading); color: #193d40; }
.invoice table td, .invoice table th { border-color: #d5dfdb; color: #1b2b29; }
.invoice .note { margin-top: 1rem; font-size: .9rem; border-top: 1px solid #d5dfdb; padding-top: .6rem; }
.invoice .right { text-align: right; }
@media print {
  .top, .dev-note, .no-print, #toast { display: none !important; }
  html, body { background: #fff; }
  main { padding: 0; max-width: none; }
  .invoice { padding: 0; }
}

/* Quadro recolhível: o título funciona como botão de abrir/fechar */
.section-toggle > summary { list-style: none; display: flex; align-items: baseline; gap: .8rem; flex-wrap: wrap; color: var(--text); margin: 0; }
.section-toggle > summary::-webkit-details-marker { display: none; }
.section-toggle > summary h2 { margin: 0; }
.section-toggle > summary h2::before { content: '▸ '; color: var(--gold); }
.section-toggle[open] > summary h2::before { content: '▾ '; }
.section-toggle[open] > summary { margin-bottom: .6rem; }
.section-toggle[open] > summary small { display: none; }

/* Navegação e quadro da oficina */
.nav { display: flex; gap: .3rem; }
.navlink { padding: .45rem .9rem; border-radius: 8px; color: var(--muted); text-decoration: none; border: 1px solid transparent; }
.navlink.active { color: var(--text); border-color: var(--outline); background: var(--emphasis); }
.stages { display: grid; grid-template-columns: repeat(5, 1fr); gap: .6rem; }
.stage { background: var(--panel); color: var(--text); border: 2px solid var(--border); border-radius: var(--radius);
  padding: .7rem; text-align: left; display: grid; gap: .2rem; min-height: 86px; }
.stage strong { font-size: 1.6rem; }
.stage small { color: var(--muted); }
.stage.active { border-color: var(--gold); background: var(--emphasis); }
.tag.late { border-color: var(--negative); color: var(--negative); }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #ffffff0a; }
@media (max-width: 900px) { .stages { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 560px) { .stages { grid-template-columns: repeat(2, 1fr); } .nav { order: 3; width: 100%; } .top { flex-wrap: wrap; } }
.brand, .navlink { white-space: nowrap; }
.stage .tag { justify-self: start; }
.top-actions, .who { white-space: nowrap; }
@media (max-width: 980px) { .who-label { display: none; } .top { padding: .6rem .8rem; gap: .6rem; } }

/* Celular: topo compacto, cartões de estágio baixos, tabelas "stack" viram cartões empilhados */
@media (max-width: 600px) {
  .top { position: static; padding: .5rem .7rem; }
  .brand small { display: none; }
  .brand strong { font-size: 1.15rem; }
  .top-actions button, .navlink { padding: .35rem .6rem; min-height: 36px; font-size: .9rem; }
  .dev-note { padding: .25rem .7rem; font-size: .78rem; }
  .totals { top: 0; }
  .stages { grid-template-columns: repeat(2, 1fr); gap: .4rem; }
  .stage { min-height: 0; padding: .45rem .6rem; grid-template-columns: 1fr auto; align-items: center; }
  .stage strong { font-size: 1.25rem; grid-row: 1 / span 2; grid-column: 2; }
  .stage small { font-size: .8rem; }
  section, .card { padding: .8rem; }
  table.stack thead { display: none; }
  table.stack, table.stack tbody { display: block; }
  table.stack tr { display: grid; grid-template-columns: 1fr auto; gap: .2rem .6rem; padding: .7rem .2rem;
    border-bottom: 1px solid #3c5650; }
  table.stack td { display: block; border: 0; padding: 0; }
  table.stack td:nth-child(2) { grid-column: 1 / -1; grid-row: 2; }
  table.stack td:nth-child(3) { grid-row: 3; }
  table.stack td:nth-child(4) { grid-row: 1; grid-column: 2; text-align: right; }
  table.stack td[data-label]::before { content: attr(data-label) ': '; color: var(--muted); font-size: .8rem; }
}

/* Assinatura e etiqueta */
dialog.wide { width: min(96vw, 980px); max-height: 94vh; }
.signature-pad { width: 100%; height: auto; aspect-ratio: 900 / 260; background: #fff; border-radius: 10px;
  border: 2px solid var(--gold); touch-action: none; display: block; }
.agreement { background: var(--warning-panel); color: var(--warning); padding: .7rem .9rem; border-radius: 8px; }
.sig-summary td { border-color: #3c5650; }
.sig-thumb { width: 150px; height: 44px; object-fit: contain; background: #fff; border-radius: 6px; cursor: pointer; }
.label-preview { width: 100%; max-width: 480px; border: 1px solid var(--border); border-radius: 6px; background: #fff; }
td.right, .right { text-align: right; }

/* Fotos */
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .6rem; margin-top: .8rem; }
.photo { margin: 0; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; cursor: pointer; }
.photo img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; display: block; background: #000; }
.photo figcaption { padding: .4rem .5rem; font-size: .85rem; display: grid; gap: .1rem; }
.photo.voided img { opacity: .35; }
.photo-full { width: 100%; max-height: 70vh; object-fit: contain; background: #000; border-radius: 8px; }

/* Logomarca: preta no papel; branca no topo escuro (inverte e some o fundo) */
.brand { flex-direction: row; align-items: center; gap: .7rem; }
.brand > span { display: flex; flex-direction: column; }
.brand-logo { height: 46px; width: auto; filter: invert(1); mix-blend-mode: screen; }
.login-logo { display: block; width: 180px; margin: .2rem auto 1rem; filter: invert(1); mix-blend-mode: screen; }
.invoice-logo { width: 170px; height: auto; display: block; }
@media (max-width: 600px) { .brand-logo { height: 36px; } }

/* Family Works */
.fw-label-photo { max-width: 100%; max-height: 260px; object-fit: contain; border-radius: 8px; background: #000; }
textarea { background: var(--field); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: .6rem .7rem; width: 100%; font: inherit; }
tr.subtotal td { border-top: 1px solid var(--border); color: var(--gold); }
.print-only { display: none; }
@media print {
  body.printing-statement main > :not(.statement-section) { display: none !important; }
  body.printing-statement .statement-section { border: 0; background: #fff; color: #000; }
  body.printing-statement .statement-section * { color: #000 !important; }
  body.printing-statement .print-only { display: block; }
  .no-print { display: none !important; }
}

/* Topo: com a logomarca, o texto pequeno repetido sai; em telas médias o menu fica numa linha própria */
.brand small { display: none; }
@media (max-width: 1000px) {
  .top { flex-wrap: wrap; row-gap: .4rem; }
  .nav { order: 3; width: 100%; justify-content: flex-start; }
  .top-actions { margin-left: auto; }
}
.late-text { color: var(--negative); }

/* Linhas compactas (preço do dia, recebidos): no celular, no máximo 2 linhas por item */
.compact-row { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: .25rem .8rem;
  padding: .5rem 0; border-bottom: 1px solid #3c5650; }
.compact-main { min-width: 0; flex: 1 1 220px; }
.compact-main .value, .compact-acts .value { font-variant-numeric: tabular-nums; }
.compact-acts { display: flex; flex-wrap: wrap; gap: .35rem; align-items: center; justify-content: flex-end; }
.meta { font-size: .8rem; color: var(--muted); line-height: 1.3; }
@media (max-width: 600px) { .compact-acts button.small { min-height: 34px; padding: .25rem .55rem; font-size: .82rem; } }
@media (max-width: 600px) {
  .totals { grid-template-columns: repeat(4, 1fr); gap: .3rem; }
  .totals .metric { padding: .3rem .4rem; border-width: 1px; border-radius: 8px; }
  .totals .metric small { font-size: .62rem; line-height: 1.1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .totals .metric strong { font-size: .88rem; }
  .compact-acts { justify-content: flex-start; }
}

/* Celular: peças/serviços e pagamentos viram mini-cartões (nada de arrastar para o lado) */
@media (max-width: 600px) {
  table.lines-table thead { display: none; }
  table.lines-table, table.lines-table tbody, table.pay-table, table.pay-table tbody { display: block; }
  table.lines-table tr { display: grid; grid-template-columns: 1fr auto; gap: .25rem .6rem; padding: .7rem 0; border-bottom: 1px solid #3c5650; }
  table.lines-table td { display: block; border: 0; padding: 0; min-width: 0; }
  table.lines-table td:nth-child(1) { grid-column: 1; grid-row: 1; }
  table.lines-table td:nth-child(3) { grid-column: 2; grid-row: 1; text-align: right; font-weight: 600; }
  table.lines-table td:nth-child(2) { grid-column: 1; grid-row: 2; }
  table.lines-table td:nth-child(4) { grid-column: 2; grid-row: 2; text-align: right; font-size: .82rem; color: var(--muted); }
  table.lines-table td.tax-cell::before { content: attr(data-label) ' '; }
  table.lines-table td:nth-child(5) { grid-column: 1 / -1; grid-row: 3; }
  table.lines-table td:nth-child(5) .actions { gap: .35rem; }
  table.lines-table td:nth-child(5) button.small { min-height: 34px; padding: .25rem .55rem; font-size: .82rem; }

  table.pay-table tr { display: grid; grid-template-columns: auto 1fr auto; gap: .2rem .6rem; padding: .6rem 0; border-bottom: 1px solid #3c5650; align-items: start; }
  table.pay-table td { display: block; border: 0; padding: 0; min-width: 0; }
  table.pay-table td:nth-child(1) { grid-column: 1; grid-row: 1; font-size: .85rem; color: var(--muted); }
  table.pay-table td:nth-child(2) { grid-column: 2; grid-row: 1; }
  table.pay-table td:nth-child(3) { grid-column: 3; grid-row: 1; text-align: right; font-weight: 600; }
  table.pay-table td:nth-child(4) { grid-column: 1 / -1; grid-row: 2; }
  table.pay-table td:nth-child(4) button.small { min-height: 34px; padding: .25rem .55rem; font-size: .82rem; }
}

/* A coluna principal nunca fica mais larga que a tela (o conteúdo se ajusta dentro dela) */
main { grid-template-columns: minmax(0, 1fr); }
.grid2 { grid-template-columns: repeat(auto-fit, minmax(min(320px, 100%), 1fr)); }
@media (max-width: 600px) { .row { grid-template-columns: repeat(auto-fit, minmax(min(140px, 100%), 1fr)); } }
@media (max-width: 600px) { .totals { grid-template-columns: repeat(4, minmax(0, 1fr)); } .totals .metric { min-width: 0; } }
@media (max-width: 600px) {
  .fw-statement table thead { display: none; }
  .fw-statement table, .fw-statement tbody { display: block; }
  .fw-statement tr { display: grid; grid-template-columns: 1fr auto; gap: .15rem .6rem; padding: .55rem 0; border-bottom: 1px solid #3c5650; }
  .fw-statement td { display: block; border: 0; padding: 0; min-width: 0; }
  .fw-statement tr:not(.subtotal) td:nth-child(1) { grid-column: 1; grid-row: 1; font-size: .8rem; color: var(--muted); }
  .fw-statement tr:not(.subtotal) td:nth-child(2) { grid-column: 1; grid-row: 2; font-weight: 600; }
  .fw-statement tr:not(.subtotal) td:nth-child(3) { grid-column: 2; grid-row: 1; text-align: right; font-size: .8rem; color: var(--muted); }
  .fw-statement tr:not(.subtotal) td:nth-child(4) { grid-column: 1 / -1; grid-row: 3; }
  .fw-statement tr:not(.subtotal) td:nth-child(5) { grid-column: 2; grid-row: 2; text-align: right; font-weight: 600; }
  .fw-statement tr.subtotal td:first-child { grid-column: 1; text-align: left; }
}

/* Estoque: cartões por grupo (clicáveis) e lista compacta */
.stock-cards { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: .5rem; margin: .6rem 0; }
.stock-card { text-decoration: none; color: var(--text); min-width: 0; }
.stock-card small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stock-card.active { border-color: var(--gold); }
.stock-row { text-decoration: none; color: var(--text); }
.stock-row:hover { background: #ffffff0a; }
@media (max-width: 700px) { .stock-cards { grid-template-columns: repeat(3, minmax(0, 1fr)); } .stock-card strong { font-size: 1rem; } }

/* Menu com 6 abas: no celular quebra em duas linhas em vez de esconder abas */
@media (max-width: 700px) { .nav { flex-wrap: wrap; row-gap: .3rem; } .navlink { padding: .3rem .55rem; font-size: .88rem; } }
/* Metal: valor e custo lado a lado; recuperação embaixo, linha inteira */
.metal-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.metal-cards strong { overflow-wrap: anywhere; }
@media (max-width: 700px) {
  .metal-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metal-cards strong { font-size: 1.1rem; }
}
.buy-row { align-items: end; border-bottom: 1px solid #3c5650; padding-bottom: .4rem; margin-bottom: .4rem; }
.buy-row .value { display: block; padding: .55rem 0; font-variant-numeric: tabular-nums; }
.photo-thumb { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; cursor: pointer; border: 1px solid var(--outline); }
.fin-cards { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.fin-cards strong { overflow-wrap: anywhere; }
@media (max-width: 700px) { .fin-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); } .fin-cards strong { font-size: 1.05rem; } }
.chart-box { position: relative; height: 230px; margin-bottom: 1rem; }
.value.debt { color: #e66767; }
.fin-debt { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.fin-debt strong { color: #e66767; }
.acct-link, .detail-row { text-decoration: none; color: var(--text); }
a.metric small::after { content: ' ›'; color: var(--gold); }
.meta.late { color: #e66767; }
.meta.soon { color: var(--gold); }
.bank-accts { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.bank-row { border-bottom: 1px solid #3c5650; padding-bottom: .4rem; margin-bottom: .4rem; }
.bank-row .compact-row { border-bottom: 0; }
.bank-acts { gap: .3rem; }
.bank-acts button.small { font-size: .8rem; padding: .25rem .5rem; }
button.ghost.active { border-color: var(--gold); color: var(--gold); }
.fin-assets { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.fin-assets strong { color: var(--value); }
