/* ═══════════════════════════════════════════════════
   GarageSaleMap v2 — Discovery Feed Layout
   Mobile-first redesign (index.php)
   ═══════════════════════════════════════════════════ */

/* ── Layout tokens ──────────────────────────────────── */
:root {
    --g2-header-h:  100px;
    --g2-chips-h:    48px;
    --g2-nav-h:      62px;
    --g2-top:       calc(var(--g2-header-h) + var(--g2-chips-h));
    --g2-bottom:    calc(var(--g2-nav-h) + env(safe-area-inset-bottom, 0px));
    --g2-bg:        #f2f4f7;
    --g2-card-r:     14px;
    --g2-sheet-r:    20px;
    --g2-shadow-sm: 0 1px 4px rgba(0,0,0,.07), 0 0 0 1px rgba(0,0,0,.04);
    --g2-shadow:    0 4px 16px rgba(0,0,0,.10), 0 0 0 1px rgba(0,0,0,.04);
    --g2-shadow-lg: 0 12px 40px rgba(0,0,0,.18);
    --g2-open:      #16a34a;
    --g2-closing:   #f59e0b;
    --g2-closed:    #64748b;
    --g2-upcoming:  #2563eb;
    --g2-ended:     #9ca3af;
    --g2-pin-open:  #16a34a;
    --g2-pin-up:    #2563eb;
    --g2-pin-cl:    #f59e0b;
    --g2-pin-end:   #9ca3af;
}

/* ── Reset / base ───────────────────────────────────── */
.g2-body {
    background: var(--g2-bg);
    overflow: hidden;
    height: 100dvh;
}

#g2-app {
    display: flex;
    flex-direction: column;
    height: 100dvh;
    overflow: hidden;
}

/* ── Header ─────────────────────────────────────────── */
#g2-header {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: var(--g2-header-h);
    background: #fff;
    border-bottom: 1px solid var(--border);
    z-index: 300;
    display: flex;
    flex-direction: column;
    padding: 0;
}

.g2-header-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1rem;
    height: 54px;
    flex-shrink: 0;
}

.g2-brand {
    display: flex;
    align-items: center;
    gap: .5rem;
    font-size: 1rem;
    font-weight: 800;
    color: var(--text);
    text-decoration: none;
    letter-spacing: -.02em;
}

.g2-header-actions {
    display: flex;
    align-items: center;
    gap: .25rem;
}

.g2-icon-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    color: var(--text-muted);
    background: none;
    border: none;
    cursor: pointer;
    text-decoration: none;
    position: relative;
    transition: background var(--transition);
}
.g2-icon-btn:hover { background: var(--bg); }
.g2-icon-btn.g2-has-badge::after {
    content: '';
    position: absolute;
    top: 7px; right: 7px;
    width: 8px; height: 8px;
    background: #ef4444;
    border-radius: 50%;
    border: 2px solid #fff;
}

/* ── User menu dropdown ─────────────────────────────── */
.g2-menu-wrap { position: relative; }

.g2-user-menu {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    min-width: 180px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--g2-shadow);
    z-index: 900;
    overflow: hidden;
}
.g2-user-menu[hidden] { display: none; }

.g2-user-menu-name {
    padding: .55rem 1rem;
    font-size: .72rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .05em;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
}
.g2-user-menu a {
    display: block;
    padding: .65rem 1rem;
    font-size: .875rem;
    color: var(--text);
    text-decoration: none;
    transition: background .12s;
}
.g2-user-menu a:hover { background: var(--bg); }
.g2-user-menu-divider { height: 1px; background: var(--border); }
.g2-user-menu-logout { color: var(--danger, #dc2626) !important; }

/* Search row inside header */
.g2-search-row {
    padding: 0 1rem .6rem;
    flex-shrink: 0;
}

.g2-search-wrap {
    position: relative;
    display: flex;
    align-items: center;
}

.g2-search-icon {
    position: absolute;
    left: .75rem;
    color: var(--text-muted);
    pointer-events: none;
    flex-shrink: 0;
}

#g2-search {
    width: 100%;
    height: 38px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 0 2.5rem 0 2.4rem;
    font-size: .875rem;
    color: var(--text);
    outline: none;
    transition: border-color .15s, box-shadow .15s;
    -webkit-appearance: none;
}
#g2-search:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,.12);
    background: #fff;
}

