:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #334155;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --accent: #10b981;
  --accent-2: #059669;
  --burn: #f97316;
  --danger: #ef4444;
  --radius: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overscroll-behavior-y: none;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.tiny { font-size: 12px; }
.error { color: var(--danger); font-size: 14px; margin-top: 8px; min-height: 18px; }

input, button { font: inherit; }
input {
  background: var(--surface-2);
  border: 1px solid transparent;
  color: var(--text);
  border-radius: 12px;
  padding: 14px;
  width: 100%;
  outline: none;
}
input:focus { border-color: var(--accent); }
button {
  cursor: pointer;
  border: none;
  border-radius: 12px;
  padding: 14px 18px;
  background: var(--accent);
  color: #04231a;
  font-weight: 700;
}
button.secondary { background: var(--surface-2); color: var(--text); }

/* Login */
.login {
  min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 24px;
}
.login-card { width: 100%; max-width: 360px; text-align: center; }
.login-card .logo {
  width: 72px; height: 72px; margin: 0 auto 12px; border-radius: 20px;
  background: linear-gradient(160deg, var(--accent), var(--accent-2));
  display: flex; align-items: center; justify-content: center; font-size: 34px; color: #fff;
}
.login-card h1 { font-size: 22px; margin: 8px 0 2px; }
.login-form, #login-form { display: flex; flex-direction: column; gap: 12px; margin-top: 16px; }

/* App shell */
#app { padding-top: var(--safe-top); padding-bottom: calc(72px + var(--safe-bottom)); max-width: 560px; margin: 0 auto; min-height: 100dvh; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px; position: sticky; top: 0; background: var(--bg); z-index: 5;
}
.date-label { font-size: 18px; font-weight: 700; }
.nav-btn { background: var(--surface); color: var(--text); width: 40px; height: 40px; padding: 0; font-size: 22px; line-height: 1; }

