/* =========================================================
   Family Tree – Main Stylesheet
   ========================================================= */

/* ---------- Reset & Base -------------------------------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:          #1a1a2e;
  --surface:     #16213e;
  --surface2:    #0f3460;
  --accent:      #e94560;
  --accent2:     #57b8ff;
  --text:        #e0e0e0;
  --text-muted:  #8892a4;
  --living:      #4caf50;
  --deceased:    #e94560;
  --marriage:    #FFD700;
  --divorced:    #ff9800;
  --partner:     #ab47bc;
  --adopted:     #26c6da;
  --radius:      8px;
  --shadow:      0 4px 20px rgba(0,0,0,.45);
}

html, body { height: 100%; font-family: 'Segoe UI', system-ui, sans-serif; background: var(--bg); color: var(--text); font-size: 15px; }

a { color: var(--accent2); text-decoration: none; }
a:hover { text-decoration: underline; }

button { cursor: pointer; font: inherit; }

/* ---------- Layout -------------------------------------- */
#app { display: flex; flex-direction: column; height: 100%; }

/* ---------- Nav Bar ------------------------------------- */
#navbar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--surface2);
  flex-wrap: wrap;
}
#navbar h1 { font-size: 1.2rem; color: var(--accent); margin-right: 8px; white-space: nowrap; }

#family-selector { display: flex; align-items: center; gap: 8px; }
#family-select {
  background: var(--bg); color: var(--text);
  border: 1px solid var(--surface2); border-radius: var(--radius);
  padding: 5px 10px; font: inherit;
}

.nav-btn {
  padding: 6px 14px; border-radius: var(--radius); border: 1px solid var(--surface2);
  background: var(--surface2); color: var(--text); transition: background .2s;
}
.nav-btn:hover { background: var(--accent); border-color: var(--accent); }
.nav-btn.danger { border-color: var(--accent); }
.nav-btn.danger:hover { background: var(--accent); }
.nav-btn.primary { background: var(--accent); border-color: var(--accent); }
.nav-btn.primary:hover { opacity: .85; }

.spacer { flex: 1; }

/* ---------- Tabs ---------------------------------------- */
#tabs {
  display: flex; gap: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--surface2);
}
.tab-btn {
  padding: 10px 28px; border: none; background: transparent;
  color: var(--text-muted); font-size: 1rem; border-bottom: 3px solid transparent;
  transition: color .2s, border-color .2s;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ---------- Panels -------------------------------------- */
#panels { flex: 1; overflow: hidden; position: relative; }
.panel { display: none; height: 100%; }
.panel.active { display: flex; flex-direction: column; }

/* ---------- List Panel ---------------------------------- */
#list-panel { padding: 20px; overflow-y: auto; }

#list-controls {
  display: flex; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; align-items: center;
}
#search-input {
  flex: 1; min-width: 200px;
  padding: 8px 14px; border-radius: var(--radius);
  border: 1px solid var(--surface2); background: var(--surface);
  color: var(--text); font: inherit;
}
#search-input::placeholder { color: var(--text-muted); }

#person-count { color: var(--text-muted); font-size: .9rem; margin-left: auto; }

#person-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}

.person-card {
  background: var(--surface); border-radius: var(--radius);
  border: 1px solid var(--surface2); padding: 16px;
  cursor: pointer; transition: border-color .2s, transform .15s;
  display: flex; gap: 14px; align-items: flex-start;
}
.person-card:hover { border-color: var(--accent2); transform: translateY(-2px); }

.person-card .avatar {
  width: 56px; height: 56px; border-radius: 50%; object-fit: cover;
  flex-shrink: 0; background: var(--surface2);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.5rem; color: var(--text-muted);
  overflow: hidden;
}
.person-card .avatar img { width: 100%; height: 100%; object-fit: cover; }

.person-card .info h3 { font-size: 1rem; margin-bottom: 4px; }
.person-card .info .dates { font-size: .82rem; color: var(--text-muted); }
.person-card .info .desc { font-size: .85rem; margin-top: 6px; color: var(--text-muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

.badge {
  display: inline-block; font-size: .72rem; padding: 2px 8px; border-radius: 20px;
  margin-top: 6px;
}
.badge.living { background: rgba(76,175,80,.2); color: var(--living); }
.badge.deceased { background: rgba(233,69,96,.2); color: var(--deceased); }
.badge.adopted { background: rgba(38,198,218,.2); color: var(--adopted); }

.no-results { color: var(--text-muted); text-align: center; padding: 60px 0; width: 100%; }

/* ---------- Tree Panel ---------------------------------- */
#tree-panel { overflow: hidden; }

#tree-controls {
  display: flex; align-items: center; gap: 12px; padding: 10px 20px;
  background: var(--surface); border-bottom: 1px solid var(--surface2);
  flex-wrap: wrap;
}
#tree-controls label { color: var(--text-muted); font-size: .9rem; }
#root-select, #depth-input {
  background: var(--bg); color: var(--text);
  border: 1px solid var(--surface2); border-radius: var(--radius);
  padding: 5px 10px; font: inherit;
}
#depth-input { width: 70px; }
#render-btn { background: var(--accent); color: #fff; border: none; padding: 7px 18px; border-radius: var(--radius); }
#render-btn:hover { opacity: .85; }

#tree-container { flex: 1; overflow: hidden; position: relative; }
#tree-svg { width: 100%; height: 100%; }

