:root {
  --bg: #0f1117;
  --bg-card: #1a1d27;
  --bg-input: #242736;
  --border: #2e3245;
  --text: #e8eaf0;
  --text-muted: #6b7280;
  --accent: #4f8ef7;
  --green: #34d399;
  --amber: #fbbf24;
  --coral: #f87171;
  --teal: #2dd4bf;
  --purple: #a78bfa;
  --danger: #ef4444;
  --success: #10b981;
  --radius: 12px;
  --radius-sm: 8px;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 14px;
  min-height: 100vh;
}

/* ── Auth Screen ─────────────────────────── */
#auth-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 16px;
}

.auth-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  width: 100%;
  max-width: 380px;
}

.auth-card h1 {
  font-size: 22px;
  font-weight: 700;
  text-align: center;
  margin-bottom: 8px;
}

.auth-card .subtitle {
  color: var(--text-muted);
  text-align: center;
  margin-bottom: 24px;
  font-size: 13px;
}

.auth-tabs {
  display: flex;
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  padding: 3px;
  margin-bottom: 20px;
}

.auth-tab {
  flex: 1;
  padding: 7px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  transition: all 0.15s;
}

.auth-tab.active {
  background: var(--accent);
  color: #fff;
}

/* ── Layout ──────────────────────────────── */
#app {
  display: none;
  max-width: 720px;
  margin: 0 auto;
  padding: 0 0 24px;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
}

.app-header h1 { font-size: 17px; font-weight: 700; }
.app-header .user-info { color: var(--text-muted); font-size: 12px; }

/* ── Tab Nav ─────────────────────────────── */
.tab-nav {
  position: sticky;
  top: 57px;
  display: flex;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  z-index: 10;
}

.tab-btn {
  flex: 1;
  padding: 12px 4px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 11px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  transition: color 0.15s;
}

.tab-btn.active { color: var(--accent); }
.tab-btn svg { width: 20px; height: 20px; }

/* ── Cards & Common ──────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin: 12px 16px;
}

.section-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 10px;
}

/* ── Form Elements ───────────────────────── */
.form-group { margin-bottom: 12px; }

label {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

input, select, textarea {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 14px;
  padding: 9px 12px;
  outline: none;
  transition: border-color 0.15s;
}

input:focus, select:focus { border-color: var(--accent); }

.input-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.input-row-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
}

/* ── Buttons ─────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.15s;
}

.btn:hover { opacity: 0.85; }

.btn-primary { background: var(--accent); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-danger  { background: var(--danger); color: #fff; }
.btn-ghost   { background: var(--bg-input); color: var(--text); }
.btn-sm      { padding: 5px 10px; font-size: 12px; }
.btn-block   { width: 100%; justify-content: center; }

.btn-icon {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  display: inline-flex;
  transition: color 0.15s;
}

.btn-icon:hover { color: var(--danger); }
.btn-icon svg { width: 16px; height: 16px; }

/* ── Macros ──────────────────────────────── */
.macro-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.macro-pill {
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  text-align: center;
}

.macro-pill .macro-val {
  font-size: 18px;
  font-weight: 700;
}

.macro-pill .macro-label {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 2px;
}

.macro-pill.kcal .macro-val  { color: var(--accent); }
.macro-pill.prot .macro-val  { color: var(--green); }
.macro-pill.fat  .macro-val  { color: var(--amber); }
.macro-pill.carb .macro-val  { color: var(--coral); }
.macro-pill.fib  .macro-val  { color: var(--teal); }
.macro-pill.salt .macro-val  { color: var(--purple); }

/* ── Progress Bars ───────────────────────── */
.progress-item { margin-bottom: 8px; }

.progress-header {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  margin-bottom: 4px;
}

.progress-bar-track {
  height: 6px;
  background: var(--bg-input);
  border-radius: 3px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.3s ease;
}

.progress-bar-fill.kcal { background: var(--accent); }
.progress-bar-fill.prot { background: var(--green); }
.progress-bar-fill.fat  { background: var(--amber); }
.progress-bar-fill.carb { background: var(--coral); }
.progress-bar-fill.fib  { background: var(--teal); }
.progress-bar-fill.salt { background: var(--purple); }

/* ── Diary ───────────────────────────────── */
.date-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
}

.date-nav .date-label {
  font-weight: 600;
  font-size: 15px;
}

.meal-section { margin: 0 16px 12px; }

.meal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 6px;
}

.meal-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.diary-entry {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

.diary-entry:last-child { border-bottom: none; }

.entry-name {
  flex: 1;
  font-size: 13px;
}

.entry-amount {
  font-size: 12px;
  color: var(--text-muted);
}

.entry-kcal {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  min-width: 48px;
  text-align: right;
}

/* ── Goal Buttons ────────────────────────── */
.goal-btns {
  display: flex;
  gap: 8px;
  margin: 0 16px 12px;
  flex-wrap: wrap;
}

/* ── Weight Input ────────────────────────── */
.weight-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 16px 12px;
}

