/* MacroSee — Traditional HTML frontend */

:root {
  --bg: #f8f9fa;
  --surface: #ffffff;
  --text: #1a1a2e;
  --text-secondary: #6c757d;
  --primary: #2d6a4f;
  --primary-light: #40916c;
  --danger: #dc3545;
  --border: #dee2e6;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.12);
  --cal-colour: #2d6a4f;
  --protein-colour: #2563eb;
  --carbs-colour: #ea580c;
  --fat-colour: #dc2626;
  --fibre-colour: #7c3aed;
  --nav-height: 64px;
  --header-height: 52px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1c1e;
    --surface: #252729;
    --text: #e0e0e0;
    --text-secondary: #9e9e9e;
    --primary: #4caf50;
    --primary-light: #66bb6a;
    --danger: #ef5350;
    --border: #333333;
    --shadow: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-lg: 0 4px 12px rgba(0,0,0,0.4);
    --cal-colour: #4caf50;
    --protein-colour: #5c9cf5;
    --carbs-colour: #f59e42;
    --fat-colour: #ef5350;
    --fibre-colour: #a78bfa;
  }
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { color-scheme: light dark; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Views */
.view { min-height: 100dvh; }
[hidden] { display: none !important; }

/* Login */
.login-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 32px;
  text-align: center;
}
.login-brand {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 8px;
}
.login-logo {
  width: 72px;
  height: 72px;
  border-radius: 16px;
}
.login-brand h1 {
  font-size: 2.2rem;
  font-weight: 400;
}
.login-brand h1 strong {
  font-weight: 700;
}
.subtitle {
  color: var(--text-secondary);
  margin-bottom: 32px;
  font-size: 1.05rem;
}
.error { color: var(--danger); margin-top: 12px; font-size: 0.9rem; }
.privacy-link {
  color: var(--text-secondary);
  font-size: 0.85rem;
  text-decoration: none;
  margin-top: 24px;
}
.privacy-link:hover { text-decoration: underline; }

/* Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  height: var(--header-height);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.header-brand {
  display: flex;
  align-items: center;
  gap: 8px;
}
.header-logo {
  width: 28px;
  height: 28px;
  border-radius: 6px;
}
.header-brand h1 {
  font-size: 1.2rem;
  font-weight: 400;
}
.header-brand h1 strong {
  font-weight: 700;
}

/* Buttons */
.btn-primary {
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 8px;
  padding: 12px 24px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-primary:hover { background: var(--primary-light); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-secondary {
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 24px;
  font-size: 1rem;
  cursor: pointer;
  color: var(--text);
}
.btn-icon {
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px;
  color: var(--text);
  display: flex;
  align-items: center;
  font-size: 1.2rem;
}

/* Tab panels */
.tab-panel {
  padding: 16px;
  padding-bottom: calc(var(--nav-height) + 16px);
  max-width: 600px;
  margin: 0 auto;
}

/* Upload area */
.upload-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 48px 24px;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  text-align: center;
  color: var(--text-secondary);
  min-height: 250px;
}
.upload-area:hover, .upload-area.dragover {
  border-color: var(--primary);
  background: color-mix(in srgb, var(--primary) 6%, transparent);
}
.upload-area .hint { font-size: 0.85rem; opacity: 0.7; }

#upload-preview {
  text-align: center;
}
#preview-img {
  max-width: 100%;
  max-height: 300px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  object-fit: contain;
}
.upload-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 300px;
  margin: 0 auto;
}
.upload-actions select {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  background: var(--surface);
}

/* Progress */
#upload-progress {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 48px;
  text-align: center;
}
.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Daily summary */
.date-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-bottom: 16px;
  font-weight: 600;
}
.date-label {
  background: none;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  font: inherit;
  font-weight: 600;
  color: var(--text);
  padding: 4px 8px;
  border-radius: 8px;
  transition: background 0.15s;
}
.date-label:hover { background: var(--border); }
#date-picker {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.summary-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 20px;
}
.summary-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
}
.summary-card .label {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}
.summary-card .value {
  font-size: 1.4rem;
  font-weight: 700;
}
.summary-card .goal {
  font-size: 0.8rem;
  color: var(--text-secondary);
}
.summary-card .bar {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin-top: 8px;
  overflow: hidden;
}
.summary-card .bar-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.4s ease;
}
.summary-card[data-type="calories"] .value,
.summary-card[data-type="calories"] .bar-fill { color: var(--cal-colour); background: var(--cal-colour); }
.summary-card[data-type="protein"] .value,
.summary-card[data-type="protein"] .bar-fill { color: var(--protein-colour); background: var(--protein-colour); }
.summary-card[data-type="carbs"] .value,
.summary-card[data-type="carbs"] .bar-fill { color: var(--carbs-colour); background: var(--carbs-colour); }
.summary-card[data-type="fat"] .value,
.summary-card[data-type="fat"] .bar-fill { color: var(--fat-colour); background: var(--fat-colour); }

