/* ═══════════════════════════════════════════════════════════════════════════
   Instagram Tagged Posts Viewer — Styles
   Dark mode, glassmorphic, Instagram-inspired grid viewer
   ═══════════════════════════════════════════════════════════════════════════ */

/* ─── Design Tokens ───────────────────────────────────────────────────────── */
:root {
    /* Palette — warm charcoal with a single amber accent (archival feel) */
    --bg-base: #0e0d0b;
    --bg-raised: #16150f;
    --bg-surface: #1c1a15;
    --bg-surface-hover: #26241c;
    --bg-overlay: rgba(12, 11, 9, 0.86);

    --border-subtle: rgba(255, 250, 245, 0.07);
    --border-medium: rgba(255, 250, 245, 0.12);
    --border-accent: rgba(255, 77, 94, 0.40);

    --text-primary: #f2efeb;
    --text-secondary: #a5a09a;
    --text-muted: #6a655f;

    /* Single accent — red. Everything else is neutral warm-gray. */
    --accent-primary: #ff4d5e;
    --accent-primary-hover: #ff6a78;
    --accent-soft: rgba(255, 77, 94, 0.13);
    --accent-gradient: linear-gradient(135deg, #ff4d5e 0%, #e63c56 100%);
    --accent-gradient-soft: linear-gradient(135deg, rgba(255, 77, 94, 0.15) 0%, rgba(230, 60, 86, 0.08) 100%);

    --fav-color: #ff4d5e;
    --like-color: #ff4d5e;
    --comment-color: #a5a09a;

    /* Typography */
    --font-body: 'Outfit', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-display: 'Space Grotesk', 'Outfit', sans-serif;

    /* Spacing */
    --topbar-height: 62px;
    --grid-gap: 12px;
    --grid-columns: 4;

    /* Transitions */
    --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
    --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);

    /* Radii */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
}

/* ─── Reset ───────────────────────────────────────────────────────────────── */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 14px;
    scroll-behavior: smooth;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-body);
    background: var(--bg-base);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
}

/* Subtle gradient background */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 520px;
    background: radial-gradient(ellipse at 50% -10%, rgba(255, 255, 255, 0.035) 0%, transparent 68%);
    pointer-events: none;
    z-index: 0;
}

/* Fine film grain over everything — breaks the flat-vector sterility */
body::after {
    content: '';
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 1;
    opacity: 0.03;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='120' height='120' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ─── Top Bar ─────────────────────────────────────────────────────────────── */
#topbar {
    position: sticky;
    top: 0;
    z-index: 100;
    background: rgba(10, 10, 15, 0.8);
    backdrop-filter: blur(24px) saturate(1.5);
    -webkit-backdrop-filter: blur(24px) saturate(1.5);
    border-bottom: 1px solid var(--border-subtle);
    height: var(--topbar-height);
}

.topbar-inner {
    max-width: 960px;
    margin: 0 auto;
    padding: 0 20px;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.topbar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-icon {
    width: 32px;
    height: 32px;
    color: var(--accent-primary);
    flex-shrink: 0;
}

.brand-text {
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.brand-name {
    font-weight: 700;
    font-size: 1.1rem;
    letter-spacing: -0.01em;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.brand-user {
    font-size: 0.78rem;
    color: var(--text-muted);
    font-weight: 400;
}

.topbar-actions {
    display: flex;
    gap: 8px;
}

/* ─── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: var(--font-body);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s var(--ease-out);
    white-space: nowrap;
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border-medium);
}
.btn-ghost:hover {
    background: var(--bg-surface);
    color: var(--text-primary);
    border-color: var(--border-accent);
}

.btn-primary {
    background: var(--accent-gradient);
    color: white;
    font-weight: 600;
    text-decoration: none;
    border: none;
    padding: 10px 20px;
}
.btn-primary:hover {
    opacity: 0.9;
    transform: translateY(-1px);
    box-shadow: 0 4px 20px rgba(168, 85, 247, 0.3);
}

.btn-page {
    background: var(--bg-surface);
    color: var(--text-secondary);
    border: 1px solid var(--border-medium);
    padding: 10px 18px;
}
.btn-page:hover:not(:disabled) {
    background: var(--bg-surface-hover);
    color: var(--text-primary);
    border-color: var(--border-accent);
}
.btn-page:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

/* ─── Stats Bar ───────────────────────────────────────────────────────────── */
#stats-bar {
    border-bottom: 1px solid var(--border-subtle);
    background: var(--bg-raised);
}

.stats-inner {
    max-width: 960px;
    margin: 0 auto;
    padding: 14px 20px;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.stat-chip {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 8px 18px;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    min-width: 100px;
    flex: 1;
}

.stat-value {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.02em;
}

.stat-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 500;
}

/* ─── Filters ─────────────────────────────────────────────────────────────── */
#filters {
    position: sticky;
    top: var(--topbar-height);
    z-index: 90;
    background: rgba(12, 12, 18, 0.85);
    backdrop-filter: blur(20px) saturate(1.3);
    -webkit-backdrop-filter: blur(20px) saturate(1.3);
    border-bottom: 1px solid var(--border-subtle);
}

.filters-inner {
    max-width: 960px;
    margin: 0 auto;
    padding: 14px 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.filter-row {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    flex-wrap: wrap;
}

.filter-row-search {
    align-items: center;
}

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

.filter-group-search {
    flex: 1;
    min-width: 200px;
}

.filter-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 600;
}

.filter-input {
    padding: 8px 12px;
    background: var(--bg-surface);
    border: 1px solid var(--border-medium);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: var(--font-body);
    font-size: 0.85rem;
    transition: all 0.2s var(--ease-out);
    outline: none;
}

.filter-input:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(168, 85, 247, 0.15);
}

