/* mobile.css — mobile-first UX
   Loads after main.css, overrides with !important where needed.

   Breakpoints:
   ≤767px   — phones
   481–767px — large phones (sub-breakpoint)
   768–1023px — tablets portrait
   1024–1366px — tablets landscape / small desktop
*/

/* ═══════════════════════════════════════════════════
   GLOBAL RESETS (all sizes)
═══════════════════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; }
html, body { max-width: 100%; overflow-x: hidden; }
img, video, iframe, canvas { max-width: 100%; }
table { display: block; overflow-x: auto; max-width: 100%; }

/* Sheet structure (default = desktop layout) */
.sheet-handle { display: none; }
.sheet-btns {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.sheet-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 0;
  overflow-y: auto;
}

/* Chat back button (hidden on desktop) */
.cr-back-btn { display: none !important; }

/* ═══════════════════════════════════════════════════
   PHONES ≤ 767px
═══════════════════════════════════════════════════ */
@media (max-width: 767px) {

  /* ── Root tokens ── */
  :root {
    --topbar-h: 60px;
    --mob-nav-h: 64px;
  }

  /* ── Scrollable body (fixes profile/friends not scrolling) ── */
  html { height: auto !important; }
  body { height: auto !important; min-height: 100dvh; }
  .app-shell { grid-template-columns: 1fr !important; min-height: 0 !important; }
  main.content {
    height: auto !important;
    overflow-y: visible !important;
  }

  /* ── Topbar ── */
  .topbar { padding: 0 12px !important; height: 60px !important; }
  .brand-title { font-size: 16px !important; }

  /* ══════════════════════════════════════════
     BOTTOM NAVIGATION (sidebar → fixed footer)
  ══════════════════════════════════════════ */
  .sidebar {
    display: flex !important;
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    top: auto !important;
    height: auto !important;
    z-index: 300 !important;
    background: var(--bg-elevated) !important;
    border-top: 1px solid var(--border) !important;
    box-shadow: 0 -4px 24px rgba(11,18,32,.12) !important;
    /* Safe area for iPhone notch */
    padding: 4px 6px calc(6px + env(safe-area-inset-bottom, 0px)) !important;
    backdrop-filter: blur(24px) !important;
    -webkit-backdrop-filter: blur(24px) !important;
    border-radius: 0 !important;
  }

  /* Grid gives each nav item exactly equal width, regardless of count */
  .sidebar-menu {
    display: grid !important;
    grid-auto-flow: column !important;
    grid-auto-columns: 1fr !important;
    align-items: stretch !important;
    width: 100% !important;
    flex: 1 !important;
    background: transparent !important;
    border: 0 !important;
    box-shadow: none !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    padding: 0 !important;
    gap: 0 !important;
  }

  .side-link {
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: center !important;
    width: 100% !important;
    height: auto !important;
    min-height: 52px !important;
    padding: 6px 2px !important;
    gap: 3px !important;
    border: 0 !important;
    background: transparent !important;
    border-radius: 10px !important;
    transform: none !important;
    text-align: center !important;
    white-space: nowrap !important;
  }
  .side-link:hover {
    transform: none !important;
    background: rgba(58,160,255,.08) !important;
    box-shadow: none !important;
  }
  .side-link.active {
    background: rgba(58,160,255,.12) !important;
    border-color: transparent !important;
  }
  .side-link.active .side-ico i,
  .side-link.active .side-text { color: rgba(58,160,255,1) !important; }

  .side-ico {
    width: 22px !important;
    height: 22px !important;
    background: transparent !important;
    border: 0 !important;
    border-radius: 0 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
  }
  .side-ico i { font-size: 20px !important; color: rgba(11,18,32,.70) !important; }
  .side-text {
    font-size: 9px !important;
    font-weight: 700 !important;
    color: rgba(11,18,32,.55) !important;
    line-height: 1.1 !important;
    letter-spacing: .01em !important;
  }

  /* Скрываем десктопные пункты — ПОСЛЕ .side-link чтобы перебить display:flex */
  .sidebar-menu .side-link--desktop-only {
    display: none !important;
    width: 0 !important;
    overflow: hidden !important;
  }

  /* Body bottom padding (safe area aware) */
  body {
    padding-bottom: calc(64px + env(safe-area-inset-bottom, 0px)) !important;
  }

  /* Content: no side padding (elements handle their own) */
  main.content {
    padding: 0 !important;
    overflow-x: hidden !important;
  }

  /* ══════════════════════════════════════════
     MAP PAGE — FULL SCREEN + BOTTOM SHEET
  ══════════════════════════════════════════ */

  /* Map: fixed to viewport between topbar and bottom nav */
  .map {
    position: fixed !important;
    top: var(--topbar-h) !important;
    left: 0 !important;
    right: 0 !important;
    bottom: var(--mob-nav-h) !important;
    height: auto !important;
    border-radius: 0 !important;
    outline: none !important;
    box-shadow: none !important;
    z-index: 1 !important;
  }

  /* ── Bottom Sheet ── */
  .map-sidebar {
    position: fixed !important;
    bottom: var(--mob-nav-h) !important;
    left: 0 !important;
    right: 0 !important;
    top: auto !important;
    width: 100% !important;

    /* Collapsed height — shows handle + action buttons */
    height: 108px !important;
    max-height: 108px !important;
    overflow: hidden !important;

    border-radius: 20px 20px 0 0 !important;
    padding: 0 !important;

    background: rgba(255,255,255,.97) !important;
    border: none !important;
    border-top: 1px solid rgba(11,18,32,.08) !important;
    box-shadow: 0 -6px 28px rgba(11,18,32,.12) !important;
    backdrop-filter: blur(24px) !important;
    -webkit-backdrop-filter: blur(24px) !important;

    transition: height .32s cubic-bezier(.2,.8,.2,1),
                max-height .32s cubic-bezier(.2,.8,.2,1) !important;

    z-index: 200 !important;
    flex-direction: column !important;
    gap: 0 !important;
    display: flex !important;
  }

  /* Expanded state */
  .map-sidebar.sheet-open {
    height: 62vh !important;
    max-height: 62vh !important;
  }

  /* Drag handle */
  .sheet-handle {
    display: flex !important;
    align-items: center;
    justify-content: center;
    height: 22px;
    flex-shrink: 0;
    cursor: pointer;
    touch-action: none;
    padding-top: 6px;
  }
  .sheet-handle::after {
    content: '';
    width: 40px;
    height: 4px;
    background: rgba(11,18,32,.18);
    border-radius: 999px;
  }

  /* Action buttons row (always visible) */
  .sheet-btns {
    flex-direction: row !important;
    gap: 6px !important;
    padding: 4px 10px 8px !important;
    flex-shrink: 0 !important;
  }
  .sheet-btns .rp-btn {
    flex: 1 !important;
    height: 38px !important;
    font-size: 12px !important;
    padding: 0 6px !important;
    border-radius: 10px !important;
    gap: 4px !important;
    justify-content: center !important;
  }

  /* Sheet scrollable body */
  .sheet-body {
    flex: 1 !important;
    overflow-y: auto !important;
    padding: 4px 10px 16px !important;
    min-height: 0 !important;
    gap: 6px !important;
    display: flex !important;
    flex-direction: column !important;
  }

  /* Search input: prevent iOS auto-zoom (needs font-size ≥ 16px) */
  #map-search-input { font-size: 16px !important; }

  /* Event detail modal: bottom sheet on mobile */
  #event-detail-modal {
    align-items: flex-end !important;
    padding: 0 !important;
  }
  #event-detail-modal > div {
    width: 100% !important;
    max-width: 100% !important;
    max-height: 88vh !important;
    border-radius: 20px 20px 0 0 !important;
    margin: 0 !important;
  }

  /* Create event modal */
  .cem-box {
    padding: 20px 14px 20px !important;
    border-radius: 20px !important;
    max-height: 88vh !important;
    max-width: 100% !important;
  }
  .cem-grid-2 { grid-template-columns: 1fr 1fr !important; gap: 8px !important; }
  .cem-cat-grid { grid-template-columns: repeat(3, 1fr) !important; }

  /* Toast: above bottom nav */
  .notif-toast {
    left: 8px !important;
    right: 8px !important;
    bottom: calc(var(--mob-nav-h) + 8px) !important;
    max-width: none !important;
  }

  /* ══════════════════════════════════════════
     PROFILE PAGE
  ══════════════════════════════════════════ */

  /* Cover: fixed height instead of aspect-ratio */
  .cover-banner {
    height: 180px !important;
    aspect-ratio: unset !important;
    border-radius: 0 !important;
  }

  /* Profile 2-col → 1-col, less negative margin */
  .profile-layout {
    grid-template-columns: 1fr !important;
    margin: -50px auto 0 !important;
    padding: 0 12px !important;
    gap: 12px !important;
    max-width: 100% !important;
  }

  /* Edit form wrap */
  .edit-form-wrap {
    margin: -50px auto 0 !important;
    padding: 0 12px !important;
    max-width: 100% !important;
  }

  /* Avatar photo: smaller on mobile */
  .avatar-xl-img {
    width: 88px !important;
    height: 88px !important;
    border-width: 3px !important;
    margin-bottom: 10px !important;
  }

  /* Avatar initials size-xl → small on mobile */
  .avatar-initials.size-xl {
    width: 88px !important;
    height: 88px !important;
    font-size: 28px !important;
    box-shadow: none !important;
  }

  /* Profile left card: less padding-top (avatar is smaller) */
  .profile-left > .card-glass:first-child {
    padding: 18px 14px 14px !important;
  }

  /* Stat cards: compact */
  .stat-row { gap: 6px !important; }
  .stat-card { padding: 10px 4px !important; }
  .stat-value { font-size: 18px !important; }
  .stat-label { font-size: 9px !important; }

  /* Page header — needs its own padding since main.content has padding:0 */
  .page-hdr {
    padding: 12px 14px 8px !important;
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    margin-bottom: var(--gap-md);
  }
  .page-h1 { font-size: 22px !important; letter-spacing: -0.01em; }
  .page-subtitle { font-size: 13px; }
  .page-hdr-actions {
    width: 100%;
    flex-wrap: wrap;
    gap: 6px;
  }
  .page-hdr-actions .btn { padding: 0 12px !important; }

  /* KV table */
  .kv-table { grid-template-columns: 86px 1fr; }
  .kv-table dt, .kv-table dd { font-size: 13px; padding: 10px 0; }

  /* ══════════════════════════════════════════
     CHATS PAGE — MOBILE NAVIGATION
  ══════════════════════════════════════════ */

  /* Full-screen shell */
  .chats-shell {
    position: fixed !important;
    top: var(--topbar-h) !important;
    left: 0 !important;
    right: 0 !important;
    bottom: var(--mob-nav-h) !important;
    width: 100% !important;
    height: auto !important;
    flex-direction: column !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    overflow: hidden !important;
  }

  /* Chat list: full screen by default */
  .cl-panel {
    width: 100% !important;
    min-width: 0 !important;
    flex: 1 !important;
    max-height: none !important;
    border-right: none !important;
    border-bottom: none !important;
  }

  /* Chat window panel: hidden by default (show only list) */
  .cr-panel {
    display: none !important;
    position: absolute !important;
    inset: 0 !important;
    z-index: 10 !important;
    background: rgba(255,255,255,.97) !important;
  }

  /* When chat is open: hide list, show chat */
  .chats-shell.mobile-chat-open .cl-panel {
    display: none !important;
  }
  .chats-shell.mobile-chat-open .cr-panel {
    display: flex !important;
    flex-direction: column !important;
  }

  /* Back button (mobile only) */
  .cr-back-btn {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    border: 1px solid rgba(11,18,32,.10);
    background: rgba(255,255,255,.70);
    color: rgba(11,18,32,.60);
    font-size: 22px;
    font-weight: 600;
    cursor: pointer;
    flex-shrink: 0;
    margin-right: 4px;
    line-height: 1;
    padding: 0;
    font-family: inherit;
  }

  /* Prevent iOS zoom on chat input */
  .cr-input { font-size: 16px !important; }

  /* Chat tabs */
  .cl-tabs { padding: 10px 8px 0; }
  .cl-tab { font-size: 12px !important; height: 36px !important; }

  /* Message bubbles */
  .msg-bubble { max-width: 82% !important; }

  /* ══════════════════════════════════════════
     FRIENDS / NOTIFICATIONS / OTHER PAGES
  ══════════════════════════════════════════ */
  .chips { flex-wrap: wrap; gap: 4px; }
  .chip { padding: 6px 10px; font-size: 12px; }
  .btn { min-height: 44px; }
  .btn-sm { min-height: 36px; }
  .notif-actions { flex-wrap: wrap; gap: 6px; }
  .card-glass { border-radius: var(--radius); }
  .notif-item { padding: 12px; }
  .rating-buttons { display: flex; flex-wrap: wrap; gap: 6px; }
  .rating-buttons button { margin: 0; }

  /* Auth pages */
  .auth-card {
    padding: 22px 16px 18px !important;
    border-radius: var(--radius) !important;
  }
  .unauth { padding: 16px 12px; }

  /* Old profile container (profile.css) */
  .profile-container {
    position: relative !important;
    left: auto !important;
    top: auto !important;
    transform: none !important;
    width: calc(100vw - 16px) !important;
    max-width: 100% !important;
    max-height: none !important;
    margin: 8px auto 20px !important;
    z-index: auto !important;
  }
  .profile-main {
    grid-template-columns: 1fr !important;
    margin-top: -40px !important;
  }
  .profile-pic, .no-photo {
    width: 120px !important;
    height: 120px !important;
  }
  .profile-actions { flex-wrap: wrap !important; }

  /* Modals */
  .modal-app {
    max-width: 100% !important;
    border-radius: var(--radius) !important;
    padding: var(--gap-md) !important;
  }
  .modal-content { width: calc(100vw - 24px) !important; }
  .modal { padding: 12px !important; }
  .settings-panel { width: 100vw !important; }
  .inv-box {
    border-radius: var(--radius-lg) !important;
    padding: 18px 14px !important;
  }
  .chat-modal-box {
    border-radius: var(--radius-lg) !important;
    padding: 18px 14px !important;
    min-width: 0 !important;
    width: 92vw !important;
  }
  .notifications-dropdown {
    width: calc(100vw - 28px) !important;
    right: -10px !important;
  }
}

