/* GesAI Invoice - base visual (blocos A e A2).
   Tema escuro por omissão. O tema claro aplica-se de três formas, todas só com CSS:
   com a classe t-light no elemento html; pela preferência do computador
   (prefers-color-scheme: light) quando o html não tem classe t-dark nem t-light;
   e na impressão (papel branco, texto escuro). As três cópias das variáveis do tema
   claro têm de ser iguais: scripts/verificar_contraste_app.mjs compara-as e mede-as.
   Sem ficheiros de fonte nem pedidos externos: a CSP exige font-src 'self'.
   As fontes do design vêm primeiro na pilha; sem elas, usa-se system-ui. */

:root {
  color-scheme: dark;

  --font-display: "Space Grotesk", "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-text: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;

  --bg: #0b111e;
  --panel: #0f1b2e;
  --panel2: #16233a;
  --line: #22304a;
  --line-strong: #6b7b99;
  --field: #0b111e;
  --text: #f8f9fb;
  --muted: #a3aec2;
  --dim: #8a96ac;
  --link: #7db0ff;
  --teal-t: #3fdcca;
  --focus: #21cab9;
  --grid: rgba(125, 176, 255, 0.07);

  --ok-bg: rgba(33, 202, 185, 0.14);
  --ok-t: #4fe0d0;
  --warn-bg: rgba(251, 191, 36, 0.14);
  --warn-t: #fbbf24;
  --bad-bg: rgba(239, 67, 67, 0.18);
  --bad-t: #ff9a9a;
  --info-bg: rgba(60, 131, 246, 0.18);
  --info-t: #9cc2ff;
  --mute-bg: rgba(148, 163, 184, 0.14);
  --mute-t: #b8c2d4;

  --side-bg: #070c17;
  --side-line: #18233a;
  --side-text: #f8f9fb;
  --side-muted: #a3aec2;
  --side-hover: rgba(255, 255, 255, 0.07);
  --side-active: rgba(60, 131, 246, 0.22);
  --side-accent: #3fdcca;
  --side-focus: #21cab9;

  --shade: rgba(125, 176, 255, 0.4);

  --grad-a: #3c83f6;
  --grad-b: #21cab9;
  --grad: linear-gradient(135deg, var(--grad-a), var(--grad-b));
  --on-grad: #07101f;

  --r-card: 18px;
  --r-btn: 12px;
  --target: 44px;
}

:root.t-light {
  color-scheme: light;

  --bg: #f8f9fb;
  --panel: #ffffff;
  --panel2: #f1f3f7;
  --line: #e1e5ec;
  --line-strong: #6b7689;
  --field: #ffffff;
  --text: #0f1729;
  --muted: #475264;
  --dim: #5c6676;
  --link: #1b55c4;
  --teal-t: #0a6b62;
  --focus: #0a6b62;
  --grid: rgba(15, 23, 41, 0.05);

  --ok-bg: #ddf7f3;
  --ok-t: #0a6b62;
  --warn-bg: #fdf1cf;
  --warn-t: #7a5200;
  --bad-bg: #fde3e3;
  --bad-t: #b42323;
  --info-bg: #e3eefe;
  --info-t: #1b55c4;
  --mute-bg: #edf0f4;
  --mute-t: #475264;

  --side-bg: #ffffff;
  --side-line: #e1e5ec;
  --side-text: #0f1729;
  --side-muted: #475264;
  --side-hover: rgba(15, 23, 41, 0.06);
  --side-active: rgba(27, 85, 196, 0.12);
  --side-accent: #0a6b62;
  --side-focus: #0a6b62;

  --shade: rgba(15, 23, 41, 0.28);
}

/* Preferência do computador: só quando o html não tem classe de tema explícita.
   Na impressão aplica-se o mesmo tema claro, mesmo com o tema escuro escolhido. */
