/* ==========================================================================
   Tipografia

   Plus Jakarta Sans, variável (200–800), servida pela própria aplicação.
   Não há CDN: numa agência com ligação fraca, uma fonte que não chega deixa o
   ecrã a piscar ou em Arial. São 60 kB num único ficheiro, com `swap` para o
   texto aparecer de imediato enquanto a fonte carrega.

   Escolhida por três razões concretas: tem algarismos tabulares (`tnum`), que
   alinham as colunas de valores; tem altura-x grande, que se lê melhor em ecrãs
   modestos; e cobre todos os diacríticos do português.
   Licença SIL Open Font 1.1 — ver public/fonts/OFL.txt
   ========================================================================== */

@font-face {
  font-family: "Plus Jakarta Sans";
  src: url("../fonts/PlusJakartaSans-Variable.woff2") format("woff2-variations"),
       url("../fonts/PlusJakartaSans-Variable.woff2") format("woff2");
  font-weight: 200 800;
  font-style: normal;
  font-display: swap;
}

/* ==========================================================================
   MicroCrédito 360 — sistema visual

   Violeta como cor de marca, superfícies elevadas e formas macias.
   Os neutros não são cinzentos: todos têm violeta na mistura, para que o
   ecrã inteiro pertença à mesma família cromática em vez de parecer um
   fundo morto com um acento colado por cima.

   A escala de severidade (mora, PAR) mantém-se quente e saturada, num eixo
   cromático diferente da marca, para nunca se confundir com uma ação.
   ========================================================================== */

:root {
  color-scheme: light;

  /* --- Superfícies: brancos e lilases, nunca cinzento neutro ------------ */
  --page: #f4f3fb;
  --surface: #ffffff;
  --surface-2: #f7f6fd;
  --surface-3: #efedfa;

  /* --- Tinta com violeta na mistura ------------------------------------- */
  --ink: #171334;
  --ink-2: #423c68;
  --ink-3: #6e6894;
  --ink-4: #9c96bd;

  --rule: #e9e5f7;
  --rule-2: #d8d2ef;

  /* --- Marca ------------------------------------------------------------ */
  --brand: #5b3fd6;
  --brand-hover: #4a2fbe;
  --brand-ink: #ffffff;
  --brand-soft: #f0ecfe;
  --brand-soft-2: #e3dcfc;
  --brand-line: #cfc3f8;
  --brand-ring: rgba(91, 63, 214, .2);
  --brand-deep: #2c1d6b;

  /* --- Severidade: eixo quente, separado da marca ----------------------- */
  --sev-0: #0f9d76;
  --sev-1: #c2760b;
  --sev-2: #dd6412;
  --sev-3: #d63b3b;
  --sev-4: #a81243;

  --sev-0-soft: #e2f7f0;
  --sev-1-soft: #fdf2da;
  --sev-2-soft: #fdeadb;
  --sev-3-soft: #fde6e6;
  --sev-4-soft: #fce4ec;

  --sev-0-line: #b3e8d7;
  --sev-1-line: #f4ddaa;
  --sev-2-line: #f7d1b3;
  --sev-3-line: #f7c6c6;
  --sev-4-line: #f5c2d3;

  /* --- Semântica -------------------------------------------------------- */
  --ok: var(--sev-0);
  --ok-soft: var(--sev-0-soft);
  --ok-line: var(--sev-0-line);
  --warn: var(--sev-1);
  --warn-soft: var(--sev-1-soft);
  --warn-line: var(--sev-1-line);
  --danger: var(--sev-3);
  --danger-soft: var(--sev-3-soft);
  --danger-line: var(--sev-3-line);
  --info: var(--brand);
  --info-soft: var(--brand-soft);
  --info-line: var(--brand-line);

  /* --- Barra lateral ---------------------------------------------------- */
  --rail-a: #3a2499;
  --rail-b: #251562;
  --rail-ink: #c5bbf0;
  --rail-muted: #9186c9;
  --rail-line: rgba(255, 255, 255, .13);

  /* --- Forma: generosa ---------------------------------------------------
     Cantos macios em toda a escala. O raio cresce com a área do elemento,
     para que um botão e um painel não partilhem a mesma curvatura. */
  --r-pill: 999px;
  --r-control: 11px;
  --r-panel: 18px;
  --r-overlay: 24px;
  --rail-w: 252px;

  /* --- Elevação: sombras tingidas de violeta, nunca cinzento sujo ------- */
  --e-1: 0 1px 2px rgba(23, 19, 52, .04), 0 4px 12px -6px rgba(91, 63, 214, .14);
  --e-2: 0 2px 4px rgba(23, 19, 52, .04), 0 12px 28px -12px rgba(91, 63, 214, .22);
  --e-3: 0 24px 56px -16px rgba(38, 24, 104, .28);
  --e-brand: 0 6px 18px -6px rgba(91, 63, 214, .45);

  /* --- Tipografia ------------------------------------------------------- */
  --sans: "Plus Jakarta Sans", -apple-system, BlinkMacSystemFont, "Segoe UI Variable Text",
          "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

  --t-micro: .8125rem;   /* 13 — etiquetas e apoio */
  --t-small: .875rem;    /* 14 — interface corrente */
  --t-body: .9375rem;    /* 15 — corpo             */
  --t-lead: 1.0625rem;   /* 17 — destaque          */
  --t-h3: 1.25rem;       /* 20 — títulos de painel */
  --t-h2: 1.625rem;      /* 26                     */
  --t-num: 2.25rem;      /* 36 — indicador         */
  --t-num-lg: 3rem;      /* 48 — indicador herói   */

  --ease: cubic-bezier(.2, .7, .3, 1);
}

[data-theme="dark"] {
  color-scheme: dark;

  --page: #0d0a1b;
  --surface: #171230;
  --surface-2: #1e1839;
  --surface-3: #282047;

  --ink: #ecebf8;
  --ink-2: #c4bee0;
  --ink-3: #9790bb;
  --ink-4: #6f6792;

  --rule: #2a2350;
  --rule-2: #3b3266;

  --brand: #9179ff;
  --brand-hover: #a893ff;
  --brand-ink: #16103a;
  --brand-soft: #241c4d;
  --brand-soft-2: #2e2460;
  --brand-line: #3d3178;
  --brand-ring: rgba(145, 121, 255, .32);
  --brand-deep: #c9bcff;

  --sev-0: #3ddba6;
  --sev-1: #efb44f;
  --sev-2: #f5904f;
  --sev-3: #f4676c;
  --sev-4: #f2588f;

  --sev-0-soft: #10312a;
  --sev-1-soft: #2f2515;
  --sev-2-soft: #331f14;
  --sev-3-soft: #331a1e;
  --sev-4-soft: #331726;

  --sev-0-line: #1c5245;
  --sev-1-line: #52401f;
  --sev-2-line: #58351f;
  --sev-3-line: #572a30;
  --sev-4-line: #56243c;

  --rail-a: #2b1a7a;
  --rail-b: #180e45;
  --rail-ink: #bdb2ee;
  --rail-muted: #8478c0;

  --e-1: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 12px -6px rgba(0, 0, 0, .5);
  --e-2: 0 2px 6px rgba(0, 0, 0, .35), 0 14px 32px -12px rgba(0, 0, 0, .6);
  --e-3: 0 26px 60px -16px rgba(0, 0, 0, .75);
  --e-brand: 0 6px 20px -6px rgba(145, 121, 255, .45);
}

