/* ============================================================================
   imgallery — premium photo gallery UI
   Design language: minimal + premium + image-focused + fast
   ============================================================================ */

/* ============================================================================
   1. Theme tokens (light / dark)
   ============================================================================ */
:root {
    color-scheme: light;
    --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter,
        "Helvetica Neue", Arial, sans-serif;
    --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

    /* Surfaces */
    --bg: #f6f6f8;
    --surface: #ffffff;
    --surface-2: #f1f1f4;
    --surface-3: #e9e9ee;
    --surface-hover: #f4f4f7;
    --border: #e8e8ed;
    --border-strong: #d5d5dd;

    /* Text */
    --text: #18181f;
    --text-2: #5a5a67;
    --text-3: #8b8b96;
    --on-accent: #ffffff;

    /* Brand / accent */
    --accent: #3b5bdb;
    --accent-hover: #2f4bc4;
    --accent-soft: rgba(59, 91, 219, 0.12);
    --accent-soft-2: rgba(59, 91, 219, 0.18);
    --accent-ring: rgba(59, 91, 219, 0.32);

    /* Semantic */
    --danger: #e5484d;
    --danger-soft: rgba(229, 72, 77, 0.12);
    --success: #2f9e63;
    --success-soft: rgba(47, 158, 99, 0.12);
    --warning: #d9822b;
    --warning-soft: rgba(217, 130, 43, 0.14);

    /* Effects */
    --shadow-xs: 0 1px 2px rgba(16, 16, 24, 0.05);
    --shadow-sm: 0 1px 3px rgba(16, 16, 24, 0.08), 0 1px 2px rgba(16, 16, 24, 0.04);
    --shadow-md: 0 6px 16px -4px rgba(16, 16, 24, 0.12), 0 2px 6px rgba(16, 16, 24, 0.05);
    --shadow-lg: 0 16px 40px -8px rgba(16, 16, 24, 0.2), 0 4px 12px rgba(16, 16, 24, 0.08);
    --shadow-xl: 0 32px 80px -16px rgba(16, 16, 24, 0.28), 0 8px 24px rgba(16, 16, 24, 0.1);

    --radius-sm: 8px;
    --radius: 12px;
    --radius-lg: 16px;
    --radius-xl: 22px;
    --radius-pill: 999px;

    --topbar-h: 60px;
    --sidebar-w: 244px;
    --sidebar-w-collapsed: 72px;

    --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
    --dur: 0.2s;

    --viewer-bg: rgba(8, 8, 12, 0.94);
    --overlay-bg: rgba(16, 16, 24, 0.55);
}

[data-theme="dark"] {
    color-scheme: dark;
    --bg: #0e0e12;
    --surface: #17171d;
    --surface-2: #1e1e25;
    --surface-3: #26262f;
    --surface-hover: #202028;
    --border: #26262f;
    --border-strong: #353540;

    --text: #f1f1f5;
    --text-2: #a3a3b1;
    --text-3: #70707d;
    --on-accent: #ffffff;

    --accent: #7c8bff;
    --accent-hover: #93a0ff;
    --accent-soft: rgba(124, 139, 255, 0.16);
    --accent-soft-2: rgba(124, 139, 255, 0.26);
    --accent-ring: rgba(124, 139, 255, 0.4);

    --danger: #f2555a;
    --danger-soft: rgba(242, 85, 90, 0.16);
    --success: #3cb876;
    --success-soft: rgba(60, 184, 118, 0.16);
    --warning: #e0934a;
    --warning-soft: rgba(224, 147, 74, 0.18);

    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4), 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 6px 16px -4px rgba(0, 0, 0, 0.5), 0 2px 6px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 16px 40px -8px rgba(0, 0, 0, 0.6), 0 4px 12px rgba(0, 0, 0, 0.4);
    --shadow-xl: 0 32px 80px -16px rgba(0, 0, 0, 0.7), 0 8px 24px rgba(0, 0, 0, 0.5);
}

/* ============================================================================
   2. Base
   ============================================================================ */
* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    font-family: var(--font-sans);
    font-size: 14.5px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    min-height: 100vh;
}

h1, h2, h3, h4, h5, h6 { margin: 0 0 0.5em; font-weight: 650; letter-spacing: -0.01em; }
p { margin: 0 0 0.75em; }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

img { max-width: 100%; }

::selection { background: var(--accent-soft-2); }

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: 4px;
}

/* Scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 8px; border: 2px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-track { background: transparent; }

/* ============================================================================
   3. Icons
   ============================================================================ */
.icon { flex-shrink: 0; display: inline-block; vertical-align: middle; }

/* ============================================================================
   4. Bootstrap component overrides (theme-aware)
   ============================================================================ */
.btn {
    --bs-btn-font-weight: 550;
    border-radius: var(--radius-sm);
    transition: background-color var(--dur) var(--ease), border-color var(--dur) var(--ease),
        box-shadow var(--dur) var(--ease), transform var(--dur) var(--ease), color var(--dur) var(--ease);
}
.btn:active { transform: scale(0.97); }

.btn-primary {
    --bs-btn-bg: var(--accent);
    --bs-btn-border-color: var(--accent);
    --bs-btn-hover-bg: var(--accent-hover);
    --bs-btn-hover-border-color: var(--accent-hover);
    --bs-btn-active-bg: var(--accent-hover);
    --bs-btn-active-border-color: var(--accent-hover);
    --bs-btn-disabled-bg: var(--accent);
    --bs-btn-disabled-border-color: var(--accent);
}

.btn-outline-primary {
    --bs-btn-color: var(--accent);
    --bs-btn-border-color: var(--accent);
    --bs-btn-hover-bg: var(--accent);
    --bs-btn-hover-border-color: var(--accent);
    --bs-btn-active-bg: var(--accent);
    --bs-btn-active-border-color: var(--accent);
}

.btn-outline-secondary {
    --bs-btn-color: var(--text-2);
    --bs-btn-border-color: var(--border-strong);
    --bs-btn-hover-bg: var(--surface-2);
    --bs-btn-hover-border-color: var(--border-strong);
    --bs-btn-hover-color: var(--text);
    --bs-btn-active-bg: var(--surface-2);
    --bs-btn-active-border-color: var(--border-strong);
    --bs-btn-active-color: var(--text);
}

.btn-ghost {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-2);
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    font-weight: 550;
    font-size: 14px;
    cursor: pointer;
    transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-xs);
}
.card-header { background: transparent; border-bottom: 1px solid var(--border); padding: 1rem 1.25rem; }
.card-header h5, .card-header .h5 { margin: 0; font-size: 1rem; }
.card-body { padding: 1.25rem; }

