/**
 * ASTA AI Chat Widget Styles
 * Branded for Alexander Shunnarah Trial Attorneys
 */

/* CSS Custom Properties */
.asta-chat-widget {
    --asta-primary: #171717;
    --asta-secondary: #Eb0010;
    --asta-text-dark: #171717;
    --asta-text-light: #ffffff;
    --asta-text-muted: #6b7280;
    --asta-bg-light: #f8f9fa;
    --asta-bg-white: #ffffff;
    --asta-border: #e5e7eb;
    --asta-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    --asta-shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.1);
    --asta-radius: 16px;
    --asta-radius-sm: 8px;
    --asta-transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Reset for widget elements */
.asta-chat-widget *,
.asta-chat-widget *::before,
.asta-chat-widget *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* Container positioning */
.asta-chat-widget {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 999999;
}

/* Toggle Button */
.asta-chat-toggle {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: var(--asta-secondary);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--asta-shadow);
    transition: var(--asta-transition);
    position: relative;
    overflow: hidden;
}

.asta-chat-toggle:hover {
    transform: scale(1.08);
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.2);
    filter: brightness(1.1);
}

.asta-chat-toggle svg {
    width: 28px;
    height: 28px;
    color: var(--asta-text-light);
    transition: var(--asta-transition);
    position: relative;
    z-index: 1;
}

.asta-chat-toggle .asta-icon-chat {
    opacity: 1;
    transform: scale(1);
}

.asta-chat-toggle .asta-icon-close {
    position: absolute;
    opacity: 0;
    transform: scale(0.5) rotate(-90deg);
}

.asta-chat-toggle[aria-expanded="true"] .asta-icon-chat {
    opacity: 0;
    transform: scale(0.5) rotate(90deg);
}

.asta-chat-toggle[aria-expanded="true"] .asta-icon-close {
    opacity: 1;
    transform: scale(1) rotate(0deg);
}

/* Pulse animation for attention */
@keyframes asta-pulse {
    0%, 100% {
        box-shadow: var(--asta-shadow), 0 0 0 0 rgba(235, 0, 16, 0.4);
    }
    50% {
        box-shadow: var(--asta-shadow), 0 0 0 12px rgba(235, 0, 16, 0);
    }
}

.asta-chat-toggle:not([aria-expanded="true"]) {
    animation: asta-pulse 3s ease-in-out infinite;
}

.asta-chat-toggle:hover {
    animation: none;
}

/* Chat Container */
.asta-chat-container {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 400px;
    max-width: calc(100vw - 48px);
    height: 600px;
    max-height: calc(100vh - 140px);
    background: var(--asta-bg-white);
    border-radius: var(--asta-radius);
    box-shadow: var(--asta-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px) scale(0.95);
    transform-origin: bottom right;
    transition: var(--asta-transition);
}

.asta-chat-container.asta-open {
    opacity: 1 !important;
    visibility: visible !important;
    transform: translateY(0) scale(1);
}

/* Header */
.asta-chat-header {
    background: linear-gradient(135deg, var(--asta-primary) 0%, #2d2d4a 100%);
    padding: 12px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    gap: 8px;
}

.asta-chat-header-content {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    min-width: 0;
    overflow: hidden;
}

.asta-chat-logo {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.asta-logo-img {
    max-width: 32px;
    max-height: 32px;
    width: auto;
    height: auto;
    object-fit: contain;
}

.asta-logo-icon {
    width: 32px;
    height: 32px;
    color: var(--asta-secondary);
}

.asta-chat-header-text {
    color: var(--asta-text-light);
    min-width: 0;
    overflow: hidden;
    flex: 1;
}

.asta-chat-title {
    font-size: 14px;
    font-weight: 600;
    margin: 0;
    letter-spacing: -0.02em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.asta-chat-subtitle {
    font-size: 11px;
    opacity: 0.8;
    margin: 1px 0 0;
    white-space: nowrap;
}

.asta-chat-header-buttons {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-shrink: 0;
    margin-left: 8px;
}

.asta-chat-back {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.15);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--asta-transition);
    flex-shrink: 0;
    margin-right: 2px;
}

.asta-chat-close {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--asta-secondary);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--asta-transition);
    flex-shrink: 0;
}

