/* ============ Tesla 数据中心 · Material 3 风格设计系统 ============ */
:root {
  --red: #e82127;
  --red-dark: #c7181d;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #eef1f4;
  --surface-3: #e4e9ee;
  --text: #171b20;
  --text-2: #5b6470;
  --text-3: #8b95a1;
  --outline: #d8dee4;
  --green: #1f9d55;
  --green-bg: #e5f5ec;
  --amber: #d97706;
  --amber-bg: #fdf0e0;
  --blue: #2563eb;
  --blue-bg: #e8effd;
  --red-bg: #fdeaea;
  --shadow: 0 1px 2px rgba(16, 20, 24, .05), 0 4px 16px rgba(16, 20, 24, .06);
  --radius: 20px;
  --radius-s: 14px;
  --nav-h: 66px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
html[data-theme="dark"] {
  --bg: #0e1114;
  --surface: #171c21;
  --surface-2: #1f252c;
  --surface-3: #272e36;
  --text: #eceff2;
  --text-2: #a3adba;
  --text-3: #6b7683;
  --outline: #2d353e;
  --green: #34c077;
  --green-bg: #12291d;
  --amber: #f0a13c;
  --amber-bg: #2d2110;
  --blue: #6b9df5;
  --blue-bg: #16233d;
  --red-bg: #33161a;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 20px rgba(0,0,0,.35);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: -apple-system, "PingFang SC", "HarmonyOS Sans SC", "MiSans", "Noto Sans SC", Roboto, "Segoe UI", sans-serif;
  background: var(--bg); color: var(--text);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
#app { display: flex; flex-direction: column; min-height: 100dvh; }

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top, 0px) + 14px) 18px 12px;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--outline);
}
.topbar-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo-mark {
  width: 40px; height: 40px; border-radius: 13px; flex: none;
  display: grid; place-items: center; color: #fff;
  background: linear-gradient(135deg, #ff3b40, var(--red) 55%, #b31217);
  box-shadow: 0 4px 12px rgba(232, 33, 39, .35);
}
.topbar-title h1 { margin: 0; font-size: 17px; font-weight: 700; letter-spacing: .2px; }
.conn-chip {
  display: inline-flex; align-items: center; gap: 6px;
  margin-top: 3px; font-size: 11px; font-weight: 600; color: var(--text-2);
  background: var(--surface-2); border: 1px solid var(--outline);
  padding: 2px 9px; border-radius: 999px;
}
.conn-chip .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--amber); }
.conn-chip.online .dot { background: var(--green); animation: pulse 2.2s infinite; }
.conn-chip.demo .dot { background: #b48be8; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .4; } }

.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--outline);
  background: var(--surface); color: var(--text-2);
  display: grid; place-items: center; cursor: pointer; flex: none;
  transition: background .2s, transform .15s;
}
.icon-btn:active { transform: scale(.92); background: var(--surface-3); }
.icon-btn.spinning svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 主视图 ---------- */
.view { flex: 1; padding: 16px 16px calc(var(--nav-h) + var(--safe-b) + 28px); max-width: 560px; width: 100%; margin: 0 auto; }

/* ---------- 底部导航 ---------- */
.bottomnav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 60;
  height: calc(var(--nav-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  display: flex; justify-content: center; gap: 4px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--outline);
}
.bottomnav a {
  flex: 1; max-width: 108px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--text-3); text-decoration: none; font-size: 10.5px; font-weight: 600;
  border-radius: 16px; margin: 6px 2px; transition: color .2s;
}
.bottomnav a svg { width: 24px; height: 24px; }
.bottomnav a.active { color: var(--red); }
.bottomnav a.active svg { transform: translateY(-1px) scale(1.06); }

/* ---------- 通用卡片 ---------- */
.card {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px; margin-bottom: 14px;
  border: 1px solid color-mix(in srgb, var(--outline) 55%, transparent);
}
.card-title { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.card-title h2 { margin: 0; font-size: 15px; font-weight: 700; }
.card-title .link { font-size: 12.5px; font-weight: 600; color: var(--red); text-decoration: none; }
.section-gap { height: 8px; }

/* 骨架屏 */
.skeleton { position: relative; overflow: hidden; background: var(--surface-2); border-radius: 10px; }
.skeleton::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--surface) 70%, transparent), transparent);
  animation: shimmer 1.4s infinite;
}
@keyframes shimmer { from { transform: translateX(-100%); } to { transform: translateX(100%); } }

/* 空状态 */
.empty { text-align: center; color: var(--text-3); padding: 36px 12px; font-size: 13.5px; }
.empty svg { width: 44px; height: 44px; opacity: .45; margin-bottom: 10px; }

