/**
 * Kairo Chat Widget Styles
 * Modern, clean, conversational design
 * Mobile-first, accessible, performant
 */

/* ============================================
   BASE WIDGET CONTAINER
   ============================================ */

#kairo-chat-widget {
    --kairo-primary: #2563eb;
    --kairo-primary-hover: #1d4ed8;
    --kairo-text: #1f2937;
    --kairo-text-light: #6b7280;
    --kairo-bg: #ffffff;
    --kairo-bg-secondary: #f9fafb;
    --kairo-border: #e5e7eb;
    --kairo-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
    --kairo-shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.15);
    --kairo-radius: 12px;
    --kairo-transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    
    position: fixed;
    z-index: 999999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 15px;
    line-height: 1.5;
}

/* Position variants */
#kairo-chat-widget[data-position="bottom-right"] {
    bottom: 20px;
    right: 20px;
}

#kairo-chat-widget[data-position="bottom-left"] {
    bottom: 20px;
    left: 20px;
}

#kairo-chat-widget[data-position="top-right"] {
    top: 20px;
    right: 20px;
}

#kairo-chat-widget[data-position="top-left"] {
    top: 20px;
    left: 20px;
}

/* Dark theme */
#kairo-chat-widget[data-theme="dark"] {
    --kairo-text: #f9fafb;
    --kairo-text-light: #9ca3af;
    --kairo-bg: #1f2937;
    --kairo-bg-secondary: #111827;
    --kairo-border: #374151;
}

/* ============================================
   TRIGGER BUTTON
   ============================================ */

.kairo-trigger {
    position: relative;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--kairo-primary) 0%, #3b82f6 100%);
    border: none;
    box-shadow: var(--kairo-shadow);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--kairo-transition);
    color: white;
}

.kairo-trigger:hover {
    transform: scale(1.05);
    box-shadow: var(--kairo-shadow-lg);
}

.kairo-trigger:active {
    transform: scale(0.95);
}

.kairo-trigger-icon {
    width: 28px;
    height: 28px;
    color: white;
}

/* Open state */
#kairo-chat-widget.kairo-open .kairo-trigger {
    background: linear-gradient(135deg, #64748b 0%, #475569 100%);
}

/* Unread badge */
.kairo-unread-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #ef4444;
    color: white;
    border-radius: 10px;
    padding: 2px 6px;
    font-size: 11px;
    font-weight: 600;
    min-width: 18px;
    text-align: center;
    box-shadow: 0 2px 8px rgba(239, 68, 68, 0.3);
}

/* ============================================
   CHAT WINDOW
   ============================================ */

.kairo-chat-window {
    position: absolute;
    bottom: 80px;
    width: 380px;
    max-width: calc(100vw - 40px);
    height: 600px;
    max-height: calc(100vh - 120px);
    background: var(--kairo-bg);
    border-radius: var(--kairo-radius);
    box-shadow: var(--kairo-shadow-lg);
    display: flex;
    flex-direction: column;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    transition: var(--kairo-transition);
    pointer-events: none;
    overflow: hidden;
}

#kairo-chat-widget.kairo-open .kairo-chat-window {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* Position adjustments */
#kairo-chat-widget[data-position="bottom-right"] .kairo-chat-window,
#kairo-chat-widget[data-position="top-right"] .kairo-chat-window {
    right: 0;
}

#kairo-chat-widget[data-position="bottom-left"] .kairo-chat-window,
#kairo-chat-widget[data-position="top-left"] .kairo-chat-window {
    left: 0;
}

#kairo-chat-widget[data-position="top-right"] .kairo-chat-window,
#kairo-chat-widget[data-position="top-left"] .kairo-chat-window {
    bottom: auto;
    top: 80px;
}

/* Minimized state */
#kairo-chat-widget.kairo-minimized .kairo-chat-window {
    height: auto;
}

/* ============================================
   HEADER
   ============================================ */

.kairo-header {
    background: var(--kairo-bg);
    border-bottom: 1px solid var(--kairo-border);
    padding: 16px;
    flex-shrink: 0;
}

.kairo-header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.kairo-branding {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    min-width: 0;
}

