/* ==========================================================================
   OVERLAYS — JS-built UI that floats over the page: toast, account drawer,
   auth forms, collection tab, account modal, tooltips, mobile filter sheet.
   Ported from the v2 stylesheet; it consumes the legacy token names
   (--ink-primary, --accent-gold, …), which style.css aliases onto the
   Exhibit design tokens. Restyle here by changing tokens, not hex values.
   ========================================================================== */

.toast-notification {
    position: fixed; bottom: -80px; left: 50%; transform: translateX(-50%);
    background: var(--ink); color: var(--paper); padding: 15px 30px;
    border: 2px solid var(--accent-gold); font-family: var(--font-mono);
    font-size: 1.1rem; z-index: 999999;
    transition: bottom 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    box-shadow: 0 10px 30px rgba(0,0,0,0.6); pointer-events: none; white-space: nowrap;
}
.toast-notification.show { bottom: 40px; }

/* ==========================================================================
   15. USER ACCOUNT DRAWER
   ========================================================================== */
.user-drawer {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10001;
    pointer-events: none;
}

.user-drawer[aria-hidden="false"] {
    pointer-events: auto;
}

.user-drawer-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.user-drawer[aria-hidden="false"] .user-drawer-overlay {
    opacity: 1;
}

.user-drawer-content {
    position: absolute;
    top: 0;
    right: 0;
    width: 90%;
    max-width: 400px;
    height: 100%;
    background: var(--bg-parchment);
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.3);
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    z-index: 10002;
}

.user-drawer[aria-hidden="false"] .user-drawer-content {
    transform: translateX(0);
}

.user-drawer-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem;
    border-bottom: 2px solid var(--ink-primary);
    background: var(--ink-primary);
    color: var(--bg-parchment);
}

.user-drawer-header h2 {
    margin: 0;
    font-family: var(--font-mono);
    font-size: 1.5rem;
    color: var(--accent-gold);
    border: none;
}

.user-drawer-close {
    background: transparent;
    border: 2px solid var(--bg-parchment);
    border-radius: 50%;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    padding: 0;
    color: var(--bg-parchment);
}

.user-drawer-close:hover {
    background: var(--bg-parchment);
    color: var(--ink-primary);
    transform: rotate(90deg);
}

.user-drawer-close svg {
    width: 20px;
    height: 20px;
}

.user-drawer-tabs {
    display: flex;
    border-bottom: 1px solid var(--ink-secondary);
    background: var(--bg-darker);
}

