/* ==========================================================================
   Map side panel (desktop, 1024px and wider)
   Lists the albergues and places on the visible map, grouped by town, and
   shows a place's detail page beside the map. Phones never see any of it:
   everything below lives inside the min-width query, and the panel's own
   stylesheets (detail_pages, detail_v2) load only when it activates.
   ========================================================================== */

:root {
  --map-panel-w: 400px;
}

.map-panel,
.map-panel-tab {
  display: none;
}

@media (min-width: 1024px) {
  body.map-panel-open .map-panel {
    display: flex;
  }
  body.map-panel-collapsed .map-panel-tab {
    display: inline-flex;
  }

  /* The map and its chrome move right to make room */
  body.map-panel-open #map {
    left: var(--map-panel-w);
    width: auto;
    right: 0;
  }
  body.map-panel-open .offline-pill {
    left: calc(var(--map-panel-w) + 14px);
  }
  body.map-panel-open .layer-bar,
  body.map-panel-open .layer-toast {
    left: calc(50% + var(--map-panel-w) / 2);
  }

  /* ---- Panel shell ---- */
  .map-panel {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--map-panel-w);
    z-index: 1060; /* above the layer bar so the photo lightbox covers it */
    flex-direction: column;
    background: var(--paper, #f4ecdc);
    background-image: var(--grain);
    background-size: 4px 4px;
    border-right: 1px solid var(--ink-line, #e2d5bd);
    box-shadow: 8px 0 28px -18px rgba(74, 52, 28, 0.45);
    font-family: var(--font-body, system-ui, sans-serif);
    color: var(--ink, #2d2114);
    -webkit-font-smoothing: antialiased;
  }
  .map-panel ::selection {
    background: #f6e4cd;
    color: var(--ink, #2d2114);
  }

  .map-panel__view {
    display: flex;
    flex-direction: column;
    min-height: 0;
    flex: 1;
  }
  .map-panel__view[hidden] {
    display: none;
  }
  .map-panel__view--detail {
    animation: map-panel-in 0.22s cubic-bezier(0.16, 1, 0.3, 1);
  }
  @keyframes map-panel-in {
    from {
      opacity: 0;
      transform: translateX(14px);
    }
    to {
      opacity: 1;
      transform: none;
    }
  }

  .map-panel__scroll {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: #cdbb9a transparent;
  }
  .map-panel__scroll::-webkit-scrollbar {
    width: 8px;
  }
  .map-panel__scroll::-webkit-scrollbar-thumb {
    background: #cdbb9a;
    border-radius: 8px;
    border: 2px solid var(--paper, #f4ecdc);
  }
  .map-panel__scroll:focus {
    outline: none;
  }

  /* ---- List header ---- */
  .map-panel__head {
    padding: 18px 20px 14px;
    border-bottom: 1px solid var(--ink-line, #e2d5bd);
  }
  .map-panel__title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
  }
  .map-panel__title {
    margin: 0;
    font-family: var(--font-display, Georgia, serif);
    font-optical-sizing: auto;
    font-weight: 600;
    font-size: 24px;
    line-height: 1.1;
    letter-spacing: -0.01em;
    color: var(--ink, #2d2114);
  }
  .map-panel__summary {
    margin: 4px 0 0;
    min-height: 20px;
    font-size: 13.5px;
    line-height: 1.45;
    color: var(--ink-soft, #6b5a45);
  }
  .map-panel__filters {
    display: flex;
    gap: 8px;
    margin-top: 12px;
  }
  .map-panel__chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 40px;
    padding: 0 14px 0 12px;
    border: 1px solid var(--ink-line, #e2d5bd);
    border-radius: 999px;
    background: var(--paper-card, #fbf6ea);
    color: var(--ink-soft, #6b5a45);
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition:
      background 0.15s,
      color 0.15s,
      border-color 0.15s;
  }
  .map-panel__chip svg {
    width: 16px;
    height: 16px;
    flex: none;
  }
  .map-panel__chip:hover {
    color: var(--ink, #2d2114);
  }
  .map-panel__chip.is-on {
    background: #f6e4cd;
    border-color: #e3c6a0;
    color: var(--amber-deep, #9c4a13);
  }
  .map-panel__chip:focus-visible,
  .map-panel__iconbtn:focus-visible,
  .map-panel__back:focus-visible,
  .map-panel__row:focus-visible,
  .map-panel-tab:focus-visible {
    outline: 2px solid var(--amber-deep, #9c4a13);
    outline-offset: -2px;
  }

  .map-panel__iconbtn {
    width: 40px;
    height: 40px;
    flex: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: var(--ink-soft, #6b5a45);
    text-decoration: none;
    cursor: pointer;
    transition:
      background 0.15s,
      color 0.15s;
  }
  .map-panel__iconbtn:hover {
    background: var(--paper-card, #fbf6ea);
    color: var(--ink, #2d2114);
  }
  .map-panel__iconbtn[hidden] {
    display: none;
  }
  .map-panel__iconbtn svg {
    display: block;
  }

  /* ---- Groups and rows ---- */
  .map-panel__hint {
    margin: 0;
    padding: 10px 20px;
    font-size: 12.5px;
    line-height: 1.45;
    color: var(--ink-soft, #6b5a45);
    border-bottom: 1px solid var(--ink-line, #e2d5bd);
  }
  .map-panel__group {
    list-style: none;
    margin: 0;
    padding: 0 0 6px;
  }
  .map-panel__group-head {
    position: sticky;
    top: 0;
    z-index: 1;
    display: block;
    margin: 0;
    padding: 14px 20px 6px;
    background: var(--paper, #f4ecdc);
    background-image: var(--grain);
    background-size: 4px 4px;
    font-family: var(--font-display, Georgia, serif);
    font-optical-sizing: auto;
    font-weight: 600;
    font-size: 17px;
    line-height: 1.2;
    color: var(--ink, #2d2114);
  }
  .map-panel__item + .map-panel__item .map-panel__row {
    box-shadow: inset 0 1px 0 var(--ink-line, #e2d5bd);
  }

  .map-panel__row {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    min-height: 56px;
    padding: 8px 20px;
    border: 0;
    background: transparent;
    text-align: left;
    font-family: inherit;
    color: inherit;
    cursor: pointer;
    transition: background 0.12s;
  }
  .map-panel__row:hover,
  .map-panel__row.is-hot {
    background: var(--paper-card, #fbf6ea);
  }
  .map-panel__row-icon {
    width: 36px;
    height: 36px;
    flex: none;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    border: 1px solid var(--ink-line, #e2d5bd);
    background: var(--paper-card, #fbf6ea);
    color: var(--amber-deep, #9c4a13);
  }
  .map-panel__row-icon--poi {
    color: var(--poi-color, #6b7280);
  }
  .map-panel__row-icon--town {
    color: var(--ink-soft, #6b5a45);
  }
  .map-panel__row-icon svg {
    width: 18px;
    height: 18px;
    display: block;
  }
  .map-panel__row-icon--poi svg {
    width: 20px;
    height: 20px;
  }
  .map-panel__row-icon img {
    width: 22px;
    height: 22px;
  }
  .map-panel__row-text {
    flex: 1;
    min-width: 0;
  }
  .map-panel__row-name {
    display: block;
    font-size: 15px;
    font-weight: 600;
    line-height: 1.25;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .map-panel__row-meta {
    display: block;
    margin-top: 2px;
    font-size: 13px;
    line-height: 1.3;
    color: var(--ink-soft, #6b5a45);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .map-panel__tag {
    display: inline-block;
    margin-left: 6px;
    padding: 1px 7px;
    border-radius: 999px;
    font-size: 11.5px;
    font-weight: 700;
    line-height: 1.4;
    vertical-align: 1px;
    background: #f3dcd3;
    color: #7f3016;
  }

  .map-panel__note {
    margin: 0;
    padding: 36px 28px;
    text-align: center;
    font-size: 14px;
    line-height: 1.5;
    color: var(--ink-soft, #6b5a45);
  }
  .map-panel__note strong {
    display: block;
    margin-bottom: 6px;
    font-family: var(--font-display, Georgia, serif);
    font-optical-sizing: auto;
    font-weight: 600;
    font-size: 19px;
    color: var(--ink, #2d2114);
  }
  .map-panel__note a {
    color: var(--amber-deep, #9c4a13);
    font-weight: 600;
    text-decoration: underline;
    text-underline-offset: 3px;
  }

  /* ---- Detail view ---- */
  .map-panel__bar {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 8px 10px 8px 8px;
    border-bottom: 1px solid var(--ink-line, #e2d5bd);
  }
  .map-panel__back {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    min-height: 40px;
    margin-right: auto;
    padding: 0 12px 0 6px;
    border: 0;
    border-radius: 10px;
    background: transparent;
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    color: var(--ink, #2d2114);
    cursor: pointer;
    transition: background 0.15s;
  }
  .map-panel__back:hover {
    background: var(--paper-card, #fbf6ea);
  }
  .map-panel__back svg {
    flex: none;
  }

  .map-panel__detail {
    background: var(--paper, #f4ecdc);
  }
  .map-panel__loading,
  .map-panel__error {
    padding: 28px 24px;
    color: var(--ink-soft, #6b5a45);
    font-size: 14px;
    line-height: 1.5;
  }
  .map-panel__loading h2,
  .map-panel__error h2 {
    margin: 0 0 8px;
    font-family: var(--font-display, Georgia, serif);
    font-optical-sizing: auto;
    font-weight: 600;
    font-size: 24px;
    line-height: 1.1;
    color: var(--ink, #2d2114);
  }
  .map-panel__error a {
    color: var(--amber-deep, #9c4a13);
    font-weight: 600;
    text-decoration: underline;
    text-underline-offset: 3px;
  }

  /* The detail page is built for a full viewport; inside the 400px panel
     it keeps its phone layout even though the window is wide. */
  .map-panel__detail .detail-v2 {
    min-height: 0;
    background: transparent;
    background-image: none;
  }
  .map-panel__detail .detail-v2 .ab-hero {
    min-height: 250px;
  }
  .map-panel__detail .detail-v2 .ab-hero__content {
    max-width: none;
    padding: 22px 22px 50px;
  }
  .map-panel__detail .detail-v2 .ab-hero__name {
    font-size: 28px;
  }
  .map-panel__detail .detail-v2 .ab-closure {
    max-width: none;
    margin: 16px 16px 0;
  }
  .map-panel__detail .detail-v2 .detail-grid {
    display: block;
    max-width: none;
    padding: 0;
  }
  .map-panel__detail .detail-v2 .detail-main {
    padding: 6px 18px 44px;
  }
  .map-panel__detail .detail-v2 .detail-aside {
    position: static;
    margin-top: -28px;
    padding: 0 16px;
  }
  .map-panel__detail .detail-v2 .ab-closure + .detail-grid .detail-aside {
    margin-top: 16px;
  }
  .map-panel__detail .detail-v2 .ab-glance__num {
    font-size: 22px;
  }
  .map-panel__detail .photo-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .map-panel__group-head h3 {
    margin: 0;
    font: inherit;
  }
  .map-panel__row.is-current .map-panel__row-name {
    color: var(--amber-deep, #9c4a13);
  }
  .map-panel__row-current {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    margin-left: 6px;
    font-size: 11.5px;
    font-weight: 700;
    letter-spacing: 0.02em;
    color: var(--amber-deep, #9c4a13);
    vertical-align: 1px;
  }
  .map-panel__row-current svg {
    width: 12px;
    height: 12px;
  }

  /* ---- Collapsed: a tab on the left edge brings the list back ---- */
  .map-panel-tab {
    position: absolute;
    top: 50%;
    left: 0;
    z-index: 1000;
    transform: translateY(-50%);
    align-items: center;
    gap: 6px;
    min-height: 44px;
    padding: 10px 14px 10px 8px;
    border: 1px solid var(--ink-line, #e2d5bd);
    border-left: 0;
    border-radius: 0 14px 14px 0;
    background: rgba(251, 246, 234, 0.93);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    box-shadow: 6px 0 18px -8px rgba(74, 52, 28, 0.45);
    font-family: var(--font-body, system-ui, sans-serif);
    font-size: 13px;
    font-weight: 600;
    color: var(--ink, #2d2114);
    cursor: pointer;
    transition: padding-left 0.15s;
  }
  .map-panel-tab:hover {
    padding-left: 12px;
  }
  .map-panel-tab svg {
    flex: none;
  }

  /* ---- Hover ring on the map ---- */
  .map-panel-ring {
    pointer-events: none;
  }
  .map-panel-ring span {
    display: block;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 3px solid var(--amber-deep, #9c4a13);
    box-shadow:
      0 0 0 3px rgba(251, 246, 234, 0.9),
      0 8px 18px -8px rgba(74, 52, 28, 0.55);
    animation: map-panel-ring 0.8s ease-in-out infinite alternate;
  }
  @keyframes map-panel-ring {
    from {
      transform: scale(0.92);
    }
    to {
      transform: scale(1.06);
    }
  }

  @media (prefers-reduced-motion: reduce) {
    .map-panel__view--detail {
      animation: none;
    }
    .map-panel-ring span {
      animation: none;
    }
  }
}
