:root {
  color-scheme: dark;
  --bg: #0e0f0e;
  --surface-1: #171816;
  --surface-2: #1f201e;
  --line: #2b2c29;
  --text-primary: #f4f4f1;
  --text-secondary: #c3c2b7;
  --text-muted: #8a897f;
  --accent: #d4ff3f;
  --accent-ink: #141a00;
  /* validated categorical slots (dark steps) */
  --series-1: #3987e5; /* proteína */
  --series-2: #d95926; /* carbos */
  --series-3: #199e70; /* grasas */
  --good: #22a861;
  --warn: #e0a400;
  --bad: #e66767;
  --radius: 16px;
  --font: "Inter", system-ui, -apple-system, sans-serif;
  --display: "Barlow Condensed", "Inter", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text-primary); font: 15px/1.45 var(--font); }
a { color: inherit; text-decoration: none; }
h1, h2, h3 { font-family: var(--display); font-weight: 700; letter-spacing: .02em; margin: 0; }
h1 { font-size: 34px; text-transform: uppercase; }
h2 { font-size: 20px; text-transform: uppercase; color: var(--text-secondary); }
h3 { font-size: 17px; }
.muted { color: var(--text-muted); }
.sec { color: var(--text-secondary); }
.small { font-size: 13px; }

/* ---------- layout */
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 24px;
  padding: 12px 24px; background: rgba(14,15,14,.85); backdrop-filter: blur(12px); border-bottom: 1px solid var(--line); }
