/* ================================================================
   map.css — 測速照相機地圖視覺化專屬樣式
   繼承自 index.css 的 Design System tokens
   ================================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800;900&family=Noto+Sans+TC:wght@400;500;700;900&display=swap');

/* ── 地圖頁面基礎佈局 ──────────────────────────────────────────── */

.map-page {
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-primary);
}

/* ── 頂部導覽列（精簡版） ──────────────────────────────────────── */

.map-navbar {
  position: relative;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.5rem;
  background: rgba(10, 10, 26, 0.9);
  backdrop-filter: blur(20px) saturate(1.5);
  -webkit-backdrop-filter: blur(20px) saturate(1.5);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.map-navbar-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  text-decoration: none;
  color: var(--text-primary);
  font-weight: 800;
  font-size: 1rem;
  transition: opacity 150ms;
}
.map-navbar-brand:hover { opacity: 0.8; color: var(--text-primary); }

.map-navbar-brand .logo-icon-img {
  width: 28px;
  height: 28px;
  border-radius: 6px;
}

.map-navbar-center {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.map-navbar-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--accent-light);
  background: rgba(245, 158, 11, 0.12);
  border: 1px solid rgba(245, 158, 11, 0.25);
  padding: 0.25rem 0.75rem;
  border-radius: 9999px;
}

.map-navbar-badge .badge-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse-dot 2s ease-in-out infinite;
}
@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.6; transform: scale(0.8); }
}

.map-navbar-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.map-navbar-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-secondary);
  background: none;
  border: 1px solid var(--border);
  padding: 0.375rem 0.875rem;
  border-radius: 9999px;
  cursor: pointer;
  text-decoration: none;
  transition: all 150ms var(--ease-out);
}
.map-navbar-btn:hover {
  color: var(--text-primary);
  border-color: rgba(255, 255, 255, 0.15);
  background: rgba(255, 255, 255, 0.05);
}

/* ── 地圖容器 ─────────────────────────────────────────────────── */

.map-wrapper {
  position: relative;
  flex: 1;
  overflow: hidden;
}

#map-canvas {
  width: 100%;
  height: 100%;
}

/* ── 共用面板樣式（Glassmorphism） ────────────────────────────── */

.map-panel {
  position: absolute;
  background: rgba(15, 15, 35, 0.82);
  backdrop-filter: blur(20px) saturate(1.4);
  -webkit-backdrop-filter: blur(20px) saturate(1.4);
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 1rem;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(255,255,255,0.03);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 0.8125rem;
  min-width: 190px;
  overflow: hidden;
  transition: box-shadow 200ms;
}
.map-panel:hover {
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.7), 0 0 0 1px rgba(255,255,255,0.05);
}

.map-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem 0.5rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.map-panel-title {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.map-panel-body {
  padding: 0.75rem 1rem;
}

/* ── 📊 統計面板（左上） ──────────────────────────────────────── */

#panel-stats {
  top: 1rem;
  left: 1rem;
  min-width: 200px;
}

.stat-grid {
  display: grid;
  gap: 0.35rem;
}

.stat-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.stat-label-text {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--text-secondary);
}

