:root {
  --bg: #f7f5f0;
  --surface: #ffffff;
  --border: #e2ddd6;
  --text: #1a1814;
  --text-secondary: #6b6560;
  --muted: #9b9490;
  --green: #2d6a4f;
  --green-bg: #e8f4ef;
  --amber: #9a6a00;
  --amber-bg: #fdf3e0;
  --red: #a3352b;
  --red-bg: #fbe9e7;
  --blue: #1d4e89;
  --blue-bg: #e8f0fb;
  --purple: #6b2d6b;
  --purple-bg: #f5e8f5;
  --radius: 10px;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: var(--sans); background: var(--bg); color: var(--text); line-height: 1.5; }
a { color: var(--green); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Top bar */
.topbar {
  display: flex; align-items: center; gap: 24px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 12px 24px; position: sticky; top: 0; z-index: 10;
}
.brand {
  display: flex; align-items: center; gap: 9px;
  font-weight: 700; font-size: 18px; color: var(--text);
}
.brand:hover { text-decoration: none; }
.brand > span { white-space: nowrap; }
.brand-mark { height: 34px; width: auto; display: block; flex-shrink: 0; }
.topbar nav { display: flex; flex-wrap: wrap; gap: 4px; }
/* Labels never break mid-name; on a narrow window whole links wrap instead. */
.topbar nav a {
  padding: 6px 12px; border-radius: 8px; color: var(--text-secondary); font-weight: 500;
  white-space: nowrap;
}
.topbar nav a:hover { background: var(--bg); text-decoration: none; }
.topbar nav a.active { background: var(--green-bg); color: var(--green); }
.topbar .user { margin-left: auto; white-space: nowrap; display: flex; align-items: center; gap: 12px; font-size: 14px; color: var(--text-secondary); }
.logout { color: var(--muted); font-size: 13px; }

.container { max-width: 1100px; margin: 0 auto; padding: 28px 24px 64px; }

h1 { font-size: 26px; font-weight: 600; letter-spacing: -0.01em; margin-bottom: 4px; }
h2 { font-size: 18px; font-weight: 600; margin: 24px 0 12px; }
.subtitle { color: var(--text-secondary); margin-bottom: 20px; }

/* Cards */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px;
}
.grid { display: grid; gap: 16px; }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 800px) { .grid.cols-4 { grid-template-columns: repeat(2,1fr);} .grid.cols-2{grid-template-columns:1fr;} }

.stat { text-align: left; }
.stat .num { font-size: 34px; font-weight: 700; color: var(--green); line-height: 1; }
.stat .label { color: var(--text-secondary); font-size: 13px; margin-top: 8px; }
.stat.hero { display: flex; align-items: center; flex-wrap: wrap; gap: 18px 36px; margin-bottom: 16px; }
.stat.hero .hero-figure { display: flex; align-items: baseline; gap: 12px; }
.stat.hero .num { font-size: 56px; }
.stat.hero .label { margin-top: 0; font-size: 15px; color: var(--text); }
.stat.hero .btn { margin-left: auto; }

/* Buttons */
.btn {
  display: inline-block; background: var(--green); color: #fff; border: none;
  padding: 9px 16px; border-radius: 8px; font-size: 14px; font-weight: 500;
  cursor: pointer; font-family: inherit;
}
.btn:hover { background: #245a42; text-decoration: none; }
.btn.secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn.secondary:hover { background: var(--bg); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.danger { background: var(--red); }

/* Tables */
table { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border); }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--border); font-size: 14px; }
th { background: #faf9f6; color: var(--text-secondary); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #fafaf8; }

/* Badges */
.badge { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; }
.badge.green { background: var(--green-bg); color: var(--green); }
.badge.amber { background: var(--amber-bg); color: var(--amber); }
.badge.red { background: var(--red-bg); color: var(--red); }
.badge.blue { background: var(--blue-bg); color: var(--blue); }
.badge.purple { background: var(--purple-bg); color: var(--purple); }
.badge.grey { background: #eceae6; color: var(--text-secondary); }
/* A badge used as a filter link/button reads as a pill, not text. */
a.badge:hover { text-decoration: none; filter: brightness(0.97); }

/* Forms */
label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 4px; color: var(--text-secondary); }
input, select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px;
  font-family: inherit; font-size: 14px; background: var(--surface); color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--green-bg); border-color: var(--green); }
.field { margin-bottom: 14px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row .field { flex: 1; min-width: 160px; }

/* Filters */
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; margin-bottom: 18px; }
.filters .field { margin-bottom: 0; }

