/* HVault PWA — dark theme mirroring the extension popup, mobile-first. */
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* Zoom lock. iOS honours user-scalable=no only in standalone PWA mode, so the
   real defence is: every text control at >= 16px (below that Safari zooms on
   focus) plus touch-action: manipulation to kill double-tap zoom. */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; touch-action: manipulation; }
body { touch-action: manipulation; }
input, select, textarea, button { touch-action: manipulation; }
input, select, textarea { font-size: 16px; }

:root {
  --bg: #0a0a0f;
  --card: #141420;
  --card-2: #1b1b2a;
  --card-3: #232337;
  --border: rgba(255,255,255,.07);
  --border-strong: rgba(255,255,255,.12);
  --text: #e8e8f0;
  --muted: #8b8ba3;
  --accent: #6c5ce7;
  --accent-2: #8d7bf7;
  --accent-glow: rgba(108,92,231,.45);
  --danger: #ff5c7a;
  --success: #3ecf8e;
  --radius: 14px;
  --radius-sm: 10px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, system-ui, sans-serif;
  --mono: 'SF Mono', ui-monospace, Menlo, Consolas, monospace;
}

html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.bg-glow {
  position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background:
    radial-gradient(520px 300px at 50% -8%, rgba(108,92,231,.14), transparent 65%),
    radial-gradient(380px 240px at 108% 108%, rgba(108,92,231,.07), transparent 60%);
}
.hidden { display: none !important; }
.mono { font-family: var(--mono); }
.screen { position: relative; z-index: 1; }

.glass {
  background: rgba(20,20,32,.78);
  -webkit-backdrop-filter: blur(18px) saturate(150%);
  backdrop-filter: blur(18px) saturate(150%);
  border: 1px solid var(--border);
}

/* ── buttons ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 12px 18px; border: none; border-radius: var(--radius-sm);
  font-size: 15px; font-weight: 600; cursor: pointer; color: var(--text);
  background: var(--card-2);
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .45; }
.btn-primary { background: linear-gradient(135deg, #6c5ce7, #8d7bf7); color: #fff; box-shadow: 0 4px 18px var(--accent-glow); }
.btn-block { width: 100%; margin-top: 14px; }
.icon-btn {
  min-width: 44px; min-height: 44px;
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent; border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text);
  font-size: 20px; cursor: pointer;
}
.icon-btn:active { background: var(--card-2); }

/* ── inputs ── */
.input-wrap { margin-top: 12px; }
.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 44px; }
.in-btn {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  width: 32px; height: 32px; border: 0; border-radius: 8px; cursor: pointer;
  background: transparent; color: var(--muted); font-size: 15px; line-height: 1;
}
.in-btn:hover { color: #fff; background: rgba(255,255,255,.08); }
.err { white-space: pre-line; }
input, select, textarea {
  width: 100%; min-height: 48px;
  background: var(--card-2); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  padding: 12px 14px; font-size: 16px; font-family: inherit;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(108,92,231,.2); }
input::placeholder { color: #5f5f74; }

/* ── lock screen ── */
.lock-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.lock-card { width: 100%; max-width: 420px; border-radius: var(--radius); padding: 26px 22px 20px; text-align: center; }
.logo { font-size: 40px; }
.lock-card h1 { font-size: 24px; margin-top: 6px; letter-spacing: .01em; }
.sub { color: var(--muted); font-size: 13px; margin-bottom: 8px; }
.foot { color: var(--muted); font-size: 12px; margin-top: 14px; }
.err { color: var(--danger); font-size: 13px; min-height: 20px; margin-top: 10px; }
.hint { color: var(--muted); font-size: 12px; margin-top: 8px; text-align: left; }
details { margin-top: 14px; text-align: left; }
summary { cursor: pointer; color: var(--muted); font-size: 13px; padding: 10px 0; min-height: 44px; display: flex; align-items: center; }
code { font-family: var(--mono); font-size: 11px; }

/* ── topbar ── */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-left: 0; border-right: 0; border-top: 0;
}
.brand { font-weight: 700; font-size: 17px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.actions { display: flex; gap: 8px; }

.searchbar { padding: 12px; }
.meta-line { padding: 0 14px 8px; color: var(--muted); font-size: 12px; }

/* ── list ── */
.entry-list { list-style: none; padding: 0 12px 40px; }
.entry {
  display: flex; align-items: center; gap: 12px;
  min-height: 60px; padding: 12px 14px; margin-bottom: 8px;
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); cursor: pointer;
}
.entry:active { background: var(--card-2); }
/* Squircle avatar, Apple/Google flavour. Colour is derived locally from the
   title (see avatarPalette in app.js) — no favicon, no external request. */
.avatar {
  position: relative;
  width: 42px; height: 42px; flex: none;
  border-radius: 13px;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 18px; line-height: 1;
  letter-spacing: .01em;
  box-shadow: 0 2px 8px rgba(0,0,0,.35), inset 0 1px 0 rgba(255,255,255,.18);
  text-shadow: 0 1px 2px rgba(0,0,0,.35);
  overflow: visible;
}
/* TOTP entries get their own marker so a code is never mistaken for a login. */
.avatar.is-totp::after {
  content: '⏲';
  position: absolute; right: -4px; bottom: -4px;
  width: 18px; height: 18px; border-radius: 50%;
  background: #10121c; color: #ffd479;
  font-size: 10px; line-height: 18px; text-align: center;
  border: 1px solid rgba(255,255,255,.16);
  text-shadow: none;
}
.entry-main { min-width: 0; flex: 1 1 auto; overflow: hidden; }
.entry-title { font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry-user { color: var(--muted); font-size: 13px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chev { color: var(--muted); font-size: 20px; }
.empty { color: var(--muted); text-align: center; padding: 40px 20px; }

/* ── detail ── */
.detail-body { padding: 14px 12px 60px; }
.field {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 14px; margin-bottom: 10px;
}
.field-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; }
.field-value { font-family: var(--mono); font-size: 15px; word-break: break-all; margin: 6px 0 10px; }
.field-row { display: flex; gap: 8px; flex-wrap: wrap; }
.field-row .btn { flex: 1 1 44%; min-height: 44px; font-size: 14px; }
.totp-code { font-family: var(--mono); font-size: 28px; letter-spacing: .18em; color: var(--accent-2); }
.ring { display: inline-block; width: 30px; height: 30px; vertical-align: middle; margin-left: 10px; }
.ring circle { fill: none; stroke-width: 3; }
.ring .bgc { stroke: var(--card-3); }
.ring .fg { stroke: var(--accent); stroke-linecap: round; transform: rotate(-90deg); transform-origin: 50% 50%; }

/* ── toast ── */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%); z-index: 20;
  background: rgba(20,20,32,.95); border: 1px solid var(--border-strong);
  border-radius: 999px; padding: 12px 20px; font-size: 14px;
  box-shadow: 0 10px 30px rgba(0,0,0,.5); max-width: 90vw; text-align: center;
}

