:root {
  --bg: #0b1220;
  --bg-elevated: #101828;
  --surface: #151d2e;
  --surface-2: #1a2438;
  --border: #243044;
  --border-soft: rgba(36, 48, 68, 0.7);
  --text: #e8eef8;
  --muted: #8b9bb4;
  --accent: #2dd4bf;
  --accent-dim: rgba(45, 212, 191, 0.15);
  --accent-ink: #04201c;
  --blue: #60a5fa;
  --blue-dim: rgba(96, 165, 250, 0.12);
  --danger: #f87171;
  --ok: #34d399;
  --warn: #fbbf24;
  --sidebar-w: 240px;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.28);
  --font: "DM Sans", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: var(--font);
  background:
    radial-gradient(ellipse 80% 50% at 10% -10%, rgba(45, 212, 191, 0.08), transparent 50%),
    radial-gradient(ellipse 60% 40% at 90% 0%, rgba(96, 165, 250, 0.07), transparent 45%),
    var(--bg);
  color: var(--text);
  line-height: 1.45;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

a {
  color: var(--accent);
  text-decoration: none;
}

button {
  cursor: pointer;
  border: none;
  background: none;
}

#app {
  min-height: 100vh;
}

/* —— Auth —— */
.auth-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}

.auth-card {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 2rem;
  box-shadow: var(--shadow);
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.auth-brand h1 {
  margin: 0;
  font-size: 1.45rem;
  letter-spacing: -0.02em;
}

.auth-brand p {
  margin: 0.15rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.logo-mark {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  flex-shrink: 0;
  object-fit: cover;
  display: block;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

.auth-tabs {
  display: flex;
  gap: 0.35rem;
  margin-bottom: 1.25rem;
  background: var(--bg);
  padding: 0.25rem;
  border-radius: 12px;
}

.auth-tabs button {
  flex: 1;
  padding: 0.55rem;
  border-radius: 10px;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.9rem;
}

.auth-tabs button.active {
  background: var(--surface-2);
  color: var(--text);
}

.field {
  display: block;
  margin-bottom: 0.9rem;
}

.field span {
  display: block;
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 0.35rem;
  font-weight: 500;
}

.input {
  width: 100%;
  padding: 0.7rem 0.85rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
}

.input:focus {
  border-color: var(--accent);
}

.textarea {
  min-height: 80px;
  resize: vertical;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.7rem 1.1rem;
  border-radius: var(--radius-sm);
  font-weight: 650;
  font-size: 0.92rem;
  transition: transform 0.12s, opacity 0.12s, background 0.12s;
}

.btn:active {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
}

.btn-primary:hover:not(:disabled) {
  filter: brightness(1.05);
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}

.btn-ghost:hover {
  color: var(--text);
  border-color: #3a4a66;
}

.btn-danger {
  background: rgba(248, 113, 113, 0.15);
  color: var(--danger);
}

.btn-sm {
  padding: 0.4rem 0.7rem;
  font-size: 0.82rem;
}

.btn-block {
  width: 100%;
}

.error-banner {
  background: rgba(248, 113, 113, 0.12);
  border: 1px solid rgba(248, 113, 113, 0.35);
  color: #fecaca;
  padding: 0.65rem 0.85rem;
  border-radius: var(--radius-sm);
  margin-bottom: 1rem;
  font-size: 0.88rem;
}

.muted {
  color: var(--muted);
}

.divider {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 1.1rem 0;
  color: var(--muted);
  font-size: 0.8rem;
}

.divider::before,
.divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* —— Shell —— */
.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  background: rgba(16, 24, 40, 0.92);
  border-right: 1px solid var(--border);
  padding: 1.25rem 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  backdrop-filter: blur(12px);
  z-index: 20;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.35rem 0.55rem 1.1rem;
}

.sidebar-brand strong {
  font-size: 1.05rem;
  letter-spacing: -0.02em;
}

.nav-list {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.65rem 0.75rem;
  border-radius: 11px;
  color: var(--muted);
  font-weight: 550;
  font-size: 0.92rem;
  text-align: left;
  width: 100%;
  transition: background 0.15s, color 0.15s;
}

.nav-item:hover {
  background: var(--surface-2);
  color: var(--text);
}

.nav-item.active {
  background: var(--accent-dim);
  color: var(--accent);
}

.nav-icon {
  width: 1.25rem;
  text-align: center;
  opacity: 0.9;
}

.user-chip {
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.7rem 0.75rem;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--blue), var(--accent));
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--accent-ink);
  flex-shrink: 0;
}

