* { box-sizing: border-box; }
html, body {
  width: 100%; height: 100%; margin: 0; padding: 0; overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: #0f172a;
  font-size: 16px;
  color: #334155;
}

/* 頂部橘色標題條 */
.top-header-bar {
  position: absolute;
  top: 0;
  left: 0;
  width: 100vw;
  height: 48px;
  background: #F37021;
  z-index: 1001;
  display: flex;
  align-items: center;
  padding: 0 20px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}
.top-header-bar h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 800;
  color: #ffffff;
  letter-spacing: 0.5px;
}

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

/* 左側控制面板與選里區 */
.switch-panel {
  position: absolute; top: 64px; left: 16px; z-index: 1000;
  display: flex; flex-direction: column; gap: 10px; pointer-events: auto;
  max-height: calc(100vh - 120px); overflow-y: auto; padding-right: 4px;
}
.switch-panel::-webkit-scrollbar { width: 4px; }
.switch-panel::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }

/* 選取卡片與下拉選單 */
.selector-card {
  background: rgba(255, 255, 255, 0.98);
  border: 1.5px solid #F37021;
  padding: 12px 16px; border-radius: 12px;
  box-shadow: 4px 4px 0px rgba(243, 112, 33, 0.4);
  width: 320px; display: flex; flex-direction: column; gap: 8px;
}
.selector-card select {
  width: 100%; padding: 8px 10px; border-radius: 8px;
  border: 1.5px solid #F37021; background: #ffffff;
  color: #0f172a; font-size: 13px; font-weight: 600; outline: none; cursor: pointer;
  box-shadow: 2px 2px 0px rgba(243, 112, 33, 0.35);
  transition: all 0.15s ease;
}
.selector-card select:focus {
  border-color: #F37021;
  box-shadow: 3px 3px 0px rgba(243, 112, 33, 0.6);
}

