/* Avocount. Mobile first: the pages work at a width of 360 px and more. */
:root {
  --bg: #f7f7f1; --panel: #fff; --ink: #1f2418; --muted: #656b5a; --line: #e3e5d8;
  --field-line: #d2d5c4; --hover: #f3f5ea;
  --accent: #36601c; --accent-ink: #fff; --accent-soft: #edf3d8; --accent-line: #cbdc9d;
  --danger: #b42318; --warn: #9a5b00; --warn-soft: #fdf3dc;
  --protein: #2b6cb0; --carbs: #b7791f; --fat: #9f3a8a;
}
* { box-sizing: border-box; }
html { font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; color: var(--ink); background: var(--bg); -webkit-text-size-adjust: 100%; }
body { margin: 0; }
a { color: var(--accent); }
main { max-width: 1180px; margin: 0 auto; padding: 12px 12px 60px; }
h1 { font-size: 1.4rem; margin: 8px 0 14px; }
/* A short value after the title of a page, for example the email on the Account page. */
.title-note { font-size: 1rem; font-weight: 400; color: var(--muted); margin-left: 8px; overflow-wrap: anywhere; }
h2 { font-size: 1.05rem; margin: 0 0 10px; }
h3 { font-size: 0.95rem; margin: 10px 0 2px; }

