/* Poli 車輛廣播監控 - 專業級跨平台 PWA 設計系統 (responsive-pwa-ui 規範) */
/* 包含：開箱預設白天亮色、夜晚暗色主題、字級動態縮放、電腦版導航右置、無 Emoji 原則 */

/* ================= 1. 設計變數 (Tokens) ================= */
:root,
[data-theme="light"] {
  /* 物理安全區動態避讓變數 */
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);

  /* 尺寸變數 */
  --nav-height: 48px;
  /* 手機底部導航列高度縮小為 48px */
  --nav-rail-width: 76px;
  --top-height: 48px;
  --radius-lg: 12px;
  --radius-md: 8px;
  --radius-sm: 4px;

  /* 字體縮放變數（預設標準 1.0x） */
  --font-scale: 1;

  /* 預設：白天亮色模式 (Default Light Mode) */
  --bg-main: #f8fafc;
  --bg-surface: #ffffff;
  --bg-surface-hover: #f1f5f9;
  --border-subtle: #e2e8f0;
  --border-focus: #0284c7;

  --accent-primary: #0284c7;
  --accent-cyan: #0284c7;
  --accent-success: #16a34a;
  --accent-warning: #d97706;
  --accent-danger: #dc2626;

  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;

  --card-shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.04);
}

/* 夜晚暗色模式覆寫 (Dark Mode) */
[data-theme="dark"] {
  --bg-main: #0a0f1d;
  --bg-surface: #121a2c;
  --bg-surface-hover: #1c2742;
  --border-subtle: rgba(255, 255, 255, 0.09);
  --border-focus: #00f2fe;

  --accent-primary: #38bdf8;
  --accent-cyan: #00f2fe;
  --accent-success: #10b981;
  --accent-warning: #f59e0b;
  --accent-danger: #ef4444;

  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  --card-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
}

/* 字級動態縮放層級 */
[data-font-size="normal"] {
  --font-scale: 1;
}

[data-font-size="medium"] {
  --font-scale: 1.125;
}

[data-font-size="large"] {
  --font-scale: 1.25;
}

/* ================= 2. 全域重置與基礎樣式 ================= */
*,
*::before,
*::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

/* 明暗模式主題主色彩顯式綁定 (徹底杜絕任何情況下 body 呈現白底) */
html[data-theme="dark"],
html[data-theme="dark"] body,
body[data-theme="dark"],
[data-theme="dark"] body,
body.theme-dark {
  background-color: #0a0f1d !important;
  color: #f8fafc !important;
}

html[data-theme="light"],
html[data-theme="light"] body,
body[data-theme="light"],
[data-theme="light"] body,
body.theme-light {
  background-color: #f8fafc !important;
  color: #0f172a !important;
}

html {
  font-size: calc(16px * var(--font-scale));
  background-color: var(--bg-main);
}

html,
body {
  overscroll-behavior-y: contain;
}

body {
  margin: 0;
  padding: 0;
  width: 100%;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding-bottom: 0;
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
  background-color: var(--bg-main);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, sans-serif;
  user-select: none;
  -webkit-user-select: none;
  transition: background-color 0.2s ease, color 0.2s ease;
}

/* 外層 App 容器 (完全比照 1150911 Evidence log，支援 iPhone 滿版與多端自適應) */
#app-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  width: 100%;
  min-height: 100vh;
  background-color: var(--bg-main);
  transition: background-color 0.2s ease;
}

/* 頂部導航與狀態列 (固定置頂，自動避讓動態島與瀏海) */
.top-bar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;

  /* 滿版安全避讓：直接依賴 env(safe-area-inset-top)。在 iPhone PWA 獨立全螢幕下自動貼頂避讓動態島；在 Safari 瀏覽器與電腦端為 0px 自然貼頂，絕不產生 52px 虛擬空白 */
  padding-top: calc(env(safe-area-inset-top, 0px) + 8px);
  padding-bottom: 8px;
  padding-left: max(12px, env(safe-area-inset-left, 0px));
  padding-right: max(12px, env(safe-area-inset-right, 0px));
  min-height: calc(48px + env(safe-area-inset-top, 0px));
  box-sizing: border-box;

  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
  transition: background-color 0.2s ease, border-color 0.2s ease;

  /* 毛玻璃效果 */
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

/* iPhone 專屬動態島 (Dynamic Island) 與橫向避讓 */
@supports (-webkit-touch-callout: none) {
  /* 手機橫向旋轉時 (Landscape)，動態島位於左右兩側，頂部釋放空間 */
  @media (orientation: landscape) and (max-height: 500px) {
    .top-bar {
      padding-top: max(env(safe-area-inset-top, 0px), 6px) !important;
      padding-bottom: 6px !important;
      min-height: auto !important;
    }
  }
}

.brand-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: 0.5px;
}

.brand-icon-box {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent-primary);
}

.brand-mark {
  color: var(--accent-primary);
}

.brand-sub {
  color: var(--text-secondary);
  font-weight: 500;
  font-size: 0.82rem;
  letter-spacing: 0.5px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* 頂部快速主題切換按鈕 */
.top-theme-btn {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface-hover);
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
  transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}

.top-theme-btn:active {
  transform: scale(0.92);
}

.top-theme-btn .theme-sun {
  display: none;
}
.top-theme-btn .theme-moon {
  display: block;
}

[data-theme="dark"] .top-theme-btn .theme-sun {
  display: block;
  color: #f59e0b;
}
[data-theme="dark"] .top-theme-btn .theme-moon {
  display: none;
}

.live-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--accent-success);
  background: rgba(22, 163, 74, 0.1);
  border: 1px solid rgba(22, 163, 74, 0.25);
  padding: 3px 8px;
  border-radius: 9999px;
  letter-spacing: 0.5px;
}

