/* AI Widget Styles */
.ai-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 999999;
    font-family: var(--font-secondary);
    /* Ensure widget never gets cut off */
    max-width: calc(100vw - 40px);
    max-height: calc(100vh - 40px);
}

/* Ensure widget stays visible */
.ai-widget * {
    box-sizing: border-box;
}

/* Widget Toggle Button */
.ai-widget-toggle {
    width: 60px;
    height: 60px;
    background: transparent;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    transition: all 0.3s ease;
    position: fixed; /* Always use fixed positioning */
    bottom: 20px;
    right: 20px;
    overflow: hidden;
    padding: 0;
    margin: 0;
    border: none;
    /* Prevent cut-off */
    min-width: 60px;
    min-height: 60px;
}

.ai-widget-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 25px rgba(0, 0, 0, 0.2);
}

.ai-widget-toggle::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    transition: left 0.5s;
}

.ai-widget-toggle:hover::before {
    left: 100%;
}

.ai-icon {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    margin: 0;
}

.bigfoot-icon {
    width: 60px;
    height: 60px;
    background-image: url('https://storage.googleapis.com/bigfoot-roofing-images/Bigfoot%20Icon.jpg');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    border-radius: 50%;
    display: block;
    transition: transform 0.3s ease;
}

.ai-widget-toggle:hover .bigfoot-icon {
    transform: scale(1.1);
}

@keyframes float {
    0%, 100% { transform: translateY(0px); }
    50% { transform: translateY(-3px); }
}

/* Notification Badge */
.notification-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #0097b2; /* Use primary color for notification badge */
    color: white;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    font-size: 11px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(255, 68, 68, 0.7); }
    70% { box-shadow: 0 0 0 10px rgba(255, 68, 68, 0); }
    100% { box-shadow: 0 0 0 0 rgba(255, 68, 68, 0); }
}

/* Widget Container */
.ai-widget-container {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 400px;
    height: 550px;
    max-height: calc(100vh - 120px);
    background: white;
    border-radius: 16px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.15);
    transform: scale(0) translateY(20px);
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    overflow: hidden;
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
}

.ai-widget-container.ai-widget-open {
    transform: scale(1) translateY(0);
    opacity: 1;
}

.ai-widget-container.ai-widget-minimized {
    height: 60px;
    overflow: hidden;
}

.ai-widget-container.ai-widget-minimized .ai-messages,
.ai-widget-container.ai-widget-minimized .ai-input-area,
.ai-widget-container.ai-widget-minimized .ai-quick-actions {
    display: none;
}

/* Widget Header */
.ai-widget-header {
    background: linear-gradient(135deg, var(--dark-bg), var(--darker-bg));
    color: white;
    padding: 16px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    flex-shrink: 0;
}

.ai-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.ai-avatar {
    width: 40px;
    height: 40px;
    background: var(--primary-color);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    color: white;
}

.ai-avatar .bigfoot-icon {
    width: 24px;
    height: 24px;
    transform: none;
}

.ai-header-text h4 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

.ai-status {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.8);
    display: flex;
    align-items: center;
    gap: 6px;
}

.ai-status::before {
    content: '';
    width: 8px;
    height: 8px;
    background: #69f2c4; /* Use aqua for status indicator */
    border-radius: 50%;
    animation: blink 2s infinite;
}

@keyframes blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0.3; }
}

.ai-header-actions {
    display: flex;
    gap: 8px;
}

.ai-action-btn {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.8);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.ai-action-btn:hover {
    color: white;
    background: rgba(255, 255, 255, 0.1);
}

/* Messages Container */
.ai-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: #f8f6f3; /* Use soft off-white for message background */
    scroll-behavior: smooth;
    min-height: 200px;
}

.ai-messages::-webkit-scrollbar {
    width: 4px;
}

.ai-messages::-webkit-scrollbar-track {
    background: transparent;
}

.ai-messages::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 2px;
}

.ai-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.3);
}

.ai-message {
    display: flex;
    margin-bottom: 16px;
    align-items: flex-start;
    gap: 10px;
}

.ai-message-user {
    flex-direction: row-reverse;
}

.ai-message-avatar {
    width: 32px;
    height: 32px;
    background: var(--primary-color);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 14px;
    flex-shrink: 0;
}

.ai-message-avatar .bigfoot-icon {
    width: 20px;
    height: 20px;
    transform: none;
}