.stat-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.stat-dot--total      { background: var(--text-muted); }
.stat-dot--highway    { background: #60a5fa; }
.stat-dot--expressway { background: #34d399; }
.stat-dot--local      { background: #f59e0b; }
.stat-dot--anomaly    { background: #f87171; }
.stat-dot--interval   { background: #a78bfa; }
.stat-dot--bidir      { background: #67e8f9; }

.stat-value {
  font-weight: 700;
  font-size: 0.875rem;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

.stat-divider-line {
  height: 1px;
  background: rgba(255,255,255,0.05);
  margin: 0.35rem 0;
}

/* ── 🔍 篩選器（左下） ──────────────────────────────────────── */

#panel-filter {
  bottom: 1rem;
  left: 1rem;
  min-width: 180px;
}

.filter-list {
  display: grid;
  gap: 0.3rem;
}

.filter-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  padding: 0.2rem 0;
  transition: opacity 150ms;
}
.filter-item:hover { opacity: 0.8; }

.filter-item input[type="checkbox"] {
  width: 14px;
  height: 14px;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}

.filter-item label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 0.8125rem;
  user-select: none;
}

/* ── 📋 圖例（右下） ──────────────────────────────────────────── */

#panel-legend {
  bottom: 1rem;
  right: 1rem;
  min-width: 170px;
}

.legend-list {
  display: grid;
  gap: 0.35rem;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8125rem;
  color: var(--text-secondary);
}

.legend-swatch {
  width: 28px;
  height: 12px;
  border-radius: 3px;
  flex-shrink: 0;
  border: 1px solid rgba(255,255,255,0.15);
}
.swatch-highway    { background: rgba(96, 165, 250, 0.5); border-color: #60a5fa; }
.swatch-expressway { background: rgba(52, 211, 153, 0.5); border-color: #34d399; }
.swatch-local      { background: rgba(245,158, 11, 0.5); border-color: #f59e0b; }
.swatch-no-azimuth { background: rgba(106,106,130, 0.4); border-color: #6a6a82; }
.swatch-collision  { background: rgba(248,113,113, 0.6); border-color: #f87171; }

.legend-icon {
  width: 28px;
  text-align: center;
  font-size: 0.875rem;
  flex-shrink: 0;
}

/* ── 🚗 虛擬測試車面板（右側） ──────────────────────────────────── */

#panel-simulator {
  top: 1rem;
  right: 1rem;
  min-width: 240px;
  max-width: 280px;
}

.sim-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: center;
  padding: 0.5rem;
  border: 1px dashed rgba(255,255,255,0.1);
  border-radius: 0.5rem;
  margin-bottom: 0.75rem;
}

.sim-control {
  margin-bottom: 0.75rem;
}

.sim-control-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 0.3rem;
}

.sim-control-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.sim-control-value {
  font-size: 0.8125rem;
  font-weight: 700;
  color: var(--accent-light);
  font-variant-numeric: tabular-nums;
}

.sim-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 9999px;
  background: rgba(255,255,255,0.1);
  outline: none;
  cursor: pointer;
  transition: background 150ms;
}
.sim-slider:hover { background: rgba(255,255,255,0.15); }
.sim-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-light));
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0,0,0,0.4);
  transition: transform 150ms var(--ease-spring);
}
.sim-slider::-webkit-slider-thumb:hover { transform: scale(1.2); }
.sim-slider:disabled { opacity: 0.4; cursor: not-allowed; }

.sim-toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.4rem 0;
}

.sim-toggle-label {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.sim-toggle {
  width: 36px;
  height: 20px;
  -webkit-appearance: none;
  appearance: none;
  background: rgba(255,255,255,0.1);
  border-radius: 10px;
  cursor: pointer;
  position: relative;
  transition: background 200ms;
}
.sim-toggle::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  background: #fff;
  border-radius: 50%;
  transition: transform 200ms var(--ease-spring);
}
.sim-toggle:checked {
  background: var(--accent);
}
.sim-toggle:checked::after {
  transform: translateX(16px);
}

.sim-divider {
  height: 1px;
  background: rgba(255,255,255,0.06);
  margin: 0.75rem 0;
}

.sim-collision-header {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

#sim-collision-list {
  max-height: 200px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.1) transparent;
}

.sim-no-hit {
  font-size: 0.8125rem;
  color: var(--text-muted);
  text-align: center;
  padding: 0.75rem 0;
}

.sim-hit-item {
  display: flex;
  gap: 0.5rem;
  padding: 0.5rem;
  border-radius: 0.5rem;
  background: rgba(248, 113, 113, 0.08);
  border: 1px solid rgba(248, 113, 113, 0.2);
  margin-bottom: 0.35rem;
  animation: slide-in 200ms var(--ease-out);
}
@keyframes slide-in {
  from { opacity: 0; transform: translateX(8px); }
  to   { opacity: 1; transform: translateX(0); }
}

.sim-hit-icon { flex-shrink: 0; font-size: 1rem; }

.sim-hit-body { flex: 1; min-width: 0; }

.sim-hit-addr {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sim-hit-detail {
  font-size: 0.6875rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
}

.sim-remove-btn {
  width: 100%;
  margin-top: 0.75rem;
  padding: 0.5rem;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-muted);
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  cursor: pointer;
  transition: all 150ms;
  text-align: center;
}
.sim-remove-btn:hover {
  color: var(--danger);
  border-color: rgba(248,113,113,0.4);
  background: rgba(248,113,113,0.06);
}