/* Date inputs */
input[type="date"] {
    width: 150px;
}
input[type="date"]::-webkit-calendar-picker-indicator {
    filter: invert(0.7);
    cursor: pointer;
}

/* Select */
select.filter-input {
    cursor: pointer;
    min-width: 130px;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%239898ac' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 30px;
}

/* Search wrapper */
.search-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.search-icon {
    position: absolute;
    left: 12px;
    color: var(--text-muted);
    pointer-events: none;
}

.search-input {
    width: 100%;
    padding-left: 36px !important;
    padding-right: 36px !important;
}

.btn-clear-search {
    position: absolute;
    right: 8px;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    line-height: 1;
}
.btn-clear-search:hover {
    color: var(--text-primary);
    background: var(--bg-surface-hover);
}

/* Preset chips */
.preset-chips {
    display: flex;
    gap: 4px;
}

.preset-chip {
    padding: 7px 14px;
    background: var(--bg-surface);
    border: 1px solid var(--border-medium);
    border-radius: 100px;
    color: var(--text-secondary);
    font-family: var(--font-body);
    font-size: 0.78rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s var(--ease-out);
    white-space: nowrap;
}

.preset-chip:hover {
    background: var(--bg-surface-hover);
    color: var(--text-primary);
    border-color: var(--border-accent);
}

.preset-chip.active {
    background: var(--accent-primary);
    color: white;
    border-color: var(--accent-primary);
}

.btn-reset {
    margin-left: auto;
    flex-shrink: 0;
}

/* ─── Grid ────────────────────────────────────────────────────────────────── */
#grid-container {
    position: relative;
    z-index: 1;
}

.grid {
    display: grid;
    grid-template-columns: repeat(var(--grid-columns), 1fr);
    gap: var(--grid-gap);
}

/* ─── Grid Item ───────────────────────────────────────────────────────────── */
.grid-item {
    position: relative;
    cursor: pointer;
}

.grid-thumb {
    position: relative;
    aspect-ratio: 1;
    overflow: hidden;
    background: var(--bg-surface);
    border-radius: var(--radius-md);
    box-shadow: 0 1px 3px rgba(0,0,0,0.35);
    transition: transform 0.3s var(--ease-out), box-shadow 0.3s var(--ease-out);
}

.grid-item:hover .grid-thumb {
    transform: translateY(-3px);
    box-shadow: 0 10px 26px -8px rgba(0,0,0,0.6), 0 0 0 1px var(--border-accent);
}

.grid-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.5s var(--ease-out), filter 0.3s ease;
}

.grid-item:hover img {
    transform: scale(1.06);
    filter: brightness(0.62);
}

/* staggered entry for freshly added cards */
@keyframes cardIn { from { opacity: 0; transform: translateY(10px) scale(0.985); } to { opacity: 1; transform: none; } }
.grid-item.enter { animation: cardIn 0.4s var(--ease-out) both; }
.grid-item.leaving { animation: cardIn 0.22s ease reverse both; }

