/* ============================================================
   COMPONENTS — nav, botões, forms, badges, cards partilhados
   ============================================================ */

/* ── Reset global box-sizing (CANÓNICO, devia estar sempre aqui) ──
   Sem isto, padding soma-se a width:100%/width:Xpx em vez de ficar incluído
   nesse valor — qualquer elemento com padding + width percentual pode
   ficar mais largo do que o seu contentor. Foi exactamente isto que causou
   o input de URL a sobrepor-se ao botão de submeter em mobile (confirmado
   por medição: o input tinha 60px mais largura do que o seu wrapper,
   batendo certo com o padding horizontal do .rx-input). Reset padrão desde
   ~2012, praticamente universal — devia ter estado aqui desde o início. */
*, *::before, *::after {
  box-sizing: border-box;
}

/* ── Scrollbar customizada GLOBAL (todo o site) ──────────────────
   Fina e discreta, com as cores do tema, em vez do estilo nativo do SO.
   Aplica-se a QUALQUER elemento scrollável (página, modais, paineis) salvo
   onde uma regra mais específica decida escondê-la de propósito (ex.: as
   barras horizontais de pills de filtro, que usam scroll sem scrollbar
   visível como affordance — essas continuam a funcionar, esta regra não as
   sobrepõe porque elas já têm scrollbar-width:none/display:none próprios,
   que vencem por especificidade/ordem). */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--wire-2, #ffffff1e) transparent;
}
*::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: var(--wire-2, #ffffff1e);
  border-radius: 99px;
}
*::-webkit-scrollbar-thumb:hover { background: var(--wire, #ffffff2e); }

/* ── NAV (landing) ── */
nav.landing-nav {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 100;
  padding: 1.25rem 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: linear-gradient(to bottom, var(--ink) 60%, transparent);
}

/* ── NAV (app) ── */
nav.app-nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  background: var(--ink);
  border-bottom: 1px solid var(--wire);
  padding: 1rem 2rem;
}

/* Conteúdo da nav limitado a uma largura confortável e centrado — a barra
   (acima) continua a cobrir 100% da largura (fundo + borda), só o
   conteúdo (logo...menu) é que fica contido. Sem isto, em ecrãs muito
   largos (ex.: 4K) o logo e o menu ficavam encostados aos cantos com um
   vazio enorme no meio — left/right mantêm-se dentro deste limite. */
.nav-inner {
  width: 100%;
  max-width: 1500px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.nav-logo {
  font-family: 'Syne', sans-serif;
  font-weight: 800;
  font-size: 1.625rem;
  letter-spacing: -0.02em;
  color: var(--text);
  text-decoration: none;
}

.nav-logo span { color: var(--amber); }

.nav-cta {
  font-family: 'DM Sans', sans-serif;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--ink);
  background: var(--amber);
  border: none;
  border-radius: 6px;
  padding: 0.5rem 1.125rem;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, transform 0.15s;
}

.nav-cta:hover {
  background: var(--amber-2);
  transform: translateY(-1px);
}

.nav-right {
  display: flex;
  align-items: center;
  gap: 1.25rem;
}

.nav-balance {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--amber);
  border: none;
  border-radius: 8px;
  padding: 0.4rem 0.875rem;
  font-family: 'DM Mono', monospace;
  font-size: 0.8125rem;
  color: var(--ink);
  transition: background 0.15s, transform 0.15s;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
/* Hover apenas em dispositivos com hover real (rato). Em touch, o :hover
   ficava "preso" após o toque (o browser mantém o último elemento tocado em
   hover até se tocar noutro sítio), deixando o botão com a cor --amber-2 como
   se continuasse clicado. Com @media (hover: hover) isto não acontece no mobile. */
@media (hover: hover) {
  .nav-balance:hover { background: var(--amber-2); transform: translateY(-1px); }
}
/* Feedback ao premir, válido em qualquer dispositivo. */
.nav-balance:active { background: var(--amber-2); }
/* Foco: sem outline nativo ao clicar; anel visível só em navegação por teclado. */
.nav-balance:focus { outline: none; }
.nav-balance:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }

.nav-balance-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--ink);
  opacity: 0.6;
}

