/* mobile.css - Mobile-first responsive styles for Mapthos */
/* Простая и юзабельная мобильная версия */

/* ==============================================
   MOBILE BASE STYLES (< 1025px)
   ============================================== */

@media (max-width: 1024px) {

  :root {
    --mobile-sidebar-collapsed-height: calc(96px + env(safe-area-inset-bottom, 0px));
    --mobile-sidebar-expanded-height: 60vh;
    --mobile-expand-btn-offset: 20px;
  }

  /* --- BODY & LAYOUT (СУПЕРАГРЕССИВНЫЙ сброс ТОЛЬКО для мобильных) --- */
  html {
    margin: 0 !important;
    padding: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    min-height: 100vh !important;
    max-height: 100vh !important;
    overflow: hidden !important;
    background: transparent !important;
    box-sizing: border-box !important;
  }

  body {
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
    position: fixed !important;
    width: 100vw !important;
    height: 100vh !important;
    min-height: 100vh !important;
    max-height: 100vh !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    display: block !important; /* Убираем flex из desktop */
    background: #161b22 !important; /* Цвет темы вместо градиента */
    box-sizing: border-box !important;
  }

  /* Убираем отступы у ВСЕХ контейнеров */
  * {
    box-sizing: border-box !important;
  }

  #root, #app, .main-container, main, .app-container, .container {
    margin: 0 !important;
    padding: 0 !important;
    width: 100% !important;
    height: 100% !important;
    display: block !important;
  }

  /* --- MAP (ВЕРХНИЕ 60%, ОТ САМОГО ВЕРХА) --- */
  #map {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: var(--mobile-sidebar-collapsed-height) !important;
    width: 100vw !important;
    height: calc(100vh - var(--mobile-sidebar-collapsed-height)) !important;
    z-index: 1 !important;
    margin: 0 !important;
    padding: 0 !important;
    background: #1a1d24 !important;
    box-sizing: border-box !important;
  }

  #sidebar.mobile-expanded ~ #map {
    bottom: var(--mobile-sidebar-expanded-height) !important;
    height: calc(100vh - var(--mobile-sidebar-expanded-height)) !important;
  }

  /* Leaflet без отступов */
  #map * {
    box-sizing: border-box !important;
  }

  #map .leaflet-container {
    margin: 0 !important;
    padding: 0 !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
  }

  .leaflet-pane,
  .leaflet-map-pane,
  .leaflet-tile-pane {
    margin: 0 !important;
    padding: 0 !important;
    top: 0 !important;
    left: 0 !important;
  }

  /* --- LOGO (левый верхний угол, на карте, маленький) --- */
  #sidebar-logo {
    position: fixed !important;
    top: 10px !important;
    left: 10px !important;
    z-index: 1002 !important;
    padding: 0 !important;
    margin: 0 !important;
    background: none !important;
    border: none !important;
    width: auto !important;
    height: auto !important;
  }

  #sidebar-logo .logo {
    max-width: 15px !important;
    max-height: 4.5px !important;
    height: auto !important;
    width: auto !important;
    display: block !important;
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.6)) !important;
  }

  /* Скрыть кнопку раскрытия из logo, она будет отдельно */
  #sidebar-logo #mobile-expand-btn {
    display: none !important;
  }

  /* --- SIDEBAR (НИЖНИЕ 40%, можно раскрыть до 60%) --- */
  #sidebar {
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    top: auto !important;
    width: 100% !important;
    height: var(--mobile-sidebar-collapsed-height) !important;
    max-height: var(--mobile-sidebar-collapsed-height) !important;
    min-width: 100% !important;
    border-right: none !important;
    border-top: 2px solid rgba(79, 195, 247, 0.4) !important;
    border-radius: 16px 16px 0 0 !important;
    z-index: 1000 !important;
    display: flex !important;
    flex-direction: column !important;
    transition: height 0.3s ease, max-height 0.3s ease !important;
    padding-top: 8px !important;
  }

  /* Расширенный сайдбар */
  #sidebar.mobile-collapsed {
    height: var(--mobile-sidebar-collapsed-height) !important;
    max-height: var(--mobile-sidebar-collapsed-height) !important;
  }

  #sidebar.mobile-expanded {
    height: var(--mobile-sidebar-expanded-height) !important;
    max-height: var(--mobile-sidebar-expanded-height) !important;
  }

  /* Кнопка раскрытия/сворачивания (в центре верхней границы сайдбара) */
  #mobile-expand-btn {
    position: fixed !important;
    bottom: calc(var(--mobile-sidebar-collapsed-height) - var(--mobile-expand-btn-offset)) !important;
    left: 50% !important;
    transform: translateX(-50%) !important;
    background: rgba(79, 195, 247, 0.2) !important;
    border: 1px solid rgba(79, 195, 247, 0.4) !important;
    border-radius: 50% !important;
    width: 40px !important;
    height: 40px !important;
    min-width: 40px !important;
    min-height: 40px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    cursor: pointer !important;
    color: #4fc3f7 !important;
    transition: all 0.3s ease !important;
    z-index: 1001 !important;
  }

  #mobile-expand-btn svg {
    width: 16px !important;
    height: 10px !important;
    display: block !important;
  }

  #sidebar.mobile-expanded ~ #mobile-expand-btn {
    bottom: calc(var(--mobile-sidebar-expanded-height) - var(--mobile-expand-btn-offset)) !important;
  }

  #mobile-expand-btn:active {
    transform: translateX(-50%) scale(0.95) !important;
    background: rgba(79, 195, 247, 0.3) !important;
  }

  /* Scrollable контент */
  #sidebar-scroll {
    flex: 1 !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    max-height: none !important;
    -webkit-overflow-scrolling: touch !important;
    padding-bottom: env(safe-area-inset-bottom, 16px) !important;
  }

  #controls {
    padding: 12px 14px !important;
  }

  /* --- LEGEND (над сайдбаром) --- */
  #legend {
    position: fixed !important;
    bottom: calc(var(--mobile-sidebar-collapsed-height) + 12px) !important;
    right: 10px !important;
    left: auto !important;
    max-width: min(260px, 68vw) !important;
    width: auto !important;
    max-height: 32vh !important;
    font-size: 13px !important;
    padding: 8px 10px !important;
    line-height: 1.15 !important;
    z-index: 1001 !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
    transition: bottom 0.3s ease, top 0.3s ease !important;
    gap: 4px !important;
  }

  /* Legend когда сайдбар расширен */
  #sidebar.mobile-expanded ~ #legend {
    bottom: calc(var(--mobile-sidebar-expanded-height) + 12px) !important;
  }

  #legend .legend-title {
    font-size: 13px !important;
    margin-bottom: 6px !important;
    line-height: 1.1 !important;
  }

  #legend .legend-header {
    padding-right: 48px !important;
  }

  #legend .legend-header-actions {
    top: 2px !important;
    right: 4px !important;
    gap: 2px !important;
  }

  #legend .legend-header-actions .legend-select-reset {
    font-size: 16px !important;
  }

  #legend .legend-scroll {
    max-height: calc(32vh - 64px) !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
    gap: 2px !important;
  }

  #legend .legend-bar {
    width: 52px !important;
    height: 10px !important;
  }

  #legend .legend-label {
    font-size: 11px !important;
    width: 30px !important;
    line-height: 1.1 !important;
  }

  #legend .legend-footer {
    font-size: 11px !important;
    gap: 3px !important;
    flex-wrap: wrap !important;
    margin-top: 6px !important;
  }

  #legend .legend-toggle {
    font-size: 12px !important;
    padding: 6px 8px !important;
    min-height: 32px !important;
  }

  #legend .legend-header-close {
    font-size: 22px !important;
    padding: 0 4px !important;
    min-width: 36px !important;
    min-height: 36px !important;
    line-height: 1 !important;
  }

  /* --- LEGEND CONTROLS (модальное окно) --- */
  #legend-controls {
    position: fixed !important;
    bottom: auto !important;
    top: 50% !important;
    left: 50% !important;
    transform: translate(-50%, -50%) !important;
    max-width: calc(100vw - 32px) !important;
    width: auto !important;
    font-size: 14px !important;
    z-index: 10000 !important;
    max-height: 70vh !important;
    overflow-y: auto !important;
  }

  #legend-controls .legend-btn {
    padding: 10px 16px !important;
    font-size: 15px !important;
    min-height: 44px !important;
  }

  #legend-controls input[type="text"],
  #legend-controls input[type="number"] {
    font-size: 16px !important;
    padding: 10px 12px !important;
    min-height: 44px !important;
  }

  #legend-controls input[type="color"] {
    width: 50px !important;
    height: 44px !important;
    min-width: 50px !important;
    min-height: 44px !important;
  }

  /* --- COUNTRY POPUP (на карте) --- */
  #country-popup {
    position: fixed !important;
    max-width: calc(100vw - 32px) !important;
    left: 16px !important;
    right: 16px !important;
    top: 50% !important;
    transform: translateY(-50%) !important;
    bottom: auto !important;
    font-size: 14px !important;
    z-index: 1002 !important;
    max-height: 50vh !important;
    overflow-y: auto !important;
  }

  #country-popup .popup-title {
    font-size: 16px !important;
    margin-bottom: 8px !important;
  }

  #country-popup .close-btn {
    font-size: 28px !important;
    right: 8px !important;
    top: 8px !important;
    min-width: 44px !important;
    min-height: 44px !important;
  }

  /* --- LANGUAGE SWITCH (внизу сайдбара) --- */
  #lang-switch {
    position: static !important;
    width: 100% !important;
    height: auto !important;
    padding: 16px !important;
    background: transparent !important;
    border-top: 1px solid rgba(79, 195, 247, 0.2) !important;
    margin-top: 16px !important;
    z-index: auto !important;
  }

  #current-lang {
    font-size: 14px !important;
    padding: 10px 12px !important;
    min-height: 44px !important;
  }

  .side-buttons {
    gap: 4px !important;
    flex-wrap: wrap !important;
    justify-content: center !important;
  }

  .side-buttons > div,
  #screenshot-btn {
    width: 40px !important;
    height: 40px !important;
    min-width: 40px !important;
    min-height: 40px !important;
    padding: 4px !important; /* Минимальный padding */
  }

  .side-buttons > div > div,
  #screenshot-btn > div {
    width: 24px !important;
    height: 24px !important;
  }

  /* Скрыть тултипы на мобильных */
  .side-buttons [style*="position: absolute"] {
    display: none !important;
  }

  /* --- LANGUAGE MENU --- */
  #lang-menu {
    position: fixed !important;
    bottom: auto !important;
    top: 50% !important;
    left: 50% !important;
    transform: translate(-50%, -50%) !important;
    max-width: calc(100vw - 32px) !important;
    z-index: 10001 !important;
  }

  /* --- MAP STYLE MENU --- */
  #map-style-menu {
    position: fixed !important;
    bottom: auto !important;
    top: 50% !important;
    left: 50% !important;
    transform: translate(-50%, -50%) !important;
    max-width: calc(100vw - 32px) !important;
    z-index: 10001 !important;
  }

  /* --- INPUTS & SELECTS (компактнее) --- */
  #controls input,
  #controls textarea,
  #controls select {
    font-size: 15px !important; /* 15px+ предотвращает zoom на iOS */
    padding: 9px 11px !important;
    margin-bottom: 8px !important;
    border-radius: 6px !important;
    width: 100% !important;
    box-sizing: border-box !important;
    min-height: 42px !important;
  }

  #controls button {
    font-size: 15px !important;
    padding: 9px 12px !important;
    margin-bottom: 8px !important;
    min-height: 42px !important;
    border-radius: 6px !important;
    width: 100% !important;
    box-sizing: border-box !important;
  }

  #controls .dropdown-label {
    font-size: 13px !important;
    margin-bottom: 4px !important;
    margin-top: 6px !important;
    font-weight: 600 !important;
  }

  #controls hr {
    margin: 10px 0 !important;
  }

  /* --- DATASET MODE SWITCHER --- */
  .dataset-mode-switch {
    flex-wrap: wrap !important;
    gap: 4px !important;
    margin: 8px 0 !important;
    justify-content: center !important;
  }

  .dataset-mode-switch span {
    font-size: 14px !important;
    padding: 8px 12px !important;
    min-height: 38px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
  }

  /* --- DATASET LOCATION SIDEBAR (only presets on mobile) --- */
  .location-sidebar {
    position: fixed !important;
    top: calc(env(safe-area-inset-top, 0px) + 8px) !important;
    right: 10px !important;
    left: auto !important;
    bottom: auto !important;
    transform: none !important;
    width: auto !important;
    max-width: 60vw !important;
    padding: 0 !important;
    margin: 0 !important;
    gap: 0 !important;
    height: auto !important;
    max-height: none !important;
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    backdrop-filter: none !important;
    z-index: 1200 !important;
    display: flex !important;
    flex-direction: column !important;
    pointer-events: none !important;
    display: none !important;
  }

  [data-dataset-mode-active="true"] .location-sidebar.dataset-mode-sidebar {
    display: flex !important;
  }

  .location-sidebar > div:first-child,
  .location-sidebar #location-sidebar-list,
  .location-sidebar.dataset-mode-sidebar #location-sidebar-list {
    display: none !important;
  }

  .location-sidebar .location-sidebar-controls,
  .location-sidebar.dataset-mode-sidebar .location-sidebar-controls {
    width: 100% !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  .location-sidebar .location-sidebar-controls-row,
  .location-sidebar.dataset-mode-sidebar .location-sidebar-controls-row {
    width: 100% !important;
    gap: 6px !important;
    align-items: center !important;
  }

  .location-sidebar #location-reset-selection,
  .location-sidebar.dataset-mode-sidebar #location-reset-selection {
    display: none !important;
  }

  .location-sidebar #location-preset-select,
  .location-sidebar.dataset-mode-sidebar #location-preset-select {
    width: 100% !important;
    font-size: 13px !important;
    padding: 8px 10px !important;
    max-width: 60vw !important;
    pointer-events: auto !important;
  }

  /* --- AI MODEL SWITCH --- */
  #ai-model-switch {
    margin: 8px 0 !important;
    gap: 10px !important;
    flex-wrap: wrap !important;
  }

  .ai-model-label {
    font-size: 13px !important;
  }

  .ai-model-btn {
    min-width: 42px !important;
    min-height: 42px !important;
    padding: 6px !important;
  }

  .ai-model-btn.small-brain img {
    width: 22px !important;
    height: 22px !important;
  }

  .ai-model-btn.big-brain img {
    width: 28px !important;
    height: 28px !important;
  }

  /* --- MODE PANELS (компактнее) --- */
  .mode {
    margin-top: 8px !important;
    margin-bottom: 8px !important;
  }

  .mode-header {
    font-size: 14px !important;
    padding: 9px 12px !important;
    min-height: 42px !important;
    display: flex !important;
    align-items: center !important;
  }

  .mode-body {
    padding: 10px !important;
  }

  /* --- MY DATASETS (компактнее) --- */
  .user-dataset-row {
    margin: 3px 0 !important;
  }

  .dataset-name,
  .inline-rename-input,
  .custom-layer-title {
    font-size: 13px !important;
  }

  /* --- ADD DATASET HEADER --- */
  #add-dataset-header,
  #my-datasets-header,
  #custom-layers-header {
    font-size: 13px !important;
    margin: 8px 0 4px 0 !important;
  }

  /* --- GENPROMPT APP --- */
  #genprompt-app {
    padding: 4px 10px !important;
  }

  #prompt-result,
  #custom-json-area,
  #api-json-area {
    font-size: 13px !important;
  }

  /* --- LABELS --- */
  .country-label {
    font-size: 11px !important;
  }

  .country-label-text {
    font-size: 11px !important;
  }

  /* --- HUD & DEBUG ELEMENTS (hide on mobile) --- */
  #render-hud,
  #leaflet-viewport-hud,
  #quality-switcher,
  #viewport-hud,
  #map-hint {
    display: none !important;
  }

  /* --- PRESENTATION MODE --- */
  #screenshot-title-overlay {
    font-size: 16px !important;
    max-width: calc(100vw - 32px) !important;
    text-align: center !important;
  }

  #screenshot-logo-overlay {
    top: 2% !important;
    right: 2% !important;
    opacity: 0.15 !important;
    z-index: 360000 !important;
  }

  #screenshot-logo-overlay img {
    height: 18vh !important;
  }

  #my-datasets-list,
  #my-drawmaps-list {
    max-height: calc(7 * 38px) !important;
    overflow-y: auto !important;
    scrollbar-width: thin;
    scrollbar-color: rgba(111, 142, 191, 0.7) transparent;
  }

  #my-datasets-list::-webkit-scrollbar,
  #my-drawmaps-list::-webkit-scrollbar {
    width: 4px !important;
  }

  #my-datasets-list::-webkit-scrollbar-thumb,
  #my-drawmaps-list::-webkit-scrollbar-thumb {
    background: rgba(135, 166, 214, 0.8) !important;
    border-radius: 999px !important;
  }

  #presentation-controls {
    bottom: 60px !important;
    left: 50% !important;
    transform: translateX(-50%) !important;
    padding: 8px 12px;
    max-width: calc(100vw - 32px);
  }

  #presentation-controls > div {
    font-size: 11px !important;
  }

  #presentation-controls button {
    width: 28px !important;
    height: 28px !important;
    font-size: 14px !important;
  }

  /* --- BILLING MODAL --- */
  #billing-modal > div {
    width: calc(100vw - 32px) !important;
    max-width: calc(100vw - 32px) !important;
    padding: 18px !important;
  }

  #billing-modal h3 {
    font-size: 17px !important;
    margin-bottom: 14px !important;
  }

  #billing-modal #billing-info {
    font-size: 13px !important;
  }

  #billing-modal button {
    font-size: 14px !important;
    padding: 11px !important;
    margin-top: 12px !important;
  }

  #close-billing {
    font-size: 22px !important;
  }

  /* --- AUTH FORMS --- */
  #login-container {
    margin: 12px 0 !important;
  }

  #email-login-form {
    gap: 10px !important;
    margin-top: 12px !important;
  }

  #email-login-form input {
    font-size: 16px !important;
    padding: 11px 12px !important;
  }

  #email-login-form button {
    font-size: 14px !important;
    padding: 11px !important;
  }

  #email-login-status {
    font-size: 12px !important;
  }

  .auth-btn {
    font-size: 14px !important;
    padding: 11px 0 !important;
  }

  .auth-btn-google {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 8px !important;
  }

  .auth-btn-google img {
    width: 18px !important;
    height: 18px !important;
    flex-shrink: 0 !important;
  }

  /* --- LEGEND ARROWS (hide on mobile) --- */
  .legend-arrow {
    display: none !important;
  }

  /* --- LEGEND CATEGORY ITEMS --- */
  .legend-cat {
    font-size: 13px !important;
    margin: 2px 4px 2px 0 !important;
    line-height: 1.15 !important;
  }

  .legend-cat span:first-child {
    width: 0.9em !important;
    height: 0.9em !important;
  }

  /* --- DRAWING TOOLBAR (над сайдбаром) --- */
  #draw-map-toolbar {
    position: fixed !important;
    bottom: calc(var(--mobile-sidebar-collapsed-height) + 10px) !important;
    left: 50% !important;
    transform: translateX(-50%) !important;
    right: auto !important;
    width: auto !important;
    max-width: calc(100vw - 24px) !important;
    padding: 10px !important;
    z-index: 1001 !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    transition: bottom 0.3s ease !important;
  }

  /* Toolbar когда сайдбар расширен */
  #sidebar.mobile-expanded ~ #draw-map-toolbar {
    bottom: calc(var(--mobile-sidebar-expanded-height) + 10px) !important;
  }

  .toolbar-btn {
    width: 48px !important;
    height: 48px !important;
    min-width: 48px !important;
    min-height: 48px !important;
    margin: 0 4px !important;
    flex-shrink: 0 !important;
  }

  .toolbar-controls {
    flex-wrap: nowrap !important;
    gap: 6px !important;
    justify-content: flex-start !important;
    display: flex !important;
  }

  .toolbar-separator {
    display: none !important;
  }

  /* --- LEAFLET CONTROLS (zoom кнопки) --- */
  .leaflet-control-zoom {
    margin-top: 12px !important;
    margin-right: 12px !important;
  }

  .leaflet-control-zoom a {
    width: 44px !important;
    height: 44px !important;
    min-width: 44px !important;
    min-height: 44px !important;
    line-height: 44px !important;
    font-size: 22px !important;
  }

  .leaflet-top {
    top: 0 !important;
  }

  .leaflet-bottom {
    bottom: var(--mobile-sidebar-collapsed-height) !important;
    transition: bottom 0.3s ease !important;
  }

  #sidebar.mobile-expanded ~ #map .leaflet-bottom {
    bottom: var(--mobile-sidebar-expanded-height) !important;
  }

  .leaflet-control-attribution {
    display: none !important;
  }

  /* --- TEXT SELECTION --- */
  .country-label,
  .legend-title,
  .mode-header {
    -webkit-user-select: none !important;
    user-select: none !important;
  }

  /* --- TOUCH IMPROVEMENTS --- */
  button,
  select,
  input[type="checkbox"],
  .side-buttons > div,
  .legend-cat,
  .mode-header,
  .toolbar-btn {
    -webkit-tap-highlight-color: rgba(93, 158, 250, 0.2) !important;
    touch-action: manipulation !important;
  }

  /* Увеличенные области нажатия для touch устройств */
  button:not(.full-width),
  .toolbar-btn,
  .side-buttons > div {
    min-width: 44px !important;
    min-height: 44px !important;
  }

  /* --- SCROLLBAR STYLING ON MOBILE --- */
  .mobile-sidebar-menu::-webkit-scrollbar,
  #legend .legend-scroll::-webkit-scrollbar {
    width: 4px !important;
  }

  .mobile-sidebar-menu::-webkit-scrollbar-thumb,
  #legend .legend-scroll::-webkit-scrollbar-thumb {
    background: rgba(79, 195, 247, 0.4) !important;
    border-radius: 2px !important;
  }

  .mobile-sidebar-menu::-webkit-scrollbar-track,
  #legend .legend-scroll::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05) !important;
  }

  /* --- CHATBOT WIDGET (оставляем где захардкожено в desktop, просто адаптируем) --- */
  #chatbot-widget {
    max-width: calc(100vw - 32px) !important;
    max-height: 60vh !important;
  }

  /* Новая версия виджета: кнопка в сайдбаре и окно в видимой зоне */
  #mapthos-chat {
    left: 0 !important;
    right: 0 !important;
    top: auto !important;
    bottom: env(safe-area-inset-bottom, 0px) !important;
    width: 100% !important;
    height: min(55svh, 55dvh, 520px) !important;
    min-height: min(50svh, 50dvh, 420px) !important;
    max-height: min(60svh, 60dvh, 560px) !important;
    pointer-events: none !important;
    justify-content: flex-end !important;
    z-index: 20000 !important;
  }

  #sidebar.mobile-expanded ~ #mapthos-chat {
    bottom: 0 !important;
  }

  #mapthos-chat #chat-toggle {
    display: none !important;
  }

  #mobile-chat-toggle {
    display: flex !important;
  }

  #mapthos-chat #chat-box {
    max-width: 100vw !important;
    width: 100vw !important;
    height: 100% !important;
    min-height: 100% !important;
    max-height: 100% !important;
    padding-bottom: env(safe-area-inset-bottom, 0px) !important;
    top: 0 !important;
    right: 0 !important;
    left: 0 !important;
    bottom: 0 !important;
    border-radius: 0 !important;
    pointer-events: auto !important;
    z-index: 20001 !important;
  }

  /* --- PRESENTATION CONTROLS --- */
  #presentation-controls {
    position: fixed !important;
    bottom: calc(var(--mobile-sidebar-collapsed-height) + 12px) !important;
    left: 50% !important;
    transform: translateX(-50%) !important;
    max-width: calc(100vw - 32px) !important;
    z-index: 1001 !important;
    transition: bottom 0.3s ease !important;
  }

  #sidebar.mobile-expanded ~ #presentation-controls {
    bottom: calc(var(--mobile-sidebar-expanded-height) + 12px) !important;
  }

  #presentation-controls > div {
    font-size: 11px !important;
  }

  #presentation-controls button {
    width: 32px !important;
    height: 32px !important;
    font-size: 16px !important;
  }

  /* --- SCROLLBAR STYLING --- */
  #sidebar-scroll::-webkit-scrollbar {
    width: 4px !important;
  }

  #sidebar-scroll::-webkit-scrollbar-thumb {
    background: rgba(79, 195, 247, 0.4) !important;
    border-radius: 2px !important;
  }

  #sidebar-scroll::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05) !important;
  }

  #legend .legend-scroll::-webkit-scrollbar {
    width: 3px !important;
  }

  #legend .legend-scroll::-webkit-scrollbar-thumb {
    background: rgba(79, 195, 247, 0.4) !important;
    border-radius: 2px !important;
  }

  /* --- TOP-ALIGNED OVERLAYS & DRAW MODE HELPERS --- */
  #legend {
    top: calc(env(safe-area-inset-top, 0px) + 8px) !important;
    bottom: auto !important;
    left: auto !important;
    right: 10px !important;
    max-width: min(260px, 68vw) !important;
    width: auto !important;
    max-height: 36vh !important;
  }

  #sidebar.mobile-expanded ~ #legend {
    top: calc(env(safe-area-inset-top, 0px) + 8px) !important;
    bottom: auto !important;
  }

  #legend .legend-scroll {
    max-height: calc(36vh - 64px) !important;
  }

  body.draw-mode-active #legend {
    display: none !important;
  }

  body.draw-mode-active #sidebar-logo {
    display: none !important;
  }

  body.draw-mode-active #draw-map-toolbar {
    top: calc(env(safe-area-inset-top, 0px) + 8px) !important;
    bottom: auto !important;
    left: 50% !important;
    right: auto !important;
    transform: translateX(-50%) !important;
    width: calc(100vw - 24px) !important;
    max-width: calc(100vw - 24px) !important;
    justify-content: center !important;
  }

  body.draw-mode-active #sidebar.mobile-expanded ~ #draw-map-toolbar {
    top: calc(env(safe-area-inset-top, 0px) + 8px) !important;
    bottom: auto !important;
  }

  #mapthos-chat {
    top: auto !important;
    bottom: env(safe-area-inset-bottom, 0px) !important;
    height: min(55svh, 55dvh, 520px) !important;
    min-height: min(50svh, 50dvh, 420px) !important;
    max-height: min(60svh, 60dvh, 560px) !important;
  }

  #sidebar.mobile-expanded ~ #mapthos-chat {
    bottom: 0 !important;
  }

  body.export-preview-active-mobile #sidebar-logo {
    display: none !important;
  }

  #mapthos-chat #chat-box {
    height: 100% !important;
    min-height: 100% !important;
    max-height: 100% !important;
  }

  #lang-menu {
    top: auto !important;
    bottom: calc(var(--mobile-sidebar-collapsed-height) + 10px) !important;
    left: 50% !important;
    transform: translateX(-50%) !important;
    max-height: 48vh !important;
    max-width: calc(100vw - 24px) !important;
    overflow-y: auto !important;
  }

  #sidebar.mobile-expanded ~ #lang-menu {
    bottom: calc(var(--mobile-sidebar-expanded-height) + 10px) !important;
  }

  #export-modal {
    top: auto !important;
    left: 12px !important;
    right: 12px !important;
    transform: none !important;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 10px) !important;
    width: auto !important;
    max-width: none !important;
  }

  #sidebar.mobile-expanded ~ #export-modal {
    bottom: calc(env(safe-area-inset-bottom, 0px) + 10px) !important;
  }

  #export-modal > div {
    width: 100% !important;
    max-width: none !important;
    padding: 10px 12px !important;
    max-height: 34vh !important;
    overflow-y: auto !important;
    border-radius: 12px !important;
    box-shadow: 0 8px 22px rgba(0, 0, 0, 0.45) !important;
    gap: 8px !important;
    background: rgba(22, 27, 34, 0.94) !important;
    border: 1px solid rgba(79, 195, 247, 0.4) !important;
  }

  #export-modal h2 {
    font-size: 13px !important;
    margin: 0 0 2px 0 !important;
    text-align: left !important;
  }

  #export-modal #ratio-grid {
    gap: 4px !important;
    grid-template-columns: repeat(auto-fit, minmax(88px, 1fr)) !important;
    display: flex !important;
    flex-wrap: wrap !important;
    justify-content: flex-start !important;
  }

  #export-modal #ratio-grid button,
  #export-modal [data-resolution] {
    min-height: unset !important;
    height: auto !important;
    font-size: 13px !important;
    border-radius: 0 !important;
    background: transparent !important;
    color: #e6f1ff !important;
    border: none !important;
    padding: 0 !important;
    text-decoration: underline !important;
    box-shadow: none !important;
    line-height: 1.35 !important;
    white-space: nowrap !important;
  }

  #export-modal [data-export-role="footer-row"] {
    gap: 4px !important;
    padding-top: 4px !important;
    justify-content: flex-end !important;
  }

  #export-modal [data-export-role="footer-row"] button {
    min-height: unset !important;
    font-size: 13px !important;
    background: transparent !important;
    border: none !important;
    padding: 0 !important;
    text-decoration: underline !important;
    border-radius: 0 !important;
  }

  #export-modal #share-btn,
  #export-modal #embed-btn {
    background: transparent !important;
    border: none !important;
    padding: 0 !important;
    text-decoration: underline !important;
    color: #e6f1ff !important;
    font-size: 13px !important;
    min-height: unset !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    flex: 0 0 auto !important;
  }

  #export-modal #share-btn + #embed-btn {
    margin-left: 4px !important;
  }
}

