:root {
  --bg: #f7f5f0;
  --card: #ffffff;
  --ink: #1e2430;
  --muted: #6b7280;
  --accent: #b5451b;
  --accent-soft: #f4e3d7;
  --good: #2f6d3c;
  --warn: #a15c00;
  --error: #a12626;
  --border: #e5e0d6;
  --radius: 12px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171512;
    --card: #232019;
    --ink: #f1ede4;
    --muted: #a39d8f;
    --accent: #e8814a;
    --accent-soft: #3a2a1e;
    --border: #3a352c;
  }
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 1.5rem; border-bottom: 1px solid var(--border); background: var(--card);
  position: sticky; top: 0; z-index: 10; flex-wrap: wrap; gap: 0.75rem;
}
.topbar h1 { font-size: 1.25rem; margin: 0; }
.topbar-actions { display: flex; gap: 0.5rem; align-items: center; }
#global-search { padding: 0.5rem 0.75rem; border: 1px solid var(--border); border-radius: 8px; min-width: 240px; background: var(--bg); color: var(--ink); }

.btn { border: 1px solid var(--border); background: var(--card); color: var(--ink); padding: 0.5rem 0.9rem; border-radius: 8px; cursor: pointer; font-size: 0.9rem; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.small { padding: 0.25rem 0.5rem; font-size: 0.8rem; }

.dashboard {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 1rem; padding: 1.5rem; max-width: 1400px; margin: 0 auto;
}

.section {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1rem 1.25rem; grid-column: span 1;
}
.section.wide { grid-column: 1 / -1; }
.section h2 { margin: 0 0 0.75rem; font-size: 1.05rem; display: flex; align-items: center; gap: 0.4rem; }

.card {
  border: 1px solid var(--border); border-radius: 10px; padding: 0.75rem;
  margin-bottom: 0.6rem; background: var(--bg);
}
.card:last-child { margin-bottom: 0; }
.card h3 { margin: 0 0 0.3rem; font-size: 0.95rem; }
.card p { margin: 0.2rem 0; font-size: 0.85rem; color: var(--muted); }
.card .card-actions { margin-top: 0.5rem; display: flex; gap: 0.4rem; }

.pill { display: inline-block; padding: 0.15rem 0.5rem; border-radius: 999px; font-size: 0.7rem; font-weight: 600; }
.pill.live { background: #e3f3e5; color: var(--good); }
.pill.unconfigured { background: #fdf1d8; color: var(--warn); }
.pill.error { background: #fbe0e0; color: var(--error); }
.pill.rating-HIGH_VALUE_DAY { background: var(--accent-soft); color: var(--accent); }
.pill.rating-ARBITRAGE_ALERT { background: #fde3e3; color: var(--error); }
.pill.rating-STANDARD_VALUE { background: var(--border); color: var(--muted); }

.source-row { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 0.6rem; }

.lineup-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 0.6rem; }
.lineup-item { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 0.6rem; font-size: 0.85rem; }
.lineup-item strong { display: block; font-size: 0.8rem; color: var(--muted); }

.brief-box { background: var(--accent-soft); border-radius: 10px; padding: 0.75rem 1rem; font-size: 0.9rem; margin-top: 0.5rem; }

.tag-list { display: flex; flex-wrap: wrap; gap: 0.3rem; margin: 0.3rem 0; }
.tag { background: var(--border); border-radius: 999px; padding: 0.1rem 0.5rem; font-size: 0.7rem; cursor: pointer; }
.tag.active { background: var(--accent); color: #fff; }

.drawer {
  position: fixed; top: 0; right: 0; height: 100%; width: 320px; background: var(--card);
  border-left: 1px solid var(--border); box-shadow: -4px 0 14px rgba(0,0,0,0.15); z-index: 50;
  overflow-y: auto;
}
.drawer-inner { padding: 1.25rem; display: flex; flex-direction: column; gap: 0.75rem; }
.drawer-header { display: flex; justify-content: space-between; align-items: center; }
.drawer label { display: flex; flex-direction: column; font-size: 0.85rem; gap: 0.25rem; }
.drawer input[type="text"], .drawer input[type="number"] { padding: 0.4rem; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); color: var(--ink); }

.toggle-row { display: flex; justify-content: space-between; align-items: center; padding: 0.35rem 0; border-bottom: 1px solid var(--border); font-size: 0.85rem; }

.empty-state { color: var(--muted); font-size: 0.85rem; font-style: italic; }

.cheat-answer { font-size: 0.85rem; }

/* --- Ritual streaks --- */
.ritual-card { display: flex; flex-direction: column; gap: 0.5rem; }
.streak-row { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 0.6rem; margin-top: 0.2rem; }
.checkin-btn {
  border: 1px solid var(--border); background: var(--card); color: var(--ink);
  padding: 0.5rem 0.9rem; border-radius: 999px; cursor: pointer; font-size: 0.85rem; font-weight: 600;
  transition: transform 0.12s ease, background 0.12s ease, border-color 0.12s ease;
}
.checkin-btn:hover { border-color: var(--accent); transform: translateY(-1px); }
.checkin-btn.done { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.checkin-btn:active { transform: scale(0.97); }

.streak-stats { display: flex; gap: 0.75rem; }
.streak-stat { display: flex; flex-direction: column; align-items: center; font-size: 0.7rem; color: var(--muted); line-height: 1.1; }
.streak-stat strong { font-size: 1.1rem; color: var(--ink); }

.heatmap { display: grid; grid-template-columns: repeat(21, 1fr); gap: 3px; margin-top: 0.35rem; }
.heat-cell { aspect-ratio: 1 / 1; border-radius: 3px; background: var(--border); }
.heat-cell.done { background: var(--accent); }

.ritual-eta { font-size: 0.78rem; color: var(--muted); margin: 0; }

/* --- Deals dataviz --- */
.deal-card { display: flex; gap: 0.75rem; align-items: flex-start; }
.deal-rank {
  flex: 0 0 auto; width: 2.2rem; height: 2.2rem; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: 0.9rem;
  display: flex; align-items: center; justify-content: center;
}
.deal-body { flex: 1 1 auto; min-width: 0; }
.deal-category { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.03em; }

.price-bars { display: flex; flex-direction: column; gap: 0.25rem; margin: 0.4rem 0; }
.price-bar-row { display: grid; grid-template-columns: 2.6rem 1fr 3.2rem; align-items: center; gap: 0.4rem; font-size: 0.75rem; }
.price-bar-label { color: var(--muted); }
.price-bar-track { background: var(--border); border-radius: 999px; height: 8px; overflow: hidden; }
.price-bar-fill { height: 100%; border-radius: 999px; }
.price-bar-fill.list { background: var(--muted); opacity: 0.55; }
.price-bar-fill.sale { background: var(--accent); }
.price-bar-value { text-align: right; font-variant-numeric: tabular-nums; }
.off-pill { align-self: flex-start; background: var(--accent-soft); color: var(--accent); }
.price-na { font-size: 0.8rem; color: var(--muted); font-style: italic; }

.deal-footer { display: flex; align-items: center; justify-content: space-between; gap: 0.6rem; margin-top: 0.3rem; }
.sparkline { width: 84px; height: 26px; flex: 0 0 auto; }
.tracking-since { font-size: 0.72rem; color: var(--muted); margin: 0; }