@media print, (prefers-color-scheme: light) {
  :root:not(.t-dark):not(.t-light) {
    color-scheme: light;

    --bg: #f8f9fb;
    --panel: #ffffff;
    --panel2: #f1f3f7;
    --line: #e1e5ec;
    --line-strong: #6b7689;
    --field: #ffffff;
    --text: #0f1729;
    --muted: #475264;
    --dim: #5c6676;
    --link: #1b55c4;
    --teal-t: #0a6b62;
    --focus: #0a6b62;
    --grid: rgba(15, 23, 41, 0.05);

    --ok-bg: #ddf7f3;
    --ok-t: #0a6b62;
    --warn-bg: #fdf1cf;
    --warn-t: #7a5200;
    --bad-bg: #fde3e3;
    --bad-t: #b42323;
    --info-bg: #e3eefe;
    --info-t: #1b55c4;
    --mute-bg: #edf0f4;
    --mute-t: #475264;

    --side-bg: #ffffff;
    --side-line: #e1e5ec;
    --side-text: #0f1729;
    --side-muted: #475264;
    --side-hover: rgba(15, 23, 41, 0.06);
    --side-active: rgba(27, 85, 196, 0.12);
    --side-accent: #0a6b62;
    --side-focus: #0a6b62;

    --shade: rgba(15, 23, 41, 0.28);
  }
}

@media print {
  :root.t-dark {
    color-scheme: light;

    --bg: #f8f9fb;
    --panel: #ffffff;
    --panel2: #f1f3f7;
    --line: #e1e5ec;
    --line-strong: #6b7689;
    --field: #ffffff;
    --text: #0f1729;
    --muted: #475264;
    --dim: #5c6676;
    --link: #1b55c4;
    --teal-t: #0a6b62;
    --focus: #0a6b62;
    --grid: rgba(15, 23, 41, 0.05);

    --ok-bg: #ddf7f3;
    --ok-t: #0a6b62;
    --warn-bg: #fdf1cf;
    --warn-t: #7a5200;
    --bad-bg: #fde3e3;
    --bad-t: #b42323;
    --info-bg: #e3eefe;
    --info-t: #1b55c4;
    --mute-bg: #edf0f4;
    --mute-t: #475264;

    --side-bg: #ffffff;
    --side-line: #e1e5ec;
    --side-text: #0f1729;
    --side-muted: #475264;
    --side-hover: rgba(15, 23, 41, 0.06);
    --side-active: rgba(27, 85, 196, 0.12);
    --side-accent: #0a6b62;
    --side-focus: #0a6b62;

    --shade: rgba(15, 23, 41, 0.28);
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  background: var(--bg);
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font-text);
  -webkit-text-size-adjust: 100%;
}

a {
  color: var(--link);
  text-underline-offset: 3px;
}

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

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

main:focus {
  outline: none;
}

h1 {
  font-family: var(--font-display);
  font-size: clamp(24px, 2.2vw + 14px, 30px);
  line-height: 1.2;
  margin: 0 0 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

h2 {
  font-family: var(--font-display);
  font-size: 19px;
  line-height: 1.3;
  font-weight: 600;
  margin: 0 0 8px;
}

p {
  margin: 0 0 12px;
}

code {
  font-family: var(--font-mono);
  font-size: 0.93em;
}

.eyebrow {
  font-family: var(--font-mono);
  text-transform: uppercase;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.08em;
  color: var(--dim);
  margin: 0 0 6px;
}

.intro {
  max-width: 700px;
  color: var(--muted);
  margin: 0 0 28px;
  font-size: 15px;
}

.muted {
  color: var(--muted);
  font-size: 13px;
}

.sr-only,
.skip {
  position: absolute;
  left: -10000px;
}

.skip:focus {
  left: 16px;
  top: 12px;
  z-index: 20;
  min-height: var(--target);
  display: inline-flex;
  align-items: center;
  padding: 0 18px;
  border-radius: var(--r-btn);
  background: var(--grad);
  color: var(--on-grad);
  font-weight: 700;
  text-decoration: none;
}

/* ---------- Estrutura: menu lateral de 232 px ---------- */

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app.has-side {
  flex-direction: row;
}

.side {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 20px;
  padding: 10px 28px;
  background: var(--side-bg);
  color: var(--side-text);
  border-bottom: 1px solid var(--side-line);
}

.has-side > .side {
  flex: 0 0 232px;
  width: 232px;
  flex-direction: column;
  flex-wrap: nowrap;
  align-items: stretch;
  gap: 18px;
  padding: 22px 14px;
  border-bottom: 0;
  border-right: 1px solid var(--side-line);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: var(--target);
  padding: 0 8px;
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 700;
  text-decoration: none;
  color: var(--side-text);
}

.brand span {
  font-weight: 400;
}

.brand::before {
  content: "G";
  content: "G" / "";
  flex: none;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--grad);
  color: var(--on-grad);
  display: grid;
  place-items: center;
  font-size: 19px;
  font-weight: 700;
}

