:root {
  /* 
      Material Design 3 Token System 
      Light Mode (Default)
    */
  --md-ref-palette-primary-40: #4F46E5;
  /* Indigo 600 */
  --md-ref-palette-primary-50: #6366F1;
  /* Indigo 500 */
  --md-ref-palette-primary-90: #E0E7FF;
  /* Indigo 100 */
  --md-ref-palette-primary-95: #EEF2FF;
  /* Indigo 50 */

  --md-ref-palette-secondary-40: #0F766E;
  /* Teal 700 */
  --md-ref-palette-secondary-90: #CCFBF1;
  /* Teal 100 */

  --md-ref-palette-neutral-10: #1C1B1F;
  --md-ref-palette-neutral-90: #E2E2E6;
  --md-ref-palette-neutral-95: #F2F0F4;
  --md-ref-palette-neutral-99: #FFFBFE;

  --md-ref-palette-neutral-variant-50: #74777F;
  --md-ref-palette-neutral-variant-90: #E7E0EC;

  --md-ref-palette-error-40: #B3261E;

  /* Semantic Roles - Light */
  --md-sys-color-primary: var(--md-ref-palette-primary-40);
  --md-sys-color-on-primary: #FFFFFF;
  --md-sys-color-primary-container: var(--md-ref-palette-primary-90);
  --md-sys-color-on-primary-container: #10104b;

  --md-sys-color-secondary: var(--md-ref-palette-secondary-40);
  --md-sys-color-on-secondary: #FFFFFF;

  --md-sys-color-background: #F8FAFC;
  /* Slate 50 */
  --md-sys-color-on-background: #1C1B1F;

  --md-sys-color-surface: #FFFFFF;
  --md-sys-color-on-surface: #1C1B1F;

  --md-sys-color-surface-variant: #F1F5F9;
  /* Slate 100 */
  --md-sys-color-on-surface-variant: #475569;
  /* Slate 600 */

  --md-sys-color-outline: #CBD5E1;
  /* Slate 300 */
  --md-sys-color-outline-variant: #E2E8F0;
  /* Slate 200 */

  --md-sys-color-error: var(--md-ref-palette-error-40);

  --md-sys-radius-medium: 12px;
  --md-sys-radius-large: 16px;

  --md-sys-shadow-1: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px -1px rgba(0, 0, 0, 0.1);
  --md-sys-shadow-2: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
  --md-sys-shadow-3: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);

  --tree-connector: #94A3B8;
  /* Slate 400 */
}

/* Dark Mode Overrides */
[data-theme="dark"] {
  /* Cash Center Dark Palette */
  --md-sys-color-primary: #6366F1;
  /* Indigo 500 */
  --md-sys-color-on-primary: #FFFFFF;
  --md-sys-color-primary-container: #312E81;
  /* Indigo 900 */
  --md-sys-color-on-primary-container: #E0E7FF;

  --md-sys-color-secondary: #14B8A6;
  /* Teal 500 */

  --md-sys-color-background: #111827;
  /* Gray 900 */
  --md-sys-color-on-background: #F3F4F6;
  /* Gray 100 */

  --md-sys-color-surface: #1F2937;
  /* Gray 800 */
  --md-sys-color-on-surface: #F3F4F6;

  --md-sys-color-surface-variant: #374151;
  /* Gray 700 - Input Bg */
  --md-sys-color-on-surface-variant: #9CA3AF;
  /* Gray 400 */

  --md-sys-color-outline: #374151;
  /* Gray 700 */
  --md-sys-color-outline-variant: #4B5563;
  /* Gray 600 */

  --tree-connector: #4B5563;
  /* Gray 600 */

  --md-sys-shadow-1: 0 1px 3px 0 rgba(0, 0, 0, 0.5);
  --md-sys-shadow-2: 0 4px 6px -1px rgba(0, 0, 0, 0.5);
  --md-sys-shadow-3: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
}

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

body {
  font-family: 'Outfit', sans-serif;
  background-color: var(--md-sys-color-background);
  color: var(--md-sys-color-on-background);
  line-height: 1.5;
  transition: background-color 0.3s ease, color 0.3s ease;
}

