:root {
  color-scheme: light;
  --page: #f4f1ea;
  --surface: #fffdf8;
  --surface-soft: #faf8f2;
  --text: #25241f;
  --muted: #6f6b61;
  --line: #ded9ce;
  --focus: #4d6b5a;
  --chart-actual: #5571ad;
  --chart-average: #2f6b50;
  --chart-boundary: #a96a32;
  --neutral-bg: #eeebe3;
  --neutral-border: #d4cfc3;
  --good: #205f42;
  --good-bg: #e2f2e8;
  --good-border: #a8d0b7;
  --danger: #8c332a;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  padding: 28px 24px 40px;
  background: var(--page);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
}

main {
  width: min(100%, 680px);
  margin: 0 auto;
  display: grid;
  gap: 24px;
}

.site-nav {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
  width: min(100%, 430px);
  margin: 0 auto -8px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: rgb(255 253 248 / 82%);
  box-shadow: 0 8px 26px rgb(56 48 33 / 6%);
}

.site-nav-link {
  padding: 9px 18px;
  border-radius: 11px;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 700;
  text-align: center;
  text-decoration: none;
  transition: color 150ms ease, background-color 150ms ease, box-shadow 150ms ease;
}

.site-nav-link:hover {
  color: var(--text);
}

.site-nav-link[aria-current="page"] {
  background: var(--text);
  color: #fff;
  box-shadow: 0 4px 12px rgb(37 36 31 / 16%);
}

.site-nav-link:focus-visible,
button:focus-visible,
.history-summary:focus-visible {
  outline: 3px solid rgb(77 107 90 / 30%);
  outline-offset: 2px;
}

.card {
  padding: clamp(24px, 6vw, 40px);
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--surface);
  box-shadow: 0 18px 50px rgb(56 48 33 / 8%);
}

.page-header {
  margin-bottom: 30px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 750;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  line-height: 1.15;
  letter-spacing: -0.035em;
}

h1 {
  font-size: clamp(1.9rem, 7vw, 2.6rem);
}

h2 {
  font-size: 1.45rem;
}

.subtitle {
  margin: 10px 0 0;
  color: var(--muted);
}

form {
  display: grid;
  gap: 20px;
}

.field {
  display: grid;
  gap: 8px;
}

.field-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

label {
  font-weight: 650;
}

.input-wrap {
  display: flex;
  align-items: center;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: #fff;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

.input-wrap:focus-within {
  border-color: var(--focus);
  box-shadow: 0 0 0 3px rgb(77 107 90 / 15%);
}

input {
  width: 100%;
  min-width: 0;
  padding: 12px 14px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 1rem;
  font-variant-numeric: tabular-nums;
}

input::placeholder {
  color: #aaa59a;
}

.unit {
  padding: 0 14px;
  border-left: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.88rem;
  white-space: nowrap;
}

.hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
  overflow-wrap: anywhere;
}

.result {
  padding: 22px;
  border: 1px solid var(--neutral-border);
  border-radius: 17px;
  background: var(--neutral-bg);
  transition: color 180ms ease, background-color 180ms ease, border-color 180ms ease;
}

.result-label {
  margin: 0;
  font-size: 0.82rem;
  font-weight: 750;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.total {
  margin: 4px 0 8px;
  font-size: clamp(2rem, 9vw, 3rem);
  font-weight: 750;
  line-height: 1.1;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
}

.breakdown {
  margin: 0;
}

.breakdown {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid currentColor;
  color: var(--muted);
  font-size: 0.86rem;
  opacity: 0.84;
}

.actions {
  display: flex;
  align-items: center;
  gap: 14px;
}

button {
  appearance: none;
  padding: 12px 18px;
  border: 0;
  border-radius: 12px;
  cursor: pointer;
  font: inherit;
  font-weight: 700;
}

button:disabled {
  cursor: wait;
  opacity: 0.6;
}

.primary-button {
  background: var(--text);
  color: #fff;
}

.primary-button:hover {
  background: #3c3a33;
}

.feedback {
  margin: 0;
  color: var(--good);
  font-size: 0.88rem;
  font-weight: 650;
}

.feedback.error {
  color: var(--danger);
}

.history-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
}

.history-view-toggle {
  display: inline-grid;
  grid-auto-flow: column;
  gap: 3px;
  margin-bottom: 18px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--neutral-bg);
}

.history-view-button {
  padding: 7px 13px;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font-size: 0.84rem;
}

.history-view-button:hover {
  color: var(--text);
}

.history-view-button[aria-selected="true"] {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 2px 8px rgb(56 48 33 / 10%);
}

.history-panel[hidden],
.chart-tooltip[hidden] {
  display: none;
}

.history-average {
  display: grid;
  justify-items: end;
  gap: 5px;
  margin-right: 18px;
}

