/* TrailGuard 軌跡守望 — Web 版樣式 */
:root {
  --green: #2e7d32;
  --green-dark: #1b5e20;
  --red: #d32f2f;
  --amber: #f9a825;
  --bg: #f5f5f4;
  --card: #ffffff;
  --text: #1c1c1c;
  --muted: #666;
  --line: #e0e0e0;
}
* {
  box-sizing: border-box;
}
/* hidden 屬性必須勝過元件的 display:flex/grid（否則 overlay 會攔截點擊） */
[hidden] {
  display: none !important;
}
html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: -apple-system, "PingFang TC", "Noto Sans TC", system-ui, sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}
body {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* 頂欄 */
.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: env(safe-area-inset-top, 0) 12px 0;
  height: calc(48px + env(safe-area-inset-top, 0));
  background: var(--green-dark);
  color: #fff;
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 17px;
}
.brand-mark {
  font-size: 20px;
}
.icon-btn {
  background: transparent;
  border: 0;
  color: inherit;
  font-size: 20px;
  padding: 8px;
  cursor: pointer;
  line-height: 1;
}

main {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
  position: relative;
}

/* 地圖 */
#map {
  flex: 1 1 auto;
  width: 100%;
  min-height: 220px;
  background: #ddd;
  z-index: 0;
}
.leaflet-container {
  background: #e8e8e8;
}
.leaflet-control-attribution {
  font-size: 11px;
}

/* 狀態卡 */
.status-card {
  flex: 0 0 auto;
  background: var(--card);
  border-top: 1px solid var(--line);
  padding: 10px 14px 8px;
}
.status-line {
  font-size: 18px;
  font-weight: 700;
  line-height: 1.3;
}
.status-line.ontrack {
  color: var(--green);
}
.status-line.suspect {
  color: var(--amber);
}
.status-line.alert {
  color: var(--red);
}
.status-line.weak,
.status-line.lost {
  color: var(--muted);
}
.status-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 4px;
  font-size: 13px;
  color: var(--muted);
}
.track-info {
  margin-top: 4px;
  font-size: 13px;
  color: var(--muted);
}
.perm-hint {
  margin-top: 6px;
  font-size: 13px;
  color: var(--red);
  background: #fdecea;
  padding: 6px 8px;
  border-radius: 6px;
}

/* 按鈕列 */
.btn-row {
  flex: 0 0 auto;
  display: flex;
  gap: 8px;
  padding: 8px 12px calc(10px + env(safe-area-inset-bottom, 0));
  background: var(--card);
  border-top: 1px solid var(--line);
  overflow-x: auto;
}
.btn {
  flex: 1 1 auto;
  white-space: nowrap;
  padding: 12px 10px;
  font-size: 15px;
  font-weight: 600;
  border: 0;
  border-radius: 10px;
  background: var(--green);
  color: #fff;
  cursor: pointer;
  min-width: 72px;
}
.btn:active {
  filter: brightness(0.92);
}
.btn-outline {
  background: #fff;
  color: var(--green-dark);
  border: 1.5px solid var(--green);
}
.btn-sm {
  padding: 9px 8px;
  font-size: 14px;
  flex: 1 1 auto;
}
.demo-controls {
  align-items: center;
  border-top: 1px dashed var(--line);
}
.demo-label {
  flex: 0 0 auto;
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
}

/* 偏離告警橫幅 */
.alert-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  background: var(--red);
  color: #fff;
  font-size: 18px;
  font-weight: 800;
  text-align: center;
  padding: calc(12px + env(safe-area-inset-top, 0)) 14px 12px;
  line-height: 1.35;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
  animation: pulse 1s ease-in-out infinite;
}
@keyframes pulse {
  0%,
  100% {
    background: #d32f2f;
  }
  50% {
    background: #b71c1c;
  }
}

/* 回軌 toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 1000;
  background: var(--green);
  color: #fff;
  padding: 12px 20px;
  border-radius: 24px;
  font-size: 16px;
  font-weight: 700;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3);
}

/* 拖放遮罩 */
.drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 1500;
  background: rgba(27, 94, 32, 0.85);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  font-weight: 800;
  border: 6px dashed rgba(255, 255, 255, 0.7);
}

/* 面板（設定 / 下載） */
.panel {
  position: fixed;
  inset: 0;
  z-index: 1200;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.panel-inner {
  width: 100%;
  max-width: 520px;
  background: var(--card);
  border-radius: 16px 16px 0 0;
  padding: 16px 18px calc(24px + env(safe-area-inset-bottom, 0));
  max-height: 85vh;
  overflow-y: auto;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.panel-head h2 {
  margin: 0;
  font-size: 18px;
}
.panel-head .icon-btn {
  color: var(--text);
}
.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
  font-size: 15px;
}
.row.col {
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  border-bottom: 0;
}
.row select {
  font-size: 15px;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
}
.switch input {
  width: 22px;
  height: 22px;
}
.cache-info {
  font-size: 13px;
  color: var(--muted);
}
.panel-actions {
  display: flex;
  gap: 10px;
  margin-top: 14px;
}
.dl-summary {
  font-size: 15px;
  line-height: 1.5;
  padding: 8px 0;
}
.dl-progress {
  margin: 10px 0;
}
.dl-bar {
  height: 12px;
  background: var(--line);
  border-radius: 6px;
  overflow: hidden;
}
.dl-bar-fill {
  height: 100%;
  width: 0%;
  background: var(--green);
  transition: width 0.2s;
}
.dl-text {
  margin-top: 6px;
  font-size: 13px;
  color: var(--muted);
}

/* 使用者位置 marker */
.user-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #1976d2;
  border: 3px solid #fff;
  box-shadow: 0 0 4px rgba(0, 0, 0, 0.5);
}