/* Seamless Navbar Overlay */
.navbar-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 80px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 2rem;
  z-index: 100;
  pointer-events: none;
  /* Passes clicks to canvas below */
  background: transparent;
}

.nav-left,
.nav-right,
.nav-center {
  pointer-events: auto;
  /* Re-enable clicks for buttons */
  display: flex;
  align-items: center;
  gap: 1rem;
}

.nav-center {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
}

.app-title a {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--md-sys-color-primary);
  text-decoration: none;
  text-shadow: 0 0 20px var(--md-sys-color-surface);
  /* Legibility glow */
}

/* Full Screen Main */
.main-content {
  max-width: none;
  padding: 0;
  margin: 0;
  height: 100vh;
  /* Full viewport */
  overflow: hidden;
}

/* Auth Page overrides */
.auth-main {
  padding: 2rem;
  height: 100vh;
  overflow: auto;
  padding-top: 100px;
  /* Space for navbar */
}

.nav-links,
.nav-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.nav-links a {
  color: var(--md-sys-color-on-surface-variant);
  text-decoration: none;
  font-weight: 500;
  transition: color 0.2s;
}

.nav-links a:hover {
  color: var(--md-sys-color-primary);
}

/* Buttons */
.btn {
  padding: 0.6rem 1.25rem;
  border-radius: 9999px;
  /* Pill shape */
  border: none;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  text-decoration: none;
  /* No underline */
}

.btn-primary {
  background-color: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
}

.btn-primary:hover {
  filter: brightness(110%);
  box-shadow: var(--md-sys-shadow-2);
}

.btn-text {
  background: transparent;
  color: var(--md-sys-color-on-surface);
}

.btn-text:hover {
  background-color: var(--md-sys-color-surface-variant);
}

.btn-logout {
  background-color: #EF5350;
  /* Muted Red (Material Red 400) */
  color: white;
  padding: 0.6rem 1.25rem;
  border-radius: 9999px;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  text-decoration: none;
  font-size: 0.9rem;
  /* Explicit match with .btn */
}

.btn-logout:hover {
  filter: brightness(110%);
  box-shadow: var(--md-sys-shadow-2);
  /* Ensure text color stays white */
  color: white;
  transform: scale(1.05);
  background-color: #EF5350;
  /* Keep base muted red */
  /* Keep background red but brighter via filter */
}

/* Dark mode logout overrides - keep consistent filled style */
[data-theme="dark"] .btn-logout:hover {
  background-color: var(--md-sys-color-error);
  color: white;
}

.btn-icon {
  padding: 0.5rem;
  border-radius: 50%;
  border: 1px solid var(--md-sys-color-outline);
  background: var(--md-sys-color-surface);
  color: var(--md-sys-color-on-surface-variant);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.btn-icon:hover {
  background: var(--md-sys-color-surface-variant);
  color: var(--md-sys-color-primary);
  border-color: var(--md-sys-color-primary);
}

/* Edit Icons */
.btn-icon.edit,
.btn-icon.delete {
  background: var(--md-sys-color-surface);
  color: var(--md-sys-color-on-surface-variant);
  border: 1px solid var(--md-sys-color-outline);
  width: 32px;
  height: 32px;
}

.btn-icon.edit:hover {
  background: var(--md-sys-color-primary);
  color: white;
  border-color: var(--md-sys-color-primary);
}

.btn-icon.delete:hover {
  background: #EF5350;
  /* Muted Red */
  color: white;
  border-color: #EF5350;
}

/* Auth Pages (Login) */
.auth-wrapper {
  min-height: 85vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  /* Dotted pattern for modern feel */
  background-image: radial-gradient(var(--md-sys-color-outline) 1px, transparent 1px);
  background-size: 24px 24px;
}

.auth-card {
  background: var(--md-sys-color-surface);
  padding: 3rem;
  border-radius: var(--md-sys-radius-large);
  box-shadow: var(--md-sys-shadow-2);
  width: 100%;
  max-width: 440px;
  border: 1px solid var(--md-sys-color-outline);
  overflow: hidden;
  position: relative;
  border-top: 4px solid var(--md-sys-color-primary);
}

.auth-card h1 {
  font-size: 1.75rem;
  color: var(--md-sys-color-on-surface);
  margin-bottom: 0.5rem;
  text-align: center;
  font-weight: 700;
}

.auth-subtitle {
  text-align: center;
  color: var(--md-sys-color-on-surface-variant);
  margin-bottom: 2.5rem;
  font-size: 0.95rem;
}

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

.form-group.mb-large {
  margin-bottom: 2.5rem;
}

.form-group label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 500;
  color: var(--md-sys-color-on-surface);
  font-size: 0.9rem;
}