.live-dot {
  width: 6px;
  height: 6px;
  background-color: var(--accent-success);
  border-radius: 50%;
  animation: pulse-dot 2s infinite ease-in-out;
}

@keyframes pulse-dot {
  0% {
    transform: scale(0.9);
    opacity: 0.7;
  }

  50% {
    transform: scale(1.3);
    opacity: 1;
    box-shadow: 0 0 6px var(--accent-success);
  }

  100% {
    transform: scale(0.9);
    opacity: 0.7;
  }
}

/* 主要內容容器 (完全比照 1150911 Evidence log：手機由 body 自然滾動杜絕 fixed 跑版與底部未滿版，電腦版內部捲動) */
.main-content {
  flex: 1;
  width: 100%;
  box-sizing: border-box;
  padding: 12px 10px calc(88px + env(safe-area-inset-bottom, 0px)) 10px;
}

@media (min-width: 768px) {
  .main-content {
    flex: 1 1 0%;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px 24px 36px 24px;
  }
}

/* 分頁視圖淡入動效 */
.view-section {
  display: none;
}

.view-section.active {
  display: block;
  animation: viewFadeIn 0.2s ease-out forwards;
}

@keyframes viewFadeIn {
  from {
    opacity: 0;
    transform: translateY(4px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.section-title {
  font-size: 1.25rem;
  font-weight: 700;
  margin: 0;
}

.stats-counter {
  font-size: 0.85rem;
  color: var(--text-secondary);
  font-weight: 600;
}

/* ================= 3. 響應式網格 (手機滿版單欄，電腦多欄自適應) ================= */
.card-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 8px;
  width: 100%;
}

@media (min-width: 768px) {
  .card-grid {
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 16px;
  }
}

@media (min-width: 1400px) {
  .card-grid {
    grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
    gap: 20px;
  }
}

/* 卡片元件設計 (手機端滿版高密度，大螢幕寬敞大氣) */
.data-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 11px 12px;
  box-shadow: var(--card-shadow);
  transition: transform 0.15s ease, background-color 0.15s ease, border-color 0.15s ease;
  cursor: pointer;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  box-sizing: border-box;
}

@media (min-width: 768px) {
  .data-card {
    border-radius: var(--radius-lg);
    padding: 14px 16px;
  }
}

.data-card:hover {
  background-color: var(--bg-surface-hover);
  border-color: var(--border-focus);
  transform: translateY(-2px);
}

.data-card:active {
  transform: scale(0.99);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.card-title {
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: 0.5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.status-badge {
  font-size: 0.72rem;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.status-badge.normal {
  background: rgba(22, 163, 74, 0.12);
  color: var(--accent-success);
  border: 1px solid rgba(22, 163, 74, 0.3);
}

.status-badge.alert {
  background: rgba(220, 38, 38, 0.12);
  color: var(--accent-danger);
  border: 1px solid rgba(220, 38, 38, 0.3);
}

.card-body {
  display: flex;
  gap: 12px;
  align-items: center;
}

.card-thumb-box {
  width: 72px;
  height: 52px;
  background: rgba(0, 0, 0, 0.06);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border: 1px solid var(--border-subtle);
  overflow: hidden;
}

[data-theme="dark"] .card-thumb-box {
  background: rgba(0, 0, 0, 0.4);
}

.card-thumb-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.card-details {
  flex: 1;
  min-width: 0;
}

.detail-line {
  margin: 2px 0;
  font-size: 0.85rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.time-text {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* 空狀態提示 */
.empty-state {
  text-align: center;
  padding: 48px 16px;
  color: var(--text-muted);
}

.empty-icon-wrap {
  width: 48px;
  height: 48px;
  margin: 0 auto 12px auto;
  color: var(--text-muted);
  opacity: 0.6;
}

/* ================= 4. 車輛詳情與快照 (Detail View) ================= */
.detail-chips-bar {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 12px;
  margin-bottom: 16px;
  -webkit-overflow-scrolling: touch;
}

.vehicle-chip {
  padding: 6px 14px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 9999px;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-secondary);
  white-space: nowrap;
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.vehicle-chip:hover {
  background: var(--bg-surface-hover);
}

.vehicle-chip.active {
  background: var(--accent-primary);
  border-color: var(--accent-primary);
  color: #ffffff;
}

.snapshot-card,
.report-card,
.history-card,
.settings-group {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 12px 10px;
  margin-bottom: 10px;
  box-shadow: var(--card-shadow);
  transition: background-color 0.2s ease, border-color 0.2s ease;
}

@media (min-width: 768px) {
  .snapshot-card,
  .report-card,
  .history-card,
  .settings-group {
    border-radius: var(--radius-lg);
    padding: 16px;
    margin-bottom: 16px;
  }
}

.card-sub-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.card-sub-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: 0.3px;
}

.snapshot-media-box {
  width: 100%;
  max-height: 320px;
  aspect-ratio: 16 / 9;
  background: var(--bg-surface-hover);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 10px;
  cursor: zoom-in;
}

[data-theme="dark"] .snapshot-media-box {
  background: #000000;
  border-color: rgba(255, 255, 255, 0.09);
}

.snapshot-img {
  width: 100%;
  max-height: 280px;
  object-fit: contain;
  display: block;
}

.snapshot-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.snapshot-info-label {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.snapshot-btn-group {
  display: flex;
  gap: 8px;
}

/* 沙盒 Iframe 容器 (嚴格限制 100% 寬度防撐爆，contain 徹底杜絕 WebKit 溢出) */
.iframe-container {
  width: 100% !important;
  max-width: 100% !important;
  height: 240px;
  border-radius: var(--radius-md);
  overflow: hidden !important;
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  box-sizing: border-box !important;
  contain: layout size paint !important;
  -webkit-overflow-scrolling: touch;
}

[data-theme="dark"] .iframe-container {
  background: #121a2c;
}

.report-iframe {
  width: 100% !important;
  max-width: 100% !important;
  height: 100% !important;
  border: none !important;
  display: block !important;
  box-sizing: border-box !important;
}

/* 歷史記錄時間軸清單 */
.history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
}

.history-item {
  background: var(--bg-surface-hover);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
}

.history-item-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

.history-item-time {
  font-size: 0.76rem;
  color: var(--accent-primary);
  font-weight: 600;
}

.history-item-tag {
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
}

.history-item-desc {
  font-size: 0.84rem;
  color: var(--text-secondary);
  line-height: 1.4;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ================= 5. 設定視圖與分段控制器 (Settings) ================= */
.group-title {
  font-size: 0.98rem;
  font-weight: 700;
  margin-top: 0;
  margin-bottom: 12px;
  color: var(--accent-primary);
  letter-spacing: 0.3px;
}

.group-desc {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-top: 0;
  margin-bottom: 14px;
  line-height: 1.4;
}

/* 分段式按鈕 (用於主題與字級切換) */
.segmented-control {
  display: flex;
  background: var(--bg-surface-hover);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 3px;
  gap: 4px;
  margin-bottom: 14px;
}

.segment-btn {
  flex: 1;
  padding: 8px 12px;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.segment-btn.active {
  background: var(--bg-surface);
  color: var(--accent-primary);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.form-item {
  margin-bottom: 14px;
}

.form-label {
  display: block;
  font-size: 0.82rem;
  color: var(--text-secondary);
  margin-bottom: 6px;
  font-weight: 500;
}

.form-input {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.88rem;
  outline: none;
  transition: border-color 0.15s ease;
}

.form-input:focus-visible {
  border-color: var(--border-focus);
}

.storage-info-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

/* 通知效果切換列 (Sound & Vibration toggles) */
.setting-toggle-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--border-subtle);
}

.setting-toggle-row:last-child {
  border-bottom: none;
  padding-bottom: 4px;
}

.setting-toggle-info {
  flex: 1;
  padding-right: 16px;
}

.setting-toggle-title {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 3px;
}

.setting-toggle-desc {
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.35;
}

/* 現代化滑動開關 Toggle Switch */
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 46px;
  height: 26px;
  flex-shrink: 0;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--bg-surface-hover);
  border: 1px solid var(--border-subtle);
  transition: 0.25s ease;
  border-radius: 26px;
}

.toggle-slider:before {
  position: absolute;
  content: "";
  height: 20px;
  width: 20px;
  left: 2px;
  bottom: 2px;
  background-color: #ffffff;
  transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.toggle-switch input:checked+.toggle-slider {
  background-color: var(--accent-primary);
  border-color: var(--accent-primary);
}

.toggle-switch input:checked+.toggle-slider:before {
  transform: translateX(20px);
}

.toggle-switch input:focus-visible+.toggle-slider {
  outline: 2px solid var(--border-focus);
}

/* ================= 6. 通用按鈕元件 (純向量與文字，無 Emoji) ================= */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: opacity 0.15s ease, transform 0.1s ease, background-color 0.15s ease;
}

.btn:active {
  transform: scale(0.97);
}

.btn-icon {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
}

.btn-primary {
  background: var(--accent-primary);
  color: #ffffff;
}

.btn-secondary {
  background: var(--bg-surface-hover);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
}

.btn-secondary:hover {
  background: var(--border-subtle);
}

.btn-action {
  background: #16a34a;
  color: #ffffff;
}

.btn-danger {
  background: rgba(220, 38, 38, 0.12);
  color: var(--accent-danger);
  border: 1px solid rgba(220, 38, 38, 0.3);
}

.btn-sm {
  padding: 4px 10px;
  font-size: 0.78rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
}

.btn-block {
  width: 100%;
}

/* ================= 7. 導航系統 (手機置底毛玻璃，電腦大於等於 768px 昇華為左側 Sidebar) ================= */

/* 手機端 (< 768px)：底部固定導航列 */
.sidebar-brand,
.sidebar-footer,
.nav-spacer {
  display: none !important;
}

/* ================= 導航列：手機版 (< 768px) 參考 1150911 Evidence log 規範 ================= */
.sidebar-theme-btn,
.sidebar-brand,
.sidebar-footer,
.nav-spacer {
  display: none !important;
}

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  display: flex;
  justify-content: space-around;
  align-items: center;
  background: rgba(248, 250, 252, 0.96);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--border-subtle);
  padding: 6px 12px calc(6px + env(safe-area-inset-bottom, 0px)) 12px;
  gap: 6px;
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.08);
  transition: background-color 0.2s ease;
}

[data-theme="dark"] .bottom-nav,
body.theme-dark .bottom-nav {
  background: rgba(18, 25, 41, 0.96);
  border-top-color: var(--border-subtle);
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.45);
}

