/* Kazakh-inspired palette: sky blue (Tengri), sun gold, felt cream, terracotta accent. */
:root {
  --bg: #efe4cc;
  --panel: #fffdf6;
  --ink: #2b2013;
  --muted: #8a765a;
  --blue: #0e6ba8;
  --blue-dark: #093f60;
  --gold: #c99a3b;
  --gold-light: #e7c876;
  --maroon: #8c3a2b;
  --line: #b8944a;
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background: var(--bg);
}
h1, h2 { font-family: Georgia, "Times New Roman", serif; }

/* ---- Header ---- */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 22px;
  background: linear-gradient(180deg, var(--blue) 0%, var(--blue-dark) 100%);
  border-bottom: 4px solid var(--gold);
  box-shadow: 0 2px 0 var(--maroon);
  position: relative;
  z-index: 5;
}
.toolbar::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: -8px;
  height: 8px;
  background: repeating-linear-gradient(
    45deg,
    var(--gold) 0px, var(--gold) 6px,
    var(--maroon) 6px, var(--maroon) 12px
  );
  opacity: 0.85;
}
.toolbar-brand { display: flex; align-items: center; gap: 12px; }
.brand-emblem {
  width: 38px; height: 38px;
  border-radius: 50%;
  display: inline-block;
  background:
    radial-gradient(circle, var(--blue-dark) 0 28%, transparent 29%),
    repeating-conic-gradient(var(--gold) 0deg 9deg, var(--gold-light) 9deg 18deg);
  border: 2px solid var(--gold-light);
  box-shadow: 0 0 0 2px var(--blue-dark) inset;
}
.toolbar h1 { font-size: 1.4rem; margin: 0; color: #fff; letter-spacing: 0.03em; }
.brand-subtitle { margin: 0; font-size: 0.72rem; color: var(--gold-light); letter-spacing: 0.04em; }
.toolbar-actions { display: flex; gap: 8px; }

.btn {
  display: inline-block;
  border: 1px solid var(--gold);
  background: var(--panel);
  color: var(--ink);
  padding: 8px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.9rem;
  text-decoration: none;
  font-family: inherit;
}
.btn:hover { border-color: var(--maroon); color: var(--maroon); }
.btn-primary { background: var(--maroon); border-color: var(--maroon); color: #fff; }
.btn-primary:hover { background: #6f2a1e; color: #fff; }
.btn-danger { color: var(--maroon); border-color: var(--maroon); }
.btn-danger:hover { background: var(--maroon); color: #fff; }
.btn-small { padding: 5px 10px; font-size: 0.8rem; }

/* ---- Canvas ---- */
.tree-root {
  position: relative;
  height: calc(100vh - 78px);
  overflow: hidden;
  cursor: grab;
  background:
    radial-gradient(circle, #d8c79a 1px, transparent 1px) 0 0 / 26px 26px,
    repeating-linear-gradient(135deg, rgba(140, 58, 43, 0.03) 0 2px, transparent 2px 14px),
    var(--bg);
}
.tree-root.dragging { cursor: grabbing; }

.tree-canvas {
  position: absolute;
  top: 0; left: 0;
  transform-origin: 0 0;
}
.tree-lines { position: absolute; top: 0; left: 0; pointer-events: none; overflow: visible; }
.tree-lines line { stroke: var(--line); stroke-width: 2.5; }
.tree-lines circle { fill: var(--gold); }
.tree-cards { position: relative; }

.person-card {
  position: absolute;
  background: var(--panel);
  border: 2px solid var(--gold);
  border-radius: var(--radius);
  padding: 9px;
  text-align: center;
  box-shadow: 0 2px 5px rgba(43, 32, 19, 0.18);
  cursor: pointer;
  user-select: none;
}
.person-card::before {
  content: "";
  position: absolute;
  top: 3px; left: 3px; right: 3px; bottom: 3px;
  border: 1px solid var(--gold-light);
  border-radius: 6px;
  pointer-events: none;
}
.person-card:hover { border-color: var(--maroon); box-shadow: 0 3px 10px rgba(43, 32, 19, 0.28); }
.person-photo {
  width: 50px; height: 50px;
  border-radius: 50%;
  margin: 0 auto 6px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; color: #fff;
  background: linear-gradient(160deg, var(--blue), var(--blue-dark));
  border: 2px solid var(--gold);
  overflow: hidden;
}
.person-photo img { width: 100%; height: 100%; object-fit: cover; }
.person-name { font-size: 0.85rem; font-weight: 600; line-height: 1.2; }
.person-dates { font-size: 0.72rem; color: var(--muted); margin-top: 2px; }

.zoom-controls {
  position: absolute; bottom: 16px; right: 16px;
  display: flex; flex-direction: column; gap: 4px;
  z-index: 4;
}
.zoom-controls button {
  width: 34px; height: 34px;
  border-radius: 50%;
  border: 2px solid var(--gold);
  background: var(--panel);
  color: var(--blue-dark);
  cursor: pointer;
  font-size: 1rem;
}
.zoom-controls button:hover { border-color: var(--maroon); color: var(--maroon); }

.empty-hint {
  position: absolute; top: 40%; left: 50%; transform: translate(-50%, -50%);
  color: var(--muted); font-size: 1rem; text-align: center; max-width: 320px;
}

/* ---- Drawer ---- */
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: 320px; max-width: 90vw;
  background: var(--panel);
  border-left: 4px solid var(--gold);
  box-shadow: -4px 0 16px rgba(0,0,0,0.18);
  padding: 20px;
  overflow-y: auto;
  z-index: 20;
}
.drawer-close {
  position: absolute; top: 12px; right: 14px;
  background: none; border: none; font-size: 1.4rem; cursor: pointer; color: var(--muted);
}
.drawer-photo {
  width: 92px; height: 92px; border-radius: 50%;
  background: linear-gradient(160deg, var(--blue), var(--blue-dark));
  margin: 0 auto 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.5rem; font-weight: 600; color: #fff;
  border: 3px solid var(--gold);
  overflow: hidden;
}
.drawer-photo img { width: 100%; height: 100%; object-fit: cover; }
#drawer-name { text-align: center; margin: 0 0 4px; color: var(--blue-dark); }
.drawer-dates, .drawer-place { text-align: center; color: var(--muted); font-size: 0.85rem; }
.drawer-bio { margin: 14px 0; line-height: 1.5; font-size: 0.9rem; white-space: pre-wrap; }
.drawer-relatives { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin: 14px 0; }
.drawer-footer { display: flex; gap: 8px; justify-content: center; border-top: 1px solid var(--gold-light); padding-top: 14px; }

/* ---- Modal ---- */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(20, 14, 6, 0.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 30;
}
.modal-backdrop[hidden] { display: none; }
.modal {
  background: var(--panel);
  border: 2px solid var(--gold);
  border-radius: var(--radius);
  padding: 22px 24px;
  width: 460px; max-width: 92vw;
  max-height: 88vh; overflow-y: auto;
}
.modal h2 { margin-top: 0; color: var(--blue-dark); }
.form-row { display: flex; gap: 12px; }
.form-row label, .form-block { display: block; flex: 1; margin-bottom: 12px; font-size: 0.85rem; color: var(--muted); }
input[type="text"], input[type="password"], input[type="file"], select, textarea {
  width: 100%; margin-top: 4px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 0.9rem;
  font-family: inherit;
  color: var(--ink);
  background: #fff;
}
input[type="text"]:focus, textarea:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 2px rgba(14, 107, 168, 0.15); }
.photo-preview img { width: 64px; height: 64px; object-fit: cover; border-radius: 50%; margin-top: 8px; border: 2px solid var(--gold); }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

/* ---- Standalone pages (login, person form) ---- */
.page-wrap {
  min-height: calc(100vh - 78px);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 40px 16px;
}
.page-card {
  background: var(--panel);
  border: 2px solid var(--gold);
  border-radius: var(--radius);
  padding: 26px 28px;
  width: 460px; max-width: 100%;
}
.page-card h2 { margin-top: 0; color: var(--blue-dark); }
.page-card-narrow { width: 340px; }
.current-photo { display: flex; align-items: center; gap: 10px; margin-top: 6px; }
.current-photo img { width: 56px; height: 56px; object-fit: cover; border-radius: 50%; border: 2px solid var(--gold); }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; font-size: 0.9rem; }
.flash-error { background: #f6dad2; color: var(--maroon); border: 1px solid var(--maroon); }
.flash-success { background: #dcecd8; color: #2e5c2b; border: 1px solid #2e5c2b; }

.back-link { display: inline-block; margin-bottom: 14px; color: var(--blue-dark); font-size: 0.85rem; text-decoration: none; }
.back-link:hover { text-decoration: underline; }

@media (max-width: 640px) {
  .form-row { flex-direction: column; gap: 0; }
  .toolbar { flex-direction: column; align-items: flex-start; gap: 10px; }
  .toolbar::after { bottom: -8px; }
}
