/**
 * JoJo 網頁分享頁樣式
 * - CSS 變數：淺色 / 深色主題切換
 * - 響應式：手機優先設計
 * - 深色模式：跟隨系統偏好 + 手動 toggle
 */

:root {
  --primary: #22c55e;
  --primary-hover: #16a34a;
  --accent: #f97316;

  --bg: #ffffff;
  --bg-elev: #f8fafc;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 20px 40px rgba(0, 0, 0, 0.12);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 20px;
}

/* 深色模式（跟隨系統） */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f172a;
    --bg-elev: #1e293b;
    --surface: #1e293b;
    --border: #334155;
    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --text-muted: #64748b;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 20px 40px rgba(0, 0, 0, 0.5);
  }
}

/* 手動深色模式（優先於 system） */
html[data-theme="dark"] {
  --bg: #0f172a;
  --bg-elev: #1e293b;
  --surface: #1e293b;
  --border: #334155;
  --text-primary: #f1f5f9;
  --text-secondary: #cbd5e1;
  --text-muted: #64748b;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 20px 40px rgba(0, 0, 0, 0.5);
}

html[data-theme="light"] {
  --bg: #ffffff;
  --bg-elev: #f8fafc;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 20px 40px rgba(0, 0, 0, 0.12);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC",
    "PingFang TC", "Microsoft JhengHei", sans-serif;
  background-color: var(--bg);
  color: var(--text-primary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

/* ── 頂部品牌列 ────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  backdrop-filter: blur(10px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 18px;
}

.brand-icon {
  font-size: 22px;
}

.brand-name {
  color: var(--primary);
}

.topbar-actions {
  display: flex;
  gap: 8px;
}

.theme-toggle,
.lang-toggle {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  cursor: pointer;
  font-size: 14px;
  color: var(--text-secondary);
  transition: all 0.15s;
}

.theme-toggle:hover,
.lang-toggle:hover {
  background: var(--border);
}

/* ── 容器 ─────────────────────────────────── */
.container {
  max-width: 640px;
  margin: 0 auto;
  padding: 24px 16px;
}

/* ── 狀態顯示（載入 / 錯誤） ──────────────── */
.state {
  text-align: center;
  padding: 60px 20px;
}

.state-icon {
  font-size: 48px;
  margin-bottom: 16px;
}

.state-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.state-desc {
  font-size: 15px;
  color: var(--text-secondary);
  margin-bottom: 24px;
}

.spinner {
  width: 40px;
  height: 40px;
  margin: 0 auto 16px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ── 打卡卡片 ─────────────────────────────── */
.card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
}

.map-wrap {
  position: relative;
  aspect-ratio: 16 / 9;
  background: var(--bg-elev);
  overflow: hidden;
}

.map-image,
.map-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.map-image {
  object-fit: cover;
}

.map-canvas {
  /* Leaflet 會填滿這個 div */
  background: var(--bg-elev);
}

/* Leaflet controls 主題適配 */
.leaflet-control-attribution {
  font-size: 10px !important;
  background: rgba(255, 255, 255, 0.9) !important;
}

html[data-theme="dark"] .leaflet-control-attribution,
@media (prefers-color-scheme: dark) {
  .leaflet-control-attribution {
    background: rgba(30, 41, 59, 0.9) !important;
    color: var(--text-secondary) !important;
  }
  .leaflet-control-attribution a {
    color: var(--primary) !important;
  }
}

.map-badge {
  position: absolute;
  top: 12px;
  left: 12px;
  background: rgba(249, 115, 22, 0.95);
  color: white;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 4px;
  box-shadow: var(--shadow-md);
}

.card-body {
  padding: 24px 20px;
}

.place-name {
  font-size: 24px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 8px;
  line-height: 1.3;
}

.checkin-time {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 16px;
}

.description {
  font-size: 15px;
  color: var(--text-primary);
  padding: 12px 16px;
  background: var(--bg-elev);
  border-radius: var(--radius-md);
  margin-bottom: 20px;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.meta-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 16px;
  background: var(--bg-elev);
  border-radius: var(--radius-md);
  margin-bottom: 20px;
}

.meta-item {
  min-width: 0;
}

.meta-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 4px;
  letter-spacing: 0.5px;
}

.meta-value {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  word-break: break-all;
}

.actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.btn-primary,
.btn-secondary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 20px;
  border-radius: var(--radius-md);
  font-size: 15px;
  font-weight: 600;
  text-decoration: none;
  transition: all 0.15s;
  cursor: pointer;
  border: none;
}

