:root {
  --bg: #f4f1ea;
  --panel: #ffffff;
  --ink: #2c2620;
  --muted: #8a8178;
  --accent: #4a7c59;
  --accent-dark: #3a6347;
  --border: #e3ddd2;
  --danger: #b5473a;
  --male: #6b8fb5;
  --female: #b56b8f;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.center { text-align: center; }
.error { color: var(--danger); min-height: 1.2em; }

button {
  cursor: pointer;
  border: none;
  background: var(--accent);
  color: #fff;
  padding: 0.5rem 0.9rem;
  border-radius: 6px;
  font-size: 0.9rem;
}
button:hover { background: var(--accent-dark); }
button.ghost { background: transparent; color: var(--ink); border: 1px solid var(--border); }
button.ghost:hover { background: #0000000a; }
button.danger { background: var(--danger); }
button.small { padding: 0.25rem 0.5rem; font-size: 0.8rem; }

input, select, textarea {
  font: inherit;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
}
label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.85rem; color: var(--muted); }
label input, label select { color: var(--ink); }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.5rem;
  box-shadow: 0 1px 3px #0000000d;
}

/* Login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; }
.login-card { width: 320px; display: flex; flex-direction: column; gap: 0.8rem; }
.login-card h1 { margin: 0; text-align: center; }
.login-card p { margin: 0; text-align: center; }

/* Topbar */
.topbar {
  display: flex; align-items: center; gap: 1rem;
  padding: 0.7rem 1.2rem;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 700; font-size: 1.1rem; }
