/* NutriAI — design system compartilhado, mobile-first */
:root {
  --bg: #0a0a0b;
  --surface: #151518;
  --surface2: #1d1d21;
  --border: #2a2a30;
  --text: #e7e7ea;
  --muted: #9a9aa3;
  --dim: #6b6b75;
  --accent: #3b82f6;
  --accent-h: #2563eb;
  --green: #34d399;
  --green-bg: #052e16;
  --red: #f87171;
  --red-bg: #2d0a0a;
  --amber: #fbbf24;
  --radius: 14px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
}

/* ---------- Header / Nav ---------- */
header {
  position: sticky; top: 0; z-index: 50;
  background: rgba(15,15,17,0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.hwrap {
  display: flex; align-items: center; gap: 12px;
  max-width: 960px; margin: 0 auto; padding: 10px 16px;
}
.brand {
  font-weight: 700; font-size: 1.05rem; color: var(--text);
  text-decoration: none; white-space: nowrap; letter-spacing: -0.02em;
}
.brand b { color: var(--accent); }
nav {
  display: flex; gap: 2px; overflow-x: auto; -webkit-overflow-scrolling: touch;
  scrollbar-width: none; flex: 1;
}
nav::-webkit-scrollbar { display: none; }
nav a {
  color: var(--muted); text-decoration: none; font-size: 0.86rem;
  padding: 7px 12px; border-radius: 99px; white-space: nowrap;
  transition: color .15s, background .15s;
}
nav a:hover { color: var(--text); }
nav a.active { color: #fff; background: var(--accent-h); }

/* ---------- Layout ---------- */
.container { max-width: 960px; margin: 0 auto; padding: 20px 16px 56px; }
.container.narrow { max-width: 680px; }
h2 { font-size: 1.35rem; letter-spacing: -0.02em; margin-bottom: 4px; }
.subtitle { color: var(--muted); font-size: 0.88rem; margin-bottom: 20px; }
.section-title {
  font-size: 0.78rem; font-weight: 600; color: var(--dim);
  text-transform: uppercase; letter-spacing: 0.08em; margin: 24px 0 10px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 14px;
}
.card.highlight { border-color: var(--accent); }

/* ---------- Grids (mobile-first) ---------- */
.grid2, .grid4 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (min-width: 640px) {
  .grid4 { grid-template-columns: repeat(4, 1fr); gap: 12px; }
  .card { padding: 24px; }
  .container { padding: 28px 24px 64px; }
}

/* ---------- Forms ---------- */
label {
  display: block; font-size: 0.72rem; font-weight: 600; color: var(--dim);
  text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 6px;
}
input, select, textarea {
  width: 100%; padding: 11px 13px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
  font-size: 16px; /* evita zoom no iOS */
  outline: none; transition: border-color .15s;
  appearance: none; -webkit-appearance: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 12 12'%3E%3Cpath fill='%236b6b75' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 13px center;
  padding-right: 34px; cursor: pointer;
}
.field { margin-bottom: 14px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 11px 20px; border-radius: 10px; border: none; cursor: pointer;
  background: var(--accent-h); color: #fff; font-size: 0.92rem; font-weight: 500;
  transition: background .15s, opacity .15s; text-decoration: none;
  min-height: 44px; /* touch target */
}
.btn:hover { background: var(--accent); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.ghost {
  background: var(--surface2); color: var(--text); border: 1px solid var(--border);
}
.btn.ghost:hover { border-color: var(--dim); background: var(--surface2); }
.btn.sm { padding: 7px 13px; min-height: 36px; font-size: 0.82rem; border-radius: 8px; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 16px; }

/* ---------- Status / Badges ---------- */
.status { font-size: 0.86rem; padding: 7px 13px; border-radius: 8px; display: none; }
.status.ok { display: inline-block; background: var(--green-bg); color: var(--green); border: 1px solid #166534; }
.status.error { display: inline-block; background: var(--red-bg); color: var(--red); border: 1px solid #7f1d1d; }
.badge {
  display: inline-block; font-size: 0.68rem; font-weight: 600;
  padding: 3px 9px; border-radius: 99px; vertical-align: middle;
}
.badge.green { background: var(--green-bg); color: var(--green); }
.badge.blue { background: #172554; color: #93c5fd; }
.chip {
  display: inline-block; padding: 5px 12px; border-radius: 99px;
  font-size: 0.76rem; border: 1px solid var(--border); background: var(--surface2);
}
.chip.CUTTING, .chip.AGGRESSIVE_DEFICIT { background: var(--green-bg); color: var(--green); border-color: #166534; }
.chip.BULKING { background: #1e1b4b; color: #818cf8; border-color: #3730a3; }
.chip.MAINTENANCE, .chip.RECOMP { background: #2a1a0a; color: #fb923c; border-color: #92400e; }
.chip.WATER_RETENTION { background: #0c2d48; color: #38bdf8; border-color: #075985; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: var(--radius); border: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; font-size: 0.85rem; background: var(--surface); }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--dim); font-weight: 600; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em; background: var(--surface2); position: sticky; top: 0; }
tr:last-child td { border-bottom: none; }

/* ---------- Misc ---------- */
.muted { color: var(--muted); font-size: 0.86rem; }
.dim { color: var(--dim); font-size: 0.8rem; }
.row { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.macros { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.macros span {
  background: var(--surface2); padding: 6px 13px; border-radius: 99px;
  border: 1px solid var(--border); font-size: 0.82rem;
}
.divider { border: none; border-top: 1px solid var(--border); margin: 20px 0; }

/* ---------- Bottom bar (estilo app mobile) ---------- */
.bottombar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 60;
  display: flex; justify-content: space-around;
  background: rgba(18,18,20,0.96); backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
.bottombar a {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  color: var(--dim); text-decoration: none; font-size: 0.62rem;
  padding: 4px 10px; border-radius: 12px; min-width: 56px;
}
.bottombar a .icon { font-size: 1.25rem; line-height: 1.2; }
.bottombar a.on { color: var(--accent); }
body.has-bottombar { padding-bottom: calc(68px + env(safe-area-inset-bottom)); }
@media (min-width: 768px) {
  .bottombar { display: none; }
  body.has-bottombar { padding-bottom: 0; }
}
/* no mobile o menu superior some — a bottom bar assume */
@media (max-width: 767px) {
  body.has-bottombar header nav a { display: none; }
  body.has-bottombar header nav a.admin-only { display: none !important; }
  body.has-bottombar header nav a[href="/diets"],
  body.has-bottombar header nav a[href="/foods"] { display: inline-block; }
  body.has-bottombar.admin-visible header nav a.admin-only { display: inline-block !important; }
}

/* ---------- barra de impersonação ---------- */
.impersonation-bar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  display: flex; justify-content: center; align-items: center; gap: 12px;
  background: #92400e; color: #fff; font-size: 0.82rem; padding: 8px 16px;
}
.impersonation-bar button {
  background: #fff; color: #92400e; border: none; border-radius: 8px;
  padding: 5px 14px; cursor: pointer; font-weight: 600; font-size: 0.78rem;
}
body.has-impersonation header { top: 36px; }
body.has-impersonation { padding-top: 36px; }