.form-group input,
.form-group select {
  width: 100%;
  padding: 0.5rem 0.75rem;
  /* More compact */
  border: 1px solid var(--md-sys-color-outline);
  background-color: var(--md-sys-color-surface-variant);
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.95rem;
  /* Slightly smaller font */
  color: var(--md-sys-color-on-surface);
  transition: all 0.2s;
}

.form-group select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
  background-position: right 0.5rem center;
  background-repeat: no-repeat;
  background-size: 1.5em 1.5em;
  padding-right: 2.5rem;
}

.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--md-sys-color-primary);
  box-shadow: 0 0 0 2px var(--md-sys-color-primary-container);
  background-color: var(--md-sys-color-surface);
}

.form-row {
  display: flex;
  gap: 1rem;
}

.form-row .form-group {
  flex: 1;
  /* Equal width */
  margin-bottom: 0;
  /* Remove bottom margin inside row if handled by row gap or parent */
}

.form-row {
  margin-bottom: 1.5rem;
  /* Space between rows */
}

/* Modal specific button spacing */
.modal-body button[type="submit"] {
  margin-top: 1rem;
}


.btn-block {
  width: 100%;
  padding: 0.85rem;
  font-size: 1rem;
}

/* Tree & Main Content */
.container.main-content {
  /* Override generic container padding for full width */
  max-width: none;
  margin: 0;
  padding: 0;
}

.tree-container {
  width: 100%;
  height: 100%;
  /* Fill main content */
  border: none;
  border-radius: 0;
  background-image: radial-gradient(var(--md-sys-color-outline) 1px, transparent 1px);
  background-size: 30px 30px;
  cursor: grab;
  overflow: hidden;
  /* We manage transform manually */
  position: relative;
  touch-action: none;
  /* Better panny */
}

.tree-container:active {
  cursor: grabbing;
}

/* The Zoomable Canvas Layer */
.tree-canvas {
  transform-origin: center center;
  /* Zoom from center or top left? Center often better for infinite canvas */
  transition: transform 0.1s ease-out;
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  padding-top: 5rem;
}

.tree-controls {
  position: absolute;
  bottom: 2rem;
  right: 2rem;
  z-index: 50;
  display: flex;
  gap: 1rem;
}

.zoom-controls {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  background: var(--md-sys-color-surface);
  padding: 0.5rem;
  border-radius: var(--md-sys-radius-medium);
  box-shadow: var(--md-sys-shadow-2);
  border: 1px solid var(--md-sys-color-outline);
  transition: box-shadow 0.2s ease, transform 0.2s ease;
}

.zoom-controls:hover {
  box-shadow: var(--md-sys-shadow-3);
}

.zoom-controls button {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  /* Slightly squarer than pill */
  border: none;
  background: transparent;
  color: var(--md-sys-color-on-surface);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
}

.zoom-controls button:hover {
  background-color: var(--md-sys-color-surface-variant);
  color: var(--md-sys-color-primary);
  transform: scale(1.1);
}

.zoom-controls button:active {
  transform: scale(0.95);
  background-color: var(--md-sys-color-outline);
}

/* Tree Structure */
.tree {
  display: inline-block;
  padding: 4rem;
  transform-origin: center top;
}

.tree-list {
  display: flex;
  padding-top: 20px;
  position: relative;
  justify-content: center;
}

.tree-list ul {
  display: flex;
  padding-top: 20px;
  position: relative;
}

.tree-list li {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px 10px 0 10px;
  position: relative;
}

/* Connectors */
.tree-list li::before,
.tree-list li::after {
  content: '';
  position: absolute;
  top: 0;
  right: 50%;
  border-top: 2px solid var(--tree-connector);
  width: 50%;
  height: 20px;
}

