/* ==========================================================================
   NUTRICHOACH AI - DESIGN SYSTEM & STYLESHEET
   Sleek Dark Mode, Glassmorphism, Micro-Interactions, Mobile-First PWA
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Outfit:wght@400;500;600;700;800&display=swap');

:root {
  --bg-primary: #090d16;
  --bg-secondary: #0f172a;
  --bg-tertiary: #1e293b;
  --bg-card: rgba(18, 24, 38, 0.78);
  --bg-card-hover: rgba(28, 36, 56, 0.88);
  --bg-glass: rgba(15, 23, 42, 0.65);
  
  --emerald-500: #10b981;
  --emerald-400: #34d399;
  --emerald-600: #059669;
  --emerald-glow: rgba(16, 185, 129, 0.25);
  
  --cyan-400: #22d3ee;
  --cyan-500: #06b6d4;
  --cyan-glow: rgba(6, 182, 212, 0.25);
  
  --rose-500: #f43f5e;
  --rose-glow: rgba(244, 63, 94, 0.3);
  --amber-400: #fbbf24;
  --amber-500: #f59e0b;
  
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-subtle: #64748b;
  
  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-focus: rgba(52, 211, 153, 0.45);
  --border-card: rgba(255, 255, 255, 0.06);

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-full: 9999px;

  --font-display: 'Outfit', -apple-system, sans-serif;
  --font-body: 'Inter', -apple-system, sans-serif;

  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 24px var(--emerald-glow);

  --bottom-bar-height: 72px;
  --header-height: 68px;
}

/* Reset & Box Sizing */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  background-color: var(--bg-primary);
  color: var(--text-main);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  height: 100%;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* Background Atmosphere */
body::before {
  content: '';
  position: fixed;
  top: -150px;
  left: 50%;
  transform: translateX(-50%);
  width: 600px;
  height: 450px;
  background: radial-gradient(circle, rgba(16, 185, 129, 0.12) 0%, rgba(6, 182, 212, 0.05) 45%, transparent 70%);
  pointer-events: none;
  z-index: 0;
}

/* App Container */
#app-container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  max-width: 540px; /* Optimal mobile app size on desktop */
  margin: 0 auto;
  position: relative;
  background: var(--bg-primary);
  border-left: 1px solid var(--border-subtle);
  border-right: 1px solid var(--border-subtle);
  box-shadow: 0 0 50px rgba(0, 0, 0, 0.6);
  z-index: 1;
}

@media (min-width: 768px) {
  #app-container {
    max-width: 680px;
  }
}

/* Header */
.app-header {
  height: var(--header-height);
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(9, 13, 22, 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
}

.brand-section {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--emerald-500), var(--cyan-500));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  box-shadow: 0 0 14px var(--emerald-glow);
}

.brand-titles h1 {
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.3px;
  background: linear-gradient(to right, #ffffff, var(--emerald-400));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-status {
  font-size: 11px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 4px;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--emerald-400);
  box-shadow: 0 0 8px var(--emerald-400);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0% { transform: scale(1); opacity: 0.9; }
  50% { transform: scale(1.3); opacity: 0.5; }
  100% { transform: scale(1); opacity: 0.9; }
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Buttons */
.btn-icon {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-full);
  background: var(--bg-tertiary);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  font-size: 15px;
}

.btn-icon:hover {
  background: var(--bg-card-hover);
  border-color: var(--emerald-400);
  transform: translateY(-1px);
}

