/* ── CSS Custom Properties (Light & Dark) ── */
:root {
  color-scheme: light;

  /* Surfaces */
  --bg:             #f5f4f0;
  --surface:        #ffffff;
  --surface-raised: #f9f8f5;
  --surface-hover:  #faf9f6;
  --hover-bg:       #f0ede8;
  --hover-surface:  #eeeeee;

  /* Borders */
  --border:         #e0ddd6;
  --border-subtle:  #e5e2db;
  --border-alt:     #dddddd;
  --border-input:   #cccccc;

  /* Text */
  --text:           #1a1a1a;
  --text-secondary: #333333;
  --text-muted:     #555555;
  --text-dim:       #666666;
  --text-faint:     #888888;
  --text-ghost:     #999999;
  --text-whisper:   #aaaaaa;
  --text-trace:     #bbbbbb;

  /* Primary action */
  --primary:        #1a1a1a;
  --on-primary:     #ffffff;

  /* Misc */
  --heatmap-empty:       #ebedf0;
  --summary-border:      #e8e5de;
  --auth-overlay:        rgba(245,244,240,0.96);
  --modal-overlay:       rgba(0,0,0,0.35);

  /* Delta badges */
  --delta-up-text:      #1a7a3c;
  --delta-up-bg:        #e6f6ed;
  --delta-down-text:    #a02020;
  --delta-down-bg:      #faeaea;
  --delta-neutral-text: #666666;
  --delta-neutral-bg:   #f0efec;
}

/* Dark theme — applied via data-theme="dark" on <html> by theme.js */
[data-theme="dark"] {
  color-scheme: dark;

  /* Surfaces — iOS HIG dark grays */
  --bg:             #111111;
  --surface:        #1c1c1e;
  --surface-raised: #2c2c2e;
  --surface-hover:  #2a2a2c;
  --hover-bg:       #2c2c2e;
  --hover-surface:  #3a3a3c;

  /* Borders */
  --border:         #3a3a3c;
  --border-subtle:  #2c2c2e;
  --border-alt:     #3a3a3c;
  --border-input:   #48484a;

  /* Text */
  --text:           #f2f2f7;
  --text-secondary: #d1d1d6;
  --text-muted:     #aeaeb2;
  --text-dim:       #8e8e93;
  --text-faint:     #6e6e73;
  --text-ghost:     #636366;
  --text-whisper:   #48484a;
  --text-trace:     #3a3a3c;

  /* Primary action (inverted) */
  --primary:        #f2f2f7;
  --on-primary:     #111111;

  /* Misc */
  --heatmap-empty:       #2c2c2e;
  --summary-border:      #3a3a3c;
  --auth-overlay:        rgba(17,17,17,0.96);
  --modal-overlay:       rgba(0,0,0,0.6);

  /* Delta badges */
  --delta-up-text:      #30d158;
  --delta-up-bg:        #1a3a25;
  --delta-down-text:    #ff6b6b;
  --delta-down-bg:      #3a1a1a;
  --delta-neutral-text: #aeaeb2;
  --delta-neutral-bg:   #2c2c2e;
}

/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ── Utilities ── */
.hidden { display: none !important; }
.error  { color: #c0392b; font-size: 0.85rem; margin-top: 6px; }

/* ── Navbar ── */
.navbar {
  display: flex;
  align-items: center;
  padding: 0 20px;
  padding-top: env(safe-area-inset-top);
  height: calc(52px + env(safe-area-inset-top));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  gap: 20px;
}
.nav-logo { font-weight: 700; font-size: 1.1rem; letter-spacing: -0.5px; flex: 1; }
.nav-links { display: flex; gap: 8px; }
.nav-link {
  padding: 5px 12px;
  border-radius: 6px;
  text-decoration: none;
  color: var(--text-muted);
  font-size: 0.9rem;
  transition: background 0.15s;
}
.nav-link:hover { background: var(--hover-bg); color: var(--text); }
.nav-link.active { background: var(--primary); color: var(--on-primary); }

/* ── Buttons ── */
.btn-primary {
  background: var(--primary);
  color: var(--on-primary);
  border: none;
  padding: 8px 18px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: background 0.15s;
}
.btn-primary:hover { background: var(--text-secondary); color: var(--on-primary); }
.btn-ghost {
  background: transparent;
  border: 1px solid var(--border-input);
  padding: 6px 14px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--text-muted);
  transition: background 0.15s;
}
.btn-ghost:hover { background: var(--hover-surface); }
.btn-icon {
  background: transparent;
  border: none;
  font-size: 1.4rem;
  cursor: pointer;
  color: var(--text-muted);
  line-height: 1;
  padding: 2px 6px;
  border-radius: 4px;
}
.btn-icon:hover { background: var(--hover-surface); }

