/* =================================================================
   FamilyPhotoVault — app.css
   Theme tokens + Bootstrap 5 overrides + component polish.
   Dark is the default; html[data-bs-theme="light"] for the light variant.
   ================================================================= */

/* --- Tokens ------------------------------------------------------- */
:root,
html[data-bs-theme="dark"] {
    --fpv-bg: #0f1218;
    --fpv-bg-elev: #141821;
    --fpv-surface: #1b1f29;
    --fpv-surface-raised: #242939;
    --fpv-surface-hover: #2a3042;
    --fpv-border: #2b3142;
    --fpv-border-strong: #3b4258;
    --fpv-text: #e8eaef;
    --fpv-text-dim: #b4b9c7;
    --fpv-muted: #8b92a5;
    --fpv-accent: #6b8afd;
    --fpv-accent-hover: #829afd;
    --fpv-accent-soft: rgba(107, 138, 253, 0.14);
    --fpv-danger: #ff6b6b;
    --fpv-danger-soft: rgba(255, 107, 107, 0.14);
    --fpv-success: #5ec886;
    --fpv-success-soft: rgba(94, 200, 134, 0.14);
    --fpv-warning: #f0b429;
    --fpv-warning-soft: rgba(240, 180, 41, 0.14);

    --shadow-1: 0 1px 2px rgba(0,0,0,0.24), 0 1px 4px rgba(0,0,0,0.16);
    --shadow-2: 0 4px 14px rgba(0,0,0,0.36);
    --shadow-3: 0 12px 40px rgba(0,0,0,0.52);

    --scrollbar-thumb: #303648;
    --scrollbar-thumb-hover: #414a66;
}

html[data-bs-theme="light"] {
    --fpv-bg: #f5f7fa;
    --fpv-bg-elev: #ffffff;
    --fpv-surface: #ffffff;
    --fpv-surface-raised: #f0f3f7;
    --fpv-surface-hover: #e7ebf2;
    --fpv-border: #d8dde5;
    --fpv-border-strong: #bcc4d1;
    --fpv-text: #11141a;
    --fpv-text-dim: #3f475a;
    --fpv-muted: #6c7485;
    --fpv-accent: #3d5bdb;
    --fpv-accent-hover: #2c48c0;
    --fpv-accent-soft: rgba(61, 91, 219, 0.10);
    --fpv-danger: #d9464c;
    --fpv-danger-soft: rgba(217, 70, 76, 0.10);
    --fpv-success: #2c9e54;
    --fpv-success-soft: rgba(44, 158, 84, 0.10);
    --fpv-warning: #b98102;
    --fpv-warning-soft: rgba(185, 129, 2, 0.10);

    --shadow-1: 0 1px 2px rgba(16, 22, 40, 0.06), 0 1px 3px rgba(16, 22, 40, 0.05);
    --shadow-2: 0 6px 18px rgba(16, 22, 40, 0.10);
    --shadow-3: 0 16px 40px rgba(16, 22, 40, 0.18);

    --scrollbar-thumb: #c2c8d4;
    --scrollbar-thumb-hover: #9aa2b3;
}

:root {
    --radius-sm: 6px;
    --radius:    10px;
    --radius-lg: 14px;
    --radius-xl: 20px;
    /* Row height for the justified timeline grid. Three rows visible per
       viewport on a 1080p display: (100vh - navbar - header - gaps) / 3.
       The tile-size slider overrides this at runtime. */
    --tile-size: clamp(140px, calc((100vh - 200px) / 3), 360px);
    --fpv-nav-h: 58px;
    --dur-fast: 120ms;
    --dur:      200ms;
    --ease:     cubic-bezier(.2, .6, .2, 1);
}

/* Belt-and-braces: nothing anywhere should spill past the viewport width. */
html, body { overflow-x: hidden; max-width: 100vw; }

/* --- Base --------------------------------------------------------- */
html, body {
    background: var(--fpv-bg);
    color: var(--fpv-text);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}
body {
    font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
    font-feature-settings: "ss01", "cv11";
}
::selection { background: var(--fpv-accent); color: #fff; }

/* Custom scrollbars */
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 999px;
    border: 2px solid transparent;
    background-clip: padding-box;
}
*::-webkit-scrollbar-thumb:hover { background: var(--scrollbar-thumb-hover); background-clip: padding-box; }

/* Focus ring — only when keyboard/assistive tech-driven */
:focus-visible {
    outline: 2px solid var(--fpv-accent);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}
.btn:focus-visible,
.form-control:focus-visible,
.form-select:focus-visible { outline: none; }  /* Bootstrap handles focus for these via box-shadow */

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { transition: none !important; animation: none !important; }
}

a { color: var(--fpv-accent); text-decoration: none; transition: color var(--dur-fast) var(--ease); }
a:hover { color: var(--fpv-accent-hover); }
code { color: var(--fpv-text); background: var(--fpv-surface-raised); padding: 1px 6px; border-radius: 4px; font-size: 88%; }

h1, h2, h3, h4, h5, h6 { letter-spacing: -0.01em; }
h3 { font-weight: 600; }
hr { border-color: var(--fpv-border); opacity: 1; }

