/* ==========================================================================
   Giants — painel de administração
   Base a preto e branco. As cores de acento só dão significado:
   verde = pago/concluído, âmbar = à espera/aviso, vermelho = atraso/erro, azul = informação.
   Índice: 1 variáveis · 2 base · 3 entrada · 4 estrutura (topo, menu, conteúdo) · 5 cabeçalho do ecrã
   6 cartões e grelhas · 7 botões · 8 etiquetas · 9 tabelas · 10 formulários · 11 avisos e etapas
   12 ecrãs (hoje, KPIs, caixa de saída, clientes, impostos, simulação, folha de cálculo…)
   13 diálogos e envio · 14 assistente · 15 utilitários · 16 responsivo · 17 impressão
   ========================================================================== */

/* ---------- 1. variáveis ---------- */
:root {
  --ink: #111111; --ink-2: #333333; --ink-3: #5f5f5f; --ink-4: #8a8a8a;
  --white: #ffffff; --bg: #f2f3f4; --surface: #ffffff; --soft: #f7f7f8; --soft-2: #efeff1; --hover: #f1f3f6;
  --line: #e2e3e5; --line-2: #cfd1d4; --line-3: #b4b6ba;
  --green: #1f7a4d; --green-bg: #e7f4ec; --green-ink: #145c38; --green-line: #b5d9c4;
  --amber: #b26b00; --amber-bg: #fdf2df; --amber-ink: #6e4200; --amber-line: #efd09a;
  --red: #b42318; --red-bg: #fdecea; --red-ink: #8c1b12; --red-line: #f1bfb9;
  --blue: #1f5fbf; --blue-bg: #e9f0fb; --blue-ink: #17468f; --blue-line: #c0d4f2;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, "Roboto Mono", monospace;
  --fs: 15px; --fs-table: 14px; --fs-label: 14px; --fs-small: 13px;
  --fs-h1: 28px; --fs-h2: 18px; --fs-h3: 16px;
  --radius: 8px; --radius-sm: 6px; --pill: 999px;
  --top-h: 76px; --side-w: 260px; --content-max: 1600px;
  --gap: 24px; --pad: 24px; --field-h: 44px; --btn-h: 40px; --btn-h-sm: 34px;
  --asst-w: clamp(480px, 34vw, 680px);
  --shadow: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .18);
  --focus: 0 0 0 2px var(--white), 0 0 0 4px var(--ink);
}

