:root {
  --bg: #0e1318;
  --bg-soft: #151c24;
  --card: #18212b;
  --card-hover: #1f2a36;
  --border: #2a3746;
  --text: #dfe7ef;
  --text-dim: #8fa0b3;
  --accent: #00d4aa;
  --accent-2: #4d9fff;
  --warn: #ffb020;
  --danger: #ff5c6c;
  --pink: #ff5c8a;
  --radius: 12px;

  /* 主题相关：浅色主题会整组覆盖 */
  --sunken: #202b36;
  --on-accent: #04231d;
  --text-strong: #ffffff;
  --danger-text: #ffb3bb;
  --overlay: rgba(3, 6, 9, .62);
  --overlay-strong: rgba(3, 6, 9, .7);
  --shadow-color: rgba(0, 0, 0, .45);
  --shadow-soft: rgba(0, 0, 0, .5);
  --topbar-from: #131c24;
}

* { box-sizing: border-box; }

/* html 只承担一件事：给 body 的百分比高度一个基准 */
html { height: 100%; }

/* body 用 min-height 而不是 height ——
   否则 body 的盒子被锁死在一屏高，内容再长也不会把盒子撑开，
   .topbar / .tabs 的 position: sticky 会被 body 的下边界顶走（滚动约一屏后就消失）。
   改成 min-height 后 body 随内容长高，顶栏与 Tab 才能一直粘在顶部。 */
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
  font-size: 14px;
}

h1, h2, h3 { margin: 0; font-weight: 600; }
h2 { font-size: 20px; }
h3 { font-size: 15px; }

.muted { color: var(--text-dim); }
.small { font-size: 12px; }
.hidden { display: none !important; }

.warn-text { color: var(--warn); }

/* 维护工具那一行的进度文字 */
.error-text { color: var(--danger); }
.ok-text { color: var(--accent); }

/* ---------------- 顶栏 ---------------- */
.topbar {
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: linear-gradient(90deg, var(--topbar-from), var(--bg));
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand {
  font-size: 16px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: inherit;
  cursor: pointer;
}
.brand:hover .brand-text { color: var(--accent); }
.logo { font-size: 20px; }
.topbar-right { display: flex; align-items: center; gap: 12px; }

.badge {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--sunken);
  border: 1px solid var(--border);
  color: var(--text-dim);
  white-space: nowrap;
}
.badge.on { background: rgba(0, 212, 170, .12); border-color: rgba(0, 212, 170, .45); color: var(--accent); }
.badge.mock { background: rgba(255, 176, 32, .1); border-color: rgba(255, 176, 32, .4); color: var(--warn); }
.badge.warn { background: rgba(255, 176, 32, .12); border-color: rgba(255, 176, 32, .45); color: var(--warn); }
.badge.danger { background: rgba(255, 92, 108, .12); border-color: rgba(255, 92, 108, .45); color: var(--danger); }

.chat-meta { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }

/* ---------------- 按钮 ---------------- */
.btn {
  border: 1px solid var(--border);
  background: var(--card-hover);
  color: var(--text);
  padding: 7px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  transition: .15s;
  font-family: inherit;
  white-space: nowrap;   /* 按钮文字不折行（窄屏顶栏靠它保持单行） */
}
.btn:hover { background: var(--card-hover); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.danger { color: var(--danger); border-color: rgba(255, 92, 108, .35); background: transparent; }
/* 破坏性操作的主按钮：实心红底，用于确认弹窗 */
.btn.danger.solid { background: var(--danger); border-color: var(--danger); color: #fff; font-weight: 600; }
.btn.danger.solid:hover { filter: brightness(1.08); }

.select {
  background: var(--card-hover);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  font-family: inherit;
  font-size: 13px;
}

/* ---------------- 布局 ---------------- */
.layout { display: flex; min-height: calc(100vh - 56px); }

.sidebar {
  width: 280px;
  flex: 0 0 280px;
  border-right: 1px solid var(--border);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  height: calc(100vh - 56px);
  position: sticky;
  top: 56px;
  overflow-y: auto;
}

.main { flex: 1; padding: 20px 24px 60px; min-width: 0; overflow-x: clip; }

/* ---------------- 登录 / 注册 ---------------- */
.auth-screen {
  position: fixed;
  inset: 0;
  background: radial-gradient(1200px 600px at 50% -10%, #16232e, #0e1318 60%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 60;
  padding: 20px;
}
.auth-card {
  position: relative;   /* 给右上角的 ✕ 定位 */
  width: min(380px, 100%);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px 26px 22px;
  box-shadow: 0 24px 60px var(--shadow-color);
}
/* 登录现在是弹窗：右上角 ✕、点遮罩、按 Esc 都能关 */
.auth-close {
  position: absolute; top: 10px; right: 12px;
  width: 30px; height: 30px; border-radius: 50%;
  border: none; cursor: pointer; font-size: 14px; line-height: 1;
  background: transparent; color: var(--text-dim);
}
.auth-close:hover { background: var(--sunken); color: var(--text); }
.auth-brand { font-size: 17px; font-weight: 600; display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.auth-card > p { margin: 0 0 18px; line-height: 1.6; }
.auth-tabs { display: flex; gap: 6px; margin-bottom: 18px; background: var(--bg-soft); padding: 4px; border-radius: 10px; }
.auth-tab {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-dim);
  padding: 8px 0;
  border-radius: 7px;
  cursor: pointer;
  font-size: 13.5px;
  font-family: inherit;
  transition: .15s;
}
.auth-tab.active { background: var(--card-hover); color: var(--text); font-weight: 600; }
.auth-card label { display: block; font-size: 12.5px; color: var(--text-dim); margin-bottom: 14px; }
.auth-card input {
  display: block;
  width: 100%;
  margin-top: 6px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 9px 12px;
  border-radius: 8px;
  font-family: inherit;
  font-size: 14px;
}
.auth-card input:focus { outline: none; border-color: var(--accent); }
.auth-submit { width: 100%; padding: 10px; font-size: 14px; margin-top: 2px; }

/* 注册邀请码：申请入口 + 点击后展开的邮箱输入框 */
.auth-invite { display: flex; flex-direction: column; gap: 8px; margin: -6px 0 14px; }
.auth-invite-btn { width: 100%; padding: 8px; font-size: 12.5px; }
.auth-invite-form { display: flex; gap: 8px; }
.auth-invite-form input { margin-top: 0; min-width: 0; }
.auth-invite-form .btn { white-space: nowrap; }
.auth-invite-msg { line-height: 1.5; }
.auth-invite-msg.ok { color: var(--accent); }
.auth-error {
  background: rgba(255, 92, 108, .12);
  border: 1px solid rgba(255, 92, 108, .4);
  color: var(--danger-text);
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 12.5px;
  margin-bottom: 12px;
}
.auth-note { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--border); line-height: 1.6; }

/* ---------------- 游客（未登录）首页 ---------------- */
.guest-points { margin: 0 0 14px; padding-left: 18px; line-height: 1.95; }
.guest-points li { font-size: 13.5px; }
.guest-login-btn { width: 100%; }
.nearby-item { cursor: pointer; }
.nearby-metrics { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }

.user-chip { display: flex; align-items: center; gap: 8px; position: relative; }
/* 头像 + 昵称做成一个按钮：手机上点它弹出账号菜单 */
.user-chip-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 6px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: inherit;
  font: inherit;
  cursor: pointer;
  transition: background .15s ease;
}
.user-chip-btn:hover { background: var(--card-hover); }
.user-name { font-size: 13px; color: var(--text); max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-caret { font-size: 10px; color: var(--text-dim); display: none; }

/* 手机端才用的账号菜单：宽屏下由媒体查询关掉 */
.user-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 40;
  min-width: 140px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--card);
  box-shadow: 0 12px 30px var(--shadow-color);
}
.user-menu-item {
  appearance: none;
  border: 0;
  background: transparent;
  padding: 9px 12px;
  border-radius: 8px;
  text-align: left;
  font: inherit;
  font-size: 13.5px;
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
}
.user-menu-item:hover { background: var(--card-hover); }
.user-menu-item.danger { color: var(--danger); }

