/* ==========================================================================
   Neighbour Bali — style.css
   ========================================================================== */

/* 1. CSS variables */
:root {
  --bg: #f4f1ea;
  --surface: #fff;
  --text: #1a1a1a;
  --muted: #6b6560;
  --accent: #c45c26;
  --accent-dark: #9a4520;
  --border: #e2ddd4;
  --male: #2d6a8f;
  --female: #8f3d6b;
  --shadow: 0 4px 24px rgba(26, 26, 26, 0.08);
  --radius: 12px;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

/* 2. Body, links, app-header */
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.app-header {
  background: linear-gradient(135deg, #1a5f4a 0%, #2d8a6e 50%, #c45c26 100%);
  color: #fff;
  padding: 1.25rem 1.5rem 2rem;
  position: relative;
  overflow: hidden;
}

.app-header::after {
  content: "";
  position: absolute;
  bottom: -40px;
  left: 0;
  right: 0;
  height: 80px;
  background: var(--bg);
  border-radius: 50% 50% 0 0 / 100% 100% 0 0;
}

.app-header h1 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 700;
  position: relative;
  z-index: 1;
}

.app-header p {
  margin: 0.25rem 0 0;
  opacity: 0.9;
  font-size: 0.9rem;
  position: relative;
  z-index: 1;
}

/* 3. Container, toolbar, search-box, buttons */
.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 0 1rem 3rem;
  position: relative;
  z-index: 2;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin: -1rem 0 1.5rem;
  align-items: center;
}

.search-box {
  flex: 1;
  min-width: 180px;
  display: flex;
  gap: 0.5rem;
}

.search-box input,
.search-box select,
input[type="search"],
input[type="text"],
input[type="date"],
input[type="file"],
select,
textarea {
  font: inherit;
  padding: 0.6rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  width: 100%;
}

.search-box input:focus,
input:focus,
select:focus,
textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.6rem 1.1rem;
  font: inherit;
  font-weight: 600;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 2px 8px rgba(196, 92, 38, 0.35);
}

.btn-primary:hover {
  background: var(--accent-dark);
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-danger {
  background: #b33;
  color: #fff;
}

.btn-sm {
  padding: 0.35rem 0.65rem;
  font-size: 0.85rem;
}

/* 4. Neighbour grid, cards, badges, tags */
.neighbour-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 1rem;
}

.neighbour-card {
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  transition: transform 0.2s, box-shadow 0.2s;
  cursor: pointer;
  text-decoration: none;
  color: inherit;
  display: block;
}

.neighbour-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 32px rgba(26, 26, 26, 0.12);
  text-decoration: none;
}

.card-photo {
  aspect-ratio: 1;
  background: #e8e4dc;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.card-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.card-photo .placeholder {
  font-size: 2.5rem;
  opacity: 0.35;
}

.card-body {
  padding: 0.75rem;
}

.card-body h3 {
  margin: 0;
  font-size: 1rem;
}

.card-body .sub {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 0.15rem;
}

.badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.badge-male {
  background: rgba(45, 106, 143, 0.15);
  color: var(--male);
}

.badge-female {
  background: rgba(143, 61, 107, 0.15);
  color: var(--female);
}

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.5rem;
}

.tag {
  font-size: 0.7rem;
  background: #eee9e0;
  color: var(--muted);
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
}

/* 5. Detail page, gallery, family list */
.detail-header {
  display: flex;
  gap: 1.5rem;
  flex-wrap: wrap;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
  margin-bottom: 1.5rem;
}

.detail-photo {
  width: 140px;
  height: 140px;
  border-radius: var(--radius);
  overflow: hidden;
  background: #e8e4dc;
  flex-shrink: 0;
}

.detail-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.detail-info h2 {
  margin: 0 0 0.25rem;
}

.detail-info .meta {
  color: var(--muted);
  font-size: 0.9rem;
}

.detail-actions {
  margin-top: 1rem;
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.section {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
  margin-bottom: 1rem;
}

.section h3 {
  margin: 0 0 1rem;
  font-size: 1rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 0.5rem;
}

.gallery-item {
  position: relative;
  aspect-ratio: 1;
  border-radius: 8px;
  overflow: hidden;
  background: #e8e4dc;
}

.gallery-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.family-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.family-list li {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--border);
}

.family-list li:last-child {
  border-bottom: none;
}

.family-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  overflow: hidden;
  background: #e8e4dc;
  flex-shrink: 0;
}

.family-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.rel-label {
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: capitalize;
}

