/* ── Modal ────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeOverlay 0.2s ease;
}

@keyframes fadeOverlay {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

.modal {
  background: var(--card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 520px;
  max-height: 90dvh;
  overflow-y: auto;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
  animation: slideUp 0.25s ease;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 0;
  margin-bottom: 20px;
}

.modal-title {
  font-family: var(--font-display);
  font-size: 1.125rem;
  font-weight: 700;
}

.modal-close {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.18s;
  padding: 0;
}

.modal-close:hover {
  background: var(--danger-dim);
  color: var(--danger);
  border-color: transparent;
}

.modal-body {
  padding: 0 24px 24px;
}

.modal-footer {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
}

@media (max-width: 560px) {
  .modal-overlay {
    align-items: flex-end;
    padding: 0;
  }

  .modal {
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    max-height: 92dvh;
  }
}

/* ── Toast ────────────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: calc(var(--mob-nav-h) + 16px);
  right: 16px;
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

@media (min-width: 769px) {
  #toast-container {
    bottom: 24px;
  }
}

.toast {
  background: var(--card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: 0.875rem;
  font-weight: 500;
  box-shadow: var(--shadow);
  max-width: 320px;
  animation: slideUp 0.3s ease;
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 10px;
}

.toast.success {
  border-color: rgba(0, 217, 166, 0.4);
  background: var(--green-dim);
  color: var(--green);
}

.toast.error {
  border-color: rgba(255, 79, 94, 0.4);
  background: var(--danger-dim);
  color: var(--danger);
}

.toast.warning {
  border-color: rgba(255, 179, 71, 0.4);
  background: var(--warning-dim);
  color: var(--warning);
}

@keyframes toastOut {
  to {
    opacity: 0;
    transform: translateX(20px);
  }
}

.toast.removing {
  animation: toastOut 0.2s ease forwards;
}

/* ── Heatmap ──────────────────────────────────────────────────── */
.heatmap-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.heatmap-grid {
  display: grid;
  grid-template-columns: repeat(30, 1fr);
  gap: 4px;
  min-width: 480px;
}

.heatmap-day {
  font-size: 0.55rem;
  font-weight: 600;
  color: var(--text-muted);
  pointer-events: none;
  line-height: 1;
}

.heatmap-cell {
  aspect-ratio: 1;
  border-radius: 4px;
  background: var(--border);
  position: relative;
  cursor: pointer;
  transition: transform 0.15s;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.heatmap-cell:hover {
  transform: scale(1.3);
  z-index: 10;
}

/* Completion intensity colors */
.heatmap-cell[data-pct="0"] {
  background: var(--border);
}

.heatmap-cell[data-pct="1"] {
  background: rgba(108, 99, 255, 0.15);
}

.heatmap-cell[data-pct="2"] {
  background: rgba(108, 99, 255, 0.3);
}

.heatmap-cell[data-pct="3"] {
  background: rgba(108, 99, 255, 0.5);
}

.heatmap-cell[data-pct="4"] {
  background: rgba(108, 99, 255, 0.7);
}

.heatmap-cell[data-pct="5"] {
  background: var(--accent);
}

/* Bad habit slip dot overlay */
.heatmap-cell .slip-dot {
  position: absolute;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  bottom: 1px;
}

.heatmap-cell .slip-dot.slip-1 {
  right: 3px;
  background: var(--danger);
}

.heatmap-cell .slip-dot.slip-2 {
  right: 10px;
  background: var(--warning);
}

.heatmap-tooltip {
  position: fixed;
  background: var(--card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 0.75rem;
  z-index: 500;
  pointer-events: none;
  box-shadow: var(--shadow);
  white-space: nowrap;
  transform: translate(-50%, -100%) translateY(-8px);
}

/* Mobile: 3 rows of 10 days */
@media (max-width: 600px) {
  .heatmap-grid {
    grid-template-columns: repeat(10, 1fr);
    min-width: 0;
    gap: 5px;
  }

  .heatmap-wrapper {
    overflow-x: visible;
  }

  .heatmap-cell {
    border-radius: 5px;
  }

  .heatmap-day {
    font-size: 0.65rem;
  }
}

/* ── Task Item ────────────────────────────────────────────────── */
.task-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
  transition: opacity 0.18s;
  min-height: 44px;
}

.task-item:last-child {
  border-bottom: none;
}

.task-item.done {
  opacity: 0.45;
}

.task-item.done .task-title {
  text-decoration: line-through;
  color: var(--text-muted);
}

.task-cat-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}

