/* Equiplatform interface. Colours are design tokens: the platform's defaults are
   below, and an organisation's brand replaces the --l-* (light) and --d-* (dark)
   values at run time (see js/theme.js). */

:root {
  --l-bg: #f8f8f6; --l-surface: #ffffff; --l-surface-sunken: #f3f3f0;
  --l-text: #1d1f21; --l-text-muted: #5f6368; --l-line: #ebebe7; --l-line-strong: #d4d4cf;
  --l-danger: #b42318; --l-success: #1d7a43; --l-warning: #8a5a00;
  --l-brand: #2f5d50; --l-brand-contrast: #ffffff; --l-brand-text: #2f5d50; --l-brand-soft: #e4ebe9;
  --l-accent: #b5893b; --l-accent-contrast: #000000; --l-accent-text: #8a6527; --l-accent-soft: #f5eee3;
  --l-focus: #2f5d50;

  --d-bg: #141516; --d-surface: #1c1d1f; --d-surface-sunken: #101112;
  --d-text: #ececea; --d-text-muted: #a3a5a9; --d-line: #2c2d30; --d-line-strong: #44464a;
  --d-danger: #ff8a80; --d-success: #6fd39a; --d-warning: #f2c162;
  --d-brand: #5f9584; --d-brand-contrast: #000000; --d-brand-text: #7fb3a2; --d-brand-soft: #1f2a27;
  --d-accent: #b5893b; --d-accent-contrast: #000000; --d-accent-text: #d1a95f; --d-accent-soft: #2a2419;
  --d-focus: #7fb3a2;

  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --radius: 10px;
  --radius-small: 7px;
  --shadow: 0 1px 2px rgb(16 24 16 / 0.04), 0 1px 1px rgb(16 24 16 / 0.03);
  --shadow-raised: 0 10px 30px rgb(16 24 16 / 0.10), 0 2px 6px rgb(16 24 16 / 0.06);
  --sidebar: 232px;
  --gutter: 16px;
  --tabbar: 60px;
  color-scheme: light dark;
}

:root, :root[data-theme="light"] {
  --bg: var(--l-bg); --surface: var(--l-surface); --surface-sunken: var(--l-surface-sunken);
  --text: var(--l-text); --text-muted: var(--l-text-muted); --line: var(--l-line);
  --line-strong: var(--l-line-strong); --danger: var(--l-danger); --success: var(--l-success);
  --warning: var(--l-warning); --brand: var(--l-brand); --brand-contrast: var(--l-brand-contrast);
  --brand-text: var(--l-brand-text); --brand-soft: var(--l-brand-soft); --accent: var(--l-accent);
  --accent-contrast: var(--l-accent-contrast); --accent-text: var(--l-accent-text);
  --accent-soft: var(--l-accent-soft); --focus: var(--l-focus);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: var(--d-bg); --surface: var(--d-surface); --surface-sunken: var(--d-surface-sunken);
    --text: var(--d-text); --text-muted: var(--d-text-muted); --line: var(--d-line);
    --line-strong: var(--d-line-strong); --danger: var(--d-danger); --success: var(--d-success);
    --warning: var(--d-warning); --brand: var(--d-brand); --brand-contrast: var(--d-brand-contrast);
    --brand-text: var(--d-brand-text); --brand-soft: var(--d-brand-soft); --accent: var(--d-accent);
    --accent-contrast: var(--d-accent-contrast); --accent-text: var(--d-accent-text);
    --accent-soft: var(--d-accent-soft); --focus: var(--d-focus);
  }
}

:root[data-theme="dark"] {
  --bg: var(--d-bg); --surface: var(--d-surface); --surface-sunken: var(--d-surface-sunken);
  --text: var(--d-text); --text-muted: var(--d-text-muted); --line: var(--d-line);
  --line-strong: var(--d-line-strong); --danger: var(--d-danger); --success: var(--d-success);
  --warning: var(--d-warning); --brand: var(--d-brand); --brand-contrast: var(--d-brand-contrast);
  --brand-text: var(--d-brand-text); --brand-soft: var(--d-brand-soft); --accent: var(--d-accent);
  --accent-contrast: var(--d-accent-contrast); --accent-text: var(--d-accent-text);
  --accent-soft: var(--d-accent-soft); --focus: var(--d-focus);
}

/* ---------- Base ---------- */

*, *::before, *::after { box-sizing: border-box; }
/* Hidden means hidden, whatever display a class gives */
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 var(--font); -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { line-height: 1.25; margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 1.6rem; letter-spacing: -0.02em; }
h2 { font-size: 1.05rem; }
h3 { font-size: 0.95rem; }
p { margin: 0 0 0.75rem; }
a { color: var(--brand-text); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.muted { color: var(--text-muted); }
.small { font-size: 0.85rem; }
.nowrap { white-space: nowrap; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap;
}
.icon { width: 20px; height: 20px; flex: none; stroke: currentColor; fill: none;
  stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Shell ---------- */

.shell { min-height: 100vh; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar); display: flex; flex-direction: column;
  border-right: 1px solid var(--line); background: var(--bg); padding: 16px 12px;
}
.brand-mark { display: flex; align-items: center; gap: 10px; padding: 4px 8px 16px; min-height: 44px; }
.brand-mark img { max-height: 32px; max-width: 120px; object-fit: contain; }
.brand-mark .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--radius-small);
  color: var(--text-muted); font-weight: 500;
}
.nav a:hover { background: var(--surface-sunken); color: var(--text); text-decoration: none; }
.nav a[aria-current="page"] { background: var(--brand-soft); color: var(--brand-text); }
.nav .group { margin: 16px 10px 4px; font-size: 0.75rem; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--text-muted); }
.sidebar .spacer { flex: 1; }
.who {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px; border: 0;
  background: none; color: inherit; font: inherit; text-align: left; border-radius: var(--radius-small);
  cursor: pointer;
}
.who:hover { background: var(--surface-sunken); }
.who .lines { min-width: 0; }
.who .lines div { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%; flex: none; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent-text); font-weight: 600; font-size: 0.8rem;
}
.main { margin-left: var(--sidebar); padding: 28px 32px 64px; }
.content { max-width: 1040px; margin: 0 auto; }
.topbar, .tabbar { display: none; }

@media (max-width: 899px) {
  .sidebar { display: none; }
  .main { margin-left: 0; padding: 16px var(--gutter) calc(var(--tabbar) + 32px + env(safe-area-inset-bottom)); }
  body { font-size: 16px; }
  .topbar {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    position: sticky; top: 0; z-index: 5; padding: 8px var(--gutter); min-height: 52px;
    background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--line);
  }
  .topbar .brand-mark { padding: 0; min-height: 0; }
  .tabbar {
    display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; position: fixed; inset: auto 0 0 0;
    z-index: 5; height: calc(var(--tabbar) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom); background: var(--surface);
    border-top: 1px solid var(--line);
  }
  .tabbar a, .tabbar button {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    color: var(--text-muted); font: 500 0.7rem var(--font); border: 0; background: none; cursor: pointer;
  }
  .tabbar a[aria-current="page"] { color: var(--brand-text); }
  .tabbar a:hover { text-decoration: none; }
}