@media (prefers-color-scheme: dark) {
  html:not([data-theme]) { color-scheme: dark; }
}

/* ==========================================================================
   Base
   ========================================================================== */

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  font-family: var(--sans);
  font-size: var(--t-body);
  line-height: 1.55;
  color: var(--ink);
  background: var(--page);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body { min-height: 100vh; }
a { text-decoration: none; color: inherit; }
button, input, select, textarea { font: inherit; }
button { color: inherit; }
::selection { background: var(--brand-soft-2); color: var(--ink); }

h1, h2, h3, h4 { letter-spacing: -.02em; font-weight: 600; margin: 0; }

/* Algarismos alinhados em coluna: num sistema financeiro é o que permite
   comparar valores a correr o olho. */
.money, .value, .stat-value, .num, td.money, th.money, .tabular, input[type=number] {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 4px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ==========================================================================
   Estrutura
   ========================================================================== */

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

.sidebar {
  width: var(--rail-w);
  background: linear-gradient(168deg, var(--rail-a) 0%, var(--rail-b) 100%);
  color: #fff;
  position: fixed;
  inset: 0 auto 0 0;
  padding: 20px 14px 14px;
  display: flex;
  flex-direction: column;
  z-index: 60;
}

.brand { display: flex; align-items: center; gap: 11px; padding: 0 8px 18px; }
.brand-mark {
  width: 36px; height: 36px; flex: 0 0 36px; border-radius: 12px;
  background: rgba(255, 255, 255, .16);
  backdrop-filter: blur(4px);
  color: #fff; display: grid; place-items: center;
  font-size: 16px; font-weight: 650; letter-spacing: -.02em;
}
.brand strong { font-size: var(--t-body); display: block; font-weight: 600; }
.brand small { color: var(--rail-ink); display: block; font-size: var(--t-micro); margin-top: 1px; }

.tenant-card {
  padding: 11px 13px; margin: 0 2px 14px;
  background: rgba(255, 255, 255, .09);
  border: 1px solid var(--rail-line);
  border-radius: var(--r-control);
}
.tenant-card span { font-size: var(--t-micro); color: var(--rail-ink); display: block; }
.tenant-card strong {
  display: block; margin-top: 2px; font-size: var(--t-small); font-weight: 550;
  color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.nav { overflow: auto; padding-bottom: 10px; scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.2) transparent; }
.nav::-webkit-scrollbar { width: 4px; }
.nav::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, .2); border-radius: 4px; }

.nav a {
  display: flex; align-items: center; gap: 11px;
  min-height: 40px; padding: 9px 12px; margin: 2px 0;
  border-radius: var(--r-control);
  color: var(--rail-ink); font-size: var(--t-small); font-weight: 500;
  transition: background .16s var(--ease), color .16s var(--ease);
}
.nav a:hover { background: rgba(255, 255, 255, .1); color: #fff; }
.nav a.active {
  background: #fff; color: var(--rail-b); font-weight: 600;
  box-shadow: 0 4px 14px -4px rgba(0, 0, 0, .3);
}
.nav a.active .nav-icon { color: var(--brand); }

.nav-icon { width: 18px; height: 18px; flex: 0 0 18px; display: grid; place-items: center; color: var(--rail-muted); }
.nav a:hover .nav-icon { color: #fff; }
.nav-icon svg { width: 17px; height: 17px; stroke-width: 1.8; }

.nav-count { margin-left: auto; font-size: var(--t-micro); font-weight: 600; color: var(--rail-muted); }

.nav-section {
  font-size: var(--t-micro); color: var(--rail-muted); font-weight: 500;
  padding: 18px 12px 7px;
}

.sidebar-footer {
  margin-top: auto; border-top: 1px solid var(--rail-line); padding-top: 13px;
  display: grid; grid-template-columns: 34px minmax(0, 1fr) 30px; gap: 10px; align-items: center;
}
.sidebar-footer .avatar {
  width: 34px; height: 34px; border-radius: var(--r-pill); flex: 0 0 34px;
  background: rgba(255, 255, 255, .18); color: #fff;
  display: grid; place-items: center; font-size: var(--t-small); font-weight: 650;
}
.sidebar-footer strong { display: block; font-size: var(--t-small); font-weight: 600; color: #fff; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-footer small { display: block; font-size: var(--t-micro); color: var(--rail-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.icon-btn, .menu-btn { border: 0; background: transparent; color: inherit; cursor: pointer; }
.icon-btn {
  width: 30px; height: 30px; border-radius: var(--r-control);
  display: grid; place-items: center; color: var(--rail-ink); transition: .16s var(--ease);
}
.icon-btn:hover { background: rgba(255, 255, 255, .14); color: #fff; }
.icon-btn svg { width: 16px; height: 16px; }

.sidebar-backdrop { display: none; position: fixed; inset: 0; background: rgba(20, 12, 48, .55); border: 0; z-index: 55; backdrop-filter: blur(3px); }

.main { margin-left: var(--rail-w); width: calc(100% - var(--rail-w)); min-width: 0; }

.topbar {
  min-height: 70px;
  background: color-mix(in srgb, var(--page) 82%, transparent);
  backdrop-filter: blur(14px);
  display: flex; align-items: center; gap: 14px;
  padding: 14px 26px;
  position: sticky; top: 0; z-index: 40;
}
.topbar h1 { font-size: var(--t-h3); font-weight: 650; }
.topbar p { margin: 2px 0 0; color: var(--ink-3); font-size: var(--t-small); }
.topbar-titles { min-width: 0; flex: 1 1 auto; }
.top-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.content { padding: 6px 26px 76px; max-width: 1600px; }

/* ==========================================================================
   Botões — a ação primária é violeta e tem elevação própria
   ========================================================================== */

.btn {
  border: 1px solid transparent; border-radius: var(--r-control);
  min-height: 46px; padding: 12px 20px;
  font-size: var(--t-small); font-weight: 600; line-height: 1;
  cursor: pointer; white-space: nowrap;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  transition: background .16s var(--ease), box-shadow .16s var(--ease),
              border-color .16s var(--ease), color .16s var(--ease), transform .16s var(--ease);
}
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 0; box-shadow: 0 0 0 4px var(--brand-ring); }
.btn:disabled, .btn.is-loading { opacity: .55; cursor: wait; box-shadow: none; }
.btn svg { width: 15px; height: 15px; stroke-width: 2; }

.btn-primary {
  background: var(--brand); color: var(--brand-ink); border-color: var(--brand);
  box-shadow: var(--e-brand);
}
.btn-primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); }

.btn-light { background: var(--surface); border-color: var(--rule-2); color: var(--ink-2); box-shadow: var(--e-1); }
.btn-light:hover { border-color: var(--brand); color: var(--brand); }

.btn-danger { background: var(--surface); color: var(--danger); border-color: var(--danger-line); box-shadow: var(--e-1); }
.btn-danger:hover { background: var(--danger); color: #fff; border-color: var(--danger); }

.btn-success { background: var(--surface); color: var(--ok); border-color: var(--ok-line); box-shadow: var(--e-1); }
.btn-success:hover { background: var(--ok); color: #fff; border-color: var(--ok); }

.btn-ghost { background: transparent; border-color: transparent; color: var(--ink-3); }
.btn-ghost:hover { background: var(--surface-3); color: var(--brand); }

.btn-sm { min-height: 38px; padding: 9px 15px; font-size: var(--t-micro); }
.btn-sm svg { width: 13px; height: 13px; }

.btn .spinner {
  width: 13px; height: 13px; border: 2px solid currentColor;
  border-right-color: transparent; border-radius: 50%; animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ==========================================================================
   Painéis — elevados e macios
   ========================================================================== */

.grid { display: grid; gap: 16px; }
.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)); }
.split { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 16px; }
.split-even { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.stack { display: grid; gap: 16px; }

.card {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--r-panel);
  box-shadow: var(--e-1);
  overflow: hidden;
}
.card-body { padding: 22px 26px; }
.card-header {
  padding: 19px 26px; border-bottom: 1px solid var(--rule);
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
}
.card-header h3 { font-size: var(--t-lead); font-weight: 650; }
.card-header .muted { font-size: var(--t-small); }

a.card { transition: transform .18s var(--ease), box-shadow .18s var(--ease), border-color .18s var(--ease); }
a.card:hover { transform: translateY(-3px); box-shadow: var(--e-2); border-color: var(--brand-line); }

/* --- Indicadores: cartões elevados, cada um com o seu peso -------------- */
.statband {
  display: grid;
  grid-template-columns: repeat(var(--cols, 4), minmax(0, 1fr));
  gap: 16px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--r-panel);
  box-shadow: var(--e-1);
  padding: 24px 26px 26px;
  min-width: 0;
  position: relative;
  overflow: hidden;
}