.asta-chat-back:hover {
    background: rgba(255, 255, 255, 0.25);
}

.asta-chat-close:hover {
    filter: brightness(1.1);
}

.asta-chat-back svg,
.asta-chat-close svg {
    width: 16px;
    height: 16px;
    color: var(--asta-text-light);
}

/* Hidden utility class */
.asta-hidden {
    display: none !important;
}

/* Chat History Panel */
.asta-chat-history {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--asta-bg-light);
}

.asta-history-list {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
}

.asta-history-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    background: var(--asta-bg-white);
    border-radius: var(--asta-radius-sm);
    margin-bottom: 8px;
    cursor: pointer;
    transition: var(--asta-transition);
    border: 1px solid var(--asta-border);
}

.asta-history-item:hover {
    border-color: var(--asta-secondary);
    box-shadow: var(--asta-shadow-sm);
}

.asta-history-item-icon {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--asta-bg-white);
    border: 1px solid var(--asta-border);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.asta-history-item-icon img {
    width: 24px;
    height: 24px;
    object-fit: contain;
}

.asta-history-item-content {
    flex: 1;
    min-width: 0;
}

.asta-history-item-title {
    font-weight: 600;
    font-size: 14px;
    color: var(--asta-text-dark);
    margin: 0 0 2px;
}

.asta-history-item-preview {
    font-size: 13px;
    color: var(--asta-text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin: 0;
}

.asta-history-item-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
    flex-shrink: 0;
}

.asta-history-item-time {
    font-size: 11px;
    color: var(--asta-text-muted);
}

.asta-history-item-delete {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: transparent;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: var(--asta-transition);
}

.asta-history-item:hover .asta-history-item-delete {
    opacity: 1;
}

.asta-history-item-delete:hover {
    background: #fef2f2;
}

.asta-history-item-delete svg {
    width: 14px;
    height: 14px;
    color: #dc2626;
}

.asta-history-empty {
    text-align: center;
    padding: 40px 20px;
    color: var(--asta-text-muted);
}

.asta-history-empty-icon {
    width: 48px;
    height: 48px;
    margin: 0 auto 12px;
    opacity: 0.5;
}

.asta-history-empty-icon svg {
    width: 100%;
    height: 100%;
    color: var(--asta-text-muted);
}

.asta-history-footer {
    padding: 16px;
    background: var(--asta-bg-white);
    border-top: 1px solid var(--asta-border);
    flex-shrink: 0;
}

.asta-start-new-chat {
    width: 100%;
    padding: 14px 20px;
    background: var(--asta-primary);
    color: var(--asta-text-light);
    border: none;
    border-radius: var(--asta-radius-sm);
    font-family: inherit;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--asta-transition);
}

.asta-start-new-chat:hover {
    filter: brightness(1.15);
}

/* Messages Area */
.asta-chat-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    background: linear-gradient(180deg, var(--asta-bg-light) 0%, var(--asta-bg-white) 100%);
    min-height: 0; /* Fix flexbox overflow issue */
}

/* Custom scrollbar */
.asta-chat-messages::-webkit-scrollbar {
    width: 6px;
}

.asta-chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.asta-chat-messages::-webkit-scrollbar-thumb {
    background: var(--asta-border);
    border-radius: 3px;
}

.asta-chat-messages::-webkit-scrollbar-thumb:hover {
    background: var(--asta-text-muted);
}

/* Message Bubbles */
.asta-message {
    display: flex;
    gap: 10px;
    max-width: 85%;
    animation: asta-message-in 0.3s ease-out;
}