/* 「修改密码」入口：桌面显示文字，窄屏收缩为钥匙图标，避免顶栏拥挤 */
#passwordBtn .pw-icon { display: none; }
#nicknameBtn .nick-icon { display: none; }

/* ---------------- 路书（行者 iMxingzhe） ---------------- */
.imx-actions { display: flex; gap: 8px; }
.imx-route-list { display: flex; flex-direction: column; gap: 6px; }
.imx-route {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: inherit;
  font-size: 13.5px;
  cursor: pointer;
  transition: .15s;
}
.imx-route:hover { border-color: var(--accent); background: var(--card-hover); }
.imx-route-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.imx-route-meta { color: var(--text-dim); font-size: 12px; white-space: nowrap; }

/* 全站搜索 */
.imx-search { display: flex; gap: 8px; margin-bottom: 10px; }
.imx-search input {
  flex: 1; min-width: 0; padding: 8px 12px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--bg-soft);
  color: var(--text); font-family: inherit; font-size: 13.5px;
}
.imx-search input:focus { outline: none; border-color: var(--accent); }
.imx-route-link { justify-content: flex-start; text-decoration: none; }
.imx-route-thumb { width: 72px; height: 48px; object-fit: cover; border-radius: 6px; flex-shrink: 0; }
.imx-route-main { min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.imx-route-main .imx-route-title { color: var(--text); }
.imx-route-main .imx-route-meta { white-space: normal; }
.imx-pager { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 12px; }
.imx-climbs { display: flex; flex-direction: column; gap: 6px; margin-top: 14px; }
.imx-climb {
  padding: 8px 12px;
  border-radius: 8px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  font-size: 12.5px;
}
.imx-map { height: 320px; width: 100%; border-radius: 10px; overflow: hidden; margin-top: 14px; }
.imx-map + .chart-box { margin-top: 14px; }   /* 地图在上、海拔图在下时的间隔 */

/* 爬升修正控制条 */
.imx-recalc { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 12px; font-size: 12.5px; color: var(--text-dim); }
.imx-recalc input {
  width: 64px; margin: 0 4px; padding: 4px 8px; border-radius: 6px;
  border: 1px solid var(--border); background: var(--bg-soft);
  color: var(--text); font-family: inherit; font-size: 13px;
}

/* 路书页卡头：标题与右侧操作始终一行（窄屏也不折行，标题过长则省略号） */
#tab-routes .card-head { flex-wrap: nowrap; align-items: center; gap: 10px; }
#tab-routes .card-head h3 { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#tab-routes .card-head > :last-child { flex-shrink: 0; }

/* ---------------- 上传区 ---------------- */
.dropzone {
  border: 1.5px dashed var(--border);
  border-radius: var(--radius);
  padding: 20px 12px;
  text-align: center;
  cursor: pointer;
  transition: .15s;
  color: var(--text-dim);
  font-size: 13px;
}
.dropzone:hover, .dropzone.drag {
  border-color: var(--accent);
  background: rgba(0, 212, 170, .06);
  color: var(--text);
}
.dz-icon { font-size: 20px; margin-bottom: 6px; color: var(--accent); }

/* 未填写车手档案时上传入口置灰不可用（点击会改为引导去填档案） */
.dropzone.disabled { opacity: .5; cursor: not-allowed; }
.dropzone.disabled:hover,
.dropzone.disabled.drag {
  border-color: var(--border);
  background: none;
  color: var(--text-dim);
}

/* 引导填档案时的弹窗说明文字 */
.modal-card p.guide { color: var(--accent); }

/* ---------------- 概览首页 ---------------- */
.home-hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 22px 24px;
  border-radius: 16px;
  margin-bottom: 16px;
  color: #fff;
  background: linear-gradient(135deg, #00d4aa 0%, #0b7d9c 58%, #123e6b 100%);
  box-shadow: 0 10px 30px rgba(0, 0, 0, .22);
}
.home-greet { font-size: 12.5px; opacity: .85; letter-spacing: .08em; }
.home-title { font-size: 22px; margin: 4px 0 6px; color: #fff; }
.home-sub { margin: 0; font-size: 13px; opacity: .92; }

.home-tsb {
  flex-shrink: 0;
  min-width: 94px;
  text-align: center;
  padding: 10px 14px;
  border-radius: 12px;
  background: rgba(255, 255, 255, .14);
  border: 1px solid rgba(255, 255, 255, .28);
}
.home-tsb:empty { display: none; }
.home-tsb-value { font-size: 24px; font-weight: 700; line-height: 1.1; }
.home-tsb-label { font-size: 11px; opacity: .85; margin-top: 2px; }
.home-tsb.warn { background: rgba(255, 176, 32, .24); border-color: rgba(255, 214, 130, .55); }
.home-tsb.good { background: rgba(0, 212, 170, .26); border-color: rgba(130, 245, 215, .55); }

.home-stats { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); margin-bottom: 16px; }

.home-week { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.home-week-bar { height: 8px; border-radius: 999px; background: var(--sunken); overflow: hidden; }
.home-week-bar > span { display: block; height: 100%; background: var(--accent); border-radius: 999px; transition: width .3s; }

.home-recent { display: flex; flex-direction: column; gap: 6px; }
.home-ride {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  text-align: left;
  padding: 11px 13px;
  border-radius: 10px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: inherit;
  cursor: pointer;
  transition: .15s;
}
.home-ride:hover { border-color: var(--accent); background: var(--card-hover); }
.home-ride-main { min-width: 0; }
.home-ride-title { font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.home-ride-sub { font-size: 12px; color: var(--text-dim); margin-top: 2px; }
.home-ride-metrics { flex-shrink: 0; font-size: 12.5px; color: var(--text-dim); white-space: nowrap; }

.home-actions { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
.home-action {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  border-radius: 10px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: inherit;
  font-size: 13.5px;
  cursor: pointer;
  transition: .15s;
}
.home-action:hover { border-color: var(--accent); background: var(--card-hover); }
.home-action > span { font-size: 16px; }

/* 首页精彩时刻（图片幻灯） */
.carousel-tools { display: flex; align-items: center; gap: 10px; }
/* 折叠式轮播：中间一张大图，两侧各露出相邻图片的一部分，把卡片两侧的空白填上。
   用原生横向滚动 + scroll-snap 实现：触摸滑动天然支持，不依赖任何库。 */
.carousel-viewport {
  position: relative;
  max-width: 900px;                /* 桌面端别铺满整宽，否则中间那张又会变得过大 */
  margin: 0 auto;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;           /* Firefox */
  -ms-overflow-style: none;
  padding: 2px 0 4px;
}
.carousel-viewport::-webkit-scrollbar { display: none; }
.carousel-track { display: flex; gap: 14px; }
.carousel-slide {
  position: relative;
  flex: 0 0 78%;                   /* 中间 78%，两侧各露约 11% */
  scroll-snap-align: center;
  opacity: .55;
  transform: scale(.965);
  transition: opacity .35s ease, transform .35s ease;
}
.carousel-slide.is-active { opacity: 1; transform: scale(1); }
/* 列表里按每张图各自（裁剪后的）比例展示 —— 不再锁 2:1：完整画面点一下看大图，
   见 .lightbox-*。只在特别高/宽的图上用 max-height 兜底，配合 object-fit: contain
   保证画面完整不被切、也不把页面撑得老长。 */
.carousel-slide img {
  display: block; width: 100%; height: auto;
  max-height: min(72vh, 680px);
  object-fit: contain; border-radius: 12px; cursor: zoom-in;
}
.carousel-caption {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 10px 14px;
  color: #fff; font-size: 13px;
  background: linear-gradient(transparent, rgba(0, 0, 0, .55));
}
.carousel-del {
  position: absolute; top: 8px; right: 8px;
  width: 28px; height: 28px; border-radius: 50%;
  border: none; cursor: pointer;
  background: rgba(0, 0, 0, .5); color: #fff; font-size: 13px; line-height: 1;
  opacity: 0; transition: .15s;
}
.carousel-slide:hover .carousel-del, .carousel-del:focus { opacity: 1; }
.carousel-nav {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 34px; height: 34px; border-radius: 50%;
  border: none; cursor: pointer; font-size: 18px; line-height: 1;
  background: rgba(0, 0, 0, .45); color: #fff; opacity: .8;
}
.carousel-nav:hover { opacity: 1; }
.carousel-nav.prev { left: 8px; }
.carousel-nav.next { right: 8px; }
.carousel-dots { display: flex; justify-content: center; gap: 6px; margin-top: 10px; }
.carousel-dot { width: 8px; height: 8px; padding: 0; border-radius: 50%; border: none; cursor: pointer; background: var(--border); }
.carousel-dot.active { background: var(--accent); }

@media (max-width: 520px) {
  .home-hero { padding: 18px; }
  .home-title { font-size: 19px; }
  .home-stats { grid-template-columns: repeat(2, 1fr); }
  .home-actions { grid-template-columns: repeat(2, 1fr); }
  .home-ride-metrics { font-size: 12px; }
  .carousel-viewport { max-width: none; }   /* 手机端铺满卡片宽度 */
}

/* 触屏没有 hover：删除按钮常显 */
@media (hover: none) {
  .carousel-del { opacity: 1; }
}

/* 查看大图（复用 .modal 的遮罩与居中） */
.lightbox-image {
  max-width: 96vw; max-height: 88vh;
  object-fit: contain; border-radius: 8px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .5);
}
.lightbox-close {
  position: fixed; top: 14px; right: 14px;
  width: 38px; height: 38px; border-radius: 50%;
  border: none; cursor: pointer; font-size: 16px; line-height: 1;
  background: rgba(0, 0, 0, .55); color: #fff;
}
.lightbox-close:hover { background: rgba(0, 0, 0, .78); }

/* ---------------- 列表 ---------------- */
.sidebar-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-dim);
  margin-top: 4px;
}

.ride-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }

