/* ============================================================
   设计令牌：浅色为基准，[data-theme='dark'] 整组覆写。
   语义色（雨=红 / 晴=绿 / 热门=橙 / 主操作=蓝）双主题各自校准，
   *-on 为语义色填充上的前景色（保证 WCAG AA）。
   ============================================================ */
:root {
  color-scheme: light;

  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --text: #17202b;
  --text-2: #5f6b78;
  --border: #e3e7ec;

  --accent: #2563eb;
  --accent-soft: #eef4fe;
  --on-accent: #ffffff;

  --ok: #16a34a;
  --ok-strong: #15803d;
  --ok-soft: #effaf3;
  --on-ok: #ffffff;

  --rain: #dc2626;
  --rain-soft: #fdf1f1;

  --hot: #ea580c;
  --hot-strong: #c2410c;
  --hot-soft: #fef4ec;
  --hot-border: #f8c49a;
  --hot-text: #9a3412;
  --on-hot: #ffffff;

  --halo: #ffffff; /* 地图上文字的描边光晕 */
  --scrim: rgba(15, 23, 42, 0.4); /* 遮罩 */

  --shadow-1: 0 1px 2px rgba(23, 32, 43, 0.06), 0 2px 8px rgba(23, 32, 43, 0.1);
  --shadow-2: 0 4px 12px rgba(23, 32, 43, 0.08), 0 12px 32px rgba(23, 32, 43, 0.14);

  --radius: 12px;
  --radius-lg: 16px;
  --ease-out: cubic-bezier(0.32, 0.72, 0.33, 1);
}

:root[data-theme='dark'] {
  color-scheme: dark;

  --bg: #10151b;
  --surface: #1b222b;
  --surface-2: #232c37;
  --text: #e8edf2;
  --text-2: #97a2ae;
  --border: #313b47;

  --accent: #7aa5f8;
  --accent-soft: rgba(122, 165, 248, 0.14);
  --on-accent: #0b1524;

  --ok: #46c97e;
  --ok-strong: #2f9e5f;
  --ok-soft: rgba(70, 201, 126, 0.14);
  --on-ok: #06130b;

  --rain: #f47c7c;
  --rain-soft: rgba(244, 124, 124, 0.13);

  --hot: #f2934c;
  --hot-strong: #d97b34;
  --hot-soft: rgba(242, 147, 76, 0.14);
  --hot-border: rgba(242, 147, 76, 0.45);
  --hot-text: #f6ad74;
  --on-hot: #1a0f05;

  --halo: #10151b;
  --scrim: rgba(0, 0, 0, 0.55);

  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.4), 0 2px 10px rgba(0, 0, 0, 0.45);
  --shadow-2: 0 4px 14px rgba(0, 0, 0, 0.45), 0 14px 36px rgba(0, 0, 0, 0.55);
}

/* ============================================================
   基础
   ============================================================ */
* { box-sizing: border-box; }

/* hidden 属性必须压过组件自身的 display 规则 */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Hiragino Sans GB',
    'Microsoft YaHei', system-ui, sans-serif;
  color: var(--text);
  background: var(--bg);
  overscroll-behavior: none;
}

