/* ========================================
   PARENT STICKY HEADER COMPONENT
   ======================================== */

/* Parent sticky header - Higher specificity to override Bootstrap */
/* Card pattern: rounded-xl, shadow-sm on canvas background - Design System */
header.parent-sticky-header,
.parent-sticky-header[role="banner"],
#parent-sticky-header.parent-sticky-header {
    position: sticky;
    top: 50px;  /* Account for navbar height (50px) - Design System */
    z-index: 999;  /* Below navbar (99999), above action toolbar (998) - Design System */
    background: var(--white);
    border-radius: var(--border-radius-xl);  /* rounded-xl (12px) - Design System */
    box-shadow: var(--shadow-sm);  /* shadow-sm - Design System */
    border-bottom: 1px solid var(--border-color); /* Brand Guidelines */
    padding: var(--spacing-md) var(--spacing-lg);
    margin-bottom: var(--spacing-lg);  /* 24px spacing between header and toolbar - Design System */
    margin-left: var(--spacing-md);  /* Horizontal spacing - Design System */
    margin-right: var(--spacing-md);  /* Horizontal spacing - Design System */
}

/* Responsive margins - Design System */
@media (min-width: 768px) {
    header.parent-sticky-header,
    .parent-sticky-header[role="banner"],
    #parent-sticky-header.parent-sticky-header {
        margin-left: var(--spacing-lg);  /* 24px on tablet+ - Design System */
        margin-right: var(--spacing-lg);  /* 24px on tablet+ - Design System */
    }
}

@media (min-width: 1024px) {
    header.parent-sticky-header,
    .parent-sticky-header[role="banner"],
    #parent-sticky-header.parent-sticky-header {
        margin-left: var(--spacing-xl);  /* 32px on desktop - Design System */
        margin-right: var(--spacing-xl);  /* 32px on desktop - Design System */
    }
}

.parent-header-container {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-lg);
    max-width: 100%;
}

/* ========================================
   AVATAR STACK SECTION
   ======================================== */

.avatar-stack-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--spacing-sm);
    flex: 1;
    min-width: 0;
}

.avatar-carousel-wrapper {
    position: relative;
    width: 100%;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    padding: 0.5rem 0;
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE and Edge */
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
    scroll-padding: 0.5rem; /* Padding for centered scrolling */
    scroll-snap-type: x proximity; /* Snap to avatars when scrolling - Design System */
}

.avatar-carousel-wrapper::-webkit-scrollbar {
    display: none; /* Chrome, Safari, Opera */
}

.avatar-stack {
    position: relative;
    display: flex !important;
    flex-direction: row !important;
    align-items: center;
    justify-content: flex-start;
    gap: 0; /* Remove gap for stacking effect */
    padding: 0.5rem;
    padding-left: 0.75rem; /* Extra left padding to accommodate scaled active avatar */
    padding-right: 0.75rem; /* Extra right padding for smooth scrolling */
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
    min-width: max-content; /* Ensure content doesn't shrink */
    width: 100%;
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1); /* Smooth container transitions */
}

.avatar-wrapper {
    position: relative;
    display: block !important;
    cursor: pointer;
    transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) !important; /* Smooth, bouncy transition - Design System */
    border-radius: 50%;
    background: var(--white);
    padding: 2px;
    border: 2px solid transparent;
    flex-shrink: 0 !important;
    opacity: 0.7;
    margin-left: -12px; /* Overlap effect - each avatar overlaps the previous one */
    z-index: 1;
    float: none !important;
    clear: none !important;
    will-change: transform, opacity, border-color; /* Optimize for smooth animations */
    scroll-snap-align: center; /* Center snap points on avatars - Design System */
}

/* First avatar should not have negative margin */
.avatar-wrapper:first-child {
    margin-left: 0;
    z-index: 1;
}

/* Each subsequent avatar should have higher z-index to appear on top */
.avatar-wrapper:nth-child(2) { z-index: 2; }
.avatar-wrapper:nth-child(3) { z-index: 3; }
.avatar-wrapper:nth-child(4) { z-index: 4; }
.avatar-wrapper:nth-child(5) { z-index: 5; }
.avatar-wrapper:nth-child(6) { z-index: 6; }
.avatar-wrapper:nth-child(7) { z-index: 7; }
.avatar-wrapper:nth-child(8) { z-index: 8; }