.ride-item {
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--card);
  border: 1px solid transparent;
  cursor: pointer;
  transition: .15s;
  position: relative;
}
.ride-item:hover { background: var(--card-hover); }
.ride-item.active { border-color: var(--accent); background: rgba(0, 212, 170, .08); }
.ride-item .name { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding-right: 60px; }
.ride-item .sub { font-size: 11.5px; color: var(--text-dim); margin-top: 3px; display: flex; gap: 8px; }

/* 重命名 / 删除按钮：桌面悬停才出现，触屏常显。两者常驻右上角并排。 */
.ride-edit,
.ride-delete {
  position: absolute;
  top: 7px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 13px;
  line-height: 1;
  padding: 3px 6px;
  border-radius: 6px;
  cursor: pointer;
  opacity: 0;
  transition: opacity .15s, color .15s, background .15s;
}
.ride-delete { right: 7px; }
.ride-edit { right: 34px; }
.ride-item:hover .ride-edit,
.ride-item:hover .ride-delete,
.ride-item.active .ride-edit,
.ride-item.active .ride-delete { opacity: 1; }
.ride-edit:hover { background: var(--card-hover); color: var(--accent); }
.ride-delete:hover { background: var(--card-hover); color: var(--danger); }
@media (hover: none) { .ride-edit, .ride-delete { opacity: .75; } }

/* inline 重命名输入框 */
.ride-rename {
  width: 100%;
  background: var(--sunken);
  border: 1px solid var(--accent);
  border-radius: 6px;
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 4px 8px;
  outline: none;
}

/* ---------------- Tabs ---------------- */
.tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--border);
  /* 粘在顶栏下方：向下滚动时 Tab 常驻，随时可以切换 */
  position: sticky;
  top: 56px;
  z-index: 15;
  background: var(--bg);
}
.tab {
  background: none;
  border: none;
  color: var(--text-dim);
  padding: 10px 16px;
  cursor: pointer;
  font-size: 14px;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  font-family: inherit;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ---------------- 卡片 ---------------- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 16px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }

.empty { text-align: center; padding: 60px 20px; color: var(--text-dim); }
.empty-icon { font-size: 32px; margin-bottom: 10px; }
.hint { color: var(--text-dim); font-size: 13px; }

.ride-head { margin-bottom: 16px; }
.ride-head h2 { margin-bottom: 6px; }

/* ---------------- 指标卡 ---------------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(126px, 1fr));
  gap: 10px;
  margin-bottom: 4px;
}
.stat {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 13px;
}
.stat .label { font-size: 11.5px; color: var(--text-dim); margin-bottom: 5px; }
.stat .value { font-size: 19px; font-weight: 600; letter-spacing: -.01em; }
.stat .value .unit { font-size: 12px; color: var(--text-dim); font-weight: 400; margin-left: 3px; }
.stat .sub { font-size: 11.5px; color: var(--text-dim); margin-top: 3px; }
.stat.accent .value { color: var(--accent); }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 980px) { .grid-2 { grid-template-columns: 1fr; } }

.chart-box { position: relative; height: 260px; }
.chart-box.tall { height: 320px; }
.chart-msg {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  font-size: 13px;
}

/* 功率曲线（横向条） */
.curve-grid { display: flex; flex-direction: column; gap: 7px; }

