/* General Reset and Base Styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background-color: #f9fafb;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* App Container */
#app {
  padding: 1rem;
  padding-bottom: 5rem; /* Space for floating button */
  min-height: 100vh;
  background: linear-gradient(180deg, #f9fafb 0%, #e5e7eb 100%);
  
}

/* Habit Card */
.habit-card {
  background: #ffffff;
  border-radius: 12px;
  padding: 1rem;
  margin-bottom: 1rem;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.habit-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.1);
}

/* Grid for Weekday and Day Numbers */
.grid div {
  border: none;
  border-radius: 8px;
  transition: background 0.2s ease, color 0.2s ease;
  user-select: none;
  touch-action: manipulation; /* Improve touch responsiveness */
}

.grid div:active {
  transform: scale(0.95); /* Subtle tap feedback */
}

.bg-green-500 {
  background-color: #22c55e;
  color: #ffffff;
  font-weight: 600;
}

.bg-gray-200 {
  background-color: #e5e7eb;
  color: #6b7280;
}

/* Habit Modal */
.habit-modal {
  background: #ffffff;
  border-radius: 16px;
  padding: 1.5rem;
  margin: 1rem;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
  position: relative;
}

/* Modal Header */
.habit-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid #e5e7eb;
}

.habit-modal-header input {
  font-size: 1.25rem;
  font-weight: 600;
  color: #111827;
  border: 1px solid transparent;
  background: transparent;
  padding: 0.5rem;
  border-radius: 6px;
  transition: background 0.2s ease, border 0.2s ease;
  width: 100%;
}

.habit-modal-header input:focus {
  background: #f3f4f6;
  border-color: #3b82f6;
  outline: none;
}

/* Modal Buttons */
.habit-modal-header-buttons {
  display: flex;
  gap: 0.5rem;
}

.habit-modal-close,
.habit-modal-delete {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.2s ease;
}

.habit-modal-close {
  background: #e5e7eb;
  color: #374151;
}

.habit-modal-close:hover {
  background: #d1d5db;
  transform: scale(1.05);
}

.habit-modal-delete {
  background: #fee2e2;
  color: #ef4444;
}

.habit-modal-delete:hover {
  background: #fecaca;
  transform: scale(1.05);
}

/* Calendar */
.habit-calendar-day {
  width: 2.5rem;
  height: 2.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  font-size: 0.875rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.habit-calendar-day.selected {
  border: 2px solid #3b82f6;
  background: #dbeafe;
  color: #1e40af;
}

.habit-calendar-day.bg-green-500 {
  background: #22c55e;
  color: #ffffff;
}

.habit-calendar-day.bg-gray-200 {
  background: #e5e7eb;
  color: #6b7280;
}

/* Messages Section */
.habit-messages {
  max-height: 12rem;
  overflow-y: auto;
  background: #f9fafb;
  border-radius: 8px;
  padding: 0.5rem;
  margin-bottom: 1rem;
  border: 1px solid #e5e7eb;
}

.habit-messages::-webkit-scrollbar {
  width: 6px;
}

.habit-messages::-webkit-scrollbar-track {
  background: #e5e7eb;
  border-radius: 3px;
}

.habit-messages::-webkit-scrollbar-thumb {
  background: #9ca3af;
  border-radius: 3px;
}

.habit-messages::-webkit-scrollbar-thumb:hover {
  background: #6b7280;
}

/* Message Input */
.habit-message-input {
  position: relative;
}

.habit-message-input input {
  padding-right: 3rem;
  border-radius: 8px;
  border: 1px solid #d1d5db;
  background: #ffffff;
  transition: border-color 0.2s ease;
}

.habit-message-input input:focus {
  border-color: #3b82f6;
  outline: none;
}

.habit-message-input button,
.relative.mb-2 > button {
  position: absolute;
  right: 0.5rem;
  top: 50%;
  transform: translateY(-50%);
  background: #eff6ff; /* blue-50 */
  border: none;
  color: #3b82f6;
  cursor: pointer;
  border-radius: 9999px;
  padding: 0.25rem;
  width: 2rem;
  height: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, color 0.2s;
}

.habit-message-input button:hover,
.relative.mb-2 > button:hover {
  background: #dbeafe; /* blue-100 */
  color: #1e40af;
}

/* Add Habit Modal */
.add-habit-modal {
  background: #ffffff;
  border-radius: 16px;
  padding: 1.5rem;
  margin: 1rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}

.add-habit-modal input {
  border: 1px solid #d1d5db;
  border-radius: 8px;
  padding: 0.75rem;
  margin-bottom: 1rem;
  width: 100%;
  font-size: 1rem;
  transition: border-color 0.2s ease;
}

.add-habit-modal input:focus {
  border-color: #3b82f6;
  outline: none;
}

.add-habit-modal button {
  border-radius: 8px;
  padding: 0.75rem;
  font-size: 1rem;
  font-weight: 500;
  transition: background 0.2s ease, transform 0.2s ease;
}

.add-habit-modal button.bg-green-500 {
  background: #22c55e;
  color: #ffffff;
}

.add-habit-modal button.bg-green-500:hover {
  background: #16a34a;
  transform: scale(1.02);
}

.add-habit-modal button.text-gray-500 {
  background: none;
  color: #6b7280;
}

.add-habit-modal button.text-gray-500:hover {
  color: #374151;
}

/* Floating Add Button */
.floating-add-button {
  width: 3.5rem;
  height: 3.5rem;
  border-radius: 50%;
  background: #22c55e;
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.75rem;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  transition: transform 0.2s ease, background 0.2s ease;
}

.floating-add-button:hover {
  background: #16a34a;
  transform: scale(1.1);
}

/* Loading Overlay & Spinner */
#loading-overlay {
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(243, 244, 246, 0.95); /* Tailwind gray-100 */
  z-index: 9999;
  transition: opacity 0.5s;
}

