:root {
  --primary: #2d5a27;
  --primary-light: #4a8c42;
  --secondary: #f4f7f6;
  --accent: #e67e22;
  --text-main: #1e293b;
  --text-muted: #64748b;
  --bg-main: #f0f2f5;
  --sidebar-bg: #1a3628;
  --white: #ffffff;
  --glass: rgba(255, 255, 255, 0.9);
  --shadow-sm: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  --border-radius: 12px;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: "Inter", "Sarabun", sans-serif;
}

body {
  background-color: var(--bg-main);
  color: var(--text-main);
  line-height: 1.6;
  display: flex;
  min-height: 100vh;
}

.app-container {
  display: flex;
  width: 100%;
}

/* Sidebar Styling removed and moved to components/sidebar.js */

.main-content {
  flex-grow: 1;
  padding: 2.5rem;
  background: var(--bg-main);
  overflow-y: auto;
}

header {
  margin-bottom: 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

h1 {
  font-size: 1.8rem;
  color: var(--primary);
  font-weight: 700;
}

nav {
  display: flex;
  gap: 1rem;
}

nav a {
  text-decoration: none;
  color: var(--text-muted);
  font-weight: 500;
  padding: 0.5rem 1rem;
  border-radius: var(--border-radius);
  transition: all 0.3s ease;
}

nav a:hover,
nav a.active {
  background: var(--white);
  color: var(--primary);
  box-shadow: var(--shadow);
}

.card {
  background: var(--glass);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: var(--border-radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
  margin-bottom: 1.5rem;
  transition: transform 0.3s ease;
}

.input-group {
  display: flex;
  gap: 1rem;
  align-items: flex-end;
  margin-bottom: 1rem;
}

.input-field {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
}

input,
select {
  padding: 0.75rem 1rem;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-size: 1rem;
  outline: none;
  transition: border-color 0.3s;
}

input:focus {
  border-color: var(--primary);
}

button {
  background: var(--primary);
  color: white;
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  transition:
    background 0.3s,
    transform 0.1s;
}

button:hover {
  background: var(--primary-light);
}

button:active {
  transform: scale(0.98);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.stat-card {
  text-align: center;
}

.stat-value {
  font-size: 2.5rem;
  font-weight: 800;
  color: var(--primary);
}

.stat-label {
  font-size: 0.9rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}

table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 1rem;
  background: white;
  border-radius: 8px;
  overflow: hidden;
}

th,
td {
  padding: 1rem;
  text-align: left;
  border-bottom: 1px solid #edf2f7;
}

th {
  background-color: #f8fafc;
  font-weight: 600;
  color: var(--text-muted);
  font-size: 0.85rem;
  text-transform: uppercase;
}

tr:hover {
  background-color: #f1f5f9;
}

.badge {
  padding: 0.25rem 0.75rem;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-low {
  background: #dcfce7;
  color: #166534;
}
.badge-medium {
  background: #fef9c3;
  color: #854d0e;
}
.badge-high {
  background: #fee2e2;
  color: #991b1b;
}

.hidden {
  display: none !important;
}

.results-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.grid-span-2 {
  grid-column: span 2;
}

.registration-card {
  grid-column: span 2;
  padding: 1.5rem;
}

.reg-section {
  margin-bottom: 1.5rem;
  border-bottom: 1px solid #edf2f7;
  padding-bottom: 1rem;
}

.reg-section:last-child {
  border-bottom: none;
}

.reg-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.reg-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.5rem 2rem;
}

.reg-item {
  display: flex;
  flex-direction: column;
}

.reg-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

.reg-value {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-main);
}

/* Transitions */
.fade-in {
  animation: fadeIn 0.5s ease-in;
}

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

/* Generational Grid Layout */
.pedigree-chart-container {
  width: 100%;
  height: 600px;
  overflow: hidden;
  position: relative;
  background: #f8fafc;
  border-radius: 12px;
  cursor: grab;
  border: 1px solid #e2e8f0;
}

.pedigree-chart-container:active {
  cursor: grabbing;
}

.pedigree-viewport {
  width: 3200px; /* Fixed wide width for deterministic math */
  min-height: 1000px;
  transform-origin: 0 0;
  transition: transform 0.1s ease-out;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 100px 0;
  background: white;
}

.pedigree-chart-outer {
  position: relative;
  width: 100%;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid #e2e8f0;
}

.zoom-controls {
  position: absolute;
  top: 1.5rem;
  right: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 100;
}

.zoom-btn {
  width: 40px;
  height: 40px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.generation-row {
  display: flex;
  justify-content: center;
  gap: 0;
  width: 100%;
  margin-bottom: 0;
}

.gen-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
}

.line-row {
  height: 60px;
  width: 100%;
  position: relative;
}

.animal-card {
  width: 140px;
  min-height: 80px;
  padding: 8px;
  background: white;
  border: 2px solid #cbd5e0;
  text-align: center;
  box-shadow: 0 2px 4px rgba(0,0,0,0.05);
  display: flex;
  flex-direction: column;
  justify-content: center;
  position: relative;
  z-index: 2;
  margin: 0 10px;
  transition: transform 0.2s;
}

.animal-card:hover {
    transform: scale(1.05);
    z-index: 3;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.animal-card.Male { 
    border-color: #3182ce; 
    border-radius: 4px;
}

.animal-card.Female { 
    border-color: #e53e3e; 
    border-radius: 40px; /* Oval shape */
}

.animal-card.wild { 
    border-style: dashed; 
    opacity: 0.6; 
    background: #f1f5f9; 
}

/* Connection Lines in Grid */
.connector-svg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
}

.card-id { font-weight: 800; font-size: 0.9rem; color: #1e293b; }
.card-data { font-size: 0.6rem; color: #475569; line-height: 1.1; }
.card-fx { font-weight: 700; color: #e53e3e; font-size: 0.65rem; margin-top: 2px; }
.card-label { 
  font-size: 0.5rem; 
  text-transform: uppercase; 
  color: #94a3b8; 
  margin-bottom: 2px;
}

.empty-card {
  width: 140px;
  height: 80px;
  margin: 0 10px;
}

@media print {
  /* Hide UI elements that shouldn't be in the report */
  nav, 
  header, 
  .zoom-controls, 
  main > section.card.fade-in, 
  .pedigree-chart-outer > p,
  footer {
    display: none !important;
  }

  body {
    background: white !important;
    padding: 0;
    margin: 0;
  }

  .container {
    width: 100% !important;
    max-width: none !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  /* Show the results even if they have the 'hidden' class (though they shouldn't if printing) */
  #results {
    display: block !important;
  }

  .card {
    background: transparent !important;
    box-shadow: none !important;
    border: none !important;
    padding: 0 !important;
    margin-bottom: 2rem !important;
    break-inside: avoid;
  }

  .registration-card {
    border: 1px solid #edf2f7 !important;
    padding: 1.5rem !important;
    display: block !important;
    margin-top: 1cm;
  }

  .pedigree-chart-outer {
    border: none !important;
    overflow: visible !important;
  }

  .pedigree-chart-container {
    height: auto !important;
    overflow: visible !important;
    background: white !important;
    cursor: default !important;
    border: none !important;
  }

  .pedigree-viewport {
    width: 3200px !important;
    /* zoom is better for print scaling than transform in Chromium */
    zoom: 0.24 !important; 
    transform: none !important; 
    padding: 0 !important;
    margin: 0 !important;
    min-height: auto !important;
    display: flex !important;
    background: white !important;
  }

  .animal-card {
    box-shadow: none !important;
    border-width: 1px !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .results-grid {
    display: block !important;
  }

  .registration-card, .result-meta, .fx-card, .pedigree-full {
    width: 100% !important;
  }
}