.user-drawer-tab {
    flex: 1;
    padding: 1rem;
    background: transparent;
    border: none;
    border-bottom: 3px solid transparent;
    color: var(--ink-primary);
    font-family: var(--font-mono);
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.user-drawer-tab:hover {
    background: rgba(62, 39, 35, 0.1);
}

.user-drawer-tab.active {
    border-bottom-color: var(--accent-gold);
    color: var(--accent-gold);
    font-weight: bold;
}

.user-drawer-body {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
}

.user-drawer-tab-content {
    display: none;
}

.user-drawer-tab-content.active {
    display: block;
}

@media (max-width: 600px) {
    .user-drawer-content {
        width: 100%;
        max-width: 100%;
    }
}

/* ==========================================================================
   USER ACCOUNT AUTHENTICATION FORMS
   ========================================================================== */

.auth-landing {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.auth-view-toggle {
    display: flex;
    gap: 0.5rem;
    border-bottom: 1px solid var(--ink-secondary);
    margin-bottom: 1rem;
}

.auth-toggle-btn {
    flex: 1;
    padding: 0.75rem 1rem;
    background: transparent;
    border: none;
    border-bottom: 3px solid transparent;
    color: var(--ink-primary);
    font-family: var(--font-mono);
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.auth-toggle-btn:hover {
    background: rgba(62, 39, 35, 0.05);
}

.auth-toggle-btn.active {
    border-bottom-color: var(--accent-gold);
    color: var(--accent-gold);
    font-weight: bold;
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.form-group label {
    font-family: var(--font-mono);
    font-size: 0.9rem;
    color: var(--ink-primary);
    font-weight: bold;
}

.form-group input {
    padding: 0.75rem;
    border: 2px solid var(--ink-secondary);
    background: var(--bg-parchment);
    color: var(--ink-primary);
    font-family: var(--font-body);
    font-size: 1rem;
    transition: all 0.2s ease;
}

.form-group input:focus {
    outline: none;
    border-color: var(--accent-gold);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(62, 39, 35, 0.1);
}

.form-group input:invalid:not(:placeholder-shown) {
    border-color: var(--accent-rust);
}

.form-hint {
    font-size: 0.8rem;
    color: var(--ink-secondary);
    font-style: italic;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    font-family: var(--font-body);
    font-size: 1rem;
    color: var(--ink-primary);
}

.checkbox-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: var(--accent-gold);
}

.checkbox-label span {
    user-select: none;
}

.form-actions {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-top: 0.5rem;
}

.btn-auth-primary {
    padding: 0.75rem 1.5rem;
    background: var(--ink-primary);
    color: var(--bg-parchment);
    border: 2px solid var(--ink-primary);
    font-family: var(--font-mono);
    font-size: 1rem;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-auth-primary:hover:not(:disabled) {
    background: var(--accent-gold);
    border-color: var(--accent-gold);
    color: var(--ink-primary);
}

.btn-auth-primary:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    position: relative;
}

.btn-auth-primary:disabled::after {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    top: 50%;
    left: 50%;
    margin-left: -8px;
    margin-top: -8px;
    border: 2px solid var(--bg-parchment);
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.btn-auth-secondary {
    padding: 0.6rem 1.25rem;
    background: transparent;
    color: var(--ink-primary);
    border: 2px solid var(--ink-primary);
    font-family: var(--font-mono);
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-auth-secondary:hover {
    background: var(--ink-primary);
    color: var(--bg-parchment);
}

.btn-auth-danger {
    padding: 0.6rem 1.25rem;
    background: transparent;
    color: var(--accent-rust);
    border: 2px solid var(--accent-rust);
    font-family: var(--font-mono);
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-top: 0.5rem;
}

.btn-auth-danger:hover {
    background: var(--accent-rust);
    color: var(--bg-parchment);
}

.auth-link {
    color: var(--ink-primary);
    text-decoration: underline;
    font-size: 0.9rem;
    text-align: center;
    transition: color 0.2s ease;
}

.auth-link:hover {
    color: var(--accent-gold);
}

.form-error {
    padding: 0.75rem;
    background: rgba(200, 50, 50, 0.1);
    border: 1px solid var(--accent-rust);
    color: var(--accent-rust);
    font-size: 0.9rem;
    border-radius: 4px;
    animation: slideIn 0.3s ease-out;
    transition: all 0.2s ease;
}

.form-success {
    padding: 0.75rem;
    background: var(--card);
    border: 1.5px solid var(--ink);
    color: var(--ink);
    font-size: 1rem;
    border-radius: 0;
    animation: slideIn 0.3s ease-out;
    transition: all 0.2s ease;
}

.form-message {
    padding: 0.75rem;
    font-size: 0.9rem;
    border-radius: 4px;
    margin-top: 1rem;
}

.form-message.form-error {
    background: rgba(200, 50, 50, 0.1);
    border: 1px solid var(--accent-rust);
    color: var(--accent-rust);
}

.form-message.form-info {
    background: rgba(62, 39, 35, 0.1);
    border: 1px solid var(--ink-secondary);
    color: var(--ink-primary);
}

.form-info {
    padding: 0.75rem;
    background: rgba(62, 39, 35, 0.05);
    border: 1px solid var(--ink-secondary);
    color: var(--ink-primary);
    font-size: 0.9rem;
    border-radius: 4px;
    font-style: italic;
}

/* Logged in view */
.auth-logged-in {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.user-info {
    padding: 1rem;
    background: rgba(62, 39, 35, 0.05);
    border: 1px solid var(--ink-secondary);
    border-radius: 4px;
}

.user-email {
    font-family: var(--font-body);
    font-size: 1.1rem;
    color: var(--ink-primary);
    margin-bottom: 0.5rem;
    word-break: break-all;
}

.user-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.status-badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: 12px;
    font-size: 0.85rem;
    font-family: var(--font-mono);
    font-weight: bold;
}

.status-badge.verified {
    background: transparent;
    color: var(--ink);
    border: 1.5px solid var(--ink);
    border-radius: 0;
}

.status-badge.unverified {
    background: transparent;
    color: var(--red);
    border: 1.5px dashed var(--red);
    border-radius: 0;
}

.user-actions {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

/* ==========================================================================
   COLLECTION TAB STYLES
   ========================================================================== */

.collection-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.collection-header h3 {
    font-family: var(--font-mono);
    font-size: 1.2rem;
    color: var(--ink-primary);
    margin: 0;
    border-bottom: 2px solid var(--accent-gold);
    display: inline-block;
    padding-bottom: 0.5rem;
}

.collection-view-toggle {
    background: var(--bg-parchment);
    border: 2px solid var(--accent-gold);
    border-radius: 4px;
    padding: 0.5rem;
    cursor: pointer;
    transition: all 0.2s ease;
    color: var(--ink-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    flex-shrink: 0;
}

.collection-view-toggle:hover {
    background: var(--accent-gold);
    color: #fff;
    transform: scale(1.05);
}

.collection-view-toggle:active {
    transform: scale(0.95);
}

.collection-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1.5rem;
    margin-top: 1rem;
}

/* Dense two-column view */
.collection-grid.dense-view {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
}

.collection-grid.dense-view .collection-card {
    border-radius: 4px;
}

.collection-grid.dense-view .collection-card-image {
    padding-top: 75%; /* Less tall in dense view */
}

.collection-grid.dense-view .collection-card-info {
    padding: 0.5rem;
}

.collection-grid.dense-view .collection-card-name {
    font-size: 0.95rem;
    margin-bottom: 0.25rem;
}

.collection-grid.dense-view .collection-card-ref {
    font-size: 0.75rem;
    margin-bottom: 0.25rem;
}

.collection-grid.dense-view .collection-card-material {
    font-size: 0.7rem;
}

.collection-grid.dense-view .collection-remove-btn {
    width: 24px;
    height: 24px;
    top: 0.25rem;
    right: 0.25rem;
}

.collection-grid.dense-view .collection-remove-btn svg {
    width: 14px;
    height: 14px;
}

.collection-card {
    background: rgba(255, 255, 255, 0.7);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: var(--paper-shadow);
    transition: all 0.3s ease;
    cursor: pointer;
}

.collection-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 15px 35px rgba(62, 39, 35, 0.2);
}

.collection-card-image {
    position: relative;
    width: 100%;
    padding-top: 100%; /* Square aspect ratio */
    overflow: hidden;
    background: var(--bg-darker);
}

.collection-card-image img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.collection-remove-btn {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    background: rgba(200, 50, 50, 0.9);
    color: white;
    border: none;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    z-index: 10;
    padding: 0;
}

.collection-remove-btn:hover {
    background: rgba(200, 50, 50, 1);
    transform: scale(1.1);
}

.collection-remove-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.collection-card-info {
    padding: 1rem;
}

.collection-card-name {
    font-family: var(--font-body);
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--ink-primary);
    margin: 0 0 0.5rem 0;
}

.collection-card-ref {
    font-family: var(--font-mono);
    font-size: 0.85rem;
    color: var(--ink-secondary);
    margin: 0 0 0.25rem 0;
}

.collection-card-material {
    font-family: var(--font-body);
    font-size: 0.9rem;
    color: var(--ink-secondary);
    font-style: italic;
    margin: 0.25rem 0 0 0;
}

.collection-empty,
.collection-loading,
.collection-error {
    text-align: center;
    padding: 3rem 1.5rem;
    color: var(--ink-primary);
}

.collection-empty h3 {
    font-family: var(--font-mono);
    font-size: 1.5rem;
    margin-bottom: 1rem;
    color: var(--ink-primary);
}

.collection-empty p {
    font-family: var(--font-body);
    font-size: 1.1rem;
    margin-bottom: 1.5rem;
    color: var(--ink-secondary);
}

.collection-loading {
    font-family: var(--font-body);
    font-size: 1.1rem;
    color: var(--ink-secondary);
    font-style: italic;
}

.collection-error {
    font-family: var(--font-body);
    font-size: 1rem;
    color: var(--accent-rust);
}

.collection-error p {
    margin: 0;
}

.spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

@media (max-width: 600px) {
    .collection-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        gap: 1rem;
    }
    
    .collection-grid.dense-view {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.5rem;
    }
    
    .collection-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }
    
    .collection-view-toggle {
        width: 32px;
        height: 32px;
        padding: 0.4rem;
    }
    
    .collection-card-info {
        padding: 0.75rem;
    }
    
    .collection-card-name {
        font-size: 1rem;
    }
}

/* ==========================================================================
   ACCOUNT MODAL
   ========================================================================== */
.account-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 20000;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease;
    display: block;
}

.account-modal.active {
    opacity: 1;
    pointer-events: auto;
}

.account-modal-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1;
}