.form-control, .form-select {
    background-color: var(--surface);
    border-color: var(--border-strong);
    color: var(--text);
    border-radius: var(--radius-sm);
    transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease), background-color var(--dur) var(--ease);
}
.form-control::placeholder { color: var(--text-3); }
.form-control:focus, .form-select:focus {
    background-color: var(--surface);
    color: var(--text);
    border-color: var(--accent);
    box-shadow: 0 0 0 4px var(--accent-ring);
}
.form-select { background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%238b8b96' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='m2 5 6 6 6-6'/%3e%3c/svg%3e"); }
.form-label { font-weight: 550; color: var(--text-2); font-size: 13px; margin-bottom: 6px; }
.form-text { color: var(--text-3); }

.form-check-input {
    background-color: var(--surface);
    border-color: var(--border-strong);
}
.form-check-input:checked { background-color: var(--accent); border-color: var(--accent); }
.form-check-input:focus { box-shadow: 0 0 0 4px var(--accent-ring); border-color: var(--accent); }

.dropdown-menu {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 6px;
    min-width: 200px;
    z-index: 1150;
}
.dropdown-item {
    border-radius: 8px;
    color: var(--text);
    padding: 9px 12px;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.dropdown-item:hover, .dropdown-item:focus { background: var(--surface-2); color: var(--text); }
.dropdown-item:active { background: var(--accent-soft); color: var(--text); }
.dropdown-item .icon { color: var(--text-2); }
.dropdown-item.text-danger, .dropdown-item.text-danger .icon { color: var(--danger); }
.dropdown-item.text-danger:hover { background: var(--danger-soft); }
.dropdown-divider { border-color: var(--border); margin: 5px 0; }

.modal-content {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
}
.modal-header { border-bottom: 1px solid var(--border); padding: 1rem 1.25rem; }
.modal-footer { border-top: 1px solid var(--border); padding: 0.9rem 1.25rem; }
.modal-title { font-weight: 650; }
.btn-close { filter: none; opacity: 0.55; }
[data-theme="dark"] .btn-close { filter: invert(1) grayscale(100%); }
.modal-backdrop.show { opacity: 0.55; }

.offcanvas {
    background: var(--surface);
    border-left: 1px solid var(--border);
    color: var(--text);
}
.offcanvas-header { border-bottom: 1px solid var(--border); }
.offcanvas-backdrop.show { opacity: 0.5; }

.toast {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    color: var(--text);
}
.toast-body { padding: 0.75rem 1rem; font-weight: 500; }

.alert { border-radius: var(--radius); border: 1px solid var(--border); }

.table { --bs-table-bg: transparent; --bs-table-color: var(--text); color: var(--text); }
.table th {
    color: var(--text-2);
    font-weight: 600;
    font-size: 12.5px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
}
.table td { border-color: var(--border); vertical-align: middle; }
.table-striped > tbody > tr:nth-of-type(odd) > * { --bs-table-striped-bg: var(--surface-2); color: var(--text); }
.table-hover > tbody > tr:hover > * { --bs-table-hover-bg: var(--surface-hover); color: var(--text); }

.pagination { --bs-pagination-color: var(--text-2); --bs-pagination-bg: var(--surface); --bs-pagination-border-color: var(--border); }
.pagination .page-link { border-radius: 8px; margin: 0 2px; }
.pagination .page-item.active .page-link { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }

.badge { font-weight: 600; }
.text-bg-light { background: var(--surface-2) !important; color: var(--text-2) !important; }

/* DataTables chrome */
.dataTables_wrapper .dataTables_filter input {
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    color: var(--text);
    padding: 6px 12px;
}
.dataTables_wrapper .dataTables_length select {
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    color: var(--text);
    padding: 4px 8px;
}
.dataTables_wrapper .dataTables_info, .dataTables_wrapper .dataTables_paginate { color: var(--text-2); }

/* ============================================================================
   5. App shell
   ============================================================================ */
.app { display: flex; min-height: 100vh; }

/* ---- Sidebar ---- */
.app-sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: var(--sidebar-w);
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 1045;
    transition: width var(--dur) var(--ease), transform var(--dur) var(--ease);
}

.app-sidebar .sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 16px 18px;
    font-weight: 750;
    font-size: 16px;
    letter-spacing: -0.01em;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
}
.app-sidebar .sidebar-brand .brand-mark {
    width: 32px; height: 32px;
    border-radius: 10px;
    background: linear-gradient(135deg, #5b7cfa, #7c4dff);
    display: inline-flex; align-items: center; justify-content: center;
    color: #fff;
    flex-shrink: 0;
}
.app-sidebar .sidebar-brand .brand-mark .icon { color: #fff; }
.app-sidebar .sidebar-brand .brand-name { overflow: hidden; text-overflow: ellipsis; }

/* Brand logo image fills its rounded container */
.brand-mark img,
.hero-mark img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: inherit;
    display: block;
}

.app-sidebar .sidebar-scroll {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 8px 12px 12px;
}

.sidebar-section {
    padding: 18px 10px 6px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.09em;
    color: var(--text-3);
    white-space: nowrap;
    overflow: hidden;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 9px 12px;
    margin: 2px 0;
    border-radius: 10px;
    color: var(--text-2);
    font-weight: 550;
    font-size: 14px;
    white-space: nowrap;
    cursor: pointer;
    background: transparent;
    border: none;
    width: 100%;
    text-align: left;
    transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.sidebar-link .icon { color: var(--text-3); transition: color var(--dur) var(--ease); }
.sidebar-link:hover { background: var(--surface-2); color: var(--text); }
.sidebar-link:hover .icon { color: var(--text-2); }
.sidebar-link.active {
    background: var(--accent-soft);
    color: var(--accent);
}
.sidebar-link.active .icon { color: var(--accent); }
.sidebar-link .sidebar-label { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.sidebar-link .sidebar-count {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-3);
    background: var(--surface-2);
    border-radius: var(--radius-pill);
    padding: 1px 9px;
}
.sidebar-link.active .sidebar-count { background: var(--accent-soft-2); color: var(--accent); }

.sidebar-footer {
    padding: 12px;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 4px;
}

/* Collapsed (desktop) */
.app-sidebar.collapsed { width: var(--sidebar-w-collapsed); }
.app-sidebar.collapsed .sidebar-brand { justify-content: center; padding: 16px 0; }
.app-sidebar.collapsed .brand-name,
.app-sidebar.collapsed .sidebar-section,
.app-sidebar.collapsed .sidebar-label,
.app-sidebar.collapsed .sidebar-count,
.app-sidebar.collapsed .sidebar-user-text,
.app-sidebar.collapsed .sidebar-footer .btn-ghost span { display: none; }
.app-sidebar.collapsed .sidebar-link { justify-content: center; padding: 10px 0; }
.app-sidebar.collapsed .sidebar-footer { align-items: center; }
.app-sidebar.collapsed .sidebar-footer .btn-ghost { justify-content: center; padding: 8px; }

/* Mobile overlay */
.app-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: var(--overlay-bg);
    z-index: 1044;
    opacity: 0;
    transition: opacity var(--dur) var(--ease);
}
.app-overlay.show { opacity: 1; }

/* ---- Main column ---- */
.app-main {
    flex: 1;
    min-width: 0;
    margin-left: var(--sidebar-w);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    transition: margin-left var(--dur) var(--ease);
}
.app-sidebar.collapsed ~ .app-main,
.app-main.sidebar-collapsed { margin-left: var(--sidebar-w-collapsed); }

/* ---- Topbar ---- */
.topbar {
    position: sticky;
    top: 0;
    z-index: 1030;
    height: var(--topbar-h);
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 20px;
    background: color-mix(in srgb, var(--bg) 82%, transparent);
    -webkit-backdrop-filter: saturate(1.6) blur(14px);
    backdrop-filter: saturate(1.6) blur(14px);
    border-bottom: 1px solid var(--border);
}

.topbar-left { display: flex; align-items: center; gap: 6px; min-width: 0; }
.topbar-title {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.02em;
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text);
}