.avatar-wrapper:hover,
.avatar-wrapper:focus {
    transform: translateY(-2px) scale(1.08) !important; /* Slightly more pronounced hover */
    z-index: 10;
    outline: none;
    opacity: 0.95 !important; /* More visible on hover */
    border-color: rgba(30, 41, 59, 0.2) !important; /* Subtle Ink Night border on hover */
}

.avatar-wrapper:focus-visible {
    outline: 3px solid var(--text-main) !important; /* Ink Night focus ring - Brand Guidelines */
    outline-offset: 2px;
    box-shadow: 0 0 0 3px rgba(30, 41, 59, 0.1) !important; /* Ink Night focus ring - Brand Guidelines */
}

.avatar-wrapper.active {
    z-index: 100 !important; /* Active avatar should always be on top */
    transform: translateY(-4px) scale(1.25) !important;
    border: 3px solid var(--brand-accent) !important; /* Golden Honey - Brand Guidelines */
    opacity: 1 !important;
    background: var(--white) !important;
    margin-left: -16px; /* Slightly more overlap when active to maintain stacking */
    box-shadow: 0 4px 12px rgba(234, 179, 8, 0.2) !important; /* Golden Honey glow - Brand Guidelines */
    /* Keep in original position - don't reorder */
}

/* First avatar when active should not have negative margin to prevent cropping */
.avatar-wrapper:first-child.active {
    margin-left: 0;
}

.avatar-wrapper.active .child-avatar {
    box-shadow: 0 6px 20px rgba(234, 179, 8, 0.3) !important; /* Golden Honey shadow - Brand Guidelines */
    transition: box-shadow 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) !important; /* Smooth shadow transition */
}

.avatar-image-container {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    overflow: hidden;
    border: 2px solid var(--white);
    background: var(--bg-neutral); /* Canvas - Brand Guidelines */
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) !important; /* Smooth, bouncy transition - Design System */
    will-change: width, height, border-width; /* Optimize for smooth size transitions */
}

.avatar-wrapper.active .avatar-image-container {
    width: 60px !important;
    height: 60px !important;
    border-width: 3px !important;
    border-color: var(--white) !important;
    background: var(--bg-neutral) !important; /* Canvas - Brand Guidelines */
    transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) !important; /* Smooth size transition */
}

.child-avatar {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    display: block;
    border-radius: 50%;
}

.child-avatar-placeholder {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--primary-gradient);
    color: var(--white);
    font-weight: 600;
    font-size: var(--font-size-base);
    text-transform: uppercase;
}

.avatar-active-indicator {
    position: absolute !important;
    bottom: -2px !important;
    right: -2px !important;
    width: 16px !important;
    height: 16px !important;
    background: var(--success-color) !important; /* Success color - Brand Guidelines */
    border: 2px solid var(--white) !important;
    border-radius: 50% !important;
    box-shadow: 0 2px 4px rgba(30, 41, 59, 0.2) !important; /* Ink Night - No pure black - Brand Guidelines */
    z-index: 200 !important;
    display: block !important;
    visibility: visible !important;
    transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) !important; /* Smooth indicator transition */
    animation: indicator-pulse 2s ease-in-out infinite; /* Subtle pulse animation */
}

@keyframes indicator-pulse {
    0%, 100% {
        transform: scale(1);
        opacity: 1;
    }
    50% {
        transform: scale(1.1);
        opacity: 0.9;
    }
}

/* Photo upload button removed from avatars - now next to name */

.selected-child-name {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0;
    min-width: 0;
    margin: 0;
    padding: 0 var(--spacing-sm);
    margin-bottom: var(--spacing-xs);
}

.child-name-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-sm);
    width: 100%;
    flex-wrap: wrap;
}

.child-name-text {
    font-weight: var(--font-weight-semibold) !important; /* 600 - Brand Guidelines */
    font-family: var(--font-family-headings) !important; /* Poppins - Brand Guidelines */
    font-size: 1.125rem !important; /* var(--font-size-lg) */
    color: var(--text-main) !important; /* Ink Night - Brand Guidelines */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    min-width: 0;
    text-align: center;
}

.child-photo-edit-btn {
    display: inline-flex;
    align-items: center;
    gap: var(--spacing-xs);
    padding: var(--spacing-xs) var(--spacing-sm);
    background: transparent; /* Secondary button pattern - Brand Guidelines */
    color: var(--text-main); /* Ink Night - Brand Guidelines */
    border: 1px solid var(--border-color); /* border-sage/30 - Brand Guidelines */
    border-radius: 8px !important; /* rounded-lg - Wise Owl Design System */
    text-decoration: none;
    font-size: var(--font-size-sm);
    font-family: var(--font-family-base); /* Open Sans - Brand Guidelines */
    font-weight: var(--font-weight-medium); /* 500 */
    transition: all 0.3s ease;
    white-space: nowrap;
    flex-shrink: 0;
}

