﻿/* Poli 車輛廣播監控 - 專業級響應式 PWA 樣式庫 (符合 responsive-pwa-ui 規範) */
/* 嚴格遵循：無 Emoji 原則、100dvh 防抖動、安全區避讓、Desktop Master-Detail 佈局 */

:root {
  /* 安全區動態避讓變數 */
  --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);

  /* 主題調色盤（深色戰術儀表風格） */
  --bg-main: #0a0f1d;
  --bg-gradient: radial-gradient(circle at 50% 0%, #151e33 0%, #0a0f1d 85%);
  --bg-surface: rgba(18, 26, 44, 0.82);
  --bg-surface-hover: rgba(28, 40, 68, 0.95);
  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-focus: #00f2fe;

  --accent-cyan: #00f2fe;
  --accent-blue: #38bdf8;
  --accent-emerald: #10b981;
  --accent-amber: #f59e0b;
  --accent-crimson: #ef4444;

  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  --nav-height: 56px;
  --top-height: 48px;
  --radius-lg: 14px;
  --radius-md: 10px;
  --radius-sm: 6px;
}

/* 全域重置與觸控體驗優化 */
*, *::before, *::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100vh;
  height: 100dvh; /* 動態視口高度：徹底杜絕 iOS 網址列展開/收合時之跳動 */
  overflow: hidden;
  overscroll-behavior-y: none; /* 禁止整頁橡皮筋反彈拉扯 */
  background-color: var(--bg-main);
  background-image: var(--bg-gradient);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  user-select: none;
  -webkit-user-select: none;
}

/* 外層 App 容器 */
#app-container {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100dvh;
  position: relative;
}

/* 頂部導航與狀態列 (自動避讓動態島與瀏海) */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: calc(var(--top-height) + var(--sat));
  padding: var(--sat) 16px 0 16px;
  background: rgba(10, 15, 29, 0.92);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-subtle);
  z-index: 100;
  flex-shrink: 0;
}

.brand-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: 0.8px;
}

.brand-icon-box {
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent-cyan);
}

.brand-mark {
  color: #ffffff;
}

.brand-sub {
  color: var(--accent-cyan);
  font-weight: 600;
  font-size: 0.82rem;
  letter-spacing: 0.5px;
}

.live-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--accent-emerald);
  background: rgba(16, 185, 129, 0.12);
  border: 1px solid rgba(16, 185, 129, 0.28);
  padding: 3px 10px;
  border-radius: 9999px;
  letter-spacing: 0.5px;
}

.live-dot {
  width: 6px;
  height: 6px;
  background-color: var(--accent-emerald);
  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 8px var(--accent-emerald); }
  100% { transform: scale(0.9); opacity: 0.7; }
}

/* 主要內容滾動容器 */
.main-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px;
  padding-bottom: calc(var(--nav-height) + var(--sab) + 24px);
  -webkit-overflow-scrolling: touch; /* iOS 原生慣性滾動 */
  position: relative;
}

/* 分頁視圖淡入動效 */
.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.18rem;
  font-weight: 700;
  margin: 0;
  letter-spacing: 0.3px;
  color: #ffffff;
}

.stats-counter {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
}

/* ================= 視圖一：車輛總覽 (Overview) ================= */
.card-grid {
  display: grid;
  grid-template-columns: 1fr; /* 手機端：單欄卡片流 */
  gap: 12px;
}

@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);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  transition: transform 0.15s ease, background-color 0.15s ease, border-color 0.15s ease;
  cursor: pointer;
}

.data-card:hover {
  background-color: var(--bg-surface-hover);
  border-color: rgba(0, 242, 254, 0.3);
  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.22rem;
  font-weight: 800;
  letter-spacing: 0.8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  color: #ffffff;
}

.card-note {
  font-size: 0.82rem;
  color: var(--accent-cyan);
  font-weight: 500;
  margin-left: 6px;
}

