/* TWP Chat Widget Styles */
/* Integrates with existing TWP Dashboard design */

.twp-chat-widget {
    position: fixed;
    bottom: calc(20px + env(safe-area-inset-bottom, 0px));
    right: calc(20px + env(safe-area-inset-right, 0px));
    z-index: 1000;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
}

/* Chat Toggle Button */
.twp-chat-toggle-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    background: linear-gradient(135deg, #1e3a8a 0%, #059669 100%);
    color: white;
    border: none;
    border-radius: 50px;
    padding: 12px 20px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(30, 58, 138, 0.4);
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.twp-chat-toggle-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 25px rgba(30, 58, 138, 0.5);
}

.twp-chat-toggle-btn.twp-pulse {
    animation: twp-pulse 2s infinite;
}

@keyframes twp-pulse {
    0% { box-shadow: 0 4px 20px rgba(30, 58, 138, 0.4); }
    50% { box-shadow: 0 4px 20px rgba(30, 58, 138, 0.8), 0 0 0 10px rgba(30, 58, 138, 0.1); }
    100% { box-shadow: 0 4px 20px rgba(30, 58, 138, 0.4); }
}

.twp-chat-icon {
    font-size: 16px;
}

.twp-chat-text {
    white-space: nowrap;
}

.twp-chat-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #ff4444;
    color: white;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: bold;
    animation: twp-bounce 1s infinite;
}

@keyframes twp-bounce {
    0%, 20%, 50%, 80%, 100% { transform: translateY(0); }
    40% { transform: translateY(-3px); }
    60% { transform: translateY(-2px); }
}

/* Chat Modal */
.twp-chat-modal {
    position: fixed;
    bottom: calc(80px + env(safe-area-inset-bottom, 0px));
    right: calc(20px + env(safe-area-inset-right, 0px));
    width: min(420px, calc(100vw - 40px));
    height: min(620px, calc(100vh - 120px));
    background: white;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: translateY(20px);
    opacity: 0;
    transition: all 0.3s ease;
}

.twp-chat-modal:not(.twp-hidden) {
    transform: translateY(0);
    opacity: 1;
}

.twp-hidden {
    display: none !important;
}