/* ═══════════════════════════════════════════════════
   LARGE PHONES 481–767px (on top of base phone rules)
═══════════════════════════════════════════════════ */
@media (min-width: 481px) and (max-width: 767px) {
  .page-h1 { font-size: 24px !important; }
  .msg-bubble { max-width: 74% !important; }
  .cover-banner { height: 200px !important; }
  .avatar-xl-img { width: 100px !important; height: 100px !important; }
  .avatar-initials.size-xl {
    width: 100px !important;
    height: 100px !important;
    font-size: 32px !important;
  }
  .map-sidebar { height: 112px !important; max-height: 112px !important; }
  .map-sidebar.sheet-open { height: 60vh !important; max-height: 60vh !important; }
}

/* ═══════════════════════════════════════════════════
   TOUCH DEVICE: remove sticky hover states
═══════════════════════════════════════════════════ */
@media (hover: none) and (pointer: coarse) {
  .side-link:hover { transform: none; background: transparent !important; }
  .event-item:hover { transform: none; }
  .btn:hover { transform: none; box-shadow: none; }
  .notif-item:hover { transform: none; }
  .msg:hover .msg-actions { display: none; }
  .side-link { min-height: 44px; }
  .btn { min-height: 44px; }
  .cl-row { min-height: 56px; }
  .rp-event-row:hover { transform: none !important; }
  .rp-btn:hover { transform: none !important; }
}

