:root {
  --forest: #1F3A32;
  --forest-2: #2E5447;
  --paper: #F4F6F3;
  --card: #FFFFFF;
  --ink: #1C2421;
  --muted: #5E6F68;
  --line: #D5DDD8;
  --tag: #E8B923;      /* collar-tag yellow: "due" and highlights */
  --alert: #B3261E;    /* overdue */
  --ok: #2F7D4F;
  --radius: 6px;
  --display: "Bricolage Grotesque", system-ui, sans-serif;
  --body: "Atkinson Hyperlegible", system-ui, sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 17px/1.5 var(--body); }
a { color: var(--forest-2); }
h1, h2 { font-family: var(--display); line-height: 1.15; margin: 0 0 .6rem; }
h1 { font-size: 2rem; font-weight: 800; }
h2 { font-size: 1.3rem; font-weight: 600; }
:focus-visible { outline: 3px solid var(--tag); outline-offset: 2px; }
.muted { color: var(--muted); }
.prose { max-width: 70ch; white-space: pre-line; }

/* Top bar */
.topbar { display: flex; align-items: center; gap: 1.5rem; padding: .75rem 1.25rem; background: var(--forest); color: #fff; flex-wrap: wrap; }
.brand { font-family: var(--display); font-weight: 800; font-size: 1.3rem; color: #fff; text-decoration: none; }
.topbar nav { display: flex; gap: 1rem; flex: 1; }
.topbar nav a { color: #CFE0D8; text-decoration: none; padding: .25rem 0; border-bottom: 3px solid transparent; }
.topbar nav a[aria-current] { color: #fff; border-bottom-color: var(--tag); }
.signout { margin: 0; }
button.link { background: none; border: 0; color: #CFE0D8; font: inherit; cursor: pointer; text-decoration: underline; }

.page { max-width: 1320px; margin: 0 auto; padding: 1.5rem 1.25rem 4rem; }
.page > section { margin-top: 2.25rem; }
.section-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }

/* Buttons */
.btn { display: inline-block; background: var(--forest); color: #fff; border: 0; border-radius: var(--radius); padding: .6rem 1.1rem; font: 700 1rem var(--body); text-decoration: none; cursor: pointer; }
.btn:hover { background: var(--forest-2); }
.btn-small { padding: .35rem .7rem; font-size: .9rem; }
.btn-quiet { background: transparent; color: var(--forest); box-shadow: inset 0 0 0 2px var(--forest); }
.btn-quiet:hover { background: #E3EBE6; }
.btn-danger { color: var(--alert); box-shadow: inset 0 0 0 2px var(--alert); }
.actions { display: flex; gap: 1rem; align-items: center; margin-top: 1rem; }
.actions form { margin: 0; }

/* Flash */
.flash { padding: .7rem 1rem; border-radius: var(--radius); border-left: 5px solid var(--ok); background: #E6F2EA; }
.flash-error { border-color: var(--alert); background: #F8E6E4; }

/* Dashboard headcount: the one loud element */
.headcount { margin-top: .5rem !important; }
.headcount-num { font: 800 clamp(4rem, 14vw, 8rem)/0.9 var(--display); color: var(--forest); margin: 0; }
.headcount-label { font-size: 1.2rem; margin: .3rem 0 .8rem; }
.headcount-split { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: .5rem 1.25rem; }

/* Medical clipboard */
.clipboard { background: var(--card); border: 1px solid var(--line); border-top: 6px solid var(--tag); border-radius: var(--radius); padding: 1.25rem; }
.due-list { list-style: none; margin: 0; padding: 0; }
.due-list li { display: grid; grid-template-columns: 7.5rem 1fr auto; gap: 1rem; align-items: center; padding: .7rem 0; border-top: 1px solid var(--line); }
.due-list li:first-child { border-top: 0; }
.due-list form { margin: 0; }
.due-what a { font-weight: 700; margin-right: .5rem; }
.due { display: inline-block; font-weight: 700; padding: .15rem .5rem; border-radius: 3px; background: #F3F0DF; }
.due-today { background: var(--tag); }
.due-over { background: var(--alert); color: #fff; }

/* Status pills */
.pill { display: inline-block; font-size: .85rem; padding: .1rem .55rem; border-radius: 999px; background: #E3EBE6; color: var(--forest); white-space: nowrap; }
.pill-medical_hold { background: #F8E6E4; color: var(--alert); }
.pill-available { background: var(--forest); color: #fff; }
.pill-reserved, .pill-fostered { background: #F3E7B8; color: #5A4500; }
.pill-adopted { background: #DDEFE2; color: var(--ok); }
.pill-travelling { background: #E1ECF7; color: #1D4470; }
.pill-deceased { background: #E4E4E4; color: #555; }

/* Animal cards */
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 1rem; }
.animal-card { display: flex; gap: .8rem; align-items: center; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .7rem; color: inherit; text-decoration: none; }
.animal-card:hover { border-color: var(--forest-2); }
.animal-card img, .animal-card .noimg { width: 64px; height: 64px; border-radius: 50%; object-fit: cover; flex: none; }
.animal-card-body { display: flex; flex-direction: column; gap: .15rem; align-items: flex-start; }
.noimg { display: grid; place-items: center; background: var(--forest); color: var(--tag); font: 800 1.6rem var(--display); }

/* Tables */
.table { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.table th, .table td { padding: .6rem .8rem; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { font-size: .9rem; color: var(--muted); font-weight: 700; }
.filters { display: flex; gap: .6rem; flex-wrap: wrap; margin: 1rem 0; }
.filters input { flex: 1; min-width: 12rem; }
.pager { display: flex; gap: 1rem; align-items: center; justify-content: center; margin-top: 1rem; }
.table form { margin: 0; }
.table .note-row td { padding-top: 0; font-size: .95rem; }
.table tr:has(+ .note-row) td { border-bottom: 0; }
.nowrap { white-space: nowrap; }
.count { display: inline-block; min-width: 1.4em; padding: 0 .35em; border-radius: 999px; background: var(--tag); color: var(--ink); font-size: .8rem; font-weight: 700; text-align: center; }
h3 { font: 600 1.05rem var(--display); margin: 1.25rem 0 .5rem; }
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 1rem; }
.photo { margin: 0; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.photo img { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; }
.photo figcaption { display: flex; flex-wrap: wrap; gap: .4rem .8rem; align-items: center; justify-content: space-between; padding: .45rem .6rem; font-size: .9rem; }
.photo figcaption form { margin: 0; }
.photo-pending { border-style: dashed; border-color: var(--tag); }
.photo-download { display: inline-block; margin-top: .4rem; font-size: .9rem; }
button.link-danger { background: none; border: 0; padding: 0; color: var(--alert); font: inherit; cursor: pointer; text-decoration: underline; }
.notifications li.is-new { background: #FBF4D6; }
.notifications li { padding-left: .6rem; padding-right: .6rem; grid-template-columns: max-content 1fr auto; }
.notice { border-left-color: var(--tag); background: #FBF4D6; }
.log tr.is-new td { background: #FBF4D6; }
.change { padding: .8rem 0; border-top: 1px solid var(--line); }
.change:first-of-type { border-top: 0; }
.change p { margin: 0 0 .3rem; }
.change-photo { display: block; width: 120px; height: 120px; object-fit: cover; border-radius: var(--radius); margin-top: .5rem; }
.log { font-size: .95rem; }
.log summary { cursor: pointer; color: var(--forest-2); }
.pill-log-create { background: #DDEFE2; color: var(--ok); }
.pill-log-delete { background: #F8E6E4; color: var(--alert); }

/* Forms */
input, select, textarea { font: inherit; padding: .5rem .6rem; border: 1px solid #AFBDB6; border-radius: var(--radius); background: #fff; width: 100%; }
textarea { min-height: 5rem; }
input[type=checkbox] { width: auto; }
[aria-invalid] { border-color: var(--alert); }
.field { display: flex; flex-direction: column; gap: .25rem; margin-bottom: .9rem; }
.field label { font-weight: 700; }
.field small { color: var(--muted); }
.field .err { color: var(--alert); }
.field-check { flex-direction: row; align-items: center; gap: .5rem; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); padding: 1rem 1.25rem .25rem; margin: 0 0 1.25rem; }
legend { font: 600 1.1rem var(--display); padding: 0 .4rem; }
.add-record { margin-top: 1rem; }
.add-record summary { cursor: pointer; font-weight: 700; color: var(--forest-2); margin-bottom: 1rem; }

/* Profile */
.profile { display: grid; grid-template-columns: 240px 1fr; gap: 1.5rem; }
.profile-photo img, .profile-photo .noimg { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: var(--radius); font-size: 5rem; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: .3rem 1.25rem; margin: 1rem 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }

.login { max-width: 380px; margin: 12vh auto 0; }
.login h1 { font-size: 3rem; color: var(--forest); }
.empty { color: var(--muted); padding: 1rem 0; }

@media (max-width: 640px) {
  .grid2, .profile { grid-template-columns: 1fr; }
  .profile-photo { max-width: 200px; }
  .due-list li { grid-template-columns: 1fr auto; }
  .due-list li .due { grid-column: 1 / -1; justify-self: start; }
  .table thead { display: none; }
  .table td { display: block; border: 0; padding: .2rem .8rem; }
  .table tr { display: block; border-bottom: 1px solid var(--line); padding: .5rem 0; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
.section-head { margin-bottom: 1rem; }
.section-head h1, .section-head h2 { margin: 0; }
.topbar-user { display: flex; gap: 1rem; align-items: center; }
.topbar-user a { color: #CFE0D8; text-decoration: none; }
.topbar-user a[aria-current] { color: #fff; }
.language-switch { text-align: center; margin-top: 2rem; }
.narrow { max-width: 480px; }
.exports { margin-top: 1.5rem; font-size: .95rem; }
.row-actions { display: flex; gap: .8rem; align-items: center; }
.trend-up { color: var(--ok); }
.trend-down { color: var(--alert); }
.inline-edit summary { cursor: pointer; color: var(--forest-2); font-size: .9rem; }
.inline-edit form { display: flex; gap: .4rem; align-items: center; margin-top: .4rem; }
.inline-edit input { width: auto; }
.due-who { display: flex; align-items: center; gap: .7rem; }
.avatar { flex: none; margin: 0 !important; }
.avatar img, .avatar .noimg { display: grid; width: 56px; height: 56px; border-radius: 50%; object-fit: cover; }
.avatar .noimg { font-size: 1.4rem; }
.pill-waiting { background: #FBF4D6; color: #5A4500; }
.stat-tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 1rem; margin: 1rem 0 0; }
.stat-tiles > div { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem 1rem; }
.stat-tiles dt { color: var(--muted); font-size: .9rem; }
.stat-tiles dd { margin: .2rem 0 0; font: 800 2rem/1.1 var(--display); color: var(--forest); }
.stat-tiles dd small { font: 400 .9rem var(--body); color: var(--muted); }
.numbers td, .numbers thead th:not(:first-child) { text-align: right; font-variant-numeric: tabular-nums; }
.numbers tfoot th, .numbers tfoot td { font-weight: 700; border-top: 2px solid var(--line); }
.section-head .filters { margin: 0; }
.pill-country { background: #E1ECF7; color: #1D4470; }
.placed-list li { grid-template-columns: 1fr auto; }
.pill-travel-ok { background: #DDEFE2; color: var(--ok); }
.pill-travel-missing { background: #F8E6E4; color: var(--alert); text-decoration: none; }
.checklist { list-style: none; margin: .6rem 0; padding: 0; }
.checklist li { display: grid; grid-template-columns: 1.6rem 1fr; gap: .5rem; padding: .5rem 0; border-top: 1px solid var(--line); }
.checklist li:first-child { border-top: 0; }
.check-mark { font-weight: 700; font-size: 1.15rem; line-height: 1.3; }
.check-ok .check-mark { color: var(--ok); }
.check-missing .check-mark { color: var(--alert); }
.check-later .check-mark { color: #5A4500; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
code { font-size: .9em; background: #E9EEEB; padding: .05rem .3rem; border-radius: 3px; word-break: break-all; }
.pill-sponsored { background: #F3E3F7; color: #6A1B7A; }
.animal-card-body > span:last-child { display: flex; flex-wrap: wrap; gap: .3rem; }
.form-aside { align-self: center; margin: 0 0 .9rem; }
.panel { background: var(--card); border: 1px solid var(--line); border-top: 4px solid var(--forest-2); border-radius: var(--radius); padding: 1.25rem; }
.panel > :last-child, .clipboard > :last-child { margin-bottom: 0; }
.panel .add-record { margin-bottom: 0; }
.panel .add-record[open] summary { margin-bottom: 1rem; }
.panel .add-record:not([open]) summary { margin-bottom: 0; }
tr[hidden] { display: none !important; }
.show-more { display: block; margin: .6rem 0 0; padding: 0; background: none; border: 0; color: var(--forest-2); font: 700 1rem var(--body); cursor: pointer; text-decoration: underline; }
.animal-card { min-width: 0; }
.animal-card-body { min-width: 0; }
.animal-card .pill { white-space: normal; }
.pill-owned { background: #E1ECF7; color: #1D4470; }
.sterilization { margin-bottom: 1.1rem; padding-bottom: 1rem; border-bottom: 1px solid var(--line); }
.sterilization p { margin: 0 0 .4rem; }
.document-details { flex-wrap: wrap; }
.document-details select, .document-details input { width: auto; max-width: 11rem; }
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: .6rem; margin: .6rem 0; }
.media-grid video { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; background: #000; }
.inline-edit form.stack { display: block; }
.photo-col { width: 56px; padding-right: 0 !important; }
.avatar-small img, .avatar-small .noimg { width: 40px; height: 40px; font-size: 1.05rem; }
.missing-icon { display: inline-block; padding: .05rem .45rem; border-radius: 999px; background: #F8E6E4; color: var(--alert); font-size: .85rem; font-weight: 700; white-space: nowrap; cursor: help; }
.missing-list { margin: .5rem 0 0; display: flex; flex-wrap: wrap; gap: .3rem; align-items: center; }
.summary-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: .75rem 2rem; }
.summary h3 { margin-top: .4rem; }
.summary-list { list-style: none; margin: 0; padding: 0; }
.summary-list li { padding: .2rem 0; }
.profile + .summary { margin-top: 1.5rem; }
.appointment { margin: .25rem 0 .6rem; }
.appointment p { margin: .2rem 0; }
.appointment-links { display: flex; flex-wrap: wrap; gap: .3rem 1rem; }
.appointment-form { flex-wrap: wrap; }
.appointment-form input { width: auto; }
.table { table-layout: auto; }
.table th, .table td { overflow-wrap: anywhere; }
.table th { white-space: nowrap; }
.due { white-space: nowrap; }
.prose { max-width: 90ch; }
.stack > fieldset, form.stack { max-width: 1040px; }
.panel form.stack, .clipboard form.stack { max-width: none; }

.site-footer { max-width: 1320px; margin: 0 auto; padding: 0 1.25rem 2rem; display: flex; flex-direction: column; align-items: center; gap: .7rem; color: var(--muted); font-size: .9rem; text-align: center; }
.site-footer p { margin: 0; }
.page { padding-bottom: 2.5rem; }
.contact-card h2 { margin-top: 0; }

/* Scan: a photo of a label, read into the field next to it. */
.scan { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem .6rem; }
.field > .scan { align-self: stretch; }
.scan-status { color: var(--muted); font-size: .9rem; }
.scan-lines { display: flex; flex-wrap: wrap; gap: .4rem; flex: 1 1 100%; }
.scan-lines button { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .45rem .7rem; font: inherit; text-align: left; cursor: pointer; overflow-wrap: anywhere; }
.scan-lines button:hover, .scan-lines button:focus-visible { border-color: var(--ink); }

/* ============================ Phones and small tablets ============================
   Most use is on a phone. Below 760px: one column, a menu that opens from a button,
   table rows as cards, and controls big enough for a thumb. */
.nav-toggle { display: none; }
.profile > *, .summary-grid > *, .grid2 > *, .due-list li > * { min-width: 0; }
.facts dd { overflow-wrap: anywhere; }
.actions { flex-wrap: wrap; }
.section-head { flex-wrap: wrap; }
img, video { max-width: 100%; }

@media (max-width: 760px) {
  body { font-size: 16px; }
  h1 { font-size: 1.6rem; }
  h2 { font-size: 1.2rem; }
  .page { padding: 1rem .8rem 3rem; }
  .page > section { margin-top: 1.25rem; }
  .panel, .clipboard { padding: .9rem; }
  fieldset { padding: .8rem .8rem .1rem; }

  /* Top bar: name and Menu button; the links drop down as a list. */
  .topbar { gap: .5rem 1rem; padding: .6rem .8rem; justify-content: space-between; }
  .nav-toggle { display: inline-flex; align-items: center; gap: .4rem; min-height: 44px; padding: 0 .8rem; background: transparent; color: #fff; border: 1px solid #5C7A6E; border-radius: var(--radius); font: 700 1rem var(--body); cursor: pointer; }
  .topbar nav { flex: 1 1 100%; flex-direction: column; gap: 0; }
  .topbar nav a { padding: .7rem .2rem; border-bottom: 1px solid #35564B; border-left: 4px solid transparent; }
  .topbar nav a[aria-current] { border-bottom-color: #35564B; border-left-color: var(--tag); padding-left: .6rem; }
  .topbar-user { flex: 1 1 100%; justify-content: space-between; padding: .5rem .2rem .2rem; }
  .js .topbar nav, .js .topbar .topbar-user { display: none; }
  .js .topbar.nav-open nav, .js .topbar.nav-open .topbar-user { display: flex; }

  /* Thumb-sized controls. */
  .btn { min-height: 44px; display: inline-flex; align-items: center; justify-content: center; }
  .btn-small { min-height: 40px; padding: .4rem .8rem; }
  input, select, textarea { min-height: 44px; font-size: 16px; }
  input[type=checkbox] { min-height: 0; width: 1.3rem; height: 1.3rem; }
  .add-record summary, .inline-edit summary, .show-more { padding: .45rem 0; }
  .actions { gap: .6rem; }
  .actions .btn { flex: 1 1 auto; }

  /* The animal page. */
  .profile { gap: .8rem; }
  .profile-photo { max-width: none; }
  .profile-photo img, .profile-photo .noimg { max-height: 300px; }
  .facts { grid-template-columns: minmax(6.2rem, 36%) 1fr; gap: .35rem .8rem; }
  .summary-grid { grid-template-columns: 1fr; }
  .stat-tiles { grid-template-columns: 1fr 1fr; gap: .6rem; }
  .stat-tiles dd { font-size: 1.6rem; }
  .sterilization p { display: flex; flex-wrap: wrap; gap: .3rem .5rem; align-items: center; }

  /* Lists of things due: one thing per line. */
  .due-list li, .placed-list li, .notifications li { grid-template-columns: 1fr; gap: .35rem; justify-items: start; }
  .due-list li .due { grid-column: auto; }
  .due { white-space: normal; }
  .due-who { width: 100%; }

  /* Tables: each row a card, each value with its column's name. */
  .table, .table tbody { display: block; border: 0; background: transparent; }
  .table thead { display: none; }
  .table tr { display: block; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .5rem .7rem; margin-bottom: .6rem; }
  /* The label sits in a fixed gutter on the left; the value flows normally beside it,
     however many parts it has (a name and a warning, a status and a badge). */
  .table td, .table tbody th { display: block; position: relative; padding: .22rem 0; border: 0; text-align: left; min-height: 1.6rem; }
  .table td[data-label] { padding-left: 6.6rem; }
  .table td[data-label]::before { content: attr(data-label); position: absolute; left: 0; top: .3rem; width: 6.1rem; color: var(--muted); font-size: .88rem; line-height: 1.3; }
  .table td .pill { margin: .1rem 0; }
  .table td.cell-empty { display: none; }
  .table tbody th, .table tfoot th { font-weight: 700; }
  /* Tables of numbers: long names, short values. */
  .numbers td[data-label] { padding-left: 68%; }
  .numbers td[data-label]::before { width: 66%; }
  .numbers tfoot th, .numbers tfoot td { border-top: 0; }
  .field-check { flex-wrap: wrap; }
  .field-check small { flex: 1 1 100%; }
  .table td:empty { display: none; }
  .table tr.note-row { margin-top: -.6rem; border-top: 0; border-radius: 0 0 var(--radius) var(--radius); }
  .table tr.note-row td:empty { display: none; }
  .table tr:has(+ .note-row) { border-radius: var(--radius) var(--radius) 0 0; margin-bottom: 0; }
  .numbers td, .numbers thead th:not(:first-child) { text-align: left; }
  .table tfoot, .table tfoot tr { display: block; }

  /* The animal list: photo on the left, the rest beside it. */
  .table tr:has(> .photo-col) { display: grid; grid-template-columns: 52px 1fr; column-gap: .7rem; }
  .table tr:has(> .photo-col) > td { grid-column: 2; }
  /* In the animal list the name and breed speak for themselves: no labels on those. */
  .table tr:has(> .photo-col) > td:nth-child(2), .table tr:has(> .photo-col) > td:nth-child(3) { padding-left: 0; }
  .table tr:has(> .photo-col) > td:nth-child(2)::before, .table tr:has(> .photo-col) > td:nth-child(3)::before { content: none; }
  .table tr:has(> .photo-col) > td:nth-child(2) a { font-weight: 700; font-size: 1.1rem; }
  .table tr:has(> .photo-col) > .photo-col { grid-column: 1; grid-row: 1 / span 8; width: auto; padding: .2rem 0 0 !important; }
  .avatar-small img, .avatar-small .noimg { width: 48px; height: 48px; }

  .row-actions, .inline-edit form, .appointment-form, .document-details { flex-wrap: wrap; }
  .inline-edit input, .inline-edit select, .appointment-form input, .document-details input, .document-details select { width: 100%; max-width: none; }
  .photo-grid { grid-template-columns: repeat(2, 1fr); gap: .6rem; }
  .media-grid { grid-template-columns: repeat(2, 1fr); }
  .card-grid { grid-template-columns: 1fr; }
  .filters input { min-width: 0; }
  .login { margin-top: 5vh; }
  .login h1 { font-size: 2.2rem; }
  .pager { flex-wrap: wrap; }
  .exports { line-height: 2; }
}