.status-badge {
  font-size: 0.7rem;
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.status-badge.normal {
  background: rgba(16, 185, 129, 0.15);
  color: var(--accent-emerald);
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.status-badge.alert {
  background: rgba(239, 68, 68, 0.15);
  color: var(--accent-crimson);
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.card-body {
  display: flex;
  gap: 14px;
  align-items: center;
}

.card-thumb-box {
  width: 72px;
  height: 54px;
  background: rgba(0, 0, 0, 0.5);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border: 1px solid var(--border-subtle);
  overflow: hidden;
}

.card-thumb-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.thumb-placeholder {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0.5px;
}

.card-details {
  flex: 1;
  min-width: 0;
}

.detail-line {
  margin: 3px 0;
  font-size: 0.84rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.time-text {
  font-size: 0.74rem;
  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 14px auto;
  color: var(--text-muted);
  opacity: 0.6;
}

/* ================= 視圖二：個別詳情 (Vehicle Detail) ================= */
.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: rgba(0, 242, 254, 0.15);
  border-color: var(--accent-cyan);
  color: #ffffff;
  box-shadow: 0 0 10px rgba(0, 242, 254, 0.2);
}

/* 快照與報表展示區塊 */
.snapshot-card, .report-card, .history-card, .settings-group {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 16px;
  margin-bottom: 16px;
}

.card-sub-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.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: 280px;
  background: #000000;
  border-radius: var(--radius-md);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
  cursor: zoom-in;
}

.snapshot-img {
  width: 100%;
  max-height: 280px;
  object-fit: contain;
  display: block;
}

.snapshot-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.snapshot-info-label {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.snapshot-btn-group {
  display: flex;
  gap: 8px;
}

/* 沙盒 Iframe 容器 */
.iframe-container {
  width: 100%;
  height: 240px;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--border-subtle);
  background: #ffffff;
}

.report-iframe {
  width: 100%;
  height: 100%;
  border: none;
}

/* 歷史記錄時間軸清單 */
.history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
}

.history-item {
  background: rgba(0, 0, 0, 0.3);
  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-cyan);
  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;
}

/* ================= 視圖三：系統設定 (Settings) ================= */
.group-title {
  font-size: 0.98rem;
  font-weight: 700;
  margin-top: 0;
  margin-bottom: 12px;
  color: var(--accent-blue);
  letter-spacing: 0.3px;
}

.group-desc {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0;
  margin-bottom: 14px;
  line-height: 1.4;
}

.form-item {
  margin-bottom: 12px;
}

.form-label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 6px;
  font-weight: 500;
}

.form-input {
  width: 100%;
  padding: 10px 12px;
  background: rgba(0, 0, 0, 0.35);
  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);
}

.form-actions {
  margin-top: 14px;
}

/* 通用按鈕元件 (無 Emoji, 純文字與 SVG 圖標) */
.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-cyan);
  color: #04101e;
}

.btn-primary:hover {
  background: #25f4ff;
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-primary);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.18);
}

.btn-action {
  background: #06c755;
  color: #ffffff;
}

.btn-action:hover {
  background: #05b04b;
}

.btn-danger {
  background: rgba(239, 68, 68, 0.15);
  color: var(--accent-crimson);
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.btn-danger:hover {
  background: rgba(239, 68, 68, 0.25);
}

.btn-block {
  width: 100%;
}

.storage-info-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

/* ================= 底部固定導航列 (高 56px + Home Indicator 避讓) ================= */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--nav-height) + var(--sab));
  padding-bottom: var(--sab);
  background: rgba(10, 15, 29, 0.96);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  justify-content: space-around;
  align-items: center;
  z-index: 1000;
  flex-shrink: 0;
}

.nav-btn {
  flex: 1;
  height: var(--nav-height);
  background: transparent;
  border: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  color: var(--text-muted);
  cursor: pointer;
  transition: color 0.15s ease;
  padding: 0;
}

.nav-icon {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
}

.nav-text {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.3px;
}

.nav-btn.active {
  color: var(--accent-cyan);
}

.nav-btn.active .nav-icon {
  stroke: var(--accent-cyan);
}

/* ================= 全螢幕放大檢視模態 (Lightbox) ================= */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.94);
  z-index: 2000;
  justify-content: center;
  align-items: center;
  padding: 16px;
}

.modal-overlay.active {
  display: flex;
}

.modal-img {
  max-width: 100%;
  max-height: 88vh;
  object-fit: contain;
  border-radius: var(--radius-md);
}

.modal-close-btn {
  position: absolute;
  top: calc(var(--sat) + 16px);
  right: 20px;
  background: rgba(255, 255, 255, 0.15);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.2);
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 0.5px;
}

.modal-close-btn:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* ================= 輕提示訊息 (Toast) ================= */
#toast {
  position: fixed;
  top: calc(var(--sat) + 56px);
  left: 50%;
  transform: translateX(-50%) translateY(-20px);
  background: rgba(15, 23, 42, 0.96);
  color: #ffffff;
  padding: 9px 20px;
  border-radius: 9999px;
  font-size: 0.85rem;
  font-weight: 600;
  border: 1px solid var(--accent-cyan);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  opacity: 0;
  pointer-events: none;
  transition: all 0.25s ease-out;
  z-index: 3000;
}

#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ================= 電腦版寬螢幕優化 (>= 1024px) ================= */
@media (min-width: 1024px) {
  .main-content {
    max-width: 1280px;
    margin: 0 auto;
    width: 100%;
    padding: 24px 20px;
  }
}