/* ---------------- 区间查询 ---------------- */
/* 卡片可左滑 / 点「收起」临时隐藏；刷新页面或切换骑行后恢复 */
.segment-card {
  touch-action: pan-y;   /* 垂直照常滚动，水平手势交给 JS 做左滑 */
  transition: transform .18s ease, opacity .18s ease;   /* 收起 / 回弹动画 */
}
.segment-card.dragging { transition: none; }             /* 跟手期间不要过渡 */
.segment-card .card-head .muted { margin-left: auto; }
.card-collapse {
  flex: 0 0 auto;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: transparent;
  color: var(--text-dim);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
  transition: color .15s, border-color .15s;
}
.card-collapse:hover { color: var(--text); border-color: var(--accent); }

/* 维度切换与起止输入分成两组：宽度够时并排，窄屏时输入组整体落到下一行 ——
   否则「按距离/按时间」会和「从…」挤在同一行（手机上尤其明显）。 */
.segment-form {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 12px;
  margin-bottom: 12px;
}
.segment-range {
  display: flex;
  flex-wrap: nowrap;   /* 不换行：靠收缩把「从/到/查询」压在同一行，避免按钮被挤到下一行 */
  align-items: center;
  gap: 10px 12px;
  /* 关键：flex 容器默认按 min-content 撑住，窄屏会直接横向溢出，必须放开 */
  min-width: 0;
}
.segment-range .btn { flex: 0 0 auto; }
.segment-dim {
  display: flex;
  flex: 0 0 auto;   /* 两个 tab 始终保持完整，不参与压缩 */
  gap: 4px;
  padding: 3px;
  border-radius: 9px;
  background: var(--sunken);
}
.seg-tab {
  border: none;
  background: transparent;
  color: var(--text-dim);
  font: inherit;
  font-size: 12.5px;
  padding: 6px 12px;
  border-radius: 7px;
  cursor: pointer;
  transition: .15s;
}
.seg-tab.active { background: var(--accent); color: var(--on-accent); font-weight: 600; }
/* 带前置文字的输入（「从 / 到」、训练目标）：标签与输入框同排，输入框默认定宽 */
.seg-field,
.training-field {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  font-size: 12px;
  color: var(--text-dim);
}
.seg-field input,
.training-field input {
  width: 110px;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--sunken);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
}
.seg-field input:focus,
.training-field input:focus { outline: none; border-color: var(--accent); }
/* 只有区间查询需要吸附剩余宽度：窄屏时靠收缩把「从/到/查询」压在同一行。
   注意别把这个规则放到全局 —— 训练目标表单共用 .training-field，被拉宽会错位。 */
.segment-range .seg-field { flex: 1 1 auto; }
.segment-range .seg-field input {
  flex: 1 1 auto;
  width: auto;        /* 交给 flex 决定，覆盖上面的定宽 */
  min-width: 64px;    /* 再窄也得能看清输入的数字 */
  max-width: 130px;
}
#segResult:not(:empty) { margin-top: 4px; }

/* ---------------- 爬山线路图（高德地图） ---------------- */
.route-map {
  position: relative;
  z-index: 0;   /* 建立层叠上下文，别让地图控件盖过顶栏/弹窗 */
  height: 340px;
  border-radius: 10px;
  overflow: hidden;
  background: var(--sunken);
}
/* 速度着色图例 */
.route-legend { margin-top: 10px; font-size: 11px; color: var(--text-dim); }
.route-legend .legend-bar { display: flex; height: 10px; border-radius: 5px; overflow: hidden; }
.route-legend .legend-swatch { flex: 1; }
.route-legend .legend-labels { display: flex; justify-content: space-between; margin-top: 4px; }
@media (max-width: 520px) { .route-map { height: 260px; } }

/* ---------------- 爬坡段 ---------------- */
.climb-list { display: flex; flex-direction: column; gap: 8px; }
.climb-row {
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 9px;
  cursor: pointer;
  transition: border-color .15s;
}
.climb-row:hover { border-color: var(--accent); }
/* 这段爬坡正被高亮在地图上：卡片同步给个选中态，两边对得上 */
.climb-row.active { border-color: var(--accent); background: var(--card-hover); }
.climb-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 4px; }
.climb-index { font-size: 11.5px; color: var(--text-dim); }
.climb-grade { font-size: 15px; font-weight: 700; color: var(--accent); }
/* 环法式爬坡等级标识（HC / 1级 …）：难度从高到低依次降温，无等级时整块不渲染 */
.climb-cat {
  font-size: 10.5px;
  font-weight: 700;
  line-height: 1;
  padding: 2px 6px;
  border: 1px solid currentColor;
  border-radius: 999px;
  align-self: center;
  white-space: nowrap;
}
.climb-cat-hc { color: var(--danger); }
.climb-cat-1 { color: var(--pink); }
.climb-cat-2 { color: var(--warn); }
.climb-cat-3 { color: var(--accent); }
.climb-cat-4 { color: var(--text-dim); }
.climb-range { margin-left: auto; font-size: 11.5px; color: var(--text-dim); }
/* 爬坡数据行：每项「字段名 + 值」，字段名淡一点、值亮一点，避免一堆裸数字看不懂 */
.climb-stats { display: flex; flex-wrap: wrap; gap: 2px 12px; font-size: 12px; color: var(--text-dim); }
.climb-stat { display: inline-flex; align-items: baseline; gap: 4px; white-space: nowrap; }
.climb-stat .k { font-size: 11px; color: var(--text-dim); opacity: .8; }
.climb-stat .v { color: var(--text); }

/* 「含 N 处短暂下坡」：说明这段爬坡跨过了中间的小下坡 */
.climb-head-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

/* 截图识别的预览表格 */
.scan-table-wrap {
  max-height: 46vh;
  overflow-y: auto;
  margin: 8px 0 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
}

.scan-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}

.scan-table th,
.scan-table td {
  padding: 7px 10px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.scan-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--bg-soft);
  color: var(--text-dim);
  font-weight: 500;
}

.scan-table tr:last-child td { border-bottom: 0; }

.scan-table td:first-child {
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

.climb-merged {
  font-size: 11px;
  color: var(--warn);
  padding: 1px 6px;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--warn) 40%, transparent);
  background: color-mix(in srgb, var(--warn) 12%, transparent);
  white-space: nowrap;
}
/* 「展开全部 / 收起」：整行通栏，弱化存在感，不跟爬坡行抢注意力 */
.climb-toggle {
  width: 100%;
  margin-top: 8px;
  padding: 6px;
  font-size: 12px;
  color: var(--text-dim);
}
.climb-toggle:hover { color: var(--accent); border-color: var(--accent); }

