/* ai-assist.css - AI Assist Chat Panel */

/* =================================================================
   AI ASSIST WIDGET - positioned left of feedback widget
   ================================================================= */

.ai-assist-widget {
    position: fixed;
    bottom: 20px;
    right: 80px;
    z-index: 1000;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* Trigger button - matches feedback style with Hesyra teal gradient */
.ai-assist-trigger {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: linear-gradient(135deg, rgba(0, 173, 180, 0.85), rgba(0, 139, 148, 0.85));
    border: 1px solid rgba(0, 173, 180, 0.9);
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 173, 180, 0.3);
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    font-size: 20px;
    -webkit-tap-highlight-color: rgba(0,0,0,0);
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
    padding: 0;
}

.ai-assist-trigger:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 173, 180, 0.4);
    background: linear-gradient(135deg, rgba(0, 173, 180, 0.95), rgba(0, 139, 148, 0.95));
    border-color: rgba(0, 173, 180, 1);
}

.ai-assist-trigger.expanded {
    display: none;
}

.ai-assist-trigger svg {
    width: 22px;
    height: 22px;
    fill: none;
    stroke: white;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* Chat panel */
.ai-assist-panel {
    position: absolute;
    bottom: 0;
    right: 0;
    width: var(--ai-assist-width, 400px);
    max-width: calc(100vw - 40px);
    height: var(--ai-assist-height, 500px);
    max-height: 90vh;
    min-width: 320px;
    min-height: 380px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
    transform: translateY(100%) scale(0.9);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                transform 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                visibility 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    border: 1px solid #e5e7eb;
}

/* Resize handle — top-left corner for floating mode */
.ai-assist-resize-handle {
    position: absolute;
    top: 0;
    left: 0;
    width: 16px;
    height: 16px;
    cursor: nwse-resize;
    z-index: 10;
    background: linear-gradient(135deg, transparent 46%, #9CA3AF 46%, #9CA3AF 54%, transparent 54%);
    border-top-left-radius: 12px;
    opacity: 0.5;
    transition: opacity 0.2s;
}

.ai-assist-resize-handle:hover {
    opacity: 1;
}

/* Pinned (sidebar) mode — docks panel to right edge of viewport */
.ai-assist-panel.pinned {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: auto;
    width: var(--ai-assist-pin-width, 420px);
    height: 100vh;
    max-height: 100vh;
    max-width: 70vw;
    min-width: 320px;
    border-radius: 0;
    border-top: none;
    border-right: none;
    border-bottom: none;
    border-left: 1px solid #e5e7eb;
    box-shadow: -4px 0 16px rgba(0, 0, 0, 0.08);
}

.ai-assist-panel.pinned .ai-assist-header {
    border-radius: 0;
}

/* In pinned mode, resize handle becomes a left-edge grip */
.ai-assist-panel.pinned .ai-assist-resize-handle {
    top: 0;
    left: 0;
    width: 6px;
    height: 100%;
    cursor: ew-resize;
    background: transparent;
    border-radius: 0;
    opacity: 1;
}

.ai-assist-panel.pinned .ai-assist-resize-handle:hover {
    background: rgba(0, 173, 180, 0.15);
}

/* When body is pinned, shift the main content left to make room */
body.ai-assist-pinned {
    padding-right: var(--ai-assist-pin-width, 420px);
    transition: padding-right 0.2s ease;
}

/* Shift the feedback widget so it doesn't hide behind the sidebar */
body.ai-assist-pinned .feedback-widget {
    right: calc(var(--ai-assist-pin-width, 420px) + 20px);
}

/* Disable resize-drag transitions so movement is 1:1 with mouse */
.ai-assist-panel.resizing {
    transition: none !important;
}
body.ai-assist-pinned.resizing {
    transition: none !important;
}

.ai-assist-panel.active {
    transform: translateY(0) scale(1);
    opacity: 1;
    visibility: visible;
}

/* Header */
.ai-assist-header {
    padding: 14px 16px;
    background: linear-gradient(135deg, #00ADB4, #008B94);
    color: white;
    border-radius: 12px 12px 0 0;
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.ai-assist-header-icon {
    width: 28px;
    height: 28px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.ai-assist-header-icon svg {
    width: 16px;
    height: 16px;
    fill: none;
    stroke: white;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.ai-assist-header-text {
    flex: 1;
}

.ai-assist-title {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
    color: white;
}

.ai-assist-subtitle {
    margin: 1px 0 0 0;
    font-size: 12px;
    color: rgba(255, 255, 255, 0.8);
}

.ai-assist-header-actions {
    display: flex;
    align-items: center;
    gap: 2px;
    margin-left: auto;
    flex-shrink: 0;
}

.ai-assist-icon-btn {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.8);
    cursor: pointer;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s;
    padding: 0;
}

.ai-assist-icon-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    color: white;
}

.ai-assist-icon-btn svg {
    width: 15px;
    height: 15px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.ai-assist-icon-btn.active {
    background: rgba(255, 255, 255, 0.25);
    color: white;
}

.ai-assist-close {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.8);
    font-size: 18px;
    cursor: pointer;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s;
    padding: 0;
}

.ai-assist-close:hover {
    background: rgba(255, 255, 255, 0.2);
    color: white;
}

/* Messages area */
.ai-assist-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.ai-assist-messages::-webkit-scrollbar {
    width: 4px;
}

.ai-assist-messages::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 2px;
}

/* Welcome state */
.ai-assist-welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 24px 16px;
    gap: 12px;
    flex: 1;
}

.ai-assist-welcome-icon {
    width: 48px;
    height: 48px;
    background: linear-gradient(135deg, #E0F7FA, #B2EBF2);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ai-assist-welcome-icon svg {
    width: 24px;
    height: 24px;
    fill: none;
    stroke: #00ADB4;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.ai-assist-welcome h4 {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
    color: #374151;
}

.ai-assist-welcome p {
    margin: 0;
    font-size: 13px;
    color: #6b7280;
    line-height: 1.5;
}

.ai-assist-suggestions {
    display: flex;
    flex-direction: column;
    gap: 6px;
    width: 100%;
    margin-top: 4px;
}

.ai-assist-suggestion {
    background: #F0FAFB;
    border: 1px solid #E0F7FA;
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 12px;
    color: #008B94;
    cursor: pointer;
    transition: all 0.15s;
    text-align: left;
}

.ai-assist-suggestion:hover {
    background: #E0F7FA;
    border-color: #B2EBF2;
}

/* Message bubbles */
.ai-msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 13px;
    line-height: 1.5;
    word-wrap: break-word;
    white-space: pre-wrap;
}

.ai-msg-user {
    align-self: flex-end;
    background: #00ADB4;
    color: white;
    border-bottom-right-radius: 4px;
}

.ai-msg-assistant {
    align-self: flex-start;
    background: #F3F4F6;
    color: #374151;
    border-bottom-left-radius: 4px;
}

/* Content preview within assistant message */
.ai-msg-content-preview {
    margin-top: 8px;
    padding: 8px 10px;
    background: #F9FAFB;
    border: 1px solid #E5E7EB;
    border-radius: 6px;
    font-size: 11px;
    color: #4B5563;
    line-height: 1.5;
    max-height: 200px;
    overflow-y: auto;
    white-space: pre-wrap;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* Content update banner within assistant message */
.ai-msg-content-update {
    margin-top: 8px;
    padding: 8px 10px;
    background: #F0FDF4;
    border: 1px solid #BBF7D0;
    border-radius: 6px;
    font-size: 12px;
    color: #166534;
    display: flex;
    align-items: center;
    gap: 8px;
}

.ai-msg-apply-btn {
    background: #16A34A;
    color: white;
    border: none;
    border-radius: 4px;
    padding: 4px 10px;
    font-size: 11px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s;
    white-space: nowrap;
    flex-shrink: 0;
}

.ai-msg-apply-btn:hover {
    background: #15803D;
}

.ai-msg-apply-btn.ai-msg-apply-secondary {
    background: #E5E7EB;
    color: #374151;
    border: 1px solid #D1D5DB;
}

.ai-msg-apply-btn.ai-msg-apply-secondary:hover {
    background: #D1D5DB;
}

.ai-msg-apply-btn.applied {
    background: #D1D5DB;
    color: #6B7280;
    cursor: default;
}

/* Slash command menu */
.ai-assist-slash-menu {
    position: absolute;
    bottom: calc(100% + 6px);
    left: 12px;
    right: 12px;
    max-height: 220px;
    overflow-y: auto;
    background: #FFFFFF;
    border: 1px solid #E5E7EB;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    z-index: 10;
    padding: 4px;
}

.ai-assist-slash-menu[hidden] {
    display: none;
}

.ai-assist-slash-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    color: #374151;
    transition: background 0.1s;
}

.ai-assist-slash-item:hover,
.ai-assist-slash-item.selected {
    background: #EEF2FF;
    color: #3730A3;
}

.ai-assist-slash-name {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-weight: 600;
    color: #6366F1;
    font-size: 11px;
    min-width: 70px;
    flex-shrink: 0;
}

.ai-assist-slash-label {
    color: #4B5563;
}

.ai-assist-slash-item.selected .ai-assist-slash-label {
    color: #3730A3;
}

/* No-transcript warning banner */
.ai-assist-no-transcript-banner {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 10px 12px;
    margin-bottom: 12px;
    background: #FFFBEB;
    border: 1px solid #FCD34D;
    border-radius: 8px;
    font-size: 12px;
    color: #78350F;
}

.ai-assist-banner-icon {
    font-size: 16px;
    line-height: 1;
    flex-shrink: 0;
}

.ai-assist-banner-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
    line-height: 1.4;
}

.ai-assist-banner-text strong {
    font-weight: 600;
}

/* Error bubble with retry button */
.ai-msg-error {
    background: #FEF2F2;
    color: #991B1B;
    border: 1px solid #FECACA;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.ai-msg-error-text {
    line-height: 1.4;
}

.ai-msg-retry-btn {
    align-self: flex-start;
    background: #DC2626;
    color: white;
    border: none;
    border-radius: 4px;
    padding: 4px 12px;
    font-size: 11px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s;
}

.ai-msg-retry-btn:hover {
    background: #B91C1C;
}

/* Typing indicator */
.ai-msg-typing {
    align-self: flex-start;
    background: #F3F4F6;
    padding: 12px 16px;
    border-radius: 12px;
    border-bottom-left-radius: 4px;
    display: flex;
    gap: 4px;
    align-items: center;
}

.ai-typing-dot {
    width: 6px;
    height: 6px;
    background: #9CA3AF;
    border-radius: 50%;
    animation: aiTypingBounce 1.4s infinite;
}

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

@keyframes aiTypingBounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-4px); }
}

