:root {
  --primary: #10b981;
  --primary-dark: #059669;
  --primary-light: #d1fae5;
  --bg: #f8fafc;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --danger: #ef4444;
  --warning: #f59e0b;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  font-size: 15px;
}

a { color: var(--primary-dark); text-decoration: none; }
img { max-width: 100%; }

/* ---- Nav ---- */
.app-nav {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}
.nav-inner {
  max-width: 900px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.brand { font-weight: 800; font-size: 18px; color: var(--primary-dark); }
.nav-toggle { display: none; background: none; border: 0; font-size: 22px; cursor: pointer; }
.nav-links { display: flex; gap: 4px; align-items: center; list-style: none; }
.nav-links li a {
  display: block; padding: 8px 12px; border-radius: 8px; color: var(--text);
  font-weight: 500; font-size: 14px;
}
.nav-links li a:hover { background: var(--primary-light); color: var(--primary-dark); }
.btn-link { background: none; border: 0; color: var(--danger); font-weight: 500; cursor: pointer; padding: 8px 12px; font-size: 14px; }

@media (max-width: 640px) {
  .nav-toggle { display: block; }
  .nav-links {
    display: none; position: absolute; top: 100%; left: 0; right: 0;
    background: var(--card); flex-direction: column; padding: 8px 16px;
    border-bottom: 1px solid var(--border);
  }
  .nav-links.open { display: flex; }
}

/* ---- Layout ---- */
.container { max-width: 900px; margin: 0 auto; padding: 20px 16px 60px; }
.page-head { margin-bottom: 20px; }
.page-head h1 { font-size: 22px; }
.page-head p { color: var(--muted); font-size: 14px; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.card h2 { font-size: 16px; margin-bottom: 12px; }
.card-title { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.card-title h2 { margin: 0; }

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }

@media (max-width: 640px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr 1fr; }
}

/* ---- Stat cards ---- */
.stat {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; text-align: center; box-shadow: var(--shadow);
}
.stat .value { font-size: 26px; font-weight: 800; color: var(--primary-dark); }
.stat .label { font-size: 12px; color: var(--muted); margin-top: 2px; }
.stat .value.warn { color: var(--warning); }
.stat .value.bad { color: var(--danger); }

/* ---- Progress bars ---- */
.bar-track { background: #f1f5f9; border-radius: 999px; height: 10px; overflow: hidden; }
.bar-fill { background: var(--primary); height: 100%; border-radius: 999px; transition: width .3s; }
.bar-row { margin-bottom: 12px; }
.bar-row .bar-head { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 4px; }

/* ---- Forms ---- */
label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 4px; color: #334155; }
input, select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 14px; background: #fff; color: var(--text); margin-bottom: 14px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-light); border-color: var(--primary); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
@media (max-width: 640px) { .form-grid { grid-template-columns: 1fr; } }

.btn {
  display: inline-block; background: var(--primary); color: #fff; border: 0;
  padding: 11px 18px; border-radius: 8px; font-size: 15px; font-weight: 600; cursor: pointer;
}
.btn:hover { background: var(--primary-dark); }
.btn-block { width: 100%; }
.btn-outline { background: #fff; color: var(--primary-dark); border: 1.5px solid var(--primary); }
.btn-danger { background: var(--danger); }
.btn-sm { padding: 7px 12px; font-size: 13px; }
.btn:disabled { opacity: .6; cursor: not-allowed; }

/* ---- Meals ---- */
.meal-card { border-left: 4px solid var(--primary); }
.meal-card .meal-name { font-weight: 700; }
.meal-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 0; border-bottom: 1px solid #f1f5f9; font-size: 14px;
}
.meal-item:last-child { border-bottom: 0; }
.meal-item .m-name { font-weight: 500; }
.meal-item .m-macro { color: var(--muted); font-size: 12px; }

/* ---- Chat ---- */
.chat-box { display: flex; flex-direction: column; height: calc(100vh - 180px); min-height: 420px; }
.chat-history { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.bubble { max-width: 80%; padding: 11px 14px; border-radius: 14px; font-size: 14px; white-space: pre-wrap; }
.bubble.user { align-self: flex-end; background: var(--primary); color: #fff; border-bottom-right-radius: 4px; }
.bubble.ai { align-self: flex-start; background: #f1f5f9; border-bottom-left-radius: 4px; }
.chat-input { display: flex; gap: 8px; padding-top: 10px; }
.chat-input input { margin: 0; flex: 1; }
.chat-input button { flex-shrink: 0; }

/* ---- Auth pages ---- */
.auth-wrap { max-width: 420px; margin: 40px auto; }
.auth-logo { text-align: center; font-size: 24px; font-weight: 800; color: var(--primary-dark); margin-bottom: 20px; }
.alert {
  padding: 10px 14px; border-radius: 8px; font-size: 13px; margin-bottom: 14px;
}
.alert-error { background: #fee2e2; color: #991b1b; }
.alert-success { background: #dcfce7; color: #166534; }

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

/* ---- Tables ---- */
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; color: var(--muted); font-size: 12px; text-transform: uppercase; padding: 8px; border-bottom: 2px solid var(--border); }
.table td { padding: 8px; border-bottom: 1px solid #f1f5f9; }

.spinner { display: inline-block; width: 16px; height: 16px; border: 2px solid var(--primary-light); border-top-color: var(--primary); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge-success { background: #dcfce7; color: #166534; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-danger { background: #fee2e2; color: #991b1b; }
