@font-face {
	font-family: 'IBM Plex Sans Arabic';
	font-style: normal;
	font-weight: 400;
	font-display: swap;
	src: url('/fonts/ibm-plex-sans-arabic-arabic-400-normal.woff2') format('woff2');
}

@font-face {
	font-family: 'IBM Plex Sans Arabic';
	font-style: normal;
	font-weight: 700;
	font-display: swap;
	src: url('/fonts/ibm-plex-sans-arabic-arabic-700-normal.woff2') format('woff2');
}

/* Colours by role; the editing dialogs reuse these. Copper (--line-out, --badge) marks only people outside the line. */
:root {
	color-scheme: dark;
	--bg-top: #0a1730;
	--bg-bottom: #0d2146;
	--bg: #0b1a38;
	--surface: #12264d;
	--surface-raised: #183160;
	--text: #e6e9ef;
	--text-strong: #ffffff;
	--muted: #9aa6bd;
	--silver: #c9cfda;
	--silver-soft: rgba(201, 207, 218, 0.35);
	--focus: #ffffff;
	--error: #ffb4b4;
	--line-in: #c9cfda;
	--line-out: #e0a565;
	--box-in: #1c3a70;
	--box-in-text: #ffffff;
	--box-out: #2a2420;
	--box-out-text: #f3d9b8;
	--badge: #e0a565;
	--badge-text: #2a1a08;
	--side-area: rgba(224, 165, 101, 0.08);
	--radius: 10px;
	--font: 'IBM Plex Sans Arabic', system-ui, 'Geeza Pro', Tahoma, sans-serif;
}

*,
*::before,
*::after {
	box-sizing: border-box;
}

html {
	height: 100%;
}

body {
	margin: 0;
	min-height: 100%;
	display: flex;
	flex-direction: column;
	height: 100dvh;
	background: linear-gradient(180deg, var(--bg-top), var(--bg-bottom)) fixed;
	background-color: var(--bg);
	color: var(--text);
	font-family: var(--font);
	font-size: 16px;
	line-height: 1.5;
}

button,
input,
select {
	font: inherit;
	color: inherit;
}

:focus-visible {
	outline: 3px solid var(--focus);
	outline-offset: 2px;
}

[hidden] {
	display: none !important;
}

/* Header */
.site-header {
	display: grid;
	grid-template-columns: 1fr auto;
	grid-template-areas:
		'titles actions'
		'search legend';
	gap: 10px 16px;
	align-items: center;
	padding: 14px 20px 12px;
	border-bottom: 1px solid var(--silver-soft);
}

.titles {
	grid-area: titles;
	min-width: 0;
}

h1 {
	margin: 0;
	font-size: 1.5rem;
	font-weight: 700;
	color: var(--text-strong);
	letter-spacing: 0.3px;
}

.lineage {
	margin: 2px 0 0;
	font-size: 0.85rem;
	color: var(--muted);
}

.actions {
	grid-area: actions;
	display: flex;
	gap: 8px;
	align-items: center;
	flex-wrap: wrap;
	justify-content: flex-end;
}

.locked-note {
	padding: 2px 10px;
	border: 1px solid var(--silver);
	border-radius: 999px;
	font-size: 0.85rem;
	color: var(--silver);
}

.control {
	min-height: 40px;
	padding: 6px 14px;
	border: 1.5px solid var(--silver);
	border-radius: var(--radius);
	background: var(--surface);
	color: var(--text);
	cursor: pointer;
}

.control:hover:not(:disabled) {
	background: var(--surface-raised);
}

.control:disabled {
	opacity: 0.5;
	cursor: default;
}

.control.primary {
	background: var(--silver);
	color: var(--bg-top);
	font-weight: 700;
}

.control.primary:hover:not(:disabled) {
	background: var(--text-strong);
}

/* Search */
.search {
	grid-area: search;
	position: relative;
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 4px 10px;
	max-width: 420px;
}

.search label {
	font-size: 0.9rem;
	color: var(--muted);
}