/* ═══════════════════════════════════════════════════
   TABLETS PORTRAIT 768–1023px
═══════════════════════════════════════════════════ */
@media (min-width: 768px) and (max-width: 1023px) {
  :root {
    --left-w: 200px;
    --right-w: 270px;
    --topbar-h: 66px;
  }

  .topbar { padding: 0 14px; }
  .brand-title { font-size: 17px; }
  .sidebar { padding: 10px; }
  .sidebar-menu { gap: 6px; }
  .side-link { height: 42px; }
  .side-text { font-size: 12px; }

  .map-sidebar {
    width: var(--right-w) !important;
    right: var(--gap) !important;
  }

  .profile-layout { grid-template-columns: 220px 1fr !important; }
  .profile-container {
    width: min(980px, calc(100vw - 210px)) !important;
  }

  .page-h1 { font-size: 24px; }
  .page-hdr { flex-wrap: wrap; }

  .cl-panel { width: 240px !important; min-width: 240px !important; }

  .cem-cat-grid { grid-template-columns: repeat(4, 1fr) !important; }
  .btn { min-height: 44px; }
  .btn-sm { min-height: 36px; }
}

/* ═══════════════════════════════════════════════════
   TABLETS LANDSCAPE / SMALL DESKTOP 1024–1366px
═══════════════════════════════════════════════════ */
@media (min-width: 1024px) and (max-width: 1366px) {
  :root {
    --left-w: 230px;
    --right-w: 300px;
  }
}