.brand { font-family: var(--display); font-size: 22px; letter-spacing: .08em; display: flex; align-items: center; gap: 8px; }
.brand b { color: var(--accent); }
.brand .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 12px var(--accent); }
.nav { display: flex; gap: 4px; }
.nav a { display: flex; align-items: center; gap: 6px; padding: 8px 12px; border-radius: 999px; color: var(--text-secondary); font-weight: 500; }
.nav a:hover { background: var(--surface-2); color: var(--text-primary); }
.nav a.on { background: var(--accent); color: var(--accent-ink); }
.nav svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.wrap { max-width: 1180px; margin: 0 auto; padding: 24px; }
.page-head { display: flex; align-items: end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.grid { display: grid; gap: 16px; align-items: start; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span2 { grid-column: span 2; }
.card { background: var(--surface-1); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; min-width: 0; }
.card > h2 { margin-bottom: 12px; display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.card > h2 select { max-width: 100%; font-family: var(--font); font-size: 14px; text-transform: none; }
.stack > * + * { margin-top: 12px; }

@media (max-width: 900px) {
  .g3, .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .span2 { grid-column: auto; }
  .g2 { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .wrap { padding: 16px 16px 96px; }
  /* backdrop-filter would make the fixed bottom nav position relative to the header */
  .topbar { padding: 10px 16px; backdrop-filter: none; -webkit-backdrop-filter: none; background: var(--bg); }
  .nav { position: fixed; bottom: 0; left: 0; right: 0; justify-content: space-around; padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
    background: rgba(23,24,22,.96); border-top: 1px solid var(--line); backdrop-filter: blur(12px); }
  .nav a { flex-direction: column; gap: 2px; padding: 6px 4px; font-size: 10px; border-radius: 10px; flex: 1; }
  .nav a.on { background: none; color: var(--accent); }
  .g2, .g3 { grid-template-columns: 1fr; }
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .span2 { grid-column: auto; }
  .kpi .val { font-size: 34px; }
  h1 { font-size: 28px; }
}

/* ---------- KPIs */
.kpi .label { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--text-muted); font-weight: 600; }
.kpi .val { font-family: var(--display); font-size: 40px; font-weight: 700; line-height: 1.05; margin-top: 4px; }
.kpi .val small { font-size: 18px; color: var(--text-secondary); font-weight: 500; margin-left: 2px; }
.kpi .delta { font-size: 13px; margin-top: 2px; color: var(--text-secondary); }
.delta.down::before { content: "▼ "; } .delta.up::before { content: "▲ "; }

.ring-wrap { display: flex; gap: 20px; align-items: center; flex-wrap: wrap; }
.ring { position: relative; width: 150px; height: 150px; flex: none; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 12; stroke-linecap: round; }
.ring .track { stroke: var(--surface-2); }
.ring .fill { stroke: var(--accent); transition: stroke-dashoffset .8s ease; }
.ring .fill.over { stroke: var(--warn); }
.ring .center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.ring .center b { font-family: var(--display); font-size: 36px; line-height: 1; }
.ring .center span { font-size: 12px; color: var(--text-muted); }
.macros { flex: 1; min-width: 180px; }
.macro + .macro { margin-top: 12px; }
.macro .row { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 4px; }
.macro .row b { font-weight: 600; }
.bar { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 999px; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: 0; }

/* ---------- lists */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; gap: 12px; align-items: center; padding: 10px 0; border-top: 1px solid var(--line); }
.list li:first-child { border-top: 0; }
.thumb { width: 56px; height: 56px; border-radius: 12px; object-fit: cover; background: var(--surface-2); flex: none; }
.thumb.ph { display: grid; place-items: center; font-size: 22px; }
.grow { flex: 1; min-width: 0; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip { display: inline-block; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); font-size: 12px; color: var(--text-secondary); }
.chip.pr { background: rgba(212,255,63,.12); color: var(--accent); }
.chip.low { background: rgba(224,164,0,.14); color: var(--warn); }
.setline { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.set { font-family: var(--display); font-size: 16px; padding: 2px 8px; border-radius: 8px; background: var(--surface-2); }
.set.pr { background: var(--accent); color: var(--accent-ink); }
.ex-block + .ex-block { margin-top: 12px; }
.empty { color: var(--text-muted); padding: 18px 0; text-align: center; }

/* ---------- forms */
input, select, textarea { font: inherit; color: var(--text-primary); background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 12px; padding: 10px 12px; width: 100%; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
textarea { resize: vertical; min-height: 64px; }
label { display: block; font-size: 12px; color: var(--text-muted); margin-bottom: 4px; text-transform: uppercase; letter-spacing: .06em; }
.field + .field { margin-top: 10px; }
.row-fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 10px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 0; border-radius: 12px; padding: 10px 16px;
  font: 600 14px var(--font); cursor: pointer; background: var(--surface-2); color: var(--text-primary); }
.btn:hover { filter: brightness(1.15); }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; border: 1px solid var(--line); }
.btn.danger { background: transparent; color: var(--bad); padding: 6px 8px; }
.btn.sm { padding: 6px 10px; font-size: 13px; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 12px; padding: 3px; gap: 2px; }
.seg input { display: none; }
.seg label { margin: 0; padding: 7px 12px; border-radius: 9px; cursor: pointer; font-size: 13px; text-transform: none; letter-spacing: 0; color: var(--text-secondary); }
.seg input:checked + label { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 10px; }
.drop { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; border: 1.5px dashed var(--line);
  border-radius: 14px; padding: 18px; cursor: pointer; color: var(--text-secondary); text-align: center; }
.drop:hover { border-color: var(--accent); color: var(--text-primary); }
.drop input { display: none; }
.drop .fname { font-size: 12px; color: var(--accent); }
details summary { cursor: pointer; color: var(--text-secondary); list-style: none; }
details summary::-webkit-details-marker { display: none; }
details[open] summary { margin-bottom: 10px; }
form.inline { display: inline; }

/* ---------- tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .06em; font-weight: 600; padding: 8px; border-bottom: 1px solid var(--line); }
td { padding: 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- charts */
.chart { position: relative; height: 240px; }
.chart.tall { height: 300px; }

/* ---------- flash / busy */
.flash { position: relative; white-space: pre-line; background: var(--surface-1); border: 1px solid var(--accent); border-radius: var(--radius);
  padding: 14px 40px 14px 16px; margin-bottom: 20px; box-shadow: 0 0 0 4px rgba(212,255,63,.06); }
.flash .x { position: absolute; top: 8px; right: 10px; background: none; border: 0; color: var(--text-muted); font-size: 22px; cursor: pointer; }
.busy { position: fixed; inset: 0; background: rgba(0,0,0,.65); display: flex; flex-direction: column; align-items: center; justify-content: center; z-index: 50; gap: 12px; }
.busy[hidden] { display: none; }
.spinner { width: 44px; height: 44px; border-radius: 50%; border: 4px solid var(--surface-2); border-top-color: var(--accent); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.hero-photo { width: 100%; max-height: 220px; object-fit: cover; border-radius: 12px; }
.tag-group { display: flex; flex-wrap: wrap; gap: 6px; }
.seg-body { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.seg-body div { background: var(--surface-2); border-radius: 10px; padding: 8px 10px; }
.seg-body b { font-family: var(--display); font-size: 20px; display: block; }

/* ---------- alerts */
.alerts { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 10px; margin-bottom: 16px; }
.alert { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; border-radius: 14px; background: var(--surface-1);
  border: 1px solid var(--line); border-left: 4px solid var(--text-muted); }
.alert.warn { border-left-color: var(--warn); }
.alert.info { border-left-color: var(--series-1); }
.alert.ok { border-left-color: var(--good); }
.alert .ai { font-size: 20px; line-height: 1.2; }

/* ---------- suggestions */
.span3 { grid-column: 1 / -1; }
.dishes { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; margin: 12px 0; transition: opacity .3s; }
.dishes.dim { opacity: .55; }
.dish { background: var(--surface-2); border-radius: 14px; padding: 14px; display: flex; flex-direction: column; gap: 6px; }
.dish h3 { font-size: 18px; line-height: 1.15; }
.dish-head { display: flex; justify-content: space-between; gap: 8px; align-items: start; }
.dish-head .chip { white-space: nowrap; flex: none; }
.chip.fit { background: rgba(34,168,97,.15); color: var(--good); }
.dish-macros { font-size: 14px; color: var(--text-secondary); }
.dish-macros b { font-family: var(--display); font-size: 22px; color: var(--text-primary); }
.dish p { margin: 0; }
.dish .actions { margin-top: auto; padding-top: 6px; }
.ing-list { list-style: none; padding: 0; margin: 6px 0; }
.ing-list li { display: flex; justify-content: space-between; gap: 8px; padding: 3px 0; border-bottom: 1px solid var(--line); }
.refreshing { display: flex; align-items: center; gap: 8px; color: var(--accent); }
.spinner.sm { width: 16px; height: 16px; border-width: 2px; }
.btn[disabled] { opacity: .5; cursor: default; }

/* ---------- plan */
.goal-seg { display: flex; flex-wrap: wrap; margin-bottom: 12px; }
.goal-seg label { display: flex; flex-direction: column; align-items: flex-start; padding: 10px 16px; }
.goal-seg label b { font-size: 15px; }
.goal-seg label span { font-size: 11px; opacity: .8; }
.plan .kpi .val { font-size: 32px; }

/* ---------- workout plan */
.plan-list { margin: 0; padding-left: 22px; }
.plan-list li { padding: 8px 0; border-bottom: 1px solid var(--line); }
.plan-list li::marker { color: var(--text-muted); font-family: var(--display); }
.plan-list li { display: list-item; }
.plan-list .pl-main { display: inline-block; min-width: 0; }
.plan-list .pl-dose { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-top: 4px; }
.dim { opacity: .55; transition: opacity .3s; }

/* ---------- chat */
.chat-wrap { max-width: 760px; margin: 0 auto; padding-bottom: 150px; }
.chat-log { display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 85%; padding: 10px 14px; border-radius: 18px; position: relative; word-wrap: break-word; }
.msg .txt { white-space: pre-line; }
.msg time { display: block; font-size: 10px; color: var(--text-muted); margin-top: 4px; text-align: right; }
.msg.user { align-self: flex-end; background: var(--accent); color: var(--accent-ink); border-bottom-right-radius: 6px; }
.msg.user time { color: rgba(20,26,0,.6); }
.msg.assistant { align-self: flex-start; background: var(--surface-1); border: 1px solid var(--line); border-bottom-left-radius: 6px; }
.msg img { display: block; max-width: 220px; max-height: 220px; border-radius: 12px; margin-bottom: 6px; object-fit: cover; }
.msg .actions { margin-top: 8px; }
.typing { display: flex; gap: 4px; padding: 14px; }
.typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--text-muted); animation: blink 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: .2s; } .typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
.draft-card { position: sticky; top: 64px; z-index: 5; background: var(--surface-1); border: 1px solid var(--accent);
  border-radius: var(--radius); padding: 12px 14px; margin-bottom: 14px; box-shadow: 0 8px 24px rgba(0,0,0,.4); }
.draft-card .dh { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.draft-card .dg { margin-top: 8px; }
.draft-card .dgs { margin-top: 8px; border-top: 1px solid var(--line); max-height: 30vh; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.draft-card .set.changed { animation: set-flash 1.6s ease-out; }
@keyframes set-flash { 0%, 30% { background: var(--accent); color: var(--accent-ink); } 100% { background: var(--surface-2); color: inherit; } }
.msg.rest { min-width: 220px; }
.msg.rest .rest-bar { height: 4px; border-radius: 2px; background: var(--surface-2); margin-top: 6px; overflow: hidden; }
.msg.rest .rest-bar span { display: block; height: 100%; border-radius: 2px; background: var(--text-muted); transition: width 1s linear; }
.msg.rest.done { border-color: var(--accent); }
.msg.rest.done .rest-bar span { background: var(--accent); }
.draft-card .set { border: 0; color: inherit; cursor: pointer; font: inherit; font-family: var(--display); font-size: 15px; }
.draft-card details { margin-top: 8px; }
.live-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--bad); margin-right: 6px;
  animation: blink 1.4s infinite; vertical-align: 1px; }
.chat-quick { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 8px; scrollbar-width: none; }
.chat-quick::-webkit-scrollbar { display: none; }
.chip-btn { flex: none; border: 1px solid var(--line); background: var(--surface-1); color: var(--text-secondary); border-radius: 999px;
  padding: 6px 12px; font: 500 13px var(--font); cursor: pointer; }
.chip-btn:hover { color: var(--text-primary); border-color: var(--accent); }
.composer { position: fixed; left: 0; right: 0; bottom: 0; background: rgba(14,15,14,.96); border-top: 1px solid var(--line);
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); }
.composer > * { max-width: 760px; margin: 0 auto; }
.composer-row { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { min-height: 44px; max-height: 140px; resize: none; border-radius: 22px; padding: 11px 16px; }
.icon-btn { flex: none; width: 44px; height: 44px; display: grid; place-items: center; border-radius: 50%; background: var(--surface-2);
  cursor: pointer; font-size: 20px; margin: 0; text-transform: none; }
.icon-btn.pulse { box-shadow: 0 0 0 0 rgba(212,255,63,.7); animation: pulse 1.6s infinite; }
@keyframes pulse { 70% { box-shadow: 0 0 0 12px rgba(212,255,63,0); } 100% { box-shadow: 0 0 0 0 rgba(212,255,63,0); } }
.send { width: 44px; height: 44px; border-radius: 50%; padding: 0; font-size: 18px; flex: none; }
.photo-pick { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.photo-pick img { width: 48px; height: 48px; border-radius: 10px; object-fit: cover; }
.photo-pick img[hidden], .photo-pick .seg[hidden] { display: none; }
.fab { position: fixed; right: 20px; bottom: 24px; z-index: 20; width: 58px; height: 58px; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent); color: var(--accent-ink); font-size: 26px; box-shadow: 0 8px 24px rgba(0,0,0,.5); }
.fab .dot { position: absolute; top: 4px; right: 4px; width: 14px; height: 14px; border-radius: 50%; background: var(--bad); border: 2px solid var(--bg); }
.quick-start { display: flex; gap: 8px; flex-wrap: wrap; }
@media (max-width: 640px) {
  .fab { bottom: 84px; right: 16px; }
  .composer { bottom: 64px; }
  .chat-wrap { padding-bottom: 210px; }
  .draft-card { top: 56px; }
}
.spark-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.spark { background: var(--surface-2); border-radius: 14px; padding: 12px; }
.spark-head { display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.photo-pick[hidden], .draft-card[hidden] { display: none; }
.guide { background: var(--surface-2); border-radius: 14px; padding: 12px 14px; margin: 4px 0 8px; }
.guide .aim { margin: 0 0 6px; font-weight: 600; }
.guide ul { margin: 0; padding-left: 0; list-style: none; display: grid; gap: 4px; font-size: 14px; color: var(--text-secondary); }


/* ---------- chat page: full-height app layout (messages scroll inside, composer pinned) */
body.chat-page { height: 100vh; height: 100dvh; overflow: hidden; display: flex; flex-direction: column; }
body.chat-page .wrap { flex: 1; min-height: 0; max-width: none; padding: 0; display: flex; }
body.chat-page .chat-wrap { flex: 1; min-height: 0; display: flex; flex-direction: column; width: 100%; max-width: 760px;
  margin: 0 auto; padding: 0; }
.chat-header { display: flex; align-items: center; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.chat-header .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 10px var(--accent); }
.chat-header b { font-family: var(--display); font-size: 20px; letter-spacing: .06em; text-transform: uppercase; }
.chat-close { margin-left: auto; width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface-1);
  color: var(--text-primary); font-size: 18px; cursor: pointer; }
body.chat-page .chat-log { flex: 1; min-height: 0; overflow-y: auto; padding: 12px 16px; -webkit-overflow-scrolling: touch; }
body.chat-page .chat-log > :first-child { margin-top: auto; }  /* messages sit at the bottom, like a messenger */
body.chat-page .draft-card { position: static; margin: 10px 16px 0; }
body.chat-page .composer { position: static; padding: 8px 12px calc(8px + env(safe-area-inset-bottom)); }
body.chat-page .composer > * { max-width: none; }
.composer textarea::placeholder { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 640px) {
  body.chat-page .topbar { display: none; }  /* full screen: the chat header has the close button */
  body.chat-page .composer { bottom: auto; }
  body.chat-page .chat-wrap { padding-bottom: 0; }
}
/* flex children default to min-width:auto — the scrollable chip row must not widen the whole chat */
body.chat-page .wrap > .chat-wrap, body.chat-page .composer, body.chat-page .chat-quick, body.chat-page .chat-log { min-width: 0; }
body.chat-page .chat-wrap { overflow: hidden; }
body.chat-page .chat-quick { max-width: 100%; }
body.chat-page .wrap { width: 100%; max-width: 100vw; overflow: hidden; }
.composer-row textarea { flex: 1 1 0; width: auto; min-width: 0; }

.date-edit { position: relative; }
.date-edit summary { list-style: none; }
.date-pop { position: absolute; right: 0; top: 36px; z-index: 6; display: flex; gap: 6px; background: var(--surface-1);
  border: 1px solid var(--line); border-radius: 12px; padding: 8px; width: max-content; box-shadow: 0 8px 24px rgba(0,0,0,.45); }
.date-pop input { width: 150px; }

.msg.progress .txt { display: flex; align-items: center; gap: 8px; color: var(--accent); }

.date-btn { list-style: none; cursor: pointer; font-size: 16px; display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap;
  padding: 4px 8px; margin-left: -8px; border-radius: 10px; }
.date-btn::-webkit-details-marker { display: none; }
.date-btn:hover { background: var(--surface-2); }
.date-btn .edit-hint { font-size: 12px; color: var(--accent); border: 1px solid rgba(212,255,63,.35); border-radius: 999px; padding: 1px 8px; }
.date-edit[open] .edit-hint { display: none; }
.date-inline { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; margin: 6px 0 8px; padding: 10px; border-radius: 12px;
  background: var(--surface-2); }
.date-inline input { width: auto; }

.seg.range { padding: 2px; }
.seg.range button { border: 0; background: none; color: var(--text-secondary); font: 600 12px var(--font); padding: 5px 9px;
  border-radius: 8px; cursor: pointer; text-transform: none; letter-spacing: 0; }
.seg.range button.on { background: var(--accent); color: var(--accent-ink); }
.trends h2 { flex-wrap: wrap; }
.trend-sub { margin: -4px 0 8px; min-height: 1.2em; }

/* ---------- quick actions (collapsible, top of home) */
.quick-actions { margin-bottom: 16px; padding: 0; border-color: rgba(212,255,63,.35); }
.quick-actions > summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 10px; padding: 14px 18px; }
.quick-actions > summary::-webkit-details-marker { display: none; }
.qa-title { font-family: var(--display); font-size: 20px; text-transform: uppercase; letter-spacing: .04em; }
.quick-actions .chev { margin-left: auto; color: var(--text-secondary); font-size: 18px; transition: transform .2s; }
.quick-actions[open] .chev { transform: rotate(180deg); }
.quick-actions[open] .qa-hint { display: none; }
.qa-buttons { display: flex; gap: 8px; flex-wrap: wrap; padding: 0 18px 12px; }
.qa-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding: 0 18px 18px; }
.qa-block { background: var(--surface-2); border-radius: 14px; padding: 12px; min-width: 0; }
.qa-block textarea, .qa-block input { background: var(--surface-1); }
.qa-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.qa-head .seg { background: var(--surface-1); flex-wrap: wrap; }
.qa-photo { display: grid; grid-template-columns: auto 1fr; gap: 8px; align-items: stretch; }
.qa-photo .drop { padding: 10px 14px; flex-direction: row; }
.qa-block .actions { margin-top: 8px; }
@media (max-width: 760px) {
  .qa-grid { grid-template-columns: 1fr; }
  .qa-photo { grid-template-columns: 1fr; }
}
.qa-title { white-space: nowrap; }
@media (max-width: 640px) { .quick-actions .qa-hint { display: none; } }