.search input {
	flex: 1;
	min-width: 0;
	min-height: 40px;
	padding: 6px 12px;
	border: 1.5px solid var(--silver);
	border-radius: var(--radius);
	background: var(--bg-top);
}

.search-status {
	flex-basis: 100%;
	margin: 0;
	font-size: 0.8rem;
	color: var(--muted);
	min-height: 1em;
}

.search-status:empty {
	display: none;
}

.search-results {
	position: absolute;
	inset-inline: 0;
	top: 100%;
	z-index: 5;
	margin: 4px 0 0;
	padding: 4px;
	list-style: none;
	max-height: 50vh;
	overflow-y: auto;
	background: var(--surface);
	border: 1.5px solid var(--silver);
	border-radius: var(--radius);
	box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}

.search-results button {
	display: block;
	width: 100%;
	min-height: 40px;
	padding: 6px 10px;
	border: 0;
	border-radius: 6px;
	background: transparent;
	text-align: start;
	cursor: pointer;
}

.search-results button:hover {
	background: var(--surface-raised);
}

/* Legend */
.legend {
	grid-area: legend;
	display: flex;
	flex-wrap: wrap;
	gap: 6px 16px;
	margin: 0;
	padding: 0;
	list-style: none;
	font-size: 0.8rem;
	color: var(--muted);
}

.legend li {
	display: flex;
	align-items: center;
	gap: 8px;
}

.sample.person {
	position: static;
	width: auto;
	height: auto;
	padding: 2px 10px;
	cursor: default;
	box-shadow: none;
}

.sample .badge {
	margin-top: 1px;
}

.page-error {
	margin: 12px 20px 0;
	padding: 10px 14px;
	border: 1.5px solid var(--error);
	border-radius: var(--radius);
	color: var(--error);
}

/* Diagram */
.diagram {
	position: relative;
	flex: 1;
	min-height: 0;
	display: flex;
	flex-direction: column;
}

.zoom {
	position: absolute;
	inset-block-end: 14px;
	inset-inline-start: 14px;
	z-index: 2;
	display: flex;
	gap: 6px;
}

.zoom .control {
	box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
}

.canvas {
	flex: 1;
	min-height: 0;
	overflow: auto;
	outline: none;
	overscroll-behavior: contain;
}

.sizer {
	position: relative;
	margin: 0 auto;
}

.stage {
	position: absolute;
	top: 0;
	left: 0;
	transform-origin: 0 0;
}

.stage ul {
	margin: 0;
	padding: 0;
	list-style: none;
}

.lines {
	position: absolute;
	top: 0;
	left: 0;
	pointer-events: none;
	overflow: visible;
}

.lines .link,
.lines .marriage {
	fill: none;
	stroke: var(--line-in);
	stroke-width: 1.5;
}

.lines .link.outside {
	stroke: var(--line-out);
	stroke-dasharray: 5 4;
}

.lines .marriage.former {
	stroke-opacity: 0.5;
}

.lines .side-area {
	fill: var(--side-area);
	stroke: var(--line-out);
	stroke-width: 1.5;
	stroke-dasharray: 6 4;
}

.empty {
	margin: 40px 20px;
	color: var(--muted);
	direction: rtl;
}

/* Person boxes (also the legend samples) */
.person {
	position: absolute;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 1px;
	padding: 4px 8px;
	border-radius: var(--radius);
	direction: rtl;
	text-align: center;
	line-height: 1.25;
	cursor: pointer;
	box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}

.person.in-line {
	background: var(--box-in);
	border: 1.5px solid var(--line-in);
	color: var(--box-in-text);
}

.person.outside {
	background: var(--box-out);
	border: 1.5px dashed var(--line-out);
	color: var(--box-out-text);
	box-shadow: none;
}

.person .name,
.person .meta,
.person .badge {
	max-width: 100%;
	overflow: hidden;
	white-space: nowrap;
	text-overflow: ellipsis;
}

.person .name {
	font-size: 0.9rem;
	font-weight: 700;
}

.person .meta {
	font-size: 0.7rem;
	color: inherit;
}

