/* ==========================================
   BASE — :root, reset, typography, layout shell
   ========================================== */

:root {
    color-scheme: light;
    --color-brand: #059669;
    --color-brand-deep: #047857;
    --color-brand-soft: #00b050;
    --color-text: #111827;
    --color-text-muted: #6b7280;
    --color-text-subtle: #9ca3af;
    --color-border: #e5e7eb;
    --color-surface: #ffffff;
    --color-surface-muted: #f8fafc;
    --color-vk: #0077ff;
    --radius-card: 16px;
    --radius-panel: 20px;
    --app-max-width: 420px;
    --app-frame-break: 768px; /* потолок рамки только на планшете/десктопе */
    --font-sans: "Segoe UI", system-ui, -apple-system, sans-serif;
}

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

/* Надёжное скрытие экранов/модалок (не зависим только от Tailwind .hidden) */
.hidden,
[hidden] {
    display: none !important;
}

html {
    /* Не hidden/clip на html — document.scrollingElement, sticky ломается */
    overflow-x: visible !important;
    overflow-y: auto !important;
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

html.lock-scroll {
    overflow: hidden !important;
}

body {
    margin: 0;
    padding: 0;
    font-family: var(--font-sans);
    color: var(--color-text);
    -webkit-font-smoothing: antialiased;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    height: auto !important;
    max-height: none !important;
    /* visible на обеих осей — auto на body ломает sticky; скролл на html */
    overflow: visible !important;
}

body.lock-scroll {
    overflow: hidden !important;
    touch-action: none;
}

body {
    background-color: #F5F7F6 !important;
    color: #1e293b;
    margin: 0;
    padding: 0;
}

/* Принудительно задаем фоны для карточек и контейнеров, чтобы Safari не делал их черными */
.product-card,
.card,
.search-control-panel,
.categories-nav {
    background-color: #ffffff !important;
}

/* Safari Dark Mode: внутренние текстовые блоки не должны получать чёрный фон */
.product-card *,
.card * {
    background-color: transparent !important;
}


.product-card h2,
.product-card h3,
.product-card p,
.product-card span,
.product-card .title,
.product-title {
    color: #0f172a !important;
}

/* Глобальный фикс для всего приложения */


.global-phone-wrapper,
.app-container,
.app-wrapper,
.mobile-wrapper {
    position: relative !important;
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 auto !important;
    min-height: 100vh !important;
    height: auto !important;
    max-height: none !important;
    box-sizing: border-box !important;
    display: flex !important;
    flex-direction: column !important;
    background-color: #708276 !important; /* Наш фирменный фоновый темно-зеленый оттенок */
    padding: var(--content-gutter, 4px) !important;
    border-radius: 20px !important;
    z-index: 1 !important;
    box-shadow: 0 0 32px rgba(0, 0, 0, 0.1) !important;
    overflow: visible !important;
    isolation: isolate;
}

/* Главный блок витрины с объявлениями — белый поверх зеленого фона */
.main-feed-card,
.feed-card {
    background-color: #ffffff !important;
    border-radius: 16px !important;
}

/* Фиксированный фоновый слой, который никогда не прыгает */
.global-phone-wrapper::before {
    content: '' !important;
    position: fixed !important; /* Именно fixed, чтобы оставаться на месте при любом скролле */
    top: 0 !important;
    left: 50% !important;
    transform: translateX(-50%) !important; /* Центрируем строго по нашему мобильному каркасу */
    width: 100% !important;
    max-width: 100% !important;
    height: 100vh !important;
    background-image: url('../img/banner.webp') !important;
    background-size: cover !important;
    background-position: center !important;
    background-repeat: no-repeat !important;
    z-index: -1 !important; /* Уходит на самый задний план */
    pointer-events: none !important;
}

/* Накладываем мягкое затемнение вторым фиксированным слоем */
.global-phone-wrapper::after {
    content: '' !important;
    position: fixed !important;
    top: 0 !important;
    left: 50% !important;
    transform: translateX(-50%) !important;
    width: 100% !important;
    max-width: 100% !important;
    height: 100vh !important;
    background: rgba(255, 255, 255, 0.45) !important;
    z-index: 0 !important;
    pointer-events: none !important;
}

/* Убираем старый псевдоэлемент с главного экрана, так как он теперь на wrapper */
#screen-main::before, .app-banner-bg {
    display: none !important;
}

#screen-main {
    height: auto !important;
    max-height: none !important;
    overflow: visible !important;
}

/* Главный контейнер-телефон */
.app-mobile-container {
    position: relative !important;
    z-index: 1 !important;
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
    min-height: calc(100vh - 60px) !important;
    overflow: visible !important;
    box-sizing: border-box !important;
    background: transparent !important;
}

main,
footer {
    position: relative !important;
    z-index: 1 !important;
    overflow: visible !important;
}

/* Фон, который подстраивается под размеры контейнера-телефона */
.app-banner-bg {
    position: absolute !important;
    inset: 0 !important;
    background-size: cover !important;
    background-position: center !important;
    z-index: 1 !important;
}

.app-banner-bg::before {
    content: '' !important;
    position: absolute !important;
    inset: 0 !important;
    background: rgba(255, 255, 255, 0.45) !important;
}

/* Слой для контента с внутренними отступами безопасной зоны телефона */
.app-content-layer {
    position: relative !important;
    z-index: 2 !important;
    padding: 16px !important;
    width: 100% !important;
    box-sizing: border-box !important;
}

/* Отключаем автоматическую инверсию для элементов при Dark Mode */
@media (prefers-color-scheme: dark) {
    body, html {
        background-color: #F5F7F6 !important;
        color: #1e293b !important;
    }

    .product-card *,
    .card * {
        background-color: transparent !important;
    }

    .product-card,
    .card {
        background-color: #ffffff !important;
    }

    .product-card h2,
    .product-card h3,
    .product-card p,
    .product-card span,
    .product-title {
        color: #0f172a !important;
    }
}

/* Вариант A: на телефоне рамка = всю ширину экрана; 420px только на широких экранах */
@media (min-width: 768px) {
    .global-phone-wrapper,
    .app-container,
    .app-wrapper,
    .mobile-wrapper {
        max-width: var(--app-max-width, 420px) !important;
    }

    .global-phone-wrapper::before,
    .global-phone-wrapper::after {
        max-width: var(--app-max-width, 420px) !important;
    }
}
