/* ==========================================================================
   ÁRVORE GENEALÓGICA INTERATIVA - PEREIRA JÚNIOR & ÁVILA
   Design lúdico, aconchegante e 100% adaptado para celular (Touch-first)
   ========================================================================== */

:root {
  /* Paleta Lúdica Botânica & Pergaminho */
  --bg-main: #FBF9F4;
  --bg-surface: #FFFFFF;
  --bg-surface-alt: #F4EFE6;
  --bg-header: rgba(251, 249, 244, 0.96);
  --bg-card: #FFFFFF;
  
  --primary: #2D6A4F;
  --primary-light: #40916C;
  --primary-subtle: #EAF4EE;
  --primary-dark: #1B4332;
  
  --accent-gold: #D48B38;
  --accent-gold-light: #FDF5E6;
  --accent-terracotta: #BC544B;
  --accent-rose: #C05C7E;
  --accent-rose-light: #F9ECF1;
  
  --male-color: #2B6CB0;
  --male-bg: #EBF4FF;
  --female-color: #B83280;
  --female-bg: #FDF2F8;
  --neutral-color: #4A5568;
  --neutral-bg: #EDF2F7;

  --text-main: #242220;
  --text-muted: #6B665F;
  --text-light: #968F85;
  
  --border-color: #E6DFD3;
  --border-subtle: #F0EAE1;
  --shadow-sm: 0 2px 8px rgba(45, 35, 25, 0.05);
  --shadow-md: 0 4px 16px rgba(45, 35, 25, 0.08);
  --shadow-lg: 0 12px 32px rgba(45, 35, 25, 0.12);
  --shadow-card: 0 4px 14px rgba(45, 35, 25, 0.07);

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-full: 9999px;
  
  --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --transition: all 0.22s cubic-bezier(0.2, 0.8, 0.2, 1);
  --bottom-nav-height: 64px;
}

/* Reset Global e Proteção de Imagens */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

img {
  max-width: 100%;
  height: auto;
  display: block;
}

body {
  font-family: var(--font-family);
  background-color: var(--bg-main);
  color: var(--text-main);
  line-height: 1.5;
  overflow: hidden;
  height: 100vh;
  width: 100vw;
  user-select: none;
}

#app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
  position: relative;
}

/* ==========================================================================
   Header Superior
   ========================================================================== */
.main-header {
  height: 60px;
  background: var(--bg-header);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 100;
  flex-shrink: 0;
  box-shadow: var(--shadow-sm);
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}

.brand-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  display: flex;
  align-items: center;
  justify-content: center;
  color: #FFF;
  font-size: 19px;
  box-shadow: 0 4px 10px rgba(45, 106, 79, 0.25);
}

.brand-info h1 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--primary-dark);
  letter-spacing: -0.3px;
  line-height: 1.2;
}

.brand-info p {
  font-size: 0.72rem;
  color: var(--text-muted);
}

/* Barra de Busca Topo */
.header-search {
  position: relative;
  flex: 1;
  max-width: 360px;
  margin: 0 16px;
}

.search-input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 12px;
  color: var(--text-light);
  pointer-events: none;
}

.search-input {
  width: 100%;
  height: 38px;
  padding: 6px 36px 6px 36px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-color);
  background: var(--bg-surface);
  font-size: 0.88rem;
  color: var(--text-main);
  outline: none;
  transition: var(--transition);
  box-shadow: 0 2px 6px rgba(0,0,0,0.02);
}

.search-input:focus {
  border-color: var(--primary);
  background: #FFF;
  box-shadow: 0 0 0 3px var(--primary-subtle);
}

.search-clear-btn {
  position: absolute;
  right: 12px;
  background: none;
  border: none;
  color: var(--text-light);
  font-size: 15px;
  cursor: pointer;
  display: none;
}

.search-results-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  max-height: 360px;
  overflow-y: auto;
  display: none;
  z-index: 500;
}

.search-result-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-subtle);
  cursor: pointer;
  transition: var(--transition);
}

