/* =================================================================== */
/* Tokens — a paleta deriva do verde do logotipo (#0cb16d)             */
/* =================================================================== */
:root,
:root[data-theme='dark'] {
  --page: #16191a;
  --shell: #0d1011;
  --surface: #14191a;
  --surface-2: #1b2224;
  --surface-3: #222b2d;
  --border: #232c2e;
  --border-soft: #1b2223;

  --text: #e7eeeb;
  --muted: #8a9a95;
  --faint: #5f706b;

  --accent: #0cb16d;
  --accent-hover: #14c67d;
  --accent-text: #34d68f; /* verde legível sobre superfícies escuras */
  --accent-soft: rgb(12 177 109 / 0.14);
  --on-accent: #04140d;

  --danger: #ff8a8a;
  --danger-soft: rgb(255 90 90 / 0.12);

  --checker-a: #1b2224;
  --checker-b: #151b1c;

  --radius-lg: 22px;
  --radius: 16px;
  --radius-sm: 11px;
  --shadow: 0 18px 44px rgb(0 0 0 / 0.42);
}

:root[data-theme='light'] {
  --page: #e9eeec;
  --shell: #ffffff;
  --surface: #ffffff;
  --surface-2: #f2f6f4;
  --surface-3: #e7edea;
  --border: #e0e8e5;
  --border-soft: #eef2f0;

  --text: #0f1a16;
  --muted: #5d6d67;
  --faint: #8c9a95;

  --accent: #0cb16d;
  --accent-hover: #0aa063;
  --accent-text: #067448; /* escurecido para contraste sobre branco */
  --accent-soft: rgb(12 177 109 / 0.12);
  --on-accent: #04140d;

  --danger: #b91c1c;
  --danger-soft: #fef2f2;

  --checker-a: #ffffff;
  --checker-b: #e7edea;

  --shadow: 0 16px 40px rgb(16 32 26 / 0.1);
}

* {
  box-sizing: border-box;
}

/* Vários blocos abaixo definem `display`, que por si só venceria o atributo
   `hidden`. Esta regra garante que esconder um elemento funciona sempre. */