.environment {
  display: inline-flex;
  align-items: center;
  align-self: flex-start;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 12px;
  background: var(--warn-bg);
  color: var(--warn-t);
  box-shadow: inset 0 0 0 1px var(--warn-t);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.3;
}

.environment::before {
  content: "";
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  border: 1.5px dashed currentColor;
}

.side form {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
}

.has-side > .side form {
  margin: auto 0 0;
  flex-wrap: wrap;
  padding: 10px 8px 0;
  border-top: 1px solid var(--side-line);
}

.user {
  font-size: 13px;
  font-weight: 600;
  color: var(--side-text);
}

.side .link {
  color: var(--side-muted);
}

.company-bar {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px;
  border: 1px solid var(--side-line);
  border-radius: var(--r-btn);
}

.company-bar small {
  display: block;
  color: var(--side-muted);
  font-size: 12px;
}

.company-bar strong {
  display: block;
  font-size: 15px;
  overflow-wrap: anywhere;
}

.company-bar a {
  display: inline-flex;
  align-items: center;
  min-height: var(--target);
  color: var(--side-muted);
  font-size: 13px;
}

.company-bar a:hover {
  color: var(--side-text);
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav a {
  display: flex;
  align-items: center;
  min-height: var(--target);
  padding: 0 12px;
  border-radius: 10px;
  color: var(--side-muted);
  font-weight: 500;
  text-decoration: none;
}

.nav a:hover {
  background: var(--side-hover);
  color: var(--side-text);
}

.nav a[aria-current="page"] {
  background: var(--side-active);
  color: var(--side-text);
  font-weight: 700;
  box-shadow: inset 3px 0 0 var(--side-accent);
}

.side :focus-visible {
  outline-color: var(--side-focus);
}

.nav a:focus-visible {
  outline-offset: -2px;
}

.main-col {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

main {
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
  padding: 28px 36px 56px;
  flex: 1 0 auto;
}

footer {
  padding: 18px 36px;
  text-align: center;
  font-size: 12px;
  color: var(--dim);
  border-top: 1px solid var(--line);
}

/* ---------- Botões ---------- */

button,
.button,
.primary {
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--target);
  padding: 0 18px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-btn);
  background: var(--panel);
  color: var(--text);
  font-weight: 600;
  text-decoration: none;
  transition: background-color 0.12s;
}

button:hover,
.button:hover {
  background: var(--panel2);
}

.primary,
button.primary,
.button.primary {
  background: var(--grad);
  color: var(--on-grad);
  border-color: transparent;
  font-weight: 700;
}

.primary:hover,
button.primary:hover,
.button.primary:hover {
  background: var(--grad);
  filter: brightness(1.08);
}

.link {
  background: transparent;
  border: 0;
  padding: 0 8px;
  color: var(--link);
  font-weight: 500;
}

.link:hover {
  background: transparent;
  text-decoration: underline;
}

/* ---------- Cartões, listas e painéis ---------- */

.card,
.next-action {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-card);
  padding: 22px 24px;
  margin-bottom: 16px;
}

.card pre,
#email-preview pre {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.next-action {
  max-width: 660px;
}

.next-action p {
  color: var(--muted);
}

.hero {
  padding: 30px 32px 8px;
  margin-bottom: 24px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background-color: var(--panel);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 32px 32px;
}

.hero .intro {
  margin-bottom: 20px;
}

.stats {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin: 0 0 24px;
}

.stats > div {
  min-width: 190px;
  padding: 16px 22px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-card);
}