.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover, .search-result-item.active { background: var(--primary-subtle); }

.search-item-info { flex: 1; min-width: 0; }
.search-item-name { font-size: 0.88rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.search-item-meta { font-size: 0.75rem; color: var(--text-muted); }
.search-item-badge { font-size: 0.7rem; padding: 2px 8px; border-radius: var(--radius-full); background: var(--bg-surface-alt); color: var(--text-muted); font-weight: 500; }

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-icon {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border-color);
  background: var(--bg-surface);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  cursor: pointer;
  transition: var(--transition);
}

.btn-icon:hover {
  background: var(--primary-subtle);
  color: var(--primary);
  border-color: var(--primary-light);
}

/* ==========================================================================
   BARRA DE ISOLAMENTO DE ÁRVORES (SELETOR PRINCIPAL DE RAMOS)
   ========================================================================== */
.tree-isolation-bar {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  padding: 7px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  z-index: 95;
  flex-shrink: 0;
  overflow-x: auto;
}

.isolation-selector-pills {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-surface-alt);
  padding: 3px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-color);
  white-space: nowrap;
}

.isolation-pill {
  padding: 5px 12px;
  border-radius: var(--radius-full);
  border: none;
  background: none;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  gap: 5px;
}

.isolation-pill:hover { color: var(--primary-dark); }
.isolation-pill.active { background: var(--primary); color: #FFF; box-shadow: var(--shadow-sm); }
.isolation-pill.pereira.active { background: var(--primary); color: #FFF; }
.isolation-pill.avila.active { background: var(--accent-rose); color: #FFF; }

.view-mode-toggle {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--bg-surface-alt);
  padding: 3px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-color);
  white-space: nowrap;
}

.view-mode-pill {
  padding: 4px 10px;
  border-radius: var(--radius-full);
  border: none;
  background: none;
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: var(--transition);
}

.view-mode-pill.active {
  background: var(--bg-surface);
  color: var(--primary);
  box-shadow: 0 1px 4px rgba(0,0,0,0.1);
}

/* Sub-Header / Chips Rápidos de Navegação */
.quick-nav-bar {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  padding: 6px 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  overflow-x: auto;
  white-space: nowrap;
  scrollbar-width: none;
  -ms-overflow-style: none;
  z-index: 90;
  flex-shrink: 0;
}

.quick-nav-bar::-webkit-scrollbar { display: none; }
.quick-nav-label { font-size: 0.7rem; font-weight: 600; color: var(--text-light); text-transform: uppercase; letter-spacing: 0.5px; margin-right: 4px; }

.quick-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  background: var(--bg-surface-alt);
  border: 1px solid var(--border-color);
  font-size: 0.76rem;
  font-weight: 500;
  color: var(--text-main);
  cursor: pointer;
  transition: var(--transition);
}