/* ==============================================
   ДЕСКТОП - убираем все мобильные стили
   ============================================== */

@media (min-width: 1025px) {
  /* На десктопе все работает как обычно */
  #mobile-expand-btn {
    display: none !important;
  }
}

/* ==============================================
   LANDSCAPE MOBILE (< 1024px width, landscape)
   ============================================== */

@media (max-width: 1024px) and (orientation: landscape) {

  /* В landscape делаем sidebar поменьше для большей видимости карты */
  #sidebar {
    height: 35vh !important;
    max-height: 35vh !important;
  }

  #sidebar.mobile-expanded {
    height: 55vh !important;
    max-height: 55vh !important;
  }

  #map {
    height: 65vh !important;
  }

  #sidebar-logo .logo {
    max-height: 13px !important;
  }

  #legend {
    top: calc(env(safe-area-inset-top, 0px) + 8px) !important;
    bottom: auto !important;
    max-height: 34vh !important;
    font-size: 12px !important;
  }

  #sidebar.mobile-expanded ~ #legend {
    top: calc(env(safe-area-inset-top, 0px) + 8px) !important;
    bottom: auto !important;
  }

  #draw-map-toolbar {
    top: calc(env(safe-area-inset-top, 0px) + 8px) !important;
    bottom: auto !important;
  }

  #sidebar.mobile-expanded ~ #draw-map-toolbar {
    top: calc(env(safe-area-inset-top, 0px) + 8px) !important;
    bottom: auto !important;
  }

  #chatbot-toggle-btn {
    bottom: calc(35vh + 12px) !important;
  }

  #sidebar.mobile-expanded ~ #chatbot-toggle-btn {
    bottom: calc(55vh + 12px) !important;
  }
}