/* ---------- calorie "water" ring */
.water-ring { position: relative; width: 170px; height: 170px; flex: none; }
.water-ring svg { width: 100%; height: 100%; }
.water-ring .glass { fill: var(--surface-2); }
.water-ring .water { fill: var(--good); transition: d .8s; }
.water-ring .water.back { opacity: .35; animation: wave 4s linear infinite; }
.water-ring .water.front { opacity: .55; animation: wave 2.6s linear infinite reverse; }
@keyframes wave { from { transform: translateX(0); } to { transform: translateX(80px); } }
.water-ring .rim { fill: none; stroke-width: 6; stroke: var(--good); transition: stroke .4s; }
.water-ring.mid .rim, .water-ring.mid .water { stroke: var(--warn); fill: var(--warn); }
.water-ring.mid .rim { fill: none; }
.water-ring.near .rim { stroke: #f0702e; }
.water-ring.near .water { fill: #f0702e; }
.water-ring.over .rim { stroke: var(--bad); animation: blink 1s ease-in-out infinite; }
.water-ring.over .water { fill: var(--bad); }
.water-ring .center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-shadow: 0 1px 6px rgba(0,0,0,.6); }
.water-ring .center b { font-family: var(--display); font-size: 42px; line-height: 1; }
.water-ring .center span { font-size: 12px; color: var(--text-secondary); letter-spacing: .04em; }
.kcal-side { flex: 1; min-width: 200px; }
.kcal-facts { display: flex; gap: 18px; flex-wrap: wrap; }
.kcal-facts div { display: flex; flex-direction: column; }
.kcal-facts span { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--text-muted); }
.kcal-facts b { font-family: var(--display); font-size: 26px; line-height: 1.1; }
.kcal-facts .over b { color: var(--bad); }
.kcal-why { margin: 4px 0 12px; }
@media (prefers-reduced-motion: reduce) { .water-ring .water, .water-ring.over .rim { animation: none; } }

