:root {
  --bg: #f4efe2;
  --panel: #fffaf0;
  --panel-strong: #f8f0dc;
  --text: #27301f;
  --muted: #66705f;
  --line: #d8ceb9;
  --green: #4f5f45;
  --green-dark: #34402f;
  --gold: #b98b2d;
  --shadow: rgba(38, 48, 31, 0.14);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: linear-gradient(180deg, #e9e1cf 0%, var(--bg) 320px);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.45;
}

a { color: var(--green-dark); font-weight: 700; text-decoration: none; }
a:hover { text-decoration: underline; }

.site-header {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  padding: 1rem clamp(1rem, 4vw, 3rem);
  background: rgba(79, 95, 69, 0.96);
  color: white;
  box-shadow: 0 2px 18px var(--shadow);
}

.site-header a { color: white; }
.brand { display: flex; flex-direction: column; gap: .15rem; }
.brand > a { font-size: 1.15rem; letter-spacing: .02em; }
.subtle { opacity: .78; font-size: .84rem; }
nav { display: flex; gap: 1rem; align-items: center; }

.page {
  width: min(1180px, calc(100% - 2rem));
  margin: 1.5rem auto 3rem;
}

.panel {
  background: rgba(255, 250, 240, 0.94);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 1.25rem;
  box-shadow: 0 8px 28px var(--shadow);
  margin-bottom: 1.25rem;
}

.hero {
  padding: clamp(1.5rem, 4vw, 3rem);
  background: linear-gradient(135deg, rgba(79,95,69,.96), rgba(52,64,47,.94));
  color: white;
  border: none;
}
.hero.compact { padding: 1.5rem; }
.hero h1 { margin-top: 0; font-size: clamp(2rem, 4vw, 3.25rem); line-height: 1.05; }
.hero.compact h1 { font-size: clamp(1.8rem, 3vw, 2.4rem); }
.hero p { max-width: 780px; }
.hero .muted, .hero a { color: #f4efe2; }

.search-row {
  display: flex;
  gap: .75rem;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 1.25rem;
}

input, select, button, .button {
  border-radius: 999px;
  border: 1px solid var(--line);
  font: inherit;
  padding: .75rem 1rem;
}

input { min-width: min(100%, 420px); flex: 1; }
button, .button {
  background: var(--gold);
  color: #1f211a;
  font-weight: 800;
  border: none;
  cursor: pointer;
  display: inline-block;
}
.button.secondary { background: var(--panel-strong); border: 1px solid var(--line); }
button:hover, .button:hover { filter: brightness(.96); text-decoration: none; }

.grid { display: grid; gap: 1.25rem; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.stats-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; margin-bottom: 1.25rem; }
.stat-card { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 1.25rem; box-shadow: 0 8px 28px var(--shadow); }
.stat-number { display: block; font-size: 2rem; font-weight: 900; color: var(--green-dark); }
.stat-label { color: var(--muted); }

.clean-list { list-style: none; padding: 0; margin: 0; }
.clean-list li { padding: .35rem 0; border-bottom: 1px solid rgba(216,206,185,.6); }
.clean-list li:last-child { border-bottom: none; }
.links-list a { display: block; }

.chip-row { display: flex; flex-wrap: wrap; gap: .5rem; }
.chip { background: var(--panel-strong); border: 1px solid var(--line); border-radius: 999px; padding: .45rem .75rem; font-size: .92rem; }

.table-wrap { overflow-x: auto; border-radius: 14px; border: 1px solid var(--line); }
table { width: 100%; border-collapse: collapse; min-width: 760px; background: white; }
th, td { padding: .65rem .75rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; font-size: .92rem; }
th { background: var(--panel-strong); color: var(--green-dark); position: sticky; top: 0; z-index: 1; }
tr:hover td { background: #fff8e8; }

.detail-grid { display: grid; grid-template-columns: minmax(170px, 260px) 1fr; gap: .25rem 1rem; }
dt { font-weight: 800; color: var(--green-dark); border-top: 1px solid var(--line); padding-top: .5rem; }
dd { margin: 0; border-top: 1px solid var(--line); padding-top: .5rem; overflow-wrap: anywhere; }

.mini h2 { margin-top: 0; }
.muted { color: var(--muted); }
.breadcrumb { font-size: .9rem; opacity: .85; margin-bottom: .75rem; }
.pager { display: flex; gap: .75rem; align-items: center; justify-content: center; margin-top: 1rem; }
pre { white-space: pre-wrap; background: #2d3429; color: #f4efe2; padding: 1rem; border-radius: 12px; overflow-x: auto; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; }
.site-footer { width: min(1180px, calc(100% - 2rem)); margin: 0 auto 2rem; color: var(--muted); font-size: .85rem; }

@media (max-width: 760px) {
  .site-header { align-items: flex-start; flex-direction: column; }
  .grid.two, .stats-grid { grid-template-columns: 1fr; }
  .search-row { align-items: stretch; }
  input, select, button, .button { width: 100%; }
  .detail-grid { grid-template-columns: 1fr; }
  dd { padding-bottom: .5rem; }
}

.button-row { display: flex; gap: .75rem; flex-wrap: wrap; margin-top: 1rem; }
.warning { background: #fff1d6; color: #5f3512; padding: .75rem 1rem; border-radius: 12px; margin-top: 1rem; }
.search-row.tight { margin-top: .75rem; }

.pedigree-panel { overflow: hidden; }
.pedigree-toolbar { display: flex; justify-content: space-between; gap: 1rem; align-items: baseline; flex-wrap: wrap; }
.pedigree-toolbar h2 { margin: 0; }
.pedigree-chart {
  display: grid;
  grid-template-columns: repeat(5, minmax(220px, 1fr));
  grid-template-rows: 34px repeat(var(--pedigree-rows), minmax(92px, auto));
  gap: .55rem .75rem;
  overflow-x: auto;
  min-width: 1180px;
  padding: .25rem 0 1rem;
}
.generation-label {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--panel-strong);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: .35rem .65rem;
  text-align: center;
  font-weight: 900;
  color: var(--green-dark);
}
.pedigree-card {
  align-self: center;
  min-height: 82px;
  background: white;
  border: 1px solid var(--line);
  border-left: 5px solid var(--green);
  border-radius: 14px;
  padding: .55rem .65rem;
  box-shadow: 0 4px 15px var(--shadow);
  font-size: .82rem;
  overflow-wrap: anywhere;
}
.pedigree-card.missing {
  opacity: .42;
  border-left-color: var(--line);
  background: #faf7ef;
}
.pedigree-label {
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  font-weight: 800;
}
.pedigree-name {
  font-weight: 900;
  color: var(--green-dark);
  margin: .15rem 0 .25rem;
  line-height: 1.2;
}
.pedigree-card.gen-1 { border-left-color: var(--gold); }
.pedigree-card.gen-2 { font-size: .84rem; }
.pedigree-card.gen-4, .pedigree-card.gen-5 { font-size: .78rem; }

@media (min-width: 1100px) {
  .grid.three-if-wide { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media print {
  .site-header, .site-footer, .button-row, .pedigree-toolbar .muted { display: none; }
  .page { width: 100%; margin: 0; }
  .panel { box-shadow: none; border: none; }
  .pedigree-chart { min-width: 0; grid-template-columns: repeat(5, 1fr); gap: .25rem; }
  .pedigree-card { box-shadow: none; font-size: .68rem; padding: .35rem; }
}

.trait-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: .75rem;
  margin-top: 1rem;
}
.trait-card {
  background: white;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: .75rem .85rem;
  box-shadow: 0 4px 15px var(--shadow);
}
.trait-label {
  display: block;
  font-size: .76rem;
  color: var(--muted);
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-bottom: .25rem;
}
.trait-card strong {
  display: block;
  font-size: 1.35rem;
  color: var(--green-dark);
  overflow-wrap: anywhere;
}


.inline-chart { margin-top: 1.25rem; }
.inline-chart h3 { margin-bottom: .35rem; }
.bar-chart { display: grid; gap: .85rem; margin-top: 1rem; }
.bar-row { display: grid; gap: .35rem; }
.bar-meta { display: flex; justify-content: space-between; gap: 1rem; align-items: baseline; }
.bar-label { font-weight: 800; color: var(--green-dark); }
.bar-value { color: var(--text); }
.bar-track { position: relative; height: 18px; background: #efe6d2; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--gold), var(--green)); }


.chart-group {
  margin-top: 1.4rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
}
.chart-group:first-of-type { border-top: none; }
.chart-group-header {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: baseline;
  flex-wrap: wrap;
  margin-bottom: .75rem;
}
.chart-group-header h3,
.chart-group-header h4 {
  margin: 0;
  color: var(--green-dark);
}
.chart-group-header .muted { margin: 0; }

.vertical-chart {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(92px, 1fr));
  gap: .8rem;
  align-items: end;
  min-height: 260px;
  padding: 1rem .5rem .4rem;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255,255,255,.72);
}
.compact-vertical-chart { min-height: 220px; }

.vertical-bar-item {
  min-width: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: .4rem;
  height: 100%;
  text-align: center;
}
.vertical-bar-value {
  font-weight: 900;
  color: var(--green-dark);
  font-size: .95rem;
}
.vertical-bar-track {
  height: 170px;
  border: 1px solid var(--line);
  border-radius: 12px 12px 8px 8px;
  background: #efe6d2;
  display: flex;
  align-items: end;
  overflow: hidden;
}
.compact-vertical-chart .vertical-bar-track { height: 135px; }
.vertical-bar-fill {
  width: 100%;
  min-height: 2px;
  border-radius: 12px 12px 0 0;
  background: linear-gradient(180deg, var(--gold), var(--green));
}
.vertical-bar-label {
  font-size: .78rem;
  line-height: 1.15;
  color: var(--text);
  font-weight: 750;
  min-height: 2.4em;
  overflow-wrap: anywhere;
}

@media (max-width: 760px) {
  .vertical-chart {
    grid-template-columns: repeat(auto-fit, minmax(76px, 1fr));
    min-height: 220px;
  }
  .vertical-bar-track { height: 135px; }
}


/* Igenity summary cards should stay compact and read horizontally */
.trait-grid {
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}
@media (min-width: 980px) {
  .trait-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}


/* Refined Igenity horizontal bar charts */
.horizontal-chart {
  display: grid;
  gap: .85rem;
  margin-top: 1rem;
}
.horizontal-chart .bar-row {
  display: grid;
  grid-template-columns: minmax(150px, 260px) minmax(80px, 1fr);
  gap: .75rem;
  align-items: center;
}
.horizontal-chart .bar-meta {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: .6rem;
  align-items: baseline;
}
.horizontal-chart .bar-label {
  font-weight: 850;
  color: var(--green-dark);
  overflow-wrap: anywhere;
}
.horizontal-chart .bar-value {
  color: var(--text);
  white-space: nowrap;
}
.horizontal-chart .bar-track {
  height: 22px;
  background: #efe6d2;
  border: 1px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
}
.horizontal-chart .bar-fill {
  height: 100%;
  min-width: 2px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--gold), var(--green));
}

@media (max-width: 760px) {
  .horizontal-chart .bar-row {
    grid-template-columns: 1fr;
    gap: .35rem;
  }
}


/* Make breadcrumb/top links readable on green hero panels */
.hero .breadcrumb a,
.hero .button.secondary,
.hero a.button.secondary {
  color: var(--green-dark);
}
.hero .breadcrumb {
  color: #f4efe2;
}
.hero .breadcrumb a {
  background: #f4efe2;
  border-radius: 999px;
  padding: .25rem .55rem;
  display: inline-block;
}


.inline-open-link {
  display: inline-block;
  background: var(--panel-strong);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: .25rem .65rem;
  font-weight: 900;
  white-space: nowrap;
}


/* Homepage background summary */
.intro-panel p {
  font-size: 1rem;
  max-width: 920px;
}


/* Header logo */
.brand-with-logo {
  flex-direction: row;
  align-items: center;
  gap: .75rem;
}
.logo-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
}
.site-logo {
  width: 54px;
  height: 54px;
  object-fit: contain;
  border-radius: 10px;
  background: rgba(255, 250, 240, .92);
  padding: .25rem;
  box-shadow: 0 2px 10px rgba(0,0,0,.18);
}
.brand-text {
  display: flex;
  flex-direction: column;
  gap: .15rem;
}

@media (max-width: 760px) {
  .site-logo {
    width: 46px;
    height: 46px;
  }
}


/* Logo recolored to app green */
.site-logo {
  background: #f4efe2;
}


/* Search result row action links */
.action-links {
  white-space: nowrap;
  min-width: 220px;
}
.action-links .inline-open-link {
  margin-right: .35rem;
  margin-bottom: .25rem;
}
.inline-open-link {
  display: inline-block;
  background: var(--panel-strong);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: .25rem .65rem;
  font-weight: 900;
  white-space: nowrap;
}


/* Disabled row action links for missing data */
.disabled-link {
  color: #8b897f;
  background: #ebe5d7;
  border-color: #d2c8b5;
  cursor: not-allowed;
  opacity: .65;
}
.disabled-link:hover {
  text-decoration: none;
  filter: none;
}

.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 1rem;
  margin: 1rem 0;
}
.photo-card {
  background: white;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: .75rem;
  box-shadow: 0 4px 15px var(--shadow);
}
.photo-card img {
  width: 100%;
  height: 220px;
  object-fit: cover;
  border-radius: 12px;
  display: block;
}
.photo-caption {
  margin: .65rem 0 .25rem;
  font-weight: 700;
}
.small { font-size: .8rem; }
.upload-form {
  display: grid;
  gap: .75rem;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
}
.upload-form label {
  display: grid;
  gap: .35rem;
  font-weight: 800;
  color: var(--green-dark);
}
.upload-form input[type="file"] {
  background: white;
  border-radius: 14px;
  min-width: 0;
}
.button.danger,
button.danger {
  background: #f2d7ca;
  color: #5c251b;
  border: 1px solid #d8aa98;
  padding: .5rem .75rem;
  font-size: .86rem;
}