/* ---------- Page header and contextual actions ---------- */

.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px;
  margin-bottom: 24px; flex-wrap: wrap; }
.page-head .titles { min-width: 0; }
.page-head .eyebrow { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 4px; }
.page-head .eyebrow a { color: inherit; }
.page-head .sub { color: var(--text-muted); margin-top: 4px; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
@media (max-width: 599px) {
  .page-head .actions .secondary-action { display: none; }
}

/* ---------- Controls ---------- */

/* Buttons. Each is made by button() in ui.js and has one kind, named for its
   purpose; each kind's colours are set here and nowhere else. Places that hold
   buttons may only make them .small. The bulk bar, a dark surface, is the one place
   that swaps the colours, and it does so through the same variables. */
.button {
  --btn-bg: var(--surface); --btn-fg: var(--text); --btn-line: var(--line-strong); --btn-hover: var(--surface-sunken);
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 36px;
  padding: 0 14px; border-radius: var(--radius-small); border: 1px solid var(--btn-line);
  background: var(--btn-bg); color: var(--btn-fg); font: 550 0.9rem var(--font); cursor: pointer;
  white-space: nowrap; text-decoration: none;
}
.button:hover { background: var(--btn-hover); text-decoration: none; }
.button.action { --btn-fg: var(--brand-text); --btn-line: color-mix(in srgb, var(--brand) 55%, var(--line-strong)); --btn-hover: var(--brand-soft); font-weight: 600; }
.button.action:hover { border-color: var(--brand); }
.button.confirm { --btn-bg: var(--brand); --btn-fg: var(--brand-contrast); --btn-line: var(--brand);
  --btn-hover: color-mix(in srgb, var(--brand) 88%, black); box-shadow: 0 1px 2px rgb(16 24 16 / 0.15); }
.button.danger { --btn-fg: var(--danger); --btn-line: color-mix(in srgb, var(--danger) 40%, var(--line-strong));
  --btn-hover: color-mix(in srgb, var(--danger) 8%, var(--surface)); }
.button.ghost { --btn-bg: transparent; --btn-line: transparent; }
.button.square { width: 36px; padding: 0; }
.button.small { min-height: 32px; height: 32px; padding: 0 10px; font-size: 0.85rem; }
.button.small.square { width: 32px; padding: 0; }
.button.block { width: 100%; }
.button .icon { width: 18px; height: 18px; }
.button.small .icon { width: 16px; height: 16px; }
.button:disabled { opacity: 0.55; cursor: default; }
@media (max-width: 899px) {
  .button { min-height: 44px; } .button.square { width: 44px; }
  .button.small { min-height: 40px; height: 40px; } .button.small.square { width: 40px; }
}

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field label { font-weight: 500; font-size: 0.9rem; }
.field .hint { color: var(--text-muted); font-size: 0.82rem; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: var(--radius-small); padding: 8px 10px; min-height: 38px; width: 100%;
}
textarea { min-height: 80px; resize: vertical; }
input[type="color"] { padding: 2px; width: 52px; }
input[type="checkbox"] { width: auto; min-height: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--focus); outline-offset: -1px; }
.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 0 16px; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; flex-wrap: wrap; }
.error-box {
  border: 1px solid color-mix(in srgb, var(--danger) 40%, transparent); color: var(--danger);
  background: color-mix(in srgb, var(--danger) 8%, transparent); border-radius: var(--radius-small);
  padding: 10px 12px; margin-bottom: 16px;
}
.error-box ul { margin: 6px 0 0; padding-left: 18px; }
.notice { border: 1px solid var(--line); background: var(--surface-sunken); border-radius: var(--radius-small);
  padding: 10px 12px; margin-bottom: 16px; }

/* ---------- Surfaces ---------- */

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 20px; }
.card + .card, .section + .section { margin-top: 16px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px 20px; border-bottom: 1px solid var(--line); }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.grid-2 { display: grid; gap: 16px; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
@media (max-width: 899px) { .grid-2 { grid-template-columns: minmax(0, 1fr); } }
.stat .value { font-size: 1.75rem; font-weight: 600; letter-spacing: -0.02em; }
.stat .label { color: var(--text-muted); font-size: 0.85rem; }

.list { list-style: none; margin: 0; padding: 0; }
.list > li { border-top: 1px solid var(--line); }
.list > li:first-child { border-top: 0; }
.list-row { display: flex; align-items: center; gap: 12px; padding: 12px 20px; color: inherit; min-height: 56px; }
button.list-row { width: 100%; border: 0; background: none; font: inherit; text-align: left; cursor: pointer; }
label.list-row { cursor: pointer; }
a.list-row:hover, button.list-row:hover { background: var(--surface-sunken); text-decoration: none; }
.list-row .grow { flex: 1; min-width: 0; }
.list-row .title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-row .meta { color: var(--text-muted); font-size: 0.85rem; }
.chev { color: var(--text-muted); }

.dl { display: grid; grid-template-columns: minmax(120px, 180px) 1fr; gap: 10px 16px; margin: 0; }
.dl dt { color: var(--text-muted); }
.dl dd { margin: 0; overflow-wrap: anywhere; }
@media (max-width: 599px) { .dl { grid-template-columns: 1fr; gap: 2px; } .dl dd { margin-bottom: 10px; } }

.badge { display: inline-flex; align-items: center; height: 22px; padding: 0 8px; border-radius: 11px;
  font-size: 0.75rem; font-weight: 500; background: var(--surface-sunken); color: var(--text-muted);
  border: 1px solid var(--line); white-space: nowrap; }
.badge.brand { background: var(--brand-soft); color: var(--brand-text); border-color: transparent; }
.badge.warn { color: var(--warning); }
.badge.danger { color: var(--danger); border-color: currentColor; }
.badges { display: flex; gap: 6px; flex-wrap: wrap; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 20px; overflow-x: auto; }
.tabs a { display: inline-flex; align-items: center; gap: 6px; padding: 10px 12px; color: var(--text-muted); font-weight: 500;
  border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs .icon { width: 16px; height: 16px; }
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a[aria-current="page"] { color: var(--text); border-bottom-color: var(--brand); }

.empty { text-align: center; padding: 40px 20px; color: var(--text-muted); }
.empty .icon { width: 28px; height: 28px; margin-bottom: 8px; }
.empty h3 { color: var(--text); margin-bottom: 4px; }

.search { position: relative; }
.search .icon { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--text-muted); width: 18px; height: 18px; }
.search input { padding-left: 34px; }
.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar > .search { flex: 1; min-width: 200px; }
.toolbar select { width: auto; }
.toolbar input[type="date"] { width: auto; }
/* Newer and older pages of a long list */
.pager { display: flex; gap: 8px; justify-content: center; margin-top: 16px; }
.pager:empty { display: none; }

/* ---------- Yard board ---------- */

.board-block + .board-block { margin-top: 24px; }
.board-block h3 { margin-bottom: 10px; color: var(--text-muted); font-weight: 500; }
.boxes { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.box { border: 1px solid var(--line); border-radius: var(--radius-small); padding: 10px 12px;
  background: var(--surface); min-height: 64px; display: flex; flex-direction: column; gap: 2px; color: inherit; }
a.box:hover { border-color: var(--line-strong); text-decoration: none; }
.box .box-name { font-size: 0.78rem; color: var(--text-muted); }
.box .box-horse { font-weight: 500; }
.box.empty-box { background: var(--surface-sunken); border-style: dashed; }
.box.empty-box .box-horse { color: var(--text-muted); font-weight: 400; }

/* ---------- Timeline (care log) ---------- */

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: grid; grid-template-columns: 64px 1fr auto; gap: 12px; padding: 12px 20px;
  border-top: 1px solid var(--line); align-items: start; }
.timeline li:first-child { border-top: 0; }
.timeline .time { color: var(--text-muted); font-variant-numeric: tabular-nums; font-size: 0.85rem; padding-top: 1px; }
.timeline .voided .what { text-decoration: line-through; color: var(--text-muted); }
@media (max-width: 599px) { .timeline li { grid-template-columns: 52px 1fr; } .timeline li > :last-child { grid-column: 2; } }

.quick { display: flex; gap: 8px; flex-wrap: wrap; }
.quick .button { min-height: 40px; }

/* ---------- Menus, dialogs and toasts ---------- */

.menu-wrap { position: relative; }
.menu {
  position: absolute; right: 0; top: calc(100% + 4px); z-index: 20; min-width: 200px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.12); padding: 4px;
}
.menu.up { top: auto; bottom: calc(100% + 4px); left: 0; right: auto; }
.menu button, .menu a {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border: 0; background: none;
  font: inherit; color: var(--text); text-align: left; border-radius: var(--radius-small); cursor: pointer;
}
.menu button:hover, .menu a:hover { background: var(--surface-sunken); text-decoration: none; }
.menu .sep { height: 1px; background: var(--line); margin: 4px 0; }
.menu .label { padding: 6px 10px 2px; font-size: 0.75rem; color: var(--text-muted); }
.menu .check { margin-left: auto; color: var(--brand-text); }
.menu button > .icon { width: 18px; height: 18px; color: var(--text-muted); }