.btn-primary {
  background: var(--primary);
  color: white;
  box-shadow: var(--shadow-md);
}

.btn-primary:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow-lg);
}

.btn-secondary {
  background: var(--bg-elev);
  color: var(--text-primary);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--border);
}

/* ── 速度顏色圖例 ─────────────────────────── */
.legend-box {
  padding: 16px;
  background: var(--bg-elev);
  border-radius: var(--radius-md);
  margin-bottom: 20px;
}

.legend-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 10px;
}

.legend-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-secondary);
}

.legend-swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  flex-shrink: 0;
}

/* ── 軌跡時間軸 ───────────────────────────── */
.timeline-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 12px;
}

.timeline-list {
  margin-bottom: 20px;
  max-height: 480px;
  overflow-y: auto;
}

.timeline-item {
  display: flex;
  gap: 12px;
  padding-bottom: 16px;
}

.timeline-left {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 12px;
  flex-shrink: 0;
}

.timeline-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 2px;
}

.timeline-line {
  flex: 1;
  width: 2px;
  background: var(--border);
  min-height: 20px;
}

.timeline-body {
  flex: 1;
  min-width: 0;
  padding-bottom: 4px;
}

.timeline-item-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 6px;
}

.timeline-item-time {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.timeline-item-subtitle {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 2px;
  word-break: break-all;
}

.timeline-item-thumb {
  width: 100%;
  max-width: 240px;
  border-radius: var(--radius-sm);
  margin-top: 8px;
  display: block;
  background: var(--bg-elev);
}

.timeline-item.clickable {
  cursor: pointer;
}

.timeline-item.clickable:hover .timeline-body {
  opacity: 0.8;
}

/* ── 底部 ─────────────────────────────────── */
.footer {
  text-align: center;
  padding: 32px 16px;
  color: var(--text-muted);
  font-size: 13px;
}

/* ── 工具 class ───────────────────────────── */
.hidden {
  display: none !important;
}
/* ── 標記卡片專屬樣式（8-1e Phase 2） ────────────── */
.marker-header {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 6px;
}
.marker-tag-circle {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
  color: white;
  background-color: var(--accent, #22c55e);
}
.marker-header-text {
  flex: 1;
  min-width: 0;
}
.marker-place-name {
  margin: 4px 0 0 0;
  color: var(--text-muted);
  font-size: 13px;
}
.marker-tag-icon-img {
  width: 28px;
  height: 28px;
  object-fit: contain;
}

/* ── 群組分享專屬樣式（8-1g Phase 6） ────────────── */
.back-to-group {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  color: var(--text-secondary);
  text-decoration: none;
  margin-bottom: 12px;
}
.back-to-group:hover {
  color: var(--primary);
}
.group-list {
  margin-bottom: 20px;
}
.group-list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: var(--radius-md);
  background: var(--bg-elev);
  margin-bottom: 8px;
  text-decoration: none;
  color: inherit;
  transition: background 0.15s;
}
.group-list-item:hover {
  background: var(--border);
}
.group-list-item-dot {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  flex-shrink: 0;
}
.group-list-item-text {
  flex: 1;
  min-width: 0;
}
.group-list-item-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.group-list-item-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}
.group-list-empty {
  text-align: center;
  padding: 24px;
  color: var(--text-muted);
  font-size: 14px;
}