.act-list li { display: block; padding: 6px 0; }
.act-edit > summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 8px; }
.act-edit > summary::-webkit-details-marker { display: none; }
.act-edit .edit-hint { color: var(--accent); }
.act-edit[open] > summary { margin-bottom: 4px; }
.add-act { margin: 8px 0; }
.add-act > summary { list-style: none; }
.add-act > summary::-webkit-details-marker { display: none; }
/* top nav must never widen the page at intermediate widths */
.topbar { min-width: 0; }
.nav { min-width: 0; overflow-x: auto; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
@media (min-width: 641px) and (max-width: 980px) {
  .topbar { gap: 12px; padding: 12px 16px; }
  .nav a { padding: 8px 9px; gap: 4px; font-size: 14px; }
  .nav svg { width: 16px; height: 16px; }
}
@media (min-width: 641px) and (max-width: 820px) {
  .nav a span { display: none; }  /* icons only; the active page keeps its pill */
  .nav a.on span { display: inline; }
}
.act-list .act-day { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--text-muted); padding: 10px 0 2px;
  border-top: 0; }
.chat-tools { display: flex; gap: 6px; margin-left: auto; }
.chat-tools + .chat-close { margin-left: 4px; }
.chat-tools .btn { padding: 6px 10px; }
.history-log { display: flex; flex-direction: column; gap: 10px; max-height: 70vh; overflow-y: auto; }
@media (max-width: 640px) { .chat-tools .btn { font-size: 12px; padding: 6px 8px; } }

