/* ========================================
   HEALTH CSS - Healthy OS Page
   Metrics, recovery, schedule, nutrition, goals, AI chat
   ======================================== */

/* ========== Health-specific Colors ========== */
:root {
  --workout: #e53935;
  --meal: #43a047;
  --sleep: #1e88e5;
  --work: #fdd835;
  --focus: #ff9800;
  --rest: #81c784;
  --study: #26c6da;
}

/* ========== Metrics ========== */
.metric {
  text-align: center;
  padding: 16px;
}

.metric-value {
  font-size: 36px;
  font-weight: 700;
  color: var(--accent);
}

.metric-label {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 6px;
  font-weight: 500;
}

.metric-trend {
  font-size: 12px;
  margin-top: 6px;
  font-weight: 500;
}

.metric-trend.up { color: var(--success); }
.metric-trend.down { color: var(--danger); }

/* ========== Recovery Score ========== */
.recovery-score {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100px;
  height: 100px;
  border-radius: 50%;
  font-size: 28px;
  font-weight: 700;
  margin: 0 auto;
  box-shadow: var(--shadow-md);
}

.recovery-high {
  background: linear-gradient(135deg, #4caf50, #81c784);
  color: #fff;
}

.recovery-medium {
  background: linear-gradient(135deg, #ff9800, #ffb74d);
  color: #fff;
}

.recovery-low {
  background: linear-gradient(135deg, #f44336, #e57373);
  color: #fff;
}

/* ========== Schedule ========== */
.schedule-day {
  margin-bottom: 20px;
}

.schedule-day h4 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 10px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-light);
  padding-bottom: 6px;
}

.schedule-event {
  display: flex;
  gap: 14px;
  padding: 12px;
  border-radius: 12px;
  margin-bottom: 8px;
  background: var(--bg-tertiary);
  align-items: center;
  transition: background 0.2s;
}

.schedule-event:hover {
  background: var(--accent-bg);
}

.schedule-event .time {
  font-size: 13px;
  font-weight: 600;
  min-width: 55px;
  color: var(--text-muted);
}

.schedule-event .title {
  font-size: 14px;
  flex: 1;
  line-height: 1.4;
}

.schedule-event .type-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.type-workout { background: var(--workout); }
.type-meal { background: var(--meal); }
.type-sleep { background: var(--sleep); }
.type-work { background: var(--work); }
.type-focus { background: var(--focus); }
.type-rest { background: var(--rest); }
.type-study { background: var(--study); }

/* ========== Quick Actions ========== */
.quick-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.quick-btn {
  padding: 12px 18px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--btn-bg);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: all 0.2s ease;
  min-height: 48px;
  touch-action: manipulation;
  -webkit-tap-highlight-color: rgba(74,124,74,0.2);
  color: var(--text);
}

.quick-btn:hover {
  background: var(--accent-bg);
  border-color: var(--accent);
  transform: translateY(-1px);
}

.quick-btn:active {
  transform: scale(0.98);
}

/* ========== Goals (WOOP) ========== */
.goal-item {
  padding: 16px;
  border: 1px solid var(--border-light);
  border-radius: 14px;
  margin-bottom: 12px;
  background: var(--bg-tertiary);
  transition: all 0.2s;
}

.goal-item:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-sm);
}

.goal-wish {
  font-weight: 600;
  margin-bottom: 6px;
  font-size: 15px;
  line-height: 1.4;
}

.goal-plan {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
}

.goal-progress {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  margin-top: 10px;
  overflow: hidden;
}

.goal-progress-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  transition: width 0.3s;
}

/* ========== Nutrition & Meal Plan ========== */
.nutrition-progress {
  padding: 16px 0;
}

.macro-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 10px 0;
}

.macro-row span:first-child {
  width: 75px;
  font-size: 14px;
  font-weight: 500;
}

.macro-row span:last-child {
  width: 100px;
  font-size: 13px;
  text-align: right;
  color: var(--text-muted);
}

.macro-bar {
  flex: 1;
  height: 10px;
  background: var(--border);
  border-radius: 5px;
  overflow: hidden;
}

.macro-bar > div {
  height: 100%;
  background: var(--accent);
  transition: width 0.3s;
  border-radius: 5px;
}

.macro-bar.warning > div { background: #ff9800; }
.macro-bar.danger > div { background: var(--danger); }

.meals-list {
  border-top: 1px solid var(--border);
  padding-top: 16px;
  margin-top: 16px;
}

.meals-list:empty {
  display: none;
}

.meal-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--border-light);
  font-size: 14px;
}

.meal-item:last-child {
  border-bottom: none;
}

.meal-item .meal-name {
  flex: 1;
}

.meal-item .meal-macros {
  color: var(--text-muted);
  font-size: 13px;
}

