/* ==========================================================================
   Passkey Vault 2.0 design layer (loaded last on every theme view)
   1  Tokens (light + dark)         5  Entry list (table -> cards on small screens)
   2  App shell: sidebar + topbar   6  Detail panel, modals and sheets
   3  Cards, buttons, forms         7  Mobile layout (<= 720px) + tablet (<= 1100px)
   4  Dashboard                     8  PWA: install, offline bar, standalone, safe areas
   ========================================================================== */

/* 1 ── Tokens ─────────────────────────────────────────────────────────── */
:root, :root[data-theme="light"] {
  --bg-primary: #f3f5fb;  --bg-secondary: #ffffff;  --bg-card: #ffffff;
  --bg-input: #f1f4fa;    --bg-hover: #eaeffa;
  --text-primary: #0d1530; --text-secondary: #46526e; --text-muted: #8190ad;
  --accent-rgb: 67, 97, 238;
  --accent-primary: #4361ee; --accent-text: #3451d8; --accent-hover: #3752e0; --accent-active: #2c43c2;
  --accent-subtle: rgba(67, 97, 238, .11); --accent-glow: rgba(67, 97, 238, .30);
  --border-color: #e2e8f4; --border-subtle: #ebeff8; --border-accent: rgba(67, 97, 238, .45);
  --shadow-sm: 0 1px 2px rgba(13, 21, 48, .05);
  --shadow: 0 8px 24px rgba(13, 21, 48, .07);
  --shadow-lg: 0 28px 70px rgba(13, 21, 48, .18);
  --shadow-glow: 0 0 0 4px rgba(67, 97, 238, .18);
  --strength-good: #4361ee;
  --pv-radius: 16px; --pv-radius-sm: 11px;
  --pv-nav-h: 64px;
  --pv-safe-b: env(safe-area-inset-bottom, 0px); --pv-safe-t: env(safe-area-inset-top, 0px);
  --pv-grad: linear-gradient(135deg, #4361ee 0%, #3a86ff 100%);
}
:root[data-theme="dark"] {
  --bg-primary: #0a1020;  --bg-secondary: #0e1730;  --bg-card: #121d3a;
  --bg-input: #0b1328;    --bg-hover: #1a2749;
  --text-primary: #e8edfa; --text-secondary: #a6b4d0; --text-muted: #7384a6;
  --accent-rgb: 124, 156, 255;
  --accent-primary: #5b7cff; --accent-text: #8ba6ff; --accent-hover: #7490ff; --accent-active: #4a69ec;
  --accent-subtle: rgba(124, 156, 255, .16); --accent-glow: rgba(91, 124, 255, .38);
  --border-color: #213158; --border-subtle: #182446; --border-accent: rgba(124, 156, 255, .5);
  --shadow: 0 10px 28px rgba(0, 0, 0, .35); --shadow-lg: 0 30px 80px rgba(0, 0, 0, .55);
  --pv-grad: linear-gradient(135deg, #5b7cff 0%, #3a86ff 100%);
}
html { -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }
body { font-feature-settings: "cv11", "ss01"; -webkit-font-smoothing: antialiased; }
:focus-visible { outline: 3px solid rgba(var(--accent-rgb), .55); outline-offset: 2px; border-radius: 8px; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; padding: 0; }

/* 2 ── App shell ──────────────────────────────────────────────────────── */
.app-layout { background: var(--bg-primary); }
.app-sidebar { background: var(--bg-secondary); border-right: 1px solid var(--border-color); }
.SB-logo-icon, .sidebar-logo-icon { background: var(--pv-grad); box-shadow: 0 8px 18px var(--accent-glow); border-radius: 13px; }
.SB-item, .sidebar-item { border-radius: 12px; font-weight: 550; transition: background .15s, color .15s; }
.SB-item:hover, .sidebar-item:hover { background: var(--bg-hover); }
.SB-item.is-active, .sidebar-item.is-active, .sidebar-item.active { background: var(--accent-subtle); color: var(--accent-text); box-shadow: inset 3px 0 0 var(--accent-primary); }
.SB-secure { border-radius: var(--pv-radius); background: var(--bg-input); border: 1px solid var(--border-color); }
.HF-bar, .app-topbar { background: color-mix(in srgb, var(--bg-secondary) 86%, transparent); backdrop-filter: saturate(160%) blur(14px); -webkit-backdrop-filter: saturate(160%) blur(14px); border-bottom: 1px solid var(--border-color); }
.HF-search .search-input, .search-input { border-radius: 14px; background: var(--bg-input); border: 1px solid transparent; transition: border-color .15s, box-shadow .15s, background .15s; }
.HF-search .search-input:focus, .search-input:focus { background: var(--bg-card); border-color: var(--accent-primary); box-shadow: var(--shadow-glow); }
.HF-avatar { background: var(--pv-grad); }

/* 3 ── Cards, buttons, forms ──────────────────────────────────────────── */
.btn { border-radius: var(--pv-radius-sm); font-weight: 600; letter-spacing: .005em; transition: transform .08s, background .15s, box-shadow .15s, border-color .15s; }
.btn:active { transform: scale(.975); }
.btn-primary { background: var(--pv-grad); border-color: transparent; box-shadow: 0 6px 16px var(--accent-glow); }
.btn-primary:hover { filter: brightness(1.06); background: var(--pv-grad); }
.btn-secondary { background: var(--bg-card); border: 1px solid var(--border-color); }
.btn-secondary:hover { background: var(--bg-hover); }
.form-input, .form-select, input[type="text"], input[type="email"], input[type="password"], input[type="url"], input[type="search"], textarea, select { border-radius: var(--pv-radius-sm); }
.form-input:focus, textarea:focus, select:focus { border-color: var(--accent-primary); box-shadow: var(--shadow-glow); }
.settings-item { border-radius: 14px; }
.pv-switch { position: relative; display: inline-block; flex: none; width: 48px; height: 28px; }
.pv-switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; z-index: 1; }
.pv-switch-ui { position: absolute; inset: 0; border-radius: 99px; background: var(--border-color); transition: background .2s; }
.pv-switch-ui::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 2px 6px rgba(0, 0, 0, .25); transition: transform .2s; }
.pv-switch input:checked + .pv-switch-ui { background: var(--accent-primary); }
.pv-switch input:checked + .pv-switch-ui::after { transform: translateX(20px); }
.pv-switch input:focus-visible + .pv-switch-ui { outline: 3px solid rgba(var(--accent-rgb), .55); outline-offset: 2px; }

