:root {
    --bg: #f5f5f5;
    --primary: #2c5aa0;
    --primary-fg: #fff;
    --card-bg: #fff;
    --border: #ddd;
    --text: #222;
    --muted: #666;
    --hh: #2c5aa0;       /* happy hour blue */
    --special: #3aa758;  /* special green */
    --voucher: #e0892a;  /* voucher orange */
    --today: #f5d76e;    /* gentle yellow accent for "today" */
    --selected: #d9534f;
    font-family: system-ui, -apple-system, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; background: var(--bg); color: var(--text); }
body { display: grid; grid-template-rows: auto auto 1fr; }

.app-bar {
    background: var(--primary); color: var(--primary-fg);
    padding: env(safe-area-inset-top, 0) 1rem .75rem;
    display: flex; justify-content: space-between; align-items: center;
}
.app-bar h1 { font-size: 1.1rem; margin: 0; }
.app-bar-actions { display: flex; gap: .5rem; }
.app-bar button {
    background: transparent; border: 0; color: inherit; font-size: 1rem;
    cursor: pointer; padding: .25rem .5rem; border-radius: 4px;
}
.app-bar button.active { background: rgba(255,255,255,.2); }

.day-tabs {
    display: grid; grid-template-columns: repeat(7, 1fr); background: var(--card-bg);
    border-bottom: 1px solid var(--border);
}
.day-tabs button {
    background: none; border: 0; padding: .5rem 0 .4rem; cursor: pointer; color: var(--text);
    display: flex; flex-direction: column; align-items: center; gap: 1px;
    position: relative;
}
.day-tabs button .day-letter { font-weight: 600; line-height: 1; }
.day-tabs button .day-count { font-size: .65rem; color: var(--muted); line-height: 1; }
.day-tabs button.today::after {
    content: ""; position: absolute; bottom: 2px;
    width: 4px; height: 4px; background: var(--today); border-radius: 50%;
}
.day-tabs button.active { background: var(--primary); color: var(--primary-fg); }
.day-tabs button.active .day-count { color: rgba(255,255,255,.7); }
.day-tabs button.active.today::after { background: var(--today); bottom: 1px; }

#view-container {
    position: relative;
    display: flex;
    height: 100%;
    min-height: 0;  /* let flex children own their own scroll */
}
#map { flex: 1; min-height: 50vh; height: 100%; position: relative; }