/* --- Navbar ------------------------------------------------------- */
.navbar {
    height: var(--fpv-nav-h);
    background: var(--fpv-surface);
    border-bottom: 1px solid var(--fpv-border);
    padding: 0 0.75rem;
    backdrop-filter: saturate(140%) blur(6px);
    transition: box-shadow var(--dur) var(--ease);
}
.navbar.is-scrolled { box-shadow: var(--shadow-1); }
.navbar .navbar-brand { color: var(--fpv-text) !important; letter-spacing: -0.01em; text-decoration: none; }
.navbar .navbar-brand i { color: var(--fpv-accent); }
.navbar .brand-icon { font-size: 1.5rem; line-height: 1; }
/* QR variant: larger + white padding so phones can read it from across a room */
.navbar .brand-icon-qr {
    width: 44px; height: 44px;
    padding: 2px; background: #fff; border-radius: 4px;
    image-rendering: pixelated; /* keep module edges crisp at small sizes */
}

/* Icon picker grid (admin → config → Site icon) */
.icon-picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(86px, 1fr)); gap: 0.5rem; }
.icon-picker label {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 0.25rem; padding: 0.65rem 0.4rem; border-radius: var(--radius);
    border: 1px solid var(--fpv-border); cursor: pointer; text-align: center;
    background: var(--fpv-surface); transition: all var(--dur-fast) var(--ease);
}
.icon-picker label:hover { border-color: var(--fpv-border-strong); transform: translateY(-1px); }
.icon-picker label i.bi { font-size: 1.6rem; color: var(--fpv-muted); transition: color var(--dur-fast) var(--ease); }
.icon-picker label small { color: var(--fpv-muted); font-size: 0.72rem; }
.icon-picker input[type="radio"] { display: none; }
.icon-picker input[type="radio"]:checked + i.bi { color: var(--fpv-accent); }
.icon-picker label:has(input:checked) {
    border-color: var(--fpv-accent); background: var(--fpv-accent-soft);
    box-shadow: 0 0 0 2px var(--fpv-accent-soft);
}
.icon-picker label:has(input:checked) small { color: var(--fpv-accent); }
.icon-picker label:has(input:checked) i.bi { color: var(--fpv-accent); }
.navbar .brand-text { font-weight: 700; font-size: 1rem; line-height: 1.1; }
.navbar .brand-sub {
    font-size: 0.84rem;
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    line-height: 1;
    margin-top: 2px;
    white-space: nowrap;
}
/* (mobile brand-sub hide lives in mobile.css) */
.navbar .nav-link { color: var(--fpv-text) !important; }
.navbar .nav-link:hover,
.navbar .nav-link.active { color: var(--fpv-accent) !important; }

/* Nav search field */
.navbar .input-group-text { background: var(--fpv-surface-raised); border-color: var(--fpv-border); color: var(--fpv-muted); }
.navbar .input-group .form-control {
    background: var(--fpv-surface-raised);
    border-color: var(--fpv-border);
    transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.navbar .input-group:focus-within .form-control,
.navbar .input-group:focus-within .input-group-text {
    border-color: var(--fpv-accent);
    box-shadow: 0 0 0 3px var(--fpv-accent-soft);
}

/* Hamburger for mobile drawer */
.nav-burger {
    display: none;
    background: transparent;
    border: 1px solid var(--fpv-border);
    border-radius: var(--radius-sm);
    color: var(--fpv-text);
    width: 36px; height: 36px;
    align-items: center; justify-content: center;
    cursor: pointer;
}
.nav-burger:hover { background: var(--fpv-surface-raised); }

/* --- Cards / surfaces -------------------------------------------- */
.card, .modal-content, .dropdown-menu, .list-group-item, .form-control, .form-select {
    background: var(--fpv-surface);
    color: var(--fpv-text);
    border-color: var(--fpv-border);
}
.card {
    border-radius: var(--radius);
    box-shadow: var(--shadow-1);
}
.card-header, .card-footer {
    background: var(--fpv-surface-raised);
    border-color: var(--fpv-border);
}
.card.card-hover {
    transition: transform var(--dur) var(--ease), border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.card.card-hover:hover {
    transform: translateY(-2px);
    border-color: var(--fpv-border-strong);
    box-shadow: var(--shadow-2);
}

/* Dropdowns pick up the theme properly */
.dropdown-menu {
    border-radius: var(--radius);
    box-shadow: var(--shadow-2);
    padding: 0.35rem;
}
.dropdown-item {
    color: var(--fpv-text);
    border-radius: var(--radius-sm);
    padding: 0.45rem 0.7rem;
}
.dropdown-item:hover, .dropdown-item:focus {
    background: var(--fpv-surface-raised);
    color: var(--fpv-text);
}
.dropdown-divider { border-top: 1px solid var(--fpv-border); margin: 0.35rem 0; }

/* --- Forms -------------------------------------------------------- */
.form-control, .form-select {
    transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease), background var(--dur) var(--ease);
}
.form-control:focus, .form-select:focus {
    background: var(--fpv-surface);
    color: var(--fpv-text);
    border-color: var(--fpv-accent);
    box-shadow: 0 0 0 3px var(--fpv-accent-soft);
}
.form-control::placeholder { color: var(--fpv-muted); opacity: 0.7; }
.form-label { color: var(--fpv-text-dim); font-weight: 500; letter-spacing: 0.01em; margin-bottom: 0.25rem; }
.form-label.small, label.form-label.small { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--fpv-muted); }
.form-text { color: var(--fpv-muted); }
.form-check-input { background-color: var(--fpv-surface-raised); border-color: var(--fpv-border-strong); }
.form-check-input:checked { background-color: var(--fpv-accent); border-color: var(--fpv-accent); }
.form-check-input:focus { box-shadow: 0 0 0 3px var(--fpv-accent-soft); border-color: var(--fpv-accent); }
.form-switch .form-check-input { background-image: none; }
input[type="range"] { accent-color: var(--fpv-accent); }

