:root {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #29382f;
  background: #f5f4ef;
  font-synthesis: none;
  --green: #315e47;
  --line: #e3e7df;
  --muted: #788176;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
}

main {
  max-width: 760px;
  margin: auto;
  padding: 36px 28px 60px;
}

button, input {
  font: inherit;
}

button {
  cursor: pointer;
  border: 0;
  background: transparent;
  color: inherit;
  min-height: 44px;
  border-radius: 8px;
}

button:hover {
  background: #edf1e9;
}

button:focus-visible, a:focus-visible {
  outline: 3px solid #88a995;
  outline-offset: 3px;
}

input:focus {
  outline: 2px solid #6f977d;
  outline-offset: 1px;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--line);
}

.brand {
  text-decoration: none;
  color: inherit;
  font-size: 18px;
  font-weight: 650;
  letter-spacing: -.5px;
}

.brand span {
  color: #9bab96;
}

.local-note, .meta, .hint, footer, .optional {
  color: var(--muted);
  font-size: 13px;
}

.overview {
  text-align: center;
  padding: 28px 0 32px;
}

.date-nav {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
}

.date-nav button {
  width: 44px;
  font-size: 20px;
}

.date-label {
  position: relative;
  font-size: 14px;
  font-weight: 550;
  padding: 12px 4px;
  cursor: pointer;
}

.date-label input {
  position: absolute;
  inset: 0;
  width: 100%;
  opacity: 0;
  cursor: pointer;
}

.date-label:focus-within {
  outline: 2px solid #6f977d;
  border-radius: 6px;
}

.total {
  display: flex;
  justify-content: center;
  align-items: baseline;
  gap: 12px;
  margin-top: 12px;
}

.total #total {
  font-size: 76px;
  font-weight: 600;
  letter-spacing: -5px;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
}

.unit {
  font-size: 17px;
  color: var(--muted);
}

.overview p {
  font-size: 13px;
  color: var(--muted);
  margin: 12px 0 0;
}

.panel {
  background: transparent;
  border: 0;
  border-radius: 0;
  padding: 22px 24px;
  margin-bottom: 16px;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

h1, h2 {
  font-size: 17px;
  margin: 0;
  font-weight: 600;
  letter-spacing: -.3px;
}

.hint {
  margin: 0 0 12px;
  line-height: 1.5;
}

.empty {
  padding: 24px 8px 26px;
  text-align: center;
}

.empty strong {
  font-size: 15px;
  font-weight: 500;
  display: block;
}

.empty p {
  font-size: 13px;
  color: var(--muted);
  margin: 8px 0 0;
  line-height: 1.5;
}

.entry, .food {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 59px;
  border-top: 1px solid var(--line);
}

.time {
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  width: 42px;
  flex-shrink: 0;
}

.entry-name, .food-name {
  flex: 1;
  text-align: left;
  min-width: 0;
  overflow-wrap: anywhere;
  font-size: 14px;
}

.entry-name {
  padding: 10px 6px;
  margin-left: -6px;
}

.entry-calories {
  padding: 10px 6px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.cal-unit {
  font-size: 12px;
  color: var(--muted);
  padding-left: 4px;
}

.remove {
  color: #9a9f97;
  font-size: 18px;
  min-width: 32px;
}

.remove:hover {
  color: #a44035;
  background: #fcf0ed;
}

.food-calories {
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.add-food {
  color: var(--green);
  font-size: 13px;
  font-weight: 600;
  padding: 0 12px;
  background: #f0f4ec;
  min-width: 66px;
}

.tabs {
  background: #f3f4ef;
  padding: 3px;
  border-radius: 8px;
  display: flex;
}

.tabs button {
  min-height: 32px;
  padding: 0 12px;
  font-size: 12px;
  color: var(--muted);
}

.tabs button[aria-pressed=true] {
  background: #fff;
  color: var(--green);
  box-shadow: 0 1px 3px #253a2014;
}

.form-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 112px 82px;
  gap: 12px;
  align-items: end;
}

label {
  font-size: 12px;
  font-weight: 550;
}

.optional {
  font-size: 11px;
  font-weight: 400;
  margin-left: 4px;
}

input {
  width: 100%;
  min-height: 46px;
  border: 1px solid #dce2d7;
  border-radius: 8px;
  padding: 10px 12px;
  color: inherit;
  background: #fff;
  margin-top: 7px;
}

input::placeholder {
  color: #a0a59c;
  font-size: 13px;
}

.primary {
  background: var(--green);
  color: white;
  min-height: 46px;
  font-weight: 550;
  font-size: 14px;
}

.primary:hover {
  background: #244c36;
}

.add-panel .hint {
  margin-top: 12px;
  margin-bottom: 0;
}

#matches:not(:empty) {
  margin-top: 18px;
}

#matches .food:first-child {
  border-top: 0;
}