.stats strong {
  display: block;
  font-family: var(--font-display);
  font-size: 36px;
  line-height: 1.15;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.stats span {
  color: var(--muted);
}

.page-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px 20px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.page-title h1 {
  margin-bottom: 0;
}

.company-list {
  max-width: 760px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 28px;
}

.company-choice {
  display: flex;
  gap: 16px;
  align-items: center;
  min-height: 72px;
  padding: 14px 20px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-card);
  color: var(--text);
  text-decoration: none;
}

.company-choice:hover {
  background: var(--panel2);
}

.company-choice strong,
.company-choice small {
  display: block;
}

.company-choice small {
  font-size: 13px;
  color: var(--muted);
  margin-top: 2px;
}

.company-choice > span:last-child {
  margin-left: auto;
  color: var(--teal-t);
  font-size: 20px;
}

.company-icon {
  flex: none;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  background: var(--grad);
  color: var(--on-grad);
  border-radius: 12px;
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 700;
}

.empty {
  padding: 32px 20px;
  color: var(--muted);
}

/* ---------- Estados: cor + forma + texto ---------- */

.pill,
.tag {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 26px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  background: var(--info-bg);
  color: var(--info-t);
}

.tag::before {
  content: "";
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  border: 2px solid currentColor;
}

.pill .sh {
  flex: none;
  width: 8px;
  height: 8px;
}

.p-ok {
  background: var(--ok-bg);
  color: var(--ok-t);
}

.p-warn {
  background: var(--warn-bg);
  color: var(--warn-t);
}

.p-bad {
  background: var(--bad-bg);
  color: var(--bad-t);
}

.p-mute {
  background: var(--mute-bg);
  color: var(--mute-t);
}

.sh-ok {
  border-radius: 50%;
  background: currentColor;
}

.sh-warn {
  border-radius: 50%;
  border: 2px solid currentColor;
}

.sh-bad {
  background: currentColor;
  transform: rotate(45deg);
}

.sh-mute {
  border-radius: 50%;
  border: 1.5px dashed currentColor;
}

/* ---------- Pesquisa e tabelas ---------- */

.search {
  margin: 20px 0;
}

.search label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 6px;
}

.search > div {
  display: flex;
  gap: 10px;
  max-width: 560px;
}

.search input {
  flex: 1 1 auto;
  min-width: 0;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--r-card);
  margin-bottom: 16px;
  /* Tabela mais larga do que o ecrã: desliza na horizontal e as margens mostram
     uma sombra do lado onde ainda há conteúdo (só CSS; some quando se chega ao fim). */
  background-color: var(--panel);
  background-image:
    linear-gradient(to right, var(--panel), var(--panel)),
    linear-gradient(to left, var(--panel), var(--panel)),
    linear-gradient(to right, var(--shade), transparent),
    linear-gradient(to left, var(--shade), transparent);
  background-position: left center, right center, left center, right center;
  background-repeat: no-repeat;
  background-size: 28px 100%, 28px 100%, 20px 100%, 20px 100%;
  background-attachment: local, local, scroll, scroll;
}

table {
  border-collapse: collapse;
  width: 100%;
  min-width: 520px;
  text-align: left;
  font-variant-numeric: tabular-nums;
}

th {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--dim);
  white-space: nowrap;
}

th,
td {
  padding: 8px 20px;
  border-bottom: 1px solid var(--line);
}

td {
  height: 56px;
}

tbody tr:hover td {
  background: var(--panel2);
}

tbody tr:last-child td {
  border-bottom: 0;
}

td a,
main > a {
  display: inline-flex;
  align-items: center;
  min-height: var(--target);
}

/* Coluna de valores à direita: a classe vai na tabela (num-3 = 3.ª coluna, num-4 = 4.ª). */
.num-3 :is(th, td):nth-child(3),
.num-4 :is(th, td):nth-child(4) {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* ---------- Formulários ---------- */

.editor {
  max-width: 720px;
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 28px;
  border-radius: 22px;
  margin-bottom: 24px;
}

.field {
  margin-bottom: 20px;
}

.field label,
.login label {
  display: block;
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 6px;
}

.field small {
  display: block;
  color: var(--muted);
  margin-top: 6px;
}

input,
select,
textarea {
  display: block;
  width: 100%;
  min-height: var(--target);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-btn);
  padding: 9px 14px;
  background: var(--field);
  color: var(--text);
}

