:root {
  --green-900: #0b3d2e;
  --green-700: #0e5a45;
  --green-500: #14876a;
  --green-100: #e3f3ec;
  --gold: #e0a526;
  --gold-soft: #fff3d1;
  --cream: #fbf7ee;
  --ink: #1f2a25;
  --muted: #6b7a73;
  --line: #9cc4b5;
  --male: #2f7fb5;
  --female: #c2547f;
  --card: #ffffff;
  --radius: 16px;
  --shadow: 0 6px 24px rgba(14, 90, 69, .12);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: 'Cairo', system-ui, -apple-system, 'Segoe UI', Tahoma, sans-serif;
  background: var(--cream);
  color: var(--ink);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  line-height: 1.6;
}
a { color: var(--green-500); }
img { max-width: 100%; }
[hidden] { display: none !important; }

/* ---------- Buttons & forms ---------- */
.btn {
  font: inherit; font-weight: 600; cursor: pointer; border: 1.5px solid transparent;
  padding: .5rem 1.1rem; border-radius: 999px; display: inline-flex; align-items: center;
  gap: .4rem; text-decoration: none; transition: .18s; background: #fff; color: var(--green-700);
}
.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow); }
.btn-primary { background: linear-gradient(135deg, var(--green-700), var(--green-500)); color: #fff; }
.btn-gold { background: linear-gradient(135deg, #ffd86b, var(--gold)); color: #4a3200; }
.btn-danger { background: #fff; color: #b3261e; border-color: #f0c4c0; }
.btn-ghost { background: rgba(255,255,255,.14); color: #fff; border-color: rgba(255,255,255,.35); }
.btn-outline { border-color: var(--line); }
.btn-sm { padding: .25rem .8rem; font-size: .88rem; }
.btn-block { width: 100%; justify-content: center; }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }

label { display: block; font-weight: 600; font-size: .92rem; color: var(--green-900); margin-bottom: .8rem; }
input[type=text], input[type=password], input[type=date], input[type=search], select, textarea {
  width: 100%; font: inherit; padding: .55rem .8rem; margin-top: .25rem; border: 1.5px solid #d4e3dc;
  border-radius: 12px; background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 3px solid rgba(20,135,106,.25); border-color: var(--green-500); }
textarea { resize: vertical; min-height: 70px; }

.alert { background: #fde8e6; color: #8a1f17; padding: .6rem .9rem; border-radius: 12px; margin-bottom: 1rem; font-weight: 600; }

/* ---------- Header / hero ---------- */
.hero {
  background: radial-gradient(1200px 400px at 80% -20%, rgba(255,216,107,.25), transparent),
    linear-gradient(135deg, var(--green-900), var(--green-700) 60%, var(--green-500));
  color: #fff; padding: 1rem 1.25rem 2.2rem; position: relative; overflow: hidden;
}
.topbar { display: flex; align-items: center; gap: .8rem; flex-wrap: wrap; max-width: 1200px; margin: 0 auto; }
.brand { display: flex; align-items: center; gap: .7rem; text-decoration: none; color: #fff; margin-inline-end: auto; }
.brand img { width: 44px; height: 44px; border-radius: 12px; }
.brand b { font-size: 1.25rem; }
.hero-body { max-width: 1200px; margin: 1.6rem auto 0; text-align: center; }
.hero h1 { margin: 0; font-size: clamp(1.6rem, 4vw, 2.6rem); font-weight: 800; }
.hero p { margin: .3rem 0 0; opacity: .9; }
.stats { display: flex; gap: .8rem; justify-content: center; flex-wrap: wrap; margin-top: 1.3rem; }
.stat { background: rgba(255,255,255,.12); border: 1px solid rgba(255,255,255,.22); border-radius: 14px; padding: .4rem 1.1rem; min-width: 110px; }
.stat b { display: block; font-size: 1.5rem; color: #ffd86b; line-height: 1.2; }
.stat span { font-size: .85rem; opacity: .9; }

/* ---------- Tree viewer ---------- */
.tree-section { flex: 1; max-width: 100%; position: relative; }
.toolbar {
  display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; justify-content: center;
  padding: .9rem 1rem; position: sticky; top: 0; z-index: 20; background: rgba(251,247,238,.92); backdrop-filter: blur(6px);
  border-bottom: 1px solid #e6ece8;
}
.toolbar input[type=search] { max-width: 280px; margin: 0; border-radius: 999px; }
.viewport {
  overflow: auto; padding: 2rem 1rem 3rem; cursor: grab; min-height: 60vh;
  background-image: radial-gradient(#d9e8e0 1px, transparent 1px); background-size: 22px 22px;
}
.viewport.dragging { cursor: grabbing; user-select: none; }
.canvas { width: max-content; min-width: 100%; direction: ltr; display: flex; justify-content: center; }

.tree ul { display: flex; justify-content: center; padding: 28px 0 0; margin: 0; position: relative; list-style: none; }
.tree li { position: relative; padding: 28px 10px 0; display: flex; flex-direction: column; align-items: center; }
.tree li::before, .tree li::after {
  content: ''; position: absolute; top: 0; right: 50%; width: 50%; height: 28px; border-top: 2px solid var(--line);
}
.tree li::after { right: auto; left: 50%; border-left: 2px solid var(--line); }
.tree li:only-child::before, .tree li:only-child::after { display: none; }
.tree li:only-child { padding-top: 0; }
.tree li:first-child::before, .tree li:last-child::after { border: 0 none; }
.tree li:last-child::before { border-right: 2px solid var(--line); border-radius: 0 10px 0 0; }
.tree li:first-child::after { border-radius: 10px 0 0 0; }
.tree ul ul::before { content: ''; position: absolute; top: 0; left: 50%; border-left: 2px solid var(--line); height: 28px; }
.tree > ul { padding-top: 0; }
.tree > ul > li { padding-top: 0; }
.tree > ul > li::before, .tree > ul > li::after { display: none; }
.tree > ul > li + li { margin-inline-start: 40px; }

.unit { display: flex; align-items: stretch; position: relative; gap: 26px; }
html[dir=rtl] .unit { flex-direction: row-reverse; }
.unit.couple::before {
  content: '♥'; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); z-index: 2;
  color: #fff; background: var(--gold); width: 22px; height: 22px; border-radius: 50%; font-size: 12px;
  display: flex; align-items: center; justify-content: center;
}
.unit.couple::after {
  content: ''; position: absolute; top: 50%; left: 50%; width: 34px; transform: translateX(-50%); border-top: 3px solid var(--gold); z-index: 1;
}

.person {
  width: 156px; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: .7rem .5rem .6rem; text-align: center; cursor: pointer; border: 2px solid transparent;
  transition: .2s; direction: var(--dir, rtl); position: relative;
}
html[dir=rtl] .person { direction: rtl; }
html[dir=ltr] .person { direction: ltr; }
.person:hover { transform: translateY(-3px); box-shadow: 0 10px 30px rgba(14,90,69,.22); }
.person.male { border-top: 4px solid var(--male); }
.person.female { border-top: 4px solid var(--female); }
.person.deceased { filter: grayscale(.35); background: #f6f6f3; }
.person.match { border-color: var(--gold); box-shadow: 0 0 0 5px rgba(224,165,38,.35); }
.avatar {
  width: 78px; height: 78px; border-radius: 50%; margin: 0 auto .35rem; overflow: hidden; background: var(--green-100);
  display: flex; align-items: center; justify-content: center; border: 3px solid #fff; box-shadow: 0 2px 10px rgba(0,0,0,.15);
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar svg { width: 60%; height: 60%; fill: #8fb9a9; }
.person.male .avatar { box-shadow: 0 0 0 3px rgba(47,127,181,.45); }
.person.female .avatar { box-shadow: 0 0 0 3px rgba(194,84,127,.45); }
.person .pname { font-weight: 700; font-size: .95rem; line-height: 1.25; word-break: break-word; }
.person .pmeta { font-size: .78rem; color: var(--muted); }
.person .page { display: inline-block; margin-top: .2rem; font-size: .78rem; background: var(--gold-soft); color: #7a5600; padding: 0 .6rem; border-radius: 999px; font-weight: 700; }
.person.deceased .page { background: #eceeea; color: #555; }
.ribbon { position: absolute; top: 6px; inset-inline-end: 8px; font-size: 1rem; color: var(--gold); }

.empty { text-align: center; padding: 4rem 1rem; color: var(--muted); font-size: 1.1rem; }
.empty img { width: 96px; opacity: .8; margin-bottom: 1rem; }

/* ---------- Modal ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(8,30,23,.55); display: none; align-items: center; justify-content: center; z-index: 100; padding: 1rem; }
.modal-bg.open { display: flex; }
.modal { background: #fff; border-radius: 22px; width: min(560px, 100%); max-height: 92vh; overflow: auto; padding: 1.4rem; box-shadow: 0 20px 60px rgba(0,0,0,.35); animation: pop .2s ease; }
@keyframes pop { from { transform: scale(.96); opacity: 0; } to { transform: none; opacity: 1; } }
.modal h2 { margin: 0 0 1rem; color: var(--green-700); }
.modal-actions { display: flex; gap: .6rem; justify-content: flex-end; margin-top: 1rem; }
.detail-head { text-align: center; }
.detail-head .avatar { width: 120px; height: 120px; }
.detail-head h2 { margin: .2rem 0; }
.detail dl { display: grid; grid-template-columns: auto 1fr; gap: .35rem 1rem; margin: 1rem 0 0; }
.detail dt { color: var(--muted); font-weight: 600; }
.detail dd { margin: 0; font-weight: 600; }
.chip { display: inline-block; background: var(--green-100); color: var(--green-700); border-radius: 999px; padding: 0 .7rem; margin: 0 0 .25rem .25rem; font-size: .88rem; cursor: pointer; border: 0; font-family: inherit; font-weight: 600; }
html[dir=rtl] .chip { margin: 0 0 .25rem .25rem; }

/* ---------- Footer / offline ---------- */
.site-footer { text-align: center; padding: 1.1rem; background: var(--green-900); color: #cfe6dc; font-size: .92rem; }
.net-banner { position: fixed; bottom: 64px; inset-inline: 0; margin: auto; width: max-content; max-width: 92vw; background: #1f2a25; color: #fff; padding: .5rem 1.1rem; border-radius: 999px; z-index: 90; font-weight: 600; box-shadow: var(--shadow); }
.net-banner.ok { background: var(--green-700); }

/* ---------- Login ---------- */
.login-page { background: linear-gradient(135deg, var(--green-900), var(--green-500)); align-items: center; justify-content: center; }
.login-page .login-card { background: #fff; border-radius: 24px; padding: 2rem 1.8rem; width: min(400px, 92vw); box-shadow: 0 24px 60px rgba(0,0,0,.3); margin: auto; position: relative; margin-top: 8vh; }
.login-page .site-footer { width: 100%; background: transparent; }
.login-logo { width: 84px; height: 84px; display: block; margin: 0 auto .6rem; border-radius: 22px; }
.login-card h1 { text-align: center; font-size: 1.35rem; margin: 0 0 1.2rem; color: var(--green-700); }
.back-link { text-align: center; margin: 1rem 0 0; }
.lang-corner { position: absolute; top: 12px; inset-inline-end: 12px; }
.lang-corner .btn-ghost { background: var(--green-100); color: var(--green-700); border-color: transparent; }

/* ---------- Dashboard ---------- */
.dash { max-width: 1200px; margin: 0 auto; padding: 1.2rem; width: 100%; flex: 1; }
.panel { background: #fff; border-radius: 20px; box-shadow: var(--shadow); padding: 1.2rem; margin-bottom: 1.2rem; }
.panel h2 { margin: 0 0 .8rem; font-size: 1.2rem; color: var(--green-700); }
.panel-head { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; margin-bottom: .8rem; }
.panel-head h2 { margin: 0; margin-inline-end: auto; }
.panel-head input[type=search] { width: 220px; margin: 0; }
.table-wrap { overflow-x: auto; }
table.members { width: 100%; border-collapse: collapse; min-width: 760px; }
table.members th { text-align: start; background: var(--green-100); color: var(--green-900); padding: .6rem .7rem; font-size: .88rem; white-space: nowrap; }
table.members td { padding: .55rem .7rem; border-bottom: 1px solid #edf2ef; vertical-align: middle; }
table.members tr:hover td { background: #f8fbf9; }
.thumb { width: 46px; height: 46px; border-radius: 50%; object-fit: cover; background: var(--green-100); display: block; }
.badge { padding: 0 .6rem; border-radius: 999px; font-size: .8rem; font-weight: 700; }
.badge.alive { background: #dff5e8; color: #17653a; }
.badge.dead { background: #eceeea; color: #555; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 1rem; }
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.2rem; }
.toast { position: fixed; top: 16px; inset-inline: 0; margin: auto; width: max-content; max-width: 92vw; z-index: 200; background: var(--green-700); color: #fff; padding: .6rem 1.2rem; border-radius: 12px; font-weight: 600; box-shadow: var(--shadow); }
.toast.err { background: #b3261e; }
.photo-row { display: flex; align-items: center; gap: .9rem; margin-bottom: .8rem; }
.photo-row .thumb { width: 72px; height: 72px; }
.file-btn input { display: none; }

@media (max-width: 640px) {
  .grid2, .grid3, .settings-grid { grid-template-columns: 1fr; }
  .person { width: 132px; }
  .avatar { width: 64px; height: 64px; }
  .toolbar input[type=search] { max-width: 100%; flex: 1 1 100%; }
}
@page { size: A4 landscape; margin: 8mm; }
/* Compact card sizing used while measuring and printing */
.printing, .printing * { transition: none !important; animation: none !important; }
.printing .canvas { min-width: 0; margin: 0 auto; }
.printing .person { width: 92px; padding: .35rem .2rem .3rem; border-radius: 8px; box-shadow: none; }
.printing .avatar { width: 36px; height: 36px; border-width: 2px; margin-bottom: .15rem; }
.printing .person .pname { font-size: .72rem; line-height: 1.15; }
.printing .person .pmeta { font-size: .6rem; }
.printing .person .page { font-size: .58rem; padding: 0 .35rem; margin-top: .1rem; }
.printing .ribbon { font-size: .65rem; top: 2px; inset-inline-end: 4px; }
.printing .tree li { padding: 16px 4px 0; }
.printing .tree ul { padding-top: 16px; }
.printing .tree li::before, .printing .tree li::after { height: 16px; }
.printing .tree ul ul::before { height: 16px; }
.printing .tree > ul > li + li { margin-inline-start: 16px; }
.printing .unit { gap: 14px; }
.printing .unit.couple::before { width: 14px; height: 14px; font-size: 8px; }
.printing .unit.couple::after { width: 18px; border-top-width: 2px; }
@media print {
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  html, body { background: #fff; min-height: 0; display: block; }
  .toolbar, .net-banner, .modal-bg, .topbar .btn, #installBtn, .topbar > a.btn { display: none !important; }
  .hero { padding: 6mm 8mm; border-radius: 10px; }
  .topbar { display: none; }
  .hero-body { margin: 0; }
  .hero h1 { font-size: 22pt; }
  .hero p { font-size: 10pt; margin: 0; }
  .stats { margin-top: 3mm; gap: 6px; }
  .stat { padding: 1px 12px; min-width: 70px; }
  .stat b { font-size: 13pt; }
  .stat span { font-size: 8pt; }
  .tree-section { display: block; }
  .viewport { overflow: visible; padding: 6mm 0 0; min-height: 0; background: none; cursor: default; }
  .canvas { min-width: 0; width: 100%; }
  .person { box-shadow: none; border: 1px solid #cfdcd6; break-inside: avoid; }
  .person:hover { transform: none; }
  .site-footer { background: none; color: #555; border-top: 1px solid #ccd; padding: 2mm 0 0; margin-top: 4mm; font-size: 8pt; }
}
