:root {
  --bg: #f3f6f4;
  --surface: #ffffff;
  --surface-alt: #f8faf9;
  --text: #111827;
  --text-muted: #6b7280;
  --primary: #10b981;
  --primary-dark: #059669;
  --primary-light: #d1fae5;
  --accent-blue: #3b82f6;
  --accent-amber: #f59e0b;
  --accent-rose: #f43f5e;
  --accent-purple: #8b5cf6;
  --border: #e5e7eb;
  --radius: 18px;
  --shadow: 0 4px 20px rgba(17, 24, 39, 0.05);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg);
  color: var(--text);
  padding-bottom: calc(82px + env(safe-area-inset-bottom, 12px));
}

.app-shell {
  max-width: 520px;
  margin: 0 auto;
  min-height: 100vh;
}

/* Auth Screen */
.auth-overlay {
  position: fixed;
  inset: 0;
  background: linear-gradient(145deg, #ecfdf5 0%, #f3f6f4 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 1000;
}

.auth-card {
  background: var(--surface);
  border-radius: 24px;
  padding: 32px 24px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 12px 35px rgba(16, 185, 129, 0.12);
  text-align: center;
}

.auth-logo {
  width: 64px;
  height: 64px;
  border-radius: 18px;
  margin-bottom: 14px;
}

/* Header & Date Bar */
.top-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(243, 246, 244, 0.9);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  padding: calc(12px + env(safe-area-inset-top, 0px)) 16px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(229, 231, 235, 0.7);
}

.brand-title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.3px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.date-nav {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--surface);
  padding: 5px 8px;
  border-radius: 12px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04);
}

.date-nav button {
  border: none;
  background: transparent;
  font-size: 16px;
  padding: 4px 8px;
  cursor: pointer;
  color: var(--text);
  border-radius: 8px;
}

.date-nav input[type="date"] {
  border: none;
  background: transparent;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  font-family: inherit;
  outline: none;
}

/* Main Content & Cards */
.content-area {
  padding: 14px 16px;
}

.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}

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

.card-title {
  font-size: 16px;
  font-weight: 700;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 7px;
}

.badge {
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--primary-light);
  color: var(--primary-dark);
}

.badge.warn {
  background: #fef3c7;
  color: #b45309;
}

.badge.danger {
  background: #ffe4e6;
  color: #be123c;
}

/* Calorie Hero Card */
.kcal-hero {
  background: linear-gradient(135deg, #059669 0%, #10b981 100%);
  color: #ffffff;
  border-radius: 22px;
  padding: 18px;
  margin-bottom: 14px;
  box-shadow: 0 8px 24px rgba(16, 185, 129, 0.25);
}

.kcal-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 14px;
}

.kcal-main-num {
  font-size: 32px;
  font-weight: 800;
  line-height: 1.05;
}

.kcal-sub {
  font-size: 13px;
  opacity: 0.9;
}

.kcal-bar-bg {
  height: 10px;
  background: rgba(255, 255, 255, 0.25);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 14px;
}

.kcal-bar-fill {
  height: 100%;
  background: #ffffff;
  border-radius: 999px;
  transition: width 0.3s ease;
}

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

.macro-box {
  background: rgba(255, 255, 255, 0.16);
  border-radius: 12px;
  padding: 8px 10px;
}

.macro-label {
  font-size: 12px;
  opacity: 0.9;
  display: flex;
  justify-content: space-between;
  margin-bottom: 4px;
}

.macro-val {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 5px;
}

.macro-mini-bar {
  height: 5px;
  background: rgba(255, 255, 255, 0.25);
  border-radius: 999px;
  overflow: hidden;
}

.macro-mini-fill {
  height: 100%;
  background: #ffffff;
  border-radius: 999px;
}

/* Inputs & Buttons */
.input-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 10px;
}

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

.input-row-4 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 10px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 10px;
}

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

input[type="text"],
input[type="number"],
input[type="password"],
input[type="time"],
input[type="date"],
select,
textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 15px;
  font-family: inherit;
  background: var(--surface-alt);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  background: #ffffff;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: 12px;
  padding: 11px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: transform 0.1s, opacity 0.15s;
}

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

.btn-primary {
  background: var(--primary);
  color: #ffffff;
}

.btn-secondary {
  background: var(--surface-alt);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-sm {
  padding: 7px 11px;
  font-size: 13px;
  border-radius: 10px;
}

.btn-block {
  width: 100%;
}

.btn-icon-del {
  border: none;
  background: transparent;
  color: #9ca3af;
  font-size: 16px;
  padding: 4px 6px;
  cursor: pointer;
}

.btn-icon-del:hover {
  color: var(--accent-rose);
}

/* Water Tracker */
.water-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.water-Wave {
  font-size: 22px;
  font-weight: 800;
  color: var(--accent-blue);
}

/* Chips & Quick Pickers */
.chips-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  padding: 8px 12px;
  border-radius: 12px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  user-select: none;
}

.chip.active {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary-dark);
  font-weight: 600;
}

/* Sliders for ratings 1-10 */
.scale-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.scale-label {
  font-size: 13px;
  font-weight: 600;
  min-width: 125px;
}

.scale-row input[type="range"] {
  flex: 1;
  accent-color: var(--primary);
}

.scale-val {
  font-size: 14px;
  font-weight: 700;
  min-width: 34px;
  text-align: right;
  color: var(--primary-dark);
}

/* Meal Lists & Saved Dishes */
.meal-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 0;
  border-bottom: 1px solid #f1f5f9;
}

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

.meal-info-title {
  font-size: 14px;
  font-weight: 600;
}

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

.dish-quick-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 300px;
  overflow-y: auto;
}

.dish-card-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  text-align: left;
  cursor: pointer;
}

.dish-card-btn:active {
  background: var(--primary-light);
  border-color: var(--primary);
}

/* Bottom Navigation Bar */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-around;
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom, 8px));
  z-index: 100;
}

.nav-item {
  flex: 1;
  max-width: 100px;
  border: none;
  background: transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 6px 4px;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  border-radius: 12px;
}

.nav-item .nav-icon {
  font-size: 20px;
  line-height: 1;
}

.nav-item.active {
  color: var(--primary-dark);
}

/* Toast Notification */
.toast {
  position: fixed;
  bottom: calc(76px + env(safe-area-inset-bottom, 12px));
  left: 50%;
  transform: translateX(-50%);
  background: #1f2937;
  color: #ffffff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 6px 20px rgba(0,0,0,0.2);
  z-index: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.toast.show {
  opacity: 1;
}

.chart-box {
  width: 100%;
  overflow: hidden;
  padding-top: 6px;
}

.stat-pills {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.stat-pill {
  background: var(--surface-alt);
  border-radius: 12px;
  padding: 10px;
  text-align: center;
  border: 1px solid var(--border);
}

.stat-pill-val {
  font-size: 18px;
  font-weight: 800;
  color: var(--text);
}

.stat-pill-lbl {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}
