/* Base Chat Styles */
.ai-chat-container {
    max-width: 800px;
    margin: 0 auto;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: #ffffff;
    border-radius: 12px;
    border: 1px solid #e5e7eb;
    overflow: hidden;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
}

/* CSS Variables for Customization */
:root {
    --primary-color: #0066cc;
    --secondary-color: #f9fafb;
    --text-color: #374151;
    --border-color: #e5e7eb;
    --success-color: #10b981;
    --error-color: #ef4444;
    --warning-color: #f59e0b;
}

/* Chat Header */
.ai-chat-header {
    background: var(--primary-color);
    color: white;
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 15px;
}

.ai-chat-header .company-logo {
    height: 40px;
    width: auto;
    border-radius: 4px;
}

.ai-chat-header .header-text h3 {
    margin: 0;
    font-size: 20px;
    font-weight: 600;
}

.ai-chat-header .header-text small {
    opacity: 0.9;
    font-size: 14px;
}

/* Quick Actions */
.ai-quick-actions {
    background: white;
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
}

.quick-actions-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 12px;
}

.quick-action-btn {
    background: white;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    padding: 12px 16px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: center;
    color: var(--text-color);
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
}

.quick-action-btn:hover {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 102, 204, 0.15);
}

/* Chat Messages */
.ai-chat-messages {
    height: 450px;
    overflow-y: auto;
    padding: 20px;
    background: var(--secondary-color);
}

.ai-message {
    margin-bottom: 20px;
    display: flex;
    align-items: flex-start;
    gap: 12px;
}

.ai-message.user {
    flex-direction: row-reverse;
}

.ai-message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 14px;
    flex-shrink: 0;
}

.ai-message.user .ai-message-avatar {
    background: var(--primary-color);
    color: white;
}

.ai-message.assistant .ai-message-avatar {
    background: #6b7280;
    color: white;
}

