/* === Tokens === */
:root {
  --bg: #f5efe4;
  --bg-2: #ede5d4;
  --paper: #fbf7ef;
  --paper-2: #ffffff;
  --ink: #1a1814;
  --ink-2: #36322a;
  --muted: #8a8273;
  --muted-2: #948876;
  --line: #e3dccb;
  --line-strong: #cfc6b1;

  --sage: #4a5d3e;
  --sage-soft: #e8ecdf;
  --terra: #c46f4d;
  --terra-soft: #f4e4d8;
  --amber: #c4924d;
  --amber-soft: #f4e8d2;
  --plum: #6b4f63;
  --plum-soft: #ecdfe8;
  --ink-soft: #f0ebde;

  /* Macro palette */
  --m-cal: #1a1814;
  --m-pro: #c46f4d;
  --m-carb: #c4924d;
  --m-fat: #4a5d3e;

  --display: "Instrument Serif", "Cormorant Garamond", "Times New Roman", serif;
  --sans: "DM Sans", system-ui, -apple-system, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;

  --r-sm: 6px;
  --r-md: 12px;
  --r-lg: 18px;
  --r-xl: 28px;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, textarea, select { font-family: inherit; color: inherit; }

/* Meadow links — clean by default; rich-text regions (.stretched-content) can
   opt back into the underline so embedded URLs stay discoverable. */
a { color: inherit; text-decoration: none; }
a:hover, a:focus, a:active, a:visited { text-decoration: none; }
.stretched-content a { color: var(--sage); text-decoration: underline; text-underline-offset: 2px; }
.stretched-content a:hover { color: var(--ink); }

/* Default icon sizing — SVG sprite refs need explicit dimensions or they render at default 300×150. */
.ico { width: 14px; height: 14px; flex-shrink: 0; display: inline-block; vertical-align: text-bottom; }
.btn .ico, .btn-icon .ico, .suggest-pill .ico, .pill .ico { width: 14px; height: 14px; }
.ai-input .send .ico { width: 14px; height: 14px; }
.btn-sm .ico { width: 12px; height: 12px; }

/* Loading spinner — used by lock overlays, vision uploads, async modals. */
@keyframes m-spin { to { transform: rotate(360deg); } }
.m-spinner {
  display: inline-block;
  width: 28px; height: 28px;
  border: 2px solid var(--line);
  border-top-color: var(--ink);
  border-radius: 50%;
  animation: m-spin 0.9s linear infinite;
  vertical-align: middle;
}
.m-spinner.sm { width: 16px; height: 16px; border-width: 2px; }
.m-spinner.lg { width: 44px; height: 44px; border-width: 3px; }
.m-loading {
  text-align: center;
  padding: 40px 0;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.06em;
}
.m-loading .m-spinner { display: block; margin: 0 auto 14px; }

/* === Typography === */
.display { font-family: var(--display); font-weight: 400; letter-spacing: -0.01em; line-height: 1.02; }
.eyebrow {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 500;
}
.num { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }

/* === App shell === */
.app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 232px 1fr;
}
.app[data-layout="topnav"] { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
.app[data-layout="split"] { grid-template-columns: 232px 1fr 360px; }

/* === Sidebar === */
.sidebar {
  background: var(--bg);
  border-right: 1px solid var(--line);
  padding: 28px 18px 24px;
  display: flex;
  flex-direction: column;
  gap: 28px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 6px; }
.brand-mark {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--ink);
  color: var(--bg);
  display: grid; place-items: center;
  font-family: var(--display); font-size: 16px;
}
.brand-name { font-family: var(--display); font-size: 20px; letter-spacing: -0.01em; }
.brand-sub { font-family: var(--mono); font-size: 9.5px; letter-spacing: 0.18em; color: var(--muted); text-transform: uppercase; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-section { font-family: var(--mono); font-size: 10px; letter-spacing: 0.16em; color: var(--muted-2); text-transform: uppercase; padding: 12px 10px 6px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: 10px;
  font-size: 13.5px; color: var(--ink-2);
  text-align: left; width: 100%;
  text-decoration: none;
  transition: background .15s;
}
.nav-item:hover { background: var(--ink-soft); text-decoration: none; }
.nav-item:focus, .nav-item:active, .nav-item:visited { text-decoration: none; }
.nav-item.active { background: var(--ink); color: var(--paper); }
.sidebar a, .sidebar a:hover, .sidebar a:focus, .sidebar a:active, .sidebar a:visited,
.m-topbar a, .m-topbar a:hover, .m-topbar a:focus, .m-topbar a:active { text-decoration: none; }
.nav-item .ico { width: 16px; height: 16px; flex-shrink: 0; }
.nav-item .badge { margin-left: auto; font-family: var(--mono); font-size: 10px; opacity: .7; }
.nav-item.active .badge { opacity: .9; }

.user-card {
  margin-top: auto;
  display: flex; align-items: center; gap: 10px;
  padding: 10px; border-radius: 12px;
  background: var(--paper);
  border: 1px solid var(--line);
}
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: linear-gradient(135deg, #d4b896, #a37e5a);
  color: var(--paper); display: grid; place-items: center;
  font-family: var(--display); font-size: 14px;
  flex-shrink: 0;
}
.user-card .name { font-size: 13px; font-weight: 500; }
.user-card .meta { font-size: 11px; color: var(--muted); }

/* === Top nav variant === */
.topnav {
  display: none;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  padding: 14px 32px;
  align-items: center;
  gap: 28px;
  position: sticky; top: 0; z-index: 20;
}
.app[data-layout="topnav"] .sidebar { display: none; }
.app[data-layout="topnav"] .topnav { display: flex; }
.topnav .nav { flex-direction: row; gap: 2px; flex: 1; }
.topnav .nav-item { padding: 7px 12px; }
.topnav .nav-section { display: none; }
.topnav .user-card { margin: 0; padding: 6px 10px 6px 6px; }
.topnav .brand-sub { display: none; }

/* === Main === */
.main {
  padding: 36px 48px 80px;
  max-width: 1280px;
  width: 100%;
  margin: 0 auto;
}
.app[data-layout="split"] .main { padding: 36px 36px 80px; max-width: none; }

.page-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 24px; margin-bottom: 32px;
}
.page-head .left { flex: 1; }
.page-head h1 { font-family: var(--display); font-size: 64px; margin: 6px 0 0; line-height: 1; }
.page-head h1 em { font-style: italic; color: var(--terra); }
.page-head .sub { color: var(--muted); margin-top: 12px; max-width: 520px; }