.quick-chip:hover { background: var(--primary-subtle); border-color: var(--primary-light); color: var(--primary); }
.quick-chip.active { background: var(--primary); border-color: var(--primary); color: #FFF; }
.quick-chip img { width: 18px; height: 18px; border-radius: 50%; object-fit: cover; }

/* ==========================================================================
   COMPONENTES DE AVATAR (DIMENSÕES ESTRITAS E BLINDADAS)
   ========================================================================== */
.avatar-img,
img.avatar-img {
  object-fit: cover !important;
  flex-shrink: 0 !important;
  border: 1px solid var(--border-color) !important;
  background: var(--bg-surface-alt) !important;
  display: block !important;
}

.avatar-placeholder {
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  position: relative !important;
  font-weight: 700 !important;
  border: 1px solid var(--border-color) !important;
  user-select: none !important;
  flex-shrink: 0 !important;
}

.avatar-placeholder.male { background: #EDF2F7; color: #2B4C6F; border-color: #CBD5E1 !important; }
.avatar-placeholder.female { background: #FDF2F4; color: #7A2E4B; border-color: #F1D4DF !important; }
.avatar-placeholder.neutral { background: #F4EFEA; color: #4A463F; border-color: #DCD6CD !important; }
.avatar-placeholder .avatar-icon { display: none !important; }

/* Tamanho SM (28px) */
.size-sm,
img.avatar-img.size-sm,
.avatar-placeholder.size-sm {
  width: 28px !important;
  height: 28px !important;
  min-width: 28px !important;
  max-width: 28px !important;
  min-height: 28px !important;
  max-height: 28px !important;
  font-size: 11px !important;
  border-radius: 50% !important;
}
.size-sm .avatar-icon { font-size: 8px !important; }

/* Tamanho MD (48px) - Usado nos Cards da Árvore */
.size-md,
img.avatar-img.size-md,
.avatar-placeholder.size-md {
  width: 48px !important;
  height: 48px !important;
  min-width: 48px !important;
  max-width: 48px !important;
  min-height: 48px !important;
  max-height: 48px !important;
  font-size: 15px !important;
  border-radius: var(--radius-sm) !important;
}
.size-md .avatar-icon { font-size: 11px !important; }

/* Tamanho LG (64px) - Usado no Card de Foco Mobile */
.size-lg,
img.avatar-img.size-lg,
.avatar-placeholder.size-lg {
  width: 64px !important;
  height: 64px !important;
  min-width: 64px !important;
  max-width: 64px !important;
  min-height: 64px !important;
  max-height: 64px !important;
  font-size: 20px !important;
  border-radius: var(--radius-md) !important;
}
.size-lg .avatar-icon { font-size: 14px !important; bottom: -4px !important; right: -4px !important; padding: 2px !important; }

/* Tamanho XL (80px) - Usado no Topo da Ficha Bottom Sheet */
.size-xl,
img.avatar-img.size-xl,
.avatar-placeholder.size-xl {
  width: 80px !important;
  height: 80px !important;
  min-width: 80px !important;
  max-width: 80px !important;
  min-height: 80px !important;
  max-height: 80px !important;
  font-size: 24px !important;
  border-radius: var(--radius-md) !important;
}
.size-xl .avatar-icon { font-size: 16px !important; bottom: -5px !important; right: -5px !important; padding: 3px !important; }

/* ==========================================================================
   Área de Conteúdo Principal
   ========================================================================== */
.main-content {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: radial-gradient(#E8E1D5 1px, transparent 1px);
  background-size: 24px 24px;
  background-color: var(--bg-main);
}

.view-section {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: none !important;
  overflow: hidden;
}

.view-section.active {
  display: flex !important;
  flex-direction: column;
}

/* ==========================================================================
   1. MODO MOBILE VERTICAL (CASCATA OTIMIZADA PARA CELULAR)
   ========================================================================== */
#mobile-vertical-tree {
  overflow-y: auto;
  padding: 16px 14px 80px;
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  display: none;
}

.mobile-tree-section-title {
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-light);
  margin: 16px 0 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.mobile-tree-section-title::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border-color);
}

.mobile-focal-card {
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  border: 2px solid var(--accent-gold);
  box-shadow: 0 4px 16px rgba(212, 139, 56, 0.15);
  padding: 14px;
  display: flex;
  gap: 14px;
  align-items: center;
  margin-bottom: 14px;
  cursor: pointer;
  position: relative;
  background: linear-gradient(to right, #FFF, #FAF6EE);
  overflow: hidden;
}

.mobile-focal-card::before {
  content: 'PESSOA EM FOCO';
  position: absolute;
  top: 10px;
  right: 12px;
  background: var(--bg-surface-alt);
  color: var(--primary-dark);
  font-size: 0.64rem;
  font-weight: 700;
  letter-spacing: 0.6px;
  padding: 2px 7px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
}

.mobile-gen-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 10px;
}

.mobile-gen-grid.single-col { grid-template-columns: 1fr; }

.mobile-gen-card {
  background: var(--bg-surface);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  padding: 8px 10px;
  box-shadow: var(--shadow-sm);
  display: flex;
  gap: 10px;
  align-items: center;
  cursor: pointer;
  transition: var(--transition);
  overflow: hidden;
}

.mobile-gen-card:hover, .mobile-gen-card:active {
  border-color: var(--primary);
  background: var(--primary-subtle);
  transform: translateY(-2px);
}

.mobile-gen-card.male { border-left: 4px solid var(--male-color); }
.mobile-gen-card.female { border-left: 4px solid var(--female-color); }
.mobile-card-info { min-width: 0; flex: 1; overflow: hidden; }
.mobile-card-role { font-size: 0.68rem; font-weight: 700; color: var(--text-light); text-transform: uppercase; }
.mobile-card-name { font-size: 0.82rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mobile-card-dates { font-size: 0.7rem; color: var(--text-muted); }

/* ==========================================================================
   2. MODO PANORÂMICO (CANVAS / SVG COM PAN E ZOOM)
   ========================================================================== */
#tree-panoramic-container {
  width: 100%;
  height: 100%;
  position: relative;
}

#tree-viewport {
  width: 100%;
  height: 100%;
  cursor: grab;
  position: relative;
  overflow: hidden;
}

#tree-viewport:active { cursor: grabbing; }

#tree-svg {
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
}

