/**
 * ArchiFlow AI Chat Widget Styles
 * Enterprise-grade floating chat interface - ArchiFlow Design System v2
 */

/* ========================================
   CSS Variables - ArchiFlow Professional Theme
   ======================================== */
#archiflow-chat-container {
    /* Primary Brand Colors */
    --af-green-light: #6ee7b7;
    --af-green-primary: #10b981;
    --af-green-dark: #059669;
    --af-teal-light: #5eead4;
    --af-teal-primary: #14b8a6;
    --af-teal-dark: #0f766e;

    /* Background Layers */
    --af-bg-primary: #0f172a;
    --af-bg-secondary: #1e293b;
    --af-bg-tertiary: #334155;
    --af-bg-elevated: #1e293b;
    --af-bg-hover: rgba(255, 255, 255, 0.04);

    /* Text Hierarchy */
    --af-text-primary: #f1f5f9;
    --af-text-secondary: #94a3b8;
    --af-text-muted: #64748b;
    --af-text-brand: #6ee7b7;

    /* Borders */
    --af-border-subtle: rgba(148, 163, 184, 0.1);
    --af-border-default: rgba(148, 163, 184, 0.15);
    --af-border-hover: rgba(148, 163, 184, 0.25);
    --af-border-accent: var(--af-green-primary);

    /* Status Colors */
    --af-warning: #f59e0b;
    --af-danger: #ef4444;
    --af-blue: #3b82f6;
    --af-purple: #8b5cf6;

    /* Shadows */
    --af-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --af-shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
    --af-shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.5);
    --af-shadow-glow: 0 0 20px rgba(16, 185, 129, 0.15);
}

/* ========================================
   Container - Fixed Position
   ======================================== */
#archiflow-chat-container {
    position: fixed;
    bottom: 24px;
    left: 24px;
    z-index: 10000;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

/* ========================================
   Toggle Button - Floating FAB (Professional)
   ======================================== */
.archiflow-chat-btn {
    width: 56px;
    height: 56px;
    border-radius: 16px;
    background: var(--af-green-primary);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--af-shadow-lg), var(--af-shadow-glow);
    transition: all 0.2s ease;
    color: white;
    position: relative;
    overflow: visible;
}

.archiflow-chat-btn:hover {
    transform: translateY(-2px);
    background: var(--af-green-dark);
    box-shadow: var(--af-shadow-lg), 0 0 30px rgba(16, 185, 129, 0.25);
}

.archiflow-chat-btn:active {
    transform: translateY(0);
}

.archiflow-chat-btn svg {
    width: 24px;
    height: 24px;
}

/* AI Badge on button - minimal */
.archiflow-chat-btn::after {
    content: 'AI';
    position: absolute;
    top: -6px;
    right: -6px;
    background: var(--af-bg-secondary);
    color: var(--af-green-primary);
    font-size: 9px;
    font-weight: 700;
    padding: 3px 6px;
    border-radius: 6px;
    border: 1px solid var(--af-border-default);
    letter-spacing: 0.5px;
}

/* ========================================
   Chat Panel - Main Container (Professional)
   ======================================== */