/* To-do list */
.todo { display: flex; align-items: center; gap: 14px; padding: 12px 16px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); margin-bottom: 8px; }
.todo.snoozed { opacity: 0.5; }
.todo .desc { flex: 1; }
.todo .desc strong { display: block; }
.todo .meta { font-size: 12px; color: var(--muted); }
.todo .actions { display: flex; gap: 6px; }

/* Login */
.login-wrap { max-width: 360px; margin: 10vh auto; }
.login-wrap .card { padding: 28px; }
.login-wrap h1 { text-align: center; }
.login-mark { display: block; width: 190px; max-width: 100%; margin: 0 auto 4px; }

/* Available to assistive technology, but not shown. */
.visually-hidden {
  position: absolute; width: 1px; height: 1px; margin: -1px;
  padding: 0; border: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}
.error { background: var(--red-bg); color: var(--red); padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; font-size: 14px; }
.notice { background: var(--blue-bg); color: var(--blue); padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; font-size: 14px; }

.timeline { list-style: none; }
.timeline li { padding: 10px 0 10px 18px; border-left: 2px solid var(--border); position: relative; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: 15px; width: 10px; height: 10px; border-radius: 50%; background: var(--green); }
.timeline .when { font-size: 12px; color: var(--muted); }
.event-type { font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-secondary); font-weight: 600; }

.muted { color: var(--muted); }
.pill-row { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0 16px; }
details.action-form { border: 1px solid var(--border); border-radius: 10px; margin-bottom: 8px; background: var(--surface); }
details.action-form summary { padding: 12px 16px; cursor: pointer; font-weight: 500; }
details.action-form .body { padding: 0 16px 16px; }
/* Existing-or-new person picker (foster carers, adopters).
   The name/contact panel is revealed only when "+ Add new…" is selected. */
.new-person {
  border-left: 2px solid var(--green); background: var(--green-bg);
  border-radius: 0 8px 8px 0; padding: 12px 14px; margin-bottom: 14px;
}
.new-person[hidden] { display: none; }
.new-person .field:last-child { margin-bottom: 0; }
.new-person .row .field { margin-bottom: 0; }

