/* Domus — семейная летопись. Тёплая «бумажная» палитра, заголовки с засечками. */
:root {
  --bg: #f6f2ea;
  --paper: #fffdf9;
  --ink: #26221c;
  --muted: #73695b;
  --line: #e4dccd;
  --line-strong: #cfc4b0;
  --accent: #3d5c48;
  --accent-ink: #ffffff;
  --accent-soft: #e5ece4;
  --link: #2c5a73;
  --male: #dbe5ef;
  --male-ink: #2e4f6c;
  --female: #f1e0e2;
  --female-ink: #7a3a45;
  --gold: #a5792a;
  --memorial: #6d6a8a;
  --danger: #a33a2c;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(60, 45, 20, .06), 0 6px 20px rgba(60, 45, 20, .06);
  --serif: Georgia, "PT Serif", "Times New Roman", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.55 var(--sans);
}
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { font-family: var(--serif); font-weight: 400; line-height: 1.2; }
img { max-width: 100%; }
.wrap { max-width: 1240px; margin: 0 auto; padding: 0 24px; }
.main { padding-top: 28px; padding-bottom: 40px; min-height: calc(100vh - 140px); }
.muted { color: var(--muted); }
.code { font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; font-size: .9em; color: var(--muted); }

/* ---- Шапка ---- */
.topbar { background: var(--paper); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 50; }
.topbar__inner { display: flex; align-items: center; gap: 28px; height: 60px; }
.brand { display: flex; align-items: center; gap: 8px; color: var(--accent); font: 24px/1 var(--serif); letter-spacing: .02em; }
.brand:hover { text-decoration: none; }
.brand__mark { width: 28px; height: 28px; }
.nav { display: flex; gap: 4px; }
.nav a { padding: 6px 12px; border-radius: 6px; color: var(--ink); }
.nav a:hover { background: var(--bg); text-decoration: none; }
.nav a.is-active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.search { position: relative; margin-left: auto; }
.search input {
  width: 260px; padding: 8px 12px; border: 1px solid var(--line-strong); border-radius: 8px;
  background: var(--bg); font: inherit; color: inherit;
}
.search input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); background: var(--paper); }
.search__suggest {
  position: absolute; top: 42px; left: 0; right: 0; margin: 0; padding: 4px 0; list-style: none;
  background: var(--paper); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow);
}
.search__suggest a { display: flex; gap: 10px; align-items: center; padding: 6px 12px; color: var(--ink); }
.search__suggest a:hover, .search__suggest .is-active a { background: var(--bg); text-decoration: none; }
.search__suggest small { color: var(--muted); }
.userbox { display: flex; align-items: center; gap: 14px; font-size: 14px; color: var(--muted); }
.userbox form { margin: 0; }
.link-button { background: none; border: 0; padding: 0; font: inherit; color: var(--link); cursor: pointer; }
.link-button:hover { text-decoration: underline; }

.footer { color: var(--muted); font-size: 13px; padding-top: 24px; padding-bottom: 32px; border-top: 1px solid var(--line); }

/* ---- Кнопки и поля ---- */
.button {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 16px; border-radius: 8px; border: 1px solid var(--line-strong);
  background: var(--paper); color: var(--ink); font: inherit; cursor: pointer; white-space: nowrap;
}
.button:hover { text-decoration: none; border-color: var(--accent); }
.button--primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.button--primary:hover { background: #33503e; }
.button--ghost { background: transparent; }
.button--wide { width: 100%; }
select, input[type=search], input[type=text], input[type=password] {
  padding: 8px 10px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--paper);
  font: inherit; color: inherit;
}