/* ---------------- 训练管理 ---------------- */
/* 训练目标：标签列定宽，两行输入框自然对齐；保存按钮贴到所在行行尾 */
.training-form { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 12px; margin-top: 12px; }
.training-label { min-width: 84px; }
.training-form .btn { margin-left: auto; }
.training-alerts { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.training-alert {
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 12.5px;
  color: var(--text-dim);
}
.training-alert.good { border-color: rgba(34, 197, 94, .5); color: #22c55e; }
.training-alert.warn { border-color: rgba(249, 115, 22, .55); color: #f97316; }

/* ---------------- 训练日历 ---------------- */
.cal-nav { display: flex; gap: 6px; }
.cal-legend { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; margin-bottom: 10px; font-size: 11px; color: var(--text-dim); }
.cal-legend-swatch { width: 20px; height: 10px; border-radius: 3px; }
.cal-legend-note { margin-left: 6px; }
.cal-weekdays,
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 6px;
}
.cal-weekdays { margin-bottom: 6px; }
.cal-weekdays span { text-align: center; font-size: 11.5px; color: var(--text-dim); padding: 2px 0; }
.cal-cell {
  min-height: 78px;
  padding: 6px 7px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--card);
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 11px;
  color: var(--text-dim);
}
.cal-cell.blank { border-color: transparent; background: transparent; }
.cal-cell.has-ride { cursor: pointer; box-shadow: inset 0 0 0 2px transparent; transition: box-shadow .15s ease; }
.cal-cell.has-ride:hover,
.cal-cell.selected { box-shadow: inset 0 0 0 2px var(--accent); }
.cal-cell .cal-day { font-size: 12px; font-weight: 600; color: var(--text); }
.cal-cell .cal-day.today { color: var(--accent); }
.cal-cell .cal-km { font-size: 12.5px; font-weight: 600; color: var(--text); }
.cal-cell .cal-km .unit { margin-left: 1px; font-size: 10px; font-weight: 400; color: var(--text-dim); }
.cal-cell .cal-sub { display: flex; flex-wrap: wrap; gap: 6px; }
.cal-cell .cal-tss { color: var(--accent); font-weight: 600; }
.cal-detail { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border); }
.cal-detail h4 { margin-bottom: 8px; font-size: 13px; }
.cal-ride {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
  padding: 7px 9px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 12.5px;
  cursor: pointer;
  transition: border-color .15s;
}
.cal-ride:hover { border-color: var(--accent); }
.cal-ride .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.cal-ride .meta { color: var(--text-dim); font-size: 11.5px; }
.curve-row { display: grid; grid-template-columns: 56px 1fr 82px; align-items: center; gap: 10px; font-size: 12.5px; }
.curve-label { color: var(--text-dim); text-align: right; }
.curve-bar { height: 14px; background: var(--sunken); border-radius: 4px; overflow: hidden; }
.curve-bar > span {
  display: block;
  height: 100%;
  border-radius: 4px;
  /* JS 会按训练区间改写这个颜色，这里只是兜底 */
  background: var(--text-dim);
}
.curve-value {
  text-align: right;
  display: flex;
  flex-direction: column;
  gap: 1px;
  align-items: flex-end;
}
.curve-watts { font-size: 12.5px; color: var(--text); font-variant-numeric: tabular-nums; }
.curve-pct { font-size: 10.5px; font-weight: 600; font-variant-numeric: tabular-nums; }

/* 流式输出时的光标 */
.markdown.streaming::after {
  content: '▍';
  color: var(--accent);
  animation: blink 1s step-end infinite;
  margin-left: 2px;
}
@keyframes blink { 50% { opacity: 0; } }
.typing { color: var(--text-dim); font-style: italic; }

/* FTP 更新提醒 */
.advice {
  padding: 10px 14px;
  border-radius: 9px;
  font-size: 13px;
  line-height: 1.65;
  margin-bottom: 12px;
  border: 1px solid var(--border);
  background: var(--bg-soft);
}
.advice.up { border-color: rgba(0, 212, 170, .45); background: rgba(0, 212, 170, .08); color: var(--accent); }
.advice.down { border-color: rgba(255, 176, 32, .45); background: rgba(255, 176, 32, .08); color: var(--warn); }
.advice.stable { color: var(--text-dim); }
.advice strong { color: inherit; }

/* ---------------- 区间条 ---------------- */
.zones { display: flex; flex-direction: column; gap: 10px; }
.zone-row {
  display: grid;
  grid-template-columns: 116px 1fr 54px;
  align-items: center;
  gap: 10px;
}
/* 名称 + 区间范围（如 Z4 阈值 / 152–171）上下两行，信息更完整 */
.zone-name { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.zone-title { font-size: 12.5px; color: var(--text); line-height: 1.25; }
.zone-range {
  font-size: 10.5px;
  color: var(--text-dim);
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
}
.zone-bar { height: 12px; background: var(--sunken); border-radius: 999px; overflow: hidden; }
.zone-bar > span { display: block; height: 100%; border-radius: 999px; transition: width .35s ease; }
.zone-percent {
  text-align: right;
  font-size: 12.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
/* 没练到的区间仍列出（方便看出强度分布），但整体淡化。
   修饰类刻意不叫 "empty"：全局 .empty 是空状态占位（padding: 60px 20px、居中），
   会和这里的行撞上，把 0% 的行撑成 150px 高、文字也被居中。 */
.zone-row.zone-empty { opacity: .42; }

/* ---------------- Markdown ---------------- */
.markdown { line-height: 1.7; font-size: 13.5px; word-wrap: break-word; }
.markdown h1, .markdown h2, .markdown h3 { margin: 16px 0 8px; font-size: 15px; color: var(--accent); }
.markdown h3:first-child, .markdown > :first-child { margin-top: 0; }
.markdown p { margin: 8px 0; }
.markdown ul, .markdown ol { margin: 8px 0; padding-left: 22px; }
.markdown li { margin: 4px 0; }
.markdown table { border-collapse: collapse; margin: 10px 0; width: 100%; font-size: 12.5px; }
.markdown th, .markdown td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
.markdown th { background: var(--bg-soft); }
.markdown blockquote { margin: 10px 0; padding: 8px 14px; border-left: 3px solid var(--warn); background: rgba(255, 176, 32, .07); color: var(--text-dim); border-radius: 0 8px 8px 0; }
.markdown code { background: var(--sunken); padding: 2px 6px; border-radius: 5px; font-size: 12.5px; }
.markdown strong { color: var(--text-strong); }
.markdown hr { border: none; border-top: 1px solid var(--border); margin: 14px 0; }

/* ---------------- 聊天 ---------------- */
.chat-card { display: flex; flex-direction: column; height: calc(100vh - 160px); }
.chat-log { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; padding: 4px 2px 12px; }
.chat-hint { color: var(--text-dim); font-size: 13px; line-height: 1.8; background: var(--bg-soft); padding: 14px 16px; border-radius: 10px; }
.msg { max-width: 78%; padding: 10px 14px; border-radius: 12px; font-size: 13.5px; line-height: 1.65; }
.msg.user { align-self: flex-end; background: rgba(77, 159, 255, .16); border: 1px solid rgba(77, 159, 255, .3); }
.msg.assistant { align-self: flex-start; background: var(--bg-soft); border: 1px solid var(--border); }
.msg.pending { color: var(--text-dim); font-style: italic; }
.chat-input { display: flex; gap: 10px; padding-top: 12px; border-top: 1px solid var(--border); }
.chat-input input {
  flex: 1;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 9px;
  font-family: inherit;
  font-size: 13.5px;
}
.chat-input input:focus { outline: none; border-color: var(--accent); }

/* ---------------- 弹窗 ---------------- */
.modal {
  position: fixed;
  inset: 0;
  background: var(--overlay-strong);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  backdrop-filter: blur(2px);
}
.modal-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 22px 24px;
  width: min(400px, 92vw);
}
.modal-card h3 { margin-bottom: 6px; }
.modal-card p { margin: 0 0 16px; line-height: 1.6; }
.modal-card label { display: block; font-size: 12.5px; color: var(--text-dim); margin-bottom: 12px; }
.modal-card input {
  display: block;
  width: 100%;
  margin-top: 6px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 12px;
  border-radius: 8px;
  font-family: inherit;
  font-size: 14px;
}
.modal-card input:focus { outline: none; border-color: var(--accent); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.modal-head h3 { margin-bottom: 0; }
.modal-close {
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  background: transparent;
  color: var(--text-dim);
}
.modal-close:hover { background: var(--sunken); color: var(--text); }

/* ---------------- 图片裁剪弹窗 ---------------- */
.crop-card { width: min(720px, 94vw); }
/* 比例切换：点一下锁形状，选「自由」则拖手柄随意调 */
.crop-ratios { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 10px; }
.crop-ratio {
  padding: 4px 11px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--border); background: transparent;
  color: var(--text-dim); font-size: 12.5px; line-height: 1.6;
}
.crop-ratio:hover { color: var(--text); border-color: var(--text-dim); }
.crop-ratio.is-active {
  background: var(--accent); border-color: var(--accent);
  color: var(--on-accent); font-weight: 600;
}
.crop-stage {
  position: relative;
  width: 100%;
  height: clamp(300px, 56vh, 520px);
  background: var(--sunken);
  border-radius: 10px;
  overflow: hidden;
  touch-action: none;
  user-select: none;
}
.crop-stage img {
  position: absolute;
  left: 0;
  top: 0;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}
.crop-box {
  position: absolute;
  box-sizing: border-box;
  border: 2px solid #fff;
  border-radius: 4px;
  cursor: move;
  touch-action: none;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, .55);
}
.crop-handle {
  position: absolute;
  width: 12px;
  height: 12px;
  background: #fff;
  border: 1px solid rgba(0, 0, 0, .45);
  border-radius: 3px;
  box-shadow: 0 0 3px rgba(0, 0, 0, .3);
  touch-action: none;
}
.crop-handle[data-dir='nw'] { left: -7px; top: -7px; cursor: nwse-resize; }
.crop-handle[data-dir='n']  { left: 50%; top: -7px; margin-left: -6px; cursor: ns-resize; }
.crop-handle[data-dir='ne'] { right: -7px; top: -7px; cursor: nesw-resize; }
.crop-handle[data-dir='e']  { right: -7px; top: 50%; margin-top: -6px; cursor: ew-resize; }
.crop-handle[data-dir='se'] { right: -7px; bottom: -7px; cursor: nwse-resize; }
.crop-handle[data-dir='s']  { left: 50%; bottom: -7px; margin-left: -6px; cursor: ns-resize; }
.crop-handle[data-dir='sw'] { left: -7px; bottom: -7px; cursor: nesw-resize; }
.crop-handle[data-dir='w']  { left: -7px; top: 50%; margin-top: -6px; cursor: ew-resize; }

