/* ==========================================================================
   CaloTrack - Pure Vanilla CSS (Strictly NO CSS Variables & NO Frameworks)
   ========================================================================== */

/* Universal Reset & Box-Sizing */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background-color: #f1f5f9;
  color: #1e293b;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ==========================================================================
   Header & Navigation
   ========================================================================== */
.app-header {
  background-color: #ffffff;
  border-bottom: 1px solid #e2e8f0;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.05);
}

.header-container {
  max-width: 1040px;
  margin: 0 auto;
  padding: 0.85rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 800;
  font-size: 1.35rem;
  color: #4f46e5;
  user-select: none;
}

.logo-icon {
  font-size: 1.5rem;
}

.logo-title {
  letter-spacing: -0.5px;
}

/* Date Navigator */
.date-navigator {
  display: flex;
  align-items: center;
  background-color: #f8fafc;
  border: 1px solid #cbd5e1;
  border-radius: 9999px;
  padding: 0.2rem 0.4rem;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.03);
}

.nav-btn {
  background: transparent;
  border: none;
  font-size: 1.1rem;
  font-weight: bold;
  color: #475569;
  cursor: pointer;
  width: 2rem;
  height: 2rem;
  border-radius: 9999px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.nav-btn:hover {
  background-color: #e2e8f0;
  color: #0f172a;
}

.today-btn {
  background-color: #4f46e5;
  color: #ffffff;
  border: none;
  padding: 0.35rem 0.85rem;
  font-size: 0.8rem;
  font-weight: 600;
  border-radius: 9999px;
  cursor: pointer;
  margin-right: 0.35rem;
  transition: background-color 0.15s ease;
}

.today-btn:hover {
  background-color: #4338ca;
}

.date-input {
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  color: #334155;
  padding: 0.25rem 0.5rem;
  cursor: pointer;
  outline: none;
}

/* Settings button */
.settings-btn {
  background-color: #f8fafc;
  color: #334155;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  padding: 0.5rem 0.9rem;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  transition: all 0.15s ease;
}

.settings-btn:hover {
  background-color: #e2e8f0;
  color: #0f172a;
}

/* ==========================================================================
   Main Layout & Base Cards
   ========================================================================== */
.main-container {
  max-width: 1040px;
  width: 100%;
  margin: 1.5rem auto 3rem auto;
  padding: 0 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  flex: 1;
}

.card {
  background-color: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 1.25rem;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.04), 0 2px 4px -2px rgba(0, 0, 0, 0.02);
}

.card-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: #0f172a;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* ==========================================================================
   Overview Section: Calories & Macros
   ========================================================================== */
.overview-section {
  display: grid;
  grid-template-columns: 1.15fr 1fr;
  gap: 1.25rem;
}

/* Calorie Card */
.calorie-display-wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.calorie-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 90px;
}

.stat-number {
  font-size: 1.75rem;
  font-weight: 800;
  color: #0f172a;
  line-height: 1.1;
}

.stat-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #64748b;
  margin-top: 0.25rem;
}

.calorie-middle {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.65rem;
}

.calorie-progress-track {
  width: 100%;
  height: 16px;
  background-color: #e2e8f0;
  border-radius: 9999px;
  overflow: hidden;
  position: relative;
}

.calorie-progress-fill {
  height: 100%;
  width: 0%;
  background-color: #4f46e5;
  border-radius: 9999px;
  transition: width 0.4s ease, background-color 0.3s ease;
}

.budget-subtext {
  font-size: 0.9rem;
  color: #475569;
}

.budget-subtext strong {
  font-weight: 700;
  color: #0f172a;
}