/* === Buttons === */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 9px 14px; border-radius: 999px;
  font-size: 13px; font-weight: 500;
  border: 1px solid transparent;
  transition: all .15s;
  white-space: nowrap;
  text-decoration: none;
}
.btn:hover, .btn:focus, .btn:active, .btn:visited { text-decoration: none; }
.btn-primary { background: var(--ink); color: var(--paper); }
.btn-primary:hover { background: #2c2820; }
.btn-ghost { color: var(--ink-2); border-color: var(--line-strong); background: transparent; }
.btn-ghost:hover { background: var(--paper); }
.btn-soft { background: var(--paper); color: var(--ink); border-color: var(--line); }
.btn-soft:hover { border-color: var(--line-strong); }
.btn-sm { padding: 6px 10px; font-size: 12px; }
.btn-icon {
  width: 34px; height: 34px; padding: 0;
  border-radius: 50%; display: grid; place-items: center;
  border: 1px solid var(--line);
  background: var(--paper);
}
.btn-icon:hover { border-color: var(--line-strong); }

/* === Cards === */
.card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
}
.card-pad { padding: 22px; }
.card-head {
  display: flex; align-items: baseline; justify-content: space-between;
  padding: 18px 22px 0; gap: 12px;
}
.card-title { font-family: var(--display); font-size: 22px; }
.card-eyebrow { font-family: var(--mono); font-size: 10px; letter-spacing: 0.16em; color: var(--muted); text-transform: uppercase; }