.g2-search-clear {
    position: absolute;
    right: .75rem;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.1rem;
    cursor: pointer;
    line-height: 1;
    padding: 0;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ── Filter chips bar ───────────────────────────────── */
#g2-chips-wrap {
    position: fixed;
    top: var(--g2-header-h);
    left: 0; right: 0;
    height: var(--g2-chips-h);
    background: #fff;
    border-bottom: 1px solid var(--border);
    z-index: 290;
    display: flex;
    align-items: center;
}

#g2-chips {
    display: flex;
    align-items: center;
    gap: .35rem;
    overflow-x: auto;
    padding: 0 .75rem;
    flex: 1;
    min-width: 0;
    scrollbar-width: none;
    -ms-overflow-style: none;
}
#g2-chips::-webkit-scrollbar { display: none; }

.g2-chip {
    flex-shrink: 0;
    height: 30px;
    padding: 0 .7rem;
    border-radius: 999px;
    border: 1.5px solid var(--border);
    background: #fff;
    color: var(--text-muted);
    font-size: .75rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: background .13s, border-color .13s, color .13s;
}
.g2-chip.g2-chip-active {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}
.g2-chip.g2-chip-cat { padding: 0 .55rem; font-size: .85rem; }

.g2-chips-sep {
    width: 1px;
    height: 20px;
    background: var(--border-strong);
    flex-shrink: 0;
    margin: 0 .15rem;
}

#g2-filter-btn {
    flex-shrink: 0;
    width: 44px;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #fff;
    border: none;
    border-left: 1px solid var(--border);
    cursor: pointer;
    color: var(--text-muted);
    position: relative;
    transition: color .13s;
}
#g2-filter-btn:hover { color: var(--primary); }

#g2-filter-count {
    position: absolute;
    top: 8px; right: 8px;
    background: var(--primary);
    color: #fff;
    font-size: .6rem;
    font-weight: 700;
    border-radius: 999px;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    line-height: 16px;
    text-align: center;
}

/* ── Content area ───────────────────────────────────── */
#g2-content {
    position: fixed;
    top: var(--g2-top);
    left: 0; right: 0;
    bottom: var(--g2-bottom);
    overflow: hidden;
}

.g2-view {
    display: none;
    width: 100%;
    height: 100%;
}

/* Active view shown based on data-view attribute */
#g2-app[data-view="feed"]  #g2-feed-view  { display: flex; flex-direction: column; overflow-y: auto; }
#g2-app[data-view="map"]   #g2-map-view   { display: block; }
#g2-app[data-view="route"] #g2-route-view { display: flex; flex-direction: column; overflow-y: auto; }

/* ── Feed view ──────────────────────────────────────── */
#g2-feed-summary {
    padding: .7rem 1rem .4rem;
    font-size: .78rem;
    color: var(--text-muted);
    font-weight: 500;
    flex-shrink: 0;
}

#g2-cards {
    display: flex;
    flex-direction: column;
    gap: .75rem;
    padding: 0 .75rem .75rem;
    flex: 1;
    min-height: 0;
}

/* ── Sale card ──────────────────────────────────────── */
.g2-card {
    background: #fff;
    border-radius: var(--g2-card-r);
    overflow: hidden;
    box-shadow: var(--g2-shadow-sm);
    cursor: pointer;
    transition: transform .12s, box-shadow .12s;
    -webkit-tap-highlight-color: transparent;
    /* In the mobile flex-column feed, never let a card shrink below its
       content height — otherwise overflow:hidden clips the bottom rows
       (dates/tags) when the cards don't all fit the container. */
    flex-shrink: 0;
}
.g2-card:active { transform: scale(.985); box-shadow: var(--g2-shadow-sm); }