textarea {
  min-height: 96px;
}

input::placeholder,
textarea::placeholder {
  color: var(--dim);
  opacity: 1;
}

input[type="checkbox"],
input[type="radio"] {
  width: 24px;
  height: 24px;
  min-height: 0;
  padding: 0;
  accent-color: var(--focus);
}

.actions {
  display: flex;
  gap: 12px 24px;
  flex-wrap: wrap;
  align-items: center;
  margin-top: 28px;
}

.actions a {
  display: inline-flex;
  align-items: center;
  min-height: var(--target);
}

.errorlist,
.error {
  list-style: none;
  margin: 8px 0;
  padding: 10px 14px;
  background: var(--bad-bg);
  color: var(--bad-t);
  border-radius: 10px;
  font-size: 14px;
}

.errorlist li {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.errorlist li::before,
.errorlist:not(ul)::before,
.error::before {
  content: "";
  flex: none;
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 10px;
  vertical-align: 0.05em;
  background: currentColor;
  transform: rotate(45deg);
}

.errorlist li::before {
  margin-right: 0;
}

.messages p,
.notice {
  margin: 0 0 16px;
  padding: 12px 16px;
  background: var(--info-bg);
  color: var(--text);
  border: 1px solid var(--line);
  border-left: 4px solid var(--link);
  border-radius: 10px;
}

/* ---------- Entrada e contas ---------- */

.login {
  max-width: 460px;
  margin: 24px auto;
  padding: 32px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 24px;
}

.login .eyebrow {
  color: var(--teal-t);
}

.login label {
  margin: 18px 0 6px;
}

.login .primary,
.login button.primary {
  width: 100%;
  margin-top: 24px;
}

.login a.primary {
  width: auto;
  margin-top: 0;
}

.login .link {
  margin-top: 8px;
}

.recovery-codes {
  list-style: none;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.recovery-codes li {
  padding: 10px 14px;
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 10px;
  text-align: center;
}

/* ---------- Ecrãs estreitos: o menu passa para cima ---------- */

@media (max-width: 899px) {
  .app.has-side {
    flex-direction: column;
  }

  /* A ordem visual é a do HTML (marca, aviso, empresa, menu, Sair): sem "order",
     para o Tab seguir o que se vê. */
  .has-side > .side {
    position: static;
    height: auto;
    width: auto;
    flex: none;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px 12px;
    padding: 8px 16px;
    border-right: 0;
    border-bottom: 1px solid var(--side-line);
    overflow: visible;
  }

  .has-side > .side form {
    margin: 0 0 0 auto;
    padding: 0;
    border-top: 0;
    flex: none;
  }

  .has-side > .side .environment {
    flex: 1 1 0;
    min-width: 150px;
    align-self: center;
  }

  .company-bar {
    flex: 1 1 100%;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 4px 12px;
  }

  /* Menu numa só linha que desliza na horizontal, com sombra nas margens. */
  .nav {
    flex: 1 1 0;
    min-width: 0;
    flex-direction: row;
    flex-wrap: nowrap;
    gap: 4px;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
    background-color: var(--side-bg);
    background-image:
      linear-gradient(to right, var(--side-bg), var(--side-bg)),
      linear-gradient(to left, var(--side-bg), var(--side-bg)),
      linear-gradient(to right, var(--shade), transparent),
      linear-gradient(to left, var(--shade), transparent);
    background-position: left center, right center, left center, right center;
    background-repeat: no-repeat;
    background-size: 28px 100%, 28px 100%, 20px 100%, 20px 100%;
    background-attachment: local, local, scroll, scroll;
  }

  .nav a {
    flex: none;
    white-space: nowrap;
  }

  main {
    padding: 22px 16px 40px;
  }

  footer {
    padding: 16px;
  }

  .hero {
    padding: 22px 18px 4px;
    border-radius: 18px;
  }
}

@media (max-width: 650px) {
  .side {
    padding: 8px 16px;
  }

  .user {
    display: none;
  }

  .editor {
    padding: 20px 16px;
  }

  .login {
    padding: 22px 18px;
    margin: 8px auto;
  }

  .stats > div {
    flex: 1 1 100%;
  }

  .search > div {
    flex-wrap: wrap;
  }

  .search input {
    min-width: 100%;
  }

  .actions {
    gap: 12px;
  }

  .company-choice {
    padding: 12px 14px;
  }

  .recovery-codes {
    grid-template-columns: minmax(0, 1fr);
  }

  .count-import-preview {
    min-width: 0;
    table-layout: fixed;
  }

  .count-import-preview th,
  .count-import-preview td {
    padding: 10px 6px;
    overflow-wrap: anywhere;
  }

  .count-import-preview th:first-child {
    width: 46%;
  }

  .count-import-preview th:nth-child(2) {
    width: 25%;
  }

  .count-import-preview th:nth-child(3) {
    width: 29%;
  }
}

/* ---------- Impressão de uma página da aplicação ---------- */
/* As variáveis do tema claro vêm do bloco "@media print" no início do ficheiro. */

@media print {
  .side,
  .skip,
  footer {
    display: none;
  }

  .app,
  .app.has-side,
  .main-col {
    display: block;
    min-height: 0;
  }

  html,
  body {
    background: #fff;
    color: #000;
  }

  main {
    max-width: none;
    padding: 0;
  }

  .hero {
    background-image: none;
  }

  .table-wrap {
    overflow: visible;
    background-image: none;
    border-radius: 0;
  }

  table {
    min-width: 0;
  }

  thead {
    display: table-header-group;
  }

  tr,
  .card,
  .stats > div {
    break-inside: avoid;
  }

  a {
    color: #000;
  }

  button,
  .button,
  .primary,
  button.primary,
  .button.primary {
    border-color: #000;
    background: #fff;
    color: #000;
  }
}

@page {
  margin: 15mm;
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    scroll-behavior: auto !important;
  }
}

/* ---------- SIMULAÇÃO em papel ---------- */
/* Toda a página da aplicação que se imprima leva a faixa «SIMULAÇÃO — NÃO É DOCUMENTO FISCAL» no topo e no fim da página (e, onde o navegador o permite, no pé de cada folha).
   Só preto sobre branco, com borda e negrito: lê-se em preto e branco e não depende de cor nem de fundo. */

.simulacao-papel {
  display: none;
}

@media print {
  .simulacao-papel {
    display: block;
    margin: 0 0 8mm;
    padding: 2mm 3mm;
    border: 0.8mm solid #000;
    background: #fff;
    color: #000;
    font-size: 12pt;
    font-weight: 700;
    line-height: 1.3;
    text-align: center;
    text-transform: none;
    break-inside: avoid;
  }

  main + .simulacao-papel {
    margin: 8mm 0 0;
  }
}

/* Nos navegadores que suportam caixas de margem (Chromium), a faixa repete-se também no pé de cada folha. */
@page {
  margin: 15mm 15mm 24mm;

  @bottom-center {
    content: "SIMULAÇÃO — NÃO É DOCUMENTO FISCAL · Dados fictícios";
    box-sizing: border-box;
    width: 100%;
    margin-bottom: 4mm;
    padding: 2mm 3mm;
    border: 0.8mm solid #000;
    background: #fff;
    color: #000;
    font-family: sans-serif;
    font-size: 12pt;
    font-weight: 700;
    text-align: center;
    vertical-align: middle;
  }
}

/* ===== B1 · rascunhos e avenças (início) =====
   Só o que falta nos componentes do bloco A: fila de ligações, ações por linha, paginação, legenda e colunas
   numéricas 2 e 5. Fim do bloco abaixo. */

.link-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0 22px;
  margin: 0 0 12px;
}