.stat-label { font-size: var(--t-small); color: var(--ink-3); font-weight: 500; }
.stat-value {
  font-size: var(--t-num); font-weight: 650; letter-spacing: -.035em;
  line-height: 1.05; margin: 11px 0 0; word-break: break-word;
}
.stat-value.lead { font-size: var(--t-num-lg); }
.stat-value.tiny { font-size: var(--t-h2); letter-spacing: -.02em; }
.stat-unit { font-size: var(--t-small); color: var(--ink-3); font-weight: 500; margin-left: 4px; letter-spacing: 0; }
.stat-foot { margin-top: 10px; font-size: var(--t-small); color: var(--ink-3); line-height: 1.5; }
.stat-foot a { color: var(--brand); font-weight: 600; }
.stat-foot a:hover { text-decoration: underline; }

/* A severidade tinge o número e assina o topo do cartão. */
.stat::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 3px; background: transparent; }
.stat.sev-1::before { background: var(--sev-1); }
.stat.sev-2::before { background: var(--sev-2); }
.stat.sev-3::before { background: var(--sev-3); }
.stat.sev-4::before { background: var(--sev-4); }
.stat.ok::before { background: var(--sev-0); }
.stat.sev-1 .stat-value { color: var(--sev-1); }
.stat.sev-2 .stat-value { color: var(--sev-2); }
.stat.sev-3 .stat-value { color: var(--sev-3); }
.stat.sev-4 .stat-value { color: var(--sev-4); }
.stat.ok .stat-value { color: var(--sev-0); }

/* Um cartão herói por ecrã. Marcado com .hero na faixa principal: se todas
   as faixas fossem violeta, nenhuma se destacaria. */
.statband.hero .stat:first-child {
  background: linear-gradient(158deg, var(--brand) 0%, var(--brand-deep) 100%);
  border-color: transparent;
  box-shadow: var(--e-brand);
  color: #fff;
}
.statband.hero .stat:first-child .stat-label,
.statband.hero .stat:first-child .stat-foot { color: rgba(255, 255, 255, .78); }
.statband.hero .stat:first-child .stat-value { color: #fff; }
.statband.hero .stat:first-child .stat-unit { color: rgba(255, 255, 255, .7); }
.statband.hero .stat:first-child .stat-foot a { color: #fff; text-decoration: underline; }
.statband.hero .stat:first-child::before { display: none; }
[data-theme="dark"] .statband.hero .stat:first-child { color: var(--brand-ink); }
[data-theme="dark"] .statband.hero .stat:first-child .stat-value { color: var(--brand-ink); }
[data-theme="dark"] .statband.hero .stat:first-child .stat-label,
[data-theme="dark"] .statband.hero .stat:first-child .stat-foot { color: rgba(22, 16, 58, .72); }

/* Compatibilidade com a classe .metric ainda usada nalguns ecrãs. */
.metric { padding: 20px 22px 22px; }
.metric .label { font-size: var(--t-small); color: var(--ink-3); font-weight: 500; }
.metric .value { font-size: var(--t-num); font-weight: 650; letter-spacing: -.035em; line-height: 1.05; margin: 11px 0 0; }
.metric .hint { margin-top: 10px; font-size: var(--t-small); color: var(--ink-3); line-height: 1.5; }
.metric .hint a { color: var(--brand); font-weight: 600; }
.metric.warn .value { color: var(--warn); }
.metric.danger .value { color: var(--danger); }
.metric.ok .value { color: var(--ok); }

.danger-zone { border-color: var(--danger-line); }
.danger-zone .card-header { background: var(--danger-soft); border-bottom-color: var(--danger-line); }
.danger-zone .card-header h3 { color: var(--danger); }

.box { border: 1px solid var(--rule); border-radius: var(--r-panel); padding: 16px 18px; background: var(--surface-2); }

.section-title { font-size: var(--t-small); color: var(--ink-3); font-weight: 600; margin: 26px 0 11px; }

/* ==========================================================================
   Formulários
   ========================================================================== */

.form-card { max-width: 1080px; }
.form-narrow { max-width: 740px; }
.form-medium { max-width: 900px; }

.form-section { padding: 30px 30px 32px; border-bottom: 1px solid var(--rule); }
.form-section:last-of-type { border-bottom: 0; }
.form-section > h3 { font-size: var(--t-lead); font-weight: 650; margin-bottom: 4px; }
.form-section > p { margin: 0 0 20px; color: var(--ink-3); font-size: var(--t-small); line-height: 1.55; max-width: 68ch; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px 22px; }
.form-grid .span-2 { grid-column: span 2; }
.form-grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }

label {
  display: flex; flex-direction: column; gap: 9px;
  font-size: var(--t-small); font-weight: 600; color: var(--ink-2); line-height: 1.45; min-width: 0;
}
label small { font-weight: 400; color: var(--ink-3); font-size: var(--t-micro); line-height: 1.5; }
.field-label { display: flex; align-items: center; gap: 4px; }
.required-mark { color: var(--sev-3); font-weight: 700; }

.input, select, textarea,
input[type=text], input[type=email], input[type=password], input[type=number],
input[type=date], input[type=tel], input[type=url], input[type=search], input:not([type]) {
  width: 100%;
  border: 1px solid var(--rule-2);
  border-radius: var(--r-control);
  padding: 13px 15px;
  min-height: 50px;
  font-size: var(--t-body);
  background: var(--surface);
  color: var(--ink);
  transition: border-color .14s var(--ease), box-shadow .14s var(--ease);
}
input::placeholder, textarea::placeholder { color: var(--ink-4); opacity: 1; }
input:hover, select:hover, textarea:hover { border-color: var(--ink-4); }
input:focus, select:focus, textarea:focus, .input:focus {
  outline: 0; border-color: var(--brand); box-shadow: 0 0 0 4px var(--brand-ring);
}
input:disabled, select:disabled, textarea:disabled { background: var(--surface-3); color: var(--ink-3); cursor: not-allowed; }

textarea { min-height: 120px; resize: vertical; line-height: 1.65; padding-top: 13px; }

select {
  appearance: none; -webkit-appearance: none; padding-right: 40px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='15' height='15' viewBox='0 0 24 24' fill='none' stroke='%236e6894' stroke-width='2.2' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
}
[data-theme="dark"] select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='15' height='15' viewBox='0 0 24 24' fill='none' stroke='%239790bb' stroke-width='2.2' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
}