.nav-btn-group {
  display: flex;
  width: 100%;
  justify-content: space-around;
  align-items: center;
  gap: 6px;
}

.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  gap: 2px;
  padding: 4px 2px;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
  -webkit-tap-highlight-color: transparent;
}

.nav-btn * {
  pointer-events: none;
}

/* 按壓回饋：縮放 + 半透明色 */
.nav-btn:active {
  transform: scale(0.9);
  opacity: 0.75;
}

/* 啟用中：主色文字 + 淡色背景高亮 */
.nav-btn.active {
  color: var(--accent-primary);
  background: rgba(2, 132, 199, 0.1);
}

[data-theme="dark"] .nav-btn.active,
body.theme-dark .nav-btn.active {
  background: rgba(56, 189, 248, 0.12);
}

.nav-btn.active .nav-icon {
  stroke: var(--accent-primary);
}

.nav-icon {
  width: 22px;
  height: 22px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
}

.nav-icon-wrapper {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.nav-badge {
  position: absolute;
  top: -4px;
  right: -8px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  background-color: var(--accent-danger, #ef4444);
  color: #ffffff;
  font-size: 0.65rem;
  font-weight: 800;
  line-height: 16px;
  border-radius: 999px;
  text-align: center;
  box-shadow: 0 0 6px rgba(239, 68, 68, 0.6);
  pointer-events: none;
}

.nav-text {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.3px;
  white-space: nowrap;
}


/* ================= 電腦端 (>= 768px)：參考 1150911 Evidence log 左側邊欄規範 ================= */
@media (min-width: 768px) {
  :root {
    --sidebar-width: 260px;
  }

  /* 隱藏手機版專屬元素 */
  .top-bar {
    display: none !important;
  }

  #btn-quick-theme {
    display: none !important;
  }

  /* 容器轉為雙欄水平佈局 */
  #app-container {
    flex-direction: row;
    height: 100vh;
    min-height: 100vh;
    max-height: 100vh;
    overflow: hidden;
  }

  /* 左側側邊欄 (緊鎖 100vh 視口高度，按鈕靠頂，設定靠底，永不溢出) */
  .bottom-nav {
    position: sticky;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    height: 100vh;
    max-height: 100vh;
    padding: 20px 16px;
    box-sizing: border-box;
    display: flex !important;
    flex-direction: column;
    justify-content: space-between;
    align-items: stretch;
    gap: 0;
    border-top: none;
    border-right: 1px solid var(--border-subtle);
    background: var(--bg-surface);
    box-shadow: 2px 0 12px rgba(0, 0, 0, 0.04);
    z-index: 90;
    order: -1; /* 確保位於 main-content 左側 */
  }

  [data-theme="dark"] .bottom-nav,
  body.theme-dark .bottom-nav {
    background: var(--bg-surface);
    box-shadow: 2px 0 16px rgba(0, 0, 0, 0.35);
  }

  /* Sidebar 頂部 Logo 品牌列 */
  .sidebar-brand {
    display: flex !important;
    align-items: center;
    gap: 12px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-subtle);
    margin-bottom: 12px;
    flex-shrink: 0;
  }

  .sidebar-brand-icon {
    width: 42px;
    height: 42px;
    border-radius: var(--radius-md);
    overflow: hidden;
    flex-shrink: 0;
    border: 1px solid var(--border-subtle);
  }

  .brand-logo-img {
    width: 42px;
    height: 42px;
    object-fit: cover;
    display: block;
  }

  .sidebar-brand-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
  }

  .sidebar-brand-title {
    font-size: 1.18rem;
    font-weight: 800;
    color: var(--text-primary);
    letter-spacing: 0.5px;
    line-height: 1.2;
  }

  .sidebar-brand-badge {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-muted);
    letter-spacing: 0.3px;
  }

  /* 導航按鈕群組容器 */
  .nav-btn-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 0;
    flex: 1;
    width: 100%;
    align-items: stretch;
    justify-content: flex-start;
    overflow-y: auto;
  }

  /* 導航按鈕膠囊樣式 (與 1150911 側邊欄一致) */
  .nav-btn {
    width: 100%;
    height: 42px;
    min-height: 42px;
    padding: 0 14px;
    margin: 0;
    flex: 0 0 auto;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
    gap: 12px;
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.92rem;
    font-weight: 600;
    transition: background-color 0.15s ease, color 0.15s ease;
  }

  .nav-btn:hover {
    background-color: var(--bg-surface-hover);
    color: var(--text-primary);
  }

  .nav-btn.active {
    background-color: rgba(14, 165, 233, 0.12);
    color: var(--accent-primary);
    font-weight: 700;
    border-color: rgba(14, 165, 233, 0.25);
  }

  .nav-btn .nav-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
  }

  .nav-btn .nav-text {
    font-size: 0.9rem;
    font-weight: 600;
  }

  .nav-btn .nav-icon-wrapper {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
  }

  .nav-btn .nav-badge {
    position: static;
    margin-left: auto;
    font-size: 0.72rem;
    min-width: 18px;
    height: 18px;
    line-height: 18px;
  }

  /* 彈性空間推底 (將設定按鈕推至底部) */
  .nav-spacer {
    display: block !important;
    flex: 1;
    min-height: 12px;
  }

  /* 設定按鈕靠底樣式 */
  .nav-btn-bottom {
    border-top: 1px solid var(--border-subtle);
    padding-top: 8px;
    margin-bottom: 2px;
  }

  /* Sidebar 底部區塊 */
  .sidebar-footer {
    display: flex !important;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding-top: 12px;
    border-top: 1px solid var(--border-subtle);
    margin-top: 8px;
    flex-shrink: 0;
  }

  .sidebar-live-badge {
    font-size: 0.72rem;
    padding: 4px 10px;
    flex-shrink: 0;
  }

  .sidebar-theme-btn {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    padding: 5px 12px;
    font-size: 0.78rem;
    font-weight: 600;
    background: var(--bg-surface-hover);
    color: var(--text-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    cursor: pointer;
    white-space: nowrap;
    transition: background-color 0.15s ease, color 0.15s ease;
  }

  .sidebar-theme-btn:hover {
    background: var(--border-subtle);
    color: var(--text-primary);
  }

  /* 主內容容器 (右側獨立捲動) */
  .main-content {
    flex: 1;
    min-width: 0;
    height: 100vh;
    max-height: 100vh;
    overflow-y: auto;
    padding: 24px 32px 32px 32px;
    margin: 0;
  }

  /* 電腦版總覽與車輛管理卡片網格 */
  .card-grid {
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 18px;
  }

  /* 電腦版設定區塊寬度限制，避免過度拉伸 */
  .settings-content-wrapper {
    max-width: 860px;
  }
}