[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  padding: 14px;
  background: var(--page);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, 'Segoe UI', Inter, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3,
p {
  margin: 0;
}

svg {
  width: 100%;
  height: 100%;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

svg.filled {
  fill: currentColor;
}

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

/* =================================================================== */
/* Estrutura                                                           */
/* =================================================================== */
.app {
  display: grid;
  grid-template-columns: 252px minmax(0, 1fr);
  height: calc(100vh - 28px);
  overflow: hidden;
  background: var(--shell);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.app.collapsed {
  grid-template-columns: 78px minmax(0, 1fr);
}

/* ------------------------------ Sidebar ---------------------------- */
.sidebar {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 18px 14px;
  border-right: 1px solid var(--border-soft);
  min-width: 0;
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 4px 4px;
}

.logo-full {
  width: 132px;
  height: auto;
}

.logo-mark {
  display: none;
  width: 22px;
  height: auto;
}

.app.collapsed .logo-full {
  display: none;
}

.app.collapsed .logo-mark {
  display: block;
  margin-inline: auto;
}

.app.collapsed .sidebar-head {
  flex-direction: column;
}

/* Navegação — os itens são os modos de remoção */
.nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-label {
  padding: 0 10px 6px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--faint);
}

.nav-item {
  cursor: pointer;
}

.nav-item input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.nav-body {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 11px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--muted);
  transition: background 0.14s, color 0.14s, border-color 0.14s;
}

.nav-body:hover {
  background: var(--surface-2);
  color: var(--text);
}

.nav-icon {
  flex: 0 0 auto;
  width: 19px;
  height: 19px;
}

.nav-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.nav-text strong {
  font-size: 13.5px;
  font-weight: 600;
  white-space: nowrap;
}

.nav-text small {
  font-size: 11.5px;
  color: var(--faint);
  white-space: nowrap;
}

.nav-chevron {
  margin-left: auto;
  font-size: 17px;
  line-height: 1;
  color: var(--faint);
}

.nav-item input:checked + .nav-body {
  background: var(--surface-2);
  border-color: var(--border);
  color: var(--text);
}

.nav-item input:checked + .nav-body .nav-icon {
  color: var(--accent-text);
}

.nav-item input:focus-visible + .nav-body {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.app.collapsed .nav-label,
.app.collapsed .nav-text,
.app.collapsed .nav-chevron,
.app.collapsed .tip-card {
  display: none;
}

.app.collapsed .nav-body {
  justify-content: center;
  padding: 11px;
}

/* Rodapé da barra lateral */
.sidebar-foot {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.tip-card {
  padding: 14px;
  background: linear-gradient(160deg, var(--accent-soft), transparent 70%), var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.tip-art {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 11px;
}

.tip-chip {
  padding: 3px 8px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--accent-text);
  background: var(--accent-soft);
  border-radius: 6px;
}

.tip-card strong {
  display: block;
  font-size: 13px;
}

.tip-card p {
  margin-top: 4px;
  font-size: 11.5px;
  line-height: 1.45;
  color: var(--muted);
}

.theme-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px;
  padding: 3px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.theme-opt {
  display: grid;
  place-items: center;
  height: 30px;
  padding: 0;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 9px;
  cursor: pointer;
}

.theme-opt svg {
  width: 16px;
  height: 16px;
}

.theme-opt:hover {
  color: var(--text);
}

.theme-opt.active {
  color: var(--text);
  background: var(--surface);
  box-shadow: 0 1px 3px rgb(0 0 0 / 0.25);
}

.app.collapsed .theme-switch {
  grid-template-columns: 1fr;
}

/* ------------------------------ Topbar ----------------------------- */
.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 18px;
}

.topbar-title h1 {
  font-size: 19px;
  font-weight: 650;
  letter-spacing: -0.015em;
}

.topbar-title p {
  margin-top: 2px;
  font-size: 12.5px;
  color: var(--muted);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

/* ------------------------------ Botões ----------------------------- */
.btn {
  padding: 9px 18px;
  font: inherit;
  font-size: 13.5px;
  font-weight: 600;
  border: 1px solid transparent;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
}

.btn-primary {
  background: var(--accent);
  color: var(--on-accent);
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-ghost {
  background: var(--surface-2);
  border-color: var(--border);
  color: var(--text);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--surface-3);
}

.btn:disabled,
.icon-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.icon-btn {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  padding: 8px;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
}

.icon-btn:hover:not(:disabled) {
  color: var(--text);
  background: var(--surface-3);
}

/* =================================================================== */
/* Cartões                                                             */
/* =================================================================== */
.content {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 330px;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 14px;
  padding: 0 18px 18px;
  min-height: 0;
  flex: 1;
}

.card {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.card-stage {
  grid-column: 1;
  grid-row: 1;
  gap: 12px;
  padding: 14px;
}

.card-controls {
  grid-column: 2;
  grid-row: 1 / span 2;
  overflow: hidden;
}

.card-queue {
  grid-column: 1;
  grid-row: 2;
}

.card-qr-preview {
  grid-column: 1;
  grid-row: 1;
  gap: 12px;
  padding: 14px;
}

.card-qr-controls {
  grid-column: 2;
  grid-row: 1 / span 2;
  overflow: hidden;
}

/* Só a secção activa é mostrada; a outra sai da grelha por completo. */
.content[data-section='remove'] [data-section='qr'],
.content[data-section='qr'] [data-section='remove'] {
  display: none;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-soft);
}

.card-head h2 {
  font-size: 14px;
  font-weight: 650;
}

.card-body {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 16px;
  overflow-y: auto;
}

.pill {
  padding: 2px 9px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--accent-text);
  background: var(--accent-soft);
  border-radius: 999px;
}

/* ----------------------------- Dropzone ---------------------------- */
.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 7px;
  flex: 1;
  padding: 40px 20px;
  text-align: center;
  color: var(--muted);
  background: var(--surface-2);
  border: 1.5px dashed var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}

.dropzone:hover,
.dropzone.dragging {
  color: var(--text);
  background: var(--accent-soft);
  border-color: var(--accent);
}

.dropzone strong {
  font-size: 15px;
  color: var(--text);
}

.dropzone.compact {
  flex: 0 0 auto;
  flex-direction: row;
  gap: 9px;
  padding: 11px 16px;
}

.dropzone.compact .dz-hint,
.dropzone.compact strong {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--muted);
}