dialog {
  border: 1px solid var(--line); border-radius: 12px; padding: 0; background: var(--surface); color: var(--text);
  width: min(520px, calc(100vw - 32px)); max-height: calc(100vh - 48px); box-shadow: 0 20px 48px rgb(0 0 0 / 0.2);
}
.field.read-only input, .field.read-only select, .field.read-only textarea { background: var(--surface-sunken); color: var(--text-muted); cursor: not-allowed; }
.field .read-only-mark { display: inline-flex; vertical-align: -3px; margin-left: 6px; color: var(--text-muted); }
.field .read-only-mark .icon { width: 14px; height: 14px; }
dialog.wide { width: min(860px, calc(100vw - 32px)); }
dialog::backdrop { background: rgb(0 0 0 / 0.35); }
dialog .dialog-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--line); }
dialog .dialog-body { padding: 20px; overflow-y: auto; max-height: calc(100vh - 140px); }
@media (max-width: 599px) {
  dialog, dialog.wide { width: 100vw; max-width: 100vw; margin: auto 0 0; border-radius: 14px 14px 0 0; max-height: 90vh; }
}
.sheet .menu-like button, .sheet .menu-like a {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 12px 4px; border: 0; background: none;
  font: inherit; color: var(--text); border-bottom: 1px solid var(--line); text-align: left; cursor: pointer;
}

.toasts { position: fixed; z-index: 50; left: 50%; transform: translateX(-50%); bottom: 24px; display: flex;
  flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
@media (max-width: 899px) { .toasts { bottom: calc(var(--tabbar) + 16px + env(safe-area-inset-bottom)); } }
.toast { background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: var(--radius); font-size: 0.9rem;
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.2); }
.toast.bad { background: var(--danger); color: #fff; }

/* ---------- Sign-in pages ---------- */

.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px var(--gutter); }
.auth-card { width: min(400px, 100%); }
.auth-card .brand-mark { justify-content: center; padding-bottom: 24px; }
.auth-card h1 { font-size: 1.35rem; margin-bottom: 6px; text-align: center; }
.auth-card .lead { text-align: center; color: var(--text-muted); margin-bottom: 24px; }
.auth-card .alt { text-align: center; margin-top: 16px; font-size: 0.9rem; }
.divider { display: flex; align-items: center; gap: 12px; color: var(--text-muted); font-size: 0.8rem; margin: 16px 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }

/* ---------- Charts ---------- */

.chart { width: 100%; height: auto; display: block; }
.chart .axis { stroke: var(--line-strong); stroke-width: 1; }
.chart .grid-line { stroke: var(--line); stroke-width: 1; }
.chart .tick { fill: var(--text-muted); font-size: 11px; }
.chart .series { fill: none; stroke: var(--brand); stroke-width: 2; }
.chart .point { fill: var(--surface); stroke: var(--brand); stroke-width: 2; }
.chart .point.high { stroke: var(--danger); fill: var(--danger); }
.chart .band { fill: var(--brand-soft); }
.chart .threshold { stroke: var(--danger); stroke-dasharray: 4 4; stroke-width: 1; }

/* ---------- Brand preview ---------- */

.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatch { width: 40px; height: 40px; border-radius: var(--radius-small); border: 1px solid var(--line); }
.logo-preview { max-height: 56px; max-width: 200px; object-fit: contain; }
.colour-field { display: flex; gap: 8px; align-items: center; }
.colour-field input[type="text"] { max-width: 120px; font-family: ui-monospace, monospace; }

.loading { padding: 40px; text-align: center; color: var(--text-muted); }
/* Shown on staging only (added by the server) */
.test-system {
  padding: 6px 16px; text-align: center; font-size: 0.85rem; font-weight: 600;
  color: var(--text); background: color-mix(in srgb, var(--warning) 22%, var(--bg));
  border-bottom: 1px solid color-mix(in srgb, var(--warning) 50%, transparent);
}

/* ---------- Small additions ---------- */

.phone-only-menu { display: none; }
@media (max-width: 599px) { .phone-only-menu { display: block; } .wide-only-menu { display: none; } }
fieldset.field { border: 0; padding: 0; margin: 0 0 16px; min-width: 0; }
fieldset.field legend { font-weight: 500; font-size: 0.9rem; margin-bottom: 6px; padding: 0; }
fieldset.field label.list-row { padding: 8px 0; min-height: 0; cursor: pointer; }
.form-actions.stretch .button { flex: 1; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.85em;
  background: var(--surface-sunken); padding: 2px 6px; border-radius: 4px; overflow-wrap: anywhere; }