.topbar-search {
    flex: 1 1 0%;
    min-width: 0;
    max-width: 560px;
    margin: 0 auto;
    position: relative;
}

.topbar-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }

/* Icon buttons */
.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px; height: 40px;
    padding: 0;
    border-radius: 12px;
    background: transparent;
    border: none;
    color: var(--text-2);
    cursor: pointer;
    position: relative;
    transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn:active { transform: scale(0.92); }
.icon-btn .icon { display: block; }
.icon-btn .badge-dot {
    position: absolute;
    top: 8px; right: 8px;
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--danger);
    border: 2px solid var(--bg);
}

/* Upload pill button */
.btn-upload {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    height: 40px;
    padding: 0 18px;
    border-radius: var(--radius-pill);
    background: var(--text);
    color: var(--bg);
    font-weight: 600;
    font-size: 14px;
    border: none;
    cursor: pointer;
    transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease), opacity var(--dur) var(--ease);
    box-shadow: var(--shadow-sm);
}
.btn-upload:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); opacity: 0.92; color: var(--bg); }
.btn-upload:active { transform: scale(0.97); }
[data-theme="dark"] .btn-upload { background: #fff; color: #0e0e12; }
[data-theme="dark"] .btn-upload:hover { color: #0e0e12; }

/* Search */
.search-wrap { position: relative; }
.search-input {
    width: 100%;
    height: 42px;
    padding: 0 42px 0 42px;
    border-radius: var(--radius-pill);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font-size: 14px;
    transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease), background-color var(--dur) var(--ease);
}
.search-input::placeholder { color: var(--text-3); }
.search-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-ring); }
.search-wrap > .icon {
    position: absolute;
    left: 15px; top: 50%;
    transform: translateY(-50%);
    color: var(--text-3);
    pointer-events: none;
}
.search-clear {
    position: absolute;
    right: 8px; top: 50%;
    transform: translateY(-50%);
    width: 28px; height: 28px;
    border-radius: 50%;
    display: none;
    align-items: center;
    justify-content: center;
    border: none;
    background: var(--surface-2);
    color: var(--text-2);
    cursor: pointer;
}
.search-clear.show { display: inline-flex; }

.search-panel {
    position: absolute;
    top: calc(100% + 8px);
    left: 0; right: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    padding: 10px;
    display: none;
    z-index: 1060;
}
.search-panel.open { display: block; animation: pop-in var(--dur) var(--ease); }
.search-panel .sp-label {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--text-3);
    padding: 8px 10px 4px;
}
.search-panel .sp-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    border: none;
    background: none;
    color: var(--text);
    padding: 9px 10px;
    border-radius: 8px;
    font-size: 14px;
    text-align: left;
    cursor: pointer;
}
.search-panel .sp-item:hover { background: var(--surface-2); }
.search-panel .sp-item .icon { color: var(--text-3); }
.search-panel .sp-divider { height: 1px; background: var(--border); margin: 6px 0; }

/* Chips (active filters) */
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 20px 0; }
.chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 10px 5px 12px;
    border-radius: var(--radius-pill);
    background: var(--surface);
    border: 1px solid var(--border-strong);
    color: var(--text-2);
    font-size: 13px;
    font-weight: 550;
}
.chip .icon { color: var(--text-3); }
.chip .chip-x {
    display: inline-flex; align-items: center; justify-content: center;
    width: 18px; height: 18px;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: var(--text-3);
    cursor: pointer;
    padding: 0;
}
.chip .chip-x:hover { background: var(--surface-3); color: var(--text); }
.chip.chip-accent { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.chip.chip-accent .icon, .chip.chip-accent .chip-x { color: var(--accent); }
.chip.chip-accent .chip-x:hover { background: var(--accent-soft-2); }

/* App content */
.app-content {
    flex: 1;
    padding: 20px;
    width: 100%;
}
.app-content .container-fluid { padding: 0; }

/* ============================================================================
   6. Gallery — masonry + tiles
   ============================================================================ */
.gallery-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}
.gallery-head h1 { margin: 0; font-size: 22px; letter-spacing: -0.02em; }
.gallery-sub { color: var(--text-3); font-size: 13px; margin: 2px 0 0; }