.history-average[hidden],
.latest-weight[hidden] {
  display: none;
}

.history-average-label {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
}

.history-average-value {
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.weight-average-value {
  font-size: 1.05rem;
}

.history-list {
  display: grid;
  gap: 12px;
}

.history-chart {
  min-width: 0;
}

.chart-figure {
  display: grid;
  gap: 12px;
  margin: 0;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  color: var(--muted);
  font-size: 0.76rem;
}

.chart-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.chart-legend-swatch {
  width: 22px;
  border-top: 2px solid var(--focus);
}

.chart-legend-average {
  border-color: var(--chart-average);
  border-top-width: 3px;
}

.chart-legend-series {
  border-color: var(--chart-actual);
  opacity: 0.8;
}

.chart-legend-boundaries {
  border-color: var(--chart-boundary);
  border-top-style: dashed;
}

.chart-plot {
  position: relative;
  min-width: 0;
}

.history-chart-svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}

.chart-grid line,
.chart-date-labels line {
  stroke: var(--line);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}

.chart-week-grid line {
  stroke: var(--line);
  stroke-width: 1;
  opacity: 0.55;
  vector-effect: non-scaling-stroke;
}

.chart-grid text,
.chart-date-labels text,
.chart-axis-title {
  fill: var(--muted);
  font-family: inherit;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.chart-axis-title {
  font-size: 12px;
  font-weight: 700;
}

.chart-axis-line {
  stroke: var(--neutral-border) !important;
}

.chart-daily-line,
.chart-average-line,
.chart-boundary {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}

.chart-daily-line {
  stroke: var(--chart-actual);
  stroke-width: 1.5;
  opacity: 0.55;
}

.chart-average-line {
  stroke: var(--chart-average);
  stroke-width: 3.25;
}

.chart-average-markers {
  pointer-events: none;
}

.chart-average-marker {
  fill: var(--chart-average);
  stroke: var(--surface);
  stroke-width: 1.5;
  vector-effect: non-scaling-stroke;
}

.chart-average-marker-label {
  fill: var(--chart-average);
  stroke: var(--surface);
  stroke-width: 3.5px;
  stroke-linejoin: round;
  paint-order: stroke fill;
  font-size: 11px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.chart-boundary {
  stroke-width: 1.5;
}

.chart-boundary-lower,
.chart-boundary-upper {
  stroke: var(--chart-boundary);
  stroke-dasharray: 7 5;
}

.chart-point-target {
  cursor: pointer;
  outline: none;
}

.chart-point-hit {
  fill: transparent;
}

.chart-point-dot {
  fill: var(--surface);
  stroke: var(--chart-actual);
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
}

.chart-point-target:hover .chart-point-dot,
.chart-point-target:focus .chart-point-dot {
  fill: var(--chart-actual);
  stroke: var(--surface);
  stroke-width: 3;
}

.chart-tooltip {
  position: absolute;
  z-index: 2;
  display: grid;
  min-width: 126px;
  max-width: min(220px, 80vw);
  padding: 9px 11px;
  border: 1px solid var(--neutral-border);
  border-radius: 10px;
  background: var(--text);
  box-shadow: 0 8px 20px rgb(37 36 31 / 18%);
  color: #fff;
  font-size: 0.76rem;
  line-height: 1.4;
  pointer-events: none;
  transform: translate(-50%, calc(-100% - 10px));
}

.chart-tooltip[data-align="start"] {
  transform: translate(0, calc(-100% - 10px));
}

.chart-tooltip[data-align="end"] {
  transform: translate(-100%, calc(-100% - 10px));
}

.chart-tooltip strong,
.chart-tooltip span {
  display: block;
  white-space: nowrap;
}

.chart-caption {
  color: var(--muted);
  font-size: 0.76rem;
  text-align: right;
}

.empty-history,
.empty-latest {
  margin: 0;
  padding: 26px;
  border: 1px dashed var(--line);
  border-radius: 15px;
  color: var(--muted);
  text-align: center;
}

.empty-history p {
  margin: 0;
}

.empty-history .text-button {
  margin-top: 8px;
}

.history-item {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: var(--surface-soft);
}

.history-summary {
  display: grid;
  grid-template-columns: 14px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 17px;
  cursor: pointer;
  list-style: none;
}

.history-summary::-webkit-details-marker {
  display: none;
}

.history-summary::before {
  content: "›";
  color: var(--muted);
  font-size: 1.35rem;
  line-height: 1;
  transform-origin: center;
  transition: transform 150ms ease;
}

.history-item[open] .history-summary::before {
  transform: rotate(90deg);
}

.history-summary-total {
  justify-self: start;
  font-size: 0.9rem;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.history-item[open] .history-summary-total {
  display: none;
}

.history-expanded {
  padding: 16px 17px 17px;
  border-top: 1px solid var(--line);
}

.history-date {
  margin: 0;
  font-weight: 400;
}

.history-total {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
}

.history-details {
  margin: 12px 0;
  color: var(--muted);
  font-size: 0.84rem;
}

.history-actions {
  display: flex;
  align-items: center;
  gap: 14px;
  justify-content: flex-start;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.text-button {
  padding: 4px 0;
  background: transparent;
  color: var(--focus);
  font-size: 0.85rem;
}

.text-button.danger {
  color: var(--danger);
}

.secondary-button {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
}

.secondary-button:hover {
  background: var(--surface-soft);
}

.report-main {
  width: min(100%, 940px);
}

.report-controls {
  display: grid;
  gap: 24px;
}

.report-controls-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 28px;
}

.report-print-button {
  flex: 0 0 auto;
  max-width: 260px;
}

.report-period-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.report-period-link {
  padding: 8px 13px;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
  text-decoration: none;
}

.report-period-link:hover {
  color: var(--text);
}

.report-period-link.selected {
  border-color: var(--text);
  background: var(--text);
  color: #fff;
}

.report-period-form {
  grid-template-columns: minmax(150px, 1fr) minmax(150px, 1fr) auto;
  align-items: end;
  gap: 14px;
}

.report-error {
  margin: 0;
  padding: 13px 15px;
  border: 1px solid #d9aaa5;
  border-radius: 12px;
  background: #f8e9e7;
  color: var(--danger);
  font-weight: 650;
}

.report-document {
  display: grid;
  gap: 30px;
}

.report-document-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 30px;
  padding-bottom: 24px;
  border-bottom: 2px solid var(--text);
}

.report-document-header h2 {
  max-width: 620px;
  font-size: clamp(1.7rem, 4vw, 2.35rem);
}

.report-period {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 1rem;
}

.report-generated {
  display: grid;
  flex: 0 0 auto;
  gap: 3px;
  color: var(--muted);
  font-size: 0.76rem;
  text-align: right;
}

.report-generated strong {
  color: var(--text);
  font-size: 0.82rem;
  white-space: nowrap;
}

.report-section {
  display: grid;
  gap: 15px;
}

.report-section h3 {
  margin: 0;
  font-size: 1.08rem;
  line-height: 1.25;
}

.report-definition-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px 18px;
  margin: 0;
}

.report-definition-grid div {
  min-width: 0;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.report-definition-grid dt {
  color: var(--muted);
  font-size: 0.72rem;
}

.report-definition-grid dd {
  margin: 3px 0 0;
  font-size: 0.9rem;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.report-summary-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.report-metric {
  display: grid;
  align-content: start;
  gap: 5px;
  min-height: 122px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface-soft);
}

.report-metric > span,
.report-product > span {
  color: var(--muted);
  font-size: 0.74rem;
}

.report-metric strong {
  font-size: 1.25rem;
  font-variant-numeric: tabular-nums;
}

.report-metric small,
.report-product small {
  color: var(--muted);
  line-height: 1.35;
}

.report-metric-details {
  display: block;
  white-space: nowrap;
}

.report-chart {
  min-height: 280px;
  padding: 16px 12px 8px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface-soft);
}

.report-chart .empty-history {
  margin-top: 54px;
}

.report-note {
  margin: 0;
  color: var(--muted);
  font-size: 0.76rem;
}

.report-products {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.report-product {
  display: grid;
  gap: 3px;
  padding: 13px 15px;
  border: 1px solid var(--line);
  border-radius: 12px;
}

.report-product strong {
  overflow-wrap: anywhere;
}

.report-empty {
  margin: 0;
  padding: 16px;
  border: 1px dashed var(--line);
  border-radius: 12px;
  color: var(--muted);
}

.report-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
}

.report-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
  line-height: 1.35;
}