/* ── Nav hamburger dropdown ── */
.nav-menu-wrap { position: relative; }
.nav-hamburger { font-size: 1.25rem; padding: 4px 8px; }
.nav-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.15);
  min-width: 160px;
  z-index: 200;
  overflow: hidden;
}
.nav-dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  background: transparent;
  border: none;
  padding: 13px 16px;
  font-size: 0.9rem;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  transition: background 0.15s;
  white-space: nowrap;
}
.nav-dropdown-item:hover { background: var(--hover-surface); }
.nav-dropdown-item + .nav-dropdown-item { border-top: 1px solid var(--border); }

/* ── Auth Overlay ── */
.auth-overlay {
  position: fixed; inset: 0;
  background: var(--auth-overlay);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.auth-box {
  background: var(--surface);
  border: 1px solid var(--border-alt);
  border-radius: 12px;
  padding: 32px 28px;
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.auth-box h2 { margin-bottom: 4px; }
.auth-box input {
  padding: 9px 12px;
  border: 1px solid var(--border-input);
  border-radius: 7px;
  font-size: 1rem;
  outline: none;
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.15s;
}
.auth-box input:focus { border-color: var(--primary); }
.auth-box button {
  width: 100%;
  padding: 10px;
  font-size: 1rem;
}
.auth-toggle { font-size: 0.85rem; color: var(--text-dim); text-align: center; }
.auth-toggle a { color: var(--text); }

/* ── Page Layout ── */
.page-wrapper {
  display: flex;
  height: calc(100vh - 52px);
  overflow: hidden;
}

/* ── Sidebar ── */
.sidebar {
  width: 220px;
  min-width: 180px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  flex-shrink: 0;
}
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 14px 10px;
  border-bottom: 1px solid var(--hover-surface);
}
.sidebar-header h3 { font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-faint); }
.habit-list { list-style: none; padding: 8px 0; flex: 1; }
.habit-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: background 0.12s;
  user-select: none;
}
.habit-item:hover { background: var(--bg); }
.habit-item.selected { background: var(--bg); }
.habit-symbol-badge {
  width: 26px; height: 26px;
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.95rem;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}
.habit-item-name { font-size: 0.9rem; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.habit-item-edit {
  opacity: 0;
  font-size: 0.8rem;
  color: var(--text-ghost);
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
}
.habit-item:hover .habit-item-edit { opacity: 1; }
.habit-item-edit:hover { background: var(--border-alt); color: var(--text-muted); }

/* ── Calendar ── */
.calendar-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 20px 24px;
  gap: 12px;
}
.calendar-nav {
  display: flex;
  align-items: center;
  gap: 16px;
}
.calendar-nav h2 { font-size: 1.2rem; font-weight: 600; min-width: 160px; }
.calendar-nav .btn-ghost { padding: 4px 12px; font-size: 1.2rem; border: none; }

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 5px;
  flex: 1;
  overflow: hidden;
}
.cal-dow {
  text-align: center;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-ghost);
  letter-spacing: 0.04em;
  padding-bottom: 4px;
}
.cal-day {
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 6px 4px 4px;
  cursor: pointer;
  position: relative;
  transition: border-color 0.12s, background 0.12s;
  min-height: 60px;
  overflow: hidden;
}
.cal-day:hover { border-color: var(--text-faint); background: var(--surface-hover); }
.cal-day.today { border-color: var(--primary); }
.cal-day.empty { background: transparent; border-color: transparent; cursor: default; pointer-events: none; }
.cal-day.other-month { opacity: 0.35; }
.cal-day-num {
  font-size: 0.78rem;
  color: var(--text-ghost);
  font-weight: 500;
  align-self: flex-start;
  line-height: 1;
  margin-bottom: 4px;
}
.cal-day.today .cal-day-num { color: var(--primary); font-weight: 700; }

/* Marks container inside a day cell */
.cal-marks {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  justify-content: center;
  align-items: center;
  flex: 1;
  width: 100%;
}
.cal-mark {
  font-size: 1.05rem;
  font-weight: 800;
  line-height: 1;
  transition: transform 0.1s;
}
.cal-mark:hover { transform: scale(1.2); }