.g2-card-media {
    position: relative;
    height: 190px;
    background: linear-gradient(135deg, #e8ecf2 0%, #d5dce9 100%);
    overflow: hidden;
}
.g2-card-media img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.g2-card-nophoto {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #e8ecf2 0%, #d2dae8 100%);
}
.g2-card-nophoto svg { color: #b0bcd0; }

/* Status pill overlaid on photo */
.g2-status-pill {
    position: absolute;
    bottom: .6rem; right: .65rem;
    padding: .22rem .65rem;
    border-radius: 999px;
    font-size: .7rem;
    font-weight: 700;
    letter-spacing: .01em;
    color: #fff;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}
.g2-status-open    { background: rgba(22,163,74,.88); }
.g2-status-closing { background: rgba(245,158,11,.9); }
.g2-status-closed  { background: rgba(100,116,139,.82); }
.g2-status-upcoming { background: rgba(37,99,235,.85); }
.g2-status-ended   { background: rgba(107,114,128,.78); }

/* Item count chip on photo (top-left) */
.g2-card-item-count {
    position: absolute;
    top: .6rem; left: .65rem;
    background: rgba(0,0,0,.5);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    color: #fff;
    font-size: .68rem;
    font-weight: 600;
    padding: .18rem .55rem;
    border-radius: 999px;
}

.g2-card-body {
    padding: .75rem .9rem .5rem;
}

.g2-card-title {
    font-size: .95rem;
    font-weight: 700;
    color: var(--text);
    margin: 0 0 .3rem;
    line-height: 1.35;
}

.g2-card-loc-row {
    display: flex;
    align-items: center;
    gap: .5rem;
    margin-bottom: .2rem;
    flex-wrap: wrap;
}

.g2-community-chip {
    display: inline-flex;
    align-items: center;
    background: #eff6ff;
    color: var(--primary);
    border-radius: 999px;
    font-size: .68rem;
    font-weight: 700;
    padding: .12rem .55rem;
    white-space: nowrap;
}

.g2-card-distance {
    font-size: .72rem;
    color: var(--text-muted);
    font-weight: 500;
}

.g2-card-address {
    font-size: .78rem;
    color: var(--text-muted);
    margin-bottom: .2rem;
    /* Generous line box so the 📍 emoji isn't clipped by overflow:hidden */
    line-height: 1.5;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.g2-card-dates {
    font-size: .75rem;
    color: var(--text-muted);
    margin-bottom: .45rem;
    /* Generous line box so the 📅 emoji glyph isn't clipped at the bottom */
    line-height: 1.5;
}

.g2-card-tags {
    display: flex;
    flex-wrap: wrap;
    gap: .3rem;
    margin-bottom: .1rem;
}

.g2-tag {
    font-size: .67rem;
    font-weight: 600;
    padding: .15rem .5rem;
    border-radius: 999px;
    background: #f0fdf4;
    color: #15803d;
    border: 1px solid #bbf7d0;
    white-space: nowrap;
}

.g2-card-actions {
    display: flex;
    gap: .5rem;
    padding: .5rem .9rem .75rem;
    border-top: 1px solid var(--border);
}

.g2-btn-route {
    flex: 1;
    height: 36px;
    border-radius: 999px;
    border: 1.5px solid var(--border-strong);
    background: #fff;
    font-size: .78rem;
    font-weight: 600;
    color: var(--text);
    cursor: pointer;
    transition: background .12s, border-color .12s, color .12s;
}
.g2-btn-route.in-route {
    background: #eff6ff;
    border-color: var(--primary);
    color: var(--primary);
}

.g2-btn-details {
    flex: 2;
    height: 36px;
    border-radius: 999px;
    background: var(--primary);
    color: #fff;
    font-size: .78rem;
    font-weight: 700;
    text-decoration: none;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity .12s;
}
.g2-btn-details:hover { opacity: .9; text-decoration: none; }

/* Empty / loading states */
.g2-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem 1.5rem;
    color: var(--text-muted);
    text-align: center;
}
.g2-empty svg { margin-bottom: .75rem; color: #d1d5db; }
.g2-empty h3 { font-size: .95rem; color: var(--text); margin: 0 0 .4rem; }
.g2-empty p  { font-size: .82rem; margin: 0; }

.g2-skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e8e8e8 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: g2-shimmer 1.4s infinite;
    border-radius: 8px;
}
@keyframes g2-shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ── Map view ───────────────────────────────────────── */
#g2-map {
    width: 100%;
    height: 100%;
}

#g2-map-search-bar {
    position: absolute;
    top: .75rem;
    left: 3.25rem;
    right: .75rem;
    z-index: 450;
    pointer-events: none;
}
#g2-map-search-bar select {
    pointer-events: all;
    width: 100%;
    max-width: 280px;
    box-shadow: var(--g2-shadow);
    background: #fff;
}