.dropzone.compact .dz-icon {
  width: 17px;
  height: 17px;
}

.dz-icon {
  width: 26px;
  height: 26px;
  color: var(--accent-text);
}

.dz-hint {
  font-size: 12.5px;
}

/* ------------------------------ Palco ------------------------------ */
.stage {
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex: 1;
  min-height: 0;
}

.stage-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.segmented {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 11px;
}

.seg {
  padding: 5px 12px;
  font: inherit;
  font-size: 12.5px;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}

.seg:hover {
  color: var(--text);
}

.seg.active {
  color: var(--text);
  background: var(--surface);
  font-weight: 600;
  box-shadow: 0 1px 3px rgb(0 0 0 / 0.22);
}

.icon-seg {
  display: grid;
  place-items: center;
  width: 30px;
  padding: 6px;
}

.meta {
  margin-left: auto;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.canvas {
  position: relative;
  display: grid;
  place-items: center;
  flex: 1;
  min-height: 260px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.canvas img {
  grid-area: 1 / 1;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
}

.bg-checker {
  background-color: var(--checker-a);
  background-image: linear-gradient(45deg, var(--checker-b) 25%, transparent 25%),
    linear-gradient(-45deg, var(--checker-b) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, var(--checker-b) 75%),
    linear-gradient(-45deg, transparent 75%, var(--checker-b) 75%);
  background-size: 18px 18px;
  background-position: 0 0, 0 9px, 9px -9px, -9px 0;
}

.bg-light {
  background: #ffffff;
}

.bg-dark {
  background: #101414;
}

/* Comparação com cortina.
   O original sobe para cima do resultado e é recortado à esquerda da cortina.
   Assim vê-se: à esquerda o original opaco, à direita o resultado sobre o
   xadrez — em vez do original a espreitar pela transparência do resultado. */
.canvas.split #img-original {
  z-index: 2;
  clip-path: inset(0 calc(100% - var(--split, 50%)) 0 0);
}

.split-handle {
  position: absolute;
  z-index: 3;
  top: 0;
  bottom: 0;
  left: var(--split, 50%);
  display: grid;
  place-items: center;
  width: 26px;
  transform: translateX(-13px);
  cursor: ew-resize;
}

.split-handle span {
  width: 2px;
  height: 100%;
  background: var(--accent);
  box-shadow: 0 0 0 1px rgb(0 0 0 / 0.25);
}

.split-handle::after {
  content: '⇄';
  position: absolute;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  font-size: 13px;
  color: var(--on-accent);
  background: var(--accent);
  border-radius: 50%;
}

.spinner {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgb(8 12 11 / 0.45);
  backdrop-filter: blur(2px);
}

.spinner span {
  width: 32px;
  height: 32px;
  border: 3px solid rgb(255 255 255 / 0.22);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .spinner span {
    animation-duration: 2.4s;
  }
}

/* =================================================================== */
/* Campos de ajuste                                                    */
/* =================================================================== */
.field {
  display: flex;
  flex-direction: column;
  gap: 11px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-soft);
}

.field:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}

/* Cabeçalho de campo. `.switch` também é um <label> filho de `.field`,
   por isso fica de fora. */
.field > label:not(.switch) {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--faint);
}