.user-chip .meta {
  min-width: 0;
}

.user-chip .meta strong {
  display: block;
  font-size: 0.88rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-chip .meta span {
  font-size: 0.75rem;
  color: var(--muted);
}

.main {
  min-width: 0;
  padding: 1.25rem 1.5rem 2.5rem;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}

.topbar h2 {
  margin: 0;
  font-size: 1.35rem;
  letter-spacing: -0.02em;
}

.menu-toggle {
  display: none;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 1.1rem;
}

.sidebar-backdrop {
  display: none;
}

/* —— Week strip —— */
.week-strip {
  display: flex;
  gap: 0.45rem;
  overflow-x: auto;
  padding-bottom: 0.25rem;
  margin-bottom: 1.25rem;
  scrollbar-width: thin;
}

.day-chip {
  flex: 0 0 auto;
  min-width: 58px;
  padding: 0.55rem 0.45rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  text-align: center;
  transition: border-color 0.15s, background 0.15s;
}

.day-chip:hover {
  border-color: #3a4a66;
}

.day-chip.active {
  border-color: var(--accent);
  background: var(--accent-dim);
}

.day-chip .dow {
  display: block;
  font-size: 0.7rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
}

.day-chip .dom {
  display: block;
  font-size: 1.15rem;
  font-weight: 700;
  margin-top: 0.1rem;
}

.day-chip.today .dom {
  color: var(--accent);
}

/* —— Layout grids —— */
.grid-2 {
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: 1rem;
  align-items: start;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.15rem;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.9rem;
}

.card-head h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 650;
}

.card-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.progress-bar {
  height: 6px;
  border-radius: 99px;
  background: var(--bg);
  overflow: hidden;
  margin-bottom: 0.85rem;
}

.progress-bar > i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--blue));
  border-radius: inherit;
  transition: width 0.25s ease;
}

/* —— List rows —— */
.row-list {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.row {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.55rem 0.45rem;
  border-radius: 10px;
  transition: background 0.12s;
}

.row:hover {
  background: rgba(255, 255, 255, 0.03);
}

.row.done .row-title {
  text-decoration: line-through;
  color: var(--muted);
}

.check {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  border: 2px solid var(--border);
  flex-shrink: 0;
  display: grid;
  place-items: center;
  transition: background 0.12s, border-color 0.12s;
}

.check.on {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-size: 0.75rem;
  font-weight: 800;
}

.habit-swatch {
  width: 8px;
  height: 28px;
  border-radius: 4px;
  flex-shrink: 0;
}

.row-body {
  flex: 1;
  min-width: 0;
}

.row-title {
  display: block;
  font-weight: 550;
  font-size: 0.92rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.row-sub {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 0.1rem;
}

.streak-badge {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--accent);
  background: var(--accent-dim);
  padding: 0.2rem 0.45rem;
  border-radius: 6px;
  font-weight: 600;
}

.group-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 650;
  margin: 0.75rem 0 0.35rem;
  padding-left: 0.35rem;
}

.group-label:first-child {
  margin-top: 0;
}

.empty {
  text-align: center;
  padding: 1.5rem 1rem;
  color: var(--muted);
  font-size: 0.9rem;
}

/* —— Pulse / stats —— */
.pulse-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
}

.pulse-stat {
  background: var(--bg);
  border: 1px solid var(--border-soft);
  border-radius: 12px;
  padding: 0.85rem;
}