button {
  font-family: inherit;
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ============================================================
   动效层：全部收在 no-preference 内，reduced-motion 下为静态
   ============================================================ */
@media (prefers-reduced-motion: no-preference) {
  .weekend-toggle, .hot-toggle, .date-pill, .lc-switch,
  .nb-toggle, .nb-group button, .nb-row,
  .picker-city, .picker-geo, .picker-row,
  .dp-close, .picker-close {
    transition: background-color 0.18s ease, border-color 0.18s ease,
      color 0.18s ease, transform 0.12s ease, box-shadow 0.18s ease;
  }

  /* 按压的物理反馈 */
  .weekend-toggle:active, .hot-toggle:active, .date-pill:active,
  .lc-switch:active, .nb-toggle:active, .nb-group button:active,
  .picker-city:active, .picker-geo:active {
    transform: scale(0.97);
  }

  /* 标记悬停抬升（触屏无 hover，无副作用） */
  .wx-pill { transition: transform 0.15s ease, box-shadow 0.15s ease; }
  .wx-marker:hover .wx-pill {
    transform: translateY(-1px);
    box-shadow: var(--shadow-2);
  }

  /* 无数据占位呼吸 */
  .wx-wrap.nodata .wx-pill { animation: wx-pulse 1.6s ease-in-out infinite; }
  @keyframes wx-pulse {
    0%, 100% { opacity: 0.55; }
    50% { opacity: 0.9; }
  }

  /* 入场过渡：@starting-style 渐进增强，不支持的浏览器即时显示 */
  .detail-panel { transition: transform 0.3s var(--ease-out), opacity 0.3s ease; }
  @starting-style {
    .detail-panel:not([hidden]) { transform: translateY(28px); opacity: 0; }
  }

  .picker-sheet { transition: transform 0.3s var(--ease-out), opacity 0.3s ease; }
  @starting-style {
    .picker-overlay:not([hidden]) .picker-sheet { transform: translateY(24px); opacity: 0; }
  }

  .panel-overlay, .picker-overlay { transition: opacity 0.25s ease; }
  @starting-style {
    .panel-overlay:not([hidden]), .picker-overlay:not([hidden]) { opacity: 0; }
  }

  .nb-body { transition: transform 0.28s var(--ease-out), opacity 0.28s ease; }
  @starting-style {
    .nb-body:not([hidden]) { transform: translateY(12px); opacity: 0; }
  }

  .toast { transition: transform 0.25s var(--ease-out), opacity 0.25s ease; }
  @starting-style {
    .toast:not([hidden]) { transform: translateX(-50%) translateY(12px); opacity: 0; }
  }
}

/* ============================================================
   顶部 Header（mobile-first：两行）
   ============================================================ */
.app-header {
  flex: none;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 8px 12px;
  z-index: 1200;
}

.header-row1 {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.app-title {
  order: 1;
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  white-space: nowrap;
  letter-spacing: -0.01em;
}

.hot-toggle {
  order: 2;
  margin-left: auto;
}

.weekend-toggle { order: 3; }

.hot-toggle,
.weekend-toggle {
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 14px;
  font-weight: 600;
  padding: 7px 13px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  min-height: 36px;
}

.hot-toggle[aria-pressed='true'] {
  background: var(--hot-strong);
  border-color: var(--hot-strong);
  color: var(--on-hot);
}

.weekend-toggle[aria-pressed='true'] {
  background: var(--ok-strong);
  border-color: var(--ok-strong);
  color: var(--on-ok);
}

.datebar {
  order: 4;
  width: 100%;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding: 6px 0 2px;
}

.datebar::-webkit-scrollbar { display: none; }

.datebar.is-muted .date-pill { opacity: 0.4; }

.date-pill {
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 10px;
  padding: 5px 10px;
  min-width: 54px;
  cursor: pointer;
}

.date-pill .dp-label { font-size: 13px; font-weight: 600; }
.date-pill .dp-sub {
  font-size: 11px;
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
}
.date-pill.is-weekend .dp-label { color: var(--accent); }

.date-pill.active {
  background: var(--accent);
  border-color: var(--accent);
}
.date-pill.active .dp-label,
.date-pill.active .dp-sub { color: var(--on-accent); }

/* ============================================================
   主区域与地图
   ============================================================ */
.app-main {
  flex: 1;
  position: relative;
  min-height: 0;
}

.map {
  position: absolute;
  inset: 0;
  background: var(--surface-2);
}

/* 深色模式：反色滤镜让高德浅色瓦片变夜间图 */
:root[data-theme='dark'] .leaflet-tile {
  filter: invert(1) hue-rotate(180deg) saturate(0.5) brightness(0.92) contrast(0.9);
}

/* Leaflet 控件与版权条适配双主题 */
.leaflet-control-zoom { display: none; }
.leaflet-bar a,
.leaflet-bar a:hover {
  background: var(--surface);
  color: var(--text);
  border-bottom-color: var(--border);
}
.leaflet-container .leaflet-control-attribution {
  background: color-mix(in srgb, var(--surface) 78%, transparent);
  color: var(--text-2);
}
.leaflet-container .leaflet-control-attribution a { color: var(--text-2); }

/* ============================================================
   本地锚点卡片
   ============================================================ */
.local-card {
  position: absolute;
  top: 8px;
  left: 8px;
  right: 8px;
  z-index: 1100;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-1);
  padding: 8px 12px;
  font-size: 13px;
  min-height: 42px;
}

.local-card.is-empty {
  cursor: pointer;
  color: var(--accent);
  font-weight: 600;
}

.lc-city { font-weight: 700; white-space: nowrap; }

.lc-wx {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.lc-muted { color: var(--text-2); }

.lc-flag {
  font-size: 12px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
}
.lc-flag.is-rain { color: var(--rain); background: var(--rain-soft); }
.lc-flag.is-ok { color: var(--ok); background: var(--ok-soft); }

.lc-switch {
  flex: none;
  border: none;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  border-radius: 999px;
  padding: 6px 10px;
  cursor: pointer;
}

/* ============================================================
   天气标记
   ============================================================ */
.wx-wrap {
  background: none;
  border: none;
}

.wx-marker {
  position: absolute;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.wx-pill {
  display: flex;
  align-items: center;
  gap: 3px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 8px;
  box-shadow: var(--shadow-1);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  line-height: 1.2;
}

.wx-ico { font-size: 15px; line-height: 1; }
.wx-tmp { font-variant-numeric: tabular-nums; }

.wx-name {
  margin-top: 2px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text);
  text-shadow: 0 0 3px var(--halo), 0 0 3px var(--halo), 0 0 3px var(--halo);
  white-space: nowrap;
}

.hide-names .wx-name { display: none; }

/* 无数据占位 */
.wx-wrap.nodata .wx-pill {
  padding: 3px 7px;
  color: var(--text-2);
  font-weight: 400;
  box-shadow: none;
}

/* 周末模式：推荐 / 置灰 */
.wx-wrap.recommend .wx-pill {
  border: 2px solid var(--ok);
  background: var(--ok-soft);
}

.wx-wrap.recommend .wx-pill::before {
  content: '✓';
  color: var(--on-ok);
  background: var(--ok-strong);
  font-size: 9px;
  line-height: 1;
  border-radius: 50%;
  padding: 2px;
}

.wx-wrap.dim {
  filter: grayscale(1);
  opacity: 0.45;
}

/* ============================================================
   定位蓝点
   ============================================================ */
.user-dot-wrap { background: none; border: none; }

.user-dot {
  position: absolute;
  transform: translate(-50%, -50%);
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid var(--surface);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 40%, transparent), var(--shadow-1);
}

/* ============================================================
   周边城市抽屉
   ============================================================ */
#nearby-list .nearby {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: calc(12px + env(safe-area-inset-bottom));
  z-index: 1300;
  display: flex;
  flex-direction: column-reverse; /* 移动端：列表在横条上方 */
  align-items: center;
  gap: 6px;
  pointer-events: none;
}