.loader-spinner {
  width: 3rem;
  height: 3rem;
  border: 6px solid #e5e7eb; /* Tailwind gray-200 */
  border-top: 6px solid #22c55e; /* Tailwind green-500 */
  border-radius: 50%;
  animation: spin 1s linear infinite;
  background: transparent;
  margin-bottom: 1rem;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Toast Notification */
#toast-notification {
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  font-size: 0.875rem;
  pointer-events: none;
}

/* Dropdown Menu Positioning Fix */
nav.absolute {
  position: absolute !important; /* Override any other positioning */
  right: 0 !important; 
  transform-origin: top right;
  will-change: transform, opacity; /* Performance optimization */
  transform: translateZ(0); /* Force GPU acceleration */
  top: 100%; /* Ensure it's positioned right below the button */
  margin-top: 0.5rem;
}

/* Animation adjustments */
@keyframes fade-in {
  from { opacity: 0; transform: translate(-50%, 1rem); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

@keyframes menu-fade-in {
  from { opacity: 0; transform: translateY(-5px); }
  to { opacity: 1; transform: translateY(0); }
}

.animate-fade-in {
  animation: fade-in 0.2s ease-out;
}

nav.animate-fade-in {
  animation: menu-fade-in 0.15s ease-out forwards !important;
  opacity: 0; /* Start fully transparent */
}

/* Responsive Adjustments */
@media (min-width: 640px) {
  #app {
    padding: 2rem;
  }

  .habit-card {
    padding: 1.25rem;
  }

  .habit-modal,
  .add-habit-modal {
    max-width: 28rem;
    margin: 0 auto;
  }
}

/* Accessibility Enhancements */
:focus-visible {
  outline: 2px solid #3b82f6;
  outline-offset: 2px;
}

button,
input,
[tabindex] {
  -webkit-tap-highlight-color: transparent;
}

/* Scroll Behavior */
* {
  scrollbar-width: thin;
  scrollbar-color: #9ca3af #e5e7eb;
}

/* Enhanced scrollbar styling for better visibility */
.scrollbar-thin {
  scrollbar-width: thin;
  scrollbar-color: rgba(156, 163, 175, 0.7) rgba(229, 231, 235, 0.5);
}

.scrollbar-thin::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.scrollbar-thin::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 4px;
}

.scrollbar-thin::-webkit-scrollbar-thumb {
  background-color: #9ca3af;
  border-radius: 4px;
  border: 2px solid #f1f1f1;
}

.scrollbar-thin::-webkit-scrollbar-thumb:hover {
  background-color: #6b7280;
}

/* Force scrollbar to be visible */
.scrollbar-thin::-webkit-scrollbar {
  display: block;
}