.report-table th,
.report-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.report-table th {
  background: var(--neutral-bg);
  font-size: 0.72rem;
  letter-spacing: 0.02em;
}

.report-table tbody tr:last-child td {
  border-bottom: 0;
}

.report-table time,
.report-calories,
.report-weight {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.report-data-table {
  table-layout: fixed;
}

.report-date-column {
  width: 34%;
}

.report-value-column {
  width: 33%;
}

.latest-weight {
  border-color: var(--good-border);
  background: var(--good-bg);
  color: var(--good);
}

.weight-history-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  padding: 17px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: var(--surface-soft);
}

.weight-history-main {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 18px;
}

.weight-history-value {
  font-weight: 750;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.weight-history-actions {
  display: flex;
  gap: 12px;
}

@media (max-width: 760px) {
  .report-metric-details {
    white-space: normal;
  }
}

@media (max-width: 560px) {
  body {
    padding: 12px;
  }

  main {
    gap: 14px;
  }

  .site-nav {
    margin-top: 2px;
    margin-bottom: 0;
  }

  .card {
    padding: 22px 18px;
    border-radius: 19px;
  }

  .page-header {
    margin-bottom: 24px;
  }

  .field-row {
    grid-template-columns: 1fr;
  }

  .history-summary {
    grid-template-columns: 14px minmax(0, 1fr) auto;
  }

  .history-header {
    flex-direction: column;
  }

  .history-view-toggle {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-auto-flow: row;
    width: 100%;
  }

  .history-average {
    justify-items: start;
    margin-right: 0;
  }

  .primary-button {
    width: 100%;
  }

  .actions {
    align-items: stretch;
    flex-direction: column;
  }

  .weight-history-row {
    grid-template-columns: 1fr;
  }

  .weight-history-actions {
    padding-top: 10px;
    border-top: 1px solid var(--line);
  }

  .report-controls-header,
  .report-document-header {
    flex-direction: column;
  }

  .report-print-button {
    width: 100%;
    max-width: none;
  }

  .report-period-form,
  .report-definition-grid,
  .report-summary-grid,
  .report-products {
    grid-template-columns: 1fr;
  }

  .report-generated {
    text-align: left;
  }

  .report-table-wrap {
    margin-right: -18px;
    margin-left: -18px;
    border-right: 0;
    border-left: 0;
    border-radius: 0;
  }
}

@page {
  size: A4 portrait;
  margin: 12mm;
}

@media print {
  :root {
    --page: #fff;
    --surface: #fff;
    --surface-soft: #fff;
    --text: #111;
    --muted: #4b4b4b;
    --line: #bdbdbd;
    --neutral-bg: #f1f1f1;
    --chart-actual: #3f5685;
    --chart-average: #24583f;
  }

  * {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  body {
    min-height: 0;
    padding: 0;
    background: #fff;
    font-size: 9pt;
    line-height: 1.35;
  }

  main.report-main {
    display: block;
    width: 100%;
  }

  .site-nav,
  .report-controls,
  .chart-tooltip {
    display: none !important;
  }

  .report-document {
    display: block;
    padding: 0;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .report-document-header {
    margin-bottom: 6.5mm;
    padding-bottom: 3mm;
  }

  .report-document-header h2 {
    font-size: 20pt;
  }

  .report-section {
    gap: 2.5mm;
    margin-bottom: 6.5mm;
  }

  .report-pet > h3,
  .report-summary > h3,
  .report-pet-species,
  .report-pet-breed,
  .report-pet-coat-color,
  .report-pet-birth-date,
  .report-chart-card .report-note,
  .report-chart .chart-caption {
    display: none;
  }

  .report-pet,
  .report-summary-grid,
  .report-products-section,
  .report-products,
  .report-chart-card,
  .report-product,
  .report-metric {
    break-inside: avoid;
  }

  .report-definition-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 3mm;
  }

  .report-definition-grid div {
    padding-top: 0;
    border-top: 0;
  }

  .report-summary-grid {
    gap: 4.5mm;
  }

  .report-metric {
    min-height: 0;
    gap: 1mm;
    padding: 2.5mm 3mm;
    border-radius: 2mm;
  }

  .report-metric strong {
    font-size: 11pt;
  }

  .report-chart-card {
    gap: 3.5mm;
  }

  .report-chart {
    min-height: 0;
    padding: 1.5mm 2mm;
    border-radius: 2mm;
  }

  .history-chart-svg {
    max-height: 61mm;
  }

  .report-chart .chart-figure {
    gap: 1mm;
  }

  .report-chart .chart-legend {
    gap: 2mm 4mm;
    font-size: 7.5pt;
  }

  .chart-point-target {
    pointer-events: none;
  }

  .report-table-wrap {
    display: block;
    overflow: visible;
    border-radius: 0;
  }

  .report-table-section {
    display: block;
  }

  .report-table-section h3 {
    margin-bottom: 4mm;
    break-after: avoid-page;
    page-break-after: avoid;
  }

  .report-table-chunk {
    break-inside: avoid-page;
    page-break-inside: avoid;
  }

  .report-table-chunk + .report-table-chunk {
    break-before: page;
    page-break-before: always;
  }

  .report-table {
    font-size: 7.8pt;
  }

  .report-table thead {
    display: table-header-group;
  }

  .report-table tr {
    break-inside: avoid-page;
    page-break-inside: avoid;
  }

  .report-table th,
  .report-table td {
    padding: 2.3mm 2.5mm;
  }

  .report-data-table,
  .report-data-table thead,
  .report-data-table tbody {
    display: block;
    width: 100%;
  }

  .report-data-table colgroup {
    display: none;
  }

  .report-data-table tr {
    display: grid;
    grid-template-columns: 34% 33% 33%;
  }

}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