.topbar { display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
/* The brand: the avocado mark and the name. */
.brand { display: inline-flex; align-items: center; gap: 7px; font-weight: 700; color: var(--accent); text-decoration: none; }
.brand img { display: block; width: 24px; height: 24px; }
.topbar nav { display: flex; align-items: center; gap: 2px; }
.topbar .main-nav { overflow-x: auto; flex: 1; min-width: 0; }
.topbar .side-nav { flex: none; margin-left: auto; }
.topbar .language-form { flex: none; margin: 0 0 0 auto; }
.topbar .language-form select { width: auto; min-height: 0; padding: 4px 8px; font-size: 0.9rem; }
.topbar nav a { color: var(--ink); text-decoration: none; padding: 6px 10px; border-radius: 6px; white-space: nowrap; }
.topbar nav a.active, .topbar nav a:hover { background: var(--accent-soft); color: var(--accent); }
.topbar nav a.nav-icon { display: inline-flex; align-items: center; padding: 5px 8px; }
.topbar nav a.nav-icon svg { width: 20px; height: 20px; display: block; }
/* On a phone, the main pages go to a second row, so that each link stays visible. */
@media (max-width: 559px) {
  .topbar { flex-wrap: wrap; row-gap: 2px; padding-bottom: 4px; }
  .topbar .main-nav { order: 3; flex: 1 0 100%; }
}
.logout { margin: 0; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px; margin-bottom: 14px; }
.card.narrow { max-width: 420px; margin: 40px auto; }
.muted { color: var(--muted); }
.strong { font-weight: 700; }
.nowrap { white-space: nowrap; }
.error { color: var(--danger); margin: 6px 0; }
.hint { color: var(--muted); font-size: 0.9rem; margin: 6px 0; }
.warn-text { color: var(--warn); margin: 6px 0; }
.banner { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; background: #eef4ff; border: 1px solid #c9d8f5; }
.banner.ok { background: var(--accent-soft); border-color: var(--accent-line); }
.spacer { flex: 1; }
.tag { display: inline-block; font-size: 0.75rem; padding: 1px 7px; border-radius: 10px; background: #e9ebe0; color: #33392b; vertical-align: middle; white-space: nowrap; }
.tag.muted { background: #eff0e8; color: var(--muted); }
.tag.src-memory { background: var(--accent-soft); color: var(--accent); }
.tag.src-model { background: var(--warn-soft); color: var(--warn); }
.tag.src-owner { background: #ece8f7; color: #4b3a8a; }
.approx { color: var(--warn); font-weight: 700; margin-right: 1px; }

/* Forms */
form.stacked { display: flex; flex-direction: column; align-items: stretch; gap: 10px; }
.stacked-part { display: flex; flex-direction: column; gap: 10px; }
form.stacked > label, .row > label, .stacked-part > label { display: flex; flex-direction: column; gap: 3px; font-size: 0.85rem; color: var(--muted); }
.row { display: flex; flex-wrap: wrap; gap: 10px 12px; align-items: flex-end; }
.row > label.grow { flex: 1 1 220px; }
/* button.primary aligns to the start of a column form. In a row, it aligns with the fields. */
.row > button, .row > button.primary { align-self: flex-end; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field-label { font-size: 0.85rem; color: var(--muted); }
.window-label { padding-bottom: 9px; font-weight: 600; }
input[type=text], input[type=date], input[type=time], input[type=number], input[type=search], input[type=password], input[type=email], select {
  font: inherit; font-size: 16px; padding: 7px 9px; border: 1px solid var(--field-line); border-radius: 6px; background: #fff; color: var(--ink); min-width: 0; width: 100%;
}
.row > label input, .row > label select { width: auto; min-width: 120px; }
.row > label.grow input { width: 100%; }
input.short, .row > label input.short { min-width: 70px; width: 90px; }
label.check { display: flex; flex-direction: row; align-items: center; gap: 6px; color: var(--ink); font-size: 0.95rem; }
button, .button { font: inherit; padding: 7px 12px; border: 1px solid var(--field-line); border-radius: 6px; background: #fff; color: var(--ink); cursor: pointer; text-decoration: none; display: inline-block; line-height: 1.3; }
button.primary, .button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); align-self: flex-start; padding: 8px 18px; }
button.link { border: none; background: none; color: var(--accent); padding: 2px 6px; }
button.link.danger { color: var(--danger); }
button.danger:not(.link) { background: var(--danger); color: #fff; border-color: var(--danger); align-self: flex-start; padding: 8px 18px; }
.preview { min-height: 1.6em; padding: 8px 10px; border: 1px dashed var(--field-line); border-radius: 6px; margin: 0; }

.seg { display: inline-flex; flex-wrap: wrap; }
.seg-item { position: relative; cursor: pointer; margin-left: -1px; }
.seg-item:first-child, .seg > .seg-btn:first-child { margin-left: 0; }
.seg > .seg-btn { margin-left: -1px; }
.seg-item input { position: absolute; opacity: 0; width: 0; height: 0; }
.seg-item span, .seg-btn { display: inline-flex; align-items: center; padding: 7px 12px; border: 1px solid var(--field-line); background: #fff; color: var(--ink); text-decoration: none; white-space: nowrap; line-height: 1.2; cursor: pointer; }
.seg-item:first-child span, .seg > .seg-btn:first-child { border-radius: 6px 0 0 6px; }
.seg-item:last-child span, .seg > .seg-btn:last-child { border-radius: 0 6px 6px 0; }
.seg-item input:checked + span, .seg-btn.on { background: var(--accent); border-color: var(--accent); color: #fff; position: relative; z-index: 1; }
.seg-item input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 1px; position: relative; z-index: 2; }

/* Today */
.datebar { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.datebar form { margin: 0; }
.datebar input[type=date] { width: auto; }
.summary .kcal-line { display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; }
.big { font-size: 2rem; font-weight: 700; line-height: 1.1; }
.unit { color: var(--muted); }
.left { font-weight: 600; color: var(--accent); }
.left.over { color: var(--danger); }
.bar { height: 12px; background: #e8eadb; border-radius: 6px; overflow: hidden; margin: 8px 0; }
.bar.thin { height: 7px; margin: 4px 0 0; }
.bar .fill { height: 100%; background: var(--accent); }
.bar .fill.over { background: var(--danger); }
.macros { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 10px; }
.macro-head { display: flex; flex-direction: column; font-size: 0.85rem; }
.macro-head span:first-child { color: var(--muted); }
.macro-head .num { font-weight: 600; }
.macro:nth-child(1) .fill { background: var(--protein); }
.macro:nth-child(2) .fill { background: var(--carbs); }
.macro:nth-child(3) .fill { background: var(--fat); }
.macro .fill.over { background: var(--danger); }
.num { font-variant-numeric: tabular-nums; }
.meal-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin-bottom: 4px; }
.meal-head h2 { margin: 0; }
.meal-total { font-size: 0.9rem; color: var(--muted); }
.meal-total strong { color: var(--ink); }
ul.entries { list-style: none; margin: 0; padding: 0; }
.entry-item { border-top: 1px solid var(--line); }
.entry-view { padding: 8px 6px; margin: 0 -6px; border-radius: 6px; cursor: pointer; }
.entry-view:hover { background: var(--hover); }
.entry-view:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.deleted-line { padding: 8px 0; }
.entry-item:first-child { border-top: none; }
.entry-item.deleted { color: var(--muted); }
.entry-item.editing { background: var(--hover); margin: 0 -14px; padding: 10px 14px; }
.entry-main { display: flex; justify-content: space-between; gap: 10px; }
.entry-name { font-weight: 600; }
.entry-kcal { white-space: nowrap; font-weight: 600; font-variant-numeric: tabular-nums; }
.entry-sub { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 10px; font-size: 0.85rem; color: var(--muted); margin-top: 2px; }
.entry-note { font-size: 0.85rem; margin-top: 2px; }
.deleted-line { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.entry-edit { display: flex; flex-direction: column; gap: 8px; }
.form-actions { display: flex; align-items: center; gap: 8px; }
.field { display: flex; flex-direction: column; gap: 3px; font-size: 0.85rem; color: var(--muted); }
.chart-box { position: relative; height: 220px; }
.describe { display: flex; flex-direction: column; gap: 6px; }
.describe-row { display: flex; gap: 8px; align-items: stretch; }
.describe-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
/* The second way to add a meal: a small link to the Add page, beside the text box. */
.manual-link { display: inline-flex; align-items: center; gap: 5px; font-size: 0.85rem; color: var(--accent); text-decoration: none; white-space: nowrap; }
.manual-link:hover { text-decoration: underline; }
.manual-link svg { width: 15px; height: 15px; flex: none; }
.describe textarea { flex: 1; font: inherit; font-size: 16px; padding: 8px 10px; border: 1px solid var(--field-line); border-radius: 6px; resize: vertical; min-height: 44px; }
.describe button.primary { align-self: stretch; }
.describe .question { margin: 4px 0 0; padding: 8px 10px; background: var(--warn-soft); border-radius: 6px; }

/* Log */
.filters { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: flex-end; margin-bottom: 12px; }
.filters form { margin: 0; }
.filters label { display: flex; flex-direction: column; font-size: 0.85rem; color: var(--muted); gap: 3px; }
.filters input, .filters select { width: auto; }
.toolbar { display: flex; align-items: center; gap: 10px; margin: 10px 0; flex-wrap: wrap; }
.scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { border-collapse: collapse; width: 100%; background: var(--panel); }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-weight: 600; color: var(--muted); font-size: 0.85rem; white-space: nowrap; }
td.num, th.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
table.compact td, table.compact th { padding: 4px 6px; }
tr.total td { font-weight: 700; border-top: 2px solid var(--line); }
tr.average td { color: var(--muted); }
.actions { white-space: nowrap; text-align: right; }
tr.row-deleted td { color: var(--muted); background: #fbf3f2; }
tr.row-edit td { background: var(--hover); }
tbody.entry.htmx-swapping, li.entry-item.htmx-swapping { opacity: 0; transition: opacity 400ms ease; }

/* Add */
.selected-food { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 8px 10px; background: var(--accent-soft); border-radius: 6px; }
ul.food-results { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.food-pick { width: 100%; text-align: left; display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: baseline; }

/* Foods */
.entry-edit textarea { font: inherit; font-size: 16px; padding: 7px 9px; border: 1px solid var(--field-line); border-radius: 6px; width: 100%; }
tbody.food.archived td { color: var(--muted); }

/* Settings */
.facts { display: grid; grid-template-columns: 1fr auto; gap: 4px 14px; margin: 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right; }
.window-row { display: grid; grid-template-columns: 84px 1fr 1fr; gap: 8px; align-items: end; }
.window-row label { display: flex; flex-direction: column; gap: 3px; font-size: 0.85rem; color: var(--muted); }

/* Field grids: the inputs fill equal columns. */
.fields3, .fields4 { display: grid; gap: 8px 10px; grid-template-columns: repeat(3, minmax(0, 1fr)); align-items: end; }
.fields4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.fields3 > label, .fields4 > label { display: flex; flex-direction: column; gap: 3px; font-size: 0.85rem; color: var(--muted); min-width: 0; }
.fields4.wide, .fields3.when { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.fields3.when > label:first-child { grid-column: 1 / -1; }
.fields3 input, .fields4 input, .fields3 select, .fields4 select { width: 100%; }
/* The Log table shows fewer columns on a phone. */
.sub { display: block; font-size: 0.8rem; color: var(--muted); white-space: normal; }
.phone-only { display: block; }
.wide-only { display: none; }

@media (min-width: 720px) {
  main { padding: 16px 20px 60px; }
  .topbar { padding: 10px 20px; gap: 24px; }
  .topbar .main-nav { flex: 0 1 auto; }
  .card { padding: 16px; }
  .entry-item.editing { margin: 0 -16px; padding: 10px 16px; }
  .phone-only { display: none; }
  td.wide-only, th.wide-only { display: table-cell; }
  button.wide-only { display: inline-block; }
  .fields4.wide { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .fields3.when { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .fields3.when > label:first-child { grid-column: auto; }
}

/* The QR code of the Telegram link. The SVG comes from the server. */
.qr { margin: 8px 0; }
.qr svg { display: block; max-width: 100%; height: auto; border-radius: 6px; }
/* The /start command holds a code of 32 characters without a space. Break it anywhere,
   so that it does not make the card wider than a phone screen. */
.hint code { overflow-wrap: anywhere; }

/* The footer and the legal pages. */
main { padding-bottom: 24px; }
.site-footer { display: flex; justify-content: center; flex-wrap: wrap; gap: 6px 18px; padding: 18px 16px 32px; border-top: 1px solid var(--line); font-size: 0.85rem; }
.site-footer a { color: var(--muted); text-decoration: none; }
.site-footer a:hover { color: var(--accent); text-decoration: underline; }
.site-footer .language-form { margin: 0; }
.site-footer select { width: auto; min-height: 0; padding: 2px 6px; font-size: 0.85rem; color: var(--muted); background: transparent; }
.legal { max-width: 760px; margin: 0 auto; line-height: 1.55; }
.legal h2 { margin-top: 22px; }
.legal ul { padding-left: 20px; }
.legal li { margin: 4px 0; }
.legal .updated { color: var(--muted); }

/* The admin pages. */
.subnav { display: flex; gap: 4px; margin: -6px 0 14px; flex-wrap: wrap; }
.subnav a { color: var(--ink); text-decoration: none; padding: 5px 10px; border-radius: 6px; border: 1px solid var(--line); background: var(--panel); }
.subnav a.active, .subnav a:hover { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-line); }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.stat { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.stat.warn { border-color: #e9c46a; background: var(--warn-soft); }
.stat-value { font-size: 1.35rem; font-weight: 700; }
.stat-label { color: var(--muted); font-size: 0.82rem; margin-top: 2px; }
.inline-form { display: flex; gap: 6px; align-items: center; }
.inline-form input.short { width: 70px; min-width: 0; }
.admin-users td { vertical-align: middle; }
.danger-zone summary { color: var(--danger); cursor: pointer; font-size: 0.9rem; }
.danger-zone form { margin-top: 8px; min-width: 240px; }
label.check { flex-direction: row; align-items: center; gap: 6px; }
.tag.level-error { background: #fde8e6; color: var(--danger); }
.log-text { overflow-wrap: anywhere; font-size: 0.9rem; }
.log-text pre { white-space: pre-wrap; font-size: 0.8rem; margin: 6px 0 0; max-height: 300px; overflow: auto; }
