:root {
  color-scheme: light;
  --paper: #f8f6f0;
  --panel: #fffdf7;
  --surface: #f1eee4;
  --line: #dedacf;
  --ink: #272d26;
  --muted: #62685b;
  --green: #305343;
  --green-dark: #234036;
  --green-light: #e4ece1;
  --rust: #8d583f;
  --rust-light: #f3e7dc;
  --serif: "Georgia", "Times New Roman", serif;
  --sans: "Inter", "Arial", sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 14px/1.45 var(--sans); }
h1, h2, h3, p { margin: 0; }
h1, h2 { font-family: var(--serif); font-weight: 500; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; color: inherit; }
button, input, select, textarea { border-radius: 6px; }
button { padding: 8px 12px; border: 1px solid transparent; background: transparent; }
button:hover { background: var(--surface); }
button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible, .viewport:focus-visible { outline: 2px solid #587f68; outline-offset: 3px; }
button:disabled { opacity: .6; cursor: wait; }
a { color: var(--green); text-underline-offset: 3px; overflow-wrap: anywhere; }
input, select, textarea { width: 100%; border: 1px solid var(--line); color: var(--ink); background: var(--panel); padding: 10px 12px; }
textarea { resize: vertical; }
label { font-weight: 600; }
.primary { background: var(--green); color: white; border-color: var(--green); font-weight: 600; }
.primary:hover { background: var(--green-dark); }
.secondary { background: var(--panel); border-color: var(--line); font-weight: 600; }
.quiet { color: var(--green); font-weight: 600; }
.muted { color: var(--muted); }
.small-label { color: var(--muted); font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip-path: inset(50%); }
.brand-mark { display: grid; grid-template-columns: repeat(2, 6px); grid-template-rows: repeat(2, 6px); gap: 6px; justify-content: center; align-content: center; width: 37px; height: 37px; border-radius: 8px; background: var(--green); color: #f3f2e8; position: relative; flex: none; }
.brand-mark::after { position: absolute; content: ""; width: 12px; height: 7px; top: 15px; left: 12.5px; border: 1px solid currentColor; border-bottom: 0; }
.brand-mark i { width: 6px; height: 6px; border: 1px solid currentColor; border-radius: 50%; }
.brand-mark i:first-child { grid-column: span 2; justify-self: center; }
.brand-mark i:nth-child(2), .brand-mark i:nth-child(3) { background: currentColor; }
.gate { min-height: 100vh; display: grid; place-items: center; padding: 22px; background: radial-gradient(ellipse at 48% 35%, #fdfbf3, #e9eee5); }
.login-card { width: min(100%, 410px); padding: 36px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 15px 45px #354c3e15; }
.login-card h1 { font-size: 32px; margin: 17px 0 7px; }
.login-card p { color: var(--muted); }
.login-card form { display: grid; gap: 9px; margin-top: 24px; }
.login-card button { margin-top: 5px; }
.status { color: #813f30; overflow-wrap: anywhere; }
.status:empty { display: none; }
.login-card .status:not(:empty) { margin-top: 12px; color: #813f30; }
.topbar { position: relative; z-index: 3; display: grid; grid-template-columns: 240px minmax(180px, 440px) 1fr; align-items: center; gap: 20px; padding: 12px 22px; min-height: 67px; border-bottom: 1px solid var(--line); background: var(--panel); }
.brand { padding: 0; display: flex; gap: 11px; width: max-content; align-items: center; font: 21px var(--serif); }
.brand:hover { background: transparent; color: var(--green); }
.search-box { position: relative; }
.search-box input { background: #f5f2ea; }
.search-results { position: absolute; inset: calc(100% + 5px) 0 auto; max-height: min(430px, 65vh); overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 5px; box-shadow: 0 10px 24px #283d3324; }
.search-results .person-link { padding: 9px; }
.top-actions { display: flex; justify-content: end; gap: 8px; }
.workspace { display: grid; grid-template-columns: 228px minmax(0, 1fr) 365px; min-height: calc(100vh - 67px); }
.sidebar { border-right: 1px solid var(--line); padding: 25px 16px 18px 20px; display: flex; flex-direction: column; gap: 24px; background: #f5f2e9; }
.side-header { display: grid; gap: 12px; }
.side-modes { display: grid; gap: 4px; }
.side-modes button { text-align: left; padding: 9px 10px; font-weight: 600; }
.side-modes [aria-pressed="true"] { color: var(--green-dark); background: var(--green-light); }
.nearby { display: grid; align-content: start; gap: 7px; }
.person-link { display: flex; flex-direction: column; gap: 1px; text-align: left; padding: 7px 8px; width: 100%; }
.person-link strong { font-weight: 600; }
.person-link small { color: var(--muted); font-size: 12px; }
.inventory { margin-top: auto; color: var(--muted); padding-top: 12px; border-top: 1px solid var(--line); font-size: 12px; }
.tree-page { min-width: 0; }
.tree-header { padding: 23px 25px 17px; display: grid; gap: 4px; }
.tree-header h1 { font-size: clamp(22px, 2.75vw, 34px); line-height: 1.15; overflow-wrap: anywhere; }
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 51px; border-block: 1px solid var(--line); padding: 6px 13px; background: var(--panel); }
.view-buttons, .zoom, .detail-tabs { display: flex; align-items: center; gap: 2px; }
.view-buttons button[aria-pressed="true"], .detail-tabs button[aria-pressed="true"] { background: var(--green-light); color: var(--green-dark); font-weight: 700; }
.zoom button { min-width: 34px; }
.zoom #zoom-value { font-variant-numeric: tabular-nums; min-width: 54px; }
#mobile-mode { display: none; width: auto; }
.chart-legend { display: flex; align-items: center; gap: 10px; font-size: 12px; white-space: nowrap; }
.chart-legend span { display: inline-flex; align-items: center; gap: 3px; }
.chart-legend b { display: grid; place-items: center; width: 20px; height: 20px; border-radius: 4px; font-size: 15px; }
.legend-male b { background: #d9e9fd; color: #184d83; }
.legend-female b { background: #f7dfeb; color: #873858; }
.viewport { height: max(440px, calc(100vh - 272px)); overflow: auto; position: relative; background-color: #efeee4; background-image: radial-gradient(#b8b9a76b 1px, transparent 1px); background-size: 19px 19px; scroll-behavior: auto; }
.viewport::-webkit-scrollbar:horizontal { height: 0; }
.diagram { position: relative; margin: 0 auto; min-height: 100%; }
.diagram canvas { position: absolute; inset: 0; pointer-events: none; }
.tree-node { --card-fill: #fffdf7; --card-line: #9a978a; --card-mark: #575447; }
.tree-node.male { --card-fill: #d9e9fd; --card-line: #356d9f; --card-mark: #184d83; }
.tree-node.female { --card-fill: #f7dfeb; --card-line: #a15376; --card-mark: #873858; }
.tree-node {
  position: absolute;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-start;
  padding: .22em .34em;
  text-align: left;
  border: 1px solid var(--card-line);
  border-left-width: 4px;
  background: var(--card-fill);
  box-shadow: 0 2px 5px #313b2e15;
  line-height: 1.15;
}
.tree-node.has-markers { padding-bottom: 1.22em; }
.card-markers { position: absolute; right: .22em; bottom: .18em; display: flex; gap: .24em; color: #fffdf7; }
.card-markers span { position: relative; display: block; height: .86em; border-radius: 2px; background: #293c34; }
.card-marker-text { width: .72em; }
.card-marker-text::after { content: ""; position: absolute; inset: 26% 25%; border-block: 1px solid currentColor; }
.card-marker-scan { width: 1em; }
.card-marker-scan::after { content: ""; position: absolute; inset: 22% 12% 15%; background: currentColor; clip-path: polygon(0 100%, 33% 35%, 53% 66%, 73% 18%, 100% 100%); }
.tree-node .node-name { max-width: 100%; font-weight: 700; overflow-wrap: anywhere; }
.tree-node .node-name.long-word { font-size: .95em; letter-spacing: -.02em; }
.tree-node small { font-size: .82em; color: #4a4e49; margin-top: .25em; }
.tree-node:hover, .tree-node.selected { background: var(--card-fill); outline: 2px solid var(--card-mark); outline-offset: 1px; }
.tree-node.root { outline: 2px solid var(--card-mark); outline-offset: 2px; box-shadow: 0 3px 8px #182d4050; }
.tree-node.root.selected { outline-width: 3px; }
.chart-scroll { display: grid; grid-template-columns: 38px minmax(0, 1fr) 38px; align-items: center; gap: 8px; position: sticky; bottom: 0; padding: 3px 8px; background: var(--panel); border-block: 1px solid var(--line); z-index: 1; }
.chart-scroll button { height: 33px; padding: 0; border-color: var(--line); color: var(--green-dark); font-size: 18px; }
.chart-scroll input { appearance: none; height: 33px; padding: 0; margin: 0; border: 0; background: transparent; cursor: ew-resize; }
.chart-scroll input::-webkit-slider-runnable-track { height: 14px; border-radius: 8px; background: #d8e1d9; }
.chart-scroll input::-webkit-slider-thumb { appearance: none; width: 44px; height: 23px; border-radius: 6px; margin-top: -4.5px; background: #4d7561; border: 2px solid #375b4b; }
.chart-scroll input::-moz-range-track { height: 14px; border-radius: 8px; background: #d8e1d9; }
.chart-scroll input::-moz-range-thumb { width: 40px; height: 19px; border-radius: 6px; background: #4d7561; border: 2px solid #375b4b; }
.people-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 9px; padding: 17px; }
.people-list .person-link { border: 1px solid var(--line); border-radius: 7px; background: var(--panel); }
.people-list .person-link:hover { background: var(--green-light); }
.details { min-width: 0; border-left: 1px solid var(--line); background: var(--panel); padding: 21px 20px; }
.person-header { display: flex; align-items: center; gap: 11px; min-height: 70px; }
.person-header h2 { font-size: 23px; line-height: 1.12; overflow-wrap: anywhere; }
.person-header p { margin-top: 5px; }
.avatar { width: 45px; height: 45px; border-radius: 50%; display: grid; place-items: center; flex: none; background: var(--green-light); color: var(--green-dark); font: 19px var(--serif); }
.avatar.female { color: var(--rust); background: var(--rust-light); }
.avatar.has-portrait { width: 68px; height: 80px; border-radius: 7px; }
.portrait-preview { width: 100%; height: 100%; padding: 0; border: 0; overflow: hidden; }
.portrait-preview img { display: block; width: 100%; height: 100%; object-fit: cover; object-position: center 25%; }
.person-actions { margin: 14px 0; display: flex; flex-wrap: wrap; gap: 7px; }
.person-actions button { flex: 1 1 auto; }
.detail-tabs { border-bottom: 1px solid var(--line); padding-bottom: 8px; }
.detail-tabs button { flex: 1; padding-inline: 5px; }
#doc-count { color: var(--muted); font-size: 12px; margin-left: 3px; }
#detail-content { margin-top: 15px; display: grid; gap: 15px; }
.detail-section { border-bottom: 1px solid var(--line); padding-bottom: 10px; }
.detail-section:last-child { border-bottom: 0; }
.detail-section h3 { font: 600 14px var(--sans); margin-bottom: 7px; color: var(--green-dark); }
.rich { white-space: pre-wrap; overflow-wrap: anywhere; color: #383d34; }
.rich + .rich { margin-top: 9px; }
.source { display: grid; gap: 5px; margin-bottom: 10px; }
.event { padding: 4px 0; }
.event .rich { font-size: 13px; }
.event-title { display: flex; gap: 10px; justify-content: space-between; }
.doc-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.doc-card { border: 1px solid var(--line); background: var(--paper); padding: 0; text-align: left; overflow: hidden; }
.doc-card img { width: 100%; height: 98px; object-fit: contain; display: block; padding: 6px; background: #ece9dd; }
.doc-card span { display: block; padding: 7px; font-size: 12px; overflow-wrap: anywhere; }
.doc-card .type-label { display: grid; place-items: center; min-height: 65px; background: var(--surface); color: var(--muted); }
dialog { color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 0; width: min(560px, calc(100vw - 26px)); max-height: 90vh; overflow: auto; box-shadow: 0 20px 60px #162d2850; }
dialog::backdrop { background: #22292078; }
.modal-header { display: flex; justify-content: space-between; gap: 10px; align-items: start; border-bottom: 1px solid var(--line); padding: 17px 20px; }
.modal-header h2 { font-size: 24px; overflow-wrap: anywhere; }
.close { font-size: 24px; line-height: 1; padding: 3px 8px; flex: none; }
.modal-form, .admin-queue { padding: 17px 20px; display: grid; gap: 8px; }
.form-end { display: flex; align-items: start; justify-content: space-between; gap: 10px; margin-top: 5px; }
.form-end button { margin-left: auto; }
.document-dialog { width: min(1100px, calc(100vw - 26px)); }
.document-content { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(250px, 1fr); gap: 16px; padding: 14px; }
.document-visual { overflow: auto; background: var(--surface); text-align: center; border-radius: 8px; min-height: 180px; max-height: 66vh; }
.document-visual img { width: 100%; max-width: 100%; height: auto; display: block; margin: auto; }
.document-visual button { width: 100%; padding: 5px; cursor: zoom-in; }
.document-visual.expanded button { width: max(100%, 1450px); cursor: zoom-out; }
.document-text { min-width: 0; display: grid; align-content: start; gap: 9px; }
.document-tools { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.document-tools a { border: 1px solid var(--line); border-radius: 6px; padding: 7px 9px; }
.admin-dialog { width: min(730px, calc(100vw - 26px)); }
.queue-item { border: 1px solid var(--line); border-radius: 7px; padding: 12px; display: grid; gap: 6px; }
.queue-actions { display: flex; gap: 7px; }
.notice { position: fixed; inset: auto 12px 13px auto; z-index: 4; max-width: min(460px, calc(100vw - 24px)); background: var(--green-dark); color: white; padding: 11px 15px; border-radius: 8px; }
@media (max-width: 1160px) {
  .workspace { grid-template-columns: 177px minmax(0, 1fr) 320px; }
  .topbar { grid-template-columns: 177px minmax(180px, 410px) 1fr; gap: 12px; }
  .sidebar { padding-inline: 12px; }
  .tree-header { padding-inline: 15px; }
  .details { padding-inline: 13px; }
}
@media (max-width: 900px) {
  .workspace { grid-template-columns: minmax(0, 1fr) 300px; }
  .sidebar { display: none; }
  #mobile-mode { display: block; max-width: 170px; }
  .tree-header { min-height: 100px; }
  .toolbar { flex-wrap: wrap; }
  .chart-legend { order: 2; }
}
@media (max-width: 660px) {
  .topbar { grid-template-columns: 1fr auto; padding: 9px 11px; gap: 8px; }
  .brand { font-size: 17px; gap: 7px; }
  .search-box { grid-row: 2; grid-column: 1 / -1; }
  .top-actions { gap: 2px; }
  .top-actions button { padding-inline: 5px; font-size: 12px; }
  .workspace { display: block; }
  .tree-header { min-height: auto; padding: 14px 12px; }
  .toolbar { padding: 5px; }
  .toolbar button { padding-inline: 5px; }
  .zoom #zoom-value { min-width: 42px; }
  .zoom button { min-width: 25px; }
  #mobile-mode { padding: 6px; max-width: 145px; }
  .viewport { height: min(55vh, 520px); }
  .chart-scroll { grid-template-columns: 42px minmax(0, 1fr) 42px; }
  .chart-scroll button, .chart-scroll input { height: 39px; }
  .details { border-left: 0; border-top: 1px solid var(--line); padding: 14px 12px; }
  .doc-grid { grid-template-columns: repeat(auto-fit, minmax(125px, 1fr)); }
  .document-content { grid-template-columns: 1fr; }
  .document-visual { max-height: 58vh; }
}
.exchange-import { border-top: 1px solid var(--line); }
.download-action { display: inline-block; margin-block: 5px; padding: 8px 11px; border: 1px solid var(--line); border-radius: 6px; }
@media (max-width: 660px) {
  .top-actions { flex-wrap: wrap; justify-content: flex-end; }
}
