:root{
  color-scheme: dark;

  --frame-bg: #07080b;
  --panel-bg: #0c0f14;
  --card-bg: #111622;
  --card-2: #0f1420;
  --input-bg: #0b0f18;

  --line: rgba(255,255,255,.10);
  --line-2: rgba(255,255,255,.07);

  --text: rgba(255,255,255,.92);
  --muted: rgba(255,255,255,.68);
  --muted-2: rgba(255,255,255,.50);

  --accent: #39d353;
  --danger: #ff4d4d;

  --hl-blue: 120, 170, 255;
  --hl-blue-strong: 0, 140, 255;

  --blue-line: rgba(74,168,255,.55);
  --blue-glow: rgba(74,168,255,.12);
}

html{ color-scheme: dark; }
*{ box-sizing:border-box; }

body{
  margin:0;
  background: var(--frame-bg);
  font-family: 'Manrope', ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  color: var(--text);
  font-size: 14px;
  line-height: 1.35;
}

img{ max-width:100%; }

.app,
.shell,
.appShell{
  max-width: 1280px;
  margin: 18px auto;
}

.app{
  padding: 18px;
  background: var(--panel-bg);
  border: 1px solid rgba(255,255,255,.06);
  border-radius: 18px;
  box-shadow: 0 24px 70px rgba(0,0,0,.55);
}

.shell{ padding:18px; }

.center{ text-align:center; }
.text{
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}
.msg{
  margin-top: 10px;
  min-height: 18px;
  font-size: 12px;
  color: var(--muted);
}
.labelTitle{
  font-size: 12px;
  font-weight: 800;
  color: var(--muted);
}
.grow{ flex:1 1 auto; min-width:0; }
.logo{
  display:block;
  width:min(180px, 60vw);
  margin:0 auto 18px;
}

/* =========================
   TOPBAR
   ========================= */

.topbar{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  padding:14px 16px;
  border-radius:14px;
  background: linear-gradient(180deg, rgba(255,255,255,.05), rgba(255,255,255,.03));
  border: 1px solid rgba(255,255,255,.08);
}

.title{
  font-weight:800;
  letter-spacing:.2px;
  color: var(--text);
}
.subtitle{
  font-size:12px;
  color: var(--muted-2);
  text-transform:uppercase;
  letter-spacing:1.2px;
  margin-top:2px;
}

.topbar.topbarCockpit{
  display:grid;
  grid-template-columns: auto 1fr auto;
  align-items:center;
  gap:12px;
  padding:12px 14px;
  border-radius:14px;
  border: 1px solid rgba(var(--hl-blue-strong), .35);
  background: linear-gradient(180deg, rgba(255,255,255,.05), rgba(255,255,255,.02));
  box-shadow:
    0 18px 50px rgba(0,0,0,.45),
    0 0 34px rgba(var(--hl-blue-strong), .12),
    inset 0 1px 0 rgba(255,255,255,.06);
}

.topbarLeft,
.topbarCenter,
.topbarRight{
  display:flex;
  align-items:center;
  min-width:0;
}

.topbarLeft{ justify-content:flex-start; }
.topbarCenter{ justify-content:center; }
.topbarRight{ justify-content:flex-end; }

.topbarTitle{
  font-size: 22px;
  font-weight: 900;
  letter-spacing: .4px;
  color: rgba(255,255,255,.95);
  text-align:center;
  white-space:nowrap;
  text-shadow:
    0 0 8px rgba(var(--hl-blue-strong), .45),
    0 0 18px rgba(var(--hl-blue-strong), .35),
    0 0 40px rgba(var(--hl-blue-strong), .25),
    0 0 70px rgba(var(--hl-blue-strong), .18);
}

.appLogo{
  height: 72px;
  width: auto;
  display:block;
  background: transparent;
  filter:
    drop-shadow(0 0 10px rgba(var(--hl-blue-strong), .18))
    drop-shadow(0 0 22px rgba(var(--hl-blue-strong), .10));
}

.topbarHelp{
  width: 38px;
  height: 38px;
  border-radius: 12px;
  display:grid;
  place-items:center;
  border: 1px solid rgba(255,255,255,.12);
  background: rgba(255,255,255,.06);
  color: rgba(255,255,255,.88);
  text-decoration:none;
  flex:0 0 auto;
}
.topbarHelp:hover{
  border-color: rgba(var(--hl-blue-strong), .55);
  box-shadow: 0 0 18px rgba(var(--hl-blue-strong), .16);
}
.topbarHelp svg{
  width:18px;
  height:18px;
  fill: currentColor;
}

/* =========================
   BUTTONS / FORMS
   ========================= */

.btn{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  min-height:36px;
  padding:0 14px;
  border-radius:10px;
  font-size:13px;
  font-weight:900;
  letter-spacing:.2px;
  border:1px solid transparent;
  cursor:pointer;
  transition: all .15s ease;
  text-align:center;
}

