/* NutriRhythm - Application Styles */

/* Prevent double-tap zoom on mobile while preserving pinch-to-zoom */
html {
  touch-action: manipulation;
}

/* Tab Navigation */
.tab-active {
  border-bottom: 3px solid #3b82f6;
  color: #3b82f6;
}

/* Jar Buttons (Meal Tracking) */
.jar-btn {
  transition: all 0.2s;
}
.jar-btn.active {
  transform: scale(1.05);
}
.jar-btn.disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* Range & Breakdown Buttons (Analytics) */
.range-btn.active {
  background-color: #3b82f6;
  color: white;
}
.breakdown-btn.active {
  background-color: #10b981;
  color: white;
}

/* Loading Spinner */
.loader {
  border: 3px solid #f3f3f3;
  border-top: 3px solid #3b82f6;
  border-radius: 50%;
  width: 24px;
  height: 24px;
  animation: spin 1s linear infinite;
}
@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* Flatpickr Override */
.flatpickr-input {
  background: white !important;
}

/* Collapsible Sections */
.collapsible-header {
  cursor: pointer;
  user-select: none;
}
.collapsible-header:hover {
  background-color: #f9fafb;
}
.collapsible-content {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease-out;
}
.collapsible-content.open {
  max-height: 500px;
}
.chevron {
  transition: transform 0.3s ease;
}
.chevron.open {
  transform: rotate(180deg);
}