#tree-nodes-container {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  will-change: transform;
}

/* Card de Cada Pessoa na Árvore Panorâmica */
.tree-node-card {
  position: absolute;
  width: 220px;
  height: 76px;
  background: var(--bg-card);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  border: 2px solid var(--border-color);
  padding: 8px 10px;
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.2s ease;
  user-select: none;
  z-index: 10;
  overflow: hidden;
}

.tree-node-card:hover {
  transform: translateY(-3px) scale(1.02);
  box-shadow: var(--shadow-lg);
  border-color: var(--primary);
  z-index: 20;
}

.tree-node-card.focal-person {
  border: 3px solid var(--accent-gold);
  box-shadow: 0 0 0 4px var(--accent-gold-light), var(--shadow-lg);
  background: linear-gradient(to bottom, #FFF, #FCF8F2);
}

.tree-node-card.selected {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-subtle), var(--shadow-lg);
}

.tree-node-card.male { border-left: 5px solid var(--male-color); }
.tree-node-card.female { border-left: 5px solid var(--female-color); }

.tree-node-card img.avatar-img {
  width: 48px !important;
  height: 48px !important;
  min-width: 48px !important;
  max-width: 48px !important;
  border-radius: var(--radius-sm) !important;
  object-fit: cover !important;
}

.node-details {
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

.node-name {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-main);
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.node-dates {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.node-branch-tag {
  display: inline-block;
  font-size: 0.65rem;
  padding: 1px 6px;
  border-radius: var(--radius-full);
  background: var(--bg-surface-alt);
  color: var(--text-muted);
  margin-top: 3px;
  font-weight: 500;
  white-space: nowrap;
}

/* Controles Flutuantes da Árvore */
.tree-floating-controls {
  position: absolute;
  bottom: 24px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 80;
}

.float-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  box-shadow: var(--shadow-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 19px;
  cursor: pointer;
  transition: var(--transition);
}

.float-btn:hover {
  background: var(--primary-subtle);
  color: var(--primary);
  border-color: var(--primary-light);
  transform: scale(1.05);
}

.float-btn:active { transform: scale(0.95); }

.tree-mode-selector {
  position: absolute;
  top: 14px;
  left: 16px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(8px);
  padding: 3px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  display: flex;
  gap: 3px;
  z-index: 80;
}

.mode-btn {
  padding: 5px 11px;
  border-radius: var(--radius-full);
  border: none;
  background: none;
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: var(--transition);
}

.mode-btn.active { background: var(--primary); color: #FFF; box-shadow: var(--shadow-sm); }

/* ==========================================================================
   Visualização em Leque (Fan Chart)
   ========================================================================== */
#fanchart-view {
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  overflow: auto;
}

.fanchart-container {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

#fanchart-svg {
  max-width: 95vw;
  max-height: 80vh;
}

/* ==========================================================================
   Calculadora de Parentesco ("O que sou de...?")
   ========================================================================== */
#kinship-view {
  overflow-y: auto;
  padding: 20px 16px 80px;
  max-width: 720px;
  margin: 0 auto;
  width: 100%;
}

.kinship-header { text-align: center; margin-bottom: 20px; }
.kinship-header h2 { font-size: 1.4rem; color: var(--primary-dark); font-weight: 700; }
.kinship-header p { color: var(--text-muted); font-size: 0.85rem; margin-top: 4px; }

.kinship-card {
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  padding: 18px;
  box-shadow: var(--shadow-card);
  margin-bottom: 20px;
}

.kinship-selectors {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 12px;
  align-items: center;
}

.selector-box label { display: block; font-size: 0.78rem; font-weight: 600; color: var(--text-muted); margin-bottom: 6px; }
.kinship-select { width: 100%; padding: 10px 12px; border-radius: var(--radius-md); border: 1px solid var(--border-color); background: var(--bg-main); font-size: 0.85rem; color: var(--text-main); outline: none; }
.kinship-swap-btn { width: 38px; height: 38px; border-radius: 50%; background: var(--primary-subtle); border: 1px solid var(--primary-light); color: var(--primary); font-size: 16px; display: flex; align-items: center; justify-content: center; cursor: pointer; margin-top: 18px; }
.kinship-calc-btn { width: 100%; margin-top: 16px; padding: 12px; background: var(--primary); color: #FFF; border: none; border-radius: var(--radius-md); font-size: 0.95rem; font-weight: 600; cursor: pointer; box-shadow: 0 4px 12px rgba(45, 106, 79, 0.25); transition: var(--transition); }
.kinship-calc-btn:hover { background: var(--primary-light); }

.kinship-result-box {
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  border: 2px dashed var(--border-color);
  padding: 20px;
  text-align: center;
}

.kinship-badge-big {
  display: inline-block;
  background: linear-gradient(135deg, var(--accent-gold), #F39C12);
  color: #FFF;
  font-size: 1.25rem;
  font-weight: 800;
  padding: 8px 22px;
  border-radius: var(--radius-full);
  margin-bottom: 14px;
  box-shadow: 0 4px 14px rgba(212, 139, 56, 0.3);
}

.kinship-path-list {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.path-step {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-surface-alt);
  padding: 4px 10px;
  border-radius: var(--radius-full);
  font-size: 0.8rem;
  font-weight: 600;
}

.path-arrow { color: var(--text-light); font-weight: bold; }

/* ==========================================================================
   Linha do Tempo (Timeline)
   ========================================================================== */
#timeline-view {
  overflow-y: auto;
  padding: 20px 16px 80px;
  max-width: 800px;
  margin: 0 auto;
  width: 100%;
}

.timeline-track { position: relative; padding-left: 28px; }
.timeline-track::before { content: ''; position: absolute; left: 10px; top: 10px; bottom: 10px; width: 3px; background: linear-gradient(to bottom, var(--primary), var(--accent-gold)); border-radius: 2px; }
.timeline-event-item { position: relative; margin-bottom: 20px; cursor: pointer; }
.timeline-dot { position: absolute; left: -28px; top: 12px; width: 20px; height: 20px; border-radius: 50%; background: #FFF; border: 3px solid var(--primary); box-shadow: 0 0 0 2px var(--primary-subtle); display: flex; align-items: center; justify-content: center; font-size: 9px; }

.timeline-card {
  background: var(--bg-surface);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  padding: 10px 14px;
  box-shadow: var(--shadow-sm);
  display: flex;
  gap: 12px;
  align-items: center;
  transition: var(--transition);
  overflow: hidden;
}

.timeline-card:hover { transform: translateX(4px); border-color: var(--primary); box-shadow: var(--shadow-md); }
.timeline-year { display: inline-block; font-size: 0.75rem; font-weight: 700; color: var(--primary); background: var(--primary-subtle); padding: 2px 8px; border-radius: var(--radius-full); margin-bottom: 2px; }
.timeline-title { font-size: 0.9rem; font-weight: 700; }
.timeline-desc { font-size: 0.76rem; color: var(--text-muted); }

/* ==========================================================================
   Galeria de Fotos Históricas
   ========================================================================== */
#gallery-view {
  overflow-y: auto;
  padding: 20px 16px 90px;
  width: 100%;
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 14px;
  max-width: 1200px;
  margin: 0 auto;
}

.gallery-card {
  background: var(--bg-surface);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  padding: 8px;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  flex-direction: column;
}

.gallery-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-lg); border-color: var(--accent-gold); }
.gallery-img-wrapper { position: relative; width: 100%; aspect-ratio: 1; border-radius: var(--radius-sm); overflow: hidden; background: var(--bg-surface-alt); }
.gallery-card img { width: 100%; height: 100%; object-fit: cover; transition: transform 0.3s ease; }
.gallery-card:hover img { transform: scale(1.05); }
.gallery-number-badge { position: absolute; top: 6px; left: 6px; background: rgba(0, 0, 0, 0.65); color: #FFF; font-size: 0.7rem; font-weight: 700; padding: 2px 6px; border-radius: var(--radius-full); backdrop-filter: blur(4px); }
.gallery-card-info { padding: 8px 4px 4px; }
.gallery-card-name { font-size: 0.8rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gallery-card-type { font-size: 0.68rem; color: var(--text-muted); }

/* ==========================================================================
   Estatísticas & Curiosidades
   ========================================================================== */
#stats-view {
  overflow-y: auto;
  padding: 20px 16px 90px;
  max-width: 900px;
  margin: 0 auto;
  width: 100%;
}

.stats-grid-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}