/* ---------- muscle heatmap */
.bodymap { --heat-lo: #6b2c25; --heat-hi: #ff3b2f; --body: #2e2f2b;
  display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1fr) minmax(220px, 1.1fr); gap: 16px; align-items: start; }
.bm-fig { margin: 0; text-align: center; }
.bm-fig svg { width: 100%; max-height: 440px; display: block; }
.bm-fig figcaption { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .08em; margin-top: 4px; }
.bm-n { fill: var(--body); }
.bm-m { fill: var(--body); stroke: var(--surface-1); stroke-width: 1.5; stroke-linejoin: round; cursor: pointer; transition: fill .35s; outline: none; }
.bm-m.sel { stroke: var(--accent); stroke-width: 2; }
.bm-n { stroke: var(--surface-1); stroke-width: 1.5; }
.bm-ramp { display: block; height: 10px; border-radius: 5px; background: linear-gradient(90deg, var(--body) 0 6%, var(--heat-lo) 6%, var(--heat-hi)); }
.bm-ticks { display: flex; justify-content: space-between; margin-top: 4px; }
.bm-info { min-height: 2.9em; margin: 10px 0 6px; }
.bm-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.bm-list li { display: grid; grid-template-columns: 12px 1fr auto; gap: 8px; align-items: center; padding: 4px 6px; border-radius: 8px; cursor: pointer; font-size: 13px; }
.bm-list li:hover, .bm-list li.sel { background: var(--surface-2); }
.bm-list i { width: 12px; height: 12px; border-radius: 3px; }
.bm-list b { font-variant-numeric: tabular-nums; font-weight: 600; }
@media (max-width: 700px) {
  .bodymap { grid-template-columns: 1fr 1fr; }
  .bm-side { grid-column: 1 / -1; }
  .bm-list { grid-template-columns: 1fr 1fr; column-gap: 8px; }
}