.page-head .actions select, .page-head .actions input { width: auto; }

/* ---------- Feeding, temperatures and work ---------- */

.feed-time { width: 72px; flex: none; font-size: 0.85rem; padding-top: 1px; align-self: flex-start; }
.feed-row { margin-bottom: 12px; padding: 12px 16px 4px; }
.feed-row .field { margin-bottom: 10px; }
.feed-chart { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.table th, .table td { text-align: left; vertical-align: top; padding: 10px 14px; border-top: 1px solid var(--line); }
.table thead th { border-top: 0; color: var(--text-muted); font-weight: 500; font-size: 0.8rem;
  text-transform: uppercase; letter-spacing: 0.04em; white-space: nowrap; }
.table tbody th { font-weight: 500; white-space: nowrap; }
.table td div + div { margin-top: 4px; }
.segmented { display: inline-flex; border: 1px solid var(--line-strong); border-radius: var(--radius-small); overflow: hidden; }
.segmented a { padding: 4px 10px; font-size: 0.82rem; color: var(--text-muted); }
.segmented a + a { border-left: 1px solid var(--line-strong); }
.segmented a[aria-current="page"] { background: var(--brand-soft); color: var(--brand-text); font-weight: 500; }
.segmented a:hover { text-decoration: none; color: var(--text); }


/* ---------- Selection and bulk actions ---------- */

.check { width: 18px; height: 18px; min-height: 0; accent-color: var(--brand); cursor: pointer; flex: none; }
.list-row.selected { background: var(--brand-soft); }
.list-head { display: flex; align-items: center; gap: 12px; padding: 10px 20px; border-bottom: 1px solid var(--line);
  color: var(--text-muted); font-size: 0.85rem; }
.bulk-bar {
  position: sticky; bottom: 16px; z-index: 6; margin: 16px auto 0; width: fit-content; max-width: 100%;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 8px 8px 8px 16px;
  background: var(--text); color: var(--bg); border-radius: 999px; box-shadow: var(--shadow-raised);
}
.bulk-bar .button { --btn-bg: transparent; --btn-fg: inherit; --btn-line: color-mix(in srgb, var(--bg) 30%, transparent);
  --btn-hover: color-mix(in srgb, var(--bg) 14%, transparent); border-radius: 999px; }
.bulk-bar .count { font-weight: 600; margin-right: 4px; white-space: nowrap; }
@media (max-width: 899px) {
  .bulk-bar { bottom: calc(var(--tabbar) + 12px + env(safe-area-inset-bottom)); border-radius: 16px; }
}

/* ---------- Chips and comboboxes ---------- */

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 4px; height: 30px; padding: 0 12px; border-radius: 15px;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--text); font: 500 0.85rem var(--font);
  cursor: pointer; }
.chip:hover { border-color: var(--text-muted); }
.chip[aria-pressed="true"] { background: var(--brand-soft); border-color: var(--brand); color: var(--brand-text); }
.combo { position: relative; }
.combo-list { position: absolute; z-index: 30; left: 0; right: 0; top: calc(100% + 4px); max-height: 260px; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-raised);
  padding: 4px; }
.combo-list button { display: block; width: 100%; text-align: left; padding: 8px 10px; border: 0; background: none;
  font: inherit; color: var(--text); border-radius: var(--radius-small); cursor: pointer; }
.combo-list button[aria-selected="true"], .combo-list button:hover { background: var(--surface-sunken); }
.combo-list .add { color: var(--brand-text); font-weight: 500; }
.combo-list .meta { color: var(--text-muted); font-size: 0.82rem; }

/* ---------- Command palette ---------- */

dialog.palette { width: min(620px, calc(100vw - 24px)); margin: 12vh auto auto; }
.palette .dialog-body { padding: 0; }
.palette .palette-input { border: 0; border-bottom: 1px solid var(--line); border-radius: 0; font-size: 1.05rem;
  padding: 16px 20px; min-height: 56px; outline: none; }
.palette-results { list-style: none; margin: 0; padding: 6px; max-height: 50vh; overflow-y: auto; }
.palette-results li button { display: flex; align-items: center; gap: 12px; width: 100%; padding: 10px 12px; border: 0;
  background: none; font: inherit; color: var(--text); text-align: left; border-radius: var(--radius-small); cursor: pointer; }
.palette-results li button[aria-selected="true"] { background: var(--brand-soft); color: var(--brand-text); }
.palette-results .group { padding: 10px 12px 4px; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-muted); }
.palette-results .hint { margin-left: auto; color: var(--text-muted); font-size: 0.8rem; }
kbd { font: 500 0.75rem ui-monospace, SFMono-Regular, Menlo, monospace; padding: 2px 6px; border-radius: 5px;
  border: 1px solid var(--line-strong); border-bottom-width: 2px; background: var(--surface); color: var(--text-muted); }
.palette-foot { display: flex; gap: 16px; padding: 10px 16px; border-top: 1px solid var(--line); color: var(--text-muted);
  font-size: 0.8rem; flex-wrap: wrap; }
.search-trigger { display: flex; align-items: center; gap: 8px; width: 100%; margin: 0 0 12px; padding: 8px 10px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text-muted); border-radius: var(--radius-small);
  font: inherit; cursor: pointer; text-align: left; }
.search-trigger kbd { margin-left: auto; }
.search-trigger:hover { border-color: var(--line-strong); }

/* ---------- Profile sections ---------- */

.profile-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); align-items: start; }
.profile-grid .card + .card { margin-top: 0; }

/* ---------- Pedigree ---------- */

.pedigree { display: grid; grid-template-columns: repeat(var(--generations, 4), minmax(160px, 1fr)); gap: 6px 10px;
  overflow-x: auto; padding: 16px; }
.pedigree .slot { display: flex; flex-direction: column; justify-content: center; min-height: 52px; padding: 8px 10px;
  border-radius: var(--radius-small); border: 1px solid var(--line); background: var(--surface); color: inherit; }
.pedigree .slot.sire { border-left: 3px solid var(--brand); }
.pedigree .slot.dam { border-left: 3px solid var(--accent); }
.pedigree .slot.empty { border-style: dashed; background: var(--surface-sunken); color: var(--text-muted); cursor: pointer;
  font: inherit; text-align: left; }
.pedigree .slot.empty:hover { border-color: var(--line-strong); color: var(--text); }
.pedigree .slot.unknown { border-style: dashed; color: var(--text-muted); }
.pedigree .slot .name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pedigree .slot .meta { font-size: 0.78rem; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
a.slot:hover { border-color: var(--line-strong); text-decoration: none; }
.legend { display: flex; gap: 16px; font-size: 0.8rem; color: var(--text-muted); padding: 0 16px 12px; }
.legend span::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px;
  vertical-align: -1px; }