/* 4 ── Dashboard ──────────────────────────────────────────────────────── */
.CM-stat, .CM-stat-card, .EL-card, .entry-list-card { border-radius: 18px; border: 1px solid var(--border-color); box-shadow: var(--shadow-sm); }
.CM-greeting { letter-spacing: -.02em; }

/* 5 ── Entry list ─────────────────────────────────────────────────────── */
.EL-row { transition: background .12s; }
.EL-row:hover { background: var(--bg-hover); }
.EL-tab.is-active { color: var(--accent-text); border-color: var(--accent-primary); }

/* 6 ── Detail panel, modals ───────────────────────────────────────────── */
.DP-panel { background: var(--bg-secondary); border-left: 1px solid var(--border-color); box-shadow: var(--shadow-lg); }
.modal-content { border-radius: 22px; border: 1px solid var(--border-color); box-shadow: var(--shadow-lg); }
.modal-overlay { backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
.toast { border-radius: 14px; box-shadow: var(--shadow-lg); }
.settings-panel { background: var(--bg-secondary); }

/* 8 ── PWA bits ───────────────────────────────────────────────────────── */
#pv-offline-bar { position: fixed; left: 0; right: 0; top: 0; z-index: 3000; padding: calc(8px + var(--pv-safe-t)) 14px 8px; text-align: center; font-size: 13px; font-weight: 600; background: #b45309; color: #fff; }
html.pv-offline .app-layout { padding-top: 34px; }
html.pv-readonly #btn-add-entry, html.pv-readonly #btn-new-menu, html.pv-readonly #mnav-add, html.pv-readonly .DP-actions .btn-danger { opacity: .45; }
.pv-sheet { position: fixed; inset: 0; z-index: 4000; display: flex; align-items: flex-end; justify-content: center; background: rgba(8, 12, 28, .55); backdrop-filter: blur(4px); }
.pv-sheet-card { width: min(440px, 100%); background: var(--bg-card); color: var(--text-primary); border-radius: 22px 22px 0 0; padding: 24px 22px calc(22px + var(--pv-safe-b)); box-shadow: var(--shadow-lg); animation: pv-up .22s ease-out; }
.pv-sheet-card h3 { margin: 0 0 8px; font-size: 18px; } .pv-sheet-card p { margin: 0 0 18px; color: var(--text-secondary); }
@keyframes pv-up { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
html.is-standalone body { overscroll-behavior-y: none; }
html.is-standalone .HF-bar { padding-top: var(--pv-safe-t); }

@media (max-width: 900px) { .mobile-menu-btn { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 14px; } }

/* 7a ── Tablet (<= 1100px): leaner list, 2x2 stats ───────────────────── */
@media (max-width: 1100px) {
  .EL-thead, .EL-row { grid-template-columns: minmax(180px, 1.6fr) minmax(90px, .9fr) minmax(130px, 1.1fr) 40px; }
  .EL-thead > :nth-child(3), .EL-thead > :nth-child(5), .EL-thead > :nth-child(6), .EL-thead > :nth-child(7),
  .EL-row .EL-email, .EL-row .EL-totp, .EL-row .EL-hlth, .EL-row .EL-when { display: none; }
  .CM-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* 7b ── Phone (<= 720px) ─────────────────────────────────────────────── */
@media (max-width: 720px) {
  :root { --pv-nav-h: 64px; }
  html, body { overscroll-behavior-y: none; }
  /* big, thumb-friendly controls; 16px inputs stop iOS from zooming on focus */
  input, select, textarea, .form-input, .search-input { font-size: 16px !important; }
  .btn, .EL-ibtn, .DP-icon-btn, .btn-icon { min-height: 44px; min-width: 44px; }
  .btn-sm { min-height: 40px; }

  /* top bar: menu, search, add */
  .HF-bar { padding: calc(8px + var(--pv-safe-t)) 12px 8px; gap: 8px; height: auto; min-height: 56px; }
  .HF-actions { gap: 6px; }
  .HF-actions > :not(.HF-split) { display: none !important; }
  .HF-split .HF-caret, .HF-split .HF-menu { display: none; }
  .HF-split { display: none; } /* the centre button in the bottom bar adds entries */
  .HF-search { flex: 1; min-width: 0; }
  .HF-search .search-input { height: 44px; border-radius: 14px; }
  .HF-kbd { display: none; }
  .mobile-menu-btn { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 14px; }

  /* content */
  .app-content .content-wrap { padding: 14px 14px calc(var(--pv-nav-h) + var(--pv-safe-b) + 24px); }
  .CM-hero { flex-direction: column; align-items: flex-start; gap: 4px; }
  .CM-greeting { font-size: 24px; }
  .CM-hero-meta { display: none; }
  .CM-stats { display: flex; overflow-x: auto; scroll-snap-type: x mandatory; gap: 10px; margin-inline: -14px; padding: 2px 14px 8px; scrollbar-width: none; }
  .CM-stats::-webkit-scrollbar { display: none; }
  .CM-stat { min-width: 168px; scroll-snap-align: start; padding: 14px; }
  .CM-stat-icon { display: none; }

  .EL-tabs { overflow-x: auto; scrollbar-width: none; }

  /* detail panel: full-screen sheet */
  .DP-panel { width: 100% !important; border-left: 0; z-index: 1000; animation: pv-up .22s ease-out; padding-top: var(--pv-safe-t); }
  .DP-banner { display: none; }
  .DP-actions { position: sticky; bottom: 0; background: var(--bg-secondary); padding: 12px 14px calc(12px + var(--pv-safe-b)); border-top: 1px solid var(--border-color); }
  .DP-tabs { overflow-x: auto; scrollbar-width: none; }

  /* modals become bottom sheets */
  .modal-overlay { align-items: flex-end; padding: 0; }
  .modal-content { width: 100%; max-width: 100% !important; max-height: 92dvh; border-radius: 24px 24px 0 0; border-bottom: 0; animation: pv-up .22s ease-out; }
  .modal-content::before { content: ""; display: block; width: 40px; height: 4px; border-radius: 4px; background: var(--border-color); margin: 8px auto 0; }
  .modal-header { padding-top: 10px; }
  .modal-body { -webkit-overflow-scrolling: touch; }
  .modal-footer { position: sticky; bottom: 0; background: var(--bg-card); padding-bottom: calc(14px + var(--pv-safe-b)); }
  .settings-panel { width: 100%; right: -100%; height: 100dvh; padding-top: var(--pv-safe-t); box-shadow: none; }
  .settings-panel.open { right: 0; box-shadow: var(--shadow-lg); }

  /* bottom navigation */
  .mobile-bottom-nav { height: calc(var(--pv-nav-h) + var(--pv-safe-b)); padding-bottom: var(--pv-safe-b); background: color-mix(in srgb, var(--bg-secondary) 90%, transparent); box-shadow: 0 -8px 28px rgba(13, 21, 48, .10); }
  .mobile-nav-btn { height: var(--pv-nav-h); min-width: 56px; color: var(--text-muted); }
  .mobile-nav-btn.is-active { color: var(--accent-text); }
  .mobile-nav-add { flex: 0 0 56px; width: 56px; height: 56px; background: var(--pv-grad); transform: translateY(-14px); box-shadow: 0 10px 24px var(--accent-glow); }
  .app-main { padding-bottom: 0; }
  .toast-container { left: 12px; right: 12px; bottom: calc(var(--pv-nav-h) + var(--pv-safe-b) + 14px); }
  .SB-root { width: min(86vw, 320px); padding-top: var(--pv-safe-t); }
}


/* 7c ── Entry list in a narrow container (phones AND tablets): one tidy row per item ── */
@container (max-width: 860px) {
  .entry-grid.EL-list { display: block; padding: 0; gap: 0; }
  .EL-row, .EL-row.entry-card { border: 0; border-bottom: 1px solid var(--border-subtle); border-radius: 0; background: transparent; box-shadow: none; margin: 0; }
  .EL-row:active { background: var(--bg-hover); }
  .EL-thead { display: none !important; }
  .EL-row { grid-template-columns: minmax(0, 1fr) auto auto; grid-template-areas: "name pass more" "user pass more"; gap: 0 6px; padding: 10px 12px; min-height: 68px; border-bottom: 1px solid var(--border-subtle); }
  .EL-row .EL-name { grid-area: name; }
  .EL-row .EL-user { grid-area: user; display: block !important; padding-left: 52px; margin-top: -2px; font-size: 13px; color: var(--text-muted); }
  .EL-row .EL-user::before, .EL-row .EL-field::before { display: none !important; }
  .EL-row .EL-user .EL-ibtn { display: none; }
  .EL-row .EL-pass { grid-area: pass; display: flex !important; align-items: center; justify-content: flex-end; }
  .EL-row .EL-pass .EL-secret, .EL-row .EL-pass .EL-eye, .EL-row .EL-pass .EL-muted { display: none; }
  .EL-row .EL-more { grid-area: more; }
  .EL-row .EL-email, .EL-row .EL-totp, .EL-row .EL-hlth, .EL-row .EL-when { display: none !important; }
  .EL-pills { display: none; }
  .EL-name-text { min-width: 0; }
  .EL-row { min-height: 0; padding: 8px 12px; }
  .EL-row .EL-name { align-self: end; gap: 12px; }
  .EL-row .EL-user { align-self: start; margin-top: 0; line-height: 1.2; padding-bottom: 2px; }
  .EL-row .EL-star, .EL-row .EL-dots { min-width: 32px; min-height: 32px; }
  .EL-row .EL-pass .EL-ibtn { min-width: 44px; min-height: 44px; }
  .EL-site { max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
  .EL-pager-info { display: none; }
}

/* very small phones */
@media (max-width: 360px) {
  .CM-stat { min-width: 148px; }
  .mobile-nav-btn { min-width: 48px; }
}

/* coarse pointers (any size): comfortable hit areas, no hover-only tricks */
@media (pointer: coarse) {
  .SB-item, .sidebar-item { min-height: 46px; }
  .EL-ibtn, .EL-dots, .EL-star { min-width: 40px; min-height: 40px; }
}

/* landscape phones: shorter chrome */
@media (max-height: 480px) and (orientation: landscape) {
  .mobile-bottom-nav { --pv-nav-h: 48px; }
  .modal-content { max-height: 100dvh; border-radius: 0; }
}

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

/* 9 ── Auth + public pages ───────────────────────────────────────────── */
.auth-aside { background: linear-gradient(150deg, #24359a 0%, #4361ee 56%, #3a86ff 100%) !important; }
.auth-card { border-radius: 24px; box-shadow: var(--shadow-lg); }
.pk-logo img { border-radius: 10px; }
[hidden] { display: none !important; }
@media (max-width: 860px) {
  .centered-layout { min-height: 100dvh; padding: calc(16px + var(--pv-safe-t)) 16px calc(16px + var(--pv-safe-b)); }
  .auth-card { width: 100%; max-width: 440px; }
}

/* Website icons: the real logo sits on a light tile so it reads in light and dark themes. */
.entry-favicon, .EL-logo, .DP-logo { position: relative; box-sizing: border-box; overflow: hidden; }
.fav-img { position: absolute; inset: 18%; width: 64%; height: 64%; object-fit: contain; }
.fav-img[hidden] { display: none; }
.has-img { background: #fff !important; box-shadow: inset 0 0 0 1px rgba(15, 23, 42, .12); }
.has-img .fav-l { visibility: hidden; }

/* Chrome extension: sign-in prompt and install guide */
.ext-prompt { position: fixed; right: 18px; bottom: 18px; z-index: 9000; width: min(380px, calc(100vw - 36px)); background: var(--bg-card, #fff); color: var(--text, #0b1220); border: 1px solid var(--border, #dde4f0); border-radius: 14px; padding: 16px; box-shadow: 0 14px 44px rgba(0, 0, 0, .35); }
.ext-prompt p { margin: 6px 0 12px; font-size: 14px; opacity: .85; }
.ext-prompt-row { display: flex; gap: 8px; flex-wrap: wrap; }
.ext-guide-back { position: fixed; inset: 0; z-index: 9100; background: rgba(2, 6, 20, .6); display: grid; place-items: center; padding: 16px; }
.ext-guide { width: min(520px, 100%); max-height: 90vh; overflow: auto; background: var(--bg-card, #fff); color: var(--text, #0b1220); border: 1px solid var(--border, #dde4f0); border-radius: 16px; padding: 20px; }
.ext-guide-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.ext-guide-head h3 { margin: 0; font-size: 18px; }
.ext-steps { list-style: none; padding: 0; margin: 12px 0; display: grid; gap: 10px; }
.ext-steps li { display: block; line-height: 2; }
.ext-steps li .btn { vertical-align: middle; margin: 0 2px; }
.ext-steps code { background: rgba(127, 140, 170, .18); padding: 2px 7px; border-radius: 6px; }
.ext-note { font-size: 12.5px; opacity: .7; margin: 8px 0 0; }
.settings-item-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