/* ==============================================
   TOUCH DEVICE SPECIFIC
   ============================================== */

@media (hover: none) and (pointer: coarse) {

  /* Увеличенные области нажатия для всех интерактивных элементов */
  button,
  select,
  a,
  .side-buttons > div,
  .legend-cat,
  .mode-header,
  .toolbar-btn,
  .dataset-mode-switch span,
  .user-dataset-row button {
    min-height: 44px !important;
    min-width: 44px !important;
  }

  /* Тактильная обратная связь при нажатии */
  button:active,
  .side-buttons > div:active,
  .toolbar-btn:active,
  .mode-header:active,
  select:active {
    transform: scale(0.96) !important;
    transition: transform 0.1s ease !important;
  }

  /* Убираем hover эффекты на touch устройствах */
  *:hover {
    transition: none !important;
  }

  .mode-header:hover,
  .legend-cat:hover,
  button:not(.auth-btn):not(.login-btn-google):not(.login-btn-email):not(.login-btn-send):hover {
    background: inherit !important;
    opacity: 1 !important;
  }

  /* Улучшенная прокрутка для iOS */
  .mobile-sidebar-menu,
  #legend,
  #legend .legend-scroll {
    -webkit-overflow-scrolling: touch !important;
  }
}

/* ==============================================
   ACCESSIBILITY
   ============================================== */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* Высокая контрастность */
