*, *::before, *::after { box-sizing: border-box; }
:root {
  --bg: #F6F8FA;
  --surface: #FFFFFF;
  --ink: #0F1D2E;
  --muted: #556678;
  --subtle: #8494A6;
  --line: #DFE5EC;
  --line-soft: #EEF2F6;
  --primary: #0B63CE;
  --primary-hover: #084FA6;
  --ok: #0D7A52;
  --warn: #B45309;
  --danger: #C81E1E;
  --font: "PingFang SC", "Noto Sans SC", "Hiragino Sans GB", -apple-system, BlinkMacSystemFont, sans-serif;
}
html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }

/* Login */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-box {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 32px 28px;
}
.brand-mark { font-size: 13px; font-weight: 600; color: var(--primary); margin-bottom: 6px; }
.login-box h1 { margin: 0 0 6px; font-size: 22px; font-weight: 600; }
.login-box p { margin: 0 0 20px; font-size: 13px; }
label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 14px; color: var(--ink); }
input[type="text"], input[type="password"], input[type="search"], input[type="date"], select {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
  color: var(--ink);
  background: #FFF;
}
input:focus, select:focus { outline: 2px solid rgba(11,99,206,0.22); border-color: var(--primary); }

/* Buttons */
button { font-family: inherit; cursor: pointer; }
.btn-primary {
  background: var(--primary);
  color: #FFF;
  border: 1px solid var(--primary);
  border-radius: 6px;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 500;
}
.btn-primary:hover { background: var(--primary-hover); }
.btn-primary.full { width: 100%; padding: 9px 14px; font-size: 14px; }
.btn-ghost {
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 12px;
  font-size: 13px;
}
.btn-ghost:hover { background: #F0F4F8; }
.btn-ghost.active { border-color: var(--primary); color: var(--primary); font-weight: 600; }
.btn-link { background: transparent; border: none; color: var(--muted); padding: 6px 8px; font-size: 13px; }
.btn-link:hover { color: var(--ink); }

/* Topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: 0 24px;
  min-height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.brand { font-size: 16px; font-weight: 700; color: var(--ink); text-decoration: none; letter-spacing: -0.01em; }
.main-nav { display: flex; gap: 4px; }
.nav-link {
  text-decoration: none;
  color: var(--muted);
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
}
.nav-link:hover { color: var(--ink); background: var(--bg); }
.nav-link.active { color: var(--primary); background: rgba(11,99,206,0.08); font-weight: 600; }
.quick-search { display: flex; align-items: center; gap: 6px; margin: 0; }
.quick-search input { margin-top: 0; width: 210px; padding: 6px 10px; font-size: 13px; }

/* Layout */
.main-container { max-width: 1320px; margin: 0 auto; padding: 22px 24px 56px; }
.page-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.page-head h1 { margin: 0; font-size: 20px; font-weight: 600; }
.sheet {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 20px;
  overflow: hidden;
}
.sheet-head {
  padding: 14px 18px;
  border-bottom: 1px solid var(--line-soft);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.sheet-head h2 { margin: 0; font-size: 15px; font-weight: 600; }
.sheet-body { padding: 18px; }

/* Watchlist Table */
.table-wrap { width: 100%; overflow-x: auto; }
table.ledger { width: 100%; border-collapse: collapse; text-align: left; }
table.ledger th {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  background: #FAFBFD;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
table.ledger td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: middle;
}
table.ledger tr.clickable:hover td { background: #F5F9FF; cursor: pointer; }
.app-ident { display: flex; align-items: center; gap: 12px; min-width: 210px; }
.app-icon {
  width: 42px;
  height: 42px;
  border-radius: 9px;
  border: 1px solid var(--line-soft);
  object-fit: cover;
  background: #EFF3F8;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  color: var(--primary);
}
.app-title { font-weight: 600; font-size: 14px; color: var(--ink); }
.app-sub { font-size: 12px; color: var(--muted); max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.metric-cell { min-width: 118px; font-variant-numeric: tabular-nums; }
.metric-dl { font-weight: 600; font-size: 13px; color: var(--ink); }
.metric-dl.na { font-weight: 400; color: var(--subtle); }
.metric-sub { font-size: 11.5px; color: var(--muted); margin-top: 2px; }

/* Detail Page */
.detail-hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px;
  flex-wrap: wrap;
}
.detail-hero-left { display: flex; align-items: center; gap: 16px; }
.app-icon-lg { width: 64px; height: 64px; border-radius: 14px; object-fit: cover; border: 1px solid var(--line); background: #EFF3F8; display: flex; align-items: center; justify-content: center; font-size: 22px; font-weight: 700; color: var(--primary); }
.detail-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.store-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}
.store-card {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 14px;
  background: #FCFDFE;
}
.store-card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; font-weight: 600; }
.kv-row { display: flex; justify-content: space-between; padding: 4px 0; font-size: 13px; border-bottom: 1px dashed var(--line-soft); }
.kv-row:last-child { border-bottom: none; }
.kv-k { color: var(--muted); }
.kv-v { font-weight: 600; font-variant-numeric: tabular-nums; }
.kv-v.na { font-weight: 400; color: var(--subtle); }

/* Screenshots & Description */
.shot-strip {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 8px;
}
.shot-item {
  position: relative;
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
  background: #F2F5F8;
  cursor: zoom-in;
}
.shot-item img { height: 260px; width: auto; display: block; }
.shot-tag {
  position: absolute;
  bottom: 6px;
  right: 6px;
  background: rgba(15,29,46,0.75);
  color: #FFF;
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 4px;
}
.tab-bar { display: flex; gap: 6px; margin-bottom: 12px; flex-wrap: wrap; }
.desc-body {
  white-space: pre-line;
  max-width: 78ch;
  color: var(--ink);
  line-height: 1.7;
  font-size: 14px;
}

/* Date Filter & SVG Chart */
.filter-bar {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.filter-bar label { margin-bottom: 0; font-size: 12px; color: var(--muted); }
.filter-bar input[type="date"] { width: 152px; margin-top: 4px; padding: 6px 8px; font-size: 13px; }
.preset-group { display: flex; gap: 6px; }
.chart-box {
  border: 1px solid var(--line-soft);
  border-radius: 6px;
  padding: 14px;
  background: #FAFBFD;
  margin-bottom: 14px;
}
.chart-legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 12.5px; margin-bottom: 8px; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.legend-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.delta-up { color: var(--ok); font-weight: 600; }
.delta-down { color: var(--warn); font-weight: 600; }

/* Badges, Toast, Modal, Lightbox */
.badge { display: inline-block; padding: 2px 7px; border-radius: 4px; font-size: 11.5px; font-weight: 500; }
.badge-ok { background: #E6F5EF; color: var(--ok); }
.badge-run { background: #E6F0FC; color: var(--primary); }
.badge-warn { background: #FEF3C7; color: var(--warn); }
.badge-fail { background: #FDE8E8; color: var(--danger); }
.error-banner { background: #FDE8E8; color: var(--danger); padding: 8px 10px; border-radius: 6px; font-size: 13px; margin-bottom: 12px; }
.job-toast {
  background: #0F1D2E;
  color: #FFF;
  padding: 10px 24px;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15,29,46,0.45);
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-panel {
  background: var(--surface);
  border-radius: 8px;
  width: 100%;
  max-width: 480px;
  padding: 22px 24px;
  border: 1px solid var(--line);
}
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.modal-head h2 { margin: 0; font-size: 17px; }
.icon-close { background: none; border: none; font-size: 22px; color: var(--muted); line-height: 1; }
.field-group { margin-bottom: 14px; }
.field-label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 8px; }
.store-checks { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px; }
.store-checks label, .checkbox-inline { display: flex; align-items: center; gap: 6px; font-weight: 400; margin-bottom: 6px; }
.hint { font-size: 12px; color: var(--muted); margin: 10px 0 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }

.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(10,18,28,0.9);
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: center;
}
.lightbox-body { margin: 0; text-align: center; max-width: 88vw; max-height: 88vh; }
.lightbox-body img { max-height: 80vh; max-width: 86vw; border-radius: 6px; }
.lightbox-body figcaption { color: #D8E1EB; font-size: 13px; margin-top: 8px; }
.lightbox-close { position: absolute; top: 18px; right: 24px; background: none; border: none; color: #FFF; font-size: 32px; }
.lightbox-nav { background: rgba(255,255,255,0.14); border: none; color: #FFF; font-size: 28px; width: 44px; height: 44px; border-radius: 50%; margin: 0 16px; }
.empty-state { text-align: center; padding: 36px 18px; color: var(--muted); }