.person .badge {
	padding: 0 8px;
	border-radius: 999px;
	background: var(--badge);
	color: var(--badge-text);
	font-size: 0.7rem;
	font-weight: 700;
	line-height: 1.5;
}

.person.former {
	opacity: 0.72;
}

.person.former.in-line {
	border-style: dotted;
}

.person .link-mark {
	position: absolute;
	top: 3px;
	inset-inline-end: 4px;
	width: 14px;
	height: 14px;
	fill: none;
	stroke: currentColor;
	stroke-width: 1.6;
	stroke-linecap: round;
}

.person:hover {
	filter: brightness(1.12);
}

.person:focus-visible {
	outline: 3px solid var(--focus);
	outline-offset: 3px;
}

.person.found {
	outline: 3px solid var(--focus);
	outline-offset: 3px;
	box-shadow: 0 0 0 7px rgba(255, 255, 255, 0.22), 0 0 22px rgba(201, 207, 218, 0.6);
}

/* Dialogs */
.dialog {
	width: min(420px, calc(100vw - 32px));
	padding: 22px 22px 18px;
	border: 1.5px solid var(--silver);
	border-radius: 14px;
	background: var(--surface);
	color: var(--text);
	box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}

.dialog::backdrop {
	background: rgba(5, 12, 26, 0.82);
	backdrop-filter: blur(3px);
}

.dialog h2 {
	margin: 0 0 6px;
	font-size: 1.25rem;
	color: var(--text-strong);
}

.dialog .hint {
	margin: 0 0 16px;
	font-size: 0.9rem;
	color: var(--muted);
}

.dialog label {
	display: block;
	margin-bottom: 6px;
	font-weight: 700;
}

.dialog input {
	width: 100%;
	min-height: 44px;
	padding: 8px 12px;
	border: 1.5px solid var(--silver);
	border-radius: var(--radius);
	background: var(--bg-top);
}

.form-error {
	min-height: 1.5em;
	margin: 8px 0 0;
	font-size: 0.9rem;
	color: var(--error);
}

.field-error {
	min-height: 0;
	margin-top: 4px;
}

.dialog-actions {
	display: flex;
	justify-content: flex-start;
	gap: 8px;
	margin-top: 8px;
}

/* Household and history dialogs */
.dialog.sheet {
	width: min(560px, calc(100vw - 32px));
	max-height: calc(100dvh - 32px);
	overflow-y: auto;
}

.dialog-head {
	display: flex;
	align-items: flex-start;
	justify-content: space-between;
	gap: 12px;
	margin-bottom: 8px;
}

.dialog-head h2 {
	margin: 0;
	min-width: 0;
	overflow-wrap: anywhere;
}

.dialog h3 {
	margin: 16px 0 6px;
	font-size: 1rem;
	color: var(--text-strong);
}

.dialog .locked-note {
	display: inline-block;
	margin: 4px 0 8px;
}

.form-status {
	margin: 0;
	font-size: 0.9rem;
	color: var(--silver);
}

.form-status:empty,
#household-error:empty,
#history-error:empty {
	display: none;
}

.crumbs {
	display: flex;
	flex-wrap: wrap;
	gap: 2px 4px;
	margin: 0 0 10px;
	padding: 0;
	list-style: none;
	font-size: 0.85rem;
	color: var(--muted);
}

.crumbs li:not(:last-child)::after {
	content: '›';
	margin-inline-start: 4px;
}

.crumbs [aria-current] {
	color: var(--text);
	font-weight: 700;
}

.crumb {
	min-height: 32px;
	padding: 2px 4px;
	border: 0;
	background: none;
	color: var(--silver);
	text-decoration: underline;
	text-underline-offset: 3px;
	cursor: pointer;
}

.person.chip {
	position: relative;
	min-width: 112px;
	max-width: 100%;
	min-height: 48px;
	padding: 4px 12px;
	box-shadow: none;
}

.person.chip.self {
	cursor: default;
}

.self-row {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 8px 12px;
}

.self-row .hint {
	margin: 0;
}

.relations {
	display: flex;
	flex-wrap: wrap;
	gap: 8px 16px;
	margin: 12px 0 0;
}