.stat-metric-card {
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  gap: 12px;
}

.stat-icon { width: 44px; height: 44px; border-radius: var(--radius-md); display: flex; align-items: center; justify-content: center; font-size: 22px; }
.stat-icon.green { background: var(--primary-subtle); color: var(--primary); }
.stat-icon.gold { background: var(--accent-gold-light); color: var(--accent-gold); }
.stat-icon.rose { background: var(--female-bg); color: var(--female-color); }
.stat-icon.blue { background: var(--male-bg); color: var(--male-color); }

.stat-value { font-size: 1.4rem; font-weight: 800; color: var(--text-main); line-height: 1.1; }
.stat-label { font-size: 0.75rem; color: var(--text-muted); font-weight: 500; }

.stats-section-box {
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  padding: 18px;
  box-shadow: var(--shadow-card);
  margin-bottom: 20px;
}

.stats-section-box h3 { font-size: 1.05rem; font-weight: 700; color: var(--primary-dark); margin-bottom: 12px; }
.bars-list { display: flex; flex-direction: column; gap: 8px; }
.bar-item { display: flex; flex-direction: column; gap: 4px; }
.bar-labels { display: flex; justify-content: space-between; font-size: 0.82rem; font-weight: 600; }
.bar-track { height: 8px; background: var(--bg-surface-alt); border-radius: var(--radius-full); overflow: hidden; }
.bar-fill { height: 100%; background: var(--primary); border-radius: var(--radius-full); }