.ai-message-content {
    max-width: 80%;
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.ai-message-text {
    background: white;
    padding: 12px 16px;
    border-radius: 18px;
    border: 1px solid var(--border-color);
    font-size: 14px;
    line-height: 1.4;
    word-wrap: break-word;
}

.ai-message-user .ai-message-text {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.ai-message-text ul {
    margin: 8px 0 0 0;
    padding-left: 20px;
}

.ai-message-text li {
    margin-bottom: 4px;
}

.ai-message-time {
    font-size: 11px;
    color: var(--text-light);
    margin-top: 4px;
    text-align: right;
}

.ai-message-user .ai-message-time {
    text-align: left;
}

/* Data Components */
.ai-data-component {
    margin-top: 12px;
    padding: 16px;
    background: #4a5a61; /* Use muted blue-gray for data component background */
    border-radius: 12px;
    border: 1px solid var(--border-color);
}

/* Quote Form */
.ai-quote-form h5 {
    margin: 0 0 12px 0;
    color: var(--text-dark);
    font-size: 14px;
    font-weight: 600;
}

.ai-quote-form input,
.ai-quote-form select,
.ai-quote-form textarea {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 13px;
    margin-bottom: 8px;
    transition: border-color 0.2s ease;
}

.ai-quote-form input:focus,
.ai-quote-form select:focus,
.ai-quote-form textarea:focus {
    outline: none;
    border-color: var(--primary-color);
}

.ai-quote-form textarea {
    height: 60px;
    resize: vertical;
}

.ai-form-submit {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 10px 16px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s ease;
    width: 100%;
}

.ai-form-submit:hover {
    background: var(--accent-color);
}

/* Service Cards */
.ai-services-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

.ai-service-card {
    background: white;
    padding: 12px;
    border-radius: 8px;
    text-align: center;
    border: 1px solid var(--border-color);
    transition: transform 0.2s ease;
}

.ai-service-card:hover {
    transform: translateY(-2px);
}

.ai-service-card i {
    font-size: 20px;
    color: var(--primary-color);
    margin-bottom: 6px;
}

.ai-service-card h6 {
    margin: 0 0 4px 0;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-dark);
}

.ai-service-card p {
    margin: 0 0 6px 0;
    font-size: 11px;
    color: var(--text-light);
    line-height: 1.3;
}

.ai-service-price {
    font-size: 12px;
    font-weight: 600;
    color: var(--primary-color);
}

/* Analytics */
.ai-analytics h5 {
    margin: 0 0 12px 0;
    color: var(--text-dark);
    font-size: 14px;
    font-weight: 600;
}

.ai-stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}

.ai-stat {
    background: white;
    padding: 12px;
    border-radius: 8px;
    text-align: center;
    border: 1px solid var(--border-color);
}

.ai-stat-number {
    display: block;
    font-size: 18px;
    font-weight: 700;
    color: var(--primary-color);
}

.ai-stat-label {
    font-size: 11px;
    color: var(--text-light);
    margin-top: 2px;
}

/* Quick Actions */
.ai-quick-actions {
    padding: 16px 20px;
    background: white;
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    flex-shrink: 0;
}