.btn.primary{
  background: linear-gradient(180deg, rgba(var(--hl-blue-strong), .95), rgba(var(--hl-blue-strong), .80));
  border:1px solid rgba(var(--hl-blue-strong), .85);
  color:#fff;
  box-shadow:
    0 6px 18px rgba(var(--hl-blue-strong), .25),
    inset 0 1px 0 rgba(255,255,255,.15);
}
.btn.primary:hover{
  transform: translateY(-1px);
  background: linear-gradient(180deg, rgba(var(--hl-blue-strong), 1), rgba(var(--hl-blue-strong), .9));
}
.btn.primary:active{
  transform: translateY(0);
  box-shadow:
    0 3px 10px rgba(var(--hl-blue-strong), .25),
    inset 0 1px 0 rgba(255,255,255,.12);
}

.btn.secondary{
  background: rgba(255,255,255,.04);
  border:1px solid rgba(var(--hl-blue-strong), .35);
  color: rgba(255,255,255,.85);
}
.btn.secondary:hover{
  background: rgba(var(--hl-blue-strong), .08);
  border-color: rgba(var(--hl-blue-strong), .6);
  color: #fff;
}
.btn.secondary:active{ background: rgba(var(--hl-blue-strong), .12); }

.btn.danger{
  background: rgba(255,77,77,.14);
  border-color: rgba(255,77,77,.30);
  color: rgba(255,235,235,.92);
}

select,
input,
textarea{
  width:100%;
  background: var(--input-bg);
  color: var(--text);
  border: 1px solid rgba(255,255,255,.10);
  border-radius:10px;
  outline:none;
  font-size: 14px;
  font-family: inherit;
}

select,
input{
  padding: 7px 10px;
  height: 34px;
}

textarea{
  min-height: 86px;
  padding:10px;
  resize:vertical;
}

select:focus,
input:focus,
textarea:focus{
  border-color: rgba(57,211,83,.55);
  outline: 3px solid rgba(57,211,83,.16);
  outline-offset: 2px;
}

select{
  background: var(--input-bg) !important;
  color: var(--text) !important;
}
option{
  background: #0b0f18;
  color: rgba(255,255,255,.92);
}

label{
  display:flex;
  flex-direction:column;
  gap:6px;
  font-size:13px;
  font-weight:600;
  color: var(--muted);
}

/* =========================
   LAYOUT / CARDS
   ========================= */

.grid{
  display:grid;
  grid-template-columns: repeat(12, 1fr);
  gap:12px;
  margin-top:12px;
}

.card{
  grid-column: span 6;
  background: var(--card-bg);
  color: var(--text);
  border: 1px solid rgba(255,255,255,.08);
  border-radius:16px;
  padding:14px;
  box-shadow:
    0 26px 70px rgba(0,0,0,.55),
    0 10px 26px rgba(0,0,0,.35),
    inset 0 1px 0 rgba(255,255,255,.07);
}
.card.wide{ grid-column: span 12; }

.card.framed{
  border: 1px solid rgba(var(--hl-blue-strong), .35);
  box-shadow:
    0 20px 60px rgba(0,0,0,.45),
    inset 0 1px 0 rgba(255,255,255,.06);
}

.card.hero{
  position: relative;
  border: 1px solid rgba(var(--hl-blue-strong), .45);
  box-shadow:
    0 40px 120px rgba(0,0,0,.78),
    0 20px 60px rgba(0,0,0,.55),
    0 0 80px rgba(var(--hl-blue-strong), .28);
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}
.card.hero::before{
  content:"";
  position:absolute;
  inset:-1px;
  border-radius:16px;
  pointer-events:none;
  background: linear-gradient(135deg, rgba(var(--hl-blue-strong), .35), rgba(var(--hl-blue-strong), 0) 40%);
  opacity:.55;
  mix-blend-mode: screen;
}
@media (hover:hover){
  .card.hero:hover{
    transform: translateY(-3px);
    box-shadow:
      0 36px 110px rgba(0,0,0,.72),
      0 18px 46px rgba(0,0,0,.50),
      0 0 55px rgba(var(--hl-blue-strong), .18),
      inset 0 1px 0 rgba(255,255,255,.10);
  }
}

h2{
  margin:0 0 12px;
  font-size:18px;
  font-weight:800;
  color: var(--text);
  letter-spacing:.2px;
}
.card.hero > h2{
  text-align:center;
  font-size:22px;
  font-weight:900;
  letter-spacing:.4px;
  margin-bottom:14px;
  text-shadow:
    0 0 14px rgba(var(--hl-blue-strong), .22),
    0 0 30px rgba(var(--hl-blue-strong), .14);
}
h3{
  margin:0 0 10px;
  font-size:14px;
  font-weight:700;
  color: var(--muted);
}

.row{
  display:flex;
  gap:10px;
  align-items:center;
}

/* =========================
   TAGESZIELE
   ========================= */

.targetsWrap{
  display:flex;
  gap:14px;
  align-items:stretch;
}