.account-modal-content {
    position: absolute;
    background: var(--bg-parchment);
    border: 2px solid var(--ink-primary);
    box-shadow: 0 -10px 40px rgba(0,0,0,0.3);
    display: flex;
    flex-direction: column;
    max-height: 85vh;
    width: 90%;
    max-width: 600px;
    left: 50%;
    top: 50%;
    z-index: 2;
    transform: translate(-50%, -50%) scale(0.9);
    transition: transform 0.3s ease, opacity 0.3s ease;
    opacity: 0;
    border-radius: 8px;
    overflow: hidden;
}

.account-modal.active .account-modal-content {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
}

/* Mobile: Convert to bottom sheet */
@media (max-width: 850px) {
    .account-modal-content {
        left: 0;
        right: 0;
        top: auto;
        bottom: 0;
        max-width: 100%;
        width: 100%;
        max-height: 90vh;
        border-left: none;
        border-right: none;
        border-top: 3px solid var(--ink-primary);
        border-radius: 20px 20px 0 0;
        transform: translateY(100%);
        opacity: 1;
    }

    .account-modal.active .account-modal-content {
        transform: translateY(0);
    }
}

.account-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem;
    border-bottom: 2px solid var(--ink-primary);
    background: var(--ink-primary);
    color: var(--bg-parchment);
}