.task-title {
  flex: 1;
  font-size: 0.9rem;
  line-height: 1.35;
}

.task-goal-tag {
  font-size: 0.7rem;
  color: var(--text-muted);
  background: var(--border);
  padding: 2px 7px;
  border-radius: 100px;
  white-space: nowrap;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  flex-shrink: 0;
}

.task-delete-btn {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 0.875rem;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: all 0.15s;
  padding: 0;
  flex-shrink: 0;
}

.task-item:hover .task-delete-btn {
  opacity: 1;
}

.task-delete-btn:hover {
  background: var(--danger-dim);
  color: var(--danger);
}

/* ── Add Task Inline ──────────────────────────────────────────── */
.add-task-row {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.add-task-input {
  flex: 1;
  padding: 8px 12px;
  font-size: 0.875rem;
  background: var(--surface);
  border: 1px dashed var(--border-light);
  border-radius: var(--radius-sm);
  color: var(--text);
  outline: none;
  transition: border-color 0.18s;
}

.add-task-input:focus {
  border-color: var(--accent);
  border-style: solid;
}

.add-task-input::placeholder {
  color: var(--text-dim);
  font-size: 0.8125rem;
}

/* ── Goal Card ────────────────────────────────────────────────── */
.goal-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  cursor: pointer;
  transition: all 0.22s;
  position: relative;
  overflow: hidden;
}

.goal-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--cat-color, var(--accent));
  opacity: 0;
  transition: opacity 0.22s;
}

.goal-card:hover {
  border-color: var(--border-light);
  box-shadow: var(--shadow);
  transform: translateY(-2px);
}

.goal-card:hover::before {
  opacity: 1;
}

.goal-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 14px;
}

.goal-icon-wrap {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  background: var(--cat-bg, var(--accent-dim));
  border: 1px solid var(--border);
}

.goal-status-badge {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 100px;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.goal-status-badge.on-track {
  background: var(--green-dim);
  color: var(--green);
}

.goal-status-badge.at-risk {
  background: var(--warning-dim);
  color: var(--warning);
}

.goal-status-badge.behind {
  background: var(--danger-dim);
  color: var(--danger);
}

.goal-status-badge.no-tasks {
  background: var(--border);
  color: var(--text-muted);
}

.goal-status-badge.completed {
  background: var(--accent-dim);
  color: var(--accent);
}

.goal-card-title {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 4px;
  line-height: 1.3;
}

.goal-card-cat {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 5px;
}

.goal-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 14px;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.goal-pct {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.875rem;
  color: var(--text);
}

/* ── Habit Row ────────────────────────────────────────────────── */
.habit-row {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  transition: border-color 0.18s;
}

.habit-row-top {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.habit-icon {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  background: var(--border);
  flex-shrink: 0;
}

.habit-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.9375rem;
  flex: 1;
}

.habit-streaks {
  display: flex;
  gap: 12px;
  font-size: 0.75rem;
}

.streak-item {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.streak-val {
  font-family: var(--font-display);
  font-size: 1.125rem;
  font-weight: 800;
  line-height: 1;
}

.streak-label {
  color: var(--text-muted);
  font-size: 0.625rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-top: 2px;
}

/* 30-day mini calendar for habits */
.habit-mini-cal {
  display: grid;
  grid-template-columns: repeat(30, 1fr);
  gap: 3px;
}

.mini-cal-dot {
  aspect-ratio: 1;
  border-radius: 3px;
  background: var(--border);
  transition: background 0.15s;
}

.mini-cal-dot.done {
  background: var(--habit-color, var(--green));
}

.mini-cal-dot.missed {
  background: var(--border);
}

.mini-cal-dot.future {
  background: transparent;
  border: 1px solid var(--border);
  opacity: 0.3;
}

/* ── Bad Habit Card ───────────────────────────────────────────── */
.bad-habit-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  display: flex;
  align-items: center;
  gap: 14px;
}

.bad-habit-info {
  flex: 1;
}

.bad-habit-name {
  font-family: var(--font-display);
  font-weight: 700;
  margin-bottom: 2px;
}

.bad-habit-streak {
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.bad-habit-streak span {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.125rem;
  color: var(--green);
}

.slip-btn {
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  background: var(--danger-dim);
  border: 1px solid rgba(255, 79, 94, 0.25);
  color: var(--danger);
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.18s;
  white-space: nowrap;
  flex-shrink: 0;
}

.slip-btn:hover {
  background: var(--danger);
  color: #fff;
}

.slip-btn.slipped-today {
  background: var(--border);
  color: var(--text-muted);
  border-color: transparent;
  cursor: default;
}

/* ── Note Card ────────────────────────────────────────────────── */
.note-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  transition: all 0.2s;
}

.note-card:hover {
  border-color: var(--accent);
  box-shadow: 0 4px 20px rgba(108, 99, 255, 0.1);
  transform: translateY(-2px);
}

.note-card-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.9375rem;
  margin-bottom: 6px;
}