.targetsLeft{
  flex: 1 1 auto;
  min-width: 520px;
  display:flex;
  flex-direction:column;
}
.targetsRight{
  flex:0 0 auto;
  display:flex;
  align-items:stretch;
}
.targets{
  display:grid;
  grid-template-columns: repeat(4, minmax(120px, 1fr));
  gap:10px;
}
.targets input{
  height: 36px;
  font-weight:800;
}
.targetsActions{
  margin-top:auto;
  padding-top:12px;
}

.kpiGrid{
  height:100%;
  display:grid;
  grid-template-columns: 88px repeat(4, 78px);
  column-gap:10px;
  row-gap:10px;
  align-content:start;
  padding:12px 0 0 14px;
  border-left:1px solid var(--line);
}
.kpiHead{
  font-size:11px;
  font-weight:900;
  color: var(--muted-2);
  text-transform:uppercase;
  letter-spacing:1.1px;
  text-align:right;
}
.kpiLabel{
  font-size:12px;
  font-weight:900;
  color: var(--muted);
  white-space:nowrap;
}
.kpiVal{
  width:78px;
  height:36px;
  display:flex;
  align-items:center;
  justify-content:flex-end;
  padding:0 8px;
  border-radius:10px;
  border:1px solid rgba(255,255,255,.10);
  background: rgba(255,255,255,.04);
  font-size:13px;
  font-weight:900;
  color: var(--text);
}
.kpiVal.neg{
  border-color: rgba(255,77,77,.22);
  background: rgba(255,77,77,.08);
  color: rgba(255,235,235,.92);
}

/* =========================
   MACRO HEADER / TABLE
   ========================= */

.macroHeader{
  display:flex;
  align-items:flex-end;
  justify-content:space-between;
  gap:12px;
  margin-bottom:12px;
}

.macroControls{
  display:flex;
  align-items:flex-end;
  gap:10px;
  flex-wrap:wrap;
  justify-content:flex-start;
  flex:1 1 auto;
  min-width:0;
}

.macroActions{
  display:flex;
  align-items:flex-end;
  justify-content:flex-end;
  gap:10px;
  flex:0 0 auto;
}

.ctrl{
  min-width:0;
}

.ctrlRecipe{
  width: 260px;
  flex: 0 0 260px;
}

.ctrlPortions{
  width: 56px;
  min-width: 56px;
  flex: 0 0 56px;
}

.ctrl select{ width:100%; }
.ctrlSmall select{ width:100%; }

.macroHeader label{
  font-size:12px;
  font-weight:800;
  color: var(--muted);
}

.macroHeader select{
  height:36px;
  padding:6px 10px;
  font-size:13px;
  font-weight:800;
  letter-spacing:.1px;
  border-color: rgba(255,255,255,.16);
  background: rgba(255,255,255,.06);
}

.macroHeader select:focus{
  border-color: rgba(var(--hl-blue-strong), .80);
  outline: 3px solid rgba(var(--hl-blue-strong), .18);
  outline-offset: 2px;
}

.optimizerMode{
  display:flex;
  gap:8px;
  padding:6px;
  border:1px solid rgba(255,255,255,.10);
  border-radius:14px;
  background: rgba(0,0,0,.18);
}

.viewTab{
  min-height:36px;
  padding:0 14px;
  border-radius:12px;
  border:1px solid rgba(255,255,255,.10);
  background: rgba(255,255,255,.06);
  color: var(--muted);
  font-weight:900;
  cursor:pointer;
  white-space:nowrap;
}

.viewTab.active{
  color: var(--text);
  border-color: rgba(var(--hl-blue-strong), .55);
  background: rgba(var(--hl-blue-strong), .12);
  box-shadow: 0 0 26px rgba(var(--hl-blue-strong), .10);
}

.tableWrap{
  overflow:auto;
  -webkit-overflow-scrolling: touch;
  border:1px solid var(--line);
  border-radius:14px;
  background: var(--card-2);
}

#ingTable,
#journalTable{
  width:100%;
  border-collapse:collapse;
}

#ingTable{
  table-layout:auto;
  min-width:980px;
}

#ingTable th,
#ingTable td,
#journalTable th,
#journalTable td{
  padding:8px;
  border-bottom:1px solid rgba(255,255,255,.06);
  color: var(--text);
}

#ingTable td{
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
}

#ingTable thead{ position:relative; z-index:2; }
#ingTable tbody{ position:relative; z-index:1; }

#ingTable th,
#journalTable th{
  position:sticky;
  top:0;
  z-index:2;
  background: var(--card-2);
  font-size:12px;
  color: var(--muted);
  text-align:left;
  border-bottom:1px solid var(--line-2);
  white-space:nowrap;
  vertical-align:middle;
}

#ingTable thead tr:nth-child(1) th{
  top:0;
  z-index:3;
  font-weight:800;
  color: var(--text);
}
#ingTable thead tr:nth-child(2) th{
  top:34px;
  z-index:2;
}

