/* ===== 全局 & 移动端优先 ===== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --bg: #fef9f3;
  --bg-2: #ffffff;
  --panel: #fff5eb;
  --border: #ffe0c2;
  --text: #4a3f35;
  --text-dim: #a89b8c;
  --primary: #ff9a76;
  --primary-hover: #ff845c;
  --danger: #ff6b6b;
  --danger-hover: #ee5a5a;
  --accent: #ffd56b;
  --nav-h: 64px;
  --topbar-h: 56px;
  --radius: 18px;
  --radius-sm: 12px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  padding-top: var(--topbar-h);
  padding-bottom: var(--nav-h);
  height: 100vh;
}

/* ===== 顶部栏 ===== */
.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  z-index: 500;
  padding-top: env(safe-area-inset-top);
  box-shadow: 0 2px 12px rgba(255, 154, 118, 0.08);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
}

.logo {
  font-size: 24px;
}

.brand h1 {
  font-size: 18px;
  font-weight: 700;
  color: var(--primary);
}

.actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.action-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  padding: 4px 8px;
  border: none;
  background: var(--panel);
  border-radius: 10px;
  cursor: pointer;
  color: var(--text);
  transition: all 0.2s;
  min-width: 44px;
}

.action-btn span {
  font-size: 16px;
  line-height: 1;
}

.action-btn small {
  font-size: 10px;
  color: var(--text-dim);
}

.action-btn:active {
  transform: scale(0.92);
  background: var(--accent);
}

.icon-btn {
  width: 36px;
  height: 36px;
  border: none;
  background: var(--panel);
  border-radius: 50%;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  transition: background 0.2s;
}

/* ===== 视图 ===== */
.view {
  display: none;
  height: calc(100vh - var(--topbar-h) - var(--nav-h));
  overflow: hidden;
}

.view.active {
  display: block;
}

/* ===== 地图 ===== */
#map {
  width: 100%;
  height: 100%;
  background: #f5ede4;
}

.map-stats {
  position: absolute;
  top: 16px;
  left: 16px;
  background: rgba(30, 34, 43, 0.92);
  backdrop-filter: blur(8px);
  padding: 8px 14px;
  border-radius: 20px;
  font-size: 13px;
  color: var(--text-dim);
  border: 1px solid var(--border);
  z-index: 400;
}

.map-stats b {
  color: var(--primary);
  font-size: 15px;
}

/* 自定义地图标记 */
.photo-marker {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 3px solid #fff;
  background-size: cover;
  background-position: center;
  box-shadow: 0 2px 10px rgba(255, 154, 118, 0.3);
  cursor: pointer;
}

/* Leaflet 适配 */
.leaflet-container {
  background: #f5ede4;
  font-family: inherit;
}

.leaflet-popup-content-wrapper {
  background: var(--bg-2);
  color: var(--text);
  border-radius: var(--radius-sm);
  box-shadow: 0 4px 20px rgba(255, 154, 118, 0.2);
}

.leaflet-popup-tip {
  background: var(--bg-2);
}

.leaflet-popup-content {
  margin: 10px 12px;
  text-align: center;
}

.popup-thumb {
  width: 120px;
  height: 120px;
  object-fit: cover;
  border-radius: 8px;
  margin-bottom: 6px;
  cursor: pointer;
}

.popup-name {
  font-size: 12px;
  color: var(--text-dim);
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ===== 图库 ===== */
.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 4px;
  padding: 4px;
  height: 100%;
  overflow-y: auto;
  align-content: start;
}

.photo-card {
  background: var(--panel);
  border-radius: var(--radius-sm);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.15s;
  aspect-ratio: 1;
  position: relative;
}

.photo-card:active {
  transform: scale(0.96);
}

/* 选中态 */
.photo-card.selected {
  outline: 3px solid var(--primary);
  outline-offset: -3px;
}

.check-overlay {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.2s;
}

.check-overlay.show {
  opacity: 1;
}

.check-circle {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid #fff;
  background: rgba(0, 0, 0, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 13px;
  font-weight: bold;
}

.check-circle.checked {
  background: var(--primary);
  border-color: var(--primary);
}

/* 选择模式下网格 */
.photo-grid.select-mode .photo-card:active {
  transform: scale(0.98);
}

/* ===== 选择操作栏 ===== */
.select-bar {
  position: fixed;
  bottom: var(--nav-h);
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--bg-2);
  border-top: 1px solid var(--border);
  z-index: 600;
  box-shadow: 0 -2px 12px rgba(255, 154, 118, 0.1);
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
  animation: slideUp 0.2s;
}

.select-count {
  font-size: 15px;
  font-weight: 600;
  color: var(--primary);
}

.photo-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.photo-card .loc-dot {
  position: absolute;
  top: 4px;
  left: 4px;
  background: rgba(255, 154, 118, 0.85);
  color: #fff;
  font-size: 10px;
  padding: 2px 5px;
  border-radius: 8px;
}

/* ===== 空状态 ===== */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 30px;
  text-align: center;
  color: var(--text-dim);
  height: 100%;
}

.empty-icon {
  font-size: 56px;
  margin-bottom: 16px;
}

.empty-state p {
  font-size: 15px;
  margin-bottom: 8px;
}

.empty-state .hint {
  font-size: 13px;
  opacity: 0.7;
  line-height: 1.6;
}

/* ===== 编辑器 ===== */
#editorView {
  display: none;
  flex-direction: column;
}