/* Rings / summary */
.rings { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding: 0 16px; }
.ring-card { background: var(--surface); border-radius: var(--radius); padding: 18px 16px; text-align: center; }
.ring-value { font-size: 30px; font-weight: 800; letter-spacing: -0.5px; }
.ring-value .unit { font-size: 16px; font-weight: 600; color: var(--muted); }
.ring-label { color: var(--muted); font-size: 13px; margin-top: 2px; text-transform: uppercase; letter-spacing: 0.5px; }
.bar { height: 8px; background: var(--surface-2); border-radius: 99px; margin: 12px 0 6px; overflow: hidden; }
.bar-fill { height: 100%; width: 0%; background: var(--accent); border-radius: 99px; transition: width .3s ease; }
.bar-fill.protein { background: #38bdf8; }
.bar-fill.over { background: var(--danger); }
.sub { font-size: 12px; color: var(--muted); }

/* Add buttons */
.add-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding: 16px; }
.add { padding: 16px; font-size: 16px; }
.add.food { background: var(--accent); color: #04231a; }
.add.burn { background: var(--burn); color: #2a1204; }

/* Entries */
.section-divider { border: none; border-top: 1px solid var(--surface-2); margin: 4px 16px 14px; }
.entries { padding: 0 16px; display: flex; flex-direction: column; gap: 8px; }
.entry { background: var(--surface); border-radius: 12px; overflow: hidden; }
.entry-row {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; cursor: pointer;
}
.entry .dot { width: 10px; height: 10px; border-radius: 99px; background: var(--accent); flex: none; }
.entry.burn .dot { background: var(--burn); }
.entry .info { flex: 1; min-width: 0; }
.entry .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.entry .meta { font-size: 13px; color: var(--muted); }
.entry .note-badge { font-size: 13px; flex: none; opacity: .8; }
.entry .chevron { color: var(--muted); font-size: 20px; flex: none; transition: transform .2s ease; }
.entry.open .chevron { transform: rotate(90deg); }
.entry .del { background: transparent; color: var(--muted); padding: 6px 10px; font-size: 18px; flex: none; }
.entry-details { padding: 0 14px 12px 36px; display: flex; flex-direction: column; gap: 6px; }
.ed-row { display: flex; justify-content: space-between; font-size: 14px; color: var(--text); }
.ed-row span:first-child { color: var(--muted); }
.ed-note {
  margin-top: 4px; padding-top: 8px; border-top: 1px solid var(--surface-2);
  font-size: 14px; white-space: pre-wrap; word-break: break-word;
}
.empty { text-align: center; color: var(--muted); padding: 40px 16px; }

/* History */
.history-list { padding: 0 16px 16px; display: flex; flex-direction: column; gap: 8px; }
.hist-row { background: var(--surface); border-radius: 12px; padding: 14px; }
.hist-top { display: flex; justify-content: space-between; align-items: baseline; }
.hist-date { font-weight: 700; }
.hist-net { font-weight: 700; }
.hist-meta { color: var(--muted); font-size: 13px; margin-top: 4px; }

/* Settings */
.settings { padding: 16px; display: flex; flex-direction: column; gap: 14px; max-width: 420px; }
.settings label { display: flex; flex-direction: column; gap: 6px; color: var(--muted); font-size: 14px; }
.settings hr { border: none; border-top: 1px solid var(--surface-2); margin: 8px 0; width: 100%; }
.section-title { font-weight: 700; font-size: 15px; color: var(--text); }

/* Bottom nav */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  display: flex; background: var(--surface); border-top: 1px solid var(--surface-2);
  padding-bottom: var(--safe-bottom); max-width: 560px; margin: 0 auto;
}
.nav-item {
  flex: 1; background: transparent; color: var(--muted); border-radius: 0;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  font-size: 11px; font-weight: 600; padding: 10px 0;
}
.nav-item span { font-size: 20px; }
.nav-item.active { color: var(--accent); }

/* Sheet */
.sheet { position: fixed; inset: 0; z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.5); }
.sheet-card {
  position: relative; width: 100%; max-width: 560px; background: var(--surface);
  border-radius: 22px 22px 0 0; padding: 10px 18px calc(24px + var(--safe-bottom));
  animation: slideup .22s ease;
}
@keyframes slideup { from { transform: translateY(100%); } to { transform: translateY(0); } }
.sheet-handle { width: 40px; height: 4px; background: var(--surface-2); border-radius: 99px; margin: 6px auto 12px; }
.sheet-card h2 { margin: 4px 0 14px; font-size: 18px; }
#entry-form { display: flex; flex-direction: column; gap: 12px; }
#entry-form .row { display: flex; gap: 12px; }
#entry-form .row label { flex: 1; display: flex; flex-direction: column; gap: 6px; color: var(--muted); font-size: 13px; }
#servings-field { display: flex; flex-direction: column; gap: 6px; color: var(--muted); font-size: 13px; }
.sheet-actions { display: flex; gap: 12px; margin-top: 4px; }
.sheet-actions button { flex: 1; }

/* Saved-food dropdown in the add sheet */
.food-select {
  background: var(--surface-2); color: var(--text); border: 1px solid transparent;
  border-radius: 12px; padding: 14px; width: 100%; font: inherit; cursor: pointer;
  appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%2394a3b8' d='M6 8 0 0h12z'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 16px center;
  padding-right: 40px;
}
.food-select:focus { border-color: var(--accent); outline: none; }
.note-field { display: flex; flex-direction: column; gap: 6px; color: var(--muted); font-size: 13px; }
.note-field textarea {
  background: var(--surface-2); border: 1px solid transparent; color: var(--text);
  border-radius: 12px; padding: 12px; width: 100%; font: inherit; resize: vertical; min-height: 44px;
}
.note-field textarea:focus { border-color: var(--accent); outline: none; }
.save-food-toggle {
  display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 14px;
}
.save-food-toggle input { width: auto; }

/* My foods management list in settings */
.foods-list { display: flex; flex-direction: column; gap: 8px; }
.food-item {
  display: flex; align-items: center; gap: 12px; background: var(--surface);
  border-radius: 12px; padding: 10px 14px;
}
.food-item .fi-info { flex: 1; min-width: 0; }
.food-item .fi-name { font-weight: 600; }
.food-item .fi-meta { font-size: 13px; color: var(--muted); }
.food-item .del { background: transparent; color: var(--muted); padding: 6px 10px; font-size: 18px; }
.food-add-row { display: flex; flex-direction: column; gap: 10px; }
.food-add-row .row { display: flex; gap: 10px; }