input[type=file] {
  width: 100%; border: 1.5px dashed var(--brand-line); border-radius: var(--r-panel);
  background: var(--brand-soft); padding: 16px; min-height: 58px; cursor: pointer;
}
input[type=file]:hover { border-color: var(--brand); background: var(--brand-soft-2); }
input[type=checkbox], input[type=radio] { accent-color: var(--brand); width: 18px; height: 18px; }

.input-affix { position: relative; width: 100%; display: block; }
.input-affix > input { padding-right: 54px !important; }
.input-suffix {
  position: absolute; right: 13px; top: 50%; transform: translateY(-50%);
  color: var(--ink-3); font-size: var(--t-micro); font-weight: 650; pointer-events: none;
}

.check {
  display: flex !important; flex-direction: row !important; align-items: center;
  gap: 12px !important; min-height: 52px; padding: 14px 16px;
  border: 1px solid var(--rule); border-radius: var(--r-control);
  background: var(--surface-2); cursor: pointer; transition: .14s var(--ease);
}
.check:hover { border-color: var(--brand); background: var(--brand-soft); }

.form-actions {
  padding: 20px 30px; display: flex; gap: 9px; justify-content: flex-end; align-items: center;
  border-top: 1px solid var(--rule); background: var(--surface-2); flex-wrap: wrap;
}
.actions-inline { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.form-note {
  padding: 13px 15px; border-radius: var(--r-control);
  background: var(--brand-soft); border: 1px solid var(--brand-line);
  color: var(--brand); font-size: var(--t-small); line-height: 1.55;
}
.field-error { color: var(--danger); font-size: var(--t-micro); font-weight: 600; }
.has-error input, .has-error select, .has-error textarea { border-color: var(--danger); }

.select-search { display: block; width: 100%; }
.select-search-input { margin-bottom: 7px; }
/* ==========================================================================
   Filtros
   ========================================================================== */

.toolbar {
  display: flex; gap: 11px; align-items: center; justify-content: space-between;
  margin-bottom: 16px; flex-wrap: wrap;
}
.toolbar form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.toolbar .input, .toolbar select, .toolbar input { min-height: 44px; width: auto; min-width: 160px; }

/* Filtros como pastilhas macias. A ativa enche-se de violeta. */
.chip-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 18px; }
.chip {
  display: inline-flex; align-items: center; gap: 7px;
  border: 1px solid var(--rule-2); background: var(--surface);
  border-radius: var(--r-pill); padding: 8px 15px;
  font-size: var(--t-small); font-weight: 550; color: var(--ink-2);
  cursor: pointer; white-space: nowrap; box-shadow: var(--e-1);
  transition: background .15s var(--ease), color .15s var(--ease),
              border-color .15s var(--ease), box-shadow .15s var(--ease);
}
.chip:hover { border-color: var(--brand); color: var(--brand); }
.chip.is-active {
  background: var(--brand); border-color: var(--brand); color: var(--brand-ink);
  box-shadow: var(--e-brand);
}
.chip-count {
  font-size: var(--t-micro); font-weight: 700; color: var(--ink-3);
  background: var(--surface-3); border-radius: var(--r-pill); padding: 1px 8px;
}
.chip.is-active .chip-count { background: rgba(255, 255, 255, .25); color: inherit; }

.segmented {
  display: inline-flex; background: var(--surface-3); border-radius: var(--r-pill); padding: 4px; gap: 3px;
}
.segmented a, .segmented button {
  border: 0; background: transparent; cursor: pointer; border-radius: var(--r-pill);
  padding: 7px 14px; font-size: var(--t-small); font-weight: 550; color: var(--ink-3);
}
.segmented a:hover, .segmented button:hover { color: var(--ink); }
.segmented .is-active { background: var(--surface); color: var(--brand); box-shadow: var(--e-1); }

/* ==========================================================================
   Tabelas
   ========================================================================== */

.table-wrap { overflow: auto; scrollbar-width: thin; scrollbar-color: var(--rule-2) transparent; }
.table { width: 100%; border-collapse: separate; border-spacing: 0; min-width: 640px; }

.table th {
  font-size: var(--t-micro); color: var(--ink-3); font-weight: 600;
  text-align: left; padding: 14px 20px; white-space: nowrap;
  background: var(--surface-2); border-bottom: 1px solid var(--rule);
  position: sticky; top: 0; z-index: 2;
}
.table td {
  padding: 16px 20px; font-size: var(--t-small);
  border-bottom: 1px solid var(--rule); vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr { transition: background .13s var(--ease); }
.table tbody tr:hover td { background: var(--brand-soft); }
.table td.money, .table th.money, .table .right { text-align: right; }
.table td strong { font-weight: 650; font-size: var(--t-body); }
.table tfoot td { font-weight: 700; border-top: 2px solid var(--rule-2); background: var(--surface-2); }

.table th.sortable a { display: inline-flex; align-items: center; gap: 5px; }
.table th.sortable:hover { color: var(--brand); }
.sort-caret { opacity: .35; }
.table th.is-sorted { color: var(--brand); }
.table th.is-sorted .sort-caret { opacity: 1; }

.empty { padding: 52px 24px; text-align: center; color: var(--ink-3); font-size: var(--t-small); }
.empty-title { display: block; font-weight: 650; color: var(--ink); font-size: var(--t-lead); margin-bottom: 5px; }

.muted { color: var(--ink-3); font-size: var(--t-micro); }
.line { height: 1px; background: var(--rule); margin: 18px 0; border: 0; }
.right { text-align: right; }
.full { width: 100%; }
.large { font-size: var(--t-lead); font-weight: 650; }
.code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: var(--t-micro); color: var(--brand);
  background: var(--brand-soft); padding: 2px 7px; border-radius: 6px;
}
.meta { color: var(--ink-3); font-size: var(--t-micro); }
.page-link { color: var(--brand); font-weight: 600; }
.page-link:hover { text-decoration: underline; }

/* ==========================================================================
   Estado — pastilhas cheias, escala de severidade saturada
   ========================================================================== */

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  border-radius: var(--r-pill); padding: 4px 11px;
  font-size: var(--t-micro); font-weight: 650;
  background: var(--surface-3); color: var(--ink-2);
  white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: 0 0 6px; }
