/* --- Global Reset & Base Styles --- */
* {
  box-sizing: border-box;
  /* Modern system font stack with Segoe UI fallback */
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

body {
  /* Vibrant purple-to-indigo gradient background */
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  padding: 30px 20px;
  margin: 0;
}

.app {
  width: 100%;
  max-width: 900px;
}

/* --- Main Typography --- */
h1 {
  font-size: 52px;
  text-align: center;
  margin-bottom: 40px;
  color: white;
  font-weight: 700;
  text-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  letter-spacing: -1px;
}

h2 {
  font-size: 28px;
  font-weight: 600;
  margin: 0 0 20px 0;
}

/* --- Reusable Card Container (.habits) --- */
.habits {
  background: white;
  padding: 30px;
  border-radius: 24px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
  width: 100%;
  margin: 0 auto 30px auto;
  font-size: 16px;
  position: relative;
  transition: transform 0.2s ease;
}

/* Hover effect for all card-based sections */
.habits:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 45px rgba(0, 0, 0, 0.18);
}

/* --- Stats Dashboard Section --- */
.stats-dashboard {
  /* Matching the body gradient for a cohesive dashboard look */
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
}

.stats-dashboard h2 {
  text-align: center;
  margin-bottom: 25px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
  padding: 10px 0;
}

.stat-card {
  text-align: center;
  padding: 20px;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 16px;
  backdrop-filter: blur(10px); /* Frosted glass effect */
  transition: all 0.3s ease;
}

.stat-card:hover {
  background: rgba(255, 255, 255, 0.25);
  transform: scale(1.05);
}

.stat-card div {
  font-size: 36px;
  font-weight: 700;
  margin-bottom: 8px;
}

.stat-card strong {
  font-size: 14px;
  font-weight: 500;
  opacity: 0.9;
}

/* Global utility to hide elements */
.hidden {
  display: none !important;
}

/* --- Habit Streak & Progress Visualization --- */
#streak-display {
  font-size: 20px;
  font-weight: 600;
  color: #667eea;
  margin-bottom: 20px;
  padding: 15px;
  background: linear-gradient(135deg, #ffeaa7 0%, #fdcb6e 100%);
  border-radius: 12px;
  text-align: center;
}

#progress-container {
  margin: 25px 0;
}

.progress-text {
  display: block;
  font-weight: 600;
  color: #555;
  margin-bottom: 10px;
  font-size: 15px;
}

.progress-bar {
  width: 100%;
  height: 14px;
  background: #f0f0f0;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
  transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
  border-radius: 10px;
}

/* --- Habit Creation Form --- */
.add-habit-form {
  display: flex;
  gap: 12px;
  margin-top: 20px;
  background: #f8f9fa;
  padding: 20px;
  border-radius: 16px;
  border: 2px dashed #e0e0e0; /* UI hint for a "drop-in" area */
}

.add-habit-form input,
.add-habit-form select {
  padding: 12px 16px;
  border-radius: 10px;
  border: 2px solid #e0e0e0;
  font-size: 15px;
  transition: all 0.2s ease;
}

.add-habit-form input:focus,
.add-habit-form select:focus {
  outline: none;
  border-color: #667eea;
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.add-habit-form input {
  flex: 2; /* Takes more space than the select */
}

.add-habit-form select {
  flex: 1;
}

#save-habit-btn {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: none;
  padding: 0 24px;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 600;
  font-size: 15px;
  transition: all 0.2s ease;
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

#save-habit-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(102, 126, 234, 0.4);
}

#save-habit-btn:active {
  transform: translateY(0);
}

/* The toggle button to show the add form */
.add-btn {
  position: absolute;
  top: 30px;
  right: 30px;
  border-radius: 12px;
  background: linear-gradient(135deg, #00b894 0%, #00cec9 100%);
  padding: 12px 20px;
  border: none;
  color: white;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  box-shadow: 0 4px 12px rgba(0, 184, 148, 0.3);
  transition: all 0.2s ease;
}

.add-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(0, 184, 148, 0.4);
}

/* --- Habit List Items --- */
.habit-item {
  display: flex;
  align-items: center;
  gap: 15px;
  padding: 16px;
  border-bottom: 1px solid #f0f0f0;
  transition: background 0.2s ease;
  border-radius: 8px;
  margin-bottom: 8px;
}

.habit-item:hover {
  background: #f8f9fa;
}

