/* ── Reset & Base ── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --clr-bg: #f4f6f9;
  --clr-surface: #ffffff;
  --clr-primary: #4f46e5;
  --clr-primary-light: #818cf8;
  --clr-success: #22c55e;
  --clr-warning: #f59e0b;
  --clr-danger: #ef4444;
  --clr-text: #1e293b;
  --clr-text-muted: #64748b;
  --clr-border: #e2e8f0;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.1);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--clr-bg);
  color: var(--clr-text);
  line-height: 1.5;
  min-height: 100vh;
}

#app {
  max-width: 640px;
  margin: 0 auto;
  padding: 0 16px 48px;
}

/* ── Utility ── */
.hidden { display: none !important; }

/* ── Header ── */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  padding: 20px 0 12px;
  border-bottom: 1px solid var(--clr-border);
  margin-bottom: 16px;
}

.header h1 {
  font-size: 1.25rem;
  font-weight: 700;
}

.user-selector {
  display: flex;
  align-items: center;
  gap: 8px;
}

.user-selector label {
  font-size: 0.875rem;
  color: var(--clr-text-muted);
}

.user-selector select {
  padding: 6px 10px;
  border: 1px solid var(--clr-border);
  border-radius: var(--radius);
  font-size: 0.875rem;
  background: var(--clr-surface);
  cursor: pointer;
}

/* ── Goal Banner ── */
.goal-banner {
  background: var(--clr-surface);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.goal-info {
  display: flex;
  justify-content: space-between;
  font-size: 0.875rem;
  margin-bottom: 8px;
}

#goal-remaining {
  font-weight: 600;
}

.progress-bar-track {
  width: 100%;
  height: 12px;
  background: var(--clr-bg);
  border-radius: 6px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  width: 0%;
  border-radius: 6px;
  transition: width 0.4s ease, background-color 0.4s ease;
  background: var(--clr-success);
}

.progress-bar-fill.over {
  background: var(--clr-danger);
}

.progress-bar-fill.warning {
  background: var(--clr-warning);
}

/* ── Date Navigation ── */
.date-nav {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 16px;
  padding: 10px 0;
  margin-bottom: 16px;
}

.date-nav span {
  font-weight: 600;
  font-size: 1rem;
  min-width: 160px;
  text-align: center;
}

.btn-icon {
  background: var(--clr-surface);
  border: 1px solid var(--clr-border);
  border-radius: var(--radius);
  width: 36px;
  height: 36px;
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.btn-icon:hover {
  background: var(--clr-bg);
}

/* ── Search ── */
.search-section {
  margin-bottom: 16px;
}

.search-wrapper {
  position: relative;
}

#food-search {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--clr-border);
  border-radius: var(--radius);
  font-size: 1rem;
  background: var(--clr-surface);
  box-shadow: var(--shadow);
  transition: border-color 0.15s;
}

#food-search:focus {
  outline: none;
  border-color: var(--clr-primary);
}

.search-results {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--clr-surface);
  border: 1px solid var(--clr-border);
  border-radius: var(--radius);
  max-height: 280px;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  z-index: 100;
}

.search-result-item {
  padding: 10px 14px;
  cursor: pointer;
  font-size: 0.875rem;
  border-bottom: 1px solid var(--clr-border);
  transition: background 0.1s;
}

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

.search-result-item:hover {
  background: #f0f0ff;
}

.search-result-item .brand {
  color: var(--clr-text-muted);
  font-size: 0.75rem;
}

/* ── Food Detail Panel ── */
.food-detail {
  background: var(--clr-surface);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.food-detail h2 {
  font-size: 1rem;
  margin-bottom: 14px;
}

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

.nutrient-card {
  text-align: center;
  padding: 10px 6px;
  background: var(--clr-bg);
  border-radius: 8px;
}

.nutrient-value {
  display: block;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--clr-primary);
}

.nutrient-label {
  display: block;
  font-size: 0.7rem;
  color: var(--clr-text-muted);
  margin-top: 2px;
}

.btn-primary {
  width: 100%;
  padding: 12px;
  background: var(--clr-primary);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-primary:hover {
  background: var(--clr-primary-light);
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ── Daily Totals ── */
.daily-totals {
  margin-bottom: 16px;
}

.daily-totals h2 {
  font-size: 1rem;
  margin-bottom: 10px;
}

.totals-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.total-card {
  background: var(--clr-surface);
  border-radius: var(--radius);
  padding: 12px 6px;
  text-align: center;
  box-shadow: var(--shadow);
}

.total-card span:first-child {
  display: block;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--clr-primary);
}

.total-card span:last-child {
  display: block;
  font-size: 0.7rem;
  color: var(--clr-text-muted);
  margin-top: 2px;
}

/* ── Entries List ── */
.entries-section h2 {
  font-size: 1rem;
  margin-bottom: 10px;
}

.entries-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.empty-state {
  text-align: center;
  color: var(--clr-text-muted);
  font-size: 0.875rem;
  padding: 24px 0;
}

.entry-card {
  background: var(--clr-surface);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: box-shadow 0.15s;
}

.entry-card:hover {
  box-shadow: var(--shadow-lg);
}

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

.entry-name {
  font-weight: 600;
  font-size: 0.875rem;
}

.entry-cals {
  font-weight: 700;
  font-size: 0.875rem;
  color: var(--clr-primary);
}

.entry-macros {
  display: flex;
  gap: 12px;
  font-size: 0.75rem;
  color: var(--clr-text-muted);
}

.entry-breakdown {
  display: none;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--clr-border);
  font-size: 0.8rem;
  color: var(--clr-text-muted);
}

.entry-breakdown.open {
  display: block;
}

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--clr-text);
  color: #fff;
  padding: 10px 20px;
  border-radius: var(--radius);
  font-size: 0.875rem;
  box-shadow: var(--shadow-lg);
  z-index: 200;
  transition: opacity 0.3s;
}

.toast.hidden {
  opacity: 0;
  pointer-events: none;
}

/* ── Responsive ── */
@media (max-width: 480px) {
  .header {
    flex-direction: column;
    align-items: flex-start;
  }

  .nutrient-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .totals-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}
