/**
 * DevPilot-AI - Consistency & Habit Tracker Stylesheet
 * 
 * Clean, modern aesthetics following the DevPilot AI design system:
 * - Slate/Indigo/Amber brand palette
 * - Touch-friendly interactive checkboxes
 * - Dynamic streak badges & at-risk indicators
 * - 6-month heatmap grid with month headers & weekday labels
 * - Interactive heatmap day detail tooltip
 * - Actionable habit insights cards
 * - Accessible modal dialogs
 */

/* ==========================================================================
   1. Habit Checklist & Items
   ========================================================================== */

.habit-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.875rem 1rem;
  background-color: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 0.75rem;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  gap: 0.75rem;
}

.habit-item:hover {
  border-color: #cbd5e1;
  box-shadow: 0 2px 6px -1px rgba(0, 0, 0, 0.05);
}

.habit-item.is-completed {
  background-color: #f8fafc;
  border-color: #e2e8f0;
}

.habit-item.is-completed .habit-title {
  text-decoration: line-through;
  color: #94a3b8;
}

/* Habit Toggle Button (matches Daily Goals check button style) */
.habit-toggle-btn {
  width: 1.25rem;
  height: 1.25rem;
  border-radius: 0.375rem;
  border: 1.5px solid #cbd5e1;
  background-color: #ffffff;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.15s ease-in-out;
  color: transparent;
  padding: 0;
}

.habit-toggle-btn:hover {
  border-color: #6366f1;
  color: #6366f1;
}

.habit-toggle-btn.is-checked {
  background-color: #4f46e5;
  border-color: #4f46e5;
  color: #ffffff;
}

.habit-toggle-btn:focus-visible {
  outline: 2px solid #6366f1;
  outline-offset: 2px;
}

/* Badges */
.category-pill {
  display: inline-flex;
  align-items: center;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.125rem 0.5rem;
  border-radius: 9999px;
  background-color: #f1f5f9;
  color: #475569;
}

.at-risk-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.125rem 0.5rem;
  border-radius: 9999px;
  background-color: #fef3c7;
  color: #b45309;
  border: 1px solid #fde68a;
}

/* ==========================================================================
   2. Consistency Heatmap Matrix
   ========================================================================== */

.dev-card.heatmap-card {
  overflow: visible;
}

.heatmap-wrapper {
  position: relative;
  width: 100%;
  overflow-x: auto;
  overflow-y: visible;
  padding-bottom: 0.5rem;
  -webkit-overflow-scrolling: touch;
}

.heatmap-wrapper::-webkit-scrollbar {
  height: 4px;
}

.heatmap-wrapper::-webkit-scrollbar-track {
  background: #f1f5f9;
  border-radius: 9999px;
}

.heatmap-wrapper::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 9999px;
}

.heatmap-wrapper::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

.heatmap-table {
  display: flex;
  flex-direction: column;
  width: 100%;
  min-width: 390px;
}

.heatmap-months-row {
  display: grid;
  grid-template-columns: repeat(26, minmax(0, 1fr));
  gap: 3px;
  font-size: 0.7rem;
  font-weight: 600;
  color: #94a3b8;
  margin-bottom: 0.4rem;
  padding-left: 2rem;
}

.heatmap-month-label {
  text-align: left;
  white-space: nowrap;
  overflow: visible;
  user-select: none;
}

.heatmap-body {
  display: flex;
  gap: 0.5rem;
  align-items: flex-start;
}

.heatmap-days-col {
  display: grid;
  grid-template-rows: repeat(7, 13px);
  gap: 3px;
  width: 1.5rem;
  font-size: 0.65rem;
  font-weight: 600;
  color: #94a3b8;
  line-height: 13px;
  user-select: none;
}

.heatmap-grid-container {
  display: grid;
  grid-template-columns: repeat(26, minmax(0, 1fr));
  gap: 3px;
  flex: 1;
}

.heatmap-col {
  display: grid;
  grid-template-rows: repeat(7, 13px);
  gap: 3px;
}

.heatmap-cell {
  width: 100%;
  height: 13px;
  aspect-ratio: 1 / 1;
  max-width: 14px;
  max-height: 14px;
  border-radius: 2.5px;
  cursor: pointer;
  transition: transform 0.15s ease, outline 0.15s ease, box-shadow 0.15s ease;
  position: relative;
}