@media (prefers-contrast: high) {
  .mobile-sidebar-menu,
  #legend,
  #legend-controls {
    background: rgba(20, 25, 35, 0.95) !important;
    border: 2px solid rgba(79, 195, 247, 0.8) !important;
  }
}

/* ==============================================
   SMALL MOBILE (< 375px)
   ============================================== */

@media (max-width: 374px) {

  .mobile-sidebar-header .logo {
    max-height: 40px !important;
  }

  .mobile-sidebar-header {
    height: 65px !important;
  }

  #map {
    top: 0 !important;
  }

  #legend {
    font-size: 11px !important;
    padding: 10px 12px !important;
  }

  #legend .legend-bar {
    width: 50px !important;
    height: 10px !important;
  }

  #legend .legend-label {
    font-size: 10px !important;
  }

  .side-buttons > div,
  #screenshot-btn {
    width: 42px !important;
    height: 42px !important;
    min-width: 42px !important;
    min-height: 42px !important;
  }

  .side-buttons > div > div,
  #screenshot-btn > div {
    width: 20px !important;
    height: 20px !important;
  }

  .mobile-sidebar-menu input,
  .mobile-sidebar-menu textarea,
  .mobile-sidebar-menu select {
    font-size: 15px !important;
    padding: 10px 12px !important;
  }

  .dataset-mode-switch span {
    font-size: 14px !important;
    padding: 8px 12px !important;
  }

  .mode-header {
    font-size: 14px !important;
    padding: 10px 12px !important;
  }

  .toolbar-btn {
    width: 44px !important;
    height: 44px !important;
    min-width: 44px !important;
    min-height: 44px !important;
  }
}