/* 各里得票細節面板 */
.info-panel {
  position: relative;
  padding: 14px 16px; background: rgba(255, 255, 255, 0.98);
  box-shadow: 4px 4px 0px rgba(243, 112, 33, 0.4);
  border-radius: 12px; width: 320px; line-height: 1.4;
  border: 1.5px solid #F37021;
  font-size: 13px; color: #334155;
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.info-panel-close-btn {
  position: absolute;
  top: 10px;
  right: 12px;
  background: #f1f5f9;
  border: 1px solid #cbd5e1;
  border-radius: 50%;
  width: 24px;
  height: 24px;
  font-size: 16px;
  font-weight: 700;
  line-height: 20px;
  text-align: center;
  color: #64748b;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: all 0.15s ease;
}
.info-panel-close-btn:hover {
  background: #fee2e2;
  color: #ef4444;
  border-color: #fca5a5;
}
.info-header {
  display: flex; justify-content: space-between; align-items: baseline;
  border-bottom: 2px solid #f1f5f9; padding-bottom: 6px; margin-bottom: 8px;
  padding-right: 20px;
}
.info-header h3 { margin: 0; font-size: 17px; font-weight: 800; color: #0f172a; }
.margin-badge { font-size: 11px; font-weight: 700; padding: 2px 6px; border-radius: 6px; }
.stat-row { font-size: 12px; margin: 4px 0; display: flex; justify-content: space-between; align-items: center; color: #334155; }
.stat-row strong { font-weight: 600; color: #64748b; }
.bar-box { height: 10px; display: flex; border-radius: 9999px; overflow: hidden; margin: 8px 0 4px; background: #e2e8f0; }
.bar-blue { background: #3b82f6; height: 100%; }
.bar-green { background: #22c55e; height: 100%; }
.bar-white { background: #94a3b8; height: 100%; }
.bar-yellow { background: #facc15; height: 100%; }

/* 整合到面板內的歷次圖表樣式 */
.integrated-chart-section {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed #cbd5e1;
}
.chart-section-title {
  font-weight: 800; font-size: 12px; color: #0f172a; margin-bottom: 6px;
}
.chart-container {
  display: flex; justify-content: space-between; align-items: flex-end;
  height: 180px; padding-top: 10px; border-bottom: 1px solid #e2e8f0; gap: 6px;
}
.chart-col {
  flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; justify-content: flex-end;
}
.stacked-bar {
  width: 32px; display: flex; flex-direction: column; border-radius: 4px; overflow: hidden; background: #e2e8f0;
}
.chart-label {
  font-size: 11px; color: #475569; margin-top: 4px; text-align: center; white-space: nowrap; font-weight: 600;
}
.chart-legend-mini {
  display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; font-size: 11px; color: #475569; justify-content: center;
}
.mini-dot { width: 9px; height: 9px; border-radius: 2px; display: inline-block; margin-right: 3px; }

/* 跟隨游標的浮動 Tooltip 樣式 (極簡顯示里名) */
.custom-cursor-tooltip {
  background: rgba(15, 23, 42, 0.92) !important;
  color: #ffffff !important;
  border: 1px solid #F37021 !important;
  border-radius: 8px !important;
  padding: 5px 10px !important;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25) !important;
  font-family: inherit !important;
}
.custom-cursor-tooltip::before {
  border-top-color: rgba(15, 23, 42, 0.92) !important;
}
.hover-tip-box {
  line-height: 1.2;
  text-align: center;
  font-size: 12px;
}

/* 頂部即時統計看板 */
.top-summary {
  position: absolute; top: 64px; left: 352px; z-index: 999;
  background: rgba(255, 255, 255, 0.98);
  padding: 10px 18px; border-radius: 12px;
  border: 1.5px solid #F37021;
  box-shadow: 4px 4px 0px rgba(243, 112, 33, 0.4);
  display: flex; align-items: center; gap: 12px;
}
.stat-pill {
  display: inline-flex; align-items: center; padding: 4px 12px; border-radius: 9999px; font-size: 12px; font-weight: 700;
}
.pill-blue { background: #eff6ff; color: #1d4ed8; border: 1px solid #bfdbfe; }
.pill-green { background: #f0fdf4; color: #15803d; border: 1px solid #bbf7d0; }
.pill-neutral { background: #f8fafc; color: #475569; border: 1px solid #e2e8f0; }

/* 圖例視窗 (桌面版：左右雙欄；手機版：上下單欄) */
.legend {
  position: absolute; top: 64px; right: 16px; bottom: auto; z-index: 999;
  padding: 10px 14px; background: rgba(255, 255, 255, 0.98);
  box-shadow: 4px 4px 0px rgba(243, 112, 33, 0.4);
  border-radius: 12px; font-size: 13px; color: #1e293b;
  line-height: 1.4; border: 1.5px solid #F37021;
  width: 220px;
}
.legend-title { font-weight: 800; font-size: 13px; margin-bottom: 6px; color: #0f172a; text-align: center; }
.legend-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.legend-col-title { font-size: 12px; font-weight: 700; margin-bottom: 3px; padding-bottom: 2px; }
.legend-item { display: flex; align-items: center; margin: 2px 0; font-size: 12px; color: #334155; }
.legend-item i { width: 12px; height: 12px; margin-right: 5px; border-radius: 2px; display: inline-block; flex-shrink: 0; }

/* 底部宣告列：始終固定在畫面最下方，層級最高 */
.bottom-global-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100vw;
  z-index: 1003;
  padding: 5px 10px;
  background: rgba(15, 23, 42, 0.94);
  border-top: 1px solid rgba(243, 112, 33, 0.4);
  font-size: 12px;
  color: #cbd5e1;
  text-align: center;
  font-weight: 600;
  pointer-events: auto;
}
.bottom-global-footer span.link {
  color: #60a5fa;
  text-decoration: underline;
  cursor: pointer;
  margin-left: 2px;
}
.footer-source-short { display: none; }
.footer-source-full { display: inline; }

/* 免責聲明彈窗 */
.modal-overlay {
  display: none; position: fixed; top: 0; left: 0; width: 100vw; height: 100vh;
  background: rgba(15, 23, 42, 0.6); z-index: 2000; align-items: center; justify-content: center;
}
.modal-box {
  background: #ffffff; max-width: 620px; width: 90%; border-radius: 16px;
  border: 2px solid #F37021;
  padding: 24px 28px; box-shadow: 8px 8px 0px rgba(243, 112, 33, 0.45);
  font-size: 14px; color: #334155; line-height: 1.65; position: relative;
  max-height: 85vh; overflow-y: auto;
}
.modal-box h2 { margin: 0 0 12px 0; font-size: 19px; color: #0f172a; font-weight: 800; }
.modal-box hr { border: none; border-top: 1px solid #e2e8f0; margin: 12px 0; }
.modal-close {
  position: absolute; top: 18px; right: 20px; font-size: 22px; font-weight: 700;
  color: #94a3b8; cursor: pointer; border: none; background: transparent;
}
.modal-close:hover { color: #F37021; }

.leaflet-interactive { vector-effect: non-scaling-stroke; }

/* 手機版直式排版響應式設計 */
@media screen and (max-width: 768px) {
  html, body { overflow: auto; }
  .top-header-bar { height: 42px; padding: 0 12px; }
  .top-header-bar h1 { font-size: 14px; }
  #map { width: 100vw; height: 50vh; position: relative; top: 42px; }
  
  .top-summary {
    position: relative; top: 42px; left: auto; width: 100%;
    border-radius: 0; justify-content: center; flex-wrap: wrap; padding: 8px 12px; gap: 6px;
  }

  .switch-panel {
    position: relative; top: 42px; left: auto; width: 100%;
    padding: 12px; background: #0f172a; gap: 10px; max-height: none;
    padding-bottom: 40px;
  }
  .selector-card { width: 100% !important; }

  /* 需求二：浮動框下調 10% (原 40% 改為 30%) */
  .info-panel {
    position: fixed !important;
    bottom: calc(40% + 30px) !important;
    left: 12px !important;
    right: 12px !important;
    width: auto !important;
    max-height: 48vh !important;
    overflow-y: auto !important;
    z-index: 1002 !important;
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.5), 3px 3px 0px rgba(243, 112, 33, 0.7) !important;
  }

  /* 需求一：右上角 Legend 改為上下單欄排列 (綠在上、藍在下)，大幅縮小寬度不遮地圖 */
  .legend {
    transform: scale(0.85);
    transform-origin: top right;
    top: 136px !important;
    right: 8px !important;
    bottom: auto !important;
    padding: 6px 8px !important;
    letter-spacing: -0.2px !important;
    border-radius: 8px !important;
    box-shadow: 2px 2px 0px rgba(243, 112, 33, 0.4) !important;
    width: 108px !important;
  }
  .legend-title { font-size: 11px !important; margin-bottom: 4px !important; }
  .legend-grid {
    display: flex !important;
    flex-direction: column !important;
    gap: 6px !important;
  }
  .legend-col-title { font-size: 11px !important; margin-bottom: 2px !important; }
  .legend-item { margin: 1px 0 !important; font-size: 10px !important; }
  .legend-item i { width: 9px !important; height: 9px !important; margin-right: 4px !important; }

  /* 需求三：手機版最下方保持單行、縮減字樣 */
  .footer-source-full { display: none !important; }
  .footer-source-short { display: inline !important; }
  .bottom-global-footer {
    position: fixed !important;
    bottom: 0 !important;
    font-size: 11px !important;
    padding: 5px 6px !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
  }
}