/* ==========================================================================
   消防山域救援導航系統 — Tactical Fire SAR UI Design System
   深邃戰術黑曜石 × 消防警示橘紅 × 雷達青光 × 高對比戶外強光／夜間適配
   ========================================================================== */
:root {
  --bg: #050912;
  --bg-grad: radial-gradient(circle at 18% 0%, rgba(14, 165, 233, 0.12), transparent 45%),
             radial-gradient(circle at 85% 100%, rgba(239, 68, 68, 0.08), transparent 45%),
             #050912;
  --panel: #0b1220;
  --panel-elev: #111b2e;
  --card: linear-gradient(180deg, rgba(23, 35, 58, 0.92), rgba(15, 24, 42, 0.96));
  --card-solid: #131e33;
  --border: rgba(148, 163, 184, 0.18);
  --border-bright: rgba(56, 189, 248, 0.42);
  --text: #f8fafc;
  --text-soft: #cbd5e1;
  --muted: #8ea1bc;
  --accent: #38bdf8;
  --cyan: #22d3ee;
  --fire: #f97316;
  --danger: #ef4444;
  --warn: #f59e0b;
  --ok: #10b981;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --shadow-card: 0 6px 20px rgba(0, 0, 0, 0.32), inset 0 1px 0 rgba(255, 255, 255, 0.06);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --nav-h: 62px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0; width: 100%; height: 100%;
  background: var(--bg-grad);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

/* 細緻深色捲軸 */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(148, 163, 184, 0.25); border-radius: 999px; }
::-webkit-scrollbar-thumb:hover { background: rgba(56, 189, 248, 0.5); }

.app-shell {
  display: flex; flex-direction: column;
  width: 100%; height: 100%;
  padding-top: var(--safe-top);
}

/* ================= 頂部戰術狀態列 ================= */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 9px 14px;
  background: linear-gradient(90deg, rgba(11, 18, 32, 0.96), rgba(15, 23, 42, 0.94));
  border-bottom: 1px solid var(--border);
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(12px);
  z-index: 40; flex-shrink: 0;
}

.brand {
  display: flex; align-items: center; gap: 8px;
  font-weight: 800; font-size: 0.98rem; letter-spacing: 0.02em; white-space: nowrap;
}
.brand-badge {
  font-size: 0.72rem; font-weight: 700;
  padding: 3px 9px; border-radius: 999px;
  background: linear-gradient(135deg, rgba(239, 68, 68, 0.26), rgba(249, 115, 22, 0.22));
  color: #fed7aa;
  border: 1px solid rgba(249, 115, 22, 0.5);
  box-shadow: 0 0 12px rgba(239, 68, 68, 0.18);
}

.hud-coords {
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-variant-numeric: tabular-nums;
  font-size: 0.75rem; color: #e2e8f0;
}
.hud-pill {
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid var(--border);
  padding: 4px 9px; border-radius: 7px;
  letter-spacing: 0.01em;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}
.hud-pill.online {
  border-color: rgba(16, 185, 129, 0.55);
  background: rgba(16, 185, 129, 0.14);
  color: #6ee7b7;
}
.hud-pill.offline {
  border-color: rgba(245, 158, 11, 0.55);
  background: rgba(245, 158, 11, 0.14);
  color: #fde68a;
}
.hud-pill.offroute {
  background: linear-gradient(135deg, rgba(220, 38, 38, 0.45), rgba(185, 28, 28, 0.35));
  border-color: #f87171;
  color: #fff; font-weight: 800;
  animation: pulse-alert 1.2s ease-in-out infinite;
}

@keyframes pulse-alert {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.55); }
  50% { box-shadow: 0 0 0 6px rgba(239, 68, 68, 0); }
}

/* ================= 主工作區 ================= */
.workspace {
  position: relative; flex: 1; display: flex; min-height: 0; overflow: hidden;
}

.side-panel {
  width: 396px; max-width: 100%;
  background: linear-gradient(180deg, #0b1220 0%, #070d19 100%);
  border-right: 1px solid var(--border);
  overflow-y: auto; padding: 14px; z-index: 20; flex-shrink: 0;
}

.map-stage {
  position: relative; flex: 1; min-width: 0; height: 100%; background: #030712;
}
#map2d, #map3d { width: 100%; height: 100%; }

.radar3d-wrap {
  position: relative; width: 100%; height: 100%; background: #030712; overflow: hidden;
  touch-action: none;
}
#radar3d-gl, #radar3d-hud {
  position: absolute; inset: 0; width: 100%; height: 100%; display: block;
}
#radar3d-hud { pointer-events: none; }
.radar3d-hint {
  position: absolute; top: 12px; left: 12px; z-index: 5;
  background: rgba(5, 9, 18, 0.82);
  border: 1px solid rgba(34, 211, 238, 0.42);
  backdrop-filter: blur(10px);
  color: #a5f3fc; font-size: 0.74rem; font-weight: 600;
  padding: 6px 11px; border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  pointer-events: none;
}

