/* ===========================================================
   Kalorien – Design Tokens
   =========================================================== */
:root{
  --bg: #F7F8F5;
  --surface: #FFFFFF;
  --surface-2: #EEF2EC;
  --surface-3: #E4E9E1;
  --text: #1B211D;
  --text-muted: #5B655F;
  --text-faint: #8B958E;
  --border: #DDE3DA;
  --border-strong: #1B211D;

  --primary: #2F6B5E;
  --primary-strong: #234F45;
  --primary-soft: #DEEBE6;
  --on-primary: #F6FBF9;

  --protein: #B84C3E;
  --protein-soft: #F5DFDA;
  --fat: #C6902A;
  --fat-soft: #F2E5C9;
  --carbs: #3E7C9B;
  --carbs-soft: #DCEAF1;

  --danger: #B84C3E;
  --success: #2F6B5E;

  --radius-sm: 8px;
  --radius: 14px;
  --radius-lg: 22px;
  --shadow-sm: 0 1px 2px rgba(20,25,20,.06), 0 1px 1px rgba(20,25,20,.04);
  --shadow: 0 8px 24px -12px rgba(20,25,20,.22);
  --shadow-lg: 0 20px 48px -16px rgba(20,25,20,.28);

  --font-display: 'Fraunces', Georgia, 'Times New Roman', serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace;

  --nav-h: 68px;
  --header-h: 56px;
  color-scheme: light;
}

:root[data-theme="dark"]{
  --bg: #10161A;
  --surface: #172026;
  --surface-2: #1D272E;
  --surface-3: #263139;
  --text: #EAEFEC;
  --text-muted: #9AA8A1;
  --text-faint: #6C7A73;
  --border: #26323A;
  --border-strong: #EAEFEC;

  --primary: #57A88F;
  --primary-strong: #7CC4AB;
  --primary-soft: #1C3630;
  --on-primary: #0D1512;

  --protein: #DE8272;
  --protein-soft: #3A2320;
  --fat: #E3BC63;
  --fat-soft: #392E19;
  --carbs: #7DBEDB;
  --carbs-soft: #17303B;

  --danger: #DE8272;
  --success: #57A88F;

  --shadow-sm: 0 1px 2px rgba(0,0,0,.3);
  --shadow: 0 8px 24px -12px rgba(0,0,0,.5);
  --shadow-lg: 0 20px 48px -16px rgba(0,0,0,.6);
  color-scheme: dark;
}

*, *::before, *::after{ box-sizing: border-box; }
html, body{ height: 100%; }
body{
  margin: 0;
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  transition: background-color .25s ease, color .25s ease;
  overscroll-behavior-y: none;
}
h1,h2,h3,h4{ margin: 0; font-family: var(--font-display); font-weight: 600; letter-spacing: -0.01em; }
p{ margin: 0; }
button{ font-family: inherit; }
input, select{ font-family: inherit; }
a{ color: inherit; }
::selection{ background: var(--primary-soft); }

.tabular{ font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1; }
.mono{ font-family: var(--font-mono); }

/* Focus visibility */
:focus-visible{
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ===========================================================
   App shell
   =========================================================== */
#app{
  max-width: 560px;
  margin: 0 auto;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  position: relative;
  background: var(--bg);
}

