/* ============================================
   HEADER - Исправленная версия для iPhone
   ============================================ */

.header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    background: rgba(74, 10, 10, 0.9);
    backdrop-filter: blur(30px) saturate(180%);
    -webkit-backdrop-filter: blur(30px) saturate(180%);
    border-bottom: 1px solid var(--border-light);
    width: 100%;
    box-sizing: border-box;
    
    /* Отступ сверху для иконки логотипа + safe-area */
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
    padding-top: max(18px, calc(env(safe-area-inset-top) + 18px));
    padding-bottom: 0;
    
    /* Максимально компактная высота на мобильных */
    min-height: 40px;
    height: auto;
    
    /* Исправление для Safari iOS */
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
    
    /* Предотвращаем выход за пределы */
    overflow: visible;
}

/* Улучшенный блюр когда показывается имя мастера */
.header.show-master-name {
    backdrop-filter: blur(40px) saturate(200%);
    -webkit-backdrop-filter: blur(40px) saturate(200%);
    background: rgba(74, 10, 10, 0.95);
    transition: backdrop-filter 0.3s ease, background 0.3s ease;
}

@supports not (backdrop-filter: blur(30px)) {
    .header {
        background: rgba(74, 10, 10, 0.98);
    }
}

/* Контейнер контента header */
.header-content {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: space-between;
    width: 100%;
    margin: 0;
    position: relative;
    gap: 8px;
    min-height: 40px;
    height: 100%;
    box-sizing: border-box;
    /* Одинаковые отступы сверху и снизу */
    padding: 8px 0;
}

/* Логотип вверху, фильтры внизу */
.logo {
    font-family: "Cormorant Garamond", serif;
    font-size: 1.4rem;
    color: #E6C88C;
    font-weight: 400;
    line-height: 1;
    cursor: pointer;
    transition: opacity 0.2s ease;
    -webkit-tap-highlight-color: transparent;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    position: relative;
    font-optical-sizing: auto;
    overflow: visible;
    flex-shrink: 0;
    margin: 0 auto;
    padding: 0;
    opacity: 1;
    text-align: center;
    /* Логотип вверху с отступом для иконки */
    align-self: center;
    margin-top: 0;
    margin-bottom: 0;
}

.logo:hover {
    opacity: 0.8;
}

.logo > * {
    position: relative;
    z-index: 1;
}

.map-container {
    position: relative;
    display: inline-block;
    overflow: visible;
}

.a-with-icon {
    position: relative;
    display: inline-block;
    vertical-align: baseline;
}

/* Иконка логотипа - в зоне видимости */
.map-container .a-with-icon::before {
    content: '';
    position: absolute;
    bottom: calc(100% + 2px);
    left: 50%;
    transform: translateX(-50%);
    width: 16px;
    height: 16px;
    min-width: 16px;
    min-height: 16px;
    background-image: url("/static/images/pre-logo.svg");
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    pointer-events: none;
    z-index: 1000;
    display: block;
    visibility: visible;
    opacity: 1;
}

/* Кнопки фильтров и избранного - привязаны к низу */
.header-buttons {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    width: 100%;
    overflow: hidden;
    margin: 0;
    padding: 0;
    margin-top: 0;
    margin-bottom: 0;
    /* Привязка к низу */
    align-self: flex-end;
}

.header-buttons.hidden {
    display: none;
}

.header-buttons-left {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    min-width: 0;
}

.header-buttons-right {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    min-width: 0;
    justify-content: flex-end;
}

/* Кнопка фильтра */
.filter-dropdown {
    position: relative;
    flex: 1;
    min-width: 0;
    max-width: 180px;
}

.filter-btn {
    background: rgba(230, 200, 140, 0.12);
    border: 1px solid rgba(230, 200, 140, 0.25);
    border-radius: 12px;
    padding: 5px 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    flex-direction: column;
    gap: 1px;
    width: 100%;
    text-align: left;
    font-family: inherit;
    -webkit-tap-highlight-color: transparent;
    min-height: 36px;
    height: 36px;
    justify-content: center;
    align-items: flex-start;
    box-sizing: border-box;
    position: relative;
    margin: 0;
}

.filter-btn:hover {
    background: rgba(230, 200, 140, 0.18);
    border-color: rgba(230, 200, 140, 0.35);
}

.filter-btn:active {
    background: rgba(230, 200, 140, 0.25);
}

.filter-btn-top {
    font-size: 0.6rem;
    color: var(--text-secondary);
    line-height: 1.1;
    font-weight: 400;
    margin: 0;
    padding: 0;
}

.filter-btn-bottom {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 4px;
    margin: 0;
    padding: 0;
    width: 100%;
}

