:root {
  --paper: #f7f3ea;
  --surface: #fffdf8;
  --surface-2: #f0ece2;
  --ink: #242824;
  --muted: #6d716c;
  --line: #ddd6c8;
  --green: #315c49;
  --green-2: #dce8df;
  --clay: #b85c38;
  --gold: #d7a33a;
  --shadow: 0 12px 32px rgba(37, 34, 26, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: "Segoe UI", Arial, sans-serif;
}

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

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.login-view {
  height: 100vh;
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(0, min(100%, 72vh));
  align-items: end;
  justify-content: center;
  padding: clamp(22px, 4vw, 56px);
  position: relative;
  isolation: isolate;
  overflow: hidden;
  background:
    linear-gradient(90deg, rgba(31, 30, 25, 0.84), rgba(38, 39, 33, 0.34) 22%, rgba(42, 42, 36, 0.12) 52%, rgba(45, 43, 36, 0.44) 82%, rgba(31, 30, 25, 0.84)),
    linear-gradient(180deg, rgba(8, 12, 10, 0.18), rgba(8, 12, 10, 0.58)),
    #24251f;
}

.login-view::before,
.login-view::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.login-view::before {
  z-index: -2;
  background: url("/assets/login-family-background-colorized.png") center center / contain no-repeat;
  filter: drop-shadow(18px 0 38px rgba(13, 18, 14, 0.34));
}

.login-view::after {
  z-index: -1;
  background:
    linear-gradient(180deg, rgba(4, 8, 7, 0.08) 20%, rgba(4, 8, 7, 0.32) 62%, rgba(4, 8, 7, 0.72)),
    linear-gradient(90deg, rgba(10, 13, 11, 0.28), rgba(10, 13, 11, 0.04) 30%, rgba(10, 13, 11, 0.08) 72%, rgba(10, 13, 11, 0.36));
  backdrop-filter: sepia(0.16) saturate(0.82);
}

.login-intro {
  width: min(100%, 620px);
  color: #fff9ed;
  text-shadow: 0 2px 18px rgba(0, 0, 0, 0.45);
  align-self: end;
  justify-self: start;
  margin-bottom: clamp(18px, 5vh, 48px);
}

.login-intro-crest {
  width: clamp(128px, 14vw, 210px);
  height: clamp(128px, 14vw, 210px);
  object-fit: contain;
  border-radius: 18px;
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.24);
  background: rgba(255, 253, 248, 0.2);
  padding: 12px;
  margin-bottom: 26px;
}

.login-intro-title {
  font-size: clamp(42px, 5.2vw, 76px);
  line-height: 0.95;
  font-weight: 850;
  margin-bottom: 4px;
}

.login-panel {
  width: min(100%, 380px);
  justify-self: start;
  display: grid;
  gap: 12px;
  padding: 18px 0 0;
  background: transparent;
  border: 0;
  border-radius: 8px;
  box-shadow: none;
  backdrop-filter: none;
}

.login-panel label {
  color: rgba(255, 249, 237, 0.86);
  text-shadow: 0 1px 10px rgba(0, 0, 0, 0.42);
}

.login-panel input {
  color: #fff9ed;
  background: rgba(14, 18, 15, 0.28);
  border-color: rgba(255, 253, 248, 0.26);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.18),
    0 10px 26px rgba(0, 0, 0, 0.12);
  backdrop-filter: blur(8px);
}

.login-panel input:focus {
  background: rgba(18, 23, 19, 0.34);
  border-color: rgba(255, 249, 237, 0.52);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.22),
    0 0 0 3px rgba(255, 249, 237, 0.14),
    0 10px 26px rgba(0, 0, 0, 0.16);
}

.login-panel input:-webkit-autofill,
.login-panel input:-webkit-autofill:hover,
.login-panel input:-webkit-autofill:focus {
  -webkit-text-fill-color: #fff9ed;
  box-shadow: 0 0 0 1000px rgba(18, 23, 19, 0.36) inset;
  caret-color: #fff9ed;
}

.login-panel .primary-button {
  margin-top: 8px;
  background: rgba(49, 92, 73, 0.9);
  border-color: rgba(255, 249, 237, 0.18);
  box-shadow: 0 14px 32px rgba(0, 0, 0, 0.18);
}

.login-panel .form-error {
  color: #ffe0d4;
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.42);
}

.brand-mark {
  width: 82px;
  height: 82px;
  object-fit: contain;
  background: #fffaf0;
  border-radius: 12px;
  padding: 6px;
  border: 1px solid var(--line);
  box-shadow: 0 6px 16px rgba(37, 34, 26, 0.08);
}

