/* =============================================================================
   GLOBAL LAYOUT
   ============================================================================= */
html {
    overflow-x: hidden;
    max-width: 100vw;
    width: 100%;
}

body {
    overflow-x: hidden;
    max-width: 100vw;
    width: 100%;
    position: relative;
}

/* =============================================================================
   SAGA ADVANCED LOADING OVERLAY SYSTEM
   A comprehensive, mobile-optimized loading experience
   ============================================================================= */

/* Main Overlay Container */
.saga-loading-overlay {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.98) 0%, rgba(244, 246, 248, 0.98) 100%) !important;
    z-index: 999999 !important;
    display: flex !important;
    justify-content: center !important;
    align-items: center !important;
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    -webkit-overflow-scrolling: touch;
    opacity: 0 !important;
    visibility: hidden !important;
    transition: opacity 0.3s ease, visibility 0.3s ease !important;
    pointer-events: none !important;
}

.saga-loading-overlay.active {
    opacity: 1 !important;
    visibility: visible !important;
    pointer-events: auto !important;
}

/* Main Content Container */
.saga-loading-container {
    text-align: center;
    padding: 30px 25px;
    max-width: 400px;
    width: 90%;
    background: white;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(129, 196, 8, 0.15), 0 8px 25px rgba(0, 0, 0, 0.08);
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
    animation: sagaContainerPulse 2s ease-in-out infinite;
}

@keyframes sagaContainerPulse {
    0%, 100% { box-shadow: 0 20px 60px rgba(129, 196, 8, 0.15), 0 8px 25px rgba(0, 0, 0, 0.08); }
    50% { box-shadow: 0 25px 70px rgba(129, 196, 8, 0.2), 0 10px 30px rgba(0, 0, 0, 0.1); }
}

/* Brand Section */
.saga-loading-brand {
    margin-bottom: 20px;
}

.saga-loading-logo {
    width: 80px;
    height: 80px;
    object-fit: contain;
    animation: sagaLogoFloat 3s ease-in-out infinite;
}

@keyframes sagaLogoFloat {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-5px); }
}

/* Spinner Wrapper */
.saga-spinner-wrapper {
    position: relative;
    height: 120px;
    margin: 20px 0;
}

/* Main Spinner */
.saga-spinner {
    position: relative;
    width: 80px;
    height: 80px;
    margin: 0 auto;
}

.saga-spinner-ring {
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    border: 3px solid transparent;
    animation: sagaSpinnerRotate 1.5s linear infinite;
}

.saga-spinner-ring:nth-child(1) {
    border-top-color: #81C408;
    animation-duration: 1.2s;
}

.saga-spinner-ring:nth-child(2) {
    width: 70%;
    height: 70%;
    top: 15%;
    left: 15%;
    border-right-color: #FFB524;
    animation-duration: 1.5s;
    animation-direction: reverse;
}

.saga-spinner-ring:nth-child(3) {
    width: 40%;
    height: 40%;
    top: 30%;
    left: 30%;
    border-bottom-color: #81C408;
    animation-duration: 1s;
}

