:root {
  --bg-page: #F5F5F5;
  --bg-card: #FFFFFF;
  --bg-brand-dark: #0B0B0B;
  --accent: #00A8E8;
  --accent-hover: #0090C9;
  --accent-soft: #E6F7FD;
  --text-primary: #1A1A1A;
  --text-secondary: #8C8C8C;
  --success: #22C55E;
  --warning: #F59E0B;
  --radius-card: 14px;
  --shadow-card: 0 2px 12px rgba(0,0,0,.06);
  --sidebar-w: 72px;
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg-page); color: var(--text-primary); }
a { color: var(--accent); text-decoration: none; }
button, input, select, textarea { font: inherit; }
.hidden { display: none !important; }

/* Login */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px;
  background: linear-gradient(135deg, #eef7fb, #f5f5f5);
}
.login-card {
  width: min(920px, 100%); display: grid; grid-template-columns: 1.05fr 1fr;
  background: #fff; border-radius: 20px; overflow: hidden; box-shadow: var(--shadow-card);
}
.login-brand {
  background: radial-gradient(circle at 20% 10%, rgba(0,168,232,.35), transparent 45%), var(--bg-brand-dark);
  color: #fff; padding: 40px 36px; position: relative; min-height: 420px;
}
.login-brand .logo { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.login-brand .mark {
  width: 28px; height: 28px; border-radius: 8px; background: var(--accent);
  display: grid; place-items: center; font-weight: 700;
}
.login-brand h1 { font-size: 28px; margin: 48px 0 12px; line-height: 1.3; }
.login-brand p { color: #b0b0b0; margin: 0; }
.login-form { padding: 48px 40px; }
.login-form h2 { margin: 0 0 8px; font-size: 28px; }
.login-form .hint { color: var(--text-secondary); margin-bottom: 28px; }
.field { margin-bottom: 16px; }
.field input {
  width: 100%; padding: 14px 16px; border: 1px solid #e6e6e6; border-radius: 12px; outline: none;
}
.field input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.btn {
  border: 0; border-radius: 12px; padding: 12px 18px; cursor: pointer; background: #eee; color: #333;
}
.btn-primary { background: var(--accent); color: #fff; width: 100%; padding: 14px; font-weight: 600; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-ghost { background: transparent; color: var(--text-secondary); }

/* Shell */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w); background: #fff; border-right: 1px solid #eee;
  display: flex; flex-direction: column; align-items: center; padding: 16px 0; gap: 8px;
  position: sticky; top: 0; height: 100vh;
}
.sidebar .mark {
  width: 36px; height: 36px; border-radius: 10px; background: var(--accent); color: #fff;
  display: grid; place-items: center; font-weight: 700; margin-bottom: 12px;
}
.nav-btn {
  width: 44px; height: 44px; border: 0; border-radius: 12px; background: transparent; cursor: pointer;
  color: #666; font-size: 18px;
}
.nav-btn.active { background: var(--accent-soft); color: var(--accent); }
.sidebar .ver { margin-top: auto; font-size: 10px; color: #bbb; writing-mode: vertical-rl; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  height: 56px; background: #fff; border-bottom: 1px solid #eee;
  display: flex; align-items: center; justify-content: space-between; padding: 0 20px; gap: 12px;
}
.topbar .title { font-weight: 600; }
.topbar .right { display: flex; align-items: center; gap: 10px; color: var(--text-secondary); }
.content { padding: 20px; }

.card {
  background: var(--bg-card); border-radius: var(--radius-card); box-shadow: var(--shadow-card); padding: 16px 18px;
}
.grid { display: grid; gap: 14px; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 1100px) {
  .grid-4, .grid-3 { grid-template-columns: repeat(2, 1fr); }
  .login-card { grid-template-columns: 1fr; }
  .login-brand { min-height: 220px; }
}
@media (max-width: 700px) {
  .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; }
}