/* Overlay on hover */
.grid-item-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    opacity: 0;
    transition: opacity 0.25s ease;
    pointer-events: none;
    z-index: 2;
}

.grid-item:hover .grid-item-overlay {
    opacity: 1;
}

.grid-item-stats {
    display: flex;
    gap: 20px;
    color: white;
    font-weight: 700;
    font-size: 1rem;
}

.grid-item-stats span {
    display: flex;
    align-items: center;
    gap: 6px;
}

.grid-item-stats svg {
    width: 18px;
    height: 18px;
}

.grid-item-date {
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.75rem;
    font-weight: 500;
}

/* Type badge (top-left; heart owns top-right) */
.grid-item-type {
    position: absolute;
    top: 8px;
    left: 8px;
    z-index: 3;
    color: white;
    filter: drop-shadow(0 1px 3px rgba(0,0,0,0.5));
}

.grid-item-type svg {
    width: 20px;
    height: 20px;
}

/* ─── Loading / Empty States ──────────────────────────────────────────────── */
.loading-state, .empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 80px 20px;
    color: var(--text-muted);
    gap: 16px;
}

.empty-state h3 {
    color: var(--text-secondary);
    font-size: 1.2rem;
}

.spinner {
    width: 36px;
    height: 36px;
    border: 3px solid var(--border-medium);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* ─── Grid loading overlay (frosted) ─────────────────────────────────────────
   Shown when navigating (page change, category switch, filters) while posts
   are already rendered — frosts the stale grid instead of flashing it away. */
#grid-overlay {
    position: absolute;
    inset: -8px;
    z-index: 6;
    display: none;
    justify-content: center;
    align-items: flex-start;
    background: rgba(14, 13, 11, 0.38);
    -webkit-backdrop-filter: blur(9px) saturate(115%);
    backdrop-filter: blur(9px) saturate(115%);
    border-radius: var(--radius-md);
}

#grid-overlay.show {
    display: flex;
    animation: overlayIn 0.22s var(--ease-out, ease) both;
}

@keyframes overlayIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

#grid-overlay .overlay-chip {
    position: sticky;
    top: 38vh;
    margin-top: 110px;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 13px 24px;
    background: rgba(28, 26, 21, 0.72);
    border: 1px solid var(--border-medium);
    border-radius: 999px;
    box-shadow: 0 10px 34px rgba(0, 0, 0, 0.45);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    color: var(--text-secondary);
    font-size: 0.95rem;
    letter-spacing: 0.02em;
}

#grid-overlay .spinner {
    width: 20px;
    height: 20px;
    border-width: 2.5px;
}

/* ─── Pagination ──────────────────────────────────────────────────────────── */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 30px 0;
}

.page-info {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-weight: 500;
    min-width: 120px;
    text-align: center;
}

/* ─── Modal ───────────────────────────────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: var(--bg-overlay);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    animation: fadeIn 0.2s ease;
    backdrop-filter: blur(8px);
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal {
    background: var(--bg-raised);
    border: 1px solid var(--border-medium);
    border-radius: var(--radius-xl);
    max-width: 900px;
    width: 100%;
    max-height: 85vh;
    overflow: hidden;
    animation: modalSlide 0.35s var(--ease-spring);
    position: relative;
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255,255,255,0.03);
}

.modal-sm {
    max-width: 500px;
    padding: 28px;
    overflow-y: auto;
}

@keyframes modalSlide {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.97);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.modal-close {
    position: absolute;
    top: 12px;
    right: 14px;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,0.5);
    border: 1px solid var(--border-medium);
    border-radius: 50%;
    color: var(--text-secondary);
    font-size: 1.3rem;
    cursor: pointer;
    transition: all 0.2s ease;
    z-index: 10;
    line-height: 1;
}
.modal-close:hover {
    background: rgba(168, 85, 247, 0.2);
    color: var(--text-primary);
    border-color: var(--accent-primary);
}

.modal-content {
    display: flex;
    height: 100%;
    max-height: 85vh;
}

.modal-media {
    flex: 1.2;
    position: relative;
    background: #000;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 400px;
}

.modal-media img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.modal-media-type {
    position: absolute;
    top: 14px;
    left: 14px;
    padding: 5px 10px;
    background: rgba(0,0,0,0.6);
    border-radius: 100px;
    color: white;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    backdrop-filter: blur(8px);
}

.modal-details {
    flex: 0.8;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    overflow-y: auto;
    min-width: 280px;
}

.modal-header {
    padding-bottom: 14px;
    border-bottom: 1px solid var(--border-subtle);
}

.modal-user {
    display: flex;
    align-items: center;
    gap: 12px;
}

.modal-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--accent-gradient);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1rem;
    color: white;
    flex-shrink: 0;
}

.modal-user-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.modal-username {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text-primary);
    text-decoration: none;
}
.modal-username:hover {
    color: var(--accent-primary-hover);
}

.modal-date {
    font-size: 0.78rem;
    color: var(--text-muted);
}

.modal-caption {
    font-size: 0.9rem;
    line-height: 1.6;
    color: var(--text-secondary);
    flex: 1;
    white-space: pre-wrap;
    word-break: break-word;
}

.modal-stats {
    display: flex;
    gap: 24px;
    padding: 14px 0;
    border-top: 1px solid var(--border-subtle);
}

.modal-stat {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    font-size: 0.95rem;
}

.modal-stat:first-child {
    color: var(--like-color);
}
.modal-stat:last-child {
    color: var(--comment-color);
}

.modal-actions {
    padding-top: 14px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.modal-actions .btn-fav { align-self: flex-start; }

.modal-actions .btn-primary {
    width: 100%;
    justify-content: center;
    font-size: 0.9rem;
}

/* ─── Modal Title (data source) ───────────────────────────────────────────── */
.modal-title {
    font-size: 1.3rem;
    font-weight: 700;
    margin-bottom: 4px;
}