/* ---------- 2. base ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body { font-family: var(--font); font-size: var(--fs); line-height: 1.5; color: var(--ink); background: var(--bg); font-variant-numeric: tabular-nums; -webkit-font-smoothing: antialiased; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
h1, h2, h3, h4 { font-family: var(--font); line-height: 1.3; color: var(--ink); letter-spacing: 0; }
h1 { font-size: var(--fs-h1); font-weight: 700; }
h2 { font-size: var(--fs-h2); font-weight: 650; }
h3 { font-size: var(--fs-h3); font-weight: 650; }
h4 { font-size: 15px; font-weight: 650; }
b, strong { font-weight: 650; }
small { font-size: var(--fs-small); }
code { font-family: var(--mono); font-size: 13px; }
::selection { background: var(--ink); color: var(--white); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.muted { color: var(--ink-3); }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.empty { padding: 32px 16px; text-align: center; color: var(--ink-3); font-size: var(--fs); }

/* ---------- 3. entrada (login e nova palavra-passe) ---------- */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 32px 16px; background: radial-gradient(ellipse at 50% 0%, #2c2c2c 0%, #121212 55%, #0a0a0a 100%); }
.login { width: min(480px, 92vw); background: var(--surface); border-radius: 12px; box-shadow: 0 24px 60px rgba(0, 0, 0, .5); overflow: hidden; }
.login__brand { display: flex; justify-content: center; align-items: center; padding: 40px 40px 28px; border-bottom: 1px solid var(--line); background: var(--white); }
.login__brand img { display: block; height: 90px; width: auto; max-width: 100%; object-fit: contain; }
.login__body { display: grid; gap: 18px; padding: 32px 40px 40px; }
.login__titles { display: grid; gap: 6px; text-align: center; }
.login h1 { font-size: 24px; font-weight: 700; }
.login__sub { color: var(--ink-3); font-size: 15px; }
.login label { gap: 8px; font-size: 15px; }
.login input:not([type=checkbox]) { min-height: 48px; height: 48px; font-size: 16px; padding: 0 14px; }
.login__error { min-height: 22px; color: var(--red); font-weight: 600; font-size: 14px; text-align: center; }
.login__error:empty { min-height: 0; margin-top: -18px; }
.login__hint { margin-top: -8px; font-size: 14px; color: var(--ink-3); }
.login__out { justify-self: center; font-size: 15px; }

/* ---------- 4. estrutura ---------- */
/* Barra de topo fixa a toda a largura. O logótipo fica ao centro exato da janela (50vw: também com a barra de deslocamento visível);
   as duas pontas têm a mesma largura máxima e nunca lhe tocam. */
.topbar { --brand-half: 62px; position: fixed; top: 0; left: 0; right: 0; z-index: 50; height: var(--top-h); display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 0 24px; background: var(--white); border-bottom: 1px solid var(--line); box-shadow: 0 1px 0 rgba(0, 0, 0, .02); }
.topbar__left, .topbar__right { flex: 0 1 calc(50vw - var(--brand-half) - 40px); min-width: 0; }
.topbar__left { display: flex; align-items: center; gap: 12px; }
.topbar__title { display: flex; align-items: baseline; gap: 10px; min-width: 0; font-size: 18px; font-weight: 650; white-space: nowrap; }
.topbar__group { font-size: 14px; font-weight: 600; color: var(--ink-3); }
.topbar__group::after { content: "/"; margin-left: 10px; color: var(--line-3); }
.topbar__name { overflow: hidden; text-overflow: ellipsis; }
.topbar__brand { position: absolute; top: 50%; left: 50vw; transform: translate(-50%, -50%); display: flex; justify-content: center; align-items: center; border-radius: var(--radius-sm); }
.topbar__brand img { display: block; height: 52px; width: auto; }
.topbar__brand:focus-visible { outline-offset: 4px; }
.topbar__right { display: flex; justify-content: flex-end; align-items: center; gap: 16px; }
.topbar__user { display: grid; justify-items: end; min-width: 0; max-width: 260px; padding: 4px 8px; border-radius: var(--radius-sm); text-align: right; line-height: 1.3; }
.topbar__user:hover { background: var(--soft); }
.topbar__user b, .topbar__user small { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar__user b { font-size: 14px; font-weight: 650; }
.topbar__user small { color: var(--ink-3); }
.topbar__user:has(b:empty) { display: none; }
.topbar__menu { display: none; align-items: center; gap: 8px; min-height: 44px; padding: 0 14px 0 10px; border: 1px solid var(--line-2); border-radius: var(--radius-sm); font-size: 15px; font-weight: 600; }
.topbar__menu:hover { border-color: var(--ink); }
.asst-open { display: inline-flex; align-items: center; gap: 10px; min-height: 40px; padding: 0 16px 0 8px; border: 1px solid var(--ink); border-radius: var(--radius-sm); background: var(--ink); color: var(--white); font-size: 15px; font-weight: 650; white-space: nowrap; }
.asst-open:hover { background: #2b2b2b; }
.asst-open:focus-visible { outline: none; box-shadow: var(--focus); }
.asst-open__icon { display: inline-grid; place-items: center; width: 28px; height: 26px; border-radius: 4px; background: var(--white); color: var(--ink); font-size: 13px; font-weight: 800; }

.shell { display: grid; grid-template-columns: var(--side-w) minmax(0, 1fr); min-height: 100vh; padding-top: var(--top-h); }
.side { position: sticky; top: var(--top-h); height: calc(100vh - var(--top-h)); display: flex; flex-direction: column; background: var(--ink); color: var(--white); z-index: 30; }
.side__nav { flex: 1; overflow: auto; display: grid; align-content: start; padding: 10px 0 12px; scrollbar-width: thin; scrollbar-color: #444 transparent; }
.side__nav a { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 40px; padding: 0 18px 0 21px; border-left: 3px solid transparent; font-size: 15px; color: rgba(255, 255, 255, .8); }
.side__nav a:hover { background: rgba(255, 255, 255, .08); color: var(--white); }
.side__nav a.is-on { background: rgba(255, 255, 255, .14); border-left-color: var(--white); color: var(--white); font-weight: 650; }
.side__nav a:focus-visible { outline: 2px solid var(--white); outline-offset: -3px; }
.side__nav b { min-width: 24px; padding: 0 7px; border-radius: var(--pill); background: var(--white); color: var(--ink); font-size: 13px; font-weight: 700; line-height: 22px; text-align: center; }
.side__nav b:empty { display: none; }
.nav-group { display: grid; }
.nav-group + .nav-group { margin-top: 8px; padding-top: 8px; border-top: 1px solid rgba(255, 255, 255, .12); }
.nav-group__label { display: block; padding: 6px 21px 6px; font-size: 13px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: rgba(255, 255, 255, .5); user-select: none; pointer-events: none; }
.side__foot { padding: 8px 21px; border-top: 1px solid rgba(255, 255, 255, .14); font-size: 14px; }
.side__foot a { display: inline-flex; align-items: center; gap: 6px; min-height: 36px; color: rgba(255, 255, 255, .8); }
.side__foot a:hover { color: var(--white); text-decoration: underline; }
.side__foot a:focus-visible { outline-color: var(--white); }
.nav-scrim { display: none; }

/* Área de conteúdo: largura máxima confortável, margens laterais iguais. */
.main { min-width: 0; padding: 32px 40px 96px; }
.view { max-width: var(--content-max); margin: 0 auto; }
.view > * + * { margin-top: var(--gap); }
.view > .crumb + .head { margin-top: 8px; }
.main > section, .view .review, .view > section { scroll-margin-top: calc(var(--top-h) + 16px); }

/* ---------- 5. cabeçalho de cada ecrã ---------- */
.head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 16px 24px; }
.head > div:first-child { min-width: 0; flex: 1 1 520px; }
.head h1 { font-size: var(--fs-h1); }
.head p { max-width: 920px; margin-top: 6px; color: var(--ink-3); font-size: 15px; }
.head > .actions { justify-content: flex-end; flex: 0 1 auto; padding-top: 2px; }
.head > .actions:empty { display: none; }
.crumb { display: inline-flex; align-items: center; gap: 6px; min-height: 32px; font-size: 14px; font-weight: 600; color: var(--ink-3); }
.crumb:hover { color: var(--ink); text-decoration: underline; }

/* ---------- 6. cartões e grelhas ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: var(--pad); box-shadow: var(--shadow); min-width: 0; }
.card > * + * { margin-top: 16px; }
.card > h2:first-child { margin-bottom: 0; }
.card__head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px 16px; min-height: 34px; }
.card__head > h2, .card__head > h3 { margin: 0; }
.card__head > div:first-child:not(.actions) { min-width: 0; }
.card__head small { display: block; margin-top: 4px; font-size: 14px; }
.card__head > .actions { margin-left: auto; justify-content: flex-end; }
.card__sub { margin-top: 28px !important; padding-top: 20px; border-top: 1px solid var(--line); }
h2.card__sub, h3.card__sub { font-size: var(--fs-h3); }
.section-gap { margin-top: var(--gap); }

.grid { display: grid; gap: var(--gap); align-items: stretch; }
.grid > * { min-width: 0; margin: 0; } /* tabelas largas deslocam-se dentro do cartão, não a página */
.grid--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid--4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid--wide { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); }
.grid--tight { gap: 10px; }
.grid__full { grid-column: 1 / -1; }

/* KPIs: colunas iguais, valor grande, linha de cor só com significado. */
.kpi { display: flex; flex-direction: column; gap: 6px; border-top: 4px solid var(--ink); }
.kpi > * + * { margin-top: 0; }
a.kpi:hover { background: var(--soft); border-color: var(--line-3); }
a.kpi:focus-visible { outline: none; box-shadow: var(--focus); }
.kpi > span { font-size: 14px; font-weight: 650; color: var(--ink-2); }
.kpi > b { font-size: 30px; font-weight: 700; line-height: 1.2; color: var(--ink); }
.kpi > b.kpi__text { font-size: 22px; }
.kpi > small { color: var(--ink-3); font-size: 14px; }
.kpi--ok { border-top-color: var(--green); }
.kpi--warn { border-top-color: var(--amber); }
.kpi--danger { border-top-color: var(--red); }
.kpi--info { border-top-color: var(--blue); }
.totals { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: var(--gap); }
.totals > * { margin: 0; }

/* ---------- 7. botões ---------- */
.btn { position: relative; display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: var(--btn-h); padding: 0 16px; border: 1px solid var(--line-3); border-radius: var(--radius-sm); background: var(--surface); color: var(--ink); font-size: 14px; font-weight: 600; line-height: 1.2; white-space: nowrap; text-align: center; transition: background-color .12s, border-color .12s; }
.btn:hover { border-color: var(--ink); background: var(--soft); }
.btn--primary, .btn--dark { background: var(--ink); border-color: var(--ink); color: var(--white); }
.btn--primary:hover, .btn--dark:hover { background: #2b2b2b; border-color: #2b2b2b; }
.btn--danger { color: var(--red); border-color: var(--red-line); }
.btn--danger:hover { background: var(--red-bg); border-color: var(--red); }
.btn--small { min-height: var(--btn-h-sm); padding: 0 12px; font-size: 14px; }
.btn--lg { min-height: 48px; font-size: 16px; }
.btn--block { width: 100%; }
.btn:focus-visible { outline: none; box-shadow: var(--focus); }
.btn:disabled, .btn[aria-disabled="true"] { background: var(--soft-2); border-color: var(--line); color: var(--ink-3); cursor: not-allowed; box-shadow: none; }
.btn--file { cursor: pointer; }
.btn--file input { position: absolute; inset: 0; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.btn--file:focus-visible { outline: none; box-shadow: var(--focus); }
.link-btn { padding: 0 2px; font-size: 14px; font-weight: 600; color: var(--ink-2); text-decoration: underline; text-underline-offset: 3px; }
.link-btn:hover { color: var(--ink); }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.actions--end { justify-content: flex-end; }
td .actions { flex-wrap: nowrap; }
/* Linha com campo + botões (adicionar produto, trocar cliente, ligação de rastreio): botões com a altura do campo, sem degrau. */
.actions:has(> input, > select) { align-items: stretch; }
.actions:has(> input, > select) > :is(.btn, button) { min-height: var(--field-h); }

/* ---------- 8. etiquetas (estado, origem, códigos) ---------- */
.tag { display: inline-flex; align-items: center; gap: 4px; min-height: 26px; padding: 1px 10px; border: 1px solid var(--line-2); border-radius: var(--pill); background: var(--soft-2); color: var(--ink-2); font-size: 13px; font-weight: 600; line-height: 1.3; white-space: nowrap; vertical-align: middle; }
.tag--ok { background: var(--green-bg); border-color: var(--green-line); color: var(--green-ink); }
.tag--warn { background: var(--amber-bg); border-color: var(--amber-line); color: var(--amber-ink); }
.tag--danger { background: var(--red-bg); border-color: var(--red-line); color: var(--red-ink); }
.tag--info { background: var(--blue-bg); border-color: var(--blue-line); color: var(--blue-ink); }
.tag--site, .tag--manual, .tag--painel { min-height: 24px; padding: 0 8px; border-radius: 4px; letter-spacing: .03em; text-transform: uppercase; }
.tag--site { background: var(--ink); border-color: var(--ink); color: var(--white); }
.tag--manual { background: var(--white); border-color: var(--ink); color: var(--ink); }
.tag--painel { background: var(--soft-2); border-color: var(--line-2); color: var(--ink-2); }
.doc-type { display: inline-flex; align-items: center; min-height: 24px; padding: 0 8px; border: 1px solid var(--ink); border-radius: 4px; font-size: 13px; font-weight: 700; letter-spacing: .03em; text-transform: uppercase; color: var(--ink); white-space: nowrap; }
.code { display: inline-flex; align-items: center; min-height: 24px; padding: 0 7px; border: 1px solid var(--line-3); border-radius: 4px; background: var(--soft); font-family: var(--mono); font-size: 13px; font-weight: 700; color: var(--ink); white-space: nowrap; vertical-align: middle; }
a:hover .code { background: var(--ink); border-color: var(--ink); color: var(--white); }

/* ---------- 9. tabelas ---------- */
.table-wrap { overflow: auto; max-height: min(75vh, 900px); border: 1px solid var(--line); border-radius: var(--radius-sm); overscroll-behavior-x: contain; }
table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: var(--fs-table); }
th { position: sticky; top: 0; z-index: 2; padding: 10px 14px; text-align: left; font-size: 14px; font-weight: 650; color: var(--ink-2); background: #f3f4f5; border-bottom: 1px solid var(--line-2); white-space: nowrap; }
td { height: 44px; padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:last-child > td { border-bottom: 0; }
.table-wrap tbody tr:nth-child(even) > td { background: #fbfbfc; }
tbody tr:hover > td { background: var(--hover); }
.table-wrap tbody tr:nth-child(even):hover > td { background: var(--hover); }
td small { display: block; margin-top: 2px; color: var(--ink-3); font-size: 13px; }
td a:not(.btn):hover { text-decoration: underline; }
td.right, th.right { text-align: right; }
td.right { white-space: nowrap; }
tr.is-link { cursor: pointer; }
tfoot td { font-weight: 700; border-top: 1px solid var(--ink); border-bottom: 0; background: var(--soft); }
td.details { max-width: 560px; font-size: 14px; color: var(--ink-2); overflow-wrap: anywhere; }
td.col-bar { width: 22%; min-width: 140px; }
tr.pending-ready > td:first-child { box-shadow: inset 4px 0 0 var(--green); }
tr.pending-blocked > td { color: var(--ink-3); }
tr.pending-blocked > td b { color: var(--ink-2); }
tr.pending-blocked > td:first-child { box-shadow: inset 4px 0 0 var(--amber-line); }
tr.pending-blocked .doc-type { border-color: var(--line-3); color: var(--ink-3); }
tr.is-off > td { color: var(--ink-4); }
tr.row-edit > td { padding: 16px; background: var(--soft) !important; }
/* tabela sem envolvente (documentos da venda): linhas separadas, sem cabeçalho */
.doc-table td { padding-left: 0; }
.doc-table td.right { padding-right: 0; }
.doc-table tbody tr:hover > td { background: transparent; }

/* ---------- 10. formulários ---------- */
label { display: grid; gap: 6px; align-content: start; font-size: var(--fs-label); font-weight: 600; color: var(--ink-2); }
label > small, label > .muted { font-size: 13px; font-weight: 400; }
input, select, textarea { width: 100%; min-height: var(--field-h); padding: 0 12px; border: 1px solid var(--line-3); border-radius: var(--radius-sm); background: var(--surface); font-size: 15px; font-weight: 400; color: var(--ink); }
select { padding-right: 32px; }
textarea { padding: 10px 12px; line-height: 1.5; resize: vertical; }
input:hover, select:hover, textarea:hover { border-color: var(--ink-3); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--ink); box-shadow: 0 0 0 3px rgba(17, 17, 17, .14); }
input:disabled, select:disabled, textarea:disabled { background: var(--soft-2); color: var(--ink-3); cursor: not-allowed; }
input[readonly] { background: var(--soft); }
input::placeholder, textarea::placeholder { color: var(--ink-4); }
input[type=checkbox], input[type=radio] { flex: none; width: 18px; min-height: 18px; height: 18px; padding: 0; accent-color: var(--ink); box-shadow: none; }
input[type=file] { padding: 8px; font-size: 14px; }
td input, td select { min-height: 38px; font-size: 14px; }
td input.num { width: 110px; text-align: right; }
td input.qty { width: 90px; text-align: right; }
/* Linhas de produtos (venda e fatura manual): em ecrã estreito a tabela desloca-se no cartão em vez de esmagar o nome. */
td input:is([data-l="name"], [data-ml="name"]) { min-width: 200px; }
td input:is([data-l="unit"], [data-ml="unit"]) { min-width: 140px; }
.form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px 20px; align-items: start; }
.form--1 { grid-template-columns: minmax(0, 1fr); max-width: 460px; }
.form--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form--4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.form > * { margin: 0; }
.form .is-full { grid-column: 1 / -1; }
.form > .check { align-self: end; min-height: var(--field-h); }
.form > .check.is-full { min-height: 0; }
.form > .actions.is-full, .form-actions { justify-content: flex-end; padding-top: 4px; }
.form > .actions.is-full > .muted { flex-basis: 100%; text-align: right; font-size: 14px; }
.u-self-end { align-self: end; }
.u-self-end .btn, .form .u-self-end.btn { min-height: var(--field-h); }
/* Um campo + botões numa grelha de 3 colunas (ex.: relatório da manhã): os botões ocupam as 2 colunas restantes e ficam na mesma linha. */
.form--3 > :first-child:nth-last-child(2) + .actions.u-self-end { grid-column: span 2; }
.check { display: flex; align-items: center; gap: 10px; font-size: 15px; font-weight: 500; color: var(--ink); }
.check.is-off { color: var(--ink-4); }
.field { display: grid; gap: 6px; align-content: start; }
.field__hint { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 14px; color: var(--ink-3); }
.field__hint .btn--small { min-height: var(--btn-h-sm); padding: 0 12px; }
#saleUnsaved { margin-right: auto; font-size: 15px; font-weight: 600; color: var(--amber-ink); }
#saleUnsaved:empty { display: none; }
.switch { gap: 12px; font-weight: 600; }
.switch input { position: relative; width: 44px; height: 24px; min-height: 24px; margin: 0; appearance: none; -webkit-appearance: none; border: 1px solid var(--ink-3); border-radius: var(--pill); background: var(--soft-2); cursor: pointer; flex: none; transition: background-color .15s; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: var(--white); box-shadow: 0 1px 2px rgba(0, 0, 0, .3); transition: transform .15s; }
.switch input:checked { background: var(--green); border-color: var(--green); }
.switch input:checked::after { transform: translateX(20px); }
.switch input:focus-visible { box-shadow: var(--focus); }

/* editor de linhas (fatura manual) */
.lines-editor { padding: 20px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--soft); }
.lines-editor .table-wrap { background: var(--white); }
.lines-editor td { padding: 6px 10px; }
.lines-editor td:nth-child(1) input { min-width: 220px; }
.lines-editor td:nth-child(2) input { min-width: 160px; }
.lines-editor tfoot td { padding: 12px 10px; font-size: 15px; }

/* caixa de IA (preencher com IA, ler certificado, ler lista) */
.ai-box { padding: 20px; border: 1px solid var(--blue-line); border-left: 4px solid var(--blue); border-radius: var(--radius); background: #f7faff; }
.ai-box > * + * { margin-top: 14px; }
.card > .ai-box:only-child { padding: 0; border: 0; background: transparent; }
.card.ai-box { background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--blue); }
.ai-box__head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 12px; }
.ai-box__head::before { content: "IA"; display: inline-grid; place-items: center; width: 30px; height: 26px; border-radius: 4px; background: var(--blue); color: var(--white); font-size: 13px; font-weight: 800; flex: none; }
.ai-box__head > h2, .ai-box__head > h3 { margin: 0; }
.ai-box__head > .tag { margin-left: auto; }
.ai-box textarea { background: var(--white); }

/* ---------- 11. avisos, etapas, barras ---------- */
.alerts { display: grid; gap: 10px; }
.alert { display: flex; align-items: flex-start; gap: 12px; padding: 12px 16px; border: 1px solid var(--line); border-left: 4px solid var(--ink-3); border-radius: var(--radius-sm); background: var(--soft); font-size: 15px; }
.alert--info { background: var(--blue-bg); border-color: var(--blue-line); border-left-color: var(--blue); }
.alert--warn { background: var(--amber-bg); border-color: var(--amber-line); border-left-color: var(--amber); }
.alert--danger, .alert--dup { background: var(--red-bg); border-color: var(--red-line); border-left-color: var(--red); }
.alert--danger b, .alert--dup b { color: var(--red-ink); }
.alert--dup b { white-space: normal; }
.alert--dup a { text-decoration: underline; }
a.alert:hover { filter: brightness(.97); }
a.alert:hover span { text-decoration: underline; }
.alert > b { white-space: nowrap; }
.alert > span { min-width: 0; }
.alert .actions { margin-top: 10px; }
.steps { display: flex; flex-wrap: wrap; gap: 6px; }
.steps span { display: inline-flex; align-items: center; min-height: 32px; padding: 0 12px; border: 1px solid var(--line-2); border-radius: var(--pill); background: var(--white); font-size: 14px; font-weight: 600; color: var(--ink-3); }
.steps span.is-done { background: var(--green-bg); border-color: var(--green-line); color: var(--green-ink); }
.steps span.is-done::before { content: "✓"; margin-right: 6px; }
.steps span.is-now { background: var(--ink); border-color: var(--ink); color: var(--white); }
.steps-list { display: grid; gap: 8px; padding-left: 22px; color: var(--ink-2); }
.savebar { position: sticky; bottom: 0; z-index: 5; display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 12px; margin: 24px calc(-1 * var(--pad)) calc(-1 * var(--pad)); padding: 16px var(--pad); background: rgba(255, 255, 255, .97); border-top: 1px solid var(--line); border-radius: 0 0 var(--radius) var(--radius); }
.savebar--card { margin: 0; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 -4px 16px rgba(16, 24, 40, .08); }
.bar { height: 8px; border-radius: var(--pill); background: var(--soft-2); overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--ink); border-radius: var(--pill); }

/* ---------- 12. ecrãs ---------- */
/* Hoje (relatório da manhã) */
.today { border-top: 4px solid var(--ink); }
.today__grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 16px 24px; }
.today__sec { min-width: 0; padding-top: 12px; border-top: 1px solid var(--line); }
.today__sec h3 { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; font-size: 15px; color: var(--ink); }
.today__n { min-width: 26px; padding: 0 8px; border-radius: var(--pill); background: var(--ink); color: var(--white); font-size: 13px; line-height: 22px; text-align: center; }
.today__list { display: grid; gap: 2px; margin: 0 0 6px; padding: 0; list-style: none; font-size: 14px; }
.today__list li { min-width: 0; }
.today__list a, .today__list li > span { display: block; padding: 6px 10px; border-left: 3px solid var(--line-2); border-radius: 0 4px 4px 0; overflow-wrap: anywhere; }
.today__list a:hover { border-left-color: var(--ink); background: var(--soft); }
.today__list a:hover span { text-decoration: underline; }
.today__list b { font-family: var(--mono); font-size: 13px; }