.tabs { display: flex; gap: 0.3rem; flex: 1; }
.tab { background: transparent; color: var(--muted); }
.tab:hover { background: #0000000a; }
.tab.active { background: var(--accent); color: #fff; }
.user-box { display: flex; align-items: center; gap: 0.6rem; }

.tab-panel { padding: 1.2rem; max-width: 1200px; margin: 0 auto; }

/* People layout */
.people-layout { display: grid; grid-template-columns: 300px 1fr; gap: 1.2rem; }
.sidebar { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; height: calc(100vh - 140px); display: flex; flex-direction: column; }
.sidebar-head { display: flex; gap: 0.5rem; padding: 0.8rem; border-bottom: 1px solid var(--border); }
.sidebar-head input { flex: 1; }
.people-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; }
.people-list li { padding: 0.6rem 0.8rem; border-bottom: 1px solid var(--border); cursor: pointer; display: flex; align-items: center; gap: 0.5rem; }
.people-list li:hover { background: #0000000a; }
.people-list li.active { background: #4a7c5920; }
.li-main { display: flex; flex-direction: column; line-height: 1.25; }
.li-sub { font-size: 0.72rem; color: var(--muted); }
.combo-sub { font-size: 0.72rem; color: var(--muted); margin-top: 1px; }
.sex-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; background: var(--muted); }
.sex-dot.M { background: var(--male); }
.sex-dot.F { background: var(--female); }

.detail { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 1.5rem; min-height: 400px; }
.detail h2 { margin-top: 0; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.8rem; margin: 1rem 0; }
.field { display: flex; flex-direction: column; gap: 0.2rem; }
.field span.k { font-size: 0.75rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; }
.detail-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 1rem; }

.rel-section { margin-top: 1.2rem; }
.rel-section h3 { margin-bottom: 0.4rem; font-size: 0.95rem; }
.rel-chips { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.chip { background: #4a7c5915; border: 1px solid var(--border); border-radius: 20px; padding: 0.25rem 0.6rem; font-size: 0.85rem; display: inline-flex; align-items: center; gap: 0.4rem; cursor: pointer; }
.chip .x { color: var(--danger); font-weight: 700; }

.media-gallery { display: flex; flex-wrap: wrap; gap: 0.6rem; margin-top: 0.5rem; }
.media-item { position: relative; width: 110px; }
.media-item img { width: 110px; height: 110px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); }
.media-item .cap { font-size: 0.7rem; color: var(--muted); }
.media-item .del { position: absolute; top: 4px; right: 4px; background: #000000aa; padding: 0 0.35rem; border-radius: 4px; }

/* Tree */
.tree-controls { display: flex; align-items: flex-end; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.tree-canvas { position: relative; background: #edebe6; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; height: 70vh; min-height: 500px; }
.magnifier { position: absolute; top: 14px; width: 47%; height: calc(100% - 28px); border: 2px solid #8a8577; border-radius: 14px; box-shadow: 0 10px 30px rgba(0,0,0,0.3), 0 0 0 4px rgba(255,255,255,0.55); overflow: hidden; pointer-events: none; z-index: 40; opacity: 0.98; transition: opacity 0.12s ease; }
.magnifier.hidden { display: none; }
.magnifier .mag-bg { fill: #f3f1ea; }
.magnifier .mag-cursor { fill: none; stroke: #4a7c59; stroke-width: 2px; stroke-dasharray: 4 3; }
.mag-l { left: 14px; }
.mag-r { right: 14px; }
.tree-canvas svg { display: block; cursor: grab; }
.tree-canvas svg:active { cursor: grabbing; }
.zoom-controls { display: flex; gap: 0.3rem; }
.zoom-controls button { min-width: 2.2rem; }
.zoom-controls button.active { background: #4a7c59; color: #fff; border-color: #4a7c59; }
/* Sadece ağaç sekmesi tam ekranda: kontrol çubuğu üstte, kanvas kalanı doldurur */
#tab-tree:fullscreen { background: #edebe6; padding: 12px; box-sizing: border-box; display: flex; flex-direction: column; }
#tab-tree:fullscreen .tree-canvas { flex: 1; height: auto; min-height: 0; }
.combo { position: relative; }
#tree-root-input { min-width: 230px; }
.combo-list { position: absolute; top: calc(100% + 2px); left: 0; right: 0; max-height: 260px; overflow: auto; background: #fff; border: 1px solid var(--border); border-radius: 8px; z-index: 30; box-shadow: 0 4px 12px rgba(0,0,0,0.12); }
.combo-item { padding: 0.4rem 0.6rem; cursor: pointer; font-size: 0.85rem; }
.combo-item:hover { background: #4a7c5915; }
.combo-empty { padding: 0.4rem 0.6rem; color: var(--muted); font-size: 0.85rem; }
.build-footer { position: fixed; bottom: 6px; right: 12px; font-size: 0.7rem; color: var(--muted); opacity: 0.75; pointer-events: none; z-index: 60; }

/* Anasayfa (dashboard) */
.dash { display: flex; flex-direction: column; gap: 1rem; }
.dash-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 0.7rem; }
.stat-card { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 0.8rem 1rem; text-align: center; }
.stat-card .v { font-size: 1.5rem; font-weight: 700; color: #2f5d3f; }
.stat-card .l { font-size: 0.75rem; color: var(--muted); margin-top: 0.15rem; }
.stat-card.wide .v { font-size: 1.05rem; }
.stat-card.clickable { cursor: pointer; transition: border-color 0.12s, transform 0.12s; }
.stat-card.clickable:hover { border-color: #4a7c59; transform: translateY(-2px); }

/* Liste sayfası (evlilikler / anekdotlar / fotoğraflar) */
.list-page { max-width: 780px; margin: 0 auto; }
.list-page-head { display: flex; align-items: baseline; gap: 1rem; margin-bottom: 1rem; }
.list-page-head h1 { font-size: 1.3rem; margin: 0; }
.back-link { color: #4a7c59; text-decoration: none; font-size: 0.9rem; }
.back-link:hover { text-decoration: underline; }
.page-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.7rem; }
.page-list li { padding: 0.7rem 0.9rem; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; }
.anec-item-head { display: flex; align-items: center; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 0.3rem; }
.anec-item-head .share-btn { margin-left: auto; }
.anec-by { font-size: 0.72rem; margin-top: 0.3rem; }
@keyframes flashHighlight { 0% { background: #4a7c5940; } 100% { background: var(--panel); } }
.flash { animation: flashHighlight 1.8s ease-out; }
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 0.7rem; }
.photo-cell { display: flex; flex-direction: column; align-items: center; gap: 0.3rem; text-decoration: none; color: inherit; font-size: 0.75rem; text-align: center; }
.photo-cell img, .photo-cell .ph { width: 72px; height: 72px; border-radius: 50%; object-fit: cover; border: 2px solid var(--border); }
.photo-cell .ph { display: flex; align-items: center; justify-content: center; background: #4a7c5915; font-weight: 700; color: #4a7c59; }
.photo-cell:hover .pc-name { text-decoration: underline; }
.dash-cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 1rem; align-items: start; }
.dash-card h2 { font-size: 1rem; margin-bottom: 0.6rem; }
.dash-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.45rem; font-size: 0.88rem; }
.dash-list li { line-height: 1.45; }
.dash-list .ago { color: var(--muted); font-size: 0.72rem; white-space: nowrap; }
.plink { color: #2f5d3f; font-weight: 600; text-decoration: none; }
.plink:hover { text-decoration: underline; }
.health-bar { position: relative; background: #00000012; border-radius: 8px; height: 22px; overflow: hidden; margin-bottom: 0.7rem; }
.health-bar .fill { position: absolute; inset: 0 auto 0 0; background: #4a7c59; border-radius: 8px; }
.health-bar span { position: relative; display: block; text-align: center; font-size: 0.75rem; line-height: 22px; color: #fff; mix-blend-mode: difference; }
.health-issue { font-size: 0.85rem; margin-bottom: 0.5rem; }
.health-issue .chips { margin-top: 0.25rem; display: flex; flex-wrap: wrap; gap: 0.3rem; }

/* Eşler */
.spouse-list { display: flex; flex-direction: column; gap: 0.5rem; }
.spouse-row { display: flex; align-items: center; flex-wrap: wrap; gap: 0.4rem 0.6rem; }
.sp-info { font-size: 0.82rem; color: var(--muted); }
.sp-edit-btn { padding: 0.1rem 0.4rem; }
.sp-edit { display: flex; gap: 0.4rem; flex-wrap: wrap; flex-basis: 100%; margin-top: 0.2rem; }
.sp-edit input { font-size: 0.85rem; }

/* Yaşadığı yerler — zaman çizelgesi */
.res-timeline { list-style: none; margin: 0.3rem 0 0; padding: 0; }
.res-timeline li { position: relative; padding: 0 0 0.9rem 1.4rem; }
.res-timeline li::before { content: ""; position: absolute; left: 5px; top: 0.55rem; bottom: -0.35rem; width: 2px; background: var(--border); }
.res-timeline li:last-child::before { display: none; }
.res-dot { position: absolute; left: 0; top: 0.3rem; width: 12px; height: 12px; border-radius: 50%; background: #fff; border: 2px solid #8a8577; box-sizing: border-box; }
.res-timeline li.ongoing .res-dot { background: #4a7c59; border-color: #4a7c59; box-shadow: 0 0 0 3px #4a7c5933; }
.res-head { display: flex; align-items: baseline; flex-wrap: wrap; gap: 0.5rem; }
.res-place { font-weight: 600; }
.res-range { font-size: 0.8rem; color: var(--muted); }
.res-timeline li.ongoing .res-range { color: #2f5d3f; font-weight: 600; }
.res-note { font-size: 0.8rem; color: var(--muted); margin-top: 0.1rem; }
.res-form { flex-wrap: wrap; }

/* Anekdotlar */
.anecdotes { display: flex; flex-direction: column; gap: 0.6rem; }
.anecdote { background: #4a7c590d; border: 1px solid var(--border); border-radius: 10px; padding: 0.6rem 0.8rem; }
.anec-title { font-weight: 600; margin-bottom: 0.2rem; }
.anec-text { font-size: 0.9rem; white-space: pre-wrap; }
.anec-meta { margin-top: 0.35rem; font-size: 0.72rem; color: var(--muted); display: flex; align-items: center; gap: 0.5rem; }
.anec-form { display: flex; flex-direction: column; gap: 0.4rem; margin-top: 0.6rem; max-width: 560px; }
.anec-form button { align-self: flex-start; }
.node-card rect { fill: #fff; stroke: #b3ada1; stroke-width: 1.5px; filter: drop-shadow(0 1px 2px rgba(0,0,0,0.22)); }
.node-card.M rect { fill: #d9ecf9; stroke: #5b9bd1; }
.node-card.F rect { fill: #fbe0e6; stroke: #dd8ba1; }
.node-card.U rect { fill: #f2efe8; stroke: #a9a294; }
.node-card.focus rect { stroke-width: 3px; }
.node-card circle.avatar { fill: #fff; stroke: rgba(0,0,0,0.18); stroke-width: 1px; }
.node-card text.initials { font-size: 12px; font-weight: 700; text-anchor: middle; fill: #a9a294; }
.node-card.M text.initials { fill: #5b9bd1; }
.node-card.F text.initials { fill: #dd8ba1; }
.node-card text.name { font-weight: 600; font-size: 11px; fill: #2f2c26; }
.node-card text.dates { font-size: 9px; fill: #6f6a5e; }
.link { fill: none; stroke: #b0aa9d; stroke-width: 2px; }
.couple-link { stroke: #b0aa9d; stroke-width: 2px; }
.sib-link { stroke: #c4bfb2; stroke-width: 1.5px; stroke-dasharray: 5 4; }
.jump-btn { cursor: pointer; }
.jump-btn circle { fill: #fff; stroke: #8a8577; stroke-width: 1px; }
.jump-btn:hover circle { fill: #eaf3ec; stroke: #4a7c59; stroke-width: 1.5px; }
.jump-btn text { font-size: 10px; }

/* Import */
.import-card { max-width: 640px; display: flex; flex-direction: column; gap: 0.8rem; align-items: flex-start; }
#import-result { width: 100%; }
.result-ok { background: #4a7c5915; border: 1px solid var(--accent); border-radius: 8px; padding: 0.8rem; margin-top: 0.5rem; }

/* Users */
.user-form { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 1rem; }
.users-table { width: 100%; border-collapse: collapse; }
.users-table th, .users-table td { text-align: left; padding: 0.5rem; border-bottom: 1px solid var(--border); font-size: 0.9rem; }

/* Modal-ish inline forms */
.inline-form { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; margin-top: 0.5rem; padding: 0.6rem; background: #0000000a; border-radius: 8px; }

/* Toast */
.toast { position: fixed; bottom: 1.5rem; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 0.7rem 1.2rem; border-radius: 8px; z-index: 100; }
.toast.err { background: var(--danger); }
