/* =========================================================
   DIETA APP — polished responsive UI
   Desktop + mobile, bez ruszania istniejących ID / onclick / API.
   ========================================================= */

:root {
  --bg-1: #f4f0ff;
  --bg-2: #ebe7ff;
  --bg-3: #f7fbf4;
  --surface: rgba(255, 255, 255, 0.92);
  --surface-solid: #ffffff;
  --surface-soft: #f8f7ff;
  --surface-warm: #fffaf2;
  --ink: #171321;
  --text: #2c2638;
  --muted: #847992;
  --muted-2: #a69cb2;
  --line: rgba(37, 27, 55, 0.08);
  --line-strong: rgba(37, 27, 55, 0.14);
  --primary: #7c3aed;
  --primary-2: #9f7aea;
  --primary-3: #ede9fe;
  --green: #18a65c;
  --green-soft: #e8f8ef;
  --orange: #f97316;
  --orange-soft: #fff2e8;
  --blue: #2563eb;
  --blue-soft: #eaf0ff;
  --red: #ef4444;
  --red-soft: #fee8e8;
  --yellow: #f59e0b;
  --yellow-soft: #fff7dc;
  --shadow-xs: 0 2px 8px rgba(45, 30, 80, 0.06);
  --shadow-sm: 0 10px 30px rgba(45, 30, 80, 0.10);
  --shadow-md: 0 22px 60px rgba(45, 30, 80, 0.15);
  --shadow-nav: 0 18px 45px rgba(12, 10, 20, 0.25);
  --radius-sm: 14px;
  --radius-md: 20px;
  --radius-lg: 28px;
  --radius-xl: 36px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html {
  min-height: 100%;
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100dvh;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 10% 8%, rgba(255, 255, 255, 0.84) 0 13rem, transparent 13.5rem),
    radial-gradient(circle at 88% 12%, rgba(167, 139, 250, 0.30) 0 16rem, transparent 16.5rem),
    radial-gradient(circle at 80% 86%, rgba(52, 211, 153, 0.22) 0 18rem, transparent 18.5rem),
    linear-gradient(135deg, var(--bg-1), var(--bg-2) 52%, var(--bg-3));
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: -1;
  background-image:
    linear-gradient(rgba(255,255,255,.34) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.34) 1px, transparent 1px);
  background-size: 42px 42px;
  mask-image: linear-gradient(to bottom, rgba(0,0,0,.44), transparent 72%);
}

button, input, select, textarea { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 4px solid rgba(124, 58, 237, 0.18);
  outline-offset: 2px;
}

/* ===== PAGES ===== */
.page { min-height: 100dvh; }
.page.hidden, #page-app.page.hidden, #page-login.page.hidden { display: none !important; }
.page.active { display: block; }
.section { display: none; padding: 0; }
.section.active { display: block; animation: sectionIn .32s cubic-bezier(.2,.8,.2,1) both; }
.section.hidden { display: none !important; }
.hidden { display: none !important; }

@keyframes sectionIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ===== LOGIN ===== */
.login-container {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 34px 20px;
  position: relative;
  isolation: isolate;
}

.login-container::before {
  content: "";
  position: absolute;
  width: min(92vw, 520px);
  height: min(92vw, 520px);
  border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, rgba(255,255,255,.78), rgba(124,58,237,.20) 48%, transparent 70%);
  filter: blur(2px);
  z-index: -1;
}

.login-logo {
  width: 92px;
  height: 92px;
  display: grid;
  place-items: center;
  margin-bottom: 18px;
  border-radius: 30px;
  background: linear-gradient(145deg, rgba(255,255,255,.92), rgba(255,255,255,.62));
  box-shadow: var(--shadow-md);
  font-size: 48px;
  border: 1px solid rgba(255,255,255,.72);
}

.login-container h1 {
  font-size: clamp(2.15rem, 7vw, 3.65rem);
  letter-spacing: -0.075em;
  line-height: .92;
  color: var(--ink);
  margin-bottom: 10px;
}

.login-container h1::after {
  content: "";
  display: block;
  width: 74px;
  height: 8px;
  margin: 16px auto 0;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--primary), #34d399);
}

.login-sub {
  color: var(--muted);
  margin-bottom: 28px;
  font-size: 1rem;
  font-weight: 650;
}

.user-select {
  width: min(100%, 440px);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 22px;
}

.user-btn {
  min-height: 156px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 22px;
  border: 1px solid rgba(255,255,255,.68);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  font-size: 1.02rem;
  font-weight: 850;
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(18px);
  transition: transform .2s ease, box-shadow .2s ease, border-color .2s ease, background .2s ease;
}
.user-btn:hover { transform: translateY(-5px); box-shadow: var(--shadow-md); border-color: rgba(124,58,237,.28); background: #fff; }
.user-btn:active { transform: translateY(-1px) scale(.99); }
.user-icon {
  width: 64px;
  height: 64px;
  display: grid;
  place-items: center;
  border-radius: 24px;
  background: var(--primary-3);
  font-size: 38px;
}

#login-form {
  width: min(100%, 390px);
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 18px;
  border-radius: var(--radius-lg);
  background: var(--surface);
  border: 1px solid rgba(255,255,255,.68);
  box-shadow: var(--shadow-md);
  backdrop-filter: blur(18px);
}
.login-selected-user { font-size: 1.05rem; font-weight: 850; color: var(--ink); text-align: center; margin: 2px 0 6px; }
.remember-label { display: flex; align-items: center; gap: 9px; color: var(--muted); font-size: .91rem; font-weight: 650; margin: 2px 0 6px; cursor: pointer; }
.remember-label input { accent-color: var(--primary); }
.btn-back { background: none; border: none; color: var(--muted); cursor: pointer; margin-top: 4px; font-size: .95rem; font-weight: 750; text-decoration: none; }
.btn-back:hover { color: var(--primary); }

/* ===== APP SHELL ===== */
#page-app {
  min-height: 100dvh;
  width: 100%;
}

#main-content {
  width: min(100%, 560px);
  margin: 0 auto;
  padding: 18px 16px calc(112px + var(--safe-bottom));
}