.link-row a {
  display: inline-flex;
  align-items: center;
  min-height: var(--target);
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 16px;
}

.row-actions form {
  margin: 0;
}

.pager {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0 20px;
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 13px;
}

.pager a {
  display: inline-flex;
  align-items: center;
  min-height: var(--target);
}

caption:not(.sr-only) {
  padding: 14px 20px 6px;
  text-align: left;
  font-size: 13px;
  color: var(--muted);
}

.num-2 :is(th, td):nth-child(2),
.num-5 :is(th, td):nth-child(5) {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* ===== fim B1 ===== */

/* ===== BLOCO C: nova fatura em formulário (início) =====
   Duas colunas: campos e linhas à esquerda, pré-visualização com o aspeto da folha à direita.
   Cada coluna precisa de 460 px; abaixo disso a pré-visualização passa para baixo do formulário (uma coluna).
   A folha é sempre clara (papel), em qualquer tema: as suas cores são fixas e não vêm das variáveis do tema.
   Só apresentação: não calcula nada. */

.nf-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 24px;
  align-items: flex-start;
}

.nf-col-form,
.nf-col-previa {
  flex: 1 1 460px;
  min-width: 0;
}

.nf-col-form .editor {
  max-width: none;
}

.nf-linhas {
  margin-top: 28px;
}