.account-modal-header h2 {
    margin: 0;
    font-family: var(--font-mono);
    font-size: 1.2rem;
    color: var(--accent-gold);
    border: none;
}

.account-modal-close {
    background: transparent;
    border: none;
    color: var(--bg-parchment);
    cursor: pointer;
    padding: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.2s;
}

.account-modal-close:hover {
    opacity: 0.7;
}

.account-modal-body {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
}

.account-section {
    margin-bottom: 2rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid rgba(62, 39, 35, 0.2);
}

.account-section:last-child {
    border-bottom: none;
}

.account-section h3 {
    font-family: var(--font-body);
    color: var(--ink-primary);
    margin-top: 0;
    margin-bottom: 1rem;
    border-bottom: 2px solid var(--ink-primary);
    padding-bottom: 0.5rem;
}

.account-main-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 1.5rem;
    border-bottom: 2px solid var(--ink-primary);
    background: var(--bg-darker);
    border-radius: 4px 4px 0 0;
}

.account-main-tab {
    flex: 1;
    background: none;
    border: none;
    padding: 1rem 1.5rem;
    font-family: var(--font-body);
    font-size: 1.1rem;
    color: var(--ink-primary);
    cursor: pointer;
    border-bottom: 3px solid transparent;
    transition: all 0.3s;
    background: transparent;
}

.account-main-tab.active {
    border-bottom-color: var(--ink-primary);
    font-weight: 700;
    background: var(--bg-parchment);
}

.account-main-tab:hover {
    background: rgba(62, 39, 35, 0.1);
}

.account-main-tab.active:hover {
    background: var(--bg-parchment);
}

.account-main-tab-content {
    display: none;
}

.account-main-tab-content.active {
    display: block;
}

.account-tabs {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
    border-bottom: 2px solid var(--ink-primary);
}

.account-tab {
    background: none;
    border: none;
    padding: 0.75rem 1.5rem;
    font-family: var(--font-body);
    font-size: 1.1rem;
    color: var(--ink-primary);
    cursor: pointer;
    border-bottom: 3px solid transparent;
    transition: all 0.3s;
}

.account-tab.active {
    border-bottom-color: var(--ink-primary);
    font-weight: 700;
}

.account-tab:hover {
    background: rgba(62, 39, 35, 0.1);
}

.account-form {
    display: none;
}

.account-form.active {
    display: block;
}

.account-form .form-group {
    margin-bottom: 1.5rem;
}

.account-form .form-group label {
    display: block;
    font-family: var(--font-body);
    font-weight: 700;
    color: var(--ink-primary);
    margin-bottom: 0.5rem;
    font-size: 1.1rem;
}