.stage-overlay {
  position: absolute; inset: 0; z-index: 25; background: #000; display: flex; flex-direction: column;
}
.hidden { display: none !important; }

/* ================= AR 視圖 ================= */
.ar-viewport { position: relative; flex: 1; overflow: hidden; background: #000; }
#ar-video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
#ar-canvas { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.ar-controls {
  background: rgba(11, 18, 32, 0.94);
  border-top: 1px solid var(--border);
  backdrop-filter: blur(12px);
  padding: 10px 14px; display: flex; flex-direction: column; gap: 8px;
}

/* ================= 卡片與版面元件 ================= */
.tab-pane { display: none; flex-direction: column; gap: 12px; animation: fade-in 0.16s ease; }
.tab-pane.active { display: flex; }
@keyframes fade-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

.card {
  position: relative;
  background: var(--card);
  border: 1px solid var(--border);
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-md);
  padding: 13px;
  display: flex; flex-direction: column; gap: 10px;
  box-shadow: var(--shadow-card);
}
.card h3 {
  margin: 0; font-size: 0.92rem; font-weight: 800; letter-spacing: 0.02em;
  color: #e0f2fe;
  display: flex; align-items: center; justify-content: space-between; gap: 6px;
  padding-bottom: 7px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.14);
}

.row { display: flex; gap: 7px; align-items: center; flex-wrap: wrap; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }

/* ================= 表單與高對比輸入元件 ================= */
label.field-lbl {
  font-size: 0.74rem; font-weight: 600; color: var(--muted);
  display: block; margin-bottom: 4px; letter-spacing: 0.02em;
}
input[type="text"], input[type="password"], input[type="url"], input[type="number"], select, textarea {
  width: 100%;
  background: rgba(5, 10, 20, 0.85);
  color: var(--text);
  border: 1px solid rgba(148, 163, 184, 0.24);
  border-radius: var(--radius-sm);
  padding: 9px 11px; font-size: 0.86rem; outline: none;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  background: rgba(7, 14, 28, 0.98);
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.18);
}

input[type="range"] {
  accent-color: var(--cyan);
  height: 6px; cursor: pointer;
}
input[type="checkbox"] {
  accent-color: var(--cyan);
  width: 15px; height: 15px; vertical-align: middle; cursor: pointer;
}