/* === Pills === */
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 9px; border-radius: 999px;
  font-size: 11px; font-weight: 500;
  background: var(--ink-soft); color: var(--ink-2);
}
.pill-sage { background: var(--sage-soft); color: var(--sage); }
.pill-terra { background: var(--terra-soft); color: var(--terra); }
.pill-amber { background: var(--amber-soft); color: #8d6629; }
.pill-plum { background: var(--plum-soft); color: var(--plum); }
.pill-outline { background: transparent; border: 1px solid var(--line-strong); color: var(--muted); }

/* AI marker - very subtle */
.ai-mark {
  display: inline-flex; align-items: center; gap: 5px;
  font-family: var(--mono); font-size: 9.5px; letter-spacing: 0.14em;
  color: var(--muted); text-transform: uppercase;
}
.ai-mark::before {
  content: ""; width: 5px; height: 5px; border-radius: 50%;
  background: var(--sage);
}

/* === Macro rings === */
.macro-ring { position: relative; }
.macro-ring svg { display: block; transform: rotate(-90deg); }
.macro-ring .center {
  position: absolute; inset: 0; display: grid; place-items: center;
  text-align: center;
}
.macro-ring .center .big { font-family: var(--display); font-size: 42px; line-height: 1; }
.macro-ring .center .small { font-family: var(--mono); font-size: 10px; letter-spacing: 0.14em; color: var(--muted); text-transform: uppercase; margin-top: 4px; }

.macro-legend { display: flex; flex-direction: column; gap: 12px; }
.macro-legend .row { display: flex; align-items: center; gap: 10px; }
.macro-legend .swatch { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }
.macro-legend .label { flex: 1; font-size: 13px; color: var(--ink-2); }
.macro-legend .val { font-family: var(--mono); font-size: 12px; }
.macro-legend .target { font-family: var(--mono); font-size: 11px; color: var(--muted); }

/* === Meal planner grid === */
.planner {
  display: grid;
  grid-template-columns: 90px repeat(7, 1fr);
  gap: 10px;
}
.planner .day-head {
  padding: 10px 4px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
}
.planner .day-head .dow { font-family: var(--mono); font-size: 10px; letter-spacing: 0.14em; color: var(--muted); text-transform: uppercase; }
.planner .day-head .num { font-family: var(--display); font-size: 32px; line-height: 1; margin-top: 2px; }
.planner .day-head.today .num { color: var(--terra); }
.planner .day-head.today .dow { color: var(--terra); }

.planner .row-label {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 4px; font-family: var(--mono); font-size: 10px;
  letter-spacing: 0.14em; color: var(--muted); text-transform: uppercase;
  border-top: 1px solid var(--line);
}
.planner .corner { border: none; }

.meal-cell {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px 11px;
  display: flex; flex-direction: column;
  gap: 6px;
  min-height: 96px;
  text-align: left;
  transition: all .15s;
  position: relative;
}
.meal-cell:hover { border-color: var(--line-strong); transform: translateY(-1px); }
.meal-cell.empty { background: transparent; border: 1px dashed var(--line-strong); color: var(--muted); justify-content: center; align-items: center; }
.meal-cell.empty:hover { border-color: var(--ink); color: var(--ink-2); }
.meal-cell .title { font-size: 12.5px; font-weight: 500; line-height: 1.3; }
.meal-cell .meta { display: flex; align-items: center; gap: 6px; font-family: var(--mono); font-size: 10px; color: var(--muted); margin-top: auto; }
.meal-cell .dot { width: 3px; height: 3px; border-radius: 50%; background: var(--muted-2); }
.meal-cell .accent { position: absolute; top: 10px; right: 10px; width: 6px; height: 6px; border-radius: 50%; }
.meal-cell.b .accent { background: var(--amber); }
.meal-cell.l .accent { background: var(--terra); }
.meal-cell.d .accent { background: var(--sage); }

/* === AI panel === */
.ai-panel {
  background: var(--paper);
  border-left: 1px solid var(--line);
  display: flex; flex-direction: column;
  height: 100vh;
  position: sticky; top: 0;
}
.ai-panel-head {
  padding: 22px 22px 14px;
  border-bottom: 1px solid var(--line);
}
.ai-panel-body { flex: 1; overflow-y: auto; padding: 22px; }
.ai-panel-foot {
  padding: 14px 18px 22px;
  border-top: 1px solid var(--line);
}

.app:not([data-layout="split"]) > .ai-panel { display: none; }

.msg { margin-bottom: 18px; }
.msg.user .bubble {
  background: var(--ink); color: var(--paper);
  margin-left: 24px; border-radius: 14px 14px 4px 14px;
}
.msg.bot .bubble {
  background: var(--bg-2); color: var(--ink);
  margin-right: 24px; border-radius: 14px 14px 14px 4px;
}
.msg .bubble { padding: 10px 14px; font-size: 13px; line-height: 1.5; }
.msg .author { font-family: var(--mono); font-size: 9.5px; letter-spacing: 0.14em; color: var(--muted); text-transform: uppercase; margin-bottom: 4px; }
.msg.user .author { text-align: right; }

.ai-input {
  display: flex; align-items: flex-end; gap: 8px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 8px 8px 8px 14px;
  transition: border-color .15s;
}
.ai-input:focus-within { border-color: var(--ink); }
.ai-input textarea {
  flex: 1; border: none; background: transparent; resize: none;
  font-size: 13px; line-height: 1.45; outline: none;
  min-height: 22px; max-height: 120px; padding: 6px 0;
}
.ai-input .send {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--ink); color: var(--paper);
  display: grid; place-items: center;
  flex-shrink: 0;
}
.ai-input .send:disabled { opacity: 0.4; }