.brand-mark.small {
  width: 66px;
  height: 66px;
  padding: 4px;
  border-radius: 14px;
}

.login-panel h1 {
  margin: 0 0 2px;
  font-size: 28px;
  line-height: 1.05;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

input,
select,
textarea {
  min-height: 40px;
  color: var(--ink);
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(49, 92, 73, 0.14);
}

textarea {
  width: 100%;
  min-height: 132px;
  padding: 10px 12px;
  line-height: 1.45;
  resize: vertical;
}

.form-error {
  min-height: 18px;
  margin: 0;
  color: #a33b29;
  font-size: 13px;
}

.primary-button,
.ghost-button,
.compact-button,
.icon-button {
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: 8px;
  font-weight: 700;
}

.primary-button {
  background: var(--green);
  color: white;
}

.ghost-button,
.compact-button,
.icon-button {
  background: white;
  color: var(--ink);
  border-color: var(--line);
}

.ghost-button:hover,
.compact-button:hover,
.icon-button:hover,
.person-row:hover,
.relation-button:hover {
  border-color: var(--green);
}

.feedback-button {
  flex: 0 0 auto;
  background: #fff8df;
  border-color: rgba(215, 163, 58, 0.42);
  color: #2b3f31;
}

.chat-button {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: #eef6f0;
  border-color: rgba(49, 92, 73, 0.28);
  color: #244334;
}

#chatOnlineCount,
.chat-dialog-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  min-height: 24px;
  padding: 0 7px;
  border-radius: 999px;
  background: var(--green);
  color: white;
  font-size: 13px;
  line-height: 1;
}

.app-shell {
  height: 100vh;
  min-height: 100vh;
  overflow: hidden;
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr) 360px;
  grid-template-rows: 86px minmax(0, 1fr);
}

.topbar {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: minmax(150px, auto) minmax(0, 1fr) auto auto auto auto;
  align-items: center;
  gap: 18px;
  padding: 10px 18px;
  background: rgba(255, 253, 248, 0.96);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}

#logoutButton {
  justify-self: end;
}

.topbar-title {
  display: grid;
  gap: 2px;
  min-width: 150px;
}

.topbar-title strong {
  display: block;
  line-height: 1.1;
  font-size: 18px;
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-title span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

.stats {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
  overflow-x: auto;
}

.stat-pill {
  flex: 0 0 auto;
  display: inline-flex;
  gap: 6px;
  align-items: center;
  min-height: 32px;
  padding: 0 10px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  font-size: 13px;
}

.stat-pill strong {
  color: var(--ink);
}

.sidebar,
.details-panel {
  min-height: 0;
  overflow: auto;
  background: var(--surface);
  position: relative;
  z-index: 4;
}

.sidebar {
  border-right: 1px solid var(--line);
  padding: 14px;
}

.details-panel {
  border-left: 1px solid var(--line);
}

.search-box {
  margin-bottom: 10px;
}

.search-box input {
  width: 100%;
}

.sidebar-search {
  margin: 0 0 10px;
}

.sidebar-search input {
  min-height: 40px;
}

.list-count {
  color: var(--muted);
  font-size: 12px;
  margin: 0 0 8px 2px;
}

.people-list {
  display: grid;
  gap: 8px;
}

.person-row {
  width: 100%;
  min-height: 64px;
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  padding: 8px;
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  text-align: left;
}

.person-row > span {
  min-width: 0;
}

.person-row.active {
  border-color: var(--green);
  background: var(--green-2);
}

.avatar,
.detail-photo,
.node-photo {
  background: var(--surface-2);
  border: 1px solid var(--line);
  overflow: hidden;
  position: relative;
}

.avatar {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  color: var(--green);
  font-weight: 800;
}

.avatar img,
.node-photo img,
.detail-photo img,
.gallery-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.tree-photo-hidden {
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #3a3329 0%, #171411 100%);
  color: #fff7e6;
  font-size: 10px;
  font-weight: 900;
}

.detail-photo.tree-photo-hidden {
  font-size: 13px;
}

.avatar.is-deceased::after,
.node-photo.is-deceased::after,
.detail-photo.is-deceased::after {
  content: "";
  position: absolute;
  top: -2px;
  right: -9px;
  width: 36px;
  height: 7px;
  background: rgba(20, 17, 14, 0.92);
  border-radius: 999px;
  transform: rotate(45deg);
  transform-origin: center;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.22);
  pointer-events: none;
  z-index: 2;
}

.detail-photo.is-deceased::after {
  top: 8px;
  right: -16px;
  width: 78px;
  height: 12px;
}