/* ================= 電腦寬螢幕詳情工作台 (>= 992px) ================= */
@media (min-width: 992px) {
  .detail-dashboard-layout {
    display: grid;
    grid-template-columns: 460px 1fr;
    gap: 24px;
    align-items: start;
  }

  .detail-col-left {
    display: flex;
    flex-direction: column;
    gap: 16px;
  }

  .detail-col-right {
    display: flex;
    flex-direction: column;
    gap: 16px;
    min-width: 0;
  }

  .report-card .iframe-container {
    height: 380px !important;
  }
}

/* 手機與窄螢幕詳情佈局 (< 992px) */
@media (max-width: 991px) {
  .detail-dashboard-layout {
    display: flex;
    flex-direction: column;
    gap: 14px;
  }

  .detail-col-left,
  .detail-col-right {
    display: flex;
    flex-direction: column;
    gap: 14px;
  }
}

/* iOS PWA 指引卡片樣式 (無 Emoji) */
.ios-guide-box {
  background: rgba(2, 132, 199, 0.08);
  border: 1px solid rgba(2, 132, 199, 0.28);
  border-radius: var(--radius-lg);
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: var(--card-shadow);
}

[data-theme="dark"] .ios-guide-box {
  background: rgba(56, 189, 248, 0.1);
  border-color: rgba(56, 189, 248, 0.35);
}