.filter-btn-bottom .filter-selected {
    font-size: 0.75rem;
    color: var(--text-primary);
    font-weight: 500;
    line-height: 1.1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin: 0;
    padding: 0;
    flex: 1;
    min-width: 0;
}

.filter-chevron {
    font-size: 16px;
    color: var(--text-primary);
    flex-shrink: 0;
    font-variation-settings: "FILL" 0, "wght" 300, "GRAD" 0, "opsz" 20;
    transition: transform 0.2s ease;
}

.filter-btn.active .filter-chevron {
    transform: rotate(180deg);
}

.filter-dropdown-menu {
    display: none;
}

.filter-option {
    padding: 10px 12px;
    font-size: 0.85rem;
    color: var(--text-primary);
    cursor: pointer;
    border-radius: 8px;
    transition: background 0.2s ease;
}

.filter-option:hover {
    background: rgba(255, 217, 102, 0.15);
}

.filter-option.active {
    background: rgba(230, 200, 140, 0.25);
    color: var(--accent);
    font-weight: 500;
}

/* Кнопка избранного */
.favorites-btn {
    width: 36px;
    height: 36px;
    min-width: 36px;
    min-height: 36px;
    border-radius: 50%;
    background: rgba(230, 200, 140, 0.12);
    border: 1px solid rgba(230, 200, 140, 0.25);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    padding: 0;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
    margin: 0;
    box-sizing: border-box;
}

.favorites-btn:hover {
    background: rgba(230, 200, 140, 0.18);
    border-color: rgba(230, 200, 140, 0.35);
}

.favorites-btn:active {
    background: rgba(230, 200, 140, 0.25);
    transform: scale(0.95);
}

.favorites-btn .favorites-icon {
    font-size: 18px;
    color: var(--text-primary);
    font-variation-settings: "FILL" 0, "wght" 400, "GRAD" 0, "opsz" 20;
}

.favorites-btn.active {
    background: rgba(230, 200, 140, 0.25);
    border-color: rgba(230, 200, 140, 0.45);
}

.favorites-btn.active .favorites-icon {
    font-variation-settings: "FILL" 1, "wght" 400, "GRAD" 0, "opsz" 20;
    color: var(--accent);
}

/* ============================================
   MASTER VIEW - Лого по центру, кнопки по сторонам
   ============================================ */

.header-content.in-master-view {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    position: relative;
    /* Одинаковые отступы сверху и снизу для кнопок */
    padding: 0;
    min-height: 52px;
    height: 100%;
}

/* Кнопки для master view */
.master-header-buttons {
    display: none;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    width: 100%;
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    z-index: 1;
    padding: 8px 0;
    box-sizing: border-box;
    height: 100%;
}

.header-content.in-master-view .master-header-buttons {
    display: flex;
}

.master-header-buttons-left {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 0 0 auto;
    z-index: 2;
    padding: 0;
    margin: 0;
}

.master-header-buttons-right {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 0 0 auto;
    z-index: 2;
    padding: 0;
    margin: 0;
}

.master-back-btn,
.master-favorite-btn {
    width: 36px;
    height: 36px;
    min-width: 36px;
    min-height: 36px;
    border-radius: 50%;
    background: rgba(230, 200, 140, 0.12);
    border: 1px solid rgba(230, 200, 140, 0.25);
    cursor: pointer;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-primary);
    transition: all 0.2s ease;
    -webkit-tap-highlight-color: transparent;
    flex-shrink: 0;
    box-sizing: border-box;
}

.master-back-btn:hover,
.master-favorite-btn:hover {
    background: rgba(230, 200, 140, 0.18);
    border-color: rgba(230, 200, 140, 0.35);
}

.master-back-btn:active,
.master-favorite-btn:active {
    background: rgba(230, 200, 140, 0.25);
    transform: scale(0.95);
}

.master-back-btn .material-symbols-outlined {
    font-size: 18px;
    font-variation-settings: "FILL" 0, "wght" 400, "GRAD" 0, "opsz" 20;
}

.master-favorite-btn .favorites-icon {
    width: 18px;
    height: 18px;
    object-fit: contain;
    filter: brightness(0) saturate(100%) invert(90%) sepia(15%) saturate(800%) hue-rotate(15deg) brightness(105%) contrast(95%);
}

/* Логотип в master view - абсолютно по центру */
.header-content.in-master-view .logo {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    margin: 0;
    z-index: 3;
    pointer-events: auto;
}

/* Имя мастера в header */
.master-header-name {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%) scale(0.8);
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-primary);
    opacity: 0;
    transition: opacity 0.4s cubic-bezier(0.4, 0, 0.2, 1),
                transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: none;
    white-space: nowrap;
    display: block;
    z-index: 4;
    text-align: center;
    max-width: calc(100% - 100px);
    overflow: hidden;
    text-overflow: ellipsis;
}