.hint {
  font-size: 0.82rem;
  color: var(--text-whisper);
  text-align: center;
  margin-top: -4px;
}

/* ── Symbol + Color Pickers ── */
.symbol-picker, .color-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 4px;
}
.symbol-opt, .color-opt {
  width: 36px; height: 36px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  border: 2px solid transparent;
  font-size: 1.1rem;
  font-weight: 700;
  transition: border-color 0.12s, transform 0.1s;
  background: var(--hover-bg);
}
.symbol-opt:hover, .color-opt:hover { transform: scale(1.08); }
.symbol-opt.selected, .color-opt.selected { border-color: var(--primary); }
.color-opt { border-color: transparent; }
.color-opt.selected { border-color: var(--primary); }

/* ── Modal ── */
.modal {
  position: fixed; inset: 0;
  background: var(--modal-overlay);
  display: flex; align-items: center; justify-content: center;
  z-index: 50;
}
.modal-box {
  background: var(--surface);
  border-radius: 12px;
  padding: 28px 24px;
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.modal-box h3 { margin-bottom: 4px; }
.modal-box label { font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-faint); margin-top: 4px; }
.modal-box input {
  padding: 8px 11px;
  border: 1px solid var(--border-input);
  border-radius: 7px;
  font-size: 0.95rem;
  outline: none;
  background: var(--surface);
  color: var(--text);
}
.modal-box input:focus { border-color: var(--primary); }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 6px; align-items: center; }
#modal-delete { margin-right: auto; }
.btn-danger {
  padding: 8px 14px;
  border: none;
  border-radius: 6px;
  background: #e74c3c;
  color: #fff;
  font-size: 0.9rem;
  cursor: pointer;
}
.btn-danger:hover { background: #c0392b; }

/* ── Stats ── */
.stats-wrapper {
  max-width: 860px;
  margin: 0 auto;
  padding: 28px 20px;
}
.stats-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 12px;
}
.period-tabs { display: flex; gap: 6px; }
.period-btn {
  padding: 6px 14px;
  border-radius: 20px;
  border: 1px solid var(--border-input);
  background: var(--surface);
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text-muted);
  transition: background 0.12s;
}
.period-btn.active { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }
.stats-range { font-size: 0.82rem; color: var(--text-ghost); margin-bottom: 20px; }
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.stat-card-header {
  display: flex;
  align-items: center;
  gap: 10px;
}
.stat-card-name { font-weight: 600; font-size: 0.95rem; }
.stat-bar-bg {
  background: var(--hover-bg);
  border-radius: 100px;
  height: 8px;
  overflow: visible;
  position: relative;
}
.stat-bar-fill {
  height: 100%;
  border-radius: 100px;
  transition: width 0.4s ease;
}
.stat-nums {
  display: flex;
  justify-content: space-between;
  font-size: 0.82rem;
  color: var(--text-dim);
}
.stat-nums strong { color: var(--text); font-size: 0.9rem; }
.stat-streaks {
  display: flex;
  gap: 12px;
  font-size: 0.8rem;
  color: var(--text-faint);
}
.stat-streaks span strong { color: var(--text); }
.loading-msg { color: var(--text-whisper); font-size: 0.9rem; padding: 20px 0; }

/* ── Stats sections ── */
.stats-section { margin-bottom: 8px; }
.stats-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  flex-wrap: wrap;
  gap: 10px;
}
.heatmap-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.heatmap-legend {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.75rem;
  color: var(--text-faint);
}
.legend-swatch {
  width: 12px; height: 12px;
  border-radius: 2px;
  display: inline-block;
}
.legend-label { font-size: 0.72rem; color: var(--text-whisper); }

