/* Plain, neutral layout. Spacing scale: 4 / 8 / 16 / 24 / 40 px. */
:root {
  --fg: #1d1d1f;
  --muted: #6e6e73;
  --line: #e3e3e8;
  --line-strong: #cfcfd6;
  --bg: #ffffff;
  --accent: #1f4e8c;
  --error: #a3261c;
  --width: 1100px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-variant-numeric: tabular-nums;
}

a { color: var(--accent); text-underline-offset: 2px; }
h1 { font-size: 20px; font-weight: 600; margin: 8px 0 16px; }
h2 { font-size: 16px; font-weight: 600; margin: 0; }

/* page frame: header and content share one column */
header { border-bottom: 1px solid var(--line); }
header .bar, main { max-width: var(--width); margin: 0 auto; padding-left: 24px; padding-right: 24px; }
header .bar { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 8px 24px; padding-top: 14px; padding-bottom: 14px; }
header .name { font-weight: 600; color: var(--fg); text-decoration: none; }
header nav { display: flex; flex-wrap: wrap; gap: 4px 20px; }
header nav a { text-decoration: none; }
header nav a:hover { text-decoration: underline; }
main { padding-top: 24px; padding-bottom: 64px; }

/* text helpers */
.label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; margin-bottom: 8px; }
.note, .sub { color: var(--muted); font-size: 13px; }
.sub { margin: 4px 0 0; }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.msg { margin: 0 0 24px; padding: 8px 12px; border-left: 3px solid var(--accent); background: #f5f6f8; }
.error { padding: 8px 12px; border-left: 3px solid var(--error); color: var(--error); }
.notice { margin: 0 0 32px; }
.notice p { margin: 0; }
.notice p + p { margin-top: 6px; }
.notice code { font-size: 12px; word-break: break-all; color: var(--fg); }

/* summary: three equal columns */
.summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 24px; }
.stat .label { margin-bottom: 4px; }
.stat .value { font-size: 34px; line-height: 1.15; font-weight: 400; }
.stat .value.strong { font-weight: 600; }
.stat .unit { font-size: 15px; color: var(--muted); margin-left: 6px; font-weight: 400; }

/* rate by period: one row per period, the selected one drives the chart's rate and -0.5 kg/week lines */
.periods { margin-top: 40px; }
table.rates thead th { font-size: 12px; padding-bottom: 2px; }
table.rates td, table.rates thead th:not(:first-child) { text-align: right; }
table.rates tr.selected th, table.rates tr.selected td { color: var(--fg); font-weight: 600; }
table.rates .short { display: none; }
form.since { margin: 8px 0 0; }
@media (max-width: 600px) {
  table.rates .chg { display: none; }  /* phone: the rate and the gap answer the question */
  table.kv.rates td { white-space: nowrap; }
  table.rates .long { display: none; }
  table.rates .short { display: inline; }
  table.kv.rates th, table.kv.rates td { padding-left: 12px; padding-right: 0; }
  table.kv.rates th:first-child { padding-left: 0; }
  table.rates thead th { white-space: normal; vertical-align: bottom; }
}
form.since input { font-size: 13px; padding: 2px 6px; margin-left: 4px; }

/* details: change table and target, aligned to the summary columns */
.details { display: grid; grid-template-columns: repeat(3, 1fr); gap: 24px; margin-top: 40px; }
.details table.kv td { white-space: normal; }
table { border-collapse: collapse; }
table.kv th, table.kv td { padding: 4px 0; text-align: left; vertical-align: baseline; white-space: nowrap; }
table.kv th { font-weight: normal; color: var(--muted); padding-right: 24px; }
table.kv td + td { padding-left: 24px; }
table.changes thead th { font-size: 12px; padding-bottom: 2px; }
table.changes td, table.changes thead th:not(:first-child) { text-align: right; }

/* toolbar above the chart: period on the left, sync on the right */
.toolbar { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 12px 24px;
  margin-top: 40px; padding: 12px 0; border-top: 1px solid var(--line); }
.ranges { display: flex; flex-wrap: wrap; gap: 4px 20px; }
.ranges strong { font-weight: 600; }
form.sync { display: flex; align-items: center; gap: 12px; margin: 0; }
form.sync .sub { margin: 0; }
form.sync button { padding: 3px 10px; font-size: 13px; }

.chart { position: relative; height: 400px; margin-top: 8px; }
#chart-note:empty { display: none; }
.more { margin-top: 24px; }

/* history */
.history-section { margin-top: 40px; }
.section-head { display: flex; justify-content: space-between; align-items: baseline; gap: 16px; }
.history-section > .sub { margin: 4px 0 12px; }
.history { width: 100%; }
.history th, .history td { padding: 6px 16px 6px 0; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
.history th:last-child, .history td:last-child { padding-right: 0; }
.history th:first-child, .history td:first-child { text-align: left; }
.history thead th { font-weight: 600; font-size: 13px; border-bottom-color: var(--line-strong); }
.history td.note, .history td.actions { text-align: left; }
.history tr.error td { color: var(--error); }
.history tr.duplicate-db td, .history tr.duplicate-file td { color: var(--muted); }
.actions form { display: inline; margin-left: 8px; }

/* body page */
.body-layout { display: grid; grid-template-columns: 1fr 1fr; gap: 40px; }
.body-layout form.add { margin: 0; }
.howto p { margin: 0 0 12px; max-width: 60ch; }

/* other pages */
.facts th { text-align: left; font-weight: normal; color: var(--muted); padding: 4px 24px 4px 0; }
.facts td { padding: 4px 24px 4px 0; }
form.add { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: end; margin: 24px 0; }
form.add label, form.stack label { display: flex; flex-direction: column; font-size: 13px; color: var(--muted); gap: 4px; }
form.stack { display: flex; flex-direction: column; align-items: flex-start; gap: 16px; margin: 16px 0; }
label.inline { flex-direction: row !important; align-items: center; gap: 6px !important; color: var(--fg) !important; margin-right: 16px; }
fieldset { border: 1px solid var(--line-strong); padding: 8px 16px 12px; }
legend { padding: 0 4px; }
dt { font-weight: 600; margin-top: 8px; }
dd { margin-left: 0; }

input, select, button { font: inherit; padding: 5px 8px; border: 1px solid var(--line-strong); border-radius: 3px; background: #fff; color: var(--fg); }
button { background: #f2f2f4; cursor: pointer; }
button:hover { background: #e8e8ec; }
button.link { border: none; background: none; padding: 0; color: var(--accent); text-decoration: underline; }

@media (max-width: 760px) {
  header .bar, main { padding-left: 16px; padding-right: 16px; }
  .summary { grid-template-columns: 1fr 1fr; gap: 24px 16px; }
  .summary .stat:nth-child(3) { grid-column: span 2; }
  .stat .value { font-size: 28px; }
  .details { grid-template-columns: 1fr; gap: 24px; margin-top: 32px; }
  table.kv { width: 100%; }
  table.kv td { white-space: normal; }
  .toolbar { margin-top: 32px; }
  .chart { height: 300px; }
  .history { display: block; overflow-x: auto; }
  .body-layout { grid-template-columns: 1fr; gap: 32px; }
}

/* login: one narrow centred column, full-width fields */
.login { max-width: 320px; margin: 40px auto 0; }
.login h1 { margin-bottom: 24px; }
.login form.stack { align-items: stretch; margin: 0; }
.login form.stack label { font-size: 14px; }
.login input, .login button { width: 100%; padding: 10px 12px; font-size: 16px; }
.login button { margin-top: 8px; }