.btn-sos {
  background: linear-gradient(135deg, #e11d48, #be123c);
  border: 1px solid rgba(244, 63, 94, 0.4);
  color: #fff;
  padding: 6px 12px;
  border-radius: var(--radius-full);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.5px;
  display: flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  box-shadow: 0 0 14px var(--rose-glow);
  transition: all 0.2s ease;
}

.btn-sos:hover {
  transform: scale(1.04);
  box-shadow: 0 0 20px var(--rose-glow);
}

.btn-sos:active {
  transform: scale(0.97);
}

/* Routine Bar (Current Activity Today) */
.today-routine-banner {
  padding: 8px 16px;
  background: linear-gradient(90deg, rgba(16, 185, 129, 0.12), rgba(6, 182, 212, 0.08));
  border-bottom: 1px solid rgba(16, 185, 129, 0.2);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
}

.routine-tag {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
  color: var(--emerald-400);
}

.routine-timing {
  color: var(--text-muted);
  font-weight: 400;
}

/* Main Content Area */
.main-content {
  flex: 1;
  padding-bottom: calc(var(--bottom-bar-height) + 24px);
  display: flex;
  flex-direction: column;
}

/* Tab Panels */
.tab-panel {
  display: none;
  flex-direction: column;
  flex: 1;
  animation: fadeIn 0.25s ease-out;
}

.tab-panel.active {
  display: flex;
}

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

/* Coach IA Chat Interface */
.chat-container {
  display: flex;
  flex-direction: column;
  flex: 1;
  height: calc(100vh - var(--header-height) - var(--bottom-bar-height) - 40px);
}

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

.message {
  display: flex;
  flex-direction: column;
  max-width: 86%;
  animation: messageIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

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

.message.user {
  align-self: flex-end;
}

.message.assistant {
  align-self: flex-start;
}

.message-bubble {
  padding: 12px 16px;
  border-radius: var(--radius-md);
  font-size: 14px;
  line-height: 1.55;
  position: relative;
  word-break: break-word;
}

.message.user .message-bubble {
  background: linear-gradient(135deg, var(--emerald-600), #047857);
  color: #ffffff;
  border-bottom-right-radius: 4px;
  box-shadow: 0 4px 14px rgba(5, 150, 105, 0.25);
}

.message.assistant .message-bubble {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  border-bottom-left-radius: 4px;
  box-shadow: var(--shadow-sm);
}

.message-bubble h3 {
  font-family: var(--font-display);
  font-size: 15px;
  color: var(--emerald-400);
  margin-bottom: 8px;
}

.message-bubble p {
  margin-bottom: 8px;
}

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

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

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

.message-image {
  max-width: 100%;
  max-height: 220px;
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  object-fit: cover;
  border: 1px solid var(--border-subtle);
}

.message-time {
  font-size: 10px;
  color: var(--text-subtle);
  margin-top: 4px;
  align-self: flex-end;
}

/* Quick Action Chips */
.quick-prompts-bar {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 6px 16px 10px;
  scrollbar-width: none;
}

.quick-prompts-bar::-webkit-scrollbar {
  display: none;
}

.chip-btn {
  white-space: nowrap;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  padding: 6px 12px;
  border-radius: var(--radius-full);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 5px;
}

.chip-btn:hover {
  background: var(--bg-card-hover);
  color: var(--emerald-400);
  border-color: rgba(52, 211, 153, 0.3);
  transform: translateY(-1px);
}

/* Chat Input Bar */
.chat-input-wrapper {
  padding: 8px 14px 14px;
  background: rgba(9, 13, 22, 0.95);
  border-top: 1px solid var(--border-subtle);
}

.media-preview-container {
  display: none;
  position: relative;
  margin-bottom: 8px;
  width: fit-content;
}

.media-preview-img {
  width: 72px;
  height: 72px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  border: 1px solid var(--emerald-400);
}

.media-preview-remove {
  position: absolute;
  top: -6px;
  right: -6px;
  background: var(--rose-500);
  color: #fff;
  border-radius: 50%;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 11px;
  font-weight: bold;
  border: 1px solid #fff;
}

.chat-input-box {
  display: flex;
  align-items: center;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  padding: 4px 6px 4px 14px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.chat-input-box:focus-within {
  border-color: var(--emerald-500);
  box-shadow: 0 0 14px var(--emerald-glow);
}

.chat-textarea {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-main);
  font-family: var(--font-body);
  font-size: 14px;
  resize: none;
  max-height: 90px;
  padding: 8px 0;
}

.chat-textarea::placeholder {
  color: var(--text-subtle);
}

.input-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.btn-camera {
  background: transparent;
  border: none;
  color: var(--text-muted);
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 16px;
  transition: color 0.2s;
}

.btn-camera:hover {
  color: var(--emerald-400);
}

.btn-send {
  background: var(--emerald-500);
  border: none;
  color: #ffffff;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 15px;
  transition: transform 0.2s, background 0.2s;
}

.btn-send:hover {
  background: var(--emerald-400);
  transform: scale(1.05);
}

.btn-send:disabled {
  background: var(--bg-tertiary);
  color: var(--text-subtle);
  cursor: not-allowed;
  transform: none;
}

/* ==========================================================================
   CARDS & DASHBOARD GRIDS (Diario, Balanza, Eventos)
   ========================================================================== */

.page-container {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.section-header h2 {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 700;
  color: var(--text-main);
}

.card {
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-lg);
  padding: 18px;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.2s, transform 0.2s;
}

.card:hover {
  border-color: rgba(255, 255, 255, 0.12);
}

.card-title {
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* Macro Rings / Calorie Progress */
.calorie-hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.calorie-number {
  font-family: var(--font-display);
  font-size: 36px;
  font-weight: 800;
  line-height: 1;
  color: #fff;
}

.calorie-number span {
  font-size: 16px;
  font-weight: 500;
  color: var(--emerald-400);
}

.calorie-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

.macro-bars {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 16px;
}

.macro-box {
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 10px;
  text-align: center;
}

.macro-label {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 600;
}

.macro-value {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  margin: 3px 0;
}

.macro-meter {
  height: 4px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-full);
  overflow: hidden;
  margin-top: 4px;
}

.macro-fill {
  height: 100%;
  border-radius: var(--radius-full);
}

.fill-protein { background: var(--cyan-400); }
.fill-carbs { background: var(--amber-400); }
.fill-fat { background: var(--rose-500); }

/* Sodium Warning Box */
.alert-box {
  background: rgba(244, 63, 94, 0.1);
  border: 1px solid rgba(244, 63, 94, 0.3);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 12px;
  color: #fda4af;
}

.alert-box.info {
  background: rgba(6, 182, 212, 0.1);
  border-color: rgba(6, 182, 212, 0.3);
  color: #67e8f9;
}

/* Meals List */
.meal-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px;
  background: rgba(15, 23, 42, 0.5);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  margin-bottom: 8px;
  transition: transform 0.15s ease;
}

.meal-item:hover {
  transform: translateX(2px);
  background: rgba(28, 36, 56, 0.7);
}

.meal-item-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.meal-thumb {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  background: var(--bg-tertiary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}

.meal-info h4 {
  font-size: 13px;
  font-weight: 600;
  color: #fff;
}

.meal-info p {
  font-size: 11px;
  color: var(--text-muted);
}

.meal-macros-tag {
  font-size: 11px;
  color: var(--emerald-400);
  font-weight: 600;
  text-align: right;
}

.meal-cheat-tag {
  color: var(--rose-500);
  font-size: 10px;
  font-weight: 700;
}

/* Weight Tracking Page */
.weight-stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.stat-card {
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 12px;
  text-align: center;
}

.stat-val {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 800;
  color: #fff;
}

.stat-label {
  font-size: 11px;
  color: var(--text-muted);
}

.chart-wrapper {
  position: relative;
  height: 220px;
  width: 100%;
  margin-top: 8px;
}

/* Event Planner */
.event-card {
  background: rgba(15, 23, 42, 0.6);
  border-left: 4px solid var(--amber-400);
  border-radius: var(--radius-md);
  padding: 14px;
  margin-bottom: 10px;
}

.event-card h4 {
  font-family: var(--font-display);
  font-size: 15px;
  color: #fff;
  display: flex;
  justify-content: space-between;
}

.event-date {
  font-size: 11px;
  color: var(--amber-400);
  font-weight: 600;
}

.event-card p {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 6px;
}

/* SOS Checklist */
.sos-step {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px;
  background: rgba(15, 23, 42, 0.7);
  border: 1px solid rgba(244, 63, 94, 0.2);
  border-radius: var(--radius-md);
  margin-bottom: 8px;
}

.sos-step-num {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--rose-500);
  color: #fff;
  font-weight: 700;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.sos-step-body h4 {
  font-size: 13px;
  font-weight: 600;
  color: #fff;
}

.sos-step-body p {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Bottom Navigation Bar (PWA Mobile Bar) */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 540px;
  height: var(--bottom-bar-height);
  background: rgba(9, 13, 22, 0.92);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  justify-content: space-around;
  align-items: center;
  z-index: 50;
  padding: 0 4px;
}

@media (min-width: 768px) {
  .bottom-nav {
    max-width: 680px;
  }
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: transparent;
  border: none;
  color: var(--text-subtle);
  cursor: pointer;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  font-family: var(--font-body);
  font-size: 11px;
  font-weight: 500;
  position: relative;
}

.nav-icon {
  font-size: 18px;
  transition: transform 0.2s;
}

.nav-item:hover {
  color: var(--text-muted);
}

.nav-item.active {
  color: var(--emerald-400);
}

.nav-item.active .nav-icon {
  transform: translateY(-2px) scale(1.1);
}

.nav-item.active::after {
  content: '';
  position: absolute;
  bottom: 2px;
  width: 16px;
  height: 3px;
  background: var(--emerald-400);
  border-radius: var(--radius-full);
  box-shadow: 0 0 8px var(--emerald-400);
}

/* Modals */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-overlay.open {
  display: flex;
  animation: fadeIn 0.2s ease;
}

.modal-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 480px;
  padding: 22px;
  box-shadow: var(--shadow-lg);
  max-height: 90vh;
  overflow-y: auto;
}

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

.modal-header h3 {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 700;
  color: #fff;
}

.modal-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 20px;
  cursor: pointer;
}

/* Forms */
.form-group {
  margin-bottom: 14px;
}

.form-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.form-input, .form-select, .form-textarea {
  width: 100%;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  color: var(--text-main);
  font-family: var(--font-body);
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--emerald-400);
}

.btn-primary {
  width: 100%;
  background: linear-gradient(135deg, var(--emerald-500), var(--emerald-600));
  border: none;
  color: #fff;
  padding: 12px;
  border-radius: var(--radius-md);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 4px 14px var(--emerald-glow);
}

.btn-primary:hover {
  background: linear-gradient(135deg, var(--emerald-400), var(--emerald-500));
  transform: translateY(-1px);
}

/* Typing indicator */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 14px;
  background: var(--bg-card);
  border-radius: var(--radius-md);
  width: fit-content;
}

.typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--emerald-400);
  animation: typing 1.4s infinite ease-in-out both;
}

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

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