/* Input area */
.ai-assist-input-area {
    position: relative;
    padding: 12px 16px;
    border-top: 1px solid #E5E7EB;
    background: #FAFBFC;
    display: flex;
    gap: 8px;
    align-items: flex-end;
    flex-shrink: 0;
}

.ai-assist-input {
    flex: 1;
    border: 1px solid #D1D5DB;
    border-radius: 8px;
    padding: 10px 12px;
    font-size: 13px;
    font-family: inherit;
    resize: none;
    max-height: 140px;
    min-height: 64px;
    line-height: 1.4;
    transition: border-color 0.2s;
    outline: none;
    box-sizing: border-box;
}

.ai-assist-input:focus {
    border-color: #00ADB4;
    box-shadow: 0 0 0 2px rgba(0, 173, 180, 0.1);
}

.ai-assist-input::placeholder {
    color: #9CA3AF;
}

.ai-assist-send-btn {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: #00ADB4;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
    flex-shrink: 0;
    padding: 0;
}

.ai-assist-send-btn:hover {
    background: #008B94;
}

.ai-assist-send-btn:disabled {
    background: #D1D5DB;
    cursor: not-allowed;
}

.ai-assist-send-btn svg {
    width: 16px;
    height: 16px;
    fill: none;
    stroke: white;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* Section indicator pill */
.ai-assist-section-pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: #E0F7FA;
    color: #008B94;
    font-size: 11px;
    font-weight: 500;
    padding: 3px 8px;
    border-radius: 10px;
    margin-bottom: 4px;
}

/* Hide widget when not on summary view */
.ai-assist-widget.hidden {
    display: none;
}

/* Mobile responsive */
@media (max-width: 480px) {
    .ai-assist-widget {
        bottom: 15px;
        right: 72px;
    }

    .ai-assist-trigger {
        width: 48px;
        height: 48px;
        font-size: 18px;
        min-height: 44px;
        min-width: 44px;
    }

    .ai-assist-panel,
    .ai-assist-panel.pinned {
        width: calc(100vw - 30px);
        left: 15px;
        right: 15px;
        bottom: 15px;
        top: auto;
        position: fixed;
        z-index: 1002;
        height: 60vh;
        max-height: 60vh;
        border-radius: 12px;
        border: 1px solid #e5e7eb;
    }

    .ai-assist-resize-handle,
    .ai-assist-icon-btn[data-action="pin"] {
        display: none;
    }

    body.ai-assist-pinned {
        padding-right: 0;
    }

    .ai-assist-close {
        width: 32px;
        height: 32px;
        font-size: 20px;
    }
}

@media (max-width: 280px) {
    .ai-assist-widget {
        display: none;
    }
}