.archiflow-chat-panel {
    position: absolute;
    bottom: 72px;
    left: 0;
    width: 400px;
    height: 560px;
    background: var(--af-bg-primary);
    border-radius: 16px;
    box-shadow: var(--af-shadow-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: opacity 0.15s ease, transform 0.15s ease, visibility 0.15s;
    border: 1px solid var(--af-border-subtle);
}

.archiflow-chat-panel.hidden {
    opacity: 0;
    transform: translateY(12px) scale(0.98);
    pointer-events: none;
    visibility: hidden;
}

/* ========================================
   Header - Clean Professional Style
   ======================================== */
.archiflow-chat-header {
    padding: 12px 16px;
    background: var(--af-bg-secondary);
    border-bottom: 1px solid var(--af-border-subtle);
    color: var(--af-text-primary);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.archiflow-chat-header-title {
    font-weight: 600;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--af-text-primary);
}

.archiflow-chat-header-title svg {
    width: 18px;
    height: 18px;
    color: var(--af-green-primary);
}

.archiflow-chat-header-actions {
    display: flex;
    align-items: center;
    gap: 2px;
}

.archiflow-chat-header button {
    background: transparent;
    border: none;
    color: var(--af-text-muted);
    width: 28px;
    height: 28px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
}

.archiflow-chat-header button:hover {
    background: var(--af-bg-hover);
    color: var(--af-text-primary);
}

.archiflow-chat-header button:active {
    transform: scale(0.95);
}

/* ========================================
   Tabs Container - Segmented Control Style
   ======================================== */
.archiflow-chat-tabs {
    display: flex;
    background: var(--af-bg-primary);
    padding: 8px 12px;
    gap: 4px;
}

.archiflow-tab {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 12px;
    background: transparent;
    border: none;
    border-radius: 8px;
    color: var(--af-text-muted);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
    position: relative;
}

.archiflow-tab:hover {
    color: var(--af-text-secondary);
    background: var(--af-bg-hover);
}

.archiflow-tab.active {
    color: var(--af-text-primary);
    background: var(--af-bg-secondary);
    box-shadow: var(--af-shadow-sm);
}

.archiflow-tab svg {
    flex-shrink: 0;
    width: 14px;
    height: 14px;
}

/* ========================================
   Tab Content Areas
   ======================================== */
.archiflow-tab-content {
    display: none;
    flex: 1;
    overflow-y: auto;
    background: var(--af-bg-primary);
}

.archiflow-tab-content.active {
    display: flex;
    flex-direction: column;
}

/* ========================================
   Search Results Container
   ======================================== */
.archiflow-search-results {
    flex: 1;
    padding: 12px;
    overflow-y: auto;
}

.search-welcome {
    padding: 24px 16px;
    text-align: center;
    color: var(--af-text-secondary);
}

.search-welcome strong {
    color: var(--af-text-primary);
    font-size: 14px;
    font-weight: 600;
}

.search-welcome p {
    margin: 8px 0;
    font-size: 13px;
    line-height: 1.5;
}

.search-welcome code {
    background: var(--af-bg-secondary);
    padding: 2px 6px;
    border-radius: 4px;
    color: var(--af-green-light);
    font-size: 12px;
    font-family: 'SF Mono', Monaco, Consolas, monospace;
}

.search-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 32px;
    color: var(--af-text-muted);
    font-size: 13px;
}

.loading-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid var(--af-border-default);
    border-top-color: var(--af-green-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.search-error {
    padding: 16px;
    text-align: center;
    color: var(--af-danger);
    background: rgba(239, 68, 68, 0.08);
    border-radius: 8px;
    margin: 8px;
    font-size: 13px;
    border: 1px solid rgba(239, 68, 68, 0.2);
}

.search-empty {
    padding: 24px 16px;
    text-align: center;
    color: var(--af-text-secondary);
    font-size: 13px;
}

.search-hint {
    font-size: 12px;
    color: var(--af-text-muted);
    margin-top: 8px;
}

.search-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    padding: 0 4px 10px;
    border-bottom: 1px solid var(--af-border-subtle);
}

.search-query {
    color: var(--af-text-secondary);
    font-size: 12px;
    font-weight: 500;
}

.search-timing {
    font-size: 11px;
    color: var(--af-green-primary);
    font-family: 'SF Mono', Monaco, Consolas, monospace;
}

.search-section {
    margin-bottom: 16px;
}

.search-section h4 {
    color: var(--af-text-muted);
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    font-weight: 600;
    margin: 0 0 8px 4px;
}

/* ========================================
   Result Cards - Clean List Style
   ======================================== */
.result-card {
    background: var(--af-bg-secondary);
    border: 1px solid var(--af-border-subtle);
    border-radius: 10px;
    padding: 10px 12px;
    margin-bottom: 6px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    transition: all 0.12s ease;
}

.result-card:hover {
    background: var(--af-bg-tertiary);
    border-color: var(--af-border-default);
}

.result-main {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    min-width: 0;
}

.result-icon {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.3px;
    background: var(--af-bg-tertiary);
    color: var(--af-green-primary);
}

.result-icon.diagram-icon {
    background: rgba(59, 130, 246, 0.1);
    color: var(--af-blue);
}

.result-icon.device-icon {
    background: rgba(245, 158, 11, 0.1);
    color: var(--af-warning);
}

.result-info {
    flex: 1;
    min-width: 0;
}

