/**
 * Family Tree Styles
 *
 * World-class, warm, photo-forward design for family connections
 * Following design-system.css patterns
 */

/* =========================================
   Family Card Component
   ========================================= */

.family-card {
  background: white;
  border-radius: 12px;
  padding: 16px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
  transition: all 0.2s ease;
  cursor: pointer;
  border: 2px solid transparent;
}

.family-card:hover {
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  transform: translateY(-2px);
  border-color: var(--color-teal-200, #99f6e4);
}

.family-card:focus-visible {
  outline: none;
  ring: 2px solid var(--color-teal-500);
  ring-offset: 2px;
}

.family-card-center {
  background: linear-gradient(135deg, #f0fdfa 0%, #ffffff 100%);
  border: 2px solid var(--color-teal-300, #5eead4);
  cursor: default;
  transform: none;
}

.family-card-center:hover {
  transform: none;
}

/* Memorial (deceased) card styling */
.family-card.memorial {
  background: linear-gradient(135deg, #faf5f0 0%, #ffffff 100%);
  border-color: #e5ddd5;
}

.family-card.memorial:hover {
  border-color: #d4c8be;
}

/* Former partner styling */
.family-card.former-partner {
  border-style: dashed;
}

/* Sepia filter for deceased photos */
img.sepia {
  filter: sepia(30%) saturate(80%);
}

/* =========================================
   Living Indicator (green dot)
   ========================================= */

.living-indicator {
  position: absolute;
  bottom: 2px;
  right: 2px;
  width: 14px;
  height: 14px;
  background-color: #22c55e;
  border: 3px solid white;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.living-indicator-sm {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 10px;
  height: 10px;
  background-color: #22c55e;
  border: 2px solid white;
  border-radius: 50%;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

/* =========================================
   Family Section
   ========================================= */

.family-section {
  margin-bottom: 2rem;
  padding: 1.5rem;
  background: rgba(255, 255, 255, 0.5);
  border-radius: 16px;
  backdrop-filter: blur(10px);
}

.family-section .section-title {
  font-size: 0.875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #6b7280;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid #e5e7eb;
}

/* =========================================
   Family Cards Grid
   ========================================= */

.family-cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}

@media (max-width: 640px) {
  .family-cards-grid {
    grid-template-columns: 1fr;
  }
}

/* =========================================
   Family List View
   ========================================= */

.family-list-container {
  background: white;
  border-radius: 16px;
  padding: 1.5rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.family-list-item {
  padding: 1rem;
  border-radius: 8px;
  transition: all 0.15s ease;
  cursor: pointer;
  border: 1px solid transparent;
}

.family-list-item:hover {
  background-color: #f0fdfa;
  border-color: #99f6e4;
}

.family-list-item.memorial {
  background-color: #faf9f7;
}

.family-list-item.memorial:hover {
  background-color: #f5f3f0;
  border-color: #e5ddd5;
}

/* =========================================
   Family Circle Container
   ========================================= */

.family-circle-container {
  max-width: 900px;
  margin: 0 auto;
}

/* =========================================
   Buttons
   ========================================= */

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.625rem 1.25rem;
  border: none;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 500;
  color: white;
  background-color: #0d9488;
  transition: all 0.15s ease;
  cursor: pointer;
}

.btn-primary:hover:not(:disabled) {
  background-color: #0f766e;
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.625rem 1.25rem;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 500;
  color: #374151;
  background-color: white;
  transition: all 0.15s ease;
  cursor: pointer;
}

.btn-secondary:hover:not(:disabled) {
  background-color: #f9fafb;
  border-color: #9ca3af;
}

.btn-secondary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* =========================================
   Stats Badge
   ========================================= */

.stats-badge {
  text-align: center;
}

.stats-badge-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: #0d9488;
}

.stats-badge-label {
  font-size: 0.75rem;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* =========================================
   Form Styles
   ========================================= */

.family-tree-header input[type="search"],
.family-tree-header select {
  border-radius: 8px;
  border-color: #d1d5db;
  padding: 0.5rem 1rem;
}

.family-tree-header input[type="search"]:focus,
.family-tree-header select:focus {
  border-color: #0d9488;
  box-shadow: 0 0 0 3px rgba(13, 148, 136, 0.1);
}

/* =========================================
   Modal Styles
   ========================================= */

[x-cloak] {
  display: none !important;
}

/* Modal backdrop animation */
.modal-backdrop {
  transition: opacity 0.2s ease;
}

/* =========================================
   Import Review Cards
   ========================================= */

.import-review-card {
  border-radius: 8px;
  padding: 1rem;
  border: 2px solid #e5e7eb;
  transition: all 0.15s ease;
}

.import-review-card.approved {
  border-color: #22c55e;
  background-color: #f0fdf4;
}

.import-review-card.rejected {
  border-color: #ef4444;
  background-color: #fef2f2;
}

/* =========================================
   Lineage Document Styles
   ========================================= */

.prose h1 {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 1rem;
  color: #111827;
}

.prose h2 {
  font-size: 1.25rem;
  font-weight: 600;
  margin-top: 1.5rem;
  margin-bottom: 0.75rem;
  color: #1f2937;
}

.prose h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-top: 1rem;
  margin-bottom: 0.5rem;
  color: #374151;
}

.prose p {
  margin-bottom: 0.75rem;
  color: #4b5563;
  line-height: 1.6;
}

.prose li {
  margin-left: 1rem;
  margin-bottom: 0.25rem;
  color: #4b5563;
}

.prose strong {
  font-weight: 600;
  color: #1f2937;
}

.prose em {
  font-style: italic;
  color: #6b7280;
}

/* =========================================
   Animations
   ========================================= */

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

.family-card {
  animation: fadeInUp 0.3s ease forwards;
}

.family-section:nth-child(1) { animation-delay: 0.05s; }
.family-section:nth-child(2) { animation-delay: 0.1s; }
.family-section:nth-child(3) { animation-delay: 0.15s; }
.family-section:nth-child(4) { animation-delay: 0.2s; }
.family-section:nth-child(5) { animation-delay: 0.25s; }
.family-section:nth-child(6) { animation-delay: 0.3s; }

/* =========================================
   Responsive Adjustments
   ========================================= */

@media (max-width: 640px) {
  .family-section {
    padding: 1rem;
  }

  .family-card {
    padding: 12px;
  }

  .family-card-center img {
    width: 60px;
    height: 60px;
  }

  .btn-primary,
  .btn-secondary {
    padding: 0.5rem 1rem;
    font-size: 0.8125rem;
  }
}

/* =========================================
   Accessibility
   ========================================= */

@media (prefers-reduced-motion: reduce) {
  .family-card,
  .family-section {
    animation: none;
    transition: none;
  }
}

/* High contrast mode */
@media (prefers-contrast: high) {
  .family-card {
    border: 2px solid #000;
  }

  .living-indicator,
  .living-indicator-sm {
    border-color: #000;
  }
}

/* Focus indicators for keyboard navigation */
.family-card:focus-visible,
.family-list-item:focus-visible,
button:focus-visible {
  outline: 2px solid #0d9488;
  outline-offset: 2px;
}

/* =========================================
   Tree Builder - Zoom/Pan Controls
   ========================================= */

.tree-builder-container {
  background: white;
  border-radius: 16px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  overflow: hidden;
}

.tree-viewport {
  background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
  background-image:
    radial-gradient(circle, #e2e8f0 1px, transparent 1px);
  background-size: 24px 24px;
}

.tree-content {
  transition: transform 0.1s ease-out;
  will-change: transform;
  min-width: max-content;
}

.tree-person-card {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  background: white;
  border-radius: 8px;
  border: 1px solid #e5e7eb;
  margin-bottom: 0.25rem;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.tree-person-card:hover {
  background: #f0fdfa;
  border-color: #99f6e4;
}

.tree-person-card.family-deceased {
  background: #fafaf9;
  border-color: #e7e5e4;
}

.tree-spouse-connector {
  color: #9ca3af;
  margin: 0 0.25rem;
  font-weight: bold;
}

.tree-partner {
  color: #0f766e;
  font-weight: 500;
}

.tree-ex-partner {
  color: #78716c;
  font-style: italic;
}

.tree-ex-partner::before {
  content: "(ex) ";
  font-size: 0.75em;
  color: #a8a29e;
}

.family-initials {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 600;
  color: white;
  flex-shrink: 0;
}

.family-initials-lg {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.875rem;
  font-weight: 600;
  color: white;
  flex-shrink: 0;
}

/* Zoom level visual feedback */
.tree-viewport[data-zooming="true"] .tree-content {
  transition: none;
}

/* =========================================
   Timeline View
   ========================================= */

.timeline-container {
  min-height: 400px;
}

.timeline-chart {
  position: relative;
  padding-bottom: 1rem;
}

.timeline-decades {
  position: relative;
}

.timeline-row {
  position: relative;
}

.timeline-row:hover .timeline-bar {
  filter: brightness(1.1);
  transform: scaleY(1.1);
}

.timeline-bar {
  transition: all 0.15s ease;
  min-width: 80px;
  overflow: hidden;
}

.timeline-bar:hover {
  z-index: 10;
}

/* Tooltip styling */
.timeline-row:hover .timeline-tooltip {
  opacity: 1;
}

.timeline-tooltip {
  position: absolute;
  top: -30px;
  left: 50%;
  transform: translateX(-50%);
  background: #1f2937;
  color: white;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 0.75rem;
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.15s ease;
  pointer-events: none;
  z-index: 20;
}

/* =========================================
   Mobile Optimizations
   ========================================= */

/* Mobile swipe hint */
.mobile-swipe-hint {
  animation: pulse-hint 2s ease-in-out 3;
  background: linear-gradient(90deg, transparent, rgba(20, 184, 166, 0.1), transparent);
  border-radius: 8px;
}

@keyframes pulse-hint {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 1; }
}

/* Mobile-specific adjustments */
@media (max-width: 640px) {
  /* Larger touch targets for cards */
  .family-card {
    padding: 16px;
    min-height: 64px;
  }

  .family-card img {
    width: 48px;
    height: 48px;
  }

  /* Better button sizing for touch */
  .btn-primary,
  .btn-secondary {
    min-height: 44px;
    padding: 12px 16px;
  }

  /* Family section spacing */
  .family-section {
    padding: 16px;
    margin-bottom: 16px;
  }

  /* Cards grid - single column on small screens */
  .family-cards-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  /* View mode toggle - horizontal on mobile */
  .fixed.bottom-6.left-6 {
    flex-direction: row !important;
    bottom: 16px !important;
    left: 50% !important;
    transform: translateX(-50%);
    gap: 8px !important;
    background: rgba(255, 255, 255, 0.95);
    padding: 8px;
    border-radius: 999px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  }

  .fixed.bottom-6.left-6 button {
    padding: 10px;
  }

  .fixed.bottom-6.left-6 button svg {
    width: 20px;
    height: 20px;
  }

  /* Timeline - horizontal scroll with touch momentum */
  .timeline-container {
    -webkit-overflow-scrolling: touch;
  }

  .timeline-chart {
    min-width: 600px;
  }

  .timeline-bar {
    min-width: 60px;
    padding: 4px 8px;
  }

  /* Tree builder adjustments */
  .tree-builder-container .bg-white.border-b {
    flex-direction: column;
    gap: 12px;
    padding: 12px;
  }

  .tree-viewport {
    height: calc(100vh - 320px) !important;
  }

  /* Modal improvements for mobile */
  .fixed.inset-0.z-50 .relative.bg-white {
    max-height: 95vh;
    margin: 8px;
    border-radius: 16px;
  }

  /* Header actions wrap */
  .family-tree-header .flex.gap-2 {
    flex-wrap: wrap;
  }

  .family-tree-header button {
    flex: 1 1 calc(50% - 4px);
    min-width: 120px;
  }
}

/* Tablet adjustments */
@media (min-width: 641px) and (max-width: 1024px) {
  .family-cards-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  /* Keep view toggle vertical but smaller */
  .fixed.bottom-6.left-6 button {
    padding: 10px;
  }
}

/* Touch feedback */
@media (hover: none) and (pointer: coarse) {
  .family-card:active {
    transform: scale(0.98);
    transition: transform 0.1s ease;
  }

  .timeline-row:active .timeline-bar {
    filter: brightness(0.9);
  }
}

/* =========================================
   Print Styles
   ========================================= */

@media print {
  .family-tree-header button,
  .view-mode-toggle,
  #main-navigation,
  #main-footer {
    display: none !important;
  }

  .family-card {
    box-shadow: none;
    border: 1px solid #ccc;
    page-break-inside: avoid;
  }

  .family-section {
    background: white;
    backdrop-filter: none;
  }
}