.messages { list-style: none; padding: 0; margin: 0 0 20px; }
.messages__item { padding: 10px 14px; border-radius: 8px; background: var(--accent-soft); margin-bottom: 8px; }
.messages__item--error { background: #f5dfdb; color: var(--danger); }

/* ---- Аватары и «чипы» людей ---- */
.avatar {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  border-radius: 50%; object-fit: cover; font-weight: 600; letter-spacing: .02em;
  background: var(--line); color: var(--muted);
}
.avatar--M { background: var(--male); color: var(--male-ink); }
.avatar--F { background: var(--female); color: var(--female-ink); }
.avatar--sm { width: 32px; height: 32px; font-size: 12px; }
.avatar--lg { width: 56px; height: 56px; font-size: 18px; }
.avatar--xl { width: 96px; height: 96px; font-size: 30px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 8px; padding: 4px 12px 4px 4px;
  background: var(--paper); border: 1px solid var(--line); border-radius: 999px; color: var(--ink);
  max-width: 100%;
}
a.chip:hover { border-color: var(--accent); text-decoration: none; box-shadow: var(--shadow); }
.chip__text { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.chip__name { font-weight: 600; font-size: 14px; }
.chip__meta { font-size: 12px; color: var(--muted); }
.chip--empty { padding: 8px 14px; color: var(--muted); border-style: dashed; background: transparent; font-size: 13px; }
.chip--self { border-color: var(--accent); background: var(--accent-soft); }

.badge {
  display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: #f3e8d2; color: var(--gold); vertical-align: middle;
}
.badge--quiet { background: var(--bg); color: var(--muted); font-weight: 500; }

/* ---- Главная ---- */
.hero {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 24px;
  padding: 8px 0 28px; border-bottom: 1px solid var(--line); margin-bottom: 28px;
}
.hero__title { font-size: 44px; margin: 0 0 8px; }
.hero__lead { margin: 0; color: var(--muted); font-size: 17px; max-width: 640px; }
.hero__actions { display: flex; gap: 10px; }
.home-grid { display: grid; grid-template-columns: 1.1fr 1fr; gap: 20px; }
.panel { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px 22px; }
.panel--wide { grid-column: 1 / -1; }
.panel__title { font-size: 20px; margin: 0 0 16px; display: flex; justify-content: space-between; align-items: baseline; }
.panel__more { font: 14px var(--sans); }
.feature { display: flex; gap: 18px; align-items: center; color: var(--ink); }
.feature:hover { text-decoration: none; }
.feature:hover .feature__name { color: var(--link); }
.feature > span:last-child { display: flex; flex-direction: column; gap: 4px; }
.feature__name { font: 22px/1.25 var(--serif); }
.feature__meta { color: var(--muted); }
.feature__summary { margin-top: 4px; }
.empty { padding: 48px; text-align: center; background: var(--paper); border: 1px dashed var(--line-strong); border-radius: var(--radius); color: var(--muted); }

.dates { list-style: none; margin: 0; padding: 0; }
.dates__item { display: flex; gap: 14px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.dates__item:last-child { border-bottom: 0; }
.dates__day { flex: none; width: 92px; font-weight: 600; }
.dates__item--birthday .dates__day { color: var(--accent); }
.dates__item--memorial .dates__day, .dates__item--birth_memorial .dates__day { color: var(--memorial); }
.dates__item--wedding .dates__day { color: var(--gold); }
.dates__body { display: flex; flex-direction: column; }
.dates__title { font-size: 13px; color: var(--muted); }

/* ---- Список людей ---- */
.page-title { font-size: 32px; margin: 0 0 20px; }
.page-title__count { font: 600 15px var(--sans); color: var(--muted); background: var(--paper); border: 1px solid var(--line); padding: 2px 10px; border-radius: 999px; vertical-align: middle; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 24px; padding: 14px; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); }
.filters__q { flex: 1 1 260px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.card {
  position: relative; display: flex; gap: 14px; align-items: center; padding: 14px;
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); color: var(--ink);
}
.card:hover { border-color: var(--accent); box-shadow: var(--shadow); text-decoration: none; }
.card__body { display: flex; flex-direction: column; min-width: 0; }
.card__name { font: 17px/1.25 var(--serif); }
.card__patronymic { font-size: 13px; }
.card__meta { font-size: 13px; color: var(--muted); }
.card__code { position: absolute; top: 10px; right: 12px; font-size: 11px; color: var(--muted); font-family: ui-monospace, monospace; }
.pager { display: flex; gap: 20px; justify-content: center; margin-top: 24px; color: var(--muted); }

/* ---- Страница человека ---- */
.article { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 28px 32px 36px; }
.article__head { display: flex; justify-content: space-between; gap: 20px; align-items: flex-start; border-bottom: 1px solid var(--line-strong); padding-bottom: 14px; margin-bottom: 24px; }
.article__title { font-size: 36px; margin: 0 0 4px; }
.article__sub { margin: 0; color: var(--muted); }
.article__tools { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.article__layout { display: flex; flex-direction: row-reverse; gap: 32px; align-items: flex-start; }
.article__main { flex: 1; min-width: 0; }

.infobox { flex: none; width: 300px; border: 1px solid var(--line-strong); background: #fbf8f1; border-radius: 8px; padding: 12px; font-size: 14px; }
.infobox__photo { display: block; width: 100%; border-radius: 6px; cursor: zoom-in; }
.infobox__placeholder { display: flex; align-items: center; justify-content: center; height: 220px; border-radius: 6px; font: 64px var(--serif); background: var(--line); color: var(--muted); }
.infobox__placeholder.avatar--M { background: var(--male); color: var(--male-ink); }
.infobox__placeholder.avatar--F { background: var(--female); color: var(--female-ink); }
.infobox__caption { text-align: center; font-family: var(--serif); font-size: 16px; padding: 10px 0; border-bottom: 1px solid var(--line); margin-bottom: 6px; }
.infobox__table { width: 100%; border-collapse: collapse; }
.infobox__table th { text-align: left; vertical-align: top; font-weight: 600; padding: 5px 10px 5px 0; width: 42%; color: var(--ink); }
.infobox__table td { padding: 5px 0; vertical-align: top; }

.toc { display: inline-block; background: #fbf8f1; border: 1px solid var(--line-strong); border-radius: 8px; padding: 12px 20px 10px; margin-bottom: 8px; font-size: 14px; }
.toc__title { font-weight: 600; margin-bottom: 4px; }
.toc ol { margin: 0; padding-left: 20px; }

.section { margin-top: 28px; }
.section h2 { font-size: 24px; margin: 0 0 14px; padding-bottom: 6px; border-bottom: 1px solid var(--line); }
.section h3 { font-size: 18px; margin: 22px 0 10px; }

.relatives { display: grid; grid-template-columns: 170px 1fr; gap: 14px 18px; margin: 0; }
.relatives dt { font-weight: 600; padding-top: 8px; }
.relatives dd { margin: 0; }
.child-group + .child-group { margin-top: 14px; }
.child-group__head { font-size: 14px; margin-bottom: 6px; }
.sib-row { display: flex; gap: 12px; align-items: center; }
.sib-row + .sib-row { margin-top: 8px; }
.sib-row__label { flex: none; width: 80px; font-size: 13px; color: var(--muted); }

.mini-tree { display: flex; flex-direction: column; gap: 10px; padding: 16px; border: 1px solid var(--line); border-radius: var(--radius); background: #fbf8f1; }
.mini-tree__row { display: flex; gap: 12px; align-items: center; }
.mini-tree__row + .mini-tree__row { padding-top: 10px; border-top: 1px dashed var(--line); }
.mini-tree__label { flex: none; width: 140px; font-size: 13px; color: var(--muted); }
.mini-tree__items { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.mini-tree__plus { color: var(--gold); font-size: 18px; }

.prose { font-size: 16px; line-height: 1.7; max-width: 760px; }
.prose p { margin: 0 0 1em; }
.prose blockquote { margin: 0 0 1em; padding: 4px 0 4px 16px; border-left: 3px solid var(--line-strong); color: var(--muted); font-style: italic; }
.prose--small { font-size: 14px; line-height: 1.6; }
.prose--small p:last-child { margin-bottom: 0; }
.person-link { border-bottom: 1px dotted currentColor; }
.person-link:hover { text-decoration: none; border-bottom-style: solid; }
.person-link.broken { color: var(--danger); cursor: help; }

.timeline { list-style: none; padding: 0; margin: 0; border-left: 2px solid var(--line-strong); }
.timeline__item { display: flex; gap: 18px; padding: 0 0 18px 18px; position: relative; }
.timeline__item::before { content: ""; position: absolute; left: -7px; top: 6px; width: 12px; height: 12px; border-radius: 50%; background: var(--paper); border: 2px solid var(--accent); }
.timeline__date { flex: none; width: 150px; font-weight: 600; color: var(--accent); }
.timeline__title { margin-bottom: 2px; }

.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; }
.gallery__item { margin: 0; }
.gallery__missing { display: flex; align-items: center; justify-content: center; aspect-ratio: 4 / 3; border-radius: 6px; border: 1px dashed var(--line-strong); color: var(--muted); font-size: 13px; background: var(--bg); }
.gallery__item img { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 6px; cursor: zoom-in; border: 1px solid var(--line); }
.gallery__item figcaption, .video figcaption { font-size: 13px; margin-top: 6px; display: flex; flex-direction: column; }
.gallery__item figcaption p, .video figcaption p { margin: 0; }
.videos { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }
.video { margin: 0; }
.video video { width: 100%; border-radius: 6px; background: #000; }
.documents { padding-left: 20px; }
.documents li { margin-bottom: 6px; }

/* ---- Лайтбокс и подсказка ---- */
.lightbox { position: fixed; inset: 0; z-index: 100; background: rgba(20, 16, 10, .92); display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 40px 70px; }
.lightbox img { max-width: 100%; max-height: calc(100vh - 120px); border-radius: 4px; }
.lightbox__caption { color: #eee; margin-top: 12px; text-align: center; }
.lightbox button { position: absolute; background: none; border: 0; color: #fff; font-size: 36px; cursor: pointer; padding: 10px 16px; opacity: .8; }
.lightbox button:hover { opacity: 1; }
.lightbox__close { top: 10px; right: 14px; }
.lightbox__prev { left: 10px; top: 50%; transform: translateY(-50%); }
.lightbox__next { right: 10px; top: 50%; transform: translateY(-50%); }

.hovercard { position: absolute; z-index: 90; width: 280px; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px; display: flex; gap: 12px; pointer-events: none; }
.hovercard[hidden] { display: none; }
.hovercard__name { font: 16px/1.25 var(--serif); }
.hovercard__meta { font-size: 13px; color: var(--muted); }
.hovercard__summary { font-size: 13px; margin-top: 4px; }

/* ---- Древо ---- */
.page-tree .main { max-width: none; }
.tree-head { display: flex; flex-wrap: wrap; gap: 12px 24px; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.tree-head .page-title { margin: 0; font-size: 26px; }
.tree-controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.tree-controls select[name=person] { max-width: 300px; }
.tree-controls__depth { display: flex; gap: 6px; align-items: center; font-size: 14px; color: var(--muted); }
.segmented { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 8px; overflow: hidden; }
.segmented input { display: none; }
.segmented span { display: block; padding: 8px 14px; cursor: pointer; background: var(--paper); }
.segmented input:checked + span { background: var(--accent); color: var(--accent-ink); }
.tree-stage { position: relative; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.tree-svg { display: block; width: 100%; height: calc(100vh - 230px); min-height: 480px; cursor: grab; user-select: none; }
.tree-svg.is-dragging { cursor: grabbing; }
.tree-zoom { position: absolute; top: 12px; right: 12px; display: flex; flex-direction: column; gap: 4px; z-index: 2; }
.tree-zoom button { width: 36px; height: 36px; border-radius: 8px; border: 1px solid var(--line-strong); background: var(--paper); font-size: 18px; cursor: pointer; }
.tree-zoom button:hover { border-color: var(--accent); }
.tree-hint { position: absolute; left: 14px; bottom: 6px; margin: 0; font-size: 12px; color: var(--muted); }
.tnode { cursor: pointer; }
.tnode__box { fill: var(--paper); stroke: var(--line-strong); stroke-width: 1.2; }
.tnode--M .tnode__box { fill: #f2f6fa; stroke: #b9cbdd; }
.tnode--F .tnode__box { fill: #fbf3f4; stroke: #dfc1c6; }
.tnode--focus .tnode__box { stroke: var(--accent); stroke-width: 2.6; }
@media (hover: hover) {
  .tnode:hover .tnode__box { stroke: var(--accent); stroke-width: 2; }
  .tnode--focus:hover .tnode__box { stroke-width: 3; }
}
.tnode__name { font: 600 13px var(--sans); fill: var(--ink); }
.tnode__years { font: 12px var(--sans); fill: var(--muted); }
.tnode__note { font: 11.5px var(--sans); fill: var(--gold); }
.tnode__initials { font: 600 13px var(--sans); fill: var(--muted); }
.tnode__avatar { fill: var(--line); }
.tnode__avatar--M { fill: var(--male); }
.tnode__avatar--F { fill: var(--female); }
.tnode--M .tnode__initials { fill: var(--male-ink); }
.tnode--F .tnode__initials { fill: var(--female-ink); }
.tl-path { fill: none; stroke: var(--line-strong); stroke-width: 1.6; }
.tl-path--marriage { stroke: var(--gold); stroke-width: 2.2; }
.tl-path--divorce { stroke: var(--gold); stroke-width: 2; stroke-dasharray: 7 5; }
.tl-path--coparent { stroke: var(--gold); stroke-width: 2; stroke-dasharray: 2 4; stroke-linecap: round; }
.tree-legend { position: absolute; left: 14px; top: 12px; display: flex; gap: 14px; font-size: 12px; color: var(--muted); background: rgba(255, 253, 249, .9); padding: 4px 8px; border-radius: 6px; }
.tree-legend span { display: inline-flex; align-items: center; gap: 6px; }
.tl { display: inline-block; width: 22px; height: 0; border-top: 2px solid var(--gold); }
.tl--divorce { border-top-style: dashed; }
.tl--coparent { border-top-style: dotted; }

/* ---- Календарь ---- */
.cal-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.cal-head .page-title { margin: 0; min-width: 220px; text-align: center; }
.cal-legend { margin-left: auto; display: flex; gap: 6px 14px; align-items: center; font-size: 13px; color: var(--muted); }
.cal-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: -8px; }
.cal-dot--birthday { background: var(--accent); }
.cal-dot--memorial { background: var(--memorial); }
.cal-dot--wedding { background: var(--gold); }
.calendar { width: 100%; border-collapse: separate; border-spacing: 0; table-layout: fixed; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.calendar th { padding: 10px; font-weight: 600; font-size: 13px; color: var(--muted); border-bottom: 1px solid var(--line); }
.calendar td { height: 110px; vertical-align: top; padding: 6px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.calendar td:last-child { border-right: 0; }
.calendar tr:last-child td { border-bottom: 0; }
.calendar td.is-out { background: var(--bg); }
.calendar td.is-today .calendar__num { background: var(--accent); color: var(--accent-ink); }
.calendar__num { display: inline-flex; width: 26px; height: 26px; align-items: center; justify-content: center; border-radius: 50%; font-size: 13px; font-weight: 600; margin-bottom: 4px; }
.cal-entry { font-size: 12px; line-height: 1.3; padding: 3px 6px; border-radius: 4px; margin-bottom: 3px; border-left: 3px solid; }
.cal-entry a { color: inherit; }
.cal-entry--birthday { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.cal-entry--memorial, .cal-entry--birth_memorial { background: #ebeaf2; border-color: var(--memorial); color: var(--memorial); }
.cal-entry--wedding { background: #f6eedd; border-color: var(--gold); color: #7d5a1c; }

/* ---- Вход ---- */
.page-login .topbar { display: none; }
.login { display: flex; justify-content: center; align-items: center; min-height: 70vh; }
.login__card { width: 380px; background: var(--paper); border: 1px solid var(--line); border-radius: 14px; padding: 36px 34px; box-shadow: var(--shadow); }
.login__title { font-size: 40px; margin: 0; color: var(--accent); text-align: center; }
.login__lead { text-align: center; color: var(--muted); margin: 6px 0 24px; }
.login__hint { font-size: 13px; color: var(--muted); text-align: center; margin: 18px 0 0; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 14px; font-size: 14px; }
.field input { width: 100%; }
.form-error { color: var(--danger); background: #f5dfdb; padding: 8px 12px; border-radius: 8px; }

/* =====================================================================
   Мобильная версия (только сайт; админка рассчитана на компьютер)
   ===================================================================== */
.tree-svg { touch-action: none; }

@media (hover: none) {
  .hovercard { display: none !important; }
}

@media (max-width: 900px) {
  .wrap { padding: 0 16px; }
  .main { padding-top: 18px; }

  .topbar__inner { height: auto; flex-wrap: wrap; gap: 8px 12px; padding-top: 10px; padding-bottom: 10px; }
  .brand { font-size: 22px; }
  .userbox { margin-left: auto; gap: 12px; }
  .userbox__name { display: none; }
  .search { order: 3; flex: 1 0 100%; margin-left: 0; }
  .search input { width: 100%; font-size: 16px; } /* 16px — iOS не зумит поле */
  .nav { order: 4; flex: 1 0 100%; overflow-x: auto; scrollbar-width: none; }
  .nav::-webkit-scrollbar { display: none; }
  .nav a { flex: none; }

  .hero { flex-direction: column; align-items: flex-start; padding-bottom: 20px; margin-bottom: 20px; }
  .hero__title { font-size: 32px; }
  .hero__lead { font-size: 16px; }
  .home-grid { grid-template-columns: 1fr; gap: 14px; }
  .panel { padding: 16px; }
  .feature { align-items: flex-start; }
  .avatar--xl { width: 72px; height: 72px; font-size: 24px; }

  .page-title { font-size: 26px; }
  .filters { padding: 10px; }
  .filters > * { flex: 1 1 calc(50% - 8px); min-width: 0; }
  .filters .filters__q { flex-basis: 100%; }
  select, input[type=search], input[type=text], input[type=password] { font-size: 16px; }
  .cards { grid-template-columns: 1fr; }

  .article { padding: 18px 16px 24px; border-radius: 8px; }
  .article__head { flex-direction: column; gap: 12px; }
  .article__title { font-size: 28px; }
  .article__tools { justify-content: flex-start; }
  .article__tools .button { padding: 6px 12px; font-size: 14px; }
  .article__layout { flex-direction: column; gap: 20px; }
  .infobox { width: 100%; }
  .infobox__photo { max-width: 220px; margin: 0 auto; }
  .infobox__placeholder { height: 160px; font-size: 48px; }
  .toc { display: none; }
  .section { margin-top: 22px; }
  .section h2 { font-size: 22px; }

  .relatives { grid-template-columns: 1fr; gap: 6px; }
  .relatives dt { padding-top: 10px; }
  .relatives dd + dt { border-top: 1px solid var(--line); margin-top: 6px; }
  .sib-row { flex-direction: column; align-items: flex-start; gap: 4px; }
  .sib-row__label { width: auto; }
  .chip { padding-right: 10px; }

  .mini-tree { padding: 12px; }
  .mini-tree__row { flex-direction: column; align-items: flex-start; gap: 6px; }
  .mini-tree__label { width: auto; }

  .timeline__item { flex-direction: column; gap: 2px; }
  .timeline__date { width: auto; }
  .prose { font-size: 16px; }

  .gallery { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .videos { grid-template-columns: 1fr; }

  .lightbox { padding: 48px 8px 16px; }
  .lightbox img { max-height: calc(100vh - 140px); }
  .lightbox__prev, .lightbox__next { top: auto; bottom: 8px; transform: none; }

  .tree-head { flex-direction: column; align-items: stretch; }
  .tree-head .page-title { font-size: 22px; }
  .tree-controls select[name=person] { flex: 1 0 100%; max-width: none; }
  .tree-controls .button { flex: 1; }
  .tree-svg { height: calc(100vh - 330px); min-height: 420px; }
  .tree-hint { display: none; }
  .tree-legend { top: auto; bottom: 10px; gap: 10px; }
  .page-tree .main { padding-left: 0; padding-right: 0; }
  .page-tree .tree-head { padding: 0 16px; }
  .page-tree .tree-stage { border-radius: 0; border-left: 0; border-right: 0; }

  .cal-head { gap: 8px; }
  .cal-head .page-title { min-width: 0; flex: 1; font-size: 22px; }
  .cal-legend { margin-left: 0; flex: 1 0 100%; flex-wrap: wrap; }
  .calendar th { padding: 6px 2px; font-size: 12px; }
  .calendar td { height: 52px; padding: 3px; }
  .calendar__num { width: 22px; height: 22px; font-size: 12px; margin-bottom: 2px; }
  /* в клетке — только цветные точки, подробности в списке под календарём */
  .cal-entry { display: inline-block; width: 8px; height: 8px; padding: 0; margin: 0 2px 0 0; border: 0; border-radius: 50%; font-size: 0; vertical-align: top; }
  .cal-entry a { display: none; }
  .cal-entry--birthday { background: var(--accent); }
  .cal-entry--memorial, .cal-entry--birth_memorial { background: var(--memorial); }
  .cal-entry--wedding { background: var(--gold); }
  .dates__day { width: 84px; }

  .login__card { width: 100%; padding: 28px 22px; }

  .footer { padding-top: 16px; padding-bottom: 24px; }
}

@media (max-width: 380px) {
  .gallery { grid-template-columns: 1fr 1fr; gap: 6px; }
  .dates__item { flex-direction: column; gap: 2px; }
  .dates__day { width: auto; }
}
