/* Base, shell (barra de separadores / barra lateral), ecrãs de entrada e folhas. */

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

html {
  -webkit-tap-highlight-color: transparent; /* sem o flash cinzento ao tocar */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  overscroll-behavior: none; /* sem "puxar para atualizar" a sequestrar o deslizar */
  background: var(--bg2);
}

body {
  font: 16px/1.45 var(--letra);
  color: var(--ink);
  background: linear-gradient(180deg, var(--bg1) 0%, var(--bg2) 100%) fixed;
  min-height: 100dvh;
  font-variant-numeric: tabular-nums;
  overscroll-behavior: none;
}

button, input, select, textarea { font: inherit; color: inherit; }
/* Nunca menos de 16 px nos campos: o iOS amplia a página ao tocar num campo mais pequeno. */
input, textarea, select { font-size: 16px; }
button {
  border: 0; background: none; cursor: pointer;
}
button, a, [role="button"], summary {
  touch-action: manipulation; /* toque sem espera de duplo toque */
}
/* Controlos não se selecionam com toque longo; o conteúdo sim. */
button, .separadores a, .lateral a, summary {
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }

.vidro {
  background: var(--glass);
  -webkit-backdrop-filter: var(--vidro);
  backdrop-filter: var(--vidro);
  border: 1px solid var(--glass-edge);
}

/* ---------- Shell ---------- */

.app { min-height: 100dvh; }

.lateral { display: none; }

.principal {
  padding:
    calc(env(safe-area-inset-top, 0px) + 14px)
    calc(env(safe-area-inset-right, 0px) + var(--margem))
    calc(env(safe-area-inset-bottom, 0px) + 96px)
    calc(env(safe-area-inset-left, 0px) + var(--margem));
}

.separadores {
  position: fixed; z-index: 10;
  left: calc(env(safe-area-inset-left, 0px) + 12px);
  right: calc(env(safe-area-inset-right, 0px) + 12px);
  bottom: calc(env(safe-area-inset-bottom, 0px) + 10px);
  display: grid; grid-template-columns: repeat(4, 1fr);
  padding: 6px;
  border-radius: var(--r-barra);
  background: var(--glass);
  -webkit-backdrop-filter: var(--vidro-barra);
  backdrop-filter: var(--vidro-barra);
  border: 1px solid var(--glass-edge);
  box-shadow: var(--sombra);
}
.separadores a {
  display: grid; place-items: center;
  min-height: 44px; border-radius: 18px;
  font-size: 13px; font-weight: 600; color: var(--ink-2); text-decoration: none;
  transition: transform var(--t-toque) var(--ease-out);
}
.separadores a[aria-current="page"] { background: var(--glass-on); color: var(--accent); }
.separadores a:active { transform: scale(.96); }