.inline-edit {
  margin: 0;
  min-height: 40px;
  padding: 8px;
  min-width: 0;
}

.inline-edit[data-field=name] {
  flex: 1;
}

.inline-edit[data-field=calories] {
  width: 100px;
}

footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 4px;
  gap: 8px;
}

.text-button {
  font-size: 12px;
  color: var(--muted);
  padding: 0 8px;
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #293e30;
  color: #fff;
  border-radius: 12px;
  padding: 8px 12px 8px 20px;
  display: flex;
  align-items: center;
  gap: 20px;
  box-shadow: 0 5px 25px #26332926;
  max-width: calc(100% - 32px);
  font-size: 14px;
}

.toast button {
  color: #d1e9b8;
  padding: 0 12px;
}

.toast button:hover {
  background: #ffffff15;
}

.error {
  background: #fff1ee;
  color: #91392d;
  border-radius: 8px;
  padding: 14px;
  font-size: 13px;
}

[hidden] {
  display: none!important;
}

@media(max-width:540px) {
  main {
    padding: 20px 16px 40px;
  }
  .local-note {
    display: none;
  }
  .overview {
    padding: 22px 0 28px;
  }
  .total #total {
    font-size: 64px;
  }
  .panel {
    padding: 18px 16px;
  }
  .form-grid {
    grid-template-columns: minmax(0, 1fr) 82px;
  }
  .form-grid label:first-child {
    grid-column: 1/-1;
  }
  .form-grid .primary {
    align-self: end;
  }
  .section-heading .meta {
    font-size: 11px;
  }
  .entry, .food {
    gap: 8px;
  }
  .time {
    width: 36px;
    font-size: 11px;
  }
  .entry-name, .food-name {
    font-size: 13px;
  }
  .tabs button {
    padding: 0 9px;
  }
  footer {
    font-size: 11px;
  }
  .text-button {
    padding: 0 6px;
  }
  .toast {
    bottom: 16px;
    gap: 8px;
  }
}


/* Compact journal: long lists scroll inside their panels on phone screens. */
main
 {
  padding: 18px 20px 24px;
  max-width: 700px;
}

header {
  padding-bottom: 10px;
}

.overview {
  padding: 10px 0 14px;
}

.date-nav {
  gap: 6px;
}

.date-label {
  padding: 8px 4px;
}

.total {
  margin-top: 0;
  gap: 8px;
}

.total #total {
  font-size: 52px;
  letter-spacing: -3px;
}

.unit {
  font-size: 14px;
}

