/* Animations and Loading States */

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s, visibility 0.2s;
}

.loading-overlay.active {
    opacity: 1;
    visibility: visible;
}

.loading-box {
    background: white;
    border: 2px outset var(--window-border);
    padding: 32px 48px;
    text-align: center;
    min-width: 280px;
}

.loading-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--sap-gray);
    border-top-color: var(--sap-blue);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 16px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-text {
    font-size: 12px;
    color: var(--sap-dark-gray);
}

.loading-subtext {
    font-size: 10px;
    color: #999;
    margin-top: 8px;
}

/* Progress Bar Loading */
.loading-progress {
    width: 200px;
    height: 20px;
    background: var(--sap-gray);
    border: 2px inset var(--sap-dark-gray);
    margin: 16px auto;
    overflow: hidden;
}

.loading-progress-bar {
    height: 100%;
    background: linear-gradient(90deg,
        var(--sap-blue) 0%,
        var(--sap-light-blue) 50%,
        var(--sap-blue) 100%);
    background-size: 200% 100%;
    animation: progressShimmer 1.5s linear infinite;
    transition: width 0.3s;
}

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

/* Hourglass Animation (SAP Classic) */
.hourglass {
    font-size: 32px;
    animation: hourglassFlip 1s ease-in-out infinite;
}

@keyframes hourglassFlip {
    0%, 100% { transform: rotate(0deg); }
    50% { transform: rotate(180deg); }
}

/* Popup Animations */
.popup-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10001;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s, visibility 0.2s;
}

.popup-overlay.active {
    opacity: 1;
    visibility: visible;
}

.popup {
    background: #ffffff;
    border-radius: 8px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3), 0 0 0 1px rgba(0, 0, 0, 0.1);
    width: 90%;
    max-width: 560px;
    min-width: 320px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    transform: scale(0.9) translateY(20px);
    transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
    overflow: hidden;
}

.popup-overlay.active .popup {
    transform: scale(1) translateY(0);
}

.popup-title {
    background: linear-gradient(135deg, var(--sap-blue) 0%, var(--sap-dark-blue) 100%);
    color: white;
    padding: 12px 16px;
    font-size: 14px;
    font-weight: 600;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
    cursor: grab;
    user-select: none;
}

.popup-title:active {
    cursor: grabbing;
}

.popup-title .sap-titlebar-btn {
    background: rgba(255, 255, 255, 0.15);
    border: none;
    border-radius: 4px;
    color: white;
    width: 24px;
    height: 24px;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.15s;
}

.popup-title .sap-titlebar-btn:hover {
    background: rgba(255, 255, 255, 0.25);
}

.popup-content {
    padding: 20px;
    display: flex;
    align-items: flex-start;
    gap: 16px;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
}

.popup-icon {
    font-size: 36px;
    flex-shrink: 0;
    line-height: 1;
}

.popup-text {
    font-size: 13px;
    line-height: 1.6;
    color: #333;
    flex: 1;
    min-width: 0;
    width: 100%;
}

/* Preserve whitespace only for simple text content */
.popup-text:not(:has(div)):not(:has(table)):not(:has(ul)) {
    white-space: pre-wrap;
}

/* Reset whitespace for complex HTML content */
.popup-text div,
.popup-text table,
.popup-text ul,
.popup-text ol {
    white-space: normal;
}

.popup-buttons {
    padding: 16px 20px;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    background: #f8f9fa;
    border-top: 1px solid #e9ecef;
    flex-shrink: 0;
}

.popup-buttons .btn-classic {
    padding: 8px 24px;
    font-size: 13px;
    font-weight: 500;
    border-radius: 0;
    border: 2px outset #dfdfdf;
    background: #c0c0c0;
    color: #000;
    cursor: pointer;
    transition: all 0.1s;
    min-width: 80px;
}

.popup-buttons .btn-classic:hover {
    background: #d4d4d4;
}

.popup-buttons .btn-classic:active {
    border: 2px inset #808080;
    background: #a0a0a0;
}

.popup-buttons .btn-classic.primary {
    background: #000080;
    border: 2px outset #4040c0;
    color: white;
    font-weight: bold;
}

.popup-buttons .btn-classic.primary:hover {
    background: #0000a0;
    border-color: #6060e0;
}

.popup-buttons .btn-classic.primary:active {
    border: 2px inset #000060;
    background: #000060;
}

/* Wide Popup Variant */
.popup.wide {
    max-width: 640px;
}

/* Popup with hidden icon - full width content */
.popup-content:has(.popup-icon[style*="display: none"]) {
    gap: 0;
}

.popup-content:has(.popup-icon[style*="display: none"]) .popup-text {
    width: 100%;
}

/* Task items in popup */
.popup-text [style*="overflow-y: auto"] {
    scrollbar-width: thin;
    scrollbar-color: #c1c1c1 #f1f1f1;
}

/* Ensure nested scrollable areas work */
.popup-text > div {
    max-width: 100%;
}

/* Custom Scrollbar for Popup Content */
.popup-content::-webkit-scrollbar {
    width: 8px;
}

.popup-content::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.popup-content::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 4px;
}

.popup-content::-webkit-scrollbar-thumb:hover {
    background: #a1a1a1;
}

/* Responsive Popup */
@media (max-width: 480px) {
    .popup {
        width: 95%;
        max-height: 90vh;
        margin: 16px;
    }

    .popup-content {
        padding: 16px;
        flex-direction: column;
        align-items: center;
        text-align: center;
    }

    .popup-icon {
        margin-bottom: 8px;
    }

    .popup-buttons {
        flex-direction: column;
        padding: 12px 16px;
    }

    .popup-buttons .btn-classic {
        width: 100%;
        justify-content: center;
    }
}