.nav-balance-link {
  color: var(--ink);
  text-decoration: none;
  font-family: 'DM Mono', monospace;
  font-size: 0.8125rem;
  font-weight: 700;
}
.nav-balance-link:visited { color: var(--ink); }
.nav-balance-link:hover { color: var(--ink); }

.nav-logout {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-2);
  background: var(--ghost-2);
  border: 1px solid var(--wire-2);
  border-radius: 8px;
  cursor: pointer;
  padding: 0.4375rem 1rem;
  transition: all 0.15s;
  white-space: nowrap;
  font-family: 'Syne', sans-serif;
  text-decoration: none;
}

.nav-logout:hover {
  color: var(--text);
  background: var(--ghost-3);
  border-color: var(--wire);
}

/* ── BUTTONS ── */
.btn-primary {
  background: var(--amber);
  color: var(--ink);
  border: none;
  border-radius: 8px;
  padding: 0.9375rem 1.75rem;
  font-family: 'Syne', sans-serif;
  font-size: 0.9375rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s, transform 0.15s;
  white-space: nowrap;
}

.btn-primary:hover {
  background: var(--amber-2);
  transform: translateY(-1px);
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* ── FORM INPUTS ── */
/* ── STATUS BADGES ── */
/* ── CHIP/PILL (CANÓNICO) ──
   Base partilhada para qualquer botão tipo "pill" clicável (filtros,
   ordenação, etc.). Usa junto de uma classe própria do contexto para
   comportamento extra específico (ex.: .facet-pill, .sort-btn) — ver
   dashboard.css/transactions.css. */
.rx-chip {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.375rem 0.875rem;
  border-radius: 99px;
  font-size: 0.75rem;
  font-weight: 500;
  border: 1px solid var(--wire-2);
  background: transparent;
  color: var(--text-3);
  cursor: pointer;
  transition: all 0.15s;
  font-family: 'DM Sans', sans-serif;
  white-space: nowrap;
}
.rx-chip:hover { border-color: var(--ghost-3); color: var(--text-2); }
.rx-chip.active {
  background: var(--amber);
  border-color: var(--amber);
  color: var(--ink);
  font-weight: 600;
}
.rx-chip.disabled {
  opacity: 0.35;
  cursor: not-allowed;
  pointer-events: none;
}
/* Botão de ordenação com seta rotativa — partilhado (dashboard + transações). */
.sort-btn .sort-arrow { transition: transform 0.18s ease; }
.sort-btn.active.asc .sort-arrow { transform: rotate(180deg); }

/* Estado vazio simples (texto centrado) — para listas com menos peso visual
   que o .empty-state do dashboard (esse tem ícone+título+corpo, estrutura
   própria, não vale a pena forçar a partilhar). */
.rx-empty {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-3);
  font-size: 0.875rem;
}

.status-badge {
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 0.3rem 0.7rem;
  border-radius: 99px;
  font-family: 'DM Mono', monospace;
}

.status-badge.done {
  background: rgba(34,197,94,0.1);
  color: var(--green);
  border: 1px solid rgba(34,197,94,0.2);
}

.status-badge.processing,
.status-badge.pending {
  background: rgba(245,166,35,0.1);
  color: var(--amber-2);
  border: 1px solid rgba(245,166,35,0.2);
}

.status-badge.error,
.status-badge.failed {
  background: rgba(239,68,68,0.1);
  color: var(--red);
  border: 1px solid rgba(239,68,68,0.2);
}

/* ── ERROR / SUCCESS BANNERS ── */
.error-banner {
  background: rgba(239,68,68,0.1);
  border: 1px solid rgba(239,68,68,0.3);
  border-radius: 10px;
  padding: 0.875rem 1.25rem;
  font-size: 0.875rem;
  color: #fca5a5;
  display: none;
}

.error-msg {
  background: rgba(239,68,68,0.1);
  border: 1px solid rgba(239,68,68,0.3);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  font-size: 0.8125rem;
  color: #fca5a5;
  display: none;
}

/* ── SKELETON ── */
.skeleton {
  background: linear-gradient(90deg, var(--ghost) 25%, var(--ghost-2) 50%, var(--ghost) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 4px;
}

.skeleton-card {
  background: var(--ink-2);
  border: 1px solid var(--wire-2);
  border-radius: 12px;
  padding: 1.25rem 1.5rem;
  margin-bottom: 0.75rem;
  display: flex;
  align-items: center;
  gap: 1rem;
}

/* ── SECTION COMMON ── */
.section-label {
  font-size: 0.6875rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--amber);
  margin-bottom: 1rem;
}