/* Custom Leaflet marker pins */
.g2-pin {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 2.5px solid #fff;
    box-shadow: 0 1px 5px rgba(0,0,0,.35);
}

/* ── Route view ─────────────────────────────────────── */
#g2-route-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.g2-route-header {
    padding: 1rem 1rem .6rem;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.g2-route-header h2 {
    font-size: 1rem;
    font-weight: 700;
    margin: 0 0 .2rem;
    display: flex;
    align-items: center;
    gap: .5rem;
}

.g2-route-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    text-align: center;
    color: var(--text-muted);
    gap: .5rem;
}
.g2-route-empty svg { color: #d1d5db; }
.g2-route-empty p { font-size: .85rem; margin: 0; }

.g2-route-list {
    flex: 1;
    overflow-y: auto;
    padding: .5rem 0;
}

.g2-route-stop {
    display: flex;
    align-items: center;
    padding: .65rem 1rem;
    gap: .75rem;
    border-bottom: 1px solid var(--border);
}
.g2-route-stop-num {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    font-size: .72rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.g2-route-stop-info { flex: 1; min-width: 0; }
.g2-route-stop-title { font-size: .85rem; font-weight: 600; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.g2-route-stop-addr  { font-size: .75rem; color: var(--text-muted); }
.g2-route-stop-remove {
    background: none;
    border: none;
    color: #d1d5db;
    font-size: 1.2rem;
    cursor: pointer;
    padding: .25rem;
    transition: color .12s;
    flex-shrink: 0;
}
.g2-route-stop-remove:hover { color: #ef4444; }

.g2-route-summary {
    padding: .7rem 1rem;
    font-size: .78rem;
    color: var(--text-muted);
    background: var(--bg);
    text-align: center;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.g2-route-actions {
    padding: .75rem 1rem;
    display: flex;
    flex-direction: column;
    gap: .5rem;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

/* ── Bottom nav ─────────────────────────────────────── */
#g2-bottom-nav {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    height: calc(var(--g2-nav-h) + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: #fff;
    border-top: 1px solid var(--border);
    display: flex;
    z-index: 300;
}

.g2-tab {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    color: var(--text-muted);
    font-size: .62rem;
    font-weight: 600;
    text-decoration: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: .4rem 0 .3rem;
    transition: color .13s;
    -webkit-tap-highlight-color: transparent;
}
.g2-tab.g2-tab-active {
    color: var(--primary);
    font-weight: 700;
    position: relative;
}
.g2-tab.g2-tab-active::before {
    content: '';
    position: absolute;
    top: 0;
    left: 20%;
    right: 20%;
    height: 2px;
    background: var(--primary);
    border-radius: 0 0 2px 2px;
}
.g2-tab svg { flex-shrink: 0; }

#g2-route-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--primary);
    color: #fff;
    border-radius: 999px;
    font-size: .58rem;
    font-weight: 800;
    min-width: 15px;
    height: 15px;
    padding: 0 4px;
    margin-left: 2px;
    vertical-align: middle;
}
#g2-route-badge:empty { display: none; }

/* ── FAB ─────────────────────────────────────────────── */
#g2-fab {
    position: fixed;
    right: 1rem;
    bottom: calc(var(--g2-bottom) + .75rem);
    z-index: 250;
    display: flex;
    align-items: center;
    gap: .4rem;
    padding: .7rem 1.2rem;
    border-radius: 999px;
    background: var(--primary);
    color: #fff;
    font-size: .875rem;
    font-weight: 700;
    text-decoration: none;
    box-shadow: 0 4px 16px rgba(37,99,235,.45), 0 1px 4px rgba(0,0,0,.15);
    transition: transform .12s, box-shadow .12s, opacity .2s;
    white-space: nowrap;
}
#g2-fab:hover { text-decoration: none; opacity: .92; }
#g2-fab:active { transform: scale(.95); }
/* Hide FAB on map view */
#g2-app[data-view="map"] #g2-fab { display: none; }

/* ── Detail sheet ───────────────────────────────────── */
#g2-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    z-index: 450;
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
}
#g2-backdrop.open { display: block; }

#g2-detail-sheet {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    height: 91vh;
    background: #fff;
    border-radius: var(--g2-sheet-r) var(--g2-sheet-r) 0 0;
    z-index: 500;
    transform: translateY(100%);
    transition: transform .32s cubic-bezier(.32, .72, 0, 1);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    will-change: transform;
}
#g2-detail-sheet.open { transform: translateY(0); }

#g2-detail-handle {
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    cursor: grab;
    touch-action: none;
}
#g2-detail-handle::after {
    content: '';
    width: 40px; height: 4px;
    background: var(--border-strong);
    border-radius: 2px;
}