/* List view: hidden on mobile by default; shown side-by-side on desktop. */
#list-view {
    background: var(--card-bg);
    overflow-y: auto;
    border-left: 1px solid var(--border);
    -webkit-overflow-scrolling: touch;
}
.venue-list { list-style: none; margin: 0; padding: 0; }
.venue-row {
    padding: .65rem 1rem .65rem .5rem;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    display: grid;
    /* heart | pip | name | distance */
    grid-template-columns: auto auto 1fr auto;
    gap: .15rem .5rem;
    align-items: baseline;
}
.venue-row:hover, .venue-row:focus-visible { background: #f0f4fb; outline: 0; }
.venue-row.selected { background: #fde8e8; }
.venue-row .v-fav-btn {
    grid-row: 1; grid-column: 1; align-self: center;
    background: transparent; border: 0; padding: .25rem .35rem;
    font-size: 1.2rem; line-height: 1; color: #bbb;
    cursor: pointer; border-radius: 4px;
}
.venue-row .v-fav-btn:hover { color: #d9534f; background: #fde8e8; }
.venue-row .v-fav-btn.active { color: #d9534f; }
.venue-row .v-pip {
    width: 8px; height: 8px; border-radius: 50%; align-self: center;
    grid-row: 1; grid-column: 2;
}
.venue-row .v-name {
    font-weight: 600; grid-row: 1; grid-column: 3;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.venue-row .v-distance {
    grid-row: 1; grid-column: 4; font-size: .75rem; color: var(--muted);
    white-space: nowrap;
}
.venue-row .v-meta {
    grid-row: 2; grid-column: 3 / span 2;
    font-size: .8rem; color: var(--muted);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
/* Inline badges on list rows: small pill chips. */
.v-badge {
    display: inline-block; font-size: .65rem; padding: .05rem .35rem;
    border-radius: 3px; margin-left: .3rem; vertical-align: middle;
    font-weight: normal;
}
.v-badge-popular { background: #e3f0ff; color: #1b4a8a; }
.v-badge-new     { background: #e6f6e6; color: #1a6a1a; }
.v-badge-review  { background: #fff3e0; color: #8a4a00; cursor: help; }
.v-badge-reverse { background: #efe5ff; color: #4a2a8a; }

/* Favorite heart markers. Leaflet wraps divIcon content in a default
 * .leaflet-div-icon box (border + bg); strip it so just the glyph shows. */
.fav-marker {
    background: transparent !important;
    border: none !important;
    text-align: center;
    text-shadow: 0 0 2px #fff, 0 0 4px rgba(0,0,0,.35);
}
.fav-marker.selected { transform: scale(1.15); transform-origin: center bottom; }

/* Venue-sheet socials, features, phone, hours -- compact rows under the
 * address. The chips keep visual hierarchy down so the deals stay primary. */
.socials { margin: .35rem 0; }
.social-link {
    display: inline-flex; align-items: center; justify-content: center;
    width: 1.8rem; height: 1.8rem; margin-right: .35rem;
    background: var(--card-bg); color: var(--accent, #2c5aa0);
    border: 1px solid var(--border); border-radius: 999px;
    font-size: .8rem; font-weight: 600; text-decoration: none;
}
.social-link:hover { background: var(--accent, #2c5aa0); color: #fff; }
.features { margin: .35rem 0; line-height: 1.9; }
.feature-chip {
    display: inline-block; padding: .1rem .55rem; margin-right: .3rem;
    background: #eef4fb; color: #2c5aa0; border-radius: 999px;
    font-size: .75rem;
}
.phone { margin: .25rem 0; }
.phone a { color: var(--accent, #2c5aa0); text-decoration: none; }
.hours-osm { margin: .25rem 0; font-size: .85rem; color: var(--muted); }

/* "unknown cuisine" / "unknown price" sentinels in the meta line. Italic
 * + muted so they don't compete with real values that get the same row. */
.meta-unknown { color: var(--muted); font-style: italic; }

/* Subtle "sorted by distance from home" hint above the list. */
.list-sort-hint {
    font-size: .75rem; color: var(--muted); padding: .35rem .75rem;
    border-bottom: 1px solid var(--border); background: var(--bg-alt, transparent);
}

/* Specific review reasons in the venue sheet, shown only when needs_review.
 * Keeps the orange palette of the badge so users connect the two. */
.review-reasons {
    background: #fff8ec; border: 1px solid #f1d8a8; border-radius: .35rem;
    padding: .55rem .75rem; margin: .55rem 0;
}
.review-reasons-title { margin: 0 0 .25rem; font-weight: 600; color: #8a4a00; }
.review-reasons ul { margin: 0; padding-left: 1.2rem; }
.review-reasons li { font-size: .85rem; color: #5a3a10; }
.venue-row .v-nogeo {
    display: inline-block; font-size: .65rem; padding: .05rem .35rem;
    background: #f0e2c4; color: #7a5b1c; border-radius: 3px; margin-left: .25rem;
    vertical-align: middle;
}
.venue-row .v-photo-icon {
    font-size: .8rem; margin-left: .3rem; opacity: .65;
    vertical-align: middle;
}

/* Tiny count tag next to filter options: "Old Market (12)" so users see
   coverage before clicking and don't gray the map by surprise. */
.count-tag { color: var(--muted); font-size: .8rem; }

/* Header view-toggle (mobile only). Hidden on wide screens since both panes show. */
.view-toggle {
    display: inline-flex; border: 1px solid rgba(255,255,255,.4); border-radius: 999px;
    overflow: hidden; margin-right: .25rem;
}
.view-toggle button {
    background: transparent; color: inherit; border: 0; padding: .2rem .65rem;
    font-size: .8rem; cursor: pointer;
}
.view-toggle button[aria-selected="true"] {
    background: rgba(255,255,255,.25);
}

/* Default mobile: one view at a time, controlled by body data-view attribute. */
body[data-view="list"] #map { display: none; }
body[data-view="map"] #list-view { display: none; }

/* Empty state overlay sits on top of the map */
.empty-overlay {
    position: absolute; inset: 0; display: grid; place-items: center;
    background: rgba(245,245,245,.85); pointer-events: none; z-index: 500;
}
.empty-overlay p { background: var(--card-bg); padding: .75rem 1rem;
    border-radius: 8px; box-shadow: 0 2px 8px rgba(0,0,0,.15); }
.empty-overlay.hidden { display: none; }

.sheet {
    position: fixed; left: 0; right: 0; bottom: 0;
    background: var(--card-bg);
    padding: 1rem 1rem calc(1rem + env(safe-area-inset-bottom));
    border-top: 1px solid var(--border); max-height: 70vh; overflow: auto;
    box-shadow: 0 -4px 12px rgba(0,0,0,.1); z-index: 1000;
}
.sheet.hidden { display: none; }
/* Sticky so the close button stays reachable as the user scrolls through
 * a long sheet. The negative top padding compensates for the sheet's own
 * 1rem top padding so the sticky header doesn't leave a visible gap. */
.sheet-header {
    display: flex; justify-content: space-between; align-items: center;
    position: sticky; top: -1rem; z-index: 5;
    background: var(--card-bg);
    margin: -1rem -1rem 0; padding: .75rem 1rem;
    border-bottom: 1px solid var(--border);
}
.sheet-header h2 { margin: 0; font-size: 1.1rem; }
.sheet-header-actions { display: flex; gap: .5rem; align-items: center; }
.sheet-close-btn {
    background: transparent; border: 0; color: var(--muted); cursor: pointer;
    font-size: 1.6rem; line-height: 1; padding: 0 .35rem;
    width: 2rem; height: 2rem; border-radius: 4px;
}
.sheet-close-btn:hover { background: var(--border); color: var(--text, #222); }
.link-btn { background: none; border: 0; color: var(--primary); cursor: pointer;
    font-size: .85rem; padding: .25rem 0; }
.sheet fieldset { border: 0; padding: 0; margin: 0 0 1rem; }
.sheet label { display: block; padding: .5rem 0; }
.sheet legend { font-weight: 600; padding: 0; margin-bottom: .25rem; }
.sheet .meta { color: var(--muted); font-size: .85rem; margin: -.5rem 0 .5rem; }
.sheet .distance { color: var(--muted); font-size: .85rem; }
.sheet .hint { color: var(--muted); font-size: .85rem; }

/* Kind pip = small colored swatch in front of a kind name */
.kind-pip {
    display: inline-block; width: 10px; height: 10px; border-radius: 50%;
    vertical-align: middle; margin: 0 .35em 0 .25em;
}
.kind-happy_hour { background: var(--hh); }
.kind-special    { background: var(--special); }
.kind-voucher    { background: var(--voucher); }

.venue-deal { padding: .5rem 0; border-bottom: 1px solid var(--border); }
.venue-deal:last-child { border: 0; }
.venue-deal .kind {
    display: inline-block; color: #fff;
    padding: .1em .5em; border-radius: 3px; font-size: .75rem; margin-right: .5rem;
}
.venue-deal .kind.kind-happy_hour { background: var(--hh); }
.venue-deal .kind.kind-special    { background: var(--special); }
.venue-deal .kind.kind-voucher    { background: var(--voucher); }
.venue-deal .deal-text { color: var(--muted); font-size: .85rem; display: block;
    margin-top: .25rem; }
.venue-deal .deal-source-link { color: var(--muted); font-size: .75rem;
    margin-top: .25rem; display: inline-block; }

.fav-btn {
    background: transparent; border: 1px solid var(--border);
    border-radius: 999px; padding: .25rem .75rem; cursor: pointer;
    font-size: .9rem;
}
.fav-btn.active { background: #ffe1e1; border-color: #d9534f; color: #d9534f; }

/* Home marker: emoji rendered inside a Leaflet divIcon. Background-transparent
   so it sits cleanly on the map tiles; the drop-shadow keeps the emoji
   legible against busy backgrounds. */
.home-icon {
    background: transparent;
    border: 0;
    font-size: 22px;
    line-height: 28px;
    text-align: center;
    filter: drop-shadow(0 1px 2px rgba(0,0,0,.4));
}

.venue-photo {
    margin: 0 0 .75rem;
    border-radius: 6px;
    overflow: hidden;
    background: #eee;
}
.venue-photo img {
    width: 100%;
    max-height: 220px;
    object-fit: cover;
    display: block;
}
.venue-photo figcaption {
    font-size: .7rem;
    color: var(--muted);
    padding: .2rem .4rem;
    text-align: right;
    background: var(--card-bg);
}

.report-link { margin-top: .75rem; font-size: .85rem; }
.report-link a { color: var(--muted); }
.report-link .link-btn { font-size: .85rem; padding: 0; }
.contribute-links { margin-top: 1rem; font-size: .85rem; color: var(--muted); }
.contribute-links a { color: var(--hh); }
.contribute-links .link-btn { font-size: .85rem; padding: 0; }

.tip-jar { margin-top: .5rem; font-size: .85rem; color: var(--muted); }
.tip-jar a { color: var(--hh); }

#contribute-sheet { max-height: 92vh; }
#contribute-iframe {
    width: 100%; min-height: 70vh; border: 0;
    background: var(--bg);
}

.slider-row { display: grid; grid-template-columns: 1fr; gap: .25rem; padding: .5rem 0; }
.slider-row input[type=range] { width: 100%; }
.slider-row input[type=text] {
    width: 100%; padding: .5rem .75rem; font-size: 1rem;
    border: 1px solid var(--border); border-radius: 4px;
}
.sheet button:not(.link-btn):not(.fav-btn) {
    background: var(--primary); color: var(--primary-fg);
    border: 0; padding: .5rem 1rem; margin: .25rem .25rem .25rem 0;
    border-radius: 4px; cursor: pointer; font-size: .9rem;
}
.sheet button:not(.link-btn):not(.fav-btn).pressed {
    background: var(--selected);
}
.banner {
    position: absolute; top: .5rem; left: 50%; transform: translateX(-50%);
    background: var(--card-bg); padding: .5rem 1rem; border-radius: 999px;
    box-shadow: 0 2px 8px rgba(0,0,0,.15); z-index: 1100; font-size: .85rem;
}
.banner.hidden { display: none; }

@media (min-width: 768px) {
    body { max-width: 60rem; margin: 0 auto; box-shadow: 0 0 16px rgba(0,0,0,.1); }
}

/* Desktop: show both panes side-by-side; hide the mobile toggle. */
@media (min-width: 900px) {
    body { max-width: 80rem; }
    body[data-view="list"] #map,
    body[data-view="map"] #list-view { display: block; }
    .view-toggle { display: none; }
    #list-view { flex: 0 0 22rem; max-width: 22rem; }

    /* The flex container puts the map on the left and the list pane on
       the right. Sheets are position:fixed, so we anchor them to span
       only the map column - left edge at the body's left edge, right
       edge at the list pane's left edge - so the list stays scrollable
       while a venue is selected. On mobile (below 900px) the sheets
       still span full width (this block doesn't fire there). */
    #venue-sheet, #contribute-sheet, #home-sheet, #filter-sheet {
        /* Centered 80rem body: left edge = 50% - 40rem.
           List's left edge = body's right edge - 22rem = 50% + 40rem - 22rem,
           i.e., 50% - 18rem from the right of the viewport. */
        left: calc(50% - 40rem);
        right: calc(50% - 18rem);
        max-width: none;
        margin-left: 0;
        margin-right: 0;
    }
    /* When the viewport is narrower than the centered max, the body fills
       the screen edge to edge. Map is on the left, list is the rightmost
       22rem. Sheet covers the left side up to where the list begins. */
    @media (max-width: 80rem) {
        #venue-sheet, #contribute-sheet, #home-sheet, #filter-sheet {
            left: 0;
            right: 22rem;
        }
    }
}