.tree-list li::after {
  right: auto;
  left: 50%;
  border-left: 2px solid var(--tree-connector);
}

.tree-list li:only-child::after,
.tree-list li:only-child::before {
  display: none;
}

.tree-list li:only-child {
  padding-top: 0;
}

.tree-list li:first-child::before,
.tree-list li:last-child::after {
  border: 0 none;
}

.tree-list li:last-child::before {
  border-right: 2px solid var(--tree-connector);
  border-radius: 0 8px 0 0;
}

.tree-list li:first-child::after {
  border-radius: 8px 0 0 0;
}

.tree-list ul::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  border-left: 2px solid var(--tree-connector);
  width: 0;
  height: 20px;
}

/* Spouse Tooltip */
/* Spouse Tooltip */
.spouse-tooltip {
  position: absolute;
  top: -35px;
  /* Appear ABOVE the card */
  left: 50%;
  transform: translateX(-50%);
  background-color: var(--secondary);
  color: white;
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 0.85rem;
  white-space: nowrap;
  opacity: 0;
  visibility: hidden;
  transition: all 0.2s ease;
  z-index: 10;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  pointer-events: none;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.spouse-tooltip span {
  opacity: 0.7;
  font-size: 0.75em;
  margin-right: 4px;
}

.member-card:hover .spouse-tooltip {
  opacity: 1;
  visibility: visible;
  top: -50px;
  /* Slight slight up animation */
}


/* Couple Container */
.couple-container {
  display: flex;
  gap: 20px;
  align-items: center;
  position: relative;
  /* Add connector between spouses */
}

/* If there is more than one card (i.e. spouses), connect them */
.couple-container>.member-card:not(:last-child)::after {
  content: '';
  position: absolute;
  top: 50%;
  /* Center vertically relative to CARD */
  right: -20px;
  /* Use the gap width */
  width: 20px;
  height: 2px;
  background-color: var(--tree-connector);
  z-index: 0;
}

/* Adjust connector so it doesn't overlap on top of cards if they have different heights?
 Actually, flex aligns center so top 50% is safe. 
 But we need to make sure the :after is technically attached to the card.
*/

/* Gender Card Styling */
.member-card.m {
  border-top: 4px solid #60A5FA;
  /* Blue 400 */
  background: linear-gradient(to bottom, var(--md-sys-color-surface), #F0F9FF);
}

.member-card.f {
  border-top: 4px solid #F472B6;
  /* Pink 400 */
  background: linear-gradient(to bottom, var(--md-sys-color-surface), #FDF2F8);
}

/* Dark mode overrides for cards */
[data-theme="dark"] .member-card.m {
  border-top-color: #3B82F6;
  /* Blue 500 */
  background: linear-gradient(to bottom, var(--md-sys-color-surface), #172554);
}

[data-theme="dark"] .member-card.f {

  border-top-color: #EC4899;
  /* Pink 500 */
  background: linear-gradient(to bottom, var(--md-sys-color-surface), #831843);
}

/* Member Card */
.member-card {
  background: var(--md-sys-color-surface);
  border: 1px solid var(--md-sys-color-outline);
  border-radius: var(--md-sys-radius-medium);
  padding: 1rem;
  min-width: 180px;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  z-index: 10;
  box-shadow: var(--md-sys-shadow-1);
  transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
}

.member-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--md-sys-shadow-3);
  border-color: var(--md-sys-color-primary);
  z-index: 20;
}

/* Gender Avatar Rings */
.member-photo {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  object-fit: cover;
  margin-bottom: 0.75rem;
  border: 2px solid var(--md-sys-color-outline);
  padding: 2px;
  /* Ring effect */
}

/* Specific Gender Colors could be thematic, but let's stick to system or subtle vars */
.member-card.m .member-photo {
  border-color: #60A5FA;
}

/* Blue */
.member-card.f .member-photo {
  border-color: #F472B6;
}

/* Pink */

.member-photo-placeholder {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.5rem;
  margin-bottom: 0.75rem;
}

.member-info {
  text-align: center;
}

.member-name {
  font-size: 1rem;
  font-weight: 600;
  color: var(--md-sys-color-on-surface);
  margin-bottom: 0.1rem;
}

.member-dates {
  font-size: 0.8rem;
  color: var(--md-sys-color-on-surface-variant);
}

/* Hover Actions */
.member-actions {
  background: var(--md-sys-color-surface);
  padding: 4px;
  border-radius: 20px;
  box-shadow: var(--md-sys-shadow-1);
  border: 1px solid var(--md-sys-color-outline);
  display: flex;
  gap: 0.5rem;
  top: -20px;
  right: -10px;
  opacity: 1;
  /* Always visible */
  transition: opacity 0.2s;
  pointer-events: auto;
  /* Always clickable */
}

/* Hover effect for visual lift only, no visibility toggle */
.member-card:hover .member-actions {
  /* opacity already 1 */
}

.btn-action-mini {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid var(--md-sys-color-outline);
  background: var(--md-sys-color-surface);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--md-sys-color-on-surface-variant);
  font-size: 0.8rem;
  box-shadow: var(--md-sys-shadow-1);
}

.btn-action-mini:hover {
  background: var(--md-sys-color-primary);
  color: white;
  border-color: var(--md-sys-color-primary);
}

.btn-add-child {
  position: absolute;
  bottom: -16px;
  left: 50%;
  transform: translateX(-50%) scale(1);
  /* Always visible */
  background: var(--md-sys-color-secondary);
  color: white;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  cursor: pointer;
  transition: transform 0.2s;
  box-shadow: var(--md-sys-shadow-2);
}

.member-card:hover .btn-add-child {
  transform: translateX(-50%) scale(1.1);
  /* Slight pulse on hover */
}

/* Navbar Add Button */
#nav-add-member {
  gap: 0.5rem;
  font-size: 0.85rem;
  padding: 0.5rem 1rem;
}

/* Modal */
/* Modal */
.modal {
  display: flex;
  /* Changed to flex to align items center */
  position: fixed;
  z-index: 1000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  /* Overlay */
  backdrop-filter: blur(4px);
  align-items: center;
  justify-content: center;

  /* Transition state */
  opacity: 1;
  visibility: visible;
  transition: opacity 0.2s, visibility 0.2s;
}

.modal.hidden {
  display: none !important;
  opacity: 0;
  visibility: hidden;
}

.modal-content {
  background-color: var(--md-sys-color-surface);
  padding: 2rem;
  border-radius: var(--md-sys-radius-large);
  width: 90%;
  max-width: 500px;
  box-shadow: var(--md-sys-shadow-3);
  border: 1px solid var(--md-sys-color-outline);
  max-height: 90vh;
  overflow-y: auto;
}

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

.modal-header h2 {
  color: var(--md-sys-color-on-surface);
}

.close-modal-btn {
  background: transparent;
  border: none;
  padding: 0;
  cursor: pointer;
  color: var(--md-sys-color-on-surface-variant);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s;
}

.close-modal-btn:hover {
  color: var(--md-sys-color-error);
}


.modal-content.modal-sm {
  max-width: 400px;
  text-align: center;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 1rem;
  margin-top: 1.5rem;
}

/* Animations */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
  .navbar-overlay {
    height: auto;
    /* Allow growth */
    padding: 0.5rem 1rem;
    /* Keep layout aligned */
    align-items: flex-start;
    /* Align TOP */
  }

  .nav-center {
    position: absolute;
    top: 60px;
    /* Move title BELOW the buttons row */
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    text-align: center;
    justify-content: center;
    /* Fix for flex centering */
    padding-bottom: 1rem;
    pointer-events: none;
  }

  .app-title a {
    font-size: 1.25rem;
  }

  /* Revert icon-only hiding */
  .nav-label {
    display: inline !important;
  }

  .icon-only-mobile {
    display: none !important;
  }

  /* Standard pill buttons again */
  .btn {
    padding: 0.6rem 1.25rem;
    border-radius: 9999px;
    width: auto;
    height: auto;
  }

  /* Stack fixes */
  .nav-left,
  .nav-right {
    z-index: 101;
    /* Ensure buttons stay clickable above title layer if needed */
  }

  .modal-content {
    width: 95%;
    padding: 1.5rem;
  }




}