/* Shake Animation (for errors) */
.shake {
    animation: shake 0.5s ease-in-out;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
    20%, 40%, 60%, 80% { transform: translateX(5px); }
}

/* Fade Animations */
.fade-in {
    animation: fadeIn 0.3s ease-out;
}

.fade-out {
    animation: fadeOut 0.3s ease-in forwards;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes fadeOut {
    from { opacity: 1; }
    to { opacity: 0; }
}

/* Slide Animations */
.slide-in-right {
    animation: slideInRight 0.3s ease-out;
}

.slide-out-right {
    animation: slideOutRight 0.3s ease-in forwards;
}

@keyframes slideInRight {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

@keyframes slideOutRight {
    from { transform: translateX(0); opacity: 1; }
    to { transform: translateX(100%); opacity: 0; }
}

.slide-in-up {
    animation: slideInUp 0.3s ease-out;
}

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

/* Bounce Animation */
.bounce {
    animation: bounce 0.5s ease-out;
}

@keyframes bounce {
    0% { transform: scale(0.5); }
    50% { transform: scale(1.1); }
    70% { transform: scale(0.95); }
    100% { transform: scale(1); }
}

/* Pulse Animation */
.pulse {
    animation: pulse 2s infinite;
}

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

/* Glow Effect */
.glow {
    animation: glow 1.5s ease-in-out infinite alternate;
}

@keyframes glow {
    from { box-shadow: 0 0 5px var(--sap-yellow); }
    to { box-shadow: 0 0 20px var(--sap-yellow), 0 0 30px var(--sap-orange); }
}

/* Typing Animation */
.typing::after {
    content: '|';
    animation: blink 1s step-end infinite;
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

/* Coffee Steam Animation */
.steam {
    position: relative;
}

.steam::before,
.steam::after {
    content: '';
    position: absolute;
    width: 8px;
    height: 20px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    animation: steam 2s infinite;
}

.steam::before {
    left: 25%;
    animation-delay: 0.5s;
}

.steam::after {
    left: 50%;
}

@keyframes steam {
    0% {
        transform: translateY(0) scaleX(1);
        opacity: 0.3;
    }
    100% {
        transform: translateY(-30px) scaleX(1.5);
        opacity: 0;
    }
}

/* Phone Ring Animation */
.ring {
    animation: ring 0.5s ease-in-out infinite;
}

@keyframes ring {
    0%, 100% { transform: rotate(0deg); }
    25% { transform: rotate(15deg); }
    50% { transform: rotate(0deg); }
    75% { transform: rotate(-15deg); }
}

/* Points Float Animation */
.points-float {
    position: fixed;
    font-size: 24px;
    font-weight: bold;
    color: var(--sap-green);
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
    pointer-events: none;
    animation: floatUp 1.5s ease-out forwards;
    z-index: 10004;
}

.points-float.negative {
    color: var(--sap-red);
}

@keyframes floatUp {
    0% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
    100% {
        opacity: 0;
        transform: translateY(-100px) scale(1.5);
    }
}

/* Screen Flash (for dumps) */
.screen-flash {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: white;
    z-index: 9999;
    animation: flash 0.3s ease-out;
    pointer-events: none;
}

@keyframes flash {
    0% { opacity: 1; }
    100% { opacity: 0; }
}

/* Window Focus Effect */
.window-focus {
    animation: windowFocus 0.2s ease-out;
}

@keyframes windowFocus {
    0% { box-shadow: 4px 4px 10px rgba(0, 0, 0, 0.3); }
    50% { box-shadow: 0 0 20px rgba(53, 74, 95, 0.5); }
    100% { box-shadow: 4px 4px 10px rgba(0, 0, 0, 0.3); }
}

/* Countdown Timer Animation */
.countdown {
    font-family: var(--font-mono);
    font-size: 48px;
    font-weight: bold;
    animation: countdownPulse 1s ease-in-out infinite;
}

@keyframes countdownPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

/* Success Checkmark */
.checkmark {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    display: block;
    stroke-width: 2;
    stroke: var(--sap-green);
    stroke-miterlimit: 10;
    box-shadow: inset 0 0 0 var(--sap-green);
    animation: checkmarkFill 0.4s ease-in-out 0.4s forwards, checkmarkScale 0.3s ease-in-out 0.9s both;
}

.checkmark__circle {
    stroke-dasharray: 166;
    stroke-dashoffset: 166;
    stroke-width: 2;
    stroke-miterlimit: 10;
    stroke: var(--sap-green);
    fill: none;
    animation: checkmarkStroke 0.6s cubic-bezier(0.65, 0, 0.45, 1) forwards;
}

.checkmark__check {
    transform-origin: 50% 50%;
    stroke-dasharray: 48;
    stroke-dashoffset: 48;
    animation: checkmarkStroke 0.3s cubic-bezier(0.65, 0, 0.45, 1) 0.8s forwards;
}

@keyframes checkmarkStroke {
    100% { stroke-dashoffset: 0; }
}

@keyframes checkmarkScale {
    0%, 100% { transform: none; }
    50% { transform: scale3d(1.1, 1.1, 1); }
}

@keyframes checkmarkFill {
    100% { box-shadow: inset 0 0 0 30px rgba(10, 102, 64, 0.1); }
}