/* Donut charts. */
.pie-wrap { display: flex; align-items: center; gap: 22px; flex-wrap: wrap; }
.pie { width: 168px; height: 168px; flex: 0 0 auto; }
.pie .seg { transition: stroke-width 0.12s ease; }
.pie .seg:hover { stroke-width: 8; }
.pie-total {
  font-size: 7px; font-weight: 700; fill: var(--text);
  text-anchor: middle; font-family: var(--sans);
}
.pie-total-label {
  font-size: 2.6px; fill: var(--text-secondary);
  text-anchor: middle; font-family: var(--sans);
  text-transform: uppercase; letter-spacing: 0.08em;
}
.pie-legend { list-style: none; flex: 1; min-width: 170px; display: grid; gap: 7px; }
.pie-legend li { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.pie-legend .swatch {
  width: 11px; height: 11px; border-radius: 3px; flex: 0 0 auto;
}
.pie-legend .legend-label { flex: 1; color: var(--text-secondary); }
.pie-legend .legend-n { font-weight: 700; font-variant-numeric: tabular-nums; }
.pie-legend .legend-pct { font-size: 12px; width: 34px; text-align: right; }

/* Cats in and out, per period: two bars to a period on one shared scale. */
.flow-key {
  display: flex; gap: 16px; margin-bottom: 14px;
  font-size: 13px; color: var(--text-secondary);
}
.flow-key .swatch {
  display: inline-block; width: 11px; height: 11px; border-radius: 3px;
  margin-right: 5px; vertical-align: -1px;
}
.flow-key .swatch.in, .flow-bars .bar.in { background: var(--green); }
.flow-key .swatch.out, .flow-bars .bar.out { background: var(--blue); }

.flow-bars { list-style: none; display: grid; gap: 12px; }
.flow-bars li {
  display: grid; grid-template-columns: 62px minmax(0, 1fr);
  align-items: center; gap: 10px;
}
.flow-bars .period {
  font-size: 13px; color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}
.flow-bars .pair { display: grid; gap: 3px; }
.flow-bars .row {
  display: grid; grid-template-columns: minmax(0, 1fr) 34px;
  align-items: center; gap: 10px;
}
/* The bar sits in a track of its own so its width reads as a share of the
   busiest period, not of whatever space the row happens to have. */
.flow-bars .track { max-width: 640px; }
.flow-bars .bar {
  display: block; height: 13px; min-width: 2px; border-radius: 3px;
}
/* A period with none of one kind should show nothing, not a stub that reads
   as a small count. */
.flow-bars .bar.zero { min-width: 0; }
.flow-bars .n {
  font-size: 13px; font-weight: 600; color: var(--text);
  font-variant-numeric: tabular-nums;
}

/* Sortable column header. */
.sort-link { color: inherit; text-decoration: none; white-space: nowrap; }
.sort-link:hover { color: var(--green); text-decoration: none; }
.sort-link.active { color: var(--green); }

/* Cat photo. Until photos are stored, the card holds their place so the row
   does not reflow when they arrive. */
.photo-card { display: flex; padding: 0; overflow: hidden; }
.photo-card img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-empty {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 8px; min-height: 240px;
  background: #faf9f6; border-radius: var(--radius);
}
.photo-mark { font-size: 40px; line-height: 1; opacity: 0.35; }

/* Custody banner: whose care a cat is in, at the top of its page. */
.custody {
  display: flex; align-items: center; gap: 14px;
  border: 1px solid var(--border); border-left-width: 4px;
  border-radius: 10px; padding: 12px 16px; margin-bottom: 18px;
}
.custody-mark { font-size: 22px; line-height: 1; }
.custody-label {
  display: block; font-size: 12px; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--text-secondary); margin-bottom: 2px;
}
.custody strong { font-size: 17px; font-weight: 600; }
/* Extra context under the name, e.g. the adoption event a cat went home from. */
.custody-sub { display: block; font-size: 13px; color: var(--text-secondary); margin-top: 2px; }
.custody-contact {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 16px;
  font-size: 13px; color: var(--text-secondary); margin-top: 4px;
}
.custody.fostered { border-left-color: var(--blue); background: var(--blue-bg); }
.custody.fostered .custody-label { color: var(--blue); }
.custody.adopted { border-left-color: var(--green); background: var(--green-bg); }
.custody.adopted .custody-label { color: var(--green); }
.custody.memorial { border-left-color: var(--muted); background: #f4f2ef; }
.custody.left-care { border-left-color: var(--amber); background: var(--amber-bg); }
.custody.left-care .custody-label { color: var(--amber); }

/* Inline rename on the cat detail heading. */
.name-edit .name-display[hidden], .name-edit .name-form[hidden] { display: none; }
.pencil {
  background: none; border: none; padding: 0 0 0 4px; cursor: pointer;
  font-size: 16px; line-height: 1; vertical-align: middle;
  /* Mostly transparent so it does not compete with the name, but not fully
     invisible — an affordance nobody can see is one nobody uses. */
  opacity: 0.25;
  transition: opacity 0.15s ease;
}
.name-display:hover .pencil, .pencil:focus-visible { opacity: 0.7; }
.pencil:hover { opacity: 1; }
.name-form { display: flex; gap: 8px; align-items: center; }
.name-form input {
  width: auto; min-width: 260px; font-size: 22px; font-weight: 600;
  padding: 4px 8px;
}

/* Record death — irreversible, so it reads as a distinct danger zone. */
details.danger-form { border-color: #eccdc9; }
details.danger-form summary { color: var(--red); }
.confirm-step {
  border: 1px solid #eccdc9; background: var(--red-bg); color: var(--red);
  border-radius: 8px; padding: 12px 14px; margin-top: 12px;
}
.confirm-step[hidden] { display: none; }
.confirm-step p { margin-bottom: 10px; font-size: 14px; }
.confirm-actions { display: flex; gap: 8px; }

.readiness { display: flex; gap: 8px; align-items: center; }
/* The subjective check is a judgement, not a medical fact; a rule separates
   it from the four clinical criteria above. */
.readiness.subjective {
  margin-top: 8px; padding-top: 10px; border-top: 1px solid var(--border);
}
.check { color: var(--green); } .cross { color: var(--red); }
.section-actions { display: flex; justify-content: space-between; align-items: center; }

/* Fosters & adoption events: a stack of cards, one per person/event. */
.people { display: grid; gap: 12px; margin-top: 16px; }
.people h2 { margin: 0 0 8px; }
.people details.action-form { margin: 14px 0 0; }
.contact { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; font-size: 14px; }
.contact dt { color: var(--text-secondary); }
.multiline { white-space: pre-line; }
/* Foster card: who they are on the left, the cats in their care on the right. */
.person-cols { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; }
.foster-cats { border-left: 1px solid var(--border); padding-left: 20px; }
.foster-cats ul { list-style: none; display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 6px; }
@media (max-width: 640px) {
  .person-cols { grid-template-columns: 1fr; gap: 12px; }
  .foster-cats { border-left: none; padding-left: 0; }
}
.event-when { font-size: 13px; font-weight: 600; color: var(--green); margin-bottom: 2px; }
.event-venue { color: var(--text-secondary); margin-bottom: 8px; }
/* "Adopted here" sits inside the card, not in a side column. */
.event-adoptions { border-left: none; padding-left: 0; margin-top: 10px; }
/* Past events stay readable but step back from what's coming up. */
.past-events .event-when { color: var(--text-secondary); }

/* Dashboard: the next adoption event, as a one-line strip above the charts. */
.next-event { display: flex; align-items: center; gap: 14px; margin-bottom: 16px; padding: 14px 20px; }
.next-event-mark { font-size: 22px; line-height: 1; }
.next-event-body { flex: 1; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.next-event-body strong { font-size: 16px; }
/* Adopter page: one cat per line, with when/where it went home. */
.foster-cats ul.adopted-list { flex-direction: column; gap: 4px; }
/* Names in the custody banner link to the person's page but read as a name. */
.custody strong a { color: inherit; }

/* Vetting history: each row is also where that treatment is logged. */
.vet-head, .vet-row summary {
  display: grid; grid-template-columns: 1.1fr 1.4fr 1.4fr auto; gap: 12px; align-items: center;
}
.vet-head {
  padding: 0 10px 8px; color: var(--text-secondary); font-size: 12px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.04em; border-bottom: 1px solid var(--border);
}
.vet-row { border-bottom: 1px solid var(--border); }
.vet-row summary { padding: 10px; cursor: pointer; list-style: none; border-radius: 8px; }
.vet-row summary::-webkit-details-marker { display: none; }
.vet-row summary:hover { background: #faf9f6; }
.vet-row[open] summary { background: #faf9f6; }
.vet-label { font-weight: 600; }
.vet-given .muted, .vet-due .muted { font-size: 13px; margin-left: 4px; }
.vet-log {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px;
  border: 1px solid var(--border); border-radius: 99px; background: var(--surface);
  font-size: 13px; font-weight: 600; color: var(--green); white-space: nowrap;
}
.vet-row summary:hover .vet-log { border-color: var(--green); }
.vet-log .chevron { display: inline-block; transition: transform 0.15s ease; }
.vet-row[open] .vet-log { border-color: var(--green); background: var(--green-bg); }
.vet-row[open] .vet-log .chevron { transform: rotate(180deg); }
.vet-form { padding: 6px 10px 4px; }
.vet-form .field.result { flex: 2; min-width: 300px; }
.choice-pills { display: flex; gap: 6px; flex-wrap: wrap; }
.choice-pills label {
  display: inline-flex; align-items: center; gap: 6px; margin: 0; padding: 6px 12px;
  border: 1px solid var(--border); border-radius: 99px; cursor: pointer;
  font-size: 13px; color: var(--text);
}
.choice-pills label:has(input:checked) { border-color: var(--green); background: var(--green-bg); color: var(--green); }
@media (max-width: 600px) {
  .vet-head { display: none; }
  .vet-row summary { grid-template-columns: 1fr auto; }
  .vet-label { grid-column: 1; }
  .vet-log { grid-column: 2; grid-row: 1; }
  .vet-given, .vet-due { grid-column: 1 / -1; font-size: 13px; }
  .vet-given::before { content: "Last given: "; color: var(--text-secondary); }
  .vet-due::before { content: "Next due: "; color: var(--text-secondary); }
}

/* Vet planner: one card per cat, everything due in the window. */
.planner-summary { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.planner-bucket { margin-bottom: 8px; }
.planner-cat { display: grid; grid-template-columns: minmax(180px, 1fr) 2fr; gap: 16px; padding: 14px 18px; margin-bottom: 8px; }
.planner-who { display: flex; flex-direction: column; gap: 2px; }
.planner-who .muted { font-size: 13px; }
.planner-items { list-style: none; display: flex; flex-direction: column; gap: 6px; margin: 0; }
.planner-items li { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.planner-what { min-width: 140px; font-weight: 500; }
.planner-items .muted { font-size: 13px; }
.planner-empty { margin: 4px 0 12px; }
@media (max-width: 600px) { .planner-cat { grid-template-columns: 1fr; gap: 8px; } }
.vet-summary { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; padding: 14px 20px; }
.vet-summary a { color: var(--text); }
.vet-summary a.overdue { color: var(--red); }
.vet-summary .btn { margin-left: auto; }
