:root {
  --ink: #15171c;
  --ink-2: #23262e;
  --muted: #6b7280;
  --line: #e5e7eb;
  --bg: #f4f5f7;
  --card: #ffffff;
  --accent: #d4f84a;
  --accent-ink: #15171c;
  --brand: #2f6bff;
  --ok: #16a34a;
  --warn: #d97706;
  --bad: #dc2626;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.05);
  font-family: Inter, "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); line-height: 1.5; font-size: 15px; }
a { color: var(--brand); }
h1, h2, h3, h4 { line-height: 1.2; margin: 0 0 .5em; }
img { max-width: 100%; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.grow { flex: 1; }
.right { text-align: right; }

/* ---------- buttons & forms ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  padding: 9px 16px; border-radius: 10px; font: inherit; font-weight: 600; cursor: pointer;
  text-decoration: none; white-space: nowrap; transition: transform .05s, background .15s;
}
.btn:hover { background: #f3f4f6; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--ink); color: #fff; border-color: var(--ink); }
.btn.primary:hover { background: var(--ink-2); }
.btn.accent { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.accent:hover { filter: brightness(.95); }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

label { display: block; font-size: 13px; font-weight: 600; color: #374151; }
label > input, label > select, label > textarea { margin-top: 4px; }
input, select, textarea {
  width: 100%; font: inherit; padding: 9px 11px; border: 1px solid #d1d5db; border-radius: 10px; background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: -1px; border-color: transparent; }
textarea { resize: vertical; min-height: 80px; }
input[type=checkbox], input[type=radio] { width: auto; margin: 0; }
.check { display: flex; gap: 8px; align-items: center; font-weight: 500; }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
.span2 { grid-column: span 2; }
.span-all { grid-column: 1 / -1; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin: 0 0 16px; }
legend { font-weight: 700; padding: 0 6px; }

/* ---------- cards, tables, badges ---------- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.card + .card { margin-top: 16px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin-bottom: 16px; }
.stat { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; }
.stat .v { font-size: 28px; font-weight: 800; letter-spacing: -.02em; }
.stat .l { font-size: 13px; color: var(--muted); }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 10px; border-bottom: 1px solid var(--line); vertical-align: top; font-size: 14px; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 700; }
tr.click { cursor: pointer; }
tr.click:hover td { background: #fafafa; }
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; background: #eef0f3; color: #374151; }
.badge.ok { background: #dcfce7; color: #166534; }
.badge.warn { background: #fef3c7; color: #92400e; }
.badge.bad { background: #fee2e2; color: #991b1b; }
.badge.info { background: #dbeafe; color: #1e40af; }
.badge.lime { background: var(--accent); color: var(--accent-ink); }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }
.banner { padding: 10px 14px; border-radius: 10px; background: #fef3c7; color: #78350f; font-size: 14px; margin-bottom: 16px; }

/* ---------- toast & modal ---------- */
#toast { position: fixed; top: 20px; left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); font-size: 14px; animation: pop .2s; }
.toast.bad { background: var(--bad); }
@keyframes pop { from { opacity: 0; transform: translateY(8px); } }
.modal-bg { position: fixed; inset: 0; background: rgba(15,17,21,.5); z-index: 50; display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto; }
.modal { background: #fff; border-radius: 16px; width: 100%; max-width: 640px; padding: 24px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal.wide { max-width: 980px; }
.modal h2 { margin-bottom: 16px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }

/* ---------- chart ---------- */
.chart { width: 100%; height: auto; display: block; }
.chart text { font-size: 11px; fill: var(--muted); }
.chart-legend { display: flex; gap: 16px; font-size: 13px; color: var(--muted); }
.chart-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }

/* ---------- app shell (trainer + portal) ---------- */
.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.side { background: var(--ink); color: #cbd5e1; padding: 20px 14px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; }
.side .brand { color: #fff; font-weight: 800; font-size: 18px; padding: 4px 10px 20px; display: flex; gap: 10px; align-items: center; }
.side .brand .dot { width: 28px; height: 28px; border-radius: 8px; background: var(--accent); display: grid; place-items: center; color: var(--ink); font-size: 15px; }
.side nav a { display: flex; align-items: center; gap: 10px; color: #cbd5e1; text-decoration: none; padding: 10px 12px; border-radius: 10px; font-weight: 600; margin-bottom: 2px; }
.side nav a:hover { background: var(--ink-2); color: #fff; }
.side nav a.active { background: var(--accent); color: var(--ink); }
.side nav a .count { margin-left: auto; background: #ef4444; color: #fff; font-size: 11px; padding: 1px 7px; border-radius: 99px; }
.side .foot { margin-top: auto; display: grid; gap: 6px; }
.side .foot a, .side .foot button { color: #94a3b8; background: none; border: 0; font: inherit; text-align: left; padding: 8px 12px; cursor: pointer; text-decoration: none; border-radius: 8px; }
.side .foot a:hover, .side .foot button:hover { color: #fff; background: var(--ink-2); }
main.content { padding: 28px 32px 60px; min-width: 0; }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: 26px; letter-spacing: -.02em; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 18px; overflow-x: auto; }
.tabs button { background: none; border: 0; padding: 10px 14px; font: inherit; font-weight: 600; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.active { color: var(--ink); border-color: var(--ink); }
.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px 20px; }
.kv div b { display: block; font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--accent); color: var(--ink); display: grid; place-items: center; font-weight: 800; flex-shrink: 0; object-fit: cover; }
.bmi-scale { height: 10px; border-radius: 99px; background: linear-gradient(90deg, #60a5fa 0 18%, #22c55e 18% 50%, #f59e0b 50% 72%, #ef4444 72%); position: relative; margin: 10px 0 4px; }
.bmi-scale span { position: absolute; top: -5px; width: 4px; height: 20px; background: var(--ink); border-radius: 2px; transform: translateX(-2px); }

/* login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: var(--ink); }
.login-card { background: #fff; border-radius: 18px; padding: 32px; width: 100%; max-width: 380px; }
.login-card h1 { font-size: 24px; }
.login-card .grid { margin-top: 18px; }
.err { color: var(--bad); font-size: 14px; min-height: 20px; }

/* diet plan */
.meal { border: 1px solid var(--line); border-radius: 12px; padding: 14px; margin-bottom: 12px; background: #fff; }
.meal-head { display: flex; gap: 10px; align-items: center; margin-bottom: 10px; }
.meal-head input { max-width: 220px; font-weight: 700; }
.meal-head input.time { max-width: 110px; font-weight: 400; }
.meal table td, .meal table th { padding: 6px 8px; }
.meal input.qty { width: 70px; padding: 5px 8px; }
.macro-bar { display: flex; height: 8px; border-radius: 99px; overflow: hidden; background: #eee; margin: 6px 0; }
.macro-bar i { display: block; height: 100%; }
.food-search-results { max-height: 300px; overflow-y: auto; border: 1px solid var(--line); border-radius: 10px; margin-top: 8px; }
.food-search-results div { padding: 8px 12px; display: flex; justify-content: space-between; gap: 10px; cursor: pointer; border-bottom: 1px solid #f3f4f6; font-size: 14px; }
.food-search-results div:hover { background: #f9fafb; }
.totals { position: sticky; bottom: 0; background: var(--ink); color: #fff; border-radius: 12px; padding: 12px 16px; display: flex; gap: 22px; flex-wrap: wrap; align-items: center; margin-top: 12px; }
.totals b { font-size: 20px; }
.totals .over { color: #fca5a5; }

/* posts */
.post { display: grid; grid-template-columns: 110px 1fr auto; gap: 16px; padding: 16px 0; border-bottom: 1px solid var(--line); }
.post:last-child { border-bottom: 0; }
.post .thumb { width: 110px; height: 110px; border-radius: 10px; object-fit: cover; background: #f3f4f6; display: grid; place-items: center; color: #9ca3af; font-size: 12px; }
.post .cap { white-space: pre-wrap; font-size: 14px; max-height: 110px; overflow: hidden; }
.post .actions { display: flex; flex-direction: column; gap: 6px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip-toggle { border: 1px solid var(--line); border-radius: 99px; padding: 6px 12px; cursor: pointer; font-weight: 600; font-size: 13px; user-select: none; }
.chip-toggle input { display: none; }
.chip-toggle:has(input:checked) { background: var(--ink); color: #fff; border-color: var(--ink); }

.mobile-top { display: none; }
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: 250px; z-index: 40; transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; }
  .mobile-top { display: flex; align-items: center; gap: 12px; padding: 12px 16px; background: var(--ink); color: #fff; position: sticky; top: 0; z-index: 30; }
  .mobile-top button { background: none; border: 0; color: #fff; font-size: 22px; cursor: pointer; }
  main.content { padding: 20px 16px 60px; }
  .g2, .g3, .g4 { grid-template-columns: 1fr 1fr; }
  .post { grid-template-columns: 80px 1fr; }
  .post .thumb { width: 80px; height: 80px; }
  .post .actions { grid-column: 1 / -1; flex-direction: row; flex-wrap: wrap; }
}
@media (max-width: 520px) {
  .g2, .g3, .g4 { grid-template-columns: 1fr; }
  .span2 { grid-column: auto; }
}
@media print {
  .side, .mobile-top, .no-print, .tabs { display: none !important; }
  .shell { display: block; }
  body { background: #fff; }
  .card { box-shadow: none; padding: 0; }
  .totals { position: static; background: #fff; color: var(--ink); border: 1px solid var(--line); }
}