/* ==========================================================================
   Bottom Sheet (Ficha do Indivíduo)
   ========================================================================== */
.bottom-sheet-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(30, 25, 20, 0.45);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.bottom-sheet-backdrop.active { opacity: 1; pointer-events: auto; }

.bottom-sheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-width: 600px;
  margin: 0 auto;
  max-height: 85vh;
  background: var(--bg-surface);
  border-top-left-radius: var(--radius-lg);
  border-top-right-radius: var(--radius-lg);
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.15);
  z-index: 210;
  transform: translateY(100%);
  transition: transform 0.35s cubic-bezier(0.2, 0.9, 0.2, 1);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.bottom-sheet.active { transform: translateY(0); }
.sheet-handle-bar { width: 44px; height: 5px; background: var(--border-color); border-radius: var(--radius-full); margin: 10px auto 4px; cursor: grab; }
.sheet-header { padding: 12px 20px 14px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--border-subtle); }
.sheet-close-btn { width: 32px; height: 32px; border-radius: 50%; background: var(--bg-surface-alt); border: none; color: var(--text-muted); font-size: 16px; display: flex; align-items: center; justify-content: center; cursor: pointer; }
.sheet-content { overflow-y: auto; padding: 20px; flex: 1; }

.profile-card-top {
  display: flex;
  gap: 16px;
  align-items: center;
  margin-bottom: 20px;
}