.rel-inferred {
  font-size: 0.7rem;
  opacity: 0.85;
}

/* 6. Modal overlay, forms, toast */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 1rem;
  z-index: 1000;
  overflow-y: auto;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s, visibility 0.2s;
}

.modal-overlay.open {
  opacity: 1;
  visibility: visible;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  width: 100%;
  max-width: 520px;
  padding: 1.5rem;
  margin: auto;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.2);
}

.modal h2 {
  margin: 0 0 1.25rem;
}

.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 0.35rem;
  color: var(--muted);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.form-hint {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 0.25rem;
}

.radio-group {
  display: flex;
  gap: 1rem;
}

.radio-group label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-weight: normal;
  cursor: pointer;
}

.preview-img {
  width: 80px;
  height: 80px;
  border-radius: 8px;
  object-fit: cover;
  margin-top: 0.5rem;
  background: #e8e4dc;
}

.family-rows {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.family-row {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 0.5rem;
  align-items: end;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: #1a1a1a;
  color: #fff;
  padding: 0.75rem 1.25rem;
  border-radius: 8px;
  font-size: 0.9rem;
  z-index: 2000;
  transition: transform 0.3s;
  max-width: 90%;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
}

/* 7. Crop / camera / tree overlays (above form modal) */
.crop-overlay,
.camera-overlay,
.tree-overlay {
  z-index: 1100;
  align-items: center;
}

/* 8. Crop, camera, family-tree modals */
.crop-modal {
  max-width: 100%;
  width: 420px;
}

.crop-container {
  max-height: min(60vh, 400px);
  background: #111;
  border-radius: 8px;
  overflow: hidden;
}

.crop-container img {
  display: block;
  max-width: 100%;
}

.crop-toolbar {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  margin: 0.75rem 0 0;
}

.camera-modal {
  max-width: 100%;
  width: 420px;
}

.camera-wrap {
  background: #000;
  border-radius: 8px;
  overflow: hidden;
  aspect-ratio: 1;
  max-height: min(70vh, 420px);
}

.camera-wrap video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.camera-error {
  color: #b33;
  margin: 0.5rem 0 0;
}

.tree-modal {
  max-width: 96%;
  width: 720px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  padding: 1rem 1.25rem;
}

.tree-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.tree-modal-header h2 {
  margin: 0;
  font-size: 1.15rem;
}

.tree-canvas {
  overflow: auto;
  flex: 1;
  min-height: 200px;
  max-height: calc(90vh - 80px);
  -webkit-overflow-scrolling: touch;
}

.ft-chart {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  padding: 0.5rem 0 1rem;
  min-width: min-content;
}

.ft-row {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.ft-row-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 600;
}

.ft-row-nodes {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.75rem;
}

.ft-node {
  background: var(--bg);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 0.65rem;
  width: 110px;
  text-align: center;
  position: relative;
}

.ft-node-root {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(196, 92, 38, 0.2);
}

.ft-node-link {
  color: inherit;
  text-decoration: none;
  display: block;
}

.ft-node-link:hover {
  text-decoration: none;
}

.ft-avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  overflow: hidden;
  margin: 0 auto 0.4rem;
  background: #e8e4dc;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ft-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.ft-avatar span {
  font-size: 1rem;
  opacity: 0.4;
  font-weight: 700;
}

.ft-name {
  font-size: 0.85rem;
  font-weight: 600;
  line-height: 1.2;
  word-break: break-word;
}

.ft-sex {
  margin-top: 0.25rem;
  font-size: 0.65rem;
}

.ft-expand {
  margin-top: 0.5rem;
  width: 100%;
  font-size: 0.65rem;
  padding: 0.3rem 0.25rem;
  line-height: 1.2;
}

.ft-hint {
  text-align: center;
  margin-top: 0.5rem;
}

/* 9. Profile photo helpers */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.photo-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.foto-preview-wrap {
  margin-top: 0.5rem;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  overflow: hidden;
  background: #e8e4dc;
}

.foto-preview-wrap .preview-img {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  object-fit: cover;
  display: block;
  margin-top: 0;
}

/* 10. Back link, empty state, loading, responsive form-row */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin-bottom: 1rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.back-link:hover {
  color: var(--accent);
  text-decoration: none;
}

.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--muted);
}

.loading {
  text-align: center;
  padding: 2rem;
  color: var(--muted);
}

@media (max-width: 520px) {
  .form-row,
  .family-row {
    grid-template-columns: 1fr;
  }
}