.macro-totals {
  display: flex;
  justify-content: center;
  gap: 20px;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.macro-totals strong {
  color: var(--green);
  font-weight: 600;
}

.overview p {
  margin-top: 5px;
  font-size: 11px;
}

.panel {
  padding: 12px 14px;
  margin-bottom: 10px;
  border-radius: 0;
}

.section-heading {
  margin-bottom: 5px;
}

h1, h2 {
  font-size: 15px;
}

.hint {
  font-size: 11px;
  margin-bottom: 4px;
}

.entry, .food {
  min-height: 44px;
  gap: 8px;
}

.entry-name, .food-name {
  font-size: 13px;
}

.empty {
  padding: 12px 4px;
}

.empty p {
  margin-top: 4px;
  font-size: 12px;
}

.empty strong {
  font-size: 13px;
}

.form-grid {
  grid-template-columns: minmax(0, 1fr) repeat(3, 65px);
  gap: 7px;
}

.form-grid label:first-child {
  grid-column: auto;
}

.form-grid .primary {
  grid-column: 1/-1;
  min-height: 38px;
}

input {
  min-height: 38px;
  padding: 6px 7px;
  margin-top: 4px;
  font-size: 16px;
}

input::placeholder {
  font-size: 12px;
}

.form-grid label {
  font-size: 11px;
  white-space: nowrap;
}

.optional {
  margin-left: 1px;
}

.add-panel .hint {
  margin-top: 6px;
}

.food-label {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  padding: 3px 0;
}

.food-name {
  padding: 0;
  min-height: 24px;
}

.food-macros {
  font-size: 10px;
  color: var(--muted);
}

.entry-metrics {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.entry-calories {
  min-height: 24px;
  padding: 2px 4px;
  font-size: 13px;
}

.entry-macros {
  display: flex;
  gap: 5px;
}

.entry-macros button {
  font-size: 10px;
  color: var(--muted);
  min-height: 20px;
  padding: 1px 3px;
}

.inline-edit[data-field=protein], .inline-edit[data-field=carbs] {
  width: 65px;
  min-height: 28px;
  padding: 3px;
}

.tabs button {
  min-height: 28px;
}

.time {
  font-size: 10px;
  width: 33px;
}

footer {
  font-size: 11px;
}

.text-button {
  min-height: 32px;
}

#matches:not(:empty) {
  margin-top: 8px;
  max-height: 132px;
  overflow-y: auto;
}

.remove {
  min-width: 26px;
}

#edit-hint {
  font-size: 10px;
}

@media(max-width:540px) {
  main {
    height: 100svh;
    display: flex;
    flex-direction: column;
    padding: 10px 12px 8px;
    overflow: hidden;
  }
  header {
    flex-shrink: 0;
    padding-bottom: 6px;
  }
  .brand {
    font-size: 16px;
  }
  .overview {
    flex-shrink: 0;
    padding: 5px 0 10px;
  }
  .total #total {
    font-size: 46px;
  }
  .date-nav button {
    min-height: 32px;
  }
  .date-label {
    padding: 5px 4px;
  }
  .panel {
    padding: 9px 10px;
    margin-bottom: 8px;
    min-height: 0;
    display: flex;
    flex-direction: column;
  }
  .panel:has(#entries), .panel:has(#quick-foods) {
    flex: 0 1 auto;
  }
  #entries, #quick-foods {
    max-height: min(176px, 22svh);
    overflow-y: auto;
    min-height: 0;
    overscroll-behavior: contain;
  }
  .section-heading, .hint {
    flex-shrink: 0;
  }
  .add-panel {
    flex: 0 0 auto;
  }
  .form-grid {
    grid-template-columns: minmax(0, 1fr) repeat(3, 57px);
    gap: 5px;
  }
  .form-grid label:first-child {
    grid-column: auto;
  }
  .form-grid .primary {
    grid-column: 1/-1;
  }
  .form-grid input {
    width: 100%;
    padding: 6px 5px;
  }
  footer {
    flex-shrink: 0;
    padding: 0;
  }
  .entry, .food {
    gap: 5px;
  }
  .food-calories {
    font-size: 12px;
  }
  .add-food {
    min-width: 52px;
    padding: 0 7px;
  }
  #matches:not(:empty) {
    max-height: 88px;
  }
  .error {
    flex-shrink: 0;
    font-size: 11px;
    padding: 8px;
    margin: 4px 0;
  }
}

@media(max-height:570px) and (max-width:540px) {
  main {
    height: auto;
    min-height: 100svh;
    overflow: visible;
  }
  .panel:has(#entries), .panel:has(#quick-foods) {
    flex: none;
  }
  .overview p {
    display: none;
  }
}


