/**
 * Dog Pedigree — front-end styles.
 *
 * Colours are derived from a small set of custom properties so a theme can
 * restyle the charts by overriding .dogped without touching this file.
 */

.dogped {
	--dogped-border: #d9d9de;
	--dogped-bg: #fff;
	--dogped-bg-alt: #f7f7f9;
	--dogped-text: inherit;
	--dogped-muted: #6b6b76;
	--dogped-male: #3d6fb4;
	--dogped-female: #b4517d;
	--dogped-radius: 4px;
	--dogped-gap: 4px;

	color: var(--dogped-text);
	box-sizing: border-box;
}

.dogped *,
.dogped *::before,
.dogped *::after {
	box-sizing: inherit;
}

/* ---------------------------------------------------------------- Node card */

.dogped-node {
	display: flex;
	align-items: center;
	gap: 8px;
	min-width: 0;
	padding: 6px 8px;
	line-height: 1.35;
}

.dogped-node__body {
	display: flex;
	flex-direction: column;
	gap: 1px;
	min-width: 0;
}

.dogped-node__role {
	position: absolute;
	top: 4px;
	left: 8px;
	font-size: 0.65em;
	font-weight: 600;
	text-transform: uppercase;
	letter-spacing: 0.06em;
	color: var(--dogped-muted);
}

.dogped-node__name {
	font-weight: 600;
	overflow-wrap: anywhere;
}

.dogped-node__link {
	color: inherit;
	text-decoration: none;
}

.dogped-node__link:hover,
.dogped-node__link:focus {
	text-decoration: underline;
}

.dogped-node__titles {
	font-size: 0.75em;
	font-weight: 600;
	color: var(--dogped-muted);
	overflow-wrap: anywhere;
}

.dogped-node__meta {
	font-size: 0.78em;
	color: var(--dogped-muted);
}

.dogped-node__photo-wrap {
	flex: 0 0 auto;
}

.dogped-node__photo {
	display: block;
	width: 40px;
	height: 40px;
	border-radius: 50%;
	object-fit: cover;
}

.dogped-node--empty .dogped-node__name {
	font-weight: 400;
	font-style: italic;
	color: var(--dogped-muted);
}

/* A quiet sex indicator: a coloured rule rather than pink and blue fills. */
.dogped-node--male {
	box-shadow: inset 3px 0 0 var(--dogped-male);
}

.dogped-node--female {
	box-shadow: inset 3px 0 0 var(--dogped-female);
}

/* -------------------------------------------------------------- Subject card */

.dogped__subject {
	margin-bottom: 12px;
}

.dogped__subject .dogped-node {
	padding: 10px 12px;
	background: var(--dogped-bg-alt);
	border: 1px solid var(--dogped-border);
	border-radius: var(--dogped-radius);
}

.dogped__subject .dogped-node__name {
	font-size: 1.15em;
}

.dogped__subject .dogped-node__photo {
	width: 56px;
	height: 56px;
}

/* -------------------------------------------------------- Classic gen. table */

.dogped__scroller {
	overflow-x: auto;
	-webkit-overflow-scrolling: touch;
}

.dogped-table {
	width: 100%;
	min-width: 640px;
	border-collapse: separate;
	border-spacing: var(--dogped-gap);
	table-layout: fixed;
	margin: 0;
}

.dogped-table th {
	padding: 4px 8px;
	font-size: 0.72em;
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: 0.06em;
	color: var(--dogped-muted);
	text-align: left;
	border: 0;
}

.dogped-table__cell {
	position: relative;
	padding: 0;
	background: var(--dogped-bg);
	border: 1px solid var(--dogped-border);
	border-radius: var(--dogped-radius);
	vertical-align: middle;
}

/* Later generations are known in less detail, so they get less room. */
.dogped-table__cell--gen1 {
	background: var(--dogped-bg-alt);
}

.dogped-table__cell--gen1 .dogped-node {
	padding-top: 18px;
}

.dogped-table__cell--gen3 .dogped-node__photo,
.dogped-table__cell--gen4 .dogped-node__photo {
	width: 28px;
	height: 28px;
}

.dogped-table__cell--gen4 .dogped-node,
.dogped-table__cell--gen5 .dogped-node,
.dogped-table__cell--gen6 .dogped-node,
.dogped-table__cell--gen7 .dogped-node,
.dogped-table__cell--gen8 .dogped-node {
	font-size: 0.85em;
	padding: 4px 6px;
}

.dogped-table__cell--empty {
	background: transparent;
	border-style: dashed;
}

/* Charts deeper than five generations cannot show photos legibly. */
.dogped--table[data-generations="6"] .dogped-node__photo-wrap,
.dogped--table[data-generations="7"] .dogped-node__photo-wrap,
.dogped--table[data-generations="8"] .dogped-node__photo-wrap {
	display: none;
}

.dogped--table[data-generations="6"] .dogped-table,
.dogped--table[data-generations="7"] .dogped-table,
.dogped--table[data-generations="8"] .dogped-table {
	min-width: 900px;
}

/* ------------------------------------------------------------ Expandable tree */

.dogped-tree,
.dogped-tree__children {
	margin: 0;
	padding: 0;
	list-style: none;
}