.ai-message-content {
    background: white;
    padding: 14px 18px;
    border-radius: 18px;
    max-width: 75%;
    border: 1px solid var(--border-color);
    line-height: 1.6;
    font-size: 14px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.ai-message.user .ai-message-content {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

/* Welcome Message Styles */
.welcome-content {
    max-width: none;
}

.welcome-features {
    margin: 16px 0;
    padding: 16px;
    background: #f0f9ff;
    border-radius: 8px;
    border-left: 4px solid var(--primary-color);
}

.welcome-features h4 {
    margin: 0 0 12px 0;
    color: var(--primary-color);
    font-size: 15px;
}

.welcome-features ul {
    margin: 0;
    padding-left: 20px;
}

.welcome-features li {
    margin-bottom: 6px;
    font-size: 13px;
    line-height: 1.4;
}

.welcome-examples {
    margin-top: 16px;
}

.welcome-examples h4 {
    margin: 0 0 10px 0;
    color: var(--text-color);
    font-size: 15px;
}

.example-queries {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.example-query {
    background: #e0f2fe;
    color: #0066cc;
    padding: 6px 12px;
    border-radius: 16px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
    border: 1px solid transparent;
}

.example-query:hover {
    background: var(--primary-color);
    color: white;
    transform: translateY(-1px);
}

/* Financial Tools Styles */
.tool-container {
    margin-top: 16px;
}

.financial-tool {
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    margin: 16px 0;
    overflow: hidden;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
}

.tool-header {
    background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
}

.tool-header h4 {
    margin: 0 0 4px 0;
    font-size: 18px;
    font-weight: 600;
    color: var(--text-color);
}

.tool-header p {
    margin: 0;
    color: #6b7280;
    font-size: 14px;
}

.tool-form {
    padding: 24px;
}

.form-grid {
    display: grid;
    gap: 20px;
    margin-bottom: 24px;
}

.form-row {
    position: relative;
}

.form-row label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: var(--text-color);
    font-size: 14px;
}

.form-row input {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-size: 14px;
    transition: all 0.2s ease;
    background: white;
    box-sizing: border-box;
}

.form-row input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(0, 102, 204, 0.1);
}

.form-row small {
    display: block;
    color: #6b7280;
    font-size: 12px;
    margin-top: 6px;
    line-height: 1.4;
}

/* Calculator Buttons */
.calculate-btn {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 14px 28px;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    width: 100%;
    position: relative;
    overflow: hidden;
}

.calculate-btn:hover:not(:disabled) {
    background: #0052a3;
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(0, 102, 204, 0.3);
}

.calculate-btn:disabled {
    background: #9ca3af;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* Tool Results */
.tool-result {
    border-top: 1px solid var(--border-color);
    background: linear-gradient(135deg, #f8fafc 0%, #ffffff 100%);
}

.result-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    padding: 24px;
}

.result-item {
    background: white;
    padding: 20px;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    text-align: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.result-label {
    display: block;
    font-size: 13px;
    color: #6b7280;
    margin-bottom: 8px;
    font-weight: 500;
}

.result-value {
    display: block;
    font-size: 24px;
    font-weight: 700;
    color: var(--primary-color);
}

/* FIXED: Chat Input Styles for Mobile */
.ai-chat-input-container {
    padding: 16px 20px;
    background: white;
    border-top: 1px solid var(--border-color);
    position: sticky;
    bottom: 0;
    z-index: 10;
}

.ai-chat-input-wrapper {
    display: flex;
    gap: 12px;
    align-items: flex-end;
    background: #f9fafb;
    border-radius: 24px;
    padding: 6px;
    border: 2px solid var(--border-color);
    transition: border-color 0.2s ease;
    min-height: 52px;
}

.ai-chat-input-wrapper:focus-within {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(0, 102, 204, 0.1);
}

.ai-chat-input {
    flex: 1;
    min-height: 40px;
    max-height: 120px;
    padding: 10px 16px;
    border: none;
    background: transparent;
    resize: none;
    font-family: inherit;
    font-size: 16px; /* Prevents zoom on iOS */
    line-height: 1.5;
    outline: none;
    color: var(--text-color);
}

.ai-chat-input::placeholder {
    color: #9ca3af;
    font-size: 14px;
}

.ai-chat-send-btn {
    width: 40px;
    height: 40px;
    border: none;
    background: var(--primary-color);
    color: white;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.ai-chat-send-btn:hover:not(:disabled) {
    background: #0052a3;
    transform: scale(1.05);
}

.ai-chat-send-btn:disabled {
    background: #d1d5db;
    cursor: not-allowed;
    transform: none;
}

/* Footer */
.ai-chat-footer {
    padding: 12px 20px;
    background: #f8fafc;
    border-top: 1px solid var(--border-color);
    text-align: center;
}

.ai-chat-footer small {
    color: #6b7280;
    font-size: 12px;
    line-height: 1.4;
}

/* ENHANCED: Mobile Responsive Styles */
@media (max-width: 768px) {
    .ai-chat-container {
        margin: 0;
        border-radius: 0;
        border-left: none;
        border-right: none;
        max-width: 100vw;
        height: 100vh;
        display: flex;
        flex-direction: column;
    }
    
    .ai-chat-header {
        padding: 12px 16px;
        border-radius: 0;
    }
    
    .ai-chat-header .header-text h3 {
        font-size: 16px;
    }
    
    .ai-chat-header .company-logo {
        height: 28px;
    }
    
    .ai-quick-actions {
        padding: 12px 16px;
    }
    
    .quick-actions-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }
    
    .quick-action-btn {
        padding: 8px 10px;
        font-size: 11px;
        min-height: 36px;
    }
    
    .ai-chat-messages {
        height: calc(100vh - 280px);
        padding: 16px;
        flex: 1;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .ai-message-content {
        max-width: 85%;
        font-size: 14px;
        padding: 12px 16px;
    }
    
    /* CRITICAL: Mobile Input Container Fix */
    .ai-chat-input-container {
        padding: 12px 16px 12px 16px;
        background: white;
        border-top: 2px solid var(--border-color);
        position: sticky;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 999;
        box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
    }
    
    .ai-chat-input-wrapper {
        background: white;
        border: 2px solid var(--border-color);
        border-radius: 25px;
        padding: 4px;
        display: flex;
        align-items: center;
        gap: 8px;
        min-height: 48px;
        width: 100%;
        box-sizing: border-box;
    }
    
    .ai-chat-input {
        flex: 1;
        min-height: 36px;
        max-height: 100px;
        padding: 8px 12px;
        border: none;
        background: transparent;
        resize: none;
        font-family: inherit;
        font-size: 16px; /* Prevents iOS zoom */
        line-height: 1.4;
        outline: none;
        color: var(--text-color);
        width: 100%;
        box-sizing: border-box;
    }
    
    .ai-chat-input::placeholder {
        color: #9ca3af;
        font-size: 14px;
    }
    
    .ai-chat-send-btn {
        width: 36px;
        height: 36px;
        border: none;
        background: var(--primary-color);
        color: white;
        border-radius: 50%;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        flex-shrink: 0;
        transition: all 0.2s ease;
    }
    
    .ai-chat-send-btn:active {
        transform: scale(0.95);
    }
    
    .ai-chat-footer {
        padding: 8px 16px;
    }
    
    .ai-chat-footer small {
        font-size: 11px;
    }
    
    /* Mobile Tool Styles */
    .financial-tool {
        border-radius: 8px;
        margin: 12px 0;
    }
    
    .tool-form {
        padding: 16px;
    }
    
    .form-row input {
        padding: 10px 14px;
        font-size: 16px; /* Prevents iOS zoom */
    }
    
    .calculate-btn {
        padding: 12px 20px;
        font-size: 14px;
    }
    
    .result-grid {
        grid-template-columns: 1fr;
        padding: 16px;
        gap: 12px;
    }
    
    .result-item {
        padding: 16px;
    }
    
    .result-value {
        font-size: 20px;
    }
    
    .result-actions {
        padding: 12px 16px;
        flex-direction: column;
    }
    
    .secondary-btn, .primary-btn {
        width: 100%;
        margin-bottom: 8px;
    }
    
    /* Welcome message mobile optimization */
    .welcome-features {
        padding: 12px;
        margin: 12px 0;
    }
    
    .welcome-features ul {
        padding-left: 16px;
    }
    
    .example-queries {
        flex-direction: column;
        gap: 6px;
    }
    
    .example-query {
        text-align: center;
        padding: 8px 12px;
    }
}

/* CRITICAL: Small Mobile Devices (iPhone SE, etc.) */
@media (max-width: 480px) {
    .ai-chat-container {
        height: 100vh;
        border-radius: 0;
        border: none;
    }
    
    .ai-chat-header {
        padding: 10px 12px;
    }
    
    .ai-chat-header .header-text h3 {
        font-size: 14px;
    }
    
    .quick-actions-grid {
        grid-template-columns: 1fr;
        gap: 6px;
    }
    
    .quick-action-btn {
        padding: 10px 12px;
        font-size: 12px;
        min-height: 40px;
    }
    
    .ai-chat-messages {
        height: calc(100vh - 240px);
        padding: 12px;
    }
    
    /* ULTRA-CRITICAL: Input container for very small screens */
    .ai-chat-input-container {
        padding: 10px 12px;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: white;
        border-top: 2px solid var(--border-color);
        z-index: 9999;
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
    }
    
    .ai-chat-input-wrapper {
        min-height: 44px;
        padding: 3px;
        border-radius: 22px;
    }
    
    .ai-chat-input {
        font-size: 16px; /* Critical for iOS */
        padding: 8px 12px;
        min-height: 32px;
    }
    
    .ai-chat-send-btn {
        width: 34px;
        height: 34px;
    }
    
    .ai-chat-send-btn svg {
        width: 16px;
        height: 16px;
    }
    
    /* Ensure input is always visible above keyboard */
    .ai-chat-input-container {
        padding-bottom: env(safe-area-inset-bottom, 10px);
    }
}

/* iOS Safari Specific Fixes */
@supports (-webkit-touch-callout: none) {
    .ai-chat-input-container {
        padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    }
    
    .ai-chat-input {
        -webkit-appearance: none;
        border-radius: 0;
    }
}

/* Android Chrome Specific Fixes */
@media screen and (-webkit-min-device-pixel-ratio: 0) {
    .ai-chat-input {
        font-size: 16px; /* Prevents zoom */
    }
}

/* Landscape mode adjustments */
@media (max-width: 768px) and (orientation: landscape) {
    .ai-chat-messages {
        height: calc(100vh - 200px);
    }
    
    .quick-actions-grid {
        grid-template-columns: repeat(3, 1fr);
    }
    
    .quick-action-btn {
        font-size: 10px;
        padding: 6px 8px;
    }
}

/* Touch device optimizations */
@media (pointer: coarse) {
    .quick-action-btn,
    .calculate-btn,
    .ai-chat-send-btn {
        min-height: 44px; /* Touch target size */
    }
    
    .result-actions button {
        min-height: 44px;
        padding: 12px 16px;
    }
}

/* Animation Classes */
.fade-in {
    animation: fadeIn 0.3s ease-in;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Typing indicator styles */
.typing-dots {
    display: flex;
    gap: 4px;
    padding: 8px 0;
}

.typing-dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #9ca3af;
    animation: typing-bounce 1.4s infinite;
}

.typing-dots span:nth-child(1) { animation-delay: 0ms; }
.typing-dots span:nth-child(2) { animation-delay: 200ms; }
.typing-dots span:nth-child(3) { animation-delay: 400ms; }

@keyframes typing-bounce {
    0%, 60%, 100% { 
        opacity: 0.3;
        transform: translateY(0); 
    }
    30% { 
        opacity: 1;
        transform: translateY(-4px); 
    }
}