/* ── Reset & base ───────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #ffffff;
  --bg2:       #f5f5f3;
  --bg3:       #eeede9;
  --text:      #1a1a18;
  --text2:     #6b6b67;
  --text3:     #a8a8a4;
  --border:    rgba(0,0,0,0.10);
  --border2:   rgba(0,0,0,0.18);
  --accent:    #185FA5;
  --accent-bg: #E6F1FB;
  --radius:    8px;
  --radius-lg: 12px;
  --c-muted:   #a8a8a4;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:      #1a1a18;
    --bg2:     #242422;
    --bg3:     #2e2e2b;
    --text:    #f0efea;
    --text2:   #999992;
    --text3:   #666660;
    --border:  rgba(255,255,255,0.10);
    --border2: rgba(255,255,255,0.18);
    --c-muted: #666660;
  }
}

html { font-size: 16px; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg3);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

/* ── App shell ──────────────────────────────────────────────── */
.app {
  max-width: 680px;
  margin: 0 auto;
  background: var(--bg);
  min-height: 100vh;
  padding: 0 0 3rem;
}

/* ── Top bar ────────────────────────────────────────────────── */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem 0.875rem;
  border-bottom: 0.5px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
}

.top-left { display: flex; align-items: center; gap: 10px; }

.logo-mark {
  width: 30px; height: 30px;
  border-radius: 8px;
  background: #185FA5;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  letter-spacing: 0.03em;
}

.top-bar h1 { font-size: 17px; font-weight: 600; letter-spacing: -0.01em; }

.top-right { display: flex; align-items: center; gap: 10px; }

.top-date { font-size: 12px; color: var(--text2); }

/* ── Sync badge ─────────────────────────────────────────────── */
.sync-badge {
  display: flex; align-items: center; gap: 4px;
  font-size: 11px;
  padding: 3px 10px;
  border-radius: 99px;
  border: 0.5px solid var(--border2);
  color: var(--text2);
  background: var(--bg2);
  transition: all 0.2s;
}
.sync-badge.synced  { color: #3B6D11; border-color: #3B6D11; background: #EAF3DE; }
.sync-badge.syncing { color: #BA7517; border-color: #BA7517; background: #FAEEDA; }
.sync-badge.error   { color: #A32D2D; border-color: #A32D2D; background: #FCEBEB; }

/* ── Views ──────────────────────────────────────────────────── */
.view { display: none; padding: 1.25rem; }
.view.active { display: block; }

/* ── Loading ────────────────────────────────────────────────── */
.loading-screen {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  min-height: 300px; gap: 16px;
}
.loading-screen p { font-size: 14px; color: var(--text2); }

.spinner {
  width: 32px; height: 32px;
  border: 2.5px solid var(--border);
  border-top-color: #185FA5;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Home ───────────────────────────────────────────────────── */
.home-intro {
  display: flex; align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}
.home-intro p { font-size: 13px; color: var(--text2); }

/* ── Leaderboard ────────────────────────────────────────────── */
.leaderboard-panel {
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  margin-bottom: 1.25rem;
  overflow: hidden;
  background: var(--bg2);
}

.lb-header {
  display: flex; align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 0.5px solid var(--border);
}

.lb-title { font-size: 13px; font-weight: 500; }

.lb-tabs { display: flex; gap: 4px; }

.lb-tab {
  padding: 4px 10px;
  border-radius: 99px;
  border: 0.5px solid var(--border2);
  background: transparent;
  font-size: 12px;
  cursor: pointer;
  color: var(--text2);
  font-family: inherit;
  transition: all 0.1s;
}
.lb-tab.active, .lb-tab:hover {
  background: var(--accent-bg);
  border-color: var(--accent);
  color: var(--accent);
}

.lb-row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px;
  border-bottom: 0.5px solid var(--border);
}
.lb-row:last-child { border-bottom: none; }

.lb-rank { font-size: 18px; min-width: 28px; text-align: center; }

.lb-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 500;
  flex-shrink: 0;
}

.lb-info { flex: 1; min-width: 0; }
.lb-name { font-size: 13px; font-weight: 500; margin-bottom: 4px; }

.lb-bar-wrap { display: flex; align-items: center; gap: 8px; }

.lb-bar {
  flex: 1; height: 5px;
  background: var(--border);
  border-radius: 99px; overflow: hidden;
}
.lb-fill { height: 100%; border-radius: 99px; transition: width 0.4s ease; }

.lb-score { font-size: 12px; color: var(--text2); min-width: 80px; }

/* ── Profile grid ───────────────────────────────────────────── */
.profile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
}

.profile-card {
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 14px 14px;
  display: flex; flex-direction: column;
  align-items: center; gap: 7px;
  cursor: pointer;
  background: var(--bg);
  transition: border-color 0.15s, transform 0.1s;
  text-align: center;
}
.profile-card:hover { border-color: var(--border2); transform: translateY(-1px); }
.profile-card:active { transform: scale(0.98); }

.avatar {
  width: 52px; height: 52px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 500;
}
.av-lg {
  width: 62px; height: 62px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; font-weight: 500;
}

.p-name { font-size: 15px; font-weight: 500; }
.p-role { font-size: 12px; color: var(--text2); }
.p-sub  { font-size: 12px; color: var(--text2); }

.streak-pip {
  display: flex; align-items: center; gap: 3px;
  font-size: 12px; font-weight: 500;
}

/* ── Back button ────────────────────────────────────────────── */
.back-btn {
  background: none; border: none; cursor: pointer;
  color: var(--text2); font-size: 14px;
  padding: 4px 0;
  display: flex; align-items: center; gap: 5px;
  font-family: inherit;
  margin-bottom: 0.875rem;
}
.back-btn:hover { color: var(--text); }

/* ── Profile header ─────────────────────────────────────────── */
.profile-header {
  display: flex; align-items: center; gap: 16px;
  margin-bottom: 1.25rem;
}
.ph-info h2 { font-size: 20px; font-weight: 600; letter-spacing: -0.01em; }
.ph-info p  { font-size: 13px; color: var(--text2); margin-top: 2px; }

/* ── Stat row ───────────────────────────────────────────────── */
.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
  margin-bottom: 1.25rem;
}
.streak-stats {
  display: flex; gap: 10px;
  margin-bottom: 1.25rem;
}
.streak-stats .stat-card { flex: 1; }

