:root {
  --bg: #0b0b10;
  --surface: rgba(255, 255, 255, 0.06);
  --surface-2: rgba(255, 255, 255, 0.1);
  --line: rgba(255, 255, 255, 0.09);
  --text: #f5f5f7;
  --muted: rgba(245, 245, 247, 0.55);
  --accent: #8b7bff;
  --danger: #ff5a6a;
  --spring: cubic-bezier(0.32, 1.25, 0.45, 1);
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --radius: 22px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
  overscroll-behavior-y: none;
}
body.locked { overflow: hidden; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
[hidden] { display: none !important; }

.aurora {
  position: fixed; inset: -20% -20% auto; height: 70vh; z-index: -1; pointer-events: none;
  background:
    radial-gradient(40% 50% at 20% 30%, rgba(124, 92, 255, 0.28), transparent 70%),
    radial-gradient(40% 50% at 80% 10%, rgba(40, 200, 255, 0.18), transparent 70%);
  filter: blur(30px);
  animation: drift 18s ease-in-out infinite alternate;
}
@keyframes drift { to { transform: translate3d(4%, 6%, 0) scale(1.08); } }

/* ---------- Header ---------- */
.top {
  position: sticky; top: 0; z-index: 20;
  padding: calc(var(--safe-top) + 14px) 20px 10px;
  background: linear-gradient(var(--bg) 70%, transparent);
  transition: opacity .35s var(--ease), transform .45s var(--ease);
}
.top-row { display: flex; align-items: center; justify-content: space-between; }
h1 { font-size: 34px; letter-spacing: -0.02em; margin: 0; font-weight: 750; }
.top-actions { display: flex; gap: 10px; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center;
  background: var(--surface-2); transition: transform .25s var(--spring), background .2s;
}
.icon-btn:active { transform: scale(.88); }
.icon-btn.primary { background: var(--text); color: #000; }
.icon-btn.primary svg { stroke-width: 2.6; }

.search {
  display: flex; align-items: center; gap: 8px; margin-top: 14px;
  background: var(--surface); border-radius: 14px; padding: 0 12px; height: 42px;
  border: 1px solid var(--line); transition: border-color .2s, background .2s;
}
.search:focus-within { border-color: rgba(139, 123, 255, .6); background: var(--surface-2); }
.search svg { width: 18px; height: 18px; color: var(--muted); }
.search input { flex: 1; background: none; border: 0; outline: 0; height: 100%; }
.search input::-webkit-search-cancel-button { filter: invert(1) opacity(.5); }

.chips { display: flex; gap: 8px; overflow-x: auto; margin: 12px -20px 0; padding: 0 20px 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; padding: 7px 14px; border-radius: 999px; font-size: 14px; font-weight: 550;
  background: var(--surface); border: 1px solid var(--line); color: var(--muted);
  transition: all .3s var(--ease);
}
.chip.on { background: var(--text); color: #000; border-color: transparent; }
.chip:active { transform: scale(.94); }

body.focused .top { opacity: 0; transform: translateY(-30px); pointer-events: none; }

/* ---------- Pilha de cartões ---------- */
main { padding: 6px 20px calc(var(--safe-bottom) + 40px); position: relative; }
.stack { position: relative; transition: height .55s var(--ease); }

.card {
  position: absolute; left: 0; right: 0; top: 0;
  aspect-ratio: 1.586; max-height: 240px; width: 100%;
  border-radius: var(--radius); padding: 18px 20px; overflow: hidden;
  color: #fff; text-align: left; isolation: isolate;
  background: var(--g);
  box-shadow: 0 -1px 0 rgba(255, 255, 255, .25) inset, 0 18px 40px -12px rgba(0, 0, 0, .7), 0 2px 6px rgba(0, 0, 0, .3);
  transform: translate3d(0, var(--y, 0), 0) scale(var(--s, 1));
  transform-origin: 50% 0;
  transition: transform .62s var(--spring), opacity .4s var(--ease), filter .4s var(--ease);
  will-change: transform;
  animation: card-in .7s var(--spring) backwards;
  animation-delay: calc(var(--i, 0) * 45ms);
}
@keyframes card-in { from { opacity: 0; transform: translate3d(0, calc(var(--y, 0) + 80px), 0) scale(.96); } }
.card::before { /* brilho */
  content: ""; position: absolute; inset: 0; z-index: -1;
  background:
    radial-gradient(120% 80% at 100% 0%, rgba(255, 255, 255, .28), transparent 50%),
    linear-gradient(115deg, transparent 40%, rgba(255, 255, 255, .12) 50%, transparent 60%);
  background-size: 100% 100%, 250% 100%;
  background-position: 0 0, 120% 0;
  transition: background-position 1.2s var(--ease);
}
.card.active::before { background-position: 0 0, -40% 0; }
.card::after { /* textura */
  content: ""; position: absolute; inset: 0; z-index: -1; opacity: .18; mix-blend-mode: overlay;
  background-image: repeating-linear-gradient(45deg, rgba(255,255,255,.18) 0 1px, transparent 1px 7px);
}
.card.dim { filter: brightness(.6) saturate(.8); }
.card.leaving { opacity: 0; transform: translate3d(0, var(--y, 0), 0) scale(.85); }

.card-top { display: flex; align-items: center; gap: 10px; height: 28px; }
.card-icon { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; background: rgba(255, 255, 255, .22); backdrop-filter: blur(6px); }
.card-icon svg { width: 18px; height: 18px; }
.card-title { font-weight: 700; font-size: 17px; letter-spacing: -0.01em; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-badge { font-size: 11px; font-weight: 700; padding: 4px 8px; border-radius: 999px; background: rgba(0, 0, 0, .28); text-transform: uppercase; letter-spacing: .04em; }
.card-badge.warn { background: #ffd34d; color: #3b2a00; }
.card-badge.bad { background: #fff; color: #d0142c; }
.card-pin { width: 14px; height: 14px; opacity: .9; }

.card-body { position: absolute; left: 20px; right: 20px; bottom: 18px; display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; }
.card-label { font-size: 10px; text-transform: uppercase; letter-spacing: .12em; opacity: .7; }
.card-holder { font-size: 18px; font-weight: 650; letter-spacing: -0.01em; }
.card-notes { font-size: 13px; opacity: .8; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 55vw; }
.card-thumb {
  width: 64px; aspect-ratio: .72; border-radius: 6px; flex: none; background: #fff center/cover no-repeat;
  box-shadow: 0 6px 16px rgba(0, 0, 0, .35); transform: rotate(4deg); transition: transform .6s var(--spring);
}
.card.active .card-thumb { transform: rotate(0) scale(1.05); }

/* ---------- Detalhe ---------- */
.detail {
  position: absolute; left: 20px; right: 20px; top: 0;
  opacity: 0; transform: translateY(24px); pointer-events: none;
  transition: opacity .35s var(--ease), transform .55s var(--spring);
}
.detail.show { opacity: 1; transform: none; pointer-events: auto; transition-delay: .12s; }
.actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.action {
  display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 14px 4px;
  border-radius: 18px; background: var(--surface); border: 1px solid var(--line);
  font-size: 12px; font-weight: 600; color: var(--text);
  transition: transform .25s var(--spring), background .2s;
}
.action:active { transform: scale(.92); background: var(--surface-2); }
.action.big { grid-column: 1 / -1; flex-direction: row; justify-content: center; font-size: 16px; padding: 15px; background: var(--text); color: #000; }
.action.danger { color: var(--danger); }
.info { margin-top: 14px; border-radius: 18px; background: var(--surface); border: 1px solid var(--line); overflow: hidden; }
.info div { display: flex; justify-content: space-between; gap: 12px; padding: 12px 16px; font-size: 14px; }
.info div + div { border-top: 1px solid var(--line); }
.info dt { color: var(--muted); }
.info dd { margin: 0; text-align: right; font-weight: 550; word-break: break-word; }
.back-hint { text-align: center; color: var(--muted); font-size: 13px; margin-top: 14px; }

/* ---------- Vazio ---------- */
.empty { text-align: center; padding: 50px 20px 0; animation: fade-up .7s var(--ease); }
.empty h2 { margin: 26px 0 6px; font-size: 22px; }
.empty p { color: var(--muted); margin: 0 auto 26px; max-width: 300px; }
.empty-cards { position: relative; width: 180px; height: 130px; margin: 0 auto; }
.empty-cards i { position: absolute; inset: 0; height: 100px; border-radius: 16px; animation: float 4s ease-in-out infinite; }
.empty-cards i:nth-child(1) { background: linear-gradient(135deg, #7c5cff, #4c2fd6); transform: rotate(-8deg); }
.empty-cards i:nth-child(2) { background: linear-gradient(135deg, #22c1ee, #1867e0); top: 14px; animation-delay: -1.3s; }
.empty-cards i:nth-child(3) { background: linear-gradient(135deg, #ff8a5b, #ff3d77); top: 28px; transform: rotate(6deg); animation-delay: -2.6s; }
@keyframes float { 50% { translate: 0 -8px; } }
@keyframes fade-up { from { opacity: 0; transform: translateY(20px); } }

.btn { height: 50px; padding: 0 24px; white-space: nowrap; border-radius: 16px; font-weight: 650; transition: transform .25s var(--spring); }
.btn.primary { background: var(--text); color: #000; }
.btn:active { transform: scale(.95); }

/* ---------- Bottom sheet ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 40; background: rgba(0, 0, 0, .55);
  opacity: 0; pointer-events: none; transition: opacity .4s var(--ease); backdrop-filter: blur(2px);
}
.sheet-backdrop.show { opacity: 1; pointer-events: auto; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41;
  max-height: 92dvh; display: flex; flex-direction: column;
  background: #17171f; border-radius: 26px 26px 0 0; border-top: 1px solid var(--line);
  transform: translateY(105%); transition: transform .55s var(--ease);
  max-width: 640px; margin: 0 auto;
}
.sheet.show { transform: translateY(var(--drag, 0px)); }
.sheet.dragging { transition: none; }
.grabber { width: 38px; height: 5px; border-radius: 3px; background: rgba(255, 255, 255, .25); margin: 8px auto 0; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 18px 12px; }
.link { color: var(--accent); font-size: 16px; padding: 6px 2px; }
.link.strong { font-weight: 700; }
.sheet-body { overflow-y: auto; padding: 4px 18px calc(var(--safe-bottom) + 24px); }

.preview-card {
  aspect-ratio: 1.9; border-radius: 20px; background: var(--g); position: relative; overflow: hidden;
  display: flex; align-items: flex-end; padding: 16px 18px; gap: 14px; margin-bottom: 14px;
  box-shadow: 0 -1px 0 rgba(255,255,255,.25) inset, 0 14px 30px -12px rgba(0,0,0,.6);
  transition: background .5s var(--ease);
}
.pc-thumb { position: absolute; right: 18px; top: 16px; width: 70px; aspect-ratio: .72; border-radius: 6px; background: rgba(255,255,255,.2) center/cover no-repeat; box-shadow: 0 6px 16px rgba(0,0,0,.3); }
.pc-meta { display: flex; flex-direction: column; }
.pc-cat { font-size: 10px; letter-spacing: .12em; text-transform: uppercase; opacity: .75; }
.pc-title { font-weight: 700; font-size: 19px; }
.pc-holder { opacity: .85; font-size: 14px; }

.file-pick {
  display: flex; align-items: center; justify-content: center; height: 50px; border-radius: 14px;
  border: 1.5px dashed rgba(255, 255, 255, .22); color: var(--muted); font-weight: 600; margin-bottom: 14px;
  transition: border-color .2s, color .2s;
}
.file-pick.has { border-style: solid; border-color: rgba(139, 123, 255, .5); color: var(--text); }
.file-pick input { display: none; }
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin: 0 0 6px 4px; }
.field em { font-style: normal; opacity: .7; }
.field input {
  width: 100%; height: 48px; border-radius: 14px; border: 1px solid var(--line); background: var(--surface);
  padding: 0 14px; outline: 0; transition: border-color .2s, background .2s;
}
.field input:focus { border-color: rgba(139, 123, 255, .6); background: var(--surface-2); }
.field input[type="date"] { -webkit-appearance: none; appearance: none; min-height: 48px; }

.cat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.cat {
  display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 2px; border-radius: 14px;
  background: var(--surface); border: 1px solid var(--line); font-size: 11.5px; color: var(--muted);
  transition: all .3s var(--spring);
}
.cat svg { width: 20px; height: 20px; }
.cat.on { background: var(--text); color: #000; transform: scale(1.04); }
.swatches { display: flex; gap: 10px; flex-wrap: wrap; }
.swatch {
  width: 36px; height: 36px; border-radius: 50%; background: var(--g);
  box-shadow: 0 0 0 0 var(--bg), 0 0 0 0 #fff; transition: box-shadow .3s var(--spring), transform .3s var(--spring);
}
.swatch.on { box-shadow: 0 0 0 3px #17171f, 0 0 0 5px #fff; transform: scale(1.06); }

/* ---------- Visualizador ---------- */
.viewer {
  position: fixed; inset: 0; z-index: 50; background: #050507; display: flex; flex-direction: column;
  transform: translateY(100%); transition: transform .55s var(--ease), border-radius .55s var(--ease);
  border-radius: 28px 28px 0 0;
}
.viewer.show { transform: translateY(var(--drag, 0px)); border-radius: 0; }
.viewer.dragging { transition: none; border-radius: 28px 28px 0 0; }
.viewer-bar {
  display: flex; align-items: center; gap: 12px; padding: calc(var(--safe-top) + 10px) 14px 10px;
  background: rgba(5, 5, 7, .8); backdrop-filter: blur(20px); border-bottom: 1px solid var(--line);
}
.viewer-title { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.viewer-title strong, .viewer-title span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.viewer-title span { font-size: 12px; color: var(--muted); }
.viewer-pages { flex: 1; overflow: auto; padding: 16px 12px calc(var(--safe-bottom) + 30px); -webkit-overflow-scrolling: touch; }
.page {
  width: 100%; margin: 0 auto 14px; background: #fff; border-radius: 6px; overflow: hidden;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .5); opacity: 0; transform: translateY(16px) scale(.98);
  transition: opacity .5s var(--ease), transform .6s var(--spring), width .45s var(--ease);
}
.page.ready { opacity: 1; transform: none; }
.page canvas, .page img { display: block; width: 100%; height: auto; }
.viewer-pages.zoom .page { width: 220%; }
.zoom-hint {
  position: absolute; left: 50%; bottom: calc(var(--safe-bottom) + 24px); translate: -50% 0;
  background: rgba(255, 255, 255, .14); backdrop-filter: blur(16px); padding: 8px 14px; border-radius: 999px;
  font-size: 13px; opacity: 0; transition: opacity .4s; pointer-events: none; white-space: nowrap;
}
.zoom-hint.show { opacity: 1; }

/* ---------- Menu e toast ---------- */
.menu {
  position: fixed; z-index: 30; right: 16px; top: calc(var(--safe-top) + 62px); min-width: 220px;
  background: rgba(30, 30, 40, .85); backdrop-filter: blur(24px); border: 1px solid var(--line);
  border-radius: 16px; overflow: hidden; transform-origin: top right; animation: pop .35s var(--spring);
}
@keyframes pop { from { opacity: 0; transform: scale(.85); } }
.menu button, .menu-file { display: block; width: 100%; text-align: left; padding: 14px 16px; font-size: 15px; cursor: pointer; }
.menu button + *, .menu-file + * { border-top: 1px solid var(--line); }
.menu-file input { display: none; }
.menu-foot { padding: 10px 16px; font-size: 12px; color: var(--muted); }

.toast {
  position: fixed; z-index: 110; left: 50%; bottom: calc(var(--safe-bottom) + 24px);
  transform: translate(-50%, 40px); opacity: 0; transition: all .45s var(--spring);
  background: rgba(255, 255, 255, .92); color: #000; padding: 11px 18px; border-radius: 999px;
  font-weight: 600; font-size: 14px; pointer-events: none; white-space: nowrap;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; }

@media (min-width: 640px) {
  main, .top { max-width: 560px; margin: 0 auto; }
}

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

/* ---------- Bloqueio ---------- */
.lock {
  position: fixed; inset: 0; z-index: 100; display: grid; place-items: center;
  background: radial-gradient(60% 40% at 30% 10%, rgba(124, 92, 255, .35), transparent 70%),
              radial-gradient(50% 40% at 80% 0%, rgba(40, 200, 255, .22), transparent 70%), #08080c;
  padding: calc(var(--safe-top) + 20px) 24px calc(var(--safe-bottom) + 20px);
  opacity: 0; transition: opacity .4s var(--ease);
}
.lock.show { opacity: 1; }
.lock-inner { width: 100%; max-width: 340px; text-align: center; display: flex; flex-direction: column; align-items: center; animation: fade-up .55s var(--ease); }
.lock-icon {
  width: 64px; height: 64px; border-radius: 20px; display: grid; place-items: center; margin-bottom: 18px;
  background: linear-gradient(135deg, #9b7bff, #3b1ea8); box-shadow: 0 12px 30px -8px rgba(124, 92, 255, .6);
}
.lock-icon svg { width: 30px; height: 30px; color: #fff; }
.lock-icon.big { width: 88px; height: 88px; border-radius: 26px; }
.lock-icon.big svg { width: 44px; height: 44px; }
.lock-icon.spin svg { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(.85); opacity: .6; } }
.lock h2 { margin: 0 0 6px; font-size: 22px; letter-spacing: -0.01em; }
.lock-sub { margin: 0; color: var(--muted); font-size: 15px; min-height: 21px; }
.dots { display: flex; gap: 16px; margin: 28px 0 8px; }
.dots i {
  width: 14px; height: 14px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, .55);
  transition: background .15s, transform .3s var(--spring), border-color .2s;
}
.dots i.on { background: #fff; border-color: #fff; transform: scale(1.12); }
.dots.checking i { animation: wave .8s ease-in-out infinite; }
.dots.checking i:nth-child(2) { animation-delay: .08s } .dots.checking i:nth-child(3) { animation-delay: .16s }
.dots.checking i:nth-child(4) { animation-delay: .24s } .dots.checking i:nth-child(5) { animation-delay: .32s }
.dots.checking i:nth-child(6) { animation-delay: .4s }
@keyframes wave { 50% { transform: translateY(-6px); } }
.dots.ok i { background: #3ee0a5; border-color: #3ee0a5; }
.lock-err { color: #ff8a95; font-size: 14px; min-height: 20px; margin: 4px 0 14px; }
.keypad { display: grid; grid-template-columns: repeat(3, 76px); gap: 16px 26px; justify-content: center; }
.key {
  width: 76px; height: 76px; border-radius: 50%; font-size: 30px; font-weight: 400;
  background: rgba(255, 255, 255, .1); backdrop-filter: blur(10px);
  transition: background .25s, transform .2s var(--spring);
}
.key:active { background: rgba(255, 255, 255, .32); transform: scale(.92); transition-duration: 0s; }
.key.fn { background: none; }
.key.fn svg { width: 30px; height: 30px; }
.lock-foot { display: flex; gap: 24px; justify-content: center; margin-top: 22px; min-height: 30px; }
.lock-foot .link { font-size: 15px; color: rgba(255, 255, 255, .7); }
.lock-choices { display: flex; flex-direction: column; gap: 10px; width: 100%; margin-top: 30px; }
.lock-choices .link { color: var(--muted); }
@media (max-height: 680px) {
  .keypad { grid-template-columns: repeat(3, 66px); gap: 12px 22px; }
  .key { width: 66px; height: 66px; font-size: 26px; }
  .lock-icon { display: none; }
}

/* Esconde o conteúdo na troca de apps (miniatura do multitarefa) */
body.privacy main, body.privacy .viewer, body.privacy .sheet { filter: blur(24px); }