/* ── Heatmap ── */
.heatmap-container {
  overflow-x: auto;
  padding-bottom: 8px;
}
.heatmap-month-row {
  display: flex;
  align-items: flex-end;
  margin-bottom: 2px;
}
.heatmap-dow-spacer {
  width: 80px;
  flex-shrink: 0;
}
.heatmap-row {
  display: flex;
  align-items: flex-start;
  gap: 4px;
  margin-bottom: 4px;
}
.heatmap-row-label {
  width: 80px;
  min-width: 80px;
  font-size: 0.78rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  padding-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.heatmap-dow-col {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-right: 2px;
}
.heatmap-dow-label {
  height: 11px;
  font-size: 0.65rem;
  color: var(--text-trace);
  line-height: 11px;
  text-align: right;
  padding-right: 2px;
  width: 14px;
}
.heatmap-weeks {
  display: flex;
  gap: 2px;
}
.heatmap-week-col {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.heatmap-cell {
  width: 11px; height: 11px;
  border-radius: 2px;
  background: var(--heatmap-empty);
  cursor: default;
  transition: transform 0.1s;
}
.heatmap-cell:hover { transform: scale(1.3); z-index: 1; position: relative; }
.heatmap-empty {
  background: transparent !important;
}
.heatmap-month-label {
  width: 13px;
  font-size: 0.65rem;
  color: var(--text-ghost);
  white-space: nowrap;
  overflow: visible;
}

/* Minimal (desktop) heatmap rows */
.heatmap-row-minimal { margin-bottom: 3px; }
.heatmap-minimal-weeks { display: flex; gap: 2px; flex: 1; }
.heatmap-minimal-weeks .heatmap-cell {
  flex: 1;
  min-width: 0;
  width: auto;
  height: 16px;
  border-radius: 3px;
}
.heatmap-minimal-weeks .heatmap-month-label {
  flex: 1;
  min-width: 0;
  width: auto;
}

/* Habit detail modal */
.habit-modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--modal-overlay);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.habit-modal {
  background: var(--surface);
  border-radius: 16px;
  padding: 24px;
  max-width: min(90vw, 860px);
  max-height: 80vh;
  overflow-y: auto;
  min-width: min(340px, 90vw);
  border: 1px solid var(--border-subtle);
}
.habit-modal-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.habit-modal-title-row {
  display: flex;
  align-items: center;
  flex: 1;
  min-width: 100px;
}
.habit-modal-close {
  background: none;
  border: 1px solid var(--border-subtle);
  font-size: 1rem;
  cursor: pointer;
  color: var(--text-dim);
  padding: 4px 10px;
  border-radius: 8px;
  line-height: 1.4;
  transition: background 0.15s;
}
.habit-modal-close:hover { background: var(--hover-bg); }
.habit-modal-heatmap { overflow-x: auto; padding-bottom: 4px; }

/* 2-column grid for per-habit heatmap rows */
.heatmap-habit-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 16px;
  margin-top: 6px;
}
@media (max-width: 600px) {
  .heatmap-habit-grid { grid-template-columns: 1fr; }
}

/* ── Period Summary ── */
.summary-nav {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 8px 0 16px;
}
.summary-nav-btn {
  background: var(--surface-raised);
  border: 1px solid var(--border-alt);
  border-radius: 6px;
  padding: 5px 12px;
  font-size: 0.85rem;
  cursor: pointer;
  color: var(--text-muted);
  transition: background 0.15s;
}
.summary-nav-btn:hover:not(:disabled) { background: var(--hover-bg); }
.summary-nav-btn:disabled { opacity: 0.35; cursor: default; }
.summary-label {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text);
  flex: 1;
  text-align: center;
}

/* Overall banner */
.summary-overall {
  background: var(--surface-raised);
  border: 1px solid var(--summary-border);
  border-radius: 12px;
  padding: 20px 24px;
  text-align: center;
  margin-bottom: 20px;
}
.summary-overall-rate {
  font-size: 3rem;
  font-weight: 700;
  line-height: 1;
  color: var(--text);
}
.summary-overall-rate .pct-sign { font-size: 1.5rem; font-weight: 400; color: var(--text-dim); }
.summary-overall-label { font-size: 0.8rem; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.05em; margin: 4px 0 2px; }
.summary-overall-details { font-size: 0.85rem; color: var(--text-muted); margin-bottom: 10px; }
.summary-overall-deltas { display: flex; gap: 16px; justify-content: center; flex-wrap: wrap; }

/* Delta badges */
.summary-delta {
  font-size: 0.82rem;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 20px;
}
.delta-up      { color: var(--delta-up-text);      background: var(--delta-up-bg); }
.delta-down    { color: var(--delta-down-text);    background: var(--delta-down-bg); }
.delta-neutral { color: var(--delta-neutral-text); background: var(--delta-neutral-bg); }