/* ---------------- Toast ---------------- */
.toast {
  position: fixed;
  bottom: 26px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--card-hover);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 20px;
  font-size: 13px;
  z-index: 100;
  box-shadow: 0 10px 32px var(--shadow-soft);
  max-width: 80vw;
}
.toast.error { border-color: rgba(255, 92, 108, .5); color: var(--danger-text); }
.toast.ok { border-color: rgba(0, 212, 170, .5); color: var(--accent); }

/* 滚动条 */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #2c3a48; border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: #3a4b5c; }

/* ======================================================================
 * 响应式适配：桌面 → 平板 → 手机
 * ==================================================================== */

.topbar-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* 桌面下隐藏、窄屏才出现的控件 */
.icon-btn {
  display: none;
  padding: 8px 11px;
  font-size: 15px;
  line-height: 1;
}
.sidebar-close { display: none; position: absolute; top: 10px; right: 10px; z-index: 1; }

/* 抽屉遮罩 */
.backdrop {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  z-index: 39;
  backdrop-filter: blur(1px);
}

/* AI 回答里的表格 / 代码块：窄屏横向滚动，而不是撑破布局 */
.table-scroll { overflow-x: auto; margin: 10px 0; }
.table-scroll table { margin: 0; min-width: 320px; }
.markdown pre {
  overflow-x: auto;
  background: var(--sunken);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 12.5px;
}
.markdown img { max-width: 100%; height: auto; }

/* ---------- 平板：侧栏收窄、双列改单列 ---------- */
@media (max-width: 1024px) {
  .sidebar { width: 236px; flex-basis: 236px; padding: 14px; }
  .main { padding: 16px 18px 52px; }
  .grid-2 { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); }
}

/* ---------- 手机 / 竖屏平板：侧栏改抽屉 ---------- */
@media (max-width: 860px) {
  .icon-btn { display: inline-block; }

  .layout { display: block; min-height: auto; }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    height: 100vh;
    width: min(300px, 84vw);
    flex-basis: auto;
    z-index: 40;
    background: var(--bg-soft);
    padding: 52px 14px 20px;
    overflow-y: auto;
    transform: translateX(-102%);
    transition: transform .22s ease;
    box-shadow: 8px 0 40px var(--shadow-soft);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-close { display: inline-block; }

  .main { padding: 14px 14px 56px; }
  .topbar { padding: 0 12px; }
  .brand-text { display: none; }
  .brand { padding: 6px 8px; }   /* 窄屏只剩 🚴，扩大点击热区 */
  .topbar-right { gap: 8px; }
  #aiBadge { max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  .stat-grid { grid-template-columns: repeat(auto-fill, minmax(108px, 1fr)); gap: 8px; }
  .stat { padding: 9px 11px; }
  .stat .value { font-size: 17px; }

  .chat-card { height: calc(100vh - 190px); }
}

/* ---------- 手机上顶栏挤不下：账号按钮收进点头像弹出的菜单 ---------- */
@media (max-width: 640px) {
  /* 只隐藏这四个入口（它们都在 #userMenu 里有对应项），其余顶栏按钮照旧 */
  #profileBtn,
  #nicknameBtn,
  #passwordBtn,
  #logoutBtn { display: none; }

  #userMenuBtn .user-caret { display: inline; }
  .user-name { max-width: 88px; }   /* 按钮里空间富裕一点，别一上来就省略号 */
}

/* 宽屏不用这个菜单：那几个入口本来就直接摆在顶栏上 */
@media (min-width: 641px) {
  #userMenu { display: none !important; }
}

