/* ==========================================================================
   得獎美食地圖（/awards?view=map）
   --------------------------------------------------------------------------
   版面：控制項與清單集中在同一側（.amap__rail），地圖獨佔另一側。
     ・桌機：左側地圖吃滿剩餘寬度，右側 344px 控制欄
             （篩選 → 開關 → 圖例 → 清單），兩欄同高，整塊高度吃視窗。
     ・手機：順序換成「地圖 → 控制欄」，先看到圖，再往下調條件。

   為什麼把控制項從地圖上方搬進側欄：
     原本三顆下拉、搜尋框、兩顆按鈕各佔一列，地圖被推到 y≈430；
     而且選項散在上下兩列、由左至右排，點一次要跨整個頁面。
     收成單欄之後，地圖上移約 150px，空出來的高度就還給地圖
     （桌機 460px → 視窗高減去表頭，最多 880px）。
   ========================================================================== */

.amap {
  --amap-gold: #b8891b;
  --amap-silver: #7d8792;
  --amap-bronze: #a06a44;
  --amap-plain: #0f6b5c;
  --amap-closed: #98a0a8;
  /* 地圖與控制欄共用同一個高度。兩邊各自算高度的話，
     面板（篩選＋圖例＋清單）會比 canvas 高，grid 再把外框拉齊，
     地圖下方就露出一條灰底。 */
  --amap-h: clamp(340px, 56vh, 500px);
  margin: 0 0 1.5rem;
}

.amap__layout {
  display: flex;
  flex-direction: column;
  gap: .6rem;
  min-width: 0;
}

.amap__rail {
  order: 2;
  display: flex;
  flex-direction: column;
  gap: .6rem;
  min-width: 0;
}