/* ================= 戴手套友善高質感按鈕 ================= */
button, .btn {
  appearance: none;
  border: 1px solid rgba(148, 163, 184, 0.25);
  background: linear-gradient(180deg, #1a2740 0%, #111b2e 100%);
  color: var(--text);
  padding: 9px 12px; border-radius: var(--radius-sm);
  font-size: 0.84rem; font-weight: 700; letter-spacing: 0.01em;
  cursor: pointer; min-height: 42px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25), inset 0 1px 0 rgba(255, 255, 255, 0.07);
  transition: transform 0.1s ease, background 0.15s, border-color 0.15s, box-shadow 0.15s;
}
button:hover {
  border-color: rgba(56, 189, 248, 0.65);
  background: linear-gradient(180deg, #213252 0%, #16233b 100%);
}
button:active { transform: scale(0.975); }

button.primary {
  background: linear-gradient(135deg, #0284c7 0%, #0369a1 100%);
  border-color: rgba(56, 189, 248, 0.75);
  color: #fff;
  box-shadow: 0 4px 14px rgba(2, 132, 199, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.2);
}
button.primary:hover { background: linear-gradient(135deg, #0ea5e9 0%, #0284c7 100%); }

button.danger {
  background: linear-gradient(135deg, #dc2626 0%, #991b1b 100%);
  border-color: rgba(248, 113, 113, 0.75);
  color: #fff;
  box-shadow: 0 4px 14px rgba(220, 38, 38, 0.34), inset 0 1px 0 rgba(255, 255, 255, 0.18);
}
button.danger:hover { background: linear-gradient(135deg, #ef4444 0%, #b91c1c 100%); }

button.success {
  background: linear-gradient(135deg, #059669 0%, #047857 100%);
  border-color: rgba(52, 211, 153, 0.7);
  color: #fff;
  box-shadow: 0 4px 14px rgba(16, 185, 129, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.18);
}
button.success:hover { background: linear-gradient(135deg, #10b981 0%, #059669 100%); }

button.warn {
  background: linear-gradient(135deg, #d97706 0%, #b45309 100%);
  border-color: rgba(251, 191, 36, 0.7);
  color: #fff;
  box-shadow: 0 4px 14px rgba(217, 119, 6, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.18);
}
button.warn:hover { background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%); }

button.small { min-height: 34px; padding: 5px 10px; font-size: 0.77rem; }

/* 罐頭回報高識別按鈕 */
.canned-btn {
  min-height: 50px; font-size: 0.88rem; border-width: 1.5px;
  background: linear-gradient(180deg, rgba(19, 30, 51, 0.95), rgba(11, 18, 32, 0.98));
  justify-content: center;
}
.canned-btn.urgent {
  border-color: rgba(239, 68, 68, 0.8);
  background: linear-gradient(135deg, rgba(220, 38, 38, 0.28), rgba(153, 27, 27, 0.22));
  color: #fecaca;
}

.small { font-size: 0.78rem; }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-variant-numeric: tabular-nums; }

/* ================= 清單與高度剖面 ================= */
.list-box { display: flex; flex-direction: column; gap: 7px; max-height: 230px; overflow-y: auto; }
.list-item {
  background: rgba(7, 13, 25, 0.85);
  border: 1px solid rgba(148, 163, 184, 0.18);
  border-radius: 9px;
  padding: 9px 10px;
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  transition: border-color 0.15s, background 0.15s;
}
.list-item:hover {
  border-color: rgba(56, 189, 248, 0.45);
  background: rgba(15, 23, 42, 0.95);
}
.list-item .meta { font-size: 0.74rem; color: var(--muted); margin-top: 2px; }

.ele-svg {
  width: 100%; height: 92px; display: block;
  background: rgba(5, 10, 20, 0.9);
  border: 1px solid rgba(56, 189, 248, 0.2);
  border-radius: 8px;
}

.log-box {
  background: #030712;
  border: 1px solid rgba(16, 185, 129, 0.25);
  border-radius: 8px;
  padding: 8px 10px; font-size: 0.74rem; line-height: 1.5;
  max-height: 118px; overflow-y: auto;
  font-family: ui-monospace, Menlo, monospace; color: #cbd5e1;
}

/* ================= 底部導覽列 ================= */
.bottom-nav {
  display: flex;
  background: rgba(8, 14, 26, 0.96);
  border-top: 1px solid var(--border);
  backdrop-filter: blur(12px);
  padding: 4px 6px calc(4px + var(--safe-bottom));
  gap: 4px;
  z-index: 40; flex-shrink: 0;
}
.nav-btn {
  flex: 1; border: 1px solid transparent; border-radius: 10px;
  background: transparent; color: var(--muted);
  box-shadow: none;
  min-height: calc(var(--nav-h) - 8px);
  flex-direction: column; gap: 2px; font-size: 0.73rem; font-weight: 600; padding: 5px 4px;
}
.nav-btn:hover { background: rgba(56, 189, 248, 0.08); border-color: transparent; color: #e2e8f0; }
.nav-btn .ico { font-size: 1.18rem; line-height: 1.1; }
.nav-btn.active {
  color: #38bdf8; font-weight: 800;
  background: linear-gradient(180deg, rgba(56, 189, 248, 0.18), rgba(2, 132, 199, 0.08));
  border-color: rgba(56, 189, 248, 0.42);
  box-shadow: 0 0 16px rgba(56, 189, 248, 0.15);
}

/* ================= 地圖浮動快捷按鈕 ================= */
.map-fab-stack {
  position: absolute; right: 12px; bottom: 20px; z-index: 1000;
  display: flex; flex-direction: column; gap: 9px;
}
.fab {
  width: 46px; height: 46px; border-radius: 14px; padding: 0;
  background: rgba(11, 18, 32, 0.88);
  border: 1px solid rgba(56, 189, 248, 0.5);
  backdrop-filter: blur(10px);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.5);
  font-size: 1.15rem;
}
.fab:hover {
  background: rgba(14, 165, 233, 0.25);
  border-color: #38bdf8;
}

/* ================= 全螢幕覆蓋與 QR 彈窗 ================= */
.fullscreen-overlay {
  position: fixed; inset: 0; z-index: 9999; background: #000;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: #fff; padding: 20px; text-align: center;
}
.qr-modal-box {
  background: var(--panel-elev);
  border: 1px solid var(--border-bright);
  border-radius: var(--radius-lg);
  padding: 20px; max-width: 350px; width: 92%;
  display: flex; flex-direction: column; gap: 12px; align-items: center;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.7);
}
.qr-canvas-wrap { background: #fff; padding: 14px; border-radius: 12px; }

/* ================= 響應式規則：電腦版(1~3) vs 手機版(1~5) ================= */
.mobile-only-nav { display: none !important; }
.mobile-drawer-toggle { display: none; }
@media (max-width: 900px) {
  .mobile-only-nav { display: inline-flex !important; }
  .topbar { padding: 8px 10px; }
  .hud-coords { font-size: 0.7rem; }
  .mobile-drawer-toggle { display: inline-flex; }
  .side-panel {
    position: absolute; inset: 0; width: 100%; max-width: 100%;
    transform: translateY(100%);
    transition: transform 0.24s cubic-bezier(0.22, 1, 0.36, 1);
    z-index: 30;
  }
  .side-panel.mobile-open { transform: translateY(0); }
}