.modal-subtitle {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-bottom: 18px;
}

/* ─── Data Source List ────────────────────────────────────────────────────── */
.datasource-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.datasource-item {
    padding: 14px 16px;
    background: var(--bg-surface);
    border: 1px solid var(--border-medium);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s var(--ease-out);
}

.datasource-item:hover {
    background: var(--bg-surface-hover);
    border-color: var(--accent-primary);
    transform: translateY(-1px);
}

.datasource-item-user {
    font-weight: 600;
    font-size: 0.95rem;
    margin-bottom: 4px;
}

.datasource-item-meta {
    display: flex;
    gap: 16px;
    font-size: 0.78rem;
    color: var(--text-muted);
}

/* ─── Keyboard Nav Toast ──────────────────────────────────────────────────── */
.nav-toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-surface);
    border: 1px solid var(--border-medium);
    border-radius: 100px;
    padding: 10px 24px;
    font-size: 0.78rem;
    color: var(--text-muted);
    z-index: 1100;
    animation: toastIn 0.4s var(--ease-spring);
    backdrop-filter: blur(12px);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

/* Show keyboard hint on desktop, swipe hint on touch/mobile. */
.nav-toast .toast-mobile { display: none; }
@media (max-width: 768px) {
    .nav-toast .toast-desktop { display: none; }
    .nav-toast .toast-mobile { display: inline; }
}

.nav-toast kbd {
    display: inline-block;
    padding: 2px 7px;
    background: var(--bg-raised);
    border: 1px solid var(--border-medium);
    border-radius: 4px;
    font-family: var(--font-body);
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-primary);
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(16px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

/* ─── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
    :root {
        --grid-columns: 2;
        --grid-gap: 2px;
    }

    .filter-row {
        gap: 8px;
    }

    .filter-group-presets {
        order: 99;
        width: 100%;
    }

    .preset-chips {
        flex-wrap: wrap;
    }

    /* Whole modal becomes one scrollable column so nothing overlaps or clips. */
    .modal {
        max-height: 92vh;
        height: auto;
        border-radius: var(--radius-lg);
    }
    .modal-content {
        flex-direction: column;
        height: auto;
        max-height: 92vh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    .modal-media {
        flex: none;
        min-height: 0;
        max-height: 56vh;
        background: #000;
    }
    /* contain (not cover) so portrait photos/videos show fully, uncropped. */
    .modal-media img {
        object-fit: contain;
        max-height: 56vh;
    }
    .modal-details {
        flex: none;
        min-width: 0;
        padding: 16px 16px calc(18px + env(safe-area-inset-bottom));
        gap: 12px;
        overflow: visible;
    }
    .modal-actions .btn { width: 100%; justify-content: center; }

    .stats-inner {
        gap: 6px;
    }

    .stat-chip {
        padding: 6px 10px;
        min-width: 70px;
    }

    .stat-value {
        font-size: 1rem;
    }
}

@media (max-width: 480px) {
    :root {
        --grid-columns: 2;
    }

    .topbar-actions span {
        display: none;
    }

    input[type="date"] {
        width: 130px;
    }
}

/* ─── Scrollbar ───────────────────────────────────────────────────────────── */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-base);
}