/* ==============================================
   IPHONE SE & SIMILAR (маленькие устройства)
   ============================================== */

@media only screen
  and (max-width: 375px)
  and (max-height: 667px) {

  .mobile-sidebar-menu {
    height: 38vh !important;
    padding: 16px 12px !important;
  }

  #map {
    bottom: 38vh !important;
    min-height: 280px !important;
  }

  #legend {
    bottom: calc(38vh + 12px) !important;
  }

  #draw-map-toolbar {
    bottom: calc(38vh + 10px) !important;
  }
}

/* ==============================================
   NOTCH SUPPORT (iPhone X+ и другие с вырезами)
   ============================================== */

@supports (padding: max(0px)) {
  @media (max-width: 1024px) {

    /* Верхний header учитывает вырез */
    .mobile-sidebar-header {
      padding-top: max(10px, calc(10px + env(safe-area-inset-top, 0))) !important;
      height: max(70px, calc(70px + env(safe-area-inset-top, 0))) !important;
    }

    /* Map учитывает header с вырезом */
    #map {
      top: 0 !important;
    }

    /* Нижнее меню учитывает home indicator */
    .mobile-sidebar-menu {
      padding-bottom: max(20px, calc(20px + env(safe-area-inset-bottom, 0))) !important;
    }

    /* Legend учитывает правую и нижнюю области */
    #legend {
      bottom: max(calc(35vh + 16px), calc(35vh + 16px + env(safe-area-inset-bottom, 0))) !important;
      right: max(12px, calc(12px + env(safe-area-inset-right, 0))) !important;
      left: max(12px, calc(12px + env(safe-area-inset-left, 0))) !important;
    }

    /* Тулбар рисования */
    #draw-map-toolbar {
      bottom: max(calc(35vh + 12px), calc(35vh + 12px + env(safe-area-inset-bottom, 0))) !important;
    }

    /* Контролы презентации */
    #presentation-controls {
      bottom: max(calc(35vh + 12px), calc(35vh + 12px + env(safe-area-inset-bottom, 0))) !important;
    }

    /* Чатбот */
    #chatbot-toggle-btn {
      bottom: max(calc(35vh + 16px), calc(35vh + 16px + env(safe-area-inset-bottom, 0))) !important;
      right: max(16px, calc(16px + env(safe-area-inset-right, 0))) !important;
    }

    /* Country popup */
    #country-popup {
      bottom: max(calc(35vh + 16px), calc(35vh + 16px + env(safe-area-inset-bottom, 0))) !important;
      left: max(16px, calc(16px + env(safe-area-inset-left, 0))) !important;
      right: max(16px, calc(16px + env(safe-area-inset-right, 0))) !important;
    }

    /* Leaflet controls */
    .leaflet-control-zoom {
      margin-top: max(80px, calc(80px + env(safe-area-inset-top, 0))) !important;
      margin-right: max(12px, calc(12px + env(safe-area-inset-right, 0))) !important;
    }
  }
}

/* ==============================================
   PREVENT ZOOM ON INPUT FOCUS (iOS Safari fix)
   ============================================== */

@media screen and (-webkit-min-device-pixel-ratio: 0) {
  @media (max-width: 1024px) {
    select,
    textarea,
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="number"] {
      font-size: 16px !important; /* Минимум 16px чтобы iOS не зумил */
    }
  }
}

/* ==============================================
   ДЕСКТОП - убираем все мобильные стили
   ============================================== */

@media (min-width: 1025px) {
  /* На десктопе мобильные контейнеры полностью скрыты */
  .mobile-sidebar-header,
  .mobile-sidebar-menu {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    pointer-events: none !important;
  }

  /* Оригинальный sidebar видим на десктопе */
  #sidebar {
    display: flex !important;
  }
}
