/* ===========================================
   Sofia Living Score — Production Styles
   =========================================== */

:root {
    --blue: #0A5CDB;
    --blue-light: #EBF1FE;
    --blue-dark: #0848B0;
    --g50: #F9FAFB; --g100: #F3F4F6; --g200: #E5E7EB; --g300: #D1D5DB;
    --g400: #9CA3AF; --g500: #6B7280; --g600: #4B5563; --g700: #374151;
    --g800: #1F2937; --g900: #111827;
    --green: #22C55E; --yellow: #EAB308; --orange: #F97316; --red: #EF4444;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,.08), 0 4px 12px rgba(0,0,0,.05);
    --shadow-lg: 0 4px 12px rgba(0,0,0,.1), 0 12px 32px rgba(0,0,0,.08);
    --panel-w: 420px;
    --header-h: 52px;
    --ease: cubic-bezier(.4,0,.2,1);
    --t: .3s;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    color: var(--g800);
    overflow: hidden;
    height: 100dvh;
    width: 100vw;
}

/* ---- Header ---- */
.brand-header {
    position: absolute; top: 0; left: 0; right: 0;
    height: var(--header-h);
    z-index: 1001;
    background: linear-gradient(135deg, #0A5CDB 0%, #2979FF 50%, #448AFF 100%);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    box-shadow: 0 2px 12px rgba(10,92,219,.25);
}

.brand-left { display: flex; align-items: center; gap: 10px; }

.brand-logo {
    width: 30px; height: 30px;
    background: rgba(255,255,255,.18);
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-size: 14px;
}

.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-name { font-size: 14px; font-weight: 700; color: #fff; letter-spacing: -.02em; }
.brand-tagline { font-size: 10px; color: rgba(255,255,255,.65); }

.about-trigger {
    background: rgba(255,255,255,.15);
    border: none; border-radius: 50%;
    width: 32px; height: 32px;
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-size: 16px; cursor: pointer;
    transition: background var(--t) var(--ease);
}
.about-trigger:hover { background: rgba(255,255,255,.25); }

/* ---- Map ---- */
#map {
    position: absolute; top: var(--header-h); left: 0;
    width: 100%; height: calc(100% - var(--header-h));
    z-index: 1;
}
.leaflet-control-attribution { font-size: 10px !important; }

/* ---- Search ---- */
.search-container {
    position: absolute;
    top: calc(var(--header-h) + 10px);
    left: 50%; transform: translateX(-50%);
    z-index: 1000;
    width: 90%; max-width: 460px;
}

.search-bar {
    display: flex; align-items: center;
    background: #fff; border-radius: 48px;
    box-shadow: var(--shadow-lg);
    padding: 0 18px; height: 46px; gap: 8px;
    transition: box-shadow var(--t) var(--ease);
}
.search-bar:focus-within {
    box-shadow: 0 4px 16px rgba(10,92,219,.15), 0 12px 32px rgba(0,0,0,.1);
}
.search-icon { color: var(--g400); font-size: 16px; flex-shrink: 0; }
#searchInput {
    border: none; outline: none;
    font-size: 14px; flex: 1;
    background: transparent; color: var(--g800); font-family: inherit;
}
#searchInput::placeholder { color: var(--g400); }

.search-clear {
    display: none;
    background: var(--g200); border: none; border-radius: 50%;
    width: 22px; height: 22px;
    font-size: 14px; line-height: 1;
    cursor: pointer; color: var(--g600); flex-shrink: 0;
    align-items: center; justify-content: center;
    transition: background var(--t);
}
.search-clear:hover { background: var(--g300); }
.search-clear.visible { display: flex; }

.search-results {
    display: none; list-style: none;
    background: #fff; border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    margin-top: 6px; overflow: hidden; max-height: 240px; overflow-y: auto;
}
.search-results.open { display: block; }
.search-results li {
    padding: 11px 18px; font-size: 13px; color: var(--g700);
    cursor: pointer; border-bottom: 1px solid var(--g100);
    transition: background .15s;
}
.search-results li:last-child { border-bottom: none; }
.search-results li:hover { background: var(--blue-light); }
.search-results .no-results { color: var(--g400); cursor: default; }
.search-results .no-results:hover { background: transparent; }

/* ---- Panel ---- */
.panel {
    position: absolute; top: var(--header-h); right: 0;
    width: var(--panel-w);
    height: calc(100% - var(--header-h));
    background: #fff;
    z-index: 999;
    box-shadow: -4px 0 24px rgba(0,0,0,.1);
    transform: translateX(100%);
    transition: transform var(--t) var(--ease);
    display: flex; flex-direction: column;
}
.panel.open { transform: translateX(0); }