.profile-info h2 { font-size: 1.25rem; font-weight: 700; line-height: 1.2; }

.profile-status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  font-size: 0.78rem;
  font-weight: 600;
  margin-top: 6px;
}

.profile-status-badge.alive { background: var(--primary-subtle); color: var(--primary-dark); }
.profile-status-badge.deceased { background: var(--bg-surface-alt); color: var(--text-muted); }

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
  margin-right: 2px;
}
.profile-status-badge.alive .status-dot { background: var(--primary); }
.profile-status-badge.deceased .status-dot { background: var(--text-light); }

.pill-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
  margin-right: 3px;
}
.pill-dot.unida { background: var(--primary); }
.pill-dot.pereira { background: #2B6CB0; }
.pill-dot.avila { background: #B83280; }

.quick-chip .chip-initials {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--primary-subtle);
  color: var(--primary-dark);
  font-size: 8px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  letter-spacing: -0.5px;
}

.sheet-section { margin-bottom: 18px; }
.sheet-section-title { font-size: 0.78rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.6px; color: var(--text-light); margin-bottom: 8px; }

.relatives-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 8px;
}

.relative-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: var(--bg-surface-alt);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: var(--transition);
  overflow: hidden;
}

.relative-chip:hover { background: var(--primary-subtle); border-color: var(--primary); }
.relative-chip-text { min-width: 0; flex: 1; overflow: hidden; }
.relative-chip-name { font-size: 0.78rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.relative-chip-role { font-size: 0.68rem; color: var(--text-muted); }

.sheet-actions { display: flex; gap: 10px; margin-top: 20px; }
.sheet-btn { flex: 1; padding: 10px; border-radius: var(--radius-md); border: 1px solid var(--border-color); background: var(--bg-surface-alt); font-size: 0.85rem; font-weight: 600; color: var(--text-main); cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 6px; transition: var(--transition); }
.sheet-btn.primary { background: var(--primary); border-color: var(--primary); color: #FFF; }
.sheet-btn:hover { transform: translateY(-2px); }

/* ==========================================================================
   Barra de Navegação Inferior
   ========================================================================== */
.bottom-nav-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--bottom-nav-height);
  background: var(--bg-surface);
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-around;
  z-index: 100;
  box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.04);
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 600;
  padding: 6px 12px;
  cursor: pointer;
  transition: var(--transition);
  border-radius: var(--radius-md);
}

.nav-item .nav-icon { font-size: 20px; line-height: 1; }
.nav-item.active { color: var(--primary); }
.nav-item.active .nav-icon { transform: scale(1.15); }

/* Lightbox Modal */
.lightbox-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.88);
  backdrop-filter: blur(8px);
  z-index: 300;
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  padding: 20px;
}