.ios-guide-steps {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 10px;
}

.ios-step-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.45;
}

.ios-step-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent-primary);
  color: #ffffff;
  font-size: 0.75rem;
  font-weight: 700;
  flex-shrink: 0;
  margin-top: 1px;
}

/* ================= 8. 全螢幕模態 (Lightbox) 與提示訊息 (Toast) ================= */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 23, 42, 0.78);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 2000;
  justify-content: center;
  align-items: center;
  padding: 16px;
}

[data-theme="dark"] .modal-overlay {
  background: rgba(0, 0, 0, 0.94);
}

.modal-overlay.active {
  display: flex;
}

.modal-img {
  max-width: 100%;
  max-height: 88dvh;
  object-fit: contain;
  border-radius: var(--radius-md);
}

.modal-close-btn {
  position: absolute;
  top: max(calc(env(safe-area-inset-top, 0px) + 14px), 52px);
  right: max(calc(env(safe-area-inset-right, 0px) + 16px), 16px);
  background: rgba(255, 255, 255, 0.18);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.25);
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.84rem;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 0.5px;
  z-index: 2100;
}

.modal-close-btn:hover {
  background: rgba(255, 255, 255, 0.3);
}

#toast {
  position: fixed;
  top: max(calc(env(safe-area-inset-top, 0px) + 64px), 76px);
  left: 50%;
  transform: translateX(-50%) translateY(-20px);
  background: var(--bg-surface);
  color: var(--text-primary);
  padding: 9px 20px;
  border-radius: 9999px;
  font-size: 0.85rem;
  font-weight: 600;
  border: 1px solid var(--border-focus);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
  opacity: 0;
  pointer-events: none;
  transition: all 0.25s ease-out;
  z-index: 3000;
}

#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  pointer-events: auto;
  cursor: pointer;
}

#toast:active {
  transform: translateX(-50%) scale(0.97);
}


/* ================= 9. 車輛管理、容量提醒與地理位置擴充 ================= */

/* 手機容量佔用提醒警語卡片 (滿版自適應) */
.storage-notice-box {
  background: rgba(217, 119, 6, 0.08);
  border: 1px solid rgba(217, 119, 6, 0.28);
  border-radius: var(--radius-md);
  padding: 12px 10px;
  margin-bottom: 10px;
  box-shadow: var(--card-shadow);
  transition: background-color 0.2s ease, border-color 0.2s ease;
}

@media (min-width: 768px) {
  .storage-notice-box {
    border-radius: var(--radius-lg);
    padding: 14px 16px;
    margin-bottom: 16px;
  }
}

[data-theme="dark"] .storage-notice-box {
  background: rgba(245, 158, 11, 0.1);
  border-color: rgba(245, 158, 11, 0.35);
}

.notice-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.notice-title {
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--accent-warning);
  letter-spacing: 0.3px;
}

.notice-badge {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: var(--radius-sm);
  background: rgba(217, 119, 6, 0.15);
  color: var(--accent-warning);
  border: 1px solid rgba(217, 119, 6, 0.3);
}

.notice-desc {
  font-size: 0.82rem;
  color: var(--text-secondary);
  line-height: 1.5;
  margin: 0 0 10px 0;
}

.notice-stats-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 8px;
  border-top: 1px dashed rgba(217, 119, 6, 0.25);
  font-size: 0.82rem;
  color: var(--text-secondary);
}

.notice-stats-val {
  color: var(--accent-warning);
  font-weight: 700;
}

/* 車輛管理卡片 (滿版自適應) */
.manage-vehicle-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 12px 10px;
  margin-bottom: 8px;
  box-shadow: var(--card-shadow);
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

@media (min-width: 768px) {
  .manage-vehicle-card {
    border-radius: var(--radius-lg);
    padding: 14px 16px;
    margin-bottom: 12px;
  }
}

.manage-vehicle-card:hover {
  border-color: var(--border-focus);
}

.manage-card-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.manage-plate {
  font-size: 1.12rem;
  font-weight: 800;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--text-primary);
}