::-webkit-scrollbar-thumb {
    background: var(--border-medium);
    border-radius: 100px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ─── Selection ───────────────────────────────────────────────────────────── */
::selection {
    background: rgba(224, 168, 92, 0.32);
    color: #fff;
}

/* ═══════════════════════════════════════════════════════════════════════════
   Rare — added components: login gate · favorites · category bar · polish
   ═══════════════════════════════════════════════════════════════════════════ */

.brand-name { font-family: var(--font-display); letter-spacing: -0.02em; }
.brand-icon { color: var(--text-primary); }
.live-dot { color: var(--fav-color); font-weight: 600; }

/* ─── Login gate ─── */
.login-overlay {
    position: fixed; inset: 0; z-index: 2000;
    display: flex; align-items: center; justify-content: center; padding: 24px;
    background:
        radial-gradient(ellipse at 50% 0%, rgba(255,255,255,0.05), transparent 60%),
        var(--bg-base);
    opacity: 1; transition: opacity 0.4s ease, visibility 0.4s;
}
.login-overlay.hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.login-card {
    width: 100%; max-width: 380px; text-align: center;
    animation: cardIn 0.5s var(--ease-out) both;
}
.login-mark { font-size: 40px; color: var(--accent-primary); line-height: 1; margin-bottom: 14px;
    filter: drop-shadow(0 4px 18px rgba(255,77,94,0.35)); }
.login-title { font-family: var(--font-display); font-size: 2.4rem; letter-spacing: -0.03em; font-weight: 700; }
.login-sub { color: var(--text-secondary); font-size: 0.95rem; line-height: 1.5; margin: 8px auto 24px; max-width: 300px; }
.login-form { display: flex; gap: 8px; }
.login-input {
    flex: 1; background: var(--bg-surface); border: 1px solid var(--border-medium);
    border-radius: var(--radius-md); padding: 13px 16px; color: var(--text-primary);
    font-family: var(--font-body); font-size: 1rem; outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.login-input:focus { border-color: var(--accent-primary); box-shadow: 0 0 0 3px var(--accent-soft); }
.login-input.shake { animation: shake 0.4s; }
@keyframes shake { 0%,100%{transform:translateX(0)} 20%,60%{transform:translateX(-6px)} 40%,80%{transform:translateX(6px)} }
.login-btn {
    background: var(--accent-primary); color: #fff; font-weight: 600; border: none;
    border-radius: var(--radius-md); padding: 0 22px; font-size: 1rem; cursor: pointer;
    font-family: var(--font-body); transition: transform 0.15s var(--ease-spring), filter 0.2s;
}
.login-btn:hover { filter: brightness(1.08); }
.login-btn:active { transform: scale(0.96); }
.login-error { color: var(--fav-color); font-size: 0.85rem; margin-top: 14px; min-height: 1.2em; }

/* ─── User chip + favorites button ─── */
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.fav-count {
    background: var(--bg-surface); color: var(--text-secondary); font-size: 0.72rem; font-weight: 700;
    padding: 1px 7px; border-radius: 10px; font-variant-numeric: tabular-nums;
}
#btn-favorites.active { color: var(--fav-color); border-color: rgba(255,84,112,0.4); background: rgba(255,84,112,0.08); }
#btn-favorites.active .fav-count { background: var(--fav-color); color: #fff; }
.fav-star { transition: transform 0.3s var(--ease-spring); }
#btn-favorites:hover .fav-star { transform: rotate(-12deg) scale(1.12); }

.user-chip {
    display: flex; align-items: center; gap: 7px; padding: 4px 8px 4px 4px;
    background: var(--bg-surface); border: 1px solid var(--border-subtle);
    border-radius: 999px; font-size: 0.82rem; font-weight: 500;
}
.user-dot {
    width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center;
    background: var(--accent-primary); color: #fff; font-weight: 700; font-size: 0.8rem; text-transform: uppercase;
}
.btn-logout {
    background: none; border: none; color: var(--text-muted); font-size: 1.15rem; line-height: 1;
    cursor: pointer; padding: 0 2px; transition: color 0.2s;
}
.btn-logout:hover { color: var(--fav-color); }

/* ─── Grid favorite heart ─── */
.grid-fav {
    position: absolute; top: 7px; right: 7px; z-index: 4;
    width: 34px; height: 34px; border-radius: 50%; border: none; cursor: pointer;
    display: grid; place-items: center; padding: 0;
    background: rgba(12,11,9,0.35); backdrop-filter: blur(6px);
    color: rgba(255,255,255,0.9);
    opacity: 0; transform: scale(0.8) translateY(-2px);
    transition: opacity 0.2s, transform 0.2s var(--ease-spring), background 0.2s, color 0.2s;
}
.grid-fav svg { fill: none; stroke: currentColor; stroke-width: 2; }
.grid-item:hover .grid-fav, .grid-fav.faved { opacity: 1; transform: none; }
.grid-fav:hover { background: rgba(12,11,9,0.6); color: #fff; }
.grid-fav.faved { color: var(--fav-color); background: rgba(12,11,9,0.5); }
.grid-fav.faved svg { fill: var(--fav-color); stroke: var(--fav-color); }
.grid-fav.pop { animation: heartPop 0.35s var(--ease-spring); }
@keyframes heartPop { 0%{transform:scale(1)} 35%{transform:scale(1.35)} 60%{transform:scale(0.9)} 100%{transform:scale(1)} }

.grid-item-stats svg { fill: currentColor; }
.grid-item-stats span:first-child { color: #ff8095; }

/* ═══ Sidebar layout ═══ */
#topbar .topbar-inner { max-width: 1440px; }
#layout {
    display: flex; align-items: flex-start;
    max-width: 1440px; margin: 0 auto; padding: 0 20px; gap: 24px;
    position: relative; z-index: 2;
}
#sidebar {
    position: sticky; top: var(--topbar-height); flex: 0 0 244px; width: 244px;
    height: calc(100dvh - var(--topbar-height)); overflow: hidden;
}
.sidebar-scroll {
    height: 100%; overflow-y: auto; padding: 20px 4px 40px 0;
    display: flex; flex-direction: column; gap: 20px;
    scrollbar-width: thin;
}
#main { flex: 1 1 auto; min-width: 0; padding: 20px 0 60px; }

#cat-mount { display: flex; flex-direction: column; gap: 22px; }
.side-block { display: flex; flex-direction: column; gap: 10px; }
#filters .side-block + .side-block { margin-top: 2px; }
.side-label {
    font-size: 0.68rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.09em;
    color: var(--text-muted);
}
.side-label.is-tag { color: var(--text-muted); }

/* categories as full-width rows */
.cat-list { display: flex; flex-direction: column; gap: 4px; }
.cat-btn {
    display: flex; align-items: center; justify-content: space-between; gap: 8px; width: 100%;
    cursor: pointer; border: 1px solid transparent; background: transparent; color: var(--text-secondary);
    border-radius: var(--radius-sm); padding: 8px 11px; font-size: 0.88rem; font-family: var(--font-body);
    text-align: left; transition: background 0.16s, color 0.16s, border-color 0.16s;
}
.cat-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat-btn:hover { background: var(--bg-surface); color: var(--text-primary); }
.cat-btn.active {
    background: var(--accent-soft); color: var(--accent-primary-hover);
    border-color: var(--border-accent); font-weight: 600;
}
.cat-count { font-size: 0.72rem; opacity: 0.65; font-variant-numeric: tabular-nums; flex-shrink: 0; }
.cat-btn.active .cat-count { opacity: 0.85; }

/* date range + presets in sidebar */
.date-row { display: flex; align-items: center; gap: 6px; }
.date-row .filter-input { padding: 8px 8px; font-size: 0.82rem; flex: 1; min-width: 0; }
.date-sep { color: var(--text-muted); flex-shrink: 0; }
.preset-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 2px; }
#sidebar .btn-reset { width: 100%; justify-content: center; margin-top: 4px; }

/* ─── Live bar ─── */
#live-bar {
    display: none; gap: 18px; align-items: center; flex-wrap: wrap;
    padding: 8px 12px; margin-bottom: 14px; font-size: 0.82rem;
    color: var(--text-secondary); background: var(--bg-raised);
    border: 1px solid var(--border-subtle); border-radius: var(--radius-md);
}
#live-bar b { color: var(--text-primary); font-variant-numeric: tabular-nums; }