#editorView.active {
  display: flex;
}

.preview-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #fff8f0;
  min-height: 0;
}

.preview-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
}

.preview-toolbar .spacer {
  flex: 1;
}

.geo-badge {
  font-size: 12px;
  color: var(--text-dim);
  background: var(--panel);
  padding: 5px 10px;
  border-radius: 12px;
  white-space: nowrap;
}

.geo-badge.ok {
  color: #4caf50;
}

.geo-badge.warn {
  color: #ff9800;
}

.canvas-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  overflow: hidden;
}

#editorCanvas {
  max-width: 100%;
  max-height: 100%;
  border-radius: var(--radius-sm);
  box-shadow: 0 4px 20px rgba(255, 154, 118, 0.2);
}

/* ===== 滤镜面板 ===== */
.filter-panel {
  max-height: 45vh;
  background: var(--bg-2);
  border-top: 1px solid var(--border);
  padding: 14px 16px 16px;
  overflow-y: auto;
}

.filter-panel h2 {
  font-size: 15px;
  margin-bottom: 14px;
}

.filter-group {
  margin-bottom: 16px;
}

.filter-group h3 {
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.slider-row {
  margin-bottom: 12px;
}

.slider-row label {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  margin-bottom: 5px;
}

.slider-row label span {
  color: var(--primary);
  font-variant-numeric: tabular-nums;
}

.slider-row input[type="range"] {
  width: 100%;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--border);
  border-radius: 4px;
  outline: none;
}

.slider-row input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
}

.slider-row input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
  border: none;
}

.preset-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.preset {
  padding: 9px 4px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
}

.preset:active {
  border-color: var(--primary);
  background: #ffe8d6;
  transform: scale(0.96);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 16px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  color: var(--text);
  background: var(--panel);
  transition: all 0.2s;
}

.btn.primary {
  background: var(--primary);
}

.btn.danger {
  background: var(--danger);
}

.btn.ghost {
  background: transparent;
  border: 1px solid var(--border);
}

.btn.full {
  width: 100%;
  margin-top: 10px;
}

/* ===== 底部导航 ===== */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--nav-h);
  display: flex;
  align-items: center;
  justify-content: space-around;
  background: var(--bg-2);
  border-top: 1px solid var(--border);
  z-index: 500;
  padding-bottom: env(safe-area-inset-bottom);
  box-shadow: 0 -2px 12px rgba(255, 154, 118, 0.08);
}

.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 6px 0;
  transition: all 0.2s;
}

.nav-btn.active {
  color: var(--primary);
  transform: scale(1.05);
}

.nav-icon {
  font-size: 20px;
}

.nav-label {
  font-size: 11px;
  font-weight: 500;
}

.nav-camera {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--primary);
  border: 4px solid var(--bg);
  color: #fff;
  font-size: 24px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: -20px;
  box-shadow: 0 4px 12px rgba(79, 124, 255, 0.4);
  transition: transform 0.15s;
}

.nav-camera:active {
  transform: scale(0.92);
}

/* ===== 详情弹窗 ===== */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(74, 63, 53, 0.4);
  z-index: 1000;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fadeIn 0.2s;
}

.modal.hidden {
  display: none;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-content {
  background: var(--bg-2);
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  border-radius: 20px 20px 0 0;
  padding: 16px;
  overflow-y: auto;
  animation: slideUp 0.25s;
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.modal-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.modal-header .spacer {
  flex: 1;
}

.modal-title {
  font-size: 14px;
  color: var(--text-dim);
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.detail-img {
  width: 100%;
  border-radius: var(--radius-sm);
  display: block;
  margin-bottom: 12px;
}

.detail-meta {
  background: var(--panel);
  border-radius: var(--radius-sm);
  padding: 12px;
  margin-bottom: 12px;
}

.meta-row {
  display: flex;
  gap: 10px;
  padding: 4px 0;
  font-size: 13px;
}

.meta-label {
  color: var(--text-dim);
  min-width: 60px;
}

.meta-value {
  color: var(--text);
  word-break: break-all;
}

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

.modal-actions .btn {
  flex: 1;
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: calc(var(--nav-h) + 20px);
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--panel);
  color: var(--text);
  padding: 10px 20px;
  border-radius: 20px;
  border: 1px solid var(--border);
  font-size: 13px;
  opacity: 0;
  transition: all 0.25s;
  z-index: 2000;
  white-space: nowrap;
  box-shadow: 0 4px 16px rgba(255, 154, 118, 0.15);
  pointer-events: none;
}

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

.toast.success {
  border-color: #4caf50;
}

.toast.error {
  border-color: var(--danger);
}

/* ===== 设置面板 ===== */
.settings-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 8px;
}

.setting-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s;
  text-align: left;
  width: 100%;
}

.setting-item:active {
  background: #ffe8d6;
  transform: scale(0.98);
}

.setting-icon {
  font-size: 24px;
  width: 40px;
  text-align: center;
}

.setting-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.setting-text b {
  font-size: 15px;
  color: var(--text);
  font-weight: 600;
}

.setting-text small {
  font-size: 12px;
  color: var(--text-dim);
}

/* ===== 桌面端优化 ===== */
@media (min-width: 768px) {
  .photo-grid {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 10px;
    padding: 10px;
  }

  .filter-panel {
    max-height: 40vh;
  }

  .modal-content {
    max-height: 85vh;
    border-radius: 20px;
    margin-bottom: 20px;
  }
}