/* chave-valor */
.kv { display: grid; gap: 10px; }
.kv > div { display: grid; grid-template-columns: 200px minmax(0, 1fr); gap: 12px; align-items: baseline; }
.kv dt { font-size: 14px; font-weight: 600; color: var(--ink-3); }
.kv dd { margin: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; overflow-wrap: anywhere; }

/* WhatsApp (simulação) */
.chat { display: grid; align-content: start; gap: 10px; max-height: 560px; overflow: auto; padding: 16px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--soft); }
.bubble { max-width: 80%; padding: 10px 14px; border: 1px solid var(--line); border-radius: 12px 12px 12px 4px; background: var(--white); white-space: pre-wrap; font-size: 15px; }
.bubble--in { justify-self: end; border-radius: 12px 12px 4px 12px; background: var(--ink); border-color: var(--ink); color: var(--white); }
.bubble small { display: block; margin-top: 4px; font-size: 13px; color: var(--ink-3); }
.bubble--in small { color: rgba(255, 255, 255, .7); }

/* clientes */
.cust-card { display: grid; gap: 4px; padding: 14px 16px; border: 1px solid var(--line); border-left: 4px solid var(--ink); border-radius: var(--radius-sm); background: var(--soft); }
.cust-card > div { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.cust-card small { color: var(--ink-3); font-size: 14px; }
.cert { padding: 14px 16px; border: 1px solid var(--green-line); border-left: 4px solid var(--green); border-radius: var(--radius-sm); background: var(--green-bg); }
.cert__summary { margin-top: 6px; white-space: pre-wrap; color: var(--ink-2); font-size: 14px; }
.search { max-width: 380px; }

/* separadores */
.tabs { display: flex; flex-wrap: wrap; gap: 4px; border-bottom: 1px solid var(--line-2); }
.tabs a { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; margin-bottom: -1px; padding: 0 18px; border-bottom: 3px solid transparent; font-size: 15px; font-weight: 600; color: var(--ink-3); }
.tabs a:hover { color: var(--ink); border-bottom-color: var(--line-3); }
.tabs a.is-on { color: var(--ink); border-bottom-color: var(--ink); }
.tabs a b { min-width: 24px; padding: 0 7px; border-radius: var(--pill); background: var(--soft-2); color: var(--ink); font-size: 13px; line-height: 22px; text-align: center; }
.tabs a.is-on b { background: var(--ink); color: var(--white); }

/* caixa de saída */
.outs { display: grid; gap: 14px; }
.out { display: grid; gap: 12px; padding: 20px 24px; border: 1px solid var(--line); border-left: 4px solid var(--line-3); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.out--por_confirmar { border-left-color: var(--amber); }
.out--a_enviar { border-left-color: var(--blue); }
.out--erro { border-left-color: var(--red); }
.out--enviada { border-left-color: var(--green); }
.out--descartada { background: var(--soft); }
.out--descartada .out__subject { color: var(--ink-3); text-decoration: line-through; }
.out__head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 16px; }
.out__title { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 16px; }
.out__head small { color: var(--ink-3); font-size: 14px; }
.out__meta { display: flex; flex-wrap: wrap; gap: 8px 28px; font-size: 15px; }
.out__meta div { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.out__meta dt { font-size: 13px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--ink-3); }
.out__meta dd { margin: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.out__meta a:hover { text-decoration: underline; }
.out__subject { font-size: 16px; font-weight: 650; overflow-wrap: anywhere; }
.out details summary, .send__text summary, .toc-raw summary { width: fit-content; cursor: pointer; font-size: 14px; font-weight: 600; color: var(--ink-2); }
.out details summary:hover { color: var(--ink); text-decoration: underline; }
.out__body { margin-top: 8px; padding: 14px 16px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--soft); white-space: pre-wrap; overflow-wrap: anywhere; font-size: 15px; line-height: 1.55; }
.msg-new { padding: 20px; border: 1px solid var(--line-2); border-radius: var(--radius); background: var(--soft); }
.msg-new > * + * { margin-top: 14px; }
.msg-new input, .msg-new textarea { background: var(--white); }

/* folha de cálculo (tabela de preços e fretes) */
.sheet-card { padding: 0; overflow: hidden; }
.sheet-card > * + * { margin-top: 0; }
.sheet-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 14px 16px; background: var(--soft); border-bottom: 1px solid var(--line); }
.sheet-tools input[type=search] { width: 400px; max-width: 100%; }
.sheet-tools select { width: auto; max-width: 240px; }
.sheet-hint { margin-left: auto; font-size: 13px; color: var(--ink-3); white-space: nowrap; }
.sheet-wrap { overflow: auto; max-height: calc(100vh - var(--top-h) - 280px); min-height: 320px; background: var(--white); overscroll-behavior: contain; }
table.sheet { table-layout: fixed; border-collapse: separate; border-spacing: 0; font-size: 14px; }
.sheet th { position: sticky; top: 0; z-index: 3; padding: 0; background: #f0f1f2; border-bottom: 1px solid var(--line-3); border-right: 1px solid var(--line); font-size: 14px; color: var(--ink); }
.th-sort { display: flex; align-items: center; justify-content: space-between; gap: 4px; width: 100%; height: 40px; padding: 0 10px; font-weight: 650; text-align: left; white-space: nowrap; overflow: hidden; }
.th-sort:hover { background: #e6e8ea; }
.th-sort:focus-visible { outline: 2px solid var(--ink); outline-offset: -2px; }
.th-sort i { font-style: normal; font-size: 13px; }
.sheet th.n .th-sort { justify-content: flex-end; flex-direction: row-reverse; }
.sheet td { height: 38px; padding: 0 10px; border-bottom: 1px solid var(--line); border-right: 1px solid var(--line); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; background: var(--white); cursor: cell; scroll-margin: 44px 0 0 90px; }
.sheet td.n { text-align: right; }
.sheet td.is-ro { background: var(--soft); color: var(--ink-2); cursor: default; }
.sheet td.is-late { color: var(--red); font-weight: 600; }
.sheet td .muted { font-size: 13px; }
.sheet tbody tr:hover > td { background: #f6f8fb; }
.sheet tbody tr:hover > td.is-ro { background: var(--soft-2); }
.sheet .c-code { position: sticky; left: 0; z-index: 2; border-right: 1px solid var(--line-3); font-family: var(--mono); font-size: 13px; font-weight: 700; color: var(--ink); }
.sheet td.c-code { background: var(--soft); }
.sheet th.c-code { z-index: 4; background: #f0f1f2; }
.sheet td.c-st { padding: 0 8px; text-align: right; background: var(--white); cursor: default; }
.sheet th.c-st { background: #f0f1f2; }
.sheet td:focus { outline: none; }
.sheet td.is-active { box-shadow: inset 0 0 0 2px var(--ink); }
.sheet td.is-editing { padding: 0; overflow: visible; box-shadow: none; }
.cell-in { display: block; width: 100%; height: 37px; min-height: 0; padding: 0 8px; border: 0; border-radius: 0; outline: 2px solid var(--ink); outline-offset: -2px; background: var(--white); font-size: 14px; box-shadow: none; }
.cell-in:focus { outline: 2px solid var(--ink); outline-offset: -2px; box-shadow: none; }
.cell-in.n { text-align: right; }
select.cell-in { padding: 0 4px; }
.row-st { margin-right: 8px; font-size: 13px; color: var(--ink-3); }
.row-st.is-ok { color: var(--green); font-weight: 600; }
.row-st.is-err { color: var(--red); font-weight: 700; cursor: help; }
.sheet tr.is-err > td { background: var(--red-bg); }
.sheet tr.is-err > td.c-code { box-shadow: inset 4px 0 0 var(--red); }
.sheet tr.is-draft > td { background: var(--amber-bg); border-bottom: 1px dashed var(--amber-line); }
.sheet tr.is-draft > td.c-code { box-shadow: inset 4px 0 0 var(--amber); }
.sheet-empty { padding: 40px 16px !important; height: auto !important; text-align: center !important; color: var(--ink-3); white-space: normal !important; cursor: default !important; }
.sheet-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 16px; border-top: 1px solid var(--line); background: var(--soft); font-size: 14px; color: var(--ink-2); }
.pager { display: flex; align-items: center; gap: 10px; }

/* revisão (importação e documento lido pela IA) */
.review-wrap { max-height: 480px; }
.review-wrap tr.is-same > td { color: var(--ink-3); }
.review-wrap tr.is-err > td { background: var(--red-bg); }
.review-wrap td.is-big { font-weight: 700; color: var(--amber-ink); }
.review-wrap td.is-big small { color: var(--amber-ink); }
.review > * + * { margin-top: 0; }
.review h3 { margin-bottom: 0; }
.review__block > * + * { margin-top: 12px; }
.review__block + .review__block { margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--line-2); }
.review h4 { font-size: 15px; }
.review-wrap .check { white-space: nowrap; font-size: 14px; }
.cur-in { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.cur-in > span { font-size: 13px; font-weight: 700; letter-spacing: .03em; color: var(--ink-3); }
.file-pill { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 8px; padding: 8px 12px; border: 1px solid var(--line-2); border-radius: var(--radius-sm); background: var(--soft); font-size: 14px; }

/* impostos por país */
.tax-layout { display: grid; grid-template-columns: 270px minmax(0, 1fr); gap: var(--gap); align-items: start; }
.tax-side { position: sticky; top: calc(var(--top-h) + 24px); }
.tax-list { display: grid; gap: 6px; }
.tax-list__item { display: flex; align-items: flex-start; gap: 10px; width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-left: 4px solid var(--line-2); border-radius: var(--radius-sm); background: var(--white); font-size: 15px; text-align: left; }
.tax-list__item:hover { border-color: var(--line-3); border-left-color: var(--ink); background: var(--soft); }
.tax-list__item.is-on { border-color: var(--ink); border-left-color: var(--ink); background: var(--soft); }
.tax-list__item small { display: block; font-size: 13px; color: var(--ink-3); }
.tax-list__item:focus-visible { outline: none; box-shadow: var(--focus); }
.tax-main { min-width: 0; }
.tax-main > * + * { margin-top: var(--gap); }
.tax-table th, .tax-table td { padding: 6px 6px; }
.tax-table th:first-child, .tax-table td:first-child { padding-left: 12px; }
.tax-table td input.num { width: 76px; padding: 0 8px; }
.tax-key { width: 116px; padding: 0 8px !important; font-family: var(--mono); font-size: 13px !important; }
.tax-name { min-width: 210px; }
.tax-note { min-width: 150px; }
.tax-table select { min-width: 128px; padding-left: 8px; padding-right: 26px; }
.tax-table .btn--small { padding: 0 10px; }
.tax-table input[data-k="ncm"] { min-width: 120px; font-family: var(--mono); font-size: 13px; }
.tax-table input[data-txn][data-k="note"] { min-width: 180px; }
.tax-n { width: 36px; color: var(--ink-3); font-size: 13px; text-align: right; }
.tax-row-acts { flex-wrap: nowrap; justify-content: flex-end; }
.tax-thc { display: grid; grid-template-columns: minmax(0, 1fr) 110px; gap: 10px; }
.tax-hist { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; font-size: 14px; }
.tax-hist li { padding: 10px 12px; border-left: 3px solid var(--line-2); border-radius: 0 4px 4px 0; background: var(--soft); }
.tax-hist span { display: block; margin-top: 2px; font-size: 14px; color: var(--ink-2); overflow-wrap: anywhere; }

/* simulação do custo no destino */
.sim > * + * { margin-top: 12px; }
.sim__meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 14px; color: var(--ink-2); }
.sim__table td small { display: block; }
.sim__table tbody tr.sim__cif > td { background: var(--soft); border-bottom: 1px solid var(--line-2); }
.sim__table tfoot td { border-top: 1px solid var(--line-2); font-weight: 600; }
.sim__table tfoot tr.sim__total td { border-top: 2px solid var(--ink); font-size: 16px; font-weight: 700; }
.sim__table tfoot td small { font-weight: 500; }
.sim__notes { display: grid; gap: 4px; padding-left: 20px; font-size: 14px; color: var(--ink-2); }

/* ---------- 12b. acompanhamento do cliente (QR code, mapa e linha do tempo do contêiner) ---------- */
.track__top { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 24px; align-items: start; }
.track__qr { display: grid; gap: 8px; justify-items: center; padding: 10px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--white); text-align: center; }
.track__qr img { display: block; width: 200px; height: 200px; image-rendering: pixelated; }
.track__qr figcaption, .track__qrerr { font-size: 14px; color: var(--ink-3); }
.track__info { display: grid; gap: 12px; min-width: 0; }
.track__info > * { margin: 0; }
.track__kv > div { grid-template-columns: 160px minmax(0, 1fr); }
.track__err { color: var(--red-ink); font-weight: 600; }
.track__body { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 24px; align-items: start; padding-top: 20px; border-top: 1px solid var(--line); }
.track__body > * { min-width: 0; }
/* letra mínima de 14 px no bloco do rastreio, também nas etiquetas e na atribuição do mapa */
.track .card__head .tag { font-size: 14px; }
.track__map.leaflet-container, .track__map .leaflet-control-attribution, .track__map .leaflet-popup-content { font-size: 14px; font-family: inherit; }
.track__map { height: 380px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: #e8ecef; }
.nomap { padding: 14px 16px; border: 1px dashed var(--line-2); border-radius: var(--radius-sm); background: var(--soft); color: var(--ink-2); font-size: 14px; }
.ship-mk { display: grid; place-items: center; }
.ship-mk svg { filter: drop-shadow(0 1px 2px rgba(0, 0, 0, .45)); }
.tl { list-style: none; display: grid; max-height: 420px; overflow: auto; padding-right: 4px; }
.tl li { position: relative; display: grid; gap: 2px; padding: 0 0 16px 30px; font-size: 14px; }
.tl li:last-child { padding-bottom: 0; }
.tl li::before { content: ""; position: absolute; left: 4px; top: 4px; width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--line-3); background: var(--white); z-index: 1; }
.tl li::after { content: ""; position: absolute; left: 10px; top: 18px; bottom: 0; width: 2px; background: var(--line); }
.tl li:last-child::after { display: none; }
.tl li.is-done::before { background: var(--ink); border-color: var(--ink); }
.tl li.is-done::after { background: var(--ink); }
.tl li.is-now::before { border: 4px solid var(--ink); box-shadow: 0 0 0 3px rgba(17, 17, 17, .12); }
.tl li.is-plan { color: var(--ink-3); }
.tl li.is-plan::before { border-style: dashed; }
.tl b { font-weight: 650; }
.tl small { font-size: 14px; color: var(--ink-3); }
.tl__plan { display: inline-block; margin-left: 4px; padding: 0 7px; border: 1px solid var(--line-2); border-radius: var(--pill); font-size: 14px; font-weight: 600; color: var(--ink-3); }
@media (max-width: 1100px) { .track__body { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 640px) {
  .track__top { grid-template-columns: minmax(0, 1fr); }
  .track__qr { justify-self: center; width: min(260px, 100%); }
  .track__map { height: 300px; }
  .track__kv > div { grid-template-columns: minmax(0, 1fr); }
  /* botões grandes para o dedo no telemóvel */
  .track .actions .btn { flex: 1 1 auto; min-height: 44px; }
  .track__info .actions > input { flex-basis: 100%; min-height: 44px; }
  .track__map .leaflet-bar a { width: 40px; height: 40px; line-height: 40px; font-size: 22px; }
}

/* ---------- 13. diálogos, envio ao cliente, TOConline ---------- */
.dialog { width: min(760px, calc(100vw - 32px)); min-width: min(520px, calc(100vw - 32px)); max-height: calc(100vh - 32px); margin: auto; padding: 24px; border: 0; border-radius: 10px; background: var(--surface); color: var(--ink); box-shadow: var(--shadow-lg); overflow: auto; }
.dialog::backdrop { background: rgba(0, 0, 0, .55); }
.dialog > h2 { font-size: 20px; margin-bottom: 16px; }
.dialog__actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; margin-top: 24px; padding-top: 16px; border-top: 1px solid var(--line); }
.dialog pre { max-height: 60vh; overflow: auto; margin: 12px 0; padding: 14px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--soft); font-family: var(--mono); font-size: 13px; line-height: 1.5; }
.dialog--toc { width: min(1080px, calc(100vw - 32px)); }
.toc-seg { margin-bottom: 12px; }
.toc-state { margin-bottom: 6px; font-size: 15px; }
.toc-h { display: flex; align-items: center; gap: 8px; margin: 22px 0 10px; font-size: 16px; }
.toc-kv { width: 100%; border-collapse: collapse; font-size: 14px; }
.toc-kv th, .toc-kv td { position: static; height: auto; padding: 8px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; background: transparent; white-space: normal; }
.toc-kv tbody tr:last-child > * { border-bottom: 0; }
.toc-kv th { width: 34%; font-weight: 600; color: var(--ink-2); }
.toc-kv th small { display: block; font-family: var(--mono); font-size: 13px; font-weight: 400; color: var(--ink-3); }
.toc-kv td { overflow-wrap: anywhere; }
.toc-lines { font-size: 14px; }
.toc-lines td { vertical-align: top; }
.dialog pre.toc-notes { max-height: none; margin: 0; font-family: inherit; font-size: 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.toc-raw { margin-top: 18px; }
/* Verificação da faturação (Definições → TOConline): passos com ✓ verde / ✗ vermelho. */
.selftest { padding-top: 6px; border-top: 1px solid var(--line); }
.alert--ok { background: var(--green-bg); border-color: var(--green-line); border-left-color: var(--green); }
.alert--ok b { color: var(--green-ink); }
.selftest .alert small { display: block; margin-top: 4px; }
.selftest__list { list-style: none; margin: 12px 0 0; padding: 0; border: 1px solid var(--line); border-radius: var(--radius-sm); }
.selftest__step { display: flex; align-items: flex-start; gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--line); font-size: 15px; }
.selftest__step:last-child { border-bottom: 0; }
.selftest__step > div { min-width: 0; }
.selftest__step small { display: block; margin-top: 2px; color: var(--ink-3); font-size: 14px; overflow-wrap: anywhere; }
.selftest__step.is-bad { background: var(--red-bg); }
.selftest__step.is-bad small { color: var(--red-ink); }
.selftest__mark { flex: none; display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; font-weight: 700; font-size: 14px; line-height: 1; }
.selftest__mark--ok { background: var(--green); color: #fff; }
.selftest__mark--bad { background: var(--red); color: #fff; }
.selftest__mark--skip { background: var(--soft); color: var(--ink-3); border: 1px solid var(--line); }
.dialog--pw { width: min(560px, calc(100vw - 32px)); }
.dialog--pw #pwDlgBody > * + * { margin-top: 14px; }
.pw-temp .actions { flex-wrap: nowrap; }
.pw-temp input { font-family: var(--mono); font-size: 17px; letter-spacing: .04em; }

.dialog--send { width: min(720px, calc(100vw - 24px)); max-height: calc(100vh - 24px); padding: 0; }
.send { display: grid; gap: 16px; padding: 24px; }
.send__head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.send__head h2 { font-size: 20px; }
.send__head p { margin-top: 4px; font-size: 15px; }
.send__status { display: flex; flex-wrap: wrap; gap: 8px; }
.send__set { display: grid; gap: 10px; min-width: 0; margin: 0; padding: 14px 16px 16px; border: 1px solid var(--line); border-radius: var(--radius-sm); }
.send__set legend { padding: 0 6px; font-size: 13px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-3); }
.send__docs { display: flex; flex-wrap: wrap; gap: 8px 24px; }
.send__guard, .send__hint { font-size: 14px; color: var(--ink-3); }
.send__opts { display: grid; gap: 8px; margin: 10px 0; padding: 12px 14px; border: 1px solid var(--amber-line); border-left: 4px solid var(--amber); border-radius: var(--radius-sm); background: var(--amber-bg); }
.send__sum { margin: 12px 0 8px; padding: 14px 16px; border: 1px solid var(--line); border-left: 4px solid var(--ink); border-radius: var(--radius-sm); background: var(--soft); }
.send__sum > div { grid-template-columns: 110px minmax(0, 1fr); }
.send__manual { display: grid; gap: 10px; margin-top: 12px; padding: 14px 16px; border: 1px dashed var(--line-3); border-radius: var(--radius-sm); background: var(--soft); font-size: 15px; }
.send__acts { margin-top: 16px; justify-content: flex-end; }
.send__checking { margin-bottom: 8px; font-size: 15px; }
#sendStatus .alert { margin-top: 6px; }
#sendStatus > .send__hint { margin-top: 8px; text-align: right; }
.seg { display: inline-flex; border: 1px solid var(--ink); border-radius: var(--radius-sm); width: fit-content; overflow: hidden; }
.seg__btn { min-height: 40px; padding: 0 22px; font-size: 15px; font-weight: 600; }
.seg__btn + .seg__btn { border-left: 1px solid var(--ink); }
.seg__btn.is-on { background: var(--ink); color: var(--white); }
.seg__btn:focus-visible { outline: none; box-shadow: inset 0 0 0 3px var(--blue); }

.toast { position: fixed; left: 50%; bottom: 28px; z-index: 80; max-width: min(680px, calc(100vw - 32px)); transform: translate(-50%, 12px); padding: 14px 20px; border-radius: var(--radius); background: var(--ink); color: var(--white); font-size: 15px; font-weight: 600; box-shadow: var(--shadow-lg); opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; }
.toast.is-on { opacity: 1; transform: translate(-50%, 0); }
.toast.is-error { background: var(--red); }

/* ---------- 14. assistente (painel lateral à direita) ---------- */
.asst { position: fixed; top: var(--top-h); right: 0; z-index: 40; width: var(--asst-w); height: calc(100vh - var(--top-h)); height: calc(100dvh - var(--top-h)); display: flex; flex-direction: column; overflow: hidden; background: var(--surface); border-left: 1px solid var(--line-2); box-shadow: -8px 0 24px rgba(16, 24, 40, .1); }
.asst__head { flex: none; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 20px; background: var(--soft); border-bottom: 1px solid var(--line); }
.asst__head .actions { flex-wrap: nowrap; gap: 8px; }
.asst__full { display: inline-flex; align-items: center; gap: 6px; }
.asst__title { display: grid; gap: 4px; min-width: 0; }
.asst__title h2 { font-size: 19px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } /* uma só linha: o cabeçalho não cresce */
.asst__short { display: none; }
/* Painel lateral no computador (480–544 px): título e botões numa só linha — "Assistente" e "Limpar" (o nome completo fica no botão para leitores de ecrã). */
@media (min-width: 961px) {
  body:not(.asst-full) .asst__brand, body:not(.asst-full) .asst__long { display: none; }
  body:not(.asst-full) .asst__short { display: inline; }
}
.asst__state { display: inline-flex; align-items: center; gap: 6px; width: fit-content; font-size: 13px; font-weight: 600; color: var(--ink-3); }
.asst__state::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--line-3); }
.asst__state.is-on { color: var(--green-ink); }
.asst__state.is-on::before { background: var(--green); }
.asst__state.is-off { color: var(--amber-ink); }
.asst__state.is-off::before { background: var(--amber); }
/* Só a lista de mensagens desliza; as mensagens começam em baixo (junto da caixa de escrita) e as antigas sobem. */
.asst__log { flex: 1 1 auto; min-height: 0; overflow-y: auto; overflow-anchor: none; display: flex; flex-direction: column; gap: 18px; padding: 20px; background: #f6f6f7; overscroll-behavior: contain; font-size: 15px; }
.asst__log > :first-child { margin-top: auto; }
.asst-empty { display: grid; gap: 12px; color: var(--ink-2); font-size: 15px; line-height: 1.5; }
.asst-empty p { margin: 0; }
.asst-sugg { display: flex; flex-wrap: wrap; gap: 8px; }
/* Aviso fixo por cima da conversa (pedidos do site por responder) e lista de propostas à espera de um administrador. */
.asst__notice { flex: none; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; padding: 10px 20px; border-bottom: 1px solid var(--line); border-left: 3px solid var(--ink); background: var(--soft); font-size: 14px; color: var(--ink); }
.asst__notice small { color: var(--ink-3); font-size: 13px; overflow-wrap: anywhere; }
.asst__notice .asst__site-name { color: var(--ink-3); font-style: italic; } /* nome escrito pelo cliente no site: discreto, entre «» */
.asst__notice .link-btn { margin-left: auto; color: var(--ink); white-space: nowrap; }
.asst__queue { flex: none; border-bottom: 1px solid var(--line); border-left: 3px solid var(--ink); background: var(--soft); }
.asst__queue > summary { padding: 10px 20px; font-size: 14px; font-weight: 600; cursor: pointer; }
.asst__queue > summary:focus-visible { outline: 2px solid var(--ink); outline-offset: -4px; }
.asst__queue-body { max-height: 40vh; overflow-y: auto; overscroll-behavior: contain; padding: 0 14px 14px; }
.asst-msg { max-width: 92%; display: grid; gap: 10px; }
.asst-msg__text { padding: 12px 16px; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 15.5px; line-height: 1.55; }
.asst-msg--user { align-self: flex-end; justify-items: end; max-width: 85%; }
.asst-msg--user .asst-msg__text { border-radius: 14px 14px 4px 14px; background: var(--ink); color: var(--white); }
.asst-msg__att { padding: 4px 10px; border: 1px solid var(--line-3); border-radius: var(--pill); background: var(--white); font-size: 13px; font-weight: 600; }
.asst-msg--bot { align-self: flex-start; }
.asst-msg--bot .asst-msg__text { border-radius: 14px 14px 14px 4px; background: var(--white); border: 1px solid var(--line); }
.asst-msg.is-error .asst-msg__text { background: var(--red-bg); border-color: var(--red-line); color: var(--red-ink); }
.asst-thinking span { padding: 10px 16px; border: 1px dashed var(--line-3); border-radius: 14px; background: var(--white); color: var(--ink-3); font-size: 15px; animation: asst-pulse 1.2s ease-in-out infinite; }
@keyframes asst-pulse { 50% { opacity: .45; } }
.asst-src { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.asst-src > span { font-size: 13px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--ink-3); }
.chip { display: inline-flex; align-items: center; min-height: 34px; padding: 0 14px; border: 1px solid var(--line-3); border-radius: var(--pill); background: var(--white); font-size: 14px; font-weight: 600; color: var(--ink); text-align: left; cursor: pointer; }
button.chip:hover { border-color: var(--ink); background: var(--ink); color: var(--white); }
button.chip:focus-visible { outline: none; box-shadow: var(--focus); }
button.chip:disabled { border-color: var(--line); background: var(--soft-2); color: var(--ink-4); cursor: not-allowed; }
.chip--static { border-color: var(--line); background: var(--soft-2); color: var(--ink-2); cursor: default; }
.props { display: grid; gap: 12px; }
.prop { display: grid; gap: 12px; padding: 18px 20px; border: 1px solid var(--line-2); border-left: 5px solid var(--blue); border-radius: var(--radius); background: var(--white); box-shadow: var(--shadow); font-size: 15px; }
.prop--documento { border-left-color: var(--red); }
.prop--envio { border-left-color: var(--amber); }
.prop.is-closed { border-left-color: var(--line-3); background: var(--soft); }
.prop__head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 10px; font-size: 16px; }
.prop__count { font-size: 14px; font-weight: 600; color: var(--ink-2); }
.prop__sum { display: grid; gap: 4px; margin: 0; padding-left: 20px; font-size: 15px; color: var(--ink-2); overflow-wrap: anywhere; }
.prop__sum.is-long { max-height: 320px; overflow-y: auto; padding: 10px 12px 10px 28px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--soft); }
.prop__sum li.is-row { font-family: var(--mono); font-size: 13px; color: var(--ink); }
.prop__res { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 14px; color: var(--ink-2); }
.prop__block { display: grid; gap: 6px; padding-top: 10px; border-top: 1px solid var(--line); }
.prop__block h4 { font-size: 13px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--ink-2); }
.prop__block > .muted { font-size: 14px; }
.prop .actions { gap: 10px; }
.prop .actions .btn { min-height: 44px; padding: 0 22px; font-size: 15px; }
.prop .actions small { font-size: 13px; }
.prop__send { display: grid; gap: 6px; margin: 0; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--soft); font-size: 14px; }
.prop__send > div { display: grid; grid-template-columns: 70px minmax(0, 1fr); gap: 8px; align-items: baseline; }
.prop__send dt { font-size: 13px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--ink-3); }
.prop__send dd { margin: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; overflow-wrap: anywhere; }
.prop__send dd small { flex-basis: 100%; color: var(--ink-3); }
.out__atts { gap: 6px !important; }
/* Caixa de escrita: uma linha compacta [microfone][anexar][texto][Enviar], sempre em baixo; o texto cresce até ~6 linhas e depois desliza. */
.asst__form { flex: none; display: grid; gap: 8px; padding: 12px 20px; padding-bottom: max(12px, env(safe-area-inset-bottom)); border-top: 1px solid var(--line-2); background: var(--surface); }
.asst__row { display: grid; grid-template-columns: auto auto minmax(0, 1fr) auto; align-items: end; gap: 8px; }
.asst__row textarea { min-height: 44px; max-height: 160px; padding: 10px 12px; font-size: 16px; line-height: 1.4; resize: none; overflow-y: auto; }
.asst__row .icon-btn { width: 44px; justify-content: center; padding: 0; }
.asst__row .icon-btn > span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.asst__row .icon-btn[hidden] { display: none; }
.asst__send { min-height: 44px; padding: 0 20px; font-size: 15px; }
.icon-btn { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 14px 0 12px; border: 1px solid var(--line-3); border-radius: var(--radius-sm); background: var(--white); font-size: 14px; font-weight: 600; color: var(--ink); }
.icon-btn:hover { border-color: var(--ink); background: var(--soft); }
.icon-btn:focus-visible { outline: none; box-shadow: var(--focus); }
.icon-btn:disabled { border-color: var(--line); background: var(--soft-2); color: var(--ink-4); cursor: not-allowed; }
.icon-btn.is-on { background: var(--red); border-color: var(--red); color: var(--white); animation: asst-pulse 1.4s ease-in-out infinite; }
.asst__live { font-size: 14px; font-weight: 600; color: var(--ink-2); }
.asst__live:empty { display: none; }
.asst__attach { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 12px; border: 1px solid var(--line-2); border-left: 4px solid var(--blue); border-radius: var(--radius-sm); background: var(--blue-bg); font-size: 14px; overflow-wrap: anywhere; }
@media (min-width: 1440px) { body.asst-on:not(.asst-full) .main { margin-right: var(--asst-w); } }
/* Página inteira (#assistente): o mesmo painel ocupa a área do ecrã, ao lado do menu; o conteúdo fica centrado. */
body.asst-full .asst { left: var(--side-w); width: auto; border-left: 0; box-shadow: none; }
body.asst-full .asst__head, body.asst-full .asst__notice, body.asst-full .asst__queue > summary, body.asst-full .asst__log, body.asst-full .asst__form { padding-left: max(20px, calc((100% - 920px) / 2)); padding-right: max(20px, calc((100% - 920px) / 2)); }
body.asst-full .asst__queue-body { padding-left: max(14px, calc((100% - 920px) / 2)); padding-right: max(14px, calc((100% - 920px) / 2)); }
body.asst-full { overflow: hidden; }