#g2-detail-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .2rem .9rem .4rem;
    flex-shrink: 0;
    border-bottom: 1px solid var(--border);
    min-height: 36px;
}
.g2-detail-nav-btn {
    display: flex;
    align-items: center;
    gap: .25rem;
    background: none;
    border: none;
    color: var(--primary);
    font-size: .8rem;
    font-weight: 600;
    cursor: pointer;
    padding: .3rem .5rem;
    border-radius: 6px;
}
.g2-detail-nav-btn:hover { background: var(--bg); }
.g2-detail-nav-count { font-size: .75rem; color: var(--text-muted); font-weight: 500; }
.g2-detail-close {
    background: none;
    border: none;
    font-size: 1.3rem;
    color: var(--text-muted);
    cursor: pointer;
    padding: .2rem .4rem;
    line-height: 1;
}

#g2-detail-body {
    flex: 1;
    overflow: hidden;
    position: relative;
}

#g2-detail-track {
    display: flex;
    width: 300%;
    height: 100%;
    will-change: transform;
}

.g2-detail-slide {
    flex: 0 0 33.333%;
    min-width: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.g2-detail-photo {
    width: 100%;
    height: 220px;
    object-fit: cover;
    display: block;
    cursor: zoom-in;
}
.g2-detail-nophoto {
    width: 100%;
    height: 160px;
    background: linear-gradient(135deg, #e8ecf2 0%, #d2dae8 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #b0bcd0;
}

.g2-detail-content {
    padding: .9rem 1rem 1rem;
}

.g2-detail-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: .5rem;
    margin-bottom: .5rem;
}
.g2-detail-title {
    font-size: 1.1rem;
    font-weight: 800;
    color: var(--text);
    line-height: 1.3;
    margin: 0;
    flex: 1;
}
.g2-detail-status {
    padding: .25rem .75rem;
    border-radius: 999px;
    font-size: .72rem;
    font-weight: 700;
    color: #fff;
    flex-shrink: 0;
    margin-top: .1rem;
}
.g2-detail-status.open    { background: var(--g2-open); }
.g2-detail-status.closing { background: var(--g2-closing); }
.g2-detail-status.closed  { background: var(--g2-closed); }
.g2-detail-status.upcoming { background: var(--g2-upcoming); }
.g2-detail-status.ended   { background: var(--g2-ended); }

.g2-detail-meta {
    font-size: .8rem;
    color: var(--text-muted);
    margin-bottom: .5rem;
    display: flex;
    flex-direction: column;
    gap: .25rem;
}
.g2-detail-meta a { color: var(--primary); }

.g2-detail-desc {
    font-size: .85rem;
    color: var(--text);
    line-height: 1.55;
    margin-bottom: .75rem;
    white-space: pre-wrap;
}

.g2-detail-section {
    margin-bottom: .8rem;
}
.g2-detail-section-title {
    font-size: .68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--text-subtle);
    margin-bottom: .35rem;
}