/* ═══════════════════════════════════════════════════
   REDUCED MOTION
═══════════════════════════════════════════════════ */
@media (prefers-reduced-motion: reduce) {
  .map-sidebar { transition: none !important; }
}

/* ═══════════════════════════════════════════════════
   FRIENDS PAGE — icon-only action buttons on mobile
═══════════════════════════════════════════════════ */
@media (max-width: 767px) {
  /* friend cards: убираем текст трюком font-size:0, иконку возвращаем */
  .fl-friend-card .fl-actions .btn {
    font-size: 0 !important;
    width: 40px !important;
    height: 40px !important;
    min-height: 40px !important;
    padding: 0 !important;
    border-radius: 50% !important;
    flex-shrink: 0;
  }
  .fl-friend-card .fl-actions .btn i {
    font-size: 17px !important;
    margin: 0 !important;
  }
  /* request cards: чуть компактнее, но оставляем текст */
  .fl-req-card .fl-actions .btn {
    height: 34px !important;
    min-height: 34px !important;
    padding: 0 10px !important;
    font-size: 12px !important;
    border-radius: var(--radius-sm) !important;
  }
  /* search result cards: то же самое что friend cards */
  .fl-result-card .fl-actions .btn {
    font-size: 0 !important;
    width: 40px !important;
    height: 40px !important;
    min-height: 40px !important;
    padding: 0 !important;
    border-radius: 50% !important;
  }
  .fl-result-card .fl-actions .btn i {
    font-size: 17px !important;
    margin: 0 !important;
  }
  /* fl-actions не переносим строку */
  .fl-friend-card .fl-actions,
  .fl-result-card .fl-actions {
    flex-wrap: nowrap !important;
    gap: 6px !important;
  }
}
