/* AnimalTrakker Breeding Planner. Colours follow the AnimalTrakker theme
   (components/client/shared-ui/.../theme/Colors.kt): primary #006878, logo teal #3EB1C8, secondary #3F646D,
   tertiary #784C91, error #9A414D. No CSS framework. */
:root {
  --at-primary: #006878;
  --at-primary-dark: #004A59;
  --at-primary-container: #3EB1C8;
  --at-primary-tint: #E6F4F7;
  --at-secondary: #3F646D;
  --at-secondary-container: #C2E9F3;
  --at-tertiary: #784C91;
  --at-error: #9A414D;
  --at-surface: #F6F8F8;
  --at-surface-variant: #E4ECEE;
  --at-on-surface: #171C1E;

  --fg: var(--at-on-surface);
  --muted: #5A6669;
  --faint: #8D999C;
  --line: #D3DCDE;
  --line-strong: #B5C3C6;
  --bg: #FFFFFF;
  --panel: var(--at-surface);
  --accent: var(--at-primary);
  --danger: var(--at-error);
  --ok-bg: #E6F4F7;   --ok-fg: #00505D;
  --warn-bg: #FFF4E0; --warn-fg: #7A4B00; --warn-line: #F2D29B;
  --err-bg: #FBE9EB;  --err-fg: #85323D; --err-line: #EBC1C7;
  --highlight: #FFF3CF;      /* allocated pairing: warm, so it never reads as a percentile teal */
  --highlight-line: #E5B94C;
  --ewe-band: #2F4F57;       /* ewe heading in the planning grid: dark slate, not teal or yellow */
  --ewe-band-hover: #3A5E67;
  --ewe-fg: #FFFFFF;
  --ewe-fg-muted: #C9DADE;

  --space-1: 4px; --space-2: 8px; --space-3: 12px; --space-4: 16px; --space-5: 24px; --space-6: 32px;
  --radius: 8px; --radius-sm: 6px;
  --shadow-sm: 0 1px 2px rgba(23, 28, 30, 0.06);
  --shadow-md: 0 8px 24px rgba(23, 28, 30, 0.14);
  --text-xs: 0.75rem; --text-sm: 0.85rem; --text-md: 0.95rem; --text-lg: 1.15rem; --text-xl: 1.6rem;
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
  --header-h: 56px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px; line-height: 1.45; color: var(--fg); background: var(--bg);
  display: flex; flex-direction: column; min-height: 100vh;
}
main { flex: 1; padding: var(--space-5) var(--space-5) var(--space-6); max-width: 1640px; width: 100%; margin: 0 auto; }
h1 { font-size: var(--text-xl); line-height: 1.2; margin: 0; color: var(--at-primary-dark); letter-spacing: -0.01em; }
h2 { font-size: var(--text-lg); margin: 0 0 var(--space-3); color: var(--at-primary-dark); }
h3 { font-size: 1rem; margin: 0; color: var(--at-secondary); }
a { color: var(--at-primary); }
p { margin: 0 0 var(--space-2); }
.lead { color: var(--muted); margin: var(--space-1) 0 0; }
.muted { color: var(--muted); }
.small { font-size: var(--text-sm); }
.num { font-variant-numeric: tabular-nums; }
.spacer { flex: 1; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.no-js { display: none; }
:focus-visible { outline: 2px solid var(--at-primary-container); outline-offset: 2px; border-radius: 4px; }
.skip-link { position: absolute; left: -999px; top: 8px; background: #fff; padding: 8px 12px; z-index: 100; border-radius: var(--radius-sm); }
.skip-link:focus { left: 8px; }
.narrow { max-width: 560px; display: flex; flex-direction: column; gap: var(--space-4); }

/* ---- Header / footer ---- */
.site-header {
  position: sticky; top: 0; z-index: 30; height: var(--header-h);
  display: flex; align-items: center; gap: var(--space-5); padding: 0 var(--space-5);
  background: #FFFFFF; border-bottom: 2px solid var(--at-primary-container);
}
.site-header a { text-decoration: none; }
.site-header .brand { display: flex; align-items: center; gap: var(--space-3); color: var(--at-primary-dark); }
.site-header .brand img { height: 38px; width: auto; display: block; }
.site-header .brand .app-name { font-weight: 600; font-size: 1.05rem; padding-left: var(--space-3); border-left: 1px solid var(--line); }
.site-header nav { display: flex; gap: var(--space-1); margin-left: auto; }
.site-header nav a { color: var(--at-secondary); padding: 6px 14px; border-radius: 999px; font-weight: 500; }
.site-header nav a:hover { background: var(--at-primary-tint); color: var(--at-primary-dark); }
.site-header nav a.active { background: var(--at-primary-tint); color: var(--at-primary-dark); font-weight: 650; box-shadow: inset 0 0 0 1px var(--at-secondary-container); }
.site-footer {
  display: flex; flex-wrap: wrap; gap: 6px 18px; align-items: center;
  padding: 10px var(--space-5); color: var(--muted); border-top: 1px solid var(--line); font-size: var(--text-sm); background: var(--at-surface);
}
.site-footer img { height: 18px; width: 18px; }

/* ---- Buttons ---- */
button, .btn {
  font: inherit; font-size: var(--text-md); line-height: 1.2; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 34px; padding: 6px 14px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: #fff; color: var(--fg); cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background-color .12s, border-color .12s, color .12s, box-shadow .12s;
}
button:hover, .btn:hover { background: var(--at-primary-tint); border-color: var(--at-primary-container); }
button:active, .btn:active { transform: translateY(1px); }
button:disabled, .btn[aria-disabled=true] { opacity: .45; cursor: not-allowed; transform: none; background: #fff; border-color: var(--line); }
.primary, button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.primary:hover, button.primary:hover { background: var(--at-primary-dark); border-color: var(--at-primary-dark); }
.ghost { background: transparent; border-color: transparent; color: var(--at-primary); }
.ghost:hover { background: var(--at-primary-tint); border-color: transparent; }
.danger, button.danger { color: var(--danger); }
.ghost.danger:hover { background: var(--err-bg); }
.danger-solid { background: var(--danger); border-color: var(--danger); color: #fff; font-weight: 600; }
.danger-solid:hover { background: #7E333E; border-color: #7E333E; }
.btn.small, button.small { min-height: 28px; padding: 3px 10px; font-size: var(--text-sm); }
.icon-btn {
  min-height: 28px; min-width: 28px; padding: 2px 6px; border-color: transparent; background: transparent; color: var(--muted);
  border-radius: var(--radius-sm); display: inline-flex; align-items: center; justify-content: center; cursor: pointer;
}
.icon-btn:hover { color: var(--danger); background: var(--err-bg); border-color: transparent; }

/* ---- Form controls ---- */
input[type=text], input[type=number], textarea, select {
  font: inherit; font-size: var(--text-md); min-height: 34px; padding: 5px 9px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: #fff; color: var(--fg); transition: border-color .12s, box-shadow .12s;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--at-primary); box-shadow: 0 0 0 3px rgba(62, 177, 200, .25); }
input[type=checkbox] { accent-color: var(--at-primary); width: 15px; height: 15px; margin: 0; }
textarea { width: 100%; }
.input-lg { font-size: 1.1rem; min-height: 44px; padding: 8px 12px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: var(--text-sm); color: var(--muted); }
.field > select, .field > input { color: var(--fg); }
.field-inline { display: inline-flex; align-items: center; gap: 6px; font-size: var(--text-sm); color: var(--muted); white-space: nowrap; }
.field-hint { min-height: 1.4em; font-size: var(--text-sm); }
.field-error { color: var(--danger); font-size: var(--text-sm); }
.field-ok { color: var(--at-primary); font-size: var(--text-sm); font-weight: 500; }
.unit { color: var(--muted); margin-left: -2px; }

/* ---- Notices, toasts, badges, chips, bars ---- */
.notice { display: flex; gap: var(--space-2); align-items: flex-start; padding: 8px 12px; border-radius: var(--radius-sm); margin: var(--space-2) 0; font-size: var(--text-sm); border: 1px solid transparent; }
.notice ul { margin: 0; padding-left: 18px; }
.notice-icon { font-weight: 700; }
.notice-ok, .notice-info { background: var(--ok-bg); color: var(--ok-fg); border-color: var(--at-secondary-container); }
.notice-warn { background: var(--warn-bg); color: var(--warn-fg); border-color: var(--warn-line); }
.notice-error { background: var(--err-bg); color: var(--err-fg); border-color: var(--err-line); }
.toasts { position: fixed; right: var(--space-5); bottom: var(--space-5); z-index: 60; display: flex; flex-direction: column; gap: var(--space-2); max-width: min(440px, calc(100vw - 32px)); }
.toast { margin: 0; box-shadow: var(--shadow-md); align-items: center; animation: toast-in .18s ease-out; }
.toast .toast-close { margin-left: auto; min-height: 24px; min-width: 24px; color: inherit; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }
.badge { display: inline-block; margin-left: 6px; padding: 0 7px; border-radius: 999px; font-size: var(--text-xs); line-height: 1.6; background: var(--at-surface-variant); color: var(--at-secondary); font-weight: 600; vertical-align: 1px; }
.badge-error { background: var(--err-bg); color: var(--err-fg); }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px; border-radius: 999px; background: #fff; border: 1px solid var(--line); font-size: var(--text-sm); font-weight: 600; color: var(--at-primary-dark); font-variant-numeric: tabular-nums; }
.bar { display: inline-block; position: relative; width: 100%; max-width: 160px; height: 6px; border-radius: 999px; background: var(--at-surface-variant); overflow: hidden; vertical-align: middle; }
.bar-fill { position: absolute; inset: 0 auto 0 0; background: var(--at-primary-container); border-radius: inherit; transition: width .25s; }
.bar-done .bar-fill { background: var(--at-primary); }
.spinner {
  display: inline-block; width: 12px; height: 12px; border: 2px solid var(--line);
  border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; vertical-align: -1px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.empty { color: var(--muted); font-size: var(--text-sm); margin: var(--space-2) 0 0; }
.empty-state { max-width: 460px; margin: 64px auto; text-align: center; display: flex; flex-direction: column; align-items: center; gap: var(--space-2); }
.empty-icon { font-size: 2rem; font-weight: 700; color: var(--at-primary); width: 72px; height: 72px; border-radius: 50%; background: var(--at-primary-tint); display: grid; place-items: center; margin-bottom: var(--space-2); }

/* ---- Cards ---- */
.card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: var(--space-5); box-shadow: var(--shadow-sm); }

/* ---- LPN IDs: muted flock prefix, distinguishing suffix ---- */
.lpn { font-family: var(--mono); font-size: 0.92em; white-space: nowrap; }
.lpn-flock { color: var(--faint); }
.lpn-own { color: var(--fg); font-weight: 600; }

/* ---- Menus (details-based dropdowns) ---- */
details.menu { position: relative; display: inline-block; }
details.menu > summary { list-style: none; cursor: pointer; }
details.menu > summary::-webkit-details-marker { display: none; }
details.menu[open] > summary { background: var(--at-primary-tint); border-color: var(--at-primary-container); }
details.menu[open] > summary.primary { background: var(--at-primary-dark); }
.menu-panel {
  position: absolute; z-index: 40; top: calc(100% + 6px); left: 0; min-width: 260px; background: #fff;
  border: 1px solid var(--line); border-radius: var(--radius); padding: var(--space-1); box-shadow: var(--shadow-md);
  display: flex; flex-direction: column;
}
.menu-right { left: auto; right: 0; }
.menu-item, label.menu-item {
  display: flex; align-items: center; gap: 6px; width: 100%; min-height: 32px; padding: 6px 10px; border: none; border-radius: var(--radius-sm);
  background: none; color: var(--fg); text-decoration: none; white-space: nowrap; font-size: var(--text-md); justify-content: flex-start; cursor: pointer;
}
.menu-item:hover, .menu-item:focus-visible, label.menu-item:focus-within { background: var(--at-primary-tint); }
.menu-item.danger { color: var(--danger); }
.menu-item.danger:hover { background: var(--err-bg); }
.menu-sep { height: 1px; background: var(--line); margin: var(--space-1) 0; }
.menu-heading { font-size: var(--text-xs); text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 6px 10px 2px; }
.open-form { margin: 0; }
.file-button { position: relative; overflow: hidden; }
.file-button input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

/* ---- Confirm dialog ---- */
dialog { border: 1px solid var(--line); border-radius: 12px; padding: var(--space-5); box-shadow: var(--shadow-md); color: var(--fg); }
dialog::backdrop { background: rgba(23, 28, 30, 0.35); }
dialog.confirm-dialog { width: min(420px, 92vw); }
dialog.confirm-dialog h2 { margin-bottom: var(--space-2); }
dialog .actions { display: flex; gap: var(--space-2); justify-content: flex-end; margin-top: var(--space-4); }

/* ---- Start page ---- */
.hero { margin: var(--space-4) 0 var(--space-5); }
.hero h1 { font-size: 1.9rem; }
.start-grid { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: var(--space-5); max-width: 980px; }
@media (max-width: 800px) { .start-grid { grid-template-columns: 1fr; } }
.start-card { display: flex; flex-direction: column; gap: var(--space-2); }
.start-card label { font-weight: 600; font-size: var(--text-sm); }
.start-card .actions { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-2); }
.start-card .actions .btn { min-height: 40px; padding: 8px 18px; }
.loading-note { margin-top: var(--space-2); }
.dropzone {
  position: relative; flex: 1; min-height: 150px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  border: 2px dashed var(--line-strong); border-radius: var(--radius); background: var(--at-surface); text-align: center; padding: var(--space-4);
  cursor: pointer; transition: border-color .12s, background-color .12s;
}
.dropzone:hover, .dropzone.dragover, .dropzone:focus-within { border-color: var(--at-primary-container); background: var(--at-primary-tint); }
.dropzone input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.dropzone-icon { font-size: 1.6rem; color: var(--at-primary); }
.dropzone-title { font-weight: 600; color: var(--at-primary-dark); }
.start-card .open-form { display: flex; flex: 1; }
.recent-plans { margin-top: var(--space-6); max-width: 980px; }
.section-head { display: flex; align-items: baseline; gap: var(--space-3); margin-bottom: var(--space-2); }
.section-head h2 { margin: 0; }
.plan-list { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.plan-row { display: grid; grid-template-columns: minmax(0, 1fr) 64px 170px 90px auto; align-items: center; gap: var(--space-4); padding: 10px var(--space-4); border-top: 1px solid var(--line); background: #fff; }
.plan-row:first-child { border-top: none; }
.plan-row:hover { background: var(--at-surface); }
.plan-main { display: flex; flex-direction: column; text-decoration: none; min-width: 0; }
.plan-title { font-weight: 600; color: var(--at-primary-dark); }
.plan-main:hover .plan-title { text-decoration: underline; }
.plan-meta { color: var(--muted); font-size: var(--text-sm); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.plan-progress { display: flex; flex-direction: column; gap: 2px; }
.plan-time { text-align: right; }
.plan-actions { display: flex; gap: var(--space-1); }
.plan-actions form.inline { display: inline; margin: 0; }
@media (max-width: 800px) { .plan-row { grid-template-columns: 1fr auto; } .plan-progress, .plan-time, .plan-row .badge { display: none; } }

/* ---- Page head (Planning / Compare) ---- */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--space-3) var(--space-5); margin-bottom: var(--space-4); }
.page-title { flex: 1; min-width: 0; }
.title-row { display: flex; align-items: center; gap: var(--space-2); }
.page-actions { display: flex; align-items: center; gap: var(--space-3); }
.save-state { transition: color .2s; }
.save-state.saving { color: var(--at-secondary); }
.save-state.error { color: var(--danger); }
details.rename { position: relative; }
details.rename > summary { list-style: none; cursor: pointer; }
details.rename > summary::-webkit-details-marker { display: none; }
details.rename > summary:hover { color: var(--at-primary); background: var(--at-primary-tint); }
.rename-form { position: absolute; z-index: 40; top: calc(100% + 6px); left: 0; display: flex; gap: var(--space-2); background: #fff; padding: var(--space-2);
  border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-md); }
.rename-form input { width: 260px; }

/* ---- Selection panel ---- */
.selection { margin: 0 0 var(--space-4); }
details.selection-panel { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
summary.selection-summary { display: flex; align-items: center; gap: var(--space-2); padding: 10px var(--space-4); cursor: pointer; list-style: none; user-select: none; border-radius: var(--radius); }
summary.selection-summary::-webkit-details-marker { display: none; }
summary.selection-summary:hover { background: var(--at-surface-variant); }
.selection-label { font-weight: 650; color: var(--at-secondary); margin-right: var(--space-2); }
details.selection-panel[open] > summary { border-bottom: 1px solid var(--line); border-radius: var(--radius) var(--radius) 0 0; }
details.selection-panel:not([open]) .when-open, details.selection-panel[open] .when-closed { display: none; }
.selection-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-4); padding: var(--space-4); }
.compare-selection .sel-list { margin: var(--space-4); }
@media (max-width: 1000px) { .selection-grid { grid-template-columns: 1fr; } }
.sel-list { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: var(--space-3) var(--space-4); min-width: 0; display: flex; flex-direction: column; gap: var(--space-2); }
.sel-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); min-height: 28px; }
.id-form { display: flex; flex-direction: column; gap: 4px; }
.id-form > label { font-size: var(--text-sm); color: var(--muted); }
.id-row { display: flex; gap: var(--space-2); }
.id-input { flex: 1; min-width: 0; max-width: 260px; font-family: var(--mono); text-transform: uppercase; }
.id-lookup { min-height: 1.5em; font-size: var(--text-sm); }
/* Hide the previous answer while a lookup runs so a stale count never looks current. */
.id-lookup.htmx-request > * { display: none; }
.id-lookup.htmx-request::before { content: "Looking up…"; color: var(--muted); }
.lookup-card { display: flex; flex-wrap: wrap; align-items: center; gap: 2px; }
.badge-warn { background: var(--warn-bg); color: var(--warn-fg); }
.fill-form .flock { width: 84px; font-family: var(--mono); }
.fill-form .htmx-indicator { width: 14px; height: 14px; }
.fill-form { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; }
.fill-form label { display: inline-flex; align-items: center; gap: 6px; font-size: var(--text-sm); color: var(--muted); }
.fill-form .year { width: 96px; }
.current-only { white-space: nowrap; }
details.paste > summary { cursor: pointer; color: var(--accent); font-size: var(--text-sm); width: fit-content; }
details.paste form { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; margin-top: 6px; }
.fill-candidates { background: var(--at-surface); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: var(--space-3); display: flex; flex-direction: column; gap: var(--space-2); }
.fill-candidates .rule { font-size: var(--text-sm); margin: 0; }
.fill-candidates .rule-name { font-weight: 600; }
.fill-candidates .actions { display: flex; gap: var(--space-2); }
.candidate-tools { display: flex; align-items: center; gap: var(--space-1); }
.candidate-tools > span { margin-right: auto; }
.candidate-list { max-height: 220px; overflow: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 2px 12px; background: #fff; border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 6px 8px; }
.candidate { display: flex; gap: 6px; align-items: center; font-size: var(--text-sm); padding: 2px 0; cursor: pointer; }
.sel-table-wrap {
  max-height: 272px; overflow: auto; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: linear-gradient(#fff 30%, rgba(255,255,255,0)) top / 100% 24px no-repeat local,
              linear-gradient(rgba(255,255,255,0), #fff 70%) bottom / 100% 24px no-repeat local,
              radial-gradient(farthest-side at 50% 0, rgba(0,0,0,.12), transparent) top / 100% 8px no-repeat scroll,
              radial-gradient(farthest-side at 50% 100%, rgba(0,0,0,.12), transparent) bottom / 100% 8px no-repeat scroll, #fff;
}
.sel-table { border-collapse: collapse; width: 100%; font-size: var(--text-sm); }
.sel-table th, .sel-table td { padding: 4px 10px; border-bottom: 1px solid var(--at-surface-variant); text-align: left; }
.sel-table th { position: sticky; top: 0; background: var(--panel); font-weight: 600; color: var(--muted); font-size: var(--text-xs); text-transform: uppercase; letter-spacing: .04em; z-index: 1; }
.sel-table tbody tr:hover { background: var(--at-primary-tint); }
.sel-table .row-action { width: 36px; text-align: right; padding: 0 4px; }
.sel-table .row-action .icon-btn { opacity: 0; }
.sel-table tr:hover .icon-btn, .sel-table .icon-btn:focus-visible { opacity: 1; }
@media (hover: none) { .sel-table .row-action .icon-btn { opacity: 1; } }

/* ---- Toolbar ---- */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-4); padding: var(--space-2) 0; }
.sticky-toolbar, .sticky-controls { position: sticky; top: var(--header-h); z-index: 20; background: #fff; border-bottom: 1px solid var(--line); margin-bottom: var(--space-3); }
.sticky-controls .toolbar { border-bottom: 1px solid var(--at-surface-variant); }
.sticky-controls .status-strip { margin: 0; padding: var(--space-2) 0; }
.toolbar-group { display: flex; align-items: center; gap: var(--space-2); margin: 0; }
.toolbar-group + .toolbar-group { padding-left: var(--space-4); border-left: 1px solid var(--line); }
.group-label { font-size: var(--text-xs); text-transform: uppercase; letter-spacing: .06em; color: var(--faint); font-weight: 600; }
.constraints input[type=number] { width: 72px; }
.segmented { display: inline-flex; margin: 0; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); overflow: hidden; background: #fff; }
.segmented .seg { border: none; border-radius: 0; min-height: 32px; padding: 4px 12px; background: transparent; }
.segmented .seg + .seg { border-left: 1px solid var(--line); }
.segmented .seg:hover { background: var(--at-primary-tint); }
.segmented .seg.active { background: var(--at-primary); color: #fff; font-weight: 600; }
.status-text { color: var(--muted); font-size: var(--text-sm); }

/* ---- Status strip ---- */
.status-strip { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-3); margin: var(--space-2) 0 var(--space-3); min-height: 30px; }
.stat { display: inline-flex; align-items: center; gap: 8px; font-size: var(--text-sm); color: var(--muted); font-variant-numeric: tabular-nums; }
.stat b { color: var(--fg); font-size: 1rem; }
.stat .bar { width: 120px; }
button.stat, .stat-chip { min-height: 28px; padding: 2px 10px; border-radius: 999px; border: 1px solid var(--line); background: #fff; font-size: var(--text-sm); }
.stat-warn { background: var(--warn-bg) !important; border-color: var(--warn-line) !important; color: var(--warn-fg) !important; }
.stat-error { background: var(--err-bg) !important; border-color: var(--err-line) !important; color: var(--err-fg) !important; }
.stat-ok { color: var(--ok-fg); }
button.stat.active { box-shadow: 0 0 0 2px var(--at-primary-container); }
.status-strip .filters { margin-left: auto; }
.status-strip .hint { font-size: var(--text-xs); }
@media (max-width: 1200px) { .status-strip .hint { display: none; } }
.hint { color: var(--muted); font-size: var(--text-sm); }
kbd { font-family: var(--mono); font-size: var(--text-xs); border: 1px solid var(--line-strong); border-bottom-width: 2px; border-radius: 4px; padding: 0 4px; background: #fff; }

/* ---- Grid + summary ---- */
.grid-area { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: var(--space-4); align-items: start; }
.grid-area.summary-closed { grid-template-columns: minmax(0, 1fr); }
.grid-area.summary-closed .summary-panel { display: none; }
.grid-wrap { min-width: 0; }
#grid, #compare-grid { font-size: var(--text-sm); border-radius: var(--radius); }
#grid:focus-visible { outline: 2px solid var(--at-primary-container); outline-offset: 2px; }
.grid-loading { padding: 40px; color: var(--muted); display: flex; gap: 8px; align-items: center; justify-content: center; }
.summary-panel { position: sticky; top: calc(var(--header-h) + var(--controls-h, 100px) + 8px); max-height: calc(100vh - var(--header-h) - var(--controls-h, 100px) - 24px); overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: var(--space-3) var(--space-4); }
.summary-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: var(--space-2); }
.summary-total { margin-bottom: 6px; }
.big-num { font-size: 1.35rem; color: var(--at-primary-dark); font-variant-numeric: tabular-nums; }
.summary .bar { max-width: none; margin-bottom: var(--space-3); }
.summary .notice { display: block; }
.summary .notice ul { list-style: none; padding: 0; margin-top: 4px; font-size: var(--text-xs); }
.summary .notice .lpn-flock { display: none; }
.summary-rams { list-style: none; padding: 0; margin: var(--space-2) 0 0; font-size: var(--text-sm); display: flex; flex-direction: column; gap: var(--space-3); }
.ram-line { display: flex; justify-content: space-between; gap: var(--space-2); }
.ram-load { font-variant-numeric: tabular-nums; font-weight: 600; }
.load-bar { display: block; height: 4px; border-radius: 999px; background: var(--at-surface-variant); margin: 4px 0; overflow: hidden; }
.load-fill { display: block; height: 100%; background: var(--at-primary-container); border-radius: inherit; }
.over-limit .load-fill { background: var(--danger); }
.over-limit .ram-load, .load.over { color: var(--danger); }
.ewe-list { display: flex; flex-wrap: wrap; gap: 2px 8px; font-size: var(--text-xs); }
.ewe-list .lpn-own { font-weight: 500; color: var(--muted); }

/* ---- Tabulator in AnimalTrakker colours ---- */
.tabulator { border: 1px solid var(--line); background: #FFFFFF; border-radius: var(--radius); }
.tabulator .tabulator-header { background: var(--at-surface); border-bottom: 1px solid var(--line-strong); color: var(--at-on-surface); font-weight: 600; }
.tabulator .tabulator-header .tabulator-col { background: var(--at-surface); border-right-color: var(--line); }
.tabulator .tabulator-header .tabulator-col .tabulator-col-content { padding: 6px 6px 5px; }
.tabulator .tabulator-header .tabulator-col .tabulator-col-title { white-space: normal; line-height: 1.15; font-size: var(--text-sm); }
.tabulator .tabulator-header .tabulator-col.tabulator-sortable .tabulator-col-title { padding-right: 12px; }
.tabulator .tabulator-header .tabulator-col .tabulator-col-content .tabulator-col-sorter { right: 0; }
.tabulator .tabulator-header .tabulator-col.tabulator-sortable:not([aria-sort=ascending]):not([aria-sort=descending]) .tabulator-col-sorter { opacity: 0; }
.tabulator .tabulator-header .tabulator-col.tabulator-sortable:hover .tabulator-col-sorter { opacity: 1; }
.tabulator .tabulator-header .tabulator-col.tabulator-sortable:hover { background: var(--at-primary-tint); }
.tabulator .tabulator-header .tabulator-header-filter input { min-height: 26px; padding: 2px 6px; font-size: var(--text-xs); font-weight: 400; }
.tabulator-row .tabulator-cell { border-right-color: rgba(0, 0, 0, 0.04); font-variant-numeric: tabular-nums; }
.tabulator-row.tabulator-row-even { background: #FCFDFD; }
.tabulator-row.tabulator-selectable:hover, .tabulator-row:hover { background: var(--at-primary-tint); }
/* Ewe heading: a dark band with a white gap above, so each ewe's block of rams reads as its own section. A border,
   not a margin, because the virtual renderer measures row heights. */
.tabulator-row.tabulator-group { background: var(--ewe-band); border-top: 8px solid var(--bg); border-bottom: 0; color: var(--ewe-fg); font-weight: 600; font-size: var(--text-md); padding: 7px 10px; }
.tabulator-row.tabulator-group:first-child { border-top: 0; }
.tabulator-row.tabulator-group:hover { background: var(--ewe-band-hover); }
.tabulator-row.tabulator-group .tabulator-arrow { border-left-color: var(--ewe-fg); }
.tabulator-row.tabulator-group.tabulator-group-visible .tabulator-arrow { border-left-color: transparent; border-top-color: var(--ewe-fg); }
.tabulator-row.tabulator-group span { color: inherit; margin-left: 0; }
.tabulator-row.tabulator-group span.lpn-flock { color: var(--ewe-fg-muted); font-weight: 400; }
.tabulator-row.tabulator-group span.muted { color: var(--ewe-fg-muted); font-weight: 400; }
.tabulator-row.tabulator-group .ewe-chip { display: inline-block; margin-right: 8px; padding: 0 7px; border-radius: 999px; background: var(--ewe-fg); color: var(--ewe-band); font-size: var(--text-xs); font-weight: 700; letter-spacing: .04em; text-transform: uppercase; line-height: 1.7; vertical-align: 1px; }
.tabulator-row.tabulator-group .group-count { color: var(--ewe-fg-muted); font-weight: 400; margin-left: 8px; }
.tabulator-row.tabulator-group .group-alloc span.muted { color: var(--muted); }
/* Ram rows sit under their ewe: indented ID with a muted "ram" tag. */
.tabulator-row .tabulator-cell.ram-cell { padding-left: 22px; }
.ram-tag { color: var(--faint); font-size: var(--text-xs); margin-right: 6px; text-transform: uppercase; letter-spacing: .04em; }
.tabulator-row.tabulator-group .group-alloc { display: inline-flex; gap: 6px; align-items: center; margin-left: 12px; padding: 0 8px; border-radius: 999px; background: var(--highlight); border: 1px solid var(--highlight-line); color: var(--fg); font-weight: 600; }
.tabulator-row.tabulator-group .group-alloc .lpn-flock { display: none; }
.tabulator-row.tabulator-group .group-open { margin-left: 12px; color: var(--ewe-fg-muted); font-weight: 400; font-size: var(--text-xs); }
/* Allocated pairing: warm highlight + outline (not a teal shade, so it never blends with the percentile colours). */
.tabulator-row.row-selected { background: var(--highlight) !important; box-shadow: inset 0 0 0 1px var(--highlight-line); font-weight: 600; }
/* The other pairings of an allocated ewe recede, colours included. */
.tabulator-row.row-other .tabulator-cell { opacity: .45; }
.tabulator-row.row-other:hover .tabulator-cell { opacity: .8; }
.tabulator-row.row-focus { box-shadow: inset 0 0 0 2px var(--at-primary-container); }
.alloc-btn { min-height: 22px; min-width: 22px; padding: 0; border-radius: 50%; border: 1.5px solid var(--line-strong); background: #fff; color: transparent; font-size: 12px; line-height: 1; }
.alloc-btn:hover { border-color: var(--at-primary); background: var(--at-primary-tint); color: var(--at-primary); }
.alloc-btn.on { background: var(--at-primary); border-color: var(--at-primary); color: #fff; }
.tabulator-cell.over-f, .tabulator-row .tabulator-cell.over-f { background: var(--err-bg) !important; color: var(--danger) !important; font-weight: 700; opacity: 1 !important; }
.f-cell { font-weight: 600; }
.notes-cell { cursor: text; color: var(--at-secondary); font-style: italic; }
.notes-cell:empty::after { content: ""; }
.tabulator .tabulator-tableholder .tabulator-placeholder .tabulator-placeholder-contents { color: var(--muted); font-weight: 400; font-size: var(--text-md); padding: 32px 16px; }
.tabulator .tabulator-alert { background: rgba(255, 255, 255, .85); }
.tabulator .tabulator-alert .tabulator-alert-msg { border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-md); font-size: var(--text-sm); }
.tabulator .tabulator-alert .tabulator-alert-msg.tabulator-alert-state-msg { border-color: var(--line); color: var(--fg); }

/* ---- Legend (in the Key popover) ---- */
.legend-panel { padding: var(--space-3); min-width: 0; width: max-content; max-width: 90vw; }
.legend { display: flex; flex-wrap: wrap; align-items: center; gap: 3px; font-size: var(--text-xs); }
.legend-label { margin-right: 6px; color: var(--muted); font-weight: 600; }
.legend-swatch { display: inline-block; min-width: 44px; text-align: center; padding: 3px 4px; border-radius: 4px; font-variant-numeric: tabular-nums; box-shadow: inset 0 0 0 1px rgba(0,0,0,.06); }
.legend-end { color: var(--muted); margin: 0 4px; }
.legend-note { flex-basis: 100%; margin: 6px 0 0; }

/* ---- Columns dialog ---- */
dialog.columns-dialog { max-width: 640px; width: 92vw; }
dialog.columns-dialog h3 { margin-bottom: var(--space-3); font-size: var(--text-lg); color: var(--at-primary-dark); }
dialog fieldset { border: 1px solid var(--line); border-radius: var(--radius-sm); margin: 0 0 var(--space-3); display: flex; flex-wrap: wrap; gap: 6px 16px; }
dialog fieldset label { display: inline-flex; gap: 6px; align-items: center; }
dialog legend { font-weight: 600; color: var(--at-secondary); padding: 0 4px; }
.trait-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)); gap: 4px 12px; width: 100%; }
.formula-row { display: flex; gap: 10px; width: 100%; align-items: center; }
.formula-row .grow { flex: 1; display: flex; gap: 6px; align-items: center; }
.formula-row .grow input { flex: 1; }
.formula-name { width: 80px; text-transform: uppercase; }
.formula-check { width: 100%; min-height: 1.4em; }

/* ---- Suggest menu ---- */
.suggest .menu-panel { width: 340px; padding: var(--space-3); gap: var(--space-2); }
.suggest-form { display: flex; flex-direction: column; gap: var(--space-2); }
.suggest-form input[type=number] { width: 110px; }
.suggest-form .btn { align-self: flex-start; }
.suggest .menu-panel form:last-child .menu-item { padding-left: 4px; }

/* ---- Compare ---- */
.pedigree-card { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-4); margin: 0 0 var(--space-3); padding: 10px var(--space-4); background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.pedigree-card > div { flex: 1; min-width: 260px; }
.pedigree-progress:empty { display: none; }
details.help { margin-top: var(--space-3); font-size: var(--text-sm); color: var(--muted); }
details.help > summary { cursor: pointer; color: var(--accent); width: fit-content; }
details.help ul { margin: 6px 0 0; padding-left: 18px; }

/* ---- Accessibility / print ---- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
@media print {
  .site-header, .site-footer, .toolbar, .selection, .status-strip, .summary-panel, .page-actions, .rename, .toasts, .pedigree-card, details.help { display: none !important; }
  main { padding: 0; max-width: none; }
  .grid-area { display: block; }
  .tabulator { border: none; }
}