/* ── Loading Overlay ──────────────────────────────────────────── */

#map-loading {
  position: absolute;
  inset: 0;
  z-index: 500;
  background: rgba(10, 10, 26, 0.92);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 400ms;
}

#map-loading.hidden {
  opacity: 0;
  pointer-events: none;
}

.map-loading-content {
  text-align: center;
}

.map-loading-spinner {
  width: 48px;
  height: 48px;
  border: 3px solid rgba(245, 158, 11, 0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 800ms linear infinite;
  margin: 0 auto 1rem;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

#map-loading-text {
  font-size: 0.9375rem;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
}

.map-loading-sub {
  font-size: 0.8125rem;
  color: var(--text-muted);
}

/* ── Google Maps InfoWindow 自訂樣式 ─────────────────────────── */

/* 覆寫 Google 預設樣式 */
.gm-style-iw-d { overflow: hidden !important; }
.gm-style-iw   { padding: 0 !important; border-radius: 0.75rem !important; }
.gm-style-iw-c {
  background: rgba(15, 15, 35, 0.95) !important;
  border: 1px solid rgba(255,255,255,0.1) !important;
  border-radius: 0.75rem !important;
  box-shadow: 0 8px 32px rgba(0,0,0,0.6) !important;
  padding: 0 !important;
}
.gm-style-iw-t::after {
  background: rgba(15, 15, 35, 0.95) !important;
}
.gm-ui-hover-effect { display: none !important; }

.map-iw {
  min-width: 260px;
  max-width: 320px;
  padding: 1rem;
  font-family: var(--font-sans);
  color: var(--text-primary);
  font-size: 0.8125rem;
}

.map-iw-header {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.map-iw-icon { font-size: 1.25rem; flex-shrink: 0; }

.map-iw-title {
  font-weight: 700;
  font-size: 0.875rem;
  line-height: 1.4;
  color: var(--text-primary);
}

.map-iw-table {
  width: 100%;
  border-collapse: collapse;
}

.map-iw-table td {
  padding: 0.2rem 0;
  vertical-align: top;
}

.map-iw-table td:first-child {
  color: var(--text-muted);
  width: 60px;
  font-size: 0.75rem;
}

.map-iw-table td:last-child {
  color: var(--text-primary);
}

.map-iw-anomalies {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  margin-top: 0.75rem;
  padding-top: 0.5rem;
  border-top: 1px solid rgba(255,255,255,0.06);
}

.map-iw-badge {
  font-size: 0.6875rem;
  font-weight: 600;
  padding: 0.15rem 0.5rem;
  border-radius: 9999px;
}
.map-iw-badge--warn {
  background: rgba(248,113,113,0.15);
  color: var(--danger);
  border: 1px solid rgba(248,113,113,0.3);
}
.map-iw-badge--override {
  background: rgba(245,158,11,0.15);
  color: var(--accent-light);
  border: 1px solid rgba(245,158,11,0.3);
  animation: badge-flash 600ms ease;
}
@keyframes badge-flash {
  0%   { opacity: 0; transform: scale(0.9); }
  60%  { opacity: 1; transform: scale(1.05); }
  100% { opacity: 1; transform: scale(1); }
}

/* ── 相機編輯器 (WEB-002) ─────────────────────────────────────── */

.map-iw-edit-actions {
  display: flex;
  gap: 0.375rem;
  margin-top: 0.75rem;
  padding-top: 0.5rem;
  border-top: 1px solid rgba(255,255,255,0.06);
}

.map-iw-edit-btn,
.map-iw-revert-btn,
.map-iw-save-btn,
.map-iw-cancel-btn {
  font-size: 0.75rem;
  font-weight: 600;
  font-family: var(--font-sans);
  padding: 0.375rem 0.75rem;
  border-radius: 0.5rem;
  border: 1px solid;
  cursor: pointer;
  transition: all 150ms var(--ease-out);
  white-space: nowrap;
}

.map-iw-edit-btn {
  color: var(--accent-light);
  background: rgba(245,158,11,0.1);
  border-color: rgba(245,158,11,0.3);
  flex: 1;
}
.map-iw-edit-btn:hover {
  background: rgba(245,158,11,0.2);
  border-color: rgba(245,158,11,0.5);
}

.map-iw-revert-btn {
  color: var(--text-muted);
  background: rgba(255,255,255,0.04);
  border-color: var(--border);
}
.map-iw-revert-btn:hover {
  color: var(--danger);
  border-color: rgba(248,113,113,0.4);
  background: rgba(248,113,113,0.06);
}

.map-iw-save-btn {
  color: #0a0a1a;
  background: linear-gradient(135deg, var(--accent), var(--accent-light));
  border-color: transparent;
  flex: 1;
}
.map-iw-save-btn:hover {
  filter: brightness(1.1);
  transform: translateY(-1px);
}
.map-iw-save-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  filter: none;
  transform: none;
}

.map-iw-cancel-btn {
  color: var(--text-muted);
  background: rgba(255,255,255,0.04);
  border-color: var(--border);
}
.map-iw-cancel-btn:hover {
  color: var(--text-primary);
  border-color: rgba(255,255,255,0.15);
  background: rgba(255,255,255,0.08);
}

/* 編輯表單 */
.map-iw--edit {
  min-width: 280px;
  max-width: 340px;
  padding: 1rem;
  font-family: var(--font-sans);
  color: var(--text-primary);
  font-size: 0.8125rem;
}

.map-iw-edit-form {
  margin: 0.75rem 0;
}

.map-iw-edit-label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  display: block;
  margin-bottom: 0.5rem;
}