.badge.plain::before { display: none; }

.badge.green { background: var(--sev-0-soft); color: var(--sev-0); }
.badge.red { background: var(--sev-3-soft); color: var(--sev-3); }
.badge.orange { background: var(--sev-1-soft); color: var(--sev-1); }
.badge.blue { background: var(--brand-soft); color: var(--brand); }

.badge.sev-0 { background: var(--sev-0-soft); color: var(--sev-0); }
.badge.sev-1 { background: var(--sev-1-soft); color: var(--sev-1); }
.badge.sev-2 { background: var(--sev-2-soft); color: var(--sev-2); }
.badge.sev-3 { background: var(--sev-3-soft); color: var(--sev-3); }
.badge.sev-4 { background: var(--sev-4-soft); color: var(--sev-4); }

.pill {
  border: 1px solid var(--rule); border-radius: var(--r-pill);
  padding: 6px 13px; font-size: var(--t-micro); color: var(--ink-2); font-weight: 550;
  display: inline-flex; align-items: center; gap: 6px; background: var(--surface-2);
}
.kpi-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.stat-note { color: var(--ink-3); font-size: var(--t-micro); line-height: 1.6; max-width: 76ch; }
.sign { font-weight: 650; }

.trend { display: inline-flex; align-items: center; gap: 3px; font-size: var(--t-micro); font-weight: 700; }
.trend.up { color: var(--sev-0); }
.trend.down { color: var(--sev-3); }
.trend.flat { color: var(--ink-3); }
.trend svg { width: 12px; height: 12px; }
.statband.hero .stat:first-child .trend { color: #fff; }

.progress { height: 8px; background: var(--surface-3); border-radius: var(--r-pill); overflow: hidden; }
.progress-bar {
  height: 100%; border-radius: var(--r-pill);
  background: linear-gradient(90deg, var(--brand), var(--brand-hover));
  transition: width .55s var(--ease);
}
.progress-bar.ok { background: var(--sev-0); }
.progress-bar.warn { background: var(--sev-1); }
.progress-bar.danger { background: var(--sev-3); }

.summary-list { display: grid; }
.summary-item {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 17px 26px; border-bottom: 1px solid var(--rule);
  transition: background .13s var(--ease);
}
.summary-item:last-child { border-bottom: 0; }
.summary-item:hover { background: var(--surface-2); }
.summary-item .right { text-align: right; white-space: nowrap; }
.summary-item strong { font-weight: 650; }

.feature-row { display: flex; align-items: flex-start; gap: 11px; padding: 9px 0; }

.alert {
  border: 1px solid var(--rule); border-left: 4px solid var(--ink-4);
  border-radius: var(--r-control); padding: 14px 16px; margin-bottom: 16px;
  display: flex; align-items: flex-start; gap: 11px;
  font-size: var(--t-small); background: var(--surface); color: var(--ink-2);
  box-shadow: var(--e-1);
}
.alert strong { color: var(--ink); font-weight: 650; }
.alert.success { border-left-color: var(--sev-0); background: var(--sev-0-soft); border-color: var(--sev-0-line); }
.alert.warning { border-left-color: var(--sev-1); background: var(--sev-1-soft); border-color: var(--sev-1-line); }
.alert.danger { border-left-color: var(--sev-3); background: var(--sev-3-soft); border-color: var(--sev-3-line); }
.alert.info { border-left-color: var(--brand); background: var(--brand-soft); border-color: var(--brand-line); }
.alert-content { flex: 1; line-height: 1.6; }
.alert-content ul { margin: 6px 0 0; padding-left: 18px; }
.alert-close { border: 0; background: transparent; cursor: pointer; color: var(--ink-4); font-size: 18px; line-height: 1; padding: 0 2px; }
.alert-close:hover { color: var(--ink); }

.alert-feed { display: grid; }
.alert-row {
  display: flex; align-items: center; gap: 13px;
  padding: 15px 22px; border-bottom: 1px solid var(--rule);
  transition: background .13s var(--ease);
}
.alert-row:last-child { border-bottom: 0; }
.alert-row:hover { background: var(--brand-soft); }
.alert-dot { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 9px; background: var(--ink-4); }
.alert-dot.info { background: var(--brand); }
.alert-dot.warn { background: var(--sev-1); }
.alert-dot.danger { background: var(--sev-3); }
.alert-row strong { display: block; font-size: var(--t-small); font-weight: 600; }
.alert-row span { color: var(--ink-3); font-size: var(--t-micro); }

/* ==========================================================================
   Gráficos
   ========================================================================== */

.chart { display: flex; align-items: flex-end; gap: 3px; height: 150px; padding-top: 10px; position: relative; }
.chart-col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; min-width: 0; height: 100%; }
.chart-bar {
  background: linear-gradient(180deg, var(--brand), var(--brand-soft-2));
  border-radius: 5px 5px 3px 3px; min-height: 3px;
  transition: filter .14s var(--ease);
}
.chart-col:hover .chart-bar { filter: brightness(1.12); }
.chart-tip {
  position: absolute; bottom: calc(100% + 6px); left: 50%; transform: translateX(-50%);
  background: var(--ink); color: var(--page); font-size: var(--t-micro); font-weight: 600;
  padding: 6px 10px; border-radius: var(--r-control); white-space: nowrap; opacity: 0;
  pointer-events: none; transition: opacity .14s var(--ease); z-index: 5; box-shadow: var(--e-2);
}
.chart-col:hover .chart-tip { opacity: 1; }
.chart-axis {
  display: flex; justify-content: space-between; color: var(--ink-3);
  font-size: var(--t-micro); margin-top: 10px; border-top: 1px solid var(--rule); padding-top: 9px;
}

.stackbar { display: flex; height: 12px; border-radius: var(--r-pill); overflow: hidden; background: var(--surface-3); gap: 2px; }
.stackbar span { display: block; height: 100%; border-radius: var(--r-pill); transition: width .55s var(--ease); }
.seg-ok, .legend-swatch.seg-ok { background: var(--sev-0); }
.seg-watch, .legend-swatch.seg-watch { background: var(--sev-1); }
.seg-warn, .legend-swatch.seg-warn { background: var(--sev-2); }
.seg-high, .legend-swatch.seg-high { background: var(--sev-3); }
.seg-danger, .legend-swatch.seg-danger { background: var(--sev-4); }

.legend { display: grid; margin-top: 16px; }
.legend-item {
  display: flex; align-items: center; gap: 11px;
  font-size: var(--t-small); padding: 9px 0; border-bottom: 1px solid var(--rule);
}
.legend-item:last-child { border-bottom: 0; }
.legend-swatch { width: 10px; height: 10px; border-radius: 3px; flex: 0 0 10px; }
.legend-item .right { margin-left: auto; font-weight: 650; font-variant-numeric: tabular-nums; }