.master-header-name.show {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
}

.header-content.show-master-name .logo {
    opacity: 0 !important;
    pointer-events: none;
    visibility: hidden;
    transform: translate(-50%, -50%) scale(0.85);
    filter: blur(4px);
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

/* Скрываем иконку логотипа синхронно с логотипом */
.header-content.show-master-name .logo .map-container .a-with-icon::before {
    opacity: 0 !important;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

/* Skeleton для логотипа */
.logo.skeleton-logo {
    opacity: 0.5;
}

.logo.skeleton-logo::before {
    content: "BEAUTYMAP";
    position: absolute;
    top: 0;
    left: 0;
    font-family: "Cormorant Garamond", serif;
    font-size: 1.3rem;
    font-weight: 400;
    line-height: 1;
    white-space: nowrap;
    font-optical-sizing: auto;
    background: linear-gradient(90deg, 
        rgba(255, 255, 255, 0.05) 0%, 
        rgba(255, 255, 255, 0.2) 20%, 
        rgba(255, 255, 255, 1) 40%, 
        rgba(255, 255, 255, 1) 60%, 
        rgba(255, 255, 255, 0.2) 80%, 
        rgba(255, 255, 255, 0.05) 100%);
    background-size: 200% 100%;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    color: transparent;
    animation: skeleton-logo-shimmer 0.6s linear infinite;
    pointer-events: none;
    z-index: 2;
    display: block;
    width: 100%;
    height: 100%;
    overflow: visible;
}

@keyframes skeleton-logo-shimmer {
    0% {
        background-position: -200% 0;
    }
    100% {
        background-position: 200% 0;
    }
}

.logo.no-animation {
    animation: none;
}

/* ============================================
   Filter Popup Modal
   ============================================ */

.filter-popup-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 10000;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding: 0;
    opacity: 0;
    transition: opacity 0.3s ease;
    outline: none !important;
}

.filter-popup-overlay.show {
    opacity: 1;
}

.filter-popup {
    background: rgba(58, 5, 5, 0.98);
    backdrop-filter: blur(30px) saturate(180%);
    -webkit-backdrop-filter: blur(30px) saturate(180%);
    border: 1px solid rgba(230, 200, 140, 0.3);
    border-radius: 20px 20px 0 0;
    width: 100%;
    max-width: 100%;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.5);
    transform: translateY(100%);
    transition: transform 0.4s cubic-bezier(0.32, 0.72, 0, 1);
    overflow: hidden;
    outline: none !important;
    /* iOS стиль - снизу */
    padding-bottom: max(20px, env(safe-area-inset-bottom));
}

.filter-popup-overlay.show .filter-popup {
    transform: translateY(0);
}

/* Handle для iOS стиля попапа */
.filter-popup-handle {
    width: 40px;
    height: 4px;
    background: rgba(230, 200, 140, 0.3);
    border-radius: 2px;
    margin: 12px auto 8px;
    flex-shrink: 0;
    display: block;
}

.filter-popup-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px 16px;
    border-bottom: 1px solid rgba(230, 200, 140, 0.2);
    flex-shrink: 0;
}

.filter-popup-title {
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.filter-popup-close {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(230, 200, 140, 0.1);
    border: 1px solid rgba(230, 200, 140, 0.2);
    color: var(--accent);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
    outline: none !important;
}

.filter-popup-close:hover {
    background: rgba(230, 200, 140, 0.15);
    border-color: rgba(230, 200, 140, 0.3);
    transform: scale(1.1);
}

.filter-popup-close:active {
    transform: scale(0.95);
}

.filter-popup-close .material-symbols-outlined {
    font-size: 24px;
    font-variation-settings: "FILL" 0, "wght" 400, "GRAD" 0, "opsz" 24;
}

.filter-popup-content {
    padding: 16px;
    overflow-y: auto;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.filter-popup-content .filter-option {
    padding: 14px 16px;
    font-size: 0.95rem;
    color: var(--text-primary);
    cursor: pointer;
    border-radius: 12px;
    transition: all 0.2s ease;
    border: 1px solid transparent;
    text-align: left;
    width: 100%;
    background: transparent;
    outline: none !important;
    -webkit-tap-highlight-color: transparent !important;
}

.filter-popup-content .filter-option:hover {
    background: rgba(230, 200, 140, 0.12);
    border-color: rgba(230, 200, 140, 0.2);
    transform: translateX(4px);
}

.filter-popup-content .filter-option.active {
    background: rgba(230, 200, 140, 0.2);
    border-color: rgba(230, 200, 140, 0.4);
    color: var(--accent);
    font-weight: 500;
    transform: translateX(0);
}

.filter-popup-content .filter-option:active {
    transform: translateX(2px) scale(0.98);
}
