/* ================================================================
   CoreBase · mobile.css  v1.0
   Мобильная адаптация (≤ 768px) + планшет (769–1024px)
   Подключить ПОСЛЕ main.css в <head>:
     <link rel="stylesheet" href="/static/css/mobile.css">
   Десктоп не затрагивается — все стили внутри @media
================================================================ */

/* ── Desktop: скрыть мобильные элементы ─────────────────────── */
@media (min-width: 769px) {
  .mob-hamburger  { display: none !important; }
  .mob-bottom-nav { display: none !important; }
  .mob-overlay    { display: none !important; }
}

/* ══════════════════════════════════════════════════════════════
   МОБИЛЬНЫЙ BREAKPOINT  ≤ 768px
══════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {

  /* ── 1. КОРНЕВОЙ LAYOUT ──────────────────────────────────────── */
  .app {
    flex-direction: column;
    height: 100dvh; /* dynamic viewport — iOS Safari fix */
  }

  /* ── 2. БОКОВАЯ ПАНЕЛЬ → выдвижной drawer ───────────────────── */
  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: min(280px, 85vw);
    z-index: 900;
    transform: translateX(-100%);
    transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 4px 0 32px rgba(0, 0, 0, 0.22);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .sidebar.mob-open {
    transform: translateX(0);
  }

  /* Затемнение за сайдбаром */
  .mob-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.42);
    z-index: 850;
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
  }
  .mob-overlay.active { display: block; }

  /* ── 3. ОСНОВНОЙ БЛОК ───────────────────────────────────────── */
  .main {
    width: 100%;
    height: 100dvh;
    margin-left: 0 !important;
  }

  /* ── 4. ТОПБАР ─────────────────────────────────────────────── */
  .topbar {
    padding: 0 10px;
    height: 52px;
    gap: 6px;
  }

  /* Кнопка гамбургера (вставляется через mobile.js) */
  .mob-hamburger {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    border: none;
    background: none;
    cursor: pointer;
    border-radius: var(--radius-sm);
    color: var(--text-2);
    flex-shrink: 0;
    transition: background 0.15s;
    -webkit-tap-highlight-color: transparent;
  }
  .mob-hamburger:hover,
  .mob-hamburger:active { background: var(--bg); }
  .mob-hamburger svg { width: 22px; height: 22px; }

  /* Хлебные крошки: не переполнять */
  .breadcrumb {
    flex: 1;
    min-width: 0;
    overflow: hidden;
  }
  .bc, .bc-active {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 120px;
  }
  .bc-sep { display: none; } /* скрываем разделители, оставляем только активный */

  /* Действия в топбаре */
  #topbar-actions {
    display: flex;
    gap: 4px;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    flex-shrink: 0;
    max-width: 50vw;
  }

  /* ── 5. КОНТЕНТ ─────────────────────────────────────────────── */
  .content {
    padding: 14px 12px;
    padding-bottom: 74px; /* отступ для нижней навигации */
  }

  /* ── 6. СТАТИСТИКА → 2 колонки ──────────────────────────────── */
  .stats-row {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    margin-bottom: 16px;
  }
  .stat-card { padding: 12px 10px; }
  .stat-value { font-size: 22px; }
  .stat-label { font-size: 10px; }

  /* ── 7. СЕТКА СКВАЖИН → 1 колонка ───────────────────────────── */
  .wells-grid {
    grid-template-columns: 1fr;
    gap: 8px;
  }
  .well-card { padding: 14px; }

  /* Действия карточки — всегда видны на мобиле */
  .card-actions { opacity: 1 !important; }

  /* ── 8. ТАБЛИЦЫ → горизонтальный скролл ─────────────────────── */
  .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--radius);
  }

  .data-table {
    min-width: 560px;
  }

  .data-table td,
  .data-table th {
    padding: 8px 10px;
  }

  /* Действия строк — всегда видны */
  .row-actions { opacity: 1 !important; }

  /* ── 9. ТАБЫ СКВАЖИНЫ → горизонтальный скролл ───────────────── */
  .well-tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap;
    gap: 0;
    scrollbar-width: none;
  }
  .well-tabs::-webkit-scrollbar { display: none; }

  .well-tab {
    flex-shrink: 0;
    padding: 10px 14px;
    white-space: nowrap;
    font-size: 12px;
  }

  /* ── 10. ЗАГОЛОВОК СЕКЦИИ → перенос ─────────────────────────── */
  .section-hdr {
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 10px;
  }
  .section-hdr .spacer { flex: 0; display: none; }

  .search-box {
    width: 100%;
    max-width: 100%;
  }

  /* ── 11. МОДАЛЬНЫЕ ОКНА → bottom sheet ──────────────────────── */
  .modal-overlay {
    align-items: flex-end;
    padding: 0;
  }

  .modal {
    width: 100% !important;
    max-width: 100% !important;
    max-height: 93dvh;
    border-radius: 18px 18px 0 0 !important;
    transform: translateY(100%) !important;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
  }

  .modal-overlay.open .modal {
    transform: translateY(0) !important;
  }

  /* Drag handle для модалок */
  .modal-hdr::before {
    content: '';
    display: block;
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    width: 36px; height: 4px;
    background: var(--border-md);
    border-radius: 4px;
  }
  .modal-hdr { position: relative; }

  /* ── 12. ФОРМЫ → 1 колонка, без zoom на iOS ─────────────────── */
  .form-row {
    grid-template-columns: 1fr;
    gap: 0;
  }

  /* Предотвращаем zoom на iOS при фокусе на input < 16px */
  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="number"],
  input[type="search"],
  .form-input,
  .cal-inp,
  select,
  textarea {
    font-size: 16px !important;
  }

  /* ── 13. КНОПКИ → минимум 44px (Apple HIG) ──────────────────── */
  .btn {
    min-height: 40px;
    padding: 8px 14px;
  }
  .btn-sm { min-height: 36px; }
  .icon-btn { width: 36px; height: 36px; }

  /* ── 14. СЕТКИ РЕЗУЛЬТАТОВ И ОТЧЁТОВ ─────────────────────────── */
  .results-grid { grid-template-columns: 1fr; gap: 8px; }
  .reports-list-grid { grid-template-columns: 1fr; gap: 8px; }
  .research-grid { grid-template-columns: repeat(2, 1fr); }

  /* ── 15. КАРТА ───────────────────────────────────────────────── */
  .map-layout {
    flex-direction: column !important;
    height: auto !important;
  }

  #map-container {
    height: 55vmax;
    min-height: 300px;
    width: 100%;
    order: 1;
  }

  .map-left-panel {
    width: 100% !important;
    max-height: 180px;
    border-right: none !important;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    order: 0;
    overflow-y: auto;
  }

  .map-side-panel {
    width: 100% !important;
    max-height: 220px;
    border-left: none !important;
    border-top: 1px solid var(--border);
    overflow-y: auto;
    order: 2;
  }

  .map-toolbar {
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px 10px;
    overflow-x: auto;
  }
  .map-toolbar > div {
    flex-wrap: wrap;
    gap: 4px;
  }

  #map-draw-hint {
    margin: 6px 10px 0;
    font-size: 11px;
  }

  /* ── 16. СГК / ГИС → стек ──────────────────────────────────── */
  .sgk-layout {
    grid-template-columns: 1fr;
    gap: 10px;
  }
  .sgk-files-col {
    max-height: 260px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* ── 17. ЧАТОВАЯ И AI ПАНЕЛИ → полный экран ────────────────── */
  #chat-panel {
    width: 100% !important;
    right: -100% !important;
    transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
  }
  #chat-panel.chat-open {
    right: 0 !important;
  }

  .chat-sidebar {
    width: 110px;
  }

  #ai-panel {
    width: 100% !important;
    left: -100% !important;
    transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
  }
  #ai-panel.ai-open {
    left: 0 !important;
  }

  /* Боковые кнопки чата/ИИ/календаря → скрыты, управление через нижнюю панель */
  #ai-tab-btn,
  #chat-tab-btn,
  #cal-tab-btn {
    display: none !important;
  }

  /* ── 18. КАЛЕНДАРЬ ──────────────────────────────────────────── */
  #calendar-panel {
    left: 0 !important;
    right: 0 !important;
    height: 94dvh;
  }

  .cal-body { flex-direction: column; }

  .cal-left {
    width: 100% !important;
    border-right: none !important;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    padding: 10px;
  }

  .cal-cell { min-height: 36px; }
  .cal-dnum { font-size: 11px; }
  .cal-tabs-bar { overflow-x: auto; flex-wrap: nowrap; }
  .cal-tabs-row { flex-wrap: nowrap; }

  /* ── 19. МАТРИЦА ────────────────────────────────────────────── */
  #matrix-wrap {
    overflow-x: auto;
    max-height: calc(100dvh - 160px);
    -webkit-overflow-scrolling: touch;
  }

  /* ── 20. КОРЗИНА ────────────────────────────────────────────── */
  #trash-filter-bar {
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 4px;
    scrollbar-width: none;
  }
  #trash-filter-bar::-webkit-scrollbar { display: none; }
  #trash-filter-bar .btn { flex-shrink: 0; }

  /* ── 21. ТОСТЫ → снизу по центру ───────────────────────────── */
  .toast-wrap {
    right: 12px;
    left: 12px;
    bottom: 70px;
    align-items: center;
  }
  .toast { text-align: center; }

  /* ── 22. НИЖНЯЯ НАВИГАЦИЯ ───────────────────────────────────── */
  .mob-bottom-nav {
    display: flex !important;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    height: 60px;
    background: var(--surface);
    border-top: 1px solid var(--border);
    z-index: 1300; /* выше панелей чата/ИИ/календаря (z:1100) */
    align-items: center;
    justify-content: space-around;
    padding: 0 2px env(safe-area-inset-bottom);
    box-shadow: 0 -2px 16px rgba(0, 0, 0, 0.08);
  }

  .mob-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-width: 50px;
    min-height: 50px;
    padding: 4px 6px;
    border: none;
    background: none;
    cursor: pointer;
    border-radius: 10px;
    color: var(--text-3);
    font-family: inherit;
    font-size: 10px;
    font-weight: 500;
    transition: color 0.15s, background 0.15s;
    position: relative;
    -webkit-tap-highlight-color: transparent;
  }
  .mob-nav-item:active { background: var(--bg); }
  .mob-nav-item.active { color: var(--blue); }

  /* Кнопка в режиме "закрыть панель" */
  .mob-nav-item.panel-open {
    color: #dc2626;
    background: rgba(220, 38, 38, 0.08);
    border-radius: 10px;
  }
  .mob-nav-item.panel-open svg,
  .mob-nav-item.panel-open .mob-nav-icon { display: none; }
  .mob-nav-item.panel-open .mob-nav-close { display: flex !important; }

  .mob-nav-close {
    display: none;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    line-height: 1;
  }

  .mob-nav-item svg { width: 20px; height: 20px; }

  .mob-nav-badge {
    position: absolute;
    top: 4px; right: 8px;
    background: #dc2626;
    color: #fff;
    border-radius: 50%;
    width: 14px; height: 14px;
    font-size: 8px; font-weight: 700;
    display: flex; align-items: center; justify-content: center;
    line-height: 1;
  }

  /* ── Топбар: кнопки действий меньше ─────────────────────────── */
  #topbar-actions {
    display: flex;
    gap: 4px;
    align-items: center;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    flex-shrink: 0;
    max-width: 56vw;
    scrollbar-width: none;
    padding-bottom: 1px;
  }
  #topbar-actions::-webkit-scrollbar { display: none; }

  #topbar-actions .btn,
  #topbar-actions button {
    font-size: 11px !important;
    padding: 4px 8px !important;
    min-height: 30px !important;
    height: 30px;
    white-space: nowrap;
    flex-shrink: 0;
    gap: 3px !important;
  }

  /* Иконочные кнопки (без текста) */
  #topbar-actions .icon-btn,
  #topbar-actions button[title]:not([class*="btn-primary"]) {
    width: 30px !important;
    height: 30px !important;
    padding: 0 !important;
    min-height: 30px !important;
  }

  /* ── 23. СПЛЭШ ────────────────────────────────────────────── */
  #splash > div[style*="font-size:42px"] {
    font-size: 32px !important;
  }

  /* ── 24. ДОПОЛНИТЕЛЬНО ──────────────────────────────────────── */
  /* Volume table */
  #volume-content .table-wrap { overflow-x: auto; }
  #volume-table { min-width: 700px; }

  /* Admin form */
  #page-admin .form-row {
    display: flex;
    flex-direction: column;
    gap: 10px;
  }

  /* Litho viewer */
  #modal-litho-viewer .modal {
    max-height: 96dvh;
  }
  /* Litho export buttons: wrap */
  #modal-litho-viewer [style*="padding:12px 24px"] {
    flex-wrap: wrap;
    gap: 6px;
  }

  /* SGK toggle */
  .sgk-toggle-wrap { flex-shrink: 0; }

  /* Section header chips — scroll */
  .chip-row {
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 2px;
  }
  .chip-row::-webkit-scrollbar { display: none; }
  .chip { flex-shrink: 0; }

  /* Help page */
  .help-section { padding: 14px 16px; }

  /* About page */
  #page-about > div {
    padding: 20px 16px !important;
    margin: 0 !important;
  }

  /* Creator page header */
  #page-creator > div:first-child {
    flex-wrap: wrap;
    gap: 10px;
  }
}

/* ══════════════════════════════════════════════════════════════
   ПЛАНШЕТ  769px–1024px — лёгкая адаптация
══════════════════════════════════════════════════════════════ */
@media (min-width: 769px) and (max-width: 1024px) {
  .sidebar { width: 210px; }
  .stats-row { grid-template-columns: repeat(2, 1fr); }
  .wells-grid { grid-template-columns: repeat(2, 1fr); }
  .results-grid { grid-template-columns: repeat(2, 1fr); }
  .cal-left { width: 280px; }
}

/* ══════════════════════════════════════════════════════════════
   ОЧЕНЬ УЗКИЙ ЭКРАН  ≤ 380px
══════════════════════════════════════════════════════════════ */
@media (max-width: 380px) {
  .stats-row { grid-template-columns: 1fr 1fr; gap: 6px; }
  .stat-value { font-size: 18px; }
  .content { padding: 10px 8px 74px; }
  .well-tab { padding: 8px 10px; font-size: 11px; }
  .mob-nav-item { min-width: 44px; font-size: 9px; }
}
