:root {
  --bg: #f4f1ea;
  --panel: #ffffff;
  --ink: #2d2a26;
  --ink-soft: #6b6457;
  --line: #c9bfae;
  --line-soft: #e3dccf;
  --accent: #5b7a52;
  --accent-dark: #46603f;
  --male: #cfe0ef;
  --male-line: #6a93bd;
  --female: #f2d6df;
  --female-line: #c0708c;
  --other: #e7e2d6;
  --other-line: #b3a98f;
  --danger: #b2483d;
  --input-bg: #fbfaf6;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 14px rgba(0,0,0,.08);
  --radius: 12px;
  --topbar-h: 60px;
  --sidebar-w: 380px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

/* Atrybut hidden ma zawsze chować element — ważniejsze niż display komponentów
   (np. .modal{display:flex}, .sidebar{display:flex}), inaczej zostają widoczne. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
}

button { font-family: inherit; cursor: pointer; }

/* ---------- Topbar ---------- */
.topbar {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line-soft);
  position: sticky;
  top: 0;
  z-index: 40;
}
.topbar__left { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.logo { font-size: 24px; }
.topbar__title { font-size: 18px; margin: 0; font-weight: 700; white-space: nowrap; }

.sync-status {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px;
  color: var(--ink-soft);
  white-space: nowrap;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--line-soft);
}
.sync-status .sync-dot { color: #bbb; font-size: 11px; line-height: 1; }
.sync-status.is-db { color: var(--accent-dark); }
.sync-status.is-db .sync-dot { color: #4caf50; }
.sync-status.is-local { color: #9a7b1f; }
.sync-status.is-local .sync-dot { color: #d8a01f; }
.sync-status.is-saving { color: var(--ink-soft); }
.sync-status.is-saving .sync-dot { color: #999; }
.sync-status.is-error { color: var(--danger); }
.sync-status.is-error .sync-dot { color: var(--danger); }
.topbar__center { position: relative; flex: 1; max-width: 460px; }
.topbar__right { display: flex; align-items: center; gap: 8px; margin-left: auto; flex-shrink: 0; }

.search {
  width: 100%;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 16px;
  font-size: 14px;
  background: var(--input-bg);
  outline: none;
}
.search:focus { border-color: var(--accent); background: var(--panel); }
.search--block { width: 100%; border-radius: 8px; height: 40px; }

.search-results {
  position: absolute;
  top: 44px; left: 0; right: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  list-style: none;
  margin: 0; padding: 4px;
  max-height: 320px; overflow: auto;
  z-index: 50;
}
.search-results li {
  padding: 8px 12px;
  border-radius: 7px;
  cursor: pointer;
  display: flex; justify-content: space-between; gap: 10px;
}
.search-results li:hover { background: var(--bg); }
.search-results .muted { color: var(--ink-soft); font-size: 13px; }

.select-wrap { display: flex; align-items: center; gap: 6px; }
.select-label { font-size: 13px; color: var(--ink-soft); }
.select {
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 8px;
  background: var(--input-bg);
  font-size: 14px;
  max-width: 230px;
}

/* ---------- Buttons ---------- */
.btn {
  height: 38px;
  padding: 0 14px;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 8px;
  font-size: 14px;
  color: var(--ink);
  white-space: nowrap;
  transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--bg); }
.btn--primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn--primary:hover { background: var(--accent-dark); }
.btn--danger { background: var(--panel); color: var(--danger); border-color: #e2c0bc; }
.btn--danger:hover { background: #fbeae8; }
.btn--ghost { border: none; background: transparent; color: var(--accent-dark); text-decoration: underline; }
.btn--ghost:hover { background: transparent; color: var(--accent); }
.btn--toggle.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn--toggle.is-active:hover { background: var(--accent-dark); }
.btn--sm { padding: 6px 12px; font-size: 13px; min-height: 0; }
.btn--lg { height: 46px; padding: 0 22px; font-size: 16px; }
.btn--block { width: 100%; }

.icon-btn {
  border: none; background: transparent; font-size: 18px; color: var(--ink-soft);
  width: 32px; height: 32px; border-radius: 7px;
}
.icon-btn:hover { background: var(--bg); color: var(--ink); }

/* ---------- Menu dropdown ---------- */
.menu { position: relative; }
.menu__dropdown {
  position: absolute; right: 0; top: 44px;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; box-shadow: var(--shadow);
  padding: 6px; min-width: 230px; z-index: 60;
}
.menu__item {
  display: block; width: 100%; text-align: left;
  border: none; background: transparent; padding: 9px 12px;
  border-radius: 7px; font-size: 14px; color: var(--ink);
}
.menu__item:hover { background: var(--bg); }
.menu__item--danger { color: var(--danger); }
.menu__sep { height: 1px; background: var(--line-soft); margin: 6px 4px; }

/* ---------- Ekran logowania ---------- */
.auth-overlay {
  position: fixed; inset: 0; z-index: 300;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  background: linear-gradient(160deg, var(--accent) 0%, var(--accent-dark) 45%, #2d2a26 100%);
}
.auth-box {
  background: var(--panel); border-radius: 16px; box-shadow: var(--shadow);
  padding: 30px 26px; width: min(360px, 100%);
  display: flex; flex-direction: column; gap: 10px; text-align: center;
}
.auth-logo { font-size: 48px; line-height: 1; }
.auth-box h2 { margin: 0; font-size: 20px; }
.auth-sub { margin: 0 0 8px; color: var(--ink-soft); font-size: 13px; line-height: 1.5; }
.auth-input {
  height: 46px; border: 1px solid var(--line); border-radius: 10px;
  padding: 0 14px; font-size: 16px; background: var(--input-bg); outline: none; text-align: center;
}
.auth-input:focus { border-color: var(--accent); background: var(--panel); }
.auth-error { color: var(--danger); font-size: 13px; margin: 0; }

/* ---------- Layout ---------- */
.layout { display: flex; height: calc(100vh - var(--topbar-h)); }
.canvas-wrap { position: relative; flex: 1; overflow: hidden; }

.canvas-toolbar {
  position: absolute; left: 16px; bottom: 16px; z-index: 20;
  display: flex; align-items: center; gap: 4px;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 999px; padding: 4px 6px; box-shadow: var(--shadow);
}
.zoom-btn {
  border: none; background: transparent; font-size: 18px;
  width: 32px; height: 32px; border-radius: 50%; color: var(--ink);
}
.zoom-btn:hover { background: var(--bg); }
.zoom-level { font-size: 13px; color: var(--ink-soft); width: 46px; text-align: center; }

.canvas {
  width: 100%; height: 100%;
  overflow: auto;
  padding: 40px;
  background-image: radial-gradient(var(--line-soft) 1px, transparent 1px);
  background-size: 22px 22px;
}
.tree-root {
  display: inline-flex;
  justify-content: center;
  min-width: 100%;
  transform-origin: top center;
  transition: transform .12s ease-out;
}

/* ---------- Empty state ---------- */
.empty-state {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; gap: 10px; padding: 20px;
}
.empty-state__emoji { font-size: 64px; }
.empty-state h2 { margin: 0; font-size: 22px; }
.empty-state p { margin: 0 0 12px; color: var(--ink-soft); line-height: 1.6; }

/* ---------- Tree nodes ---------- */
.node { display: flex; flex-direction: column; align-items: center; position: relative; padding: 0 12px; }

/* couple = person (+ spouse) */
.couple { display: flex; align-items: stretch; gap: 0; position: relative; }
.couple__link {
  display: flex; align-items: center; justify-content: center;
  padding: 0 6px; color: var(--ink-soft); font-size: 18px; align-self: center;
}
.couple__link--sibling { font-size: 14px; opacity: .75; }

.card-slot { position: relative; display: flex; }

.quick-add {
  position: absolute;
  width: 22px; height: 22px;
  border-radius: 50%;
  border: 2px solid #fff;
  background: var(--accent);
  color: #fff;
  font-size: 16px;
  line-height: 1;
  display: flex; align-items: center; justify-content: center;
  padding: 0;
  opacity: 0;
  transform: scale(.5);
  transition: opacity .12s ease, transform .12s ease;
  z-index: 9;
  box-shadow: var(--shadow);
  pointer-events: none;
}
.card-slot:hover .quick-add { opacity: 1; transform: scale(1); pointer-events: auto; }
.quick-add:hover { background: var(--accent-dark); transform: scale(1.18); }
.quick-add--top    { top: -11px;    left: 50%; margin-left: -11px; }
.quick-add--bottom { bottom: -11px; left: 50%; margin-left: -11px; }
.quick-add--left   { left: -11px;   top: 50%;  margin-top: -11px; }
.quick-add--right  { right: -11px;  top: 50%;  margin-top: -11px; }

.card {
  position: relative;
  width: 180px;
  min-height: 78px;
  background: var(--other);
  border: 1.5px solid var(--other-line);
  border-radius: 10px;
  padding: 9px 11px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform .1s, box-shadow .1s;
  text-align: left;
}
.card:hover { transform: translateY(-2px); box-shadow: 0 4px 18px rgba(0,0,0,.16); }
.card.is-selected { outline: 3px solid var(--accent); outline-offset: 2px; }
.card.is-root { box-shadow: 0 0 0 2px var(--accent-dark), var(--shadow); }
.card--male { background: var(--male); border-color: var(--male-line); }
.card--female { background: var(--female); border-color: var(--female-line); }

.card__name { font-weight: 700; font-size: 14px; line-height: 1.25; }
.card__photo {
  width: 52px; height: 52px; border-radius: 50%; object-fit: cover;
  display: block; margin: 0 auto 7px;
  border: 2px solid rgba(0,0,0,.1);
  box-shadow: 0 1px 4px rgba(0,0,0,.12);
}
.card--has-photo { min-height: 88px; text-align: center; }
.card--has-photo .card__name,
.card--has-photo .card__birthname { text-align: center; }
.card--has-photo .card__meta { text-align: center; }
.card__birthname { font-size: 11.5px; color: var(--ink-soft); font-style: italic; line-height: 1.3; margin-top: 1px; }
.card__meta { font-size: 12px; color: var(--ink-soft); margin-top: 3px; line-height: 1.4; }
.card__dead { font-size: 11px; color: var(--ink-soft); }
.card__badge {
  position: absolute; top: -8px; right: -8px;
  background: var(--accent-dark); color: #fff;
  font-size: 10px; padding: 2px 6px; border-radius: 999px;
}

/* Children container + connector lines (org-chart style) */
.children {
  display: flex;
  justify-content: center;
  position: relative;
  padding-top: 28px;
}
/* vertical line down from parent */
.node > .children::before {
  content: "";
  position: absolute;
  top: 0; left: 50%;
  width: 2px; height: 28px;
  background: var(--line);
  transform: translateX(-50%);
}
.child-wrap {
  display: flex; flex-direction: column; align-items: center;
  position: relative;
  padding: 28px 6px 0;
}
/* horizontal connector among siblings */
.child-wrap::before {
  content: "";
  position: absolute;
  top: 0; right: 50%;
  width: 50%; height: 2px;
  background: var(--line);
}
.child-wrap::after {
  content: "";
  position: absolute;
  top: 0; left: 50%;
  width: 50%; height: 2px;
  background: var(--line);
}
/* first/last trim the outer horizontal segment */
.child-wrap:first-child::before { display: none; }
.child-wrap:last-child::after { display: none; }
.child-wrap:only-child::before,
.child-wrap:only-child::after { display: none; }
/* vertical stub up into each child */
.child-wrap > .node::before {
  content: "";
  position: absolute;
  top: -28px; left: 50%;
  width: 2px; height: 28px;
  background: var(--line);
  transform: translateX(-50%);
}

.collapse-toggle {
  position: absolute;
  bottom: -11px; right: -11px;
  width: 22px; height: 22px; border-radius: 50%;
  border: 1.5px solid var(--line); background: var(--panel);
  font-size: 13px; line-height: 1; color: var(--ink-soft);
  display: flex; align-items: center; justify-content: center;
  z-index: 5;
}
.collapse-toggle:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- Sidebar ---------- */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--panel);
  border-left: 1px solid var(--line-soft);
  display: flex; flex-direction: column;
}
.sidebar__header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--line-soft);
}
.sidebar__title { margin: 0; font-size: 16px; }
.sidebar__body { flex: 1; overflow: auto; padding: 16px; }
.sidebar__footer {
  display: flex; flex-direction: column; gap: 8px; padding: 12px 16px;
  border-top: 1px solid var(--line-soft);
}
.sidebar__footer-row { display: flex; gap: 8px; }
.sidebar__footer-row .btn { flex: 1; }

/* Zdjęcie osoby w panelu edycji */
.photo-field {
  display: flex; align-items: flex-start; gap: 14px;
  margin-bottom: 16px; padding-bottom: 16px;
  border-bottom: 1px solid var(--line-soft);
}
.photo-preview {
  width: 76px; height: 76px; border-radius: 50%; overflow: hidden;
  background: var(--line-soft); display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; border: 2px solid var(--line);
}
.photo-preview img { width: 100%; height: 100%; object-fit: cover; }
.photo-placeholder { font-size: 30px; opacity: .45; line-height: 1; }
.photo-actions { display: flex; flex-direction: column; gap: 6px; flex: 1; min-width: 0; }
.photo-hint { margin: 0; font-size: 11px; color: var(--ink-soft); line-height: 1.35; }

/* ---------- Form ---------- */
.form { display: flex; flex-direction: column; gap: 12px; }
.form__row { display: flex; gap: 10px; }
.form__row .field { flex: 1; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field > span { font-size: 12px; color: var(--ink-soft); font-weight: 600; }
.field input, .field textarea {
  border: 1px solid var(--line); border-radius: 8px;
  padding: 9px 10px; font-size: 14px; background: var(--input-bg);
  font-family: inherit; outline: none; resize: vertical;
}
.field input:focus, .field textarea:focus { border-color: var(--accent); background: var(--panel); }

.segmented { display: flex; gap: 4px; }
.seg {
  flex: 1; border: 1px solid var(--line); background: var(--input-bg);
  border-radius: 8px; padding: 8px 4px; font-size: 12px; color: var(--ink-soft);
}
.seg.is-active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---------- Relations ---------- */
.relations { margin-top: 22px; border-top: 1px solid var(--line-soft); padding-top: 16px; }
.relations__title { margin: 0 0 10px; font-size: 14px; }
.relations__buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 14px; }
.rel-btn {
  border: 1px dashed var(--accent); background: #f3f6f1;
  color: var(--accent-dark); border-radius: 8px; padding: 9px; font-size: 13px;
}
.rel-btn:hover { background: #e9efe5; }

.rel-group { margin-bottom: 12px; }
.rel-group h4 { margin: 0 0 5px; font-size: 12px; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .03em; }
.rel-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.rel-list:empty::after { content: "—"; color: var(--line); padding-left: 2px; }
.rel-list li {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: var(--bg); border-radius: 7px; padding: 6px 9px; font-size: 13px;
}
.rel-list li .rel-name { cursor: pointer; flex: 1; }
.rel-list li .rel-name:hover { color: var(--accent-dark); text-decoration: underline; }
.rel-list li .rel-unlink { border: none; background: transparent; color: var(--ink-soft); font-size: 14px; padding: 0 4px; }
.rel-list li .rel-unlink:hover { color: var(--danger); }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; }
.modal__backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.35); }
.modal__box {
  position: relative; background: var(--panel); width: min(440px, 92vw);
  border-radius: 14px; box-shadow: var(--shadow); overflow: hidden;
}
.modal__header { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--line-soft); }
.modal__header h3 { margin: 0; font-size: 16px; }
.modal__body { padding: 16px; }
.modal__divider { text-align: center; margin: 14px 0; position: relative; color: var(--ink-soft); font-size: 12px; }
.modal__divider::before { content: ""; position: absolute; top: 50%; left: 0; right: 0; height: 1px; background: var(--line-soft); }
.modal__divider span { background: var(--panel); padding: 0 10px; position: relative; }
.link-list { list-style: none; margin: 10px 0 0; padding: 0; max-height: 260px; overflow: auto; }
.link-list li { padding: 9px 11px; border-radius: 8px; cursor: pointer; display: flex; justify-content: space-between; gap: 10px; }
.link-list li:hover { background: var(--bg); }
.link-list .muted { color: var(--ink-soft); font-size: 13px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 11px 18px; border-radius: 999px;
  font-size: 14px; z-index: 200; box-shadow: var(--shadow);
  animation: toastIn .2s ease-out;
}
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 10px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ---------- Tryb podglądu (tylko odczyt) ---------- */
.view-badge {
  display: inline-flex; align-items: center; gap: 5px;
  background: #fff4d6; color: #8a6d12; border: 1px solid #e6cf86;
  font-size: 12px; font-weight: 600; padding: 4px 9px; border-radius: 999px;
  white-space: nowrap;
}
body.view-mode #addPersonBtn,
body.view-mode #emptyAddBtn,
body.view-mode #emptySampleBtn,
body.view-mode #saveBtn,
body.view-mode #deletePersonBtn,
body.view-mode .quick-add,
body.view-mode .rel-unlink,
body.view-mode #importBtn,
body.view-mode #gedcomImportBtn,
body.view-mode #sampleBtn,
body.view-mode #clearBtn,
body.view-mode #photoPickBtn,
body.view-mode #photoRemoveBtn {
  display: none !important;
}
body.view-mode #genderSeg { pointer-events: none; opacity: .7; }
body.view-mode .field input[readonly],
body.view-mode .field textarea[readonly] {
  background: #f3f1ea; cursor: default;
}