/* ---------- 15. utilitários de espaçamento (substituem os estilos soltos) ---------- */
.u-mt-0 { margin-top: 0 !important; }
.u-mt-1 { margin-top: 8px !important; }
.u-mt-2 { margin-top: 12px !important; }
.u-mt-3 { margin-top: 24px !important; }
.u-mb-1 { margin-bottom: 8px !important; }
.u-mb-2 { margin-bottom: 12px !important; }
.u-mb-3 { margin-bottom: 24px !important; }
.u-my { margin-top: 12px !important; margin-bottom: 16px !important; }
.u-grow { flex: 1 1 260px; min-width: 220px; max-width: 560px; }
.u-w-sm { max-width: 360px; }
.u-w-auto { width: auto; }
.u-w-search { width: auto; min-width: 320px; }

/* ---------- 16. responsivo ---------- */
@media (max-width: 1440px) {
  :root { --side-w: 240px; }
  .main { padding: 28px 32px 96px; }
}
@media (max-width: 1280px) {
  .grid--4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form--4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .topbar__user { max-width: 200px; }
}
@media (max-width: 1100px) {
  .grid--2, .grid--wide { grid-template-columns: minmax(0, 1fr); }
  .grid--3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sheet-hint { display: none; }
  .tax-layout { grid-template-columns: minmax(0, 1fr); }
  .tax-side { position: static; }
  .tax-list { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
  .topbar__group { display: none; }
}
/* Ecrãs estreitos: o menu passa a gaveta aberta pelo botão "Menu"; o logótipo continua ao centro. */
@media (max-width: 960px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .topbar__menu { display: inline-flex; }
  .topbar__title { display: none; }
  .topbar__user { display: none; }
  .side { position: fixed; top: var(--top-h); left: 0; bottom: 0; height: auto; width: min(300px, 86vw); transform: translateX(-100%); transition: transform .2s ease, visibility .2s; z-index: 46; visibility: hidden; }
  body.nav-open .side { transform: none; visibility: visible; box-shadow: 8px 0 24px rgba(0, 0, 0, .25); }
  body.nav-open .nav-scrim { display: block; position: fixed; inset: var(--top-h) 0 0 0; z-index: 45; background: rgba(0, 0, 0, .45); }
  /* Telemóvel e tablet: o assistente ocupa o ecrã todo (lateral ou página inteira são iguais). */
  .asst, body.asst-full .asst { top: 0; left: 0; right: 0; z-index: 60; width: 100vw; height: 100vh; height: 100dvh; border-left: 0; }
  body.asst-on { overflow: hidden; }
  .asst__full { display: none !important; }
  .main { padding: 24px 20px 80px; }
}
@media (max-width: 640px) {
  :root { --top-h: 64px; --pad: 18px; --gap: 18px; --fs-h1: 24px; }
  .topbar { --brand-half: 48px; gap: 8px; padding: 0 12px; }
  .topbar__brand img { height: 40px; }
  .topbar__menu { padding: 0 10px; }
  .topbar__menu span, .asst-open__text { display: none; }
  .asst-open { padding: 0 6px; min-height: 40px; }
  .topbar__right { gap: 8px; }
  .main { padding: 18px 16px 72px; }
  .head > div:first-child { flex-basis: 100%; }
  .head > .actions { justify-content: flex-start; }
  .grid--3, .grid--4, .totals { grid-template-columns: minmax(0, 1fr); }
  .form, .form--3, .form--4 { grid-template-columns: minmax(0, 1fr); }
  .form--3 > :first-child:nth-last-child(2) + .actions.u-self-end { grid-column: auto; }
  .form--1 { max-width: none; }
  .form > .check { min-height: 0; }
  .table-wrap > table { min-width: 620px; }
  .table-wrap > table.tax-table { min-width: 0; }
  .kv > div { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .today__grid { grid-template-columns: minmax(0, 1fr); }
  .kpi > b { font-size: 26px; }
  .tax-list { grid-template-columns: minmax(0, 1fr); }
  .ai-box, .lines-editor, .msg-new { padding: 14px; }
  .out { padding: 16px; }
  .savebar { position: static; }
  .savebar--card { position: sticky; }
  .sheet-tools input[type=search] { width: 100%; }
  .sheet-tools select { flex: 1 1 140px; max-width: none; }
  .sheet-wrap { max-height: 70vh; }
  .u-w-search, .u-grow { min-width: 0; width: 100%; max-width: none; flex-basis: 100%; }
  .search { max-width: none; width: 100%; }
  .dialog { padding: 18px; min-width: 0; }
  .send { padding: 18px; }
  .send__sum > div { grid-template-columns: minmax(0, 1fr); }
  .login__brand { padding: 28px 24px 20px; }
  .login__brand img { height: 72px; }
  .login__body { padding: 24px 24px 28px; }
  .bubble { max-width: 92%; }
  .asst__head, .asst__form, .asst__notice, .asst__queue > summary { padding-left: 14px; padding-right: 14px; }
  body.asst-full .asst__head, body.asst-full .asst__notice, body.asst-full .asst__queue > summary, body.asst-full .asst__log, body.asst-full .asst__form { padding-left: 14px; padding-right: 14px; }
  .asst__head { padding-top: 10px; padding-bottom: 10px; }
  .asst__title h2 { font-size: 17px; }
  .asst__head .actions { gap: 6px; }
  .asst__head .btn { padding: 0 10px; }
  .asst__log { padding: 14px; gap: 14px; }
  .asst__row { gap: 6px; }
  .asst__notice small { display: none; }
  .asst__send { padding: 0 14px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

/* ---------- 17. impressão ---------- */
@media print {
  .asst, .asst-open, .side, .topbar, .nav-scrim { display: none !important; }
  .shell { display: block; padding-top: 0; }
  .main { padding: 0; }
  .table-wrap { max-height: none; overflow: visible; }
}

/* ---------- olho nas palavras-passe ---------- */
.pw-field { position: relative; display: block; width: 100%; }
.pw-field > input { width: 100%; padding-right: 52px; }
.pw-eye { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); width: 44px; height: 38px; display: inline-flex; align-items: center; justify-content: center; border: 0; border-radius: 6px; background: transparent; color: var(--ink-3); cursor: pointer; }
.pw-eye:hover { color: var(--ink); background: rgba(0, 0, 0, .05); }
.pw-eye[aria-pressed="true"] { color: var(--ink); }
.pw-eye:focus-visible { outline: 2px solid var(--ink); outline-offset: 0; }

/* ---------- fecho do mês, exportação e procura de clientes ---------- */
.close-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; }
.close-bar__month { display: flex; align-items: center; gap: 8px; font-weight: 650; }
.close-bar__month input { width: auto; min-width: 170px; }
.close-bar__name { font-size: 18px; margin-right: auto; }
.close-bar__name::first-letter { text-transform: uppercase; }
.close-seal { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; padding: 14px 18px; border: 2px solid var(--ink); border-radius: var(--radius-sm); background: var(--white); }
.close-seal > b { padding: 4px 10px; border: 2px solid var(--ink); border-radius: 4px; font-size: 13px; letter-spacing: .08em; text-transform: uppercase; }
.close-seal > span { color: var(--ink-2); font-size: 15px; }
.close-kpis .kpi > b.kpi__text { font-size: 24px; }
.close-kpis .kpi > small { overflow-wrap: anywhere; }
.export-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 16px; }
.export-item { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--soft); }
.export-item > div { display: grid; gap: 2px; min-width: 0; }
.export-item small { color: var(--ink-3); font-size: 14px; }
.export-item .btn { flex: 0 0 auto; }
.cust-search { display: grid; gap: 8px; }
.cust-search__list { display: grid; gap: 6px; }
.cust-search__list:empty { display: none; }
.cust-pick { display: grid; gap: 2px; justify-items: start; width: 100%; padding: 10px 14px; border: 1px solid var(--line-2); border-left: 4px solid var(--ink); border-radius: var(--radius-sm); background: var(--white); text-align: left; cursor: pointer; font: inherit; }
.cust-pick:hover { background: var(--soft); }
.cust-pick:focus-visible { outline: none; box-shadow: var(--focus); }
.cust-pick small { color: var(--ink-3); font-size: 14px; }
@media (max-width: 960px) { .export-list { grid-template-columns: minmax(0, 1fr); } }
@media print { .close-bar, .head > .actions { display: none; } }