#ingTable td input{
  width:100%;
  min-width:0;
  height:30px;
  padding:6px 8px;
  background: var(--input-bg);
  color: var(--text);
  border:1px solid rgba(255,255,255,.10);
  border-radius:10px;
}
#ingTable td input[readonly]{
  background: rgba(255,255,255,.06);
  border-color: rgba(255,255,255,.10);
  color: var(--text);
  opacity:1;
}
#ingTable td:nth-child(n+2) input{ text-align:right; }

#ingTable .col-ing{
  width:260px;
  min-width:260px;
}

#ingTable .orig-col,
#ingTable .adj-col{
  width:85px;
  min-width:85px;
}

#ingTable .col-adjg{
  width: 100px;
}

#ingTable .col-adjpct{
  width: 100px;
}

#ingTable.view-original .adj-col,
#ingTable.view-original .group-adjusted{
  display:none;
}

#ingTable.view-adjusted .orig-col,
#ingTable.view-adjusted .group-original{
  display:none;
}

.macroApplyBar{
  margin-top:12px;
  display:flex;
  gap:12px;
  flex-wrap:wrap;
}

/* top driver highlights */
td.hl-original,
td.hl-adjusted,
td.hl-ing{
  background: transparent !important;
  color: var(--text);
}
td.hl-original input,
td.hl-adjusted input,
td.hl-ing input{
  border-color: rgba(var(--hl-blue-strong), .95) !important;
  background: rgba(var(--hl-blue), .14) !important;
  box-shadow:
    0 0 0 1px rgba(var(--hl-blue-strong), .55),
    0 0 18px rgba(var(--hl-blue-strong), .22);
  font-weight: 800;
}
td.hl-ing input{
  background: rgba(var(--hl-blue), .18) !important;
  box-shadow:
    0 0 0 1px rgba(var(--hl-blue-strong), .65),
    0 0 22px rgba(var(--hl-blue-strong), .28);
}
td.hl-original input:focus,
td.hl-adjusted input:focus,
td.hl-ing input:focus{
  box-shadow:
    0 0 0 3px rgba(57,211,83,.16),
    0 0 18px rgba(57,211,83,.10) !important;
}

/* =========================
   TOTALS
   ========================= */

.totals2{
  margin-top:14px;
  display:grid;
  gap:14px;
}
.totRow{
  border-top:1px solid var(--line);
  padding-top:12px;
}
.totTitle{
  color:var(--text);
  font-weight:900;
  font-size:14px;
  letter-spacing:.2px;
  margin-bottom:8px;
}
.totCols{
  display:grid;
  grid-template-columns:1fr 1fr;
  gap:14px;
}
.totCol{
  border: 1px solid var(--blue-line);
  border-radius:16px;
  padding:14px 14px 12px;
  background: rgba(255,255,255,.03);
  box-shadow:
    0 0 0 1px rgba(74,168,255,.10) inset,
    0 14px 34px rgba(0,0,0,.35),
    0 0 26px var(--blue-glow);
}
.totLabel{
  font-size:12px;
  color:var(--muted);
  margin-bottom:6px;
  font-weight:800;
}
#totalsTotalOrig,
#totalsTotalAdj,
#totalsPortionOrig,
#totalsPortionAdj{
  display:flex;
  flex-wrap:wrap;
  align-items:baseline;
  gap:10px;
  font-size:14px;
  line-height:1.2;
  color: var(--text);
}
.totKcal{
  font-size:18px;
  font-weight:900;
  letter-spacing:.2px;
  color: var(--text);
  text-shadow: 0 0 14px rgba(74,168,255,.14);
}
.totSep{
  color: rgba(255,255,255,.35);
  font-weight:800;
}
.totMacros{
  font-size:14px;
  font-weight:800;
  color: rgba(255,255,255,.82);
}
#totalsTotalAdj,
#totalsPortionAdj{
  text-shadow: 0 0 12px rgba(var(--hl-blue-strong), .18);
}

/* =========================
   SAVE BOX
   ========================= */

.saveBox{
  margin-top:16px;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 16px;
  padding: 12px;
  background: rgba(255,255,255,.03);
  box-shadow:
    0 12px 30px rgba(0,0,0,.35),
    inset 0 1px 0 rgba(255,255,255,.06);
}

.saveMode{
  display:flex;
  gap:8px;
  padding:6px;
  border: 1px solid rgba(255,255,255,.10);
  border-radius:14px;
  background: rgba(0,0,0,.18);
  margin-bottom:12px;
}
.saveTab{
  flex:1;
  min-height:36px;
  border-radius:12px;
  border:1px solid rgba(255,255,255,.10);
  background: rgba(255,255,255,.06);
  color: var(--muted);
  font-weight:900;
  cursor:pointer;
}
.saveTab.active,
.saveTab[data-active="1"]{
  color: var(--text);
  border-color: rgba(var(--hl-blue-strong), .55);
  background: rgba(var(--hl-blue-strong), .12);
  box-shadow: 0 0 26px rgba(var(--hl-blue-strong), .10);
}