@keyframes asta-message-in {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.asta-message-user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.asta-message-assistant {
    align-self: flex-start;
}

.asta-message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.asta-message-assistant .asta-message-avatar {
    background: #ffffff;
    border: 1px solid #e5e7eb;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.asta-message-avatar svg {
    width: 18px;
    height: 18px;
    color: var(--asta-secondary);
}

.asta-avatar-logo {
    width: 20px;
    height: 20px;
    object-fit: contain;
}

.asta-message-user .asta-message-avatar {
    background: #1e51c0;
}

.asta-message-user .asta-message-avatar svg {
    color: #ffffff;
}

.asta-message-content {
    padding: 12px 16px;
    border-radius: var(--asta-radius-sm);
    line-height: 1.6;
}

.asta-message-assistant .asta-message-content {
    background: var(--asta-bg-white);
    color: var(--asta-text-dark);
    border: 1px solid var(--asta-border);
    border-bottom-left-radius: 4px;
}

.asta-message-user .asta-message-content {
    background: linear-gradient(135deg, var(--asta-primary) 0%, #2d2d4a 100%);
    color: var(--asta-text-light);
    border-bottom-right-radius: 4px;
}

.asta-message-content p {
    margin: 0 0 8px;
}

.asta-message-content p:last-child {
    margin-bottom: 0;
}

.asta-message-content ul,
.asta-message-content ol {
    margin: 8px 0;
    padding-left: 20px;
}

.asta-message-content li {
    margin: 4px 0;
}

.asta-message-content a {
    color: var(--asta-secondary);
    text-decoration: underline;
}

.asta-message-user .asta-message-content a {
    color: var(--asta-secondary);
}

/* Typing Indicator */
.asta-typing {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
}

.asta-typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--asta-text-muted);
    animation: asta-typing-bounce 1.4s ease-in-out infinite;
}

.asta-typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.asta-typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes asta-typing-bounce {
    0%, 60%, 100% {
        transform: translateY(0);
    }
    30% {
        transform: translateY(-8px);
    }
}

/* Input Area */
.asta-chat-input-area {
    padding: 12px 16px 16px;
    background: var(--asta-bg-white);
    border-top: 1px solid var(--asta-border);
    flex-shrink: 0;
}

.asta-chat-disclaimer {
    font-size: 10px;
    color: var(--asta-text-muted);
    text-align: center;
    margin-bottom: 10px;
    padding: 6px;
    background: var(--asta-bg-light);
    border-radius: 4px;
}

.asta-chat-form {
    margin: 0;
}