/* Estado da sincronização: discreto, só aparece quando há algo a dizer. */
.sync { font-size: 13px; color: var(--ink-2); }
.sync:not(:empty) { margin: 0 2px 10px; }
.sync .pendentes::before {
  content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%;
  background: var(--accent); margin-right: 7px; vertical-align: 1px;
}
.sync details { background: var(--card-2); border-radius: 12px; padding: 8px 12px; }
.sync summary { color: var(--erro); font-weight: 600; cursor: pointer; list-style-position: inside; }
.sync details p { margin-top: 6px; overflow-wrap: anywhere; color: var(--ink); }
.sync details .tecnico { font-size: 12px; color: var(--ink-2); }
.sync-acoes { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.sync-acoes .botao-sec { margin-top: 0; font-size: 14px; }

/* "Saltar para o conteúdo": só aparece com o foco do teclado. */
.saltar {
  position: fixed; z-index: 60; top: calc(env(safe-area-inset-top, 0px) + 8px); left: 8px; padding: 10px 14px; border-radius: 12px;
  background: var(--card); color: var(--accent); font-weight: 600; text-decoration: none; box-shadow: var(--sombra);
  transform: translateY(-200%);
}
.saltar:focus { transform: none; }

/* Modo de demonstração no telemóvel (no computador está na barra lateral). */
.etiqueta-demo {
  display: inline-block; margin: 0 0 10px; padding: 3px 10px; border-radius: 999px;
  font-size: 13px; font-weight: 500; color: var(--ink-2); background: var(--card-2);
}

/* Cabeçalho de cada secção */
.topo { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; min-height: 44px; }
.topo h1 { font-size: 28px; line-height: 34px; font-weight: 700; letter-spacing: -.02em; }
.topo h1 span { color: var(--ink-2); font-weight: 500; }
.topo h1:focus { outline: none; }
.setas { display: flex; gap: 6px; flex: none; }
.setas button {
  width: 44px; height: 44px; border-radius: 999px; display: grid; place-items: center;
  background: var(--glass);
  -webkit-backdrop-filter: blur(18px) saturate(160%);
  backdrop-filter: blur(18px) saturate(160%);
  border: 1px solid var(--glass-edge);
  transition: transform var(--t-toque) var(--ease-out);
}
.setas button:active { transform: scale(.94); }
.setas svg { width: 18px; height: 18px; }

@media (min-width: 900px) {
  .app {
    display: grid; grid-template-columns: 232px minmax(0, 1fr); gap: 20px;
    height: 100dvh; padding: 20px;
  }
  .lateral {
    display: flex; flex-direction: column; gap: 4px;
    border-radius: var(--r-painel); padding: 22px 14px;
    background: var(--glass);
    -webkit-backdrop-filter: var(--vidro);
    backdrop-filter: var(--vidro);
    border: 1px solid var(--glass-edge);
  }
  .lateral .marca { font-size: 20px; font-weight: 700; letter-spacing: -.01em; margin: 0 10px 22px; }
  .lateral .marca small { display: block; font-size: 13px; font-weight: 500; color: var(--ink-2); letter-spacing: 0; }
  .lateral a {
    display: flex; align-items: center; min-height: 44px; padding: 0 12px; border-radius: 12px;
    color: var(--ink-2); font-weight: 550; text-decoration: none;
  }
  .lateral a[aria-current="page"] { background: var(--glass-on); color: var(--ink); }
  .principal { padding: 8px 4px; overflow: auto; overscroll-behavior: contain; }
  .separadores { display: none; }
  .etiqueta-demo { display: none; }
  .topo h1 { font-size: 34px; line-height: 40px; }
}

@media (hover: hover) and (pointer: fine) {
  .lateral a:not([aria-current="page"]):hover { background: rgba(255, 255, 255, .55); color: var(--ink); }
  .setas button:hover { background: var(--card); }
  .botao:hover { filter: brightness(1.06); }
  .ligacao:not(:disabled):hover { text-decoration: underline; }
}
@media (hover: hover) and (pointer: fine) and (prefers-color-scheme: dark) {
  .lateral a:not([aria-current="page"]):hover { background: rgba(255, 255, 255, .06); }
}

/* ---------- Ecrãs de entrada (Ligar ao Supabase, Entrar) ---------- */

.entrada {
  min-height: 100dvh;
  display: grid; place-items: center;
  padding:
    calc(env(safe-area-inset-top, 0px) + 24px)
    calc(env(safe-area-inset-right, 0px) + var(--margem))
    calc(env(safe-area-inset-bottom, 0px) + 24px)
    calc(env(safe-area-inset-left, 0px) + var(--margem));
}
.entrada-caixa { width: 100%; max-width: 400px; border-radius: var(--r-painel); padding: 28px 22px 24px; box-shadow: var(--sombra); }
.entrada-caixa .simbolo { width: 52px; height: 52px; border-radius: 13px; display: block; margin-bottom: 18px; }
.entrada-caixa h1 { font-size: 28px; line-height: 34px; font-weight: 700; letter-spacing: -.02em; }
.entrada-caixa .explica { color: var(--ink-2); margin: 6px 0 20px; }
.entrada-caixa .explica b { color: var(--ink); font-weight: 600; overflow-wrap: anywhere; }

.campo { display: grid; gap: 6px; margin-bottom: 16px; }
.campo label { font-size: 15px; font-weight: 600; }
.campo .ajuda { font-size: 13px; color: var(--ink-2); }
.campo input {
  font-size: 16px; /* nunca menos: o iOS amplia a página em campos mais pequenos */
  width: 100%; min-height: 48px; padding: 0 14px;
  border-radius: 12px; border: 1px solid var(--line); background: var(--card);
  outline: none;
}
.campo input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
.campo-senha { position: relative; display: grid; }
.campo-senha input { padding-right: 96px; }
.campo-senha .olho {
  position: absolute; top: 0; right: 0; min-width: 44px; min-height: 48px; padding: 0 14px;
  color: var(--accent); font-size: 15px; font-weight: 500; background: none;
}

.botao {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; min-height: 48px; border-radius: 999px;
  background: var(--accent); color: var(--accent-ink); font-weight: 600;
  transition: transform var(--t-toque) var(--ease-out);
}
.botao:active { transform: scale(.98); }
.botao[aria-busy="true"] { opacity: .7; cursor: progress; }

.alerta { color: var(--erro); background: var(--card-2); border-radius: 12px; padding: 10px 12px; font-size: 15px; margin-bottom: 14px; }
/* Mensagem boa (conta confirmada, ligação enviada): como o alerta, com a cor do texto. */
.aviso-ok { color: var(--ink); background: var(--card-2); border-radius: 12px; padding: 10px 12px; font-size: 15px; margin-bottom: 14px; overflow-wrap: anywhere; }
.aviso-ok::before {
  content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%;
  background: var(--accent); margin-right: 8px; vertical-align: 2px;
}
/* Sempre no DOM e nunca display:none (os leitores de ecrã só anunciam alertas que existem);
   vazio, fica escondido só visualmente. */
.aviso-ok:empty,
.aviso-app:empty,
.alerta:empty {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden;
  clip-path: inset(50%); white-space: nowrap; border: 0;
}

.secundarias { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 18px; margin-top: 16px; }
.ligacao {
  min-height: 44px; display: inline-flex; align-items: center;
  color: var(--accent); font-weight: 500; font-size: 15px; text-decoration: none; background: none;
}
.ligacao:disabled { color: var(--ink-2); cursor: default; }
.ligacao.discreta { color: var(--ink-2); font-size: 14px; }
.sem-servidor { flex-basis: 100%; text-align: center; }
.sem-servidor .explica { margin: 0 0 4px; font-size: 14px; }

/* Modos do ecrã de entrada */
.inteira { white-space: nowrap; }
.esqueci { display: flex; justify-content: flex-end; margin: -10px 0 8px; }
.esqueci .ligacao { font-size: 14px; }
.trocar { width: 100%; display: flex; flex-wrap: wrap; justify-content: center; align-items: center; column-gap: 6px; font-size: 15px; color: var(--ink-2); }
.aviso-pendentes { font-size: 15px; font-weight: 600; background: var(--card-2); border-radius: 12px; padding: 10px 12px; margin: -6px 0 14px; }
.entrada-caixa > .botao-sec { width: 100%; margin-top: 10px; }
.privacidade { font-size: 13px; line-height: 18px; color: var(--ink-2); margin: -2px 0 16px; }
/* Só para o gestor de palavras-passe saber a conta (Nova palavra-passe, Definições). */
.so-gestor { display: none; font-size: 16px; }

/* Mensagem ao abrir a app ("Palavra-passe alterada.") */
.aviso-app { font-size: 15px; background: var(--card-2); border-radius: 12px; padding: 10px 12px; margin: 0 0 12px; }

/* ---------- Folha (baixo no telemóvel, painel à direita no computador) ---------- */

.folha-fundo {
  position: fixed; inset: 0; z-index: 40; background: var(--veu);
  opacity: 0; transition: opacity var(--t-folha) var(--ease-out);
}
.folha-fundo.aberta { opacity: 1; }

.folha {
  position: fixed; z-index: 41; left: 0; right: 0; bottom: 0;
  max-height: 88dvh; display: flex; flex-direction: column;
  border-radius: var(--r-painel) var(--r-painel) 0 0;
  background: var(--glass-folha);
  -webkit-backdrop-filter: var(--vidro-barra);
  backdrop-filter: var(--vidro-barra);
  border: 1px solid var(--glass-edge); border-bottom: 0;
  box-shadow: 0 -8px 30px rgba(20, 40, 80, .12);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  transform: translateY(100%);
  transition: transform var(--t-folha) var(--ease-out);
  outline: none;
}
.folha.aberta { transform: none; }
.folha.a-arrastar { transition: none; }

.folha-pega { flex: none; height: 22px; display: grid; place-items: center; cursor: grab; touch-action: none; }
.folha-pega::before { content: ""; width: 36px; height: 5px; border-radius: 999px; background: var(--line); }
.folha-topo { flex: none; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 0 12px 8px 20px; touch-action: none; }
.folha-topo h2 { font-size: 20px; line-height: 26px; font-weight: 700; letter-spacing: -.01em; }
.folha-fechar {
  flex: none; width: 44px; height: 44px; border-radius: 999px; display: grid; place-items: center; color: var(--ink-2);
}
.folha-fechar svg { width: 30px; height: 30px; }
.folha-descartar { flex: none; margin: 0 20px 10px; padding: 12px; border-radius: 14px; background: var(--card-2); }
.folha-descartar p { font-size: 15px; font-weight: 600; margin-bottom: 8px; }
.folha-descartar-botoes { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; }
.folha-descartar .botao-sec { margin-top: 0; width: 100%; padding: 0 10px; }
.folha-corpo { overflow-y: auto; overscroll-behavior: contain; padding: 4px 20px 20px; }

@media (min-width: 900px) {
  .folha {
    left: auto; top: 20px; right: 20px; bottom: 20px; width: 340px; max-height: none;
    border-radius: var(--r-painel); border-bottom: 1px solid var(--glass-edge);
    box-shadow: var(--sombra); padding-bottom: 0;
    transform: translateX(24px); opacity: 0;
    transition: transform var(--t-folha) var(--ease-out), opacity var(--t-folha) var(--ease-out);
  }
  .folha.aberta { transform: none; opacity: 1; }
  .folha-pega { display: none; }
  .folha-topo { padding: 16px 12px 8px 20px; touch-action: auto; }
  .folha-fundo { background: transparent; }
}

/* ---------- Preferências do sistema ---------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0ms !important; animation-duration: 0ms !important; }
  .folha, .folha.aberta { transform: none !important; }
  .separadores a:active, .setas button:active, .botao:active { transform: none; }
}

@media (prefers-reduced-transparency: reduce) {
  .vidro, .separadores, .lateral, .setas button, .folha {
    background: var(--card);
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
}