.app-header{
  position: sticky;
  top: 0;
  z-index: 20;
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.app-header .brand{
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 17px;
}
.app-header .brand .mark{
  width: 22px; height: 22px;
  border-radius: 50%;
  background: conic-gradient(var(--primary) 0deg 280deg, var(--fat) 280deg 320deg, var(--border) 320deg 360deg);
  flex: none;
}
.header-date{
  font-size: 13px;
  color: var(--text-muted);
  text-transform: capitalize;
}

main.view{
  flex: 1 1 auto;
  padding: 16px 16px calc(var(--nav-h) + 28px);
  animation: fadeIn .22s ease;
}
@keyframes fadeIn{ from{ opacity: 0; transform: translateY(4px);} to{ opacity: 1; transform: none; } }

/* Bottom navigation */
.bottom-nav{
  position: sticky;
  bottom: 0;
  z-index: 30;
  height: var(--nav-h);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-btn{
  appearance: none;
  border: none;
  background: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--text-faint);
  cursor: pointer;
  padding: 6px 0 8px;
  position: relative;
}
.nav-btn svg{ width: 22px; height: 22px; }
.nav-btn span{ font-size: 11px; font-weight: 500; }
.nav-btn.active{ color: var(--primary); }
.nav-btn.active::before{
  content: "";
  position: absolute;
  top: 2px;
  width: 22px; height: 3px;
  border-radius: 3px;
  background: var(--primary);
}

/* ===========================================================
   Nutrition-Label inspired cards (signature element)
   =========================================================== */
.label-card{
  background: var(--surface);
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 18px 18px 14px;
  box-shadow: var(--shadow-sm);
}
.label-card .label-title{
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 700;
  border-bottom: 6px solid var(--border-strong);
  padding-bottom: 8px;
  margin-bottom: 6px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}
.label-card .label-title small{
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
}
.label-row{
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.label-row:last-child{ border-bottom: none; }
.label-row .k{ color: var(--text); font-weight: 500; }
.label-row .v{ font-family: var(--font-mono); font-weight: 600; }
.label-row.thick{ border-bottom-width: 3px; border-color: var(--border-strong); }
.label-row.sub .k{ padding-left: 14px; color: var(--text-muted); font-weight: 400; }

/* ===========================================================
   Today / dashboard
   =========================================================== */
.today-hero{
  display: flex;
  align-items: center;
  gap: 20px;
  margin-bottom: 16px;
}
.ring-wrap{ position: relative; width: 148px; height: 148px; flex: none; }
.ring-wrap svg{ width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-track{ fill: none; stroke: var(--surface-3); stroke-width: 12; }
.ring-progress{ fill: none; stroke-width: 12; stroke-linecap: round; transition: stroke-dashoffset .5s ease, stroke .3s; }
.ring-center{
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.ring-center .num{ font-family: var(--font-display); font-size: 30px; font-weight: 700; line-height: 1; }
.ring-center .lbl{ font-size: 11px; color: var(--text-muted); margin-top: 4px; text-align: center; }

.hero-stats{ flex: 1; display: flex; flex-direction: column; gap: 8px; }
.hero-stat-row{ display: flex; justify-content: space-between; font-size: 13px; }
.hero-stat-row .k{ color: var(--text-muted); }
.hero-stat-row .v{ font-family: var(--font-mono); font-weight: 600; }
.hero-stat-row.over .v{ color: var(--danger); }

.macro-bars{ display: flex; flex-direction: column; gap: 10px; margin-top: 4px; }
.macro-bar-item{ display: grid; grid-template-columns: 64px 1fr auto; align-items: center; gap: 10px; font-size: 12.5px; }
.macro-bar-item .dot{ width: 9px; height: 9px; border-radius: 50%; display: inline-block; margin-right: 6px; }
.macro-bar-track{ height: 7px; border-radius: 6px; background: var(--surface-3); overflow: hidden; }
.macro-bar-fill{ height: 100%; border-radius: 6px; transition: width .4s ease; }
.macro-bar-item .amt{ font-family: var(--font-mono); color: var(--text-muted); white-space: nowrap; }

.section-heading{
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 22px 0 10px;
}
.section-heading h3{ font-size: 15px; letter-spacing: .01em; }
.section-heading .count{ font-size: 12px; color: var(--text-faint); font-family: var(--font-mono); }

.meal-list{ display: flex; flex-direction: column; gap: 8px; }

.meal-section{ margin-bottom: 18px; }
.meal-section-head{
  display: flex; align-items: center; gap: 10px;
  padding: 4px 2px 8px;
}
.meal-section-head .ms-name{ font-weight: 600; font-size: 14px; flex: 1; }
.meal-section-head .ms-kcal{ font-size: 12.5px; color: var(--text-muted); }
.meal-section-head .ms-add{
  appearance: none; border: 1.5px solid var(--border); background: var(--surface);
  color: var(--primary); width: 26px; height: 26px; border-radius: 8px; font-size: 16px;
  line-height: 1; cursor: pointer; flex: none;
  display: flex; align-items: center; justify-content: center;
}
.meal-section-head .ms-add:hover{ background: var(--primary-soft); }
.meal-section-empty{
  font-size: 12.5px; color: var(--text-faint); padding: 10px 2px;
  border: 1.5px dashed var(--border); border-radius: var(--radius-sm); text-align: center;
}
.meal-item{
  display: flex; align-items: center; gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 11px 12px;
}
.meal-item .m-icon{
  width: 36px; height: 36px; border-radius: 10px;
  background: var(--surface-2);
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; flex: none;
}
.meal-item .m-body{ flex: 1; min-width: 0; }
.meal-item .m-name{ font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meal-item .m-sub{ font-size: 12px; color: var(--text-muted); font-family: var(--font-mono); margin-top: 1px; }
.meal-item .m-kcal{ font-family: var(--font-mono); font-weight: 700; font-size: 14px; white-space: nowrap; }
.meal-item .m-del{
  appearance: none; border: none; background: none; color: var(--text-faint);
  width: 28px; height: 28px; border-radius: 8px; cursor: pointer; flex: none;
  display: flex; align-items: center; justify-content: center;
}
.meal-item .m-del:hover{ background: var(--protein-soft); color: var(--protein); }

.empty-state{
  text-align: center;
  padding: 34px 20px;
  color: var(--text-muted);
  border: 1.5px dashed var(--border);
  border-radius: var(--radius);
  font-size: 13.5px;
}
.empty-state .es-icon{ font-size: 26px; margin-bottom: 8px; }

/* Date switcher */
.date-switcher{
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px;
}
.date-switcher .ds-label{ font-family: var(--font-display); font-size: 18px; font-weight: 600; text-transform: capitalize; }
.icon-btn{
  appearance: none; border: 1px solid var(--border); background: var(--surface);
  width: 34px; height: 34px; border-radius: 10px; cursor: pointer;
  display: flex; align-items: center; justify-content: center; color: var(--text);
}
.icon-btn:hover{ background: var(--surface-2); }
.icon-btn:disabled{ opacity: .35; cursor: default; }

/* FAB */
.fab{
  position: fixed;
  right: calc(50% - 280px + 18px);
  bottom: calc(var(--nav-h) + 18px);
  width: 56px; height: 56px;
  border-radius: 18px;
  background: var(--primary);
  color: var(--on-primary);
  border: none;
  box-shadow: var(--shadow-lg);
  font-size: 26px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  z-index: 25;
}
@media (max-width: 592px){
  .fab{ right: 18px; }
}
.fab:active{ transform: scale(.94); }

/* ===========================================================
   Buttons & form controls
   =========================================================== */
.btn{
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 11px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background-color .15s ease, transform .1s ease;
}
.btn:active{ transform: scale(.98); }
.btn-primary{ background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn-primary:hover{ background: var(--primary-strong); }
.btn-ghost{ background: transparent; border-color: transparent; }
.btn-ghost:hover{ background: var(--surface-2); }
.btn-danger{ color: var(--danger); border-color: var(--protein-soft); }
.btn-danger:hover{ background: var(--protein-soft); }
.btn-block{ width: 100%; }
.btn-sm{ padding: 7px 12px; font-size: 12.5px; }

.field{ margin-bottom: 16px; }
.field label{ display: block; font-size: 12.5px; font-weight: 600; color: var(--text-muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .03em; }
.field input[type="text"],
.field input[type="number"],
.field input[type="search"],
.field select{
  width: 100%;
  padding: 11px 12px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 15px;
}
.field input:focus, .field select:focus{ border-color: var(--primary); }
.field .hint{ font-size: 11.5px; color: var(--text-faint); margin-top: 5px; }
.field-row{ display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

input[type="range"]{
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 6px; border-radius: 6px;
  background: var(--surface-3);
  outline: none;
}
input[type="range"]::-webkit-slider-thumb{
  -webkit-appearance: none; appearance: none;
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--primary);
  border: 3px solid var(--surface);
  box-shadow: 0 0 0 1px var(--primary);
  cursor: pointer;
  margin-top: -7px;
}
input[type="range"]::-moz-range-thumb{
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--primary); border: 3px solid var(--surface);
  box-shadow: 0 0 0 1px var(--primary); cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track{ height: 6px; border-radius: 6px; }

.card{
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow-sm);
}
.card + .card{ margin-top: 12px; }
.card-title{
  font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  color: var(--text-muted); margin-bottom: 12px;
  display: flex; align-items: center; justify-content: space-between;
}

/* Segmented control (theme) */
.segmented{
  display: grid; grid-template-columns: repeat(3, 1fr);
  background: var(--surface-2); border-radius: var(--radius-sm); padding: 3px; gap: 3px;
}
.segmented button{
  appearance: none; border: none; background: transparent; color: var(--text-muted);
  padding: 9px 6px; border-radius: 7px; font-size: 13px; font-weight: 600; cursor: pointer;
}
.segmented button.active{ background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }

/* Macro split sliders */
.macro-slider{ margin-bottom: 18px; }
.macro-slider .ms-head{ display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; font-size: 13.5px; }
.macro-slider .ms-head .name{ display: flex; align-items: center; gap: 8px; font-weight: 600; }
.macro-slider .ms-head .dot{ width: 10px; height: 10px; border-radius: 50%; }
.macro-slider .ms-head .val{ font-family: var(--font-mono); color: var(--text-muted); }
.macro-split-sum{
  display: flex; align-items: center; justify-content: space-between;
  padding-top: 10px; margin-top: 4px; border-top: 1px dashed var(--border);
  font-size: 13px; color: var(--text-muted);
}
.macro-split-sum .sum-val{ font-family: var(--font-mono); font-weight: 700; }
.macro-split-sum.ok .sum-val{ color: var(--success); }
.macro-split-sum.warn .sum-val{ color: var(--fat); }

/* Food search / picker */
.search-wrap{ position: relative; margin-bottom: 14px; }
.search-wrap svg{ position: absolute; left: 16px; top: 50%; transform: translateY(-50%); width: 21px; height: 21px; color: var(--text-faint); pointer-events: none; }
.search-wrap input{
  width: 100%;
  padding: 16px 16px 16px 48px;
  font-size: 17px;
  border-radius: var(--radius);
  border: 2px solid var(--border);
  background: var(--surface);
  color: var(--text);
}
.search-wrap input:focus{ border-color: var(--primary); }
.search-wrap input::-webkit-search-cancel-button{ transform: scale(1.3); margin-right: 2px; }

.cat-chips{ display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 12px; -ms-overflow-style: none; scrollbar-width: none; }
.cat-chips::-webkit-scrollbar{ display: none; }
.chip{
  flex: none; padding: 7px 13px; border-radius: 100px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text-muted); font-size: 12.5px; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.chip.active{ background: var(--primary); border-color: var(--primary); color: var(--on-primary); }

.food-list{ display: flex; flex-direction: column; gap: 7px; }
.food-item{
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 11px 12px; cursor: pointer; text-align: left; width: 100%;
}
.food-item:hover{ border-color: var(--primary); }
.food-item .f-name{ font-weight: 600; font-size: 14px; }
.food-item .f-sub{ font-size: 11.5px; color: var(--text-faint); font-family: var(--font-mono); margin-top: 2px; }
.food-item .f-kcal{ font-family: var(--font-mono); font-weight: 700; font-size: 13.5px; color: var(--primary); white-space: nowrap; }

/* Modal / sheet */
.sheet-overlay{
  position: fixed; inset: 0; background: rgba(10,14,12,.45);
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 100; opacity: 0; pointer-events: none; transition: opacity .2s ease;
}
.sheet-overlay.open{ opacity: 1; pointer-events: auto; }
.sheet{
  width: 100%; max-width: 560px; max-height: 88vh; overflow-y: auto;
  background: var(--surface);
  border-radius: 22px 22px 0 0;
  padding: 10px 18px calc(24px + env(safe-area-inset-bottom));
  transform: translateY(24px);
  transition: transform .25s ease;
  box-shadow: var(--shadow-lg);
}
.sheet-overlay.open .sheet{ transform: translateY(0); }
.sheet-handle{ width: 38px; height: 4px; border-radius: 4px; background: var(--border); margin: 8px auto 14px; }
.sheet-title{ font-size: 18px; margin-bottom: 14px; display: flex; justify-content: space-between; align-items: center; }
.sheet-title .close-x{
  appearance: none; border: none; background: var(--surface-2); color: var(--text-muted);
  width: 30px; height: 30px; border-radius: 50%; cursor: pointer; font-size: 15px;
  display: flex; align-items: center; justify-content: center;
}

.qty-stepper{ display: flex; align-items: center; gap: 10px; }
.qty-stepper button{
  width: 40px; height: 40px; border-radius: 10px; border: 1.5px solid var(--border);
  background: var(--surface); font-size: 18px; cursor: pointer; color: var(--text);
}
.qty-stepper input{ flex: 1; text-align: center; font-family: var(--font-mono); font-size: 17px; font-weight: 700; }
.portion-chips{ display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }

.detail-preview{
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 16px 0;
}
.detail-preview .dp-item{ text-align: center; background: var(--surface-2); border-radius: 10px; padding: 10px 4px; }
.detail-preview .dp-item .n{ font-family: var(--font-mono); font-weight: 700; font-size: 15px; }
.detail-preview .dp-item .l{ font-size: 10.5px; color: var(--text-muted); margin-top: 2px; text-transform: uppercase; letter-spacing: .03em; }

/* Statistik */
.stat-tabs{ display: flex; gap: 8px; margin-bottom: 14px; }
.canvas-card{ background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 14px; }
.canvas-card canvas{ width: 100%; display: block; }
.legend-row{ display: flex; gap: 16px; justify-content: center; margin-top: 10px; flex-wrap: wrap; }
.legend-row .li{ display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-muted); }
.legend-row .dot{ width: 9px; height: 9px; border-radius: 50%; }

.kpi-grid{ display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
.kpi{
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 10px; text-align: center;
}
.kpi .n{ font-family: var(--font-mono); font-weight: 700; font-size: 19px; }
.kpi .l{ font-size: 10.5px; color: var(--text-muted); margin-top: 3px; }

/* toast */
.toast{
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + 16px); transform: translate(-50%, 8px);
  background: var(--border-strong); color: var(--bg);
  padding: 11px 18px; border-radius: 100px; font-size: 13.5px; font-weight: 600;
  box-shadow: var(--shadow-lg); z-index: 200; opacity: 0; pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
  white-space: nowrap;
}
.toast.show{ opacity: 1; transform: translate(-50%, 0); }

.settings-group{ margin-bottom: 22px; }
.settings-group-title{ font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--text-faint); margin-bottom: 10px; padding-left: 2px; }
.row-between{ display: flex; align-items: center; justify-content: space-between; }
.export-btns{ display: flex; flex-direction: column; gap: 8px; }
.settings-actions{ display: flex; flex-direction: column; gap: 10px; }

.custom-food-item{
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 13.5px;
}
.custom-food-item:last-child{ border-bottom: none; }

footer.app-footer{
  text-align: center; font-size: 11px; color: var(--text-faint); padding: 18px 0 4px;
}

@media (min-width: 593px){
  #app{ box-shadow: var(--shadow-lg); min-height: 100vh; border-left: 1px solid var(--border); border-right: 1px solid var(--border); }
}
