/* Fitness Platform — single stylesheet, mobile-first. */

:root {
  --bg: #0f1115;
  --surface: #161922;
  --surface-2: #1d2230;
  --surface-3: #262c3d;
  --border: #2a3142;
  --text: #e6e9f2;
  --muted: #8a93a8;
  --primary: #4f8cff;
  --primary-hover: #6ba2ff;
  --accent: #38d9a9;
  --warn: #f7b955;
  --danger: #ff6b6b;
  --carb: #ffb454;
  --protein: #4f8cff;
  --fat: #d97cf2;
  --fiber: #38d9a9;
  --radius: 10px;
  --radius-lg: 16px;
  --shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f7fb;
    --surface: #ffffff;
    --surface-2: #f0f2f8;
    --surface-3: #e7eaf2;
    --border: #dde0e9;
    --text: #15171f;
    --muted: #5b6478;
    --shadow: 0 4px 12px rgba(20, 25, 40, 0.08);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "SF Pro", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { margin: 0 0 0.4em 0; font-weight: 600; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.05rem; }
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); }
.muted { color: var(--muted); font-size: 0.9rem; }
.hide { display: none !important; }
.error { color: var(--danger); margin-top: 0.5rem; font-size: 0.9rem; }
.success { color: var(--accent); }
.warn { color: var(--warn); }
.spacer { flex: 1; }

/* ====== Auth page ====== */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.auth-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 2rem;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow);
}
.auth-card h1 { font-size: 1.7rem; margin-bottom: 0.3rem; }
.auth-card form { margin-top: 1rem; }
.auth-card label { display: block; margin-bottom: 0.85rem; font-size: 0.88rem; color: var(--muted); }
.auth-card input { width: 100%; padding: 0.65rem 0.8rem; margin-top: 0.25rem; background: var(--bg);
  border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); font-size: 1rem; }
.auth-toggle { text-align: center; margin-top: 1rem; font-size: 0.9rem; }

/* ====== Buttons & inputs ====== */
button { font: inherit; cursor: pointer; }
.btn {
  background: var(--surface-3);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.55rem 1rem;
  border-radius: var(--radius);
  font-size: 0.92rem;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  transition: background 0.15s;
}
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: white; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-sm { padding: 0.35rem 0.7rem; font-size: 0.85rem; }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }

input, select, textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.55rem 0.7rem;
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-family: inherit;
  width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 1px; }
input[type="checkbox"] { width: auto; }

label { font-size: 0.85rem; color: var(--muted); display: block; }
label.row { display: flex; align-items: center; gap: 0.5rem; }
.field { margin-bottom: 0.85rem; }
.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 0.7rem; }

.icon-btn {
  background: transparent;
  border: 0;
  color: var(--text);
  font-size: 1.3rem;
  padding: 0.4rem 0.6rem;
  border-radius: var(--radius);
}
.icon-btn:hover { background: var(--surface-2); }

/* ====== App shell ====== */
.app {
  display: grid;
  grid-template-columns: 220px 1fr;
  grid-template-rows: 56px 1fr;
  grid-template-areas:
    "header header"
    "nav    main";
  height: 100vh;
}
.app-header {
  grid-area: header;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 1rem;
  gap: 0.7rem;
}
.app-header h1 { font-size: 1.05rem; margin: 0; }
.user-chip { display: flex; align-items: center; gap: 0.5rem; font-size: 0.9rem; color: var(--muted); }

.side-nav {
  grid-area: nav;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 0.5rem 0.5rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}
.side-nav a {
  padding: 0.6rem 0.85rem;
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.92rem;
}
.side-nav a:hover { background: var(--surface-2); color: var(--text); }
.side-nav a.active { background: var(--primary); color: white; }

.view {
  grid-area: main;
  padding: 1.2rem 1.5rem;
  overflow-y: auto;
  padding-bottom: 5rem;
}
.tab-bar { display: none; }
#menuBtn { display: none; }

@media (max-width: 720px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: 56px 1fr 64px;
    grid-template-areas:
      "header"
      "main"
      "tabs";
  }
  .side-nav {
    position: fixed;
    top: 56px; left: 0; bottom: 0;
    width: 250px;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform 0.2s;
    border-right: 1px solid var(--border);
  }
  .side-nav.open { transform: translateX(0); box-shadow: var(--shadow); }
  #menuBtn { display: block; }
  .view { padding: 1rem; padding-bottom: 1rem; }
  .tab-bar {
    display: flex;
    grid-row: 3;
    background: var(--surface);
    border-top: 1px solid var(--border);
    align-items: stretch;
  }
  .tab-bar a {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--muted);
    font-size: 0.7rem;
    gap: 2px;
    padding: 0.3rem 0;
  }
  .tab-bar a.active { color: var(--primary); }
  .tab-bar a span { display: block; }
}