/* ---------- Pokrewieństwo ---------- */
.card.is-kin {
  outline: 3px solid var(--accent);
  box-shadow: 0 0 0 4px rgba(91, 122, 82, .22), var(--shadow);
}
body.relation-mode .card { cursor: crosshair; }
body.relation-mode .card:hover { outline: 2px dashed var(--accent); }

.kin-info {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%);
  max-width: min(680px, 94vw); z-index: 210;
  background: var(--panel); color: var(--ink);
  border: 1px solid var(--line); border-left: 4px solid var(--accent);
  border-radius: 12px; box-shadow: var(--shadow);
  padding: 12px 38px 12px 16px;
}
.kin-info__close {
  position: absolute; top: 8px; right: 8px;
  border: none; background: transparent; cursor: pointer;
  font-size: 16px; color: var(--ink-soft); line-height: 1;
}
.kin-info__title { font-weight: 700; font-size: 14px; margin-bottom: 4px; }
.kin-info__chain { font-size: 13px; color: var(--ink-soft); line-height: 1.5; word-break: break-word; }

/* ---------- Opcje wydruku (modal) ---------- */
.check {
  display: flex; align-items: flex-start; gap: 9px;
  margin-top: 16px; font-size: 13px; color: var(--ink); line-height: 1.4; cursor: pointer;
}
.check input { margin-top: 2px; width: 16px; height: 16px; accent-color: var(--accent); }
.print-hint {
  font-size: 12px; color: var(--ink-soft); line-height: 1.5;
  background: var(--bg); border-radius: 8px; padding: 9px 11px; margin: 12px 0 16px;
}