.pulse-stat .val {
  display: block;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.pulse-stat .lbl {
  font-size: 0.75rem;
  color: var(--muted);
}

.pulse-stat.warn .val {
  color: var(--warn);
}

/* —— Heatmap —— */
.heatmap {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(11px, 1fr));
  gap: 3px;
}

.hm-cell {
  aspect-ratio: 1;
  border-radius: 2px;
  background: var(--bg);
}

.hm-cell.l1 {
  background: rgba(45, 212, 191, 0.25);
}
.hm-cell.l2 {
  background: rgba(45, 212, 191, 0.45);
}
.hm-cell.l3 {
  background: rgba(45, 212, 191, 0.7);
}
.hm-cell.l4 {
  background: var(--accent);
}

.hm-legend {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin-top: 0.65rem;
  font-size: 0.72rem;
  color: var(--muted);
}

.hm-legend .hm-cell {
  width: 11px;
  height: 11px;
}

/* —— Rings (stats) —— */
.rings {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  justify-content: center;
  padding: 0.5rem 0 1rem;
}

.ring-wrap {
  text-align: center;
  width: 100px;
}

.ring-wrap svg {
  width: 88px;
  height: 88px;
  transform: rotate(-90deg);
}

.ring-wrap .label {
  font-size: 0.78rem;
  margin-top: 0.35rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ring-wrap .pct {
  font-weight: 700;
  font-size: 0.9rem;
}

/* —— Modal —— */
.modal-root {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(5, 10, 20, 0.65);
  backdrop-filter: blur(4px);
}

.modal {
  width: min(440px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1.35rem;
  box-shadow: var(--shadow);
  max-height: 90vh;
  overflow-y: auto;
}

.modal h3 {
  margin: 0 0 1rem;
  font-size: 1.1rem;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1.15rem;
}

.color-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.color-swatch {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: 2px solid transparent;
  cursor: pointer;
}

.color-swatch.selected {
  border-color: #fff;
  box-shadow: 0 0 0 2px var(--accent);
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.65rem 0;
  border-bottom: 1px solid var(--border-soft);
}

.toggle-row:last-child {
  border-bottom: none;
}

.switch {
  position: relative;
  width: 42px;
  height: 24px;
  border-radius: 99px;
  background: var(--border);
  transition: background 0.15s;
  flex-shrink: 0;
}

.switch.on {
  background: var(--accent);
}

.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.15s;
}

.switch.on::after {
  transform: translateX(18px);
}

.segmented {
  display: inline-flex;
  background: var(--bg);
  border-radius: 10px;
  padding: 0.2rem;
  gap: 0.15rem;
}

.segmented button {
  padding: 0.4rem 0.75rem;
  border-radius: 8px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
}

.segmented button.active {
  background: var(--surface-2);
  color: var(--text);
}

.list-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 1rem;
}

.pill {
  padding: 0.4rem 0.75rem;
  border-radius: 99px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 0.82rem;
  font-weight: 550;
  color: var(--muted);
}

.pill.active {
  border-color: var(--accent);
  background: var(--accent-dim);
  color: var(--accent);
}

