:root {
  /* Colors */
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --bg-color: #f8fafc;
  --card-bg: #ffffff;
  --text-main: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --success: #22c55e;
  --danger: #ef4444;
  
  /* Layout */
  --header-height: 60px;
  --nav-height: 60px;
  --max-width: 600px; /* Mobile focused */
  
  /* Shadows */
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1);
  
  /* Transitions */
  --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="dark"] {
  --bg-color: #0f172a;
  --card-bg: #1e293b;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --border: #334155;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: 'Inter', -apple-system, sans-serif;
  background-color: var(--bg-color);
  color: var(--text-main);
  line-height: 1.5;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Typography */
h1, h2, h3 { font-weight: 700; }
a { color: var(--primary); text-decoration: none; }

/* Header */
.header {
  height: var(--header-height);
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--card-bg); /* Glassmorphism fallback */
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-content {
  width: 100%;
  max-width: var(--max-width);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.logo {
  font-size: 1.25rem;
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  background: none;
  border: none;
  font-size: 1.2rem;
  cursor: pointer;
  padding: 8px;
  border-radius: 50%;
  transition: var(--transition);
}

.icon-btn:hover { background-color: rgba(99, 102, 241, 0.1); }

/* Main Content */
.main {
  flex: 1;
  overflow-y: auto;
  padding-bottom: calc(var(--nav-height) + 20px);
  position: relative;
}

.view {
  display: none;
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 20px;
  animation: fadeIn 0.3s ease;
}

.view.active { display: block; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Today View Components */
.date-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 30px;
  background: var(--card-bg);
  padding: 10px 20px;
  border-radius: 20px;
  box-shadow: var(--shadow-sm);
}

.date-nav {
  background: none;
  border: none;
  font-size: 1.2rem;
  color: var(--text-muted);
  cursor: pointer;
  padding: 5px 10px;
}

.date-display {
  text-align: center;
  display: flex;
  flex-direction: column;
}

.current-date { font-weight: 600; font-size: 1.1rem; }
.today-label { font-size: 0.8rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 1px; }

/* Progress Ring */
.progress-ring-container {
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  margin: 20px 0 40px;
}

.progress-ring { width: 120px; height: 120px; transform: rotate(-90deg); }
.progress-ring-bg { fill: none; stroke: var(--border); stroke-width: 8; }
.progress-ring-fill {
  fill: none;
  stroke: var(--primary);
  stroke-width: 8;
  stroke-linecap: round;
  stroke-dasharray: 326.72; /* 2 * PI * 52 */
  stroke-dashoffset: 326.72;
  transition: stroke-dashoffset 0.5s ease;
}

.progress-text {
  position: absolute;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-main);
}

/* Habits List */
.habits-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.habit-card {
  background: var(--card-bg);
  border-radius: 16px;
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
  border: 1px solid transparent;
  cursor: pointer;
}

.habit-card:active { transform: scale(0.98); }
.habit-card.completed {
  background:  linear-gradient(to right, rgba(255, 255, 255, 0), rgba(34, 197, 94, 0.05));
  border-color: var(--success);
}
[data-theme="dark"] .habit-card.completed {
  background: linear-gradient(to right, rgba(30, 41, 59, 0), rgba(34, 197, 94, 0.1));
}

.habit-info {
  display: flex;
  align-items: center;
  gap: 15px;
  flex: 1;
}

.habit-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  background: var(--bg-color);
  transition: var(--transition);
}

.habit-card.completed .habit-icon {
  background: var(--success);
  color: white;
}

.habit-details h3 { font-size: 1rem; margin-bottom: 2px; }
.habit-details p { font-size: 0.8rem; color: var(--text-muted); }

.habit-streak {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
}
.habit-card.completed .habit-streak { color: var(--success); }

.habit-actions {
  display: flex;
  gap: 8px;
}

.check-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: transparent;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: var(--transition);
  color: transparent;
}

.habit-card.completed .check-btn {
  background: var(--success);
  border-color: var(--success);
  color: white;
}

/* FAB */
.fab {
  position: fixed;
  bottom: calc(var(--nav-height) + 20px);
  right: 20px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  border: none;
  font-size: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-lg);
  cursor: pointer;
  transition: var(--transition);
  z-index: 90;
}

.fab:hover { transform: translateY(-2px); background: var(--primary-dark); }
.fab:active { transform: translateY(0); }

/* Stats View */
.section-title { font-size: 1.5rem; margin-bottom: 20px; }
.subsection-title { font-size: 1.1rem; margin: 30px 0 15px; }

.stats-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 15px;
}

