:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --ink: #17242b;
  --muted: #6b7c85;
  --line: #e3e9ec;
  --teal: #0f766e;
  --teal-dark: #0b5850;
  --green: #16a34a;
  --amber: #d97706;
  --red: #dc2626;
  --shadow: 0 2px 10px rgba(20, 40, 50, .06);
  --radius: 16px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--ink);
  font-size: 16px; line-height: 1.4;
  padding-bottom: env(safe-area-inset-bottom);
}
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 14px; }
.err { color: var(--red); font-size: 14px; }
.ok { color: var(--green); font-size: 14px; }

/* ---- AUTH ---- */
.auth { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.auth-card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 28px 22px; width: 100%; max-width: 380px;
}
.brand { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; }
.brand .logo { font-size: 34px; }
.brand h1 { font-size: 22px; margin: 0; }

label { display: block; font-size: 14px; color: var(--muted); margin-bottom: 12px; }
input {
  width: 100%; margin-top: 5px; padding: 12px 14px; font-size: 16px;
  border: 1px solid var(--line); border-radius: 11px; background: #fff; color: var(--ink);
}
input:focus { outline: none; border-color: var(--teal); box-shadow: 0 0 0 3px rgba(15,118,110,.12); }
.row { display: flex; gap: 12px; }
.row label { flex: 1; }

button { font-family: inherit; cursor: pointer; border: none; }
.primary {
  width: 100%; padding: 14px; font-size: 16px; font-weight: 600;
  background: var(--teal); color: #fff; border-radius: 12px; margin-top: 6px;
}
.primary:active { background: var(--teal-dark); }
.ghost { background: transparent; color: var(--muted); font-size: 20px; padding: 6px 10px; border-radius: 10px; }
.ghost.danger { color: var(--red); font-size: 15px; width: 100%; padding: 12px; margin-top: 16px; border: 1px solid var(--line); background:#fff;}

/* ---- APP LAYOUT ---- */
#app { max-width: 560px; margin: 0 auto; min-height: 100vh; }
.tab { padding: 16px 16px 96px; }
h2 { font-size: 20px; margin: 6px 2px 16px; }

/* daybar */
.daybar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.day-label { font-size: 17px; font-weight: 600; text-transform: capitalize; }
.daybar .ghost { font-size: 26px; line-height: 1; color: var(--teal); }

/* gauge */
.gauge-card, .weight-card, .card, .chart-card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px; margin-bottom: 14px;
}
.gauge-top { display: flex; align-items: baseline; gap: 6px; font-size: 15px; color: var(--muted); }
#kcal-eaten { font-size: 34px; font-weight: 700; color: var(--ink); }
.gauge-top .sep { font-size: 22px; }
.gauge-top .unit { margin-left: 2px; }
.bar { height: 12px; background: #eef1f3; border-radius: 8px; overflow: hidden; margin: 12px 0 8px; }
.bar-fill { height: 100%; width: 0%; background: var(--green); border-radius: 8px; transition: width .35s ease, background .3s; }
.bar-fill.warn { background: var(--amber); }
.bar-fill.over { background: var(--red); }
.remaining { font-size: 15px; font-weight: 600; }
.remaining.over { color: var(--red); }
.macros { display: flex; gap: 14px; margin-top: 10px; font-size: 13px; color: var(--muted); }
.macros b { color: var(--ink); }

/* weight */
.weight-label { margin: 0; }
.weight-input { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.weight-input input { flex: 1; }
.weight-input span { color: var(--muted); }

/* entries */
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 18px 4px 8px; }
.entries { list-style: none; padding: 0; margin: 0; }
.entry {
  background: var(--card); border-radius: 12px; box-shadow: var(--shadow);
  padding: 12px 14px; margin-bottom: 8px; display: flex; align-items: center; justify-content: space-between;
}
.entry .e-name { font-weight: 500; }
.entry .e-sub { font-size: 12px; color: var(--muted); }
.entry .e-right { display: flex; align-items: center; gap: 12px; }
.entry .e-kcal { font-weight: 700; }
.entry .e-del { color: var(--muted); font-size: 18px; background: none; padding: 2px 6px; }
.empty { color: var(--muted); font-size: 14px; text-align: center; padding: 20px; }

/* fab */
.fab {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 82px;
  background: var(--teal); color: #fff; font-size: 16px; font-weight: 600;
  padding: 14px 26px; border-radius: 30px; box-shadow: 0 6px 18px rgba(15,118,110,.35); z-index: 20;
}
.fab:active { background: var(--teal-dark); }

/* tabbar */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; max-width: 560px; margin: 0 auto;
  background: #fff; border-top: 1px solid var(--line); display: flex;
  padding-bottom: env(safe-area-inset-bottom); z-index: 30;
}
.navbtn {
  flex: 1; background: none; padding: 10px 0 8px; font-size: 22px;
  display: flex; flex-direction: column; align-items: center; gap: 2px; color: var(--muted);
}
.navbtn span { font-size: 11px; }
.navbtn.active { color: var(--teal); }

/* charts */
.chart-title { font-size: 14px; font-weight: 600; margin-bottom: 8px; }
.range-tabs { display: flex; gap: 8px; margin-bottom: 14px; }
.range { flex: 1; padding: 9px; background: #fff; border: 1px solid var(--line); border-radius: 10px; color: var(--muted); font-size: 14px; }
.range.active { background: var(--teal); color: #fff; border-color: var(--teal); }

/* modal */
.modal {
  position: fixed; inset: 0; background: rgba(15,30,35,.45); z-index: 50;
  display: flex; align-items: flex-end; justify-content: center;
}
.modal-card {
  background: #fff; width: 100%; max-width: 560px; border-radius: 20px 20px 0 0;
  padding: 18px 16px calc(24px + env(safe-area-inset-bottom)); max-height: 92vh; overflow-y: auto;
  animation: slideup .22s ease;
}
.modal-card.small { border-radius: 20px; margin: auto; max-width: 380px; }
@keyframes slideup { from { transform: translateY(30px); opacity: .6; } to { transform: none; opacity: 1; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.modal-head h3 { margin: 0; font-size: 18px; }

.search-row { display: flex; gap: 8px; align-items: center; }
.search-row input { flex: 1; margin: 0; }
.search-row .ghost { font-size: 22px; border: 1px solid var(--line); border-radius: 11px; }
.scanner { margin-top: 12px; border-radius: 12px; overflow: hidden; }
.results { list-style: none; padding: 0; margin: 12px 0 0; }
.result {
  padding: 12px; border: 1px solid var(--line); border-radius: 11px; margin-bottom: 8px;
  display: flex; justify-content: space-between; align-items: center; gap: 10px; cursor: pointer;
}
.result:active { background: #f4f8f7; }
.result .r-name { font-size: 14px; font-weight: 500; }
.result .r-kcal { font-size: 13px; color: var(--teal); font-weight: 600; white-space: nowrap; }
.hint { font-size: 13px; color: var(--muted); margin: 12px 2px; }
.manual { border-top: 1px solid var(--line); margin-top: 14px; padding-top: 14px; }
.manual-title { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-bottom: 10px; }
.qty-preview { font-size: 15px; font-weight: 600; margin: 6px 0 14px; color: var(--teal); }
.loading { text-align: center; color: var(--muted); font-size: 14px; padding: 14px; }

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #10171b; --card: #182228; --ink: #e7edf0; --muted: #8ea1aa;
    --line: #26333a; --shadow: 0 2px 10px rgba(0,0,0,.3);
  }
  input, .range, .ghost.danger { background: #0f1619; }
  .navbtn, .tabbar { background: #182228; }
  .bar { background: #26333a; }
}
