/* Meal Journal — design system.
   Apple-inspired: system fonts, soft shadows, rounded cards, pastel
   accents, glass chrome. Mobile-first. */

/* Dark, always — the app ships with data-bs-theme="dark" hardcoded. */
:root {
  --mj-pink: #F4B6C2;
  --mj-green: #A8D5BA;
  --mj-radius: 20px;
  --mj-radius-sm: 14px;
  --mj-shadow: 0 2px 12px rgba(0, 0, 0, .35), 0 8px 32px rgba(0, 0, 0, .25);
  --mj-shadow-lift: 0 4px 16px rgba(0, 0, 0, .45), 0 12px 40px rgba(0, 0, 0, .35);
  --mj-bg: #161618;
  --mj-card: #232326;
  --mj-text: #f5f5f7;
  --mj-text-2: #98989d;
  --mj-hairline: rgba(255, 255, 255, .10);
  --mj-glass: rgba(28, 28, 30, .72);
  --mj-accent: var(--mj-pink);
}

/* Recomputed per element: custom properties resolve var() where they
   are DEFINED, so a :root-level -soft would freeze the default pink
   even after body overrides --mj-accent with the user's color. */
* {
  --mj-accent-soft: color-mix(in srgb, var(--mj-accent) 22%, transparent);
}

html { scroll-behavior: smooth; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI",
    Roboto, "Helvetica Neue", sans-serif;
  background: var(--mj-bg);
  color: var(--mj-text);
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
  min-height: 100vh;
}

h1, h2, h3, h4, .display-6 { letter-spacing: -.02em; font-weight: 700; }

.text-secondary, .form-text { color: var(--mj-text-2) !important; }

/* ---- Chrome: glass header + bottom tab bar -------------------------- */

.mj-header {
  position: sticky;
  top: 0;
  z-index: 1020;
  background: var(--mj-glass);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--mj-hairline);
}

.mj-tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 1030;
  display: flex;
  justify-content: space-around;
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  background: var(--mj-glass);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid var(--mj-hairline);
}

.mj-tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 56px;
  padding: 6px 10px;
  border-radius: 12px;
  color: var(--mj-text-2);
  text-decoration: none;
  font-size: .68rem;
  font-weight: 600;
  transition: color .15s ease, background .15s ease;
}

.mj-tab svg { width: 24px; height: 24px; }

.mj-tab.active { color: var(--mj-text); background: var(--mj-accent-soft); }
.mj-tab:hover { color: var(--mj-text); }

/* ---- Cards ---------------------------------------------------------- */

.mj-card {
  background: var(--mj-card);
  border: none;
  border-radius: var(--mj-radius);
  box-shadow: var(--mj-shadow);
  overflow: hidden;
  transition: transform .18s ease, box-shadow .18s ease;
}

a.mj-card:active { transform: scale(.98); }

@media (hover: hover) {
  a.mj-card:hover { transform: translateY(-2px); box-shadow: var(--mj-shadow-lift); }
}

.mj-card .card-body { padding: 1rem 1.15rem; }

/* Accent edge used on timeline / day cards */
.mj-accent-edge { border-left: 5px solid var(--mj-accent); }

/* ---- Avatars & chips ------------------------------------------------- */

.mj-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--mj-accent);
  color: rgba(0, 0, 0, .65);
  font-weight: 700;
  flex: 0 0 auto;
  overflow: hidden;
}

.mj-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

.mj-avatar-lg { width: 84px; height: 84px; font-size: 2rem; }

.mj-chip {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .3rem .8rem;
  border-radius: 999px;
  background: var(--mj-accent-soft);
  color: var(--mj-text);
  font-size: .8rem;
  font-weight: 600;
  border: none;
}

/* ---- Buttons ---------------------------------------------------------- */

.btn { border-radius: 12px; font-weight: 600; }

.btn-accent {
  background: var(--mj-accent);
  border: none;
  color: rgba(0, 0, 0, .7);
  border-radius: 14px;
  padding: .65rem 1.4rem;
  transition: filter .15s ease, transform .1s ease;
}

.btn-accent:hover { filter: brightness(.96); color: rgba(0, 0, 0, .7); }
.btn-accent:active { transform: scale(.97); }

