@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:ital,wght@0,400;0,700;1,400&family=DM+Sans:wght@300;400;500;600&display=swap');

:root {
  --bg:      #f8f6f1;
  --bg2:     #ffffff;
  --bg3:     #f0ede6;
  --border:  #e4dfd6;
  --text:    #1c1917;
  --muted:   #78716c;
  --accent:  #2d6a4f;
  --accent2: #52b788;
  --danger:  #b91c1c;
  --warn:    #c2410c;
  --cal:     #b91c1c;
  --pro:     #166534;
  --carb:    #1d4ed8;
  --fat:     #c2410c;
  --fib:     #7e22ce;
  --sal:     #0f766e;
  --shadow:  0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
  --shadow2: 0 4px 12px rgba(0,0,0,0.08);
  --radius:  4px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'DM Sans', sans-serif;
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
}

nav {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  padding: 0 32px; height: 56px;
  box-shadow: var(--shadow);
}

.nav-brand {
  font-family: 'Playfair Display', serif;
  font-size: 20px; font-weight: 700;
  color: var(--accent);
  margin-right: 40px;
  white-space: nowrap;
  letter-spacing: -0.01em;
}

.nav-brand span {
  font-weight: 400; font-style: italic;
  color: var(--muted); font-size: 13px; margin-left: 6px;
}

.nav-links { display: flex; gap: 2px; flex: 1; }

.nav-link {
  padding: 0 16px; height: 56px;
  display: flex; align-items: center;
  cursor: pointer; color: var(--muted);
  font-size: 13px; font-weight: 500;
  letter-spacing: 0.02em;
  border-bottom: 2px solid transparent;
  transition: all 0.15s; white-space: nowrap;
  text-decoration: none;
}
.nav-link:hover { color: var(--text); }
.nav-link.active { color: var(--accent); border-bottom-color: var(--accent); }

main {
  padding-top: 56px;
  max-width: 1140px;
  margin: 0 auto;
  padding-left: 32px;
  padding-right: 32px;
}

.page { display: none; padding: 36px 0 60px; }
.page.active { display: block; }

.page-header {
  display: flex; align-items: center;
  justify-content: space-between;
  margin-bottom: 28px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

.page-title {
  font-family: 'Playfair Display', serif;
  font-size: 28px; font-weight: 700;
  letter-spacing: -0.02em;
}

.page-subtitle { font-size: 13px; color: var(--muted); margin-top: 2px; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 18px;
  border: none; border-radius: var(--radius);
  cursor: pointer;
  font-family: 'DM Sans', sans-serif;
  font-size: 13px; font-weight: 500;
  transition: all 0.15s; white-space: nowrap;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: #245c43; }
.btn-secondary { background: var(--bg3); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn-ghost:hover { color: var(--text); border-color: var(--muted); }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-xs { padding: 4px 8px; font-size: 11px; }

.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.card-title {
  font-family: 'Playfair Display', serif;
  font-size: 17px; font-weight: 600; margin-bottom: 4px;
}
.card-meta { font-size: 12px; color: var(--muted); }

.form-group { margin-bottom: 16px; }
.form-row { display: grid; gap: 12px; }
.form-row-2 { grid-template-columns: 1fr 1fr; }
.form-row-3 { grid-template-columns: 1fr 1fr 1fr; }

label {
  display: block;
  font-size: 12px; font-weight: 500;
  color: var(--muted); margin-bottom: 5px;
  letter-spacing: 0.02em; text-transform: uppercase;
}

input, select, textarea {
  width: 100%;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text);
  font-family: 'DM Sans', sans-serif; font-size: 14px;
  padding: 9px 12px; outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(45,106,79,0.1);
}

.modal-overlay {
  display: none; position: fixed; inset: 0; z-index: 200;
  background: rgba(28,25,23,0.5);
  align-items: center; justify-content: center;
  backdrop-filter: blur(2px);
}
.modal-overlay.open { display: flex; }

.modal {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow2);
  width: 90%; max-width: 640px;
  max-height: 90vh; overflow-y: auto;
  padding: 28px;
}

.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 24px; padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
.modal-title {
  font-family: 'Playfair Display', serif;
  font-size: 20px; font-weight: 700;
}
.modal-close {
  background: none; border: none; color: var(--muted);
  font-size: 22px; cursor: pointer; line-height: 1;
  padding: 2px 6px; border-radius: var(--radius);
}
.modal-close:hover { background: var(--bg3); color: var(--text); }
.modal-footer {
  display: flex; justify-content: flex-end; gap: 10px;
  margin-top: 24px; padding-top: 16px;
  border-top: 1px solid var(--border);
}

.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
  text-align: left; font-size: 11px; font-weight: 600;
  letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--muted); padding: 10px 14px;
  border-bottom: 2px solid var(--border);
  background: var(--bg3);
}
.data-table td {
  padding: 12px 14px; border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--bg3); }