.panel-drag { display: none; }

.panel-close {
    position: absolute; top: 10px; right: 10px;
    background: rgba(255,255,255,.7); backdrop-filter: blur(4px);
    border: none; border-radius: 50%;
    width: 34px; height: 34px;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; z-index: 10; color: var(--g600);
    transition: background var(--t);
}
.panel-close:hover { background: var(--g200); }

.panel-scroll {
    flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
}

/* ---- Panel hero (dark gradient) ---- */
.panel-hero {
    background: linear-gradient(160deg, #0f172a 0%, #1e293b 100%);
    padding: 28px 24px 24px;
    color: #fff;
    position: relative;
}

.hero-content { text-align: center; }

.score-ring {
    position: relative;
    width: 130px; height: 130px;
    margin: 0 auto 14px;
}
.score-ring svg {
    width: 100%; height: 100%;
    transform: rotate(-90deg);
}
.ring-bg { fill: none; stroke: rgba(255,255,255,.1); stroke-width: 8; }
.ring-fill {
    fill: none; stroke: var(--green); stroke-width: 8;
    stroke-linecap: round;
    stroke-dasharray: 326.73; stroke-dashoffset: 326.73;
    transition: stroke-dashoffset 1.2s var(--ease), stroke .6s ease;
}

.score-num {
    position: absolute; top: 50%; left: 50%;
    transform: translate(-50%,-50%);
    font-size: 44px; font-weight: 800;
    line-height: 1; color: #fff;
}

.score-verdict { font-size: 16px; font-weight: 600; margin-bottom: 4px; }
.score-addr {
    font-size: 12px; color: rgba(255,255,255,.5);
    max-width: 300px; margin: 0 auto;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.score-compare {
    margin-top: 10px;
    font-size: 12px;
    color: rgba(255,255,255,.45);
    font-weight: 500;
}

.cache-badge {
    position: absolute; top: 12px; left: 14px;
    font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em;
    padding: 2px 8px; border-radius: 20px;
    background: rgba(34,197,94,.2); color: #4ade80;
}
.cache-badge.is-cached {
    background: rgba(250,204,21,.15); color: #fbbf24;
}

/* Share */
.share-btn {
    display: flex; align-items: center; justify-content: center; gap: 8px;
    width: calc(100% - 48px); margin: 16px auto 0;
    padding: 10px; background: var(--g50);
    border: 1px solid var(--g200); border-radius: var(--radius-sm);
    font-size: 13px; font-family: inherit; color: var(--g600);
    cursor: pointer; transition: all .2s;
}
.share-btn:hover { background: var(--blue-light); border-color: var(--blue); color: var(--blue); }
.share-btn i { font-size: 14px; }

/* Toast */
.toast {
    position: fixed; bottom: 24px; left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--g900); color: #fff;
    padding: 10px 24px; border-radius: 48px;
    font-size: 13px; opacity: 0;
    transition: all .3s ease;
    pointer-events: none; z-index: 2000;
}
.toast.visible { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---- Skeleton ---- */
.skel {
    background: linear-gradient(90deg, #e5e7eb 25%, #f3f4f6 50%, #e5e7eb 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: 6px;
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* Hero skeleton (on dark bg) */
.skeleton-hero { text-align: center; padding: 10px 0; }
.skeleton-hero .skel {
    background: linear-gradient(90deg, rgba(255,255,255,.06) 25%, rgba(255,255,255,.12) 50%, rgba(255,255,255,.06) 75%);
    background-size: 200% 100%;
}
.skel-circle { width: 120px; height: 120px; border-radius: 50%; margin: 0 auto 16px; }
.skel-line { height: 14px; margin: 0 auto 8px; }
.skel-w60 { width: 60%; }
.skel-w50 { width: 50%; }
.skel-w40 { width: 40%; }

/* Category skeleton */
.skel-cats { padding: 16px 24px; display: flex; flex-direction: column; gap: 12px; }
.skel-cat { display: flex; align-items: center; gap: 12px; }
.skel-icon { width: 36px; height: 36px; border-radius: 8px; flex-shrink: 0; }
.skel-cat-lines { flex: 1; }
.skel-bar { height: 6px; border-radius: 3px; margin-top: 6px; }
.skel-num { width: 28px; height: 20px; border-radius: 4px; }

/* ---- Categories ---- */
.categories { padding: 12px 16px 0; }

.cat {
    border-radius: var(--radius);
    margin-bottom: 2px;
    transition: background .2s;
}

.cat-head {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 14px;
    cursor: pointer; border-radius: var(--radius);
    transition: background .15s;
    user-select: none;
}
.cat-head:hover { background: var(--g50); }

.cat-icon {
    width: 36px; height: 36px;
    border-radius: var(--radius-sm);
    display: flex; align-items: center; justify-content: center;
    font-size: 15px; flex-shrink: 0;
}
.cat-icon.air { background: #DBEAFE; color: #2563EB; }
.cat-icon.transport { background: #FEF3C7; color: #D97706; }
.cat-icon.green { background: #D1FAE5; color: #059669; }
.cat-icon.education { background: #EDE9FE; color: #7C3AED; }
.cat-icon.health { background: #FCE7F3; color: #DB2777; }
.cat-icon.lifestyle { background: #FFEDD5; color: #EA580C; }

.cat-info { flex: 1; min-width: 0; }

.cat-title {
    display: flex; align-items: baseline; gap: 6px;
    margin-bottom: 5px;
}
.cat-name { font-size: 13px; font-weight: 600; color: var(--g800); }
.cat-count {
    font-size: 11px; color: var(--g400); font-weight: 500;
}

.cat-bar { height: 5px; background: var(--g100); border-radius: 3px; overflow: hidden; }
.cat-bar-fill {
    height: 100%; border-radius: 3px;
    width: 0; transition: width .8s var(--ease);
}

.cat-score {
    font-size: 17px; font-weight: 700;
    min-width: 32px; text-align: right;
}

.cat-chev {
    color: var(--g400); font-size: 14px;
    transition: transform var(--t) var(--ease);
    flex-shrink: 0;
}
.cat.expanded .cat-chev { transform: rotate(180deg); }

/* Category expanded */
.cat-detail {
    max-height: 0; overflow: hidden;
    transition: max-height .4s var(--ease);
}
.cat.expanded .cat-detail { max-height: 600px; }

.cat-detail-inner { padding: 0 14px 12px 62px; }

.poi-list { list-style: none; }
.poi-item {
    display: flex; align-items: center; justify-content: space-between;
    padding: 5px 0; border-bottom: 1px solid var(--g100);
    font-size: 12px; cursor: pointer;
    transition: background .1s;
}
.poi-item:hover { background: var(--g50); margin: 0 -4px; padding: 5px 4px; border-radius: 4px; }
.poi-item:last-child { border-bottom: none; }
.poi-name {
    color: var(--g700); overflow: hidden;
    text-overflow: ellipsis; white-space: nowrap;
    flex: 1; margin-right: 8px;
}
.poi-dist { color: var(--g400); font-size: 11px; white-space: nowrap; }
.no-pois { font-size: 12px; color: var(--g400); padding: 4px 0; }

.cat-weight {
    font-size: 10px; color: var(--g400);
    margin-top: 6px; padding-top: 6px;
    border-top: 1px solid var(--g100);
}

/* Category active highlight */
.cat.active { background: var(--g50); }

/* ---- Error ---- */
.panel-error {
    text-align: center; padding: 60px 24px; color: var(--g500);
}
.panel-error i { font-size: 36px; margin-bottom: 10px; color: var(--orange); display: block; }

/* ---- Footer ---- */
.panel-footer {
    padding: 16px 24px 24px;
    text-align: center;
    font-size: 11px; color: var(--g400);
    border-top: 1px solid var(--g100);
    margin-top: 12px;
}
.panel-footer a { color: var(--g500); text-decoration: none; }
.panel-footer a:hover { color: var(--blue); }

/* ---- Hint ---- */
.hint {
    position: absolute; bottom: 20px; left: 50%;
    transform: translateX(-50%);
    z-index: 998;
    background: #fff;
    padding: 9px 18px; border-radius: 48px;
    box-shadow: var(--shadow-lg);
    font-size: 13px; color: var(--g600);
    display: flex; align-items: center; gap: 7px;
    transition: opacity var(--t), transform var(--t);
    pointer-events: none;
}
.hint.hidden { opacity: 0; transform: translateX(-50%) translateY(12px); }

/* ---- Marker ---- */
.custom-marker { width: 32px; height: 32px; position: relative; }
.custom-marker-inner {
    width: 32px; height: 32px;
    background: var(--blue);
    border: 3px solid #fff;
    border-radius: 50%;
    box-shadow: 0 2px 8px rgba(10,92,219,.35);
    animation: markerPop .3s cubic-bezier(.34,1.56,.64,1);
}
@keyframes markerPop { from { transform: scale(0); } to { transform: scale(1); } }

.custom-marker-pulse {
    position: absolute; top: 50%; left: 50%;
    width: 48px; height: 48px;
    margin: -24px 0 0 -24px;
    border-radius: 50%;
    background: rgba(10,92,219,.15);
    animation: pulse 2s ease-out infinite;
}
@keyframes pulse { 0% { transform: scale(.5); opacity: 1; } 100% { transform: scale(1.8); opacity: 0; } }

/* POI dots — dimmed state */
.poi-marker-dim { opacity: .2 !important; transition: opacity .3s; }

/* ---- About modal ---- */
.modal-overlay {
    position: fixed; inset: 0;
    z-index: 2000;
    background: rgba(0,0,0,.5);
    backdrop-filter: blur(4px);
    display: flex; align-items: center; justify-content: center;
    padding: 24px;
    opacity: 0; pointer-events: none;
    transition: opacity .25s;
}
.modal-overlay.open { opacity: 1; pointer-events: auto; }

.modal {
    background: #fff; border-radius: 16px;
    max-width: 520px; width: 100%;
    max-height: 85vh; overflow-y: auto;
    padding: 28px; position: relative;
    box-shadow: 0 24px 48px rgba(0,0,0,.2);
    transform: translateY(16px);
    transition: transform .25s var(--ease);
}
.modal-overlay.open .modal { transform: translateY(0); }

.modal-close {
    position: absolute; top: 14px; right: 14px;
    background: var(--g100); border: none; border-radius: 50%;
    width: 32px; height: 32px;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; color: var(--g600);
}
.modal-close:hover { background: var(--g200); }

.modal h2 {
    font-size: 18px; font-weight: 700; margin-bottom: 10px; color: var(--g900);
    padding-right: 40px;
}
.modal p { font-size: 13px; color: var(--g600); line-height: 1.6; margin-bottom: 16px; }

.method-grid { display: flex; flex-direction: column; gap: 12px; margin-bottom: 16px; }
.method-item { display: flex; gap: 12px; align-items: flex-start; }
.method-icon {
    width: 32px; height: 32px; min-width: 32px;
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    font-size: 14px;
}
.method-icon.air { background: #DBEAFE; color: #2563EB; }
.method-icon.transport { background: #FEF3C7; color: #D97706; }
.method-icon.green { background: #D1FAE5; color: #059669; }
.method-icon.education { background: #EDE9FE; color: #7C3AED; }
.method-icon.health { background: #FCE7F3; color: #DB2777; }
.method-icon.lifestyle { background: #FFEDD5; color: #EA580C; }

.method-item div:last-child { font-size: 12px; color: var(--g600); line-height: 1.5; }
.method-item strong { color: var(--g800); font-size: 13px; }
.method-note { font-size: 12px; color: var(--g400); margin-bottom: 0; }

/* ---- Responsive (mobile) ---- */
@media (max-width: 768px) {
    :root { --header-h: 48px; }
    .brand-name { font-size: 13px; }
    .brand-tagline { font-size: 9px; }

    .panel {
        top: auto; bottom: 0; right: 0;
        width: 100%;
        height: 55vh;
        max-height: calc(100dvh - var(--header-h) - 60px);
        border-radius: 18px 18px 0 0;
        transform: translateY(100%);
        box-shadow: 0 -4px 24px rgba(0,0,0,.12);
        transition: transform var(--t) var(--ease), height var(--t) var(--ease);
    }
    .panel.open { transform: translateY(0); }
    .panel.expanded { height: 90vh; }
    .panel.minimized { height: 200px; }

    .panel-drag {
        display: flex; justify-content: center;
        padding: 10px 0 2px; cursor: grab;
        touch-action: none;
    }
    .panel-drag-pill {
        width: 36px; height: 4px;
        background: var(--g300); border-radius: 2px;
    }

    .panel-close { top: 6px; right: 8px; width: 30px; height: 30px; }

    .search-container {
        width: calc(100% - 20px); max-width: none;
        top: calc(var(--header-h) + 6px);
    }
    .search-bar { height: 42px; padding: 0 14px; }

    .panel-hero { padding: 20px 20px 18px; }
    .score-ring { width: 110px; height: 110px; margin-bottom: 10px; }
    .score-num { font-size: 38px; }

    .categories { padding: 8px 12px 0; }

    .hint { bottom: 14px; font-size: 12px; padding: 8px 14px; }

    .modal { padding: 22px; margin: 12px; }
}

@media (max-width: 380px) {
    .brand-tagline { display: none; }
}