.row-name {
  display: -webkit-box;
  max-height: 2.35em;
  overflow: hidden;
  overflow-wrap: anywhere;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  white-space: normal;
  font-weight: 750;
  line-height: 1.18;
}

.node-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 750;
}

.row-meta,
.node-meta {
  color: var(--muted);
  font-size: 12px;
  margin-top: 3px;
}

.tree-panel {
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  position: relative;
  z-index: 1;
}

.tree-toolbar {
  min-height: 58px;
  display: flex;
  align-items: center;
  gap: 14px;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--paper);
}

.focus-title {
  min-width: 0;
}

.focus-title span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 2px;
}

.focus-title strong {
  display: block;
  max-width: 48vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 17px;
}

.toolbar-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-button {
  width: 38px;
  padding: 0;
  font-size: 20px;
}

.compact-button {
  padding: 0 12px;
}

#zoomInput {
  width: 118px;
  padding: 0;
  accent-color: var(--green);
}

.relation-count {
  min-width: 92px;
  color: var(--green);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

#treeScopeSelect {
  width: 150px;
}

#depthSelect {
  width: 92px;
}

.tree-scroll {
  min-height: 0;
  overflow: auto;
  position: relative;
  cursor: grab;
  touch-action: auto;
  overscroll-behavior: auto;
  user-select: none;
  background:
    linear-gradient(90deg, rgba(221, 214, 200, 0.32) 1px, transparent 1px),
    linear-gradient(rgba(221, 214, 200, 0.32) 1px, transparent 1px),
    #fbf7ef;
  background-size: 36px 36px;
}

.tree-scroll:active {
  cursor: grabbing;
}

.tree-content {
  position: relative;
  min-width: 100%;
  min-height: 100%;
}

.tree-stage {
  position: relative;
  transform-origin: top left;
}

.tree-links,
.tree-nodes {
  position: absolute;
  inset: 0;
}

.tree-links path {
  fill: none;
  stroke: rgba(49, 92, 73, 0.42);
  stroke-width: 2;
}

.tree-links path.spouse-link {
  stroke: rgba(184, 92, 56, 0.55);
  stroke-dasharray: 5 5;
}

.person-node {
  position: absolute;
  width: 196px;
  height: 96px;
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  padding: 10px;
  background: rgba(255, 253, 248, 0.98);
  border: 1px solid var(--line);
  border-left: 5px solid var(--green);
  border-radius: 8px;
  box-shadow: 0 6px 18px rgba(44, 39, 29, 0.1);
  text-align: left;
  transform-origin: center;
}

.node-text {
  min-width: 0;
}

.person-node.female {
  border-left-color: var(--clay);
}