.g2-detail-item-list {
    display: flex;
    flex-direction: column;
    gap: .2rem;
}
.g2-detail-item {
    font-size: .82rem;
    color: var(--text);
    padding: .2rem 0;
    border-bottom: 1px solid var(--border);
}
.g2-detail-item:last-child { border-bottom: none; }

#g2-detail-actions {
    padding: .65rem 1rem;
    padding-bottom: calc(.65rem + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid var(--border);
    background: #fff;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: .45rem;
}
.g2-detail-action-row {
    display: flex;
    gap: .5rem;
}

/* ── Filter modal ───────────────────────────────────── */
#g2-filter-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.35);
    z-index: 550;
}
#g2-filter-backdrop.open { display: block; }

#g2-filter-modal {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    max-height: 88vh;
    background: #fff;
    border-radius: var(--g2-sheet-r) var(--g2-sheet-r) 0 0;
    z-index: 600;
    transform: translateY(100%);
    transition: transform .3s cubic-bezier(.32, .72, 0, 1);
    overflow-y: auto;
    overscroll-behavior: contain;
}
#g2-filter-modal.open { transform: translateY(0); }

.g2-sheet-handle-bar {
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.g2-sheet-handle-bar::after {
    content: '';
    width: 40px; height: 4px;
    background: var(--border-strong);
    border-radius: 2px;
}

.g2-filter-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1rem .75rem;
    flex-shrink: 0;
}
.g2-filter-title { font-size: .95rem; font-weight: 700; }
.g2-filter-reset {
    background: none;
    border: none;
    color: var(--primary);
    font-size: .8rem;
    font-weight: 600;
    cursor: pointer;
    padding: 0;
}

.g2-filter-section {
    padding: .6rem 1rem;
    border-top: 1px solid var(--border);
}
.g2-filter-label {
    font-size: .72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--text-subtle);
    margin-bottom: .5rem;
}

.g2-pill-row {
    display: flex;
    gap: .4rem;
    flex-wrap: wrap;
}
.g2-pill {
    height: 32px;
    padding: 0 .9rem;
    border-radius: 999px;
    border: 1.5px solid var(--border);
    background: #fff;
    color: var(--text-muted);
    font-size: .8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all .12s;
}
.g2-pill.g2-pill-active {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.g2-toggle-row {
    display: flex;
    flex-direction: column;
    gap: .4rem;
}
.g2-toggle-label {
    display: flex;
    align-items: center;
    gap: .5rem;
    font-size: .82rem;
    color: var(--text);
    cursor: pointer;
    user-select: none;
}
.g2-toggle-label input[type=checkbox] {
    accent-color: var(--primary);
    width: 15px;
    height: 15px;
    flex-shrink: 0;
}

/* Category grid in filter modal */
.g2-cat-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: .4rem;
}
.g2-cat-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .2rem;
    padding: .5rem .3rem;
    border-radius: 10px;
    border: 1.5px solid var(--border);
    background: #fff;
    cursor: pointer;
    transition: all .12s;
    color: var(--text);
}
.g2-cat-btn.active {
    background: #eff6ff;
    border-color: var(--primary);
    color: var(--primary);
}
.g2-cat-emoji { font-size: 1.25rem; line-height: 1; }
.g2-cat-name  { font-size: .62rem; font-weight: 600; text-align: center; color: inherit; }