.dogped-tree__children {
	margin-left: 14px;
	padding-left: 14px;
	border-left: 1px solid var(--dogped-border);
}

.dogped-tree__item {
	margin: 0;
	padding: 0;
}

.dogped-tree__row {
	display: flex;
	align-items: center;
	gap: 2px;
	margin: 2px 0;
}

.dogped-tree__row .dogped-node {
	flex: 1 1 auto;
	background: var(--dogped-bg);
	border: 1px solid var(--dogped-border);
	border-radius: var(--dogped-radius);
	position: relative;
	padding-left: 10px;
}

.dogped-tree .dogped-node__role {
	position: static;
	margin-bottom: 1px;
}

.dogped-tree__toggle {
	flex: 0 0 auto;
	display: flex;
	align-items: center;
	justify-content: center;
	width: 24px;
	height: 24px;
	padding: 0;
	background: none;
	border: 0;
	border-radius: 50%;
	cursor: pointer;
	color: var(--dogped-muted);
}

.dogped-tree__toggle:hover {
	background: var(--dogped-bg-alt);
	color: inherit;
}

.dogped-tree__toggle:focus-visible {
	outline: 2px solid currentColor;
	outline-offset: 1px;
}

.dogped-tree__toggle--leaf {
	cursor: default;
}

.dogped-tree__chevron {
	width: 0;
	height: 0;
	border-top: 4px solid transparent;
	border-bottom: 4px solid transparent;
	border-left: 6px solid currentColor;
	transition: transform 0.15s ease;
}

@media (prefers-reduced-motion: reduce) {
	.dogped-tree__chevron {
		transition: none;
	}
}

/* Rotation and collapsing are driven by aria-expanded, so the accessible state
   and the visible state cannot drift apart. */
.dogped-tree__item[aria-expanded="true"] > .dogped-tree__row .dogped-tree__chevron {
	transform: rotate(90deg);
}

.dogped-tree__item[aria-expanded="false"] > .dogped-tree__children {
	display: none;
}

/* --------------------------------------------------------------- Detail table */

.dogped-profile {
	width: 100%;
	border-collapse: collapse;
	margin: 0 0 1em;
}

.dogped-profile th,
.dogped-profile td {
	padding: 7px 10px;
	text-align: left;
	vertical-align: top;
	border-bottom: 1px solid var(--dogped-border);
}

.dogped-profile th {
	width: 34%;
	font-weight: 600;
	color: var(--dogped-muted);
}

.dogped-profile tr:last-child th,
.dogped-profile tr:last-child td {
	border-bottom: 0;
}

.dogped-profile__age {
	color: var(--dogped-muted);
}

.dogped-profile__heading {
	margin: 1.2em 0 0.4em;
}

.dogped-profile--health th {
	width: auto;
	color: inherit;
}

/* ---------------------------------------------------------------------- Grid */

.dogped-grid {
	display: grid;
	gap: 12px;
	margin: 0;
	padding: 0;
	list-style: none;
	grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
}

.dogped-grid--cols1 { grid-template-columns: 1fr; }
.dogped-grid--cols2 { grid-template-columns: repeat(2, 1fr); }
.dogped-grid--cols3 { grid-template-columns: repeat(3, 1fr); }
.dogped-grid--cols4 { grid-template-columns: repeat(4, 1fr); }
.dogped-grid--cols5 { grid-template-columns: repeat(5, 1fr); }
.dogped-grid--cols6 { grid-template-columns: repeat(6, 1fr); }

.dogped-grid__item {
	margin: 0;
}

.dogped-grid__item .dogped-node {
	height: 100%;
	padding: 10px;
	background: var(--dogped-bg);
	border: 1px solid var(--dogped-border);
	border-radius: var(--dogped-radius);
}

.dogped-grid__item .dogped-node__photo {
	width: 52px;
	height: 52px;
}

@media (max-width: 600px) {
	.dogped-grid[class*="dogped-grid--cols"] {
		grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
	}
}

/* ------------------------------------------------------------------ Sections */

.dogped-section {
	margin: 2em 0;
}

.dogped-section__title {
	margin: 0 0 0.6em;
}

.dogped-notice {
	padding: 8px 12px;
	background: #fcf3d4;
	border-left: 4px solid #dba617;
	color: #4a3c0c;
}

.dogped .screen-reader-text {
	position: absolute;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
	border: 0;
}

/* --------------------------------------------------------------------- Print */

@media print {
	.dogped {
		--dogped-border: #999;
		--dogped-bg: #fff;
		--dogped-bg-alt: #fff;
	}

	/* A pedigree is the one thing owners actually print, so the chart must not
	   be trapped inside a scroll container or split across pages. */
	.dogped__scroller {
		overflow: visible;
	}

	.dogped-table {
		min-width: 0;
		font-size: 8pt;
		page-break-inside: avoid;
	}

	.dogped-table__cell {
		border: 1px solid #999 !important;
	}

	.dogped-node__photo-wrap,
	.dogped-tree__toggle {
		display: none;
	}

	.dogped-node__link {
		text-decoration: none;
	}

	/* Expanded regardless of what was collapsed on screen. */
	.dogped-tree__item[aria-expanded="false"] > .dogped-tree__children {
		display: block;
	}

	.dogped-notice {
		display: none;
	}
}