.asta-chat-input-wrapper {
    display: flex;
    gap: 10px;
    align-items: center;
    background: var(--asta-bg-light);
    border: 2px solid var(--asta-secondary);
    border-radius: var(--asta-radius-sm);
    padding: 10px 10px 10px 16px;
    min-height: 56px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.asta-chat-input-wrapper:focus-within {
    border-color: var(--asta-secondary);
    box-shadow: 0 0 0 3px rgba(235, 0, 16, 0.15);
}

.asta-chat-input {
    flex: 1;
    border: none;
    background: transparent;
    font-family: inherit;
    font-size: 14px;
    line-height: 1.5;
    resize: none;
    min-height: 24px;
    max-height: 100px;
    color: var(--asta-text-dark);
    padding: 0;
    margin: 0;
    vertical-align: middle;
}

.asta-chat-input::placeholder {
    color: var(--asta-text-muted);
    line-height: 24px;
}

.asta-chat-input:focus {
    outline: none;
}

.asta-chat-send {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: #171717;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--asta-transition);
    flex-shrink: 0;
    align-self: center;
}

.asta-chat-send:hover:not(:disabled) {
    transform: scale(1.08);
    box-shadow: var(--asta-shadow-sm);
}

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

.asta-chat-send svg {
    width: 18px;
    height: 18px;
    color: var(--asta-text-light);
}

/* Footer */
.asta-chat-footer {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-top: 10px;
    font-size: 12px;
    color: var(--asta-text-muted);
}

.asta-chat-phone {
    color: var(--asta-primary);
    font-weight: 600;
    text-decoration: none;
    transition: color 0.2s ease;
}

.asta-chat-phone:hover {
    color: var(--asta-secondary);
}

/* Error State */
.asta-message-error {
    background: #fef2f2 !important;
    border-color: #fecaca !important;
    color: #991b1b !important;
}

/* Quick Reply Buttons */
.asta-quick-replies {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 12px 20px;
    justify-content: flex-start;
    animation: asta-message-in 0.3s ease-out;
}

.asta-quick-reply-btn {
    background: var(--asta-bg-white);
    border: 1.5px solid var(--asta-primary);
    color: var(--asta-primary);
    padding: 10px 18px;
    border-radius: 20px;
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    line-height: 1.3;
}

.asta-quick-reply-btn:hover {
    background: var(--asta-primary);
    color: var(--asta-text-light);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}

.asta-quick-reply-btn:active {
    transform: translateY(0);
    box-shadow: none;
}

.asta-quick-reply-btn:focus {
    outline: 2px solid var(--asta-secondary);
    outline-offset: 2px;
}

/* Mobile quick replies */
@media (max-width: 480px) {
    .asta-quick-replies {
        padding: 10px 16px;
        gap: 6px;
    }
    
    .asta-quick-reply-btn {
        padding: 8px 14px;
        font-size: 13px;
        flex-grow: 1;
        text-align: center;
    }
}

/* Mobile Responsive - Fullscreen Mode */
@media (max-width: 480px) {
    .asta-chat-widget {
        bottom: 16px;
        right: 16px;
    }
    
    /* Fullscreen chat container on mobile */
    .asta-chat-container {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: 100%;
        max-width: 100%;
        max-height: 100%;
        border-radius: 0;
        transform: translateY(100%);
        transform-origin: bottom center;
        display: flex;
        flex-direction: column;
    }
    
    .asta-chat-container.asta-open {
        transform: translateY(0);
    }
    
    /* Hide toggle button when chat is open on mobile */
    .asta-chat-widget.asta-mobile-open .asta-chat-toggle {
        display: none !important;
    }
    
    .asta-chat-toggle {
        width: 56px;
        height: 56px;
        transition: var(--asta-transition), opacity 0.2s ease;
    }
    
    .asta-chat-toggle svg {
        width: 24px;
        height: 24px;
    }
    
    /* Mobile header adjustments */
    .asta-chat-header {
        padding: 16px;
        padding-top: max(16px, env(safe-area-inset-top));
    }
    
    .asta-chat-title {
        font-size: 16px;
    }
    
    .asta-chat-subtitle {
        font-size: 12px;
    }
    
    /* Larger close button on mobile */
    .asta-chat-close {
        width: 36px;
        height: 36px;
    }
    
    .asta-chat-close svg {
        width: 18px;
        height: 18px;
    }
    
    /* Messages area fills available space */
    .asta-chat-messages {
        padding: 16px;
        padding-bottom: 8px;
    }
    
    .asta-message {
        max-width: 90%;
    }
    
    /* Input area adjustments for mobile */
    .asta-chat-input-area {
        padding: 12px 16px;
        padding-bottom: max(16px, env(safe-area-inset-bottom));
        flex-shrink: 0;
    }
    
    .asta-chat-input-wrapper {
        min-height: 48px;
        padding: 8px 8px 8px 14px;
    }
    
    .asta-chat-input {
        font-size: 16px; /* Prevents iOS zoom on focus */
    }
    
    /* Quick replies on mobile */
    .asta-quick-replies {
        padding: 8px 16px;
    }
    
    .asta-quick-reply-btn {
        padding: 10px 16px;
        font-size: 14px;
    }
    
    /* History panel fullscreen on mobile */
    .asta-chat-history {
        height: 100%;
    }
    
    .asta-history-list {
        padding: 12px 16px;
    }
    
    .asta-history-footer {
        padding: 16px;
        padding-bottom: max(16px, env(safe-area-inset-bottom));
    }
}

/* Prevent body scroll when chat is open on mobile */
body.asta-chat-open-mobile {
    overflow: hidden !important;
    touch-action: none;
}

/* Tablet adjustments */
@media (min-width: 481px) and (max-width: 768px) {
    .asta-chat-container {
        width: 380px;
        height: 550px;
    }
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
    .asta-chat-widget *,
    .asta-chat-widget *::before,
    .asta-chat-widget *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .asta-chat-container {
        border: 2px solid var(--asta-text-dark);
    }
    
    .asta-message-content {
        border-width: 2px;
    }
}

/* Print styles - hide widget */
@media print {
    .asta-chat-widget {
        display: none !important;
    }
}
