:root {
  --bg-start: #0F172A;
  --bg-end: #020617;
  --neon: #00F5FF;
  --neon-hover: #00D2DD;
  --card: #1E293B;
  --error: #EF4444;
  --text: #FFFFFF;
  --muted: #94A3B8;
  --field: rgba(255,255,255,.05);
  --line: rgba(255,255,255,.12);
  --ok: #34D399;  --ok-bg: rgba(16,185,129,.15);
  --warn: #FBBF24; --warn-bg: rgba(245,158,11,.15);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; min-height: 100%; }
body {
  background: linear-gradient(180deg, var(--bg-start), var(--bg-end)) fixed;
  background-color: var(--bg-end);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
/* 16px nos inputs evita o zoom automático do Safari no iOS */
input { font: inherit; font-size: 16px; }

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

/* ---------- Auth ---------- */
.auth {
  justify-content: center; align-items: center;
  padding: calc(24px + var(--safe-top)) 24px calc(24px + var(--safe-bottom));
}
.logo {
  width: 96px; height: 96px; border-radius: 50%; background: #fff; padding: 10px;
  box-shadow: 0 0 0 3px rgba(0,245,255,.35), 0 0 28px rgba(0,245,255,.25);
}
.logo img { width: 100%; height: 100%; object-fit: contain; }
.brand { font-size: 32px; font-weight: 700; letter-spacing: 1px; margin: 12px 0 28px; }
.panel {
  width: 100%; max-width: 420px; background: rgba(30,41,59,.9);
  border-radius: 24px; padding: 24px; box-shadow: 0 10px 30px rgba(0,0,0,.35);
}
.panel h2 { margin: 0 0 20px; font-size: 22px; text-align: center; }
.link-btn { display: block; margin: 16px auto 0; color: var(--neon); font-size: 14px; padding: 8px; }

/* ---------- Campos ---------- */
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin: 0 0 6px 4px; }
.field input {
  width: 100%; height: 52px; padding: 0 14px; color: #fff;
  background: var(--field); border: 1px solid var(--line); border-radius: 12px; outline: none;
  -webkit-appearance: none; appearance: none;
}
.field input:focus { border-color: var(--neon); }
.field input[type="date"] { color-scheme: dark; display: flex; align-items: center; }
.field input::-webkit-date-and-time-value { text-align: left; }

.btn {
  width: 100%; height: 54px; border-radius: 14px; background: var(--neon); color: #000;
  font-weight: 700; font-size: 16px; display: flex; align-items: center; justify-content: center; gap: 8px;
}
.btn:active { background: var(--neon-hover); }
.btn:disabled { opacity: .6; }
.error-box {
  background: rgba(239,68,68,.15); color: #FCA5A5; border-radius: 10px;
  padding: 10px 12px; font-size: 13px; text-align: center; margin-bottom: 14px;
}
.spinner {
  width: 20px; height: 20px; border-radius: 50%;
  border: 2.5px solid currentColor; border-right-color: transparent; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5; background: var(--bg-start);
  padding: calc(10px + var(--safe-top)) 8px 10px 16px;
  display: flex; align-items: center; gap: 4px;
}
.topbar h1 { flex: 1; margin: 0; font-size: 20px; font-weight: 700; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; color: #fff;
}
.icon-btn:active { background: rgba(255,255,255,.08); }
.icon-btn svg { width: 22px; height: 22px; }

/* ---------- Lista ---------- */
.list-wrap { flex: 1; width: 100%; max-width: 640px; margin: 0 auto; padding: 0 16px; }
.search { position: relative; margin: 6px 0 12px; }
.search svg { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); width: 20px; color: var(--muted); }
.search input {
  width: 100%; height: 50px; padding: 0 44px; border-radius: 12px; color: #fff;
  background: var(--field); border: 1px solid var(--line); outline: none; -webkit-appearance: none;
}
.search input:focus { border-color: var(--neon); }
.search .clear { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); }

.tabs { display: flex; border-bottom: 1px solid var(--line); margin-bottom: 12px; }
.tab {
  flex: 1; padding: 12px 0; font-size: 14px; font-weight: 600; color: var(--muted);
  border-bottom: 3px solid transparent; margin-bottom: -1px;
}
.tab.active { color: var(--neon); border-bottom-color: var(--neon); }