.person-node.selected {
  z-index: 6;
  background: linear-gradient(135deg, #fff8df 0%, #fffdf8 62%);
  border-color: var(--gold);
  border-left-color: var(--gold);
  box-shadow:
    0 0 0 4px rgba(215, 163, 58, 0.26),
    0 16px 34px rgba(44, 39, 29, 0.22);
  transform: scale(1.14);
}

.person-node.selected::after {
  content: "Главный";
  position: absolute;
  top: -14px;
  right: 12px;
  min-height: 24px;
  display: inline-flex;
  align-items: center;
  padding: 0 10px;
  border-radius: 8px;
  background: var(--gold);
  color: #2b2415;
  border: 1px solid rgba(92, 70, 25, 0.22);
  box-shadow: 0 6px 14px rgba(44, 39, 29, 0.16);
  font-size: 12px;
  font-weight: 850;
}

.person-node.selected .node-photo {
  border-color: rgba(215, 163, 58, 0.78);
  box-shadow: inset 0 0 0 2px rgba(255, 248, 223, 0.84);
}

.tree-stage.all-tree .person-node {
  width: 216px;
  height: 68px;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 8px;
  padding: 8px 10px 8px 8px;
  border-left-width: 3px;
  box-shadow: 0 3px 10px rgba(44, 39, 29, 0.09);
}

.tree-stage.all-tree .person-node.selected {
  box-shadow: 0 0 0 2px rgba(215, 163, 58, 0.28), 0 5px 14px rgba(44, 39, 29, 0.14);
  transform: scale(1.08);
}

.tree-stage.all-tree .person-node.selected::after {
  display: none;
}

.tree-stage.all-tree .node-photo {
  width: 42px;
  height: 50px;
  border-radius: 6px;
  font-size: 12px;
}

.tree-stage.all-tree .node-name {
  font-size: 12px;
  line-height: 1.12;
  white-space: normal;
  display: block;
  max-height: 2.24em;
  overflow: hidden;
  overflow-wrap: anywhere;
  word-break: normal;
  text-overflow: clip;
}

.tree-stage.all-tree .node-name.name-long {
  font-size: 11px;
  line-height: 1.1;
  max-height: 2.2em;
}

.tree-stage.all-tree .node-name.name-very-long {
  font-size: 10px;
  line-height: 1.08;
  max-height: 2.16em;
}

.tree-stage.all-tree .node-meta {
  display: none;
}

.tree-stage.all-tree .tree-links path {
  stroke-width: 1.4;
}

.node-photo {
  width: 56px;
  height: 68px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  color: var(--green);
  font-weight: 800;
}

.node-name {
  white-space: normal;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  line-height: 1.16;
  font-size: 14px;
}

.details-head {
  padding: 18px;
  display: grid;
  gap: 14px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.detail-photo {
  width: 132px;
  height: 160px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  color: var(--green);
  font-size: 34px;
  font-weight: 800;
}

.profile-photo-panel {
  display: grid;
  gap: 8px;
  width: 132px;
}

.profile-photo-controls {
  display: grid;
  gap: 6px;
}

.profile-hide-button {
  min-height: 38px;
  padding: 7px 8px;
  border-color: rgba(184, 67, 42, 0.35);
  color: #8d2f1f;
  font-size: 12px;
  font-weight: 850;
  line-height: 1.15;
}

.profile-unhide-button,
.photo-viewer-unhide {
  min-height: 38px;
  padding: 7px 8px;
  border-color: rgba(49, 92, 73, 0.32);
  color: var(--green);
  font-size: 12px;
  font-weight: 850;
  line-height: 1.15;
}

.profile-photo-hidden-status {
  display: inline-flex;
  justify-content: center;
  min-height: 30px;
  align-items: center;
  padding: 4px 8px;
  border-radius: 7px;
  background: rgba(20, 18, 14, 0.84);
  color: #fffaf0;
  font-size: 11px;
  font-weight: 900;
}

.details-head h2 {
  margin: 0;
  font-size: 24px;
  line-height: 1.1;
}

.details-title-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto 38px 38px 38px;
  gap: 10px;
  align-items: start;
}

.details-title-row h2 {
  min-width: 0;
}

.system-user-badge {
  align-self: center;
  display: inline-flex;
  min-height: 28px;
  align-items: center;
  padding: 0 8px;
  border: 1px solid rgba(49, 92, 73, 0.28);
  border-radius: 7px;
  background: var(--green-2);
  color: var(--green);
  font-size: 12px;
  font-weight: 850;
  white-space: nowrap;
}

.edit-card-button,
.message-person-button,
.add-relative-button {
  width: 38px;
  height: 38px;
  padding: 0;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff8df;
  color: var(--green);
  box-shadow: 0 5px 14px rgba(44, 39, 29, 0.08);
  font-size: 22px;
  font-weight: 800;
  line-height: 1;
}

.edit-card-button:hover,
.message-person-button:hover,
.add-relative-button:hover {
  border-color: var(--gold);
  color: #2b2415;
}

.person-node.has-system-user::before {
  content: "";
  position: absolute;
  top: 7px;
  right: 7px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 2px var(--surface);
}

.details-head .years {
  color: var(--muted);
  margin-top: 6px;
}

.relationship-badge {
  width: fit-content;
  max-width: 100%;
  display: grid;
  gap: 2px;
  margin-top: 10px;
  padding: 8px 11px;
  border: 1px solid rgba(49, 92, 73, 0.28);
  border-left: 4px solid var(--green);
  border-radius: 8px;
  background: #eef6f0;
  box-shadow: 0 8px 18px rgba(49, 92, 73, 0.09);
}

.relationship-badge span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.relationship-badge strong {
  color: var(--green);
  font-size: 17px;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.relationship-badge.nonblood {
  border-color: rgba(185, 97, 58, 0.26);
  border-left-color: var(--copper);
  background: #fff7ed;
}

.relationship-badge.nonblood strong {
  color: #8d4a2a;
}

.details-body {
  padding: 16px 18px 22px;
  display: grid;
  gap: 18px;
}

.detail-section {
  display: grid;
  gap: 9px;
}

.detail-section h3 {
  margin: 0;
  font-size: 13px;
  text-transform: uppercase;
  color: var(--muted);
  letter-spacing: 0;
}

.facts {
  display: grid;
  gap: 8px;
}

.fact {
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr);
  gap: 10px;
  font-size: 14px;
}

.fact span:first-child {
  color: var(--muted);
}

.notes {
  margin: 0;
  white-space: pre-wrap;
  line-height: 1.45;
}

.contribution-list,
.change-history {
  display: grid;
  gap: 8px;
}

.contribution-item {
  margin: 0;
  padding: 11px 12px;
  background: #fffaf0;
  border: 1px solid rgba(215, 163, 58, 0.34);
  border-radius: 8px;
}

.contribution-item p {
  margin: 0;
  white-space: pre-wrap;
  line-height: 1.45;
}

.contribution-item footer,
.change-history-item span,
.dialog-signature {
  display: block;
  margin-top: 7px;
  color: var(--muted);
  font-size: 12px;
}

.form-grid {
  display: grid;
  gap: 10px;
}

.form-grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.change-history-item {
  padding: 9px 10px;
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.change-history-item strong {
  display: block;
  font-size: 13px;
}

.uploaded-photo-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.uploaded-photo-item {
  display: grid;
  gap: 6px;
  color: inherit;
  text-decoration: none;
}

.uploaded-photo-item a,
.photo-view-button {
  color: inherit;
  text-decoration: none;
}

.photo-view-button {
  width: 100%;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  display: block;
  cursor: zoom-in;
  text-align: inherit;
}

.uploaded-photo-item img {
  width: 100%;
  aspect-ratio: 1;
  display: block;
  object-fit: cover;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.uploaded-photo-item span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
}

.uploaded-photo-item strong {
  width: fit-content;
  padding: 3px 7px;
  border-radius: 6px;
  background: #efe7d8;
  color: var(--muted);
  font-size: 11px;
}

.uploaded-photo-item.is-hidden img {
  opacity: 0.42;
  filter: grayscale(1);
}

.uploaded-photo-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(88px, 1fr));
  gap: 6px;
}