/* Selected animal dropdowns and upload helpers */
.search-row select { min-width: min(100%, 420px); flex: 1; }
.inline-label { display: grid; gap: .35rem; font-weight: 800; color: var(--green-dark); margin-bottom: 1rem; }
.raw-table table { min-width: 1100px; }
.index-cards { margin-top: 1rem; }
.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 1rem;
  margin: 1rem 0;
}
.photo-card {
  background: white;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: .75rem;
  box-shadow: 0 4px 15px var(--shadow);
}
.photo-card img {
  width: 100%;
  height: 220px;
  object-fit: cover;
  border-radius: 12px;
  display: block;
}
.photo-caption { margin: .65rem 0 .25rem; font-weight: 700; }
.small { font-size: .8rem; }
.upload-form {
  display: grid;
  gap: .75rem;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
}
.upload-form label { display: grid; gap: .35rem; font-weight: 800; color: var(--green-dark); }
.upload-form input[type="file"] { background: white; border-radius: 14px; min-width: 0; }
.button.danger, button.danger { background: #f2d7ca; color: #5c251b; border: 1px solid #d8aa98; padding: .5rem .75rem; font-size: .86rem; }


/* Animal search result thumbnail */
.animal-actions-cell {
  position: relative;
  min-width: 300px;
  padding-right: 82px;
  vertical-align: top;
}
.animal-action-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: .25rem;
}
.animal-result-thumb-link {
  position: absolute;
  top: .45rem;
  right: .5rem;
  display: block;
  width: 62px;
  height: 62px;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--line);
  box-shadow: 0 3px 10px var(--shadow);
  background: white;
}
.animal-result-thumb-link:hover {
  filter: brightness(1.04);
  transform: translateY(-1px);
}
.animal-result-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Animal photo thumbnail on Profile / Pedigree / Igenity hero panels */
.hero-with-photo {
  position: relative;
  min-height: 210px;
  padding-right: clamp(1.5rem, 4vw, 12rem);
}
.hero-photo-link {
  position: absolute;
  top: 1.35rem;
  right: 1.35rem;
  width: clamp(92px, 10vw, 140px);
  height: clamp(92px, 10vw, 140px);
  display: block;
  border-radius: 18px;
  overflow: hidden;
  border: 2px solid rgba(244, 239, 226, .85);
  box-shadow: 0 10px 28px rgba(0, 0, 0, .24);
  background: rgba(255, 255, 255, .12);
}
.hero-photo-link:hover {
  transform: translateY(-1px);
  filter: brightness(1.04);
  text-decoration: none;
}
.hero-photo-thumb {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}
@media (max-width: 720px) {
  .hero-with-photo {
    padding-right: 1.25rem;
    padding-top: 7.5rem;
  }
  .hero-photo-link {
    top: 1rem;
    left: 1.25rem;
    right: auto;
    width: 92px;
    height: 92px;
  }
}

/* Igenity import preview select-all controls */
.import-select-toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: .8rem 1.2rem;
  margin: 1rem 0;
  padding: .85rem 1rem;
  border-radius: 18px;
  background: rgba(255,255,255,.55);
  border: 1px solid rgba(71,83,63,.18);
}
.select-all-label {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  font-weight: 800;
  color: var(--green-deep, #2f3f2e);
}
.select-all-label input,
.igenity-row-checkbox {
  width: 1.05rem;
  height: 1.05rem;
}

/* MasterDB update admin pages */
.stat-panel h2 {
  margin: 0;
  color: var(--green-dark);
  font-size: 2rem;
}
.stat-panel p {
  margin: .25rem 0 0;
  color: var(--muted);
  font-weight: 700;
}
.status-pill {
  display: inline-block;
  padding: .22rem .55rem;
  border-radius: 999px;
  font-weight: 900;
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .03em;
  background: var(--panel-strong);
  color: var(--green-dark);
}
.status-update { background: #e4eefc; color: #1f466f; }
.status-add { background: #e3f2df; color: #2f5a25; }
.status-review { background: #fff1d6; color: #6a4309; }
.status-skip { background: #ece9df; color: #5b594e; }
details summary { cursor: pointer; font-weight: 800; }