/* Macros Card */
.macros-grid {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.macro-bar-group {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.macro-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.85rem;
  font-weight: 600;
}

.macro-protein {
  color: #ec4899;
}

.macro-carbs {
  color: #0284c7;
}

.macro-fat {
  color: #d97706;
}

.macro-values {
  color: #64748b;
  font-size: 0.82rem;
}

.macro-track {
  width: 100%;
  height: 9px;
  background-color: #e2e8f0;
  border-radius: 9999px;
  overflow: hidden;
}

.macro-fill {
  height: 100%;
  width: 0%;
  border-radius: 9999px;
  transition: width 0.4s ease;
}

.fill-protein {
  background-color: #ec4899;
}

.fill-carbs {
  background-color: #0284c7;
}

.fill-fat {
  background-color: #d97706;
}

/* ==========================================================================
   Presets Bar
   ========================================================================== */
.presets-card {
  padding: 1rem 1.25rem;
  background-color: #ffffff;
}

.presets-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.presets-title {
  font-size: 0.92rem;
  font-weight: 700;
  color: #0f172a;
}

.presets-hint {
  font-size: 0.78rem;
  color: #64748b;
}

.preset-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.preset-chip {
  background-color: #f1f5f9;
  border: 1px solid #cbd5e1;
  border-radius: 9999px;
  padding: 0.35rem 0.8rem;
  font-size: 0.82rem;
  font-weight: 500;
  color: #334155;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  transition: all 0.15s ease;
  user-select: none;
}

.preset-chip:hover {
  background-color: #e0e7ff;
  border-color: #818cf8;
  color: #3730a3;
  transform: translateY(-1px);
}

.preset-chip .chip-cal {
  font-weight: 700;
  color: #4f46e5;
  font-size: 0.78rem;
}

/* ==========================================================================
   Food Entry Form
   ========================================================================== */
.entry-form {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.form-row {
  display: flex;
  gap: 0.85rem;
  align-items: flex-end;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  flex: 1;
}

.form-group label {
  font-size: 0.8rem;
  font-weight: 600;
  color: #475569;
}

.invisible-label {
  visibility: hidden;
}

.meal-type-group {
  flex: 0 0 160px;
}

.food-name-group {
  flex: 2;
}

.calories-group {
  flex: 1;
}

input[type="text"],
input[type="number"],
select {
  width: 100%;
  padding: 0.55rem 0.75rem;
  font-family: inherit;
  font-size: 0.9rem;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background-color: #ffffff;
  color: #0f172a;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input[type="text"]:focus,
input[type="number"]:focus,
select:focus {
  border-color: #4f46e5;
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}

.primary-btn {
  background-color: #4f46e5;
  color: #ffffff;
  border: none;
  border-radius: 8px;
  padding: 0.6rem 1.25rem;
  font-family: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s ease, transform 0.1s ease;
  white-space: nowrap;
  width: 100%;
}

.primary-btn:hover {
  background-color: #4338ca;
}

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

/* ==========================================================================
   Meal Sections Breakdown
   ========================================================================== */
.meals-container {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.meal-card {
  padding: 1.15rem;
}

.meal-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid #f1f5f9;
  padding-bottom: 0.75rem;
  margin-bottom: 0.85rem;
}

.meal-header-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.meal-badge {
  font-size: 0.85rem;
  font-weight: 700;
  padding: 0.25rem 0.65rem;
  border-radius: 6px;
  letter-spacing: -0.2px;
}

.breakfast-badge {
  background-color: #fef3c7;
  color: #92400e;
}

.lunch-badge {
  background-color: #e0f2fe;
  color: #0369a1;
}

.dinner-badge {
  background-color: #ede9fe;
  color: #5b21b6;
}

.snacks-badge {
  background-color: #fce7f3;
  color: #9d174d;
}

.meal-item-count {
  font-size: 0.8rem;
  color: #64748b;
  font-weight: 500;
}

.meal-calories {
  font-size: 1.05rem;
  font-weight: 700;
  color: #0f172a;
}

/* Meal Items List */
.meal-items-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.empty-state-text {
  color: #94a3b8;
  font-size: 0.85rem;
  font-style: italic;
  padding: 0.6rem 0.25rem;
}

.food-item-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background-color: #f8fafc;
  border: 1px solid #f1f5f9;
  border-radius: 8px;
  padding: 0.65rem 0.85rem;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.food-item-row:hover {
  background-color: #f1f5f9;
  border-color: #e2e8f0;
}

.item-left {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.item-name {
  font-size: 0.92rem;
  font-weight: 600;
  color: #1e293b;
}

.item-macros-tags {
  display: flex;
  gap: 0.45rem;
  font-size: 0.72rem;
  font-weight: 600;
}

.macro-tag {
  border-radius: 4px;
  padding: 0.1rem 0.35rem;
}

.tag-p {
  background-color: #fce7f3;
  color: #be185d;
}

.tag-c {
  background-color: #e0f2fe;
  color: #0369a1;
}

.tag-f {
  background-color: #fef3c7;
  color: #b45309;
}

.item-right {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.item-cal-badge {
  font-size: 0.92rem;
  font-weight: 700;
  color: #334155;
  background-color: #e2e8f0;
  padding: 0.25rem 0.6rem;
  border-radius: 6px;
}

.delete-item-btn {
  background: transparent;
  border: none;
  color: #94a3b8;
  font-size: 1.15rem;
  cursor: pointer;
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
  line-height: 1;
  transition: color 0.15s ease, background-color 0.15s ease;
}

.delete-item-btn:hover {
  color: #ef4444;
  background-color: #fee2e2;
}

/* ==========================================================================
   Settings Modal Dialog
   ========================================================================== */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(2px);
}

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

.modal-dialog {
  background-color: #ffffff;
  border-radius: 12px;
  width: 90%;
  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;
  animation: modalPop 0.2s ease-out;
}

@keyframes modalPop {
  0% { transform: scale(0.95); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.modal-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid #e2e8f0;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: #0f172a;
}

.close-modal-btn {
  background: transparent;
  border: none;
  font-size: 1.5rem;
  color: #64748b;
  cursor: pointer;
  line-height: 1;
}

.close-modal-btn:hover {
  color: #0f172a;
}

.modal-body {
  padding: 1.25rem;
}

.settings-subtitle {
  font-size: 0.88rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #64748b;
  margin-bottom: 0.75rem;
}

.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.save-goals-btn {
  background-color: #4f46e5;
  color: #ffffff;
  border: none;
  border-radius: 8px;
  padding: 0.65rem 1rem;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
  transition: background-color 0.15s ease;
}

.save-goals-btn:hover {
  background-color: #4338ca;
}

.modal-divider {
  border: 0;
  border-top: 1px solid #e2e8f0;
  margin: 1.25rem 0;
}

.storage-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
}

.secondary-btn,
.file-upload-label {
  background-color: #f8fafc;
  color: #334155;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  padding: 0.55rem 0.75rem;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.secondary-btn:hover,
.file-upload-label:hover {
  background-color: #e2e8f0;
  color: #0f172a;
}

.danger-btn {
  background-color: #fee2e2;
  color: #b91c1c;
  border: 1px solid #fecaca;
  border-radius: 8px;
  padding: 0.55rem 0.75rem;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.danger-btn:hover {
  background-color: #fecaca;
  color: #991b1b;
}

.danger-outline-btn {
  background-color: transparent;
  color: #dc2626;
  border: 1px dashed #f87171;
  border-radius: 8px;
  padding: 0.55rem 0.75rem;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.danger-outline-btn:hover {
  background-color: #fef2f2;
}

/* ==========================================================================
   Footer
   ========================================================================== */
.app-footer {
  text-align: center;
  padding: 1.5rem 1rem;
  font-size: 0.8rem;
  color: #94a3b8;
  border-top: 1px solid #e2e8f0;
  background-color: #ffffff;
  margin-top: auto;
}

/* ==========================================================================
   Responsive Adaptations
   ========================================================================== */
@media (max-width: 768px) {
  .header-container {
    flex-wrap: wrap;
    justify-content: center;
  }

  .date-navigator {
    order: 3;
    width: 100%;
    justify-content: center;
  }

  .overview-section {
    grid-template-columns: 1fr;
  }

  .form-row {
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
  }

  .meal-type-group {
    flex: auto;
  }

  .macros-input-row {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .macros-input-row .form-group {
    min-width: 70px;
  }

  .macros-input-row .submit-group {
    flex: 1 1 100%;
  }

  .invisible-label {
    display: none;
  }

  .storage-actions {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 480px) {
  .calorie-display-wrap {
    flex-direction: column;
    text-align: center;
  }

  .calorie-stat {
    width: 100%;
  }

  .calorie-middle {
    width: 100%;
    order: 2;
  }

  .stat-number {
    font-size: 1.5rem;
  }
}

