:root {
    --primary: #5b6dff;
    --primary-dark: #4f46e5;
    --red: #e11d48;
    --orange: #f59e0b;
    --green: #10b981;
    --gray: #94a3b8;
    --text: #1b2242;
    --muted: #6f7899;
    --border: #e5e7f0;
    --surface: #ffffff;
    --toolbar-h: 52px;
    --chips-h: 44px;
    --sidebar-w: 300px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html,
body {
    height: 100%;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    color: var(--text);
    background: #0f162e;
    overflow: hidden;
}

button,
input,
select {
    font: inherit;
}

.app {
    display: grid;
    grid-template-rows: var(--toolbar-h) var(--chips-h) 1fr;
    grid-template-columns: 1fr;
    height: 100%;
    padding-top: var(--safe-top);
}

.toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 10px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    z-index: 30;
    overflow: hidden;
}

.toolbar-back,
.toolbar-btn,
.sidebar-tool,
.sheet-close {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--muted);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    text-decoration: none;
    flex-shrink: 0;
}

.toolbar-title {
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: 800;
    font-size: 0.9rem;
    white-space: nowrap;
}

.toolbar-title i {
    color: var(--primary);
}

.toolbar-stats {
    display: none;
    gap: 6px;
    margin-left: auto;
    flex-wrap: wrap;
}

.stat-pill {
    font-size: 0.66rem;
    font-weight: 600;
    padding: 4px 8px;
    border-radius: 999px;
    background: rgba(91, 109, 255, 0.08);
    border: 1px solid rgba(91, 109, 255, 0.18);
    color: #3d4580;
}

.stat-pill strong {
    color: var(--primary);
}

.chips {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 8px;
    background: rgba(255, 255, 255, 0.96);
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
    scrollbar-width: none;
    z-index: 25;
}

.chips::-webkit-scrollbar {
    display: none;
}

.chip {
    border: 1px solid var(--border);
    background: #f8f9fe;
    color: var(--muted);
    border-radius: 999px;
    padding: 6px 12px;
    font-size: 0.72rem;
    font-weight: 600;
    white-space: nowrap;
    cursor: pointer;
    flex-shrink: 0;
}

.chip.active {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.chip-search {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-width: 120px;
}

.chip-search input {
    border: none;
    background: transparent;
    outline: none;
    width: 100%;
    min-width: 60px;
    font-size: 0.72rem;
}

.map-wrap {
    position: relative;
    min-height: 0;
    grid-row: 3;
    grid-column: 1;
}

#map {
    width: 100%;
    height: 100%;
    touch-action: auto;
}

.map-legend {
    position: absolute;
    left: 10px;
    bottom: calc(10px + var(--safe-bottom));
    z-index: 10;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 6px 10px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.95);
    font-size: 0.65rem;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
}

.map-legend .dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 3px;
}

.dot.high { background: var(--red); }
.dot.mid { background: var(--orange); }
.dot.low { background: var(--green); }
.dot.none { background: var(--gray); }

.sidebar {
    display: none;
}

.sheet {
    display: flex;
    flex-direction: column;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 40;
    background: var(--surface);
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -8px 30px rgba(15, 22, 46, 0.2);
    max-height: 78vh;
    transform: translateY(100%);
    transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: none;
}

.sheet.is-open {
    transform: translateY(0);
    pointer-events: auto;
}

.sheet-handle {
    width: 36px;
    height: 4px;
    border-radius: 2px;
    background: #d1d5e0;
    margin: 8px auto 4px;
}

.sheet-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px 8px;
    border-bottom: 1px solid var(--border);
}

.sheet-header h2 {
    font-size: 0.95rem;
}

.sheet-detail {
    flex: 1;
    padding: 12px;
    overflow-y: auto;
    min-height: 0;
}

.sidebar-title {
    padding: 12px 14px 8px;
    font-size: 0.95rem;
    font-weight: 800;
    border-bottom: 1px solid var(--border);
}

.detail-panel {
    flex: 1;
    padding: 12px;
    overflow-y: auto;
    min-height: 0;
}

.detail-empty {
    color: var(--gray);
    font-size: 0.85rem;
    text-align: center;
    padding: 16px 8px;
}

.detail-price {
    font-size: 1.25rem;
    font-weight: 800;
    color: var(--red);
    margin-bottom: 8px;
}

.detail-title {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
}

.detail-title a {
    color: var(--primary);
    font-weight: 700;
    text-decoration: none;
}

.detail-badge {
    font-size: 0.68rem;
    padding: 2px 8px;
    border-radius: 999px;
    background: #fef2f2;
    color: var(--red);
    font-weight: 600;
}

.detail-rows {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 12px;
}

.detail-row {
    display: grid;
    grid-template-columns: 88px 1fr;
    gap: 8px;
    font-size: 0.8rem;
}

.detail-row dt {
    color: var(--muted);
    font-weight: 600;
}

.detail-row dd {
    word-break: break-word;
}

.detail-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.detail-actions a {
    text-align: center;
    padding: 11px 12px;
    border-radius: 8px;
    font-weight: 600;
    text-decoration: none;
    font-size: 0.85rem;
}

.detail-actions .btn-primary {
    background: var(--primary);
    color: #fff;
}

.detail-actions .btn-secondary {
    background: #f1f5f9;
    color: #475569;
}

.sidebar-tool.is-on,
.toolbar-btn.is-on {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

/* Yandex pin layout */
.map-pin {
    position: absolute;
    left: 0;
    top: 0;
    white-space: nowrap;
    font-family: 'Inter', sans-serif;
    font-size: 11px;
    font-weight: 700;
    padding: 5px 9px;
    border-radius: 999px;
    color: #fff;
    border: 2px solid #fff;
    box-shadow: 0 2px 10px rgba(15, 23, 42, 0.28);
    line-height: 1.1;
}

.map-pin_tier-high { background: var(--red); }
.map-pin_tier-mid { background: var(--orange); color: #1b2242; }
.map-pin_tier-low { background: var(--green); }
.map-pin_tier-none { background: var(--gray); }
.map-pin_is-selected {
    transform: scale(1.08);
    border-color: var(--primary);
    box-shadow: 0 4px 14px rgba(91, 109, 255, 0.45);
    z-index: 2000;
}

@media (min-width: 700px) {
    .toolbar-stats {
        display: flex;
    }
}

@media (min-width: 900px) {
    .app {
        grid-template-columns: var(--sidebar-w) 1fr;
        grid-template-rows: var(--toolbar-h) var(--chips-h) 1fr;
    }

    .toolbar,
    .chips {
        grid-column: 1 / -1;
    }

    .sidebar {
        display: flex;
        flex-direction: column;
        grid-row: 3;
        grid-column: 1;
        background: var(--surface);
        border-right: 1px solid var(--border);
        min-height: 0;
        z-index: 20;
    }

    .sheet {
        display: none;
    }

    .map-wrap {
        grid-column: 2;
    }

    .detail-actions {
        flex-direction: row;
    }

    .detail-actions a {
        flex: 1;
    }
}

@media (max-width: 899px) {
    .map-pin {
        font-size: 12px;
        padding: 6px 10px;
    }
}