.saveBody{ padding:2px 2px 0; }
.saveRow{
  display:grid;
  grid-template-columns: 220px 1fr auto;
  gap:10px;
  align-items:end;
}
.saveField{ min-width:0; }
#slotSelect,
#slotName{
  height:40px;
  font-size:15px;
}
#slotSelect{ font-weight:900; }
#slotName{ font-weight:800; }

.saveActions{
  display:flex;
  gap:10px;
  align-items:center;
  flex-wrap:wrap;
}
.saveActions .btn{
  min-height:40px;
  padding:10px 14px;
  font-weight:900;
}
.saveActionsSingle{
  margin-top:12px;
}

/* =========================
   JOURNAL
   ========================= */

.journalStack{
  display:flex;
  flex-direction:column;
  gap:12px;
}

.journalCard{
  background: var(--card-bg);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
}

.journalCollapse{
  background: var(--card-bg);
  border: 1px solid var(--line);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 18px 46px rgba(0,0,0,.35);
}

.journalCollapseSummary{
  list-style: none;
  cursor: pointer;
  padding: 14px 16px;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  font-weight: 900;
  font-size: 16px;
  color: var(--text);
  background: rgba(255,255,255,.03);
  border-bottom: 1px solid rgba(255,255,255,.06);
}

.journalCollapseSummary::-webkit-details-marker{ display:none; }

.journalCollapseSummary::after{
  content:"▾";
  opacity:.7;
  transform: translateY(-1px);
  transition: transform .15s ease;
}

.journalCollapse[open] .journalCollapseSummary::after{
  transform: rotate(180deg) translateY(1px);
}

.journalCollapseBody{
  padding: 14px 14px 16px 14px;
}

.journalTitle{
  font-weight:800;
  margin-bottom:12px;
  color: var(--text);
  font-size:16px;
}

.journalToolbar{
  display:flex;
  gap:12px;
  align-items:flex-end;
  flex-wrap:wrap;
  margin-bottom:14px;
}

.journalPeriodCtrl{
  max-width:220px;
}

.journalForm{
  display:grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap:10px;
}
@media (min-width: 1100px){
  .journalForm{
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap:8px;
  }
}
@media (min-width: 821px) and (max-width: 1099px){
  .journalForm{
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap:8px;
  }
}
.journalForm label{
  gap:4px;
  font-size:12px;
}
.journalForm input,
.journalForm select{
  height:32px;
  padding:6px 9px;
  font-size:13px;
}
.journalForm textarea{
  font-size:13px;
  padding:9px;
}
.journalNotes{ grid-column:1 / -1; }
.journalActions{
  grid-column:1 / -1;
  margin-top:4px;
  flex-wrap:wrap;
}

.journalSummary{
  display:flex;
  flex-direction:column;
  gap:12px;
}
.journalAverages{
  display:grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap:10px;
}
.sumItem{
  border: 1px solid rgba(255,255,255,.08);
  background: rgba(255,255,255,.03);
  border-radius: 14px;
  padding: 10px 12px;
  display:flex;
  align-items:baseline;
  justify-content:space-between;
  gap:10px;
}
.sumLabel{
  font-size:12px;
  font-weight:800;
  color: var(--muted);
  white-space: nowrap;
}
.sumVal{
  font-size:14px;
  font-weight:900;
  color: var(--text);
  text-align:right;
  white-space: nowrap;
}

.journalWeightBox{
  border: 1px solid rgba(var(--hl-blue-strong), .28);
  background: rgba(var(--hl-blue), .10);
  border-radius: 16px;
  padding: 12px;
  box-shadow:
    0 0 0 1px rgba(var(--hl-blue-strong), .10) inset,
    0 16px 40px rgba(0,0,0,.35);
}
.journalWeightTitle{
  font-weight:900;
  color: rgba(255,255,255,.90);
  font-size:13px;
  letter-spacing:.2px;
  margin-bottom:10px;
}
.journalWeightGrid{
  display:grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap:10px;
}
.wItem{
  border: 1px solid rgba(255,255,255,.10);
  background: rgba(0,0,0,.12);
  border-radius: 14px;
  padding: 10px 12px;
  display:flex;
  align-items:baseline;
  justify-content:space-between;
  gap:10px;
}
.wLabel{
  font-size:12px;
  font-weight:800;
  color: rgba(255,255,255,.72);
  white-space: nowrap;
}
.wVal{
  font-size:14px;
  font-weight:900;
  color: var(--text);
  text-align:right;
  white-space: nowrap;
}

#journalTable{
  min-width: 980px;
}
#journalTable th,
#journalTable td{
  font-size:12px;
  white-space:nowrap;
  vertical-align:top;
}