.section-title {
  font-family: 'Syne', sans-serif;
  font-weight: 800;
  font-size: clamp(1.75rem, 4vw, 2.75rem);
  letter-spacing: -0.02em;
  color: var(--text);
  line-height: 1.1;
  margin-bottom: 1.25rem;
}

.section-body {
  font-size: 1.0625rem;
  color: var(--text-2);
  line-height: 1.7;
  font-weight: 300;
  max-width: 800px;
  display: block;
}

/* ── FOOTER ── */
footer {
  border-top: 1px solid var(--wire);
  padding: 2.5rem 1.5rem;
}

.footer-inner {
  max-width: 900px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
}

/* ── Cabeçalho da página de relatório ──────────────────── */
/* .report-page-header: container do botão voltar no relatório (estático,
   sem fundo — mostra o fundo da página). O botão usa .rx-back (rx-core). */
.report-page-header {
  max-width: 860px;
  margin: 0 auto;
  padding: 1.5rem 1.5rem 0.25rem;
  background: transparent;
}

.report-page-title {
  font-family: 'Syne', sans-serif;
  font-weight: 800;
  font-size: 1.375rem;
  letter-spacing: -0.02em;
  color: var(--text);
  margin: 0 0 0.5rem;
  line-height: 1.2;
}

.report-page-subtitle {
  font-size: 0.9375rem;
  color: var(--text-2);
  line-height: 1.6;
  margin: 0;
  max-width: 680px;
}

/* ============================================================
   rx-core — Shell de página partilhado (canónico)
   Container + botão voltar + título + subtítulo. Usado por
   qualquer ecrã com layout "voltar → título → conteúdo"
   (transações, e futuros). O dashboard é a home e não usa.
   Tudo via variáveis do tokens.css → tema funciona sozinho.
   ============================================================ */
.rx-page {
  max-width: 860px;
  margin: 0 auto;
  padding: 1.5rem 1.5rem 4rem;
}

/* Botão voltar — circular, âmbar, só ícone (mesmo estilo do RXScrollNav,
   rx-core/scroll-nav.css), mas estático/in-flow em vez de flutuante. Usado
   em qualquer ecrã com um "voltar" no topo do conteúdo (transações,
   relatório, páginas estáticas). Texto removido de propósito — o ícone
   já é suficientemente claro, e mantém consistência visual com os botões
   de scroll. */
.rx-back {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--amber);
  color: var(--ink);
  border: none;
  text-decoration: none;
  cursor: pointer;
  margin-bottom: 1rem;
  transition: background 0.15s ease;
}
.rx-back svg { width: 18px; height: 18px; }
.rx-back:hover { background: var(--amber-2); }

/* Título de página canónico: Syne 800, 1.5rem. */
.rx-page-title {
  font-family: 'Syne', sans-serif;
  font-weight: 800;
  font-size: 1.5rem;
  letter-spacing: -0.02em;
  color: var(--text);
  margin: 0 0 0.375rem;
  line-height: 1.2;
}

.rx-page-subtitle {
  font-size: 0.9375rem;
  color: var(--text-3);
  line-height: 1.6;
  margin: 0;
  max-width: 680px;
}

/* Botões flutuantes (FAB): voltar ao topo / voltar às análises.
   Empilháveis via .rx-fab--lower (em baixo) e .rx-fab--upper. */
.rx-fab {
  position: fixed;
  right: 1.5rem;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--amber);
  color: var(--ink);
  border: none;
  cursor: pointer;
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 0.2s, transform 0.2s, background 0.15s;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}
.rx-fab.visible { opacity: 1; pointer-events: auto; transform: translateY(0); }
.rx-fab:hover { background: var(--amber-2); }
.rx-fab--lower { bottom: 1.5rem; }
.rx-fab--upper { bottom: 5rem; }

.footer-logo {
  font-family: 'Syne', sans-serif;
  font-weight: 800;
  font-size: 1.3125rem;
  color: var(--text);
  text-decoration: none;
}

.footer-logo span { color: var(--amber); }