.result-info strong {
    display: block;
    color: var(--af-text-primary);
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.result-detail {
    display: inline-block;
    font-size: 11px;
    color: var(--af-text-muted);
    margin-right: 6px;
}

.result-context {
    display: block;
    font-size: 11px;
    color: var(--af-text-muted);
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.result-ip {
    display: inline-block;
    font-size: 10px;
    font-family: 'SF Mono', Monaco, Consolas, monospace;
    background: var(--af-bg-tertiary);
    color: var(--af-green-light);
    padding: 2px 5px;
    border-radius: 4px;
    margin-top: 3px;
}

.result-status {
    font-size: 9px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 3px 6px;
    border-radius: 4px;
    font-weight: 600;
    flex-shrink: 0;
}

.result-status.status-active {
    background: rgba(16, 185, 129, 0.12);
    color: var(--af-green-primary);
}

.result-status.status-staging {
    background: rgba(245, 158, 11, 0.12);
    color: var(--af-warning);
}

.result-status.status-draft {
    background: var(--af-bg-tertiary);
    color: var(--af-text-muted);
}

/* Result Buttons */
.result-link {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 5px 10px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 500;
    text-decoration: none;
    transition: all 0.12s ease;
    flex-shrink: 0;
    border: none;
    cursor: pointer;
}

.result-link.source-link {
    background: transparent;
    color: var(--af-text-muted);
    border: 1px solid var(--af-border-default);
}

.result-link.source-link:hover {
    color: var(--af-text-secondary);
    border-color: var(--af-border-hover);
    background: var(--af-bg-hover);
}

.result-link.diagram-link {
    background: var(--af-green-primary);
    color: #0f172a;
    font-weight: 600;
}

.result-link.diagram-link:hover {
    background: var(--af-green-light);
}

/* Result Actions - Button Group */
.result-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

/* ========================================
   Messages Container
   ======================================== */
.archiflow-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: var(--af-bg-primary);
}

/* ========================================
   Message Bubbles - Clean Style
   ======================================== */
.chat-message {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 12px;
    line-height: 1.5;
    font-size: 13px;
    word-wrap: break-word;
    animation: message-appear 0.2s ease-out;
}

@keyframes message-appear {
    from {
        opacity: 0;
        transform: translateY(6px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* User Messages - Right aligned */
.chat-message.user {
    align-self: flex-end;
    background: var(--af-green-primary);
    color: #0f172a;
    border-bottom-right-radius: 4px;
}

/* Assistant Messages - Left aligned */
.chat-message.assistant {
    align-self: flex-start;
    background: var(--af-bg-secondary);
    color: var(--af-text-primary);
    border-bottom-left-radius: 4px;
    border: 1px solid var(--af-border-subtle);
}

.chat-message p {
    margin: 0 0 10px 0;
}

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

/* Links in messages - ArchiFlow accent */
.chat-message a {
    color: var(--af-green-light);
    text-decoration: none;
    font-weight: 500;
    transition: all 0.2s;
    border-bottom: 1px solid transparent;
}

.chat-message a:hover {
    color: var(--af-green-primary);
    border-bottom-color: var(--af-green-primary);
}

/* User message links */
.chat-message.user a {
    color: #bfdbfe;
}

.chat-message.user a:hover {
    color: white;
    border-bottom-color: white;
}

/* Lists in messages */
.chat-message ul, .chat-message ol {
    margin: 10px 0;
    padding-left: 20px;
}

.chat-message li {
    margin: 6px 0;
}

/* Code in messages */
.chat-message code {
    background: rgba(0, 0, 0, 0.25);
    padding: 3px 8px;
    border-radius: 6px;
    font-family: 'SF Mono', Monaco, Consolas, monospace;
    font-size: 13px;
    color: var(--af-teal-light);
}

.chat-message.user code {
    background: rgba(255, 255, 255, 0.15);
    color: #bfdbfe;
}

/* Strong/Bold text */
.chat-message strong {
    color: var(--af-text-brand);
    font-weight: 600;
}

.chat-message.user strong {
    color: white;
}

/* ========================================
   Typing Indicator
   ======================================== */
.chat-message.typing {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 18px 22px;
    background: var(--af-bg-tertiary);
    border: 1px solid var(--af-border-default);
}

.chat-message.typing .typing-text {
    color: var(--af-text-secondary);
    font-size: 13px;
    margin-right: 6px;
    font-weight: 500;
}

.chat-message.typing .typing-timer {
    color: var(--af-text-muted);
    font-size: 12px;
    margin-left: 10px;
    font-family: 'SF Mono', Monaco, Consolas, monospace;
    background: rgba(52, 211, 153, 0.1);
    padding: 2px 8px;
    border-radius: 4px;
}

.chat-message.typing .dot {
    width: 8px;
    height: 8px;
    background: var(--af-green-primary);
    border-radius: 50%;
    animation: typing-bounce 1.4s infinite ease-in-out;
    box-shadow: 0 0 8px rgba(52, 211, 153, 0.3);
}

.chat-message.typing .dot:nth-child(2) { animation-delay: 0s; }
.chat-message.typing .dot:nth-child(3) { animation-delay: 0.2s; }
.chat-message.typing .dot:nth-child(4) { animation-delay: 0.4s; }

@keyframes typing-bounce {
    0%, 60%, 100% {
        transform: translateY(0);
        background: var(--af-green-primary);
    }
    30% {
        transform: translateY(-8px);
        background: var(--af-teal-light);
    }
}

/* ========================================
   Error Message
   ======================================== */
.chat-message.error {
    background: linear-gradient(135deg, #7f1d1d 0%, #991b1b 100%);
    color: #fca5a5;
    border: 1px solid #dc2626;
    border-left: 4px solid var(--af-danger);
}

/* ========================================
   Input Container - Clean Professional Style
   ======================================== */
.archiflow-chat-input-container {
    padding: 12px;
    background: var(--af-bg-secondary);
    border-top: 1px solid var(--af-border-subtle);
    display: flex;
    gap: 8px;
    align-items: center;
}

#archiflow-chat-input {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid var(--af-border-default);
    border-radius: 10px;
    background: var(--af-bg-primary);
    color: var(--af-text-primary);
    font-size: 13px;
    outline: none;
    transition: all 0.15s ease;
}

#archiflow-chat-input:focus {
    border-color: var(--af-green-primary);
    box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.1);
}

#archiflow-chat-input::placeholder {
    color: var(--af-text-muted);
    font-size: 12px;
}

/* ========================================
   Send Button - Minimal Style
   ======================================== */
#archiflow-chat-send {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: var(--af-green-primary);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    transition: all 0.15s ease;
    flex-shrink: 0;
}