.stat-card {
  background: var(--card-bg);
  padding: 20px;
  border-radius: 16px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.stat-icon { font-size: 1.5rem; margin-bottom: 10px; }
.stat-value { font-size: 1.8rem; font-weight: 700; color: var(--text-main); }
.stat-label { font-size: 0.8rem; color: var(--text-muted); }

.calendar-heatmap {
  background: var(--card-bg);
  padding: 15px;
  border-radius: 16px;
  overflow-x: auto;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.calendar-day {
  width: 12px;
  height: 12px;
  border-radius: 2px;
  background: var(--border);
}
.calendar-day.level-1 { background: #bbf7d0; }
.calendar-day.level-2 { background: #86efac; }
.calendar-day.level-3 { background: #4ade80; }
.calendar-day.level-4 { background: #22c55e; }

/* Settings View */
.settings-section {
  background: var(--card-bg);
  border-radius: 16px;
  padding: 20px;
  margin-bottom: 15px;
  box-shadow: var(--shadow-sm);
}

.manage-habits { display: flex; flex-direction: column; gap: 10px; }

.habit-item-mini {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.habit-item-mini:last-child { border-bottom: none; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: 12px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: var(--transition);
  width: 100%;
}

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--bg-color); color: var(--text-main); }
.btn-danger { background: var(--danger); color: white; }

.data-buttons { display: grid; gap: 10px; }

.toggle-switch {
  display: flex;
  align-items: center;
  cursor: pointer;
  gap: 10px;
}

.toggle-switch input { display: none; }
.toggle-slider {
  width: 44px;
  height: 24px;
  background: var(--border);
  border-radius: 24px;
  position: relative;
  transition: .3s;
}
.toggle-slider:before {
  content: "";
  position: absolute;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  left: 2px;
  bottom: 2px;
  background: white;
  transition: .3s;
}
input:checked + .toggle-slider { background: var(--primary); }
input:checked + .toggle-slider:before { transform: translateX(20px); }

/* Bottom Nav */
.bottom-nav {
  position: fixed;
  bottom: 0;
  width: 100%;
  height: var(--nav-height);
  background: var(--card-bg);
  display: flex;
  justify-content: space-around;
  align-items: center;
  border-top: 1px solid var(--border);
  z-index: 100;
  backdrop-filter: blur(10px);
}

.nav-item {
  background: none;
  border: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  color: var(--text-muted);
  font-size: 0.75rem;
  cursor: pointer;
  width: 100%;
  height: 100%;
  justify-content: center;
  transition: var(--transition);
}

.nav-item.active { color: var(--primary); }
.nav-icon { font-size: 1.4rem; transition: var(--transition); }
.nav-item.active .nav-icon { transform: translateY(-2px); }

/* Modals */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  transition: opacity 0.3s;
}

.modal.show { display: flex; opacity: 1; }

.modal-content {
  background: var(--card-bg);
  padding: 24px;
  border-radius: 20px;
  width: 100%;
  max-width: 400px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  transform: translateY(20px);
  transition: transform 0.3s;
}

.modal.show .modal-content { transform: translateY(0); }

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

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-muted);
}

/* Forms */
.form-group { margin-bottom: 15px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; }

label { display: block; margin-bottom: 6px; font-weight: 500; font-size: 0.9rem; }
input[type="text"], input[type="color"], textarea {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-color);
  color: var(--text-main);
  font-family: inherit;
  font-size: 1rem;
}

input[type="color"] { height: 45px; padding: 2px; }

/* Frequency & Days */
.frequency-options { display: flex; gap: 15px; margin-bottom: 10px; }
.radio-option {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.days-selector {
  display: flex;
  justify-content: space-between;
  gap: 5px;
  margin-top: 10px;
}
.days-selector.hidden { display: none; }

.day-check { margin: 0; cursor: pointer; }
.day-check input { display: none; }
.day-check span {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--bg-color);
  border: 1px solid var(--border);
  display: grid;
  place-items: center;
  font-size: 0.8rem;
  transition: var(--transition);
}
.day-check input:checked + span {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

/* Mood Selector */
.mood-selector { display: flex; justify-content: space-between; font-size: 2rem; }
.mood-option { cursor: pointer; transition: transform 0.2s; opacity: 0.5; }
.mood-option:hover { transform: scale(1.1); }
.mood-option input { display: none; }
.mood-option input:checked + span { opacity: 1; transform: scale(1.2); }

/* Helpers */
.hidden { display: none !important; }
.muted { color: var(--text-muted); font-size: 0.8rem; text-align: center; margin-top: 20px; }

/* Mobile adjustments */
@media (max-width: 480px) {
  .header { height: 50px; }
  h1 { font-size: 1.2rem; }
  .view { padding: 15px; }
}