/* ---- 控制欄 --------------------------------------------------------- */
.amap__ctrl {
  display: flex;
  flex-direction: column;
  gap: .5rem;
  padding: .6rem .7rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.amap__count {
  margin: 0;
  font-size: .8rem;
  color: var(--ink-2);
}
.amap__count b { font-size: 1rem; color: var(--ink); }

.amap__nocoord {
  display: block;
  margin-top: .1rem;
  font-size: .72rem;
  color: var(--ink-3);
}

/* 搜尋框與「套用」同一列：控制欄只有 344px，按鈕獨立一列會白吃掉 36px，
   而清單就在下面，那 36px 剛好是一張卡片。 */
.amap__qrow {
  display: flex;
  gap: .35rem;
}
.amap__qrow .amap__select { flex: 1 1 auto; min-width: 0; width: auto; }
.amap__qrow .amap__apply { flex: 0 0 auto; padding: .34rem .55rem; font-size: .78rem; }

.amap__filters {
  display: flex;
  flex-direction: column;
  gap: .35rem;
}
.amap__select {
  font: inherit;
  font-size: .8rem;
  width: 100%;
  padding: .34rem .45rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: inherit;
}
.amap__apply {
  font: inherit;
  font-size: .82rem;
  font-weight: 700;
  padding: .42rem .6rem;
  border: 1px solid var(--brand);
  border-radius: var(--radius-sm);
  background: var(--brand);
  color: #fff;
  cursor: pointer;
}
.amap__apply:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
.amap__clear {
  font-size: .74rem;
  color: var(--ink-3);
  text-align: center;
  text-decoration: none;
}
.amap__clear:hover { color: var(--brand-dark); }

.amap__opts {
  display: flex;
  flex-wrap: wrap;
  gap: .3rem;
}

.amap__toggle {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  font-size: .76rem;
  padding: .26rem .5rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  cursor: pointer;
  user-select: none;
}
.amap__toggle:has(input:checked) {
  border-color: var(--brand);
  background: var(--brand-light);
  color: var(--brand-dark);
}
.amap__toggle input { accent-color: var(--brand); margin: 0; }

.amap__geo {
  font: inherit;
  font-size: .76rem;
  padding: .26rem .55rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: inherit;
  cursor: pointer;
}
.amap__geo:hover { border-color: var(--brand); color: var(--brand-dark); }
.amap__geo[disabled] { opacity: .5; cursor: default; }

/* ---- 圖例（收合，預設不展開，把高度留給清單）---------------------- */
.amap__legend-box {
  border-top: 1px solid var(--line-2);
  padding-top: .35rem;
}
.amap__legend-box > summary {
  display: flex;
  align-items: baseline;
  gap: .4rem;
  cursor: pointer;
  font-size: .72rem;
  color: var(--ink-3);
  list-style: none;
}
.amap__legend-box > summary::-webkit-details-marker { display: none; }
.amap__legend-box > summary::after {
  content: "▾";
  font-size: .6rem;
  margin-left: .15rem;
}
.amap__legend-box[open] > summary::after { content: "▴"; }
.amap__legend-box .amap__count {
  margin: 0 0 0 auto;
  font-size: .72rem;
}
.amap__legend-box .amap__count b { font-size: .8rem; }

.amap__legend {
  display: flex;
  flex-wrap: wrap;
  gap: .2rem .55rem;
  margin: 0;
  padding: .4rem 0 0;
  list-style: none;
  font-size: .7rem;
  color: var(--ink-3);
}
.amap__legend li { display: inline-flex; align-items: center; gap: .25rem; }
.amap__legend-note {
  margin: .35rem 0 0;
  font-size: .68rem;
  line-height: 1.6;
  color: var(--ink-3);
}
.amap__dot {
  width: .6rem;
  height: .6rem;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px rgba(20, 24, 29, .25);
}
.amap__dot--1 { background: var(--amap-gold); }
.amap__dot--2 { background: var(--amap-silver); }
.amap__dot--3 { background: var(--amap-bronze); }
.amap__dot--0 { background: var(--amap-plain); }
.amap__dot--closed { background: var(--amap-closed); }

/* ---- 地圖 ----------------------------------------------------------- */
.amap__mapwrap {
  order: 1;
  position: relative;
  height: var(--amap-h);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: #e8ecec;
}

.amap__canvas {
  height: 100%;
  width: 100%;
  z-index: 0;
}

/* Leaflet 的圖磚在深色底上會有白邊，配合站上的紙感 */
.amap__canvas .leaflet-container { background: #e8ecec; font: inherit; }

.amap__badge {
  position: absolute;
  top: .5rem;
  left: .5rem;
  z-index: 500;
  padding: .18rem .5rem;
  border-radius: 999px;
  background: rgba(20, 24, 29, .78);
  color: #fff;
  font-size: .7rem;
  line-height: 1.5;
  pointer-events: none;
}

.amap__hint {
  position: absolute;
  bottom: .5rem;
  left: .5rem;
  right: .5rem;
  z-index: 500;
  padding: .3rem .55rem;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, .92);
  border: 1px solid var(--line);
  font-size: .72rem;
  color: var(--ink-2);
  display: none;
}
.amap__hint.is-on { display: block; }

/* ---- 清單面板 ------------------------------------------------------- */
.amap__panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.amap__panel-head {
  padding: .45rem .7rem;
  border-bottom: 1px solid var(--line-2);
  font-size: .76rem;
  color: var(--ink-2);
  display: flex;
  align-items: center;
  gap: .5rem;
  justify-content: space-between;
}

.amap__cards {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  max-height: 58vh;
  overscroll-behavior: contain;
}

.amap__card {
  border-bottom: 1px solid var(--line-2);
}
.amap__card:last-child { border-bottom: 0; }

.amap__card-btn {
  display: block;
  width: 100%;
  text-align: left;
  font: inherit;
  background: none;
  border: 0;
  padding: .55rem .7rem;
  cursor: pointer;
  color: inherit;
}
.amap__card-btn:hover { background: var(--surface-2); }
.amap__card.is-active .amap__card-btn {
  background: var(--brand-light);
  box-shadow: inset 3px 0 0 var(--brand);
}

.amap__card-top {
  display: flex;
  align-items: baseline;
  gap: .4rem;
  flex-wrap: wrap;
}

.amap__name {
  font-weight: 600;
  font-size: .88rem;
  line-height: 1.4;
}

.amap__rank {
  font-size: .68rem;
  padding: .05rem .35rem;
  border-radius: 4px;
  border: 1px solid currentColor;
  white-space: nowrap;
}
.amap__rank--1 { color: var(--amap-gold); }
.amap__rank--2 { color: var(--amap-silver); }
.amap__rank--3 { color: var(--amap-bronze); }
.amap__rank--0 { color: var(--amap-plain); }

.amap__meta {
  display: flex;
  flex-wrap: wrap;
  gap: .15rem .45rem;
  font-size: .72rem;
  color: var(--ink-3);
  margin-top: .1rem;
}

.amap__cross {
  font-size: .68rem;
  color: var(--accent);
  border: 1px solid currentColor;
  border-radius: 999px;
  padding: 0 .35rem;
  white-space: nowrap;
}

.amap__closed {
  font-size: .68rem;
  color: #fff;
  background: var(--amap-closed);
  border-radius: 4px;
  padding: 0 .3rem;
  white-space: nowrap;
}

.amap__dish { color: var(--ink-2); }

.amap__dist {
  font-variant-numeric: tabular-nums;
  color: var(--brand-dark);
}

.amap__more {
  margin: 0;
  padding: .55rem .7rem;
  border-top: 1px solid var(--line-2);
  text-align: center;
}
.amap__more button {
  font: inherit;
  font-size: .78rem;
  padding: .3rem 1rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  cursor: pointer;
}
.amap__more button:hover { border-color: var(--brand); color: var(--brand-dark); }

.amap__empty {
  padding: 1.5rem .8rem;
  text-align: center;
  font-size: .82rem;
  color: var(--ink-3);
}

/* ---- 地圖標記（divIcon）-------------------------------------------- */
.amap-pinwrap {
  position: relative;
  display: block;
  width: 16px;
  height: 16px;
}

.amap-pin {
  display: block;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .35);
  background: var(--amap-plain);
  transition: transform .12s ease;
}
.amap-pin--1 { background: var(--amap-gold); }
.amap-pin--2 { background: var(--amap-silver); }
.amap-pin--3 { background: var(--amap-bronze); }
.amap-pin--0 { background: var(--amap-plain); }
.amap-pin--closed {
  background: var(--amap-closed);
  border-style: dashed;
}
/* 跨榜（兩個以上競賽）：外圈，讓「這家不只上一個榜」在縮小的圖上也看得出來 */
.amap-pin--cross {
  box-shadow: 0 0 0 2px rgba(169, 95, 58, .55), 0 1px 3px rgba(0, 0, 0, .35);
}
.amap-pin.is-active {
  transform: scale(1.5);
  box-shadow: 0 0 0 3px rgba(15, 107, 92, .35), 0 1px 4px rgba(0, 0, 0, .4);
}

