:root {
  --ink: #182033;
  --muted: #667085;
  --line: #e4e7ee;
  --bg: #f2f4f8;
  --card: #ffffff;
  --nav: #141a24;
  --accent: #1f6feb;
  --accent-ink: #ffffff;
  --up: #0c8f62;
  --down: #d64545;
  --soft: #eef3fb;
  --shadow: 0 8px 24px rgba(20, 26, 36, 0.06);
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--ink);
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }

.side {
  position: fixed;
  inset: 0 auto 0 0;
  width: 220px;
  background: var(--nav);
  color: #f5f7fb;
  padding: 22px 14px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}
.brand { display: flex; gap: 10px; align-items: center; padding: 0 8px; }
.brand strong { display: block; font-size: 16px; }
.brand small { color: #9aa3b5; }
.mark {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: var(--accent);
  font-weight: 700;
}
.nav-btn {
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  color: #d5dbe6;
  border-radius: 10px;
  padding: 10px 12px;
}
.nav-btn.active, .nav-btn:hover { background: rgba(255, 255, 255, 0.08); color: white; }

.shell { margin-left: 220px; min-height: 100vh; }
.top {
  position: sticky;
  top: 0;
  z-index: 5;
  background: rgba(242, 244, 248, 0.92);
  backdrop-filter: blur(10px);
  padding: 16px 24px 8px;
}
#add-form { display: flex; gap: 8px; }
#add-form input { flex: 1; }
input, select {
  background: white;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
}
#main { padding: 8px 24px 40px; }

.btn {
  border: 1px solid var(--line);
  background: white;
  border-radius: 10px;
  padding: 8px 12px;
  white-space: nowrap;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--down); border-color: transparent; background: transparent; }
.btn:disabled { opacity: 0.6; cursor: wait; }

.page-head { display: flex; justify-content: space-between; gap: 16px; align-items: flex-end; margin: 8px 0 16px; }
.page-head h1 { margin: 0; font-size: 26px; }
.page-head p { margin: 6px 0 0; color: var(--muted); max-width: 720px; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
.stat, .card, .metric {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
}
.stat { padding: 16px 18px; }
.stat span { color: var(--muted); font-size: 13px; }
.stat b { display: block; margin-top: 6px; font-size: 26px; font-variant-numeric: tabular-nums; }

.card { padding: 16px; }
.card h2 { margin: 0 0 12px; font-size: 16px; }
.table-wrap { overflow: auto; background: white; border: 1px solid var(--line); border-radius: 14px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 12px 14px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; white-space: nowrap; }
th { color: var(--muted); font-weight: 600; background: #fafbfd; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #f8fafc; }
tr.watched td { background: #f3f8ff; }

.app-cell { display: flex; gap: 10px; align-items: center; white-space: normal; min-width: 220px; }
.app-cell img, .hit img { width: 40px; height: 40px; border-radius: 10px; background: var(--soft); object-fit: cover; }
.app-cell a, .linkish { color: inherit; font-weight: 650; text-decoration: none; }
.app-cell small, .muted { color: var(--muted); }
.badge { display: inline-flex; align-items: center; border-radius: 999px; padding: 2px 8px; font-size: 12px; background: var(--soft); }
.badge.google { background: #e7f6ee; color: #157a45; }
.badge.apple { background: #eceef3; color: #222; }
.badge.own { background: #e7f0ff; color: #1f4fd8; }
.badge.rival { background: #fff4e8; color: #b45309; }
.delta.up { color: var(--up); font-variant-numeric: tabular-nums; }
.delta.down { color: var(--down); font-variant-numeric: tabular-nums; }
.num { font-variant-numeric: tabular-nums; }
.error-line { color: var(--down); font-size: 12px; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.chip { border: 1px solid var(--line); background: white; border-radius: 999px; padding: 6px 10px; }
.chip.active { background: var(--ink); color: white; border-color: var(--ink); }

.identity { display: flex; gap: 16px; align-items: center; }
.identity img { width: 72px; height: 72px; border-radius: 16px; }
.tabs { display: flex; gap: 6px; margin: 16px 0; }
.tab { border: 0; background: transparent; padding: 8px 12px; border-radius: 10px; color: var(--muted); }
.tab.active { background: white; color: var(--ink); box-shadow: var(--shadow); }
.metrics { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.metric { padding: 14px 16px; }
.metric span { color: var(--muted); font-size: 13px; }
.metric b { display: block; margin-top: 6px; font-size: 22px; font-variant-numeric: tabular-nums; }
.metric em { display: block; margin-top: 4px; color: var(--muted); font-style: normal; font-size: 12px; }
.grid-2 { display: grid; grid-template-columns: 1.3fr 0.7fr; gap: 12px; margin-top: 12px; }
.chart { width: 100%; height: auto; }
.more-row { display: flex; justify-content: center; margin: 8px 0 22px; }
.hist-row { display: grid; grid-template-columns: 28px 1fr 72px; gap: 8px; align-items: center; margin: 7px 0; font-size: 13px; }
.hist-bar { height: 8px; background: #e8edf5; border-radius: 99px; overflow: hidden; }
.hist-bar span { display: block; height: 100%; background: #f5b301; }
.review { padding: 12px 0; border-bottom: 1px solid var(--line); }
.review:last-child { border-bottom: 0; }
.stars { color: #e0a100; letter-spacing: 1px; }
.pre { white-space: pre-wrap; line-height: 1.6; color: #344054; }
.empty { padding: 28px; color: var(--muted); background: white; border: 1px dashed var(--line); border-radius: 14px; }
.help { line-height: 1.7; }
.help h2 { margin: 22px 0 8px; font-size: 18px; }
.help ul { margin: 0; padding-left: 18px; }
.kv { display: grid; grid-template-columns: 120px 1fr; gap: 8px 12px; font-size: 14px; }
.modal { position: fixed; inset: 0; background: rgba(16, 20, 28, 0.45); display: grid; place-items: center; z-index: 20; padding: 24px; }
.modal.hidden, .toast.hidden { display: none; }
.modal-card { width: min(760px, 100%); max-height: 80vh; overflow: auto; background: white; border-radius: 16px; padding: 16px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; }
.hit { display: flex; justify-content: space-between; gap: 12px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.toast { position: fixed; bottom: 20px; right: 20px; background: var(--nav); color: white; padding: 12px 14px; border-radius: 12px; z-index: 30; max-width: 360px; }

@media (max-width: 980px) {
  .side { position: static; width: auto; flex-direction: row; align-items: center; overflow: auto; }
  .brand small { display: none; }
  .brand strong { white-space: nowrap; }
  .side nav { display: flex; }
  .nav-btn { white-space: nowrap; }
  .shell { margin-left: 0; }
  .stats, .metrics, .grid-2 { grid-template-columns: 1fr 1fr; }
  #add-form { flex-wrap: wrap; }
  #add-form input { min-width: 180px; }
}