.legend .sire-key::before { background: var(--brand); }
.legend .dam-key::before { background: var(--accent); }

/* ---------- Coming up ---------- */

.date-badge { width: 44px; flex: none; text-align: center; border-radius: var(--radius-small); border: 1px solid var(--line);
  padding: 4px 0; line-height: 1.15; background: var(--surface); }
.date-badge .day { font-weight: 600; font-size: 1.05rem; }
.date-badge .month { font-size: 0.68rem; text-transform: uppercase; color: var(--text-muted); letter-spacing: 0.04em; }
.hint-line { color: var(--text-muted); font-size: 0.8rem; margin-top: 8px; }

/* Cards laid out in a grid are spaced by the grid, not stacked */
.grid > .card + .card, .grid-2 > .card + .card, .grid-2 > * > .card:first-child { margin-top: 0; }
.grid + .section, .section + .card { margin-top: 16px; }
.pedigree { grid-auto-rows: minmax(30px, auto); align-items: center; }
.pedigree .slot { align-self: center; min-height: 48px; }
.tabs { scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.pedigree .slot.last { min-height: 36px; padding: 4px 8px; }
.pedigree .slot.last .meta { display: none; }
.pedigree .slot-gap { min-height: 36px; }

/* ---------- Visual hierarchy (round 2) ---------- */

:root {
  --l-bg: #f3f3ef; --l-surface-sunken: #eeeee9; --l-line: #e2e2dc; --l-line-strong: #c8c8c1;
  --l-text: #17191b; --l-text-muted: #55595e;
}
h1 { font-size: 1.75rem; font-weight: 700; }
h2 { font-size: 1.08rem; font-weight: 650; }
.section-head { background: color-mix(in srgb, var(--surface-sunken) 45%, var(--surface)); border-radius: var(--radius) var(--radius) 0 0; }
.page-head { margin-bottom: 20px; }
.page-head .eyebrow { font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; font-size: 0.72rem; }

.list-row .title { font-weight: 550; }
.stat .value { font-weight: 700; color: var(--brand-text); }
.badge { color: var(--text); }

/* Row actions: quick icon buttons, then the "more" menu */
.row-actions { display: flex; align-items: center; gap: 2px; flex: none; }

/* Rounds: entering a value for every horse */
.round-table { width: 100%; border-collapse: collapse; }
.round-table th, .round-table td { padding: 10px 14px; border-top: 1px solid var(--line); text-align: left; vertical-align: middle; }
.round-table thead th { border-top: 0; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); font-weight: 600; }
.round-table input[type="number"] { max-width: 110px; }
.round-table td.flag { width: 1%; white-space: nowrap; }
.round-table tr.high td { background: color-mix(in srgb, var(--danger) 6%, transparent); }
.round-table .center { text-align: center; }
.round-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px; border-top: 1px solid var(--line); flex-wrap: wrap; }
@media (max-width: 599px) {
  .round-table thead { display: none; }
  .round-table tr { display: grid; grid-template-columns: 1fr auto; gap: 6px 10px; padding: 10px 14px; border-top: 1px solid var(--line); }
  .round-table td { border-top: 0; padding: 0; }
  .round-table td.notes-cell { grid-column: 1 / -1; }
}

/* Roles */
.permission-list { display: grid; gap: 4px; }
.permission-list label { display: flex; gap: 10px; align-items: flex-start; padding: 8px 10px; border-radius: var(--radius-small); cursor: pointer; }
.permission-list label:hover { background: var(--surface-sunken); }
.permission-list label.unavailable { opacity: 0.5; cursor: not-allowed; }
.permission-list .key { font-size: 0.78rem; color: var(--text-muted); font-family: ui-monospace, monospace; }

/* Wizard */
.wizard { max-width: 720px; margin: 0 auto; }
.steps { display: flex; gap: 6px; list-style: none; padding: 0; margin: 0 0 24px; counter-reset: step; flex-wrap: wrap; }
.steps li { flex: 1; min-width: 90px; counter-increment: step; font-size: 0.82rem; color: var(--text-muted); font-weight: 500; }
.steps li::before { content: counter(step); display: grid; place-items: center; width: 26px; height: 26px; border-radius: 50%;
  border: 2px solid var(--line-strong); margin-bottom: 6px; font-weight: 600; background: var(--surface); }
.steps li::after { content: ""; display: block; height: 3px; border-radius: 2px; background: var(--line); margin-top: 8px; }
.steps li.done, .steps li.current { color: var(--text); }
.steps li.done::before { background: var(--brand); border-color: var(--brand); color: var(--brand-contrast); content: "✓"; }
.steps li.current::before { border-color: var(--brand); color: var(--brand-text); }
.steps li.done::after, .steps li.current::after { background: var(--brand); }
.choice-grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
.choice { display: flex; flex-direction: column; gap: 4px; padding: 16px; text-align: left; border: 1.5px solid var(--line-strong);
  border-radius: var(--radius); background: var(--surface); color: var(--text); font: inherit; cursor: pointer; }
.choice:hover { border-color: var(--text-muted); }
.choice[aria-pressed="true"] { border-color: var(--brand); background: var(--brand-soft); box-shadow: inset 0 0 0 1px var(--brand); }
.choice .choice-title { font-weight: 650; }
.choice .choice-text { font-size: 0.85rem; color: var(--text-muted); }
.wizard-actions { display: flex; justify-content: space-between; gap: 8px; margin-top: 24px; }
.availability { font-size: 0.85rem; margin-top: -8px; margin-bottom: 12px; }
.availability.ok { color: var(--success); }
.availability.bad { color: var(--danger); }
.summary-list { display: grid; grid-template-columns: max-content 1fr; gap: 8px 20px; margin: 0; }
.summary-list dt { color: var(--text-muted); }
.summary-list dd { margin: 0; font-weight: 500; }
.empty-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 12px; }
.empty-actions.left { justify-content: flex-start; margin-top: 12px; }
@media (max-width: 599px) {
  .round-table.care-round thead { display: table-header-group; }
  .round-table.care-round tr { display: table-row; padding: 0; }
  .round-table.care-round td, .round-table.care-round th { padding: 8px; border-top: 1px solid var(--line); }
  .round-table.care-round thead th { border-top: 0; }
}
.care-round thead .button { font-size: 0.74rem; text-transform: none; letter-spacing: 0; padding: 0 6px; white-space: normal; line-height: 1.15; }

/* The organisation switcher, top left */
.org-switcher { display: flex; align-items: center; gap: 10px; width: 100%; padding: 6px 8px; margin-bottom: 12px;
  border: 1px solid transparent; background: none; color: inherit; font: inherit; text-align: left; cursor: pointer;
  border-radius: var(--radius-small); min-width: 0; }
