/* ================================================
   CALORIE TAB — ported from the lab prototype "Ring + Macros".
   The page header is the app's Editorial Masthead (app.jsx) — this file styles
   only the page body (ring + macros + today's list) and the Log-food sheet.
   Class renames vs the prototype to avoid clashing with app globals:
     .field -> .cal-field   .btn-primary -> .cal-btn-primary   .btn-secondary -> .cal-btn-secondary
   ================================================ */

.cal-page { display: flex; flex-direction: column; gap: 16px; max-width: 860px; }

/* ---- ring + macros ---- */
.cal-grid { display: grid; grid-template-columns: 1fr 1.15fr; gap: 18px; }
.big-ring { width: 200px; height: 200px; position: relative; margin: 6px auto 0; }
.big-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.big-ring .ri { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.big-ring .ri .n { font-family: 'Oswald', var(--font-ui); font-size: 46px; font-weight: 700; line-height: 1; color: var(--ink); }
.big-ring .ri .u { font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--ink-4); margin-top: 4px; }
.big-ring .ri .g { font-family: var(--font-mono); font-size: 11px; color: var(--gold); margin-top: 8px; }
.big-ring .ri .g.over { color: var(--err); }

.macros-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.macros-head .ttl { font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--ink-4); }
.edit-targets { font-family: var(--font-mono); font-size: 10px; color: var(--ink-3); display: inline-flex; gap: 6px; align-items: center; padding: 4px 9px; border: 1px solid var(--line-2); border-radius: 999px; cursor: pointer; }
.edit-targets:hover { color: var(--gold); border-color: var(--gold-30); }
.macros { display: flex; flex-direction: column; gap: 16px; }
.macro-row { display: flex; flex-direction: column; gap: 7px; }
.macro-top { display: flex; justify-content: space-between; align-items: baseline; }
.macro-name { font-size: 12px; font-weight: 600; color: var(--ink-2); }
.macro-val { font-family: 'Oswald', var(--font-ui); font-size: 16px; color: var(--ink); }
.macro-val small { font-family: var(--font-mono); font-size: 10px; color: var(--ink-4); }
.macro-bar { height: 7px; border-radius: 999px; background: rgba(255,255,255,0.06); overflow: hidden; }
.macro-bar > span { display: block; height: 100%; border-radius: 999px; transition: width .4s ease; }
.mb-pro > span { background: linear-gradient(90deg,#F0CF60,#D4AF37); }
.mb-carb > span { background: linear-gradient(90deg,#7FA6D4,#B8D4EC); }
.mb-fat > span { background: linear-gradient(90deg,#E8B55F,#caa24f); }

.cal-chips { display: grid; grid-template-columns: repeat(2,1fr); gap: 12px; margin-top: 22px; }
.cal-chip { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); padding: 13px 15px; }
.cal-chip .k { font-family: var(--font-mono); font-size: 9px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-4); }
.cal-chip .v { margin-top: 6px; font-family: 'Oswald', var(--font-ui); font-weight: 600; font-size: 24px; line-height: 1; color: var(--ink); }
.cal-chip .v.gold { color: var(--gold); }
.cal-chip .v small { font-family: var(--font-mono); font-size: 11px; color: var(--ink-3); font-weight: 400; }

/* ---- today's flat food list ---- */
.meal-head { display: flex; align-items: center; justify-content: space-between; padding: 13px 18px; border-bottom: 1px solid var(--line); }
.meal-name { font-size: 11px; font-weight: 600; letter-spacing: 0.16em; text-transform: uppercase; color: var(--ink-3); display: inline-flex; gap: 10px; align-items: center; }
.meal-name i { color: var(--gold); font-size: 11px; }
.meal-kcal { font-family: 'Oswald', var(--font-ui); font-size: 16px; color: var(--ink); }
.food { display: flex; align-items: center; gap: 12px; padding: 11px 18px; border-bottom: 1px solid var(--line); }
.food:last-child { border-bottom: none; }
.food .fn { flex: 1; font-size: 13px; color: var(--ink); font-weight: 500; min-width: 0; }
.food .fn .src { font-family: var(--font-mono); font-size: 8px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-5); margin-left: 8px; border: 1px solid var(--line-2); border-radius: 4px; padding: 1px 5px; vertical-align: middle; }
.food .fp { font-family: var(--font-mono); font-size: 10px; color: var(--ink-4); flex-shrink: 0; }
.food .fk { font-family: 'Oswald', var(--font-ui); font-size: 15px; color: var(--ink-2); min-width: 42px; text-align: right; flex-shrink: 0; }
.food .fx { width: 24px; height: 24px; border-radius: 6px; color: var(--ink-5); font-size: 11px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; cursor: pointer; }
.food .fx:hover { color: var(--err); background: rgba(224,108,108,0.08); }
.meal-add { display: flex; align-items: center; gap: 8px; padding: 14px 18px; color: var(--gold); font-size: 12px; font-weight: 500; width: 100%; cursor: pointer; }
.meal-add:hover { color: var(--gold-hi); }
.meal-empty { padding: 14px 18px; color: var(--ink-5); font-size: 12px; font-style: italic; }

/* ================================================
   LOG SHEET (modal)
   ================================================ */
.sheet-scrim { position: fixed; inset: 0; background: rgba(4,4,7,0.6); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); z-index: 1200; display: flex; align-items: center; justify-content: center; padding: 20px; animation: cal-fade .2s ease; }
@keyframes cal-fade { from { opacity: 0; } to { opacity: 1; } }
.sheet { width: 100%; max-width: 520px; max-height: 86vh; display: flex; flex-direction: column; background: var(--surface-2); border: 1px solid var(--line-2); border-radius: var(--r-xl); box-shadow: 0 40px 80px -30px rgba(0,0,0,0.8); overflow: hidden; animation: cal-rise .22s cubic-bezier(.2,.8,.2,1); }
@keyframes cal-rise { from { transform: translateY(10px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px 14px; border-bottom: 1px solid var(--line); }
.sheet-head h2 { font-family: var(--font-serif); font-size: 20px; font-weight: 500; color: var(--ink); }
.sheet-head .x { width: 30px; height: 30px; border-radius: 8px; color: var(--ink-3); display: flex; align-items: center; justify-content: center; font-size: 14px; cursor: pointer; }
.sheet-head .x:hover { background: rgba(255,255,255,0.05); color: var(--ink); }
.sheet-body { padding: 18px 20px 22px; overflow-y: auto; }

.method-row { display: grid; grid-template-columns: repeat(4,1fr); gap: 10px; margin-bottom: 6px; }
.method { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 16px 6px; border: 1px solid var(--line); border-radius: var(--r-md); background: rgba(255,255,255,0.02); transition: border .18s, background .18s; cursor: pointer; }
.method:hover { border-color: var(--gold-30); background: var(--gold-10); }
.method.active { border-color: var(--gold); background: var(--gold-10); }
.method i { font-size: 18px; color: var(--gold); }
.method span { font-size: 11px; font-weight: 600; color: var(--ink-2); }
.method-panel { margin-top: 18px; }

.cal-field { margin-bottom: 14px; }
.cal-field label { display: block; font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-4); margin-bottom: 7px; }
.inp { width: 100%; padding: 11px 13px; background: var(--surface); border: 1px solid var(--line-2); border-radius: var(--r-sm); color: var(--ink); font-family: var(--font-ui); font-size: 14px; outline: none; }
.inp:focus { border-color: var(--gold-30); }
select.inp { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2 4l4 4 4-4' stroke='%23999' stroke-width='1.5' fill='none'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 30px; }

.search-results { margin-top: 12px; display: flex; flex-direction: column; gap: 6px; max-height: 280px; overflow-y: auto; }
.sr { display: flex; align-items: center; gap: 12px; padding: 11px 13px; border: 1px solid var(--line); border-radius: var(--r-sm); background: rgba(255,255,255,0.015); text-align: left; width: 100%; cursor: pointer; }
.sr:hover { border-color: var(--gold-30); background: var(--gold-10); }
.sr .srn { flex: 1; min-width: 0; }
.sr .srn b { display: block; font-size: 13px; font-weight: 500; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sr .srn small { font-family: var(--font-mono); font-size: 9px; color: var(--ink-4); text-transform: uppercase; letter-spacing: 0.04em; }
.sr .srk { font-family: 'Oswald', var(--font-ui); font-size: 15px; color: var(--ink-2); flex-shrink: 0; }
.sr .srk small { font-family: var(--font-mono); font-size: 9px; color: var(--ink-5); }
.sr-msg { padding: 18px; text-align: center; color: var(--ink-4); font-size: 12px; }
.sr-msg.err { color: var(--warn); }

.qty-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 4px; }
.qty-label { font-size: 13px; color: var(--ink-2); font-weight: 600; }
.qty-stepper { display: flex; align-items: center; border: 1px solid var(--line-2); border-radius: var(--r-sm); overflow: hidden; }
.qty-btn { width: 46px; height: 46px; font-size: 20px; color: var(--ink-2); background: rgba(255,255,255,0.03); display: flex; align-items: center; justify-content: center; cursor: pointer; }
.qty-btn:hover { background: var(--gold-10); color: var(--gold); }
.qty-input { width: 70px; height: 46px; text-align: center; background: var(--surface); border: none; border-left: 1px solid var(--line-2); border-right: 1px solid var(--line-2); color: var(--ink); font-family: 'Oswald', var(--font-ui); font-size: 22px; outline: none; -moz-appearance: textfield; }
.qty-input::-webkit-outer-spin-button, .qty-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.serving-meta { font-family: var(--font-mono); font-size: 10px; color: var(--ink-4); margin-top: 7px; min-height: 13px; }

.confirm-macros { display: grid; grid-template-columns: repeat(3,1fr); gap: 10px; margin-top: 4px; }
.cm { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-sm); padding: 10px 12px; text-align: center; }
.cm .k { font-family: var(--font-mono); font-size: 9px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-4); }
.cm .v { font-family: 'Oswald', var(--font-ui); font-size: 20px; color: var(--ink); margin-top: 4px; }
.confirm-kcal { text-align: center; padding: 14px; background: var(--gold-10); border: 1px solid var(--gold-18); border-radius: var(--r-md); margin: 16px 0; }
.confirm-kcal .v { font-family: 'Oswald', var(--font-ui); font-weight: 700; font-size: 38px; color: var(--gold); line-height: 1; }
.confirm-kcal .u { font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--ink-3); margin-top: 4px; }

.sheet-foot { display: flex; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--line); }
.btn-row { display: flex; gap: 10px; width: 100%; }
.cal-btn-primary { flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 12px; border-radius: var(--r-sm); background: var(--gold-grad); color: #0b0905; font-size: 13px; font-weight: 700; box-shadow: 0 8px 20px -10px rgba(212,175,55,0.5); cursor: pointer; border: none; }
.cal-btn-primary:disabled { opacity: 0.5; cursor: default; }
.cal-btn-secondary { padding: 12px 18px; border-radius: var(--r-sm); background: rgba(255,255,255,0.04); border: 1px solid var(--line-2); color: var(--ink-2); font-size: 13px; font-weight: 500; cursor: pointer; }
.cal-btn-secondary:hover { border-color: var(--gold-30); color: var(--ink); }

/* ===== Barcode scanner ===== */
.bc-reader { width: 100%; max-width: 340px; margin: 0 auto; border-radius: var(--r-md); overflow: hidden; background: #000; min-height: 210px; display: flex; align-items: center; justify-content: center; }
.bc-reader video { width: 100% !important; height: auto !important; display: block; }
.bc-reader__placeholder { color: var(--ink-5); font-size: 12px; text-align: center; padding: 24px; }
.bc-hint { text-align: center; font-size: 12px; color: var(--ink-3); margin-top: 14px; line-height: 1.5; }
.bc-hint.err { color: var(--warn); }
.bc-or { display: flex; align-items: center; gap: 10px; margin: 16px 0 12px; color: var(--ink-5); font-size: 10px; font-family: var(--font-mono); letter-spacing: 0.12em; text-transform: uppercase; }
.bc-or::before, .bc-or::after { content: ''; flex: 1; height: 1px; background: var(--line); }
.bc-manual { display: flex; gap: 8px; }
.bc-manual .inp { flex: 1; }
.bc-notfound { text-align: center; padding: 26px 14px; color: var(--ink-3); }
.bc-notfound i { font-size: 30px; color: var(--ink-5); margin-bottom: 12px; }
.bc-notfound h3 { font-size: 15px; color: var(--ink-2); font-weight: 600; margin-bottom: 6px; }
.bc-notfound p { font-size: 12px; line-height: 1.6; max-width: 300px; margin: 0 auto 16px; }
.bc-notfound .btn-row { max-width: 300px; margin: 0 auto; }
.bc-code { font-family: var(--font-mono); color: var(--ink-2); }

/* ===== Photo (AI vision) ===== */
.ph-drop { width: 100%; display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 34px 18px; border: 1.5px dashed var(--line-strong); border-radius: var(--r-md); background: rgba(255,255,255,0.02); color: var(--ink-2); transition: border .18s, background .18s; cursor: pointer; }
.ph-drop:hover { border-color: var(--gold-30); background: var(--gold-10); }
.ph-drop i { font-size: 30px; color: var(--gold); margin-bottom: 4px; }
.ph-drop span { font-size: 14px; font-weight: 600; color: var(--ink); }
.ph-drop small { font-size: 11px; color: var(--ink-4); }
.ph-note { display: flex; align-items: center; gap: 8px; justify-content: center; margin-top: 14px; font-size: 11px; color: var(--ink-4); }
.ph-note i { color: var(--ink-5); }
.ph-loading { display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 24px 14px; }
.ph-thumb-lg { width: 160px; height: 160px; object-fit: cover; border-radius: var(--r-md); border: 1px solid var(--line-2); filter: saturate(0.9); }
.ph-spin { font-size: 22px; color: var(--gold); }
.ph-load-txt { font-size: 13px; color: var(--ink-3); }
.ph-review-head { display: flex; gap: 14px; align-items: center; margin-bottom: 14px; }
.ph-thumb { width: 60px; height: 60px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line-2); flex-shrink: 0; }
.ph-rh-title { font-family: var(--font-serif); font-size: 18px; font-weight: 500; color: var(--ink); }
.ph-rh-sub { font-size: 11px; color: var(--ink-4); margin-top: 3px; line-height: 1.4; }
.ph-est-note { display: flex; align-items: center; gap: 8px; justify-content: center; font-size: 11px; color: var(--gold); background: var(--gold-10); border: 1px solid var(--gold-18); border-radius: var(--r-sm); padding: 8px 12px; margin-bottom: 8px; }
.ph-items { display: flex; flex-direction: column; }
.ph-item { display: flex; align-items: center; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.ph-name { flex: 1; min-width: 0; }
.ph-name-inp { width: 100%; background: none; border: none; border-bottom: 1px solid transparent; color: var(--ink); font-family: var(--font-ui); font-size: 13px; font-weight: 500; padding: 2px 0; outline: none; }
.ph-name-inp:focus { border-bottom-color: var(--gold-30); }
.ph-name small { display: block; font-family: var(--font-mono); font-size: 9px; color: var(--ink-4); margin-top: 2px; }
.ph-mini-step { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.ph-mini-btn { width: 26px; height: 26px; border-radius: 6px; border: 1px solid var(--line-2); color: var(--ink-2); font-size: 14px; display: flex; align-items: center; justify-content: center; cursor: pointer; }
.ph-mini-btn:hover { border-color: var(--gold-30); color: var(--gold); }
.ph-qv { font-family: 'Oswald', var(--font-ui); font-size: 14px; min-width: 20px; text-align: center; color: var(--ink); }
.ph-kc { font-family: 'Oswald', var(--font-ui); font-size: 16px; color: var(--ink-2); min-width: 54px; text-align: right; flex-shrink: 0; }
.ph-kc small { font-family: var(--font-mono); font-size: 9px; color: var(--ink-5); }
.ph-rm { width: 24px; height: 24px; border-radius: 6px; color: var(--ink-5); font-size: 11px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; cursor: pointer; }
.ph-rm:hover { color: var(--err); background: rgba(224,108,108,0.08); }
.ph-total-row { display: flex; align-items: center; justify-content: space-between; padding: 14px 2px 2px; font-size: 12px; color: var(--ink-3); }
.ph-total-row b { font-family: 'Oswald', var(--font-ui); font-size: 20px; color: var(--gold); }

/* ================================================
   MOBILE
   ================================================ */
@media (max-width: 760px) {
  .cal-page { max-width: 100%; }
  .cal-grid { grid-template-columns: 1fr; }
  .method-row { grid-template-columns: repeat(2,1fr); }
}

/* Calorie home-launcher tile (mobile): today's kcal vs target + a small ring */
.mh-cal .mh-cal-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-top: 6px; }
.mh-cal-stat { display: flex; align-items: baseline; gap: 4px; flex-wrap: wrap; }
.mh-cal-stat b { font-family: 'Oswald', var(--font-ui); font-size: 30px; font-weight: 600; line-height: 1; color: var(--ink); }
.mh-cal-stat small { font-size: 15px; color: var(--ink-4); }
.mh-cal-stat span { font-size: 11.5px; color: var(--ink-3); margin-left: 8px; align-self: center; }
.mh-cal-mini { flex-shrink: 0; width: 50px; height: 50px; position: relative; }
.mh-cal-mini svg { width: 50px; height: 50px; transform: rotate(-90deg); }
.mh-cal-mini .mhc-pct { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-family: 'Oswald', var(--font-ui); font-size: 13px; font-weight: 600; color: var(--gold); }