.footer-links {
  display: flex;
  gap: 1.5rem;
}

.footer-links a {
  font-size: 0.8125rem;
  color: var(--text-3);
  text-decoration: none;
  transition: color 0.15s;
}

.footer-links a:hover { color: var(--text-2); }

.footer-copy {
  font-size: 0.75rem;
  color: var(--muted);
}

/* ── RESPONSIVE ── */
@media (max-width: 600px) {
  nav.app-nav {
    padding: 0.75rem 1rem;
  }
  .nav-right {
    gap: 0.625rem;
  }
  .nav-balance {
    font-size: 0.75rem;
    padding: 0.35rem 0.625rem;
  }
}

/* ── FOOTER (persistente, fora do #app) ──
   Escondido por padrão. Só aparece nas páginas públicas/de conteúdo
   (landing, FAQ, Termos, Privacidade), que adicionam body.show-footer ao
   renderizar — ver static-pages.js e landing.js. NÃO aparece nos ecrãs de
   trabalho (dashboard, relatório, transações): é o padrão usado por
   produtos SaaS (Notion, Linear, Stripe dashboard, etc.) — footers com
   links de baixa frequência (legal/ajuda) competem mal com scroll
   infinito e conteúdo de trabalho; esses links vivem no menu de ajuda da
   nav (botão "?") em vez de um footer sempre presente.
   Reutiliza a estrutura partilhada footer/.footer-inner/.footer-logo/
   .footer-links/.footer-copy (a mesma que a landing já usa) — só controla
   aqui a visibilidade condicional; o layout vem todo da base. */
footer.app-footer { display: none; }
body.show-footer footer.app-footer { display: block; }
/* ── MENU DE CONTA (consolidado: páginas + tema + sair) ──
   Substitui os três elementos separados que existiam antes (seletor de
   tema, menu de ajuda, botão de logout) por um único ponto de entrada na
   nav — padrão usado por produtos como a Railway (menu de conta, ao
   clicar no avatar/ícone). Reutiliza .theme-option (já existe, tem a
   lógica de estado activo) para os 3 itens de tema; .menu-link é o
   equivalente genérico para os restantes itens (páginas, sair). */
.account-menu-wrap { position: relative; display: inline-flex; }

.account-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 200;
  display: none;
  flex-direction: column;
  gap: 2px;
  min-width: 230px;
  max-width: 280px;
  padding: 6px;
  background: var(--ink-2);
  border: 2px solid var(--wire-2);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
}
.account-menu.open { display: flex; }

.account-menu-divider {
  height: 1px;
  background: var(--wire);
  margin: 4px 2px;
}

/* Linha de perfil no topo do menu — avatar (inicial do email) + email.
   Substitui um simples cabeçalho de texto por algo com mais identidade,
   sem precisar de foto de perfil real. */
.account-menu-profile {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.5rem 0.625rem 0.625rem;
}
.account-menu-avatar {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--amber);
  color: var(--ink);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Syne', sans-serif;
  font-weight: 800;
  font-size: 0.875rem;
}
.account-menu-email {
  font-size: 0.8125rem;
  color: var(--text-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.menu-link {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  width: 100%;
  padding: 0.5rem 0.625rem;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-2);
  font-family: 'DM Sans', sans-serif;
  font-size: 0.8125rem;
  text-decoration: none;
  cursor: pointer;
  text-align: left;
}
.menu-link svg { flex-shrink: 0; color: var(--text-3); }
.menu-link:hover { background: var(--ghost-2); color: var(--text); }

/* Última linha do menu: tema (controlo segmentado, 3 estados, não parece
   um botão tradicional) + Sair (ícone power, vermelho) lado a lado. */
.account-menu-bottom-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 4px 2px 2px;
}

.theme-segmented {
  display: flex;
  align-items: center;
  gap: 2px;
  background: var(--ghost-2);
  border-radius: 8px;
  padding: 3px;
}
.theme-seg-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-3);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.theme-seg-btn:hover { color: var(--text); }
.theme-seg-btn.active { background: var(--amber); color: var(--ink); }

.menu-logout-btn {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.4375rem 0.625rem;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--red);
  font-family: 'DM Sans', sans-serif;
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
}
.menu-logout-btn:hover { background: color-mix(in srgb, var(--red) 12%, transparent); }