.account-form .form-group input {
    width: 100%;
    padding: 0.75rem;
    font-family: var(--font-body);
    font-size: 1rem;
    border: 2px solid var(--ink-primary);
    background: #FFF;
    color: var(--ink-primary);
    box-sizing: border-box;
}

.account-form .form-group input:focus {
    outline: none;
    border-color: var(--ink-2);
    box-shadow: 0 0 0 3px rgba(93, 64, 55, 0.1);
}

.btn-account-action {
    padding: 0.75rem 2rem;
    font-family: var(--font-body);
    font-size: 1.1rem;
    font-weight: 700;
    border: 2px solid var(--ink-primary);
    background: var(--ink-primary);
    color: var(--bg-parchment);
    cursor: pointer;
    transition: all 0.3s;
    text-decoration: none;
    display: inline-block;
}

.btn-account-action:hover {
    background: var(--ink-2);
    border-color: var(--ink-2);
}

.preference-item {
    background: #FFF;
    border: 2px solid var(--ink);
    padding: 1.5rem;
    margin-bottom: 1rem;
}

.preference-item h4 {
    font-family: var(--font-body);
    color: var(--ink);
    margin-top: 0;
    margin-bottom: 0.5rem;
}

.preference-item p {
    font-family: var(--font-body);
    color: var(--ink);
    margin: 0.5rem 0;
    font-size: 0.95rem;
}

.preference-toggle {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-top: 1rem;
}

.preference-toggle label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-family: var(--font-body);
    color: var(--ink);
    cursor: pointer;
}

.preference-toggle input[type="checkbox"] {
    width: auto;
    margin: 0;
    cursor: pointer;
}


.account-section .loading {
    text-align: center;
    padding: 2rem;
    color: var(--ink-secondary);
    font-style: italic;
}

#accountAlertContainer {
    margin-bottom: 1rem;
}

#accountAlertContainer .alert {
    padding: 1rem;
    border-radius: 4px;
    margin-bottom: 1rem;
    font-family: var(--font-body);
}

#accountAlertContainer .alert-success {
    background: var(--card);
    color: var(--ink);
    border: 1.5px solid var(--ink);
}

#accountAlertContainer .alert-error {
    background: var(--card);
    color: var(--red-deep);
    border: 1.5px solid var(--red);
    display: block;
}

/* Prevent browser password manager from showing on page load */
.account-form input[readonly] {
    background-color: #fff;
    cursor: text;
}

/* Hide password fields when modal is not active to prevent auto-fill detection */
.account-modal:not(.active) .account-form input[type="password"] {
    position: absolute;
    left: -9999px;
    opacity: 0;
    pointer-events: none;
}

/* Tooltip styles for buttons */
/* Styled tooltip rendered as a fixed-position element (#js-tooltip, created in
   manifest.js) so it escapes overflow/scroll containers like the ledger
   .table-container that previously clipped the CSS ::after tooltip. */
.js-tooltip {
    position: fixed;
    z-index: 4000;
    background: var(--ink-primary);
    color: #fdfaf3;
    padding: 6px 10px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-family: var(--font-mono);
    white-space: nowrap;
    pointer-events: none;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
    opacity: 0;
    transform: translateY(4px);
    transition: opacity 0.15s ease, transform 0.15s ease;
}

.js-tooltip.visible {
    opacity: 1;
    transform: translateY(0);
}

/* Arrow points down toward the target when the tooltip sits above it (default) */
.js-tooltip::after {
    content: '';
    position: absolute;
    left: 50%;
    top: 100%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: var(--ink-primary);
}

/* Flipped below the target (not enough room above) -> arrow points up */
.js-tooltip.below::after {
    top: auto;
    bottom: 100%;
    border-top-color: transparent;
    border-bottom-color: var(--ink-primary);
}

/* ==========================================================================
   20. FLOATING NAVIGATION CLUSTER
   ========================================================================== */

