/* Caltrack. Mobile first: the pages work at a width of 360 px and more. */
:root {
  --bg: #f5f7f6; --panel: #fff; --ink: #1b2420; --muted: #66706b; --line: #e1e6e3;
  --accent: #1f6f54; --accent-ink: #fff; --accent-soft: #e6f2ed;
  --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; }
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; }
.brand { font-weight: 700; color: var(--accent); text-decoration: none; }
.topbar nav { display: flex; gap: 2px; overflow-x: auto; flex: 1; }
.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); }
.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: #b9dccd; }
.spacer { flex: 1; }
.tag { display: inline-block; font-size: 0.75rem; padding: 1px 7px; border-radius: 10px; background: #e8edf0; color: #2f3b45; vertical-align: middle; white-space: nowrap; }
.tag.muted { background: #eef0f3; 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; }
.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], select {
  font: inherit; font-size: 16px; padding: 7px 9px; border: 1px solid #cdd5d1; 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 #cdd5d1; border-radius: 6px; background: #fff; color: var(--ink); cursor: pointer; text-decoration: none; display: inline-block; line-height: 1.3; }
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); }
.preview { min-height: 1.6em; padding: 8px 10px; border: 1px dashed #cdd5d1; 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 #cdd5d1; 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: #e6ece9; 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: #f4f8f6; }
.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: #f4f8f6; 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 textarea { flex: 1; font: inherit; font-size: 16px; padding: 8px 10px; border: 1px solid #cdd5d1; 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: #f4f8f6; }
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 #cdd5d1; 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 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; }
}