/* === FAB AI button (when not in split layout) === */
.ai-fab {
  position: fixed; bottom: 26px; right: 26px;
  width: 52px; height: 52px; border-radius: 50%;
  background: var(--ink); color: var(--paper);
  display: grid; place-items: center;
  box-shadow: 0 8px 24px rgba(26,24,20,0.18), 0 2px 6px rgba(26,24,20,0.12);
  z-index: 30;
  transition: transform .2s;
}
.ai-fab:hover { transform: translateY(-2px); }
.app[data-layout="split"] ~ .ai-fab,
.app[data-layout="split"] .ai-fab { display: none; }

/* === Drawer (AI when not split) === */
.drawer-overlay {
  position: fixed; inset: 0; background: rgba(26,24,20,0.32);
  z-index: 40;
  opacity: 0; pointer-events: none;
  transition: opacity .2s;
}
.drawer-overlay.open { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: 420px; max-width: 92vw;
  background: var(--paper);
  border-left: 1px solid var(--line);
  z-index: 41;
  transform: translateX(100%);
  transition: transform .25s ease-out;
  display: flex; flex-direction: column;
}
.drawer.open { transform: translateX(0); }

/* === Modal === */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(26,24,20,0.45);
  z-index: 50;
  display: grid; place-items: center;
  padding: 32px;
  opacity: 0; pointer-events: none;
  transition: opacity .2s;
}
.modal-overlay.open { opacity: 1; pointer-events: auto; }
.modal {
  background: var(--paper);
  border-radius: 22px;
  width: 100%; max-width: 920px;
  max-height: 88vh;
  overflow: hidden;
  display: grid;
  grid-template-columns: 1fr 1fr;
  transform: translateY(8px);
  transition: transform .2s;
}
.modal-overlay.open .modal { transform: translateY(0); }