/* Desktop: Left-edge vertical stack */
.nav-cluster {
    position: fixed;
    left: 20px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 998;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.nav-cluster-stack {
    display: flex;
    flex-direction: column;
    gap: 6px;
    background: var(--ink-primary);
    border: 2px solid var(--accent-gold);
    border-radius: 8px;
    padding: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

/* Pagination section */
.nav-pagination {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 0;
    border-bottom: 1px solid rgba(184, 134, 11, 0.3);
}

.nav-page-indicator {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--accent-gold);
    min-width: 36px;
    text-align: center;
    white-space: nowrap;
}

/* Cluster buttons */
.nav-cluster-btn {
    background: transparent;
    border: none;
    color: var(--bg-parchment);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 6px;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.nav-cluster-btn:hover:not(:disabled) {
    background: rgba(184, 134, 11, 0.3);
    color: var(--accent-gold);
}

.nav-cluster-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.nav-arrow {
    width: 28px;
    height: 28px;
}

/* Filters toggle with badge */
.nav-filters-toggle {
    position: relative;
    width: 100%;
    padding: 8px;
}

.nav-filter-badge,
.nav-mobile-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: var(--accent-rust);
    color: white;
    font-family: var(--font-mono);
    font-size: 0.6rem;
    min-width: 16px;
    height: 16px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
}

/* Back to top in cluster */
.nav-back-to-top {
    width: 100%;
    padding: 8px;
    border-top: 1px solid rgba(184, 134, 11, 0.3);
    margin-top: 2px;
}

/* Filter Panel - Desktop (expands from cluster) */
/* Panel is now a sibling of nav-cluster (not a child) so mobile display:none doesn't hide it */
.nav-filter-panel {
    position: fixed;
    left: 90px; /* cluster left (20px) + cluster width (~60px) + gap (10px) */
    top: 50%;
    width: 260px;
    background: var(--ink-primary);
    border: 2px solid var(--accent-gold);
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-50%) translateX(-10px);
    transition: all 0.25s ease;
    z-index: 2001; /* Above sticky nav (2000) */
}

.nav-filter-panel[aria-hidden="false"] {
    opacity: 1;
    visibility: visible;
    transform: translateY(-50%) translateX(0);
}

.nav-filter-panel-content {
    display: flex;
    flex-direction: column;
}

.nav-filter-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    border-bottom: 1px solid rgba(184, 134, 11, 0.3);
}

.nav-filter-title {
    font-family: var(--font-mono);
    font-size: 0.9rem;
    color: var(--accent-gold);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.nav-filter-close {
    background: transparent;
    border: none;
    color: var(--bg-parchment);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.nav-filter-close:hover {
    background: rgba(184, 134, 11, 0.3);
    color: var(--accent-gold);
}

.nav-filter-body {
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.nav-filter-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.nav-filter-label {
    font-family: var(--font-mono);
    font-size: 0.7rem;
    color: var(--bg-parchment);
    opacity: 0.8;
    display: flex;
    align-items: center;
    gap: 6px;
}

.nav-filter-input,
.nav-filter-select {
    background: rgba(245, 230, 202, 0.1);
    border: 1px solid rgba(184, 134, 11, 0.5);
    border-radius: 4px;
    padding: 8px 10px;
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: var(--bg-parchment);
    transition: border-color 0.2s ease;
}

.nav-filter-input:focus,
.nav-filter-select:focus {
    outline: none;
    border-color: var(--accent-gold);
}

.nav-filter-input::placeholder {
    color: rgba(245, 230, 202, 0.5);
}

.nav-filter-select {
    cursor: pointer;
}

.nav-filter-select option {
    background: var(--ink-primary);
    color: var(--bg-parchment);
}

.nav-filter-checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    padding: 6px 0;
}

.nav-filter-checkbox input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--accent-gold);
    cursor: pointer;
}

.nav-checkbox-label {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: var(--bg-parchment);
}

.nav-filter-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    border-top: 1px solid rgba(184, 134, 11, 0.3);
    background: rgba(0, 0, 0, 0.2);
    border-radius: 0 0 6px 6px;
}

.nav-clear-btn {
    background: transparent;
    border: 1px solid var(--accent-rust);
    color: var(--accent-rust);
    font-family: var(--font-mono);
    font-size: 0.7rem;
    padding: 4px 10px;
    border-radius: 3px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.nav-clear-btn:hover {
    background: var(--accent-rust);
    color: white;
}

.nav-filter-stats {
    display: flex;
    gap: 12px;
    font-family: var(--font-mono);
    font-size: 0.65rem;
    color: rgba(245, 230, 202, 0.7);
}

.nav-filter-stats b {
    color: var(--accent-gold);
}

/* Mobile FAB */
.nav-mobile-fab {
    display: none; /* Hidden on desktop */
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 56px;
    height: 56px;
    background: var(--ink-primary);
    border: 2px solid var(--accent-gold);
    border-radius: 50%;
    color: var(--accent-gold);
    cursor: pointer;
    z-index: 998;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    transition: all 0.3s ease;
}

.nav-mobile-fab:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
}

