:root {
  color-scheme: dark;
  --bg: #0f1117;
  --panel: #171a23;
  --panel-2: #202432;
  --text: #f3f5f8;
  --muted: #9aa3b2;
  --border: #2e3445;
  --accent: #69e59f;
  --danger: #ff7676;
  --shadow: 0 20px 50px rgba(0,0,0,.24);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: radial-gradient(circle at top left, #1c2931 0, var(--bg) 36rem);
  color: var(--text);
  padding: 0 0 6rem;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem;
  background: rgba(15,17,23,.86);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}

h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: 1.6rem; }
h2 { font-size: 1.05rem; margin-bottom: 1rem; }
.eyebrow { color: var(--accent); font-size: .75rem; letter-spacing: .08em; text-transform: uppercase; margin-bottom: .2rem; }
main { width: min(980px, 100%); margin: 0 auto; padding: 1rem; }
.page { display: none; }
.page.active { display: block; }

.card, .metric, .quote-card {
  background: linear-gradient(180deg, rgba(255,255,255,.04), rgba(255,255,255,.02));
  border: 1px solid var(--border);
  border-radius: 1.25rem;
  padding: 1rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}
.quote-card { border-color: rgba(105,229,159,.35); }
.quote-card p { margin: 0; font-size: 1.05rem; line-height: 1.5; }
.grid { display: grid; gap: .8rem; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.metric span { color: var(--muted); font-size: .85rem; }
.metric strong { display: block; font-size: 1.8rem; margin: .25rem 0; }
.metric small, .muted { color: var(--muted); }
.quick-actions, .row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.quick-actions { margin-bottom: 1rem; }

button, .button-like {
  appearance: none;
  border: 0;
  color: #08140d;
  background: var(--accent);
  border-radius: .85rem;
  padding: .75rem .9rem;
  font-weight: 750;
  cursor: pointer;
  text-align: center;
}
button.ghost, .button-like.ghost {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
}
button.danger { background: var(--danger); color: #230808; }
button:disabled { opacity: .55; cursor: not-allowed; }

input, select, textarea {
  width: 100%;
  min-height: 2.85rem;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: .85rem;
  padding: .75rem .85rem;
  font: inherit;
}
textarea { min-height: 6rem; resize: vertical; margin: .7rem 0; }
.row input { flex: 1 1 12rem; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .65rem; margin-bottom: .8rem; }
.workout-grid { grid-template-columns: 1.4fr .7fr .9fr .9fr .9fr auto; }

.list { display: grid; gap: .65rem; }
.list.empty { color: var(--muted); }
.item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: .75rem;
  align-items: center;
  background: rgba(255,255,255,.035);
  border: 1px solid var(--border);
  border-radius: 1rem;
  padding: .8rem;
}
.item p { margin: .2rem 0; color: var(--muted); }
.item small { color: var(--muted); }
.food-item { grid-template-columns: 3rem 1fr auto; }
.food-img { width: 3rem; height: 3rem; border-radius: .7rem; object-fit: cover; background: var(--panel-2); }
.hidden { display: none !important; }
#barcodeVideo { width: 100%; max-height: 22rem; border-radius: 1rem; margin: .75rem 0; background: #000; }

.bottom-nav {
  position: fixed;
  left: 50%;
  bottom: .8rem;
  transform: translateX(-50%);
  width: min(960px, calc(100% - 1rem));
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: .4rem;
  background: rgba(23,26,35,.92);
  border: 1px solid var(--border);
  border-radius: 1.2rem;
  padding: .4rem;
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}
.bottom-nav button {
  background: transparent;
  color: var(--muted);
  padding: .7rem .25rem;
  font-size: .78rem;
}
.bottom-nav button.active {
  background: var(--panel-2);
  color: var(--text);
}
.photo-thumb { width: 4rem; height: 4rem; border-radius: .75rem; object-fit: cover; }

@media (max-width: 720px) {
  .grid.two, .form-grid, .workout-grid { grid-template-columns: 1fr; }
  .food-item { grid-template-columns: 2.6rem 1fr; }
  .food-item .add-btn { grid-column: 1 / -1; }
  .bottom-nav button { font-size: .7rem; }
}

.auth-only #appShell { display: none; }
.authenticated #authGate { display: none; }
.auth-gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1rem;
}
.auth-card { width: min(520px, 100%); }
.auth-status { min-height: 1.4rem; margin: .8rem 0 0; }
.header-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: .5rem;
  flex-wrap: wrap;
}
.header-actions .muted { font-size: .8rem; }
@media (max-width: 720px) {
  .header-actions { justify-content: flex-start; }
  #currentUserLabel { display: none; }
}

/* Auth safety fix */
body:not(.authenticated) #appShell { display: none !important; }
body.authenticated #appShell { display: block; }
body.authenticated #authGate { display: none !important; }
body:not(.authenticated) #authGate {
  min-height: 100vh;
  display: grid !important;
  place-items: center;
  padding: 1rem;
}
body:not(.authenticated) .auth-card { width: min(560px, 100%); }