/* ---------- 小屏手机 ---------- */
@media (max-width: 520px) {
  body { font-size: 13.5px; }
  h2 { font-size: 17px; }

  /* 小屏顶栏进一步收紧：隐藏 AI 徽标，压缩按钮与用户名，避免溢出 */
  #aiBadge { display: none; }
  .topbar-right { gap: 6px; }
  #loginBtn { padding: 8px 12px; font-size: 12.5px; }
  .imx-map { height: 240px; }

  /* 路书统计：4 个卡片排成一行（缩小字号 / 间距以适配窄屏） */
  #imxDetailStats { grid-template-columns: repeat(4, 1fr); gap: 6px; }
  #imxDetailStats .stat { padding: 8px 9px; }
  #imxDetailStats .stat .label { font-size: 11px; white-space: nowrap; }
  #imxDetailStats .stat .value { font-size: 15px; }
  #imxDetailStats .stat .sub { font-size: 10px; line-height: 1.35; }

  .badge {
    font-size: 11px;
    padding: 3px 8px;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .user-name { max-width: 48px; }

  /* Tab 横向滚动，不换行 */
  .tabs { overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { padding: 10px 12px; white-space: nowrap; font-size: 13.5px; }

  .card { padding: 13px 14px; border-radius: 10px; margin-bottom: 12px; }
  .card-head { flex-wrap: wrap; gap: 8px; align-items: flex-start; }
  .ride-head { margin-bottom: 12px; }

  .chart-box { height: 205px; }
  .chart-box.tall { height: 245px; }

  /* 区间 / 功率曲线：压缩标签列，避免溢出 */
  .zone-row { grid-template-columns: 92px 1fr 46px; gap: 8px; }
  .zone-title { font-size: 12px; }
  .zone-range { font-size: 10px; }
  .zone-bar { height: 11px; }
  .curve-row { grid-template-columns: 38px 1fr 68px; gap: 8px; font-size: 12px; }
  .curve-label { font-size: 11.5px; }
  .curve-watts { font-size: 12px; }
  .curve-pct { font-size: 10px; }

  .grid-2 { gap: 12px; }
  .msg { max-width: 92%; }
  .chat-log { gap: 10px; }

  .modal-card { padding: 18px; width: min(360px, 94vw); }
  .auth-card { padding: 22px 18px 18px; }

  /* 表单控件在 iOS 上必须 >=16px，否则聚焦时页面会被放大 */
  .auth-card input, .modal-card input, .chat-input input, .select { font-size: 16px; }
  .select { padding: 8px 10px; }

  .btn { padding: 9px 13px; }
}

/* ---------- 超窄屏 ---------- */
@media (max-width: 360px) {
  .stat-grid { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); }
  .stat .value { font-size: 16px; }
  .tab { padding: 9px 10px; }
}

/* ---------- 触屏：放大可点区域 ---------- */
@media (hover: none) and (pointer: coarse) {
  .btn { min-height: 40px; }
  .ride-item { padding: 12px 13px; }
}

/* ---------- iOS 安全区 ---------- */
@supports (padding: env(safe-area-inset-bottom)) {
  .main { padding-bottom: calc(56px + env(safe-area-inset-bottom)); }
  .chat-input { padding-bottom: env(safe-area-inset-bottom); }
  .sidebar { padding-bottom: calc(20px + env(safe-area-inset-bottom)); }
}

/* ---------- 横屏（手机横过来）：给图表更多高度 ---------- */
@media (orientation: landscape) and (max-height: 560px) {
  .chart-box { height: 230px; }
  .chart-box.tall { height: 265px; }
  .chat-card { height: calc(100vh - 150px); }
  .topbar { height: 48px; }
  .layout { min-height: calc(100vh - 48px); }
  .tabs { top: 48px; }
}

/* ======================================================================
 * 大屏优化
 *
 * 之前 metrics 网格用 auto-fill，在 1800px 屏上会膨胀到 10 列、
 * 末行只剩 2 张卡；图表被拉成 5.5:1 的扁条；内容区也没有宽度上限。
 * 下面用显式列数 + 比例高度把它们约束住。
 * ==================================================================== */

/* 内容区限宽并居中，避免超宽屏下单行文本过长、元素被拉散 */
@media (min-width: 1100px) {
  .main {
    max-width: 1320px;
    margin-inline: auto;
  }
}

/* 指标卡：改用固定列数（auto-fill 在大屏没有上限） */
@media (min-width: 861px) {
  .stat-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
  }
}

@media (min-width: 1100px) {
  .stat-grid {
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 12px;
  }
  .stat { padding: 12px 14px; }
  .stat .value { font-size: 20px; }
  .stat .label { font-size: 12px; }
}

/* 图表：宽屏按比例给高度，否则曲线被压平看不清波动 */
@media (min-width: 861px) {
  .chart-box {
    /* 必须显式锁宽：否则 aspect-ratio 会为了满足 min-height 反过来撑开宽度 */
    width: 100%;
    height: auto;
    aspect-ratio: 3.4 / 1;
    max-height: 380px;
  }
  .chart-box.tall {
    width: 100%;
    height: auto;
    aspect-ratio: 2.8 / 1;
    max-height: 420px;
  }
  /* canvas 绝对定位填充，避免它反过来把容器撑大 */
  .chart-box canvas {
    position: absolute;
    inset: 0;
    width: 100% !important;
    height: 100% !important;
  }
}

/* 宽屏下卡片内边距与标题层级都放大一档 */
@media (min-width: 861px) {
  .card { padding: 18px 20px; }
  .card-head { margin-bottom: 14px; }
  .ride-head { margin-bottom: 18px; }
  .ride-head h2 { font-size: 22px; }
  .zone-row { grid-template-columns: 132px 1fr 58px; gap: 12px; }
  .zone-title { font-size: 13px; }
  .zone-range { font-size: 11px; }
  .curve-row { grid-template-columns: 64px 1fr 90px; }
}


/* ======================================================================
 * 浅色主题
 * ==================================================================== */

[data-theme="light"] {
  --bg: #f4f6fa;
  --bg-soft: #ffffff;
  --card: #ffffff;
  --card-hover: #eef2f7;
  --border: #dfe5ee;
  --text: #1b2430;
  --text-dim: #64748b;
  --accent: #0f9b8e;
  --accent-2: #2563eb;
  --warn: #b45309;
  --danger: #dc2626;
  --pink: #db2777;

  --sunken: #eaeff6;
  --on-accent: #ffffff;
  --text-strong: #0d1520;
  --danger-text: #b91c1c;
  --overlay: rgba(15, 23, 42, .38);
  --overlay-strong: rgba(15, 23, 42, .46);
  --shadow-color: rgba(15, 23, 42, .12);
  --shadow-soft: rgba(15, 23, 42, .16);
  --topbar-from: #ffffff;
}