.child-photo-edit-btn:hover,
.child-photo-edit-btn:focus {
    background: rgba(30, 41, 59, 0.05) !important; /* Very light Ink Night tint - Brand Guidelines */
    border-color: var(--text-main) !important; /* Ink Night - Brand Guidelines */
    color: var(--text-main) !important; /* Ink Night - Brand Guidelines */
    text-decoration: none;
    outline: none;
    box-shadow: 0 0 0 3px rgba(30, 41, 59, 0.1) !important; /* Ink Night focus ring - Brand Guidelines */
}

.child-photo-edit-btn i {
    font-size: 1rem;
}

.child-photo-edit-btn .btn-text {
    display: inline;
}

@media (max-width: 576px) {
    .child-photo-edit-btn .btn-text {
        display: none; /* Hide text on very small screens, show only icon */
    }
}

/* ========================================
   COMPACT BUDGET DISPLAY SECTION
   ======================================== */

.budget-display-compact {
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-sm);
    width: 100%;
    max-width: 100%;
    padding: var(--spacing-xs) var(--spacing-sm);
    background: var(--bg-neutral) !important; /* Canvas - Brand Guidelines */
    border-radius: 8px !important; /* rounded-lg - Wise Owl Design System */
    margin-top: var(--spacing-xs);
}

.budget-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: calc(var(--spacing-xs) / 2);
    font-size: 14px;
    line-height: 1.2;
    flex: 0 1 auto;
    justify-content: center;
    min-width: 0;
    flex-shrink: 1;
}

.budget-item-link {
    text-decoration: none;
    color: inherit;
    cursor: pointer;
    transition: all 0.3s ease;
    border-radius: 8px; /* rounded-lg - Wise Owl Design System */
    padding: var(--spacing-xs);
    margin: calc(var(--spacing-xs) * -1);
}

.budget-item-link:hover,
.budget-item-link:focus {
    background: rgba(30, 41, 59, 0.05) !important; /* Very light Ink Night tint - Brand Guidelines */
    text-decoration: none;
    color: inherit;
    outline: 2px solid var(--text-main) !important; /* Ink Night - Brand Guidelines */
    outline-offset: 2px;
    box-shadow: 0 0 0 3px rgba(30, 41, 59, 0.1) !important; /* Ink Night focus ring - Brand Guidelines */
}

.budget-item-link:active {
    background: var(--gray-200);
}

.budget-item-header {
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
    white-space: nowrap;
}

.budget-item i {
    font-size: 14px;
    color: var(--gray-600);
    opacity: 0.8;
}

.budget-display-compact .budget-label {
    font-size: 14px;
    font-weight: 500;
    color: var(--gray-600);
    margin-right: 2px;
}

.budget-display-compact .budget-amount {
    font-weight: 700;
    font-size: 14px !important;
    line-height: 1.2;
}

.budget-display-compact .budget-amount.positive {
    color: var(--success-color);
}

.budget-display-compact .budget-amount.negative {
    color: var(--danger-color);
}

.budget-display-compact .meal-price-amount {
    font-weight: 700 !important;
    font-size: 14px !important;
    color: var(--text-main) !important; /* Ink Night - No pure black - Brand Guidelines */
    line-height: 1.2;
}

/* ========================================
   RESPONSIVE DESIGN
   ======================================== */