.kairo-logo {
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    color: var(--kairo-primary);
}

.kairo-title {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.kairo-name {
    font-weight: 600;
    font-size: 16px;
    color: var(--kairo-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.kairo-status {
    font-size: 12px;
    color: var(--kairo-text-light);
    display: flex;
    align-items: center;
    gap: 4px;
}

.kairo-status::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #10b981;
    display: inline-block;
    animation: pulse 2s infinite;
}

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

.kairo-header-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

.kairo-action-btn {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    background: transparent;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--kairo-text-light);
    transition: var(--kairo-transition);
}

.kairo-action-btn:hover {
    background: var(--kairo-bg-secondary);
    color: var(--kairo-text);
}

.kairo-action-btn svg {
    width: 20px;
    height: 20px;
}

/* Usage bar (free plan) */
.kairo-usage-bar {
    margin-top: 12px;
    background: var(--kairo-bg-secondary);
    border-radius: 4px;
    height: 6px;
    position: relative;
    overflow: hidden;
}

.kairo-usage-fill {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    background: linear-gradient(90deg, var(--kairo-primary), #3b82f6);
    transition: width 0.5s ease;
    border-radius: 4px;
}

.kairo-usage-text {
    display: block;
    margin-top: 4px;
    font-size: 11px;
    color: var(--kairo-text-light);
    text-align: center;
}

/* ============================================
   MESSAGES CONTAINER
   ============================================ */

.kairo-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    background: var(--kairo-bg-secondary);
}

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

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

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

.kairo-messages::-webkit-scrollbar-thumb:hover {
    background: var(--kairo-text-light);
}

/* ============================================
   MESSAGES
   ============================================ */

.kairo-message {
    display: flex;
    gap: 8px;
    animation: slideIn 0.3s ease;
}

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

.kairo-message-user {
    justify-content: flex-end;
}

.kairo-message-content {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 12px;
    word-wrap: break-word;
}

.kairo-message-user .kairo-message-content {
    background: var(--kairo-primary);
    color: white;
    border-bottom-right-radius: 4px;
}

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

.kairo-message-system .kairo-message-content {
    background: #fef3c7;
    color: #92400e;
    border: 1px solid #fbbf24;
    max-width: 100%;
    text-align: center;
    font-size: 14px;
}

[data-theme="dark"] .kairo-message-system .kairo-message-content {
    background: #451a03;
    color: #fbbf24;
}

/* Message text formatting */
.kairo-message-content p {
    margin: 0 0 8px 0;
}

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

.kairo-message-content strong {
    font-weight: 600;
}

.kairo-message-content em {
    font-style: italic;
}

.kairo-message-content code {
    background: rgba(0, 0, 0, 0.05);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Monaco', 'Courier New', monospace;
    font-size: 13px;
}

.kairo-message-content pre {
    background: rgba(0, 0, 0, 0.05);
    padding: 12px;
    border-radius: 6px;
    overflow-x: auto;
    margin: 8px 0;
}

.kairo-message-content pre code {
    background: none;
    padding: 0;
}

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

.kairo-message-user .kairo-message-content a {
    color: white;
}

.kairo-plan-notice {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--kairo-border);
    font-size: 13px;
    color: var(--kairo-text-light);
}

.kairo-plan-notice a {
    color: var(--kairo-primary);
    font-weight: 500;
}

/* Coherence indicator */
.kairo-coherence {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 8px;
    font-size: 12px;
    color: var(--kairo-text-light);
}

/* ============================================
   TYPING INDICATOR
   ============================================ */

.kairo-typing {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    background: var(--kairo-bg);
    border: 1px solid var(--kairo-border);
    border-radius: 12px;
    border-bottom-left-radius: 4px;
    width: fit-content;
    margin: 0 16px;
}

.kairo-typing span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--kairo-text-light);
    animation: bounce 1.4s infinite ease-in-out;
}

.kairo-typing span:nth-child(1) {
    animation-delay: -0.32s;
}

.kairo-typing span:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes bounce {
    0%, 80%, 100% {
        transform: translateY(0);
        opacity: 0.5;
    }
    40% {
        transform: translateY(-6px);
        opacity: 1;
    }
}