.jChartControls{
  display:flex;
  gap:12px;
  align-items:flex-end;
  flex-wrap:wrap;
  margin-bottom:10px;
}
.jChartControls label{
  font-size:12px;
  font-weight:800;
  color: rgba(255,255,255,.72);
}
.jChartControls select{
  height:40px;
  font-weight:900;
}

.jChartCheck{
  width:auto;
  flex-direction:row;
  align-items:center;
  gap:8px;
  padding: 6px 10px;
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 12px;
  background: rgba(255,255,255,.03);
  color: rgba(255,255,255,.85);
  font-size:13px;
  font-weight:900;
  min-height:40px;
}
.jChartCheck input{
  width:16px;
  height:16px;
  margin:0;
}

.jChartWrap{
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--card-2);
  overflow:hidden;
}
.jChart{
  width:100%;
  height:460px;
}

/* =========================
   BOOT / LICENSE
   ========================= */

.boot{
  position:fixed;
  inset:0;
  z-index:99999;
  display:flex;
  align-items:center;
  justify-content:center;
  background:#0b0b0b;
  color:#ffffff;
  font-family:Manrope,system-ui,sans-serif;
  padding:32px;
  text-align:center;
}
.bootCard{
  max-width:520px;
  width:100%;
  display:flex;
  flex-direction:column;
  align-items:center;
  justify-content:center;
}
.bootLogo{
  width:min(240px, 70vw);
  height:auto;
  display:block;
  margin:0 auto 26px auto;
}
.bootTitle{
  font-size:28px;
  font-weight:800;
  line-height:1.15;
  margin-bottom:10px;
}
.bootText{
  font-size:15px;
  color:rgba(255,255,255,.72);
  line-height:1.5;
  max-width:420px;
}

/* =========================
   RESPONSIVE
   ========================= */

@media (max-width: 980px){
  .targetsWrap{
    flex-direction:column;
    align-items:stretch;
  }

  .targetsLeft{ min-width:0; }
  .targetsRight{ width:100%; }

  .kpiGrid{
    grid-template-columns: 88px repeat(4, minmax(0, 1fr));
    padding:14px 0 0 0;
    border-left:none;
    border-top:1px solid var(--line);
    row-gap:12px;
  }

  .totCols{ grid-template-columns:1fr; }
  .journalAverages{ grid-template-columns: repeat(2, 1fr); }
  .journalWeightGrid{ grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 820px){
  .app{
    margin:10px;
    padding:12px;
    border-radius:16px;
  }

  .progressChartWrap{
  --chart-scale: .70;
  overflow-x: hidden;
  transform: translateZ(0);
}

.progressChartWrap .echart{
  transform: scale(var(--chart-scale));
  transform-origin: top left;
}

  .card{
    grid-column: span 12;
    padding:12px;
    border-radius:14px;
  }

  .topbar.topbarCockpit{
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items:center;
    gap:10px;
    padding:10px 12px;
  }

  .appLogo{ height:52px; }

  .topbarTitle{
    font-size:18px;
    line-height:1.1;
    white-space:nowrap;
  }

  .targets{
    grid-template-columns:1fr 1fr;
  }

  /* KEEP CURRENT GOOD MOBILE HEADER */
  .macroHeader{
    display:grid;
    grid-template-columns:1fr;
    gap:10px;
    align-items:stretch;
  }

  .macroControls{
    display:grid;
    grid-template-columns:minmax(0, 1fr) 64px;
    gap:8px;
    align-items:end;
    width:100%;
  }

  .ctrlRecipe{
    width:auto;
    min-width:0;
    flex:auto;
  }

  .ctrlPortions{
    width:64px;
    min-width:64px;
    flex:auto;
  }

  .optimizerMode{
    width:100%;
    justify-content:stretch;
  }

  .optimizerMode .viewTab{
    flex:1 1 0;
  }

  .macroActions{
    width:100%;
    justify-content:stretch;
  }

  .macroActions .btn{
    width:100%;
  }

  .saveRow{
    grid-template-columns:1fr;
  }

  .saveActions{
    justify-content:stretch;
  }

  .saveActions .btn{
    flex:1;
  }

  .journalToolbar{
    align-items:flex-end;
  }

  .journalPeriodCtrl{
    width:auto;
    max-width:220px;
  }

    .journalToolbar .journalPeriodCtrl select{
    min-width: 170px;
    width: auto;
  }

  .journalAverages{
    grid-template-columns:1fr 1fr;
    gap:8px;
  }

  .journalWeightGrid{
    grid-template-columns:1fr 1fr;
    gap:8px;
  }

    .sumItem,
  .wItem{
    padding:8px 10px;
    min-height:52px;
  }

  .sumLabel,
  .wLabel{
    font-size:11px;
  }

  .sumVal,
  .wVal{
    font-size:13px;
  }

  /* JOURNAL FORM: DATE FULL WIDTH, OTHERS TWO COLUMNS */
  .journalForm{
    grid-template-columns:1fr 1fr;
    gap:10px;
  }

  .journalForm > label:first-child,
  .journalNotes,
  .journalActions{
    grid-column:1 / -1;
  }

  .journalForm > label:first-child input[type="date"]{
    width:100%;
    min-width:0;
    max-width:100%;
    height:40px;
    font-size:14px;
    padding:0 12px;
    text-align:left;
    box-sizing:border-box;
    -webkit-appearance:none;
    appearance:none;
    background-image:none;
  }

  .journalForm > label:first-child input[type="date"]::-webkit-date-and-time-value{
    text-align:left;
  }

  .journalForm > label:first-child input[type="date"]::-webkit-datetime-edit{
    padding:0;
  }

  .journalForm > label:first-child input[type="date"]::-webkit-calendar-picker-indicator{
    opacity:0;
    display:none;
  }

  .jChartControls{
    display:grid;
    grid-template-columns:minmax(0, 1fr) auto;
    gap:8px;
    align-items:end;
  }

  .jChartControls .journalPeriodCtrl{
    grid-column:auto;
  }

  .jChartControls > *{
    min-width:0;
  }

  .jChartControls .journalPeriodCtrl select{
    height:36px;
    font-size:13px;
  }

  .jChartCheck{
    width:auto;
    min-height:36px;
    justify-content:flex-start;
    padding:6px 10px;
    font-size:13px;
  }

  /* RECIPE TABLE MOBILE: STABLE LEFT START + READABLE WIDTHS */

    .macroTableWrap{
    --macro-table-scale: .62;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    transform: translateZ(0);
  }

  .macroTableWrap #ingTable{
    width: max-content;
    min-width: 0;
    table-layout: fixed;
    transform: scale(var(--macro-table-scale));
    transform-origin: top left;
  }

  .tableWrap{
    overflow-x:auto;
    overflow-y:hidden;
    -webkit-overflow-scrolling:touch;
  }

  #ingTable{
    width:max-content;
    min-width:0;
    table-layout:fixed;
  }

  #ingTable th,
  #ingTable td{
    padding:6px 5px;
  }

  #ingTable th{
  font-size:10px;
  line-height:1.05;
}

 #ingTable td input{
  height:27px;
  padding:3px 5px;
  font-size:11px;
  border-radius:8px;
}

 #ingTable .col-ing{
  width:168px;
  min-width:168px;
}

 #ingTable .orig-col,