.macro-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: 3px;
  padding: 3px 8px; border-radius: 20px;
  font-size: 11px; font-weight: 500; border: 1px solid;
}
.chip.cal { color: var(--cal); border-color: #fca5a5; background: #fef2f2; }
.chip.pro { color: var(--pro); border-color: #86efac; background: #f0fdf4; }
.chip.carb { color: var(--carb); border-color: #93c5fd; background: #eff6ff; }
.chip.fat { color: var(--fat); border-color: #fdba74; background: #fff7ed; }
.chip.fib { color: var(--fib); border-color: #d8b4fe; background: #faf5ff; }
.chip.sal { color: var(--sal); border-color: #99f6e4; background: #f0fdfa; }

.progress-bar { height: 6px; background: var(--bg3); border-radius: 3px; overflow: hidden; margin-top: 6px; }
.progress-fill { height: 100%; border-radius: 3px; transition: width 0.4s ease; }

.alert { padding: 12px 16px; border-radius: var(--radius); font-size: 13px; margin-bottom: 16px; border: 1px solid; }
.alert-success { background: #f0fdf4; border-color: #86efac; color: #166534; }
.alert-error { background: #fef2f2; border-color: #fca5a5; color: #991b1b; }
.alert-warn { background: #fff7ed; border-color: #fdba74; color: #9a3412; }

.empty { text-align: center; padding: 60px 20px; color: var(--muted); }
.empty-icon { font-size: 40px; margin-bottom: 12px; }
.empty-title { font-size: 16px; font-weight: 500; color: var(--text); margin-bottom: 6px; }
.empty-text { font-size: 13px; }

.divider { border: none; border-top: 1px solid var(--border); margin: 20px 0; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 11px; font-weight: 500; }
.badge-green { background: #dcfce7; color: #166534; }
.badge-amber { background: #fef3c7; color: #92400e; }
.badge-red { background: #fee2e2; color: #991b1b; }
.badge-grey { background: var(--bg3); color: var(--muted); }

.search-wrap { position: relative; margin-bottom: 20px; }
.search-wrap input { padding-left: 36px; }
.search-icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 15px; pointer-events: none; }

.date-nav { display: flex; align-items: center; gap: 12px; margin-bottom: 24px; }
.date-nav-display { font-family: 'Playfair Display', serif; font-size: 20px; font-weight: 600; flex: 1; text-align: center; }

.macro-grid { display: grid; grid-template-columns: repeat(6,1fr); gap: 12px; margin-bottom: 28px; }
.macro-card { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.macro-card-label { font-size: 11px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); margin-bottom: 8px; }
.macro-card-value { font-family: 'Playfair Display', serif; font-size: 26px; font-weight: 700; line-height: 1; }
.macro-card-unit { font-size: 12px; color: var(--muted); font-weight: 400; }
.macro-card-target { font-size: 11px; color: var(--muted); margin-top: 4px; }

.chart-controls { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.chart-controls-title { font-family: 'Playfair Display', serif; font-size: 18px; font-weight: 600; }
.timeframe-tabs { display: flex; gap: 4px; }
.timeframe-tab { padding: 6px 14px; border-radius: var(--radius); cursor: pointer; font-size: 12px; font-weight: 500; color: var(--muted); border: 1px solid var(--border); background: var(--bg2); transition: all 0.15s; }
.timeframe-tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.timeframe-tab:hover:not(.active) { background: var(--bg3); }
.chart-wrap { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }

.meal-section { margin-bottom: 20px; }
.meal-section-header { display: flex; align-items: center; justify-content: space-between; padding: 8px 0; margin-bottom: 8px; border-bottom: 2px solid var(--border); }
.meal-section-label { font-size: 12px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.meal-section-cals { font-size: 12px; color: var(--muted); font-weight: 500; }

.diary-entry { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 6px; box-shadow: var(--shadow); transition: border-color 0.15s; }
.diary-entry:hover { border-color: var(--accent2); }
.diary-entry-name { font-weight: 500; font-size: 14px; }
.diary-entry-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.diary-entry-actions { display: flex; gap: 6px; flex-shrink: 0; }

.recipe-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px,1fr)); gap: 14px; }
.recipe-card { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); transition: all 0.15s; }
.recipe-card:hover { border-color: var(--accent2); box-shadow: var(--shadow2); transform: translateY(-1px); }
.recipe-card-name { font-family: 'Playfair Display', serif; font-size: 16px; font-weight: 600; margin-bottom: 6px; }
.recipe-card-actions { display: flex; gap: 6px; margin-top: 14px; }

.ing-builder { margin-top: 16px; }
.ing-builder-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.ing-builder-label { font-size: 12px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.ing-row { display: grid; grid-template-columns: 1fr 100px 36px; gap: 8px; align-items: center; margin-bottom: 8px; }

.settings-section { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; box-shadow: var(--shadow); margin-bottom: 20px; }
.settings-section-title { font-family: 'Playfair Display', serif; font-size: 18px; font-weight: 600; margin-bottom: 16px; padding-bottom: 12px; border-bottom: 1px solid var(--border); }

.report-stat-grid { display: grid; grid-template-columns: repeat(3,1fr); gap: 14px; margin-bottom: 24px; }
.report-stat { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.report-stat-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin-bottom: 6px; }
.report-stat-value { font-family: 'Playfair Display', serif; font-size: 28px; font-weight: 700; }
.report-stat-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

.flex { display: flex; }
.flex-center { display: flex; align-items: center; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.text-muted { color: var(--muted); }
.text-sm { font-size: 12px; }

@media (max-width: 768px) {
  nav { padding: 0 16px; }
  main { padding-left: 16px; padding-right: 16px; }
  .macro-grid { grid-template-columns: repeat(3,1fr); }
  .report-stat-grid { grid-template-columns: repeat(2,1fr); }
  .nav-brand span { display: none; }
}
@media (max-width: 480px) {
  .macro-grid { grid-template-columns: repeat(2,1fr); }
  .form-row-2, .form-row-3 { grid-template-columns: 1fr; }
}