/* ============================================
   INPUT AREA
   ============================================ */

.kairo-input-area {
    display: flex;
    gap: 8px;
    padding: 16px;
    background: var(--kairo-bg);
    border-top: 1px solid var(--kairo-border);
    flex-shrink: 0;
}

.kairo-input {
    flex: 1;
    min-height: 42px;
    max-height: 120px;
    padding: 10px 14px;
    border: 1px solid var(--kairo-border);
    border-radius: 8px;
    background: var(--kairo-bg);
    color: var(--kairo-text);
    font-family: inherit;
    font-size: 15px;
    line-height: 1.5;
    resize: none;
    outline: none;
    transition: var(--kairo-transition);
}

.kairo-input:focus {
    border-color: var(--kairo-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.kairo-input::placeholder {
    color: var(--kairo-text-light);
}

.kairo-send-btn {
    width: 42px;
    height: 42px;
    flex-shrink: 0;
    border-radius: 8px;
    background: var(--kairo-bg-secondary);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--kairo-text-light);
    transition: var(--kairo-transition);
}

.kairo-send-btn:hover:not(:disabled) {
    background: var(--kairo-primary);
    color: white;
}

.kairo-send-btn.kairo-active {
    background: var(--kairo-primary);
    color: white;
}

.kairo-send-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.kairo-send-btn svg {
    width: 20px;
    height: 20px;
}

/* ============================================
   FOOTER
   ============================================ */

.kairo-footer {
    padding: 10px 16px;
    background: var(--kairo-bg-secondary);
    border-top: 1px solid var(--kairo-border);
    text-align: center;
    flex-shrink: 0;
}

.kairo-powered-by {
    font-size: 12px;
    color: var(--kairo-text-light);
    text-decoration: none;
    transition: color 0.2s;
}

.kairo-powered-by:hover {
    color: var(--kairo-primary);
}

/* ============================================
   MOBILE RESPONSIVE
   ============================================ */

@media (max-width: 480px) {
    #kairo-chat-widget {
        bottom: 0 !important;
        right: 0 !important;
        left: 0 !important;
        top: auto !important;
    }
    
    .kairo-trigger {
        position: fixed;
        bottom: 16px;
        right: 16px;
        width: 56px;
        height: 56px;
    }
    
    .kairo-chat-window {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100% !important;
        max-width: 100%;
        height: 100% !important;
        max-height: 100vh;
        border-radius: 0;
        transform: translateY(100%);
    }
    
    #kairo-chat-widget.kairo-open .kairo-chat-window {
        transform: translateY(0);
    }
    
    .kairo-header {
        padding-top: max(16px, env(safe-area-inset-top));
    }
    
    .kairo-input-area {
        padding-bottom: max(16px, env(safe-area-inset-bottom));
    }
}

/* ============================================
   ACCESSIBILITY
   ============================================ */

.kairo-trigger:focus-visible,
.kairo-action-btn:focus-visible,
.kairo-send-btn:focus-visible {
    outline: 2px solid var(--kairo-primary);
    outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    #kairo-chat-widget {
        --kairo-border: currentColor;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ============================================
   PRINT STYLES
   ============================================ */

@media print {
    #kairo-chat-widget {
        display: none !important;
    }
}

/* ============================================
   FEATURE GATING STYLES
   ============================================ */

.kairo-feature-locked {
    position: relative;
    opacity: 0.5;
    pointer-events: none;
}

.kairo-feature-locked::after {
    content: '🔒 Upgrade Required';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--kairo-bg);
    padding: 8px 12px;
    border-radius: 6px;
    box-shadow: var(--kairo-shadow);
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
    z-index: 1;
}

/* Plan-specific styles */
.kairo-plan-free .kairo-pro-feature {
    opacity: 0.4;
    cursor: not-allowed;
}

.kairo-plan-free .kairo-enterprise-feature {
    opacity: 0.4;
    cursor: not-allowed;
}

.kairo-plan-pro .kairo-enterprise-feature {
    opacity: 0.4;
    cursor: not-allowed;
}
