:root {
  --bg: #f4f1ee;
  --surface: #ffffff;
  --surface-hover: #f9f7f5;
  --border: #e2ddd8;
  --text: #2c2c2c;
  --text-secondary: #6b6560;
  --accent: #5b8a72;
  --accent-hover: #4a7660;
  --accent-light: #e8f0ec;
  --danger: #c0564f;
  --danger-hover: #a8473f;
  --completed: #5b8a72;
  --missed: #e2ddd8;
  --streak: #d4a853;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.06);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

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

.app {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 0 24px;
}

header h1 {
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.date-display {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

/* Navigation tabs */
.nav-tabs {
  display: flex;
  gap: 4px;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 4px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}

.nav-tab {
  flex: 1;
  padding: 8px 12px;
  border: none;
  background: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.875rem;
  color: var(--text-secondary);
  font-weight: 500;
  transition: all 0.15s ease;
}

.nav-tab:hover {
  background: var(--surface-hover);
}

.nav-tab.active {
  background: var(--accent);
  color: white;
}

/* Habit list */
.habit-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.habit-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: var(--shadow);
  transition: background 0.15s ease;
}

.habit-card:hover {
  background: var(--surface-hover);
}

.habit-checkbox {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid var(--border);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.15s ease;
  background: none;
  padding: 0;
}

.habit-checkbox:hover {
  border-color: var(--accent);
}

.habit-checkbox.checked {
  background: var(--completed);
  border-color: var(--completed);
}

.habit-checkbox.checked svg {
  display: block;
}

.habit-checkbox svg {
  display: none;
  width: 12px;
  height: 12px;
  stroke: white;
  stroke-width: 3;
  fill: none;
}

.habit-info {
  flex: 1;
  min-width: 0;
}

.habit-name {
  font-weight: 500;
  font-size: 0.9375rem;
}

.habit-card.completed .habit-name {
  text-decoration: line-through;
  color: var(--text-secondary);
}

.habit-description {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.habit-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.streak-badge {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.8125rem;
  color: var(--streak);
  font-weight: 600;
}

.streak-badge svg {
  width: 14px;
  height: 14px;
}

.habit-actions {
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.habit-card:hover .habit-actions {
  opacity: 1;
}

.action-btn {
  background: none;
  border: none;
  padding: 4px;
  cursor: pointer;
  border-radius: 4px;
  color: var(--text-secondary);
  transition: all 0.15s ease;
}

.action-btn:hover {
  background: var(--bg);
  color: var(--text);
}

.action-btn.delete:hover {
  color: var(--danger);
}

.action-btn svg {
  width: 16px;
  height: 16px;
}

/* Add habit button */
.add-habit-btn {
  width: 100%;
  padding: 12px;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  background: none;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 0.875rem;
  font-weight: 500;
  margin-top: 8px;
  transition: all 0.15s ease;
}

.add-habit-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-light);
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 100;
  opacity: 0;
  visibility: hidden;
  transition: all 0.2s ease;
}

.modal-overlay.open {
  opacity: 1;
  visibility: visible;
}

.modal {
  background: var(--surface);
  border-radius: 12px;
  padding: 24px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.12);
  transform: translateY(10px);
  transition: transform 0.2s ease;
}

.modal-overlay.open .modal {
  transform: translateY(0);
}

.modal h2 {
  font-size: 1.125rem;
  margin-bottom: 20px;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-group input,
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.9375rem;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.15s ease;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--accent);
}

.form-group textarea {
  resize: vertical;
  min-height: 60px;
}

.days-picker {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.day-toggle {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: none;
  cursor: pointer;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-secondary);
  transition: all 0.15s ease;
}

.day-toggle.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 20px;
}

.btn {
  padding: 8px 20px;
  border-radius: 6px;
  border: none;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-primary {
  background: var(--accent);
  color: white;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--bg);
  color: var(--text);
}

.btn-secondary:hover {
  background: var(--border);
}

.btn-danger {
  background: var(--danger);
  color: white;
}

.btn-danger:hover {
  background: var(--danger-hover);
}

/* Progress view */
.progress-section {
  margin-bottom: 24px;
}