/* Phase Badges */
.phase-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 9999px;
  font-weight: 600;
  font-size: 0.875rem;
}
.phase-indulge { background: #fef3c7; color: #92400e; }
.phase-release { background: #fee2e2; color: #991b1b; }
.phase-normalize { background: #d1fae5; color: #065f46; }
.phase-live { background: #dbeafe; color: #1e40af; }
.phase-maintenance { background: #f3e8ff; color: #6b21a8; }
.phase-none { background: #f3f4f6; color: #6b7280; }

/* Phase Timeline */
.phase-timeline {
  display: flex;
  width: 100%;
  height: 8px;
  border-radius: 4px;
  overflow: hidden;
}
.phase-timeline-indulge { background: #fbbf24; flex: 2; }
.phase-timeline-release { background: #ef4444; flex: 21; }
.phase-timeline-normalize { background: #10b981; flex: 7; }
.phase-timeline-live { background: #3b82f6; flex: 12; }

/* Toggle Switch */
.toggle-switch {
  position: relative;
  width: 44px;
  height: 24px;
  background: #d1d5db;
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.2s;
}
.toggle-switch.active {
  background: #10b981;
}
.toggle-switch::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  background: white;
  border-radius: 50%;
  transition: transform 0.2s;
}
.toggle-switch.active::after {
  transform: translateX(20px);
}

/* Water Adjust Buttons */
.water-adjust-btn {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-size: 1.25rem;
  font-weight: bold;
  transition: all 0.15s;
}
.water-adjust-btn:hover {
  transform: scale(1.1);
}

/* Daily Notes */
.note-item {
  background: #f9fafb;
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 8px;
}
.note-item:last-child {
  margin-bottom: 0;
}
.note-item.editing {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
}
.note-text {
  white-space: pre-wrap;
  word-break: break-word;
}
.note-textarea,
.note-edit-textarea {
  min-height: 80px;
  resize: vertical;
}
.note-edit-textarea {
  font-size: 14px;
  line-height: 1.5;
}

/* Swipe Navigation Hints */
.swipe-hint {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  width: 40px;
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(59, 130, 246, 0.1);
  color: #3b82f6;
  font-size: 1.5rem;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
  z-index: 50;
}
.swipe-hint.left {
  left: 0;
  border-radius: 0 8px 8px 0;
}
.swipe-hint.right {
  right: 0;
  border-radius: 8px 0 0 8px;
}
.swipe-hint.visible {
  opacity: 1;
}

/* Weight Progress Tracker */
.weight-progress-visual {
  position: relative;
  height: 12px;
  background: #e5e7eb;
  border-radius: 6px;
  overflow: visible;
  margin: 16px 0;
}
.weight-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #10b981, #3b82f6);
  border-radius: 6px;
  transition: width 0.5s ease;
}
.weight-progress-marker {
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 20px;
  height: 20px;
  background: white;
  border: 3px solid #3b82f6;
  border-radius: 50%;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.weight-label {
  position: absolute;
  top: 20px;
  font-size: 0.75rem;
  white-space: nowrap;
}
.weight-label.left {
  left: 0;
  transform: none;
}
.weight-label.right {
  right: 0;
  left: auto;
  transform: none;
}

/* ============================================
   COACH TAB - Chat UI
   ============================================ */

.chat-container {
  height: 400px;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  background: #f9fafb;
  overflow: hidden;
}

.chat-welcome {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
}

.chat-message {
  display: flex;
  margin-bottom: 12px;
  animation: fadeIn 0.3s ease;
}

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

.chat-message.user {
  justify-content: flex-end;
}

.chat-message.assistant {
  justify-content: flex-start;
}

.chat-bubble {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 14px;
  line-height: 1.4;
  word-wrap: break-word;
}

.chat-message.user .chat-bubble {
  background: #3b82f6;
  color: white;
  border-bottom-right-radius: 4px;
}

.chat-message.assistant .chat-bubble {
  background: white;
  color: #1f2937;
  border: 1px solid #e5e7eb;
  border-bottom-left-radius: 4px;
}

.chat-bubble p {
  margin: 0 0 8px 0;
}

.chat-bubble p:last-child {
  margin-bottom: 0;
}

.chat-bubble ul, .chat-bubble ol {
  margin: 8px 0;
  padding-left: 20px;
}

.chat-bubble li {
  margin-bottom: 4px;
}

.chat-bubble strong {
  font-weight: 600;
}

.chat-input-container {
  display: flex;
  gap: 8px;
}

.chat-input {
  flex: 1;
  padding: 12px 16px;
  border: 1px solid #e5e7eb;
  border-radius: 24px;
  font-size: 16px; /* Prevents iOS auto-zoom on focus */
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.chat-input:focus {
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.chat-send-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: #3b82f6;
  color: white;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s;
}

.chat-send-btn:hover {
  background: #2563eb;
}

.chat-send-btn:disabled {
  background: #9ca3af;
  cursor: not-allowed;
}

.quick-prompt-btn {
  padding: 6px 12px;
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 16px;
  font-size: 12px;
  color: #4b5563;
  cursor: pointer;
  transition: all 0.2s;
}

.quick-prompt-btn:hover {
  background: #f3f4f6;
  border-color: #d1d5db;
}

.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 12px 16px;
}

.typing-indicator span {
  width: 8px;
  height: 8px;
  background: #9ca3af;
  border-radius: 50%;
  animation: typing 1.4s infinite;
}

.typing-indicator span:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typing {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-4px); }
}

/* Chat Container - Flexbox Layout */
.chat-container {
  display: flex;
  flex-direction: column;
  position: relative;
}

/* Chat History Bar (Sticky Top) */
.chat-history-bar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid #e5e7eb;
  flex-wrap: nowrap;
}

.chat-history-bar .history-label {
  position: relative;
  font-size: 14px;
  color: #6b7280;
  font-weight: 500;
  white-space: nowrap;
  flex-shrink: 0;
  cursor: help;
  user-select: none;
}

.chat-history-bar .history-dropdown {
  flex: 1;
  min-width: 120px;
  padding: 5px 10px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 14px;
  color: #374151;
  background: white;
  cursor: pointer;
  outline: none;
  transition: border-color 0.2s;
}

.chat-history-bar .history-dropdown:hover {
  border-color: #9ca3af;
}

.chat-history-bar .history-dropdown:focus {
  border-color: #3b82f6;
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.1);
}

/* Hover Tooltip */
.history-tooltip {
  visibility: hidden;
  opacity: 0;
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  width: 260px;
  padding: 10px 12px;
  background: #1f2937;
  color: white;
  font-size: 11px;
  line-height: 1.5;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  transition: opacity 0.2s, visibility 0.2s;
  pointer-events: none;
  z-index: 9999;
  white-space: normal;
  overflow-wrap: break-word;
}

.history-tooltip::after {
  content: '';
  position: absolute;
  bottom: 100%;
  left: 20px;
  border: 6px solid transparent;
  border-bottom-color: #1f2937;
}

/* Desktop: hover to show */
.history-label:hover .history-tooltip {
  visibility: visible;
  opacity: 1;
}

/* Mobile: click to show */
.history-tooltip.visible {
  visibility: visible !important;
  opacity: 1 !important;
}

/* Chat Messages Content (Scrollable) */
.chat-messages-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  min-height: 0;
}

/* Mobile Responsive */
@media (max-width: 640px) {
  .chat-history-bar {
    padding: 8px 12px;
    gap: 6px;
  }

  .chat-history-bar .history-label {
    font-size: 14px;
  }

  .chat-history-bar .history-dropdown {
    font-size: 14px;
    padding: 5px 10px;
    min-width: 80px;
  }

  .history-tooltip {
    width: 220px;
    font-size: 10px;
    padding: 8px 10px;
  }

  .chat-messages-content {
    padding: 12px;
  }
}

/* ============================================
   STREAK TOOLTIPS (Progress Tab)
   ============================================ */

.streak-label {
  position: relative;
  cursor: help;
  user-select: none;
}

.streak-tooltip {
  visibility: hidden;
  opacity: 0;
  position: absolute;
  bottom: calc(100% + 8px);
  left: 0;
  width: 220px;
  padding: 10px 12px;
  background: #1f2937;
  color: white;
  font-size: 11px;
  font-weight: 400;
  line-height: 1.5;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  transition: opacity 0.2s, visibility 0.2s;
  pointer-events: none;
  z-index: 9999;
  white-space: normal;
  overflow-wrap: break-word;
}

.streak-tooltip::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 20px;
  border: 6px solid transparent;
  border-top-color: #1f2937;
}

/* Desktop: hover to show */
.streak-label:hover .streak-tooltip {
  visibility: visible;
  opacity: 1;
}

/* Mobile: click to show */
.streak-tooltip.visible {
  visibility: visible !important;
  opacity: 1 !important;
}

@media (max-width: 640px) {
  .streak-tooltip {
    width: 180px;
    font-size: 10px;
    padding: 8px 10px;
  }
}

/* ============================================
   CONSISTENCY GOAL TOOLTIP
   ============================================ */

.consistency-info-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  font-size: 14px;
  color: #9ca3af;
  cursor: help;
  user-select: none;
}

.consistency-tooltip {
  visibility: hidden;
  opacity: 0;
  position: absolute;
  bottom: calc(100% + 8px);
  left: 0;
  width: 240px;
  padding: 10px 12px;
  background: #1f2937;
  color: white;
  font-size: 11px;
  font-weight: 400;
  line-height: 1.5;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  transition: opacity 0.2s, visibility 0.2s;
  pointer-events: none;
  z-index: 9999;
  white-space: normal;
  overflow-wrap: break-word;
}

.consistency-tooltip::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 20px;
  border: 6px solid transparent;
  border-top-color: #1f2937;
}

/* Click to show (via JS) */
.consistency-tooltip.visible {
  visibility: visible !important;
  opacity: 1 !important;
}

@media (max-width: 640px) {
  .consistency-tooltip {
    width: 200px;
    font-size: 10px;
    padding: 8px 10px;
  }
}

/* ============================================
   NAVIGATION MENU (Hamburger Dropdown)
   ============================================ */

.nav-menu-btn {
  transition: all 0.2s;
}

.nav-menu {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 8px;
  min-width: 200px;
  background: white;
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
  border: 1px solid #e5e7eb;
  overflow: hidden;
  z-index: 100;
  animation: menuFadeIn 0.15s ease-out;
}

.nav-menu.hidden {
  display: none;
}

@keyframes menuFadeIn {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.nav-menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 16px;
  font-size: 14px;
  font-weight: 500;
  color: #374151;
  background: none;
  border: none;
  cursor: pointer;
  transition: background 0.15s;
  text-align: left;
}

.nav-menu-item:hover {
  background: #f3f4f6;
}

.nav-menu-item svg {
  flex-shrink: 0;
  color: #6b7280;
}

.nav-menu-item:hover svg {
  color: #374151;
}

.nav-menu-divider {
  height: 1px;
  background: #e5e7eb;
  margin: 4px 0;
}

/* ============================================
   SETTINGS MODAL
   ============================================ */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
}