.heatmap-cell:hover {
  transform: scale(1.35);
  z-index: 20;
  outline: 1.5px solid var(--heatmap-accent, #4f46e5);
}

.heatmap-cell.is-today {
  outline: 1.5px solid var(--heatmap-accent, #6366f1);
}

.heatmap-cell.is-selected {
  outline: 2px solid var(--heatmap-accent, #4f46e5) !important;
  outline-offset: 1.5px;
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.35);
  transform: scale(1.25);
  z-index: 25;
}

.heatmap-cell.is-future {
  opacity: 0.25;
  cursor: default;
}

.heatmap-cell.is-future:hover {
  transform: none;
  outline: none;
}

/* Heatmap intensity color tokens */
.heatmap-l0 { background-color: var(--heatmap-l0, #f1f5f9); }
.heatmap-l1 { background-color: var(--heatmap-l1, #c7d2fe); }
.heatmap-l2 { background-color: var(--heatmap-l2, #818cf8); }
.heatmap-l3 { background-color: var(--heatmap-l3, #4f46e5); }
.heatmap-l4 { background-color: var(--heatmap-l4, #312e81); }

/* Interactive Popover Tooltip */
.heatmap-tooltip {
  position: absolute;
  background-color: #0f172a;
  color: #ffffff;
  padding: 0.5rem 0.75rem;
  border-radius: 0.5rem;
  font-size: 0.75rem;
  pointer-events: none;
  z-index: 100;
  white-space: nowrap;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.3);
  opacity: 0;
  transition: opacity 0.15s ease;
}

.heatmap-tooltip.visible {
  opacity: 1;
}

.heatmap-tooltip::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border-width: 4px;
  border-style: solid;
  border-color: #0f172a transparent transparent transparent;
}

.heatmap-tooltip.flip-below::after {
  top: auto;
  bottom: 100%;
  border-color: transparent transparent #0f172a transparent;
}

/* Day History Breakdown */
.heatmap-day-history {
  transition: all 0.2s ease;
}

.heatmap-history-item {
  transition: all 0.15s ease;
}

.heatmap-history-item:hover {
  transform: translateX(2px);
}

/* Daily Goals */
.daily-goal-item {
  padding: 0.875rem 1rem;
  background-color: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 0.75rem;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.daily-goal-item:hover {
  border-color: #cbd5e1;
  box-shadow: 0 2px 6px -1px rgba(0, 0, 0, 0.05);
}

.daily-goal-item.is-completed {
  background: linear-gradient(135deg, #f0fdf4 0%, #ffffff 100%);
  border-color: #86efac;
}

.daily-goal-item.is-completed .daily-goal-title {
  text-decoration: line-through;
  color: #94a3b8;
}

/* ==========================================================================
   4. Habit Insights
   ========================================================================== */

.insight-metric-card {
  background-color: #f8fafc;
  border: 1px solid #f1f5f9;
  border-radius: 0.75rem;
  padding: 0.875rem;
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.insight-metric-card:hover {
  border-color: #e2e8f0;
  transform: translateY(-1px);
}

/* ==========================================================================
   5. Modals & Dialogs
   ========================================================================== */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background-color: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(4px);
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.modal-backdrop.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-container {
  background-color: #ffffff;
  border-radius: 1rem;
  width: 100%;
  max-width: 520px;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
  overflow: hidden;
  transform: scale(0.95);
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-backdrop.active .modal-container {
  transform: scale(1);
}

/* Frequency chip toggle */
.freq-chip {
  padding: 0.35rem 0.85rem;
  font-size: 0.8rem;
  font-weight: 600;
  border-radius: 9999px;
  border: 1px solid #e2e8f0;
  background-color: #ffffff;
  color: #64748b;
  cursor: pointer;
  transition: all 0.15s ease;
}

.freq-chip:hover {
  border-color: #cbd5e1;
  color: #334155;
}

.freq-chip.active {
  background-color: #e0e7ff;
  border-color: #6366f1;
  color: #4338ca;
}

/* Custom day circular buttons */
.day-selector-btn {
  width: 2rem;
  height: 2rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 700;
  border: 1px solid #e2e8f0;
  background-color: #ffffff;
  color: #64748b;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.day-selector-btn.active {
  background-color: #4f46e5;
  border-color: #4f46e5;
  color: #ffffff;
}

/* ==========================================================================
   6. Responsive Layout Tweaks
   ========================================================================== */

@media (max-width: 768px) {
  .heatmap-wrapper {
    -webkit-overflow-scrolling: touch;
  }
  
  .habit-item {
    padding: 0.75rem 0.875rem;
  }
}