@media (max-width: 768px) {
    .parent-sticky-header {
        padding: var(--spacing-sm) var(--spacing-md);
    }
    
    .parent-header-container {
        flex-direction: column;
        align-items: stretch;
        gap: var(--spacing-sm);
    }
    
    .avatar-stack-container {
        flex-direction: column;
        align-items: center;
        gap: var(--spacing-sm);
    }
    
    .avatar-stack {
        justify-content: flex-start;
        gap: 0;
        padding: var(--spacing-sm);
    }
    
    .avatar-wrapper {
        margin-left: -10px; /* Smaller overlap on mobile */
    }
    
    .avatar-wrapper:first-child {
        margin-left: 0;
    }
    
    .avatar-wrapper.active {
        margin-left: -14px; /* Adjusted for mobile */
    }
    
    /* First avatar when active should not have negative margin to prevent cropping */
    .avatar-wrapper:first-child.active {
        margin-left: 0;
    }
    
    .avatar-image-container {
        width: 40px;
        height: 40px;
    }
    
    .avatar-wrapper.active .avatar-image-container {
        width: 60px;
        height: 60px;
    }
    
    .child-avatar,
    .child-avatar-placeholder {
        font-size: var(--font-size-sm);
    }
    
    .avatar-wrapper.active {
        transform: translateY(-2px) scale(1.15);
    }
    
    .selected-child-name {
        margin: 0;
        padding: 0;
        text-align: center;
    }
    
    .child-name-text {
        font-size: var(--font-size-base);
        max-width: calc(100% - 100px); /* Adjust for smaller button on mobile */
    }
    
    .child-photo-edit-btn {
        padding: var(--spacing-xs);
        font-size: var(--font-size-xs);
    }
    
    .budget-display-compact {
        flex-direction: row !important;
        flex-wrap: nowrap !important;
        gap: var(--spacing-sm);
        padding: var(--spacing-xs) var(--spacing-sm);
        width: 100%;
        max-width: 100%;
        justify-content: center;
        align-items: center;
    }
    
    .budget-item {
        display: flex !important;
        flex-direction: column !important;
        gap: calc(var(--spacing-xs) / 2);
        font-size: 12px;
        flex: 0 1 auto;
        justify-content: center;
        align-items: center;
        min-width: 0;
        flex-shrink: 1;
    }
    
    .budget-item-header {
        display: flex;
        align-items: center;
        gap: calc(var(--spacing-xs) / 2);
    }
    
    .budget-item i {
        font-size: 12px;
    }
    
    .budget-display-compact .budget-label {
        font-size: 12px;
        margin-right: 2px;
    }
    
    .budget-display-compact .budget-amount,
    .budget-display-compact .meal-price-amount {
        font-size: 12px !important;
    }
}

@media (max-width: 576px) {
    .avatar-stack {
        gap: 0;
        padding: var(--spacing-sm);
    }
    
    .avatar-wrapper {
        margin-left: -8px; /* Even smaller overlap on small mobile */
    }
    
    .avatar-wrapper:first-child {
        margin-left: 0;
    }
    
    .avatar-wrapper.active {
        margin-left: -12px;
    }
    
    /* First avatar when active should not have negative margin to prevent cropping */
    .avatar-wrapper:first-child.active {
        margin-left: 0;
    }
    
    .avatar-image-container {
        width: 40px;
        height: 40px;
    }
    
    .avatar-wrapper.active .avatar-image-container {
        width: 60px;
        height: 60px;
    }
    
    .child-name-text {
        font-size: var(--font-size-sm);
        max-width: calc(100% - 80px); /* Adjust for icon-only button on small screens */
    }
    
    .selected-child-name {
        margin: 0;
        padding: 0;
        gap: calc(var(--spacing-xs) / 2);
    }
    
    .child-photo-edit-btn {
        padding: calc(var(--spacing-xs) / 2);
        min-width: 32px;
        justify-content: center;
    }
    
    .budget-display-compact {
        flex-direction: row !important;
        flex-wrap: nowrap !important;
        gap: var(--spacing-xs);
        padding: 4px var(--spacing-sm);
        width: 100%;
        max-width: 100%;
        justify-content: center;
        align-items: center;
        margin-top: var(--spacing-xs);
    }
    
    .budget-item {
        display: flex !important;
        flex-direction: column !important;
        font-size: 12px;
        gap: calc(var(--spacing-xs) / 2);
        flex: 0 1 auto;
        justify-content: center;
        align-items: center;
        min-width: 0;
        flex-shrink: 1;
    }
    
    .budget-item-header {
        display: flex;
        align-items: center;
        gap: calc(var(--spacing-xs) / 2);
    }
    
    .budget-item i {
        font-size: 12px;
    }
    
    .budget-display-compact .budget-label {
        font-size: 12px;
        margin-right: 2px;
    }
    
    .budget-display-compact .budget-amount,
    .budget-display-compact .meal-price-amount {
        font-size: 12px !important;
    }
}

/* ========================================
   ACCESSIBILITY
   ======================================== */

/* Focus styles are defined in the hover section above for better organization */

/* ========================================
   ANIMATIONS
   ======================================== */

@keyframes avatar-pulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.02); /* Subtle pulse - more refined */
    }
}

.avatar-wrapper.active .child-avatar {
    animation: avatar-pulse 3s ease-in-out infinite; /* Slower, more subtle pulse */
}

/* Scroll snap rules are defined in the main selectors above */

