:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --border: #e5e7eb;
  --accent: #2563eb;
  --accent-soft: #dbeafe;
  --good: #16a34a;
  --warn: #d97706;
  --bad: #dc2626;
  --radius: 14px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

body { padding-bottom: calc(84px + var(--safe-bottom)); }

a { color: var(--accent); text-decoration: none; }

/* ---------- layout ---------- */
.wrap { max-width: 720px; margin: 0 auto; padding: 12px 14px 24px; }

header.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px;
  background: rgba(244, 245, 247, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
header.topbar h1 { font-size: 17px; margin: 0; flex: 1; font-weight: 650; }
header.topbar .sub { font-size: 12px; color: var(--muted); font-weight: 400; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}

.card h2 {
  font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--muted); margin: 0 0 10px; font-weight: 600;
}

/* ---------- hero numbers ---------- */
.hero { display: flex; align-items: flex-end; gap: 8px; margin-bottom: 4px; }
.hero .big { font-size: 40px; font-weight: 700; line-height: 1; letter-spacing: -0.02em; }
.hero .unit { font-size: 14px; color: var(--muted); padding-bottom: 5px; }
.hero-sub { font-size: 13px; color: var(--muted); margin-bottom: 12px; }

.over { color: var(--bad); }
.under { color: var(--good); }

/* ---------- bars ---------- */
.macro { margin-top: 10px; }
.macro-head {
  display: flex; justify-content: space-between;
  font-size: 13px; margin-bottom: 4px;
}
.macro-head .label { font-weight: 600; }
.macro-head .value { color: var(--muted); font-variant-numeric: tabular-nums; }
.bar { height: 7px; background: #eceff3; border-radius: 999px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.bar > span.good { background: var(--good); }
.bar > span.warn { background: var(--warn); }
.bar > span.bad  { background: var(--bad); }

/* ---------- meal sections ---------- */
.meal-head {
  display: flex; align-items: baseline; justify-content: space-between;
  margin-bottom: 6px;
}
.meal-head .name { font-weight: 600; font-size: 15px; }
.meal-head .kcal { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }

.entry {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 8px 0; border-top: 1px solid var(--border);
}
.entry:first-of-type { border-top: none; }
.entry .body { flex: 1; min-width: 0; }
.entry .title { font-size: 14px; overflow-wrap: anywhere; }
.entry .meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.entry .kcal { font-size: 14px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.icon-btn {
  border: none; background: none; color: var(--muted);
  font-size: 18px; line-height: 1; padding: 2px 4px; cursor: pointer;
}

.empty { color: var(--muted); font-size: 13px; padding: 6px 0; }

/* ---------- forms ---------- */
label { display: block; font-size: 12px; color: var(--muted); margin: 10px 0 4px; }
.input, input[type="text"], input[type="number"], input[type="search"],
input[type="password"], input[type="email"], select, textarea {
  width: 100%; padding: 11px 12px; font-size: 16px; /* 16px stops iOS zoom */
  border: 1px solid var(--border); border-radius: 10px; background: #fff;
  color: var(--text); font-family: inherit;
}
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 11px 16px; border-radius: 10px; border: 1px solid var(--border);
  background: #fff; color: var(--text); font-size: 15px; font-weight: 550;
  cursor: pointer; font-family: inherit;
}
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--accent); }
.btn-block { width: 100%; }
.btn-sm { padding: 7px 12px; font-size: 14px; }

/* ---------- bottom action bar ---------- */
.actionbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; gap: 8px;
  padding: 10px 14px calc(10px + var(--safe-bottom));
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--border);
}
.actionbar .btn {
  flex: 1;
  /* Four actions have to fit a narrow phone without the labels wrapping. */
  padding: 11px 8px;
  font-size: 14px;
}

/* ---------- search results ---------- */
.result { border-top: 1px solid var(--border); padding: 12px 0; }
.result:first-of-type { border-top: none; }
.result .name { font-size: 15px; font-weight: 550; overflow-wrap: anywhere; }
.result .brand { font-size: 13px; color: var(--muted); }
.result .numbers { font-size: 12px; color: var(--muted); margin-top: 3px; font-variant-numeric: tabular-nums; }
.result form { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.result form input[type="number"] { width: 96px; flex: none; }

.pill {
  display: inline-block; font-size: 11px; padding: 2px 7px; border-radius: 999px;
  background: var(--accent-soft); color: #1d4ed8; font-weight: 600;
}
.pill.partial { background: #fef3c7; color: #92400e; }

.notice { font-size: 13px; padding: 10px 12px; border-radius: 10px; margin-bottom: 10px; }
.notice.error { background: #fee2e2; color: #991b1b; }
.notice.ok { background: #dcfce7; color: #166534; }

.login-wrap { max-width: 380px; margin: 12vh auto 0; padding: 0 18px; }

/* ---------- misc ---------- */
.muted { color: var(--muted); }
.small { font-size: 12px; }
.row-between { display: flex; justify-content: space-between; align-items: center; }
.stack > * + * { margin-top: 10px; }
h1.page { font-size: 22px; margin: 4px 0 12px; }
