/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    color: #1a1a2e;
    background: #f0f4f8;
    display: flex;
    flex-direction: column;
}

/* === Color tokens === */
:root {
    --primary: #2563eb;
    --primary-light: #dbeafe;
    --primary-dark: #1d4ed8;
    --accent: #f59e0b;
    --accent-light: #fef3c7;
    --bg: #ffffff;
    --bg-alt: #f8fafc;
    --text: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-lg: 0 4px 6px rgba(0,0,0,0.07), 0 10px 15px rgba(0,0,0,0.1);
    --radius: 12px;
    --header-h: 56px;
    --chip-h: 48px;
}

/* === Header === */
#header {
    position: fixed; top: 0; left: 0; right: 0; z-index: 1000;
    height: var(--header-h);
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 12px;
    gap: 10px;
}
.header-left { flex-shrink: 0; }
.logo {
    font-size: 22px;
    font-weight: 700;
    color: var(--primary);
    letter-spacing: -0.5px;
}
.header-search { flex: 1; min-width: 0; }
.search-box {
    display: flex;
    align-items: center;
    background: var(--bg-alt);
    border: 1px solid var(--border);
    border-radius: 24px;
    padding: 0 12px;
    height: 38px;
    transition: border-color 0.2s;
}
.search-box:focus-within { border-color: var(--primary); }
.search-icon { width: 18px; height: 18px; color: var(--text-muted); flex-shrink: 0; }
.search-box input {
    flex: 1;
    border: none;
    background: none;
    outline: none;
    font-size: 15px;
    padding: 0 8px;
    color: var(--text);
    font-family: inherit;
}
.search-box input::placeholder { color: var(--text-muted); }
.search-clear {
    display: none;
    border: none;
    background: none;
    font-size: 20px;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0 2px;
    line-height: 1;
}
.search-clear.visible { display: block; }
.header-right { flex-shrink: 0; }
.icon-btn {
    width: 38px; height: 38px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s;
}
.icon-btn:hover { background: var(--primary-light); }
.icon-btn:active { background: var(--primary); color: #fff; }
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn.locating { animation: pulse-locate 1s ease infinite; }
@keyframes pulse-locate {
    0%, 100% { background: var(--primary-light); }
    50% { background: var(--primary); color: #fff; }
}

/* === Categories === */
.categories {
    position: fixed;
    top: var(--header-h);
    left: 0; right: 0;
    z-index: 999;
    height: var(--chip-h);
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 12px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}
.categories::-webkit-scrollbar { display: none; }
.chip {
    flex-shrink: 0;
    height: 32px;
    padding: 0 14px;
    border-radius: 16px;
    border: 1px solid var(--border);
    background: var(--bg);
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
    white-space: nowrap;
}
.chip:hover { border-color: var(--primary); color: var(--primary); }
.chip.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}
.chip .chip-icon { margin-right: 4px; font-size: 15px; }

/* === Search this area button === */
.search-area-btn {
    position: fixed;
    top: calc(var(--header-h) + var(--chip-h) + 12px);
    left: 50%;
    transform: translateX(-50%);
    z-index: 400;
    background: var(--bg);
    color: var(--primary);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 8px 20px;
    font-size: 14px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    box-shadow: var(--shadow-lg);
    transition: background 0.2s;
}
.search-area-btn:hover { background: var(--primary-light); }
.search-area-btn:active { background: var(--primary); color: #fff; }
.search-area-btn.hidden { display: none; }

/* === Map === */
#map {
    position: fixed;
    top: calc(var(--header-h) + var(--chip-h));
    left: 0; right: 0;
    bottom: 0;
    z-index: 1;
}

/* Custom map markers */
.marker-icon {
    width: 32px; height: 32px;
    border-radius: 50% 50% 50% 0;
    transform: rotate(-45deg);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 6px rgba(0,0,0,0.3);
    border: 2px solid #fff;
}
.marker-icon span {
    transform: rotate(45deg);
    font-size: 14px;
    line-height: 1;
}
.marker-dog_park { background: #22c55e; }
.marker-pet_supply { background: #8b5cf6; }
.marker-vet { background: #ef4444; }
.marker-groomer { background: #ec4899; }
.marker-hotel { background: #3b82f6; }
.marker-restaurant { background: #f97316; }
.marker-dog_beach { background: #06b6d4; }
.marker-dog_walk { background: #14b8a6; }
.marker-boarding { background: #6366f1; }
.marker-daycare { background: #a855f7; }
.marker-trainer { background: #84cc16; }
.marker-rescue { background: #e11d48; }
.marker-rental { background: #0ea5e9; }
.marker-water_stop { background: #38bdf8; }
.marker-treat_stop { background: #fbbf24; }
.marker-pup_cup { background: #fb923c; }
.marker-leash_friendly { background: #4ade80; }
.marker-potty_area { background: #a3e635; }
.marker-pet_wash { background: #2dd4bf; }
.marker-other { background: #94a3b8; }

/* === Results panel === */
.panel {
    position: fixed;
    left: 0; right: 0;
    bottom: 0;
    z-index: 500;
    background: var(--bg);
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
    display: flex;
    flex-direction: column;
    max-height: 70vh;
    transform: translateY(calc(100% - 100px));
    transition: transform 0.3s ease;
}
.panel.expanded { transform: translateY(0); }
.panel.peek { transform: translateY(calc(100% - 100px)); }
.panel-handle {
    display: flex;
    justify-content: center;
    padding: 10px 0 6px;
    cursor: grab;
}
.panel-handle span {
    width: 36px;
    height: 4px;
    border-radius: 2px;
    background: #cbd5e1;
}
.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 16px 10px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-muted);
}
.view-toggle {
    border: none;
    background: none;
    cursor: pointer;
    color: var(--text-muted);
    padding: 4px;
}
.view-toggle svg { width: 20px; height: 20px; }
.results {
    flex: 1;
    overflow-y: auto;
    padding: 0 12px 12px;
    -webkit-overflow-scrolling: touch;
}

/* === Result cards === */
.card {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 8px;
    cursor: pointer;
    transition: box-shadow 0.2s, border-color 0.2s;
}
.card:hover { box-shadow: var(--shadow); border-color: var(--primary); }
.card:active { background: var(--bg-alt); }
.card-icon {
    width: 40px; height: 40px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
    color: #fff;
}
.card-body { flex: 1; min-width: 0; }
.card-name {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.card-kind {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px;
    text-transform: capitalize;
}
.card-address {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.card-meta {
    display: flex;
    gap: 12px;
    margin-top: 4px;
    font-size: 12px;
    color: var(--text-muted);
}
.card-meta .star { color: var(--accent); }
.card-distance {
    font-size: 13px;
    font-weight: 600;
    color: var(--primary);
    flex-shrink: 0;
    text-align: right;
    min-width: 50px;
}

/* === Detail overlay === */
.detail-overlay {
    position: fixed;
    inset: 0;
    z-index: 2000;
    background: rgba(0,0,0,0.4);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    animation: fade-in 0.2s ease;
}
.detail-overlay.hidden { display: none; }
.detail-card {
    background: var(--bg);
    border-radius: 16px 16px 0 0;
    width: 100%;
    max-width: 600px;
    max-height: 80vh;
    overflow-y: auto;
    padding: 20px;
    animation: slide-up 0.3s ease;
}
.detail-close {
    position: absolute;
    top: 16px; right: 16px;
    width: 32px; height: 32px;
    border-radius: 50%;
    border: none;
    background: var(--bg-alt);
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
}
.detail-close:hover { background: var(--border); }
.detail-name { font-size: 22px; font-weight: 700; margin-bottom: 4px; padding-right: 40px; }
.detail-kind {
    font-size: 14px;
    color: var(--primary);
    font-weight: 500;
    text-transform: capitalize;
    margin-bottom: 16px;
}
.detail-section { margin-bottom: 16px; }
.detail-label { font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 6px; }
.detail-value { font-size: 15px; color: var(--text); line-height: 1.5; }
.detail-value a { color: var(--primary); text-decoration: none; }
.detail-value a:hover { text-decoration: underline; }
.detail-rating { display: flex; align-items: center; gap: 8px; }
.detail-stars { color: var(--accent); font-size: 18px; }
.detail-rating-text { font-size: 14px; color: var(--text-muted); }
.detail-directions {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 10px 20px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    margin-top: 8px;
}
.detail-directions:hover { background: var(--primary-dark); }

/* === Load more === */
.load-more-wrap { padding: 8px 16px 16px; text-align: center; }
.load-more-btn {
    background: var(--primary-light);
    color: var(--primary);
    border: none;
    border-radius: 8px;
    padding: 10px 24px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    width: 100%;
}
.load-more-btn:hover { background: var(--primary); color: #fff; }

/* === Spinner === */
.spinner {
    position: fixed;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    z-index: 3000;
}
.spinner.hidden { display: none; }
.spinner-ring {
    width: 40px; height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes slide-up { from { transform: translateY(100%); } to { transform: translateY(0); } }

/* === Empty state === */
.empty-state {
    text-align: center;
    padding: 24px 16px;
    color: var(--text-muted);
}
.empty-state .empty-icon { font-size: 40px; margin-bottom: 8px; }
.empty-state p { font-size: 14px; line-height: 1.5; }

/* === Desktop layout (>768px) === */
@media (min-width: 769px) {
    .panel {
        left: 0;
        top: calc(var(--header-h) + var(--chip-h));
        bottom: 0;
        right: auto;
        width: 380px;
        max-height: none;
        border-radius: 0;
        box-shadow: 2px 0 8px rgba(0,0,0,0.08);
        transform: none;
        transition: none;
    }
    .panel.expanded, .panel.peek { transform: none; }
    .panel-handle { display: none; }
    #map {
        left: 380px;
    }
    .search-area-btn {
        left: calc(380px + (100% - 380px) / 2);
    }
    .detail-overlay {
        align-items: center;
    }
    .detail-card {
        border-radius: 16px;
        max-width: 500px;
    }
}

/* === Leaflet popup overrides === */
.leaflet-popup-content-wrapper {
    border-radius: var(--radius) !important;
    box-shadow: var(--shadow-lg) !important;
    padding: 0 !important;
}
.leaflet-popup-content {
    margin: 12px 14px !important;
    font-family: 'Inter', sans-serif !important;
    font-size: 14px !important;
    line-height: 1.4 !important;
}
.leaflet-popup-content .popup-name {
    font-weight: 600;
    font-size: 15px;
    margin-bottom: 2px;
}
.leaflet-popup-content .popup-kind {
    font-size: 12px;
    color: var(--text-muted);
    text-transform: capitalize;
}
.leaflet-popup-content .popup-link {
    display: inline-block;
    margin-top: 6px;
    font-size: 13px;
    color: var(--primary);
    cursor: pointer;
    font-weight: 500;
}