.uploaded-photo-actions button {
  min-height: 32px;
  padding: 0 8px;
  font-size: 12px;
}

.photo-viewer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 120;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(20, 18, 14, 0.82);
}

.photo-viewer {
  width: min(100%, 1040px);
  height: min(100%, 760px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 10px;
}

.photo-viewer header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid rgba(255, 253, 248, 0.2);
  border-radius: 8px;
  background: var(--surface);
}

.photo-viewer header strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.photo-viewer-hide {
  border-color: rgba(184, 67, 42, 0.35);
  color: #8d2f1f;
}

.photo-viewer-profile {
  border-color: rgba(49, 92, 73, 0.32);
  color: var(--green);
}

.photo-viewer-status,
.hidden-photo-badge,
.profile-photo-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 6px;
  background: rgba(20, 18, 14, 0.82);
  color: #fffaf0;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0;
}

.photo-viewer-frame {
  min-height: 0;
  display: grid;
  place-items: center;
  overflow: auto;
}

.photo-viewer-frame img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 8px;
  background: #161410;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.36);
}

.relation-list,
.event-list,
.family-list,
.kinship-list {
  display: grid;
  gap: 7px;
}

.relation-button {
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  text-align: left;
  border: 1px solid var(--line);
  background: white;
  border-radius: 8px;
  color: var(--ink);
  font-weight: 650;
}

.family-block {
  display: grid;
  gap: 9px;
  padding: 10px;
  background: #fffaf0;
  border: 1px solid rgba(215, 163, 58, 0.28);
  border-radius: 8px;
}

.family-partner,
.family-children {
  display: grid;
  gap: 6px;
}

.family-partner > span,
.family-children > span,
.kinship-button span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.family-block small {
  color: var(--muted);
  font-size: 12px;
}

.kinship-button {
  display: grid;
  gap: 3px;
}

.kinship-button strong {
  font-size: 14px;
}