/* Meal Plan Grid */
.meal-plan-controls {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.meal-plan-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
}

.day-card {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  background: var(--bg-tertiary);
}

.day-header {
  font-weight: 600;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
  font-size: 15px;
}

.planned-meal {
  padding: 8px 0;
  font-size: 14px;
}

.meal-time {
  font-weight: 500;
  display: block;
  margin-bottom: 4px;
}

.meal-name-plan {
  color: var(--text);
}

.meal-macros-plan {
  color: var(--text-muted);
  font-size: 12px;
}

.day-totals {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 500;
}

/* ========== Profile Form ========== */
.profile-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}

@media (max-width: 600px) {
  .profile-grid {
    grid-template-columns: 1fr;
  }
}

/* ========== Modal (Sheet Style on Mobile) ========== */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.5);
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  padding: 20px;
  backdrop-filter: blur(4px);
}

.modal-overlay.active {
  display: flex;
}

.modal {
  background: var(--card-bg);
  border-radius: 20px;
  max-width: 600px;
  width: 100%;
  max-height: 85vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--card-bg);
  z-index: 1;
}

.modal-header h3 {
  font-size: 18px;
  font-weight: 600;
  margin: 0;
}

.modal-close {
  background: none;
  border: none;
  font-size: 28px;
  cursor: pointer;
  color: var(--text-muted);
  padding: 4px;
  line-height: 1;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
}

.modal-close:hover {
  background: var(--bg-tertiary);
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
  -webkit-overflow-scrolling: touch;
}

.modal-footer {
  padding: 20px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  position: sticky;
  bottom: 0;
  background: var(--card-bg);
}

/* Grocery Modal */
.grocery-tips {
  background: var(--accent-bg);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 20px;
}

.grocery-tips h4 {
  font-size: 14px;
  margin: 0 0 10px;
}

.grocery-tips ul {
  list-style: none;
  font-size: 13px;
  margin: 0;
  padding: 0;
}

.grocery-tips li {
  padding: 6px 0;
}

.grocery-categories {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px;
}

.grocery-category h4 {
  font-size: 14px;
  margin: 0 0 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.grocery-category ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.grocery-category li {
  padding: 6px 0;
  display: flex;
  justify-content: space-between;
  font-size: 14px;
  border-bottom: 1px solid var(--border-light);
}

.grocery-category li:last-child {
  border-bottom: none;
}

/* Meal Prep Schedule */
.prep-schedule {
  margin-top: 20px;
  background: var(--bg-tertiary);
  border-radius: 12px;
  padding: 16px;
}

.prep-day {
  margin-bottom: 16px;
}

.prep-day:last-child {
  margin-bottom: 0;
}

.prep-day-header {
  display: flex;
  justify-content: space-between;
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 10px;
}

.prep-time {
  color: var(--accent);
  font-size: 13px;
}

.prep-task {
  display: flex;
  gap: 14px;
  padding: 8px 0;
  font-size: 13px;
  border-bottom: 1px solid var(--border-light);
}

.prep-task:last-child {
  border-bottom: none;
}

.task-time {
  min-width: 55px;
  color: var(--text-muted);
}

.task-desc {
  flex: 1;
}

.task-duration {
  color: var(--accent);
}

/* ========== AI Chat Consultation ========== */
.chat-container {
  display: flex;
  flex-direction: column;
  height: 400px;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: var(--bg-tertiary);
}

.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
}