.manage-meta-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-bottom: 12px;
  background: var(--bg-surface-hover);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.manage-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* 總覽卡片與詳情頁座標與動作列 */
.card-location-row {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 0.8rem;
  min-width: 0;
}

.location-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--accent-primary);
  text-decoration: none;
  background: rgba(2, 132, 199, 0.08);
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(2, 132, 199, 0.25);
  cursor: pointer;
  transition: all 0.15s ease;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

[data-theme="dark"] .location-badge {
  background: rgba(56, 189, 248, 0.12);
  border-color: rgba(56, 189, 248, 0.3);
}

.location-badge:hover {
  background: var(--accent-primary);
  color: #ffffff;
}

.card-quick-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

/* 詳情頁車輛選擇器與 HTML 歷史軌跡清單 */
.detail-filter-box {
  margin-bottom: 14px;
}

.detail-filter-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

/* 軌跡卡片 (滿版自適應) */
.trajectory-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 12px 10px;
  margin-bottom: 10px;
  box-shadow: var(--card-shadow);
}

@media (min-width: 768px) {
  .trajectory-card {
    border-radius: var(--radius-lg);
    padding: 16px;
    margin-bottom: 16px;
  }
}

.trajectory-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
  max-height: 240px;
  overflow-y: auto;
}

.trajectory-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--bg-surface-hover);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  cursor: pointer;
  transition: all 0.15s ease;
  gap: 8px;
  flex-wrap: wrap;
}

.trajectory-item-info {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 170px;
}

.trajectory-item-title {
  font-weight: 600;
  color: var(--text-primary);
  word-break: break-all;
}

.trajectory-item-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.trajectory-item:hover {
  border-color: var(--accent-primary);
}

.trajectory-item.active {
  background: rgba(2, 132, 199, 0.1);
  border-color: var(--accent-primary);
  color: var(--accent-primary);
  font-weight: 700;
}

/* ================= 訊息中心 (View Messages) 專業排版樣式 ================= */
.msg-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.msg-filter-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
}

.msg-filter-btn {
  padding: 6px 14px;
  font-size: 0.8rem;
  font-weight: 700;
  border-radius: 999px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.msg-filter-btn.active {
  background: var(--accent-primary);
  color: #ffffff;
  border-color: var(--accent-primary);
}

.filter-count-badge {
  font-size: 0.7rem;
  background: rgba(255, 255, 255, 0.25);
  color: inherit;
  padding: 1px 6px;
  border-radius: 999px;
}

.msg-card-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.msg-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
  cursor: pointer;
  position: relative;
}

.msg-card:hover {
  border-color: var(--border-focus);
  box-shadow: var(--card-shadow);
}

.msg-card.unread {
  border-left: 4px solid var(--accent-primary);
  background: rgba(2, 132, 199, 0.03);
}

[data-theme="dark"] .msg-card.unread {
  background: rgba(56, 189, 248, 0.05);
  border-left-color: var(--accent-primary);
}

.msg-card.msg-card-highlight {
  animation: msgCardPop 1.8s ease-out;
}

@keyframes msgCardPop {
  0% {
    transform: translateY(-8px) scale(0.98);
    box-shadow: 0 0 16px rgba(2, 132, 199, 0.45);
    border-color: var(--accent-primary);
  }
  50% {
    box-shadow: 0 0 10px rgba(2, 132, 199, 0.25);
    border-color: var(--accent-primary);
  }
  100% {
    transform: translateY(0) scale(1);
    box-shadow: var(--card-shadow);
  }
}

.msg-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.msg-card-meta {
  display: flex;
  align-items: center;
  gap: 8px;
}

.msg-unread-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-primary);
  box-shadow: 0 0 6px var(--accent-primary);
  flex-shrink: 0;
}

.msg-vehicle-badge {
  font-family: monospace;
  font-weight: 800;
  font-size: 0.85rem;
  color: var(--accent-primary);
  background: rgba(2, 132, 199, 0.1);
  padding: 2px 8px;
  border-radius: var(--radius-sm);
}

[data-theme="dark"] .msg-vehicle-badge {
  background: rgba(56, 189, 248, 0.15);
}

.msg-type-tag {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--text-muted);
  border: 1px solid var(--border-subtle);
  padding: 1px 6px;
  border-radius: 4px;
}

.msg-time {
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.msg-card-body {
  font-size: 0.88rem;
  line-height: 1.5;
  color: var(--text-primary);
  word-break: break-word;
  white-space: pre-wrap;
}

.msg-card-footer,
.msg-card-actions,
.msg-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding-top: 8px;
  border-top: 1px dashed var(--border-subtle);
  margin-top: 4px;
}

.msg-note {
  font-size: 0.76rem;
  color: var(--text-secondary);
}

.msg-action-btn,
.msg-btn-action {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--bg-surface-hover);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  transition: all 0.15s ease;
  min-height: 32px;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}

.msg-action-btn:hover,
.msg-btn-action:hover {
  background: var(--border-subtle);
  color: var(--text-primary);
}

.msg-action-btn:active,
.msg-btn-action:active {
  transform: scale(0.96);
}

.msg-action-btn.primary {
  background: rgba(14, 165, 233, 0.12);
  border-color: rgba(14, 165, 233, 0.3);
  color: var(--accent-primary);
}

.msg-action-btn.primary:hover {
  background: rgba(14, 165, 233, 0.22);
}

.msg-action-btn.danger,
.msg-btn-action.delete {
  background: rgba(239, 68, 68, 0.1);
  border-color: rgba(239, 68, 68, 0.25);
  color: var(--accent-danger);
  margin-left: auto; /* 強制推至卡片右側，極具視覺辨識度 */
}