.note-card-body {
  font-size: 0.875rem;
  color: var(--text-muted);
  line-height: 1.55;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.note-card-footer {
  margin-top: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px;
}

.note-date {
  font-size: 0.7rem;
  color: var(--text-dim);
}

.note-tags {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}

.note-tag {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 2px 8px;
  border-radius: 100px;
  background: var(--accent-dim);
  color: var(--accent);
}

/* ── Check-in Card (history) ──────────────────────────────────── */
.checkin-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
}

.checkin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.checkin-date {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.checkin-mood {
  font-size: 1.25rem;
}

.checkin-field {
  margin-bottom: 6px;
  font-size: 0.875rem;
  line-height: 1.5;
}

.checkin-field-label {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-dim);
  margin-right: 6px;
}

/* ── AI Coach Card ────────────────────────────────────────────── */
.ai-coach-card {
  background: linear-gradient(135deg, rgba(108, 99, 255, 0.08) 0%, rgba(0, 217, 166, 0.05) 100%);
  border: 1px solid rgba(108, 99, 255, 0.25);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  margin-bottom: 20px;
}

.ai-coach-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.ai-coach-label {
  font-family: var(--font-display);
  font-size: 0.6875rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--accent);
}

.ai-coach-text {
  font-size: 0.9375rem;
  line-height: 1.6;
  color: var(--text);
}

.ai-coach-muted {
  color: var(--text-muted);
  font-size: 0.875rem;
  font-style: italic;
}

.ai-refresh-btn {
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  background: var(--accent-dim);
  border: 1px solid rgba(108, 99, 255, 0.25);
  color: var(--accent);
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.18s;
  margin-top: 10px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.ai-refresh-btn:hover {
  background: var(--accent);
  color: #fff;
}

/* ── Goals Progress (dashboard) ───────────────────────────────── */
.goals-progress-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.goal-progress-item {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
}

.goal-progress-top {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.goal-progress-icon {
  font-size: 1.125rem;
}

.goal-progress-title {
  flex: 1;
  font-weight: 600;
  font-size: 0.9rem;
}

.goal-progress-pct {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 0.875rem;
}

/* ── Tag filter bar ───────────────────────────────────────────── */
.tag-filter-bar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.tag-filter-btn {
  padding: 5px 14px;
  border-radius: 100px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}

.tag-filter-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.tag-filter-btn.active {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

/* ── Settings Section ─────────────────────────────────────────── */
.settings-section {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin-bottom: 20px;
}

.settings-section-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  font-family: var(--font-display);
  font-size: 0.8125rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  gap: 16px;
}

.settings-row:last-child {
  border-bottom: none;
}

.settings-row-label {
  font-weight: 500;
  font-size: 0.9375rem;
}

.settings-row-sub {
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.settings-row-control {
  flex-shrink: 0;
}

/* ── Goal detail view ─────────────────────────────────────────── */
.goal-detail-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
}

.goal-detail-icon {
  width: 56px;
  height: 56px;
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.75rem;
  background: var(--card);
  border: 1px solid var(--border);
}

.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  background: none;
  border: none;
  padding: 0;
  margin-bottom: 16px;
  transition: color 0.15s;
}

.back-btn:hover {
  color: var(--accent);
}

/* ── Emoji Picker ─────────────────────────────────────────────── */
.emoji-picker-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
  max-height: 180px;
  overflow-y: auto;
  padding: 4px;
}

.emoji-option {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 8px;
  border: 2px solid transparent;
  background: var(--surface);
  font-size: 1.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s;
  padding: 0;
}

.emoji-option:hover {
  background: var(--card-hover);
  border-color: var(--border-light);
}

.emoji-option.selected {
  border-color: var(--accent);
  background: var(--accent-dim);
}