.weight-row input {
  width: 100px;
}

/* ── Food Cards ──────────────────────────── */
.food-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.food-card:last-child { border-bottom: none; }

.food-card-info { flex: 1; }
.food-card-name { font-size: 13px; font-weight: 500; }
.food-card-macros { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

.food-card-actions { display: flex; gap: 4px; }

/* ── Week Table ──────────────────────────── */
.week-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.week-table th {
  text-align: left;
  color: var(--text-muted);
  font-weight: 500;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
}

.week-table td {
  padding: 8px;
  border-bottom: 1px solid var(--border);
}

.week-table tr.good td { background: rgba(52,211,153,0.08); }
.week-table tr.low  td { background: rgba(251,191,36,0.08); }
.week-table tr.high td { background: rgba(248,113,113,0.08); }

/* ── Modal ───────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-overlay.open {
  display: flex;
}

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  width: 100%;
  max-width: 480px;
  max-height: 85vh;
  overflow-y: auto;
}

.modal-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 16px;
}

.modal-footer {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}

/* ── Search results ──────────────────────── */
.search-results {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  max-height: 200px;
  overflow-y: auto;
  margin-top: 4px;
}

.search-result-item {
  padding: 10px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover { background: var(--border); }
.search-result-item .result-name { font-size: 13px; }
.search-result-item .result-kcal { font-size: 11px; color: var(--accent); }

/* ── Progress/chart ──────────────────────── */
.weight-chart {
  width: 100%;
  height: 160px;
  margin-bottom: 16px;
}

/* ── Meal / dropdown section headers ─────── */
.search-result-header {
  padding: 5px 12px;
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  cursor: default;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
}

.meal-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  border-left: 3px solid var(--purple);
  padding-left: 10px;
}

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

.meal-card-info { flex: 1; }
.meal-card-name { font-size: 13px; font-weight: 500; }
.meal-card-meta { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.meal-card-actions { display: flex; gap: 4px; }

.meal-item-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}

.meal-item-row select { flex: 1; }
.meal-item-row input  { width: 80px; }

.ingredient-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  gap: 8px;
}

.ingredient-row:last-child { border-bottom: none; }
.ingredient-row .ing-name  { flex: 1; font-size: 13px; }
.ingredient-row .ing-input { width: 80px; }
.ingredient-row .ing-unit  { font-size: 12px; color: var(--text-muted); min-width: 24px; }

/* ── Lang selector ───────────────────────── */
.lang-selector { display: flex; gap: 2px; }

.lang-btn {
  background: transparent;
  border: none;
  font-size: 18px;
  cursor: pointer;
  padding: 3px 5px;
  border-radius: 4px;
  opacity: 0.45;
  transition: opacity 0.15s;
  line-height: 1;
}

.lang-btn:hover, .lang-btn.active { opacity: 1; }

/* ── Misc ────────────────────────────────── */
.error-msg {
  color: var(--danger);
  font-size: 12px;
  margin-top: 6px;
}

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

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
}

.badge-breakfast  { background: rgba(79,142,247,0.15); color: var(--accent); }
.badge-lunch      { background: rgba(52,211,153,0.15); color: var(--green); }
.badge-dinner     { background: rgba(167,139,250,0.15); color: var(--purple); }
.badge-snack      { background: rgba(251,191,36,0.15); color: var(--amber); }
.badge-pre_workout  { background: rgba(45,212,191,0.15); color: var(--teal); }
.badge-post_workout { background: rgba(248,113,113,0.15); color: var(--coral); }

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

.inline-edit-form {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  margin-top: 8px;
}

/* ── Goal Presets Tab ────────────────────── */
.preset-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.preset-card:last-child { border-bottom: none; }
.preset-card-color { font-size: 20px; line-height: 1; flex-shrink: 0; }
.preset-card-info  { flex: 1; }
.preset-card-name  { font-size: 13px; font-weight: 500; }
.preset-card-macros { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.preset-card-actions { display: flex; gap: 4px; }

/* ── Color Picker ────────────────────────── */
.color-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 6px;
}
.color-option {
  font-size: 22px;
  cursor: pointer;
  border-radius: 6px;
  padding: 2px 4px;
  border: 2px solid transparent;
  transition: border-color 0.15s;
  line-height: 1;
  user-select: none;
}
.color-option.selected {
  border-color: var(--accent);
  background: rgba(79,142,247,0.12);
}

/* ── Day Actions ─────────────────────────── */
.day-actions {
  display: flex;
  gap: 8px;
  margin: 0 16px 12px;
  flex-wrap: wrap;
}