.lightbox-modal.active { display: flex; }
.lightbox-close-btn { position: absolute; top: 20px; right: 20px; background: rgba(255, 255, 255, 0.2); border: none; color: #FFF; width: 44px; height: 44px; border-radius: 50%; font-size: 24px; cursor: pointer; display: flex; align-items: center; justify-content: center; }
.lightbox-img-wrapper { max-width: 90vw; max-height: 75vh; display: flex; align-items: center; justify-content: center; }
.lightbox-img-wrapper img { max-width: 100%; max-height: 75vh; object-fit: contain; border-radius: var(--radius-md); box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5); }
.lightbox-caption { margin-top: 16px; color: #FFF; text-align: center; max-width: 600px; }
.lightbox-caption h4 { font-size: 1.1rem; font-weight: 700; }
.lightbox-caption p { font-size: 0.85rem; color: #DDD; margin-top: 4px; }

/* ==========================================================================
   Responsividade Mobile (Telas pequenas)
   ========================================================================== */
@media (max-width: 768px) {
  .header-brand .brand-info p { display: none; }
  .header-search { max-width: 180px; margin: 0 8px; }
  .tree-node-card { width: 180px; padding: 8px; gap: 8px; }
  .node-name { font-size: 0.78rem; }
  .node-dates { font-size: 0.68rem; }
  .kinship-selectors { grid-template-columns: 1fr; }
  .kinship-swap-btn { margin: 0 auto; }
}

/* ==========================================================================
   Modais Genéricos (GEDCOM & Edição de Parentesco)
   ========================================================================== */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(20, 25, 20, 0.6);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  z-index: 250;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-backdrop.active {
  display: flex;
}

.app-modal {
  background: var(--bg-surface);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: modalPop 0.25s cubic-bezier(0.2, 0.9, 0.2, 1);
}

@keyframes modalPop {
  from { opacity: 0; transform: scale(0.95) translateY(10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-surface-alt);
}

.modal-header h3 {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--primary-dark);
  display: flex;
  align-items: center;
  gap: 8px;
}

.modal-close-btn {
  background: none;
  border: none;
  font-size: 18px;
  color: var(--text-muted);
  cursor: pointer;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.modal-close-btn:hover {
  background: rgba(0,0,0,0.06);
  color: var(--text-main);
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  background: var(--bg-surface);
}

/* Dropzone de Arquivos */
.file-dropzone {
  border: 2px dashed var(--primary-light);
  border-radius: var(--radius-md);
  padding: 24px 16px;
  text-align: center;
  background: var(--primary-subtle);
  cursor: pointer;
  transition: var(--transition);
}

.file-dropzone:hover, .file-dropzone.dragover {
  background: #DCEDE2;
  border-color: var(--primary);
  transform: scale(1.01);
}

.file-dropzone-icon {
  font-size: 36px;
  margin-bottom: 8px;
}

.file-dropzone-title {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--primary-dark);
}

.file-dropzone-desc {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* Formulários & Campos */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background: var(--bg-main);
  font-size: 0.9rem;
  color: var(--text-main);
  outline: none;
  font-family: inherit;
  transition: var(--transition);
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-subtle);
}

.form-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.form-checkbox-label {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 0.85rem;
  color: var(--text-main);
  cursor: pointer;
  user-select: none;
  background: var(--bg-surface-alt);
  padding: 10px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
}

.form-checkbox-label input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
  margin-top: 2px;
}

/* Status Box */
.gedcom-status-box {
  background: var(--bg-surface-alt);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  padding: 12px;
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.gedcom-status-box strong {
  color: var(--text-main);
}

/* Botões de Ação na Lista de Parentes */
.chip-unlink-btn {
  background: none;
  border: none;
  color: var(--text-light);
  font-size: 13px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.6;
  margin-left: 2px;
  flex-shrink: 0;
}

.chip-unlink-btn:hover {
  background: rgba(188, 84, 75, 0.15);
  color: var(--accent-terracotta);
  opacity: 1;
}

/* Toast Notifications */
.app-toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #1B4332;
  color: #FFF;
  padding: 10px 20px;
  border-radius: var(--radius-full);
  font-size: 0.88rem;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  z-index: 400;
  opacity: 0;
  pointer-events: none;
  transition: transform 0.25s ease, opacity 0.25s ease;
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 90vw;
  text-align: center;
}

.app-toast.active {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.app-toast.success { background: #2D6A4F; }
.app-toast.warn { background: #D48B38; }
.app-toast.error { background: #BC544B; }