/* ==========================================================================
   18. Cara de sistema: barra de ferramentas única por ecrã, ajuda (?), listas densas,
       edição segura (linha em edição, gaveta, confirmações, desfazer) e câmbio ao vivo
   ========================================================================== */
:root { --fs-h1: 21px; --gap: 18px; --pad: 18px; --field-h: 38px; --btn-h: 36px; --btn-h-sm: 30px; }
td { height: 38px; padding: 6px 12px; }
th { padding: 8px 12px; font-size: 13px; }
td small { font-size: 13px; }
.card > * + * { margin-top: 12px; }
.card__head { min-height: 30px; }
h2 { font-size: 16px; }
.card__sub { margin-top: 20px !important; padding-top: 14px; }
.view > * + * { margin-top: 14px; }

/* Barra de ferramentas do ecrã */
.head { align-items: center; gap: 8px 12px; min-height: 48px; padding: 0 0 12px; border-bottom: 1px solid var(--line-2); }
.head > div:first-child { flex: 0 1 auto; }
.head__title { display: flex; align-items: center; gap: 8px; min-width: 0; }
.head h1 { font-size: var(--fs-h1); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.head__count { display: inline-flex; align-items: center; min-height: 22px; padding: 0 8px; border-radius: var(--pill); background: var(--soft-2); color: var(--ink-3); font-size: 13px; font-weight: 650; white-space: nowrap; }
.head__tools { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 8px; flex: 1 1 360px; min-width: 0; }
.head > .actions { flex: 0 0 auto; margin-left: auto; padding-top: 0; }
.head__tools + .actions { margin-left: 0; }
.head input[type=search], .head .lq { width: 280px; max-width: 100%; min-height: 34px; height: 34px; font-size: 14px; }
.head select { width: auto; max-width: 210px; min-height: 34px; height: 34px; font-size: 14px; }
.head .btn { min-height: 34px; }
.head .switch--sm { font-size: 14px; }
.card__head h2 .head__count { margin-left: 4px; }
.card__head h2 { display: flex; align-items: center; gap: 6px; }

/* Ajuda (?) e popover */
.help { display: inline-grid; place-items: center; flex: none; width: 22px; height: 22px; border: 1px solid var(--line-3); border-radius: 50%; background: var(--white); color: var(--ink-3); font-size: 13px; font-weight: 800; line-height: 1; cursor: help; }
.help:hover, .help[aria-expanded="true"] { border-color: var(--ink); background: var(--ink); color: var(--white); }
.help:focus-visible { outline: none; box-shadow: var(--focus); }
.pop { position: fixed; z-index: 95; width: max-content; max-width: min(420px, calc(100vw - 16px)); padding: 14px 16px; border: 1px solid var(--line-2); border-radius: var(--radius); background: var(--white); box-shadow: var(--shadow-lg); font-size: 14px; line-height: 1.5; color: var(--ink-2); }
.pop > * + * { margin-top: 10px; }
.pop h3 { font-size: 15px; color: var(--ink); }
.pop__kv { display: grid; gap: 6px; }
.pop__kv > div { display: grid; grid-template-columns: 130px minmax(0, 1fr); gap: 10px; }
.pop__kv dt { color: var(--ink-3); font-weight: 600; font-size: 13px; }
.pop__kv dd { margin: 0; }
.pop__kv small { display: block; color: var(--ink-3); font-size: 13px; }
.pop__foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-top: 10px; border-top: 1px solid var(--line); }
.pop__attr, .fx-attr a { font-size: 13px; color: var(--ink-3); text-decoration: underline; }
.pop .alert { font-size: 13px; padding: 8px 10px; }