/* 店名標籤：只在街道層級（z≥16）出現，且由 JS 做過碰撞檢查，
   撞到別的標籤的那一家只留圓點，不會疊成一團字。 */
.amap-pinlabel {
  display: none;
  position: absolute;
  left: calc(100% + 4px);
  top: 50%;
  transform: translateY(-50%);
  max-width: 7.5em;
  padding: .05rem .3rem;
  border-radius: 3px;
  background: rgba(255, 255, 255, .95);
  border: 1px solid rgba(20, 24, 29, .14);
  box-shadow: 0 1px 2px rgba(0, 0, 0, .14);
  font-size: .68rem;
  line-height: 1.45;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
  z-index: 2;
}
.amap-pinwrap.is-labeled .amap-pinlabel { display: block; }
.amap-pinwrap.is-label-left .amap-pinlabel {
  left: auto;
  right: calc(100% + 4px);
  text-align: right;
}
/* 被點選的那一家一定顯示店名（即使因為碰撞而沒標） */
.amap-pin.is-active + .amap-pinlabel { display: block; z-index: 3; }

.amap-cluster {
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: rgba(15, 107, 92, .9);
  border: 2px solid #fff;
  color: #fff;
  font-size: .72rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .3);
}
.amap-cluster:hover { background: var(--brand-dark); }
.amap-cluster--sm { width: 30px; height: 30px; }
.amap-cluster--md { width: 38px; height: 38px; font-size: .78rem; }
.amap-cluster--lg { width: 48px; height: 48px; font-size: .84rem; }