.progress-habit-name {
  font-weight: 500;
  font-size: 0.9375rem;
  margin-bottom: 8px;
}

.week-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  margin-bottom: 4px;
}

.week-label {
  text-align: center;
  font-size: 0.6875rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.day-cell {
  aspect-ratio: 1;
  border-radius: 4px;
  background: var(--bg);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.6875rem;
  color: var(--text-secondary);
}

.day-cell.completed {
  background: var(--completed);
  color: white;
}

.day-cell.missed {
  background: var(--missed);
}

.day-cell.today {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

.day-cell.not-scheduled {
  background: transparent;
}

.day-cell.future {
  background: transparent;
  border: 1px dashed var(--border);
}

.calendar-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.calendar-nav button {
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px;
  border-radius: 6px;
  color: var(--text-secondary);
  transition: all 0.15s ease;
}

.calendar-nav button:hover {
  background: var(--surface);
  color: var(--text);
}

.calendar-nav span {
  font-weight: 500;
  font-size: 0.9375rem;
}

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

.calendar-day-label {
  text-align: center;
  font-size: 0.6875rem;
  color: var(--text-secondary);
  padding: 4px 0;
  font-weight: 500;
}

.calendar-day {
  aspect-ratio: 1;
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  cursor: pointer;
  transition: background 0.15s ease;
  position: relative;
}

.calendar-day:hover {
  background: var(--surface-hover);
}

.calendar-day.today {
  font-weight: 600;
}

.calendar-day .day-number {
  font-size: 0.75rem;
  margin-bottom: 2px;
}

.calendar-day .completion-dots {
  display: flex;
  gap: 2px;
}

.completion-dot {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--border);
}

.completion-dot.filled {
  background: var(--completed);
}

.calendar-day.other-month {
  color: var(--border);
}

/* Stats */
.stats-section {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}

.stats-habit-name {
  font-weight: 500;
  font-size: 0.9375rem;
  margin-bottom: 12px;
}

.stats-row {
  display: flex;
  gap: 16px;
}

.stat-item {
  flex: 1;
}

.stat-label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.stat-value {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--accent);
}

.stat-bar {
  height: 4px;
  background: var(--bg);
  border-radius: 2px;
  margin-top: 6px;
  overflow: hidden;
}

.stat-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.3s ease;
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 48px 16px;
  color: var(--text-secondary);
}

.empty-state p {
  margin-bottom: 16px;
  font-size: 0.9375rem;
}

/* Date navigator */
.date-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 16px;
}

.date-nav button {
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  color: var(--text-secondary);
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
}

.date-nav button:hover {
  background: var(--surface);
  color: var(--text);
}

.date-nav .current-date {
  font-weight: 500;
  font-size: 0.9375rem;
  min-width: 160px;
  text-align: center;
}

.today-btn {
  font-size: 0.75rem;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: none;
  cursor: pointer;
  color: var(--text-secondary);
  transition: all 0.15s ease;
}

.today-btn:hover {
  background: var(--surface);
  border-color: var(--accent);
  color: var(--accent);
}

.today-btn.hidden {
  visibility: hidden;
}

/* Frequency badge */
.freq-badge {
  font-size: 0.6875rem;
  color: var(--text-secondary);
  background: var(--bg);
  padding: 2px 8px;
  border-radius: 10px;
}

/* Responsive */
@media (max-width: 480px) {
  .app {
    padding: 12px;
  }

  header {
    padding: 12px 0 16px;
  }

  .habit-actions {
    opacity: 1;
  }

  .habit-card {
    padding: 12px;
  }

  .modal {
    padding: 20px;
  }

  .stats-row {
    gap: 12px;
  }
}

/* Confirm dialog */
.confirm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 200;
}

.confirm-dialog {
  background: var(--surface);
  border-radius: 12px;
  padding: 24px;
  max-width: 340px;
  width: 100%;
  box-shadow: 0 8px 30px rgba(0,0,0,0.12);
}

.confirm-dialog p {
  margin-bottom: 16px;
  font-size: 0.9375rem;
}

.confirm-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}