.gauge { display: flex; align-items: center; gap: 20px; }
.gauge svg { width: 102px; height: 102px; flex: 0 0 102px; transform: rotate(-90deg); }
.gauge circle { fill: none; stroke-width: 10; stroke-linecap: round; }
.gauge .gauge-track { stroke: var(--surface-3); }
.gauge .gauge-value { stroke: var(--sev-0); transition: stroke-dasharray .6s var(--ease); }
.gauge .gauge-value.warn { stroke: var(--sev-2); }
.gauge .gauge-value.danger { stroke: var(--sev-4); }
.gauge-label { font-size: var(--t-h2); font-weight: 700; letter-spacing: -.03em; }

/* ==========================================================================
   Pesquisa global
   ========================================================================== */

.search-trigger {
  display: flex; align-items: center; gap: 9px; min-width: 230px;
  border: 1px solid var(--rule-2); border-radius: var(--r-pill);
  background: var(--surface); padding: 9px 15px;
  color: var(--ink-3); font-size: var(--t-small); cursor: pointer;
  box-shadow: var(--e-1);
  transition: border-color .15s var(--ease), color .15s var(--ease), box-shadow .15s var(--ease);
}
.search-trigger:hover { border-color: var(--brand); color: var(--brand); box-shadow: var(--e-2); }
.search-trigger svg { width: 15px; height: 15px; flex: 0 0 15px; }
.search-trigger .kbd-group { margin-left: auto; display: flex; gap: 3px; }

.kbd {
  display: inline-block; border: 1px solid var(--rule-2); border-radius: 5px;
  padding: 0 5px; font-size: 11px; font-weight: 600; line-height: 1.7;
  background: var(--surface-2); color: var(--ink-3);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.cmdk-layer {
  position: fixed; inset: 0; background: rgba(20, 12, 48, .5); backdrop-filter: blur(5px);
  z-index: 220; display: none; align-items: flex-start; justify-content: center;
  padding: 11vh 20px 20px;
}
.cmdk-layer.open { display: flex; }
.cmdk {
  width: min(620px, 100%); background: var(--surface);
  border: 1px solid var(--rule); border-radius: var(--r-overlay);
  box-shadow: var(--e-3); overflow: hidden;
}

.cmdk-field { display: flex; align-items: center; gap: 11px; padding: 17px 19px; border-bottom: 1px solid var(--rule); }
.cmdk-field svg { width: 18px; height: 18px; color: var(--brand); flex: 0 0 18px; }
.cmdk-input {
  border: 0 !important; background: transparent !important; padding: 0 !important;
  min-height: auto !important; font-size: var(--t-lead) !important; box-shadow: none !important;
}
.cmdk-results { max-height: min(420px, 54vh); overflow: auto; padding: 7px; }
.cmdk-group-label { font-size: var(--t-micro); color: var(--ink-3); font-weight: 600; padding: 11px 11px 5px; }
.cmdk-item { display: flex; align-items: center; gap: 12px; padding: 10px 11px; border-radius: var(--r-control); cursor: pointer; }
.cmdk-item:hover, .cmdk-item.is-active { background: var(--brand-soft); }
.cmdk-item strong { font-size: var(--t-small); font-weight: 600; display: block; }
.cmdk-item span { font-size: var(--t-micro); color: var(--ink-3); display: block; }
.cmdk-item .badge { margin-left: auto; }
.cmdk-empty { padding: 36px 20px; text-align: center; color: var(--ink-3); font-size: var(--t-small); }
.cmdk-footer {
  border-top: 1px solid var(--rule); padding: 10px 17px; display: flex; gap: 16px;
  color: var(--ink-3); font-size: var(--t-micro); background: var(--surface-2);
}

/* ==========================================================================
   Notificações
   ========================================================================== */

.toast-stack {
  position: fixed; right: 18px; bottom: 18px; z-index: 240;
  display: grid; gap: 10px; max-width: min(380px, calc(100vw - 36px));
}
.toast {
  background: var(--surface); border: 1px solid var(--rule);
  border-left: 4px solid var(--brand); border-radius: var(--r-control);
  padding: 14px 16px; box-shadow: var(--e-2); font-size: var(--t-small);
  display: flex; gap: 11px; align-items: flex-start;
  animation: toast-in .22s var(--ease);
}
.toast.success { border-left-color: var(--sev-0); }
.toast.warning { border-left-color: var(--sev-1); }
.toast.danger { border-left-color: var(--sev-3); }
.toast strong { display: block; font-weight: 650; margin-bottom: 2px; }
.toast p { margin: 0; color: var(--ink-3); font-size: var(--t-micro); line-height: 1.55; }
.toast.is-leaving { opacity: 0; transform: translateX(12px); transition: .24s var(--ease); }
@keyframes toast-in { from { opacity: 0; transform: translateX(16px) scale(.97); } }

/* ==========================================================================
   Confirmação
   ========================================================================== */

.confirm-layer {
  position: fixed; inset: 0; background: rgba(20, 12, 48, .5); backdrop-filter: blur(4px);
  z-index: 200; display: none; align-items: center; justify-content: center; padding: 20px;
}
.confirm-layer.open { display: flex; }
.confirm-dialog {
  background: var(--surface); border: 1px solid var(--rule);
  border-radius: var(--r-overlay); padding: 28px; max-width: 420px; width: 100%;
  box-shadow: var(--e-3);
}
.confirm-icon {
  width: 44px; height: 44px; border-radius: 14px; margin-bottom: 16px;
  background: var(--sev-1-soft); color: var(--sev-1);
  display: grid; place-items: center; font-size: 20px; font-weight: 700;
}
.confirm-dialog h3 { font-size: var(--t-h3); font-weight: 650; margin-bottom: 7px; }
.confirm-dialog p { margin: 0 0 22px; color: var(--ink-3); font-size: var(--t-small); line-height: 1.6; }
.confirm-actions { display: flex; gap: 9px; justify-content: flex-end; }

/* ==========================================================================
   Paginação
   ========================================================================== */

.pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 16px; flex-wrap: wrap; }
.pager-summary { color: var(--ink-3); font-size: var(--t-micro); }
.pager-controls { display: flex; gap: 4px; flex-wrap: wrap; }
.pager-btn {
  border: 1px solid transparent; border-radius: var(--r-control);
  min-width: 36px; height: 36px; padding: 0 12px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: var(--t-small); font-weight: 550; color: var(--ink-3);
  transition: .14s var(--ease);
}
.pager-btn:hover { background: var(--brand-soft); color: var(--brand); }
.pager-btn.is-current { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); box-shadow: var(--e-brand); }
.pager-btn.is-disabled { opacity: .35; pointer-events: none; }
.pager-gap { color: var(--ink-4); padding: 0 3px; align-self: center; }

/* ==========================================================================
   Relatórios e autenticação
   ========================================================================== */

.reports-grid { gap: 16px; }
.report-card { display: block; padding: 24px; }
.report-icon {
  width: 46px; height: 46px; border-radius: 14px; margin-bottom: 16px;
  background: var(--brand-soft); color: var(--brand); display: grid; place-items: center;
}
.report-icon svg { width: 22px; height: 22px; stroke-width: 1.8; }
.report-title { font-size: var(--t-h3); font-weight: 650; margin: 6px 0 6px; }

/* --- Entrada na aplicação ------------------------------------------------
   O formulário respira: campos altos, um só por linha, e o painel esquerdo
   diz o que a plataforma faz antes de pedir credenciais. */