/* Meal list */
.meal-list { display: flex; flex-direction: column; gap: 10px; }
.meal-card {
  display: flex;
  gap: 12px;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 12px;
  box-shadow: var(--shadow);
  position: relative;
  cursor: pointer;
  transition: background 0.15s;
}
.meal-card:active {
  background: var(--border);
}
.meal-card img {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: 8px;
  flex-shrink: 0;
}
.meal-card .meal-info { flex: 1; min-width: 0; }
.meal-card .meal-desc {
  font-weight: 600;
  font-size: 0.95rem;
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.meal-card .meal-macros {
  font-size: 0.8rem;
  color: var(--text-secondary);
}
.meal-card .meal-time {
  font-size: 0.75rem;
  color: var(--text-secondary);
}
.meal-card .btn-delete {
  position: absolute;
  top: 8px;
  right: 8px;
  color: var(--danger);
  opacity: 0.5;
  transition: opacity 0.15s;
}
.meal-card .btn-delete:hover { opacity: 1; }

.empty-state {
  text-align: center;
  color: var(--text-secondary);
  padding: 48px 24px;
}

/* History */
.history-controls {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 16px;
}
.history-controls select {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
  background: var(--surface);
}
.chart-container {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.chart-container canvas { width: 100% !important; }

/* Result overlay */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--bg);
  overflow-y: auto;
}
.result-content {
  max-width: 500px;
  margin: 0 auto;
  padding: 16px;
  padding-bottom: 32px;
}
.btn-close {
  font-size: 1.8rem;
  float: right;
}
#result-img {
  width: 100%;
  max-height: 250px;
  object-fit: cover;
  border-radius: var(--radius);
  margin-bottom: 16px;
}
#result-description {
  font-size: 1.2rem;
  margin-bottom: 8px;
}
#result-confidence {
  display: inline-block;
  font-size: 0.85rem;
  font-weight: 500;
  padding: 4px 10px;
  border-radius: 12px;
  margin-bottom: 16px;
}
#result-confidence.conf-high { background: #2d6a4f22; color: #2d6a4f; }
#result-confidence.conf-med { background: #ea580c22; color: #ea580c; }
#result-confidence.conf-low { background: #dc262622; color: #dc2626; }
@media (prefers-color-scheme: dark) {
  #result-confidence.conf-high { background: #4caf5033; color: #66bb6a; }
  #result-confidence.conf-med { background: #f59e4233; color: #f59e42; }
  #result-confidence.conf-low { background: #ef535033; color: #ef5350; }
}
.macro-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}
.macro-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px;
  text-align: center;
  border: 1px solid var(--border);
}
.macro-card .macro-value { font-size: 1.6rem; font-weight: 700; }
.macro-card .macro-label {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
}
.macro-card.calories .macro-value { color: var(--cal-colour); }
.macro-card.protein .macro-value { color: var(--protein-colour); }
.macro-card.carbs .macro-value { color: var(--carbs-colour); }
.macro-card.fat .macro-value { color: var(--fat-colour); }

#result-items {
  margin-bottom: 16px;
}
#result-items h3 {
  font-size: 0.95rem;
  margin-bottom: 8px;
  color: var(--text-secondary);
}
.food-item {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}
.food-item:last-child { border-bottom: none; }
.food-item .item-name { font-weight: 500; }
.food-item .item-portion { color: var(--text-secondary); }
.food-item .item-cals { color: var(--text-secondary); }

#result-notes {
  font-size: 0.9rem;
  color: var(--text-secondary);
  font-style: italic;
  margin-bottom: 20px;
}

/* Correction input */
.correction-row {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}
.correction-row input {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
  background: var(--surface);
}
.correction-row input:focus { outline: none; border-color: var(--primary); }

/* Result action buttons */
.result-actions {
  display: flex;
  gap: 10px;
  margin-bottom: 10px;
}
.result-actions .btn-secondary { flex: 1; }

.edit-meal-photo {
  width: 100%;
  max-height: 220px;
  object-fit: cover;
  border-radius: var(--radius);
  margin-bottom: 12px;
}

/* Edit form */
.edit-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
}
.edit-form input {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  background: var(--surface);
  color: var(--text);
}
.edit-form input:focus { outline: none; border-color: var(--primary); }
.edit-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 12px;
}
.edit-form h2 { margin-bottom: 16px; }

/* Profile */
.profile-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}
.avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--border);
  object-fit: cover;
}
.profile-name { font-weight: 700; font-size: 1.1rem; }
.profile-email { font-size: 0.85rem; color: var(--text-secondary); }
.section-title {
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
  margin-bottom: 8px;
}
.age-display {
  display: block;
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-top: 2px;
  font-weight: 400;
}

.edit-form select {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  background: var(--surface);
  color: var(--text);
  width: 100%;
}
.edit-form select:focus { outline: none; border-color: var(--primary); }
.recommendation-card {
  background: var(--surface);
  border: 1px solid var(--primary);
  border-radius: var(--radius);
  padding: 16px;
  margin-top: 12px;
}
.recommendation-card p {
  font-size: 0.9rem;
  color: var(--text-secondary);
  line-height: 1.6;
}
.btn-danger-outline {
  color: var(--danger);
  border-color: var(--danger);
}
.btn-danger-outline:hover { background: var(--danger); color: white; }

/* Re-analyse progress in overlay */
.result-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 32px 0;
}

/* Bottom navigation */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  height: var(--nav-height);
  background: var(--surface);
  border-top: 1px solid var(--border);
  z-index: 20;
}
.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: none;
  background: none;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 0.7rem;
  transition: color 0.15s;
}
.nav-btn.active { color: var(--primary); }
.nav-btn svg { transition: stroke 0.15s; }

/* Responsive */
@media (min-width: 768px) {
  .upload-area { min-height: 350px; }
  .summary-grid { grid-template-columns: repeat(4, 1fr); }
}

/* Toast */
.toast {
  position: fixed;
  bottom: calc(var(--nav-height) + 16px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 12px 24px;
  border-radius: 8px;
  font-size: 0.9rem;
  z-index: 200;
  animation: toast-in 0.3s ease, toast-out 0.3s ease 2.7s;
  pointer-events: none;
}
@keyframes toast-in { from { opacity: 0; transform: translateX(-50%) translateY(10px); } }
@keyframes toast-out { to { opacity: 0; transform: translateX(-50%) translateY(10px); } }