/* ---------- 首页车辆卡片 ---------- */
.hero {
  position: relative; overflow: hidden;
  background: linear-gradient(145deg, #232a31, #14181d 60%, #101418);
  color: #fff; border: none;
  border-radius: 24px; padding: 20px;
}
html[data-theme="dark"] .hero { background: linear-gradient(145deg, #1d242c, #12161a 60%, #0d1013); }
.hero::before {
  content: ""; position: absolute; right: -46px; top: -46px; width: 190px; height: 190px; border-radius: 50%;
  background: radial-gradient(circle, rgba(232,33,39,.34), transparent 65%);
}
.hero-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.hero-name { font-size: 16px; font-weight: 700; }
.hero-sub { font-size: 12px; color: #9aa5b1; margin-top: 3px; }
.state-badge {
  display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px; font-weight: 600;
  padding: 5px 11px; border-radius: 999px; background: rgba(255,255,255,.09); border: 1px solid rgba(255,255,255,.14);
  white-space: nowrap;
}
.state-badge .d { width: 7px; height: 7px; border-radius: 50%; background: #9aa5b1; }
.state-badge.sleeping .d { background: #7c8db0; }
.state-badge.charging .d { background: #34d077; animation: pulse 1.4s infinite; }
.state-badge.driving .d { background: #ff6b6e; animation: pulse 1.2s infinite; }
.state-badge.online .d { background: #5cc9f5; }
.hero-battery { display: flex; align-items: center; gap: 20px; margin: 18px 0 6px; }
.batt-ring { position: relative; width: 118px; height: 118px; flex: none; }
.batt-ring svg { transform: rotate(-90deg); }
.batt-ring .center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.batt-ring .pct { font-size: 30px; font-weight: 800; line-height: 1; }
.batt-ring .pct small { font-size: 14px; font-weight: 600; }
.batt-ring .lbl { font-size: 10.5px; color: #9aa5b1; margin-top: 3px; }
.hero-batt-info { display: flex; flex-direction: column; gap: 9px; min-width: 0; }
.hbi { display: flex; align-items: center; gap: 9px; font-size: 13.5px; }
.hbi .ic { width: 30px; height: 30px; border-radius: 9px; background: rgba(255,255,255,.08); display: grid; place-items: center; flex: none; }
.hbi b { font-weight: 700; }
.hbi .muted { color: #9aa5b1; font-size: 12px; }
.charge-mini { font-size: 12.5px; color: #7fe0a8; margin-top: 4px; display: flex; align-items: center; gap: 6px; }
.hero-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 16px; }
.hero-grid .g {
  background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.08);
  border-radius: 14px; padding: 10px 8px; text-align: center;
}
.hero-grid .v { font-size: 15px; font-weight: 700; }
.hero-grid .k { font-size: 10.5px; color: #9aa5b1; margin-top: 3px; }
.hero-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 14px; font-size: 11.5px; color: #828e9b; }

/* 月度统计四宫格 */
.grid4 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat-cell { background: var(--surface); border-radius: var(--radius-s); padding: 14px; box-shadow: var(--shadow); border: 1px solid color-mix(in srgb, var(--outline) 55%, transparent); }
.stat-cell .v { font-size: 19px; font-weight: 800; letter-spacing: -.2px; }
.stat-cell .v small { font-size: 11.5px; font-weight: 600; color: var(--text-3); margin-left: 2px; }
.stat-cell .k { font-size: 11.5px; color: var(--text-2); margin-top: 4px; display: flex; align-items: center; gap: 5px; }
.stat-cell .k svg { width: 14px; height: 14px; opacity: .7; }
.stat-cell.accent .v { color: var(--red); }
.stat-cell.green .v { color: var(--green); }
.stat-cell.blue .v { color: var(--blue); }

/* ---------- 列表 ---------- */
.list-item {
  display: flex; align-items: center; gap: 13px; padding: 13px 4px;
  border-bottom: 1px solid color-mix(in srgb, var(--outline) 60%, transparent);
  cursor: pointer; border-radius: 10px; transition: background .15s; text-decoration: none; color: inherit;
}
.list-item:last-child { border-bottom: none; }
.list-item:active { background: var(--surface-2); }
.li-ic {
  width: 42px; height: 42px; border-radius: 13px; flex: none;
  display: grid; place-items: center;
}
.li-ic.home { background: var(--green-bg); color: var(--green); }
.li-ic.sc { background: var(--red-bg); color: var(--red); }
.li-ic.dest { background: var(--blue-bg); color: var(--blue); }
.li-ic.drive { background: var(--surface-2); color: var(--text-2); }
.li-body { flex: 1; min-width: 0; }
.li-t { font-size: 13.5px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.li-s { font-size: 11.5px; color: var(--text-3); margin-top: 3px; }
.li-r { text-align: right; flex: none; }
.li-rv { font-size: 14.5px; font-weight: 750; }
.li-rv small { font-size: 10.5px; font-weight: 600; color: var(--text-3); }
.li-rs { font-size: 11px; color: var(--text-3); margin-top: 2px; }
.pill { display: inline-block; font-size: 10px; font-weight: 700; padding: 2px 8px; border-radius: 999px; }
.pill.good { background: var(--green-bg); color: var(--green); }
.pill.mid { background: var(--amber-bg); color: var(--amber); }
.pill.bad { background: var(--red-bg); color: var(--red); }

/* ---------- 详情页 ---------- */
.detail-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.back-btn {
  width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--outline);
  background: var(--surface); color: var(--text); display: grid; place-items: center; cursor: pointer; flex: none;
  text-decoration: none; transition: transform .15s;
}
.back-btn:active { transform: scale(.9); }
.detail-head h2 { margin: 0; font-size: 17px; font-weight: 750; }
.detail-head .sub { font-size: 12px; color: var(--text-3); margin-top: 2px; }
.route-box { border-radius: 18px; overflow: hidden; background: linear-gradient(160deg, #1b2128, #12161b); position: relative; }
.route-box svg { display: block; width: 100%; height: auto; }
.route-legend { display: flex; justify-content: space-between; padding: 10px 14px; font-size: 11.5px; color: #9aa5b1; background: rgba(255,255,255,.03); }
.kv-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.kv { background: var(--surface-2); border-radius: var(--radius-s); padding: 12px 14px; }
.kv .v { font-size: 16px; font-weight: 750; }
.kv .v small { font-size: 11px; font-weight: 600; color: var(--text-3); }
.kv .k { font-size: 11px; color: var(--text-3); margin-top: 3px; }
.kv.full { grid-column: 1 / -1; }

/* ---------- 图表 ---------- */
.chart-wrap { width: 100%; }
.chart-wrap svg { display: block; width: 100%; height: auto; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 10px; font-size: 11.5px; color: var(--text-2); }
.chart-legend .li { display: flex; align-items: center; gap: 5px; }
.chart-legend .sw { width: 10px; height: 10px; border-radius: 3px; }

/* ---------- 设置 ---------- */
.seg { display: flex; background: var(--surface-2); border-radius: 14px; padding: 4px; gap: 4px; }
.seg button {
  flex: 1; border: none; border-radius: 11px; padding: 9px 0; font-size: 13px; font-weight: 650;
  background: transparent; color: var(--text-2); cursor: pointer; transition: all .2s;
  font-family: inherit;
}
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 2px 8px rgba(0,0,0,.1); }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12.5px; font-weight: 650; color: var(--text-2); margin-bottom: 7px; }
.field input, .field select {
  width: 100%; border: 1px solid var(--outline); background: var(--surface); color: var(--text);
  border-radius: 13px; padding: 13px 14px; font-size: 14.5px; font-family: inherit; outline: none;
  transition: border .2s, box-shadow .2s;
}
.field input:focus { border-color: var(--red); box-shadow: 0 0 0 3px rgba(232,33,39,.12); }
.field .hint { font-size: 11px; color: var(--text-3); margin-top: 6px; line-height: 1.5; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  width: 100%; border: none; border-radius: 15px; padding: 14px;
  font-size: 14.5px; font-weight: 700; font-family: inherit; cursor: pointer;
  background: var(--red); color: #fff; box-shadow: 0 6px 18px rgba(232,33,39,.3);
  transition: transform .15s, background .2s;
}
.btn:active { transform: scale(.98); background: var(--red-dark); }
.btn.ghost { background: var(--surface-2); color: var(--text); box-shadow: none; }
.btn.ghost.danger { color: var(--red); }
.btn + .btn { margin-top: 10px; }
.setting-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 13px 0; border-bottom: 1px solid color-mix(in srgb, var(--outline) 60%, transparent);
}
.setting-row:last-child { border-bottom: none; }
.setting-row .t { font-size: 14px; font-weight: 600; }
.setting-row .s { font-size: 11.5px; color: var(--text-3); margin-top: 2px; }
.switch { position: relative; width: 50px; height: 29px; flex: none; cursor: pointer; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .track { position: absolute; inset: 0; border-radius: 999px; background: var(--surface-3); transition: background .25s; }
.switch .thumb { position: absolute; top: 3.5px; left: 4px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 2px 6px rgba(0,0,0,.25); transition: transform .25s; }
.switch input:checked + .track { background: var(--red); }
.switch input:checked + .track + .thumb { transform: translateX(21px); }

/* ---------- Toast ---------- */
.toast-wrap { position: fixed; left: 0; right: 0; bottom: calc(var(--nav-h) + var(--safe-b) + 16px); display: flex; flex-direction: column; align-items: center; gap: 8px; z-index: 200; pointer-events: none; }
.toast {
  max-width: 86%; padding: 11px 18px; border-radius: 13px; font-size: 13px; font-weight: 600;
  background: #262c33; color: #fff; box-shadow: 0 8px 24px rgba(0,0,0,.3);
  animation: toastIn .25s ease;
}
.toast.ok { background: #143527; }
.toast.err { background: #3d1a1c; }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px) scale(.96); } to { opacity: 1; transform: none; } }

/* ---------- 页面标题 ---------- */
.page-head { margin: 4px 2px 14px; }
.page-head h2 { margin: 0; font-size: 22px; font-weight: 800; letter-spacing: -.3px; }
.page-head p { margin: 4px 0 0; font-size: 12.5px; color: var(--text-3); }

/* 入场动画 */
.fade-in { animation: fadeIn .3s ease both; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

@media (min-width: 520px) { .bottomnav { left: 50%; transform: translateX(-50%); border-radius: 20px 20px 0 0; } }