.map-iw-edit-slider-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.map-iw-edit-slider-row input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  flex: 1;
  height: 4px;
  border-radius: 9999px;
  background: rgba(255,255,255,0.1);
  outline: none;
  cursor: pointer;
}
.map-iw-edit-slider-row input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-light));
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0,0,0,0.4);
}
.map-iw-edit-slider-row input[type="range"]:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.map-iw-edit-slider-row input[type="number"] {
  width: 56px;
  padding: 0.3rem 0.4rem;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 0.375rem;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 0.8125rem;
  font-weight: 600;
  text-align: center;
  outline: none;
  transition: border-color 150ms;
}
.map-iw-edit-slider-row input[type="number"]:focus {
  border-color: var(--accent);
}
.map-iw-edit-slider-row input[type="number"]:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.map-iw-edit-unit {
  color: var(--text-muted);
  font-size: 0.75rem;
}

.map-iw-edit-null-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.75rem;
  color: var(--text-secondary);
  cursor: pointer;
  margin-bottom: 0.5rem;
}
.map-iw-edit-null-row input[type="checkbox"] {
  width: 14px;
  height: 14px;
  accent-color: var(--accent);
  cursor: pointer;
}

.map-iw-edit-error {
  font-size: 0.6875rem;
  color: var(--danger);
  padding: 0.25rem 0.5rem;
  background: rgba(248,113,113,0.1);
  border: 1px solid rgba(248,113,113,0.2);
  border-radius: 0.375rem;
  margin-bottom: 0.5rem;
}

.map-iw-edit-status {
  margin-top: 0.5rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: center;
  padding: 0.25rem;
}
.map-iw-edit-status--error {
  color: var(--danger);
}
.map-iw-edit-status--success {
  color: #34d399;
}

.muted { color: var(--text-muted); }

/* ── 響應式．手機版 ───────────────────────────────────────────── */

@media (max-width: 768px) {
  .map-navbar-center { display: none; }

  #panel-stats {
    top: 0.5rem;
    left: 0.5rem;
    min-width: 160px;
    font-size: 0.75rem;
  }

  #panel-filter {
    display: none; /* 手機版隱藏，空間有限 */
  }

  #panel-legend {
    bottom: 0.5rem;
    right: 0.5rem;
    min-width: 150px;
    font-size: 0.75rem;
  }

  #panel-simulator {
    top: auto;
    bottom: 0.5rem;
    right: 0.5rem;
    left: 0.5rem;
    max-width: none;
    min-width: 0;
  }
}

@media (max-width: 480px) {
  #panel-stats,
  #panel-legend { display: none; }

  .map-navbar { padding: 0.5rem 1rem; }
}