/* Custom Checkbox Styling */
.habit-checkbox {
  appearance: none;
  -webkit-appearance: none;
  width: 28px;
  height: 28px;
  border: 3px solid #667eea;
  border-radius: 8px;
  background-color: white;
  cursor: pointer;
  position: relative;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.habit-checkbox:hover {
  border-color: #764ba2;
}

.habit-checkbox:checked {
  background: linear-gradient(135deg, #00b894 0%, #00cec9 100%);
  border-color: #00b894;
  transform: scale(1.1);
}

/* Checkmark inside the custom checkbox */
.habit-checkbox:checked::after {
  content: "✔";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: white;
  font-size: 16px;
  font-weight: bold;
}

.habit-info {
  flex: 1;
  cursor: pointer;
  font-weight: 500;
  color: #333;
  font-size: 16px;
}

.habit-item.completed .habit-info {
  text-decoration: none;
  opacity: 1;
}

.tick-icon {
  color: #00b894;
  margin-left: 8px;
  font-weight: bold;
}

.tag-badge {
  font-size: 12px;
  padding: 4px 10px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border-radius: 12px;
  margin-left: 8px;
  font-weight: 600;
}

.delete-btn {
  background: linear-gradient(135deg, #ff7675 0%, #d63031 100%);
  border: none;
  color: white;
  padding: 8px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
  transition: all 0.2s ease;
  box-shadow: 0 2px 8px rgba(214, 48, 49, 0.3);
}

.delete-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(214, 48, 49, 0.4);
}

/* --- Calendar Section --- */
.calendar-section {
  background: white;
  padding: 30px;
  border-radius: 24px;
  color: #333;
  width: 100%;
  margin: auto;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
}

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

.calendar-header button {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border: none;
  color: white;
  padding: 10px 18px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 18px;
  font-weight: bold;
  transition: all 0.2s ease;
  box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

.calendar-header h2 {
  margin: 0;
  font-size: 26px;
  flex-grow: 1;
  text-align: center;
  color: #333;
  font-weight: 700;
}

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

.weekday-label {
  font-weight: 700;
  font-size: 13px;
  padding-bottom: 12px;
  color: #667eea;
  background: transparent !important;
  cursor: default !important;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.calendar-grid div {
  height: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  background: #f8f9fa;
  transition: all 0.2s ease;
  font-weight: 600;
  cursor: pointer;
}

.calendar-grid .empty-cell {
  cursor: default;
  background: transparent;
  border: none;
}

.calendar-grid div:not(.empty-cell):not(.weekday-label):hover {
  transform: scale(1.08);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

/* Calendar Day Statuses */
.calendar-grid .done {
  background: linear-gradient(135deg, #00b894 0%, #00cec9 100%) !important;
  color: white !important;
  box-shadow: 0 4px 12px rgba(0, 184, 148, 0.3) !important;
}

.calendar-grid .partial {
  background: linear-gradient(135deg, #fdcb6e 0%, #ffeaa7 100%) !important;
  color: #333 !important;
  box-shadow: 0 4px 12px rgba(253, 203, 110, 0.3) !important;
}

.calendar-grid .missed {
  background: linear-gradient(135deg, #ff7675 0%, #d63031 100%) !important;
  color: white !important;
  box-shadow: 0 4px 12px rgba(214, 48, 49, 0.3) !important;
}

.calendar-grid .today {
  border: 3px solid #667eea;
  font-weight: 800;
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.2);
}

/* --- Modal UI (Popups) --- */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 100;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-content {
  background: white;
  color: #333;
  padding: 30px;
  border-radius: 24px;
  width: 90%;
  max-width: 450px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  animation: slideUp 0.3s ease;
}

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

.modal-content h3 {
  color: #667eea;
  margin-bottom: 20px;
  font-size: 22px;
}

#modal-habit-list {
  margin-bottom: 20px;
}

.history-row {
  display: flex;
  justify-content: space-between;
  padding: 12px;
  background: #f8f9fa;
  border-radius: 8px;
  margin-bottom: 8px;
}

#daily-note {
  width: 100%;
  height: 100px;
  margin-top: 10px;
  border-radius: 12px;
  border: 2px solid #e0e0e0;
  padding: 12px;
  resize: vertical;
  font-family: inherit;
  font-size: 14px;
  transition: border 0.2s ease;
}

#close-modal {
  width: 100%;
  margin-top: 20px;
  padding: 14px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  font-weight: 600;
  font-size: 15px;
  transition: all 0.2s ease;
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

/* --- Focus Timer Section --- */
.focus-timer {
  background: linear-gradient(135deg, #6c5ce7 0%, #a29bfe 100%);
  color: white;
}

#timer-display {
  font-size: 56px;
  text-align: center;
  margin: 20px 0;
  font-family: 'Courier New', monospace;
  font-weight: 700;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.timer-controls {
  display: flex;
  gap: 12px;
  justify-content: center;
}

#start-timer,
#pause-timer,
#reset-timer {
  padding: 12px 24px;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  color: white;
  font-weight: 600;
  font-size: 14px;
  transition: all 0.2s ease;
}

#start-timer {
  background: linear-gradient(135deg, #00b894 0%, #00cec9 100%);
  box-shadow: 0 4px 12px rgba(0, 184, 148, 0.3);
}

#pause-timer {
  background: linear-gradient(135deg, #fdcb6e 0%, #ffeaa7 100%);
  color: #333;
}

#reset-timer {
  background: linear-gradient(135deg, #ff7675 0%, #d63031 100%);
}

/* --- Data & Storage Tools --- */
.data-tools {
  background: linear-gradient(135deg, #2d3436 0%, #636e72 100%);
  color: white;
  margin-top: 30px;
}

.data-tools-buttons {
  display: flex;
  gap: 12px;
}

#export-btn, #reset-history-btn {
  flex: 1;
  padding: 12px;
  color: white;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 600;
  transition: all 0.2s ease;
}

#export-btn {
  background: linear-gradient(135deg, #00b894 0%, #00cec9 100%);
}

#reset-history-btn {
  background: linear-gradient(135deg, #ff7675 0%, #d63031 100%);
}

/* --- Animations & Interaction Effects --- */
.input-error {
  border: 2px solid #d63031 !important;
  background-color: #fff5f5 !important;
  animation: shake 0.4s ease-in-out;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-8px); }
  50% { transform: translateX(8px); }
  75% { transform: translateX(-8px); }
}

/* Confetti particles for success celebration */
.confetti {
  position: fixed;
  width: 12px;
  height: 12px;
  background-color: #f2d74e;
  top: -10px;
  z-index: 1000;
  border-radius: 50%;
  animation: fall 3s linear forwards;
}

@keyframes fall {
  to {
    transform: translateY(100vh) rotate(720deg);
    opacity: 0;
  }
}

#all-done {
  font-weight: 700;
  font-size: 20px;
  color: #00b894;
  text-align: center;
  padding: 20px;
  background: linear-gradient(135deg, #dfe6e9 0%, #b2bec3 100%);
  border-radius: 12px;
  margin-top: 20px;
  animation: popIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes popIn {
  0% { transform: scale(0.5); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

/* --- Inline Editing Mode --- */
.edit-group {
  display: flex;
  flex-direction: column;
  gap: 15px;
  width: 100%;
  padding: 10px;
  background: #f8f9fa;
  border-radius: 12px;
}

.edit-input, .edit-select {
  padding: 12px;
  border: 2px solid #e0e0e0;
  border-radius: 8px;
  font-size: 15px;
}

.edit-controls {
  display: flex;
  gap: 10px;
}

.cancel-edit-btn, .save-edit-btn {
  flex: 1;
  padding: 10px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
}

.cancel-edit-btn { background: #dfe6e9; color: #2d3436; }
.save-edit-btn { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; }

/* --- Responsive Media Queries --- */

/* Tablets and small desktops */
@media (max-width: 768px) {
  .stats-grid {
    grid-template-columns: 1fr;
    gap: 15px;
  }
  
  h1 { font-size: 36px; }
  
  .add-habit-form { flex-direction: column; }
}

/* Mobile phones */
@media (max-width: 480px) {
  body { padding: 20px 12px; }

  h1 {
    font-size: 30px;
    margin-bottom: 25px;
  }

  .habits,
  .calendar-section,
  .modal-content {
    padding: 20px;
    border-radius: 18px;
  }

  .habit-item {
    flex-wrap: wrap;
    gap: 10px;
  }

  .habit-info { font-size: 14px; }

  .delete-btn {
    padding: 6px 12px;
    font-size: 12px;
  }

  .add-btn {
    position: static;
    width: 100%;
    margin-top: 15px;
  }

  .calendar-grid div {
    height: 42px;
    font-size: 13px;
  }

  #timer-display { font-size: 40px; }

  .timer-controls { flex-direction: column; }

  #start-timer, #pause-timer, #reset-timer { width: 100%; }

  .data-tools-buttons { flex-direction: column; }
}