/* neutralize old sticky/blur panels — layout is handled by #layout now */
#filters { position: static; background: none; backdrop-filter: none; -webkit-backdrop-filter: none;
    border: none; display: flex; flex-direction: column; gap: 20px; }

/* ─── Slim stats strip ─── */
#stats-bar {
    display: flex; gap: 22px; flex-wrap: wrap; align-items: baseline; background: none;
    padding: 0 2px 16px; border-bottom: 1px solid var(--border-subtle); margin-bottom: 18px;
}
.stat-inline { display: flex; align-items: baseline; gap: 7px; }
.stat-inline .stat-value {
    font-family: var(--font-display); font-size: 1.15rem; font-weight: 600; color: var(--text-primary);
    font-variant-numeric: tabular-nums;
}
.stat-inline .stat-label { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); }

/* Sidebar toggle only shows on narrow screens */
.btn-icon { padding: 8px; }
#btn-sidebar { display: none; }

/* ─── Responsive: sidebar becomes a slide-in drawer ─── */
@media (max-width: 820px) {
    #btn-sidebar { display: inline-flex; }
    #layout { display: block; padding: 0 16px; }
    #sidebar {
        position: fixed; top: var(--topbar-height); left: 0; z-index: 95;
        width: 280px; height: calc(100dvh - var(--topbar-height));
        background: var(--bg-raised); border-right: 1px solid var(--border-medium);
        transform: translateX(-102%); transition: transform 0.28s var(--ease-out);
        box-shadow: 8px 0 40px rgba(0,0,0,0.4);
    }
    .sidebar-scroll { padding: 18px 16px 40px; }
    body.sidebar-open #sidebar { transform: translateX(0); }
    body.sidebar-open::after { } /* keep grain */
    #main { padding: 18px 0 60px; }
}