/* Ativos / arquivados */
.seg { display: inline-flex; border: 1px solid var(--line-3); border-radius: var(--radius-sm); overflow: hidden; background: var(--white); flex: none; }
.seg button { display: inline-flex; align-items: center; gap: 6px; min-height: 32px; padding: 0 12px; font-size: 13.5px; font-weight: 600; color: var(--ink-3); }
.seg button + button { border-left: 1px solid var(--line-3); }
.seg button:hover { color: var(--ink); background: var(--soft); }
.seg button.is-on { background: var(--ink); color: var(--white); }
.seg b { min-width: 20px; padding: 0 6px; border-radius: var(--pill); background: var(--soft-2); color: var(--ink); font-size: 13px; line-height: 18px; text-align: center; }
.seg .is-on b { background: var(--white); }

/* Listas em cartão: tabela encostada ao cartão, rodapé com contagem */
.card--table { padding: 0; overflow: hidden; }
.card--table > * + * { margin-top: 0; }
.card--table > .card__head { padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--soft); }
.card--table > .table-wrap { border: 0; border-radius: 0; }
.card--table > .empty { padding: 28px 16px; }
.list-foot { display: flex; justify-content: space-between; gap: 10px; padding: 8px 14px; border-top: 1px solid var(--line); background: var(--soft); font-size: 13px; color: var(--ink-3); }
.row-acts { display: inline-flex; align-items: center; justify-content: flex-end; gap: 12px; white-space: nowrap; }
.link-btn--danger { color: var(--red); }
.link-btn--danger:hover { color: var(--red-ink); }
tr.is-off > td b { color: var(--ink-3); }
.perm-note { font-size: 13px; }
.kv--tight { gap: 0; }
.kv--tight > div { grid-template-columns: 170px minmax(0, 1fr); padding: 6px 0; border-bottom: 1px solid var(--line); }
.kv--tight > div:last-child { border-bottom: 0; }
.switch--sm input { width: 36px; height: 20px; min-height: 20px; }
.switch--sm input::after { width: 12px; height: 12px; }
.switch--sm input:checked::after { transform: translateX(16px); }