/* ---------- chat delivery status */
.msg .ticks { font-size: 11px; letter-spacing: -3px; margin-left: 4px; opacity: .55; }
.msg .ticks.read { color: #1f5fbf; opacity: 1; }
.msg .retry { margin-top: 6px; background: rgba(20,26,0,.12); color: var(--accent-ink); }
.typing-wrap { display: flex; flex-direction: column; gap: 2px; padding: 4px 14px 10px; }
.typing-wrap .typing { padding: 10px 0 2px; }
.photo-thumbs { display: flex; gap: 4px; }
.photo-thumbs img { width: 48px; height: 48px; border-radius: 10px; object-fit: cover; }
.photo-pick .seg label[hidden] { display: none; }
.msg .imgs { display: grid; gap: 4px; margin-bottom: 6px; }
.msg .imgs.n2 { grid-template-columns: 1fr 1fr; }
.msg .imgs.n3 { grid-template-columns: 1fr 1fr 1fr; }
.msg .imgs img { margin: 0; width: 100%; max-width: 220px; aspect-ratio: 1; }
.msg .imgs.n2 img, .msg .imgs.n3 img { max-width: 110px; }
.photo-thumbs { flex-wrap: wrap; }
.photo-thumbs .thumb { position: relative; display: inline-block; }
.photo-thumbs .thumb button { position: absolute; top: -6px; right: -6px; width: 20px; height: 20px; border-radius: 50%; border: 0;
  background: var(--surface-2); color: var(--text-primary); font-size: 11px; line-height: 20px; padding: 0; cursor: pointer; }
#photo-add[hidden] { display: none; }
/* photo picker: thumbs + actions on one row, the 5 kinds spread over the full width (never wider than the screen) */
.photo-pick { display: block; }
.photo-pick .pp-top { display: flex; align-items: center; gap: 8px; min-width: 0; margin-bottom: 8px; }
.photo-pick .pp-top .photo-thumbs { flex: 0 1 auto; min-width: 0; overflow: hidden; flex-wrap: nowrap; padding-top: 6px; }
.photo-pick .pp-top .photo-thumbs img { width: 44px; height: 44px; }
.photo-pick .pp-top #photo-name { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.photo-pick .pp-top .btn { flex: none; margin: 0; }
#photo-kind { display: grid; grid-template-columns: repeat(auto-fit, minmax(0, 1fr)); width: 100%; box-sizing: border-box; }
#photo-kind[hidden] { display: none; }
#photo-kind label { display: flex; flex-direction: row; align-items: center; justify-content: center; gap: 4px; padding: 7px 2px;
  font-size: 12.5px; white-space: nowrap; min-width: 0; overflow: hidden; }
