:root {
  --green-950: #102f22;
  --green-900: #153f2c;
  --green-800: #24553a;
  --green-700: #376b48;
  --paper: #fffdf7;
  --cream: #f4ecda;
  --cream-2: #eee1c5;
  --line: rgba(92, 70, 33, .18);
  --gold: #d29a28;
  --gold-light: #fff0a6;
  --text: #27382d;
  --muted: #796f58;
  --shadow: 0 18px 50px rgba(49, 35, 13, .14);
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; }
body { overflow: hidden; font-family: Tahoma, Arial, sans-serif; color: var(--text); background: var(--cream); }
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

.app-shell { height: 100%; display: grid; grid-template-rows: 84px minmax(0, 1fr); }
.topbar {
  position: relative; z-index: 80; height: 84px; display: grid;
  grid-template-columns: minmax(310px, 1fr) auto minmax(230px, 1fr);
  align-items: center; gap: 18px; padding: 8px 20px;
  background: rgba(255, 253, 247, .97); border-bottom: 1px solid var(--line);
  box-shadow: 0 8px 28px rgba(58, 42, 17, .08); backdrop-filter: blur(14px);
}
.brand { display: flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; min-width: 0; }
.brand__mark { width: 62px; height: 62px; border-radius: 17px; overflow: hidden; border: 3px solid #c4a153; box-shadow: 0 7px 20px rgba(57, 42, 15, .18); flex: 0 0 auto; }
.brand__mark img { width: 100%; height: 100%; display: block; object-fit: cover; }
.brand__copy { min-width: 0; }
.brand h1 { margin: 0; font-size: 23px; color: var(--green-950); line-height: 1.25; }
.brand p { margin: 5px 0 0; font-size: 10.5px; color: #756642; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.main-nav { display: flex; align-items: center; justify-content: center; gap: 5px; padding: 5px; border: 1px solid rgba(90, 69, 32, .12); border-radius: 17px; background: rgba(247, 241, 227, .72); }
.nav-item { height: 43px; border: 0; border-radius: 12px; padding: 0 13px; background: transparent; color: #756e5a; font-size: 11.5px; font-weight: 800; cursor: pointer; white-space: nowrap; transition: .2s ease; }
.nav-item span { margin-left: 4px; }
.nav-item:hover { background: rgba(40, 86, 57, .08); color: var(--green-900); }
.nav-item.is-active { background: var(--green-900); color: #fff; box-shadow: 0 8px 18px rgba(21, 63, 44, .22); }
.nav-item--relationship.is-active { background: #815c18; }

.header-actions { display: flex; align-items: center; justify-content: flex-start; gap: 7px; direction: rtl; }
.soft-button, .icon-button, .admin-button { border: 1px solid rgba(86, 67, 32, .16); border-radius: 12px; height: 40px; padding: 0 13px; background: #fffdf8; color: var(--green-900); font-size: 11px; font-weight: 800; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; }
.icon-button { width: 40px; padding: 0; font-size: 18px; }
.admin-button { background: #e9f0e3; }
.soft-button:hover, .icon-button:hover, .admin-button:hover { background: var(--green-900); color: #fff; }

.workspace { position: relative; min-height: 0; overflow: hidden; background: radial-gradient(circle at 50% 40%, #fffdf7 0, #f7efde 49%, #eadcbf 100%); }
.view-panel { position: absolute; inset: 0; visibility: hidden; opacity: 0; pointer-events: none; transition: opacity .22s ease, visibility .22s ease; }
.view-panel.is-active { visibility: visible; opacity: 1; pointer-events: auto; }

.search-shell {
  position: absolute; z-index: 50; top: 18px; left: 50%; transform: translateX(-50%);
  width: min(560px, calc(100% - 400px)); height: 48px; display: flex; align-items: center; gap: 10px;
  padding: 0 14px; border: 1px solid rgba(86, 67, 32, .16); border-radius: 15px;
  background: rgba(255, 253, 247, .94); box-shadow: 0 14px 35px rgba(48, 35, 14, .12); backdrop-filter: blur(10px);
  transition: opacity .18s ease, transform .18s ease;
}
.search-shell.is-hidden { opacity: 0; visibility: hidden; pointer-events: none; transform: translate(-50%, -12px); }
.search-icon { font-size: 22px; color: var(--green-800); }
.search-shell input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: #2d4033; font-size: 13px; text-align: right; }
.search-shell kbd { direction: ltr; padding: 3px 7px; border-radius: 7px; background: #eee8d9; color: #90866f; font-size: 8px; border: 1px solid #ddd2bb; }
.search-results { position: absolute; top: calc(100% + 7px); right: 0; left: 0; max-height: 420px; overflow: auto; display: none; padding: 7px; border: 1px solid var(--line); border-radius: 15px; background: #fffdf8; box-shadow: var(--shadow); }
.search-results.is-open { display: block; }
.search-result { width: 100%; border: 0; border-radius: 11px; background: transparent; text-align: right; padding: 10px 12px; display: flex; flex-direction: column; gap: 4px; cursor: pointer; color: #253c2d; }
.search-result:hover { background: #edf2e5; }
.search-result__name { font-weight: 800; }
.search-result__meta { font-size: 10px; color: #817255; }
.search-empty { padding: 22px; text-align: center; color: #87795c; }

.canvas-frame { position: absolute; inset: 0; overflow: hidden; }
#graphComponent { position: absolute; inset: 0; background: transparent; }
.canvas-vignette { position: absolute; inset: 0; pointer-events: none; box-shadow: inset 0 0 95px rgba(114, 84, 33, .12); }
.canvas-frame::after { content: 'جذورنا واحدة · وفروعنا ممتدة'; position: absolute; right: 50%; bottom: 17px; transform: translateX(50%); color: rgba(80, 65, 34, .67); font-size: 12px; font-weight: 700; pointer-events: none; }

.tree-controls { position: absolute; left: 20px; top: 88px; z-index: 25; display: flex; flex-direction: column; gap: 6px; padding: 7px; border-radius: 18px; background: rgba(255, 251, 240, .92); border: 1px solid var(--line); box-shadow: 0 13px 35px rgba(48, 35, 14, .13); }
.tree-controls button { width: 43px; height: 43px; border: 0; border-radius: 12px; background: transparent; color: var(--green-900); font-size: 24px; font-weight: 600; cursor: pointer; }
.tree-controls button:hover, .tree-controls button.is-active { background: var(--green-900); color: #fff; }
.tree-controls button:last-child { font-size: 18px; }

.legend-card { position: absolute; right: 20px; bottom: 24px; width: 205px; z-index: 20; padding: 14px 16px; border-radius: 18px; background: rgba(255, 251, 241, .92); border: 1px solid var(--line); box-shadow: var(--shadow); backdrop-filter: blur(8px); }
.legend-card h2 { margin: 0 0 10px; font-size: 14px; color: var(--green-900); }
.legend-row { display: flex; align-items: center; gap: 9px; margin: 7px 0; color: #665c43; font-size: 10.5px; }
.legend-branch, .legend-gold { width: 20px; height: 20px; border-radius: 50%; display: inline-block; flex: 0 0 auto; border: 2px solid rgba(255, 255, 255, .78); box-shadow: 0 0 0 1px rgba(60, 45, 20, .16); }
.legend-branch--mohammad { background: #4f7652; }
.legend-branch--abdullah { background: #537d9c; }
.legend-branch--abdulaziz { background: #80668f; }
.legend-branch--nasser { background: #ae7848; }
.legend-gold { background: var(--gold); border-color: var(--gold-light); }
.legend-row--separator { margin-top: 12px; padding-top: 11px; border-top: 1px dashed rgba(93, 73, 35, .18); }

.stats-strip { position: absolute; left: 83px; bottom: 23px; z-index: 20; display: flex; direction: rtl; background: rgba(255, 251, 241, .92); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); overflow: hidden; }
.stats-strip > div { min-width: 82px; padding: 10px 13px; text-align: center; border-left: 1px solid rgba(93, 73, 35, .11); }
.stats-strip > div:last-child { border-left: 0; }
.stats-strip strong { display: block; font-size: 17px; color: var(--green-900); }
.stats-strip span { font-size: 8.5px; color: #817354; }

.status-pill { position: absolute; left: 20px; bottom: 22px; transform: translateY(-75px); z-index: 28; padding: 8px 11px; border-radius: 12px; background: rgba(255, 252, 243, .9); border: 1px solid rgba(89, 70, 34, .13); display: flex; align-items: center; gap: 7px; font-size: 9.5px; color: #5f5a44; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #5c9a55; box-shadow: 0 0 0 4px rgba(92, 154, 85, .15); }
.status-pill small { color: #98885f; border-right: 1px solid #ddd0af; padding-right: 7px; }

.person-card { position: absolute; top: 84px; right: 20px; width: min(390px, calc(100% - 40px)); max-height: calc(100% - 120px); overflow: auto; z-index: 60; background: rgba(255, 252, 243, .98); border: 1px solid rgba(97, 73, 30, .22); border-radius: 24px; padding: 24px; box-shadow: 0 28px 75px rgba(50, 35, 12, .23); transform: translateX(calc(100% + 40px)); opacity: 0; pointer-events: none; transition: transform .3s ease, opacity .25s ease; backdrop-filter: blur(12px); }
.person-card.is-open { transform: translateX(0); opacity: 1; pointer-events: auto; }
.person-card__close, .panel-close { position: absolute; left: 14px; top: 13px; width: 34px; height: 34px; border: 0; border-radius: 50%; background: #eee5d2; color: #51482f; font-size: 24px; cursor: pointer; }
.person-card__eyebrow { display: flex; gap: 7px; flex-wrap: wrap; margin-bottom: 9px; }
.person-card__eyebrow span { font-size: 9.5px; background: #e9f0e2; color: #41603f; padding: 5px 8px; border-radius: 9px; font-weight: 700; }
.person-card h2 { font-size: 27px; margin: 0 0 15px; color: var(--green-950); }
.lineage-box { background: #f4ecd8; border: 1px solid #e1d1aa; border-radius: 15px; padding: 12px 14px; }
.lineage-box > span { font-size: 9.5px; color: #847653; font-weight: 700; }
.lineage-box p { margin: 6px 0 0; line-height: 1.9; font-size: 12.5px; color: #3d493d; font-weight: 650; }
.person-data { margin: 16px 0 0; display: grid; gap: 8px; }
.person-data > div { display: grid; grid-template-columns: 65px 1fr; gap: 8px; padding: 9px 0; border-bottom: 1px dashed #dfd3b6; }
.person-data dt { color: #847451; font-size: 10.5px; }
.person-data dd { margin: 0; font-weight: 700; color: #2b4433; }
.children-list { display: flex; flex-wrap: wrap; gap: 6px; }
.child-chip { border: 1px solid #c8d6bc; background: #f3f7ed; color: #31573a; border-radius: 10px; padding: 6px 9px; cursor: pointer; font-size: 10.5px; font-weight: 700; }
.child-chip:hover { background: #dfead7; }
.empty-value { font-size: 10.5px; color: #8c8063; }
.historical-text { margin-top: 15px; padding: 14px; border-radius: 15px; background: #fff7de; border: 1px solid #e4cb82; line-height: 2; font-size: 11.5px; color: #4d432b; }
.lineage-tag { display: inline-block; border-radius: 7px; padding: 0 6px; margin: 0 2px; background: #315f3e; color: #fff6d9; font-weight: 800; }

.relationship-panel { position: absolute; top: 84px; left: 20px; width: min(380px, calc(100% - 40px)); z-index: 65; padding: 22px; border-radius: 24px; background: rgba(255, 252, 243, .98); border: 1px solid rgba(97, 73, 30, .22); box-shadow: 0 28px 75px rgba(50, 35, 12, .22); transform: translateX(calc(-100% - 40px)); opacity: 0; pointer-events: none; transition: .3s ease; }
.relationship-panel.is-open { transform: translateX(0); opacity: 1; pointer-events: auto; }
.relationship-panel__title { display: grid; gap: 5px; padding-left: 38px; }
.relationship-panel__title span { color: var(--green-950); font-size: 20px; font-weight: 850; }
.relationship-panel__title small { color: var(--muted); font-size: 10.5px; }
.relationship-selections { display: flex; flex-wrap: wrap; gap: 7px; min-height: 54px; margin: 17px 0 11px; padding: 9px; background: #f4ecd9; border-radius: 14px; }
.relationship-empty { width: 100%; display: grid; place-items: center; color: #8c8067; font-size: 10.5px; }
.relationship-chip { --chip-color: #4f7652; border: 1px solid color-mix(in srgb, var(--chip-color), #fff 45%); background: color-mix(in srgb, var(--chip-color), #fff 83%); color: #2a392e; border-radius: 12px; padding: 7px 9px; display: grid; grid-template-columns: auto auto auto; align-items: center; gap: 5px; cursor: pointer; }
.relationship-chip::before { content: ''; width: 10px; height: 10px; border-radius: 50%; background: var(--chip-color); }
.relationship-chip span { font-weight: 800; font-size: 11px; }
.relationship-chip small { font-size: 8px; color: #756c56; }
.relationship-chip b { color: #8a3d3d; }
.relationship-actions { display: flex; gap: 8px; }
.relationship-actions button { flex: 1; border: 0; border-radius: 11px; padding: 9px; cursor: pointer; background: #eae2cf; color: #5a523e; font-weight: 800; font-size: 10.5px; }
.relationship-actions button:last-child { background: var(--green-900); color: #fff; }
.relationship-actions button:disabled { opacity: .45; cursor: not-allowed; }
.relationship-result { margin-top: 13px; border: 1px solid #dccb9d; background: #fff9e9; border-radius: 16px; padding: 13px; }
.relationship-common { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.relationship-common > span { font-size: 9.5px; color: #80714e; }
.relationship-common button { border: 0; border-radius: 10px; padding: 7px 10px; background: #d29a28; color: #fff; font-weight: 800; cursor: pointer; }
.relationship-common small { opacity: .8; }
.relationship-result p { line-height: 1.8; font-size: 11px; color: #50462f; }
.relationship-result ul { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 7px; }
.relationship-result li { display: grid; grid-template-columns: 11px auto 1fr; align-items: center; gap: 7px; font-size: 10px; }
.relationship-result li > span { width: 10px; height: 10px; border-radius: 50%; background: var(--relation-color); }
.relationship-result li small { color: #87795b; text-align: left; }
.relationship-hint { margin: 11px 0 0; font-size: 9.5px; line-height: 1.7; color: #84785e; }

/* Series view */
#seriesView { padding: 78px 18px 18px; }
.series-toolbar { position: absolute; z-index: 12; top: 17px; right: 20px; display: flex; align-items: end; gap: 8px; padding: 8px; border-radius: 15px; background: rgba(255, 253, 247, .94); border: 1px solid var(--line); box-shadow: 0 12px 32px rgba(46, 34, 14, .11); }
.series-toolbar label { display: grid; gap: 4px; font-size: 8.5px; color: #7c7055; }
.series-toolbar select, .series-toolbar button { height: 35px; border: 1px solid #d9ceb5; border-radius: 9px; background: #fffdf8; color: var(--green-900); padding: 0 9px; font-size: 10px; font-weight: 750; cursor: pointer; }
.series-canvas { position: relative; width: 100%; height: 100%; border: 1px solid rgba(92, 70, 33, .15); border-radius: 22px; overflow: hidden; background: radial-gradient(circle at top, #fffdf8 0, #f3ead5 100%); box-shadow: inset 0 0 65px rgba(97, 71, 27, .09); }
.series-svg { width: 100%; height: 100%; display: block; cursor: grab; user-select: none; }
.series-svg.is-dragging { cursor: grabbing; }
.series-node { cursor: pointer; transition: opacity .2s ease; }
.series-node:hover rect { stroke-width: 5; }
.series-edge { transition: opacity .2s ease; }
.series-svg.has-highlight .series-node.is-dimmed, .series-svg.has-highlight .series-edge.is-dimmed { opacity: .12; }
.series-node.is-lineage rect { fill: #d29a28; stroke: #fff0a6; stroke-width: 6; }
.series-node.is-lineage text { fill: #fffdf1; }
.series-edge.is-lineage path { stroke: #d29a28; stroke-width: 7; filter: drop-shadow(0 0 5px rgba(210,154,40,.5)); }
.series-help { position: absolute; left: 35px; bottom: 35px; width: 255px; z-index: 5; display: grid; gap: 6px; border-radius: 16px; background: rgba(255, 253, 247, .92); border: 1px solid var(--line); padding: 13px; box-shadow: var(--shadow); }
.series-help strong { color: var(--green-900); }
.series-help span { color: #7f7358; font-size: 9.5px; line-height: 1.7; }

/* Public content views */
.content-view { overflow: auto; padding: 92px max(24px, calc((100vw - 1280px) / 2)) 45px; background: linear-gradient(180deg, rgba(255,253,247,.65), rgba(240,229,204,.78)); }
.content-heading { display: flex; justify-content: space-between; align-items: center; gap: 20px; margin-bottom: 22px; }
.content-heading h2 { margin: 0; font-size: 29px; color: var(--green-950); }
.content-heading p { margin: 7px 0 0; font-size: 12px; color: var(--muted); }
.content-count { width: 58px; height: 58px; display: grid; place-items: center; border-radius: 18px; background: var(--green-900); color: #fff; font-size: 19px; font-weight: 850; }
.content-filters { display: grid; grid-template-columns: 1fr 170px 150px; gap: 10px; margin-bottom: 18px; }
.content-filters input, .content-filters select { border: 1px solid #d9ceb4; border-radius: 13px; background: #fffdf8; padding: 11px 13px; outline: 0; color: #334437; }
.people-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(225px, 1fr)); gap: 12px; }
.person-list-card { --branch-color: #4f7652; border: 1px solid #ded2b7; border-radius: 17px; background: rgba(255,253,247,.94); padding: 12px; box-shadow: 0 9px 25px rgba(50,37,15,.07); }
.person-list-card__main { width: 100%; border: 0; background: transparent; display: flex; align-items: center; gap: 10px; text-align: right; cursor: pointer; color: inherit; }
.person-list-avatar { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 50%; color: #fff; background: var(--branch-color); font-size: 17px; font-weight: 850; flex: 0 0 auto; }
.person-list-card__main > span:last-child { display: grid; gap: 5px; min-width: 0; }
.person-list-card__main strong { font-size: 14px; color: var(--green-950); }
.person-list-card__main small { color: #7e7258; font-size: 9.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.person-list-card__meta { display: flex; justify-content: space-between; gap: 5px; border-top: 1px dashed #e2d7c0; margin-top: 10px; padding-top: 8px; color: #81765d; font-size: 8.5px; }
.person-list-compare { width: 100%; margin-top: 9px; border: 0; border-radius: 9px; padding: 7px; background: #edf2e8; color: var(--green-800); font-size: 9px; font-weight: 800; cursor: pointer; }
.news-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(310px, 1fr)); gap: 16px; }
.news-card { background: #fffdf8; border: 1px solid #ded2b7; border-radius: 20px; padding: 20px; box-shadow: 0 12px 35px rgba(49,36,14,.08); }
.news-card time { font-size: 9px; color: #8a7c5e; }
.news-card h3 { margin: 8px 0; color: var(--green-950); font-size: 19px; }
.news-card > p { color: #675f4d; font-size: 11.5px; line-height: 1.8; }
.news-card details { border-top: 1px dashed #dfd2b6; padding-top: 10px; }
.news-card summary { color: var(--green-700); font-weight: 800; cursor: pointer; font-size: 11px; }
.news-card details div { line-height: 1.9; font-size: 11px; color: #4b5147; }
.archive-grid { display: grid; gap: 12px; }
.archive-card { display: grid; grid-template-columns: 65px 1fr auto; align-items: center; gap: 15px; background: #fffdf8; border: 1px solid #ded2b7; border-radius: 18px; padding: 15px; box-shadow: 0 10px 28px rgba(49,36,14,.07); }
.archive-icon { width: 56px; height: 56px; display: grid; place-items: center; border-radius: 16px; background: #edf1e6; font-size: 26px; }
.archive-card span { color: #8a7b5a; font-size: 8.5px; }
.archive-card h3 { margin: 4px 0; color: var(--green-950); font-size: 15px; }
.archive-card p { margin: 0 0 5px; color: #716853; font-size: 10.5px; }
.archive-card small { color: #93856a; font-size: 8.5px; }
.archive-card > a { border-radius: 10px; padding: 9px 13px; background: var(--green-900); color: #fff; text-decoration: none; font-size: 10px; font-weight: 800; }
.content-loading, .content-empty { grid-column: 1 / -1; min-height: 220px; display: grid; place-items: center; align-content: center; gap: 8px; border: 1px dashed #d7c9aa; border-radius: 20px; background: rgba(255,253,247,.65); color: #83765a; text-align: center; }
.content-empty strong { color: var(--green-900); font-size: 17px; }
.content-empty span { font-size: 11px; }

.loading-overlay { position: absolute; inset: 0; z-index: 100; display: flex; flex-direction: column; align-items: center; justify-content: center; background: radial-gradient(circle, #fbf6e9 0, #eee2c9 80%); transition: opacity .45s ease, visibility .45s; }
.loading-overlay.is-hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.loading-tree { width: 78px; height: 78px; display: grid; place-items: center; border-radius: 50%; background: var(--green-900); color: #fff2c7; font-size: 38px; animation: grow 1.3s ease-in-out infinite alternate; }
.loading-overlay h2 { margin: 14px 0 8px; color: var(--green-900); font-size: 24px; }
.loading-overlay p { margin: 0; color: #7b6c4d; font-size: 12px; }
.loading-bar { margin-top: 20px; width: 260px; height: 7px; border-radius: 99px; background: #ded2b4; overflow: hidden; }
.loading-bar span { display: block; height: 100%; width: 45%; border-radius: inherit; background: linear-gradient(90deg, #2e6845, #9bbf7a); animation: load 1.3s ease-in-out infinite; }
.loading-overlay.is-error .loading-tree { filter: grayscale(1); }

.reference-modal { position: fixed; inset: 0; z-index: 200; background: rgba(17, 24, 19, .86); display: none; align-items: center; justify-content: center; padding: 30px; }
.reference-modal.is-open { display: flex; }
.reference-modal img { max-width: 95vw; max-height: 90vh; object-fit: contain; border-radius: 12px; background: #fff; box-shadow: 0 30px 90px rgba(0,0,0,.45); }
.reference-modal button { position: absolute; top: 18px; left: 18px; width: 44px; height: 44px; border: 0; border-radius: 50%; background: #fff; color: #1b3023; font-size: 27px; cursor: pointer; }

.family-node { cursor: pointer; transition: opacity .2s ease; }
.family-node text { pointer-events: none; }
.family-node:hover { filter: drop-shadow(0 5px 9px rgba(36,50,40,.3)); }

@keyframes grow { from { transform: scale(.9) translateY(4px); } to { transform: scale(1.08) translateY(-4px); } }
@keyframes load { 0% { transform: translateX(150%); } 100% { transform: translateX(-260%); } }

@media (max-width: 1280px) {
  .topbar { grid-template-columns: minmax(270px, 1fr) auto auto; gap: 9px; padding-inline: 12px; }
  .main-nav { max-width: 650px; overflow-x: auto; justify-content: flex-start; scrollbar-width: none; }
  .main-nav::-webkit-scrollbar { display: none; }
  .nav-item { padding-inline: 10px; }
  .soft-button { display: none; }
  .search-shell { width: min(520px, calc(100% - 320px)); }
}

@media (max-width: 900px) {
  .app-shell { grid-template-rows: 116px minmax(0,1fr); }
  .topbar { height: 116px; grid-template-columns: 1fr auto; grid-template-rows: 66px 42px; padding: 5px 10px; }
  .brand__mark { width: 54px; height: 54px; }
  .brand h1 { font-size: 20px; }
  .brand p { max-width: 450px; font-size: 9px; }
  .main-nav { grid-column: 1 / -1; grid-row: 2; width: 100%; max-width: none; justify-content: flex-start; }
  .header-actions { grid-column: 2; grid-row: 1; }
  .search-shell { width: min(500px, calc(100% - 160px)); top: 12px; }
  .legend-card { display: none; }
  .stats-strip { left: 78px; }
  .person-card { top: 78px; }
  .relationship-panel { top: 78px; }
  #seriesView { padding-top: 76px; }
  .series-toolbar { max-width: calc(100% - 40px); overflow-x: auto; }
  .content-view { padding-top: 86px; }
}

@media (max-width: 720px) {
  body { overflow: hidden; }
  .app-shell { grid-template-rows: 111px minmax(0,1fr); }
  .topbar { height: 111px; }
  .brand__mark { width: 48px; height: 48px; border-radius: 13px; }
  .brand h1 { font-size: 17px; }
  .brand p { max-width: 215px; font-size: 7.8px; }
  .admin-button { width: 39px; overflow: hidden; color: transparent; position: relative; padding: 0; }
  .admin-button::after { content: '⚙'; color: var(--green-900); position: absolute; font-size: 17px; }
  .icon-button { width: 38px; height: 38px; }
  .main-nav { padding: 3px; gap: 3px; }
  .nav-item { height: 35px; padding-inline: 9px; font-size: 9px; }
  .nav-item span { display: none; }
  .search-shell { top: 10px; left: 10px; right: 10px; width: auto; height: 44px; transform: none; }
  .search-shell.is-hidden { transform: translateY(-12px); }
  .search-shell kbd { display: none; }
  .tree-controls { left: 10px; top: 65px; }
  .tree-controls button { width: 38px; height: 38px; }
  .stats-strip { display: none; }
  .status-pill { left: 10px; bottom: 12px; transform: none; }
  .canvas-frame::after { bottom: 10px; font-size: 9px; }
  .person-card, .relationship-panel { right: 10px; left: 10px; top: auto; bottom: 10px; width: auto; max-height: 58%; border-radius: 22px; transform: translateY(calc(100% + 25px)); }
  .person-card.is-open, .relationship-panel.is-open { transform: translateY(0); }
  .relationship-panel { max-height: 62%; overflow: auto; }
  #seriesView { padding: 64px 7px 7px; }
  .series-toolbar { top: 8px; right: 7px; left: 7px; max-width: none; padding: 5px; }
  .series-toolbar label:first-child { min-width: 135px; }
  .series-help { display: none; }
  .content-view { padding: 70px 12px 30px; }
  .content-heading h2 { font-size: 22px; }
  .content-filters { grid-template-columns: 1fr 1fr; }
  .content-filters input { grid-column: 1 / -1; }
  .people-grid { grid-template-columns: 1fr; }
  .news-grid { grid-template-columns: 1fr; }
  .archive-card { grid-template-columns: 52px 1fr; }
  .archive-card > a { grid-column: 1 / -1; text-align: center; }
}

/* v0.6.1: name-frequency statistics, branch notes, and resilient loading */
.name-stats-card {
  position: absolute; right: 240px; bottom: 23px; z-index: 22;
  width: min(520px, calc(100% - 690px)); max-height: 98px; overflow: hidden;
  border: 1px solid var(--line); border-radius: 18px; background: rgba(255, 251, 241, .94);
  box-shadow: var(--shadow); backdrop-filter: blur(9px); transition: max-height .28s ease, width .28s ease;
}
.name-stats-card.is-expanded { max-height: min(390px, calc(100% - 130px)); width: min(680px, calc(100% - 470px)); }
.name-stats-card__header {
  width: 100%; min-height: 42px; border: 0; border-bottom: 1px solid rgba(93,73,35,.09);
  background: transparent; color: var(--green-900); display: flex; align-items: center; justify-content: space-between;
  padding: 8px 13px; cursor: pointer; text-align: right;
}
.name-stats-card__header > span { display: flex; align-items: baseline; gap: 9px; }
.name-stats-card__header strong { font-size: 12px; }
.name-stats-card__header small { color: #83765a; font-size: 8.5px; font-weight: 650; }
.name-stats-card__header small b { color: var(--green-800); }
.name-stats-card__header i { font-style: normal; transition: transform .25s ease; }
.name-stats-card.is-expanded .name-stats-card__header i { transform: rotate(180deg); }
.name-stats-list { display: flex; flex-wrap: wrap; gap: 6px; max-height: 48px; overflow: hidden auto; padding: 7px 10px 10px; }
.name-stats-card.is-expanded .name-stats-list { max-height: 320px; padding-bottom: 14px; }
.name-stat-chip { border: 1px solid #ddd0b1; background: #fffdf8; color: #5f5846; border-radius: 999px; padding: 5px 8px; display: inline-flex; align-items: center; gap: 6px; cursor: pointer; font-size: 9px; }
.name-stat-chip strong { min-width: 21px; height: 21px; border-radius: 999px; display: grid; place-items: center; background: #e9efdf; color: var(--green-900); font-size: 8.5px; }
.name-stat-chip.is-top { border-color: #d0b36e; background: #fff7da; }
.name-stat-chip:hover { background: var(--green-900); color: #fff; }
.name-stat-chip:hover strong { background: #fff; }

.branch-note { margin-top: 14px; padding: 13px 14px; border-radius: 15px; background: #f6efe0; border: 1px solid #d9c397; }
.branch-note > span { display: block; color: #8b6a2e; font-size: 9px; font-weight: 800; margin-bottom: 6px; }
.branch-note p { margin: 0; color: #4d4b3d; font-size: 12px; line-height: 1.85; font-weight: 700; }

.content-empty--error { border-color: #d9aaa2; background: #fff4f1; color: #8b4540; }
.content-empty button { border: 0; border-radius: 11px; padding: 9px 15px; background: var(--green-900); color: #fff; font-weight: 800; cursor: pointer; }
.loading-overlay.is-slow .loading-bar span { background: linear-gradient(90deg, #b1832f, #d8b967); }
.loading-overlay p button { margin-inline-start: 8px; border: 0; border-radius: 9px; padding: 7px 11px; background: var(--green-900); color: #fff; font-weight: 800; cursor: pointer; }

/* Keep non-selected series boxes readable while highlighting a path. */
.series-svg.has-highlight .series-node.is-dimmed { opacity: .34; }
.series-svg.has-highlight .series-edge.is-dimmed { opacity: .2; }

@media (max-width: 1100px) {
  .name-stats-card { right: 20px; width: 430px; }
  .name-stats-card.is-expanded { width: min(610px, calc(100% - 40px)); }
}

@media (max-width: 720px) {
  .name-stats-card { right: 62px; left: 10px; bottom: 52px; width: auto; max-height: 43px; }
  .name-stats-card.is-expanded { right: 10px; width: auto; max-height: min(52vh, 390px); }
  .name-stats-card__header { min-height: 42px; }
  .name-stats-list { max-height: 0; padding-block: 0; }
  .name-stats-card.is-expanded .name-stats-list { max-height: calc(52vh - 50px); padding-block: 8px 12px; }
  .loading-overlay h2 { font-size: 19px; text-align: center; padding-inline: 18px; }
  .loading-overlay p { max-width: 88%; text-align: center; line-height: 1.8; }
}

/* v0.6.2: cards, news galleries, series/mobile controls and name-stat overlay */
.person-card__actions { margin-top: 16px; display: flex; justify-content: stretch; }
.person-card__actions button { width: 100%; min-height: 42px; border: 0; border-radius: 13px; background: var(--green-900); color: #fff; font-weight: 850; cursor: pointer; box-shadow: 0 8px 20px rgba(21,63,44,.18); }
.person-card__actions button:hover { background: var(--green-700); }

.news-card__gallery { margin: -8px -8px 15px; display: grid; grid-template-columns: 1fr; gap: 7px; }
.news-card__gallery.is-multiple { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.news-card__gallery button { border: 0; padding: 0; border-radius: 14px; overflow: hidden; background: #eee5d2; cursor: zoom-in; min-height: 148px; }
.news-card__gallery img { width: 100%; height: 190px; display: block; object-fit: cover; transition: transform .22s ease; }
.news-card__gallery.is-multiple img { height: 132px; }
.news-card__gallery button:hover img { transform: scale(1.035); }

.name-stats-close-label { display: none; margin-inline-start: auto; color: #8b5b2f; font-weight: 850; }
.name-stats-card.is-expanded .name-stats-close-label { display: inline; }

@media (max-width: 720px) {
  /* The series filters sit below the global search instead of underneath it. */
  #seriesView { padding: 124px 7px 7px; }
  .series-toolbar { top: 62px; right: 7px; left: 7px; max-width: none; padding: 5px; overflow-x: auto; overscroll-behavior-inline: contain; scrollbar-width: thin; }
  .series-toolbar label { flex: 0 0 auto; }
  .series-toolbar label:first-child { min-width: 145px; }
  .series-toolbar select, .series-toolbar button { height: 34px; }

  /* Expanded name statistics become a dedicated, closable mobile panel. */
  .name-stats-card.is-expanded {
    position: absolute; top: 62px; right: 8px; bottom: 8px; left: 8px;
    width: auto; max-height: none; z-index: 75; display: flex; flex-direction: column;
    overflow: hidden; border-radius: 18px; background: rgba(255,253,247,.99);
  }
  .name-stats-card.is-expanded .name-stats-card__header {
    position: sticky; top: 0; z-index: 3; flex: 0 0 auto; background: #fffdf7;
    box-shadow: 0 4px 13px rgba(54,39,14,.08);
  }
  .name-stats-card.is-expanded .name-stats-list {
    flex: 1 1 auto; max-height: none; overflow-y: auto; align-content: flex-start;
    padding: 10px 11px 18px; overscroll-behavior: contain;
  }
  body.name-stats-open .tree-controls { opacity: .12; pointer-events: none; }
  .news-card__gallery img { height: 210px; }
  .news-card__gallery.is-multiple img { height: 132px; }
}


/* v0.6.8 — optional readability controls; defaults preserve the published map */
.tree-controls button.is-active{background:#173f2d;color:#fff;border-color:#173f2d}.family-royal{pointer-events:none;filter:drop-shadow(0 0 2px rgba(191,139,31,.22))}.family-node text{paint-order:stroke;stroke:rgba(24,39,31,.18);stroke-width:.7px;stroke-linejoin:round}.family-node--root text,.family-node--main text{stroke:rgba(18,35,27,.34);stroke-width:1px}
@media(max-width:700px){.tree-controls{gap:4px}.tree-controls button{min-width:42px;min-height:42px;font-weight:900}.series-canvas.is-readable .series-node text{font-size:20px!important}.series-canvas.is-readable .series-node rect{stroke-width:4px}.series-toolbar{scroll-padding-inline:12px}.series-toolbar button{flex:0 0 auto}}