.msg-action-btn.danger:hover,
.msg-btn-action.delete:hover {
  background: rgba(239, 68, 68, 0.2);
  color: #ef4444;
}

/* 空狀態容器 */
.empty-state-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 48px 24px;
  gap: 12px;
  background: var(--bg-surface);
  border: 1px dashed var(--border-subtle);
  border-radius: var(--radius-lg);
  margin-top: 12px;
}

.empty-icon-circle {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--bg-surface-hover);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 4px;
}

.empty-title {
  font-weight: 800;
  font-size: 1.05rem;
  color: var(--text-primary);
}

.empty-desc {
  font-size: 0.82rem;
  color: var(--text-muted);
  max-width: 360px;
  line-height: 1.5;
}

/* ================= 10. 圖文同框、Google 地圖預覽與個別車輛通知靜音樣式 ================= */

/* 訊息卡片內嵌快照照片 (圖文同框) */
.msg-photo-preview {
  width: 100%;
  max-height: 240px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  margin-top: 6px;
  margin-bottom: 6px;
  background: var(--bg-surface-hover);
  border: 1px solid var(--border-subtle);
  cursor: zoom-in;
  display: flex;
  align-items: center;
  justify-content: center;
}

[data-theme="dark"] .msg-photo-preview {
  background: #000000;
  border-color: rgba(255, 255, 255, 0.09);
}

.msg-photo-img {
  width: 100%;
  max-height: 240px;
  object-fit: contain;
  display: block;
  transition: transform 0.2s ease;
}

.msg-photo-preview:active .msg-photo-img {
  transform: scale(0.98);
}

/* 訊息卡片內嵌 Google 地圖預覽 */
.msg-map-container {
  width: 100%;
  height: 200px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface-hover);
  margin-top: 8px;
  margin-bottom: 4px;
  display: none;
}

.msg-map-container.expanded {
  display: block;
  animation: viewFadeIn 0.25s ease-out forwards;
}

.msg-map-iframe {
  width: 100%;
  height: 100%;
  border: none;
  display: block;
}

/* 車輛詳情頁之 Google 地圖預覽卡片 */
.map-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 12px 10px;
  margin-bottom: 10px;
  box-shadow: var(--card-shadow);
  transition: background-color 0.2s ease, border-color 0.2s ease;
}

@media (min-width: 768px) {
  .map-card {
    border-radius: var(--radius-lg);
    padding: 16px;
    margin-bottom: 16px;
  }
}

.map-iframe-container {
  width: 100%;
  height: 260px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface-hover);
}

.map-iframe {
  width: 100%;
  height: 100%;
  border: none;
  display: block;
}

/* 車輛管理之通知開關與靜音徽章 */
.mute-badge {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(148, 163, 184, 0.12);
  color: var(--text-muted);
  border: 1px solid var(--border-subtle);
}

.mute-badge.muted {
  background: rgba(239, 68, 68, 0.12);
  color: var(--accent-danger);
  border-color: rgba(239, 68, 68, 0.3);
}

.btn-mute-toggle {
  background: var(--bg-surface-hover);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
}

.btn-mute-toggle.active {
  background: rgba(239, 68, 68, 0.1);
  color: var(--accent-danger);
  border-color: rgba(239, 68, 68, 0.25);
}

/* 全螢幕地圖 Lightbox 彈窗 */
.map-modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 2600;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  align-items: center;
  justify-content: center;
  padding: 12px;
}

.map-modal-overlay.active {
  display: flex;
}

.map-modal-box {
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-subtle);
  width: 100%;
  max-width: 680px;
  height: 80vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
}

.map-modal-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.map-modal-title {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text-primary);
}

.map-modal-body {
  flex: 1;
  width: 100%;
  height: 100%;
}

/* ================= 11. 即時監控滿版卡片與歷史紀錄圖文樣式 ================= */

/* 即時監控 (Overview) 滿版卡片 */
.overview-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 12px 12px;
  box-shadow: var(--card-shadow);
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  box-sizing: border-box;
  cursor: default;
  transition: background-color 0.15s ease, border-color 0.15s ease, box-shadow 0.2s ease;
}

/* 總覽新進資料高亮綠色框樣式 */
.overview-card.is-new {
  border: 2.5px solid #10b981;
  box-shadow: 0 0 0 1px rgba(16, 185, 129, 0.4), 0 4px 18px rgba(16, 185, 129, 0.18);
  position: relative;
}

[data-theme="dark"] .overview-card.is-new {
  border-color: #10b981;
  box-shadow: 0 0 0 1px rgba(16, 185, 129, 0.5), 0 4px 20px rgba(16, 185, 129, 0.28);
}

/* 新進標籤 (Green Badge) */
.new-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.72rem;
  font-weight: 700;
  color: #059669;
  background: rgba(16, 185, 129, 0.12);
  border: 1px solid rgba(16, 185, 129, 0.35);
  padding: 2px 7px;
  border-radius: 999px;
  letter-spacing: 0.3px;
  cursor: pointer;
  user-select: none;
  animation: newBadgePulse 2s infinite ease-in-out;
}

[data-theme="dark"] .new-badge {
  color: #34d399;
  background: rgba(52, 211, 153, 0.16);
  border-color: rgba(52, 211, 153, 0.4);
}

.pulse-dot-green {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #10b981;
  display: inline-block;
}

[data-theme="dark"] .pulse-dot-green {
  background: #34d399;
}

@keyframes newBadgePulse {
  0%, 100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.88;
    transform: scale(1.05);
  }
}

.overview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.overview-title {
  font-size: 1.12rem;
  font-weight: 800;
  letter-spacing: 0.5px;
  color: var(--text-primary);
  cursor: pointer;
  transition: color 0.15s ease;
}