.masonry {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 14px;
    align-items: start;
}
@media (min-width: 576px) { .masonry { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 768px) { .masonry { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 992px) { .masonry { grid-template-columns: repeat(4, 1fr); } }
@media (min-width: 1280px) { .masonry { grid-template-columns: repeat(5, 1fr); } }
@media (min-width: 1680px) { .masonry { grid-template-columns: repeat(6, 1fr); } }
@media (max-width: 768px) { .masonry { gap: 8px; } }

.tile {
    display: block;
    width: 100%;
    margin: 0;
    break-inside: avoid;
    position: relative;
    border-radius: var(--radius);
    overflow: hidden;
    cursor: pointer;
    -webkit-user-select: none;
    user-select: none;
    background: var(--surface-2);
    box-shadow: var(--shadow-xs);
    transition: box-shadow var(--dur) var(--ease), transform var(--dur) var(--ease);
}
@media (max-width: 768px) { .tile { border-radius: 10px; } }

.tile-frame { position: relative; width: 100%; overflow: hidden; }
.tile-frame img {
    display: block;
    width: 100%;
    height: auto;
    opacity: 0;
    transition: opacity 0.3s ease, transform 0.45s var(--ease);
}
.tile-frame img.loaded { opacity: 1; }
.tile:hover .tile-frame img { transform: scale(1.03); }

/* Play badge on video tiles */
.tile-play {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.45);
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
    z-index: 2;
    transition: transform 0.2s var(--ease);
}
.tile:hover .tile-play { transform: translate(-50%, -50%) scale(1.08); }
.tile-play svg { margin-left: 2px; }

/* Skeleton shimmer behind the image */
.tile-skeleton {
    position: absolute;
    inset: 0;
    background: linear-gradient(100deg, var(--surface-2) 40%, var(--surface-3) 50%, var(--surface-2) 60%);
    background-size: 200% 100%;
    animation: shimmer 1.4s infinite linear;
}

/* Hover overlay */
.tile-overlay {
    position: absolute;
    inset: 0;
    background: linear-gradient(to top, rgba(0,0,0,0.55) 0%, rgba(0,0,0,0.12) 40%, transparent 60%);
    opacity: 0;
    transition: opacity var(--dur) var(--ease);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 10px;
    pointer-events: none;
}
.tile:hover .tile-overlay,
.tile:focus-visible .tile-overlay,
.tile.selected .tile-overlay { opacity: 1; }

.tile-actions {
    display: flex;
    gap: 8px;
    pointer-events: auto;
    margin-left: auto;
}
.tile-info {
    display: flex;
    gap: 6px;
    align-items: flex-end;
    justify-content: space-between;
}
.tile-name {
    color: #fff;
    font-size: 12.5px;
    font-weight: 550;
    text-shadow: 0 1px 3px rgba(0,0,0,0.5);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
}

.tile-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px; height: 34px;
    border-radius: 50%;
    border: none;
    background: rgba(22, 22, 28, 0.55);
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
    color: #fff;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
    transition: background-color var(--dur) var(--ease), transform var(--dur) var(--ease), color var(--dur) var(--ease);
}
.tile-btn:hover { background: rgba(22, 22, 28, 0.85); transform: scale(1.08); }
.tile-btn:active { transform: scale(0.92); }
.tile-btn .icon { display: block; }

/* Favorite indicator (heart filled) */
.tile-btn.faved { color: #ff5d73; background: rgba(255,255,255,0.92); }
.tile-btn.faved .icon { fill: currentColor; stroke: currentColor; stroke-width: 0; }

/* Selected state */
.tile.selected { box-shadow: 0 0 0 3px var(--accent), var(--shadow-md); }
.tile.selected .tile-frame img { transform: scale(1.02); }
.tile-check {
    position: absolute;
    top: 10px; left: 10px;
    width: 26px; height: 26px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 3;
    box-shadow: 0 2px 8px rgba(0,0,0,0.35);
    animation: pop-in 0.18s var(--ease);
}
.tile.selected .tile-check { display: flex; }
.tile-check .icon { display: block; }

/* Selection mode — dim unselected */
.selection-active .tile:not(.selected) .tile-frame img { filter: brightness(0.82) saturate(0.9); }
.selection-active .tile { cursor: pointer; }

/* ---- Selection toolbar (sticky under topbar) ---- */
.selection-bar {
    position: sticky;
    top: var(--topbar-h);
    z-index: 1020;
    margin: 16px auto 0;
    max-width: 760px;
    display: none;
    align-items: center;
    gap: 4px;
    padding: 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    box-shadow: var(--shadow-lg);
    flex-wrap: wrap;
    justify-content: center;
}
.selection-bar.open { display: flex; animation: slide-down var(--dur) var(--ease); }
.selection-bar .sel-count {
    font-weight: 650;
    font-size: 14px;
    padding: 0 12px;
    white-space: nowrap;
    color: var(--text);
}
.selection-bar .sel-sep { width: 1px; height: 24px; background: var(--border); margin: 0 4px; }
.sel-action {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    border: none;
    background: transparent;
    color: var(--text-2);
    font-weight: 550;
    font-size: 13.5px;
    padding: 8px 12px;
    border-radius: var(--radius-pill);
    cursor: pointer;
    transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.sel-action:hover { background: var(--surface-2); color: var(--text); }
.sel-action.danger { color: var(--danger); }
.sel-action.danger:hover { background: var(--danger-soft); }
.sel-action.primary { color: var(--accent); }
.sel-action.primary:hover { background: var(--accent-soft); }

/* ---- Pagination (gallery) ---- */
.gallery-pager {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    margin: 28px 0 8px;
    flex-wrap: wrap;
}
.pager-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-2);
    border-radius: var(--radius-pill);
    padding: 8px 14px;
    font-weight: 550;
    font-size: 13.5px;
    cursor: pointer;
    transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.pager-btn:hover:not(:disabled) { background: var(--surface-2); color: var(--text); border-color: var(--border-strong); }
.pager-btn:disabled { opacity: 0.45; cursor: default; }
.pager-info { color: var(--text-3); font-size: 13px; }

/* ============================================================================
   7. Filters popover
   ============================================================================ */
.filter-menu {
    width: 300px;
    padding: 10px;
    max-height: min(70vh, 560px);
    overflow-y: auto;
}
.filter-menu .fm-section { padding: 6px 4px 10px; }
.filter-menu .fm-section + .fm-section { border-top: 1px solid var(--border); }
.filter-menu .fm-title {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--text-3);
    margin: 0 0 8px;
}
.filter-menu .fm-grid { display: flex; flex-wrap: wrap; gap: 6px; }
.fm-opt {
    border: 1px solid var(--border-strong);
    background: var(--surface);
    color: var(--text-2);
    border-radius: var(--radius-pill);
    padding: 6px 12px;
    font-size: 13px;
    font-weight: 550;
    cursor: pointer;
    transition: all var(--dur) var(--ease);
}
.fm-opt:hover { border-color: var(--accent); color: var(--accent); }
.fm-opt.active { background: var(--accent); border-color: var(--accent); color: #fff; }
[data-theme="dark"] .fm-opt.active { color: #0e0e12; }
.fm-custom { display: flex; gap: 6px; align-items: center; margin-top: 8px; }
.fm-custom input { background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-sm); color: var(--text); padding: 6px 8px; font-size: 13px; }
.fm-custom input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }
.fm-footer { display: flex; justify-content: space-between; gap: 8px; padding: 10px 2px 2px; border-top: 1px solid var(--border); margin-top: 4px; }

/* Sort menu */
.sort-menu { min-width: 190px; }
.sort-menu .dropdown-item.active { background: var(--accent-soft); color: var(--accent); }
.sort-menu .dropdown-item.active .icon { color: var(--accent); }

/* ============================================================================
   8. Image viewer (lightbox)
   ============================================================================ */
.viewer {
    position: fixed;
    inset: 0;
    z-index: 2000;
    background: var(--viewer-bg);
    display: none;
    flex-direction: column;
}
.viewer.open { display: flex; animation: fade-in var(--dur) var(--ease); }