.relations div {
	display: flex;
	align-items: center;
	gap: 8px;
}

.relations dt {
	color: var(--muted);
	font-size: 0.9rem;
}

.relations dd {
	margin: 0;
}

.rows {
	display: grid;
	gap: 8px;
	margin: 0;
	padding: 0;
	list-style: none;
}

.row {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: space-between;
	gap: 8px;
}

.row-actions {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 8px;
}

.row-actions .field.check {
	margin: 0;
}

.household-actions {
	margin-top: 18px;
	padding-top: 12px;
	border-top: 1px solid var(--silver-soft);
}

.dialog-actions.wrap {
	flex-wrap: wrap;
}

.household-actions .hint {
	margin: 6px 0 0;
}

/* Form fields */
.field {
	margin: 0 0 12px;
}

.dialog select {
	width: 100%;
	min-height: 44px;
	padding: 8px 12px;
	border: 1.5px solid var(--silver);
	border-radius: var(--radius);
	background: var(--bg-top);
}

.dialog fieldset {
	margin: 0;
	padding: 0;
	border: 0;
	min-width: 0;
}

.dialog legend {
	margin-bottom: 6px;
	padding: 0;
	font-weight: 700;
}

.check {
	display: flex;
	align-items: center;
	gap: 10px;
	min-height: 40px;
}

.dialog .check label {
	margin: 0;
	font-weight: 400;
}

.dialog input[type='checkbox'],
.dialog input[type='radio'] {
	flex: none;
	width: 22px;
	min-height: 0;
	height: 22px;
	margin: 0;
	padding: 0;
	accent-color: var(--silver);
}

.dialog input[role='switch'] {
	appearance: none;
	width: 44px;
	height: 26px;
	border: 1.5px solid var(--silver);
	border-radius: 999px;
	background: var(--bg-top);
	position: relative;
	cursor: pointer;
}

.dialog input[role='switch']::before {
	content: '';
	position: absolute;
	top: 3px;
	inset-inline-start: 3px;
	width: 17px;
	height: 17px;
	border-radius: 50%;
	background: var(--muted);
}

.dialog input[role='switch']:checked {
	background: var(--silver);
}

.dialog input[role='switch']:checked::before {
	inset-inline-start: auto;
	inset-inline-end: 3px;
	background: var(--bg-top);
}

.dialog input[role='switch']:disabled {
	opacity: 0.5;
	cursor: default;
}

.choices .check {
	min-height: 44px;
}

.picks {
	max-height: 40vh;
	overflow-y: auto;
}

.house-form .hint[role='status'] {
	margin: 0 0 6px;
}

/* History */
#history-lock .field {
	margin: 4px 0 8px;
}

.history-list {
	display: grid;
	gap: 0;
	margin: 8px 0;
	padding: 0;
	list-style: none;
}

.change {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: space-between;
	gap: 4px 12px;
	padding: 10px 0;
	border-bottom: 1px solid var(--silver-soft);
}

.change p {
	margin: 0;
	flex-basis: 100%;
}

.change .what {
	flex: 1 1 60%;
	overflow-wrap: anywhere;
}

.change .meta {
	order: 3;
	font-size: 0.8rem;
	color: var(--muted);
}

.change.undone .what {
	color: var(--muted);
	text-decoration: line-through;
}

.change .note {
	text-decoration: none;
	display: inline-block;
}

@media (max-width: 640px) {
	.site-header {
		grid-template-columns: 1fr;
		grid-template-areas:
			'titles'
			'actions'
			'search'
			'legend';
		padding: 12px 16px 10px;
	}

	.actions {
		justify-content: flex-start;
	}

	h1 {
		font-size: 1.3rem;
	}

	.search {
		max-width: none;
	}

	.dialog.sheet {
		width: 100%;
		max-width: 100%;
		max-height: 92dvh;
		margin: auto 0 0;
		border-inline: 0;
		border-bottom: 0;
		border-radius: 14px 14px 0 0;
		padding: 16px 16px 20px;
	}
}

@media (prefers-reduced-motion: no-preference) {
	.person {
		transition: filter 0.15s;
	}
}