.overview-title:hover {
  color: var(--accent-primary);
}

/* 寬度滿版圖片 */
.overview-photo-box {
  width: 100%;
  max-height: 260px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--bg-surface-hover);
  border: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: zoom-in;
}

/* 總覽預留圖片位置 (即使無照片也確保有固定圖片格位) */
.overview-photo-box.empty {
  min-height: 140px;
  background: var(--bg-surface-hover);
  border: 1px dashed var(--border-subtle);
  cursor: default;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--text-muted);
}

.overview-photo-box.empty .placeholder-icon {
  stroke: var(--text-muted);
  opacity: 0.6;
}

.overview-photo-box.empty .placeholder-text {
  font-size: 0.8rem;
  font-weight: 600;
  opacity: 0.8;
}

.overview-photo-img {
  width: 100%;
  max-height: 260px;
  object-fit: cover;
  display: block;
}

.overview-text-box {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* 總覽時間自己一行 */
.overview-time-line {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--accent-primary);
}

.overview-time-icon {
  stroke: var(--accent-primary);
  flex-shrink: 0;
}

.overview-text-body {
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--text-primary);
  margin: 0;
  word-break: break-word;
}

.overview-meta-line {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin: 0;
}

.overview-actions-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border-subtle);
}

/* 詳情頁歷史紀錄中的圖片快照 */
.history-item-media {
  width: 100%;
  max-height: 200px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  margin-top: 8px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface-hover);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: zoom-in;
}

.history-item-img {
  width: 100%;
  max-height: 200px;
  object-fit: cover;
  display: block;
}

/* 詳情頁歷史紀錄中的地圖 */
.history-item-map-box {
  width: 100%;
  height: 160px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  margin-top: 8px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface-hover);
}

.history-item-map-iframe {
  width: 100%;
  height: 100%;
  border: none;
  display: block;
}

/* 總覽與詳情右上角通報時間徽章 (淡藍色、無 icon、極簡高辨識) */
.overview-time-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.74rem;
  font-weight: 700;
  color: #0284c7;
  background: rgba(2, 132, 199, 0.08);
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(2, 132, 199, 0.22);
  white-space: nowrap;
  letter-spacing: 0.2px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  box-sizing: border-box;
}

[data-theme="dark"] .overview-time-badge {
  color: #38bdf8;
  background: rgba(56, 189, 248, 0.12);
  border-color: rgba(56, 189, 248, 0.28);
}

/* 總覽即時地圖預覽容器 (與車輛詳情頁完全統一使用 .map-iframe-container 與 .map-iframe) */
.overview-card .map-iframe-container {
  height: 220px;
  margin-top: 4px;
}

/* 資訊項目條目 (時間、地點、座標) */
.overview-info-row {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 0.86rem;
  color: var(--text-secondary);
  line-height: 1.45;
}

.overview-info-item {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.overview-info-label {
  font-weight: 700;
  color: var(--text-muted);
  flex-shrink: 0;
  min-width: 42px;
}

.overview-info-val {
  color: var(--text-primary);
  font-weight: 600;
  word-break: break-word;
}

/* ================= 12. 車辨軌跡圖 (Leaflet) 與自訂標記 ================= */
.track-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 12px;
  box-shadow: var(--card-shadow);
}

.track-map-container {
  width: 100%;
  height: 220px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface-hover);
  position: relative;
  z-index: 10;
}

/* Leaflet 自訂高對比標記點 (起/終/序號) */
.track-marker {
  display: flex !important;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: #ffffff;
  font-size: 11px;
  font-weight: 800;
  border: 2px solid #ffffff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
  box-sizing: border-box;
}

.track-marker.start {
  background: #16a34a !important; /* 綠色 起點 */
}

.track-marker.end {
  background: #dc2626 !important; /* 紅色 終點 */
}

.track-marker.mid {
  background: #2563eb !important; /* 藍色 中繼點 */
}

/* ================= 13. 歷史紀錄折疊收合 (Accordion) ================= */
.history-item {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  overflow: hidden;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.history-item.expanded {
  border-color: var(--accent-primary);
  box-shadow: var(--card-shadow);
}

.history-item-top {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 12px;
  background: var(--bg-surface-hover);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  transition: background-color 0.15s ease;
}

.history-item-top:active {
  background: var(--bg-surface);
}

.history-top-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.history-expand-icon {
  width: 14px;
  height: 14px;
  stroke: #0284c7;
  fill: none;
  stroke-width: 2.2;
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1), stroke 0.2s ease;
  flex-shrink: 0;
}

[data-theme="dark"] .history-expand-icon {
  stroke: #38bdf8;
}

.history-item.expanded .history-expand-icon {
  transform: rotate(180deg);
  stroke: var(--accent-primary);
}

/* 折疊主體：預設完全收合隱藏 */
.history-item-content {
  display: none;
  flex-direction: column;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--border-subtle);
  background: var(--bg-surface);
}

.history-item.expanded .history-item-content {
  display: flex;
}

/* ================= 14. 燈箱手勢縮放與平移 (Pinch-to-Zoom) ================= */
.modal-img-container {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  touch-action: none;
}

.modal-img {
  max-width: 100%;
  max-height: 85dvh;
  object-fit: contain;
  border-radius: var(--radius-md);
  transform-origin: center center;
  touch-action: none;
  user-select: none;
  -webkit-user-drag: none;
  will-change: transform;
}

.modal-zoom-hint {
  position: absolute;
  bottom: max(calc(env(safe-area-inset-bottom, 0px) + 16px), 24px);
  background: rgba(15, 23, 42, 0.78);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: #e2e8f0;
  font-size: 0.74rem;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 20px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  pointer-events: none;
  z-index: 2050;
  transition: opacity 0.3s ease;
}