@media (max-width: 1300px) {
  .app-shell {
    grid-template-columns: 280px minmax(420px, 1fr) 380px;
  }
}

@media (max-width: 1080px) {
  .app-shell {
    grid-template-columns: 1fr;
    gap: 10px;
    padding: 10px;
  }

  .panel-left,
  .panel-right {
    order: 2;
  }

  .map-panel {
    order: 1;
  }

  #map {
    height: 62vh;
  }
}

@media (max-width: 768px) {
  /* Shell */
  .app-shell {
    display: block;
    position: relative;
    width: 100%;
    height: 100vh;
    overflow: hidden;
    padding: 0;
    gap: 0;
  }

  /* Mapa full screen */
  .map-panel {
    position: fixed;
    inset: 0;
    border-radius: 0;
    z-index: 1;
  }

  #map {
    height: 100vh;
    width: 100vw;
  }

  /* Painel esquerdo oculto no mobile */
  .panel-left {
    display: none !important;
  }

  /* Propriedade selecionada: popup centralizado */
  .panel-right {
    position: fixed;
    top: 50%;
    bottom: auto;
    left: 50%;
    right: auto;
    width: min(344px, calc(100vw - 24px));
    max-width: calc(100vw - 24px);
    max-height: min(72vh, calc(100vh - 136px));
    height: min(72vh, calc(100vh - 136px));
    display: flex !important;
    flex-direction: column;
    padding: 0;
    overflow: hidden;
    border-radius: 20px;
    z-index: 800;
    opacity: 0;
    pointer-events: none;
    transform: translateX(-50%) translateY(calc(-50% + 24px));
    transition:
      opacity 0.22s ease,
      transform 0.22s ease;
  }

  .panel-right.open {
    opacity: 1;
    pointer-events: auto;
    transform: translateX(-50%) translateY(-50%);
  }

  .panel-right .mobile-drag-handle,
  .panel-right .card-collapse-btn {
    display: none !important;
  }

  .panel-right .property-panel-shell {
    height: 100%;
    min-height: 0;
  }

  .panel-right .property-panel-topbar {
    padding: 16px 18px 0;
  }

  .panel-right .property-panel-headline {
    padding: 18px;
  }

  .panel-right .property-accordion-trigger {
    padding: 16px 18px 0;
  }

  .panel-right .property-panel-scroll {
    padding: 16px 18px 18px;
  }

  .panel-right .property-panel-actions {
    padding: 14px 18px 18px;
  }

  .panel-right .detail-panel .detail-grid {
    gap: 14px 18px;
  }

  .panel-right .property-empty-state {
    padding: 18px;
  }

  .panel-right .empty-state {
    padding: 36px 18px;
  }

  /* Barra de busca — pill branco no topo */
  .map-search-control {
    position: fixed;
    top: 10px;
    left: 20px;
    right: 20px;
    width: auto;
    max-width: none;
    z-index: 500;
    transform: none;
    pointer-events: none;
    box-sizing: border-box;
  }

  .map-search-control * {
    pointer-events: all;
  }

  .map-search-box {
    position: relative;
    background: #ffffff;
    border-radius: 20px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.13);
    padding: 0 10px;
    height: 40px;
    display: flex;
    align-items: center;
    border: none;
    box-sizing: border-box;
  }

  /* Input da busca ocupa toda a largura */
  .map-search-input {
    width: 100%;
    height: 40px;
    font-size: 16px !important;
    border: none;
    background: transparent;
    outline: none;
    padding: 0 6px;
    min-width: 0;
  }

  .map-search-clear {
    position: absolute;
    right: 48px;
    top: 50%;
    transform: translateY(-50%);
  }

  .map-search-results {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    margin-top: 0;
    width: auto;
    box-sizing: border-box;
    z-index: 501;
  }

  /* Controles compactos — pill branco fixo no fundo */
  .map-unified-controls {
    position: fixed;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 6px);
    left: 50%;
    transform: translateX(-50%);
    top: auto;
    right: auto !important;
    width: auto;
    max-width: calc(100vw - 32px);
    z-index: 500;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 4px;
    padding: 8px 14px;
    background: #ffffff;
    border-radius: 999px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.14);
    border: 1px solid rgba(0,0,0,0.07);
    white-space: nowrap;
    min-height: 0;
  }

  .map-unified-controls:hover {
    background: #ffffff;
    box-shadow: 0 2px 12px rgba(0,0,0,0.14);
  }

  .unified-nav-group {
    border-bottom: none;
    justify-content: center;
    padding: 0;
    gap: 4px;
  }

  .unified-divider {
    display: block;
    width: 1px;
    height: 24px;
    margin: 0 6px;
  }

  .unified-layers-group {
    width: auto;
    padding: 0;
    flex-shrink: 0;
  }

  .unified-layers-trigger {
    width: auto;
    justify-content: center;
  }

  .unified-panel-body {
    position: fixed;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 60px);
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    width: min(280px, calc(100vw - 32px));
    min-width: 0;
    box-sizing: border-box;
  }

  .map-visualization-overlay {
    display: none !important;
  }

  /* Zoom leaflet: esconder controle padrão (zoom está no overlay) */
  .leaflet-top.leaflet-right,
  .leaflet-bottom.leaflet-right,
  .leaflet-top.leaflet-left,
  .leaflet-bottom.leaflet-left {
    display: none;
  }

  /* Toast e mensagem de zoom */
  #zoomMessage,
  .talhao-toast {
    bottom: calc(env(safe-area-inset-bottom, 10px) + 80px);
    left: 50%;
    transform: translateX(-50%);
    z-index: 12050;
  }

  #toast-container {
    right: 12px;
    left: 12px;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 12px);
    z-index: 12050;
  }

  #toast-container .toast {
    min-width: 0;
    max-width: none;
    width: 100%;
  }

  /* Esconder elementos mobile antigos */
  .mobile-bottom-bar,
  .mobile-nav-pill,
  .mobile-overlay,
  .floating-clean-toggle {
    display: none !important;
  }

  /* Floating controls: esconder */
  .floating-clean-toggle {
    display: none !important;
  }

  /* Botão de perfil na barra de busca */
  .mobile-profile-btn {
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: none;
    background: rgba(0,0,0,0.06);
    color: var(--color-text-strong, #1a2a15);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.15s;
    z-index: 2;
  }

  .mobile-profile-btn:active {
    background: rgba(0,0,0,0.12);
  }

  /* Reservar espaço para limpar a busca e abrir a conta */
  .map-search-box {
    padding-right: 78px;
  }

  /* Bottom sheet de conta */
  .mobile-account-sheet {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 4000;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
    border-radius: 20px 20px 0 0;
    background: #ffffff;
    box-shadow: 0 -4px 32px rgba(0,0,0,0.14);
  }

  .mobile-account-sheet.open {
    transform: translateY(0);
  }

  .mobile-account-sheet-inner {
    padding: 0 20px 32px;
    padding-bottom: calc(env(safe-area-inset-bottom, 16px) + 16px);
  }

  .mobile-account-overlay {
    position: fixed;
    inset: 0;
    z-index: 3999;
    background: rgba(0,0,0,0.30);
    display: none;
  }

  .mobile-account-overlay.open {
    display: block;
  }

  /* Identidade */
  .mobile-account-identity {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 0 12px;
    border-bottom: 1px solid rgba(0,0,0,0.07);
    margin-bottom: 14px;
  }

  .mobile-account-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(0,200,83,0.12);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    flex-shrink: 0;
  }

  .mobile-account-name {
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--color-text-strong, #1a2a15);
  }

  .mobile-account-email {
    font-size: 0.8rem;
    color: var(--color-text-muted, #666);
    margin-top: 2px;
  }

  /* Plano e saldo */
  .mobile-account-plan {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: rgba(0,200,83,0.07);
    border-radius: 10px;
    margin-bottom: 14px;
    transition: background-color 0.18s ease, transform 0.18s ease, box-shadow 0.18s ease;
  }

  .mobile-account-plan.wallet-shortcut {
    cursor: pointer;
  }

  .mobile-account-plan.wallet-shortcut:hover {
    background: rgba(0, 200, 83, 0.12);
    box-shadow: 0 8px 18px rgba(18, 52, 32, 0.08);
    transform: translateY(-1px);
  }

  .mobile-account-plan.wallet-shortcut:focus-visible {
    outline: 2px solid var(--color-primary, #00C853);
    outline-offset: 2px;
  }

  .mobile-account-badge {
    font-size: 0.75rem;
    font-weight: 700;
    padding: 3px 10px;
    border-radius: 999px;
    background: var(--color-primary, #00C853);
    color: #fff;
  }

  .mobile-account-balance {
    font-size: 0.85rem;
    color: var(--color-text-strong, #1a2a15);
    font-weight: 500;
  }

  /* WhatsApp */
  .mobile-account-whatsapp {
    font-size: 0.82rem;
    color: var(--color-text-muted, #666);
    margin-bottom: 16px;
    text-align: center;
  }

  .mobile-account-whatsapp a {
    color: #1a7a3a;
    font-weight: 600;
    text-decoration: none;
  }

  /* Botão logout */
  .mobile-account-logout {
    width: 100%;
    padding: 13px;
    border-radius: 12px;
    border: 1px solid rgba(0,0,0,0.10);
    background: rgba(0,0,0,0.04);
    font-size: 0.9rem;
    font-weight: 600;
    color: #c0392b;
    cursor: pointer;
  }

  /* Estado não logado */
  .mobile-account-guest-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--color-text-strong, #1a2a15);
    margin: 18px 0 6px;
    text-align: center;
  }

  .mobile-account-guest-sub {
    font-size: 0.82rem;
    color: var(--color-text-muted, #666);
    text-align: center;
    margin-bottom: 18px;
    line-height: 1.45;
  }

  .mobile-account-login-btn {
    width: 100%;
    padding: 14px;
    border-radius: 14px;
    border: none;
    background: var(--color-primary, #00C853);
    color: #fff;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
  }
}

/* Fora do mobile, drag handle e nav pill são invisíveis */
@media (min-width: 769px) {
  .mobile-drag-handle {
    display: none;
  }

  .mobile-nav-pill {
    display: none !important;
  }

  .mobile-profile-btn,
  .mobile-account-sheet,
  .mobile-account-overlay {
    display: none !important;
  }
}
