/* ThinhDev Gia Phả – giao diện công khai */
.tdgp {
	--tdgp-accent: #8a1c1c;
	--tdgp-accent-soft: rgba(138, 28, 28, .08);
	--tdgp-gold: #b8862b;
	--tdgp-paper: #fbf8f2;
	--tdgp-line: #e6dccb;
	--tdgp-text: #1f1f1f;
	--tdgp-muted: #6b6560;
	--tdgp-m: #2f6fb0;
	--tdgp-f: #c2416b;
	--tdgp-radius: 12px;
	color: var(--tdgp-text);
	line-height: 1.55;
	box-sizing: border-box;
}
.tdgp *, .tdgp *::before, .tdgp *::after { box-sizing: border-box; }
.tdgp a { color: var(--tdgp-accent); }
.tdgp .tdgp-muted { color: var(--tdgp-muted); }
.tdgp .tdgp-note { font-size: .875em; }
.tdgp .tdgp-empty { color: var(--tdgp-muted); padding: 24px; text-align: center; background: var(--tdgp-paper); border-radius: var(--tdgp-radius); }
.tdgp .tdgp-lunar { color: #8a6d3b; }

.tdgp-btn, .tdgp button.tdgp-btn, .tdgp a.tdgp-btn {
	display: inline-flex; align-items: center; gap: 6px;
	padding: 8px 14px; border-radius: 999px; border: 1px solid var(--tdgp-accent);
	background: var(--tdgp-accent); color: #fff !important; font-size: 14px; font-weight: 600;
	text-decoration: none !important; cursor: pointer; line-height: 1.2; margin: 0;
}
.tdgp-btn:hover { filter: brightness(1.08); }
.tdgp-btn.tdgp-btn-ghost, .tdgp a.tdgp-btn.tdgp-btn-ghost, .tdgp button.tdgp-btn.tdgp-btn-ghost { background: #fff; color: var(--tdgp-accent) !important; }

/* Cổng thông tin */
.tdgp-portal-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 18px 20px; background: linear-gradient(135deg, #fff 0%, var(--tdgp-paper) 100%); border: 1px solid var(--tdgp-line); border-radius: var(--tdgp-radius); margin-bottom: 14px; }
.tdgp-portal-title { display: flex; align-items: center; gap: 14px; }
.tdgp-portal-title h2 { margin: 0; font-size: 1.5em; line-height: 1.25; color: var(--tdgp-accent); }
.tdgp-portal-title p { margin: 2px 0 0; color: var(--tdgp-muted); font-size: .95em; }
.tdgp-seal { flex: none; width: 52px; height: 52px; border-radius: 12px; background: var(--tdgp-accent); color: #fff; display: grid; place-items: center; font-size: 26px; font-weight: 700; box-shadow: inset 0 0 0 3px rgba(255,255,255,.25); font-family: Georgia, 'Times New Roman', serif; }
.tdgp-tabs { display: flex; gap: 4px; overflow-x: auto; border-bottom: 1px solid var(--tdgp-line); margin-bottom: 16px; scrollbar-width: none; }
.tdgp-tabs::-webkit-scrollbar { display: none; }
.tdgp-tab { flex: none; padding: 10px 14px; text-decoration: none !important; color: var(--tdgp-muted) !important; font-weight: 600; font-size: 15px; border-bottom: 3px solid transparent; margin-bottom: -1px; }
.tdgp-tab:hover { color: var(--tdgp-text) !important; }
.tdgp-tab.is-active { color: var(--tdgp-accent) !important; border-bottom-color: var(--tdgp-accent); }

/* Cây */
.tdgp-tree { position: relative; height: 72vh; min-height: 460px; border: 1px solid var(--tdgp-line); border-radius: var(--tdgp-radius); background: var(--tdgp-paper); overflow: hidden; display: flex; flex-direction: column; }
.tdgp-tree .tdgp-tree-loading { margin: auto; color: var(--tdgp-muted); }
.tdgp-tree.is-full { position: fixed; inset: 0; z-index: 99999; height: auto; border-radius: 0; border: 0; }
html.tdgp-noscroll, html.tdgp-noscroll body { overflow: hidden; }
.tdgp-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 8px 10px; background: #fff; border-bottom: 1px solid var(--tdgp-line); position: relative; z-index: 3; }
.tdgp-find { position: relative; flex: 1 1 220px; max-width: 360px; }
.tdgp-find input { width: 100%; padding: 7px 12px; border: 1px solid var(--tdgp-line); border-radius: 999px; font-size: 14px; background: var(--tdgp-paper); margin: 0; height: auto; }
.tdgp-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin-left: auto; }
.tdgp-tools button { padding: 6px 10px; border: 1px solid var(--tdgp-line); background: #fff; color: var(--tdgp-text); border-radius: 8px; font-size: 13px; cursor: pointer; line-height: 1.2; min-width: 32px; margin: 0; font-weight: 500; }
.tdgp-tools button:hover { border-color: var(--tdgp-accent); color: var(--tdgp-accent); }
.tdgp-sep { width: 1px; height: 22px; background: var(--tdgp-line); margin: 0 4px; }
.tdgp-stage { position: relative; flex: 1; min-height: 0; }
.tdgp-svg { display: block; width: 100%; height: 100%; cursor: grab; touch-action: none; user-select: none; -webkit-user-select: none; }
.tdgp-svg.is-panning { cursor: grabbing; }
.tdgp-card { cursor: pointer; }
.tdgp-card:hover > rect:first-of-type, .tdgp-card:focus > rect:first-of-type { stroke: var(--tdgp-gold); stroke-width: 2; }
.tdgp-card:focus { outline: none; }
.tdgp-card.is-hidden { opacity: .7; }
.tdgp-toggle { cursor: pointer; }
.tdgp-toggle:hover circle { stroke: var(--tdgp-accent); }
.tdgp-ring { animation: tdgp-pulse 1.6s ease-out 2; }
@keyframes tdgp-pulse { 0% { stroke-opacity: 1; } 50% { stroke-opacity: .25; } 100% { stroke-opacity: 1; } }
.tdgp-status { position: absolute; top: 12px; left: 50%; transform: translateX(-50%); background: rgba(31,31,31,.82); color: #fff; padding: 6px 14px; border-radius: 999px; font-size: 13px; z-index: 4; pointer-events: none; }
.tdgp-status[hidden] { display: none; }
.tdgp-legend { position: absolute; left: 10px; bottom: 10px; display: flex; flex-wrap: wrap; gap: 10px; background: rgba(255,255,255,.88); padding: 5px 10px; border-radius: 8px; font-size: 12px; color: var(--tdgp-muted); pointer-events: none; }
.tdgp-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 4px; vertical-align: -1px; }
.tdgp-legend .lg-m { background: var(--tdgp-m); }
.tdgp-legend .lg-f { background: var(--tdgp-f); }
.tdgp-legend .lg-d { background: #f4f1ea; border: 1px solid #d8cfbf; }
.tdgp-legend .lg-x { border: 1px dashed #b8ad9a; background: #fff; }

/* Bảng thông tin bên phải */
.tdgp-side { position: absolute; top: 10px; right: 10px; bottom: 10px; width: 340px; max-width: calc(100% - 20px); overflow-y: auto; background: #fff; border: 1px solid var(--tdgp-line); border-radius: var(--tdgp-radius); box-shadow: 0 10px 30px rgba(60, 40, 10, .12); padding: 16px; z-index: 5; font-size: 14px; }
.tdgp-side[hidden] { display: none; }
.tdgp-side h3 { margin: 0; font-size: 1.15em; line-height: 1.3; }
.tdgp-side p { margin: 2px 0 0; }
.tdgp-side-close { position: absolute; top: 8px; right: 8px; width: 30px; height: 30px; border-radius: 50%; border: 0; background: var(--tdgp-paper); color: var(--tdgp-text); font-size: 20px; line-height: 1; cursor: pointer; padding: 0; }
.tdgp-side-head { display: flex; gap: 12px; align-items: center; padding-right: 30px; margin-bottom: 12px; }
.tdgp-side-head img { width: 64px; height: 64px; border-radius: 50%; object-fit: cover; flex: none; }
.tdgp-rels { border-top: 1px solid var(--tdgp-line); padding-top: 10px; margin-top: 10px; }
.tdgp-rel { margin-bottom: 8px; }
.tdgp-rel > span { display: block; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--tdgp-muted); margin-bottom: 3px; }
.tdgp-mini { display: inline-block; margin: 0 4px 4px 0; padding: 3px 9px; border-radius: 999px; border: 1px solid var(--tdgp-line); background: #fff; font-size: 13px; cursor: pointer; color: var(--tdgp-text); line-height: 1.4; }
.tdgp-mini small { color: var(--tdgp-muted); }
.tdgp-mini.tdgp-g-m { border-left: 3px solid var(--tdgp-m); }
.tdgp-mini.tdgp-g-f { border-left: 3px solid var(--tdgp-f); }
.tdgp-mini.is-dead { background: #f7f4ee; }
.tdgp-side-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 14px; }
.tdgp-side-actions .tdgp-btn { font-size: 13px; padding: 6px 12px; }

/* Gợi ý tìm kiếm */
.tdgp-suggest { position: absolute; left: 0; right: 0; top: calc(100% + 4px); list-style: none; margin: 0; padding: 4px; background: #fff; border: 1px solid var(--tdgp-line); border-radius: 10px; box-shadow: 0 10px 24px rgba(0,0,0,.12); z-index: 20; max-height: 300px; overflow-y: auto; }
.tdgp-suggest[hidden] { display: none; }
.tdgp-suggest li { padding: 7px 10px; border-radius: 8px; cursor: pointer; margin: 0; }
.tdgp-suggest li strong { display: block; font-size: 14px; }
.tdgp-suggest li small { color: var(--tdgp-muted); font-size: 12px; }
.tdgp-suggest li.is-active, .tdgp-suggest li:hover { background: var(--tdgp-accent-soft); }
.tdgp-suggest li.is-empty { color: var(--tdgp-muted); cursor: default; }

/* Danh sách người */
.tdgp-search-form, .tdgp-kin-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; margin-bottom: 14px; }
.tdgp-search-form input[type="search"] { flex: 1 1 260px; }
.tdgp-search-form input, .tdgp-search-form select, .tdgp-kin-form input, .tdgp-inline-form select, .tdgp-converter input, .tdgp-converter select { padding: 8px 12px; border: 1px solid var(--tdgp-line); border-radius: 8px; font-size: 15px; background: #fff; margin: 0; height: auto; }
.tdgp-people { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; }
.tdgp-people li { margin: 0; }
.tdgp-people a { display: flex; gap: 10px; align-items: center; padding: 10px 12px; border: 1px solid var(--tdgp-line); border-radius: 10px; background: #fff; text-decoration: none !important; color: var(--tdgp-text) !important; height: 100%; }
.tdgp-people a:hover { border-color: var(--tdgp-gold); }
.tdgp-people li.is-dead a { background: #faf7f1; }
.tdgp-people img { width: 42px; height: 42px; border-radius: 50%; object-fit: cover; flex: none; }
.tdgp-people strong { display: block; line-height: 1.3; }
.tdgp-people small { color: var(--tdgp-muted); }
.tdgp-avatar { flex: none; width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; background: #eee; color: #777; }
.tdgp-avatar.tdgp-g-m { background: rgba(47,111,176,.12); color: var(--tdgp-m); }
.tdgp-avatar.tdgp-g-f { background: rgba(194,65,107,.12); color: var(--tdgp-f); }
.tdgp-avatar-lg { width: 88px; height: 88px; font-size: 34px; }
.tdgp-pager { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 14px; }
.tdgp-pager a, .tdgp-pager span { padding: 4px 10px; border: 1px solid var(--tdgp-line); border-radius: 6px; text-decoration: none !important; }
.tdgp-pager .is-current { background: var(--tdgp-accent); color: #fff; border-color: var(--tdgp-accent); }

/* Hồ sơ */
.tdgp-profile-head { display: flex; gap: 18px; align-items: center; margin-bottom: 18px; }
.tdgp-profile-head h2 { margin: 0 0 4px; font-size: 1.6em; line-height: 1.25; }
.tdgp-profile-head .tdgp-muted { margin: 0 0 10px; }
.tdgp-profile-photo { width: 112px; height: 112px; border-radius: 50%; object-fit: cover; flex: none; border: 3px solid #fff; box-shadow: 0 0 0 1px var(--tdgp-line); }
.tdgp-profile.is-dead .tdgp-profile-photo { filter: grayscale(.35); }
.tdgp-actions { display: flex; flex-wrap: wrap; gap: 6px; margin: 0; }
.tdgp-profile-body { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.tdgp-profile-body section { background: #fff; border: 1px solid var(--tdgp-line); border-radius: var(--tdgp-radius); padding: 14px 16px; }
.tdgp-profile-body section h3 { margin: 0 0 10px; font-size: 1.05em; color: var(--tdgp-accent); }
.tdgp-profile-body .tdgp-bio { grid-column: 1 / -1; }
.tdgp-dl { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; margin: 0; }
.tdgp-dl dt { color: var(--tdgp-muted); font-weight: 400; margin: 0; }
.tdgp-dl dd { margin: 0; }
.tdgp-chip { display: inline-block; padding: 2px 10px; margin: 0 4px 4px 0; border-radius: 999px; border: 1px solid var(--tdgp-line); background: #fff; }
.tdgp-chip small { color: var(--tdgp-muted); }
.tdgp-chip.tdgp-g-m { border-left: 3px solid var(--tdgp-m); }
.tdgp-chip.tdgp-g-f { border-left: 3px solid var(--tdgp-f); }
.tdgp-chip.is-dead { background: #faf7f1; }
.tdgp-lineage { line-height: 1.9; }

/* Lịch giỗ */
.tdgp-today { font-size: 1.05em; }
.tdgp-events { list-style: none; margin: 12px 0; padding: 0; }
.tdgp-ev { display: flex; gap: 14px; align-items: center; padding: 10px 12px; border: 1px solid var(--tdgp-line); border-radius: 10px; margin: 0 0 8px; background: #fff; }
.tdgp-ev.is-soon { border-color: var(--tdgp-gold); background: #fffaf0; }
.tdgp-ev-date { flex: none; width: 64px; text-align: center; border-radius: 8px; background: var(--tdgp-accent-soft); color: var(--tdgp-accent); padding: 6px 0; line-height: 1.2; }
.tdgp-ev-day { display: block; font-size: 1.5em; font-weight: 700; }
.tdgp-ev-date span:last-child { font-size: 12px; }
.tdgp-ev-body { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.tdgp-ev-body span { font-size: .9em; }
.tdgp-ev-when { flex: none; font-size: 13px; font-weight: 600; color: var(--tdgp-accent); }
.tdgp-converter { margin-top: 18px; padding: 14px 16px; border: 1px dashed var(--tdgp-line); border-radius: var(--tdgp-radius); }
.tdgp-converter h3 { margin: 0 0 8px; font-size: 1em; }
.tdgp-converter-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.tdgp-converter input[type="number"] { width: 84px; }
.tdgp-converter-out { margin: 8px 0 0; font-weight: 600; color: var(--tdgp-accent); }

/* Theo đời, chi */
.tdgp-gen-bar { list-style: none; margin: 0 0 16px; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.tdgp-gen-bar li { margin: 0; }
.tdgp-gen-bar a { display: flex; flex-direction: column; padding: 6px 12px; border: 1px solid var(--tdgp-line); border-radius: 10px; text-decoration: none !important; color: var(--tdgp-text) !important; line-height: 1.3; background: #fff; }
.tdgp-gen-bar a span { font-size: 12px; color: var(--tdgp-muted); }
.tdgp-gen-bar a.is-active { background: var(--tdgp-accent); border-color: var(--tdgp-accent); color: #fff !important; }
.tdgp-gen-bar a.is-active span { color: rgba(255,255,255,.8); }
.tdgp-branch-list { list-style: none; margin: 0; padding: 0; }
.tdgp-branch-list li { margin: 0 0 8px calc(var(--depth, 0) * 22px); padding: 10px 14px; border: 1px solid var(--tdgp-line); border-left: 4px solid var(--tdgp-gold); border-radius: 10px; background: #fff; }
.tdgp-branch-list p { margin: 4px 0 0; }

/* Danh xưng */
.tdgp-picker { position: relative; display: flex; flex-direction: column; gap: 4px; flex: 1 1 220px; }
.tdgp-picker label { font-size: 13px; color: var(--tdgp-muted); }
.tdgp-picker.is-picked input[type="text"] { border-color: var(--tdgp-gold); background: #fffaf0; }
.tdgp-kin-result { padding: 16px 18px; border-radius: var(--tdgp-radius); background: #fffaf0; border: 1px solid #ecdcb5; }
.tdgp-kin-result.is-none { background: var(--tdgp-paper); border-color: var(--tdgp-line); }
.tdgp-kin-term { font-size: 1.2em; margin: 0 0 6px; }
.tdgp-kin-term strong { color: var(--tdgp-accent); }

/* Giới thiệu */
.tdgp-stats { list-style: none; display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin: 0 0 16px; padding: 0; }
.tdgp-stats li { margin: 0; background: #fff; border: 1px solid var(--tdgp-line); border-radius: 10px; padding: 12px; text-align: center; }
.tdgp-stats strong { display: block; font-size: 1.6em; color: var(--tdgp-accent); line-height: 1.2; }
.tdgp-stats span { font-size: 13px; color: var(--tdgp-muted); }
.tdgp-locked { padding: 28px; text-align: center; background: var(--tdgp-paper); border: 1px solid var(--tdgp-line); border-radius: var(--tdgp-radius); }

@media (max-width: 720px) {
	.tdgp-profile-body { grid-template-columns: 1fr; }
	.tdgp-profile-head { flex-direction: column; align-items: flex-start; }
	.tdgp-tree { height: 78vh; min-height: 420px; }
	.tdgp-tools { margin-left: 0; }
	.tdgp-tools button[data-act="fit"], .tdgp-tools .tdgp-sep { display: none; }
	.tdgp-side { top: auto; left: 0; right: 0; bottom: 0; width: auto; max-width: none; max-height: 62%; border-radius: 16px 16px 0 0; }
	.tdgp-legend { display: none; }
	.tdgp-dl { grid-template-columns: 1fr; gap: 0; }
	.tdgp-dl dd { margin-bottom: 8px; }
	.tdgp-ev { flex-wrap: wrap; }
	.tdgp-ev-when { width: 100%; }
}
@media print {
	.tdgp-toolbar, .tdgp-legend, .tdgp-side, .tdgp-tabs { display: none !important; }
}
