/* ============================================
   RESPONSIVE / MOBILE-FIRST OVERRIDES
   ============================================ */

/* ── MOBILE (max 768px) ── */
@media (max-width: 768px) {

  /* Header: compact & flexible */
  #app-header    { height: var(--header-top-height, 54px); padding: 0 12px; gap: 8px; }
  .logo          { display: inline-flex !important; align-items: center; gap: 6px; text-decoration: none; flex-shrink: 0; }
  .logo-text     { display: inline-block !important; font-size: 15px !important; font-weight: 800 !important; color: #0f5940 !important; white-space: nowrap; }
  .logo-icon     { font-size: 22px; }
  #btn-filter-desktop { display: none !important; }
  .search-wrapper { min-width: 0; flex: 1; }
  #search-input  { height: 38px; padding: 0 32px 0 34px; font-size: 13px; }
  .search-icon   { left: 10px; font-size: 14px; }
  #search-clear  { right: 8px; font-size: 14px; }

  /* Register button in header */
  .btn-register  { padding: 6px 11px; font-size: 12px; }

  /* Main fills to above toolbar */
  #app-main { top: var(--total-header-height, 136px); bottom: 58px; overflow: visible !important; }

  /* Overlay backdrop: sits behind slide-in sidebar */
  #overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    z-index: 1070 !important;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-base);
  }
  #overlay.visible {
    opacity: 1 !important;
    pointer-events: auto !important;
  }

  /* Sidebar: slide-in drawer on mobile (high z-index so it's on top of map and overlay) */
  #sidebar {
    position: fixed !important;
    left: 0 !important;
    top: var(--total-header-height, 136px) !important;
    bottom: 58px !important;
    width: 100% !important;
    max-width: 480px !important;
    min-width: unset !important;
    background: #ffffff !important;
    box-shadow: 6px 0 30px rgba(0,0,0,0.22) !important;
    transform: translateX(-100%) !important;
    transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1) !important;
    z-index: 1080 !important;
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important;
  }
  #sidebar.open {
    transform: translateX(0) !important;
  }
  #btn-close-sidebar { display: flex !important; }

  /* Map fills full width */
  #map-container { left: 0; }

  /* Mobile toolbar: 4 items evenly spaced */
  #mobile-toolbar {
    height: 58px;
    display: flex !important;
    padding: 0 4px;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    background: #fff;
    border-top: 1px solid var(--color-border);
    box-shadow: 0 -2px 10px rgba(0,0,0,0.06);
    z-index: 1200;
    pointer-events: auto;
  }
  .toolbar-btn {
    flex: 1;
    min-width: 0;
    padding: 4px 2px;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    color: var(--color-text-secondary);
    text-decoration: none;
    font-size: 11px;
    font-weight: var(--font-weight-medium);
    border: none;
    background: none;
    border-radius: var(--radius-md);
  }
  .toolbar-btn:active, .toolbar-btn.active {
    color: var(--color-primary);
    background: var(--color-primary-bg);
  }
  .toolbar-btn .icon { font-size: 19px; line-height: 1; }
  .toolbar-btn.toolbar-btn-register {
    color: var(--color-primary);
    font-weight: var(--font-weight-semibold);
  }

  /* Bottom sheet: completely hidden and non-blocking when closed */
  #bottom-sheet {
    display: none !important;
    pointer-events: none !important;
    visibility: hidden !important;
    position: fixed;
    bottom: 58px; left: 0; right: 0;
    max-height: 72vh;
    z-index: 1100;
    transform: translateY(100%);
    transition: transform 0.25s ease, opacity 0.2s ease;
    opacity: 0;
  }
  #bottom-sheet.open {
    display: block !important;
    pointer-events: auto !important;
    visibility: visible !important;
    transform: translateY(0) !important;
    opacity: 1 !important;
  }

  /* Filter panel wider & higher than overlay */
  #filter-panel {
    width: min(88vw, 340px);
    z-index: 1300 !important;
  }

  /* Map controls smaller */
  #map-controls { right: 8px; top: 8px; }
  .map-control-btn { width: 38px; height: 38px; font-size: 16px; }

  /* Map hint hidden on mobile */
  .map-hint { display: none; }

  /* Toast higher (above toolbar) */
  .toast { bottom: 68px; }
}

/* ── EXTRA SMALL MOBILE (< 400px) ── */
@media (max-width: 400px) {
  #app-header { padding: 0 6px; gap: 6px; }
  .logo-text { white-space: nowrap; font-size: 14px; }
  .platform-switcher .platform-tab span:last-child { display: none; }
  .btn-register-text { display: none; }
  .btn-register {
    width: 34px; height: 34px;
    padding: 0;
    justify-content: center;
    border-radius: 50%;
  }
  .btn-register-icon { font-size: 15px; margin: 0; }
  #search-input { font-size: 12px; }
  .toolbar-btn { font-size: 10px; }
}

/* ── DESKTOP (min 769px) ── */
@media (min-width: 769px) {
  /* Hide mobile-only elements */
  #mobile-toolbar { display: none !important; }
  #bottom-sheet   { display: none !important; }
  #btn-close-sidebar { display: none !important; }

  /* Main fills right of sidebar */
  #app-main {
    position: fixed !important;
    top: var(--total-header-height, 144px) !important;
    left: var(--sidebar-width, 360px) !important;
    right: 0 !important;
    bottom: 0 !important;
    z-index: 10 !important;
  }

  /* Sidebar fixed on left */
  #sidebar {
    display: flex !important;
    transform: none !important;
    position: fixed !important;
    top: var(--total-header-height, 144px) !important;
    left: 0 !important;
    bottom: 0 !important;
    width: var(--sidebar-width, 360px) !important;
    min-width: var(--sidebar-width, 360px) !important;
    z-index: 30 !important;
    background: #ffffff !important;
    border-right: 1px solid var(--color-border, #e2e8f0) !important;
  }

  /* Map fills full container */
  #map-container { width: 100% !important; height: 100% !important; }

  /* Desktop filter button */
  #btn-filter-desktop { display: inline-flex !important; }

  /* Larger search */
  .search-wrapper { max-width: 600px; }

  /* Toast lower (no toolbar) */
  .toast { bottom: 24px; }
}

/* ── LARGE DESKTOP (min 1200px) ── */
@media (min-width: 1200px) {
  :root { --sidebar-width: 400px; }
  #search-input { font-size: var(--font-size-base); }
}

/* ── TOUCH OPTIMIZATION ── */
@media (hover: none) and (pointer: coarse) {
  .btn       { min-height: 48px; }
  .btn-sm    { min-height: 40px; }
  .toolbar-btn { min-height: 52px; }
  .filter-option { min-height: 48px; }
  .list-item { padding: 14px 16px; }
  .suggestion-item { padding: 13px 16px; }
  #search-input { height: 48px; }
}

/* ── HIGH DPI ── */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  .custom-marker { image-rendering: crisp-edges; }
}

/* ── REDUCED MOTION ── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ── PRINT ── */
@media print {
  #app-header, #mobile-toolbar, #map-container,
  #filter-panel, #bottom-sheet, #overlay { display: none !important; }
  #sidebar { position: static; width: 100%; transform: none; }
}