.org-switcher:hover, .org-switcher[aria-expanded="true"] { background: var(--surface); border-color: var(--line); }
.org-switcher img { max-height: 32px; max-width: 72px; object-fit: contain; }
.org-switcher .lines { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.org-switcher .name { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.org-switcher .where { font-size: 0.78rem; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.org-switcher .chev.down { transform: rotate(90deg); color: var(--text-muted); }
.menu.left { left: 0; right: auto; }
.topbar .menu-wrap:first-child { flex: 1; min-width: 0; }
.topbar .org-switcher { margin-bottom: 0; padding: 4px 6px; }

/* Notifications (js/notifications.js) */
.bell-row { display: flex; align-items: center; gap: 10px; padding: 8px 10px; margin: -4px 0 12px; border-radius: var(--radius-small);
  color: var(--text); font-weight: 500; }
.bell-row:hover { background: var(--surface); text-decoration: none; }
.bell-row[aria-current="page"] { background: var(--surface); box-shadow: inset 0 0 0 1px var(--line); }
.count-badge { margin-left: auto; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--brand);
  color: var(--brand-contrast); font-size: 0.72rem; font-weight: 700; display: inline-grid; place-items: center; }
.button.bell { position: relative; }
.button.bell .count-badge { position: absolute; top: 2px; right: 0; min-width: 18px; height: 18px; font-size: 0.66rem; margin: 0; }
.notifications > .notification + .notification { border-top: 1px solid var(--line); }
.notification { display: flex; gap: 14px; padding: 14px 20px; align-items: flex-start; }
.notification.unread { background: color-mix(in srgb, var(--brand-soft) 45%, transparent); }
.notification.waiting { box-shadow: inset 3px 0 0 var(--brand); }
.notification-icon { width: 36px; height: 36px; flex: none; border-radius: 50%; display: grid; place-items: center;
  background: var(--brand-soft); color: var(--brand-text); }
.notification .title { font-weight: 600; }
.notification .meta { color: var(--text-muted); font-size: 0.82rem; margin-top: 4px; }
.notification-body { margin: 6px 0 0; padding-left: 18px; }
.notification-body li { margin: 2px 0; }
.notification-actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.notification-actions .acknowledged { display: inline-flex; align-items: center; gap: 4px; }
.notification-actions .acknowledged .icon { width: 16px; height: 16px; color: var(--success); }
.receipts { margin-top: 8px; }
.receipts summary { cursor: pointer; list-style: none; display: inline-flex; }
.receipts summary::-webkit-details-marker { display: none; }
.receipts ul { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 4px; }
.receipts li { display: flex; align-items: center; gap: 8px; font-size: 0.88rem; }
.receipts li .icon { width: 16px; height: 16px; color: var(--text-muted); }
@media (max-width: 599px) {
  .notification { flex-wrap: wrap; padding: 12px 16px; }
  .notification-actions { width: 100%; justify-content: flex-start; padding-left: 50px; }
}

/* Plan and billing */
.meters { display: grid; gap: 18px; }
.meter-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 6px; }
.meter-label { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; }
.meter-label .icon { width: 18px; height: 18px; color: var(--text-muted); }
.meter-value { font-variant-numeric: tabular-nums; }
.meter-bar { height: 8px; border-radius: 4px; background: var(--surface-sunken); overflow: hidden; margin-bottom: 4px; }
.meter-bar span { display: block; height: 100%; background: var(--brand); border-radius: 4px; }
.meter.close .meter-bar span { background: var(--warning); }
.meter.full .meter-bar span { background: var(--danger); }
.meter.full .meter-value { color: var(--danger); font-weight: 600; }
.notice-line { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 12px 20px; border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--brand-soft) 50%, transparent); }
.notice-line .icon { color: var(--brand-text); }
.card + .notice-line, .tabs + .notice-line { border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 16px; }
.section-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin: 28px 0 12px; }
.plan-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.plan-grid .card + .card { margin-top: 0; }
.plan.current { border-color: var(--brand); box-shadow: inset 0 0 0 1px var(--brand), var(--shadow); }
.plan-name { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-weight: 700; font-size: 1.05rem; }
.plan-price { font-size: 1.6rem; font-weight: 700; margin: 8px 0 4px; color: var(--brand-text); }
.plan-list { list-style: none; padding: 0; margin: 12px 0; display: grid; gap: 8px; }
.plan-list li { display: flex; gap: 8px; align-items: flex-start; font-size: 0.9rem; }
.plan-list .icon { width: 18px; height: 18px; color: var(--brand-text); flex: none; margin-top: 1px; }
.plan-list li.absent { color: var(--text-muted); }
.plan-list li.absent .icon { color: var(--text-muted); }
.plan-over { color: var(--warning); }
.error-actions { margin-top: 8px; }
.notice-line .grow { flex: 1; min-width: 0; }
.paused-notice { border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 16px; }

/* Who gets which notifications */
.rule-row { align-items: flex-start; }
.rule-row.off .title, .rule-row.off .notification-icon { opacity: 0.55; }
.rule-who { display: flex; align-items: center; gap: 6px; margin: 6px 0; font-size: 0.88rem; }
.rule-who .icon { width: 16px; height: 16px; color: var(--text-muted); }
@media (max-width: 599px) { .rule-row { flex-wrap: wrap; } .rule-row > .chips { padding-left: 50px; } }

/* A record's sections as a list that opens in place (ui.sectionList) */
.section-list { overflow: hidden; }
.section-item + .section-item { border-top: 1px solid var(--line); }
.section-item > summary { display: flex; align-items: center; gap: 12px; padding: 12px 20px; min-height: 56px; cursor: pointer;
  list-style: none; }