.nb-toggle {
  pointer-events: auto;
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-1);
  border-radius: 999px;
  padding: 9px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-variant-numeric: tabular-nums;
}

.nb-body {
  pointer-events: auto;
  width: 100%;
  max-height: 52dvh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-2);
  overflow: hidden;
}

.nb-filters {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}

.nb-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.nb-group button {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
  font-variant-numeric: tabular-nums;
}

.nb-group button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}

.nb-rows {
  overflow-y: auto;
  min-height: 0;
}

.nb-row {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: none;
  border-bottom: 1px solid var(--border);
  border-left: 3px solid transparent;
  padding: 8px 12px;
  cursor: pointer;
}

.nb-row:last-child { border-bottom: none; }
.nb-row:hover { background: var(--surface-2); }
.nb-row.is-dry { border-left-color: var(--ok); }
.nb-row.is-rain { border-left-color: var(--rain); }

.nb-l1 {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.nb-name { font-weight: 700; white-space: nowrap; }
.nb-km {
  color: var(--text-2);
  font-size: 12px;
  min-width: 44px;
  font-variant-numeric: tabular-nums;
}

.nb-wx {
  margin-left: auto;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.nb-spots {
  margin-top: 3px;
  font-size: 11px;
  color: var(--text-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nb-empty {
  margin: 0;
  padding: 16px;
  text-align: center;
  color: var(--text-2);
  font-size: 13px;
}

.nb-muted { color: var(--text-2); font-weight: 400; }

/* ============================================================
   城市详情面板（移动端底部抽屉）
   ============================================================ */
.panel-overlay {
  position: fixed;
  inset: 0;
  background: var(--scrim);
  z-index: 1500;
}

.detail-panel {
  /* 绝对定位在 .app-main 内：桌面端自然从 header 下方开始，不遮挡顶栏 */
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1600;
  background: var(--surface);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  box-shadow: var(--shadow-2);
  max-height: 70dvh;
  overflow-y: auto;
  padding: 6px 16px calc(16px + env(safe-area-inset-bottom));
}

.dp-handle {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  margin: 4px auto 6px;
}

.dp-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 0 8px;
}

.dp-title strong { font-size: 17px; margin-right: 8px; }
.dp-sub { font-size: 12px; color: var(--text-2); }

.dp-close,
.picker-close {
  border: none;
  background: none;
  font-size: 16px;
  color: var(--text-2);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 8px;
}
.dp-close:hover,
.picker-close:hover { background: var(--surface-2); }

.dp-intro {
  margin: 0 0 8px;
  font-size: 13px;
  color: var(--text-2);
  line-height: 1.5;
}

.dp-spots {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-bottom: 10px;
}

.dp-sec {
  font-size: 12px;
  font-weight: 600;
  color: var(--hot);
  margin-right: 2px;
}

.spot-chip {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 9px;
  background: var(--surface);
}

.spot-chip.is-5a {
  border-color: var(--hot-border);
  background: var(--hot-soft);
  color: var(--hot-text);
}

.spot-chip.is-5a i {
  font-style: normal;
  font-size: 9px;
  font-weight: 700;
  color: var(--on-hot);
  background: var(--hot-strong);
  border-radius: 4px;
  padding: 1px 3px;
  line-height: 1;
}

.dp-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 8px;
  border-left: 3px solid transparent;
  border-radius: 6px;
  font-size: 13px;
}

.dp-row.is-rain { border-left-color: var(--rain); }
.dp-row.is-ok { border-left-color: var(--ok); }
.dp-row.is-weekend { background: var(--accent-soft); }
.dp-row.is-sel { outline: 1px solid var(--accent); }

.dp-date { width: 76px; font-weight: 600; flex: none; font-variant-numeric: tabular-nums; }
.dp-wx { flex: 1; min-width: 0; }
.dp-temp {
  width: 62px;
  text-align: right;
  font-weight: 600;
  flex: none;
  font-variant-numeric: tabular-nums;
}
.dp-precip {
  width: 92px;
  text-align: right;
  color: var(--text-2);
  font-size: 12px;
  flex: none;
  font-variant-numeric: tabular-nums;
}

.dp-loading { color: var(--text-2); text-align: center; padding: 24px; }

/* ============================================================
   城市选择弹层
   ============================================================ */
.picker-overlay {
  position: fixed;
  inset: 0;
  background: var(--scrim);
  z-index: 2000;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.picker-sheet {
  background: var(--surface);
  width: 100%;
  max-height: 80dvh;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 14px 16px calc(16px + env(safe-area-inset-bottom));
  overflow-y: auto;
}

.picker-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.picker-hint { margin: 0 0 8px; font-size: 13px; color: var(--rain); }

.picker-geo {
  display: block;
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
  border-radius: 10px;
  padding: 11px 12px;
  margin-bottom: 10px;
  cursor: pointer;
  font-size: 14px;
}

.picker-input {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 10px;
  padding: 11px 12px;
  font-size: 14px;
  margin-bottom: 10px;
  outline-color: var(--accent);
}

.picker-input::placeholder { color: var(--text-2); }

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

.picker-city {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 8px;
  padding: 10px 0;
  font-size: 13px;
  cursor: pointer;
}
.picker-city:hover { background: var(--surface-2); }

.picker-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  border: none;
  background: none;
  padding: 12px 4px;
  font-size: 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  text-align: left;
}
.picker-row:hover { background: var(--surface-2); }

.picker-prov { color: var(--text-2); font-size: 12px; }
.picker-empty { color: var(--text-2); font-size: 13px; text-align: center; padding: 16px 0; }

/* ============================================================
   Toast
   ============================================================ */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: color-mix(in srgb, var(--text) 92%, transparent);
  color: var(--bg);
  font-size: 13px;
  padding: 10px 16px;
  border-radius: 999px;
  z-index: 3000;
  max-width: 90vw;
  text-align: center;
  cursor: pointer;
  box-shadow: var(--shadow-2);
}

/* ============================================================
   桌面端（≥768px）
   ============================================================ */
@media (min-width: 768px) {
  .app-header { padding: 10px 16px; }

  .header-row1 { flex-wrap: nowrap; }

  .app-title { font-size: 18px; }

  .datebar {
    order: 2;
    width: auto;
    flex: 1;
    justify-content: center;
    padding: 0;
    margin: 0 12px;
  }

  .hot-toggle { order: 3; margin-left: 0; }

  .weekend-toggle { order: 4; }

  .leaflet-control-zoom { display: block; }

  .local-card {
    left: 12px;
    top: 12px;
    right: auto;
    max-width: 360px;
  }

  #nearby-list .nearby {
    left: 12px;
    right: auto;
    top: 68px;
    bottom: auto;
    width: 360px;
    flex-direction: column; /* 桌面端：横条在上、列表在下 */
    align-items: stretch;
  }

  .nb-toggle { border-radius: var(--radius); }
  .nb-body { max-height: 56vh; }

  /* 桌面端：右侧面板，不遮地图 */
  .panel-overlay { display: none; }

  .detail-panel {
    left: auto;
    top: 0;
    bottom: 0;
    right: 0;
    width: 380px;
    max-height: none;
    border-radius: 0;
    padding: 12px 16px;
  }

  .dp-handle { display: none; }

  .picker-overlay { align-items: center; }

  .picker-sheet {
    width: 480px;
    border-radius: var(--radius-lg);
    max-height: 70vh;
  }

  @media (prefers-reduced-motion: no-preference) {
    /* 桌面端详情面板从右侧滑入 */
    @starting-style {
      .detail-panel:not([hidden]) { transform: translateX(32px); opacity: 0; }
    }
    @starting-style {
      .picker-overlay:not([hidden]) .picker-sheet { transform: scale(0.97); opacity: 0; }
    }
  }
}

@media (min-width: 1200px) {
  .detail-panel { width: 400px; }
}