/* ====== Cards & layout ====== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.1rem;
  margin-bottom: 1rem;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.7rem;
}
.card-title { font-weight: 600; font-size: 1rem; }
.row-flex { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 1rem; }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0.8rem; }

.empty {
  text-align: center;
  padding: 2rem;
  color: var(--muted);
}

table.data { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
table.data th { text-align: left; font-weight: 600; padding: 0.5rem; border-bottom: 1px solid var(--border); color: var(--muted); }
table.data td { padding: 0.5rem; border-bottom: 1px solid var(--border); }
table.data tr:last-child td { border-bottom: 0; }

/* ====== Macro ring ====== */
.macro-summary {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 1rem;
  align-items: center;
}
@media (max-width: 480px) {
  .macro-summary { grid-template-columns: 1fr; }
}
.macro-ring { width: 140px; height: 140px; position: relative; }
.macro-ring svg { transform: rotate(-90deg); }
.macro-ring-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; }
.macro-ring-center .kcal { font-size: 1.4rem; font-weight: 700; line-height: 1; }
.macro-ring-center .kcal-sub { font-size: 0.75rem; color: var(--muted); margin-top: 4px; }
.macro-bars { display: flex; flex-direction: column; gap: 0.4rem; }
.macro-bar { display: grid; grid-template-columns: 70px 1fr 80px; align-items: center; gap: 0.5rem; font-size: 0.85rem; }
.macro-bar-track { background: var(--surface-2); border-radius: 999px; height: 8px; overflow: hidden; }
.macro-bar-fill { height: 100%; border-radius: 999px; transition: width 0.25s; }
.macro-bar-vals { color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }
.macro-protein { background: var(--protein); }
.macro-carbs { background: var(--carb); }
.macro-fat { background: var(--fat); }

/* ====== Calendar ====== */
.calendar-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.calendar-cell {
  aspect-ratio: 1 / 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 6px;
  font-size: 0.8rem;
  position: relative;
  cursor: pointer;
  transition: background 0.1s;
}
.calendar-cell:hover { background: var(--surface-2); }
.calendar-cell.other-month { opacity: 0.35; }
.calendar-cell .date-num { font-weight: 600; }
.calendar-cell.today .date-num { color: var(--primary); }
.calendar-cell .markers { display: flex; gap: 2px; flex-wrap: wrap; margin-top: 2px; }
.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; }
.dot.workout { background: var(--primary); }
.dot.workout-done { background: var(--accent); }
.dot.workout-skipped { background: var(--muted); }
.dot.workout-progress { background: var(--warn); }
.dot.cardio { background: var(--accent); border: 1px solid #fff3; }
.calendar-day-name { font-size: 0.75rem; color: var(--muted); text-align: center; padding: 0.3rem 0; font-weight: 600; }

/* ====== Workout logger ====== */
.set-row {
  display: grid;
  grid-template-columns: 32px 70px 80px 36px 1fr;
  gap: 0.45rem;
  align-items: center;
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--border);
}
.set-row.completed { opacity: 0.7; }
.set-row input { padding: 0.35rem 0.45rem; font-size: 0.9rem; text-align: center; }
.set-num { font-weight: 600; color: var(--muted); text-align: center; }
.set-check {
  width: 28px; height: 28px; border-radius: 6px;
  border: 1.5px solid var(--border); background: var(--surface);
  display: flex; align-items: center; justify-content: center;
}
.set-check.done { background: var(--accent); border-color: var(--accent); color: white; }
.set-row .last-set { font-size: 0.75rem; color: var(--muted); }

/* ====== Modal ====== */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; padding: 1rem;
}
.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  width: 100%;
  max-width: 540px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
}
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }

/* ====== Toast ====== */
#toastRoot { position: fixed; right: 1rem; bottom: 5rem; z-index: 200; display: flex; flex-direction: column; gap: 0.5rem; }
.toast {
  background: var(--surface-3);
  color: var(--text);
  padding: 0.7rem 1rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  animation: slideIn 0.2s;
}
.toast.error { border-color: var(--danger); }
.toast.success { border-color: var(--accent); }
@keyframes slideIn { from { transform: translateX(40px); opacity: 0 } to { transform: none; opacity: 1 } }

/* ====== Misc ====== */
.list-row {
  display: flex; align-items: center; gap: 0.7rem;
  padding: 0.7rem 0;
  border-bottom: 1px solid var(--border);
}
.list-row:last-child { border-bottom: 0; }
.thumb { width: 60px; height: 60px; border-radius: var(--radius); object-fit: cover; background: var(--surface-2); }
.pill { display: inline-block; padding: 2px 8px; font-size: 0.75rem; background: var(--surface-3); color: var(--muted); border-radius: 999px; }
.pill.active { background: var(--primary); color: white; }
.pill.danger { background: var(--danger); color: white; }
.pill.success { background: var(--accent); color: white; }
.pill.warn { background: var(--warn); color: white; }

.chart-wrap { position: relative; height: 220px; }

.search-results {
  max-height: 360px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-top: 0.4rem;
}
.search-result {
  padding: 0.55rem 0.75rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.search-result:hover { background: var(--surface-2); }
.search-result:last-child { border-bottom: 0; }
.search-result-name { font-weight: 500; }
.search-result-meta { font-size: 0.78rem; color: var(--muted); }

.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 0.6rem; }
.photo-grid img { width: 100%; aspect-ratio: 3 / 4; object-fit: cover; border-radius: var(--radius); cursor: pointer; }

.exercise-img-thumb { width: 60px; height: 60px; object-fit: cover; border-radius: var(--radius); background: var(--surface-2); }

details > summary { cursor: pointer; padding: 0.5rem 0; font-weight: 500; }
details > summary::-webkit-details-marker { color: var(--muted); }

.tabs { display: flex; gap: 0.3rem; border-bottom: 1px solid var(--border); margin-bottom: 1rem; }
.tabs button { padding: 0.55rem 1rem; background: transparent; border: 0; color: var(--muted); border-bottom: 2px solid transparent; }
.tabs button.active { color: var(--text); border-bottom-color: var(--primary); }