.login-body { min-height: 100vh; background: var(--page); }

.login-wrap {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(480px, 560px);
}

.login-hero {
  background: linear-gradient(158deg, var(--rail-a) 0%, var(--rail-b) 100%);
  color: #fff;
  padding: 72px 64px;
  display: flex; flex-direction: column; justify-content: center;
}
.login-hero h1 {
  font-size: clamp(2rem, 3.4vw, 3rem);
  line-height: 1.12; letter-spacing: -.035em; font-weight: 700;
  margin: 0 0 20px; max-width: 16ch;
}
.login-hero p {
  font-size: var(--t-lead); line-height: 1.65; color: rgba(255, 255, 255, .8);
  margin: 0 0 36px; max-width: 46ch;
}

.login-brand { display: flex; align-items: center; gap: 14px; margin-bottom: 48px; }
.login-brand .brand-mark {
  width: 46px; height: 46px; flex: 0 0 46px; border-radius: 14px;
  background: rgba(255, 255, 255, .16); color: #fff;
  display: grid; place-items: center; font-size: 21px; font-weight: 700;
}
.login-brand strong { display: block; font-size: var(--t-lead); font-weight: 700; letter-spacing: -.01em; }
.login-brand small { display: block; font-size: var(--t-micro); color: rgba(255, 255, 255, .65); }

.login-points { list-style: none; margin: 0; padding: 0; display: grid; gap: 14px; }
.login-points li {
  display: flex; align-items: flex-start; gap: 12px;
  font-size: var(--t-small); color: rgba(255, 255, 255, .88); line-height: 1.5;
}
.login-points span {
  width: 22px; height: 22px; flex: 0 0 22px; border-radius: 50%;
  background: rgba(255, 255, 255, .18); color: #fff;
  display: grid; place-items: center; font-size: 12px; margin-top: 1px;
}

.login-card {
  display: grid; place-items: center;
  padding: 48px 40px; background: var(--surface);
}
.login-form { width: 100%; max-width: 400px; }

.login-brand-compact { display: none; }
.login-brand-compact .brand-mark { background: var(--brand); }
.login-brand-compact strong { color: var(--ink); }
.login-brand-compact small { color: var(--ink-3); }

.login-form h2 { font-size: var(--t-h2); font-weight: 700; letter-spacing: -.03em; margin-bottom: 8px; }
.login-intro { color: var(--ink-3); font-size: var(--t-small); margin: 0 0 32px; line-height: 1.6; }

.login-form form { display: grid; gap: 22px; }
.login-form .check { margin-top: 2px; }
.login-submit { min-height: 54px; font-size: var(--t-body); margin-top: 4px; }

/* Ver a palavra-passe evita o erro mais comum em teclados de telemóvel. */
.password-wrap { position: relative; display: block; width: 100%; }
.password-wrap > input { padding-right: 92px !important; }
.password-toggle {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  border: 0; background: transparent; cursor: pointer;
  color: var(--brand); font-size: var(--t-micro); font-weight: 650;
  padding: 8px 10px; border-radius: var(--r-control);
}
.password-toggle:hover { background: var(--brand-soft); }

.login-foot {
  margin: 32px 0 0; color: var(--ink-3); font-size: var(--t-micro);
  line-height: 1.6; border-top: 1px solid var(--rule); padding-top: 20px;
}

@media (max-width: 1080px) {
  .login-wrap { grid-template-columns: 1fr; }
  .login-hero { display: none; }
  .login-body { display: grid; place-items: center; }
  .login-card { padding: 40px 24px; background: transparent; }
  .login-brand-compact { display: flex; margin-bottom: 32px; }
  .login-form {
    background: var(--surface); border: 1px solid var(--rule);
    border-radius: var(--r-overlay); box-shadow: var(--e-2);
    padding: 36px 30px; max-width: 440px;
  }
}

@media (max-width: 480px) {
  .login-card { padding: 24px 16px; }
  .login-form { padding: 28px 22px; }
}

/* ==========================================================================
   Carregamento
   ========================================================================== */

.skeleton {
  background: linear-gradient(90deg, var(--surface-3) 25%, var(--brand-soft) 50%, var(--surface-3) 75%);
  background-size: 200% 100%; animation: shimmer 1.4s infinite; border-radius: 6px;
}
@keyframes shimmer { to { background-position: -200% 0; } }
.skeleton-line { height: 11px; margin-bottom: 8px; }
.skeleton-line.short { width: 55%; }

/* Alternância de tema: mostra o destino, não o estado atual. */
.theme-btn { padding-left: 10px; padding-right: 10px; }
.theme-btn .on-dark { display: none; }
[data-theme="dark"] .theme-btn .on-light { display: none; }
[data-theme="dark"] .theme-btn .on-dark { display: inline-flex; }

/* ==========================================================================
   Barra inferior (telemóvel)
   ========================================================================== */

.tabbar { display: none; }

@media (max-width: 820px) {
  .tabbar {
    display: grid; grid-template-columns: repeat(5, 1fr);
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    backdrop-filter: blur(16px); border-top: 1px solid var(--rule);
    padding: 7px 6px calc(7px + env(safe-area-inset-bottom));
  }
  .tabbar a {
    display: grid; justify-items: center; gap: 3px; padding: 7px 2px;
    color: var(--ink-3); font-size: 11px; font-weight: 550; border-radius: var(--r-control);
  }
  .tabbar a svg { width: 20px; height: 20px; stroke-width: 1.8; }
  .tabbar a.active { color: var(--brand); background: var(--brand-soft); }
}

/* ==========================================================================
   Adaptação
   ========================================================================== */