@media (min-width: 640px) {
  #listScreen, #detailScreen { max-width: 560px; margin: 0 auto; }
}

/* Secret Key disclosure toggle (v2.6.0) */
.link-toggle {
  display: block;
  margin: -2px 0 10px;
  padding: 0;
  background: none;
  border: 0;
  color: var(--accent, #F97316);
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
  text-align: left;
}
.link-toggle:hover { text-decoration: underline; }

/* ── edit form (v2 write support) ── */
.fin {
  width: 100%;
  box-sizing: border-box;
  margin-top: 6px;
  padding: 11px 12px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, .10);
  background: rgba(255, 255, 255, .04);
  color: var(--fg, #e8e8f0);
  font-size: 16px;   /* < 16px makes iOS Safari zoom on focus */
  font-family: inherit;
  resize: vertical;
}
.fin:focus { outline: none; border-color: #6c5ce7; background: rgba(108, 92, 231, .08); }
.fin.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .04em; }
label.field { display: block; }
label.field .field-label { display: block; }
.seg { display: flex; gap: 8px; margin-top: 6px; }
.seg-btn { flex: 1; }
.seg-btn.active { background: #6c5ce7; border-color: #6c5ce7; color: #fff; }
.sync-dot { font-size: 12px; opacity: .7; margin-left: 6px; }

/* ── settings / scan (batch 2) ── */
.field-sub {
  font-size: 13px;
  line-height: 1.45;
  color: var(--muted, #9aa0b4);
  margin: 4px 0 8px;
}
.btn-danger {
  background: rgba(255, 92, 122, .12);
  border-color: rgba(255, 92, 122, .45);
  color: #ff8ea3;
}
.warn {
  font-size: 13px;
  line-height: 1.5;
  border: 1px solid rgba(240, 180, 40, .45);
  background: rgba(240, 180, 40, .10);
  color: #ffd479;
  border-radius: 10px;
  padding: 10px 12px;
  margin: 8px 0;
}
/* ── full-screen QR scanner overlay ── */
.scan-overlay {
  position: fixed; inset: 0; z-index: 60;
  background: #000;
  overflow: hidden;
}
#scanVideo {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  background: #000;
}
/* Dim everything except the sighting square (centred 70vmin box). */
.scan-shade {
  position: absolute; inset: 0; pointer-events: none;
  background: rgba(0,0,0,.62);
  -webkit-mask:
    linear-gradient(#000, #000),
    radial-gradient(circle, #000 0 0) center / min(70vw, 300px) min(70vw, 300px) no-repeat;
  -webkit-mask-composite: xor;
  mask:
    linear-gradient(#000, #000),
    radial-gradient(circle, #000 0 0) center / min(70vw, 300px) min(70vw, 300px) no-repeat;
  mask-composite: exclude;
}
.scan-frame {
  position: absolute; top: 50%; left: 50%;
  width: min(70vw, 300px); height: min(70vw, 300px);
  transform: translate(-50%, -50%);
  pointer-events: none;
}
.scan-frame .c { position: absolute; width: 34px; height: 34px; border: 3px solid #fff; border-radius: 4px; }
.scan-frame .tl { top: 0; left: 0; border-right: 0; border-bottom: 0; border-top-left-radius: 14px; }
.scan-frame .tr { top: 0; right: 0; border-left: 0; border-bottom: 0; border-top-right-radius: 14px; }
.scan-frame .bl { bottom: 0; left: 0; border-right: 0; border-top: 0; border-bottom-left-radius: 14px; }
.scan-frame .br { bottom: 0; right: 0; border-left: 0; border-top: 0; border-bottom-right-radius: 14px; }
.scan-top {
  position: absolute; left: 0; right: 0;
  top: calc(env(safe-area-inset-top) + 10px);
  display: flex; align-items: center; gap: 12px;
  padding: 0 calc(env(safe-area-inset-left) + 14px) 0 calc(env(safe-area-inset-right) + 14px);
}
.scan-title { flex: 1; min-width: 0; color: #fff; font-weight: 700; font-size: 16px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  text-shadow: 0 1px 6px rgba(0,0,0,.8); }
.scan-close {
  width: 44px; height: 44px; flex: none;
  border-radius: 50%; border: 1px solid rgba(255,255,255,.25);
  background: rgba(0,0,0,.55); color: #fff; font-size: 20px; cursor: pointer;
}
.scan-status {
  position: absolute; left: 50%; transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom) + 28px);
  max-width: 86vw; text-align: center;
  background: rgba(0,0,0,.6); border: 1px solid rgba(255,255,255,.16);
  border-radius: 999px; padding: 10px 18px;
  color: #fff; font-size: 14px; line-height: 1.4;
}
#scanCanvas { display: none; }

/* ── confirm dialog ── */
.confirm-overlay {
  position: fixed; inset: 0; z-index: 70;
  display: flex; align-items: center; justify-content: center;
  padding: 20px; background: rgba(0,0,0,.6);
}
.confirm-card {
  width: 100%; max-width: 380px;
  border-radius: var(--radius); padding: 18px 18px 14px;
}
.confirm-title { font-weight: 700; font-size: 17px; margin-bottom: 6px; }
.confirm-msg { color: var(--muted); font-size: 14px; line-height: 1.5; margin-bottom: 14px; white-space: pre-line; }

/* ═══ Batch 4: boot-failure screen, update banner, pull-to-refresh, FAB ═══ */

/* ── boot failure (the white-page backstop) ── */
.boot-fail {
  position: fixed; inset: 0; z-index: 9000;
  display: flex; align-items: center; justify-content: center;
  padding: calc(env(safe-area-inset-top) + 20px) 20px calc(env(safe-area-inset-bottom) + 20px);
  background: #0a0a0f;
}
.boot-fail.hidden { display: none; }
.boot-fail-card { max-width: 380px; width: 100%; text-align: center; padding: 26px 22px; border-radius: 20px; }
.boot-fail-card h2 { margin: 10px 0 8px; font-size: 20px; }
.boot-fail-msg { color: #ffb4a8; font-size: 13px; word-break: break-word; margin-bottom: 10px; }

/* ── update banner ── */
.update-bar {
  position: fixed; z-index: 8000;
  left: calc(env(safe-area-inset-left) + 10px);
  right: calc(env(safe-area-inset-right) + 10px);
  top: calc(env(safe-area-inset-top) + 10px);
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 14px;
  background: rgba(24,26,40,.94); border: 1px solid rgba(255,255,255,.14);
  backdrop-filter: blur(12px);
  box-shadow: 0 10px 30px rgba(0,0,0,.45);
  animation: updateIn .28s cubic-bezier(.2,.9,.3,1);
}
.update-bar.hidden { display: none; }
.update-msg { flex: 1 1 auto; font-size: 13px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.btn-sm { padding: 6px 12px; font-size: 13px; min-height: 0; }
@keyframes updateIn { from { transform: translateY(-14px); opacity: 0 } to { transform: none; opacity: 1 } }

/* ── pull-to-refresh ── */
.ptr {
  position: fixed; z-index: 60; left: 50%;
  top: calc(env(safe-area-inset-top) + 6px);
  width: 34px; height: 34px; margin-left: -17px;
  border-radius: 50%;
  background: rgba(24,26,40,.92); border: 1px solid rgba(255,255,255,.14);
  display: flex; align-items: center; justify-content: center;
  opacity: 0; transform: translateY(-40px) scale(.8); pointer-events: none;
}
.ptr-spinner {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.25); border-top-color: #7aa2ff;
}
.ptr.is-armed .ptr-spinner { border-top-color: #6ee7b7; }
.ptr.is-busy { opacity: 1 !important; transform: translateY(14px) scale(1) !important; transition: all .2s ease; }
.ptr.is-busy .ptr-spinner { animation: ptrSpin .7s linear infinite; }
.ptr.is-done { transition: all .25s ease; opacity: 0; transform: translateY(-40px) scale(.8); }
@keyframes ptrSpin { to { transform: rotate(360deg) } }

/* ── FAB (Google-Authenticator style, bottom-left) ── */
.fab-wrap {
  position: fixed; z-index: 70;
  left: calc(env(safe-area-inset-left) + 18px);
  bottom: calc(env(safe-area-inset-bottom) + 20px);
  display: flex; flex-direction: column; align-items: flex-start; gap: 12px;
}
.fab {
  width: 58px; height: 58px; border-radius: 50%;
  border: none; cursor: pointer;
  background: linear-gradient(145deg, #6f8dff, #4059d6);
  color: #fff; font-size: 30px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 8px 24px rgba(50,70,190,.45), inset 0 1px 0 rgba(255,255,255,.25);
  transition: transform .22s cubic-bezier(.2,.9,.3,1), box-shadow .2s ease;
}
.fab:active { transform: scale(.94); }
.fab-plus { display: block; transition: transform .28s cubic-bezier(.2,.9,.3,1); }
.fab-wrap.open .fab-plus { transform: rotate(45deg); }
.fab-wrap.open .fab { box-shadow: 0 10px 30px rgba(50,70,190,.6); }

.fab-menu { display: flex; flex-direction: column; align-items: flex-start; gap: 10px; }
.fab-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 14px 9px 12px; border-radius: 999px;
  background: rgba(28,30,46,.95); border: 1px solid rgba(255,255,255,.14);
  color: #eef; font-size: 14px; font-weight: 600;
  cursor: pointer; white-space: nowrap;
  box-shadow: 0 6px 18px rgba(0,0,0,.4);
  opacity: 0; transform: translateY(14px) scale(.9);
  pointer-events: none;
  transition: opacity .2s ease, transform .24s cubic-bezier(.2,.9,.3,1);
}
.fab-item-icon { font-size: 17px; }
.fab-wrap.open .fab-item { opacity: 1; transform: none; pointer-events: auto; }
/* stagger: the item nearest the button leads */
.fab-wrap.open .fab-item:nth-child(2) { transition-delay: .03s; }
.fab-wrap.open .fab-item:nth-child(1) { transition-delay: .09s; }

.fab-backdrop {
  position: fixed; inset: 0; z-index: 65;
  background: rgba(6,7,14,.55);
  backdrop-filter: blur(3px);
  animation: fabFade .22s ease;
}
.fab-backdrop.hidden { display: none; }
@keyframes fabFade { from { opacity: 0 } to { opacity: 1 } }

/* Avatar gradient is set inline from the palette in app.js. */
@media (prefers-reduced-motion: reduce) {
  .fab-plus, .fab-item, .update-bar, .ptr { transition: none !important; animation: none !important; }
}