.pill .tag {
  font-size: 0.65rem;
  opacity: 0.8;
  margin-left: 0.25rem;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.drag-handle {
  color: var(--muted);
  cursor: grab;
  padding: 0.25rem;
  font-size: 0.9rem;
  user-select: none;
}

.row.dragging {
  opacity: 0.5;
}

.loading {
  padding: 2rem;
  text-align: center;
  color: var(--muted);
}

.settings-section {
  margin-bottom: 1.5rem;
}

.settings-section h3 {
  margin: 0 0 0.75rem;
  font-size: 0.95rem;
}

.mono {
  font-family: var(--mono);
  font-size: 0.82rem;
}

/* —— Habits home (mobile-parity) —— */
.habit-home {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.habit-home-header {
  display: flex;
  align-items: flex-end;
  gap: 0.4rem;
  padding: 0.75rem 0.85rem 0.4rem;
  border-bottom: 1px solid var(--border-soft);
}

.habit-home-header .brand-spacer {
  flex: 1;
  min-width: 0;
}

.habit-days-col {
  width: 116px;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.habit-day-slot {
  width: 36px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.habit-day-head {
  width: 36px;
  text-align: center;
}

.habit-day-head .lbl {
  display: block;
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--muted);
}

.habit-day-head .num {
  display: block;
  font-size: 0.62rem;
  color: var(--muted);
  opacity: 0.8;
}

.habit-stats-col {
  width: 52px;
  flex-shrink: 0;
}

.habit-group-title {
  padding: 0.85rem 0.85rem 0.35rem;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--accent);
  border-bottom: 1px solid var(--border-soft);
}

.habit-mrow {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 0.85rem;
  border-bottom: 1px solid var(--border-soft);
  min-height: 52px;
}

.habit-mrow:last-child {
  border-bottom: none;
}

.habit-identity {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  min-width: 0;
  flex: 0 1 42%;
  max-width: 280px;
  cursor: pointer;
  text-align: left;
  background: none;
  border: none;
  color: inherit;
  padding: 0;
}

.habit-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  font-size: 0.85rem;
  font-weight: 700;
  flex-shrink: 0;
}

.habit-name-block {
  min-width: 0;
}

.habit-name-block .name {
  display: block;
  font-size: 0.84rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.habit-name-block .notes {
  display: block;
  font-size: 0.7rem;
  color: var(--muted);
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.habit-mini-wrap {
  flex: 1;
  min-width: 0;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  padding: 0 2px;
}

.mini-hm {
  display: flex;
  flex-direction: column;
  gap: 1px;
  align-items: flex-end;
}

.mini-hm-row {
  display: flex;
  align-items: center;
}

.mini-hm-row i {
  display: block;
  flex-shrink: 0;
}

.day-check {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  border: 1.5px solid;
  background: transparent;
  display: grid;
  place-items: center;
  padding: 0;
  transition: background 0.12s, transform 0.12s;
  color: #041018;
  font-size: 0.7rem;
  font-weight: 800;
}

.day-check:hover {
  transform: scale(1.06);
}

.day-check.on {
  /* background set inline via habit color */
}

.day-check.skip {
  font-weight: 700;
}

.habit-stat-pills {
  width: 52px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  flex-shrink: 0;
}

.stat-pill {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 1px 5px;
  border-radius: 6px;
  font-size: 0.7rem;
  font-weight: 700;
  line-height: 1.2;
}

.reorder-btns {
  display: flex;
  flex-direction: column;
  gap: 0;
  margin-right: 2px;
}

.reorder-btns button {
  padding: 0;
  color: var(--accent);
  font-size: 1rem;
  line-height: 1;
  opacity: 0.9;
}

.reorder-btns button:disabled {
  opacity: 0.25;
  cursor: default;
}

/* —— Stats (mobile-parity) —— */
.stats-page {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  max-width: 640px;
}

.stats-summary {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.25rem 0.15rem;
}

.stats-summary .summary-copy h3 {
  margin: 0 0 0.35rem;
  font-size: 1.15rem;
}

.stats-summary .summary-copy p {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.4;
}

.progress-ring {
  position: relative;
  width: 88px;
  height: 88px;
  flex-shrink: 0;
}

.progress-ring svg {
  width: 88px;
  height: 88px;
  transform: rotate(-90deg);
}

.progress-ring .ring-label {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 1.05rem;
}

.stats-metrics {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.5rem;
  padding: 0.15rem 0.25rem 0.35rem;
}

.stats-metric {
  text-align: center;
}

.stats-metric .val {
  display: block;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--accent);
}

.stats-metric .lbl {
  font-size: 0.7rem;
  color: var(--muted);
}

.stats-hint {
  margin: 0 0 0.55rem;
  font-size: 0.78rem;
  color: var(--muted);
}

.cal-heatmap {
  width: 100%;
  overflow-x: auto;
}

.cal-months {
  display: flex;
  position: relative;
  height: 16px;
  margin-left: 18px;
  margin-bottom: 2px;
  font-size: 0.65rem;
  color: var(--muted);
}

.cal-months span {
  position: absolute;
}

.cal-body {
  display: flex;
  gap: 0;
}

.cal-dow {
  width: 18px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  font-size: 0.6rem;
  color: var(--muted);
  flex-shrink: 0;
}

.cal-grid {
  display: grid;
  grid-auto-flow: column;
  grid-template-rows: repeat(7, var(--cal-cell, 12px));
  gap: 3px;
}

.cal-cell {
  width: var(--cal-cell, 12px);
  height: var(--cal-cell, 12px);
  border-radius: 2px;
  background: var(--surface-2);
}

.cal-legend {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.65rem;
  font-size: 0.72rem;
  color: var(--muted);
}

.cal-legend .swatch {
  width: 12px;
  height: 12px;
  border-radius: 2px;
}

.line-chart,
.bar-chart {
  width: 100%;
  overflow: hidden;
}

.habit-line {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.4rem 0;
}

.habit-line .dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.habit-line .nm {
  flex: 1;
  font-weight: 600;
  font-size: 0.9rem;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.habit-line .meta {
  font-size: 0.75rem;
  color: var(--muted);
  flex-shrink: 0;
}

/* —— Badges / insights / templates —— */
.badge {
  display: inline-flex;
  align-items: center;
  vertical-align: middle;
  padding: 0.1rem 0.4rem;
  border-radius: 6px;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 1.3;
  background: var(--surface-2);
  color: var(--muted);
  margin-left: 0.25rem;
}

.badge-skip,
.day-check.skip {
  color: var(--warn);
}

.badge-overdue {
  background: rgba(248, 113, 113, 0.15);
  color: var(--danger);
}

.badge-milestone {
  background: rgba(45, 212, 191, 0.18);
  color: var(--accent);
}

.badge-shared,
.badge-numeric,
.badge-recurrence {
  background: var(--blue-dim);
  color: var(--blue);
}

.row.overdue .row-title {
  color: #fecaca;
}

.row.overdue .row-sub {
  color: rgba(248, 113, 113, 0.85);
}

.check-field {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  margin-bottom: 0.9rem;
  cursor: pointer;
}

.check-field span {
  display: inline;
  margin: 0;
  color: var(--text);
  font-size: 0.9rem;
}

.check-field input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.modal-wide {
  width: min(560px, 100%);
}

.template-grid {
  display: grid;
  gap: 0.55rem;
}

.template-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.2rem;
  width: 100%;
  text-align: left;
  padding: 0.85rem 0.95rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  transition: border-color 0.15s, background 0.15s;
}

.template-card:hover {
  border-color: var(--accent);
  background: var(--accent-dim);
}

.template-card strong {
  font-size: 0.95rem;
}

.template-preview {
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.35;
}

.insight-list {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.insight-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.45rem 0.15rem;
  font-size: 0.88rem;
  border-bottom: 1px solid var(--border-soft);
}

.insight-row:last-child {
  border-bottom: none;
}

.ctx-menu {
  position: fixed;
  z-index: 220;
  min-width: 140px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 0.3rem;
  display: flex;
  flex-direction: column;
}

.ctx-menu button {
  text-align: left;
  padding: 0.5rem 0.7rem;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 550;
  color: var(--text);
}

.ctx-menu button:hover {
  background: var(--surface-2);
}

/* —— Responsive —— */
@media (max-width: 960px) {
  .grid-2 {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .habit-mini-wrap {
    display: none;
  }

  .habit-identity {
    flex: 1;
    max-width: none;
  }

  .stats-metrics {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
  }
}

@media (max-width: 760px) {
  .shell {
    grid-template-columns: 1fr;
  }

  .menu-toggle {
    display: grid;
    place-items: center;
  }

  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: min(280px, 86vw);
    transform: translateX(-105%);
    transition: transform 0.2s ease;
    box-shadow: var(--shadow);
  }

  .shell.nav-open .sidebar {
    transform: translateX(0);
  }

  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 15;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
  }

  .shell.nav-open .sidebar-backdrop {
    opacity: 1;
    pointer-events: auto;
  }

  .main {
    padding: 1rem;
  }
}