@media (max-width: 1180px) {
  .grid-4, .statband { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .split, .split-even, .form-grid-3 { grid-template-columns: 1fr; }
  .login-wrap { grid-template-columns: 1fr; }
  .login-hero { display: none; }
  .login-body { display: grid; place-items: center; }
}

@media (max-width: 980px) {
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .search-trigger { min-width: 0; padding: 9px 11px; }
  .search-trigger span:not(.kbd) { display: none; }
  .search-trigger .kbd-group { display: none; }
}

@media (max-width: 820px) {
  .sidebar { transform: translateX(-100%); transition: transform .22s var(--ease); box-shadow: var(--e-3); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop.open { display: block; }
  .main { margin-left: 0; width: 100%; padding-bottom: 70px; }
  .topbar { padding: 13px 16px; }
  .content { padding: 4px 16px 84px; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .span-2 { grid-column: span 1; }
  .form-section { padding: 20px 17px 22px; }
  .form-actions, .card-body, .card-header, .summary-item, .alert-row { padding-left: 17px; padding-right: 17px; }
  .stat { padding: 18px 18px 20px; }
  .toolbar form { width: 100%; }
  .toolbar .input, .toolbar input[type=search] { flex: 1 1 180px; min-width: 0; }
}

@media (max-width: 560px) {
  .grid-2, .grid-3, .grid-4, .statband { grid-template-columns: 1fr; }
  .topbar h1 { font-size: var(--t-lead); }
  .stat-value, .metric .value { font-size: var(--t-h2); }
  .stat-value.lead { font-size: var(--t-num); }
  .form-actions .btn { flex: 1 1 auto; }

  /* Uma tabela de oito colunas não se lê num telemóvel: cada linha vira ficha. */
  .table.responsive { min-width: 0; }
  .table.responsive thead { display: none; }
  .table.responsive tbody tr {
    display: grid; gap: 6px; padding: 15px 17px; border-bottom: 1px solid var(--rule);
  }
  .table.responsive tbody tr:hover td { background: transparent; }
  .table.responsive tbody td {
    display: flex; justify-content: space-between; align-items: center;
    gap: 12px; padding: 2px 0; border: 0; text-align: right;
  }
  .table.responsive tbody td::before {
    content: attr(data-label); font-size: var(--t-micro); color: var(--ink-3);
    font-weight: 550; text-align: left; flex: 0 0 auto;
  }
  .table.responsive tbody td:first-child {
    border-bottom: 1px solid var(--rule); padding-bottom: 8px; margin-bottom: 4px;
  }
}

/* ==========================================================================
   Impressão — contratos e extratos
   ========================================================================== */

@media print {
  .sidebar, .topbar, .form-actions, .toolbar, .tabbar, .no-print,
  .chip-row, .toast-stack, .cmdk-layer { display: none !important; }
  .main { margin: 0; width: 100%; }
  .content { padding: 0; max-width: none; }
  .card, .stat { box-shadow: none; border-color: #d4d4d4; break-inside: avoid; }
  .statband.hero .stat:first-child { background: #fff !important; color: #000 !important; border: 1px solid #d4d4d4; }
  .statband.hero .stat:first-child .stat-value,
  .statband.hero .stat:first-child .stat-label,
  .statband.hero .stat:first-child .stat-foot { color: #000 !important; }
  .table th { position: static; background: #f2f2f2; }
  body { background: #fff; font-size: 10.5pt; }
  a[href]::after { content: ""; }
}

/* --- Repetidor de documentos KYC ---------------------------------------- */
.doc-row {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, .7fr) minmax(0, 1.2fr) auto;
  gap: 16px;
  align-items: end;
  padding: 18px 0;
  border-bottom: 1px solid var(--rule);
}
.doc-row:first-child { padding-top: 0; }
.doc-row:last-of-type { border-bottom: 0; }
.doc-row input[type=file] { min-height: 50px; padding: 12px 14px; font-size: var(--t-micro); }
.doc-remove { color: var(--sev-3); white-space: nowrap; }
.doc-remove:hover { background: var(--sev-3-soft); color: var(--sev-3); }

@media (max-width: 820px) {
  .doc-row {
    grid-template-columns: 1fr;
    gap: 14px;
    padding: 20px 0;
  }
  .doc-remove { justify-self: start; }
}

/* --- Repetidor de contactos telefónicos --------------------------------- */
.phone-row {
  display: grid;
  grid-template-columns: minmax(0, .85fr) minmax(0, 1fr) minmax(0, 1fr) auto auto;
  gap: 16px;
  align-items: end;
  padding: 18px 0;
  border-bottom: 1px solid var(--rule);
}
.phone-row:first-child { padding-top: 0; }
.phone-row:last-of-type { border-bottom: 0; }

.phone-flags { display: flex; gap: 10px; align-items: end; }
.phone-check {
  min-height: 50px; padding: 12px 14px; white-space: nowrap;
  font-size: var(--t-micro); font-weight: 600;
}
.phone-check input:checked ~ span { color: var(--brand); }
.phone-remove { color: var(--sev-3); white-space: nowrap; }
.phone-remove:hover { background: var(--sev-3-soft); color: var(--sev-3); }

/* Lista de contactos na ficha do cliente */
.phone-list { display: grid; gap: 2px; }
.phone-entry {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 0; border-bottom: 1px solid var(--rule);
}
.phone-entry:last-child { border-bottom: 0; }
.phone-number {
  font-size: var(--t-lead); font-weight: 650; letter-spacing: -.01em;
  font-variant-numeric: tabular-nums;
}
.phone-actions { margin-left: auto; display: flex; gap: 7px; }

@media (max-width: 980px) {
  .phone-row { grid-template-columns: 1fr 1fr; gap: 14px; }
  .phone-flags { grid-column: span 2; }
}
@media (max-width: 640px) {
  .phone-row { grid-template-columns: 1fr; padding: 20px 0; }
  .phone-flags { grid-column: span 1; flex-wrap: wrap; }
  .phone-remove { justify-self: start; }
  .phone-entry { flex-wrap: wrap; }
  .phone-actions { margin-left: 0; width: 100%; }
}

/* --- Documentos KYC editáveis no sítio ---------------------------------- */
.doc-list { display: grid; gap: 14px; }
.doc-item {
  border: 1px solid var(--rule);
  border-radius: var(--r-panel);
  background: var(--surface-2);
  overflow: hidden;
}
.doc-item-form { padding: 16px 18px; }
.doc-item-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap; margin-bottom: 14px;
}
.doc-item-head a { font-size: var(--t-body); font-weight: 600; }
.doc-item-fields {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, .7fr) minmax(0, 1.1fr) auto;
  gap: 14px; align-items: end;
}
.doc-item-fields input[type=file] { min-height: 46px; padding: 11px 13px; font-size: var(--t-micro); }
.doc-item-foot {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap;
  padding: 12px 18px; border-top: 1px solid var(--rule); background: var(--surface);
}

@media (max-width: 900px) {
  .doc-item-fields { grid-template-columns: 1fr 1fr; }
  .doc-item-actions { grid-column: span 2; }
}
@media (max-width: 560px) {
  .doc-item-fields { grid-template-columns: 1fr; }
  .doc-item-actions { grid-column: span 1; }
}

/* O nome técnico do campo ao lado da mensagem: num formulário com 30 campos,
   "o campo selecionado é inválido" sozinho não diz onde corrigir. */
.error-list { display: grid; gap: 6px; }
.error-list li { line-height: 1.5; }
.error-list .code { margin-left: 6px; opacity: .75; }

/* --- Documentos existentes dentro do formulário da ficha ----------------- */
.subsection-title {
  font-size: var(--t-small); font-weight: 650; color: var(--ink-2);
  margin: 0 0 12px;
}

.doc-remove-check { min-height: 46px; padding: 12px 14px; white-space: nowrap; }
.doc-remove-check input:checked ~ span { color: var(--sev-3); font-weight: 650; }

/* A linha marcada esbate-se: o operador vê o que desaparece ao gravar. */
.doc-item.is-marked-for-removal {
  border-color: var(--sev-3-line);
  background: var(--sev-3-soft);
}
.doc-item.is-marked-for-removal .doc-item-head a,
.doc-item.is-marked-for-removal label { opacity: .5; }
.doc-item.is-marked-for-removal .doc-remove-check { opacity: 1; }

/* Seta de "abrir" nas ações da paleta: sinaliza que a linha é acionável. */
.cmdk-go {
  margin-left: auto; color: var(--ink-4); font-size: var(--t-micro);
  border: 1px solid var(--rule-2); border-radius: 5px;
  padding: 1px 6px; line-height: 1.6;
}
.cmdk-item:hover .cmdk-go, .cmdk-item.is-active .cmdk-go { color: var(--brand); border-color: var(--brand-line); }