/* ---------- Legenda wydruku ---------- */
.print-legend {
  display: flex; flex-wrap: wrap; gap: 18px; justify-content: center;
  margin-top: 9px; font-size: 11px; color: #444;
}
.print-legend .lg { display: inline-flex; align-items: center; gap: 6px; }
.print-legend .lg::before {
  content: ""; width: 13px; height: 13px; border-radius: 3px; border: 1.5px solid;
}
.lg--male::before   { background: var(--male);   border-color: var(--male-line); }
.lg--female::before { background: var(--female); border-color: var(--female-line); }
.lg--other::before  { background: var(--other);  border-color: var(--other-line); }

/* ---------- Print ---------- */
.print-only { display: none; }
@media print {
  :root { --bg: #fff; }
  html, body { background: #fff; }
  /* wymuś druk kolorów kart i legendy */
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }

  .no-print { display: none !important; }
  .print-only { display: block; }
  .layout { display: block; height: auto; }
  .canvas-wrap { overflow: visible; }
  .canvas { overflow: visible; padding: 0; background: none; height: auto; }

  /* Drzewo: bez transformacji ekranowej, wyśrodkowane, skalowane do strony.
     'zoom' (w przeciwieństwie do transform) zmienia też rozmiar w układzie,
     dzięki czemu treść mieści się na stronie i jest wyśrodkowana. */
  .tree-root {
    transform: none !important;
    display: block;
    min-width: 0 !important;
    width: max-content;
    margin: 0 auto;
    zoom: var(--print-scale, 1);
  }

  .print-header {
    text-align: center; margin-bottom: 16px;
    padding-bottom: 10px; border-bottom: 2px solid var(--accent);
  }
  .print-header h1 { margin: 0; font-size: 22px; color: var(--accent-dark); }
  .print-header p { margin: 5px 0 0; color: #555; font-size: 12px; }

  .card { box-shadow: none; }
  .collapse-toggle, .quick-add { display: none !important; }

  /* --- Tryb kafelków: drzewo podzielone na strony do sklejenia --- */
  body.printing-tiles .app,
  body.printing-tiles > header,
  body.printing-tiles .layout { display: none !important; }
  body.printing-tiles #tilePrint { display: block !important; }

  .tile-page {
    position: relative;
    width: var(--tile-w);
    height: var(--tile-h);
    overflow: hidden;
    break-after: page;
    page-break-after: always;
    background: var(--panel);
  }
  .tile-page:last-child { break-after: auto; page-break-after: auto; }
  .tile-page__inner { position: absolute; top: 0; left: 0; transform-origin: top left; }
  .tile-page__inner .tree-root {
    transform: none !important;
    zoom: var(--tile-scale, 1);
    margin: 0; width: max-content; min-width: 0 !important;
  }
  .tile-page__label {
    position: absolute; right: 5px; bottom: 4px;
    font-size: 10px; color: #b0b0b0;
    background: rgba(255,255,255,.7); padding: 1px 5px; border-radius: 4px;
  }
}

/* Kontener kafelków nie istnieje wizualnie na ekranie. */
#tilePrint { display: none; }

/* ---------- Responsywność ---------- */

/* Tablety i węższe okna */
@media (max-width: 900px) {
  .topbar { gap: 10px; padding: 0 10px; }
  .topbar__title { display: none; }
  .topbar__center { max-width: none; }
  .select { max-width: 130px; }
  /* Panel edycji wjeżdża z prawej, nad drzewem */
  .sidebar {
    position: fixed; right: 0; top: var(--topbar-h); bottom: 0;
    z-index: 70; box-shadow: var(--shadow);
  }
}

/* Telefony */
@media (max-width: 620px) {
  .topbar { gap: 6px; padding: 0 8px; }
  .topbar__center { display: none; }      /* pole wyszukiwania */
  .sync-status { padding: 4px 6px; gap: 0; }
  .sync-status .sync-text { display: none; }   /* zostaje sama kropka stanu */
  .sync-status .sync-dot { font-size: 14px; }
  .select-label { display: none; }
  .select { max-width: 150px; }
  .btn { padding: 0 10px; }
  .btn-label { display: none; }            /* zostaw ikonę, ukryj słowo */
  #addPersonBtn { font-size: 19px; padding: 0 13px; }
  .menu__dropdown { right: 0; min-width: min(260px, 86vw); }

  /* stabilna wysokość mimo paska adresu przeglądarki */
  .layout { height: calc(100dvh - var(--topbar-h)); }

  /* Panel edycji jako pełnoekranowy arkusz */
  .sidebar {
    left: 0; right: 0; top: 0; bottom: 0;
    width: 100%; z-index: 80; border-left: none;
    animation: sheetIn .18s ease-out;
  }
  .sidebar__header { position: sticky; top: 0; background: var(--panel); z-index: 1; }
  .sidebar__footer { position: sticky; bottom: 0; background: var(--panel); }

  /* iOS nie powiększa widoku, gdy pola mają >=16px */
  .field input, .field textarea, .search, .select, .seg { font-size: 16px; }

  .canvas { padding: 16px; }
  .canvas-toolbar { left: 10px; bottom: 10px; }
}

@keyframes sheetIn { from { transform: translateY(14px); opacity: .5; } to { transform: none; opacity: 1; } }

/* Urządzenia dotykowe (brak najechania): pokaż „+" przy zaznaczonej karcie
   i powiększ pola dotykowe. */
@media (hover: none) {
  .quick-add { width: 28px; height: 28px; font-size: 18px; }
  .quick-add--top    { top: -14px;    margin-left: -14px; }
  .quick-add--bottom { bottom: -14px; margin-left: -14px; }
  .quick-add--left   { left: -14px;   margin-top: -14px; }
  .quick-add--right  { right: -14px;  margin-top: -14px; }
  .card-slot:has(.is-selected) .quick-add {
    opacity: 1; transform: scale(1); pointer-events: auto;
  }
  .collapse-toggle { width: 28px; height: 28px; }
}

/* ========== Rozszerzenia (features.js) ========== */

.view-tabs { display: flex; gap: 2px; }
.view-tab {
  padding: 0 8px; min-width: 34px; height: 36px;
  border: 1px solid var(--line-soft); background: var(--panel);
  border-radius: 8px; cursor: pointer; font-size: 16px;
}
.view-tab.is-active { background: var(--accent); border-color: var(--accent-dark); color: #fff; }

.toolbar-sep { width: 1px; height: 20px; background: var(--line); margin: 0 4px; display: inline-block; vertical-align: middle; }

.card__branch {
  font-size: 9px; font-weight: 700; letter-spacing: .04em;
  text-align: center; padding: 3px 6px; margin: -9px -11px 7px;
  border-radius: 8px 8px 0 0;
  background: hsl(var(--branch-hue), 42%, 42%); color: #fff;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.card--has-branch { padding-top: 8px; }

.menu-badge {
  display: inline-flex; min-width: 18px; height: 18px; padding: 0 5px;
  background: var(--danger); color: #fff; border-radius: 999px;
  font-size: 11px; font-weight: 700; margin-left: 6px; vertical-align: middle;
}

.modal__box--wide { max-width: min(560px, 94vw); }
.tools-list { list-style: none; margin: 0; padding: 0; max-height: 50vh; overflow: auto; }
.tools-list li {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 0; border-bottom: 1px solid var(--line-soft); font-size: 14px;
}
.tools-list .ok-msg { color: var(--accent-dark); }
.tools-list .err-msg { color: var(--danger); }
.validation-list li { flex-direction: column; align-items: flex-start; }

.sources-section { margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--line-soft); }
.sources-section__head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.sources-section__head h3 { margin: 0; font-size: 14px; }
.sources-list { list-style: none; margin: 0; padding: 0; }
.source-item { position: relative; padding: 8px 28px 8px 0; border-bottom: 1px solid var(--line-soft); font-size: 13px; }
.source-item__title { font-weight: 600; }
.source-item__url { font-size: 12px; word-break: break-all; color: var(--accent-dark); }
.source-item__note { font-size: 12px; color: var(--ink-soft); margin-top: 2px; }
.source-item .rel-unlink { position: absolute; right: 0; top: 8px; }

.rel-type-sel { font-size: 11px; padding: 2px 4px; max-width: 90px; margin-right: 4px; }

.list-view { width: 100%; overflow: auto; padding: 8px 0; }
.list-table { width: 100%; border-collapse: collapse; font-size: 13px; background: var(--panel); border-radius: var(--radius); }
.list-table th, .list-table td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--line-soft); }
.list-table th { background: var(--line-soft); font-weight: 600; position: sticky; top: 0; }
.list-table tbody tr { cursor: pointer; }
.list-table tbody tr:hover { background: rgba(91, 122, 82, .08); }

.timeline-view { list-style: none; margin: 0; padding: 16px 24px; max-width: 720px; }
.tl-decade { font-weight: 800; font-size: 18px; color: var(--accent-dark); margin: 20px 0 8px; list-style: none; }
.tl-event { padding: 8px 0; border-bottom: 1px solid var(--line-soft); cursor: pointer; font-size: 14px; list-style: none; }
.tl-event:hover { color: var(--accent-dark); }
.tl-date { font-weight: 600; color: var(--ink-soft); margin-right: 8px; }

.map-list .map-place { flex-direction: column; align-items: flex-start; }
.map-place__name { font-weight: 700; margin-bottom: 4px; }
.map-link { font-size: 12px; font-weight: normal; margin-left: 6px; }
.map-people { list-style: none; margin: 0; padding: 0 0 0 12px; width: 100%; }
.map-people li { padding: 4px 0; cursor: pointer; font-size: 13px; }
.map-people li:hover { color: var(--accent-dark); }

.gallery-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 12px; }
.gallery-item { margin: 0; cursor: pointer; text-align: center; }
.gallery-item img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 10px; border: 2px solid var(--line-soft); }
.gallery-item figcaption { font-size: 12px; margin-top: 4px; }