.btn-soft {
  background: var(--mj-accent-soft);
  border: none;
  color: var(--mj-text);
  border-radius: 14px;
}

/* Big tap targets on phones */
.btn-lg, .mj-slot-add { min-height: 48px; }

/* ---- Home: suggestion slots ------------------------------------------ */

.mj-slot {
  display: flex;
  align-items: center;
  gap: .9rem;
  padding: .8rem 1rem;
  background: var(--mj-card);
  border-radius: var(--mj-radius-sm);
  box-shadow: var(--mj-shadow);
}

.mj-slot-done { opacity: .92; }

.mj-slot-thumb {
  width: 52px; height: 52px;
  border-radius: 12px;
  object-fit: cover;
  flex: 0 0 auto;
}

.mj-slot-placeholder {
  width: 52px; height: 52px;
  border-radius: 12px;
  background: var(--mj-accent-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  flex: 0 0 auto;
}

.mj-slot-add {
  margin-left: auto;
  white-space: nowrap;
}

.mj-check {
  color: #34c759;
  font-size: 1.15rem;
  margin-left: auto;
}

/* ---- Activities -------------------------------------------------------- */

.mj-activity {
  border-left: 4px dashed var(--mj-accent);
}

.mj-activity-icon {
  background: var(--mj-accent-soft);
  font-size: 1.25rem;
}

.mj-drag-handle {
  color: var(--mj-text-2);
  font-size: 1rem;
  letter-spacing: -3px;
  padding: .4rem .3rem;
  cursor: grab;
  touch-action: none;   /* the handle owns the gesture — no page scroll */
  user-select: none;
  -webkit-user-select: none;
}

.mj-activity.dragging {
  opacity: .92;
  box-shadow: var(--mj-shadow-lift);
  transform: scale(1.02);
  position: relative;
  z-index: 20;
}

.mj-chip.active {
  background: var(--mj-accent);
  color: rgba(0, 0, 0, .7);
}

button.mj-chip { cursor: pointer; }

/* ---- Nutrition plan ----------------------------------------------------- */

.mj-plan-card {
  background: var(--mj-card);
  border-radius: var(--mj-radius-sm);
  box-shadow: var(--mj-shadow);
  overflow: hidden;
}

.mj-plan-card > summary {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .85rem 1rem;
  cursor: pointer;
  list-style: none;
  user-select: none;
}

.mj-plan-card > summary::-webkit-details-marker { display: none; }

.mj-plan-body {
  padding: 0 1rem .9rem;
  border-top: 1px solid var(--mj-hairline);
  padding-top: .8rem;
}

.mj-caret {
  color: var(--mj-text-2);
  transition: transform .2s ease;
  font-size: 1.1rem;
}

details[open] > summary .mj-caret { transform: rotate(90deg); }

.mj-portion-dot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--mj-accent-soft);
  font-size: .72rem;
  font-weight: 700;
}

.mj-ingredient {
  border-radius: 10px;
  background: var(--mj-bg);
  margin-bottom: .5rem;
  overflow: hidden;
}

.mj-ingredient > summary {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .6rem .8rem;
  cursor: pointer;
  list-style: none;
  font-size: .9rem;
  user-select: none;
}

.mj-ingredient > summary::-webkit-details-marker { display: none; }

.mj-counts {
  margin-left: auto;
  font-size: .7rem;
  font-weight: 600;
  color: var(--mj-text-2);
  white-space: nowrap;
}