[data-theme="light"] .auth-screen {
  background: radial-gradient(1200px 600px at 50% -10%, #e6edf7, #f4f6fa 60%);
}
[data-theme="light"] .topbar { box-shadow: 0 1px 0 rgba(15, 23, 42, .04); }
[data-theme="light"] .card { box-shadow: 0 1px 3px rgba(15, 23, 42, .05); }
[data-theme="light"] .stat { background: var(--sunken); }
[data-theme="light"] .markdown code,
[data-theme="light"] .markdown pre { color: #1b2430; }
[data-theme="light"] .markdown th { background: var(--sunken); }
[data-theme="light"] .markdown blockquote { color: #7c5a15; }
[data-theme="light"] .chat-hint,
[data-theme="light"] .msg.assistant { background: var(--sunken); }
[data-theme="light"] .msg.user { background: rgba(37, 99, 235, .09); border-color: rgba(37, 99, 235, .28); }
[data-theme="light"] .ride-item:hover { background: var(--card-hover); }
[data-theme="light"] .ride-item.active { background: rgba(15, 155, 142, .09); }
[data-theme="light"] .zone-bar,
[data-theme="light"] .curve-bar { background: #dde5ef; }
[data-theme="light"] .badge { background: var(--sunken); }
[data-theme="light"] .toast { background: var(--card); }
[data-theme="light"] ::-webkit-scrollbar-thumb { background: #c3ccd9; }
[data-theme="light"] ::-webkit-scrollbar-thumb:hover { background: #aab6c6; }
[data-theme="light"] .chart-msg,
[data-theme="light"] .muted { color: var(--text-dim); }

/* ---------- 主题切换按钮 ---------- */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  font-size: 15px;
  line-height: 1;
  border-radius: 9px;
}


/* ---------------- 首页精彩短片（视频托管 OSS） ---------------- */
/* 分片上传进度：条 + 文字（百分比与已传字节），失败/取消后整块隐藏 */
.upload-progress { display: flex; align-items: center; gap: 10px; margin: 2px 0 12px; }
.upload-progress-bar {
  flex: 1; height: 6px; border-radius: 999px; overflow: hidden;
  background: var(--sunken); border: 1px solid var(--border);
}
.upload-progress-bar span {
  display: block; width: 0; height: 100%; border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width .2s ease;
}
.upload-progress .muted { white-space: nowrap; }
.video-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }
.video-card {
  position: relative; display: block; width: 100%; padding: 0;
  aspect-ratio: 16 / 9; border: 1px solid var(--border); border-radius: 12px;
  background: var(--sunken); overflow: hidden; cursor: pointer;
  transition: transform .16s ease, border-color .16s ease, box-shadow .16s ease;
}
.video-card:hover {
  transform: translateY(-2px); border-color: var(--accent);
  box-shadow: 0 12px 26px var(--shadow-color);
}
.video-card video,
.video-card img { display: block; width: 100%; height: 100%; object-fit: cover; }
.video-play {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  display: grid; place-items: center; width: 42px; height: 42px;
  border-radius: 50%; font-size: 15px; color: #fff;
  background: rgba(0, 0, 0, .45); pointer-events: none;
}
.video-card-title {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 22px 10px 8px;
  font-size: 12.5px; color: #fff; text-align: left;
  background: linear-gradient(transparent, rgba(0, 0, 0, .6));
}
.video-del {
  position: absolute; top: 8px; right: 8px; width: 26px; height: 26px;
  border-radius: 50%; border: none; cursor: pointer;
  background: rgba(0, 0, 0, .5); color: #fff; font-size: 12px; line-height: 1;
}
.video-del:hover { background: rgba(220, 38, 38, .85); }
.video-lightbox {
  position: fixed; inset: 0; z-index: 80; display: flex;
  align-items: center; justify-content: center; padding: 20px;
  background: rgba(0, 0, 0, .86);
}
.video-lightbox video { max-width: 96vw; max-height: 86vh; border-radius: 10px; background: #000; }
.video-lightbox-close {
  position: fixed; top: 14px; right: 16px; width: 38px; height: 38px;
  border-radius: 50%; border: none; cursor: pointer; font-size: 16px;
  color: #fff; background: rgba(255, 255, 255, .18);
}
.video-lightbox-close:hover { background: rgba(255, 255, 255, .32); }


/* ---------------- 精美路线管理（仅管理员） ---------------- */
.featured-form { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }
.featured-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.featured-row input,
.featured-row select { flex: 1 1 170px; min-width: 0; }
.featured-form input,
.featured-form select,
.featured-form textarea {
  padding: 9px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: 13.5px;
  font-family: inherit;
}
.featured-form input:focus,
.featured-form select:focus,
.featured-form textarea:focus { outline: none; border-color: var(--accent); }
.featured-form textarea { width: 100%; resize: vertical; }
.featured-admin-list { display: flex; flex-direction: column; gap: 8px; }
.featured-admin-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--card);
}
.featured-admin-main { min-width: 0; flex: 1; }
.featured-admin-name { font-weight: 600; margin-bottom: 3px; }


/* ---- 精美路线：管理列表缩略图 + 「是否显示」开关 ---- */
.featured-admin-thumb {
  width: 84px;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border-radius: 8px;
  flex: 0 0 auto;
  cursor: pointer;   /* 点缩略图同样打开路书链接 */
}
.featured-admin-title {
  font-weight: 600;
  text-decoration: none;
  color: inherit;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.switch { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; user-select: none; flex: 0 0 auto; position: relative; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch-track {
  width: 38px; height: 22px; border-radius: 999px; background: #cbd5e1;
  position: relative; transition: background .18s ease;
}
.switch-track::after {
  content: ''; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px;
  border-radius: 50%; background: #fff; transition: transform .18s ease;
}
.switch input:checked + .switch-track { background: var(--accent, #0d9488); }
.switch input:checked + .switch-track::after { transform: translateX(16px); }
.switch-label { font-size: 12px; color: var(--muted); }


/* 下拉选择（难度）：用原生控件但跟随主题配色 */
.featured-form select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
                    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 16px) 50%, calc(100% - 11px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 30px;
  cursor: pointer;
}


/* ---------------- 头像 ---------------- */
.avatar-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 0 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 14px;
}

.avatar-preview {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--sunken);
  border: 1px solid var(--border);
  flex: 0 0 auto;
}

.avatar-actions { display: flex; flex-direction: column; gap: 4px; }
.avatar-actions p { margin: 0; }

.user-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--border);
}


/* ---------------- 骑游计划（卡片列表） ---------------- */
.plan-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
  margin-top: 12px;
}

.plan-card {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--card);
  overflow: hidden;
}

.plan-card-cover {
  aspect-ratio: 16 / 9;
  background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 22%, transparent), transparent);
  display: grid;
  place-items: center;
  font-size: 26px;
  color: var(--accent);
  overflow: hidden;
}

.plan-card-cover img { width: 100%; height: 100%; object-fit: cover; }

.plan-card-body { padding: 12px 14px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.plan-card-when { font-size: 12px; color: var(--accent); font-weight: 600; }
.plan-card-title { font-size: 15px; font-weight: 650; }
.plan-card-desc {
  font-size: 12.5px;
  color: var(--text-dim);
  line-height: 1.55;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.plan-card-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: auto;
  padding-top: 8px;
  border-top: 1px solid color-mix(in srgb, var(--border) 60%, transparent);
  font-size: 12px;
  color: var(--text-dim);
}

.plan-card-foot .btn { padding: 4px 10px; font-size: 12px; }
.plan-card-actions { display: flex; gap: 6px; margin-left: auto; }

.plan-preview { display: flex; flex-wrap: wrap; gap: 8px; }
.plan-preview img {
  width: 72px;
  height: 72px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
}


/* 编辑弹窗里的已有图：带删除按钮 */
.plan-thumb {
  position: relative;
  display: inline-block;
  line-height: 0;
}

.plan-thumb img {
  width: 72px;
  height: 72px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.plan-thumb-del {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: none;
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  line-height: 20px;
  text-align: center;
  cursor: pointer;
  padding: 0;
}

.plan-thumb-del:hover { filter: brightness(1.1); }
.plan-thumb-del:disabled { opacity: .6; cursor: default; }