/* === Recipe card === */
.recipe-card {
  background: var(--paper);
  border-radius: 18px;
  overflow: hidden;
  text-align: left;
  transition: all .2s;
  display: flex; flex-direction: column;
  width: 100%;
  border: 1px solid var(--line);
}
.recipe-card:hover { transform: translateY(-2px); border-color: var(--line-strong); }
.recipe-card .img {
  aspect-ratio: 4 / 3;
  background: var(--bg-2);
  position: relative;
  overflow: hidden;
}
.recipe-card .img-grad {
  position: absolute; inset: 0;
}
.recipe-card .body { padding: 14px 16px 16px; flex: 1; display: flex; flex-direction: column; gap: 8px; }
.recipe-card .meal-tag { font-family: var(--mono); font-size: 9.5px; letter-spacing: 0.14em; color: var(--muted); text-transform: uppercase; }
.recipe-card .name { font-family: var(--display); font-size: 22px; line-height: 1.1; letter-spacing: -0.01em; }
.recipe-card .meta { display: flex; gap: 12px; font-family: var(--mono); font-size: 10.5px; color: var(--muted); margin-top: auto; padding-top: 6px; }
.recipe-card .difficulty,
.difficulty { display: inline-flex; align-items: center; gap: 5px; font-family: var(--mono); font-size: 10px; letter-spacing: 0.08em; color: var(--muted); text-transform: uppercase; }