/* Node styles */
.node circle { stroke-width: 2.5; }
.node.living circle { fill: #1e3a5f; stroke: var(--living); }
.node.deceased circle { fill: #3a1e2e; stroke: var(--deceased); }
.node text { fill: var(--text); font-size: 12px; pointer-events: none; }
.node .date-text { fill: var(--text-muted); font-size: 10px; }
.node:hover circle { filter: brightness(1.3); cursor: pointer; }
.node image { clip-path: circle(); }

/* Link styles */
.link { fill: none; stroke-width: 2; }
.link.parent-child { stroke: var(--text-muted); stroke-dasharray: none; }
.link.marriage { stroke: var(--marriage); stroke-width: 4; }
.link.divorced { stroke: var(--divorced); stroke-dasharray: 6,3; }
.link.partner { stroke: var(--partner); stroke-dasharray: 4,4; }
.link.adopted { stroke: var(--adopted); stroke-dasharray: 3,3; }

/* ---------- Legend -------------------------------------- */
#legend {
  position: absolute; bottom: 16px; right: 16px;
  background: rgba(22,33,62,.92); border: 1px solid var(--surface2);
  border-radius: var(--radius); padding: 12px 16px;
  font-size: .82rem; backdrop-filter: blur(4px);
}
#legend h4 { margin-bottom: 8px; color: var(--text-muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; }
.legend-item { display: flex; align-items: center; gap: 8px; margin: 4px 0; }
.legend-line { width: 28px; height: 3px; border-radius: 2px; }
.legend-circle { width: 14px; height: 14px; border-radius: 50%; border: 2.5px solid; }

/* ---------- Modals -------------------------------------- */
.modal-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.6); z-index: 1000;
  align-items: center; justify-content: center;
  backdrop-filter: blur(2px);
}
.modal-overlay.open { display: flex; }

.modal {
  background: var(--surface); border-radius: var(--radius);
  border: 1px solid var(--surface2); box-shadow: var(--shadow);
  width: 90%; max-width: 640px; max-height: 90vh;
  display: flex; flex-direction: column; overflow: hidden;
}
.modal.wide { max-width: 820px; }

.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--surface2);
}
.modal-header h2 { font-size: 1.1rem; }
.modal-close { background: none; border: none; color: var(--text-muted); font-size: 1.4rem; line-height: 1; padding: 0 4px; }
.modal-close:hover { color: var(--accent); }

.modal-body { padding: 20px; overflow-y: auto; flex: 1; }
.modal-footer { padding: 14px 20px; border-top: 1px solid var(--surface2); display: flex; gap: 10px; justify-content: flex-end; }

/* ---------- Forms --------------------------------------- */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; margin-bottom: 6px; color: var(--text-muted); font-size: .88rem; }
.form-group input[type=text],
.form-group input[type=date],
.form-group input[type=url],
.form-group textarea,
.form-group select {
  width: 100%; padding: 8px 12px;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--surface2); border-radius: var(--radius);
  font: inherit;
}
.form-group textarea { resize: vertical; min-height: 80px; }
.form-group input:focus, .form-group textarea:focus, .form-group select:focus {
  outline: none; border-color: var(--accent2);
}

.form-row { display: flex; gap: 12px; }
.form-row .form-group { flex: 1; }

/* Parent list in edit modal */
#parents-list { margin-top: 6px; }
.parent-entry {
  display: flex; gap: 8px; align-items: center; margin-bottom: 8px;
}
.parent-entry select { flex: 2; }
.parent-entry .type-select { flex: 1; }
.parent-entry button { background: var(--accent); color: #fff; border: none; border-radius: var(--radius); padding: 5px 10px; }

/* ---------- Person Detail Modal ------------------------- */
.detail-header { display: flex; gap: 20px; align-items: flex-start; margin-bottom: 20px; }
.detail-avatar {
  width: 80px; height: 80px; border-radius: 50%; flex-shrink: 0;
  background: var(--surface2); display: flex; align-items: center; justify-content: center;
  font-size: 2rem; overflow: hidden;
}
.detail-avatar img { width: 100%; height: 100%; object-fit: cover; }
.detail-info h2 { margin-bottom: 6px; }
.detail-dates { color: var(--text-muted); font-size: .9rem; }
.detail-desc { margin: 16px 0; line-height: 1.6; }
.detail-section h4 { color: var(--text-muted); font-size: .82rem; text-transform: uppercase; letter-spacing: .05em; margin-bottom: 10px; border-top: 1px solid var(--surface2); padding-top: 12px; }
.detail-section ul { list-style: none; padding: 0; }
.detail-section li { padding: 4px 0; font-size: .92rem; }
.detail-section li a { color: var(--accent2); }
.detail-section li a:hover { color: var(--accent); }

/* ---------- Import/Export ------------------------------- */
#export-output, #import-input {
  width: 100%; height: 300px; padding: 10px;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--surface2); border-radius: var(--radius);
  font-family: monospace; font-size: .82rem; resize: vertical;
}

/* ---------- Toast --------------------------------------- */
#toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(60px);
  background: var(--surface2); color: var(--text);
  padding: 10px 24px; border-radius: 24px; font-size: .9rem;
  box-shadow: var(--shadow); z-index: 2000;
  transition: transform .3s, opacity .3s; opacity: 0; pointer-events: none;
}
#toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }
#toast.success { background: rgba(76,175,80,.9); }
#toast.error { background: rgba(233,69,96,.9); }

/* ---------- Responsive ---------------------------------- */
@media (max-width: 600px) {
  #navbar { padding: 8px 12px; }
  #list-controls { flex-direction: column; }
  #tree-controls { flex-direction: column; align-items: flex-start; }
  #legend { font-size: .75rem; padding: 8px 12px; }
}