/* ===== TOPBAR ===== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  width: calc(100% - 32px);
  max-width: 560px;
  margin: 12px auto 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 14px;
  color: var(--ink);
  background: rgba(255, 255, 255, .78);
  border: 1px solid rgba(255, 255, 255, .72);
  border-radius: 30px;
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(20px) saturate(130%);
}
.topbar-left { min-width: 0; display: flex; align-items: center; gap: 10px; font-size: 1.02rem; font-weight: 900; letter-spacing: -.025em; }
.topbar-logo {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 15px;
  background: linear-gradient(145deg, var(--primary-3), #fff);
  font-size: 1.18rem;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.8), 0 8px 16px rgba(124,58,237,.12);
}
#topbar-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-right { flex: 0 0 auto; display: flex; align-items: center; gap: 8px; }
.topbar-user {
  max-width: 122px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: .78rem;
  color: var(--muted);
  background: var(--surface-soft);
  border: 1px solid var(--line);
  padding: 7px 10px;
  border-radius: 999px;
  font-weight: 800;
}
.icon-btn {
  width: 38px;
  height: 38px;
  display: inline-grid;
  place-items: center;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 15px;
  cursor: pointer;
  font-size: 1rem;
  box-shadow: var(--shadow-xs);
  transition: transform .18s ease, background .18s ease, box-shadow .18s ease;
}
.icon-btn:hover { transform: translateY(-2px); background: var(--primary-3); box-shadow: var(--shadow-sm); }
.icon-btn:active { transform: scale(.97); }

/* ===== BOTTOM NAV / MOBILE TABBAR ===== */
.bottom-nav {
  position: fixed;
  left: 50%;
  bottom: calc(14px + var(--safe-bottom));
  transform: translateX(-50%);
  z-index: 120;
  width: calc(100% - 32px);
  max-width: 480px;
  min-height: 66px;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  padding: 8px;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 999px;
  background: rgba(18, 17, 23, .94);
  box-shadow: var(--shadow-nav);
  backdrop-filter: blur(22px) saturate(150%);
}
.nav-btn {
  min-width: 0;
  min-height: 50px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: rgba(255,255,255,.62);
  cursor: pointer;
  font-size: .64rem;
  font-weight: 800;
  letter-spacing: -.01em;
  transition: transform .18s ease, color .18s ease, background .18s ease, box-shadow .18s ease;
}
.nav-btn span:first-child { font-size: 1.12rem; line-height: 1; }
.nav-btn.active {
  color: #fff;
  background: linear-gradient(145deg, var(--primary), #6d28d9);
  box-shadow: 0 12px 22px rgba(124, 58, 237, .38);
}
.nav-btn:hover { color: #fff; transform: translateY(-1px); }
.nav-btn:active { transform: scale(.97); }

/* ===== DATE NAV ===== */
.date-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 4px 0 16px;
  padding: 8px;
  border-radius: 999px;
  background: rgba(255,255,255,.58);
  border: 1px solid rgba(255,255,255,.62);
  box-shadow: var(--shadow-xs);
  backdrop-filter: blur(16px);
}
.date-btn {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: #fff;
  color: var(--ink);
  font-size: 1.45rem;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
  box-shadow: var(--shadow-xs);
  transition: transform .18s ease, background .18s ease, opacity .18s ease;
}
.date-btn:hover { transform: translateY(-1px); background: var(--primary-3); }
.date-btn:active { transform: scale(.96); }
.date-label {
  flex: 1 1 auto;
  text-align: center;
  color: var(--ink);
  cursor: pointer;
  font-size: .98rem;
  font-weight: 900;
  letter-spacing: -.02em;
  text-decoration: none;
}

/* ===== SHARED CARDS ===== */
.card,
.add-meal-form,
.add-activity-form,
.meal-card,
.diary-entry,
.activity-item,
.food-result,
.settings-form,
.barcode-area,
.manual-form,
.tab-content:not(.hidden) {
  background: var(--surface);
  border: 1px solid rgba(255,255,255,.72);
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(18px) saturate(130%);
}

.cards-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 14px;
}
.card {
  position: relative;
  overflow: hidden;
  min-height: 122px;
  border-radius: var(--radius-lg);
  padding: 16px;
  text-align: left;
  transition: transform .2s ease, box-shadow .2s ease;
}
.card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.card::after {
  content: "";
  position: absolute;
  right: -24px;
  top: -30px;
  width: 92px;
  height: 92px;
  border-radius: 50%;
  background: currentColor;
  opacity: .08;
}
.card-icon {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  margin-bottom: 14px;
  border-radius: 16px;
  background: #fff;
  box-shadow: var(--shadow-xs);
  font-size: 1.12rem;
}
.card-value {
  color: var(--ink);
  font-size: clamp(1.52rem, 5vw, 2rem);
  line-height: 1;
  font-weight: 950;
  letter-spacing: -.055em;
}
.card-label { margin-top: 6px; color: var(--muted); font-size: .75rem; font-weight: 800; }
.card-green { color: var(--green); }
.card-orange { color: var(--orange); }
.card-blue { color: var(--blue); }
.card-gray { color: #64748b; }
.card-green .card-value { color: var(--green); }
.card-orange .card-value { color: var(--orange); }
.card-blue .card-value { color: var(--blue); }
.card-gray .card-value { color: #475569; }

/* ===== STATUS BAR ===== */
.status-bar {
  min-height: 54px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px 16px;
  border-radius: var(--radius-md);
  margin-bottom: 14px;
  font-size: .94rem;
  font-weight: 850;
  line-height: 1.35;
  text-align: center;
  border: 1px solid var(--line);
  box-shadow: var(--shadow-xs);
}
.status-good { background: var(--green-soft); color: #117845; border-color: rgba(24,166,92,.14); }
.status-warn { background: var(--yellow-soft); color: #8a5b00; border-color: rgba(245,158,11,.16); }
.status-over { background: var(--red-soft); color: #b91c1c; border-color: rgba(239,68,68,.16); }

/* ===== RING ===== */
.ring-container {
  position: relative;
  width: 100%;
  min-height: 218px;
  margin: 0 auto 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-xl);
  background:
    radial-gradient(circle at 50% 50%, rgba(255,255,255,.95) 0 36%, transparent 36.5%),
    linear-gradient(145deg, rgba(255,255,255,.78), rgba(255,255,255,.48));
  border: 1px solid rgba(255,255,255,.72);
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(18px);
  overflow: hidden;
}
.ring-container::before,
.ring-container::after {
  content: "";
  position: absolute;
  border-radius: 999px;
  pointer-events: none;
}
.ring-container::before {
  inset: 18px;
  border: 14px solid rgba(124,58,237,.055);
}
.ring-container::after {
  width: 88px;
  height: 88px;
  right: -28px;
  bottom: -28px;
  background: rgba(52,211,153,.20);
}
.ring { position: relative; z-index: 1; width: 168px; height: 168px; transform: rotate(-90deg); filter: drop-shadow(0 18px 20px rgba(124,58,237,.10)); }
.ring-bg { fill: none; stroke: rgba(124,58,237,.12); stroke-width: 12; }
.ring-fill { fill: none; stroke: url(#unused); stroke: var(--primary); stroke-width: 12; stroke-linecap: round; transition: stroke-dashoffset .9s cubic-bezier(.2,.8,.2,1); }
.ring-text {
  position: absolute;
  z-index: 2;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
}
#ring-pct { font-size: 2.05rem; line-height: .95; font-weight: 950; letter-spacing: -.06em; color: var(--ink); }
.ring-sublabel { margin-top: 5px; font-size: .7rem; color: var(--muted); font-weight: 850; }

/* ===== QUICK ACTIONS ===== */
.quick-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 20px;
}
.qa-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 60px;
  padding: 13px 14px;
  border: 1px solid rgba(255,255,255,.72);
  border-radius: var(--radius-md);
  background: rgba(255,255,255,.78);
  color: var(--ink);
  cursor: pointer;
  font-size: .9rem;
  font-weight: 900;
  box-shadow: var(--shadow-xs);
  backdrop-filter: blur(16px);
  transition: transform .18s ease, box-shadow .18s ease, background .18s ease;
}
.qa-btn:hover { transform: translateY(-2px); background: #fff; box-shadow: var(--shadow-sm); }
.qa-btn:active { transform: scale(.98); }
.qa-btn span {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 14px;
  background: var(--primary-3);
  font-size: 1.12rem;
}

/* ===== SECTION HEADER ===== */
.section-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 4px 0 16px;
  flex-wrap: wrap;
}
.section-header h2 {
  color: var(--ink);
  font-size: clamp(1.45rem, 4vw, 2rem);
  line-height: 1;
  font-weight: 950;
  letter-spacing: -.055em;
}
.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 18px 2px 10px;
  color: var(--ink);
  font-size: 1.05rem;
  font-weight: 950;
  letter-spacing: -.035em;
}
.section-title::after {
  content: "";
  flex: 1;
  height: 1px;
  margin-left: 14px;
  background: linear-gradient(90deg, var(--line-strong), transparent);
}
.date-small {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(255,255,255,.74);
  border: 1px solid rgba(255,255,255,.72);
  color: var(--muted);
  font-size: .82rem;
  font-weight: 850;
}
.back-btn {
  height: 38px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255,255,255,.82);
  color: var(--ink);
  cursor: pointer;
  font-size: .9rem;
  font-weight: 850;
  box-shadow: var(--shadow-xs);
}
.back-btn:hover { background: var(--primary-3); }

/* ===== LIST PREVIEWS ===== */
.preview-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 14px;
  margin-bottom: 10px;
  border-radius: var(--radius-md);
  background: rgba(255,255,255,.78);
  border: 1px solid rgba(255,255,255,.72);
  box-shadow: var(--shadow-xs);
  backdrop-filter: blur(16px);
}
.preview-item > span:first-child {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 16px;
  background: var(--surface-soft);
  font-size: 1.16rem;
}

/* ===== MEALS ===== */
.meal-card {
  overflow: hidden;
  border-radius: var(--radius-lg);
  margin-bottom: 14px;
}
.meal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 15px;
  background: linear-gradient(135deg, rgba(237,233,254,.85), rgba(255,255,255,.35));
  border-bottom: 1px solid var(--line);
}
.meal-header-left { min-width: 0; display: flex; align-items: center; gap: 12px; }
.meal-type-icon {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 17px;
  background: #fff;
  box-shadow: var(--shadow-xs);
  font-size: 1.28rem;
}
.meal-name { color: var(--ink); font-weight: 950; font-size: 1.02rem; letter-spacing: -.025em; }
.meal-kcal { margin-top: 3px; font-size: .82rem; color: var(--muted); font-weight: 850; }
.meal-delete,
.meal-item-delete,
.activity-delete {
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border: 1px solid rgba(239,68,68,.12);
  border-radius: 14px;
  background: rgba(254,232,232,.68);
  color: var(--red);
  cursor: pointer;
  font-size: .9rem;
  transition: transform .18s ease, background .18s ease;
}
.meal-delete:hover,
.meal-item-delete:hover,
.activity-delete:hover { transform: translateY(-1px); background: var(--red-soft); }
.meal-items { padding: 8px 12px 4px; }
.meal-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 0;
  border-bottom: 1px solid rgba(37,27,55,.065);
}
.meal-item:last-child { border-bottom: none; }
.meal-item-img,
.meal-item-img-placeholder {
  width: 46px;
  height: 46px;
  flex: 0 0 auto;
  border-radius: 16px;
  object-fit: cover;
  background: var(--surface-soft);
  display: grid;
  place-items: center;
  font-size: 1.2rem;
}
.meal-item-info { flex: 1; min-width: 0; }
.meal-item-name { color: var(--ink); font-size: .9rem; font-weight: 900; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meal-item-details { margin-top: 3px; font-size: .76rem; color: var(--muted); font-weight: 700; }
.meal-item-kcal { color: var(--green); font-size: .9rem; font-weight: 950; white-space: nowrap; }
.meal-add-btn {
  width: 100%;
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 16px;
  border: none;
  border-top: 1px solid var(--line);
  background: rgba(255,255,255,.45);
  color: var(--primary);
  cursor: pointer;
  font-size: .92rem;
  font-weight: 950;
}
.meal-add-btn:hover { background: var(--primary-3); }
.add-meal-form, .add-activity-form, .settings-form {
  border-radius: var(--radius-lg);
  padding: 18px;
  margin-top: 14px;
  text-align: left;
}
.form-title { color: var(--ink); font-weight: 950; margin-bottom: 13px; letter-spacing: -.025em; }

.nutriscore {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 20px;
  padding: 0 7px;
  border-radius: 999px;
  font-size: .68rem;
  line-height: 1;
  font-weight: 950;
  text-transform: uppercase;
  margin-left: 5px;
  vertical-align: middle;
}
.nutriscore-a { background: #16a34a; color: white; }
.nutriscore-b { background: #86efac; color: #14532d; }
.nutriscore-c { background: #fbbf24; color: #4a2d00; }
.nutriscore-d { background: #f97316; color: white; }
.nutriscore-e { background: #ef4444; color: white; }

/* ===== TABS / FOOD SEARCH ===== */
.tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 14px;
  padding: 5px;
  border-radius: 999px;
  background: rgba(255,255,255,.62);
  border: 1px solid rgba(255,255,255,.72);
  box-shadow: var(--shadow-xs);
}
.tab {
  min-height: 42px;
  padding: 8px 10px;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: .78rem;
  font-weight: 900;
  transition: background .18s ease, color .18s ease, box-shadow .18s ease;
}
.tab.active { background: var(--ink); color: #fff; box-shadow: 0 10px 18px rgba(23,19,33,.18); }
.tab-content { display: block; }
.tab-content.hidden { display: none; }
.tab-content:not(.hidden), .manual-form, .barcode-area {
  border-radius: var(--radius-lg);
  padding: 14px;
}
.search-box { margin-bottom: 12px; }
.food-result {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: var(--radius-md);
  margin-bottom: 10px;
  cursor: pointer;
  transition: transform .18s ease, box-shadow .18s ease, background .18s ease;
}
.food-result:hover { transform: translateY(-2px); background: #fff; box-shadow: var(--shadow-sm); }
.food-result-img,
.food-result-img-placeholder {
  width: 52px;
  height: 52px;
  flex: 0 0 auto;
  object-fit: cover;
  border-radius: 17px;
  background: var(--surface-soft);
  display: grid;
  place-items: center;
  font-size: 1.35rem;
}
.food-result-info { flex: 1; min-width: 0; }
.food-result-name { color: var(--ink); font-weight: 950; font-size: .93rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.food-result-brand { margin-top: 3px; font-size: .78rem; color: var(--muted); font-weight: 700; }
.food-result-kcal { color: var(--green); font-weight: 950; font-size: .86rem; white-space: nowrap; }
.food-info-small { font-size: .82rem; color: var(--muted); margin: 8px 0; text-align: center; font-weight: 750; }
.qty-preview { padding: 12px; background: var(--primary-3); border-radius: 16px; margin: 8px 0; font-size: .9rem; color: var(--ink); font-weight: 850; text-align: center; }
.input-big { font-size: 1.35rem !important; font-weight: 950 !important; text-align: center; }
.barcode-area { text-align: center; }
.barcode-icon {
  width: 84px;
  height: 84px;
  display: grid;
  place-items: center;
  margin: 4px auto 12px;
  border-radius: 28px;
  background: var(--primary-3);
  font-size: 2.55rem;
}
.barcode-area p { color: var(--muted); font-weight: 750; }
.barcode-input-row { display: flex; gap: 8px; margin-top: 12px; }

/* ===== ACTIVITY ===== */
.activity-item {
  display: flex;
  align-items: center;
  gap: 12px;
  border-radius: var(--radius-lg);
  padding: 14px;
  margin-bottom: 12px;
}
.activity-icon {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 19px;
  background: var(--orange-soft);
  font-size: 1.7rem;
}
.activity-info { flex: 1; min-width: 0; }
.activity-name { color: var(--ink); font-weight: 950; font-size: .98rem; letter-spacing: -.02em; }
.activity-details { margin-top: 3px; font-size: .78rem; color: var(--muted); font-weight: 750; }
.activity-kcal { color: var(--orange); font-size: .92rem; font-weight: 950; white-space: nowrap; }

/* ===== DIARY ===== */
.diary-entry {
  border-radius: var(--radius-lg);
  padding: 16px;
  margin-bottom: 12px;
}
.diary-date { color: var(--ink); font-weight: 950; font-size: 1.02rem; margin-bottom: 12px; letter-spacing: -.025em; }
.diary-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.diary-stat { background: rgba(248,247,255,.78); border: 1px solid var(--line); padding: 10px; border-radius: 18px; text-align: center; min-width: 0; }
.diary-stat-val { color: var(--ink); font-weight: 950; font-size: 1rem; }
.diary-stat-label { margin-top: 2px; font-size: .7rem; color: var(--muted); font-weight: 800; }
.diary-balance-positive { color: var(--green) !important; background: var(--green-soft) !important; }
.diary-balance-negative { color: var(--red) !important; background: var(--red-soft) !important; }

/* ===== SETTINGS / PROFILE ===== */
.bmi-card {
  margin-top: 16px;
  padding: 18px;
  border-radius: var(--radius-lg);
  background: linear-gradient(145deg, var(--primary-3), rgba(232,248,239,.9));
  border: 1px solid rgba(255,255,255,.72);
  text-align: center;
}
.bmi-value { font-size: 2.75rem; line-height: .95; font-weight: 950; letter-spacing: -.07em; color: var(--ink); }
.bmi-category { font-size: 1rem; color: var(--text); margin-top: 7px; font-weight: 900; }
.bmi-info { font-size: .82rem; color: var(--muted); margin-top: 8px; font-weight: 750; }
.hint { font-size: .8rem; color: var(--muted); margin-top: 5px; font-weight: 700; }

/* ===== FORMS ===== */
.input-field {
  width: 100%;
  min-height: 48px;
  padding: 12px 14px;
  border: 1px solid rgba(37,27,55,.12);
  border-radius: 17px;
  background: rgba(255,255,255,.86);
  color: var(--ink);
  font-size: .97rem;
  font-weight: 750;
  outline: none;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.88), 0 1px 2px rgba(30,22,45,.03);
  transition: border-color .18s ease, box-shadow .18s ease, background .18s ease;
  -webkit-appearance: none;
  appearance: none;
}
.input-field::placeholder { color: var(--muted-2); font-weight: 700; }
.input-field:focus {
  border-color: rgba(124,58,237,.56);
  background: #fff;
  box-shadow: 0 0 0 5px rgba(124,58,237,.10), inset 0 1px 0 rgba(255,255,255,.88);
}
select.input-field { cursor: pointer; }
.form-row { display: flex; gap: 10px; margin-bottom: 10px; }
.form-group { flex: 1; display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; min-width: 0; }
.form-group label { font-size: .78rem; color: var(--muted); font-weight: 900; padding-left: 2px; }

/* ===== BUTTONS ===== */
.btn-primary,
.btn-secondary {
  min-height: 50px;
  padding: 13px 18px;
  border-radius: 17px;
  cursor: pointer;
  font-size: .97rem;
  font-weight: 950;
  transition: transform .18s ease, box-shadow .18s ease, background .18s ease, border-color .18s ease;
}
.btn-primary {
  color: #fff;
  border: 1px solid rgba(255,255,255,.12);
  background: linear-gradient(145deg, var(--primary), #6d28d9);
  box-shadow: 0 16px 28px rgba(124,58,237,.26);
}
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 20px 34px rgba(124,58,237,.34); }
.btn-primary:active { transform: scale(.985); }
.btn-secondary {
  color: var(--ink);
  border: 1px solid rgba(37,27,55,.12);
  background: rgba(255,255,255,.84);
  box-shadow: var(--shadow-xs);
}
.btn-secondary:hover { transform: translateY(-2px); background: var(--primary-3); box-shadow: var(--shadow-sm); }
.btn-secondary:active { transform: scale(.985); }
.btn-full { width: 100%; }

/* ===== MODAL ===== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 220;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 16px 16px var(--safe-bottom);
  background: rgba(21, 16, 32, .48);
  backdrop-filter: blur(14px);
}
.modal.hidden { display: none; }
.modal-content {
  width: min(100%, 520px);
  max-height: min(86vh, 720px);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 22px;
  border-radius: 32px 32px 0 0;
  background: rgba(255,255,255,.96);
  border: 1px solid rgba(255,255,255,.70);
  box-shadow: 0 -18px 50px rgba(14,10,24,.24);
}
.modal-content h3 { color: var(--ink); font-size: 1.22rem; font-weight: 950; text-align: center; letter-spacing: -.035em; }
.modal-btns { display: flex; gap: 10px; margin-top: 2px; }
.modal-btns button { flex: 1; }

/* ===== MOOD PICKER ===== */
.mood-picker { display: grid; grid-template-columns: repeat(4, 1fr); gap: 9px; }
.mood-btn {
  min-height: 54px;
  border: 1px solid var(--line);
  border-radius: 18px;
  cursor: pointer;
  padding: 8px;
  background: rgba(248,247,255,.9);
  font-size: 1.65rem;
  transition: transform .18s ease, background .18s ease, box-shadow .18s ease, border-color .18s ease;
}
.mood-btn:hover { transform: translateY(-2px); background: #fff; box-shadow: var(--shadow-xs); }
.mood-btn.active { border-color: rgba(124,58,237,.46); background: var(--primary-3); box-shadow: 0 0 0 5px rgba(124,58,237,.10); }

/* ===== TOAST / MISC ===== */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(98px + var(--safe-bottom));
  transform: translateX(-50%);
  z-index: 300;
  max-width: min(92vw, 480px);
  padding: 13px 18px;
  border-radius: 999px;
  background: rgba(18,17,23,.94) !important;
  color: white;
  font-size: .9rem;
  font-weight: 850;
  box-shadow: var(--shadow-nav);
  backdrop-filter: blur(18px);
}
.toast.toast-error { background: rgba(239,68,68,.94) !important; }
.toast.hidden { display: none; }
.error-msg, .msg {
  padding: 11px 12px;
  border-radius: 16px;
  font-size: .9rem;
  text-align: center;
  font-weight: 800;
}
.error-msg, .msg-err { background: var(--red-soft); color: #b91c1c; }
.msg-ok { background: var(--green-soft); color: #117845; }
.loading {
  padding: 22px;
  text-align: center;
  color: var(--muted);
  font-weight: 850;
  border-radius: var(--radius-md);
  background: rgba(255,255,255,.50);
  border: 1px dashed var(--line-strong);
}

/* ===== SMALL PHONES ===== */
@media (max-width: 420px) {
  #main-content { padding-left: 12px; padding-right: 12px; }
  .topbar { width: calc(100% - 24px); }
  .topbar-user { display: none; }
  .cards-row { gap: 10px; }
  .card { min-height: 112px; padding: 14px; border-radius: 24px; }
  .quick-actions { gap: 9px; }
  .qa-btn { padding: 12px; font-size: .82rem; }
  .form-row { flex-direction: column; gap: 0; }
  .barcode-input-row { flex-direction: column; }
  .activity-item, .food-result { align-items: flex-start; }
  .activity-kcal, .food-result-kcal { margin-top: 3px; }
  .nav-btn { font-size: .58rem; }
  .nav-btn span:first-child { font-size: 1.04rem; }
}

/* ===== TABLET / DESKTOP APP ===== */
@media (min-width: 768px) {
  #main-content { width: min(100%, 760px); }
  .cards-row { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .quick-actions { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .diary-row { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .modal { align-items: center; padding: 24px; }
  .modal-content { border-radius: var(--radius-xl); box-shadow: var(--shadow-md); }
}

@media (min-width: 1024px) {
  body {
    background:
      radial-gradient(circle at 8% 8%, rgba(255,255,255,.75) 0 14rem, transparent 14.5rem),
      radial-gradient(circle at 88% 10%, rgba(167,139,250,.36) 0 21rem, transparent 21.5rem),
      radial-gradient(circle at 86% 84%, rgba(52,211,153,.20) 0 22rem, transparent 22.5rem),
      linear-gradient(135deg, #eee9ff, #f7f4ff 50%, #f2fff7);
  }

  #page-app.page.active {
    min-height: 100dvh;
    width: min(100%, 1210px);
    margin: 0 auto;
    padding: 24px;
    display: grid;
    grid-template-columns: 104px minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas:
      "nav top"
      "nav main";
    gap: 20px;
  }

  .topbar {
    grid-area: top;
    position: sticky;
    top: 24px;
    width: 100%;
    max-width: none;
    margin: 0;
    min-height: 72px;
    padding: 14px 18px;
    border-radius: 32px;
  }
  .topbar-left { font-size: 1.18rem; }
  .topbar-logo { width: 44px; height: 44px; border-radius: 17px; }
  .topbar-user { max-width: 220px; font-size: .86rem; padding: 9px 14px; }
  .icon-btn { width: 44px; height: 44px; border-radius: 17px; }

  #main-content {
    grid-area: main;
    width: 100%;
    max-width: none;
    padding: 0 0 36px;
  }

  .bottom-nav {
    grid-area: nav;
    position: sticky;
    top: 24px;
    left: auto;
    bottom: auto;
    transform: none;
    width: 104px;
    max-width: none;
    min-height: calc(100dvh - 48px);
    grid-template-columns: 1fr;
    grid-auto-rows: min-content;
    align-self: start;
    justify-self: stretch;
    border-radius: 36px;
    padding: 14px;
    background: rgba(18,17,23,.92);
  }
  .nav-btn {
    min-height: 76px;
    border-radius: 26px;
    font-size: .72rem;
    gap: 6px;
  }
  .nav-btn span:first-child { font-size: 1.34rem; }

  .section.active { animation-duration: .24s; }
  #section-dashboard.active {
    display: grid;
    grid-template-columns: minmax(0, 1.35fr) minmax(340px, .9fr);
    grid-auto-rows: min-content;
    gap: 18px;
    align-items: start;
  }
  #section-dashboard .date-nav { grid-column: 1 / -1; margin: 0; }
  #section-dashboard .cards-row { grid-column: 1 / -1; margin: 0; }
  #section-dashboard .status-bar { grid-column: 1; margin: 0; min-height: 92px; justify-content: flex-start; text-align: left; padding: 22px; }
  #section-dashboard .ring-container { grid-column: 2; grid-row: 3 / span 2; margin: 0; min-height: 265px; }
  #section-dashboard .quick-actions { grid-column: 1; margin: 0; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #section-dashboard > .section-title { grid-column: 1 / -1; margin: 6px 2px -4px; }
  #dash-meals-preview { grid-column: 1; }
  #dash-activities-preview { grid-column: 2; }

  .section:not(#section-dashboard) {
    max-width: 930px;
  }
  #section-add-product { max-width: 980px; }
  .section-header { margin-top: 2px; }
  .cards-row { gap: 16px; }
  .quick-actions { gap: 14px; }
  .ring { width: 190px; height: 190px; }
  #ring-pct { font-size: 2.45rem; }
  .meal-card, .activity-item, .diary-entry, .add-meal-form, .add-activity-form, .settings-form { margin-bottom: 16px; }
  .meal-items { padding: 8px 16px 6px; }
  .meal-item { padding: 12px 0; }
  .food-result { padding: 14px; }
  .tabs { max-width: 600px; }
  .toast { bottom: 28px; }
}

@media (min-width: 1280px) {
  #page-app.page.active { width: min(100%, 1280px); grid-template-columns: 112px minmax(0, 1fr); }
  .bottom-nav { width: 112px; }
  #section-dashboard.active { grid-template-columns: minmax(0, 1.45fr) minmax(380px, .9fr); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: .01ms !important;
  }
}

/* Form cards reuse the .card class in the original HTML; keep them clean. */
.add-activity-form.card,
.settings-form.card {
  min-height: auto;
  overflow: visible;
}
.add-activity-form.card::after,
.settings-form.card::after { display: none; }

/* =========================================================
   PATCH: bottom nav everywhere + custom calendar + AI chat
   ========================================================= */
.date-btn:disabled,
.date-btn[aria-disabled="true"] {
  opacity: .34;
  cursor: not-allowed;
  pointer-events: none;
  transform: none !important;
}
.date-label,
.date-small[role="button"] {
  cursor: pointer;
  user-select: none;
}
.date-label::after,
.date-small[role="button"]::after {
  content: "  📅";
  font-size: .92em;
  opacity: .72;
}

/* Always keep the navigation as a premium bottom dock, also on PC. */
@media (min-width: 1024px) {
  #page-app.page.active {
    display: block;
    width: min(100%, 1180px);
    margin: 0 auto;
    padding: 24px 24px 0;
  }

  .topbar {
    position: sticky;
    top: 18px;
    width: min(100%, 980px);
    max-width: 980px;
    margin: 0 auto 20px;
  }

  #main-content {
    width: min(100%, 980px);
    max-width: 980px;
    margin: 0 auto;
    padding: 0 0 calc(158px + var(--safe-bottom));
  }

  .bottom-nav {
    position: fixed;
    left: 50%;
    right: auto;
    bottom: calc(18px + var(--safe-bottom));
    top: auto;
    transform: translateX(-50%);
    width: min(520px, calc(100% - 48px));
    max-width: 520px;
    min-height: 70px;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    grid-auto-rows: auto;
    align-self: auto;
    justify-self: auto;
    border-radius: 999px;
    padding: 9px;
  }

  .nav-btn {
    min-height: 52px;
    border-radius: 999px;
    font-size: .68rem;
    gap: 2px;
  }

  .nav-btn span:first-child { font-size: 1.18rem; }
  .toast { bottom: calc(106px + var(--safe-bottom)); }
}

@media (min-width: 1280px) {
  #page-app.page.active { width: min(100%, 1220px); }
  .bottom-nav { width: min(540px, calc(100% - 48px)); }
}

/* ===== CUSTOM CALENDAR ===== */
.calendar-modal { z-index: 260; }
.calendar-content {
  gap: 16px;
  overflow: hidden;
}
.calendar-head {
  display: grid;
  grid-template-columns: 48px 1fr 48px;
  align-items: center;
  gap: 10px;
}
.calendar-head h3 {
  margin: 0;
  text-align: center;
  font-size: 1.22rem;
}
.calendar-month-btn {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  font-size: 1.8rem;
  line-height: 1;
  box-shadow: var(--shadow-xs);
  transition: transform .18s ease, background .18s ease, opacity .18s ease;
}
.calendar-month-btn:hover { transform: translateY(-2px); background: var(--primary-3); }
.calendar-month-btn:disabled {
  opacity: .32;
  cursor: not-allowed;
  transform: none;
}
.calendar-weekdays,
.calendar-days {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 8px;
}
.calendar-weekdays span {
  text-align: center;
  color: var(--muted);
  font-size: .74rem;
  font-weight: 950;
  text-transform: uppercase;
}
.calendar-day {
  aspect-ratio: 1 / 1;
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 16px;
  background: rgba(248,247,255,.82);
  color: var(--ink);
  cursor: pointer;
  font-weight: 950;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.78);
  transition: transform .16s ease, background .16s ease, box-shadow .16s ease, border-color .16s ease;
}
.calendar-day:hover:not(:disabled) {
  transform: translateY(-2px);
  background: #fff;
  border-color: rgba(124,58,237,.22);
  box-shadow: var(--shadow-xs);
}
.calendar-day.today {
  border-color: rgba(24,166,92,.28);
  background: var(--green-soft);
  color: #117845;
}
.calendar-day.selected {
  background: linear-gradient(145deg, var(--primary), #6d28d9);
  border-color: rgba(255,255,255,.5);
  color: #fff;
  box-shadow: 0 14px 24px rgba(124,58,237,.28);
}
.calendar-day.disabled {
  opacity: .25;
  cursor: not-allowed;
  box-shadow: none;
}
.calendar-empty {
  display: block;
  min-height: 42px;
}

/* ===== AI CHAT: Messenger-style floating panel ===== */
.ai-chat-fab {
  position: fixed;
  left: 50%;
  bottom: calc(94px + var(--safe-bottom));
  transform: translateX(-50%);
  z-index: 190;
  width: 64px;
  height: 64px;
  display: grid;
  place-items: center;
  border: 2px solid rgba(255,255,255,.86);
  border-radius: 999px;
  background: radial-gradient(circle at 32% 24%, #fff 0 16%, transparent 17%), linear-gradient(145deg, #8b5cf6, #6d28d9);
  color: #fff;
  box-shadow: 0 20px 42px rgba(88, 28, 135, .35);
  cursor: pointer;
  font-size: 1.72rem;
  transition: transform .2s ease, opacity .2s ease, box-shadow .2s ease;
}
.ai-chat-fab:hover { transform: translateX(-50%) translateY(-4px); box-shadow: 0 24px 52px rgba(88, 28, 135, .42); }
.ai-chat-fab:active { transform: translateX(-50%) scale(.96); }
.ai-chat-fab.active {
  opacity: 0;
  pointer-events: none;
}
.ai-chat-panel {
  position: fixed;
  left: 50%;
  bottom: calc(96px + var(--safe-bottom));
  transform: translateX(-50%);
  z-index: 185;
  width: min(420px, calc(100% - 24px));
  height: min(560px, calc(100dvh - 128px));
  display: grid;
  grid-template-rows: auto 1fr auto;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,.72);
  border-radius: 30px;
  background: rgba(255,255,255,.96);
  box-shadow: 0 28px 80px rgba(18, 17, 23, .24);
  backdrop-filter: blur(24px) saturate(150%);
  animation: aiPanelIn .22s cubic-bezier(.2,.8,.2,1) both;
}
.ai-chat-panel.hidden { display: none; }
@keyframes aiPanelIn {
  from { opacity: 0; transform: translateX(-50%) translateY(18px) scale(.98); }
  to { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
}
.ai-chat-head {
  display: grid;
  grid-template-columns: 48px 1fr 38px;
  align-items: center;
  gap: 12px;
  padding: 14px;
  color: #fff;
  background: linear-gradient(145deg, #111016, #2c1d48 58%, #6d28d9);
}
.ai-chat-avatar {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 18px;
  background: rgba(255,255,255,.16);
  border: 1px solid rgba(255,255,255,.18);
  font-size: 1.45rem;
}
.ai-chat-title { font-weight: 950; letter-spacing: -.025em; }
.ai-chat-status { margin-top: 2px; color: rgba(255,255,255,.68); font-size: .78rem; font-weight: 750; }
.ai-chat-close {
  width: 38px;
  height: 38px;
  border: none;
  border-radius: 14px;
  background: rgba(255,255,255,.12);
  color: #fff;
  cursor: pointer;
  font-size: 1.5rem;
  line-height: 1;
}
.ai-chat-messages {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  overflow-y: auto;
  padding: 16px;
  background: linear-gradient(180deg, rgba(248,247,255,.88), rgba(255,255,255,.98));
}
.ai-msg {
  max-width: 82%;
  padding: 11px 13px;
  border-radius: 20px;
  font-size: .92rem;
  line-height: 1.35;
  font-weight: 750;
  box-shadow: var(--shadow-xs);
}
.ai-msg-bot {
  align-self: flex-start;
  border-bottom-left-radius: 8px;
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--line);
}
.ai-msg-user {
  align-self: flex-end;
  border-bottom-right-radius: 8px;
  color: #fff;
  background: linear-gradient(145deg, var(--primary), #6d28d9);
}
.ai-chat-input-row {
  display: grid;
  grid-template-columns: 1fr 46px;
  gap: 10px;
  padding: 12px;
  background: #fff;
  border-top: 1px solid var(--line);
}
.ai-chat-input-row input {
  min-width: 0;
  height: 46px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 15px;
  background: var(--surface-soft);
  color: var(--ink);
  outline: none;
  font-weight: 750;
}
.ai-chat-input-row input:focus { border-color: rgba(124,58,237,.44); box-shadow: 0 0 0 4px rgba(124,58,237,.10); }
.ai-chat-input-row button {
  width: 46px;
  height: 46px;
  border: none;
  border-radius: 999px;
  color: #fff;
  background: linear-gradient(145deg, var(--primary), #6d28d9);
  cursor: pointer;
  font-weight: 950;
  box-shadow: 0 12px 22px rgba(124,58,237,.26);
}

@media (max-width: 420px) {
  .ai-chat-fab { width: 58px; height: 58px; bottom: calc(88px + var(--safe-bottom)); }
  .ai-chat-panel {
    width: calc(100% - 18px);
    height: min(520px, calc(100dvh - 116px));
    bottom: calc(88px + var(--safe-bottom));
    border-radius: 26px;
  }
  .calendar-weekdays, .calendar-days { gap: 6px; }
  .calendar-day { min-height: 38px; border-radius: 14px; }
}

/* =========================================================
   PATCH v3: search polish, password spacing, AI button right
   ========================================================= */
.search-hint {
  margin-top: 10px;
  padding: 12px 14px;
  border: 1px dashed rgba(124,58,237,.22);
  border-radius: 18px;
  color: var(--muted);
  background: rgba(255,255,255,.58);
  font-size: .86rem;
  font-weight: 750;
  line-height: 1.35;
}

.settings-password-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.settings-password-card .form-title { margin-bottom: 2px; }
.settings-password-card .input-field { margin: 0; }
.settings-password-card .btn-full { margin-top: 2px; }

.ai-chat-fab {
  left: auto !important;
  right: max(18px, calc((100vw - 980px) / 2 + 18px));
  transform: none !important;
}
.ai-chat-fab:hover { transform: translateY(-4px) !important; }
.ai-chat-fab:active { transform: scale(.96) !important; }
.ai-chat-panel {
  left: auto !important;
  right: max(12px, calc((100vw - 980px) / 2 + 12px));
  transform: none !important;
}
@keyframes aiPanelIn {
  from { opacity: 0; transform: translateY(18px) scale(.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
@media (max-width: 420px) {
  .ai-chat-fab {
    right: 16px !important;
    bottom: calc(88px + var(--safe-bottom));
  }
  .ai-chat-panel {
    right: 9px !important;
    width: calc(100% - 18px);
  }
}


/* =========================================================
   PATCH v4: outdoor training + smartwatch entry
   ========================================================= */
.activity-favorites {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}
.activity-fav {
  display: grid;
  grid-template-columns: 42px 1fr;
  grid-template-rows: auto auto;
  align-items: center;
  column-gap: 10px;
  min-height: 74px;
  padding: 10px 12px;
  border: 1px solid rgba(37,27,55,.10);
  border-radius: 22px;
  background: rgba(255,255,255,.78);
  color: var(--ink);
  cursor: pointer;
  text-align: left;
  box-shadow: var(--shadow-xs);
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}
.activity-fav:hover {
  transform: translateY(-2px);
  border-color: rgba(124,58,237,.30);
  box-shadow: 0 14px 30px rgba(34, 26, 51, .10);
}
.activity-fav span {
  grid-row: 1 / span 2;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 16px;
  background: rgba(248,247,255,.95);
  font-size: 1.28rem;
}
.activity-fav strong {
  font-size: .94rem;
  font-weight: 950;
  letter-spacing: -.02em;
}
.activity-fav small {
  margin-top: 2px;
  color: var(--muted);
  font-size: .72rem;
  font-weight: 800;
}
.activity-fav-primary {
  background: linear-gradient(145deg, rgba(255,255,255,.92), rgba(238,232,255,.88));
  border-color: rgba(124,58,237,.22);
}
.activity-fav-primary span {
  background: linear-gradient(145deg, var(--primary), #6d28d9);
  color: #fff;
  box-shadow: 0 10px 20px rgba(124,58,237,.22);
}
.activity-selected-hint {
  margin: 10px 0 12px;
  padding: 10px 12px;
  border-radius: 16px;
  color: var(--muted);
  background: rgba(248,247,255,.72);
  border: 1px solid var(--line);
  font-size: .82rem;
  font-weight: 750;
  line-height: 1.35;
}
.activity-selected-hint.is-outdoor {
  color: #5b21b6;
  border-color: rgba(124,58,237,.22);
  background: linear-gradient(145deg, rgba(245,243,255,.92), rgba(255,255,255,.76));
}
.smartwatch-card {
  margin: 16px 0;
  text-align: left;
  border: 1px solid rgba(124,58,237,.14);
  background: linear-gradient(145deg, rgba(255,255,255,.92), rgba(248,247,255,.78));
}
.smartwatch-card.card::after { display: none; }
.smartwatch-head {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 12px;
}
.smartwatch-icon {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 20px;
  color: #fff;
  background: linear-gradient(145deg, #111016, #6d28d9);
  box-shadow: 0 14px 28px rgba(88,28,135,.20);
  font-size: 1.45rem;
}
.smartwatch-head .form-title {
  margin-bottom: 3px;
}
.smartwatch-head p {
  color: var(--muted);
  font-size: .82rem;
  font-weight: 750;
  line-height: 1.35;
}
.smartwatch-save { margin-top: 10px; }

@media (max-width: 420px) {
  .activity-favorites { grid-template-columns: 1fr; }
  .smartwatch-head { align-items: flex-start; }
}

/* ===== PATCH v5: portions, AI admin/chat, auto kcal, sharper modals ===== */
.modal {
  background: rgba(20, 16, 32, .72) !important;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
}
.modal-content {
  background: #fff !important;
  color: var(--ink);
}
.qty-product-img {
  width: 92px;
  height: 92px;
  object-fit: cover;
  border-radius: 22px;
  display: block;
  margin: 0 auto;
  box-shadow: var(--shadow-xs);
}
.unit-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 5px;
  border-radius: 18px;
  background: rgba(17,16,22,.06);
}
.unit-btn {
  border: none;
  border-radius: 14px;
  padding: 10px 12px;
  color: var(--muted);
  background: transparent;
  font-weight: 900;
  cursor: pointer;
}
.unit-btn.active {
  color: #fff;
  background: linear-gradient(145deg, var(--ink), #2c1d48);
  box-shadow: var(--shadow-xs);
}
.qty-serving-hint {
  padding: 10px 12px;
  border: 1px solid rgba(124,58,237,.18);
  border-radius: 16px;
  background: rgba(124,58,237,.08);
  color: var(--muted);
  font-weight: 750;
  font-size: .88rem;
}
.serving-pill {
  display: inline-flex;
  align-items: center;
  max-width: 220px;
  margin-left: 6px;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(124,58,237,.10);
  color: #6d28d9;
  font-size: .68rem;
  font-weight: 900;
  vertical-align: middle;
}
.auto-kcal-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 10px 0 2px;
  padding: 12px;
  border-radius: 18px;
  background: rgba(124,58,237,.08);
  border: 1px solid rgba(124,58,237,.14);
  color: var(--muted);
  font-size: .88rem;
  font-weight: 800;
}
.mini-btn {
  flex: 0 0 auto;
  border: none;
  border-radius: 999px;
  padding: 9px 14px;
  color: #fff;
  background: linear-gradient(145deg, var(--primary), #6d28d9);
  font-weight: 950;
  cursor: pointer;
  box-shadow: 0 12px 24px rgba(124,58,237,.22);
}
.admin-ai-card {
  border: 1px solid rgba(124,58,237,.18) !important;
  background: linear-gradient(180deg, rgba(255,255,255,.96), rgba(248,245,255,.94)) !important;
}
.admin-key-textarea {
  min-height: 96px;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .88rem;
}
.settings-password-card input + input,
.settings-password-card input + button,
.settings-password-card .input-field + .input-field,
.settings-password-card .input-field + .btn-secondary {
  margin-top: 12px;
}
.ai-chat-fab {
  left: auto !important;
  right: max(22px, calc((100vw - 900px) / 2 + 22px)) !important;
  transform: none !important;
}
.ai-chat-fab:hover { transform: translateY(-4px) !important; }
.ai-chat-fab:active { transform: scale(.96) !important; }
.ai-chat-panel {
  left: auto !important;
  right: max(14px, calc((100vw - 900px) / 2 + 14px)) !important;
  transform: none !important;
  background: #fff !important;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
}
@keyframes aiPanelIn {
  from { opacity: 0; transform: translateY(18px) scale(.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.ai-chat-input-row {
  grid-template-columns: auto 1fr auto;
}
.ai-file-btn {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 16px;
  background: rgba(124,58,237,.10);
  color: #6d28d9;
  font-weight: 950;
  cursor: pointer;
}
.ai-attachment-preview {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 8px 12px 0;
  padding: 8px 10px;
  border-radius: 14px;
  background: rgba(124,58,237,.08);
  color: var(--muted);
  font-size: .82rem;
  font-weight: 800;
}
.ai-attachment-preview button {
  width: 24px;
  height: 24px;
  border: none;
  border-radius: 999px;
  background: rgba(17,16,22,.10);
  cursor: pointer;
}
.ai-action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}
.ai-action-btn,
.ai-product-card button,
.ai-meal-choice {
  border: none;
  border-radius: 999px;
  padding: 9px 12px;
  background: linear-gradient(145deg, var(--primary), #6d28d9);
  color: #fff;
  font-weight: 950;
  cursor: pointer;
  box-shadow: 0 10px 20px rgba(124,58,237,.20);
}
.ai-product-cards {
  display: grid;
  gap: 9px;
  padding: 0 12px 12px;
}
.ai-product-card {
  display: grid;
  grid-template-columns: 48px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: 18px;
  background: #fff;
  border: 1px solid rgba(37,27,55,.08);
  box-shadow: var(--shadow-xs);
}
.ai-product-card img,
.ai-product-img-placeholder {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  object-fit: cover;
  display: grid;
  place-items: center;
  background: var(--primary-3);
}
.ai-product-main { min-width: 0; display: grid; gap: 2px; }
.ai-product-main strong { font-size: .88rem; line-height: 1.1; }
.ai-product-main span,
.ai-product-main small { color: var(--muted); font-size: .74rem; font-weight: 750; }
.ai-picked-product {
  display: grid;
  gap: 3px;
  padding: 12px;
  border-radius: 18px;
  background: rgba(124,58,237,.08);
}
.ai-picked-product small { color: var(--muted); font-weight: 800; }
.ai-meal-picker-list { display: grid; gap: 8px; }
.ai-meal-choice {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  border-radius: 18px;
  padding: 12px 14px;
  text-align: left;
}
.ai-meal-choice small { opacity: .8; }
.ai-meal-create {
  background: rgba(124,58,237,.10);
  color: #6d28d9;
  box-shadow: none;
}
.ai-meal-subtitle {
  margin-top: 6px;
  color: var(--muted);
  font-weight: 950;
  font-size: .82rem;
}
@media (max-width: 560px) {
  .ai-chat-fab {
    right: 18px !important;
    bottom: calc(92px + var(--safe-bottom));
  }
  .ai-chat-panel {
    right: 10px !important;
    width: calc(100% - 20px);
  }
  .auto-kcal-box { align-items: flex-start; flex-direction: column; }
  .mini-btn { width: 100%; }
}