/* === Image placeholder gradients === */
.ph-1 { background: linear-gradient(135deg, #e8a37c 0%, #c46f4d 60%, #8d4a30 100%); }
.ph-2 { background: linear-gradient(135deg, #b8c89a 0%, #6b8550 50%, #3d5230 100%); }
.ph-3 { background: linear-gradient(135deg, #f0d9a8 0%, #c4924d 60%, #8d6629 100%); }
.ph-4 { background: linear-gradient(135deg, #d4b8c4 0%, #8a5d72 50%, #4d3340 100%); }
.ph-5 { background: linear-gradient(135deg, #e8d8c0 0%, #b89a78 50%, #6b5538 100%); }
.ph-6 { background: linear-gradient(135deg, #c8d8d4 0%, #6b8a82 50%, #3d524f 100%); }
.ph-7 { background: linear-gradient(135deg, #f0c8a8 0%, #d49060 50%, #8d5530 100%); }
.ph-8 { background: linear-gradient(135deg, #d8e0b8 0%, #98a868 50%, #586830 100%); }

.ph-grain {
  position: absolute; inset: 0;
  background-image:
    radial-gradient(circle at 30% 40%, rgba(255,255,255,0.4) 0%, transparent 30%),
    radial-gradient(circle at 70% 60%, rgba(0,0,0,0.15) 0%, transparent 40%);
  mix-blend-mode: overlay;
}

/* === Stat box === */
.stat {
  padding: 18px 20px;
  border-radius: 14px;
  background: var(--paper);
  border: 1px solid var(--line);
}
.stat .lbl { font-family: var(--mono); font-size: 10px; letter-spacing: 0.14em; color: var(--muted); text-transform: uppercase; }
.stat .val { font-family: var(--display); font-size: 36px; line-height: 1.1; margin-top: 6px; }
.stat .delta { font-family: var(--mono); font-size: 11px; margin-top: 4px; }
.stat .delta.up { color: var(--sage); }
.stat .delta.down { color: var(--terra); }

/* === Sparkline === */
.spark { width: 100%; height: 36px; }

/* Mini toast — transient notification anchored top-right. */
.m-toast {
  position: fixed; top: 22px; right: 22px;
  background: var(--ink); color: var(--paper);
  padding: 10px 14px; border-radius: 10px;
  font-size: 13px; z-index: 9998;
}
.m-toast.danger { background: var(--terra); }

/* Scrollbars */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 4px; }
::-webkit-scrollbar-track { background: transparent; }

/* Focus */
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

/* Tabs */
.tabs { display: flex; gap: 2px; background: var(--bg-2); padding: 3px; border-radius: 999px; width: fit-content; }
.tab {
  padding: 7px 14px; border-radius: 999px;
  font-size: 12.5px; color: var(--muted);
}
.tab.active { background: var(--paper); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,0.05); }

/* Section header */
.section-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 16px; margin: 0 0 16px;
}
.section-head h2 { font-family: var(--display); font-size: 28px; margin: 0; line-height: 1; }
.section-head .meta { font-family: var(--mono); font-size: 11px; color: var(--muted); }

/* List rows */
.row-list { display: flex; flex-direction: column; }
.row-list .row {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}
.row-list .row:last-child { border-bottom: none; }
.row-thumb {
  width: 48px; height: 48px; border-radius: 12px;
  flex-shrink: 0; position: relative; overflow: hidden;
}

/* Progress bar */
.bar { width: 100%; height: 6px; background: var(--bg-2); border-radius: 999px; overflow: hidden; }
.bar > div { height: 100%; border-radius: 999px; transition: width .4s; }

/* Editor card prompt suggestions */
.suggest-row { display: flex; flex-wrap: wrap; gap: 6px; }
.suggest-pill {
  background: var(--bg);
  border: 1px solid var(--line);
  padding: 6px 10px; border-radius: 999px;
  font-size: 11.5px; color: var(--ink-2);
  transition: all .15s;
}
.suggest-pill:hover { border-color: var(--ink); }

/* Subtle fade in */
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }
.fade-in { animation: fadeIn .25s ease-out both; }

/* === Meadow lock overlay — for long-running AI jobs === */
.m-lock {
  position: fixed; inset: 0; z-index: 9999;
  background: rgba(245, 239, 228, 0.94);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 22px;
  color: var(--ink);
  padding: 32px;
  animation: m-lock-in 0.35s ease-out both;
}
@keyframes m-lock-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}
.m-lock.closing { animation: m-lock-out 0.22s ease-in both; }
@keyframes m-lock-out { to { opacity: 0; } }

.m-lock__logo {
  width: 96px; height: 96px;
  color: var(--ink);
  animation: m-lock-breathe 2.8s ease-in-out infinite;
  filter: drop-shadow(0 4px 16px rgba(26,24,20,0.08));
}
.m-lock__logo svg, .m-lock__logo img { width: 100%; height: 100%; display: block; }
@keyframes m-lock-breathe {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.08); }
}

.m-lock__title {
  font-family: var(--display);
  font-size: clamp(34px, 5vw, 56px);
  line-height: 1.05;
  letter-spacing: -0.02em;
  text-align: center;
  margin: 4px 0 0;
  max-width: 640px;
  color: var(--ink);
}
.m-lock__title em { font-style: italic; color: var(--terra); }
.m-lock__title .m-lock__dots::after {
  content: '\2026'; /* ellipsis fallback */
  display: inline-block;
  margin-left: 4px;
  color: var(--muted-2);
  animation: m-lock-dots 1.6s infinite steps(4, end);
}
@keyframes m-lock-dots {
  0%   { content: ''; }
  25%  { content: '\B7'; }
  50%  { content: '\B7\B7'; }
  75%  { content: '\B7\B7\B7'; }
  100% { content: '\B7\B7\B7'; }
}

.m-lock__sub {
  font-family: var(--mono);
  font-size: 11.5px;
  letter-spacing: 0.16em;
  color: var(--muted);
  text-transform: uppercase;
  text-align: center;
  min-height: 1.5em;
  transition: opacity .25s ease;
  max-width: 480px;
}
.m-lock__sub.swap { opacity: 0; }

.m-lock__divider {
  width: 36px; height: 1px; background: var(--line-strong);
  margin: 4px 0 0;
}

.m-lock__elapsed {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  color: var(--muted-2);
  text-transform: uppercase;
}
.m-lock__elapsed .num { color: var(--ink-2); }

.m-lock__cancel {
  margin-top: 12px;
  padding: 8px 18px;
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.14em;
  color: var(--muted);
  text-transform: uppercase;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
  transition: all .15s;
}
.m-lock__cancel:hover { color: var(--terra); border-color: var(--terra); }

/* Decorative corner mark (faded brand logo) */
.m-lock__corner {
  position: absolute;
  bottom: -50px; right: -50px;
  width: 260px; height: 260px;
  opacity: 0.05;
  pointer-events: none;
  color: var(--ink);
}
.m-lock__corner svg, .m-lock__corner img { width: 100%; height: 100%; }

@media (max-width: 640px) {
  .m-lock__logo { width: 72px; height: 72px; }
  .m-lock__title { font-size: clamp(28px, 8vw, 40px); }
  .m-lock__sub { font-size: 11px; letter-spacing: 0.12em; }
  .m-lock__corner { width: 180px; height: 180px; bottom: -36px; right: -36px; }
}

/* === Mobile top bar (hidden on desktop, shown on tablet/phone) === */
.m-topbar {
  display: none;
  position: sticky; top: 0; z-index: 30;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  padding: 10px 14px;
  align-items: center;
  gap: 12px;
}
.m-topbar .m-menu-toggle {
  width: 36px; height: 36px; border-radius: 10px;
  display: grid; place-items: center;
  background: transparent; color: var(--ink-2);
  border: 1px solid var(--line);
}
.m-topbar .m-menu-toggle:hover { background: var(--ink-soft); }
.m-topbar .m-brand-line { font-family: var(--display); font-size: 18px; letter-spacing: -0.01em; color: var(--ink); text-decoration: none; display: inline-flex; align-items: center; gap: 8px; }
.m-topbar .m-brand-line small { font-family: var(--mono); font-size: 9.5px; letter-spacing: 0.16em; color: var(--muted); text-transform: uppercase; }
.m-topbar .meadow-logo { width: 22px; height: 22px; }

.m-scrim {
  position: fixed; inset: 0;
  background: rgba(26,24,20,0.32);
  z-index: 39;
  opacity: 0; pointer-events: none;
  transition: opacity .2s;
}
body.menu-open .m-scrim { opacity: 1; pointer-events: auto; }

/* === Tablet (≤ 1024px) === */
@media (max-width: 1024px) {
  .main { padding: 28px 28px 64px; }
  .page-head h1 { font-size: 52px; }
}

/* === Tablet narrow & phone (≤ 920px): sidebar becomes drawer === */
@media (max-width: 920px) {
  .app, .app[data-layout="sidebar"], .app[data-layout="split"], .app[data-layout="topnav"] {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }
  .m-topbar { display: flex; }

  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: 280px; max-width: 88vw;
    height: 100vh;
    z-index: 40;
    transform: translateX(-100%);
    transition: transform .25s ease-out;
    box-shadow: 0 8px 32px rgba(26,24,20,0.12);
    overflow-y: auto;
  }
  body.menu-open .sidebar { transform: translateX(0); }

  .main { padding: 22px 20px 60px; max-width: none; }

  .page-head { flex-direction: column; align-items: stretch; gap: 14px; }
  .page-head h1 { font-size: 40px; }
  .page-head .sub { max-width: none; }
  .page-head > div:last-child { flex-wrap: wrap; }

  .section-head { flex-wrap: wrap; gap: 8px; }
  .section-head h2 { font-size: 22px; }

  /* Collapse multi-column inline-styled grids to single column. */
  .main [style*="repeat(2,"], .main [style*="repeat(3,"], .main [style*="repeat(4,"],
  .main [style*="repeat(2, "], .main [style*="repeat(3, "], .main [style*="repeat(4, "] {
    grid-template-columns: 1fr !important;
  }
  .main [style*="232px 1fr"], .main [style*="260px 1fr"], .main [style*="280px 1fr"],
  .main [style*="320px 1fr"], .main [style*="340px 1fr"], .main [style*="360px 1fr"],
  .main [style*="200px 1fr"], .main [style*="1fr 320px"], .main [style*="1fr 340px"],
  .main [style*="1fr 360px"], .main [style*="1fr 1fr"], .main [style*="1.1fr 1fr"],
  .main [style*="1.4fr 1fr auto"] {
    grid-template-columns: 1fr !important;
  }
  .planner { overflow-x: auto; grid-template-columns: 70px repeat(7, minmax(110px, 1fr)) !important; }

  .recipe-grid { grid-template-columns: 1fr 1fr !important; }
  .plans-grid { grid-template-columns: 1fr !important; }
  .plan.featured { transform: none !important; }
  .feat-grid { grid-template-columns: 1fr !important; }

  .hero, .brand-hero { padding: 44px 28px 36px !important; min-height: auto !important; margin-bottom: 28px !important; }
  .hero h1, .brand-hero__title { font-size: clamp(36px, 7vw, 52px) !important; }
  .hero .gen-form { max-width: 100% !important; padding: 4px 4px 4px 16px !important; }
  .hero .gen-form input { font-size: 14px !important; }
  .hero .gen-form button { padding: 10px 14px !important; font-size: 12.5px !important; }

  .recipe-hero { height: 280px !important; }
  .macro-ring svg { width: 180px !important; height: 180px !important; }

  .floater { right: 14px !important; }
  .timer-container { width: calc(100vw - 28px) !important; max-width: 320px; }

  .meal-table, .hist-table { display: block; overflow-x: auto; white-space: nowrap; }

  .modal-overlay { padding: 16px; }
  .modal { max-width: 100% !important; }
  .topnav .brand-sub { display: none; }
  .meadow-messages { margin-bottom: 14px; }
}

/* === Phone (≤ 640px) === */
@media (max-width: 640px) {
  .main { padding: 18px 14px 48px; }
  .page-head h1 { font-size: 32px; line-height: 1.05; }
  .page-head .sub { font-size: 13.5px; }
  .section-head h2 { font-size: 20px; }
  .card-pad { padding: 18px; }
  .card-head { padding: 14px 18px 0; }
  .card-title { font-size: 20px; }
  .recipe-grid { grid-template-columns: 1fr !important; }
  .main [style*="repeat(4, 1fr)"] { grid-template-columns: 1fr 1fr !important; }

  .hero, .brand-hero { padding: 36px 22px 28px !important; border-radius: var(--r-lg) !important; }
  .hero h1, .brand-hero__title { font-size: clamp(28px, 9vw, 40px) !important; line-height: 1.05 !important; }
  .hero .sub, .brand-hero__sub { font-size: 14px !important; }
  .hero .gen-form { flex-direction: column; gap: 6px; border-radius: var(--r-lg) !important; padding: 8px !important; align-items: stretch !important; }
  .hero .gen-form input { padding: 10px 12px !important; }
  .hero .gen-form button { width: 100%; justify-content: center !important; padding: 12px !important; }

  .recipe-hero { height: 220px !important; }
  .recipe-hero .gradient { padding: 14px 18px !important; flex-direction: column; align-items: flex-start; gap: 8px; }
  .macro-ring svg { width: 150px !important; height: 150px !important; }

  .page-head > div:last-child { width: 100%; }
  .page-head > div:last-child .btn { flex: 1; justify-content: center; }

  .sidebar { padding: 22px 16px 20px; }
  .nav-item { padding: 11px 12px; font-size: 14px; }
  .stat { padding: 14px 16px; }
  .stat .val { font-size: 28px; }

  .step { grid-template-columns: 1fr !important; gap: 12px !important; padding: 32px 0 !important; }
  .step .num { font-size: 64px !important; }
  .step .body h2 { font-size: 32px !important; }

  .m-footer > div:first-child { grid-template-columns: 1fr !important; gap: 28px !important; }
  .m-footer { padding: 32px 22px 18px !important; }

  .plan { padding: 28px 22px !important; }
}

@media (max-width: 380px) {
  .main [style*="repeat(4, 1fr)"] { grid-template-columns: 1fr !important; }
  .main [style*="repeat(2, 1fr)"] { grid-template-columns: 1fr !important; }
  .page-head h1 { font-size: 28px; }
  .hero h1, .brand-hero__title { font-size: 28px !important; }
}
