:root {
  --navy: #14324f;
  --green: #1f9d6b;
  --green-dark: #167a52;
  --amber: #e0901b;
  --red: #d24b4b;
  --bg: #f3f6f9;
  --card: #ffffff;
  --text: #1b2733;
  --muted: #6b7c8e;
  --border: #e2e8f0;
  --radius: 14px;
  --shadow: 0 2px 10px rgba(20, 50, 79, 0.06);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}
img { max-width: 100%; display: block; }
button { font-family: inherit; cursor: pointer; }
a { color: var(--green); }

/* ---------- Layout ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 12px 16px;
  background: var(--navy); color: #fff;
}
.topbar .brand { font-weight: 700; font-size: 1.05rem; display: flex; align-items: center; gap: 8px; }
.topbar .brand small { font-weight: 400; opacity: .7; font-size: .72rem; }
.topbar .spacer { flex: 1; }
.topbar .who { font-size: .8rem; opacity: .85; }

.container { max-width: 760px; margin: 0 auto; padding: 16px; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 16px;
}
.card h2 { margin: 0 0 12px; font-size: 1.1rem; }
.muted { color: var(--muted); font-size: .85rem; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: none; border-radius: 10px; padding: 12px 16px;
  font-size: 1rem; font-weight: 600; color: #fff;
  background: linear-gradient(135deg, var(--green), var(--green-dark));
  width: 100%; min-height: 48px;
}
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.secondary { background: #eef2f6; color: var(--navy); border: 1px solid var(--border); }
.btn.ghost { background: transparent; color: #fff; border: 1px solid rgba(255,255,255,.4); width: auto; min-height: 38px; padding: 8px 14px; font-size: .85rem; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-row .btn { flex: 1; }

/* ---------- Forms ---------- */
label { display: block; font-weight: 600; font-size: .85rem; margin: 12px 0 6px; }
input[type=text], input[type=email], input[type=password], select {
  width: 100%; padding: 12px; font-size: 1rem;
  border: 1px solid var(--border); border-radius: 10px; background: #fff; color: var(--text);
}
input:focus, select:focus { outline: 2px solid rgba(31,157,107,.35); border-color: var(--green); }

/* ---------- Login ---------- */
.auth-wrap { min-height: 100vh; min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.auth-card { width: 100%; max-width: 380px; }
.auth-card .logo { text-align: center; margin-bottom: 6px; font-size: 2rem; }
.auth-card h1 { text-align: center; margin: 0 0 4px; font-size: 1.4rem; }
.auth-card .sub { text-align: center; color: var(--muted); margin: 0 0 18px; font-size: .9rem; }

/* ---------- Upload / preview ---------- */
.dropzone {
  border: 2px dashed var(--border); border-radius: var(--radius);
  padding: 24px 16px; text-align: center; color: var(--muted); background: #fafcfe;
}
.preview { margin-top: 14px; }
.preview img { border-radius: 12px; width: 100%; max-height: 340px; object-fit: cover; }

/* ---------- Rating badge ---------- */
.rating { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; padding: 8px 14px; border-radius: 999px; color: #fff; font-size: 1rem; }
.rating.Good { background: var(--green); }
.rating.Moderate { background: var(--amber); }
.rating.Avoid { background: var(--red); }

/* ---------- Nutrition grid ---------- */
.nutri-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-top: 12px; }
.nutri { background: #f7fafc; border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; }
.nutri .v { font-size: 1.25rem; font-weight: 700; color: var(--navy); }
.nutri .k { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip { background: #eef4f1; color: var(--green-dark); border-radius: 999px; padding: 4px 10px; font-size: .78rem; }

ul.tips { margin: 8px 0 0; padding-left: 18px; }
ul.tips li { margin-bottom: 4px; }

/* ---------- History ---------- */
.hist-item { display: flex; gap: 12px; align-items: center; padding: 10px 0; border-top: 1px solid var(--border); }
.hist-item:first-child { border-top: none; }
.hist-item img { width: 64px; height: 64px; border-radius: 10px; object-fit: cover; flex: 0 0 auto; }
.hist-item .meta { flex: 1; min-width: 0; }
.hist-item .meta .nm { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hist-item .meta .dt { font-size: .75rem; color: var(--muted); }
.pill { font-size: .72rem; font-weight: 700; padding: 3px 9px; border-radius: 999px; color: #fff; }
.pill.Good { background: var(--green); }
.pill.Moderate { background: var(--amber); }
.pill.Avoid { background: var(--red); }

/* ---------- Misc ---------- */
.error { background: #fdecec; color: var(--red); border: 1px solid #f6c9c9; padding: 10px 12px; border-radius: 10px; font-size: .88rem; margin-top: 10px; }
.notice { background: #fff7e6; color: #8a5a00; border: 1px solid #ffe2a8; padding: 10px 12px; border-radius: 10px; font-size: .85rem; margin-bottom: 14px; }
.spinner { width: 20px; height: 20px; border: 3px solid rgba(255,255,255,.4); border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.hidden { display: none !important; }

.tabs { display: flex; gap: 6px; margin-bottom: 14px; }
.tab { flex: 1; padding: 10px; text-align: center; border-radius: 10px; background: #eef2f6; color: var(--navy); font-weight: 600; border: 1px solid var(--border); }
.tab.active { background: var(--navy); color: #fff; border-color: var(--navy); }

.disclaimer { font-size: .72rem; color: var(--muted); text-align: center; margin: 8px 0 24px; }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(20, 50, 79, 0.5);
  display: flex; align-items: flex-end; justify-content: center;
  padding: 0;
}
.modal-card {
  background: var(--card); width: 100%; max-width: 420px;
  border-radius: 16px 16px 0 0;
  padding: 18px 18px calc(18px + env(safe-area-inset-bottom));
  box-shadow: 0 -4px 24px rgba(20, 50, 79, 0.2);
  max-height: 90vh; max-height: 90dvh; overflow-y: auto;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.modal-head h2 { margin: 0; font-size: 1.1rem; }
.modal-close { background: none; border: none; font-size: 1.6rem; line-height: 1; color: var(--muted); padding: 0 4px; }
@media (min-width: 600px) {
  .modal-overlay { align-items: center; padding: 20px; }
  .modal-card { border-radius: 16px; }
}

/* ---------- Glucose panel ---------- */
.glucose { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--border); }
.glucose h3 { margin: 0 0 10px; font-size: 1rem; }
.src-toggle { display: flex; gap: 8px; margin-bottom: 12px; }
.src-toggle .src { flex: 1; padding: 9px; border-radius: 10px; border: 1px solid var(--border); background: #eef2f6; color: var(--navy); font-weight: 600; font-size: .85rem; }
.src-toggle .src.active { background: var(--navy); color: #fff; border-color: var(--navy); }
.src-toggle .src.disabled { opacity: .55; cursor: not-allowed; }
.g-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.g-row label { margin-top: 0; }
.g-row input { text-align: center; }

@media (min-width: 600px) {
  .nutri-grid { grid-template-columns: repeat(3, 1fr); }
}