/* ── Lightbox (same as app.js lightbox) ─────────────── */
#img-lightbox {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1100;
    background: rgba(0,0,0,.92);
    flex-direction: column;
    align-items: center;
    justify-content: center;
}
#img-lightbox.open { display: flex; }
#lightbox-close {
    position: absolute;
    top: max(1rem, env(safe-area-inset-top));
    right: 1rem;
    z-index: 10;
    background: rgba(255,255,255,.12);
    border: none;
    color: #fff;
    font-size: 1.6rem;
    width: 44px; height: 44px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}
#lightbox-img-wrap {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}
#lightbox-img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    user-select: none;
    -webkit-user-drag: none;
    touch-action: none;
}
.lightbox-hint {
    position: absolute;
    bottom: max(1.5rem, env(safe-area-inset-bottom));
    color: rgba(255,255,255,.6);
    font-size: .78rem;
    transition: opacity .3s;
    pointer-events: none;
}

/* ── Desktop responsive ─────────────────────────────── */
@media (min-width: 640px) {
    #g2-cards {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        /* Rows size to content and pack at the top — otherwise the single
           row stretches to fill the tall flex container, leaving each card
           with a large blank area below its content. */
        grid-auto-rows: max-content;
        align-content: start;
        align-items: start;
        gap: 1rem;
        padding: .5rem 1rem 1rem;
    }
    #g2-cards .g2-empty { grid-column: 1 / -1; }
    .g2-cat-grid { grid-template-columns: repeat(5, 1fr); }
}

@media (min-width: 1024px) {
    :root {
        --g2-header-h: 56px;
        --g2-chips-h:  0px;
    }

    .g2-search-row { display: none; }
    .g2-header-top { height: 56px; }

    /* On desktop show chips inline in header area */
    #g2-chips-wrap {
        top: 56px;
        height: 52px;
    }
    :root { --g2-chips-h: 52px; }

    #g2-cards { grid-template-columns: repeat(3, 1fr); }
    .g2-cat-grid { grid-template-columns: repeat(5, 1fr); }

    #g2-detail-sheet {
        max-width: 480px;
        left: auto;
        right: 0;
        height: 100%;
        border-radius: 0;
    }

    #g2-filter-modal {
        max-width: 460px;
        left: auto;
        right: 0;
        border-radius: var(--g2-sheet-r) 0 0 var(--g2-sheet-r);
    }
}

/* ── Suspended card (moderator view) ─────────────────── */
.g2-card-suspended { opacity: .75; outline: 2px solid #dc2626; outline-offset: -2px; }
.g2-status-suspended {
    background: #dc2626 !important;
    color: #fff !important;
}
.g2-suspended-reason {
    font-size: .75rem;
    color: #991b1b;
    background: #fee2e2;
    border-radius: 4px;
    padding: .25rem .5rem;
    margin-top: .3rem;
}
.g2-suspended-mod-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .5rem;
    padding: .5rem .6rem;
    background: #fee2e2;
    border-radius: 6px;
    font-size: .8rem;
    color: #7f1d1d;
    margin-top: .5rem;
}

/* ── Touch ergonomics: bigger hit targets on touch devices ─────────────── */
@media (pointer: coarse) {
    .g2-icon-btn          { width: 44px; height: 44px; }
    .g2-search-clear      { width: 32px; height: 32px; font-size: 1.3rem; }
    .g2-detail-nav-btn    { padding: .6rem .8rem; }
    .g2-detail-close      { padding: .55rem .75rem; }
    .g2-route-stop-remove { padding: .6rem .7rem; font-size: 1.35rem; }
    .g2-community-chip    { padding: .28rem .7rem; }
}

/* ── Respect the user's reduced-motion preference ───────────────────────── */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .01ms !important;
        scroll-behavior: auto !important;
    }
}

/* ═══════════════════════════════════════════════════
   Browse (swipe) view — Tinder-style card deck
   ═══════════════════════════════════════════════════ */
#g2-app[data-view="browse"] #g2-browse-view { display: flex; flex-direction: column; }
#g2-app[data-view="browse"] #g2-fab { display: none; }