.chat-header h4 {
  margin: 0;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-message {
  max-width: 85%;
  padding: 12px 16px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.5;
  word-wrap: break-word;
}

.chat-message.user {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.chat-message.assistant {
  align-self: flex-start;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.chat-message.assistant pre {
  background: var(--bg-tertiary);
  padding: 8px;
  border-radius: 6px;
  overflow-x: auto;
  font-size: 12px;
  margin: 8px 0;
}

.chat-message.system {
  align-self: center;
  background: var(--info-bg);
  color: var(--info);
  font-size: 12px;
  padding: 8px 16px;
  border-radius: 20px;
}

.chat-message .timestamp {
  font-size: 10px;
  opacity: 0.7;
  margin-top: 4px;
  display: block;
}

.chat-typing {
  display: flex;
  gap: 4px;
  align-items: center;
  padding: 12px 16px;
}

.chat-typing span {
  width: 8px;
  height: 8px;
  background: var(--accent);
  border-radius: 50%;
  animation: typing 1.4s infinite ease-in-out both;
}

.chat-typing span:nth-child(1) { animation-delay: -0.32s; }
.chat-typing span:nth-child(2) { animation-delay: -0.16s; }

@keyframes typing {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.5; }
  40% { transform: scale(1); opacity: 1; }
}

.chat-input-area {
  display: flex;
  gap: 8px;
  padding: 12px;
  background: var(--card-bg);
  border-top: 1px solid var(--border);
}

.chat-input-area textarea {
  flex: 1;
  resize: none;
  min-height: 44px;
  max-height: 120px;
  padding: 12px;
  border-radius: 12px;
  font-size: 15px;
}

.chat-input-area button {
  min-width: 60px;
}

.context-summary {
  background: var(--accent-bg);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 12px;
  font-size: 12px;
}

.context-summary strong {
  display: block;
  margin-bottom: 4px;
}

.context-toggle {
  cursor: pointer;
  color: var(--accent);
  font-size: 12px;
  text-decoration: underline;
}

/* ========== Agent Chips ========== */
.ai-agents {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.agent-chip {
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: 24px;
  font-size: 13px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  transition: all 0.2s;
  touch-action: manipulation;
  background: var(--btn-bg);
  color: var(--text);
}

.agent-chip.selected {
  background: var(--accent-bg);
  border-color: var(--accent);
}

.agent-chip:hover {
  border-color: var(--accent);
}

.agent-chip .icon {
  font-size: 16px;
}

/* ========== Skeleton Loading ========== */
.skeleton {
  background: linear-gradient(90deg, var(--bg-tertiary) 25%, var(--bg-secondary) 50%, var(--bg-tertiary) 75%);
  background-size: 200% 100%;
  animation: skeleton-loading 1.5s infinite;
  border-radius: 8px;
}

@keyframes skeleton-loading {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.metric-value.skeleton {
  width: 70px;
  height: 32px;
  display: inline-block;
}

/* ========== Floating Quick Actions (Mobile) ========== */
.floating-actions {
  display: none;
}

@media screen and (max-width: 480px) {
  .floating-actions {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
    padding: 12px 16px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
    display: flex;
    justify-content: space-around;
    gap: 8px;
    z-index: 90;
    box-shadow: 0 -4px 20px rgba(0,0,0,0.1);
  }

  .floating-actions .fab {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 10px 12px;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 11px;
    cursor: pointer;
    min-width: 60px;
    border-radius: 12px;
    transition: all 0.2s;
  }

  .floating-actions .fab .fab-icon {
    font-size: 24px;
  }

  .floating-actions .fab:hover,
  .floating-actions .fab:active {
    background: var(--accent-bg);
    color: var(--accent);
  }

  .floating-actions .fab.primary {
    background: var(--accent);
    color: #fff;
    border-radius: 16px;
    padding: 12px 20px;
  }

  .floating-actions .fab.primary:hover {
    background: var(--accent-light);
  }

  /* Hide desktop quick actions */
  .quick-actions {
    display: none;
  }

  /* Metrics - 2 columns on mobile */
  .grid-4 {
    grid-template-columns: repeat(2, 1fr);
  }

  .metric {
    padding: 14px 10px;
  }

  .metric-value {
    font-size: 28px;
  }

  .metric-label {
    font-size: 12px;
  }

  /* Recovery score */
  .recovery-score {
    width: 85px;
    height: 85px;
    font-size: 24px;
  }

  /* Agent chips */
  .agent-chip {
    padding: 12px 16px;
    font-size: 14px;
    min-height: 48px;
    border-radius: 24px;
  }

  /* Schedule events */
  .schedule-event {
    padding: 14px;
    border-radius: 12px;
    margin-bottom: 10px;
  }

  .schedule-event .time {
    font-size: 14px;
  }

  .schedule-event .title {
    font-size: 14px;
  }

  /* Goals */
  .goal-item {
    padding: 16px;
    border-radius: 14px;
  }

  .goal-wish {
    font-size: 15px;
  }

  .goal-plan {
    font-size: 13px;
  }

  /* Modal - Sheet style from bottom */
  .modal-overlay {
    padding: 0;
    align-items: flex-end;
  }

  .modal {
    max-height: 92vh;
    border-radius: 24px 24px 0 0;
    max-width: 100%;
  }

  .modal-header {
    padding: 20px 16px;
    border-radius: 24px 24px 0 0;
  }

  .modal-header h3 {
    font-size: 17px;
  }

  .modal-close {
    font-size: 32px;
    min-width: 48px;
    min-height: 48px;
  }

  .modal-body {
    padding: 16px;
  }

  .modal-footer {
    padding: 16px;
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
    flex-wrap: wrap;
  }

  .modal-footer button {
    flex: 1;
    min-width: calc(50% - 5px);
  }

  /* Grocery categories single column */
  .grocery-categories {
    grid-template-columns: 1fr;
  }

  /* Container bottom padding for floating actions */
  .container {
    padding-bottom: calc(100px + env(safe-area-inset-bottom));
  }
}

/* Small mobile */
@media screen and (max-width: 380px) {
  .metric-value {
    font-size: 24px;
  }
}
