:root {
  --bg: #faf7f0; --surface: #ffffff; --surface-2: #f3eee2; --ink: #1f2a44; --muted: #5e5e5e; --line: #e4ddcc;
  --primary: #1d3a8a; --primary-bg: #1d3a8a; --primary-ink: #ffffff; --primary-soft: #e6ebf7; --gold: #c9962b; --gold-soft: #f6ecd4; --gold-ink: #6b4a0f;
  --ok: #1e7a46; --ok-soft: #e3f3e9; --warn: #9a5800; --warn-soft: #fdf0d9; --bad: #b42318; --bad-soft: #fde8e6;
  --field-bg: #ffffff; --field-line: #958b74; --focus: #4a6fd6; --has-bg: #fff7e2; --bar-bg: rgba(250,247,240,.97);
  --top-bg: #1d3a8a; --top-ink: #ffffff; --toast-bg: #1f2a44; --sel-bg: #eef2fb; --sel-chg: #f3e7c6; --sel-line: #c9d4f0;
  --radius: 12px; --shadow: 0 1px 2px rgba(31,42,68,.06), 0 2px 8px rgba(31,42,68,.05);
  --nav-h: 64px; --fs-scale: 1; color-scheme: light;
}
/* Modo escuro: automático (segue o aparelho) ou escolhido em «A minha conta» */
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) {
  --bg: #11151f; --surface: #1a2030; --surface-2: #242b3d; --ink: #e9edf6; --muted: #aeb6c8; --line: #343c52;
  --primary: #a9c0ff; --primary-bg: #3657c4; --primary-ink: #ffffff; --primary-soft: #223154; --gold: #e0b04f; --gold-soft: #3a3020; --gold-ink: #f3d9a0;
  --ok: #74d6a0; --ok-soft: #173123; --warn: #f2b860; --warn-soft: #3a2c14; --bad: #ff9a90; --bad-soft: #3f1e1e;
  --field-bg: #121826; --field-line: #66708a; --focus: #8fb0ff; --has-bg: #2a2618; --bar-bg: rgba(17,21,31,.97);
  --top-bg: #161c2b; --top-ink: #e9edf6; --toast-bg: #e9edf6; --sel-bg: #22304f; --sel-chg: #3a3020; --sel-line: #3f5590;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 2px 8px rgba(0,0,0,.25); color-scheme: dark;
} }
:root[data-theme="dark"] {
  --bg: #11151f; --surface: #1a2030; --surface-2: #242b3d; --ink: #e9edf6; --muted: #aeb6c8; --line: #343c52;
  --primary: #a9c0ff; --primary-bg: #3657c4; --primary-ink: #ffffff; --primary-soft: #223154; --gold: #e0b04f; --gold-soft: #3a3020; --gold-ink: #f3d9a0;
  --ok: #74d6a0; --ok-soft: #173123; --warn: #f2b860; --warn-soft: #3a2c14; --bad: #ff9a90; --bad-soft: #3f1e1e;
  --field-bg: #121826; --field-line: #66708a; --focus: #8fb0ff; --has-bg: #2a2618; --bar-bg: rgba(17,21,31,.97);
  --top-bg: #161c2b; --top-ink: #e9edf6; --toast-bg: #e9edf6; --sel-bg: #22304f; --sel-chg: #3a3020; --sel-line: #3f5590;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 2px 8px rgba(0,0,0,.25); color-scheme: dark;
}
/* Contraste reforçado: texto secundário e contornos mais escuros (ou mais claros no modo escuro) */
:root[data-contrast="high"] { --muted: #333a48; --line: #b9ae94; --field-line: #4f4838; --ink: #0d1324; }
@media (prefers-color-scheme: dark) { :root[data-contrast="high"]:not([data-theme="light"]) { --muted: #dde3ef; --line: #66708a; --field-line: #aab3c8; --ink: #ffffff; } }
:root[data-theme="dark"][data-contrast="high"] { --muted: #dde3ef; --line: #66708a; --field-line: #aab3c8; --ink: #ffffff; }
* { box-sizing: border-box; }
html { font-size: calc(16px * var(--fs-scale)); }
html, body { margin: 0; background: var(--bg); color: var(--ink); -webkit-text-size-adjust: 100%; }
body { font: 1rem/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--primary); }
h1, h2, h3 { line-height: 1.2; margin: 0; }
h1 { font-size: 1.35rem; } h2 { font-size: 1.15rem; } h3 { font-size: 1rem; }
.hidden { display: none !important; }
.muted { color: var(--muted); } .small { font-size: .85rem; }
.nowrap { white-space: nowrap; }

/* estrutura */
.topbar { position: sticky; top: 0; z-index: 20; background: var(--top-bg); color: var(--top-ink); padding: calc(env(safe-area-inset-top) + 10px) 16px 10px; display: flex; align-items: center; gap: 12px; }
.topbar .brand { font-weight: 700; letter-spacing: .2px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .brand small { display: block; font-weight: 400; opacity: .8; font-size: .78rem; }
.topbar select { background: rgba(255,255,255,.14); border: 1px solid rgba(255,255,255,.45); color: var(--top-ink); border-radius: 10px; padding: 7px 10px; max-width: 46vw; width: auto; min-height: 44px; }
.topbar select option { color: var(--ink); background: var(--surface); }
main { max-width: 1100px; margin: 0 auto; padding: 16px 16px calc(var(--nav-h) + env(safe-area-inset-bottom) + 24px); }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.page-head p { margin: 4px 0 0; }

.tabbar { position: fixed; bottom: 0; left: 0; right: 0; z-index: 30; display: flex; background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; height: var(--nav-h); text-decoration: none; color: var(--muted); font-size: .72rem; font-weight: 600; }
.tabbar a svg { width: 24px; height: 24px; }
.tabbar a.on { color: var(--primary); }
.tabbar a .badge { position: absolute; transform: translate(14px, -10px); }
@media (min-width: 900px) {
  .tabbar { top: 0; bottom: 0; right: auto; width: 96px; flex-direction: column; justify-content: flex-start; padding-top: 72px; border-top: 0; border-right: 1px solid var(--line); }
  .tabbar a { flex: 0 0 auto; height: 76px; }
  .topbar, main { margin-left: 96px; }
  .topbar select { max-width: 300px; }
  main { padding-bottom: 40px; }
}

/* componentes */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card + .card { margin-top: 12px; }
.card-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.card-head h3 { flex: 1; min-width: 0; }
.card-body { padding: 12px 14px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); font-weight: 600; cursor: pointer; text-decoration: none; color: var(--ink); white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--primary-bg); border-color: var(--primary-bg); color: var(--primary-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.gold { background: var(--gold); border-color: var(--gold); color: #fff; }
.btn.danger { color: var(--bad); border-color: currentColor; }
.btn.small { min-height: 36px; padding: 0 12px; font-size: .9rem; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }
.btn svg { width: 18px; height: 18px; }
.icon-btn { width: 44px; height: 44px; display: inline-flex; align-items: center; justify-content: center; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; flex: 0 0 auto; }
.icon-btn svg { width: 20px; height: 20px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 12px; }

label.field { display: block; }
label.field > span { display: block; font-size: .85rem; font-weight: 600; margin-bottom: 4px; }
label.field > small { display: block; color: var(--muted); font-size: .8rem; margin-top: 3px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=time], input[type=search], input[type=url], select, textarea {
  width: 100%; min-height: 44px; padding: 9px 12px; border: 1px solid var(--field-line); border-radius: 10px; background: var(--field-bg); color: var(--ink);
}
textarea { min-height: 90px; resize: vertical; }
input:focus-visible, select:focus-visible, textarea:focus-visible, .btn:focus-visible, .icon-btn:focus-visible, .tabbar a:focus-visible, .chip:focus-visible, .seg button:focus-visible, .list-item:focus-visible, .plast:focus-visible { outline: 3px solid var(--focus); outline-offset: 1px; }
::placeholder { color: var(--muted); opacity: .7; }
.check { display: flex; align-items: center; gap: 10px; min-height: 40px; cursor: pointer; }
.check input { width: 20px; height: 20px; accent-color: var(--primary); }
.grid2 { display: grid; gap: 12px; grid-template-columns: 1fr; }
@media (min-width: 640px) { .grid2 { grid-template-columns: 1fr 1fr; } .grid2 .full { grid-column: 1 / -1; } }

.seg { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; gap: 2px; }
.seg { flex-wrap: wrap; }
.seg button { border: 0; background: transparent; padding: 7px 12px; border-radius: 8px; font-weight: 600; font-size: .88rem; cursor: pointer; color: var(--muted); }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 6px 12px; font-size: .85rem; font-weight: 600; white-space: nowrap; cursor: pointer; }
.chip.on { background: var(--primary-bg); border-color: var(--primary-bg); color: var(--primary-ink); }
.badge { display: inline-block; min-width: 20px; padding: 1px 7px; border-radius: 999px; font-size: .75rem; font-weight: 700; background: var(--gold-soft); color: var(--gold-ink); text-align: center; }
.status { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .78rem; font-weight: 700; white-space: nowrap; }
.status.enviada { background: var(--primary-soft); color: var(--primary); }
.status.recebida { background: var(--ok-soft); color: var(--ok); }
.status.falhas { background: var(--warn-soft); color: var(--warn); }
.status.erro { background: var(--bad-soft); color: var(--bad); }
.status.teste { background: var(--surface-2); color: var(--muted); }

/* lista de produtos */
.toolbar { padding: 0 0 6px; }
@media (max-width: 420px) { .hide-xs { display: none; } }
.only-xs { display: none; }
@media (max-width: 420px) { .only-xs { display: inline; } }
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.group-title { display: flex; align-items: center; gap: 8px; margin: 18px 2px 8px; font-size: .8rem; font-weight: 800; text-transform: uppercase; letter-spacing: .6px; color: var(--primary); }
.group-title .line { flex: 1; height: 1px; background: var(--line); }
.subgroup-title { margin: 10px 4px 4px; font-size: .8rem; font-weight: 700; color: var(--muted); }
.prod { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.prod:last-child { border-bottom: 0; }
.prod .info { flex: 1; min-width: 0; }
.prod .name { font-weight: 600; }
.prod .meta { font-size: .8rem; color: var(--muted); }
.prod.has { background: var(--has-bg); }
.qty { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
.qty input { width: 4.6rem; text-align: center; padding: 8px 4px; }
.qty select { width: 7rem; min-width: 0; padding: 8px 6px; }
.qty .icon-btn { width: 44px; height: 44px; }
.qty input.bad, input.bad { border-color: var(--bad); box-shadow: 0 0 0 2px var(--bad-soft); }
/* Lista de encomenda: [produto] [nota] [última encomenda] [quantidade] — no computador em colunas, no telemóvel por baixo do nome */
.prod { scroll-margin: 96px 0 160px; }
.prod .ctl { display: flex; align-items: center; gap: 10px; flex: 0 0 auto; }
.prod .pnote { width: 14rem; min-height: 44px; }
.prod .pnote.slot-empty { display: inline-block; }
.plast { width: 9.5rem; min-height: 44px; display: flex; flex-direction: column; align-items: flex-end; justify-content: center; text-align: right; border: 1px dashed var(--field-line); border-radius: 10px; background: transparent; color: var(--ink); padding: 2px 8px; cursor: pointer; line-height: 1.2; }
.plast:hover { background: var(--surface-2); }
.plast b { font-weight: 700; }
.plast small { color: var(--muted); font-size: .78rem; }
.plast.none { border-color: transparent; color: var(--muted); cursor: default; }
.plast .plast-l { display: none; }
.prod-head { display: flex; align-items: center; gap: 10px; padding: 6px 12px 4px; border-bottom: 1px solid var(--line); font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); }
.prod-head .h-note { width: 14rem; }
.prod-head .h-last { width: 9.5rem; text-align: right; }
.prod-head .h-qty { width: calc(88px + 4.6rem + 7rem + 12px); text-align: center; }
.cmp-row select { width: auto; max-width: 100%; flex: 1 1 220px; }
.note-line { display: flex; gap: 6px; align-items: flex-start; margin-top: 4px; padding: 4px 8px; border-radius: 8px; background: var(--gold-soft); color: var(--gold-ink); font-size: .85rem; font-weight: 600; }
.note-line svg { width: 16px; height: 16px; flex: 0 0 auto; margin-top: 2px; }
.prod.only-note { background: var(--surface-2); }
@media (max-width: 860px) {
  .prod { flex-wrap: wrap; }
  .prod .info { flex-basis: 100%; }
  .prod .ctl { width: 100%; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
  .prod .pnote { flex: 1 1 100%; width: auto; }
  .prod .pnote.slot-empty { display: none; }
  .plast { width: auto; flex: 1 1 auto; flex-direction: row; align-items: center; justify-content: flex-start; gap: 4px; text-align: left; }
  .plast .plast-l { display: inline; color: var(--muted); }
  .plast.none { display: none; }
  .prod-head { display: none; }
  .prod .qty { margin-left: auto; flex-wrap: nowrap; }
}
@media (max-width: 380px) { .qty select { width: 5.6rem; } .qty input { width: 3.8rem; } }
.sumbar { position: fixed; left: 0; right: 0; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); z-index: 25; padding: 8px 16px; background: var(--bar-bg); border-top: 1px solid var(--line); display: flex; gap: 10px; align-items: center; }
@media (min-width: 900px) { .sumbar { left: 96px; bottom: 0; } }
/* Ecrãs de toque: tudo o que se toca com pelo menos 44 px */
@media (pointer: coarse) {
  .btn.small { min-height: 44px; }
  .chip { min-height: 40px; padding: 8px 14px; }
  .seg button { min-height: 40px; }
  .check { min-height: 44px; }
  .check input { width: 22px; height: 22px; }
  .icon-btn { width: 44px; height: 44px; }
}

/* tabelas */
.table-wrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.t th { text-align: left; font-size: .78rem; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); padding: 8px 10px; border-bottom: 2px solid var(--line); white-space: nowrap; }
table.t td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.t td.num, table.t th.num { text-align: right; }
table.t tr.click { cursor: pointer; }
table.t tr.click:hover td { background: var(--surface-2); }
table.t input[type=number] { width: 84px; min-height: 40px; text-align: right; }
table.t input[type=text] { min-height: 40px; }
tr.bad td { background: var(--bad-soft); }
.rrow { padding: 10px 12px; border-bottom: 1px solid var(--line); }
.rrow:last-child { border-bottom: 0; }
.rrow.bad { background: var(--bad-soft); }
.rrow .name { font-weight: 600; margin-bottom: 6px; }
.rgrid { display: grid; grid-template-columns: 1fr 1fr 1.3fr 2fr; gap: 8px; }
.rgrid.rgrid-n { grid-template-columns: minmax(160px, 1fr) 3fr; }
.rgrid.rgrid-n .obs:only-child { grid-column: 1 / -1; }
.rgrid .field > span { font-size: .75rem; color: var(--muted); }
@media (max-width: 620px) { .rgrid, .rgrid.rgrid-n { grid-template-columns: 1fr 1fr; } .rgrid .obs { grid-column: 1 / -1; } }

.list-item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--line); cursor: pointer; background: none; border-left: 0; border-right: 0; border-top: 0; width: 100%; text-align: left; }
.list-item:last-child { border-bottom: 0; }
.list-item > svg { width: 20px; height: 20px; flex: 0 0 auto; color: var(--muted); }
.list-item .icon-btn svg { width: 20px; height: 20px; }
.list-item:hover { background: var(--surface-2); }
.list-item .grow .t1 { font-weight: 600; }
.list-item .grow .t2 { font-size: .85rem; color: var(--muted); }
.empty { text-align: center; padding: 36px 16px; color: var(--muted); }
.empty h3 { color: var(--ink); margin-bottom: 6px; }
.notice { padding: 10px 12px; border-radius: 10px; background: var(--gold-soft); color: var(--gold-ink); font-size: .9rem; }
.notice.info { background: var(--primary-soft); color: var(--primary); }
.notice.bad { background: var(--bad-soft); color: var(--bad); }
.notice.ok { background: var(--ok-soft); color: var(--ok); }

/* diálogo */
dialog { border: 0; border-radius: 16px; padding: 0; width: min(640px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(20,25,40,.45); }
dialog .d-head { position: sticky; top: 0; background: var(--surface); display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); z-index: 1; }
dialog .d-head h2 { flex: 1; }
dialog .d-body { padding: 16px; }
dialog .d-foot { position: sticky; bottom: 0; background: var(--surface); display: flex; gap: 8px; justify-content: flex-end; padding: 12px 16px; border-top: 1px solid var(--line); flex-wrap: wrap; }
dialog.wide { width: min(1000px, calc(100vw - 24px)); }
@media (max-width: 640px) {
  dialog { width: calc(100vw - 16px); max-width: calc(100vw - 16px); }
  dialog.full { width: 100vw; max-width: 100vw; max-height: 100dvh; height: 100dvh; border-radius: 0; margin: 0; }
}

/* entrada */
.auth { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; background: linear-gradient(180deg, var(--top-bg) 0 34%, var(--bg) 34%); }
.auth .card { width: 100%; max-width: 400px; padding: 24px; }
.auth .logo { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.auth .logo img { width: 48px; height: 48px; }
.auth .logo.brand-img { flex-direction: column; align-items: flex-start; }
.auth .logo.brand-img img { width: auto; height: auto; max-width: 220px; max-height: 72px; object-fit: contain; }
.auth .logo b { display: block; font-size: 1.2rem; }

#toast { position: fixed; left: 16px; right: 16px; margin: 0 auto; width: fit-content; max-width: min(560px, calc(100vw - 32px)); bottom: calc(var(--nav-h) + 72px + env(safe-area-inset-bottom)); background: var(--toast-bg); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-weight: 600; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 100; }
@media (max-width: 760px) { body.qe-has-sel #toast { bottom: calc(var(--nav-h) + 62px + var(--qe-selbar-h, 140px) + 16px + env(safe-area-inset-bottom)); } }
#toast.show { opacity: 1; }
#toast.bad { background: #b42318; color: #fff; }
@media (prefers-reduced-motion: reduce) { #toast { transition: none; } }

#print-area { display: none; }
@media print {
  body > *:not(#print-area) { display: none !important; }
  #print-area { display: block; color: #000; font-size: 11pt; }
  #print-area table { width: 100%; border-collapse: collapse; }
  #print-area th, #print-area td { border-bottom: 1px solid #bbb; padding: 4px 6px; text-align: left; }
  #print-area .num { text-align: right; }
  #print-area h1 { font-size: 15pt; } #print-area h2 { font-size: 12pt; margin-top: 14pt; }
}

/* edição rápida (grelha) */
.qe-tools { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 10px; }
.qe-tools input[type=search] { flex: 1 1 220px; width: auto; }
.qe-tools select { flex: 0 1 auto; width: auto; max-width: 100%; }
.qe-selbar { position: sticky; top: calc(env(safe-area-inset-top) + 62px); z-index: 15; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; background: var(--primary-soft); border: 1px solid var(--sel-line); border-radius: var(--radius); padding: 8px 10px; margin-bottom: 10px; box-shadow: var(--shadow); }
.qe-selbar .qe-n { margin-right: 4px; white-space: nowrap; }
.qe-selbar .btn svg { width: 16px; height: 16px; }
.qe-selbar .qe-bclr { width: 36px; height: 36px; order: 3; margin-left: auto; }
.qe-selbar .qe-acts { display: flex; flex-wrap: wrap; gap: 8px; order: 2; }
.qe-wrap { overflow: auto; max-height: calc(100dvh - var(--nav-h) - 150px); min-height: 220px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
table.qe { border-collapse: separate; border-spacing: 0; width: 100%; font-size: .92rem; }
table.qe th { position: sticky; top: 0; z-index: 3; background: var(--surface-2); text-align: left; padding: 0; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.qe th.num { text-align: right; }
.qe-sort { all: unset; box-sizing: border-box; display: block; width: 100%; padding: 9px 8px; font-size: .74rem; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); cursor: pointer; }
.qe-sort:hover { color: var(--ink); }
.qe-sort:focus-visible { outline: 3px solid var(--focus); outline-offset: -3px; }
table.qe td { padding: 2px 3px; border-bottom: 1px solid var(--line); background: var(--surface); vertical-align: middle; }
table.qe .qe-sel { width: 38px; text-align: center; position: sticky; left: 0; z-index: 2; }
table.qe th.qe-sel { z-index: 4; padding: 9px 0; }
table.qe td[data-col=name] { position: sticky; left: 38px; z-index: 1; box-shadow: 1px 0 0 var(--line); }
table.qe th.qe-name { position: sticky; left: 38px; z-index: 4; box-shadow: 1px 0 0 var(--line); }
table.qe .qe-tap { display: flex; align-items: center; justify-content: center; min-width: 36px; min-height: 36px; cursor: pointer; }
.qe-only-mobile { display: none; }
table.qe .qe-sel input { width: 18px; height: 18px; accent-color: var(--primary); cursor: pointer; }
table.qe td input[type=text], table.qe td select { width: 100%; min-height: 36px; padding: 6px 7px; border: 1px solid transparent; border-radius: 6px; background: transparent; }
table.qe td input[type=text]:hover, table.qe td select:hover { border-color: var(--line); }
table.qe td input[type=text]:focus, table.qe td select:focus { border-color: var(--primary); background: var(--field-bg); outline: none; box-shadow: 0 0 0 3px var(--sel-line); }
table.qe td input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--primary); display: block; margin: 0 auto; }
table.qe td input[aria-invalid=true] { border-color: var(--bad); }
table.qe td.chg { background: var(--gold-soft); }
table.qe td.qe-count { color: var(--muted); padding-right: 10px; white-space: nowrap; }
table.qe td.qe-act { width: 52px; text-align: center; }
table.qe td.qe-act .icon-btn { width: 36px; height: 36px; border-color: transparent; background: transparent; color: var(--muted); }
table.qe td.qe-act .icon-btn:hover { color: var(--bad); border-color: var(--line); }
table.qe tr.sel td { background: var(--sel-bg); }
table.qe tr.sel td.chg { background: var(--sel-chg); }
table.qe tr.new td.qe-sel { box-shadow: inset 4px 0 0 var(--ok); }
table.qe tr.del td { background: var(--bad-soft); }
table.qe tr.del td input[type=text], table.qe tr.del td select { text-decoration: line-through; color: var(--muted); }
table.qe tr.bad td[data-col=name] input { border-color: var(--bad); background: var(--field-bg); }
table.qe tr.dup td[data-col=name]::after { content: 'repetido?'; display: inline-block; margin: 0 0 2px 7px; padding: 0 6px; border-radius: 999px; font-size: .68rem; font-weight: 700; background: var(--warn-soft); color: var(--warn); }
table.qe tr.dup td[data-col=name] input { width: calc(100% - 4px); }
.qe-save { z-index: 26; }
.qe-save #qe-status { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 760px) {
  .qe-wrap { max-height: none; overflow: visible; background: transparent; border: 0; box-shadow: none; }
  table.qe, table.qe tbody { display: block; }
  table.qe thead { display: none; }
  table.qe tr { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 8px; position: relative; padding: 10px 10px 10px 10px; margin-bottom: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
  table.qe td { display: block; padding: 0; border: 0; background: transparent; position: static !important; box-shadow: none !important; }
  table.qe td::before { content: attr(data-label); display: block; font-size: .72rem; font-weight: 600; color: var(--muted); margin: 0 0 1px 8px; }
  table.qe td.qe-sel { position: absolute !important; top: 2px; left: 0; width: auto; }
  table.qe .qe-tap { min-width: 44px; min-height: 44px; }
  table.qe td.qe-sel input { width: 22px; height: 22px; }
  .qe-only-mobile { display: inline-flex; }
  table.qe td.qe-sel::before, table.qe td.qe-act::before { content: none; }
  table.qe td[data-col=name] { grid-column: 1 / -1; padding: 0 44px 0 38px; }
  table.qe td[data-col=name]::before { content: none; }
  table.qe td[data-col=name] input { font-weight: 600; font-size: 1rem; }
  table.qe td.qe-act { position: absolute !important; top: 4px; right: 4px; width: auto; }
  table.qe td[data-col=active] input { margin: 8px 0 0 8px; }
  table.qe td.qe-count { text-align: left; padding: 0 0 0 8px; }
  table.qe td input[type=text], table.qe td select { border-color: var(--field-line); background: var(--field-bg); }
  table.qe tr.sel { border-color: var(--primary); box-shadow: 0 0 0 2px var(--sel-line); }
  table.qe tr.sel td, table.qe tr.del td, table.qe td.chg { background: transparent; }
  table.qe td.chg input, table.qe td.chg select { background: var(--gold-soft); }
  table.qe tr.del { background: var(--bad-soft); }
  table.qe tr.new { border-left: 4px solid var(--ok); }
  table.qe tr.new td.qe-sel { box-shadow: none; }
  table.qe tr.dup td[data-col=name]::after { margin: 4px 0 0 8px; }
  /* no telemóvel a barra da seleção fica por cima da barra de gravar, numa só linha que desliza */
  .qe-selbar { position: fixed; top: auto; left: 8px; right: 8px; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 62px); z-index: 27; margin: 0; box-shadow: 0 6px 20px rgba(31,42,68,.18); }
  .qe-selbar .qe-n { order: 1; }
  .qe-selbar .qe-bclr { order: 2; }
  .qe-selbar .qe-acts { order: 3; width: 100%; gap: 6px; }
  .qe-selbar .qe-acts .btn { flex: 1 1 auto; padding: 0 10px; }
  .qe-spacer { height: 200px !important; }
}

/* «Fornecedor…» / «Tipologia…» (lista com pesquisa) */
.as-list { margin-top: 10px; max-height: min(52dvh, 420px); overflow-y: auto; }
.as-list .list-item { min-height: 48px; }
.as-list .list-item.on { background: var(--primary-soft); }
.as-list .list-item.on .t1 { color: var(--primary); font-weight: 700; }
.as-list .list-item > svg { color: var(--primary); }
.as-list .as-new { color: var(--ok); }
.as-list .as-new > svg { color: var(--ok); }
.qe-tools select#qe-sortsel { flex: 0 1 auto; }
.qe-selbar #qe-bgap { order: 1; }

/* Apagar produtos */
.dp-modes { display: grid; gap: 6px; }
.dp-mode { display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; background: var(--surface); }
.dp-mode:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); font-weight: 600; }
.dp-list { max-height: min(320px, 42vh); overflow: auto; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.dp-item { display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 6px 12px; border-bottom: 1px solid var(--line); cursor: pointer; }
.dp-item:last-child { border-bottom: 0; }
.dp-item .t1 { display: block; }
.dp-item:has(input:checked) { background: var(--bad-soft); }

/* Copiar a lista para outro estabelecimento */
.cp-set { border: 0; margin-inline: 0; margin-bottom: 0; padding: 0; min-width: 0; }
.cp-set legend { font-weight: 600; font-size: .9rem; margin-bottom: 6px; padding: 0; }
.dp-mode .grow { flex: 1; min-width: 0; }

/* Cabeçalho com o logótipo */
.topbar .brand { display: flex; align-items: center; gap: 10px; white-space: normal; }
.topbar .brand-logo { height: 36px; width: auto; max-width: 110px; object-fit: contain; flex: 0 0 auto; border-radius: 6px; background: #fff; padding: 2px 4px; }
.topbar .brand-txt { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 420px) { .topbar .brand-logo { height: 30px; max-width: 80px; } }
.logo-box .lbl { display: block; font-size: .85rem; font-weight: 600; margin-bottom: 6px; }
.logo-prev { min-width: 120px; min-height: 56px; display: flex; align-items: center; justify-content: center; padding: 6px 10px; border: 1px dashed var(--field-line); border-radius: 10px; background: #fff; }
.logo-prev img { max-height: 56px; max-width: 200px; object-fit: contain; }
.logo-prev .muted { color: #5e5e5e; }

/* Ordem dos fornecedores */
.so-list { list-style: none; margin: 12px 0 0; padding: 0; }
.so-row { border-bottom: 1px solid var(--line); background: var(--surface); }
.so-row:last-child { border-bottom: 0; }
.so-head { display: flex; align-items: center; gap: 8px; padding: 6px 10px; }
/* Tipologias dentro do fornecedor e produtos dentro da tipologia: listas encaixadas, com recuo */
.so-sub { margin: 0 10px 10px 46px; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.so-sub .so-sub { margin-left: 36px; }
.so-sub .so-head { padding: 4px 8px; }
.so-p .so-name .t1 { font-weight: 500; }
.so-subbar { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 8px; margin: 0 10px 6px 46px; }
.so-subbar > .grow { min-width: 0; overflow-wrap: anywhere; }
@media (max-width: 420px) { .so-subbar > .grow { flex-basis: 100%; } }
@media (max-width: 340px) { .so-sub .so-grip { width: 20px; } .so-sub .so-pos { width: 2.5rem !important; } .so-sub .so-head { gap: 4px; padding: 4px; } }
.so-sub .so-subbar { margin-left: 36px; }
.so-tog { display: flex; align-items: center; gap: 6px; background: none; border: 0; padding: 4px 0; text-align: left; color: inherit; font: inherit; cursor: pointer; min-height: 44px; }
.so-chev { display: inline-flex; flex: 0 0 auto; color: var(--muted); transition: transform .15s ease; }
.so-chev svg { width: 18px; height: 18px; }
.so-row.open > .so-head .so-chev { transform: rotate(90deg); }
.so-lbl { min-width: 0; }
.so-pos-fixed { display: inline-flex; align-items: center; justify-content: center; width: 3.4em; flex: 0 0 auto; }
@media (prefers-reduced-motion: reduce) { .so-chev { transition: none; } }
.so-row.dragging { opacity: .85; box-shadow: 0 6px 18px rgba(0,0,0,.2); position: relative; z-index: 2; border-radius: 10px; outline: 2px solid var(--primary); }
.so-grip { display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 44px; color: var(--muted); cursor: grab; touch-action: none; flex: 0 0 auto; }
.so-grip svg { width: 20px; height: 20px; fill: currentColor; stroke: none; }
.so-row.dragging .so-grip { cursor: grabbing; }
.so-pos { width: 3.4em !important; text-align: center; padding: 8px 4px !important; flex: 0 0 auto; }
.so-name .t1 { display: block; font-weight: 600; }
.so-name .t2 { display: block; font-size: .82rem; color: var(--muted); }

/* Privilégios do utilizador */
.perms-set { border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px 10px; margin: 0; min-width: 0; }
.perms-set legend { font-weight: 600; font-size: .9rem; padding: 0 4px; }
.check.perm { align-items: flex-start; padding: 4px 0; }
.check.perm input { margin-top: 2px; flex: 0 0 auto; }
.check.perm.incl { color: var(--muted); }

/* Aparência (A minha conta) */
.pref-row { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; }
.pref-row > .lbl { flex: 0 0 9em; font-weight: 600; font-size: .9rem; }
.pref-sample { padding: 10px 12px; border-radius: 10px; background: var(--surface-2); }

/* Letra grande: caixas de seleção acompanham a letra; o menu de baixo e o cabeçalho não transbordam */
.check input { width: max(20px, 1.15em); height: max(20px, 1.15em); flex: 0 0 auto; }
.tabbar a { font-size: min(.72rem, 13px); }
.tabbar a span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 2px; }
@media (max-width: 480px) {
  .topbar .brand-logo + .brand-txt { display: none; }
  .topbar select { max-width: 60vw; }
}
.sumbar > .grow { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Revisão: letra grande e ecrãs estreitos */
@media (max-width: 860px) {
  .prod .qty { max-width: 100%; min-width: 0; }
  .prod .qty input { width: auto; flex: 0 1 4.6rem; min-width: 3rem; }
  .prod .qty select { width: auto; flex: 1 1 7rem; min-width: 4.5rem; }
}
/* Enviar: «A encomendar», quantidade e unidade passam para a linha de baixo se não couberem */
.prod > .qty { flex-wrap: wrap; justify-content: flex-end; max-width: 100%; }
/* No computador com letra grande: se as colunas não couberem, a lista fica como no telemóvel */
#plist { container-type: inline-size; }
@container (max-width: 60rem) {
  .prod { flex-wrap: wrap; }
  .prod .info { flex-basis: 100%; }
  .prod .ctl { width: 100%; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
  .prod .pnote { flex: 1 1 100%; width: auto; }
  .prod .pnote.slot-empty { display: none; }
  .plast { width: auto; flex: 1 1 auto; flex-direction: row; align-items: center; justify-content: flex-start; gap: 4px; text-align: left; }
  .plast .plast-l { display: inline; color: var(--muted); }
  .plast.none { display: none; }
  .prod-head { display: none; }
  .prod .qty { margin-left: auto; flex-wrap: nowrap; max-width: 100%; min-width: 0; }
  .prod .qty input { width: auto; flex: 0 1 4.6rem; min-width: 3rem; }
  .prod .qty select { width: auto; flex: 1 1 7rem; min-width: 4.5rem; }
}
.sumbar > .grow { min-width: 4.5rem; }
.qe-save #qe-status { min-width: 5.5rem; }
/* Ordem dos fornecedores: o nome nunca fica tapado pelas setas */
.so-name { overflow-wrap: anywhere; }
.so-mv { display: flex; gap: 6px; flex: 0 0 auto; }
@media (max-width: 480px) { .so-mv { flex-direction: column; gap: 4px; } .so-pos { width: 3.2rem !important; } .so-grip { width: 28px; } .so-sub, .so-subbar { margin-left: 14px; margin-right: 6px; } .so-sub .so-sub, .so-sub .so-subbar { margin-left: 10px; } .so-head { gap: 6px; padding: 6px; } }
/* Botões desativados e separador ativo do menu bem visíveis */
.icon-btn:disabled { opacity: .4; cursor: default; }
.tabbar a.on { font-weight: 800; box-shadow: inset 0 3px 0 var(--primary); }
@media (min-width: 900px) { .tabbar a.on { box-shadow: inset 3px 0 0 var(--primary); } }
/* Caixa «incluir fornecedor» no Enviar e controlos da grelha com 44 px nos ecrãs de toque */
.inc-l { min-width: 44px; min-height: 44px; justify-content: center; }
@media (pointer: coarse) {
  table.qe td.qe-act .icon-btn, .qe-selbar .qe-bclr { width: 44px; height: 44px; }
  table.qe td input[type=checkbox] { width: 24px; height: 24px; }
}

/* Tempo real: ponto de ligação no cabeçalho e linha mudada por outra pessoa */
.live-dot { width: 12px; height: 12px; border-radius: 50%; flex: 0 0 auto; background: #9aa3b5; box-shadow: 0 0 0 2px rgba(255,255,255,.35); }
.live-dot.on { background: #3ddc84; }
.live-dot.retry { background: #f2b860; animation: live-pulse 1.4s ease-in-out infinite; }
@keyframes live-pulse { 50% { opacity: .35; } }
.prod.live-flash { animation: live-flash 1.6s ease-out; }
@keyframes live-flash { 0% { box-shadow: inset 4px 0 0 var(--ok); background: var(--ok-soft); } 100% { box-shadow: inset 4px 0 0 transparent; } }
@media (prefers-reduced-motion: reduce) { .live-dot.retry, .prod.live-flash { animation: none; } .prod.live-flash { box-shadow: inset 4px 0 0 var(--ok); } }
.live-banner { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; margin-bottom: 12px; }

/* Licença e só consulta */
.ro-hidden { display: none !important; }
.lic-banner { margin-bottom: 12px; }
.lic-banner a { color: inherit; font-weight: 700; }
.lic-dl { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; margin: 0; }
.lic-dl dt { color: var(--muted); font-size: .88rem; }
.lic-dl dd { margin: 0; font-weight: 600; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.lic-code { font: 700 1.05rem/1.2 ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .06em; padding: 4px 8px; border-radius: 8px; background: var(--surface-2); user-select: all; }
@media (max-width: 480px) { .lic-dl { grid-template-columns: 1fr; } .lic-dl dt { margin-top: 6px; } }
/* Subscrição: escolher o plano (registo) e pagar */
.plan-pick { border: 0; padding: 0; margin: 0; display: grid; gap: 8px; }
.plan-pick legend { font-weight: 600; font-size: .9rem; margin-bottom: 6px; padding: 0; }
.plan-opt { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; min-height: 44px; }
.plan-opt:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
.plan-opt input { margin-top: 3px; accent-color: var(--primary); }
.plan-opt b { display: block; }
.plan-opt small { color: var(--muted); }
.plan-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 10px; }
.plan-card { border: 1px solid var(--line); border-radius: 12px; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.plan-card.current { border-color: var(--primary); box-shadow: inset 0 0 0 1px var(--primary); }
.plan-card h3 { margin: 0; font-size: 1rem; }
.plan-card p { margin: 0; }
.plan-card .plan-now { font-size: .8rem; font-weight: 700; color: var(--primary); }
.plan-card .plan-qty input { max-width: 140px; }
.plan-card .plan-qty input[aria-invalid="true"] { border-color: var(--bad); }
.plan-btn { flex-direction: column; gap: 1px; white-space: normal; text-align: center; line-height: 1.25; padding: 6px 12px; }
.plan-btn small { font-size: .8rem; font-weight: 500; opacity: .85; }
.sub-est { padding: 6px 0; border-top: 1px solid var(--line); }
.auth-alt { border-top: 1px solid var(--line); padding-top: 12px; margin-top: 4px; }
/* Tempo real: avisos dentro da página e células mudadas por outra pessoa na edição rápida */
.live-warn { color: var(--warn) !important; font-weight: 600; }
table.qe td.remote { box-shadow: inset 0 0 0 2px var(--bad); }

/* Sair (topo), emails, anexos, cópias */
.topbar .top-out { background: transparent; border-color: rgba(255,255,255,.35); color: var(--top-ink); }
.topbar .top-out:hover { background: rgba(255,255,255,.14); }
.mail-frame { width: 100%; height: 50vh; min-height: 280px; border: 1px solid var(--line); border-radius: 10px; background: #fff; display: block; }
.prev-head { margin: 14px 0 4px; align-items: center; }
.mail-row { margin-top: 8px; align-items: center; gap: 10px; }
.mail-sum { font-size: .82rem; color: var(--primary); display: inline-flex; align-items: center; gap: 4px; }
.mail-sum svg, .file-links svg, .file-chip > svg { width: 15px; height: 15px; flex: 0 0 auto; }
.form-sub { margin: 10px 0 0; font-size: .95rem; }
.form-sub-hint { margin: 0; }
.files { list-style: none; margin: 0 0 8px; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.file-chip { display: flex; align-items: center; gap: 8px; padding: 4px 4px 4px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); min-width: 0; }
.file-chip .fc-n { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-chip .fc-x { width: 36px; height: 36px; border-color: transparent; background: transparent; color: var(--muted); }
.file-chip input[type=checkbox] { width: 20px; height: 20px; }
.fc-hint { display: block; margin-top: 6px; }
.file-links a { display: inline-flex; align-items: center; gap: 4px; }
.cc-list { max-height: 40vh; overflow: auto; display: flex; flex-direction: column; gap: 4px; margin-top: 6px; }
.seg-f { border: 0; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
@media (pointer: coarse) { .file-chip .fc-x { width: 44px; height: 44px; } }
@media (max-width: 480px) { .mail-frame { height: 45vh; } .topbar { gap: 8px; } }

/* Lista geral de produtos: marcar e atribuir a fornecedores */
.lfilt { margin-bottom: 12px; gap: 8px; flex-wrap: wrap; }
.lfilt input[type=search] { flex: 2 1 220px; width: auto; }
.lfilt select { flex: 1 1 180px; width: auto; }
.lsel-head { padding: 6px 14px; border-bottom: 1px solid var(--line); font-size: .9rem; }
.list-item.lrow { padding: 0; cursor: default; }
.lrow .lsel-hit { display: flex; align-items: center; align-self: stretch; min-width: 44px; min-height: 44px; padding: 0 8px 0 14px; cursor: pointer; }
.list-item.lrow.on { background: var(--primary-soft); }
.lrow .lsel { width: 22px; height: 22px; flex: 0 0 auto; accent-color: var(--primary); cursor: pointer; }
.lrow .li-open { flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px; padding: 12px 14px 12px 4px; background: none; border: 0; color: inherit; font: inherit; text-align: left; cursor: pointer; }
.lrow .li-open > svg { width: 20px; height: 20px; flex: 0 0 auto; color: var(--muted); }
.lrow .li-open:focus-visible { outline: 3px solid var(--focus); outline-offset: -3px; }
#lsbar { position: sticky; top: calc(env(safe-area-inset-top) + 62px); z-index: 15; }
#lsbar .qe-selbar { position: static; margin-bottom: 10px; }
@media (max-width: 760px) {
  #lsbar .qe-selbar { position: fixed; top: auto; left: 8px; right: 8px; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 8px); z-index: 27; margin: 0; }
  body.ls-has-sel main { padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + var(--ls-bar-h, 100px) + 24px); }
  body.ls-has-sel #toast { bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + var(--ls-bar-h, 100px) + 20px); }
}
.mt-def { margin-top: 6px; }
div.field > span:first-child { display: block; font-size: .85rem; font-weight: 600; margin-bottom: 4px; }
@media (max-width: 480px) { dialog .d-foot .btn { flex: 1 1 calc(50% - 8px); justify-content: center; } dialog .d-foot > .grow { display: none; } }

/* o atributo hidden ganha sempre (ex.: .check { display: flex }) */
[hidden] { display: none !important; }

/* Modelo Excel de um fornecedor */
.xl-sheet { border-top: 1px solid var(--line); padding-top: 10px; }
.xl-sf { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin: 8px 0; }
.xl-rows { max-height: 50vh; overflow: auto; }
.xl-rows select { min-width: 200px; }
tr.xl-sug td, .xl-sug-t { background: var(--gold-soft); }
.xl-cell { display: flex; gap: 6px; align-items: center; margin-bottom: 6px; flex-wrap: wrap; }
.xl-cell .xl-ref { width: 7.5em; flex: 0 0 auto; text-transform: uppercase; }
.xl-cell input[data-f=value] { flex: 1 1 200px; width: auto; }
.xl-cell select { width: auto; max-width: 40%; }
.xl-est { border-top: 1px solid var(--line); padding-top: 8px; }
.xl-est h3 { margin: 0 0 6px; font-size: .95rem; }
.xl-gridwrap { overflow: auto; max-height: 60vh; border: 1px solid var(--line); border-radius: 10px; }
.xl-grid { border-collapse: collapse; font-size: .75rem; }
.xl-grid th { position: sticky; top: 0; background: var(--surface-2); color: var(--muted); font-weight: 600; padding: 2px 6px; border: 1px solid var(--line); }
.xl-grid tbody th { position: sticky; left: 0; top: auto; }
.xl-grid td { border: 1px solid var(--line); padding: 2px 6px; white-space: nowrap; max-width: 14em; overflow: hidden; text-overflow: ellipsis; cursor: pointer; }
.xl-grid td:hover { outline: 2px solid var(--primary); outline-offset: -2px; }
.xl-grid td.g-code { background: var(--primary-soft); }
.xl-grid td.g-qty { background: var(--ok-soft, #e6f4ea); }
.xl-grid td.g-head { background: var(--gold-soft); }
.xl-grid td.g-notes { background: var(--surface-2); }
.xl-foot { align-items: flex-end; gap: 8px; flex-wrap: wrap; }
.xl-est-pick { min-width: 220px; }
@media (max-width: 620px) { .xl-sf { grid-template-columns: 1fr 1fr; } .xl-cell select { max-width: 100%; } }
.xl-file .grow > svg, .file-chip > svg { width: 18px; height: 18px; vertical-align: -3px; }
.xl-file .row { flex-wrap: wrap; gap: 8px; }
.xl-file .grow { min-width: 200px; }
.grid2 > * { min-width: 0; }
.xl-sugbar { align-items: center; gap: 8px; margin: 4px 0 8px; }
.xl-grid td:focus-visible { outline: 3px solid var(--focus); outline-offset: -3px; }

/* Encomendar: linhas mais baixas (01/12). No rato, controlos de 36 px; no toque ficam com 40 px */
.group-title { margin: 14px 2px 6px; }
.prod-head { padding: 4px 12px 3px; }
.subgroup-title { margin: 0; padding: 6px 12px 2px; font-size: .76rem; text-transform: uppercase; letter-spacing: .3px; border-bottom: 1px solid var(--line); background: var(--surface-2); }
.prod { padding: 4px 12px; gap: 10px; }
.prod .name { line-height: 1.25; }
.prod .meta { line-height: 1.2; }
.prod .qty { gap: 3px; }
.prod .qty .icon-btn { width: 36px; height: 36px; }
.prod .qty .icon-btn svg { width: 18px; height: 18px; }
.prod .qty input, .prod .qty select, .prod .pnote { min-height: 36px; height: 36px; padding-top: 4px; padding-bottom: 4px; }
.prod .plast { min-height: 36px; padding: 1px 8px; }
.prod-head .h-qty { width: calc(72px + 4.6rem + 7rem + 9px); }
@media (pointer: coarse) {
  .prod { padding: 6px 12px; }
  .prod .qty .icon-btn { width: 40px; height: 40px; }
  .prod .qty input, .prod .qty select, .prod .pnote { min-height: 40px; height: 40px; }
  .prod .plast { min-height: 40px; height: auto; }
  .prod-head .h-qty { width: calc(80px + 4.6rem + 7rem + 9px); }
}

/* Barra de cima: tamanho da letra e claro/escuro */
.top-prefs { position: relative; display: flex; align-items: center; gap: 6px; flex: 0 0 auto; }
.topbar .top-btn { background: transparent; border-color: rgba(255,255,255,.35); color: var(--top-ink); }
.topbar .top-btn:hover { background: rgba(255,255,255,.14); }
.topbar .top-btn[aria-expanded="true"] { background: rgba(255,255,255,.22); }
.top-aa { font-weight: 800; font-size: 1.05rem; line-height: 1; letter-spacing: -.5px; }
.top-aa small { font-size: .72rem; font-weight: 800; }
.top-pop { position: absolute; top: calc(100% + 8px); right: 0; z-index: 40; min-width: 190px; padding: 6px; display: flex; flex-direction: column; gap: 2px; background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,.2); }
.top-pop button { display: flex; align-items: center; gap: 10px; min-height: 40px; padding: 4px 10px; border: 0; border-radius: 8px; background: transparent; color: inherit; font: inherit; text-align: left; cursor: pointer; }
.top-pop button:hover { background: var(--surface-2); }
.top-pop button.on { background: var(--gold-soft, var(--surface-2)); font-weight: 700; }
.top-pop button:focus-visible { outline: 3px solid var(--focus); outline-offset: -2px; }
.top-pop-a { display: inline-block; width: 1.6rem; text-align: center; font-weight: 700; line-height: 1; }
@media (max-width: 480px) {
  .topbar .icon-btn { width: 40px; height: 40px; }
  .top-prefs { gap: 4px; }
  .topbar select { flex: 0 1 auto; min-width: 5.5rem; max-width: min(calc(100vw - 230px), 34vw); min-height: 40px; }
  .topbar .brand { min-width: 64px; }
  .topbar .brand-logo { flex: 0 1 auto; min-width: 0; }
}
/* Larguras médias (tablet, janela estreita, letra grande): nome, última encomenda e quantidade numa só linha; a nota, se houver, por baixo */
@container (min-width: 38rem) and (max-width: 60rem) {
  .prod { flex-wrap: wrap; row-gap: 4px; }
  .prod .info { flex: 1 1 8rem; flex-basis: 8rem; }
  .prod .ctl { display: contents; }
  .prod .pnote { order: 5; flex: 1 1 100%; width: auto; }
  .prod .pnote.slot-empty { display: none; }
  .prod .plast { width: 9.5rem; flex: 0 0 auto; flex-direction: column; align-items: flex-end; justify-content: center; text-align: right; gap: 0; }
  .prod .plast .plast-l { display: none; }
  .prod .plast.none { display: flex; }
  .prod .qty { margin-left: 0; flex: 0 0 auto; flex-wrap: nowrap; }
  .prod .qty input { width: 4.6rem; flex: none; }
  .prod .qty select { width: 7rem; flex: none; }
  .prod-head { display: flex; }
  .prod-head .h-note { display: none; }
}
/* Telemóvel: nome por cima e controlos por baixo, mais juntos */
@container (max-width: 38rem) { .prod .info { flex-basis: 100%; } .prod { row-gap: 4px; } .prod .ctl { gap: 6px; } }
/* Telemóvel: a última encomenda (compacta) ao lado da quantidade, numa só linha */
@container (max-width: 38rem) {
  .prod .ctl { flex-wrap: wrap; justify-content: flex-end; }
  .prod .plast { flex: 1 1 auto; min-width: 5rem; max-width: none; width: auto; flex-direction: column; align-items: flex-start; justify-content: center; gap: 0; text-align: left; padding: 1px 6px; }
  .prod .plast small { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .prod .plast .plast-l { display: none; }
  .prod .plast b { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .88rem; }
  .prod .qty { flex: 1 1 auto; justify-content: flex-end; }
  .prod .qty select { flex: 1 1 6.6rem; min-width: 4.2rem; max-width: 10rem; }
  .prod .qty input { flex: 0 1 3.2rem; min-width: 2.8rem; }
}
/* Telemóveis muito estreitos (até 360 px): barra de cima mais apertada, sem sair do ecrã */
@media (max-width: 360px) {
  .topbar { gap: 6px; padding-left: 10px; padding-right: 10px; }
  .topbar .brand { min-width: 40px; }
  .topbar select { min-width: 4.5rem; padding-left: 6px; padding-right: 4px; }
}
/* Foco do teclado visível na barra de cima (o contorno azul não se via no fundo azul) */
.topbar .icon-btn:focus-visible, .topbar select:focus-visible { outline-color: var(--top-ink); box-shadow: 0 0 0 1px var(--top-bg); }
/* Faturas (InvoiceXpress): número das que estão por resolver no separador do gestor; a lista do cliente */
.g-tabs a .badge { margin-left: 6px; }
table.t.sub-fat td { vertical-align: top; }
table.t.sub-fat td .btn { white-space: nowrap; }
table.t.sub-fat td.num, table.t td.fat-valor { white-space: nowrap; }
@media (max-width: 560px) { table.t.sub-fat .fat-per { display: none; } table.t.sub-fat td, table.t.sub-fat th { padding-left: 3px; padding-right: 3px; } }
table.t.sub-fat th { white-space: normal; }
@media (max-width: 560px) { table.t.sub-fat { font-size: .85rem; } table.t.sub-fat .status { white-space: normal; } table.t.sub-fat td .btn.small { padding-left: 8px; padding-right: 8px; } }