.modal-overlay.hidden {
  display: none;
}

.modal-container {
  background: white;
  border-radius: 16px;
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid #e5e7eb;
  flex-shrink: 0;
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
}

/* ============================================
   CELEBRATION ANIMATION
   ============================================ */

@keyframes bounceIn {
  0% {
    opacity: 0;
    transform: scale(0.3);
  }
  50% {
    opacity: 1;
    transform: scale(1.05);
  }
  70% {
    transform: scale(0.9);
  }
  100% {
    transform: scale(1);
  }
}

.animate-bounce-in {
  animation: bounceIn 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

/* ============================================
   COACH TAB - Full Height Layout
   ============================================ */

#page-coach {
  display: flex;
  flex-direction: column;
  /* Height: viewport minus header (~70px), tabs (~50px), and padding (~40px) */
  height: calc(100vh - 160px);
  min-height: 400px;
}

#page-coach .chat-container {
  flex: 1;
  height: auto;
  min-height: 200px;
}

#page-coach.hidden {
  display: none;
}

/* ============================================
   SNT TOGGLE TOOLTIP
   ============================================ */

.snt-toggle-wrapper {
  position: relative;
  display: inline-block;
}

.snt-tooltip {
  visibility: hidden;
  opacity: 0;
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 260px;
  padding: 10px 12px;
  background: #1f2937;
  color: white;
  font-size: 11px;
  line-height: 1.5;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  transition: opacity 0.2s, visibility 0.2s;
  pointer-events: none;
  z-index: 9999;
  white-space: normal;
  overflow-wrap: break-word;
}

.snt-tooltip::after {
  content: '';
  position: absolute;
  bottom: 100%;
  right: 20px;
  border: 6px solid transparent;
  border-bottom-color: #1f2937;
}

/* Show tooltip on hover/click when disabled */
.snt-toggle-wrapper.snt-disabled:hover .snt-tooltip,
.snt-tooltip.visible {
  visibility: visible;
  opacity: 1;
}

/* Disabled toggle visual styling */
.toggle-switch.disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

/* ============================================
   RESPONSIVE ADJUSTMENTS
   ============================================ */

@media (max-width: 640px) {
  #page-coach {
    /* Adjust for smaller mobile header/padding */
    height: calc(100vh - 150px);
  }

  .chat-container {
    height: 350px;
  }

  /* 15% larger chat text on mobile (14px * 1.15 = ~16px) */
  .chat-bubble {
    max-width: 85%;
    font-size: 16px;
  }

  .quick-prompt-btn {
    font-size: 11px;
    padding: 5px 10px;
  }
}