.viewer-top {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 18px;
    color: #e8e8ee;
    position: relative;
    z-index: 5;
}
.viewer-top .v-title {
    font-weight: 600;
    font-size: 14.5px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}
.viewer-top .v-index { color: rgba(255,255,255,0.5); font-size: 13px; white-space: nowrap; }

.viewer-stage {
    flex: 1;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    padding: 0 12px;
    cursor: zoom-in;
}
.viewer-stage.zoomed {
    cursor: grab;
    overflow: hidden;
    justify-content: flex-start;
    align-items: flex-start;
    touch-action: none;
}
.viewer-stage.dragging,
.viewer-stage.dragging .viewer-img { cursor: grabbing; }
.viewer-img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 4px;
    transition: transform 0.25s var(--ease);
    box-shadow: var(--shadow-xl);
}
.viewer-stage.zoomed .viewer-img {
    transform: scale(2);
    transform-origin: 0 0;
    cursor: grab;
    transition: none; /* panning must be instant, no easing lag */
}

/* Video player in the viewer */
.viewer-video {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    border-radius: 6px;
    box-shadow: var(--shadow-xl);
    background: #000;
    outline: none;
}
.viewer-stage .viewer-video { cursor: default; }

.viewer-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 46px; height: 46px;
    border-radius: 50%;
    border: none;
    background: rgba(255,255,255,0.1);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 5;
    transition: background-color var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.viewer-nav:hover { background: rgba(255,255,255,0.22); }
.viewer-nav:active { transform: translateY(-50%) scale(0.92); }
.viewer-nav.prev { left: 16px; }
.viewer-nav.next { right: 16px; }
.viewer-nav.hidden { opacity: 0; pointer-events: none; }

.viewer-bottom {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 14px;
    position: relative;
    z-index: 5;
}
.v-ctrl {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 44px;
    padding: 0 16px;
    border-radius: var(--radius-pill);
    border: none;
    background: rgba(255,255,255,0.1);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    color: #f0f0f4;
    font-weight: 550;
    font-size: 14px;
    cursor: pointer;
    transition: background-color var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.v-ctrl:hover { background: rgba(255,255,255,0.2); }
.v-ctrl:active { transform: scale(0.95); }
.v-ctrl.icon-only { width: 44px; padding: 0; }
.v-ctrl.faved { color: #ff5d73; }
.v-ctrl.faved .icon { fill: currentColor; stroke-width: 0; }
.v-ctrl.danger:hover { background: var(--danger); color: #fff; }

/* Topbar buttons in the viewer */
.viewer-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 42px; height: 42px;
    border-radius: 12px;
    border: none;
    background: transparent;
    color: #e8e8ee;
    cursor: pointer;
    transition: background-color var(--dur) var(--ease);
}
.viewer-btn:hover { background: rgba(255,255,255,0.12); }
.viewer-btn.faved { color: #ff5d73; }
.viewer-btn.faved .icon { fill: currentColor; stroke-width: 0; }

/* Viewer dropdown */
.viewer .dropdown-menu {
    background: #20202a;
    border-color: #30303c;
}
.viewer .dropdown-menu .dropdown-item { color: #eee; }
.viewer .dropdown-menu .dropdown-item:hover { background: rgba(255,255,255,0.08); }
.viewer .dropdown-menu .dropdown-item.text-danger { color: #ff7b80; }
.viewer .dropdown-menu .dropdown-divider { border-color: #30303c; }

/* ============================================================================
   9. Info panel (slide-out)
   ============================================================================ */
.info-panel {
    position: fixed;
    top: 0; right: 0; bottom: 0;
    width: min(400px, 92vw);
    background: var(--surface);
    border-left: 1px solid var(--border);
    box-shadow: var(--shadow-xl);
    z-index: 2001;
    transform: translateX(102%);
    transition: transform 0.28s var(--ease);
    display: flex;
    flex-direction: column;
}
.info-panel.open { transform: translateX(0); }
.info-panel .ip-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
}
.info-panel .ip-head h3 { margin: 0; font-size: 16px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.info-panel .ip-scroll { flex: 1; overflow-y: auto; padding: 16px; }
.info-panel .ip-foot { padding: 12px 16px; border-top: 1px solid var(--border); display: flex; gap: 8px; }

.ip-thumb {
    width: 100%;
    aspect-ratio: 16 / 10;
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--surface-2);
    margin-bottom: 16px;
}
.ip-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }

.ip-block { margin-bottom: 20px; }
.ip-block-title {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--text-3);
    margin: 0 0 10px;
}

.ip-props { display: flex; flex-direction: column; }
.ip-prop {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 0;
    border-bottom: 1px dashed var(--border);
    font-size: 13.5px;
}
.ip-prop:last-child { border-bottom: none; }
.ip-prop .k { color: var(--text-3); flex-shrink: 0; }
.ip-prop .v { color: var(--text); font-weight: 550; text-align: right; word-break: break-all; }
.ip-prop .v.mono { font-family: var(--font-mono); font-size: 12.5px; }

.ip-field { margin-bottom: 12px; }

.ip-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.ip-tag {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: var(--accent-soft);
    color: var(--accent);
    border-radius: var(--radius-pill);
    padding: 4px 10px;
    font-size: 12.5px;
    font-weight: 550;
}
.ip-tag .tag-x { display: inline-flex; align-items: center; justify-content: center; width: 15px; height: 15px; border-radius: 50%; border: none; background: transparent; color: inherit; cursor: pointer; padding: 0; }
.ip-tag .tag-x:hover { background: var(--accent-soft-2); }

.ip-share { border: 1px solid var(--border); border-radius: var(--radius); padding: 10px; margin-bottom: 8px; }
.ip-share .url-row { display: flex; align-items: center; gap: 6px; }
.ip-share .url-row a { flex: 1; font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ip-share .url-row .badge { flex-shrink: 0; }
.ip-share .share-meta { font-size: 12px; color: var(--text-3); margin-top: 4px; }

/* ============================================================================
   10. Upload drawer
   ============================================================================ */
.upload-drawer {
    position: fixed;
    top: 0; right: 0; bottom: 0;
    width: min(460px, 100vw);
    background: var(--surface);
    border-left: 1px solid var(--border);
    box-shadow: var(--shadow-xl);
    z-index: 2001;
    transform: translateX(102%);
    transition: transform 0.28s var(--ease);
    display: flex;
    flex-direction: column;
}
.upload-drawer.open { transform: translateX(0); }
.upload-drawer .ud-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
}
.upload-drawer .ud-head h3 { margin: 0; font-size: 16px; flex: 1; }
.upload-drawer .ud-body { flex: 1; overflow-y: auto; padding: 16px; }
.upload-drawer .ud-foot { padding: 12px 16px; border-top: 1px solid var(--border); display: flex; gap: 8px; align-items: center; }

.dropzone {
    border: 2px dashed var(--border-strong);
    border-radius: var(--radius-lg);
    padding: 34px 20px;
    text-align: center;
    color: var(--text-2);
    cursor: pointer;
    transition: border-color var(--dur) var(--ease), background-color var(--dur) var(--ease), transform var(--dur) var(--ease);
    margin-bottom: 16px;
    background: var(--surface-2);
}
.dropzone:hover, .dropzone.dragover { border-color: var(--accent); background: var(--accent-soft); }
.dropzone.dragover { transform: scale(1.01); }
.dropzone .dz-icon {
    width: 56px; height: 56px;
    border-radius: 50%;
    background: var(--surface);
    box-shadow: var(--shadow-sm);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--accent);
    margin-bottom: 12px;
}
.dropzone .dz-main { font-weight: 600; font-size: 15px; color: var(--text); margin-bottom: 4px; }
.dropzone .dz-sub { font-size: 13px; color: var(--text-3); }
.dropzone .dz-limit {
    margin-top: 8px;
    display: inline-block;
    font-size: 12px;
    font-weight: 600;
    color: var(--accent);
    background: var(--accent-soft);
    padding: 3px 12px;
    border-radius: var(--radius-pill);
}

.ud-queue { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }
.upload-item {
    display: flex;
    gap: 12px;
    align-items: center;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px;
}
.upload-item.failed { border-color: var(--danger); background: var(--danger-soft); }
.upload-item .ui-thumb {
    width: 52px; height: 52px;
    border-radius: 10px;
    overflow: hidden;
    flex-shrink: 0;
    background: var(--surface-3);
}
.upload-item .ui-thumb img,
.upload-item .ui-thumb video { width: 100%; height: 100%; object-fit: cover; display: block; }
.upload-item .ui-main { flex: 1; min-width: 0; }
.upload-item .ui-name { font-size: 13px; font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-item .ui-status { font-size: 12px; color: var(--text-3); margin-top: 2px; }
.upload-item .ui-status.done { color: var(--success); }
.upload-item .ui-status.err { color: var(--danger); }
.upload-item .ui-bar { height: 5px; border-radius: var(--radius-pill); background: var(--surface-3); overflow: hidden; margin-top: 6px; }
.upload-item .ui-bar > span { display: block; height: 100%; width: 0; background: var(--accent); border-radius: var(--radius-pill); transition: width 0.15s ease; }
.upload-item .ui-remove {
    width: 30px; height: 30px;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: var(--text-3);
    cursor: pointer;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.upload-item .ui-remove:hover { background: var(--surface-3); color: var(--text); }

/* ============================================================================
   11. Empty states
   ============================================================================ */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 64px 20px;
    color: var(--text-2);
}
.empty-state .es-illustration {
    width: 96px; height: 96px;
    border-radius: 28px;
    background: linear-gradient(135deg, var(--accent-soft), var(--surface-2));
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent);
    margin-bottom: 20px;
    box-shadow: var(--shadow-sm);
}
.empty-state .es-illustration .icon { display: block; }
.empty-state h2 { font-size: 20px; color: var(--text); margin: 0 0 6px; letter-spacing: -0.01em; }
.empty-state p { color: var(--text-3); max-width: 380px; margin: 0 0 20px; }

/* ============================================================================
   12. Albums + tags
   ============================================================================ */
.albums-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 18px;
}
@media (max-width: 768px) { .albums-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; } }