/* Summary table */
.summary-table {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.summary-row {
  display: grid;
  grid-template-columns: 2fr 1.5fr 1fr 1fr;
  align-items: center;
  gap: 12px;
  padding: 10px 8px;
  border-radius: 8px;
}
.summary-row:not(.summary-header-row):hover { background: var(--surface-raised); }
.summary-header-row {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-faint);
  padding-bottom: 6px;
  border-bottom: 1px solid var(--summary-border);
  margin-bottom: 4px;
}
.summary-prev-label, .summary-avg-note {
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
}
.summary-col-habit {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.summary-habit-name {
  font-size: 0.9rem;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.summary-col-rate {
  display: flex;
  align-items: center;
  gap: 6px;
}
.summary-rate-bar-bg {
  flex: 1;
  height: 6px;
  background: var(--summary-border);
  border-radius: 3px;
  overflow: visible;
  position: relative;
  min-width: 40px;
}
.summary-rate-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.4s ease;
}
.summary-rate-num {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
}
.summary-rate-sub {
  font-size: 0.75rem;
  color: var(--text-ghost);
  white-space: nowrap;
}
.summary-col-prev, .summary-col-avg {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.summary-compare-base {
  font-size: 0.72rem;
  color: var(--text-whisper);
}

/* ── Mobile ── */
@media (max-width: 640px) {
  .page-wrapper { flex-direction: column; }
  .sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: 140px;
  }
  .habit-list { display: flex; flex-direction: row; overflow-x: auto; padding: 8px; gap: 6px; }
  .habit-item { flex-shrink: 0; border-left: none; border-radius: 8px; border: 2px solid transparent; padding: 7px 10px; }
  .habit-item.selected { border-color: var(--primary); }
  .habit-item-edit { display: none; }
  .calendar-section { padding: 12px; gap: 8px; }
  .calendar-grid { gap: 3px; }
  .cal-day { min-height: 44px; padding: 4px 2px 2px; }
  .cal-mark { font-size: 0.85rem; }
  .cal-marks { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1px; justify-items: center; }
  .stats-wrapper { padding: 16px 12px; }
  .stats-header { flex-direction: column; align-items: flex-start; }
  .summary-row {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto auto;
    gap: 6px 8px;
  }
  .summary-col-habit { grid-column: 1 / -1; }
  .summary-col-rate  { grid-column: 1 / -1; }
  .summary-header-row { display: none; }
  .summary-col-prev,
  .summary-col-avg {
    flex-direction: row;
    align-items: center;
    flex-wrap: wrap;
    gap: 3px;
  }
  .summary-col-prev::before { content: "vs Prev "; font-size: 0.7rem; color: var(--text-whisper); white-space: nowrap; }
  .summary-col-avg::before  { content: "vs Avg ";  font-size: 0.7rem; color: var(--text-whisper); white-space: nowrap; }
  .summary-col-prev .summary-compare-base,
  .summary-col-avg  .summary-compare-base { display: none; }
}

/* ── Goal features ── */

/* Vertical tick marker on progress bars */
.goal-marker {
  position: absolute;
  top: -8px;
  bottom: -8px;
  width: 2px;
  background: var(--text);
  opacity: 0.45;
  border-radius: 1px;
  transform: translateX(-50%);
  pointer-events: none;
}

/* Goal badge in card header / summary habit name */
.goal-badge {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 20px;
  white-space: nowrap;
  margin-left: 6px;
}
.goal-met   { background: #d4edda; color: #1a6430; }
.goal-unmet { background: var(--hover-bg); color: var(--text-dim); }
@media (prefers-color-scheme: dark) {
  .goal-met   { background: #1a3d26; color: #6fcf97; }
  .goal-unmet { background: var(--hover-surface); color: var(--text-dim); }
}

/* Goal row in habit modal */
.goal-row {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
}
.goal-count-input {
  width: 62px !important;
  text-align: center;
  padding: 8px 6px !important;
}
.goal-period-select {
  padding: 8px 10px;
  border: 1px solid var(--border-input);
  border-radius: 7px;
  font-size: 0.95rem;
  background: var(--surface);
  color: var(--text);
  outline: none;
  cursor: pointer;
}
.goal-period-select:focus { border-color: var(--primary); }
.goal-label-text {
  font-size: 0.9rem;
  color: var(--text-dim);
  white-space: nowrap;
}
.btn-goal-clear {
  background: none;
  border: none;
  color: var(--text-faint);
  cursor: pointer;
  font-size: 0.9rem;
  padding: 4px 6px;
  border-radius: 4px;
  line-height: 1;
}
.btn-goal-clear:hover { color: var(--text); background: var(--hover-bg); }

/* Stat card header — allow goal badge to wrap nicely */
.stat-card-header {
  flex-wrap: wrap;
  gap: 4px;
}