#photo-kind label i { font-style: normal; }
@media (max-width: 480px) {
  #photo-kind label { flex-direction: column; gap: 1px; font-size: 11px; padding: 5px 1px; }
  #photo-kind label i { font-size: 16px; line-height: 1.1; }
}
.howto { margin: 8px 0 12px; padding-left: 20px; display: grid; gap: 8px; color: var(--text-secondary); }
.howto b { color: var(--text-primary); }
.howto code, .copyrow code { background: var(--surface-2); padding: 1px 6px; border-radius: 6px; font-size: 12px; }
.copyrow { display: flex; align-items: center; gap: 8px; margin: 6px 0; min-width: 0; }
.copyrow code { overflow-wrap: anywhere; }

/* ---------- steps counter */
.steps-card .sc-main { display: flex; justify-content: space-between; align-items: end; gap: 12px; }
.steps-card .label { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-secondary); }
.steps-card .val { font-family: var(--display); font-size: 40px; font-weight: 700; line-height: 1; margin-top: 4px; }
.steps-card .val small { font-size: 16px; color: var(--text-muted); margin-left: 4px; font-weight: 500; }
.steps-card .sc-note { text-align: right; }
.good-ink { color: var(--good); }
.steps-card .sc-bar { position: relative; height: 10px; border-radius: 5px; background: var(--surface-2); margin: 14px 0 4px; }
.steps-card .sc-bar .fill { position: absolute; inset: 0 auto 0 0; border-radius: 5px; background: var(--accent); }
.steps-card .sc-bar .base { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--text-secondary); border-radius: 1px; }
.steps-card .sc-scale { position: relative; display: flex; justify-content: space-between; height: 16px; }
.steps-card .sc-scale span[style] { position: absolute; transform: translateX(-50%); }
.wrap > .steps-card { margin-bottom: 16px; }
.steps-card .sc-div { display: grid; grid-template-columns: auto 1fr; gap: 6px; margin-top: 14px; }
.steps-card .sc-div .axis { position: relative; height: 150px; width: 40px; }
.steps-card .sc-div .axis span { position: absolute; right: 0; transform: translateY(50%); font-size: 11px; }
.steps-card .ax-zero { color: var(--text-secondary); font-weight: 600; }
.steps-card .days { position: relative; display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.steps-card .days .lines { position: absolute; left: 0; right: 0; top: 0; height: 150px; pointer-events: none; }
.steps-card .days .gl { position: absolute; left: 0; right: 0; height: 0; border-top: 1px solid var(--text-muted); }
.steps-card .days .gl.goal { border-top: 1px dashed var(--line); border-top-color: var(--text-muted); opacity: .6; }
.steps-card .days .d { display: flex; flex-direction: column; align-items: center; min-width: 0; }
.steps-card .plot { position: relative; width: 100%; height: 150px; }
.steps-card .plot .bar { position: absolute; left: 50%; width: 60%; max-width: 22px; transform: translateX(-50%); }
.steps-card .plot .bar.up { background: var(--good); border-radius: 4px 4px 0 0; }
.steps-card .plot .bar.dn { background: var(--bad); opacity: .75; border-radius: 0 0 4px 4px; }
.steps-card .plot .lbl { position: absolute; left: -4px; right: -4px; text-align: center; font-size: 11px; font-weight: 600; white-space: nowrap; }
.steps-card .plot .lbl.up { color: var(--good); }
.steps-card .plot .lbl.dn { color: var(--text-secondary); }
.steps-card .plot .none { position: absolute; left: 0; right: 0; text-align: center; color: var(--text-muted); font-size: 11px; margin-bottom: 2px; }
.steps-card .days .d.today .dl { color: var(--accent); font-weight: 600; }
.steps-card .days .dl { position: absolute; bottom: 0; height: 20px; line-height: 20px; }
.steps-card .days .d { position: relative; padding-bottom: 20px; }
.steps-card .sc-div .axis { margin-bottom: 20px; }
.steps-card .sc-legend { margin: 6px 0 0; }
/* trend cards on phones: title + range picker wrap instead of widening the page */
.trends .grid > div { min-width: 0; }
.trends h2 { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.trends .seg.range { flex-wrap: nowrap; }
@media (max-width: 900px) { .g2 { grid-template-columns: minmax(0, 1fr); } }
.steps-form { display: flex; flex-wrap: wrap; align-items: end; gap: 10px; }
.steps-form label { display: flex; flex-direction: column; gap: 4px; margin: 0; font-size: 13px; }
.steps-form input { width: 120px; }
.steps-form p { flex-basis: 100%; margin: 0; }

.trends .deficit-block { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--line); min-width: 0; }
.trends .deficit-block h2 { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.kcal-facts .exp b { color: var(--text-secondary); }
.kcal-facts .def b { color: var(--good); }
.recovery-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px 12px; }
.recovery-grid label { display: flex; flex-direction: column; gap: 4px; margin: 0; font-size: 12.5px; color: var(--text-secondary); }
.recovery-grid input { width: 100%; }

/* Ajustes → IA */
.ia-profile { padding: 12px 0; border-top: 1px solid var(--line); }
.ia-profile:first-of-type { border-top: 0; padding-top: 0; }
.ia-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.ia-wrap { overflow-wrap: anywhere; min-width: 0; }
.ia-edit { margin-top: 8px; }
.ia-form label { min-width: 0; }
.ia-form input, .ia-form select { width: 100%; max-width: 100%; box-sizing: border-box; }
.ia-form label { flex: 1 1 160px; }
.ia-form [hidden] { display: none; }

/* logged-in user + logout in the top bar */
.whoami { margin-left: auto; display: flex; align-items: center; gap: 8px; flex: none; }
.whoami .who { color: var(--text-secondary); font-size: 14px; max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.whoami .logout { display: flex; align-items: center; gap: 6px; background: none; border: 1px solid var(--line); color: var(--text-secondary);
  border-radius: 999px; padding: 6px 10px; font: inherit; font-size: 14px; cursor: pointer; }
.whoami .logout:hover { background: var(--surface-2); color: var(--text-primary); }
.whoami svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
@media (max-width: 640px) {
  .whoami .who { max-width: 80px; font-size: 13px; }
  .whoami .logout { padding: 6px; }
  .whoami .logout span { display: none; }  /* icon-only on phones */
}

/* admin → usuarios: stacked cards, never a wide table (no horizontal scroll on phones) */
.adm-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr)); gap: 16px; margin-top: 16px; }
.adm-pw { margin-bottom: 16px; border-color: var(--accent); }
.adm-code { font-size: 16px; padding: 6px 10px; background: var(--surface-2); border-radius: 8px; overflow-wrap: anywhere; user-select: all; }
.adm-user .ia-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }

/* ---------- Entreno: edit sets / exercise names of a saved session */
.ex-name { background: none; border: 0; padding: 0; cursor: pointer; font: inherit; text-align: left; }
.ex-name .edit-hint { color: var(--accent); }
.set.add-set { background: none; border: 1px dashed var(--line) !important; color: var(--text-muted) !important; }
dialog.sheet { width: min(420px, calc(100vw - 32px)); background: var(--surface-1); color: var(--text-primary);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
dialog.sheet::backdrop { background: rgba(0,0,0,.6); }
dialog.sheet h3 { margin: 0 0 10px; }
dialog.sheet .row3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-top: 8px; }
dialog.sheet .dlg-actions { display: flex; gap: 8px; align-items: center; margin-top: 14px; flex-wrap: wrap; }
.ex-pick { position: relative; }
.ex-results { list-style: none; margin: 4px 0 0; padding: 4px; max-height: 38vh; overflow-y: auto; overscroll-behavior: contain;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; }
.ex-results[hidden] { display: none; }
.ex-results li { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; padding: 9px 10px; border-radius: 8px; cursor: pointer; }
.ex-results li:hover, .ex-results li:active { background: var(--surface-1); }
.ex-results li.none { cursor: default; }