.mj-compound { color: #e8a13c !important; }

.mj-question-card { border-left: 4px solid #e8a13c; }
.mj-question-line { color: #e8a13c; font-weight: 600; }

.mj-compound-note {
  margin-top: .6rem;
  padding: .5rem .7rem;
  border-radius: 10px;
  background: rgba(232, 161, 60, .12);
  font-size: .78rem;
}

.mj-swaps {
  padding: .2rem .8rem .7rem;
  border-top: 1px solid var(--mj-hairline);
}

.mj-swap-row {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: .35rem 0;
  font-size: .85rem;
  border-bottom: 1px solid var(--mj-hairline);
}

.mj-swap-row:last-child { border-bottom: none; }

.mj-swap-row span:last-child { text-align: right; white-space: nowrap; flex: 0 0 auto; }

/* ---- Photo grids ------------------------------------------------------ */

.mj-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
}

@media (min-width: 768px) { .mj-grid { grid-template-columns: repeat(5, 1fr); gap: 8px; } }
@media (min-width: 1200px) { .mj-grid { grid-template-columns: repeat(6, 1fr); } }

.mj-grid a {
  position: relative;
  display: block;
  aspect-ratio: 1;
  border-radius: 10px;
  overflow: hidden;
}

.mj-grid img {
  width: 100%; height: 100%;
  object-fit: cover;
  transition: transform .25s ease;
}

@media (hover: hover) { .mj-grid a:hover img { transform: scale(1.04); } }

/* ---- Meal photo strip (detail & cards) -------------------------------- */

.mj-photo {
  width: 100%;
  border-radius: var(--mj-radius-sm);
  object-fit: cover;
  aspect-ratio: 4 / 3;
  background: var(--mj-accent-soft);
}

/* ---- Calendar --------------------------------------------------------- */

.mj-cal {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}

.mj-cal-head {
  text-align: center;
  font-size: .72rem;
  font-weight: 700;
  color: var(--mj-text-2);
  text-transform: uppercase;
  letter-spacing: .04em;
  padding: .25rem 0;
}

.mj-cal-day {
  position: relative;
  aspect-ratio: 1;
  border-radius: 14px;
  background: var(--mj-card);
  box-shadow: var(--mj-shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  text-decoration: none;
  color: var(--mj-text);
  font-weight: 600;
  font-size: .95rem;
  transition: transform .12s ease;
}

.mj-cal-day:active { transform: scale(.94); }
.mj-cal-day.empty { background: transparent; box-shadow: none; pointer-events: none; }

.mj-cal-day.today {
  outline: 2px solid var(--mj-accent);
  outline-offset: -2px;
}

.mj-cal-dots { display: flex; gap: 3px; height: 7px; }
.mj-cal-dots span { width: 7px; height: 7px; border-radius: 50%; }

/* Day rating: prompt card + three verdict buttons + calendar marks */
.mj-rate-prompt { outline: 2px solid var(--mj-accent); outline-offset: -2px; }

.mj-rate-btn {
  font-size: 1.3rem;
  font-weight: 800;
  border-radius: 14px;
  background: var(--mj-bg);
  border: 2px solid transparent;
  opacity: .55;
  transition: opacity .15s ease, transform .1s ease;
}

.mj-rate-btn:active { transform: scale(.95); }
.mj-rate-btn.active, .mj-rate-btn:hover { opacity: 1; }

.mj-rate-good { color: #34c759; }
.mj-rate-neutral { color: #e8a13c; }
.mj-rate-bad { color: #ff453a; }

.mj-rate-btn.active { border-color: currentColor; }

.mj-cal-rating {
  font-size: .6rem;
  font-weight: 900;
  line-height: 1;
}

/* Question count badge — corner of a calendar day */
.mj-q-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 8px;
  background: #e8a13c;
  color: rgba(0, 0, 0, .75);
  font-size: .62rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

/* ---- Timeline --------------------------------------------------------- */

.mj-day-heading {
  position: sticky;
  top: 64px;
  z-index: 10;
  padding: .45rem .9rem;
  margin: 1.4rem 0 .8rem;
  display: inline-block;
  border-radius: 999px;
  background: var(--mj-glass);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  border: 1px solid var(--mj-hairline);
  font-weight: 700;
  font-size: .9rem;
}

/* ---- Lightbox ---------------------------------------------------------- */

.mj-lightbox {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: rgba(0, 0, 0, .96);
  display: none;
  align-items: center;
  justify-content: center;
  touch-action: none;
}

.mj-lightbox.open { display: flex; }

.mj-lightbox img {
  max-width: 100vw;
  max-height: 100vh;
  object-fit: contain;
  transition: transform .2s ease;
  user-select: none;
  -webkit-user-drag: none;
}

.mj-lightbox .mj-lb-close,
.mj-lightbox .mj-lb-prev,
.mj-lightbox .mj-lb-next {
  position: absolute;
  z-index: 2001;
  border: none;
  background: rgba(255, 255, 255, .14);
  color: #fff;
  width: 44px; height: 44px;
  border-radius: 50%;
  font-size: 1.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}

.mj-lb-close { top: calc(14px + env(safe-area-inset-top)); right: 14px; }
.mj-lb-prev { left: 10px; top: 50%; transform: translateY(-50%); }
.mj-lb-next { right: 10px; top: 50%; transform: translateY(-50%); }

.mj-lb-counter {
  position: absolute;
  top: calc(24px + env(safe-area-inset-top));
  left: 0; right: 0;
  text-align: center;
  color: rgba(255, 255, 255, .8);
  font-size: .85rem;
  font-weight: 600;
  pointer-events: none;
}

@media (hover: none) {
  .mj-lb-prev, .mj-lb-next { display: none; }
}

/* ---- Capture sheet (home quick add) ------------------------------------ */

.mj-sheet {
  position: fixed;
  inset: 0;
  z-index: 1050;
  background: rgba(0, 0, 0, .4);
  display: none;
  align-items: flex-end;
  justify-content: center;
}

.mj-sheet.open { display: flex; }

.mj-sheet-panel {
  background: var(--mj-card);
  border-radius: 24px 24px 0 0;
  padding: 1.25rem 1.25rem calc(1.25rem + env(safe-area-inset-bottom));
  width: 100%;
  max-width: 560px;
  animation: mj-sheet-up .25s ease;
}

@keyframes mj-sheet-up {
  from { transform: translateY(40px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.mj-sheet-preview {
  width: 100%;
  max-height: 40vh;
  object-fit: cover;
  border-radius: var(--mj-radius-sm);
}

/* ---- Upload progress ---------------------------------------------------- */

.mj-progress {
  height: 6px;
  border-radius: 3px;
  background: var(--mj-accent-soft);
  overflow: hidden;
}

.mj-progress > div {
  height: 100%;
  width: 0;
  background: var(--mj-accent);
  border-radius: 3px;
  transition: width .15s ease;
}

/* ---- Drag & drop (desktop) ----------------------------------------------- */

.mj-dropzone {
  border: 2px dashed var(--mj-hairline);
  border-radius: var(--mj-radius);
  padding: 2rem;
  text-align: center;
  color: var(--mj-text-2);
  transition: border-color .15s ease, background .15s ease;
}

.mj-dropzone.dragover {
  border-color: var(--mj-accent);
  background: var(--mj-accent-soft);
}

/* ---- Forms ---------------------------------------------------------------- */

.form-control, .form-select {
  border-radius: 12px;
  border-color: var(--mj-hairline);
  background: var(--mj-card);
  padding: .65rem .9rem;
}

.form-control:focus, .form-select:focus {
  border-color: var(--mj-accent);
  box-shadow: 0 0 0 .2rem var(--mj-accent-soft);
}

/* ---- Profile picker --------------------------------------------------------- */

.mj-profile-btn {
  display: flex;
  align-items: center;
  gap: 1rem;
  width: 100%;
  padding: 1.1rem 1.3rem;
  background: var(--mj-card);
  border: none;
  border-radius: var(--mj-radius);
  box-shadow: var(--mj-shadow);
  text-decoration: none;
  color: var(--mj-text);
  font-size: 1.15rem;
  font-weight: 700;
  transition: transform .15s ease, box-shadow .15s ease;
}

.mj-profile-btn:active { transform: scale(.97); }

@media (hover: hover) {
  .mj-profile-btn:hover { transform: translateY(-2px); box-shadow: var(--mj-shadow-lift); color: var(--mj-text); }
}

/* ---- Print (reports) ----------------------------------------------------------- */

@media print {
  .mj-header, .mj-tabbar, .mj-no-print, .btn { display: none !important; }
  body { background: #fff; padding-bottom: 0; }
  .mj-card { box-shadow: none; border: 1px solid #ddd; break-inside: avoid; }
  .mj-cal-day { box-shadow: none; border: 1px solid #eee; }
  a { text-decoration: none; color: inherit; }
}

/* ---- Misc ------------------------------------------------------------------------ */

.mj-fade-in { animation: mj-fade .3s ease; }

@keyframes mj-fade {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

::selection { background: var(--mj-accent-soft); }