/* A tabela de linhas guardadas já existia: na meia coluna os cabeçalhos quebram em vez de cortar. */
.nf-linhas table {
  min-width: 0;
}

.nf-linhas th,
.nf-linhas td {
  padding: 8px 6px;
}

.nf-linhas td button {
  padding: 0 12px;
}

.nf-linhas th {
  white-space: normal;
}

.nf-previa-topo {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 12px;
  min-height: 28px;
  margin-bottom: 10px;
}

.nf-previa-rotulo {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--dim);
}

.folha {
  padding: 32px 32px 26px;
  border: 1px solid #c9d0dc;
  border-radius: 6px;
  background: #ffffff;
  color: #0f1729;
  box-shadow: 0 10px 30px rgba(8, 14, 28, 0.22);
  font-size: 13px;
  line-height: 1.45;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

:where(.folha) p {
  margin: 0;
}

.folha a {
  color: #1b55c4;
}

.folha-cab {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px 20px;
}

.folha-empresa {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.folha-tipo {
  margin-left: auto;
  text-align: right;
}

.folha-tipo-nome {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.folha-tipo-ref {
  margin-top: 2px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: #5c6676;
  overflow-wrap: anywhere;
}

.folha-para {
  padding: 14px 0;
  border-top: 2px solid #0f1729;
  border-bottom: 1px solid #e1e5ec;
}

.folha-rotulo {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #5c6676;
}

.folha-cliente {
  margin-top: 4px;
  font-size: 15px;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.folha-tab {
  min-width: 0;
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

.folha-tab th,
.folha-tab td {
  height: auto;
  padding: 10px 8px;
  background: transparent;
  border-bottom: 1px solid #e1e5ec;
  color: #0f1729;
  vertical-align: top;
}

.folha-tab th {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #5c6676;
  white-space: nowrap;
}

.folha-tab tbody tr:last-child td {
  border-bottom: 1px solid #e1e5ec;
}

.folha-tab tbody tr:hover td {
  background: transparent;
}

.folha-tab :is(th, td):first-child {
  padding-left: 0;
  text-align: left;
}

.folha-tab :is(th, td):not(:first-child) {
  text-align: right;
  white-space: nowrap;
}

.folha-tab :is(th, td):last-child {
  padding-right: 0;
}

.folha-desc {
  font-weight: 600;
  overflow-wrap: anywhere;
}

.folha-sub {
  display: block;
  font-size: 12px;
  font-weight: 400;
  color: #5c6676;
}

.folha-forte {
  font-weight: 700;
}

.folha-vazio {
  padding: 18px 0;
  border-bottom: 1px solid #e1e5ec;
  color: #5c6676;
}

.folha-totais {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.folha-total-linha {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  width: 280px;
  max-width: 100%;
  margin-left: auto;
  font-variant-numeric: tabular-nums;
}

.folha-total-linha span:first-child {
  color: #5c6676;
}

.folha-total-final {
  padding-top: 10px;
  border-top: 2px solid #0f1729;
}

.folha-total-final span:first-child {
  color: #0f1729;
  font-weight: 700;
}

.folha-total-final span:last-child {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 700;
}

.folha-nota {
  font-size: 12px;
  color: #5c6676;
}

@media (max-width: 650px) {
  .folha {
    padding: 20px 16px 18px;
    gap: 18px;
  }

  .folha-total-linha {
    width: 100%;
  }
}

/* ===== BLOCO C (fim) ===== */
