:root {
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #2f2925;
  background: #e8e5e2;
  font-synthesis: none;
  --primary: #6f4e37;
  --primary-soft: #e8ddd5;
  --accent: #d4a24c;
  --surface: #fbfaf9;
  --surface-2: #ded9d5;
  --border: #d0c9c3;
  --muted: #746c66;
  --danger: #b42318;
  --blue: #2176ae;
  --orange: #a75b24;
  --brown-deep: #4a2f20;
  --brown-mid: #8a6248;
  --gold: #d4a24c;
}

* { box-sizing: border-box; }
html { background: #e8e5e2; }
body { margin: 0; min-width: 320px; min-height: 100vh; background: #e8e5e2; }
button, input, select { font: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }

.app {
  max-width: 760px;
  margin: 0 auto;
  min-height: 100vh;
  padding: calc(12px + env(safe-area-inset-top)) 16px calc(108px + env(safe-area-inset-bottom));
}

.header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 4px 18px;
}
.header h1 { margin: 4px 0 2px; font-size: clamp(29px, 8vw, 38px); line-height: 1.04; letter-spacing: -0.04em; }
.brandHeader { display: flex; align-items: center; min-width: 0; gap: 12px; }
.brandMark { flex: 0 0 auto; width: 58px; height: 58px; filter: drop-shadow(0 5px 8px rgba(70, 47, 33, 0.12)); }
.brandName { color: var(--primary); font-size: 12px; letter-spacing: 0.08em; }
.header h1 { color: var(--brown-deep); }

.eyebrow { color: var(--primary); font-size: 11px; font-weight: 900; letter-spacing: 0.13em; text-transform: uppercase; }
.eyebrow.blue { color: var(--blue); }
.eyebrow.orange { color: var(--orange); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.tiny { color: var(--muted); font-size: 11px; font-weight: 700; }
.helper { font-size: 13px; line-height: 1.5; }

.card {
  margin-bottom: 14px;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  box-shadow: 0 8px 26px rgba(65, 45, 34, 0.07);
}
.card h2 { margin: 0 0 12px; font-size: 18px; }
.hero { background: var(--primary); color: #fff; border-color: var(--primary); }
.heroTop, .split { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; }
.heroLabel { color: #eadfd8; font-size: 14px; font-weight: 700; }
.big { margin-top: 2px; font-size: clamp(48px, 14vw, 64px); font-weight: 950; line-height: 1; letter-spacing: -0.055em; }
.goalPill, .badge, .sourceBadge, .statusDot {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 8px 11px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 850;
  white-space: nowrap;
}
.goalPill { color: #fff; background: rgba(255, 255, 255, 0.13); }
.badge { color: var(--primary); background: #fff; }
.blueBadge { color: var(--blue); background: #e8f4fb; }
.sourceBadge, .statusDot { min-height: 28px; padding: 6px 9px; color: var(--primary); background: var(--primary-soft); font-size: 10px; }
.statusDot::before { content: ""; width: 7px; height: 7px; margin-right: 6px; border-radius: 50%; background: #22c55e; }

.progress { height: 10px; overflow: hidden; background: #ddd7d2; border-radius: 999px; }
.progress span { display: block; height: 100%; background: var(--primary); border-radius: 999px; transition: width 220ms ease; }
.heroProgress { margin: 16px 0 12px; background: rgba(255, 255, 255, 0.18); }
.heroProgress span { background: var(--accent); }
.waterProgress span { background: var(--blue); }
.equation { display: flex; flex-wrap: wrap; gap: 8px; color: #eadfd8; font-size: 11px; font-weight: 750; }
.equation b { color: var(--accent); }

.proteinCard { background: var(--primary-soft); }
.largeMetric { margin: 2px 0 8px; font-size: 37px; font-weight: 950; letter-spacing: -0.045em; }
.largeMetric span, .metric span { margin-left: 2px; color: var(--muted); font-size: 15px; font-weight: 800; }
.macroGrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
.miniCard { min-width: 0; padding: 14px; background: var(--surface); border: 1px solid var(--border); border-radius: 20px; box-shadow: 0 6px 18px rgba(65, 45, 34, 0.05); }
.metric { margin: 5px 0 10px; font-size: 24px; font-weight: 950; letter-spacing: -0.04em; }
.miniCard .progress { height: 7px; margin-bottom: 8px; }
.waterCard, .activityCard { display: grid; gap: 12px; }
.quickButtons { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; }
.quickButtons button { padding: 11px 8px; color: var(--blue); font-weight: 850; background: #e8f4fb; border: 1px solid #c8e4f4; border-radius: 14px; }
.activityButtons button { color: var(--orange); background: #fff3e6; border-color: #f5d6b5; }
.textButton { justify-self: start; padding: 0; color: var(--muted); background: transparent; border: 0; font-size: 12px; font-weight: 800; }

.btn, .smallBtn, .roundIcon {
  border: 0;
  font-weight: 900;
  transition: transform 100ms ease, opacity 100ms ease;
}
.btn:active, .smallBtn:active, .roundIcon:active { transform: scale(0.98); opacity: 0.82; }
.btn { min-height: 48px; padding: 13px 16px; color: #fff; background: var(--primary); border-radius: 16px; }
.btn.secondary { color: var(--primary); background: var(--surface-2); }
.btn.ghost { color: var(--primary); background: transparent; border: 1px solid var(--border); }
.btn.danger { color: var(--danger); background: #fee4e2; }
.smallBtn { min-height: 38px; padding: 9px 13px; color: #fff; background: var(--primary); border-radius: 13px; }
.roundIcon { flex: 0 0 auto; width: 46px; height: 46px; color: var(--primary); background: var(--accent); border-radius: 17px; font-size: 27px; }
.actionGrid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.fullButton { width: 100%; margin-top: 10px; }
.compactCard { display: flex; align-items: center; justify-content: space-between; }
.compactCard b { display: block; margin-top: 3px; font-size: 23px; }

.sectionTitle { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 22px 4px 10px; }
.sectionTitle.inside { margin: 0 0 14px; }
.sectionTitle h2 { margin: 0; font-size: 18px; }
.entryList { padding-top: 4px; padding-bottom: 4px; }
.entry { display: flex; align-items: center; gap: 10px; min-width: 0; padding: 13px 0; border-bottom: 1px solid #e2ddda; }
.entry:last-child { border-bottom: 0; }
.entryMain { flex: 1; min-width: 0; padding: 0; text-align: left; background: transparent; border: 0; }
.entryName { overflow: hidden; font-weight: 900; text-overflow: ellipsis; white-space: nowrap; }
.entryMeta { margin-top: 3px; overflow: hidden; color: var(--muted); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.entryCalories { flex: 0 0 auto; font-size: 18px; font-weight: 950; text-align: right; }
.entryCalories span { display: block; color: var(--muted); font-size: 9px; font-weight: 800; }
.iconBtn, .starBtn, .close {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 12px;
}
.iconBtn { color: var(--danger); background: #fee4e2; font-size: 20px; }
.starBtn { color: #8b948f; background: transparent; font-size: 24px; }
.starBtn.on { color: var(--gold); }
.compactStats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; text-align: center; }
.compactStats b { display: block; font-size: 20px; }
.compactStats span { color: var(--muted); font-size: 11px; font-weight: 750; }
.empty { padding: 28px 10px; color: var(--muted); text-align: center; }
.empty b { display: block; color: #3b312b; font-size: 16px; }
.empty p { margin: 6px 0 0; font-size: 13px; }
.emptyIcon { margin-bottom: 8px; font-size: 34px; }
.smallEmpty { padding: 18px 8px; font-size: 13px; }

.addCard { display: grid; gap: 12px; }
.scannerActions { display: grid; grid-template-columns: 1fr 0.72fr 1fr; gap: 8px; }
.scannerFrame { position: absolute; top: 50%; left: 50%; width: min(80%, 390px); height: 112px; transform: translate(-50%, -50%); border: 3px solid rgba(255,255,255,.9); border-radius: 18px; box-shadow: 0 0 0 999px rgba(20,14,11,.20); pointer-events: none; }
.photoScanButton { min-height: 48px; text-align: center; }
.notice[data-tone="error"] { color: #7e271e; background: #f8e8e5; border-color: #e9b9b1; }
.notice[data-tone="success"] { color: #4f392b; background: #efe3d9; border-color: #d5bba8; }

.scanner { position: relative; overflow: hidden; min-height: 260px; background: #1e1815; border-radius: 20px; }
.scanner video { display: block; width: 100%; min-height: 260px; object-fit: cover; }
.notice { margin-top: 10px; padding: 12px; color: #7a4500; background: #fff4e5; border: 1px solid #f4d7a7; border-radius: 14px; font-size: 13px; }
.scanner .notice { position: absolute; right: 10px; bottom: 10px; left: 10px; margin: 0; }
.inlineForm { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: stretch; }
.inlineForm input { min-width: 0; }
.loading { padding: 24px 8px; color: var(--muted); text-align: center; }
.searchResults { display: grid; gap: 8px; margin-top: 14px; }
.searchResult { display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; padding: 13px; text-align: left; background: #f5f3f1; border: 1px solid var(--border); border-radius: 16px; }
.searchResult b, .searchResult span { display: block; }
.searchResult b { margin-bottom: 3px; }
.searchResult span { color: var(--muted); font-size: 11px; }
.searchResult strong { flex: 0 0 auto; color: var(--primary); font-size: 12px; }

.libraryList { padding-top: 4px; padding-bottom: 4px; }
.libraryRow { display: flex; align-items: center; gap: 8px; min-width: 0; padding: 10px 0; border-bottom: 1px solid #e2ddda; }
.libraryRow:last-child { border-bottom: 0; }
.libraryMain { flex: 1; min-width: 0; padding: 4px 0; text-align: left; background: transparent; border: 0; }
.libraryMain b, .libraryMain span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.libraryMain span { margin-top: 4px; color: var(--muted); font-size: 12px; }

.rangeToggle { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 14px; padding: 5px; background: #dcd7d3; border-radius: 17px; }
.rangeToggle button { padding: 10px; color: var(--muted); background: transparent; border: 0; border-radius: 13px; font-weight: 850; }
.rangeToggle button.active { color: var(--primary); background: #fff; box-shadow: 0 3px 10px rgba(65, 45, 34, 0.10); }
.statsGrid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.statCard { padding: 15px; background: #fff; border: 1px solid var(--border); border-radius: 19px; }
.statCard span { display: block; color: var(--muted); font-size: 11px; font-weight: 800; }
.statCard b { display: block; margin-top: 5px; font-size: 24px; }
.chartBars { display: flex; align-items: flex-end; gap: 4px; height: 220px; padding-top: 12px; overflow-x: auto; }
.barColumn { flex: 1 0 24px; min-width: 24px; height: 100%; text-align: center; }
.barPlot { position: relative; height: calc(100% - 24px); overflow: hidden; background: #e4e0dd; border-radius: 8px 8px 5px 5px; }
.valueBar { position: absolute; right: 3px; bottom: 0; left: 3px; min-height: 2px; background: var(--primary); border-radius: 6px 6px 2px 2px; }
.goalMark { position: absolute; right: 0; left: 0; z-index: 2; height: 2px; background: var(--gold); }
.barColumn small { display: block; margin-top: 6px; color: var(--muted); font-size: 9px; }
.weightSummary { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 4px; }
.weightSummary b { font-size: 26px; }
.weightSummary span { color: var(--muted); font-size: 11px; }
.weightSvg { display: block; width: 100%; height: auto; min-height: 170px; overflow: visible; }
.weightLine { fill: none; stroke: var(--primary); stroke-width: 6; stroke-linecap: round; stroke-linejoin: round; }
.weightSvg circle { fill: var(--accent); stroke: var(--primary); stroke-width: 3; }
.chartLabels { display: flex; justify-content: space-between; color: var(--muted); font-size: 10px; }
.historyList { padding-top: 4px; padding-bottom: 4px; }
.historyRow { display: flex; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid #e2ddda; }
.historyRow:last-child { border-bottom: 0; }
.historyRow div:last-child { text-align: right; }
.historyRow b, .historyRow span { display: block; }
.historyRow span { margin-top: 3px; color: var(--muted); font-size: 11px; }

.formGrid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.fullField { grid-column: 1 / -1; }
.field label { color: var(--muted); font-size: 11px; font-weight: 850; }
.field input, .field select, .inlineForm input {
  width: 100%;
  min-height: 46px;
  padding: 12px 13px;
  color: #2f2925;
  background: #fff;
  border: 1px solid #cfc6c0;
  border-radius: 14px;
  outline: none;
}
.field input:focus, .field select:focus, .inlineForm input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(111, 78, 55, 0.14); }
.checkField { display: flex; align-items: center; gap: 9px; min-height: 44px; color: #51463f; font-size: 13px; font-weight: 750; }
.checkField input, .selectRow input { width: 20px; height: 20px; accent-color: var(--primary); }
.fileButton { display: flex; align-items: center; justify-content: center; }
.fileButton input { display: none; }

.modal { position: fixed; inset: 0; z-index: 20; display: flex; align-items: flex-end; justify-content: center; background: rgba(32, 25, 21, 0.70); backdrop-filter: blur(3px); }
.sheet { width: min(100%, 760px); max-height: 94vh; padding: 18px 16px calc(22px + env(safe-area-inset-bottom)); overflow-y: auto; background: #e8e5e2; border-radius: 28px 28px 0 0; }
.shortSheet { max-height: 70vh; }
.sheetHead { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; }
.sheetHead h2 { margin: 4px 0 15px; }
.close { color: #51463f; background: #ddd7d2; font-size: 22px; }
.checkList { display: grid; gap: 8px; margin: 14px 0; }
.selectRow { display: flex; align-items: center; gap: 11px; padding: 12px; background: #f5f3f1; border: 1px solid var(--border); border-radius: 15px; }
.selectRow span, .selectRow b, .selectRow small { display: block; }
.selectRow span { min-width: 0; }
.selectRow b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.selectRow small { margin-top: 3px; color: var(--muted); }
.toast { position: fixed; right: 18px; bottom: calc(96px + env(safe-area-inset-bottom)); left: 18px; z-index: 40; max-width: 560px; margin: auto; padding: 13px 16px; color: #fff; text-align: center; background: #2f2925; border-radius: 16px; box-shadow: 0 12px 30px rgba(0, 0, 0, 0.24); font-size: 13px; font-weight: 800; }

.nav {
  position: fixed;
  right: 12px;
  bottom: calc(8px + env(safe-area-inset-bottom));
  left: 12px;
  z-index: 10;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  max-width: 736px;
  margin: auto;
  padding: 7px;
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid var(--border);
  border-radius: 23px;
  box-shadow: 0 12px 34px rgba(65, 45, 34, 0.18);
  backdrop-filter: blur(18px);
}
.nav button { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 7px 2px; color: var(--muted); background: transparent; border: 0; border-radius: 15px; font-size: 10px; font-weight: 800; }
.nav button span { font-size: 17px; line-height: 1; }
.nav button.active { color: var(--primary); background: var(--primary-soft); }

@media (max-width: 520px) {
  .macroGrid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 7px; }
  .miniCard { padding: 11px 9px; border-radius: 17px; }
  .metric { font-size: 21px; }
  .miniCard .tiny { font-size: 9px; }
  .formGrid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 520px) {
  .scannerActions { grid-template-columns: 1fr 1fr; }
  .photoScanButton { grid-column: 1 / -1; }
}

@media (max-width: 390px) {
  .app { padding-right: 12px; padding-left: 12px; }
  .formGrid { grid-template-columns: 1fr; }
  .fullField { grid-column: auto; }
  .heroTop { flex-direction: column; }
  .goalPill { align-self: flex-start; }
  .macroGrid { grid-template-columns: 1fr; }
  .statsGrid { grid-template-columns: 1fr 1fr; }
  .nav { right: 8px; left: 8px; }
  .nav button { font-size: 9px; }
}

@media (display-mode: standalone) {
  .header { padding-top: 8px; }
}