#g2-swipe-stage {
    flex: 1;
    position: relative;
    max-width: 440px;
    width: 100%;
    margin: 0 auto;
    padding: .75rem 1rem 0;
    min-height: 0;
}

.g2-swipe-card {
    position: absolute;
    inset: .75rem 1rem 0;
    background: #fff;
    border-radius: var(--g2-card-r);
    box-shadow: var(--g2-shadow);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    touch-action: none;          /* the card owns the gesture, not the scroller */
    user-select: none;
    -webkit-user-select: none;
    cursor: grab;
    will-change: transform;
}
.g2-swipe-card.g2-swipe-behind { pointer-events: none; }

.g2-swipe-media {
    flex: 1 1 55%;
    min-height: 0;
    position: relative;
    background: linear-gradient(160deg, #e0eaff 0%, #f2f4f7 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #b7c4dd;
}
.g2-swipe-img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    pointer-events: none;
}

.g2-swipe-body {
    flex: 0 0 auto;
    padding: .8rem 1rem calc(.9rem + env(safe-area-inset-bottom, 0px) * 0);
    display: flex;
    flex-direction: column;
    gap: .3rem;
}
.g2-swipe-title    { font-size: 1.15rem; font-weight: 800; color: var(--dark); margin: 0;
                     overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.g2-swipe-meta     { font-size: .8rem;  color: var(--text-muted); }
.g2-swipe-tags     { display: flex; flex-wrap: wrap; gap: .3rem; margin-top: .15rem; }

/* SAVE / PASS stamps revealed while dragging */
.g2-swipe-stamp {
    position: absolute;
    top: 1.25rem;
    padding: .3rem .9rem;
    border: 3px solid;
    border-radius: 8px;
    font-size: 1.35rem;
    font-weight: 900;
    letter-spacing: .1em;
    opacity: 0;
    pointer-events: none;
    background: rgba(255,255,255,.85);
    z-index: 5;
}
.g2-swipe-stamp-save { left: 1.25rem;  color: #16a34a; border-color: #16a34a; transform: rotate(-14deg); }
.g2-swipe-stamp-pass { right: 1.25rem; color: #64748b; border-color: #64748b; transform: rotate(14deg); }

/* Action buttons row */
#g2-swipe-actions {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1.1rem;
    padding: .9rem 0 1rem;
}
.g2-swipe-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    border: none;
    background: #fff;
    box-shadow: var(--g2-shadow);
    cursor: pointer;
    transition: transform .12s;
}
.g2-swipe-btn:active { transform: scale(.9); }
.g2-swipe-btn-undo { width: 44px; height: 44px; color: var(--text-muted); }
.g2-swipe-btn-info { width: 44px; height: 44px; color: var(--primary); }
.g2-swipe-btn-pass { color: #64748b; }
.g2-swipe-btn-save { width: 60px; height: 60px; color: #e11d48; }

/* Deck-empty state */
.g2-swipe-empty {
    position: absolute;
    inset: .75rem 1rem 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: .6rem;
    text-align: center;
    color: var(--text-muted);
    padding: 2rem 1.5rem;
}
.g2-swipe-empty h3 { margin: 0; font-size: 1.05rem; color: var(--dark); }
.g2-swipe-empty p  { margin: 0 0 .5rem; font-size: .85rem; }

/* Transient toast (e.g. "Saved!", "Log in to save") */
#g2-swipe-toast {
    position: fixed;
    left: 50%;
    bottom: calc(var(--g2-bottom) + 86px);
    transform: translateX(-50%);
    background: rgba(17, 24, 39, .92);
    color: #fff;
    font-size: .85rem;
    font-weight: 600;
    padding: .55rem 1rem;
    border-radius: 999px;
    z-index: 700;
    opacity: 0;
    transition: opacity .25s;
    pointer-events: none;
    white-space: nowrap;
}
#g2-swipe-toast a { color: #93c5fd; pointer-events: auto; }
#g2-swipe-toast.show { opacity: 1; }