#archiflow-chat-send:hover {
    background: var(--af-green-dark);
}

#archiflow-chat-send:active {
    transform: scale(0.95);
}

#archiflow-chat-send:disabled {
    background: var(--af-bg-tertiary);
    cursor: not-allowed;
    color: var(--af-text-muted);
}

#archiflow-chat-send svg {
    width: 18px;
    height: 18px;
}

/* ========================================
   RTL Support for Hebrew
   ======================================== */
[dir="rtl"] .chat-message,
.chat-message[dir="rtl"] {
    text-align: right;
}

[dir="rtl"] .chat-message ul,
[dir="rtl"] .chat-message ol {
    padding-left: 0;
    padding-right: 20px;
}

/* Auto-detect RTL content */
.chat-message p[dir="auto"] {
    unicode-bidi: plaintext;
}

/* ========================================
   Scrollbar Styling
   ======================================== */
.archiflow-chat-messages::-webkit-scrollbar {
    width: 8px;
}

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

.archiflow-chat-messages::-webkit-scrollbar-thumb {
    background: var(--af-border-hover);
    border-radius: 4px;
}

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

/* ========================================
   Status Indicator - Minimal
   ======================================== */
.archiflow-chat-status {
    padding: 6px 12px;
    background: var(--af-bg-primary);
    font-size: 10px;
    color: var(--af-text-muted);
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.archiflow-chat-status::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--af-text-muted);
}

.archiflow-chat-status.error {
    color: var(--af-danger);
}

.archiflow-chat-status.error::before {
    background: var(--af-danger);
}

.archiflow-chat-status.connected {
    color: var(--af-green-primary);
}

.archiflow-chat-status.connected::before {
    background: var(--af-green-primary);
}

/* ========================================
   Responsive Adjustments
   ======================================== */
@media (max-width: 480px) {
    #archiflow-chat-container {
        bottom: 12px;
        left: 12px;
        right: 12px;
    }

    .archiflow-chat-panel {
        width: calc(100vw - 24px);
        height: 70vh;
        max-height: 520px;
        left: 0;
        right: 0;
        bottom: 64px;
    }

    .archiflow-chat-btn {
        width: 48px;
        height: 48px;
        border-radius: 12px;
    }

    .archiflow-chat-btn svg {
        width: 20px;
        height: 20px;
    }

    .archiflow-chat-header {
        padding: 10px 12px;
    }

    .archiflow-chat-messages {
        padding: 12px;
        gap: 10px;
    }

    .chat-message {
        max-width: 90%;
        padding: 8px 12px;
        font-size: 12px;
    }
}

/* ========================================
   Animation for Panel Appearance
   ======================================== */
@keyframes chat-panel-appear {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.archiflow-chat-panel:not(.hidden) {
    animation: chat-panel-appear 0.15s ease-out;
}