.saga-spinner-dot {
    position: absolute;
    width: 12px;
    height: 12px;
    background: linear-gradient(135deg, #81C408, #FFB524);
    border-radius: 50%;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    animation: sagaDotPulse 1s ease-in-out infinite;
}

@keyframes sagaSpinnerRotate {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

@keyframes sagaDotPulse {
    0%, 100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
    50% { transform: translate(-50%, -50%) scale(1.3); opacity: 0.7; }
}

/* Floating Icons Animation */
.saga-floating-icons {
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    pointer-events: none;
}

.saga-float-icon {
    position: absolute;
    font-size: 18px;
    color: #81C408;
    opacity: 0;
    animation: sagaIconFloat 4s ease-in-out infinite;
}

.saga-float-icon.icon-1 { top: 10%; left: 10%; animation-delay: 0s; color: #81C408; }
.saga-float-icon.icon-2 { top: 10%; right: 10%; animation-delay: 0.6s; color: #FFB524; }
.saga-float-icon.icon-3 { top: 50%; left: 5%; animation-delay: 1.2s; color: #81C408; }
.saga-float-icon.icon-4 { top: 50%; right: 5%; animation-delay: 1.8s; color: #FFB524; }
.saga-float-icon.icon-5 { bottom: 10%; left: 15%; animation-delay: 2.4s; color: #81C408; }
.saga-float-icon.icon-6 { bottom: 10%; right: 15%; animation-delay: 3s; color: #FFB524; }

@keyframes sagaIconFloat {
    0%, 100% { opacity: 0; transform: translateY(10px) scale(0.8); }
    25%, 75% { opacity: 0.7; transform: translateY(-5px) scale(1); }
    50% { opacity: 1; transform: translateY(-10px) scale(1.1); }
}

/* Action Display Section */
.saga-action-display {
    margin: 15px 0;
    min-height: 50px;
}

.saga-action-label {
    font-size: 14px;
    color: #6c757d;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 5px;
}

.saga-current-item {
    font-size: 16px;
    font-weight: 600;
    color: #45595b;
    min-height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.saga-current-item .item-icon {
    color: #81C408;
}

.saga-current-item .item-name {
    max-width: 250px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Progress Section */
.saga-progress-section {
    margin: 20px 0 15px;
}

.saga-progress-bar-container {
    width: 100%;
    height: 8px;
    background: #f0f0f0;
    border-radius: 10px;
    overflow: hidden;
    position: relative;
}

.saga-progress-bar {
    height: 100%;
    background: linear-gradient(90deg, #81C408, #9ad039, #81C408);
    background-size: 200% 100%;
    border-radius: 10px;
    width: 0%;
    transition: width 0.3s ease-out;
    position: relative;
    animation: sagaProgressShimmer 2s linear infinite;
}

@keyframes sagaProgressShimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.saga-progress-glow {
    position: absolute;
    top: 0;
    right: 0;
    width: 20px;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.6), transparent);
    animation: sagaProgressGlow 1.5s ease-in-out infinite;
}

@keyframes sagaProgressGlow {
    0%, 100% { opacity: 0; transform: translateX(-10px); }
    50% { opacity: 1; transform: translateX(5px); }
}

.saga-progress-text {
    margin-top: 8px;
    font-size: 13px;
    font-weight: 600;
    color: #81C408;
}

/* Facts Section */
.saga-facts-section {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid #f0f0f0;
}

.saga-fact-card {
    background: linear-gradient(135deg, #f8fdf5 0%, #fffdf5 100%);
    border-radius: 12px;
    padding: 15px;
    min-height: 80px;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: all 0.5s ease;
}

.saga-fact-icon {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, #81C408, #9ad039);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.saga-fact-icon i {
    color: white;
    font-size: 18px;
}

.saga-fact-text {
    font-size: 14px;
    color: #45595b;
    line-height: 1.5;
    margin: 0;
    text-align: left;
    flex: 1;
}

/* Facts Category Indicator */
.saga-fact-category {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-top: 12px;
}

.saga-category-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #e0e0e0;
    transition: all 0.3s ease;
    cursor: pointer;
}

.saga-category-dot.active {
    background: #81C408;
    transform: scale(1.3);
}

.saga-category-dot[data-category="saga"].active { background: #81C408; }
.saga-category-dot[data-category="shopping"].active { background: #FFB524; }
.saga-category-dot[data-category="nutrition"].active { background: #20c997; }
.saga-category-dot[data-category="tips"].active { background: #6f42c1; }

/* Loading Footer */
.saga-loading-footer {
    margin-top: 20px;
    font-size: 12px;
    color: #adb5bd;
    letter-spacing: 2px;
    text-transform: uppercase;
}

/* Prevent scrolling when loading */
body.saga-loading-active {
    overflow: hidden !important;
    position: fixed !important;
    width: 100% !important;
    height: 100% !important;
}

/* ========================================
   RESPONSIVE STYLES
   ======================================== */

@media (max-width: 576px) {
    .saga-loading-container {
        padding: 25px 20px;
        width: 92%;
        max-width: 350px;
        border-radius: 16px;
    }
    
    .saga-loading-logo {
        width: 60px;
        height: 60px;
    }
    
    .saga-spinner-wrapper {
        height: 100px;
        margin: 15px 0;
    }
    
    .saga-spinner {
        width: 60px;
        height: 60px;
    }
    
    .saga-float-icon {
        font-size: 14px;
    }
    
    .saga-action-label {
        font-size: 12px;
    }
    
    .saga-current-item {
        font-size: 14px;
    }
    
    .saga-fact-card {
        padding: 12px;
        min-height: 70px;
    }
    
    .saga-fact-icon {
        width: 35px;
        height: 35px;
    }
    
    .saga-fact-icon i {
        font-size: 16px;
    }
    
    .saga-fact-text {
        font-size: 13px;
    }
}

/* iOS-specific fixes */
@supports (-webkit-touch-callout: none) {
    .saga-loading-overlay {
        position: fixed !important;
        height: -webkit-fill-available !important;
    }
    
    .saga-loading-container {
        -webkit-transform: translate3d(0, 0, 0);
        transform: translate3d(0, 0, 0);
    }
    
    .saga-progress-bar {
        -webkit-transform: translate3d(0, 0, 0);
        transform: translate3d(0, 0, 0);
    }
    
    .saga-spinner-ring {
        -webkit-transform: translate3d(0, 0, 0);
        transform: translate3d(0, 0, 0);
    }
}

/* ========================================
   LEGACY STYLES (for backwards compatibility)
   ======================================== */

/* ============================================
   SAGA NOTIFICATION MESSAGES
   ============================================ */
.message-container {
    max-width: 560px;
    margin: 0 auto;
    z-index: 1055;
    position: relative;
}

.saga-message {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.85rem 1rem;
    border-radius: 10px;
    margin-bottom: 0.5rem;
    box-shadow: 0 4px 16px rgba(0,0,0,0.12);
    opacity: 1;
    transform: translateY(0);
    transition: opacity 0.3s ease, transform 0.3s ease;
    font-size: 0.95rem;
}

/* Success — SAGA green */
.saga-message.saga-msg-success {
    background: linear-gradient(135deg, #e8f8d0 0%, #d4f0a8 100%);
    border-left: 4px solid #81C408;
    color: #3a5c00;
}
.saga-message.saga-msg-success .saga-msg-icon { color: #81C408; }

/* Error / danger — red */
.saga-message.saga-msg-error,
.saga-message.saga-msg-danger {
    background: linear-gradient(135deg, #fde8e8 0%, #fcd0d0 100%);
    border-left: 4px solid #dc3545;
    color: #721c24;
}
.saga-message.saga-msg-error .saga-msg-icon,
.saga-message.saga-msg-danger .saga-msg-icon { color: #dc3545; }

/* Warning — amber */
.saga-message.saga-msg-warning {
    background: linear-gradient(135deg, #fff8e1 0%, #fff0b8 100%);
    border-left: 4px solid #FFB524;
    color: #6b4e00;
}
.saga-message.saga-msg-warning .saga-msg-icon { color: #FFB524; }

/* Info — teal/blue */
.saga-message.saga-msg-info {
    background: linear-gradient(135deg, #e0f4f8 0%, #c8ecf4 100%);
    border-left: 4px solid #17a2b8;
    color: #0c5460;
}
.saga-message.saga-msg-info .saga-msg-icon { color: #17a2b8; }

.saga-msg-icon {
    font-size: 1.2rem;
    flex-shrink: 0;
}

.saga-msg-content {
    flex: 1;
}

.saga-msg-close {
    background: none;
    border: none;
    cursor: pointer;
    color: inherit;
    opacity: 0.6;
    padding: 0.2rem 0.4rem;
    font-size: 0.85rem;
    line-height: 1;
    border-radius: 4px;
    flex-shrink: 0;
    transition: opacity 0.2s ease;
}
.saga-msg-close:hover { opacity: 1; }

/* Disabled buttons */
button:disabled,
input[type="submit"]:disabled {
    background-color: gray;
    color: #fff;
    cursor: not-allowed;
}