/* Chat Header */
.twp-chat-header {
    background: linear-gradient(135deg, #1e3a8a 0%, #059669 100%);
    color: white;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.twp-chat-header-info h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

.twp-chat-subtitle {
    margin: 2px 0 0 0;
    font-size: 12px;
    opacity: 0.9;
}

.twp-chat-close {
    background: none;
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background-color 0.2s ease;
}

.twp-chat-close:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

/* Chat Content */
.twp-chat-content {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

/* Context Summary */
.twp-context-summary {
    background: #fff8e1;
    border-bottom: 2px solid #ffc107;
    padding: 14px 16px;
    font-size: 13px;
    color: #f57c00;
    flex-shrink: 0;
    font-weight: 500;
}

/* Welcome Message */
.twp-welcome-message {
    background: #000000;
    color: #ffffff;
    padding: 16px;
    font-size: 14px;
    font-weight: 600;
}

.twp-welcome-message p {
    color: #ffffff;
    margin: 0;
}

.twp-welcome-message strong {
    color: #ffffff;
    font-weight: 700;
}

/* Suggested Questions */
.twp-suggested-questions {
    background: #fffef3;
    border-bottom: 2px solid #ffc107;
    padding: 18px;
    flex-shrink: 0;
}

.twp-suggested-questions-header h4 {
    margin: 0 0 8px 0;
    font-size: 15px;
    color: #f57c00;
    font-weight: 700;
}

.twp-suggested-questions-header p {
    margin: 0 0 12px 0;
    font-size: 12px;
    color: #f57c00;
    opacity: 0.9;
    font-weight: 500;
}

.twp-question-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.twp-question-chip {
    background: #f0f0f0;
    border: 1px solid #ccc;
    color: #333;
    padding: 6px 10px;
    border-radius: 16px;
    font-size: 11px;
    font-weight: 400;
    cursor: pointer;
    transition: all 0.2s ease;
    max-width: 100%;
    word-wrap: break-word;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    margin: 2px;
}

.twp-question-chip:hover {
    background: #e0e0e0;
    border-color: #999;
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
}

/* Chat Messages */
.twp-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: #fafafa;
}

.twp-chat-messages p {
    margin: 0 0 8px 0;
    padding: 8px 12px;
    background: linear-gradient(135deg, #1e3a8a 0%, #059669 100%);
    color: #ffffff;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.4;
    font-weight: 600;
}

/* Enhanced message formatting */
.twp-message-bubble .twp-list-item {
    display: flex;
    margin: 8px 0;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 8px;
    border-left: 3px solid #ffffff;
}

.twp-message-bubble .twp-list-number {
    font-weight: 700;
    color: #ffffff;
    margin-right: 8px;
    min-width: 20px;
}

.twp-message-bubble .twp-list-content {
    flex: 1;
    color: #ffffff;
    line-height: 1.5;
}

.twp-message-bubble .twp-bullet-item {
    display: flex;
    margin: 6px 0;
    padding: 6px 12px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 6px;
}

.twp-message-bubble .twp-bullet {
    color: #ffffff;
    margin-right: 8px;
    font-weight: 700;
}

.twp-message-bubble .twp-bullet-content {
    flex: 1;
    color: #ffffff;
    line-height: 1.5;
}

/* Section headers in messages */
.twp-message-bubble .twp-section-header {
    color: #ffffff;
    font-weight: 700;
    font-size: 16px;
    margin: 16px 0 8px 0;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    border-left: 4px solid #ffffff;
}

.twp-message-bubble .twp-section-header:first-child {
    margin-top: 0;
}

/* Better paragraph spacing in messages */
.twp-message-bubble .twp-message-paragraph {
    margin: 8px 0;
    line-height: 1.6;
    color: #ffffff;
}

.twp-message-bubble .twp-message-paragraph:first-child {
    margin-top: 0;
}

.twp-message-bubble .twp-message-paragraph:last-child {
    margin-bottom: 0;
}

/* Structured Content Styles */
.twp-structured-content {
    margin: 0;
    padding: 0;
}

.twp-structured-content .twp-section-header {
    margin: 0 0 12px 0;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    border-left: 4px solid #ffffff;
    font-size: 16px;
    font-weight: 700;
    color: #ffffff;
}

/* Visa Recommendations Grid */
.twp-recommendations-grid {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.twp-recommendation-card {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    padding: 12px;
    border-left: 3px solid #ffffff;
}

.twp-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.twp-country-name {
    margin: 0;
    font-size: 16px;
    font-weight: 700;
    color: #ffffff;
}

.twp-score {
    background: rgba(255, 255, 255, 0.2);
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
    color: #ffffff;
}

.twp-program-name {
    font-weight: 600;
    color: #ffffff;
    margin-bottom: 4px;
}

.twp-summary {
    color: #ffffff;
    line-height: 1.4;
    font-size: 14px;
}

/* Comparison Table */
.twp-comparison-table {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.twp-comparison-row {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    padding: 12px;
    border-left: 3px solid #ffffff;
}

.twp-country-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.twp-country-details {
    color: #ffffff;
    line-height: 1.4;
}

/* Program Cards */
.twp-program-card {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 8px;
    border-left: 3px solid #ffffff;
}

.twp-program-name {
    font-size: 16px;
    font-weight: 700;
    color: #ffffff;
    margin: 0 0 8px 0;
}

.twp-program-details {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.twp-detail-item {
    color: #ffffff;
    line-height: 1.4;
    font-size: 14px;
}

.twp-detail-item strong {
    color: #ffffff;
    font-weight: 600;
}

.twp-chat-message {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.twp-chat-message.user {
    align-items: flex-end;
}

.twp-chat-message.assistant {
    align-items: flex-start;
}

.twp-message-bubble {
    max-width: 80%;
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.4;
    word-wrap: break-word;
}

.twp-chat-message.user .twp-message-bubble {
    background: linear-gradient(135deg, #1e3a8a 0%, #059669 100%);
    color: white;
    border-bottom-right-radius: 4px;
}

.twp-chat-message.assistant .twp-message-bubble {
    background: #000000;
    color: #ffffff;
    border: 2px solid #ffffff;
    border-bottom-left-radius: 4px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    font-weight: 600;
}

.twp-message-time {
    font-size: 11px;
    color: #9ca3af;
    margin: 0 8px;
}

.twp-message-metadata {
    margin-top: 4px;
    font-size: 11px;
    color: #6b7280;
}

/* Typing Indicator */
.twp-typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 12px 16px;
    background: white;
    border-radius: 18px;
    border: 1px solid #e2e8f0;
    max-width: 60px;
    margin-top: 4px;
}

.twp-typing-dot {
    width: 6px;
    height: 6px;
    background: #9ca3af;
    border-radius: 50%;
    animation: twp-typing 1.4s infinite ease-in-out;
}

.twp-typing-dot:nth-child(1) { animation-delay: -0.32s; }
.twp-typing-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes twp-typing {
    0%, 80%, 100% { transform: scale(0.8); opacity: 0.5; }
    40% { transform: scale(1); opacity: 1; }
}

/* Chat Input */
.twp-chat-input-container {
    border-top: 1px solid #e2e8f0;
    background: white;
    padding: 16px;
    flex-shrink: 0;
}

.twp-chat-input-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 24px;
    padding: 4px 4px 4px 16px;
    transition: border-color 0.2s ease;
    width: 100%;
}

.twp-chat-input-wrapper:focus-within {
    border-color: #1e3a8a;
    box-shadow: 0 0 0 3px rgba(30, 58, 138, 0.1);
}

.twp-chat-input {
    flex: 1;
    border: none;
    background: none;
    outline: none;
    font-size: 14px;
    padding: 8px 0;
    color: #2d3748;
    resize: none;
    width: 100%;
    min-width: 0;
}

.twp-chat-input::placeholder {
    color: #9ca3af;
}

.twp-chat-send-btn {
    background: linear-gradient(135deg, #1e3a8a 0%, #059669 100%);
    border: none;
    color: white;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
    margin-left: 8px;
}

.twp-chat-send-btn:hover:not(:disabled) {
    transform: scale(1.05);
}

.twp-chat-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.twp-send-icon {
    font-size: 14px;
}

.twp-chat-input-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 8px;
    font-size: 11px;
    color: #9ca3af;
}

.twp-input-counter {
    font-weight: 500;
}

.twp-ai-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    font-weight: 500;
}

.twp-ai-dot {
    width: 6px;
    height: 6px;
    background: #059669;
    border-radius: 50%;
    animation: twp-pulse-green 2s infinite;
}

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

/* Slide-in Animation */
.twp-slide-in {
    animation: twp-slideIn 0.3s ease-out;
}

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

/* Mobile Responsiveness */
@media (max-width: 768px) {
    .twp-chat-modal {
        position: fixed;
        bottom: 0;
        right: 0;
        left: 0;
        top: 0;
        width: 100%;
        height: 100%;
        max-width: none;
        max-height: none;
        border-radius: 0;
        transform: translateY(100%);
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }
    
    .twp-chat-modal:not(.twp-hidden) {
        transform: translateY(0);
    }
    
    .twp-chat-widget {
        bottom: 15px;
        right: 15px;
    }
    
    .twp-chat-toggle-btn {
        padding: 10px 16px;
        font-size: 13px;
    }
    
    .twp-chat-text {
        display: none;
    }
}

@supports (padding: max(0px, env(safe-area-inset-bottom))) {
    .twp-chat-modal {
        padding-bottom: max(16px, env(safe-area-inset-bottom));
    }
}

@media (prefers-reduced-motion: reduce) {
    .twp-chat-toggle-btn,
    .twp-chat-modal,
    .twp-chat-badge,
    .twp-typing-indicator,
    .twp-typing-dot,
    .twp-chat-send-btn {
        animation: none !important;
        transition-duration: 0ms !important;
        transition-property: none !important;
    }
}

/* Dark mode support (if needed) */
@media (prefers-color-scheme: dark) {
    .twp-chat-modal {
        background: #1a202c;
        color: #e2e8f0;
    }
    
    .twp-chat-message.assistant .twp-message-bubble {
        background: #2d3748;
        color: #e2e8f0;
        border-color: #4a5568;
    }
    
    .twp-chat-input-container {
        background: #2d3748;
        border-color: #4a5568;
    }
    
    .twp-chat-input-wrapper {
        background: #4a5568;
        border-color: #718096;
    }
    
    .twp-chat-input {
        color: #e2e8f0;
    }
    
    .twp-chat-input::placeholder {
        color: #a0aec0;
    }
}