.section-item > summary::-webkit-details-marker { display: none; }
.section-item > summary:hover { background: var(--surface-sunken); }
.section-item > summary .chev { transition: transform 0.15s ease; flex: none; }
.section-item[open] > summary .chev { transform: rotate(90deg); }
.section-item[open] > summary { border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--surface-sunken) 45%, var(--surface)); }
.section-icon { color: var(--text-muted); width: 18px; height: 18px; flex: none; }
.section-name { font-weight: 600; flex: none; min-width: 9rem; }
.section-summary { flex: 1; min-width: 0; color: var(--text-muted); font-size: 0.88rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.section-actions { display: flex; gap: 6px; flex: none; }
.section-actions:empty { display: none; }
.section-body > .dl { padding: 16px 20px 16px 50px; }
.section-body > .list .list-row { padding-left: 50px; }
.section-body > .card-pad { padding-left: 50px; }
@media (max-width: 599px) {
  .section-name { min-width: 0; }
  .section-summary { display: none; }
  .section-body > .dl, .section-body > .list .list-row, .section-body > .card-pad { padding-left: 20px; }
}
.summary-line { border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 16px; }
.stat-value { font-size: 1.1rem; color: var(--brand-text); }

/* Photos of horses and people (js/photos.js) */
img.avatar { object-fit: cover; padding: 0; }
.photo { flex: none; object-fit: cover; background: var(--surface-sunken); color: var(--text-muted); display: inline-grid; place-items: center; }
.photo.small { width: 40px; height: 40px; border-radius: 10px; }
.photo.medium { width: 64px; height: 64px; border-radius: 14px; }
.photo.large { width: 104px; height: 104px; border-radius: 20px; box-shadow: var(--shadow); }
.photo.placeholder .icon { width: 45%; height: 45%; }
.photo.placeholder { font-weight: 650; }
.photo-control { position: relative; flex: none; }
.photo-control .photo-button { position: absolute; right: -6px; bottom: -6px; }
.photo-control .photo-button .button { border-radius: 50%; background: var(--surface); box-shadow: var(--shadow); }
.page-head.with-lead { justify-content: flex-start; align-items: center; }
.page-head.with-lead .titles { flex: 1; }
.photo-row { display: flex; gap: 20px; align-items: center; }
@media (max-width: 599px) {
  .photo.large { width: 76px; height: 76px; border-radius: 16px; }
  .page-head.with-lead { flex-wrap: wrap; }
}
.photo.round { border-radius: 50%; }

/* The page heading and its tabs stay in place while the page scrolls under them.
   Their heights are measured by app.js (--topbar-h on phones, --page-head-h). */
:root { --topbar-h: 0px; --page-head-h: 0px; }
.page-head { position: sticky; top: var(--topbar-h); z-index: 5; background: var(--bg);
  padding-top: 12px; padding-bottom: 12px; margin-top: -12px; margin-bottom: 8px; }
.tabs { position: sticky; top: calc(var(--topbar-h) + var(--page-head-h)); z-index: 4; background: var(--bg); }
/* Once the page has scrolled, a line marks where the fixed part ends */
.scrolled .page-head:not(:has(+ .tabs)) { box-shadow: 0 1px 0 var(--line); }
.scrolled .tabs { box-shadow: 0 1px 0 var(--line); }
/* Once scrolled, a record's photo shrinks so the fixed part takes less room */
.scrolled .page-head .photo.large { width: 48px; height: 48px; border-radius: 12px; box-shadow: none; }
.scrolled .page-head .photo.large.round { border-radius: 50%; }
.scrolled .page-head .photo-button { display: none; }
@media (max-width: 599px) {
  /* On a phone, once scrolled, the fixed part keeps only the name, actions and tabs */
  .scrolled .page-head .eyebrow, .scrolled .page-head .sub, .scrolled .page-head .photo-control { display: none; }
  .scrolled .page-head h1 { font-size: 1.25rem; }
  .scrolled .page-head { padding-top: 6px; padding-bottom: 6px; }
}
/* Menus open over what is below: the top bar's over the heading, the heading's over the tabs */
@media (max-width: 899px) { .topbar { z-index: 6; } }

/* Where you are: a stripe in the organisation's colour along the top of the menu
   (and of the phone's top bar), and a dot beside each organisation in the switcher */
.sidebar { border-top: 4px solid var(--brand); }
@media (max-width: 899px) { .topbar { border-top: 3px solid var(--brand); } }
.org-switcher .avatar { background: var(--brand); color: var(--brand-contrast); }
.org-label { display: inline-flex; align-items: center; gap: 8px; }
.org-dot { width: 10px; height: 10px; border-radius: 50%; flex: none; box-shadow: 0 0 0 2px var(--surface), 0 0 0 3px var(--line); }

/* The yard board: horses as tags that can be dragged (or tapped in move mode) */
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.horse-tag { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px 4px 8px; border-radius: 999px;
  background: var(--brand-soft); color: var(--brand-text); font-weight: 600; font-size: 0.88rem;
  border: 1px solid color-mix(in srgb, var(--brand) 25%, transparent); text-decoration: none; }
.horse-tag .icon { width: 16px; height: 16px; }
.horse-tag:hover { text-decoration: none; border-color: var(--brand); }
.horse-tag[draggable="true"] { cursor: grab; }
.horse-tag.dragging { opacity: 0.45; }
.horse-tag.picked { background: var(--brand); color: var(--brand-contrast); box-shadow: 0 0 0 3px var(--brand-soft); }
.box .horse-tag { margin-top: 4px; }
.drop-target { transition: background 0.12s ease, box-shadow 0.12s ease; }
.drop-target.over, .board.placing .drop-target:hover { box-shadow: inset 0 0 0 2px var(--brand); background: var(--brand-soft); }
.board.moving .drop-target { cursor: pointer; }
.board.placing .drop-target { box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--brand) 40%, transparent); }
.paddock-row { display: flex; gap: 16px; align-items: center; padding: 12px 20px; min-height: 56px; flex-wrap: wrap; }
.paddock-name { display: flex; flex-direction: column; min-width: 9rem; }
.board-hint { margin: -4px 0 12px; }
.bag-input { display: flex; gap: 4px; align-items: center; }
.bag-input input { max-width: 80px; }

/* Pop-up windows: the page behind is dimmed and blurred, so it reads as out of reach,
   and it does not scroll underneath */
dialog::backdrop { background: rgb(12 18 16 / 0.55); backdrop-filter: blur(3px) saturate(0.7); }
html:has(dialog[open]) { overflow: hidden; }
dialog { box-shadow: 0 24px 64px rgb(0 0 0 / 0.35); }

/* Required fields, and fields that need attention */
.required-mark { color: var(--danger); font-weight: 700; }
.field.invalid input, .field.invalid select, .field.invalid textarea { border-color: var(--danger); outline-color: var(--danger);
  background: color-mix(in srgb, var(--danger) 4%, var(--surface)); }
.field-error { color: var(--danger); font-size: 0.82rem; }
.form-actions .required-note { margin-right: auto; align-self: center; }
form:not(:has(.field.required)) .required-note { display: none; }

/* Problems: an icon, the message, then the details */
.error-box { display: flex; gap: 10px; align-items: flex-start; }
.error-box > .icon { flex: none; width: 20px; height: 20px; margin-top: 1px; }
.error-box ul { margin: 6px 0 0; padding-left: 18px; }

/* Messages at the bottom: an icon, and problems in red until tapped away */
.toast { display: flex; align-items: center; gap: 8px; pointer-events: auto; cursor: default; max-width: min(560px, calc(100vw - 32px)); }
.toast .icon { width: 18px; height: 18px; flex: none; }
.toast.bad { cursor: pointer; }

/* Horse thumbnails in rows, tags and tables */
.photo.tiny { width: 22px; height: 22px; border-radius: 6px; }
.horse-tag .photo.tiny { width: 20px; height: 20px; border-radius: 50%; margin-left: -4px; }
.chart-horse { display: flex; align-items: center; gap: 10px; }
.chart-horse > div { min-width: 0; }
.chart-horse .button { margin-left: auto; }
.timeline .what .photo.tiny { vertical-align: middle; margin-right: 6px; }
img.notification-icon { object-fit: cover; padding: 0; }
.palette-results .photo.tiny { flex: none; }
.occupants { display: grid; gap: 6px; padding: 12px; margin-bottom: 16px; border: 1px dashed var(--line-strong);
  border-radius: var(--radius-small); background: var(--surface-sunken); }

