:root {
  --bg: #0b1220;
  --bg-2: #121a2b;
  --card: #161f33;
  --card-2: #1c2740;
  --line: #25304a;
  --text: #e6ecf5;
  --text-2: #9aa6bd;
  --text-3: #6b7790;
  --accent: #4f8cff;
  --accent-2: #00b3a3;
  --bad: #ff5c5c;
  --warn: #ffb020;
  --ok: #2ecc71;
  --neutral: #6b7790;
  --radius: 12px;
  --pad: env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
button { font: inherit; color: inherit; }
input { font: inherit; }

.view { min-height: 100%; padding: var(--pad); }
[hidden] { display: none !important; }

/* ===== 门禁页 ===== */
#loginView {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 28px 20px;
  text-align: center;
}
.login-card h1 { margin: 0 0 6px; font-size: 20px; }
.login-sub { margin: 0 0 18px; color: var(--text-2); font-size: 13px; }
#passwordInput {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  outline: none;
}
#passwordInput:focus { border-color: var(--accent); }
#loginBtn {
  width: 100%;
  margin-top: 12px;
  padding: 12px;
  background: var(--accent);
  border: none;
  border-radius: 10px;
  font-weight: 600;
}
#loginBtn:active { opacity: 0.85; }
.error-text { color: var(--bad); font-size: 12px; margin: 10px 0 0; }

/* ===== 主应用 ===== */
.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  padding: 10px 14px 8px;
  padding-top: calc(10px + env(safe-area-inset-top));
  border-bottom: 1px solid var(--line);
}
.header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}
.store-info { min-width: 0; }
.store-name { font-weight: 600; font-size: 15px; }
.fetched-at { display: block; color: var(--text-3); font-size: 11px; margin-top: 2px; }
.header-actions { display: flex; gap: 6px; }
.icon-btn {
  width: 36px; height: 36px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 17px;
  display: flex; align-items: center; justify-content: center;
}
.icon-btn:active { background: var(--card-2); }

.date-bar { margin-bottom: 8px; }
.date-chips {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 2px;
}
.date-chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto;
  padding: 7px 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 13px;
  color: var(--text-2);
}
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.custom-range {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  flex-wrap: wrap;
}
.custom-range input[type="date"] {
  flex: 1 1 110px;
  min-width: 0;
  padding: 8px 10px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  color-scheme: dark;
}
.mini-btn {
  padding: 8px 14px;
  background: var(--accent);
  border: none;
  border-radius: 8px;
  font-weight: 600;
}
.today-notice {
  margin: 8px 0 0;
  padding: 6px 10px;
  background: rgba(255, 176, 32, 0.12);
  border: 1px solid rgba(255, 176, 32, 0.3);
  border-radius: 8px;
  color: var(--warn);
  font-size: 12px;
}

.sort-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
}
.sort-label { color: var(--text-3); font-size: 12px; flex: 0 0 auto; }
.sort-chips {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 2px;
}
.sort-chips::-webkit-scrollbar { display: none; }
.sort-chip {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 6px 4px 10px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 12px;
  color: var(--text-2);
}
.sort-chip.active { border-color: var(--accent); color: var(--text); }
.sort-chip .arrows { display: inline-flex; gap: 1px; }
.sort-chip .arr {
  width: 18px; height: 18px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 4px;
  font-size: 11px;
  color: var(--text-3);
  background: transparent;
  border: none;
}
.sort-chip .arr:active { background: var(--card-2); }
.sort-chip .arr.on { color: var(--accent); }

.status {
  margin: 12px 14px 0;
  padding: 10px 12px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text-2);
  font-size: 13px;
}
.status.error { color: var(--bad); border-color: rgba(255, 92, 92, 0.4); }

.cards { padding: 10px 14px 24px; display: flex; flex-direction: column; gap: 10px; }

/* 卡片 */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.card-top {
  display: flex;
  gap: 12px;
  padding: 12px;
  align-items: flex-start;
}
.card-img {
  width: 56px; height: 56px;
  flex: 0 0 auto;
  border-radius: 8px;
  background: var(--bg-2);
  object-fit: contain;
}
.card-main { min-width: 0; flex: 1; }
.card-title {
  display: block;
  color: var(--text);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}
.card-title:active { color: var(--accent); }
.card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
  margin-top: 8px;
}
.meta { font-size: 12px; color: var(--text-2); }
.meta b { color: var(--text); font-weight: 600; }
.meta.gmv b { color: var(--accent-2); }
.health {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
}
.health .dot { width: 7px; height: 7px; border-radius: 50%; }
.sev-bad { color: var(--bad); border-color: rgba(255, 92, 92, 0.4); }
.sev-bad .dot { background: var(--bad); }
.sev-warn { color: var(--warn); border-color: rgba(255, 176, 32, 0.4); }
.sev-warn .dot { background: var(--warn); }
.sev-ok { color: var(--ok); border-color: rgba(46, 204, 113, 0.4); }
.sev-ok .dot { background: var(--ok); }
.sev-neutral { color: var(--neutral); }
.sev-neutral .dot { background: var(--neutral); }

.card-expand {
  width: 100%;
  background: transparent;
  border: none;
  border-top: 1px solid var(--line);
  padding: 8px 12px;
  color: var(--text-3);
  font-size: 12px;
  text-align: left;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.card-expand:active { background: var(--card-2); }
.card-expand .chev { transition: transform 0.15s; }
.card.open .card-expand .chev { transform: rotate(180deg); }

.card-detail {
  display: none;
  padding: 4px 12px 12px;
  border-top: 1px solid var(--line);
}
.card.open .card-detail { display: block; }
.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px 12px;
  margin-top: 8px;
}
.dcell { background: var(--bg-2); border-radius: 8px; padding: 8px 10px; }
.dcell .k { display: block; font-size: 11px; color: var(--text-3); }
.dcell .v { font-size: 14px; font-weight: 600; }
.findings {
  margin-top: 10px;
  font-size: 12px;
  color: var(--text-2);
  line-height: 1.5;
}
.findings .fk { color: var(--warn); }

.empty { text-align: center; color: var(--text-3); padding: 60px 20px; }

/* 加载骨架 */
.skeleton-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.skeleton { background: linear-gradient(90deg, var(--card) 25%, var(--card-2) 37%, var(--card) 63%); background-size: 400% 100%; animation: sk 1.4s infinite; border-radius: 6px; height: 12px; }
@keyframes sk { 0% { background-position: 100% 0; } 100% { background-position: -100% 0; } }
.skeleton-line { margin-bottom: 8px; }
.skeleton-line.short { width: 60%; }

/* 加载遮罩 */
.loading-overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(11, 18, 32, 0.6);
  display: flex; align-items: flex-start; justify-content: center;
  padding-top: 30dvh;
}
.spinner {
  width: 38px; height: 38px;
  border: 3px solid rgba(255,255,255,0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-overlay .loading-text {
  position: absolute; top: calc(30dvh + 50px);
  color: var(--text-2); font-size: 13px; text-align: center; width: 80%;
}