.cards { display: flex; flex-direction: column; gap: 12px; padding-bottom: calc(100px + var(--safe-bottom)); }
.card { background: var(--card); border-radius: 16px; padding: 14px 16px 16px; }
.card-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.card-top .left { display: flex; align-items: center; gap: 2px; min-width: 0; }
.nif { font-weight: 700; font-size: 16px; margin-right: 6px; white-space: nowrap; }
.mini { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; color: var(--neon); }
.mini:active { background: rgba(255,255,255,.08); }
.mini svg { width: 17px; height: 17px; }
.mini.danger { color: rgba(239,68,68,.85); }
.date { font-size: 12px; color: rgba(203,213,225,.6); white-space: nowrap; }
.email { font-size: 13px; color: rgba(203,213,225,.85); margin-top: 2px; word-break: break-word; }
.card-bottom { display: flex; align-items: flex-end; justify-content: space-between; margin-top: 12px; gap: 8px; }
.valor { font-size: 22px; font-weight: 800; color: var(--neon); }
.badges { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.badge { font-size: 11px; font-weight: 600; padding: 4px 8px; border-radius: 6px; background: rgba(255,255,255,.1); }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }

.empty { text-align: center; padding: 48px 24px; }
.empty .emoji { font-size: 56px; }
.empty h3 { margin: 16px 0 4px; font-size: 18px; }
.empty p { margin: 0; color: var(--muted); font-size: 13px; }

.fab {
  position: fixed; right: 20px; bottom: calc(20px + var(--safe-bottom)); z-index: 6;
  width: 60px; height: 60px; border-radius: 16px; background: var(--neon); color: #000;
  display: grid; place-items: center; box-shadow: 0 8px 24px rgba(0,245,255,.3);
}
.fab svg { width: 28px; height: 28px; }

/* ---------- Formulário de fatura ---------- */
.form-wrap { width: 100%; max-width: 560px; margin: 0 auto; padding: 8px 16px calc(32px + var(--safe-bottom)); }
.suggest-label { font-size: 12px; color: var(--muted); margin: 0 0 8px 2px; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 12px; margin-bottom: 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; font-size: 12px; padding: 8px 12px; border-radius: 10px; white-space: nowrap;
  background: rgba(255,255,255,.08); border: 1px solid var(--line);
}
.section-label { font-size: 14px; font-weight: 600; margin: 6px 0 10px 2px; }
.metodos { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 18px; }
.metodo {
  height: 44px; border-radius: 10px; font-size: 13px; font-weight: 600;
  background: rgba(255,255,255,.05); border: 1px solid var(--line);
}
.metodo.sel { background: var(--neon); color: #000; border-color: var(--neon); }

.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; }
.switch-row strong { display: block; font-size: 14px; }
.switch-row small { color: var(--muted); font-size: 11px; }
.switch { position: relative; width: 52px; height: 32px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch .track {
  position: absolute; inset: 0; border-radius: 16px; background: rgba(255,255,255,.15); transition: background .2s;
}
.switch .track::after {
  content: ""; position: absolute; top: 4px; left: 4px; width: 24px; height: 24px; border-radius: 50%;
  background: #fff; transition: transform .2s;
}
.switch input:checked + .track { background: var(--neon); }
.switch input:checked + .track::after { transform: translateX(20px); background: #000; }

/* ---------- Diálogo / toast ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 20; background: rgba(2,6,23,.7);
  display: grid; place-items: center; padding: 24px;
}
.dialog { width: 100%; max-width: 380px; background: var(--card); border-radius: 20px; padding: 22px; }
.dialog h3 { margin: 0 0 10px; }
.dialog p { margin: 0 0 18px; color: #CBD5E1; font-size: 14px; line-height: 1.45; }
.dialog .actions { display: flex; justify-content: flex-end; gap: 6px; }
.dialog .actions button { padding: 10px 14px; border-radius: 10px; font-weight: 700; }
.dialog .actions .danger { color: var(--error); }

.toast {
  position: fixed; left: 50%; bottom: calc(96px + var(--safe-bottom)); transform: translateX(-50%) translateY(20px);
  background: #334155; color: #fff; font-size: 14px; padding: 10px 16px; border-radius: 12px;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 30; max-width: 90vw; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.center-msg { flex: 1; display: grid; place-items: center; padding: 32px; text-align: center; color: var(--muted); }
.center-msg .btn { width: auto; padding: 0 22px; margin-top: 16px; }