/* Editing a horse's owners */
.owner-rows { display: grid; gap: 8px; margin-bottom: 12px; }
.owner-row { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: var(--radius-small); flex-wrap: wrap; }
.owner-row .share { display: inline-flex; align-items: center; gap: 4px; }
.owner-row .share input { width: 90px; }
.owner-row .main { display: inline-flex; align-items: center; gap: 6px; font-size: 0.88rem; }
.owner-row .new-owner { display: grid; gap: 6px; grid-template-columns: 1fr 1fr; }
.owner-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.owner-total { color: var(--success); }
.owner-total.bad { color: var(--danger); font-weight: 600; }
@media (max-width: 599px) { .owner-row .new-owner { grid-template-columns: 1fr; } }
.country-brings { margin: -6px 0 16px; padding: 10px 14px; border-radius: var(--radius-small); background: var(--surface-sunken); }
.country-brings .dl { gap: 4px 16px; }

/* The role editor: permissions grouped by what they act on */
.role-row { align-items: flex-end; }
/* Roles: what a role can do, as a tree of areas and their actions */
.permission-tree { display: grid; gap: 4px; margin: 4px 0 12px; padding: 0; list-style: none; }
.permission-tree .tree-area { border: 1px solid var(--line); border-radius: var(--radius-small); padding: 8px 12px; }
.permission-tree .tree-area-name { display: flex; align-items: center; gap: 8px; font-weight: 600; cursor: pointer; }
.permission-tree .tree-area-name .icon { color: var(--text-muted); flex: none; }
.permission-tree .tree-actions { display: grid; gap: 2px; margin: 6px 0 2px 26px; padding: 0; list-style: none; }
.permission-tree .tree-action { display: flex; gap: 10px; align-items: flex-start; padding: 4px 6px; border-radius: var(--radius-small); cursor: pointer; }
.permission-tree .tree-action:hover { background: var(--surface-sunken); }
.permission-tree .tree-action > span { display: flex; flex-direction: column; }
.permission-tree .tree-action.unavailable { opacity: 0.5; cursor: not-allowed; }
.permission-tree.read-only .tree-area { padding: 6px 10px; }
.permission-tree.read-only .tree-area.none { opacity: 0.55; }
.permission-tree.read-only .tree-area-name span.muted { margin-left: auto; font-weight: 400; }
.permission-tree.read-only .tree-actions li { display: flex; gap: 6px; align-items: center; font-size: 0.88rem; color: var(--success); }
.permission-tree.read-only .tree-actions .icon { width: 14px; height: 14px; }
/* Roles: what a role can see and change, one row per kind of information */
.permission-grid { display: grid; border: 1px solid var(--line); border-radius: var(--radius-small); overflow: hidden; margin: 4px 0 12px; }
.permission-grid .grid-row { display: grid; grid-template-columns: minmax(150px, 1.6fr) repeat(4, minmax(0, 1fr)); border-top: 1px solid var(--line); }
.permission-grid .grid-row > * { padding: 8px 10px; min-width: 0; }
.permission-grid.info-grid .grid-row { grid-template-columns: minmax(180px, 2.4fr) repeat(2, minmax(0, 1fr)); }
.permission-grid .grid-head { border-top: 0; background: var(--surface-sunken); font-size: 0.8rem; font-weight: 650; color: var(--text-muted); }
.permission-grid .grid-subject-name { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.permission-grid .grid-subject-name .icon { color: var(--text-muted); flex: none; }
.permission-grid .grid-cell { display: flex; flex-direction: column; gap: 4px; align-items: flex-start; }
.permission-grid .grid-verb { display: none; }
.permission-grid .grid-choice { display: flex; align-items: center; gap: 6px; cursor: pointer; font-size: 0.88rem; }
.permission-grid .grid-choice.unavailable { opacity: 0.5; cursor: not-allowed; }
.permission-grid .grid-yes { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px 2px 4px; border-radius: 999px; background: color-mix(in srgb, var(--success) 14%, transparent); color: var(--success); font-size: 0.85rem; font-weight: 600; }
.permission-grid .grid-yes .icon { width: 16px; height: 16px; stroke-width: 2.6; }
.permission-grid .grid-yes:not(:has(> :not(.icon, .visually-hidden))) { padding: 3px; }
.permission-grid .grid-no { display: inline-flex; gap: 4px; color: var(--text-muted); font-size: 0.88rem; }
.permission-grid.read-only .grid-row > * { padding: 6px 10px; }
@media (max-width: 640px) {
  .permission-grid .grid-head { display: none; }
  .permission-grid .grid-row, .permission-grid.info-grid .grid-row { grid-template-columns: 1fr 1fr; }
  .permission-grid .grid-subject { grid-column: 1 / -1; background: var(--surface-sunken); }
  .permission-grid .grid-cell:not(:has(.grid-choice, .grid-yes, .grid-no)) { display: none; }
  .permission-grid .grid-verb { display: block; font-size: 0.75rem; font-weight: 650; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
}
.claim-card .claim-horses { font-size: 1.2rem; font-weight: 700; }
.claim-actions { display: grid; gap: 8px; margin-top: 8px; }

/* A role's conditions: when and where it counts */
.conditions > label { display: inline-flex; align-items: center; gap: 0.4rem; font-weight: 600; }
.cond-options { display: flex; flex-wrap: wrap; gap: 0.4rem 1rem; margin: 0.4rem 0 0.6rem 1.6rem; }
.cond-options label { display: inline-flex; align-items: center; gap: 0.35rem; }
.cond-time input { margin-left: 0.4rem; width: auto; }

/* Check access: each rule along each relation, condition by condition */
.why-paths { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.why-path { padding: 8px 0; border-top: 1px solid var(--line); }
.why-path:first-child { border-top: 0; }
.why-rule { display: flex; align-items: center; gap: 6px; }
.why-path:not(.holds) .why-rule { color: var(--text-muted); }
.why-steps { list-style: none; margin: 6px 0 0; padding: 0 0 0 24px; display: grid; gap: 4px; font-size: 0.875rem; }
.why-steps li { display: flex; align-items: flex-start; gap: 6px; }
.why-true { color: var(--success); }
.why-false { color: var(--danger); }
.why-null { color: var(--text-muted); }
.why-steps li > :not(svg) { color: var(--text); }

/* A horse's tab holding several parts (Care: the care log and feeding) */
.part-head { font-size: 1rem; font-weight: 600; margin: 24px 0 8px; }
.part-head:first-child { margin-top: 4px; }