/* ---- 無 JS／爬蟲看的靜態清單 --------------------------------------- */
.amap-static {
  margin: 1rem 0 0;
  border-top: 1px solid var(--line);
  padding-top: .6rem;
}
.amap-static > summary {
  cursor: pointer;
  font-size: .82rem;
  color: var(--ink-2);
  font-weight: 600;
}
.amap-static__body { margin-top: .6rem; }
.amap-static__group { margin: 0 0 .7rem; }
.amap-static__sub {
  font-size: .78rem;
  margin: 0 0 .2rem;
  color: var(--ink-2);
  font-weight: 600;
}
.amap-static__sub span {
  font-weight: 400;
  color: var(--ink-3);
  margin-left: .3rem;
}
.amap-static__list {
  margin: 0;
  font-size: .78rem;
  line-height: 1.75;
  color: var(--ink-2);
}
.amap-static__list span + span::before {
  content: "・";
  color: var(--ink-3);
}

/* ---- 桌機：左大地圖＋右控制欄，兩欄同高 --------------------------- */
@media (min-width: 900px) {
  /* 高度吃視窗：扣掉表頭、麵包屑、H1、檢視切換與導言約 250px，
     剩下的全部給地圖；上下限避免小螢幕擠成一條、大螢幕無限長高。 */
  .amap { --amap-h: clamp(560px, calc(100vh - 250px), 880px); }

  .amap__layout {
    display: grid;
    /* 地圖在左、控制欄在右。控制欄靠右的理由：這一頁的內容是「一張圖」，
       視覺重心留在左半邊（也就是內文欄的起點，與上方 H1、導言同一條基線），
       操作元件貼齊右邊界，滑鼠從右側工具區過來時不必橫越地圖。 */
    grid-template-columns: minmax(0, 1fr) 344px;
    /* 列高必須鎖成 1fr（minmax(0,…)）：只給容器的 height 時，
       列的 auto 會去滿足內容（40 張卡片 → 3359px），地圖就跟著長高。 */
    grid-template-rows: minmax(0, 1fr);
    gap: .75rem;
    height: var(--amap-h);
    align-items: stretch;
  }
  .amap__mapwrap {
    order: 0;
    grid-area: 1 / 1;
    height: 100%;
  }
  .amap__rail {
    order: 0;
    grid-area: 1 / 2;
    height: 100%;
  }
  .amap__ctrl { flex: 0 0 auto; }
  .amap__panel { flex: 1 1 auto; min-height: 0; }
  .amap__cards { flex: 1 1 auto; min-height: 0; max-height: none; }
}

/* 地圖模式不吃側欄寬度：這頁的主角是圖，右側再掛一排「熱門縣市」只會壓縮它 */
.page-awards-map .list-layout { display: block; }
.page-awards-map .list-main { max-width: none; }

/* ---- 窄螢幕（桌機但不到 900）與手機 -------------------------------- */
@media (max-width: 899px) {
  /* 平板：控制欄在地圖下方，寬度夠，攤成兩欄不要拉成一長條 */
  .amap__filters {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: .35rem;
  }
  .amap__qrow { grid-column: 1 / -1; }
  .amap__clear { grid-column: 1 / -1; }
}

@media (max-width: 620px) {
  .amap__ctrl { padding: .55rem .6rem; gap: .45rem; }
  .amap__filters { gap: .3rem; }
  .amap__select { font-size: .78rem; padding: .3rem .4rem; }
  .amap__count { font-size: .76rem; }
  .amap__count b { font-size: .92rem; }
  .amap__toggle, .amap__geo { font-size: .72rem; padding: .22rem .45rem; }
  .amap__legend { font-size: .66rem; }
  .amap__cards { max-height: 56vh; }
}