/* ─── Modal open/close fade + favorite button ─── */
.modal-overlay { animation: none; opacity: 0; transition: opacity 0.22s ease; }
.modal-overlay.open { opacity: 1; }
/* Brief dim while fetching the adjacent page mid-swipe/arrow. */
.modal-overlay.nav-loading #modal-image { opacity: 0.45; transition: opacity 0.15s ease; }
.btn-fav {
    display: inline-flex; align-items: center; gap: 8px; cursor: pointer;
    background: var(--bg-surface); border: 1px solid var(--border-medium); color: var(--text-secondary);
    border-radius: var(--radius-md); padding: 11px 18px; font-family: var(--font-body); font-size: 0.9rem; font-weight: 500;
    transition: all 0.18s var(--ease-out);
}
.btn-fav .heart-icon { fill: none; stroke: currentColor; stroke-width: 2; transition: transform 0.3s var(--ease-spring); }
.btn-fav:hover { color: var(--text-primary); border-color: var(--border-accent); }
.btn-fav.faved { color: var(--fav-color); border-color: rgba(255,84,112,0.4); background: rgba(255,84,112,0.08); }
.btn-fav.faved .heart-icon { fill: var(--fav-color); stroke: var(--fav-color); transform: scale(1.12); }

.muted-center { color: var(--text-muted); text-align: center; padding: 24px; }

/* Fav-mode: dim the filter presets that don't apply, keep it obvious you're in favorites */
body.fav-mode #cat-bar { display: none !important; }

/* ─── Pagination page-jump ─── */
.page-jump { display: flex; align-items: center; gap: 8px; margin: 0; }
.page-input {
    width: 66px; text-align: center; background: var(--bg-surface); border: 1px solid var(--border-medium);
    color: var(--text-primary); border-radius: var(--radius-sm); padding: 8px 6px; font-family: var(--font-body);
    font-size: 0.92rem; font-variant-numeric: tabular-nums; outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    -moz-appearance: textfield;
}
.page-input:focus { border-color: var(--accent-primary); box-shadow: 0 0 0 3px var(--accent-soft); }
.page-input::-webkit-outer-spin-button, .page-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.page-total { color: var(--text-secondary); font-size: 0.86rem; white-space: nowrap; }
.page-total b { color: var(--text-primary); font-variant-numeric: tabular-nums; }
.btn-page-edge { padding: 9px 10px; }

/* grid column counts by width */
@media (max-width: 1200px) { :root { --grid-columns: 3; } }
@media (max-width: 820px)  { :root { --grid-columns: 3; } }
@media (max-width: 560px)  { :root { --grid-columns: 2; } }

/* ─── Reduced motion ─── */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.05ms !important; }
    html { scroll-behavior: auto; }
}