.ai-quick-btn {
    background: var(--secondary-color);
    border: 1px solid var(--border-color);
    color: var(--text-dark);
    padding: 6px 12px;
    border-radius: 16px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.ai-quick-btn:hover {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

/* Typing Indicator */
.ai-typing-indicator {
    padding: 16px 20px;
    background: white;
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 12px;
    color: var(--text-light);
}

.ai-typing-dots {
    display: flex;
    gap: 4px;
}

.ai-typing-dots span {
    width: 6px;
    height: 6px;
    background: var(--text-light);
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out;
}

.ai-typing-dots span:nth-child(1) { animation-delay: -0.32s; }
.ai-typing-dots span:nth-child(2) { animation-delay: -0.16s; }

@keyframes typing {
    0%, 80%, 100% {
        transform: scale(0.8);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Input Area */
.ai-input-area {
    background: white;
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
}

.ai-input-container {
    padding: 16px 20px;
    display: flex;
    gap: 12px;
    align-items: center;
}

.ai-input-container input {
    flex: 1;
    padding: 10px 16px;
    border: 1px solid var(--border-color);
    border-radius: 22px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s ease;
}

.ai-input-container input:focus {
    border-color: var(--primary-color);
}

.ai-send-btn {
    width: 40px;
    height: 40px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.ai-send-btn:hover {
    background: var(--accent-color);
    transform: scale(1.05);
}

.ai-input-footer {
    padding: 0 20px 12px 20px;
    text-align: center;
}

.ai-input-footer small {
    font-size: 11px;
    color: var(--text-light);
}

.ai-input-footer a {
    color: var(--primary-color);
    text-decoration: none;
}

.ai-input-footer a:hover {
    text-decoration: underline;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .ai-widget {
        bottom: 20px;
        right: 15px;
        left: auto; /* Remove left positioning to keep it on the right */
    }
    
    .ai-widget-container {
        width: calc(100vw - 30px);
        max-width: 400px;
        height: calc(100vh - 120px);
        max-height: 600px;
        bottom: 90px;
        right: 15px;
        left: auto; /* Keep container on the right side */
        margin: 0;
    }
    
    .ai-widget-toggle {
        width: 60px;
        height: 60px;
        position: fixed; /* Ensure it stays in position */
        right: 15px;
        bottom: 20px;
        left: auto;
    }
    
    .ai-icon {
        font-size: 24px;
    }
    
    .ai-messages {
        padding: 15px;
        min-height: 250px;
    }
    
    .ai-message-content {
        max-width: 85%;
    }
    
    .ai-services-grid {
        grid-template-columns: 1fr;
        gap: 8px;
    }
    
    .ai-stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }
    
    .ai-quick-actions {
        padding: 12px 15px;
        gap: 6px;
    }
    
    .ai-input-container {
        padding: 12px 15px;
    }
    
    .ai-widget-header {
        padding: 12px 15px;
    }
}

@media (max-width: 480px) {
    .ai-widget {
        bottom: 15px;
        right: 10px;
        left: auto; /* Keep on right side */
    }
    
    .ai-widget-container {
        width: calc(100vw - 20px);
        height: calc(100vh - 100px);
        bottom: 85px;
        right: 10px;
        left: auto; /* Keep container on right side */
        border-radius: 12px;
    }
    
    .ai-widget-toggle {
        width: 55px;
        height: 55px;
        position: fixed; /* Ensure it stays in position */
        right: 10px;
        bottom: 15px;
        left: auto;
    }
    
    .bigfoot-icon {
        width: 55px;
        height: 55px;
    }
    
    .ai-messages {
        padding: 12px;
        min-height: 200px;
    }
    
    .ai-message {
        margin-bottom: 12px;
    }
    
    .ai-message-avatar {
        width: 28px;
        height: 28px;
        font-size: 12px;
    }
    
    .ai-message-avatar .bigfoot-icon {
        width: 18px;
        height: 18px;
    }
    
    .ai-message-text {
        padding: 10px 12px;
        font-size: 13px;
        border-radius: 14px;
    }
    
    .ai-services-grid {
        grid-template-columns: 1fr;
        gap: 6px;
    }
    
    .ai-service-card {
        padding: 10px;
    }
    
    .ai-stats-grid {
        grid-template-columns: 1fr;
        gap: 6px;
    }
    
    .ai-stat {
        padding: 10px;
    }
    
    .ai-quick-actions {
        padding: 10px 12px;
        gap: 4px;
    }
    
    .ai-quick-btn {
        padding: 5px 10px;
        font-size: 11px;
    }
    
    .ai-input-container {
        padding: 10px 12px;
        gap: 8px;
    }
    
    .ai-input-container input {
        padding: 8px 12px;
        font-size: 13px;
    }
    
    .ai-send-btn {
        width: 36px;
        height: 36px;
        font-size: 14px;
    }
    
    .ai-widget-header {
        padding: 10px 12px;
    }
    
    .ai-header-info {
        gap: 8px;
    }
    
    .ai-avatar {
        width: 35px;
        height: 35px;
        font-size: 16px;
    }
    
    .ai-avatar .bigfoot-icon {
        width: 22px;
        height: 22px;
    }
    
    .ai-header-text h4 {
        font-size: 15px;
    }
    
    .ai-status {
        font-size: 11px;
    }
}

/* Landscape Mobile */
@media (max-width: 768px) and (orientation: landscape) {
    .ai-widget-container {
        height: calc(100vh - 40px);
        bottom: 35px;
    }
    
    .ai-messages {
        min-height: 150px;
    }
}

/* Very small screens */
@media (max-width: 360px) {
    .ai-widget {
        bottom: 10px;
        right: 8px;
        left: auto;
    }
    
    .ai-widget-container {
        width: calc(100vw - 16px);
        right: 8px;
        left: auto;
        bottom: 75px;
        border-radius: 8px;
    }
    
    .ai-widget-toggle {
        width: 50px;
        height: 50px;
        position: fixed;
        right: 8px;
        bottom: 10px;
        left: auto;
    }
    
    .bigfoot-icon {
        width: 50px;
        height: 50px;
    }
    
    .ai-message-content {
        max-width: 90%;
    }
    
    .ai-input-container input {
        padding: 6px 10px;
        font-size: 12px;
    }
    
    .ai-send-btn {
        width: 32px;
        height: 32px;
        font-size: 12px;
    }
}