/* Four labelled writing lines
;
each column can shrink without overflowing. */
.form-grid {
  grid-template-columns: minmax(0, 4fr) repeat(3, minmax(0, 1fr));
  column-gap: 10px;
  row-gap: 8px;
}

.form-grid label {
  display: flex;
  flex-wrap: wrap;
  align-content: start;
  min-width: 0;
  color: var(--muted);
}

.form-grid label:first-child {
  grid-column: auto;
}

.form-grid input {
  display: block;
  flex: 0 0 100%;
  width: 100%;
  min-width: 0;
  min-height: 34px;
  margin-top: 2px;
  padding: 5px 0;
  border: 0;
  border-bottom: 1px dashed #a4b39f;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  -webkit-appearance: none;
  appearance: none;
}

.form-grid input:focus {
  outline: none;
  border-bottom: 2px dashed var(--green);
  background: #f5f8f2;
}

.form-grid input[type=number] {
  -moz-appearance: textfield;
}

.form-grid input::-webkit-inner-spin-button,
.form-grid input::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.form-grid #food-name {
  white-space: nowrap;
  overflow-x: auto;
  overflow-y: hidden;
  text-overflow: clip;
}

.form-grid .primary {
  grid-column: 1/-1;
}


/* Shared column order and widths for the journal and saved foods. */
.list-columns, .entry, .food
 {
  display: grid;
  grid-template-columns: minmax(0, 4fr) repeat(3, minmax(0, 1fr)) 44px;
  column-gap: 6px;
  align-items: center;
}

.list-columns {
  flex-shrink: 0;
  min-height: 23px;
  font-size: 10px;
  color: var(--muted);
}

.list-columns span:not(:first-child) {
  text-align: right;
}

.entry-name, .food-name {
  width: 100%;
  margin: 0;
  padding: 4px 0;
  min-height: 44px;
  white-space: nowrap;
  overflow-x: auto;
  overflow-y: hidden;
  overflow-wrap: normal;
  text-overflow: clip;
}

.entry-name {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-start;
}

.entry-title {
  white-space: nowrap;
}

.entry .time {
  display: block;
  width: auto;
  font-size: 9px;
  line-height: 1.2;
}

.metric {
  min-width: 0;
  width: 100%;
  text-align: right;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow-x: auto;
}

.entry .metric {
  padding: 4px 0;
  min-height: 44px;
}

.food .add-food {
  min-width: 0;
  width: 44px;
  padding: 0;
  font-size: 11px;
}

.entry .remove {
  min-width: 0;
  width: 44px;
  padding: 0;
}

.entry .inline-edit {
  width: 100%;
  min-width: 0;
  margin: 0;
  padding: 4px 0;
  min-height: 44px;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  color: inherit;
  font-size: 13px;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
}

.entry .inline-edit:not([data-field=name]) {
  text-align: right;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  -moz-appearance: textfield;
}

.entry .inline-edit::-webkit-inner-spin-button,
.entry .inline-edit::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}


/* Notebook sections follow their content
;
only long lists need scrolling. */
#entries, #quick-foods {
  max-height: 264px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.panel {
  border-top: 1px solid var(--line);
}

.inline-edit {
  background: transparent;
}

.tabs {
  background: transparent;
}

.tabs button[aria-pressed=true] {
  background: #e8ede2;
  box-shadow: none;
}

@media(max-width:540px) {
  #entries, #quick-foods {
    max-height: min(176px, 22svh);
  }
}

/* Quantity sits after the name and scales the three per-unit metrics. */
.form-grid {
  grid-template-columns: minmax(0, 4fr) minmax(0, .8fr) repeat(3, minmax(0, 1fr));
}
.list-columns, .entry, .food {
  grid-template-columns: minmax(0, 4fr) minmax(0, .8fr) repeat(3, minmax(0, 1fr)) 44px;
}