select,
input[type='number'] {
  width: 100%;
  padding: 9px 11px;
  font: inherit;
  font-size: 13.5px;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.slider {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.slider label {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  font-weight: 500;
}

.slider output {
  color: var(--accent-text);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.slider small,
.hint {
  font-size: 11.5px;
  line-height: 1.45;
  color: var(--muted);
}

/* `--fill` é a percentagem do valor actual, actualizada pelo JS, para o troço
   já percorrido aparecer a verde. */
input[type='range'] {
  width: 100%;
  height: 4px;
  appearance: none;
  background: linear-gradient(
    to right,
    var(--accent) 0 var(--fill, 50%),
    var(--surface-3) var(--fill, 50%) 100%
  );
  border-radius: 4px;
  cursor: pointer;
}

input[type='range']::-webkit-slider-thumb {
  appearance: none;
  width: 15px;
  height: 15px;
  background: var(--accent);
  border: 2px solid var(--surface);
  border-radius: 50%;
  box-shadow: 0 1px 3px rgb(0 0 0 / 0.35);
}

.switch {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 13px;
  cursor: pointer;
}

.switch small {
  color: var(--muted);
}

.switch input {
  width: 15px;
  height: 15px;
  accent-color: var(--accent);
}

.switch.compact {
  font-size: 12px;
  color: var(--muted);
}

.inline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.inline label {
  font-size: 13px;
}

.inline input[type='number'] {
  width: 86px;
}

input[type='color'] {
  width: 46px;
  height: 30px;
  padding: 2px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
}

/* =================================================================== */
/* Código QR                                                           */
/* =================================================================== */
.nav-button {
  padding: 0;
  font: inherit;
  text-align: left;
  background: transparent;
  border: 0;
  width: 100%;
}

.nav-button.active .nav-body {
  background: var(--surface-2);
  border-color: var(--border);
  color: var(--text);
}

.nav-button.active .nav-icon {
  color: var(--accent-text);
}

.qr-toolbar {
  justify-content: space-between;
}

/* Preenche a caixa nas duas direcções e deixa o `object-fit` centrar e
   encaixar. Funciona tanto para o PNG como para o SVG — este vem sem
   dimensões próprias, mas o `viewBox` dá-lhe a proporção 1:1. Dimensionar
   só por uma das direcções colapsava o código em caixas estreitas. */
#qr-image {
  grid-area: 1 / 1;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  object-fit: contain;
}

.card-qr-preview .canvas {
  padding: 18px;
}

.qr-empty {
  grid-area: 1 / 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 20px;
  text-align: center;
  color: var(--muted);
}

.qr-empty strong {
  font-size: 15px;
  color: var(--text);
}

.qr-empty span {
  font-size: 12.5px;
}

.qr-notes {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.qr-notes:empty {
  display: none;
}

.qr-note {
  display: flex;
  gap: 8px;
  padding: 9px 12px;
  font-size: 12.5px;
  line-height: 1.45;
  border-radius: 10px;
}

.qr-note::before {
  content: 'i';
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 16px;
  height: 16px;
  margin-top: 1px;
  font-size: 10px;
  font-weight: 700;
  font-style: italic;
  border: 1px solid currentColor;
  border-radius: 50%;
}

.qr-note.info {
  color: var(--muted);
  background: var(--surface-2);
}

.qr-note.warn {
  color: #c2841c;
  background: rgb(214 154 46 / 0.12);
}

:root[data-theme='dark'] .qr-note.warn {
  color: #e8b95c;
}

.qr-note.warn::before {
  content: '!';
  font-style: normal;
}

textarea {
  width: 100%;
  padding: 10px 11px;
  font: inherit;
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  resize: vertical;
}

textarea::placeholder {
  color: var(--faint);
}

/* =================================================================== */
/* Fila de imagens                                                     */
/* =================================================================== */
.thumbs {
  display: flex;
  gap: 9px;
  padding: 14px 16px;
  overflow-x: auto;
}

.thumb {
  position: relative;
  flex: 0 0 auto;
  width: 72px;
  height: 72px;
  padding: 0;
  overflow: hidden;
  background: var(--surface-2);
  border: 2px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
}

.thumb.active {
  border-color: var(--accent);
}

.thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.thumb .badge {
  position: absolute;
  right: 4px;
  bottom: 4px;
  padding: 1px 5px;
  font-size: 10px;
  font-weight: 700;
  color: var(--on-accent);
  background: var(--accent);
  border-radius: 5px;
}

.thumb .badge.pending {
  color: var(--text);
  background: var(--surface-3);
}

.thumb .badge.failed {
  color: #fff;
  background: #d64545;
}

.thumb .remove {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 18px;
  height: 18px;
  font-size: 11px;
  line-height: 1;
  color: #fff;
  background: rgb(0 0 0 / 0.6);
  border: 0;
  border-radius: 50%;
  cursor: pointer;
}

/* =================================================================== */
/* Erro                                                                */
/* =================================================================== */
.error {
  margin: 0 18px 18px;
  padding: 11px 14px;
  font-size: 13px;
  color: var(--danger);
  background: var(--danger-soft);
  border: 1px solid currentColor;
  border-radius: 12px;
}

/* =================================================================== */
/* Adaptação a ecrãs menores                                           */
/* =================================================================== */

/* Uma só coluna: os cartões passam a empilhar e a área de conteúdo rola.
   Todos os cartões têm de constar aqui — um que fique com `grid-column: 2`
   numa grelha de uma coluna cria uma segunda coluna implícita e encolhe até
   ficar invisível. */
@media (max-width: 1080px) {
  .content {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: none;
    grid-auto-rows: auto;
    overflow-y: auto;
  }

  .card-stage,
  .card-controls,
  .card-queue,
  .card-qr-preview,
  .card-qr-controls {
    grid-column: 1;
    grid-row: auto;
  }

  /* Deixam de precisar de rolagem própria: rola a coluna inteira. */
  .card-controls,
  .card-qr-controls {
    overflow: visible;
  }

  /* Na versão em grelha os cartões levam `min-height: 0` para poderem encolher
     dentro da linha. Empilhados isso vira-se contra nós: as linhas automáticas
     passam a poder encolher abaixo do conteúdo e os cartões sobrepõem-se.
     Aqui cada cartão volta a ocupar o que precisa e é a coluna que rola. */
  .content > .card {
    min-height: auto;
  }

  /* Em coluna flexível é o `flex-basis` que manda no tamanho principal, e a
     altura seria ignorada — daí desligar o `flex: 1` da versão em grelha. */
  .canvas {
    flex: 0 0 auto;
    height: clamp(260px, 46vh, 460px);
  }

  /* No painel do QR o código é o conteúdo principal, e cabe num quadrado:
     vale a pena dar-lhe mais altura do que ao palco das imagens. */
  .card-qr-preview .canvas {
    height: clamp(300px, 54vh, 520px);
  }
}

/* Barra lateral passa a barra horizontal. */
@media (max-width: 860px) {
  body {
    padding: 0;
  }

  .app,
  .app.collapsed {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
    height: 100vh;
    border: 0;
    border-radius: 0;
  }

  .sidebar {
    flex-direction: row;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    overflow-x: auto;
    overflow-y: hidden;
    border-right: 0;
    border-bottom: 1px solid var(--border-soft);
  }

  .sidebar-head {
    padding: 0;
  }

  /* Só a marca cabe: o logótipo completo ocuparia a barra toda. */
  .logo-full,
  .nav-label,
  .nav-text small,
  .nav-chevron,
  .tip-card,
  #collapse {
    display: none;
  }

  .logo-mark {
    display: block;
    width: 18px;
  }

  .nav {
    flex-direction: row;
    flex: 0 0 auto;
  }

  .nav-body {
    padding: 8px 12px;
    white-space: nowrap;
  }

  .sidebar-foot {
    margin: 0 0 0 auto;
    flex: 0 0 auto;
  }

  .theme-switch {
    grid-template-columns: 1fr 1fr;
  }

  .topbar {
    padding: 12px 14px;
  }

  .content {
    padding: 0 14px 14px;
  }

  .error {
    margin: 0 14px 14px;
  }
}

/* Telemóvel: a barra de topo empilha e os controlos ganham alvos maiores. */
@media (max-width: 620px) {
  .topbar {
    flex-wrap: wrap;
    gap: 10px;
  }

  .topbar-title {
    flex: 1 1 100%;
  }

  .topbar-title h1 {
    font-size: 17px;
  }

  .topbar-actions {
    flex: 1 1 100%;
    margin-left: 0;
    flex-wrap: wrap;
  }

  /* O botão principal ocupa a linha; os de ícone ficam ao lado. */
  .topbar-actions .btn {
    flex: 1 1 auto;
  }

  .stage-toolbar {
    gap: 6px;
  }

  .meta {
    flex: 1 1 100%;
    margin-left: 0;
    order: 3;
  }

  .seg {
    padding: 6px 10px;
    font-size: 12px;
  }

  .canvas {
    height: clamp(220px, 38vh, 360px);
  }

  .card-qr-preview .canvas {
    height: clamp(280px, 46vh, 400px);
    padding: 12px;
  }

  .dropzone {
    padding: 26px 14px;
  }

  .dropzone.compact {
    flex-direction: column;
    gap: 4px;
    padding: 12px;
    text-align: center;
  }

  .dropzone.compact .dz-hint {
    display: block;
  }

  .thumb {
    width: 62px;
    height: 62px;
  }
}