/* Folha: leitura por omissão, uma linha em edição (âmbar claro) com Guardar/Cancelar */
.sheet td { cursor: default; height: 34px; }
.th-sort { height: 36px; font-size: 13px; }
.sheet tbody tr:not(.is-edit):hover > td { background: #f3f6fa; }
.sheet tr.is-edit > td, .sheet tr.is-edit:hover > td { background: #fff7e6; border-bottom-color: var(--amber-line); }
.sheet tr.is-edit > td.c-code { box-shadow: inset 4px 0 0 var(--amber); background: #fdeccb; }
.sheet tr.is-edit > td.is-ro { color: var(--ink-3); }
.sheet tr.is-edit .cell-in { height: 33px; margin: 0; outline: 1px solid var(--amber-line); outline-offset: -1px; background: var(--white); }
.sheet tr.is-edit .cell-in:focus { outline: 2px solid var(--ink); outline-offset: -2px; }
.sheet td.is-changed .cell-in { background: #fffbe8; font-weight: 650; }
.sheet td.is-invalid .cell-in { outline: 2px solid var(--red); outline-offset: -2px; background: var(--red-bg); }
.sheet td.c-st { padding: 0 10px; }
.sheet tr.is-saved > td { animation: saved 2.4s ease-out; }
@keyframes saved { 0%, 40% { background: var(--green-bg); } 100% { background: var(--white); } }
.sheet.is-arch td { color: var(--ink-3); }
.sheet-foot { padding: 8px 14px; font-size: 13px; }
.sheet-foot__edit { color: var(--amber-ink); font-weight: 600; }
.sheet-wrap { max-height: calc(100vh - var(--top-h) - 190px); }
.btn--xs { min-height: 26px; padding: 0 10px; font-size: 13px; }
.btn--danger-solid { background: var(--red); border-color: var(--red); color: var(--white); }
.btn--danger-solid:hover { background: var(--red-ink); border-color: var(--red-ink); }
.btn--danger-solid:disabled { background: var(--soft-2); border-color: var(--line); color: var(--ink-3); }

/* Aviso com "Desfazer" */
.toast { display: flex; align-items: center; gap: 16px; }
.toast.has-act.is-on { pointer-events: auto; }
.toast__act { flex: none; min-height: 30px; padding: 0 14px; border: 1px solid rgba(255, 255, 255, .6); border-radius: var(--radius-sm); color: var(--white); font-size: 14px; font-weight: 700; }
.toast__act:hover { background: rgba(255, 255, 255, .15); border-color: var(--white); }

/* Confirmação */
.dialog--cf { width: min(560px, calc(100vw - 32px)); min-width: 0; }
.dialog--cf > h2 { font-size: 18px; margin-bottom: 12px; }
.cf__body { display: grid; gap: 10px; font-size: 15px; color: var(--ink-2); }
.cf__table { font-size: 14px; border: 1px solid var(--line); border-radius: var(--radius-sm); }
.cf__table th { position: static; padding: 6px 10px; }
.cf__table td { height: auto; padding: 8px 10px; }
.cf__table .up { color: var(--red-ink); }
.cf__table .down { color: var(--blue-ink); }
.cf__warn { padding: 8px 12px; border-left: 4px solid var(--amber); background: var(--amber-bg); color: var(--amber-ink); font-size: 14px; border-radius: 4px; }
.cf__type { margin-top: 14px; }
.cf__type code { padding: 1px 6px; border-radius: 4px; background: var(--soft-2); font-size: 14px; }
.cf__list { margin: 0; padding-left: 20px; font-size: 14px; }

/* Gaveta lateral (novo / editar) */
.drawer-scrim { position: fixed; inset: 0; z-index: 70; background: rgba(0, 0, 0, .35); }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; z-index: 71; width: min(560px, 100vw); background: var(--white); box-shadow: -12px 0 32px rgba(0, 0, 0, .2); }
.drawer > form { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; height: 100%; }
.drawer__head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 18px 22px 14px; border-bottom: 1px solid var(--line); }
.drawer__head h2 { font-size: 18px; }
.drawer__head small { display: block; margin-top: 4px; color: var(--ink-3); font-size: 13px; }
.icon-x { display: grid; place-items: center; width: 34px; height: 34px; border-radius: var(--radius-sm); font-size: 22px; line-height: 1; color: var(--ink-3); }
.icon-x:hover { background: var(--soft); color: var(--ink); }
.drawer__body { overflow: auto; padding: 16px 22px 24px; }
.drawer__body > * + * { margin-top: 14px; }
.form--drawer { gap: 12px 16px; }
.drawer__sec { margin-top: 6px; padding-top: 10px; border-top: 1px solid var(--line); font-size: 13px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--ink-3); }
.form--drawer > .drawer__sec:first-child { margin-top: 0; padding-top: 0; border-top: 0; }
.field { display: grid; gap: 5px; align-content: start; min-width: 0; }
.field > label { display: block; }
.field__err { color: var(--red); font-size: 13px; font-weight: 600; }
.field.is-bad input, .field.is-bad select, .field.is-bad textarea { border-color: var(--red); background: var(--red-bg); }
.req { color: var(--red); font-style: normal; font-weight: 700; }
.drawer__foot { display: flex; align-items: center; justify-content: flex-end; gap: 10px; padding: 14px 22px; border-top: 1px solid var(--line); background: var(--soft); }
.drawer__foot > .muted { margin-right: auto; font-size: 13px; }
.drawer__aside { font-size: 14px; color: var(--ink-3); }
body.drawer-on { overflow: hidden; }

/* Câmbio ao vivo: indicador na barra de topo */
.fx-chip { display: inline-flex; align-items: baseline; gap: 4px; min-height: 34px; padding: 6px 10px; border: 1px solid var(--line-2); border-radius: var(--radius-sm); background: var(--white); font-size: 13px; color: var(--ink-2); white-space: nowrap; font-variant-numeric: tabular-nums; }
.fx-chip:hover, .fx-chip[aria-expanded="true"] { border-color: var(--ink); }
.fx-chip__pair { font-size: 13px; font-weight: 700; color: var(--ink-3); letter-spacing: .02em; }
.fx-chip b { color: var(--ink); font-size: 14px; }
.fx-chip__at { color: var(--ink-3); font-size: 13px; }
.fx-chip.is-warn { border-color: var(--amber-line); background: var(--amber-bg); }
.fx-chip__warn { align-self: center; display: inline-grid; place-items: center; width: 16px; height: 16px; margin-left: 2px; border-radius: 50%; background: var(--amber); color: var(--white); font-size: 13px; font-style: normal; font-weight: 800; }
.fx-chg { font-size: 13px; font-weight: 700; }
.fx-chg.up { color: var(--green); }
.fx-chg.down { color: var(--red); }
/* Definições → Moeda e câmbio */
.fx-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.fx-box { display: grid; gap: 2px; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--soft); }
.fx-box > span { font-size: 13px; font-weight: 650; color: var(--ink-3); }
.fx-box > b { font-size: 22px; line-height: 1.25; }
.fx-box > small { font-size: 13px; color: var(--ink-3); }
.fx-box--use { border-left: 4px solid var(--ink); background: var(--white); }
.fx-spark { margin: 0; }
.fx-spark svg { display: block; width: 100%; height: 110px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--white); }
.fx-spark__line { fill: none; stroke: var(--ink); stroke-width: 2; }
.fx-spark__area { fill: var(--soft-2); }
.fx-spark figcaption { display: flex; justify-content: space-between; gap: 10px; margin-top: 4px; font-size: 13px; color: var(--ink-3); }
.fx-admin { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px; padding-top: 12px; border-top: 1px solid var(--line); }
.fx-admin > label { width: 290px; }
.fx-manual { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px; margin-left: auto; }
.fx-manual label { width: 180px; }
.fx-manual label:nth-child(2) { width: 200px; }
.fx-attr { margin-top: 6px !important; }