.event-item {
  padding: 9px 10px;
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.event-item strong {
  display: block;
  font-size: 14px;
}

.event-item span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.gallery {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.gallery-item {
  position: relative;
  aspect-ratio: 1;
  display: block;
  overflow: hidden;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.gallery-item.is-hidden-tree img {
  filter: grayscale(1) brightness(0.55);
}

.gallery-item .hidden-photo-badge {
  position: absolute;
  right: 6px;
  bottom: 6px;
}

.gallery-item .profile-photo-badge {
  position: absolute;
  left: 6px;
  top: 6px;
  background: var(--gold);
  color: #2b2415;
}

.gallery-action-hint {
  position: absolute;
  left: 6px;
  right: 6px;
  bottom: 6px;
  min-height: 26px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 3px 6px;
  border-radius: 6px;
  background: rgba(255, 253, 248, 0.92);
  color: var(--green);
  font-size: 11px;
  font-weight: 900;
  text-align: center;
  line-height: 1.1;
}

.detail-photo[data-view-photo] {
  cursor: zoom-in;
}

.gallery-item video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.video-tile {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.edit-dialog.admin-dialog {
  width: min(940px, calc(100vw - 32px));
  max-height: calc(100vh - 44px);
  overflow: auto;
}

.admin-tabs {
  display: flex;
  gap: 5px;
  padding: 4px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.admin-tab {
  min-height: 36px;
  flex: 1;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
}

.admin-tab.active {
  background: white;
  border-color: rgba(49, 92, 73, 0.2);
  color: var(--green);
  box-shadow: 0 6px 18px rgba(44, 39, 29, 0.08);
}

.admin-panel {
  display: grid;
  gap: 12px;
}

.admin-change-list {
  display: grid;
  gap: 10px;
  max-height: min(560px, calc(100vh - 260px));
  overflow: auto;
  padding-right: 4px;
}

.admin-change {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  padding: 12px;
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.admin-change.reverted {
  opacity: 0.62;
}

.admin-change-top {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
}

.admin-change-top span {
  color: var(--muted);
  font-size: 12px;
}

.admin-change p {
  margin: 6px 0 0;
  font-weight: 750;
}

.admin-change small,
.admin-change footer {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.admin-change-actions {
  display: flex;
  gap: 8px;
  align-items: start;
}

.admin-user-form {
  display: grid;
  gap: 10px;
  padding: 12px;
  background: #fffaf0;
  border: 1px solid rgba(215, 163, 58, 0.34);
  border-radius: 8px;
}

.admin-user-list {
  display: grid;
  gap: 10px;
}

.admin-user {
  display: grid;
  grid-template-columns: minmax(180px, 0.72fr) minmax(0, 1.5fr);
  gap: 14px;
  padding: 12px;
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.admin-user-main strong,
.admin-user-main span,
.admin-user-main small {
  display: block;
}

.admin-user-main strong {
  font-size: 16px;
}

.admin-user-main span,
.admin-user-main small {
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
}

.admin-user-tools {
  display: grid;
  grid-template-columns: 140px minmax(160px, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.admin-user-actions {
  display: flex;
  gap: 8px;
  align-items: end;
}

.admin-user-message {
  grid-column: 1 / -1;
}

.danger-button {
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid rgba(151, 55, 55, 0.28);
  border-radius: 8px;
  background: #fff3f1;
  color: #8d2f2a;
  font-weight: 800;
}

.empty-state {
  height: 100%;
  display: grid;
  place-items: center;
  color: var(--muted);
  padding: 24px;
  text-align: center;
}

.empty-state.small {
  min-height: 120px;
  height: auto;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(22, 24, 21, 0.5);
  backdrop-filter: blur(4px);
}

.edit-dialog {
  width: min(100%, 520px);
  max-height: calc(100vh - 44px);
  display: grid;
  gap: 14px;
  padding: 18px;
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 24px 70px rgba(25, 24, 19, 0.28);
}

.dialog-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 38px;
  gap: 12px;
  align-items: start;
}

.dialog-head h2 {
  margin: 0;
  font-size: 24px;
  line-height: 1.1;
}

.dialog-head p,
.edit-dialog label span {
  display: block;
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.edit-dialog label {
  display: grid;
  gap: 7px;
}

.edit-dialog .checkbox-line {
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffaf0;
}

.edit-dialog .checkbox-line input {
  width: 18px;
  height: 18px;
  accent-color: var(--green);
}

.edit-dialog .checkbox-line span {
  margin: 0;
  color: var(--text);
  font-weight: 700;
}

.edit-dialog input[type="file"] {
  padding: 8px 10px;
  background: #fffaf0;
}

.dialog-close {
  font-size: 24px;
  line-height: 1;
}

.dialog-signature {
  margin: 0;
}

.dialog-actions {
  position: sticky;
  bottom: -18px;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin: 0 -18px -18px;
  padding: 12px 18px 18px;
  background: linear-gradient(180deg, rgba(255, 252, 246, 0), var(--surface) 28%);
  border-top: 1px solid rgba(222, 214, 199, 0.72);
}

.feedback-dialog {
  max-height: calc(100vh - 44px);
  overflow: auto;
}

.feedback-note {
  display: grid;
  gap: 10px;
  padding: 12px;
  background: #fffaf0;
  border: 1px solid rgba(215, 163, 58, 0.34);
  border-radius: 8px;
  line-height: 1.48;
}

.feedback-note p {
  margin: 0;
}

.feedback-note a {
  color: var(--green);
  font-weight: 850;
}

.chat-dialog {
  width: min(680px, calc(100vw - 32px));
  gap: 14px;
}

.chat-online-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.message-recipient-field {
  margin: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.message-recipient-field legend {
  padding: 0 5px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.message-recipient-list {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
  max-height: 104px;
  overflow: auto;
}

.message-recipient-option {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  font-size: 13px;
  font-weight: 750;
}

.chat-messages {
  display: grid;
  gap: 10px;
  min-height: 260px;
  max-height: min(52vh, 520px);
  overflow: auto;
  padding: 12px;
  background: #f7f3ea;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.chat-empty {
  margin: auto;
  color: var(--muted);
  text-align: center;
}

.chat-message {
  display: grid;
  gap: 6px;
  padding: 10px 12px;
  background: white;
  border: 1px solid rgba(221, 214, 200, 0.82);
  border-radius: 8px;
}

.chat-message header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.chat-message header span {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.chat-message p {
  margin: 0;
  line-height: 1.45;
  white-space: pre-wrap;
}

.message-attachment {
  width: min(100%, 240px);
  display: grid;
  gap: 6px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--ink);
  text-align: left;
}

.message-attachment img {
  width: 100%;
  max-height: 180px;
  object-fit: cover;
  border-radius: 6px;
  display: block;
}

.message-attachment span,
.message-file-field small {
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-form {
  display: grid;
  gap: 12px;
}

.message-file-field input {
  min-height: 40px;
  padding: 7px;
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 280px minmax(0, 1fr);
    grid-template-rows: 64px minmax(0, 58vh) minmax(360px, auto);
  }

  .details-panel {
    grid-column: 1 / -1;
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .gallery {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  html,
  body {
    height: auto;
    min-height: 100%;
    overflow-x: hidden;
    overflow-y: auto;
  }

  .login-view {
    grid-template-columns: 1fr;
    align-content: end;
    padding: 22px;
    background:
      linear-gradient(180deg, rgba(10, 15, 13, 0.28), rgba(15, 22, 19, 0.7) 54%, rgba(247, 243, 234, 0.88) 100%),
      var(--paper);
  }

  .login-view::before {
    background-position: center top;
    background-size: contain;
  }

  .login-intro {
    align-self: start;
    min-height: 28vh;
    margin-bottom: 0;
  }

  .login-intro-crest {
    width: 132px;
    height: 132px;
    margin-bottom: 12px;
  }

  .login-intro-title {
    font-size: 42px;
  }

  .login-panel {
    justify-self: stretch;
    width: 100%;
  }

  .app-shell {
    display: block;
    height: auto;
    min-height: 100dvh;
    overflow: visible;
  }

  .topbar {
    position: sticky;
    top: 0;
    z-index: 40;
    grid-template-columns: auto 1fr auto auto;
    grid-template-areas:
      "title title chat logout"
      "feedback feedback feedback admin";
    gap: 10px;
    padding: 8px 10px;
  }

  .topbar-title {
    grid-area: title;
    min-width: 0;
    gap: 2px;
  }

  #logoutButton {
    grid-area: logout;
    justify-self: end;
    margin-left: 0;
  }

  #chatButton {
    grid-area: chat;
  }

  #adminButton {
    grid-area: admin;
  }

  .brand-mark.small {
    width: 44px;
    height: 44px;
    border-radius: 10px;
  }

  .topbar-title strong {
    font-size: 16px;
    max-width: 100%;
  }

  .topbar-title span,
  #importStamp {
    display: none;
  }

  .topbar-actions {
    display: flex;
    gap: 6px;
    flex: 0 0 auto;
  }

  .topbar-actions button {
    min-height: 36px;
    padding: 0 9px;
    font-size: 13px;
  }

  #feedbackButton {
    grid-area: feedback;
  }

  .topbar:has(#adminButton.hidden) {
    grid-template-areas:
      "title title chat logout"
      "feedback feedback feedback feedback";
  }

  .stats {
    display: none;
  }

  .sidebar {
    min-height: 0;
    max-height: none;
    padding: 8px 10px;
    overflow: hidden;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .sidebar h2,
  .list-count {
    display: none;
  }

  .people-list {
    grid-auto-flow: column;
    grid-auto-columns: minmax(238px, 78vw);
    overflow-x: auto;
    overflow-y: hidden;
    padding: 2px 2px 8px;
    scroll-snap-type: x proximity;
  }

  .person-row {
    min-height: 58px;
    padding: 6px;
    grid-template-columns: 38px minmax(0, 1fr);
    scroll-snap-align: start;
  }

  .person-row .avatar {
    width: 38px;
    height: 38px;
    border-radius: 8px;
  }

  .row-name {
    max-height: 2.28em;
    font-size: 14px;
  }

  .row-meta {
    font-size: 11px;
    margin-top: 2px;
  }

  .tree-panel {
    min-height: 0;
    height: 68dvh;
    min-height: 440px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .tree-toolbar {
    position: relative;
    top: auto;
    z-index: 12;
    flex-wrap: wrap;
    gap: 5px;
    padding: 10px 10px 8px;
    box-shadow: 0 -1px 0 var(--line), 0 1px 0 var(--line);
  }

  .focus-title {
    display: none;
  }

  .toolbar-controls {
    width: 100%;
    display: grid;
    grid-template-columns: 36px minmax(0, 1fr) 36px 1.05fr 58px;
    gap: 6px;
  }

  .toolbar-controls button,
  .toolbar-controls select {
    min-height: 36px;
  }

  .relation-count {
    display: none;
  }

  #treeScopeSelect,
  #depthSelect {
    width: 100%;
    min-width: 0;
  }

  #treeScopeSelect {
    grid-column: 4 / 5;
  }

  #depthSelect {
    grid-column: 5 / 6;
  }

  #zoomInput {
    min-width: 0;
    width: 100%;
  }

  .tree-scroll {
    height: 100%;
  }

  .tree-stage.mobile-tree .person-node {
    width: 236px;
    height: 116px;
    grid-template-columns: 68px minmax(0, 1fr);
    gap: 12px;
    padding: 12px;
  }

  .tree-stage.mobile-tree .node-photo {
    width: 68px;
    height: 84px;
    font-size: 18px;
  }

  .tree-stage.mobile-tree .node-name {
    font-size: 16px;
    line-height: 1.16;
  }

  .tree-stage.mobile-tree .node-meta {
    font-size: 13px;
  }

  .tree-stage.mobile-tree.all-tree .person-node {
    width: 260px;
    height: 88px;
    grid-template-columns: 58px minmax(0, 1fr);
    padding: 10px;
  }

  .tree-stage.mobile-tree.all-tree .node-photo {
    width: 58px;
    height: 68px;
  }

  .tree-stage.mobile-tree.all-tree .node-name {
    font-size: 15px;
    line-height: 1.14;
  }

  .details-panel {
    min-height: auto;
    overflow: visible;
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .details-head {
    grid-template-columns: 64px minmax(0, 1fr);
    gap: 12px;
    padding: 10px 12px;
  }

  .detail-photo {
    width: 64px;
    height: 78px;
    font-size: 20px;
  }

  .profile-photo-panel {
    width: 64px;
  }

  .profile-hide-button {
    min-height: 34px;
    padding: 5px 4px;
    font-size: 10px;
  }

  .details-head h2 {
    font-size: 18px;
  }

  .details-title-row {
    grid-template-columns: minmax(0, 1fr) repeat(3, 36px);
    gap: 7px;
  }

  .edit-card-button,
  .message-person-button,
  .add-relative-button {
    width: 36px;
    height: 36px;
  }

  .system-user-badge {
    grid-column: 1 / -1;
    justify-self: start;
  }

  .relationship-badge {
    margin-top: 8px;
    padding: 7px 9px;
  }

  .relationship-badge strong {
    font-size: 15px;
  }

  .details-body {
    padding: 10px 12px 14px;
    gap: 12px;
  }

  .fact {
    grid-template-columns: 1fr;
    gap: 3px;
  }

  .uploaded-photo-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .gallery {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .modal-backdrop {
    padding: 8px;
    align-items: stretch;
  }

  .edit-dialog {
    width: 100%;
    max-height: calc(100dvh - 16px);
    align-self: center;
    padding: 14px;
  }

  .dialog-actions {
    bottom: -14px;
    margin: 0 -14px -14px;
    padding: 10px 14px 14px;
  }

  .dialog-actions button {
    flex: 1;
    min-height: 42px;
  }

  .admin-dialog {
    width: 100%;
  }

  .photo-viewer-backdrop {
    padding: 8px;
  }

  .photo-viewer {
    width: 100%;
    height: 100%;
  }

  .photo-viewer header {
    padding: 8px;
  }

  .photo-viewer-close {
    min-height: 40px;
  }

  .form-grid.two,
  .admin-change,
  .admin-user,
  .admin-user-tools {
    grid-template-columns: 1fr;
  }

  .admin-change-actions,
  .admin-user-actions {
    width: 100%;
  }

  .admin-change-actions button,
  .admin-user-actions button {
    flex: 1;
  }
}
