/* ==========================================================================
   1. ГЛОБАЛЬНЫЕ СТИЛИ И ИНТЕГРАЦИЯ С TELEGRAM MINI APP
   ========================================================================== */
html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--tg-theme-bg-color, #ffffff);
    color: var(--tg-theme-text-color, #222222);
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent; /* Убирает синюю рамку при клике на iOS */
}

#map {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
}

/* Скрываем стандартные технические кнопки движка MapLibre */
.maplibregl-ctrl {
    display: none !important;
}

/* ==========================================================================
   2. СТАРТОВЫЙ ИНДИКАТОР ЗАГРУЗКИ ПРИЛОЖЕНИЯ (СПИННЕР)
   ========================================================================== */
#map-loader {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--tg-theme-bg-color, #ffffff);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.25s ease, visibility 0.25s ease;
}

#map-loader.hidden {
    opacity: 0;
    visibility: hidden;
}

.spinner {
    width: 42px;
    height: 42px;
    border: 3.5px solid var(--tg-theme-secondary-bg-color, rgba(0, 0, 0, 0.08));
    border-top-color: var(--tg-theme-button-color, #2481cc);
    border-radius: 50%;
    animation: spin 0.75s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ==========================================================================
   3. КАСТОМНЫЙ ПУЛЬТ УПРАВЛЕНИЯ КАРТОЙ (ZOOM / GPS)
   ========================================================================== */
#map-controls {
    position: absolute;
    bottom: 85px;
    right: 16px;
    z-index: 500;
    display: flex;
    flex-direction: column;
    gap: 14px;
    transition: opacity 0.25s cubic-bezier(0.4, 0, 0.2, 1), visibility 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

#map-controls.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.zoom-group {
    display: flex;
    flex-direction: column;
    background: var(--tg-theme-bg-color, #ffffff);
    border-radius: 12px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
    overflow: hidden;
}

.control-btn {
    width: 44px;
    height: 44px;
    background: var(--tg-theme-bg-color, #ffffff);
    color: var(--tg-theme-text-color, #2d2d2d);
    border: none;
    outline: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.zoom-group .control-btn {
    border-radius: 0 !important;
}

#zoom-in-btn {
    border-bottom: 0.5px solid var(--tg-theme-secondary-bg-color, rgba(0, 0, 0, 0.05));
}

.control-btn:active {
    background-color: var(--tg-theme-secondary-bg-color, #f1f5f9);
}

.geolocate-round-btn {
    border-radius: 50% !important;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
}

.geolocate-round-btn svg {
    color: var(--tg-theme-text-color, #333333);
}

.geolocate-round-btn:active svg {
    color: var(--tg-theme-button-color, #2481cc);
}

/* ==========================================================================
   4. СТИЛИ ОДИНОЧНЫХ ИНТЕРАКТИВНЫХ ПИНОВ МЕСТ
   ========================================================================== */
.yandex-marker-wrapper {
    cursor: pointer;
    width: 42px;
    height: 42px;
    display: flex;
    align-items: center;
    justify-content: center;
    will-change: transform;
}

.modern-pin.has-photo {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: 2px solid #ffffff;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.16);
    background-size: cover;
    background-position: center;
}

.modern-pin.no-photo {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--tg-theme-button-color, #2481cc);
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 3px 10px rgba(36, 129, 204, 0.35);
    border: 2px solid #ffffff;
}

/* ==========================================================================
   5. СТИЛИ ГРУППОВЫХ МАРКЕРОВ (МАТЕМАТИЧЕСКИЕ КЛАСТЕРЫ)
   ========================================================================== */
.custom-cluster-marker {
    width: 38px;
    height: 38px;
    background: var(--tg-theme-secondary-bg-color, #f1f5f9);
    color: var(--tg-theme-button-color, #2481cc);
    border: 2px solid var(--tg-theme-bg-color, #ffffff);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 14px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.1);
    cursor: pointer;
    user-select: none;
    transition: background-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.custom-cluster-marker:active {
    filter: brightness(0.92);
}

/* ==========================================================================
   6. НАТИВНАЯ ВСПЛЫВАЮЩАЯ КАРТОЧКА (BOTTOM SHEET ШТОРКА)
   ========================================================================== */
#bottom-sheet {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 75vh;
    background: var(--tg-theme-bg-color, #ffffff);
    border-top-left-radius: 12px;
    border-top-right-radius: 12px;
    z-index: 1000;
    box-shadow: 0 -6px 20px rgba(0, 0, 0, 0.06);
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.25, 1, 0.5, 1);
    display: flex;
    flex-direction: column;
}

#bottom-sheet.active {
    transform: translateY(0);
}

#bottom-sheet.fullscreen {
    height: 100vh;
    border-radius: 0;
}

#bottom-sheet.dragging {
    transition: none;
}

.sheet-header {
    width: 100%;
    padding: 8px 0 4px 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: grab;
    user-select: none;
    background: var(--tg-theme-bg-color, #ffffff);
    border-top-left-radius: 12px;
    border-top-right-radius: 12px;
}

.sheet-drag-handle {
    width: 36px;
    height: 4px;
    background: var(--tg-theme-hint-color, rgba(0, 0, 0, 0.12));
    border-radius: 2px;
    margin-bottom: 4px;
}

.sheet-controls {
    width: 100%;
    padding: 0 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 36px;
}

.sheet-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 0;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    color: var(--tg-theme-text-color, #222222);
    opacity: 0.55;
    transition: opacity 0.15s ease, background-color 0.15s ease;
}

.sheet-btn:hover, .sheet-btn:active {
    opacity: 1;
    background-color: var(--tg-theme-secondary-bg-color, rgba(0, 0, 0, 0.04));
}

.sheet-content {
    flex: 1;
    width: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--tg-theme-bg-color, #ffffff);
}

#widget-container {
    flex: 1;
    width: 100%;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 6px 16px 20px 16px;
}

/* ==========================================================================
   7. СТИЛИ ДЛЯ ВЫСОКОПРОИЗВОДИТЕЛЬНОГО ПУБЛИКАЦИОННОГО ПОСТА
   ========================================================================== */
.native-post-container {
    display: flex;
    flex-direction: column;
    gap: 14px;
    width: 100%;
    padding: 4px 0;
}

.post-header {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
}

.post-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-color: var(--tg-theme-button-color, #2481cc);
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 16px;
    position: relative;
    overflow: hidden;
}

.post-avatar-img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    display: block;
}

.post-meta {
    display: flex;
    flex-direction: column;
}

.post-channel-name {
    font-weight: 600;
    font-size: 15px;
    color: var(--tg-theme-text-color, #222222);
}

.post-sub-text {
    font-size: 12px;
    color: var(--tg-theme-hint-color, #8e8e93);
}

.post-text-content {
    font-size: 15px;
    line-height: 1.45;
    color: var(--tg-theme-text-color, #222222);
    word-wrap: break-word;
    white-space: pre-line;
}

.post-text-content a {
    color: var(--tg-theme-link-color, #2481cc) !important;
    text-decoration: underline !important;
}

.post-media-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
}

.post-media-content {
    width: 100%;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.post-media-content img {
    width: 100%;
    display: block;
    max-height: 350px;
    object-fit: cover;
}

/* ==========================================================================
   8. FULLSCREEN IMAGE VIEWER MODAL OVERLAY (LIGHTBOX)
   ========================================================================== */
.image-viewer-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.88);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 3000;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: zoom-out;
    animation: fadeInOverlay 0.2s ease-out;
}

.viewer-img {
    max-width: 95vw;
    max-height: 85vh;
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.5);
    user-select: none;
    -webkit-user-select: none;
    animation: scaleInImg 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes fadeInOverlay {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes scaleInImg {
    from { transform: scale(0.9); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

/* ==========================================================================
   NATIVE TELEGRAM ALBUM GRID (COLLAGE)
   ========================================================================== */
.tg-album-grid {
    display: grid;
    gap: 4px;
    width: 100%;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.tg-grid-item {
    width: 100%;
    height: 100%;
    overflow: hidden;
}

.tg-grid-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* Сетка для 1 фото */
.tg-grid-1 {
    grid-template-columns: 1fr;
}
.tg-grid-1 .tg-grid-item { max-height: 360px; }

/* Сетка для 2 фото */
.tg-grid-2 {
    grid-template-columns: 1fr 1fr;
    height: 220px;
}

/* Сетка для 3 фото */
.tg-grid-3 {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 140px 140px;
    height: 284px;
}
.tg-grid-3 .tg-grid-item:first-child {
    grid-row: span 2;
}

/* Сетка для 4 и более фото */
.tg-grid-4 {
    grid-template-columns: 2fr 1fr;
    grid-template-rows: 100px 100px 100px;
    height: 308px;
}
.tg-grid-4 .tg-grid-item:first-child {
    grid-row: span 3;
}

/* ==========================================================================
   INTERACTIVE HORIZONTAL CAROUSEL & PINCH-TO-ZOOM OVERLAY
   ========================================================================== */
.slider-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: #000000;
    z-index: 3500;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.slider-track {
    display: flex;
    width: 100vw;
    height: 100vh;
    transition: transform 0.25s cubic-bezier(0.25, 1, 0.5, 1);
    will-change: transform;
}

.slider-slide {
    flex-shrink: 0;
    width: 100vw;
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.zoom-img-container {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.slider-img {
    max-width: 100vw;
    max-height: 85vh;
    object-fit: contain;
    will-change: transform;
    user-select: none;
    -webkit-user-select: none;
}

/* Кнопка закрытия слайдера (Крестик наверху) */
.slider-close-btn {
    position: absolute;
    top: calc(env(safe-area-inset-top) + 16px);
    right: 16px;
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: #ffffff;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 4000;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

/* Точки индикации страниц (Dots) */
.slider-dots {
    position: absolute;
    bottom: calc(env(safe-area-inset-bottom) + 24px);
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 8px;
    z-index: 3900;
}

.slider-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.35);
    transition: background-color 0.2s, transform 0.2s;
}

.slider-dot.active {
    background: #ffffff;
    transform: scale(1.2);
}

#privacy-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.8); z-index: 5000;
    display: flex; align-items: center; justify-content: center;
}
#privacy-overlay.hidden { display: none; }
.privacy-modal {
    background: var(--tg-theme-bg-color); color: var(--tg-theme-text-color);
    padding: 20px; border-radius: 12px; width: 85%; text-align: center;
}
#accept-privacy-btn {
    background: var(--tg-theme-button-color); color: var(--tg-theme-button-text-color);
    border: none; padding: 12px 20px; border-radius: 8px; margin-top: 15px; width: 100%;
}

.channel-select-btn {
    width: 100%;
    padding: 14px 16px;
    background: var(--tg-theme-secondary-bg-color, #f1f5f9);
    color: var(--tg-theme-text-color, #222222);
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    text-align: left;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: background-color 0.15s ease;
}
.channel-select-btn:active {
    background-color: var(--tg-theme-hint-color, rgba(0, 0, 0, 0.08));
}
.channel-select-btn .channel-icon {
    font-size: 20px;
}

/* СТИЛИ ЗАГРУЗЧИКОВ И ОШИБОК ИЗОБРАЖЕНИЙ */
.media-loader {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 24px;
    height: 24px;
    border: 2px solid var(--tg-theme-button-color, #2481cc);
    border-top-color: transparent;
    border-radius: 50%;
    animation: media-loader-spin 0.8s linear infinite;
    z-index: 5;
}

@keyframes media-loader-spin {
    0% { transform: translate(-50%, -50%) rotate(0deg); }
    100% { transform: translate(-50%, -50%) rotate(360deg); }
}

.tg-grid-item {
    position: relative;
    background-color: var(--tg-theme-secondary-bg-color, #f1f5f9);
}

.tg-grid-item.error {
    background-color: var(--tg-theme-secondary-bg-color, #f1f5f9);
    border: 2px dashed var(--tg-theme-hint-color, #cbd5e1);
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: default;
}

.tg-grid-item.error::after {
    content: "📷";
    font-size: 24px;
    opacity: 0.5;
}

.zoom-img-container.error {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    gap: 8px;
}

.zoom-img-container.error::after {
    content: "📷 Фото не загрузилось";
    color: #ffffff;
    font-size: 16px;
    opacity: 0.7;
}