@media (max-width: 1440px) {
  .head input[type=search], .head .lq { width: 220px; }
  .topbar__user { max-width: 170px; }
}
@media (max-width: 1100px) {
  .fx-grid { grid-template-columns: minmax(0, 1fr); }
  .fx-chip__at { display: none; }
}
@media (max-width: 640px) {
  .fx-chip { display: none; }
  .head__tools { justify-content: flex-start; flex-basis: 100%; }
  .head input[type=search], .head .lq { width: 100%; }
  .drawer .form--drawer { grid-template-columns: minmax(0, 1fr); }
}
.ai-usage { display: grid; gap: 6px; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--soft); }
.ai-usage__row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; font-size: 14px; }
.bar--warn i { background: var(--amber); }
.fs-plain { min-width: 0; margin: 0; padding: 0; border: 0; }
.fs-plain > * + * { margin-top: 12px; }
/* Coluna de ações da folha sempre visível (Editar/Arquivar, Guardar/Cancelar), mesmo com a tabela deslocada para a esquerda. */
.sheet td.c-st, .sheet th.c-st { position: sticky; right: 0; box-shadow: inset 1px 0 0 var(--line-3); }
.sheet td.c-st { z-index: 2; background: var(--white); }
.sheet th.c-st { z-index: 4; }
.sheet tr.is-edit > td.c-st { background: #fdeccb; }
/* Ecrãs até 1600 px: título e botões na primeira linha, pesquisa e filtros na segunda (barra de filtros). */
@media (max-width: 1600px) {
  .head__title { order: 0; }
  .head > .actions { order: 1; margin-left: auto; }
  .head__tools { order: 2; flex: 1 1 100%; justify-content: flex-start; }
  .head__tools .seg { margin-left: auto; }
}
/* Sempre: título e botões na 1.ª linha; pesquisa, filtros e Ativos/Arquivados na 2.ª (barra de filtros). */
.head__title { order: 0; }
.head > .actions { order: 1; margin-left: auto; }
.head__tools { order: 2; flex: 1 1 100%; justify-content: flex-start; }
.head__tools .seg { margin-left: auto; }

/* ==========================================================================
   19. Revisão do painel (barra de ferramentas, ações das linhas, câmbio no telemóvel, edição explícita)
   ========================================================================== */
/* Ações das linhas: botões compactos, iguais em todas as listas (não ligações sublinhadas). */
.row-acts { gap: 6px; }
.btn--xs { min-height: 28px; padding: 0 10px; font-size: 13px; font-weight: 600; }
.btn--xs-danger { color: var(--red); border-color: var(--red-line); }
.btn--xs-danger:hover { background: var(--red-bg); border-color: var(--red); color: var(--red-ink); }
/* Coluna de ações fixa à direita: sombra para se ver que a tabela continua por baixo. */
.sheet td.c-st, .sheet th.c-st { box-shadow: -8px 0 10px -8px rgba(16, 24, 40, .22), inset 1px 0 0 var(--line-3); }
/* Botões da barra do ecrã: nunca saem do ecrã, passam à linha seguinte. */
.head > .actions { flex-wrap: wrap; min-width: 0; }
/* Definições: só leitura até "Editar". */
.form input:disabled, .form select:disabled, .form textarea:disabled { background: var(--soft); color: var(--ink); border-color: var(--line); opacity: 1; cursor: default; -webkit-text-fill-color: var(--ink); }
.set-edit .card { border-color: var(--amber-line); box-shadow: inset 4px 0 0 var(--amber); }
.savebar__note { margin-right: auto; font-size: 14px; color: var(--ink-3); }
.set-edit .savebar__note { color: var(--amber-ink); font-weight: 600; }
/* Câmbio no telemóvel: barra fina por baixo da barra de topo (a de cima não tem espaço). */
.fx-chip--m { display: none; }
/* Notas de origem longas (impostos): uma linha, o resto no título. */
.clamp-1 { display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; max-width: 100%; }
@media (max-width: 640px) {
  .head > .actions { flex: 1 1 100%; justify-content: flex-start; margin-left: 0; }
  .head > .actions > .btn { flex: 0 1 auto; }
  .fx-chip--m { display: flex; width: 100%; justify-content: center; align-items: baseline; margin: -6px 0 12px; }
  .fx-chip--m[hidden] { display: none; }
  .fx-chip--m .fx-chip__at { display: inline; }
  /* Folha: só "Editar" na linha (arquivar faz-se num ecrã largo); a coluna de ações estreita. */
  .sheet .row-arch { display: none; }
  .sheet:not(.has-edit):not(.is-arch) col:last-child { width: 80px !important; }
}
.savebar--static { position: static; box-shadow: none; }
/* Painel: indicadores compactos (uma linha de 6 em ecrã largo; a nota numa linha só). */
.kpis .kpi { padding: 14px 16px; gap: 4px; }
.kpis .kpi > b { font-size: 26px; }
.kpis .kpi > small { font-size: 13px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
@media (min-width: 1500px) { body:not(.asst-on) .grid--3.kpis { grid-template-columns: repeat(6, minmax(0, 1fr)); } }
/* Assistente: propostas que exigem administrador (contagem no botão e lista no topo da conversa). */
.asst-open { position: relative; }
.asst-open__badge { position: absolute; top: -7px; right: -7px; display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 5px; border: 2px solid var(--white); border-radius: var(--pill); background: var(--red); color: var(--white); font-size: 13px; font-weight: 800; line-height: 1; }
.prop--admin { border-left: 4px solid var(--red); }
.prop .alert { margin: 8px 0; font-size: 14px; }

/* ---------- TOConline: estado automático da faturação (Definições) ---------- */
.billing { padding: 14px 16px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--soft); }
.billing .toc-h { margin-top: 0; }
.billing__state { display: flex; align-items: flex-start; gap: 12px; }
.billing__state b { display: block; font-size: 16px; }
.billing__state small { display: block; margin-top: 2px; font-size: 14px; color: var(--ink-3); }
.billing__state.is-ok b { color: var(--green-ink); }
.billing__state.is-bad b { color: var(--red-ink); }
.billing .selftest__list { background: var(--white); }
.toc-relink summary { width: fit-content; cursor: pointer; font-size: 14px; font-weight: 600; color: var(--ink-2); }
.toc-relink summary:hover { color: var(--ink); text-decoration: underline; }
.toc-relink[open] summary { margin-bottom: 10px; }

/* ---------- campos personalizados ---------- */
.cf-blocks { display: grid; gap: var(--gap); }
small.mono, .mono { font-family: var(--mono); }
.cols-pick { position: relative; }
.cols-pick > summary { list-style: none; gap: 6px; }
.cols-pick > summary::-webkit-details-marker { display: none; }
.cols-pick > summary b { font-weight: 600; color: var(--ink-3); }
.cols-pick__menu { position: absolute; z-index: 30; right: 0; top: calc(100% + 6px); display: grid; gap: 6px; min-width: 240px; max-height: 340px; overflow: auto; padding: 12px 14px;
  border: 1px solid var(--line-2); border-radius: var(--radius-sm); background: var(--white); box-shadow: var(--shadow-lg); }
.cols-pick__menu .check { white-space: nowrap; font-size: 14px; }
.card__head .cols-pick { margin-left: auto; }

/* ---------- assistente: linhas "Campo: antes → depois" nas propostas ---------- */
.prop__sum li.is-chg b { color: var(--ink); }
.prop__from { color: var(--ink-3); text-decoration: line-through; text-decoration-color: var(--line-3); }
.prop .cf__table { margin-top: 8px; }.cf-blocks table { table-layout: fixed; }
.cf-blocks th:nth-child(1) { width: 28%; } .cf-blocks th:nth-child(2) { width: 13%; } .cf-blocks th:nth-child(3) { width: 27%; } .cf-blocks th:nth-child(4) { width: 10%; } .cf-blocks th:nth-child(5) { width: 11%; }

/* ---------- tabelas comerciais (lista, detalhe por condição, edição) ---------- */
td.ct-conds-cell { max-width: 360px; }
td.ct-conds-cell small { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.ct-head { padding: 14px 18px; }
.ct-meta { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(130px, 40%), 1fr)); gap: 10px 20px; margin: 0; }
.ct-meta dt { font-size: 12px; font-weight: 650; letter-spacing: .03em; text-transform: uppercase; color: var(--ink-3); }
.ct-meta dd { margin: 2px 0 0; font-size: 15px; font-weight: 650; color: var(--ink); overflow-wrap: anywhere; }
.ct-meta dd small { display: block; font-size: 13px; font-weight: 400; color: var(--ink-3); }
.ct-notes { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); font-size: 14px; color: var(--ink-2); }
.ct-tabs { display: flex; gap: 2px; padding: 0 8px; overflow-x: auto; overflow-y: hidden; border-bottom: 1px solid var(--line-2); background: var(--white); scrollbar-width: thin; }
.ct-tab { flex: none; display: inline-flex; flex-direction: column; align-items: flex-start; justify-content: center; min-height: 52px; padding: 6px 14px; border-bottom: 3px solid transparent; font-size: 14px; font-weight: 650; color: var(--ink-3); text-align: left; line-height: 1.3; }
.ct-tab small { font-size: 12px; font-weight: 500; color: var(--ink-4); }
.ct-tab:hover { color: var(--ink); border-bottom-color: var(--line-3); }
.ct-tab.is-on { color: var(--ink); border-bottom-color: var(--ink); }
.ct-tab.is-on small { color: var(--ink-3); }
.ct-tab:focus-visible { outline: none; box-shadow: inset 0 0 0 2px var(--ink); }
.ct-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--soft); }
.ct-bar .lq { width: 280px; max-width: 100%; min-height: 34px; height: 34px; font-size: 14px; }
.ct-bar__n { font-size: 13px; }
.ct-bar__acts { margin-left: auto; flex-wrap: wrap; }
.ct-card > .table-wrap, .ct-card > .ct-wrap { border: 0; border-radius: 0; }
.ct-card > .ct-alert { margin: 10px 14px; }
.ct-wrap { max-height: min(72vh, 860px); }
.ct-grid th { padding: 8px 10px; font-size: 13px; vertical-align: bottom; }
.ct-grid td { height: 36px; padding: 6px 10px; }
.ct-grid td.mono, .ct-grid small.mono { font-size: 13px; }
.ct-grid .ct-p { font-weight: 650; color: var(--ink); }
.ct-grid--all th.right { min-width: 120px; max-width: 170px; white-space: normal; line-height: 1.3; }
.ct-grid--all td.right small { white-space: nowrap; }
/* edição */
.ct-editing .card + .card { margin-top: var(--gap); }
.ct-conds { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.drawer .ct-conds { grid-template-columns: minmax(0, 1fr); gap: 10px; margin-top: 10px; }
.ct-cond { padding: 10px 12px; border: 1px solid var(--line-2); border-left: 4px solid var(--ink); border-radius: var(--radius-sm); background: var(--soft); }
.ct-cond__head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; font-size: 14px; }
.ct-cond__head .btn { margin-left: auto; }
.ct-cond__grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px 10px; }
.ct-cond__pay { grid-column: 1 / -1; }
.ct-cond__grid label { white-space: nowrap; }
.ct-cond__grid label { font-size: 13px; gap: 4px; }
.ct-cond__grid input, .ct-cond__grid select { min-height: 36px; padding: 0 8px; font-size: 14px; }
.ct-cond__grid select { padding-right: 26px; }
.ct-cond__name { grid-column: 1 / -1; }
.ct-tools { display: flex; flex-wrap: wrap; gap: 10px 28px; padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--soft); }
.ct-tool { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 14px; }
.ct-tool > label:not(.btn) { display: flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; }
.ct-tool select, .ct-tool input { width: auto; min-height: 34px; height: 34px; padding: 0 8px; font-size: 14px; }
.ct-tool select { max-width: 240px; padding-right: 26px; }
.ct-tool input { width: 80px; }
.ct-imp { padding: 12px 14px; border-bottom: 1px solid var(--line); background: var(--amber-bg); }
.ct-imp > * + * { margin-top: 8px; }
.ct-imp .card__head h3 { font-size: 15px; }
.ct-imp .table-wrap { max-height: 320px; background: var(--white); }
.ct-edit td { height: auto; padding: 4px 5px; vertical-align: top; }
.ct-edit th { padding: 8px 6px; }
.ct-edit td.ct-n { padding-top: 12px; font-size: 13px; }
.ct-edit input { min-height: 34px; height: 34px; padding: 0 8px; font-size: 14px; }
.ct-edit input.is-bad { border-color: var(--red); background: var(--red-bg); }
.ct-edit .ct-in-prod { min-width: 230px; }
.ct-edit .ct-in-ncm { width: 108px; font-family: var(--mono); font-size: 13px; }
.ct-edit .ct-in-mid { min-width: 110px; }
.ct-edit .ct-in-num { width: 80px; text-align: right; }
.ct-edit .ct-in-price { width: 100%; min-width: 120px; text-align: right; font-weight: 650; }
.ct-edit th.ct-ch { min-width: 178px; max-width: 220px; white-space: normal; line-height: 1.25; }
.ct-edit th.ct-ch small { display: block; font-size: 12px; font-weight: 500; color: var(--ink-3); }
.ct-edit .ct-d { display: block; max-width: 220px; min-height: 16px; margin-top: 3px; font-size: 12px; line-height: 1.3; color: var(--ink-3); white-space: normal; text-align: right; }
.ct-reason { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.ct-reason input { width: 260px; min-height: 36px; font-size: 14px; }
/* venda: condição comercial */
.ct-sale__pick { grid-column: 1 / -1; max-width: 760px; }
.ct-sale__terms { margin-top: 10px; font-size: 14px; color: var(--ink-2); }
.ct-sale__terms .tag { margin-left: 4px; }
.ct-sale__add { margin-top: 10px; }
.ct-sale__add select { flex: 1 1 360px; min-width: 0; max-width: 680px; }
.ct-sale__add input { width: 110px; }
tr.is-pending > td { background: var(--amber-bg) !important; }
@media (max-width: 640px) {
  .ct-conds { grid-template-columns: minmax(0, 1fr); }
  .ct-bar__acts { margin-left: 0; }
  .ct-bar .lq { width: 100%; }
  .ct-reason { flex: 1 1 100%; }
  .ct-reason input { width: 100%; }
  .ct-sale__add input { width: 90px; }
}

/* Ficheiros dos documentos do embarque (venda e ficha do cliente) */
.ship-files { display: grid; gap: 0; border: 1px solid var(--line); border-radius: 8px; }
.ship-files__row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px 12px; align-items: center; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.ship-files__row > .ship-files__list { grid-column: 1 / -1; order: 3; }
.ship-files__row:last-child { border-bottom: 0; }
.ship-files__list { display: flex; flex-wrap: wrap; gap: 6px; min-width: 0; }
.ship-files__item { display: inline-flex; gap: 4px; max-width: 100%; min-width: 0; }
.ship-file { max-width: 100%; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: inline-block; }

td .ship-files__list { display: flex; flex-direction: column; align-items: flex-start; }
td .ship-file { max-width: 128px; }

/* Botão "Voltar" na barra de topo (ecrã anterior dentro do painel) */
.topbar__back { display: inline-flex; align-items: center; gap: 4px; min-height: 36px; padding: 0 12px 0 6px; border: 1px solid var(--line-2); border-radius: var(--radius-sm); background: var(--white); font-size: 14px; font-weight: 600; color: var(--ink); cursor: pointer; }
.topbar__back:hover:not(:disabled) { border-color: var(--ink); }
.topbar__back:disabled { opacity: .35; cursor: default; }
/* Referências nas respostas da IA */
.ref-link { font-weight: 650; text-decoration: underline; text-underline-offset: 2px; }
.ref-chip { display: inline-block; padding: 0 6px; border: 1px solid var(--ink); border-radius: 4px; background: var(--white); font: inherit; font-weight: 650; line-height: 1.5; cursor: pointer; }
.ref-chip:hover { background: var(--ink); color: var(--white); }

/* Tabela de preços por fruta */
.fruit-tabs { display: flex; flex-wrap: wrap; gap: 6px; }
.fruit-tab { display: inline-flex; align-items: center; gap: 6px; min-height: 34px; padding: 0 12px; border: 1px solid var(--line-2); border-radius: 999px; background: var(--white); font: inherit; font-size: 14px; font-weight: 600; color: var(--ink); cursor: pointer; }
.fruit-tab b { font-weight: 700; color: var(--ink-3); }
.fruit-tab:hover { border-color: var(--ink); }
.fruit-tab.is-on { background: var(--ink); border-color: var(--ink); color: var(--white); }
.fruit-tab.is-on b { color: var(--white); }

/* App instalável */
.install-btn { margin-top: 12px; }
.side-install { display: block; width: 100%; margin-bottom: 8px; padding: 8px 10px; border: 1px solid rgba(255, 255, 255, .35); border-radius: var(--radius-sm); background: transparent; color: #fff; font: inherit; font-size: 14px; font-weight: 600; text-align: left; cursor: pointer; }
.side-install:hover { border-color: #fff; }
.side-install[hidden], .install-btn[hidden], .topbar__install[hidden] { display: none; }
.install-steps { margin: 0 0 8px 18px; display: grid; gap: 6px; }
@media (max-width: 720px) {
  .topbar__install { display: none; }
  /* Telemóvel: o "Voltar" fica só com a seta, para não tapar o logótipo. */
  .topbar__back { padding: 0 6px; min-width: 40px; justify-content: center; }
  .topbar__back span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
}