.stats-dl { display: grid; grid-template-columns: 1fr auto; gap: 8px 16px; margin: 0; font-size: 14px; }
.stats-dl dt { color: var(--ink-soft); }
.stats-dl dd { margin: 0; font-weight: 700; text-align: right; }

.qr-body { text-align: center; }
.qr-url { font-size: 12px; word-break: break-all; color: var(--ink-soft); }

/* Album — druk */
#albumPrint { display: none; }
body.printing-album .app, body.printing-album > header, body.printing-album .layout { display: none !important; }
body.printing-album #albumPrint { display: block !important; padding: 0; }
.album-title { text-align: center; color: var(--accent-dark); }
.album-sub { text-align: center; color: var(--ink-soft); font-size: 13px; }
.album-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.album-grid figure { margin: 0; text-align: center; break-inside: avoid; }
.album-grid img { width: 100%; max-height: 200px; object-fit: cover; border-radius: 8px; }
.album-grid figcaption { font-size: 12px; margin-top: 6px; }

@media print {
  body.printing-album #albumPrint { display: block !important; }
}

/* Tryb ciemny */
html.theme-dark {
  --bg: #1a1917;
  --panel: #252320;
  --input-bg: #2e2b27;
  --ink: #ece8df;
  --ink-soft: #a59e90;
  --line: #4a453c;
  --line-soft: #353129;
  --accent: #7a9e6e;
  --accent-dark: #95b888;
  --male: #2a3d52;
  --male-line: #5a8ab8;
  --female: #4a2f3a;
  --female-line: #b8708c;
  --other: #3a3830;
  --other-line: #7a7568;
  --shadow: 0 2px 12px rgba(0,0,0,.35);
}
html.theme-dark .view-badge { background: #3d3520; color: #e6cf86; border-color: #6a5a30; }
html.theme-dark .auth-box { background: var(--panel); color: var(--ink); }
html.theme-dark .btn--danger { border-color: #6a4038; }
html.theme-dark .btn--danger:hover { background: #3a2826; }
html.theme-dark .menu__dropdown { box-shadow: 0 4px 20px rgba(0,0,0,.5); }
html.theme-dark .search-results { box-shadow: 0 4px 20px rgba(0,0,0,.5); }
html.theme-dark .topbar .btn,
html.theme-dark .topbar .view-tab,
html.theme-dark .topbar .select {
  color: var(--ink);
  border-color: var(--line);
}
html.theme-dark .topbar .view-tab:not(.is-active):hover,
html.theme-dark .topbar .btn:not(.btn--primary):hover {
  background: var(--bg);
}
html.theme-dark .topbar .select-label { color: var(--ink-soft); }
html.theme-dark .icon-btn { color: var(--ink-soft); }
html.theme-dark .icon-btn:hover { background: var(--bg); color: var(--ink); }

body.view-mode #addSourceBtn { display: none !important; }

@media (max-width: 620px) {
  .view-tabs { display: none; }
}

/* ========== Konta / drzewa ========== */
.auth-box--wide { max-width: 420px; }
.auth-input { width: 100%; box-sizing: border-box; margin-bottom: 10px; }
.auth-links { text-align: center; margin-top: 12px; font-size: 13px; }
.auth-hint { font-size: 12px; margin: 4px 0 10px; }
.tree-picker-list { list-style: none; margin: 0; padding: 0; }
.tree-pick-btn {
  width: 100%; text-align: left; padding: 12px 14px; margin-bottom: 8px;
  border: 1px solid var(--line-soft); border-radius: 10px; background: var(--panel);
  cursor: pointer; font-size: 14px;
}
.tree-pick-btn:hover { border-color: var(--accent); background: rgba(91,122,82,.06); }
.select--block { width: 100%; max-width: none; }
.req-actions { display: flex; gap: 6px; flex-shrink: 0; }
.import-guide h4 { margin: 16px 0 6px; font-size: 14px; }
.import-guide ol { margin: 0 0 12px; padding-left: 20px; font-size: 13px; line-height: 1.5; }
.merge-hint--high { border-left: 3px solid var(--accent); padding-left: 10px; }
.merge-hint--medium { border-left: 3px solid #c9a227; padding-left: 10px; }
.totp-uri { font-size: 10px; word-break: break-all; }
.qr-body { text-align: center; }

.tree-name-badge {
  font-size: 12px; font-weight: 500; color: var(--muted);
  background: rgba(91,122,82,.1); border: 1px solid var(--line-soft);
  padding: 3px 10px; border-radius: 999px; margin-left: 8px;
  max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
@media (max-width: 620px) { .tree-name-badge { display: none; } }

.admin-panel .admin-tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.admin-tab {
  padding: 8px 14px; border: 1px solid var(--line-soft); border-radius: 8px;
  background: var(--panel); cursor: pointer; font-size: 13px;
}
.admin-tab.is-active { border-color: var(--accent); background: rgba(91,122,82,.08); font-weight: 600; }
.admin-form h4 { margin: 0 0 10px; font-size: 14px; }
.admin-form .form__row { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.admin-form .field { flex: 1; min-width: 140px; }
.check--inline { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; margin-left: 12px; }
.merge-hint-check { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; }
.merge-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.tree-pick-create { margin-top: 12px; }
.select--sm { font-size: 12px; padding: 4px 8px; }