.nav-mobile-fab.active {
    background: var(--accent-gold);
    color: var(--ink-primary);
}

.nav-mobile-badge {
    top: -2px;
    right: -2px;
}

/* Mobile overlay */
.nav-mobile-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 997;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.nav-mobile-overlay[aria-hidden="false"] {
    opacity: 1;
}

/* Mobile Responsive - Switch to FAB + Bottom Sheet */
@media (max-width: 768px) {
    /* Hide desktop cluster */
    .nav-cluster {
        display: none;
    }

    /* Show mobile FAB */
    .nav-mobile-fab {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .nav-mobile-overlay {
        display: block;
        pointer-events: none;
        z-index: 2001; /* Above sticky nav (2000) to darken it */
    }

    .nav-mobile-overlay[aria-hidden="false"] {
        pointer-events: auto;
    }

    /* Filter panel becomes bottom sheet */
    .nav-filter-panel {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        top: auto;
        width: 100%;
        max-height: 70vh;
        border-radius: 16px 16px 0 0;
        transform: translateY(100%);
        z-index: 2002; /* Above overlay (2001) */
    }

    .nav-filter-panel[aria-hidden="false"] {
        transform: translateY(0);
    }

    .nav-filter-panel-content {
        max-height: 70vh;
        overflow-y: auto;
    }

    /* Add pagination to mobile bottom sheet header */
    .nav-filter-header {
        flex-wrap: wrap;
        gap: 10px;
        padding: 14px 16px;
    }

    .nav-filter-title {
        flex: 1;
    }

    /* Mobile pagination row (injected via JS) */
    .nav-mobile-pagination {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 12px;
        width: 100%;
        padding: 12px 16px;
        background: rgba(0, 0, 0, 0.2);
        border-bottom: 1px solid rgba(184, 134, 11, 0.3);
    }

    .nav-mobile-pagination .nav-page-indicator {
        font-size: 0.9rem;
        min-width: 60px;
    }

    .nav-mobile-pagination .nav-cluster-btn {
        width: 40px;
        height: 40px;
        background: rgba(184, 134, 11, 0.2);
        border-radius: 50%;
    }

    .nav-filter-body {
        padding: 16px;
        gap: 16px;
    }

    .nav-filter-input,
    .nav-filter-select {
        padding: 12px;
        font-size: 1rem;
    }

    .nav-filter-footer {
        flex-direction: column;
        gap: 12px;
        padding: 14px 16px;
    }

    .nav-clear-btn {
        width: 100%;
        padding: 10px;
        font-size: 0.85rem;
    }

    .nav-filter-stats {
        width: 100%;
        justify-content: center;
        font-size: 0.75rem;
    }

    /* Mobile back-to-top row */
    .nav-mobile-back-to-top {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
        padding: 12px 16px;
        border-top: 1px solid rgba(184, 134, 11, 0.3);
        color: var(--bg-parchment);
        font-family: var(--font-mono);
        font-size: 0.85rem;
        cursor: pointer;
        transition: background 0.2s ease;
    }

    .nav-mobile-back-to-top:hover {
        background: rgba(184, 134, 11, 0.2);
    }
}

/* Hide old back-to-top button (now integrated into cluster) */
.back-to-top {
    display: none !important;
}

/* On mobile the FAB bottom sheet is the control surface; on desktop the
   in-page filter bar + pagination are the canonical gallery controls. */
@media (max-width: 768px) {
    /* v3: in-page drawer pagination stays visible on phones */
    .unified-filter-bar {
        display: none !important;
    }
}

/* ==========================================================================

/* FAB hides when the gallery/ledger it controls is off screen */
.nav-mobile-fab { transition: opacity .25s ease, transform .25s ease, background .2s ease, color .2s ease; }
.nav-mobile-fab.fab-out { opacity: 0; transform: scale(.6); pointer-events: none; }