.metric .label { color: var(--text-secondary); font-size: 13px; }
.metric .value { font-size: 28px; font-weight: 700; margin-top: 6px; }
.metric .unit { font-size: 13px; color: var(--text-secondary); margin-left: 4px; font-weight: 500; }
.badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px;
  background: #ecfdf5; color: var(--success); font-size: 12px; font-weight: 600;
}
.badge.ok { background: #ecfdf5; color: var(--success); }
.badge.warn { background: #fff7ed; color: var(--warning); }
.badge.bad { background: #fef2f2; color: #dc2626; }
.badge.info { background: var(--accent-soft); color: var(--accent); }
.token-health {
  padding: 10px 12px; border-radius: 12px; background: #fafafa; border: 1px solid #eee;
}

.status-hero {
  background: linear-gradient(120deg, #111, #1a2a33); color: #fff; border-radius: 16px; padding: 20px;
}
.status-hero .row { display: flex; flex-wrap: wrap; gap: 18px; margin-top: 14px; }
.status-hero .k { color: #9aa; font-size: 12px; }
.status-hero .v { font-size: 22px; font-weight: 700; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px 8px; border-bottom: 1px solid #f0f0f0; font-size: 14px; }
th { color: var(--text-secondary); font-weight: 500; }
tr.clickable { cursor: pointer; }
tr.clickable:hover { background: #fafafa; }

.drawer-mask {
  position: fixed; inset: 0; background: rgba(0,0,0,.25); z-index: 40;
  display: flex; justify-content: flex-end;
}
.drawer {
  width: min(520px, 100%); background: #fff; height: 100%; overflow: auto; padding: 18px;
  box-shadow: -8px 0 24px rgba(0,0,0,.08);
}
.drawer-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.map-box { height: 240px; border-radius: 12px; overflow: hidden; background: #e8eef2; margin-bottom: 12px; }
#map, #footMap { width: 100%; height: 100%; }

.form-row { margin-bottom: 12px; }
.form-row label { display: block; font-size: 13px; color: var(--text-secondary); margin-bottom: 6px; }
.form-row input, .form-row select, .form-row textarea {
  width: 100%; padding: 10px 12px; border: 1px solid #e5e5e5; border-radius: 10px;
}
.switch-row { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid #f3f3f3; }
.muted { color: var(--text-secondary); font-size: 13px; }
.chart { height: 260px; }
.toast {
  position: fixed; right: 20px; bottom: 20px; background: #111; color: #fff; padding: 12px 16px;
  border-radius: 10px; z-index: 99; max-width: 360px;
}

/* ===== Mobile (Xiaomi Mate–style) ===== */
.mobile-tabbar { display: none; }
.more-sheet { display: none; }
.trip-cards { display: none; flex-direction: column; gap: 10px; }
.trip-card {
  background: #fff; border-radius: 14px; padding: 14px 14px 12px;
  box-shadow: var(--shadow-card); border: 1px solid #f0f0f0;
}
.trip-card .trip-top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.trip-card .trip-route { font-weight: 600; font-size: 15px; line-height: 1.35; margin: 8px 0 6px; }
.trip-card .trip-meta { display: flex; flex-wrap: wrap; gap: 10px; color: var(--text-secondary); font-size: 13px; }

@media (max-width: 768px) {
  .sidebar { display: none; }
  .mobile-tabbar {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    background: rgba(255,255,255,.96); backdrop-filter: blur(10px);
    border-top: 1px solid #eee; padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
    justify-content: space-around; align-items: stretch;
  }
  .tab-item {
    flex: 1; border: 0; background: transparent; color: #8a8a8a;
    display: flex; flex-direction: column; align-items: center; gap: 2px;
    padding: 6px 2px; font-size: 11px; border-radius: 10px;
  }
  .tab-item .tab-ico { font-size: 18px; line-height: 1.2; }
  .tab-item.active { color: var(--accent); background: var(--accent-soft); }
  .app-shell { padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
  .content { padding: 12px 12px 20px; }
  .topbar { height: 52px; padding: 0 12px; position: sticky; top: 0; z-index: 20; }
  .topbar .title { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 48vw; }
  .user-label { display: none; }
  .login-card { grid-template-columns: 1fr; border-radius: 16px; }
  .login-brand { display: none; }
  .login-form { padding: 28px 20px; }
  .login-form h2 { font-size: 24px; }
  .login-wrap { padding: 16px; align-items: flex-start; padding-top: 48px; }
  .status-hero { border-radius: 14px; padding: 16px; }
  .status-hero .v { font-size: 20px; }
  .status-hero .row { gap: 12px; }
  .metric .value { font-size: 22px; }
  .chart { height: 220px; }
  .map-box { height: 280px; }
  .map-box[style*="480px"] { height: 360px !important; }
  .drawer-mask { align-items: flex-end; }
  .drawer {
    width: 100%; height: min(92vh, 100%); border-radius: 16px 16px 0 0;
    padding-bottom: calc(18px + env(safe-area-inset-bottom));
  }
  .toast { left: 12px; right: 12px; bottom: calc(72px + env(safe-area-inset-bottom)); max-width: none; }
  /* tables → prefer cards on trips; horizontal scroll fallback elsewhere */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table.desktop-only { display: none; }
  .trip-cards { display: flex; }
  .grid.grid-2 { grid-template-columns: 1fr; }
  .more-sheet { display: block; position: fixed; inset: 0; z-index: 50; }
  .more-sheet.hidden { display: none !important; }
  .more-sheet-mask { position: absolute; inset: 0; background: rgba(0,0,0,.35); }
  .more-sheet-panel {
    position: absolute; left: 0; right: 0; bottom: 0;
    background: #fff; border-radius: 18px 18px 0 0; padding: 10px 16px calc(16px + env(safe-area-inset-bottom));
  }
  .more-sheet-handle {
    width: 40px; height: 4px; border-radius: 99px; background: #ddd; margin: 4px auto 12px;
  }
  .more-sheet-panel h3 { margin: 0 0 12px; font-size: 17px; }
  .more-grid {
    display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px;
  }
  .more-item {
    border: 1px solid #eee; background: #fafafa; border-radius: 14px;
    padding: 14px 8px; display: flex; flex-direction: column; align-items: center; gap: 6px;
    font-size: 13px; color: #333;
  }
  .more-item span { font-size: 20px; }
}

@media (min-width: 769px) {
  .mobile-tabbar, .more-sheet { display: none !important; }
  .trip-cards { display: none !important; }
  table.desktop-only { display: table; }
}
