/* Pocket Austin — Track 3.6: Mobile Bottom-Sheet UX
 * Strictly scoped to <= 760px; desktop layout is completely untouched.
 */

#mobile-top-bar,
#mobile-search-panel,
#mobile-sheet,
#mobile-sheet-backdrop {
  display: none;
}

@media (max-width: 760px) {
  html,
  body {
    overflow: hidden;
    overscroll-behavior: none;
    -webkit-tap-highlight-color: transparent;
  }

  /* Hide desktop floating panels so >88% of mobile screen is pure illustrated Austin */
  body.pa-mobile-active #hud,
  body.pa-mobile-active #bookmarks,
  body.pa-mobile-active #footer,
  body.pa-mobile-active #carto-controls,
  body.pa-mobile-active #hover-tip,
  body.pa-mobile-active #pa-explore-dock {
    display: none !important;
  }

  body.pa-mobile-active #pa-minimap {
    bottom: calc(max(10px, env(safe-area-inset-bottom)) + 52px) !important;
    right: 10px !important;
  }

  body.pa-mobile-active #pa-tour-card {
    bottom: calc(max(10px, env(safe-area-inset-bottom)) + 52px) !important;
    left: 10px !important;
    right: 10px !important;
    width: auto !important;
    max-width: calc(100vw - 20px) !important;
  }

  /* 1. Compact Top Floating Pill Bar */
  #mobile-top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    position: fixed;
    top: max(8px, env(safe-area-inset-top));
    left: 10px;
    right: 10px;
    height: 42px;
    padding: 4px 6px 4px 10px;
    z-index: 44;
    background: rgba(251, 246, 234, 0.94);
    border: 1.5px solid var(--border, #4a3b2c);
    border-radius: 999px;
    box-shadow: 0 6px 20px rgba(20, 14, 10, 0.28);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    max-width: calc(100vw - 20px);
  }

  .m-brand {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    min-width: 0;
    border: none;
    background: transparent;
    padding: 0;
    color: var(--ink, #2c221a);
    cursor: pointer;
    font-family: inherit;
  }

  .m-crest {
    width: 24px;
    height: 24px;
    flex-shrink: 0;
    display: block;
  }

  .m-brand-text {
    font-size: 14px;
    font-weight: 800;
    letter-spacing: -0.02em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .m-live-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--live, #2e7d32);
    flex-shrink: 0;
    box-shadow: 0 0 0 2.5px rgba(46, 125, 50, 0.2);
  }

  .m-top-actions {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
  }

  .m-icon-btn {
    appearance: none;
    border: 1.1px solid rgba(74, 59, 44, 0.32);
    background: rgba(255, 250, 240, 0.9);
    color: var(--ink, #2c221a);
    height: 32px;
    min-width: 34px;
    padding: 0 9px;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    font-family: inherit;
    font-size: 11.5px;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
  }

  .m-icon-btn:active {
    transform: scale(0.96);
  }

  .m-icon-btn.active {
    background: var(--ink, #2c221a);
    color: #fbf6ea;
    border-color: var(--ink, #2c221a);
  }

  .m-icon-btn svg {
    width: 15px;
    height: 15px;
    flex-shrink: 0;
  }

  /* 2. Mobile Search Dropdown Panel */
  #mobile-search-panel {
    display: none;
    position: fixed;
    top: calc(max(8px, env(safe-area-inset-top)) + 48px);
    left: 10px;
    right: 10px;
    z-index: 46;
    background: rgba(251, 246, 234, 0.98);
    border: 1.5px solid var(--border, #4a3b2c);
    border-radius: 14px;
    box-shadow: 0 12px 32px rgba(20, 14, 10, 0.34);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    padding: 10px;
    max-width: calc(100vw - 20px);
    overflow: hidden;
  }

  #mobile-search-panel.open {
    display: block;
  }

  .m-search-row {
    display: flex;
    align-items: center;
    gap: 6px;
  }

  #mobile-search-input {
    flex: 1 1 auto;
    min-width: 0;
    height: 38px;
    border: 1.2px solid rgba(74, 59, 44, 0.55);
    border-radius: 9px;
    background: #fffdf8;
    color: var(--ink, #2c221a);
    font-family: inherit;
    font-size: 14px;
    padding: 0 11px;
    outline: none;
  }

  #mobile-search-input:focus {
    border-color: var(--accent, #c45735);
    box-shadow: 0 0 0 2px rgba(196, 87, 53, 0.16);
  }

  #mobile-search-close {
    appearance: none;
    border: 1px solid rgba(74, 59, 44, 0.35);
    background: rgba(74, 59, 44, 0.08);
    color: var(--ink, #2c221a);
    width: 38px;
    height: 38px;
    border-radius: 9px;
    font-size: 18px;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
  }

  #mobile-search-results {
    margin-top: 8px;
    max-height: 44vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    border-top: 1px solid rgba(74, 59, 44, 0.14);
  }

  #mobile-search-results:empty {
    display: none;
    margin-top: 0;
    border-top: none;
  }

  /* 3. Bottom Sheet Backdrop */
  #mobile-sheet-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 41;
    background: rgba(24, 18, 12, 0.28);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.22s ease;
  }

  #mobile-sheet-backdrop.visible {
    opacity: 1;
    pointer-events: auto;
  }

  /* 4. Draggable / Tappable Bottom Sheet */
  #mobile-sheet {
    display: flex;
    flex-direction: column;
    position: fixed;
    left: 10px;
    right: 10px;
    bottom: max(10px, env(safe-area-inset-bottom));
    z-index: 43;
    background: rgba(251, 246, 234, 0.96);
    border: 1.5px solid var(--border, #4a3b2c);
    border-radius: 18px;
    box-shadow: 0 10px 30px rgba(20, 14, 10, 0.34);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    max-width: calc(100vw - 20px);
    max-height: 76vh;
    overflow: hidden;
    transition: transform 0.26s cubic-bezier(0.22, 1, 0.36, 1),
      border-radius 0.22s ease,
      left 0.22s ease,
      right 0.22s ease,
      bottom 0.22s ease;
    will-change: transform;
  }

  /* Collapsed slim bottom pill by default (>88% pure map!) */
  #mobile-sheet.collapsed {
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    width: min(310px, calc(100vw - 24px));
    border-radius: 999px;
    max-height: 44px;
  }

  #mobile-sheet.dragging {
    transition: none !important;
  }

  .m-sheet-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 6px 14px 8px;
    cursor: grab;
    touch-action: none;
    user-select: none;
    flex-shrink: 0;
  }

  #mobile-sheet.collapsed .m-sheet-header {
    padding: 4px 14px 6px;
  }

  .m-drag-handle {
    width: 36px;
    height: 4px;
    border-radius: 999px;
    background: rgba(74, 59, 44, 0.36);
    margin-bottom: 5px;
  }

  #mobile-sheet.collapsed .m-drag-handle {
    margin-bottom: 3px;
  }

  .m-sheet-pill-row {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
  }

  .m-sheet-title {
    font-size: 12.5px;
    font-weight: 800;
    letter-spacing: -0.01em;
    color: var(--ink, #2c221a);
    white-space: nowrap;
  }

  .m-sheet-meta {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    font-weight: 600;
    color: var(--ink-muted, #665848);
    white-space: nowrap;
  }

  .m-sheet-chevron {
    display: inline-block;
    font-size: 11px;
    transition: transform 0.2s ease;
  }

  #mobile-sheet:not(.collapsed) .m-sheet-chevron {
    transform: rotate(180deg);
  }

  .m-sheet-body {
    padding: 2px 14px 14px;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    display: flex;
    flex-direction: column;
    gap: 12px;
  }

  #mobile-sheet.collapsed .m-sheet-body {
    display: none;
  }

  .m-section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
  }

  .m-section-label {
    font-size: 10px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--ink-muted, #665848);
  }

  /* Quick-Jump Neighborhood Chips */
  .m-chip-rail {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 2px;
  }

  .m-chip-rail::-webkit-scrollbar {
    display: none;
  }

  .m-chip {
    appearance: none;
    border: 1.2px solid var(--border, #4a3b2c);
    background: #fffaf0;
    color: var(--ink, #2c221a);
    font-family: inherit;
    font-size: 12px;
    font-weight: 700;
    padding: 7px 12px;
    min-height: 36px;
    border-radius: 999px;
    white-space: nowrap;
    cursor: pointer;
    flex-shrink: 0;
  }

  .m-chip:active {
    background: var(--ink, #2c221a);
    color: #fbf6ea;
  }

  /* Solar Phase Segmented Picker */
  .m-solar-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 5px;
  }

  .m-solar-btn {
    appearance: none;
    border: 1.2px solid rgba(74, 59, 44, 0.42);
    background: rgba(255, 250, 240, 0.9);
    color: var(--ink, #2c221a);
    font-family: inherit;
    font-size: 11.5px;
    font-weight: 700;
    min-height: 38px;
    padding: 6px 4px;
    border-radius: 9px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 3px;
  }

  .m-solar-btn.active {
    background: var(--ink, #2c221a);
    border-color: var(--ink, #2c221a);
    color: #fbf6ea;
  }

  /* 2-column Layer Toggles Grid */
  .m-layer-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
  }

  .m-layer-chip {
    appearance: none;
    border: 1.2px solid rgba(74, 59, 44, 0.34);
    background: rgba(74, 59, 44, 0.055);
    color: var(--ink, #2c221a);
    font-family: inherit;
    font-size: 11.8px;
    font-weight: 600;
    min-height: 40px;
    padding: 7px 9px;
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    text-align: left;
    min-width: 0;
  }

  .m-layer-chip span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .m-layer-chip .m-layer-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    border: 1.2px solid rgba(74, 59, 44, 0.55);
    background: transparent;
    flex-shrink: 0;
  }

  .m-layer-chip.on {
    background: rgba(196, 87, 53, 0.13);
    border-color: var(--accent, #c45735);
    color: var(--ink, #2c221a);
    font-weight: 700;
  }

  .m-layer-chip.on .m-layer-dot {
    background: var(--accent, #c45735);
    border-color: var(--accent, #c45735);
  }

  /* Tours & Explore Actions */
  .m-action-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
  }

  .m-action-btn {
    appearance: none;
    border: 1.2px solid var(--border, #4a3b2c);
    background: #fffaf0;
    color: var(--ink, #2c221a);
    font-family: inherit;
    font-size: 12px;
    font-weight: 700;
    min-height: 40px;
    padding: 8px 10px;
    border-radius: 10px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    text-align: center;
  }

  .m-action-btn.primary {
    background: var(--accent, #c45735);
    border-color: var(--border, #4a3b2c);
    color: #fbf6ea;
  }

  .m-telemetry {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 12px;
    padding-top: 8px;
    border-top: 1px solid rgba(74, 59, 44, 0.16);
    font-size: 11px;
    color: var(--ink-muted, #665848);
  }

  /* 5. Crisp Mobile Inspector Bottom Card (44px touch close target + zero horizontal overflow) */
  #inspector {
    position: fixed !important;
    left: 10px !important;
    right: 10px !important;
    bottom: max(10px, env(safe-area-inset-bottom)) !important;
    top: auto !important;
    width: auto !important;
    max-width: calc(100vw - 20px) !important;
    max-height: 62vh !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    -webkit-overflow-scrolling: touch;
    z-index: 48 !important;
    border-radius: 16px !important;
    padding: 14px 14px 14px !important;
    box-shadow: 0 12px 34px rgba(20, 14, 10, 0.38) !important;
    word-wrap: break-word;
    overflow-wrap: anywhere;
  }

  #inspector .insp-head {
    margin: 0 46px 5px 0 !important;
    flex-wrap: wrap;
  }

  #inspector .close {
    top: 4px !important;
    right: 4px !important;
    width: 44px !important;
    height: 44px !important;
    min-width: 44px !important;
    min-height: 44px !important;
    border-radius: 50% !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    font-size: 22px !important;
    line-height: 1 !important;
    background: rgba(74, 59, 44, 0.08) !important;
    color: var(--ink, #2c221a) !important;
    padding: 0 !important;
  }

  #inspector .close:active {
    background: rgba(74, 59, 44, 0.2) !important;
  }

  #inspector img,
  #inspector video,
  #inspector canvas {
    max-width: 100%;
    height: auto;
  }

  #inspector #insp-actions {
    flex-wrap: wrap;
  }

  /* Keep toast comfortably above slim bottom pill */
  #toast {
    bottom: calc(max(10px, env(safe-area-inset-bottom)) + 54px) !important;
    max-width: calc(100vw - 24px);
    text-align: center;
  }
}