.stat-card { background: var(--bg2); border-radius: var(--radius); padding: 12px 14px; }
.st-label  { font-size: 12px; color: var(--text2); margin-bottom: 4px; }
.st-val    { font-size: 20px; font-weight: 500; }

/* ── Tabs ───────────────────────────────────────────────────── */
.tabs {
  display: flex; gap: 2px;
  margin-bottom: 1.25rem;
  border-bottom: 0.5px solid var(--border);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.tab {
  padding: 8px 14px;
  font-size: 14px; cursor: pointer;
  background: none; border: none;
  color: var(--text2);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  white-space: nowrap;
  font-family: inherit;
  transition: color 0.1s;
}
.tab.active { color: var(--text); border-bottom-color: #378ADD; font-weight: 500; }

/* ── Log forms ──────────────────────────────────────────────── */
.log-form {
  display: flex; gap: 10px;
  align-items: flex-end;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}

.lf-field { display: flex; flex-direction: column; gap: 5px; }
.lf-field label { font-size: 12px; color: var(--text2); }

.lf-field input {
  height: 36px;
  padding: 0 10px;
  border: 0.5px solid var(--border2);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  min-width: 80px;
  transition: border-color 0.15s;
}
.lf-field input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(24,95,165,0.12);
}

/* ── Buttons ────────────────────────────────────────────────── */
.btn {
  height: 36px;
  padding: 0 16px;
  border-radius: var(--radius);
  border: 0.5px solid var(--border2);
  background: transparent;
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
  display: inline-flex; align-items: center; gap: 6px;
  transition: background 0.1s, transform 0.1s;
}
.btn:hover  { background: var(--bg2); }
.btn:active { transform: scale(0.98); }

.btn-primary { background: #185FA5; color: #fff; border-color: #185FA5; }
.btn-primary:hover { background: #0C447C; border-color: #0C447C; }

.btn-sm { height: 30px; padding: 0 12px; font-size: 13px; }
.btn.active { background: var(--accent-bg); border-color: var(--accent); color: var(--accent); }

/* ── History list ───────────────────────────────────────────── */
.hist {
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin-bottom: 1rem;
}

.hist-row {
  display: flex; align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-bottom: 0.5px solid var(--border);
  font-size: 14px; gap: 8px;
}
.hist-row:last-child { border-bottom: none; }

.hist-date  { color: var(--text2); font-size: 12px; min-width: 54px; flex-shrink: 0; }
.hist-note  { flex: 1; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hist-val   { font-weight: 500; white-space: nowrap; }

.delta-dn { color: #3B6D11; font-size: 12px; margin-left: 4px; }
.delta-up { color: #A32D2D; font-size: 12px; margin-left: 4px; }

.empty-state {
  padding: 32px 16px;
  text-align: center;
  color: var(--text2);
  font-size: 14px;
}

/* ── Chips ──────────────────────────────────────────────────── */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 1rem; }

.chip {
  padding: 6px 14px;
  border-radius: 99px;
  border: 0.5px solid var(--border2);
  background: transparent;
  font-size: 13px; cursor: pointer;
  color: var(--text2); font-family: inherit;
  transition: all 0.1s;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip.sel  { background: var(--accent-bg); border-color: var(--accent); color: #0C447C; }
.chip.done { background: #EAF3DE; border-color: #3B6D11; color: #27500A; }

/* ── Macro cards ────────────────────────────────────────────── */
.macro-row {
  display: grid; grid-template-columns: repeat(3,1fr);
  gap: 10px; margin-bottom: 1.25rem;
}

.macro-card { background: var(--bg2); border-radius: var(--radius); padding: 12px; }
.mc-label { font-size: 11px; color: var(--text2); margin-bottom: 3px; text-transform: uppercase; letter-spacing: 0.04em; }
.mc-val   { font-size: 18px; font-weight: 500; }
.mc-unit  { font-size: 12px; font-weight: 400; color: var(--text2); }
.mc-goal  { font-size: 12px; color: var(--text2); margin-top: 1px; }

.prog { height: 4px; background: var(--border); border-radius: 99px; margin-top: 6px; overflow: hidden; }
.prog-fill { height: 100%; border-radius: 99px; transition: width 0.3s ease; }

/* ── Goals ──────────────────────────────────────────────────── */
.goal-item {
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  margin-bottom: 12px;
}
.goal-top { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 5px; }
.goal-name { font-size: 14px; font-weight: 500; }
.goal-desc { font-size: 13px; color: var(--text2); margin-bottom: 10px; }
.goal-bar-row { display: flex; align-items: center; gap: 10px; }
.goal-bar  { flex: 1; height: 6px; background: var(--border); border-radius: 99px; overflow: hidden; }
.goal-fill { height: 100%; border-radius: 99px; transition: width 0.4s ease; }
.goal-pct  { font-size: 13px; font-weight: 500; min-width: 34px; text-align: right; }

.badge { font-size: 11px; padding: 3px 10px; border-radius: 99px; }
.badge-active { background: #E6F1FB; color: #0C447C; }
.badge-done   { background: #EAF3DE; color: #27500A; }

/* ── Calendar ───────────────────────────────────────────────── */
.cal-month-label { font-size: 13px; font-weight: 500; margin-bottom: 8px; }

.cal-dow {
  display: grid; grid-template-columns: repeat(7,1fr);
  gap: 4px; margin-bottom: 4px;
}
.cal-dow-label { text-align: center; font-size: 11px; color: var(--text2); }

.cal-grid { display: grid; grid-template-columns: repeat(7,1fr); gap: 5px; }

.cal-day {
  aspect-ratio: 1; border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px;
}
.cal-logged { background: #185FA5; color: #fff; }
.cal-today  { border: 2px solid #185FA5; font-weight: 600; color: var(--text); }
.cal-empty  { background: var(--bg2); color: var(--text2); }
.cal-future { color: var(--text3); }

/* ── Misc ───────────────────────────────────────────────────── */
.tab-intro { font-size: 13px; color: var(--text2); margin-bottom: 0.75rem; }

.section-label { font-size: 13px; font-weight: 500; margin: 1rem 0 8px; }

/* ── Toast ──────────────────────────────────────────────────── */
.toast {
  position: fixed; bottom: 24px; left: 50%;
  transform: translateX(-50%);
  background: #2C2C2A; color: #fff;
  font-size: 13px;
  padding: 8px 20px;
  border-radius: 99px;
  opacity: 0; transition: opacity 0.2s;
  pointer-events: none; z-index: 999;
  white-space: nowrap;
}
.toast.show { opacity: 1; }

/* ── Mobile ─────────────────────────────────────────────────── */
@media (max-width: 480px) {
  .top-bar { padding: 0.875rem 1rem 0.75rem; }
  .view    { padding: 1rem; }
  .macro-row { grid-template-columns: repeat(3,1fr); gap: 6px; }
  .macro-card { padding: 10px; }
  .mc-val { font-size: 16px; }
  .log-form { gap: 8px; }
  .profile-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
}

/* ── Home calendar strip ─────────────────────────────────────── */
.home-section-label {
  display: flex; align-items: center; gap: 6px;
  font-size: 13px; font-weight: 500;
  color: var(--text2);
  margin: 1.5rem 0 0.75rem;
  padding-top: 1.25rem;
  border-top: 0.5px solid var(--border);
}

.cal-strip-loading {
  display: flex; justify-content: center; padding: 1rem;
}

.cal-strip-empty {
  font-size: 13px; color: var(--text2);
  padding: 12px 0;
}

.cal-strip-item {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 9px 14px;
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 8px;
  background: var(--bg);
  font-size: 14px;
}

.cal-strip-date {
  font-size: 12px; font-weight: 500; color: var(--accent);
  min-width: 68px; flex-shrink: 0;
}

.cal-strip-title {
  flex: 1; display: flex; align-items: center; gap: 5px;
  color: var(--text);
}

/* ── Calendar tab (profile page) ────────────────────────────── */
.cal-toolbar {
  display: flex; align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.cal-updated {
  font-size: 12px; color: var(--text2);
}

.cal-date-group { margin-bottom: 1.25rem; }

.cal-date-label {
  font-size: 12px; font-weight: 600;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 8px;
}

.cal-item {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 10px 14px;
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 7px;
  background: var(--bg);
}

.cal-item.chore { border-left: 3px solid #BA7517; }
.cal-item.event { border-left: 3px solid #185FA5; }

.cal-item-icon {
  font-size: 16px; color: var(--text2);
  margin-top: 1px; flex-shrink: 0;
}
.cal-item.chore .cal-item-icon { color: #BA7517; }
.cal-item.event .cal-item-icon { color: #185FA5; }

.cal-item-body { flex: 1; min-width: 0; }

.cal-item-title {
  font-size: 14px; font-weight: 500;
  margin-bottom: 4px;
}

.cal-item-meta {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}

.cal-time {
  font-size: 12px; color: var(--text2);
}

.cal-person-pill {
  font-size: 11px; font-weight: 500;
  padding: 2px 8px; border-radius: 99px;
}

.cal-chore-badge {
  font-size: 11px; padding: 2px 8px; border-radius: 99px;
  background: #FAEEDA; color: #633806;
  border: 0.5px solid #BA7517;
}
.cal-chore-badge.done {
  background: #EAF3DE; color: #27500A; border-color: #3B6D11;
}

/* ── Photo avatars ───────────────────────────────────────────── */
.avatar-photo {
  border-radius: 50%;
  display: block;
  flex-shrink: 0;
}
/* lb-avatar sizing when it's a photo */
img.lb-avatar {
  width: 32px;
  height: 32px;
}