.album-card {
    position: relative;
    border-radius: var(--radius-lg);
    overflow: hidden;
    aspect-ratio: 4 / 3;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
    display: block;
    border: none;
    padding: 0;
    width: 100%;
    text-align: left;
    background: var(--surface-2);
}
.album-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.album-card .ac-cover { position: absolute; inset: 0; }
.album-card .ac-cover img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform 0.45s var(--ease); }
.album-card:hover .ac-cover img { transform: scale(1.05); }
.album-card .ac-cover.empty {
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--surface-3), var(--surface-2));
    color: var(--text-3);
}
.album-card .ac-shade {
    position: absolute;
    inset: 0;
    background: linear-gradient(to top, rgba(0,0,0,0.72) 0%, rgba(0,0,0,0.12) 46%, transparent 70%);
}
.album-card .ac-body {
    position: absolute;
    left: 0; right: 0; bottom: 0;
    padding: 14px 16px;
    color: #fff;
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 8px;
}
.album-card .ac-name { font-weight: 650; font-size: 15.5px; letter-spacing: -0.01em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.album-card .ac-count { font-size: 12.5px; color: rgba(255,255,255,0.85); }
.album-card .ac-menu {
    width: 34px; height: 34px;
    border-radius: 50%;
    border: none;
    background: rgba(0,0,0,0.4);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: background-color var(--dur) var(--ease);
}
.album-card .ac-menu:hover { background: rgba(0,0,0,0.65); }

/* Tags page */
.tags-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
    gap: 14px;
}
@media (max-width: 768px) { .tags-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; } }
.tag-card {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    cursor: pointer;
    transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.tag-card:hover { border-color: var(--accent); box-shadow: var(--shadow-md); transform: translateY(-2px); }
.tag-card .tc-icon {
    width: 40px; height: 40px;
    border-radius: 12px;
    background: var(--accent-soft);
    color: var(--accent);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.tag-card .tc-name { font-weight: 600; font-size: 14.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag-card .tc-count { font-size: 12.5px; color: var(--text-3); }

/* ============================================================================
   13. Dashboard + stat cards
   ============================================================================ */
.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    box-shadow: var(--shadow-xs);
    transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.stat-card .sc-icon {
    width: 48px; height: 48px;
    border-radius: 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.stat-card .sc-icon.indigo { background: var(--accent-soft); color: var(--accent); }
.stat-card .sc-icon.green { background: var(--success-soft); color: var(--success); }
.stat-card .sc-icon.amber { background: var(--warning-soft); color: var(--warning); }
.stat-card .sc-icon.red { background: var(--danger-soft); color: var(--danger); }
.stat-card .sc-label { font-size: 13px; color: var(--text-2); font-weight: 550; }
.stat-card .sc-value { font-size: 26px; font-weight: 750; letter-spacing: -0.02em; color: var(--text); line-height: 1.1; }

/* ============================================================================
   14. Auth pages
   ============================================================================ */
.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background:
        radial-gradient(1200px 600px at 85% -10%, var(--accent-soft) 0%, transparent 55%),
        radial-gradient(900px 500px at -10% 110%, var(--accent-soft) 0%, transparent 50%),
        var(--bg);
}
.auth-card {
    width: 100%;
    max-width: 400px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    padding: 34px 32px;
}
.auth-card .auth-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.auth-card .auth-brand .brand-mark {
    width: 38px; height: 38px;
    border-radius: 12px;
    background: linear-gradient(135deg, #5b7cfa, #7c4dff);
    display: inline-flex; align-items: center; justify-content: center;
    color: #fff;
}
.auth-card .auth-brand .brand-mark .icon { color: #fff; }
.auth-card .auth-brand .auth-name { font-weight: 750; font-size: 18px; letter-spacing: -0.01em; }
.auth-card h1 { font-size: 20px; margin: 18px 0 4px; letter-spacing: -0.01em; }
.auth-card .auth-sub { color: var(--text-3); font-size: 13.5px; margin-bottom: 22px; }

/* ============================================================================
   15. Custom confirm dialog
   ============================================================================ */
.dialog-overlay {
    position: fixed;
    inset: 0;
    background: var(--overlay-bg);
    z-index: 3000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    opacity: 0;
    transition: opacity var(--dur) var(--ease);
}
.dialog-overlay.open { opacity: 1; }
.dialog-overlay.closing { opacity: 0; }
.dialog {
    width: 100%;
    max-width: 420px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    padding: 24px;
    transform: scale(0.94) translateY(8px);
    transition: transform var(--dur) var(--ease);
}
.dialog-overlay.open .dialog { transform: scale(1) translateY(0); }
.dialog .dlg-icon {
    width: 48px; height: 48px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 16px;
}
.dialog .dlg-icon.danger { background: var(--danger-soft); color: var(--danger); }
.dialog .dlg-icon.warning { background: var(--warning-soft); color: var(--warning); }
.dialog .dlg-icon.info { background: var(--accent-soft); color: var(--accent); }
.dialog h3 { font-size: 17px; margin: 0 0 6px; letter-spacing: -0.01em; }
.dialog .dlg-msg { color: var(--text-2); font-size: 14px; margin-bottom: 20px; }
.dialog .dlg-msg .dlg-em { color: var(--text); font-weight: 600; }
.dialog .dlg-actions { display: flex; justify-content: flex-end; gap: 10px; }

/* ============================================================================
   16. Toast wrap
   ============================================================================ */
.toast-wrap {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 4000;
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-width: min(360px, calc(100vw - 32px));
}
.app-toast {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-left: 3px solid var(--accent);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 12px 16px;
    font-size: 14px;
    font-weight: 550;
    animation: slide-up 0.25s var(--ease);
}
.app-toast.success { border-left-color: var(--success); }
.app-toast.success .app-toast-icon { color: var(--success); }
.app-toast.error { border-left-color: var(--danger); }
.app-toast.error .app-toast-icon { color: var(--danger); }
.app-toast .app-toast-icon { color: var(--accent); flex-shrink: 0; }
.app-toast .app-toast-msg { flex: 1; }
.app-toast .app-toast-x {
    border: none;
    background: transparent;
    color: var(--text-3);
    cursor: pointer;
    width: 24px; height: 24px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
}
.app-toast .app-toast-x:hover { background: var(--surface-2); color: var(--text); }

/* ============================================================================
   17. Page headers + misc
   ============================================================================ */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head h1 { margin: 0; font-size: 22px; letter-spacing: -0.02em; }
.page-head .page-sub { color: var(--text-3); font-size: 13px; margin-top: 2px; }

.settings-card { max-width: 860px; }

/* Mobile bottom sheet */
.bottom-sheet {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    background: var(--surface);
    border-top: 1px solid var(--border);
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    box-shadow: var(--shadow-xl);
    z-index: 2002;
    transform: translateY(103%);
    transition: transform 0.28s var(--ease);
    padding: 12px 16px calc(16px + env(safe-area-inset-bottom));
}
.bottom-sheet.open { transform: translateY(0); }
.bottom-sheet .bs-handle { width: 40px; height: 4px; border-radius: var(--radius-pill); background: var(--border-strong); margin: 0 auto 12px; }
.bs-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.bs-action {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    border: none;
    background: transparent;
    color: var(--text-2);
    font-size: 12px;
    font-weight: 550;
    padding: 10px 4px;
    border-radius: var(--radius);
    cursor: pointer;
}
.bs-action .icon { color: var(--text-2); }
.bs-action:hover { background: var(--surface-2); color: var(--text); }
.bs-action.danger { color: var(--danger); }
.bs-action.danger .icon { color: var(--danger); }
.bs-action.primary { color: var(--accent); }
.bs-action.primary .icon { color: var(--accent); }

/* Footer (minimal) */
.app-footer {
    padding: 18px 20px 24px;
    text-align: center;
    color: var(--text-3);
    font-size: 12.5px;
    border-top: 1px solid var(--border);
    margin-top: 24px;
}

/* ============================================================================
   18. Animations
   ============================================================================ */
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop-in { from { opacity: 0; transform: scale(0.85); } to { opacity: 1; transform: scale(1); } }
@keyframes slide-up { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }
@keyframes slide-down { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ============================================================================
   19. Responsive
   ============================================================================ */
@media (max-width: 991.98px) {
    .app-sidebar {
        transform: translateX(-103%);
        box-shadow: var(--shadow-xl);
    }
    .app-sidebar.mobile-open { transform: translateX(0); }
    .app-overlay.show { display: block; }
    .app-main, .app-sidebar.collapsed + .app-main, .app-main.sidebar-collapsed { margin-left: 0; }
}

@media (max-width: 767.98px) {
    :root { --topbar-h: 56px; }
    .topbar { padding: 0 12px; gap: 8px; flex-wrap: wrap; height: auto; min-height: var(--topbar-h); padding-top: 8px; }
    .topbar-search { order: 3; flex-basis: 100%; max-width: none; margin: 0 0 10px; }
    .topbar-actions { margin-left: auto; }
    .topbar-title { font-size: 16px; }
    .btn-upload span.upload-label { display: none; }
    .btn-upload { padding: 0 14px; }
    .app-content { padding: 14px 12px; }
    .chip-row { padding: 10px 12px 0; }
    .viewer-nav { width: 40px; height: 40px; }
    .viewer-nav.prev { left: 6px; }
    .viewer-nav.next { right: 6px; }
    .v-ctrl { padding: 0 12px; font-size: 13px; height: 42px; }
    .v-ctrl .v-label { display: none; }
    .viewer-bottom { gap: 8px; }
    .selection-bar { margin-top: 12px; }
    .stat-card .sc-value { font-size: 22px; }
    .auth-card { padding: 28px 22px; }
}

@media (max-width: 419.98px) {
    .topbar-actions .icon-btn:not(.always-show) { display: none; }
}

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

/* ============================================================================
   20. Misc (avatar, theme icons, public topbar)
   ============================================================================ */
.user-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px; height: 34px;
    flex-shrink: 0;
    border-radius: 50%;
    background: linear-gradient(135deg, #5b7cfa, #7c4dff);
    color: #fff;
    font-weight: 700;
    font-size: 14px;
    letter-spacing: 0;
    box-shadow: var(--shadow-sm);
}
.user-avatar-btn { width: 40px; height: 40px; border-radius: 50%; }

.user-card { display: block; padding: 10px 12px !important; }
.user-card-name { font-weight: 650; font-size: 14px; color: var(--text); }
.user-card-email { font-size: 12.5px; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Theme icon visibility */
[data-theme="light"] .theme-icon-moon { display: none !important; }
[data-theme="light"] .theme-icon-sun { display: inline-flex !important; }
[data-theme="dark"] .theme-icon-sun { display: none !important; }
[data-theme="dark"] .theme-icon-moon { display: inline-flex !important; }

/* Public layout */
.topbar-public { justify-content: space-between; }
.topbar-public .sidebar-brand { padding: 6px 0; }
.app-content-public { max-width: 1080px; margin: 0 auto; }

/* Landing page hero */
.hero {
    padding: 80px 16px 40px;
    text-align: center;
}
.hero .hero-mark {
    width: 88px; height: 88px;
    margin: 0 auto 24px;
    border-radius: 28px;
    background: linear-gradient(135deg, #5b7cfa, #7c4dff);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    box-shadow: var(--shadow-lg);
}
.hero .hero-mark .icon { display: block; }
.hero h1 { font-size: clamp(30px, 5vw, 44px); font-weight: 750; letter-spacing: -0.03em; margin-bottom: 12px; }
.hero p { color: var(--text-2); font-size: 16.5px; max-width: 520px; margin: 0 auto 26px; }

.feature-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 16px; margin-top: 40px; }
.feature-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 22px;
    transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.feature-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); }
.feature-card .fc-icon {
    width: 44px; height: 44px;
    border-radius: 13px;
    background: var(--accent-soft);
    color: var(--accent);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 14px;
}
.feature-card h3 { font-size: 15.5px; margin-bottom: 6px; }
.feature-card p { color: var(--text-3); font-size: 13.5px; margin: 0; }

/* Search keyboard hint */
.sp-kbd {
    margin-left: auto;
    font-size: 11px;
    color: var(--text-3);
    border: 1px solid var(--border);
    border-radius: 5px;
    padding: 1px 6px;
    background: var(--surface-2);
}

/* ============================================================================
   21. Panels backdrop + album picker + info panel on mobile
   ============================================================================ */
.panel-backdrop {
    position: fixed;
    inset: 0;
    background: var(--overlay-bg);
    z-index: 1999;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s var(--ease);
}
.panel-backdrop.show { opacity: 1; pointer-events: auto; }

.album-picker-list .ap-item {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--border);
    background: var(--surface);
    border-radius: var(--radius);
    color: var(--text);
    font-weight: 550;
    cursor: pointer;
    text-align: left;
    transition: border-color var(--dur) var(--ease), background-color var(--dur) var(--ease);
}
.album-picker-list .ap-item:hover { border-color: var(--accent); background: var(--accent-soft); }
.album-picker-list .ap-item .ap-icon { color: var(--text-3); }
.album-picker-list .ap-item .ap-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.album-picker-list .ap-item .ap-count { color: var(--text-3); font-size: 12.5px; font-weight: 500; }

/* Info panel becomes a bottom sheet on small phones */
@media (max-width: 575.98px) {
    .info-panel {
        top: auto;
        bottom: 0;
        width: 100%;
        max-height: 84vh;
        border-left: none;
        border-top: 1px solid var(--border);
        border-radius: var(--radius-xl) var(--radius-xl) 0 0;
        transform: translateY(103%);
        padding-bottom: env(safe-area-inset-bottom);
    }
    .info-panel.open { transform: translateY(0); }
    .ip-scroll { padding-bottom: 20px; }
}

/* ============================================================================
   22. Recycle bin / checkboxes / EXIF / album sharing / public links
   ============================================================================ */

/* Persistent selection checkbox on each tile */
.tile-check {
    position: absolute;
    top: 10px; left: 10px;
    width: 26px; height: 26px;
    border-radius: 50%;
    background: rgba(20, 20, 26, 0.5);
    border: 2px solid rgba(255, 255, 255, 0.92);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 3;
    cursor: pointer;
    padding: 0;
    transition: background-color 0.15s var(--ease), border-color 0.15s var(--ease), transform 0.15s var(--ease);
}
.tile-check:hover { transform: scale(1.08); }
.tile-check .icon { display: none; }
.tile.selected .tile-check { background: var(--accent); border-color: var(--accent); }
.tile.selected .tile-check .icon { display: block; }

/* Albums page tabs */
.albums-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
    scrollbar-width: none;
}
.albums-tabs::-webkit-scrollbar { display: none; }
.albums-tabs .at-tab {
    border: none;
    background: transparent;
    color: var(--text-2);
    font-weight: 550;
    font-size: 14px;
    padding: 10px 16px;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    white-space: nowrap;
    margin-bottom: -1px;
    transition: color var(--dur) var(--ease);
}
.albums-tabs .at-tab:hover { color: var(--text); }
.albums-tabs .at-tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* Shared badge on album covers */
.ac-share-badge {
    position: absolute;
    top: 12px; right: 12px;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: rgba(0, 0, 0, 0.5);
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
    color: #fff;
    border-radius: 999px;
    padding: 4px 10px;
    font-size: 11.5px;
    font-weight: 600;
    z-index: 2;
}
.ac-owner {
    position: absolute;
    top: 12px; left: 12px;
    background: rgba(0,0,0,0.5);
    color: #fff;
    border-radius: 999px;
    padding: 4px 10px;
    font-size: 11.5px;
    font-weight: 600;
    z-index: 2;
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
}

/* Share modal */
.share-user-row { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--border); }
.share-user-row:last-child { border-bottom: none; }
.share-user-av {
    width: 30px; height: 30px;
    border-radius: 50%;
    background: var(--accent-soft);
    color: var(--accent);
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

/* Public links page */
.pub-link-item { display: flex; align-items: center; gap: 14px; padding: 14px 16px; }
.pub-link-item + .pub-link-item { border-top: 1px solid var(--border); }
.pub-link-item .pl-icon {
    width: 40px; height: 40px;
    border-radius: 12px;
    background: var(--accent-soft);
    color: var(--accent);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.pub-link-item .pl-main { flex: 1; min-width: 0; }
.pub-link-item .pl-name { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pub-link-item .pl-url { font-size: 12px; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pub-link-item .pl-meta { font-size: 12px; color: var(--text-3); margin-top: 2px; }
.pub-link-item .pl-actions { display: flex; gap: 6px; flex-shrink: 0; }