/* Dark-mode number input spinners — leave them default; Firefox handles it. */

/* --- Buttons ------------------------------------------------------ */
.btn {
    border-radius: var(--radius-sm);
    transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease),
                color var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
    font-weight: 500;
}
.btn:active { transform: translateY(1px); }
.btn-sm { padding: 0.3rem 0.7rem; }
.btn-primary { background-color: var(--fpv-accent); border-color: var(--fpv-accent); color: #fff; }
.btn-primary:hover, .btn-primary:focus { background-color: var(--fpv-accent-hover); border-color: var(--fpv-accent-hover); color: #fff; }
.btn-primary:focus-visible { box-shadow: 0 0 0 3px var(--fpv-accent-soft); }
.btn-outline-secondary { color: var(--fpv-text); border-color: var(--fpv-border); background: transparent; }
.btn-outline-secondary:hover { background: var(--fpv-surface-raised); color: var(--fpv-text); border-color: var(--fpv-border-strong); }
.btn-outline-primary { color: var(--fpv-accent); border-color: var(--fpv-accent); background: transparent; }
.btn-outline-primary:hover { background: var(--fpv-accent); border-color: var(--fpv-accent); color: #fff; }
.btn-outline-danger { color: var(--fpv-danger); border-color: var(--fpv-border); }
.btn-outline-danger:hover { background: var(--fpv-danger); border-color: var(--fpv-danger); color: #fff; }
.btn-outline-warning { color: var(--fpv-warning); border-color: var(--fpv-border); }
.btn-outline-warning:hover { background: var(--fpv-warning); border-color: var(--fpv-warning); color: #11141a; }
.btn-link { color: var(--fpv-accent); text-decoration: none; }
.btn-link:hover { color: var(--fpv-accent-hover); }

/* Icon-only buttons — keep square */
.btn-icon { width: 36px; height: 36px; padding: 0; display: inline-flex; align-items: center; justify-content: center; }

/* --- Tables ------------------------------------------------------- */
.table {
    --bs-table-bg: transparent;
    --bs-table-border-color: var(--fpv-border);
    color: var(--fpv-text);
    border-color: var(--fpv-border);
}
.table > :not(caption) > * > * { border-bottom-color: var(--fpv-border); }
.table thead th {
    background: var(--fpv-surface-raised);
    color: var(--fpv-text-dim);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.72rem;
    letter-spacing: 0.05em;
    padding: 0.5rem 0.6rem;
    border-bottom: 1px solid var(--fpv-border);
}
.table tbody td { padding: 0.55rem 0.6rem; vertical-align: middle; }
.table-hover tbody tr { transition: background var(--dur-fast) var(--ease); }
.table-hover tbody tr:hover { background: var(--fpv-surface-raised); }

/* --- Badges ------------------------------------------------------- */
.badge { font-weight: 500; letter-spacing: 0.01em; padding: 0.32em 0.6em; border-radius: 999px; }
.badge.bg-primary    { background: var(--fpv-accent-soft) !important; color: var(--fpv-accent) !important; }
.badge.bg-success    { background: var(--fpv-success-soft) !important; color: var(--fpv-success) !important; }
.badge.bg-danger     { background: var(--fpv-danger-soft) !important; color: var(--fpv-danger) !important; }
.badge.bg-warning    { background: var(--fpv-warning-soft) !important; color: var(--fpv-warning) !important; }
.badge.bg-info       { background: var(--fpv-accent-soft) !important; color: var(--fpv-accent) !important; }
.badge.bg-secondary  { background: var(--fpv-surface-raised) !important; color: var(--fpv-muted) !important; }

/* --- Utilities ---------------------------------------------------- */
.text-muted { color: var(--fpv-muted) !important; }
.text-dim   { color: var(--fpv-text-dim) !important; }
.border-fpv { border-color: var(--fpv-border) !important; }
.bg-surface { background: var(--fpv-surface) !important; }
.bg-raised  { background: var(--fpv-surface-raised) !important; }
.rounded-fpv { border-radius: var(--radius) !important; }
.shadow-1 { box-shadow: var(--shadow-1) !important; }
.shadow-2 { box-shadow: var(--shadow-2) !important; }
.font-mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; }
.scrollbox { max-height: 400px; overflow-y: auto; }

/* Empty states */
.empty-state {
    text-align: center;
    padding: 3rem 1.5rem;
    color: var(--fpv-muted);
    position: relative;
    overflow: hidden;
    border-radius: var(--radius);
}
.empty-state .bi {
    font-size: 2.5rem;
    color: var(--fpv-border-strong);
    display: block;
    margin-bottom: 0.75rem;
}
.empty-state h5, .empty-state strong { color: var(--fpv-text-dim); font-weight: 600; }
.empty-state p { margin-bottom: 1rem; }

/* With a library-sampled backdrop, the blurred photo sits behind the
   icon/text and the icon brightens so it stays legible. */
.empty-state.has-backdrop .bi { color: var(--fpv-text-dim); }
.empty-state.has-backdrop .empty-bg {
    position: absolute; inset: 0;
    background-size: cover; background-position: center;
    filter: blur(24px) brightness(0.35) saturate(0.85);
    opacity: 0.5;
    z-index: 0;
    transition: opacity 300ms var(--ease);
}
.empty-state.has-backdrop > *:not(.empty-bg) { position: relative; z-index: 1; }

/* Dropzone */
.dropzone {
    border: 2px dashed var(--fpv-border-strong);
    border-radius: var(--radius);
    padding: 2.25rem;
    text-align: center;
    color: var(--fpv-muted);
    transition: all var(--dur) var(--ease);
    background: var(--fpv-surface);
}
.dropzone:hover { border-color: var(--fpv-muted); }
.dropzone.dragover {
    border-color: var(--fpv-accent);
    background: var(--fpv-accent-soft);
    color: var(--fpv-text);
}

.notification-bell { position: relative; }
.notification-bell .badge {
    position: absolute; top: -2px; right: -4px;
    font-size: 0.65rem; padding: 2px 5px;
    box-shadow: 0 0 0 2px var(--fpv-surface);
}

/* --- Library layout (sidebar + main) ------------------------------ */
.lib-layout {
    display: flex;
    min-height: calc(100vh - var(--fpv-nav-h));
    align-items: stretch;
}
.lib-sidebar {
    width: 248px;
    flex-shrink: 0;
    background: var(--fpv-surface);
    border-right: 1px solid var(--fpv-border);
    padding: 0.75rem 0.5rem 2rem 0.5rem;
    overflow-y: auto;
    max-height: calc(100vh - var(--fpv-nav-h));
    position: sticky;
    top: var(--fpv-nav-h);
    scrollbar-gutter: stable;
}
.lib-main { flex: 1 1 auto; min-width: 0; padding: 0.85rem 1rem; }

/* --- App-shell scroll model -------------------------------------- *
 * Pages that render with a sidebar (timeline, albums, people, places,
 * events, activity, saved searches, videos, memory pages, export) use
 * a fixed nav + fixed sidebar + single scrollable main area. Pages
 * without a sidebar (login, register, errors, help) keep the normal
 * body-scrolls-everything behaviour.
 *
 * The body is a flex column; navbar and the optional admin task-bar
 * stay at the top (flex: 0 0 auto) and .lib-layout flex-grows to fill
 * the remaining viewport with overflow:hidden. Sidebar + .lib-main
 * each have their own overflow:auto so the content area scrolls
 * independently of the sidebar, and neither scrolls the rest of the
 * page.
 */
body.app-shell {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;   /* iOS / Android honours the dynamic viewport */
    overflow: hidden;
    margin: 0;
}
body.app-shell > #fpv-nav,
body.app-shell > .navbar,
body.app-shell > #fpv-task-bar { flex: 0 0 auto; }

/* The <main class="lib-layout"> fills the remaining vertical space. */
body.app-shell > main.lib-layout {
    flex: 1 1 auto;
    min-height: 0;       /* needed so inner overflow kicks in */
    overflow: hidden;
    align-items: stretch;
    min-height: 0;
}

/* Sidebar takes the full height of the flex row and scrolls internally. */
body.app-shell .lib-sidebar {
    position: static;
    top: auto;
    max-height: none;
    height: 100%;
    overflow-y: auto;
}

/* The main column scrolls — this is where timeline / album grids / etc.
 * live. Infinite-scroll sentinels continue to trigger because
 * IntersectionObserver with a default root uses the viewport, which
 * matches what's visible here. */
body.app-shell .lib-main {
    flex: 1 1 auto;
    min-width: 0;
    height: 100%;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-gutter: stable;
}

/* Mobile: the bottom tab-bar needs a clear space above the last
 * visible tile. In app-shell mode body overflow is hidden, so the
 * padding that used to live on body must move to the actual scroller. */
body.app-shell.is-mobile { padding-bottom: 0; }
body.app-shell.is-mobile:not(.msearch-open) .lib-main {
    padding-bottom: calc(var(--mtab-height) + var(--fpv-safe-bot) + 0.85rem);
}

.lib-sidebar .lib-section {
    display: flex;
    align-items: center;
    justify-content: space-between;
    text-transform: uppercase;
    font-size: 0.68rem;
    letter-spacing: 0.1em;
    color: var(--fpv-muted);
    padding: 0.85rem 0.75rem 0.3rem 0.75rem;
    font-weight: 700;
}
.lib-sidebar .lib-section .lib-section-add {
    color: var(--fpv-muted);
    text-decoration: none;
    font-weight: 400;
    font-size: 1.1rem;
    line-height: 1;
    transition: color var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
.lib-sidebar .lib-section .lib-section-add:hover { color: var(--fpv-accent); transform: scale(1.1); }
.lib-sidebar ul { list-style: none; padding: 0; margin: 0 0 0.4rem 0; }
.lib-sidebar li a {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.4rem 0.75rem;
    border-radius: var(--radius-sm);
    color: var(--fpv-text);
    text-decoration: none;
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.lib-sidebar li a i.bi { color: var(--fpv-muted); width: 18px; text-align: center; font-size: 1rem; transition: color var(--dur-fast) var(--ease); }
.lib-sidebar li a:hover { background: var(--fpv-surface-raised); }
.lib-sidebar li a:hover i.bi { color: var(--fpv-text); }
.lib-sidebar li a.active {
    background: var(--fpv-accent-soft);
    color: var(--fpv-accent);
    font-weight: 500;
}
.lib-sidebar li a.active i.bi { color: var(--fpv-accent); }
.lib-sidebar li a .lib-count {
    margin-left: auto;
    font-size: 0.72rem;
    color: var(--fpv-muted);
    padding: 1px 8px;
    border-radius: 999px;
    background: var(--fpv-surface-raised);
}
.lib-sidebar li a.active .lib-count { background: var(--fpv-accent-soft); color: var(--fpv-accent); }

/* Sidebar backdrop for mobile drawer */
.lib-sidebar-backdrop {
    display: none;
    position: fixed; inset: 0; background: rgba(0,0,0,0.45);
    z-index: 1090;
    opacity: 0; transition: opacity var(--dur) var(--ease);
}

/* --- Photo grid + tiles ------------------------------------------- */
/* Justified-row grid: each tile's width is proportional to its image's
   aspect ratio (supplied via inline `--aspect`), every row is stretched to
   fill the container width, rows wrap vertically. The trailing ::after
   flex-filler prevents the last incomplete row from stretching its few
   tiles up to full-width width. */
.photo-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    min-width: 0;
}
.photo-grid::after {
    content: "";
    flex-grow: 100000;
    min-width: 80px;
    height: 0;
}

.tile-size-control {
    display: inline-flex; align-items: center; gap: 0.45rem;
    padding: 0.25rem 0.7rem;
    background: var(--fpv-surface);
    border: 1px solid var(--fpv-border);
    border-radius: 999px;
    font-size: 0.8rem;
    color: var(--fpv-muted);
}
.tile-size-control input[type="range"] { width: 130px; margin: 0; accent-color: var(--fpv-accent); }
.tile-size-control .icon-small { font-size: 0.75rem; }
.tile-size-control .icon-large { font-size: 1rem; }

.photo-tile {
    position: relative;
    /* Keep the image's true aspect so panoramas are wide, portraits are tall.
       `--aspect` (width / height) is set inline per tile; default 1 = square. */
    --aspect: 1;
    flex: var(--aspect) var(--aspect) calc(var(--aspect) * var(--tile-size));
    height: var(--tile-size);
    min-width: 80px;
    aspect-ratio: var(--aspect);
    background: var(--fpv-surface-raised);
    overflow: hidden;
    border-radius: var(--radius-sm);
    border: 1px solid var(--fpv-border);
    cursor: pointer;
    transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.photo-tile:hover,
.photo-tile:focus-within {
    transform: translateY(-2px);
    border-color: var(--fpv-accent);
    box-shadow:
        0 0 0 2px var(--fpv-accent-soft),
        0 10px 22px rgba(107, 138, 253, 0.22),
        var(--shadow-2);
}
.photo-tile img {
    width: 100%; height: 100%; object-fit: cover; display: block;
    transition: transform 700ms var(--ease),
                opacity 220ms var(--ease),
                filter 220ms var(--ease);
}
/* Progressive (blur-up) loading. Until a tile's ``<img>`` gets the ``loaded``
   class, it's held at low opacity + slight blur over the shimmering skeleton.
   The utility in ``progressive.js`` flips the class on the ``load`` event. */
.photo-tile img:not(.loaded) {
    opacity: 0;
    filter: blur(6px);
}
.photo-tile img.loaded {
    opacity: 1;
    filter: none;
}
/* Reveal the skeleton only while the image is still loading. */
.photo-tile .photo-skel { display: block; }
.photo-tile img.loaded + .photo-skel,
.photo-tile .photo-skel.hidden { display: none; }
.photo-tile:hover img,
.photo-tile:focus-within img { transform: scale(1.045); }

/* Staggered grid entrance. progressive.js / timeline.js set ``--idx`` on
   freshly-appended tiles; the animation clears itself via the `is-entering`
   class being removed after ~600ms by the JS. */
@keyframes fpv-tile-in {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: translateY(0); }
}
.photo-tile.is-entering {
    animation: fpv-tile-in 360ms var(--ease) both;
    animation-delay: calc(var(--idx, 0) * 22ms);
}
@media (prefers-reduced-motion: reduce) {
    .photo-tile.is-entering { animation: none !important; }
    .photo-tile:hover img,
    .photo-tile:focus-within img { transform: none !important; }
}
.photo-tile .photo-meta {
    position: absolute; bottom: 0; left: 0; right: 0;
    padding: 8px 10px 6px;
    background: linear-gradient(to top, rgba(0,0,0,0.85), rgba(0,0,0,0));
    font-size: 0.75rem;
    color: #fff;
    opacity: 0;
    transition: opacity var(--dur) var(--ease);
}
.photo-tile:hover .photo-meta { opacity: 1; }
.photo-tile.selected {
    outline: 3px solid var(--fpv-accent);
    outline-offset: -3px;
    border-color: transparent;
}
.photo-tile.selected::after {
    content: "";
    position: absolute; inset: 0;
    background: var(--fpv-accent-soft);
    pointer-events: none;
}
body.batch-select-mode .photo-tile { cursor: copy; }

/* Skeleton placeholder (when image is loading) — accent-tinted sweep
   so the app's own colour reads through while photos resolve. */
.photo-tile .photo-skel {
    position: absolute; inset: 0;
    background: linear-gradient(
        90deg,
        var(--fpv-surface-raised) 0%,
        var(--fpv-accent-soft) 50%,
        var(--fpv-surface-raised) 100%
    );
    background-size: 200% 100%;
    animation: fpv-shimmer 1.3s linear infinite;
}
@keyframes fpv-shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.date-section { margin-bottom: 0.9rem; }
.date-section h5 {
    border-bottom: 1px solid var(--fpv-border);
    padding: 0.3rem 0.2rem;
    margin-bottom: 0.3rem;
    font-size: 0.72rem;
    color: var(--fpv-muted);
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    background: var(--fpv-bg);
}
.photo-tile { border-radius: 4px; }
.photo-tile:hover { transform: none; }

/* --- People / Places cards ---------------------------------------- */
.people-grid, .places-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(calc(var(--tile-size) - 20px), 1fr));
    gap: 0.9rem;
}
.person-card, .place-card {
    background: var(--fpv-surface);
    border: 1px solid var(--fpv-border);
    border-radius: var(--radius);
    overflow: hidden;
    text-decoration: none;
    color: var(--fpv-text);
    display: block;
    transition: transform var(--dur) var(--ease), border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.person-card:hover, .place-card:hover {
    transform: translateY(-2px);
    border-color: var(--fpv-border-strong);
    box-shadow: var(--shadow-2);
}
.person-card .avatar, .place-card .thumb {
    width: 100%; aspect-ratio: 1/1;
    background: var(--fpv-surface-raised);
    display: flex; align-items: center; justify-content: center;
    color: var(--fpv-muted);
}
.person-card .avatar img, .place-card .thumb img { width: 100%; height: 100%; object-fit: cover; }
.person-card .label, .place-card .label { padding: 0.6rem 0.8rem; }
.person-card .label strong, .place-card .label strong { display: block; font-weight: 600; }

/* Rename-named-person pencil — top-left of the card, hover-revealed. */
.person-card.is-renameable { position: relative; }
.person-rename-btn {
    position: absolute; top: 6px; left: 6px; z-index: 4;
    width: 26px; height: 26px; padding: 0; border: 0; border-radius: 50%;
    background: rgba(20, 20, 20, 0.72); color: #eaeaea;
    opacity: 0; transition: opacity 120ms;
    display: inline-flex; align-items: center; justify-content: center;
    cursor: pointer;
}
.person-card.is-renameable:hover .person-rename-btn,
.person-rename-btn:focus-visible { opacity: 1; }
.person-rename-btn:hover { background: rgba(40, 40, 40, 0.92); }
.person-card .label small, .place-card .label small { color: var(--fpv-muted); }

/* --- Slideshow ---------------------------------------------------- */
.slideshow-root { position: fixed; inset: 0; background: #000; display: flex; flex-direction: column; z-index: 2000; }
.slideshow-stage { flex: 1 1 auto; position: relative; overflow: hidden; }
.slideshow-photo { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
                   opacity: 0; transition: opacity 0.5s ease-in-out; }
.slideshow-photo.active { opacity: 1; z-index: 2; }
.slideshow-photo img { max-width: 100%; max-height: 100%; object-fit: contain; }
.slideshow-overlay {
    position: absolute; bottom: 0; left: 0; right: 0;
    padding: 1.5rem 2rem;
    background: linear-gradient(to top, rgba(0,0,0,0.85), rgba(0,0,0,0));
    color: #fff;
    z-index: 5;
    transition: opacity 400ms ease;
}
.slideshow-controls {
    display: flex; gap: 0.75rem; align-items: center; justify-content: center;
    padding: 0.75rem;
    background: rgba(0,0,0,0.6);
    color: #fff;
    transition: opacity 400ms ease, transform 400ms ease;
}
.slideshow-controls button {
    background: transparent; border: 1px solid rgba(255,255,255,0.3);
    color: #fff; padding: 0.4rem 0.9rem; border-radius: 999px;
    transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}
.slideshow-controls button:hover { background: rgba(255,255,255,0.12); border-color: rgba(255,255,255,0.55); }
.slideshow-controls .ss-speed-group {
    display: inline-flex; align-items: center; gap: 0.25rem;
    border: 1px solid rgba(255,255,255,0.25); border-radius: 999px;
    padding: 2px 4px;
}
.slideshow-controls .ss-speed-group button { padding: 0.15rem 0.55rem; border: none; }
.slideshow-controls .ss-speed-group select {
    background: transparent; color: #fff; border: none; outline: none;
    font-size: 0.85rem; padding: 2px 4px; min-width: 58px; text-align: center;
    appearance: none; -webkit-appearance: none;
}
.slideshow-controls .ss-speed-group select option { background: #1a1e26; color: #fff; }

.slideshow-root.slideshow-idle { cursor: none; }
.slideshow-root.slideshow-idle .slideshow-controls { opacity: 0; transform: translateY(8px); pointer-events: none; }
.slideshow-root.slideshow-idle .slideshow-overlay  { opacity: 0; pointer-events: none; }

/* Offline / cache chip on edge slideshow pages (PWA). */
.slideshow-offline-chip {
    position: fixed; top: 12px; right: 12px; z-index: 20;
    display: inline-flex; align-items: center; gap: 0.5rem;
    padding: 0.25rem 0.75rem; border-radius: 999px;
    background: rgba(20, 20, 20, 0.72); color: #eaeaea;
    font-size: 0.8rem; backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
    transition: opacity 0.4s;
}
.slideshow-root.slideshow-idle + .slideshow-offline-chip { opacity: 0; pointer-events: none; }
.slideshow-offline-chip .ss-offline-dot {
    width: 8px; height: 8px; border-radius: 50%; background: #34a853;
    display: inline-block;
}
.slideshow-offline-chip .ss-offline-count { color: #bdbdbd; }
.slideshow-offline-chip .ss-offline-clear { padding: 0 0.25rem; font-size: 0.8rem; }

/* "Unavailable" state for photos that couldn't be fetched offline. */
.slideshow-photo.slideshow-photo-unavailable img { opacity: 0.18; filter: blur(2px); }
.slideshow-photo.slideshow-photo-unavailable::after {
    content: "Not available offline"; position: absolute; inset: auto 0 50% 0;
    text-align: center; color: #bdbdbd; font-size: 0.9rem;
}

/* Slideshow themes (F-15) */
.ss-theme-cinematic .slideshow-photo img { filter: contrast(1.08) saturate(1.05); }
.ss-theme-cinematic .slideshow-overlay { font-family: Georgia, "Times New Roman", serif; font-style: italic; }
.ss-theme-film .slideshow-photo img { filter: sepia(0.35) contrast(1.05) brightness(0.95); }
.ss-theme-bw .slideshow-photo img { filter: grayscale(1) contrast(1.08); }
.ss-theme-minimal .slideshow-overlay { display: none; }
.ss-theme-minimal .slideshow-controls { opacity: 0; transition: opacity 0.3s; }
.ss-theme-minimal .slideshow-controls:hover { opacity: 1; }

/* F-15 Theme-change badge — briefly overlaid on the slideshow after
   the viewer presses T to confirm which theme took effect. */
.ss-theme-badge {
    position: absolute; top: 14px; right: 14px; z-index: 30;
    padding: 0.35rem 0.85rem; border-radius: 999px;
    background: rgba(20, 20, 20, 0.78); color: #eaeaea;
    font-size: 0.85rem; text-transform: capitalize;
    backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
    opacity: 0; transform: translateY(-4px);
    transition: opacity 180ms, transform 180ms;
    pointer-events: none;
}
.ss-theme-badge.is-visible { opacity: 1; transform: translateY(0); }

/* I-06 TV mode — hover-only hints stay visible, controls get big-button
   sized for a 10-foot remote, captions don't hide on idle. */
body.tv-mode .slideshow-overlay,
body.tv-mode .slideshow-photo .photo-meta { opacity: 1 !important; }
body.tv-mode .slideshow-controls { font-size: 1.1rem; padding: 0.75rem 1rem; }
body.tv-mode .slideshow-controls .btn { min-width: 48px; min-height: 48px; }
body.tv-mode .slideshow-root.slideshow-idle .slideshow-controls {
    opacity: 0.25;
}

/* --- Memory page builder ------------------------------------------ */
.mp-block {
    background: var(--fpv-surface);
    border: 1px solid var(--fpv-border);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 0.75rem;
    position: relative;
    transition: border-color var(--dur) var(--ease);
}
.mp-block:hover { border-color: var(--fpv-border-strong); }
.mp-block .mp-block-handle {
    cursor: grab; color: var(--fpv-muted);
    position: absolute; top: 0.5rem; right: 0.5rem;
    font-size: 0.85rem;
}
.mp-block.sortable-ghost { opacity: 0.35; }

/* --- Face box ----------------------------------------------------- */
.face-box {
    position: absolute;
    border: 2px solid var(--fpv-accent);
    border-radius: 4px;
    pointer-events: auto;
    cursor: pointer;
    transition: background var(--dur-fast) var(--ease);
}
.face-box:hover { background: var(--fpv-accent-soft); }
.face-box .face-label {
    position: absolute; top: -22px; left: 0;
    font-size: 0.7rem; padding: 2px 7px;
    background: var(--fpv-accent); color: #fff; border-radius: 3px;
    white-space: nowrap;
}

/* --- Lightbox ----------------------------------------------------- */
.fpv-lb-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.92); z-index: 3000; display: flex; align-items: center; justify-content: center; overflow: hidden; user-select: none; }
.fpv-lb-stage { width: 100vw; height: 100vh; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.fpv-lb-img { max-width: 100%; max-height: 100%; transform-origin: center center; transform: translate(0,0) scale(1); will-change: transform; cursor: grab; touch-action: none; }
.fpv-lb-img:active { cursor: grabbing; }
.fpv-lb-close { position: absolute; top: 16px; right: 16px; background: rgba(255,255,255,0.12); color: #fff; border: 0; font-size: 2rem; line-height: 1; width: 44px; height: 44px; border-radius: 50%; cursor: pointer; transition: background var(--dur-fast) var(--ease); }
.fpv-lb-close:hover { background: rgba(255,255,255,0.25); }
.fpv-lb-nav { position: absolute; top: 50%; transform: translateY(-50%); background: rgba(255,255,255,0.10); color: #fff; border: 0; font-size: 2.2rem; line-height: 1; width: 48px; height: 48px; border-radius: 50%; cursor: pointer; transition: background var(--dur-fast) var(--ease); }
.fpv-lb-nav:hover { background: rgba(255,255,255,0.22); }
.fpv-lb-prev { left: 16px; }
.fpv-lb-next { right: 16px; }
.fpv-lb-hint { position: absolute; bottom: 16px; left: 50%; transform: translateX(-50%); color: rgba(255,255,255,0.75); font-size: 0.8rem; background: rgba(0,0,0,0.4); padding: 4px 10px; border-radius: 999px; pointer-events: none; }
body.fpv-lb-open { overflow: hidden; }

/* --- Voice widgets ------------------------------------------------ */
.voice-input-controls { display: inline-flex; align-items: center; margin-top: 0.35rem; margin-left: 0.25rem; }
.voice-input-btn.btn-danger { box-shadow: 0 0 0 0.2rem rgba(255, 107, 107, 0.25); }
.voice-input-status { font-size: 0.8rem; }
.input-group + .voice-input-controls { margin-top: 0; }

.voice-recorder {
    display: flex; align-items: center; gap: 0.5rem;
    background: var(--fpv-surface-raised);
    padding: 0.75rem;
    border-radius: var(--radius-sm);
}
.voice-recorder.recording .rec-dot {
    display: inline-block; width: 10px; height: 10px;
    background: var(--fpv-danger); border-radius: 50%;
    animation: pulse 1s infinite;
}
@keyframes pulse { 50% { opacity: 0.4; } }

/* --- Responsive: mobile drawer ------------------------------------ */
/* Mobile rules (≤ 900px) live in static/css/mobile.css which is loaded via
   conditional <link media="(max-width: 900px)"> in base.html. Desktop users
   never parse those rules. */

/* --- PWA standalone mode ---------------------------------------------
   <html> gets `.fpv-standalone` when the app is installed to the home
   screen and launched as a standalone window (no browser chrome). We hide
   the back-to-browser crutches and the PWA install bar (now redundant). */
html.fpv-standalone .hide-in-standalone,
html.fpv-standalone #pwa-install-bar { display: none !important; }
/* Extra top padding for iOS standalone (safe-area status bar overlay) */
html.fpv-standalone body { padding-top: env(safe-area-inset-top); }
html.fpv-standalone .navbar { top: env(safe-area-inset-top); }

/* --- Background task bar (admin only) ---------------------------- */
.fpv-task-bar {
    position: sticky; top: 0; z-index: 1040;
    background: var(--fpv-surface-raised, #242939);
    border-bottom: 1px solid var(--fpv-border, #333);
    padding: 0.4rem 1rem;
    display: flex; flex-direction: column; gap: 0.35rem;
    box-shadow: 0 2px 6px rgba(0,0,0,0.25);
}
.fpv-task-row { font-size: 0.82rem; }
.fpv-task-head {
    display: flex; align-items: center; gap: 0.5rem;
}
.fpv-task-title { flex: 1 1 auto; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fpv-task-counts { color: var(--bs-secondary); font-variant-numeric: tabular-nums; }
.fpv-task-cancel { color: var(--bs-secondary); }
.fpv-task-cancel:hover { color: var(--bs-danger); }
.fpv-task-msg { color: var(--bs-secondary); font-size: 0.78rem; margin-top: 2px; }
.fpv-task-bar .progress { background: rgba(255,255,255,0.08); margin-top: 2px; }

/* --- Print -------------------------------------------------------- */
@media print {
    .lib-sidebar, .navbar, .slideshow-root, .fpv-lb-backdrop, .fpv-toast-stack { display: none !important; }
    .lib-main { padding: 0; }
    body, html { background: #fff; color: #000; }
    a { color: #000; }
}

/* ---- Signature touches -------------------------------------------- *
 * Small, deliberate moments layered on top of the existing design.
 * ------------------------------------------------------------------- */

/* Aperture spinner — a rotating 6-blade camera iris. Scales to the
   element's font-size so callers can just drop one inline. */
.fpv-spinner {
    display: inline-block;
    width: 1.1em; height: 1.1em;
    vertical-align: -0.15em;
    border: 2px solid transparent;
    border-top-color: var(--fpv-accent);
    border-right-color: var(--fpv-accent);
    border-radius: 50%;
    animation: fpv-spin 1.1s linear infinite;
}
@keyframes fpv-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
    .fpv-spinner { animation: none; }
}

/* Count-up number display — matches .h3 sizing used in admin stat tiles. */
.fpv-countup { font-variant-numeric: tabular-nums; }

/* Login / landing backdrop — a blurred, dimmed photo from the library
   pulled in by JS. Falls back to a gradient when nothing qualifies. */
.login-backdrop {
    position: fixed; inset: 0; z-index: -1;
    background-size: cover; background-position: center;
    background-image: linear-gradient(135deg,
        var(--fpv-surface-raised), var(--fpv-bg));
    filter: blur(22px) brightness(0.5) saturate(0.9);
    opacity: 0.88;
    transition: opacity 600ms var(--ease);
    /* Mask the blur halo at the edges so the blurred image doesn't leak
       a pale halo past the viewport. */
    transform: scale(1.05);
}
.login-backdrop.loaded { opacity: 1; }
.login-shell { position: relative; }

/* Favorite sparkle — pure CSS particles emitted by ui_sparkle.js. */
.fpv-sparkle {
    position: absolute;
    pointer-events: none;
    width: 6px; height: 6px;
    border-radius: 50%;
    background: var(--fpv-accent);
    box-shadow: 0 0 6px var(--fpv-accent);
    animation: fpv-sparkle-out 600ms ease-out forwards;
}
@keyframes fpv-sparkle-out {
    0%   { opacity: 1; transform: translate(0,0) scale(1); }
    80%  { opacity: 0.7; }
    100% { opacity: 0; transform: translate(var(--dx, 0), var(--dy, 0)) scale(0.2); }
}
@media (prefers-reduced-motion: reduce) {
    .fpv-sparkle { display: none; }
}