#ingTable .adj-col{
  width:52px;
  min-width:52px;
}

  #ingTable .col-adjg,
#ingTable .col-adjpct{
  width:66px;
  min-width:66px;
}

  #ingTable thead tr:nth-child(1) th{
    height:38px;
  }

  #ingTable thead tr:nth-child(2) th{
    top:38px;
  }

  #journalTable{ min-width:920px; }

  /* MOBILE JOURNAL CHART: SCALED LIKE MACRO TABLE */
  .jChartWrap{
    overflow:hidden;
  }

  .progressChartWrap{
    --journal-chart-scale: .70;
    overflow:hidden;
    transform: translateZ(0);
  }

  .progressChartWrap .jChart{
    min-width:0;
    height:320px;
    transform: scale(var(--journal-chart-scale));
    transform-origin: top left;
  }
}

@media (max-width: 560px){
  .app{
    margin:8px;
    padding:10px;
  }

  .progressChartWrap{
  --chart-scale: .62;
}

  .topbar.topbarCockpit{
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap:8px;
    padding:10px;
  }

  .appLogo{ height:44px; }

  .topbarTitle{
    font-size:16px;
    letter-spacing:.2px;
    white-space:nowrap;
  }

  .topbarHelp{
    width:36px;
    height:36px;
  }

  .targets{
    grid-template-columns:1fr 1fr;
    gap:8px;
  }

  .kpiGrid{
    grid-template-columns: 76px repeat(4, minmax(0, 1fr));
    column-gap:8px;
    row-gap:12px;
    padding-top:12px;
  }

  .kpiHead{
    font-size:10px;
    letter-spacing:.8px;
  }

  .kpiLabel{
    font-size:11px;
    line-height:1.15;
    white-space:normal;
    align-self:center;
  }

  .kpiVal{
    width:auto;
    min-width:0;
    font-size:12px;
    padding:0 6px;
  }

  .macroHeader{
    gap:8px;
  }

  .macroControls{
    grid-template-columns:minmax(0, 1fr) 60px;
    gap:8px;
  }

  .ctrlPortions{
    width:60px;
    min-width:60px;
  }

  .optimizerMode{
    display:grid;
    grid-template-columns:1fr 1fr;
    gap:8px;
  }

  .macroActions .btn,
  .macroApplyBar .btn,
  .saveActions .btn,
  .journalActions .btn,
  .jChartControls .btn{
    min-height:42px;
  }

  .tableWrap{
    border-radius:12px;
  }

  /* RECIPE TABLE VERY SMALL MOBILE */
  #ingTable{
    width:max-content;
    min-width:0;
    table-layout:fixed;
  }

  #ingTable th,
  #ingTable td{
    padding:5px 4px;
  }

  #ingTable th{
    font-size:10px;
    line-height:1.1;
  }

  #ingTable td input{
    height:26px;
    padding:3px 5px;
    font-size:11px;
    border-radius:7px;
  }

  #ingTable .col-ing{
    width:160px;
    min-width:160px;
  }

  #ingTable .orig-col,
  #ingTable .adj-col{
    width:50px;
    min-width:50px;
  }

  #ingTable .col-adjg,
  #ingTable .col-adjpct{
    width:68px;
    min-width:68px;
  }

  #ingTable thead tr:nth-child(1) th{
    height:36px;
  }

  #ingTable thead tr:nth-child(2) th{
    top:36px;
  }

    .macroTableWrap{
    --macro-table-scale: .58;
  }

  .totRow{
    padding-top:10px;
  }

  .totCol{
    padding:12px;
  }

  .totKcal{
    font-size:16px;
  }

  .totMacros{
    font-size:13px;
  }

  #totalsTotalOrig,
  #totalsTotalAdj,
  #totalsPortionOrig,
  #totalsPortionAdj{
    display:grid;
    grid-template-columns:1fr 1fr;
    gap:6px 10px;
    align-items:start;
  }

  .totSep{
    display:none;
  }

  .saveMode{
    flex-direction:column;
  }

  .saveTab{
    width:100%;
  }

  .saveActions{
    display:flex;
    gap:10px;
    flex-wrap:wrap;
  }

  .journalCollapseSummary{
    padding:12px 14px;
    font-size:15px;
  }

  .journalCollapseBody,
  .journalCard{
    padding:12px;
  }

  /* SAFE FIX: DATE + NOTES FULL WIDTH, REST TWO COLUMNS */
  .journalForm{
    grid-template-columns:1fr 1fr;
    gap:10px;
  }

  .journalForm > label:first-child,
  .journalNotes,
  .journalActions{
    grid-column:1 / -1;
  }

  .journalForm label{
    gap:5px;
  }

  .journalForm input,
  .journalForm select{
    height:40px;
    font-size:14px;
  }

  .journalForm > label:first-child input[type="date"]{
    width:100%;
    min-width:0;
    max-width:100%;
    height:40px;
    font-size:14px;
    padding:0 12px;
    text-align:left;
    box-sizing:border-box;
    -webkit-appearance:none;
    appearance:none;
    background-image:none;
  }

  .journalForm > label:first-child input[type="date"]::-webkit-date-and-time-value{
    text-align:left;
  }

  .journalForm > label:first-child input[type="date"]::-webkit-datetime-edit{
    padding:0;
  }

  .journalForm > label:first-child input[type="date"]::-webkit-calendar-picker-indicator{
    opacity:0;
    display:none;
  }

  .journalForm textarea{
    min-height:110px;
    font-size:14px;
  }

  .journalActions{
    display:grid;
    grid-template-columns:1fr;
    gap:10px;
    align-items:stretch;
  }

  .journalActions .btn{
    width:100%;
  }

  .sumItem,
  .wItem{
    padding:8px 9px;
  }

  .journalAverages{
    grid-template-columns:1fr 1fr;
    gap:8px;
  }

  .journalWeightGrid{
    grid-template-columns:1fr 1fr;
    gap:8px;
  }

  .sumLabel,
  .wLabel{
    font-size:11px;
  }

  .sumVal,
  .wVal{
    font-size:13px;
  }

  .journalToolbar{
    align-items:flex-end;
  }

  .journalPeriodCtrl{
    width:auto;
    max-width:190px;
  }

  .journalToolbar .journalPeriodCtrl select{
    min-width:160px;
    width:auto;
  }

  #journalTable{
    min-width:840px;
  }

  /* OLD-STYLE CHART FEEL */
  .jChartWrap{
    overflow:hidden;
  }

  .progressChartWrap{
    --journal-chart-scale: .62;
  }

  .progressChartWrap .jChart{
    min-width:0;
    height:300px;
  }

  .licenseShell{
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 32px 18px;
  }

  .licenseCard{
    width: min(760px, 100%);
    max-width: 760px;
    margin: 0 auto !important;
    padding: 24px !important;
  }

  .licenseInner{
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
  }

  .licenseLogo{
    width: min(240px, 60vw);
    margin: 0 0 18px 0;
  }

  .licenseIntro{
    max-width: 620px;
    margin: 0 auto 22px auto;
  }

  .licenseField{
    width: 100%;
    margin-bottom: 16px;
  }

  .licenseField input{
    width: 100%;
  }

  .licenseActions{
    width: 100%;
    display: flex;
    justify-content: center;
    margin-top: 12px;
    margin-bottom: 18px;
  }

  .licenseActions .btn{
    min-width: 180px;
  }

  .licenseMsg{
    width: 100%;
    text-align: center;
    margin-top: 0;
    margin-bottom: 10px;
  }

  .licenseHint{
    margin-top: 18px;
    max-width: 520px;
  }
}