:root {
  --bg: #f3f6f4;
  --card: #fff;
  --ink: #1c2420;
  --muted: #5c6b63;
  --line: #d5e0da;
  --accent: #1c7a40;
  --danger: #b42318;
  --radius: 14px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Segoe UI", Tahoma, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.3;
}

.top {
  background: #1b3a2f;
  color: #fff;
  padding: 0.35rem 0.75rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.35rem 0.75rem;
  position: sticky;
  top: 0;
  z-index: 5;
}
.brand { font-weight: 700; line-height: 1.15; }
.brand a { color: #fff; text-decoration: none; }
.who { font-weight: 650; color: #fff; }
.top nav { display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: center; gap: 0.2rem 0.65rem; line-height: 1.2; font-size: 0.92rem; }
.top nav a { color: #d7ebe0; text-decoration: none; }
.top nav a:hover { color: #fff; }

.wrap { padding: 0.65rem 0.75rem 1.25rem; max-width: 880px; margin: 0 auto; }
h1 { font-size: 1.25rem; margin: 0; line-height: 1.2; }
h2 { font-size: 1.02rem; margin: 0 0 0.3rem; }
p { margin: 0.15rem 0; }
a { color: #146b38; }

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.45rem;
  margin-bottom: 0.45rem;
}
.muted, .field-hint { color: var(--muted); }
.field-hint { font-size: 0.85rem; margin: 0; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.65rem 0.75rem;
  margin-bottom: 0.45rem;
}
.meal-card { display: block; }
.meal-link { display: block; color: inherit; text-decoration: none; }
.meal-name { color: inherit; text-decoration: none; }
.meal-card:hover { border-color: #9db8a6; position: relative; z-index: 3; }
.meal-line { display: flex; justify-content: space-between; align-items: center; gap: 0.45rem; }
.meal-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 0.35rem; flex: 0 0 auto; }
.meal-card .show-comments, .meal-card .meal-edit, .food-card .show-comments { margin: 0; padding: 0.25rem 0.55rem; font-size: 0.85rem; }
.food-score { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 0.45rem; }
#meal-comments, #food-comments {
  border: 0;
  border-radius: var(--radius);
  max-width: 32rem;
  width: calc(100% - 2rem);
  padding: 1rem 1.1rem;
}
#meal-comments::backdrop, #food-comments::backdrop { background: rgba(20, 32, 26, 0.45); }
#meal-comments h2, #food-comments h2 { margin: 0 0 0.6rem; font-size: 1.15rem; }
#meal-comments p, #food-comments p { white-space: pre-wrap; margin: 0 0 1rem; }
.food-find {
  position: sticky;
  top: var(--food-find-top, 2.4rem);
  z-index: 4;
  background: var(--bg);
  padding: 0.25rem 0 0.4rem;
}
.food-find h1 { margin-bottom: 0.35rem; }
.food-find .actions { margin-top: 0.35rem; }
.find-line { display: flex; gap: 0.5rem; align-items: center; }
.find-line input { flex: 1; min-width: 0; }
.find-line button { flex: 0 0 auto; }
.remove-panel { margin-top: 0.8rem; }
.food-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: stretch;
  margin-top: 0.35rem;
}
.food-buttons > .remove-form { display: contents; }
.food-buttons > button,
.food-buttons .ask-remove {
  flex: 1 1 0;
  width: auto;
  min-width: 0;
  margin: 0;
  white-space: normal;
  line-height: 1.2;
  display: flex;
  align-items: center;
  justify-content: center;
}
.food-buttons .remove-panel { flex: 1 1 100%; }
.remove-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.6rem;
}
.replace-status { margin: 0; flex: 1 1 12rem; font-weight: 650; }
.replace-status.is-empty {
  background: #fde8e6;
  color: #8a1c13;
  padding: 0.45rem 0.65rem;
  border-radius: 8px;
}
.meal-top, .person {
  display: flex;
  justify-content: space-between;
  gap: 0.8rem;
  align-items: flex-start;
}
.person { padding: 0.7rem 0; border-top: 1px solid var(--line); }
.person:first-of-type { border-top: 0; }
.person-tools { flex: 1 1 16rem; max-width: 22rem; }
.reset-password { margin-top: 0; }
.person-tools form + form { margin-top: 0.45rem; }
.bits { color: var(--muted); font-size: 0.92rem; }
.foods { margin: 0.15rem 0 0; }
.food-line {
  display: block;
  position: relative;
  padding-left: 0.9rem;
  text-indent: -0.9rem;
}
button.food-line {
  width: 100%;
  margin: 0;
  padding: 0.22rem 0 0.22rem 0.9rem;
  border: 0;
  border-radius: 0;
  background: transparent;
  font-weight: 400;
  text-align: left;
  line-height: 1.3;
  cursor: pointer;
}
.food-line.band-blue { color: #3b8fc4; }
.food-line.band-green { color: #3c9a5c; }
.food-line.band-black { color: #1c2420; }
.food-line.band-yellow { color: #b8920a; }
.food-line.band-red { color: #d23c3c; }
.pill { font-weight: 700; }

form, .inline-form { display: grid; gap: 0.4rem; margin-top: 0.35rem; }
label { display: grid; gap: 0.15rem; font-size: 0.92rem; color: var(--muted); }
input, select, textarea {
  font: inherit;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  width: 100%;
  min-width: 0;
}
input[type="date"] {
  min-height: 0;
  height: 2.45rem;
}
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0.7rem; }
.check-row { display: flex; align-items: center; gap: 0.4rem; color: var(--ink); }
.check-row input { width: auto; }
.series { display: flex; flex-wrap: wrap; gap: 0.7rem 1rem; margin-bottom: 0.8rem; }
.filters { display: grid; grid-template-columns: 1fr 1fr auto; gap: 0.7rem; align-items: end; }
.filters.date-filters { display: flex; flex-wrap: wrap; align-items: end; }
.filters.date-filters label { flex: 1 1 8.5rem; min-width: 0; min-height: 0; }
.filters.date-filters .filter-hint { flex: 1 1 100%; }
.filters.date-filters button { flex: 0 0 auto; }
.filters.date-filters .filter-actions { display: flex; flex: 0 0 auto; gap: 0.5rem; align-items: end; }
.audit-table { margin-top: 0.75rem; }
.audit-table td { vertical-align: top; }
.audit-table .when { white-space: nowrap; }
.audit-label { display: none; }
.audit-summary { overflow-wrap: break-word; }
.saved-pick { margin-bottom: 0.8rem; }
.saved-results {
  list-style: none;
  margin: 0.4rem 0 0;
  padding: 0;
  max-height: 16rem;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}
.saved-results li + li { border-top: 1px solid var(--line); }
.saved-results .saved-hit {
  display: block;
  width: 100%;
  text-align: left;
  background: #fff;
  color: var(--ink);
  font-weight: 550;
  border-radius: 0;
  padding: 0.65rem 0.75rem;
}
.saved-results .saved-hit:hover,
.saved-results .saved-hit:focus { background: #f3f7f4; }
.saved-results .lookup-new { color: #146b38; }
.saved-empty { padding: 0.65rem 0.75rem; color: var(--muted, #5c6b63); }
.food-row {
  display: flex;
  justify-content: space-between;
  gap: 0.8rem;
  align-items: center;
  padding: 0.7rem 0;
  border-top: 1px solid var(--line);
}
.food-row .bits { margin: 0.2rem 0 0; }
#food-rows { margin-top: 0.8rem; }
#food-empty { margin-top: 0.8rem; }

.btn, button, input[type=submit] {
  font: inherit;
  font-size: 0.95rem;
  font-weight: 650;
  border: 0;
  border-radius: 10px;
  padding: 0.45rem 0.7rem;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
  text-align: center;
}
.btn.secondary, button.secondary { background: #5c6b63; }
.btn.danger, button.danger { background: var(--danger); }
.actions { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.barcode-actions { align-self: end; }
.login-wrap { max-width: 460px; margin: 0.6rem auto; }
.password-line { display: flex; gap: 0.5rem; align-items: center; }
.password-line input { flex: 1; min-width: 0; }
.password-line button { flex: 0 0 auto; }
.error, .notice { padding: 0.75rem 0.9rem; border-radius: 10px; }
.error { background: #fde8e6; color: #8a1c13; }
.notice { background: #e5f6ea; color: #146b38; }
.busy {
  display: none;
  align-items: center;
  gap: 0.6rem;
  position: fixed;
  z-index: 7;
  left: 50%;
  transform: translateX(-50%);
  width: min(880px, calc(100% - 1.5rem));
  padding: 0.7rem 0.85rem;
  background: #e5f6ea;
  color: #146b38;
  border-radius: 10px;
  font-weight: 650;
  box-shadow: 0 2px 8px rgba(20, 40, 30, 0.12);
}
.busy.is-on { display: flex; }
.busy-spin {
  width: 1.05rem;
  height: 1.05rem;
  border: 2px solid #b7d7c4;
  border-top-color: #146b38;
  border-radius: 50%;
  flex: 0 0 auto;
  animation: busy-spin 0.7s linear infinite;
}
@keyframes busy-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .busy-spin { animation: none; }
}
button:disabled, input[type=submit]:disabled { opacity: 0.65; cursor: default; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 0.45rem 0.35rem; border-bottom: 1px solid var(--line); }
#chart { width: 100%; height: auto; background: #fff; }
.chart-wrap { position: relative; }
.chart-tip {
  position: absolute;
  z-index: 2;
  pointer-events: none;
  background: #1b3a2f;
  color: #fff;
  border-radius: 8px;
  padding: 0.35rem 0.55rem;
  font-size: 0.82rem;
  line-height: 1.35;
  white-space: pre;
  box-shadow: 0 2px 8px rgba(20, 40, 30, 0.18);
}
.scan-pop {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.75rem;
  background: rgba(20, 32, 26, 0.55);
}
.scan-pop[hidden] { display: none !important; }
body.scan-open { overflow: hidden; }
.scan-card {
  width: min(28rem, 100%);
  max-height: calc(100dvh - 1.5rem);
  overflow: auto;
  background: #fff;
  border-radius: var(--radius);
  padding: 0.85rem 0.9rem 1rem;
}
.scan-card h2 { margin: 0 0 0.55rem; }
.scan-card video {
  display: block;
  width: 100%;
  aspect-ratio: 3 / 4;
  max-height: min(62dvh, 28rem);
  object-fit: contain;
  background: #111;
  border-radius: 10px;
}
.scan-card .field-hint { margin: 0.5rem 0 0.75rem; }
.scan-card button { width: 100%; }

@media (max-width: 700px) {
  .top { align-items: flex-start; flex-direction: column; padding: 0.28rem 0.6rem; gap: 0.15rem; }
  .brand { font-size: 0.95rem; }
  .top nav { font-size: 0.88rem; gap: 0.1rem 0.5rem; }
  .row2, .filters { grid-template-columns: 1fr; }
  .filters.date-filters { flex-direction: row; flex-wrap: wrap; align-items: end; }
  .filters.date-filters label { flex: 1 1 calc(50% - 0.4rem); }
  .filters.date-filters button { width: auto; flex: 1 1 auto; }
  .filters.date-filters .filter-actions { flex: 1 1 100%; }
  .filters.date-filters .filter-actions .btn,
  .filters.date-filters .filter-actions button { flex: 1 1 auto; }
  .food-row { flex-direction: column; align-items: stretch; }
  .page-head, .meal-top, .person { flex-direction: column; }
  .audit-table,
  .audit-table tbody,
  .audit-table tr,
  .audit-table td { display: block; width: 100%; }
  .audit-table thead { display: none; }
  .audit-table tr { padding: 0.45rem 0 0.55rem; border-bottom: 1px solid var(--line); }
  .audit-table td { border-bottom: 0; padding: 0.08rem 0; overflow-wrap: break-word; }
  .audit-table .when { white-space: normal; }
  .audit-label {
    display: inline;
    color: var(--muted);
    font-weight: 650;
    font-size: 0.78rem;
  }
  .audit-label::after { content: " "; }
}

.print-only, .print-report { display: none; }

@media print {
  .top, .filters, .page-head, .series, form, video, .print-table, .chart-tip, .scan-pop { display: none !important; }
  .print-only, .print-report { display: block; }
  body { background: #fff; }
  .chart-card { break-inside: avoid; }
  .print-day { break-inside: auto; margin-top: 1rem; }
  .print-day h3 { margin: 0 0 0.4rem; }
  .print-meal { break-inside: avoid; margin: 0 0 0.9rem; }
  .print-meal h4 { margin: 0.2rem 0; }
  .print-score, .print-notes, .print-comments { margin: 0.35rem 0; }
  .report-scope { margin: 0 0 0.6rem; color: #5c6b63; }
}
