/**
 * KineticCopy Brain — Chat Assistant
 * v2.0.5: Flat dark header · Sharp corners · Bone bg · Conversation history
 */

/* ── Float button ────────────────────────────────────────────────────── */
#claude-chat-btn,
.claude-fab {
    position: fixed;
    top: 50%;
    right: 12px;
    transform: translateY(-50%);
    z-index: 999999;
    width: 46px;
    height: 46px;
    background: #A6172A;
    color: #ffffff;
    border: none;
    border-radius: 50%;
    cursor: grab;
    user-select: none;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 14px rgba(166,23,42,0.4);
    transition: transform 0.15s, background 0.15s, box-shadow 0.15s;
    pointer-events: all;
}
#claude-chat-btn:hover,
.claude-fab:hover {
    background: #7A1620;
    box-shadow: 0 6px 18px rgba(122,22,32,0.45);
    transform: translateY(-50%) scale(1.04);
}
#claude-chat-btn.claude-fab-hidden,
.claude-fab.claude-fab-hidden {
    opacity: 0;
    pointer-events: none;
}

/* ── Chat panel ──────────────────────────────────────────────────────── */
#claude-chat-panel {
    position: fixed;
    top: 50%;
    right: 72px;
    transform: translateY(-50%);
    z-index: 999998;
    width: 360px;
    height: 520px;
    max-height: calc(100vh - 80px);
    background: #ffffff;
    border: 1px solid #D6263A;
    border-radius: 3px;
    box-shadow: 0 8px 36px rgba(0,0,0,0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: opacity 0.15s, transform 0.15s;
    opacity: 1;
    pointer-events: all;
    position: fixed; /* keep fixed */
}
#claude-chat-panel[hidden] {
    display: none !important;
}
#claude-chat-panel:not(.claude-chat-open):not([hidden]) {
    opacity: 0;
    transform: translateY(-50%) scale(0.97);
    pointer-events: none;
}
#claude-chat-panel.claude-chat-open {
    opacity: 1;
    transform: translateY(-50%) scale(1);
    pointer-events: all;
}

/* ── Header: flat dark, NO gradient ─────────────────────────────────── */
.claude-chat-header {
    display: flex;
    align-items: center;
    padding: 0 10px;
    height: 44px;
    min-height: 44px;
    background: #7A1620;
    color: #ffffff;
    flex-shrink: 0;
    border-bottom: none;
    gap: 8px;
}
.claude-chat-title {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    min-width: 0;
}
.claude-chat-title span,
.claude-chat-header > span {
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: rgba(255,255,255,0.9);
}
.claude-chat-actions {
    display: flex;
    gap: 2px;
    flex-shrink: 0;
}
.claude-chat-btn {
    background: none;
    border: none;
    color: rgba(255,255,255,0.65);
    width: 28px;
    height: 28px;
    border-radius: 3px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s;
    padding: 0;
}
.claude-chat-btn:hover {
    background: rgba(255,255,255,0.15);
    color: #ffffff;
}

/* ── Messages area ───────────────────────────────────────────────────── */
.claude-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: #FBFAF7;
}

/* ── Message bubbles ─────────────────────────────────────────────────── */
.claude-message,
.claude-msg {
    max-width: 86%;
    animation: kc-msg-in 0.18s ease-out;
}
@keyframes kc-msg-in {
    from { opacity: 0; transform: translateY(5px); }
    to   { opacity: 1; transform: translateY(0);   }
}
.claude-message-user,
.claude-msg.user { align-self: flex-end; }
.claude-message-ai,
.claude-msg.assistant { align-self: flex-start; }

.claude-message-content,
.claude-msg {
    padding: 10px 13px;
    border-radius: 3px;
    font-size: 13px;
    line-height: 1.6;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

/* User bubble: soft crimson tint */
.claude-message-user .claude-message-content,
.claude-msg.user {
    background: #FFF0F2;
    color: #1a1a1a;
    border: 1px solid #F5C0C5;
    border-radius: 3px 3px 0 3px;
}
/* AI bubble: white */
.claude-message-ai .claude-message-content {
    background: #ffffff;
    color: #1a1a1a;
    border: 1px solid #e5e7eb;
    border-radius: 3px 3px 3px 0;
}
.claude-msg.assistant {
    background: #ffffff;
    color: #1a1a1a;
    border: 1px solid #e5e7eb;
}
/* Error */
.claude-message-ai.error .claude-message-content {
    background: #fef2f2;
    border-color: #fecaca;
    color: #dc2626;
}
/* System */
.claude-message-ai.system .claude-message-content {
    background: #FBFAF7;
    border-color: #e5e7eb;
    color: #6b7280;
    font-size: 11.5px;
    font-family: 'JetBrains Mono', monospace;
}
/* Greeting */
.kc-greeting .claude-message-content,
.kc-greeting-content {
    background: #FFF0F2 !important;
    border-color: #F5C0C5 !important;
    color: #7A1620 !important;
    font-family: 'Instrument Serif', Georgia, serif !important;
    font-style: italic;
    font-size: 13.5px;
    line-height: 1.65;
}
.kc-greeting { animation: kc-greeting-in 0.35s ease-out both; }
@keyframes kc-greeting-in {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Skeleton */
.kc-greeting-skeleton { display: flex; flex-direction: column; gap: 8px; }
.kc-skeleton-line {
    display: block;
    height: 11px;
    border-radius: 3px;
    background: linear-gradient(90deg, #e2e8f0 25%, #f1f5f9 50%, #e2e8f0 75%);
    background-size: 200% 100%;
    animation: kc-shimmer 1.4s infinite;
}
.kc-skeleton-short { width: 60%; }
@keyframes kc-shimmer {
    0%   { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* Content formatting */
.claude-message-content p { margin: 0 0 6px 0; }
.claude-message-content p:last-child { margin-bottom: 0; }
.claude-message-content ul { margin: 6px 0; padding-left: 18px; }
.claude-message-content li { margin: 3px 0; }
.claude-message-content code {
    background: rgba(0,0,0,0.07);
    padding: 1px 5px;
    border-radius: 2px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 11.5px;
}
.claude-message-content pre {
    background: #1e293b;
    color: #e2e8f0;
    padding: 10px 12px;
    border-radius: 3px;
    overflow-x: auto;
    margin: 6px 0;
}
.claude-message-content pre code { background: none; padding: 0; color: inherit; }

/* ── Clear button ────────────────────────────────────────────────────── */
#claude-chat-clear {
    display: block;
    width: 100%;
    padding: 5px 14px 4px;
    font-size: 11px;
    font-family: 'JetBrains Mono', monospace;
    letter-spacing: 0.04em;
    color: #9ca3af;
    text-align: center;
    cursor: pointer;
    background: #FBFAF7;
    border: none;
    border-top: 1px solid #F0EDE7;
    text-decoration: underline;
    text-decoration-style: dotted;
    text-underline-offset: 2px;
    transition: color 0.15s;
    flex-shrink: 0;
}
#claude-chat-clear:hover { color: #D6263A; background: #FBFAF7; }

/* ── Input row ───────────────────────────────────────────────────────── */
.claude-chat-input-row {
    display: flex;
    gap: 6px;
    padding: 10px 12px;
    background: #ffffff;
    border-top: 1px solid #e5e7eb;
    flex-shrink: 0;
    align-items: flex-end;
}
#claude-chat-input,
.claude-chat-input-row textarea {
    flex: 1;
    padding: 9px 11px;
    font-size: 13px;
    font-family: 'Inter', -apple-system, sans-serif;
    border: 1px solid #e5e7eb;
    border-radius: 3px;
    resize: none;
    line-height: 1.45;
    max-height: 80px;
    background: #FBFAF7;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}
#claude-chat-input:focus,
.claude-chat-input-row textarea:focus {
    border-color: #D6263A;
    box-shadow: 0 0 0 2px rgba(214,38,58,0.1);
    background: #ffffff;
}

/* Research toggle */
.claude-chat-research {
    width: 36px;
    height: 36px;
    border: 1px solid #e5e7eb;
    border-radius: 3px;
    background: #FBFAF7;
    color: #9ca3af;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
    flex-shrink: 0;
}
.claude-chat-research:hover { background: #f3f4f6; color: #374151; border-color: #d1d5db; }
.claude-research-active,
.claude-chat-research.active {
    background: #D6263A !important;
    color: #ffffff !important;
    border-color: #A6172A !important;
}

/* Send button: flat dark crimson */
#claude-chat-send,
.claude-chat-send {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 3px;
    background: #A6172A;
    color: #ffffff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, transform 0.1s;
    flex-shrink: 0;
}
#claude-chat-send:hover:not(:disabled),
.claude-chat-send:hover:not(:disabled) { background: #7A1620; }
#claude-chat-send:disabled,
.claude-chat-send:disabled { opacity: 0.45; cursor: not-allowed; }

/* ── Loading / typing ────────────────────────────────────────────────── */
.claude-chat-loading {
    padding: 8px 14px;
    display: flex;
    flex-shrink: 0;
}
.claude-typing-indicator {
    display: flex;
    gap: 4px;
    align-items: center;
}
.claude-typing-indicator span {
    width: 7px;
    height: 7px;
    background: #D6263A;
    border-radius: 50%;
    animation: kc-bounce 1.4s infinite ease-in-out both;
}
.claude-typing-indicator span:nth-child(1) { animation-delay: -0.32s; }
.claude-typing-indicator span:nth-child(2) { animation-delay: -0.16s; }
@keyframes kc-bounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.5; }
    40%           { transform: scale(1);   opacity: 1;   }
}

/* ── BrainWave animation ─────────────────────────────────────────────── */
.kc-brainwave { display: block; overflow: visible; flex-shrink: 0; }
.kc-wave {
    animation: kc-wave-idle 2s ease-in-out infinite;
    transform-origin: center;
}
.kc-wave-1 { animation-delay: 0s; }
.kc-wave-2 { animation-delay: 0.2s; }
.kc-wave-3 { animation-delay: 0.4s; }
@keyframes kc-wave-idle {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0.45; }
}
#claude-chat-btn.kc-thinking .kc-wave,
.claude-fab.kc-thinking .kc-wave {
    animation: kc-wave-think 0.55s ease-in-out infinite;
}
@keyframes kc-wave-think {
    0%, 100% { opacity: 1;    transform: scaleY(1);    }
    50%       { opacity: 0.85; transform: scaleY(1.55); }
}
#claude-chat-btn.kc-speaking .kc-wave,
.claude-fab.kc-speaking .kc-wave {
    animation: kc-wave-speak 0.8s ease-in-out infinite;
}
@keyframes kc-wave-speak {
    0%, 100% { opacity: 1;    transform: scaleY(1);    }
    30%       { opacity: 0.75; transform: scaleY(1.3);  }
    60%       { opacity: 0.9;  transform: scaleY(0.85); }
}

/* ── History panel ───────────────────────────────────────────────────── */
#kc-history-panel {
    position: absolute;
    top: 44px;
    left: 0;
    right: 0;
    bottom: 0;
    background: #FBFAF7;
    z-index: 10;
    display: flex;
    flex-direction: column;
    transform: translateX(-102%);
    transition: transform 0.2s ease;
}
#kc-history-panel.kc-history-open {
    transform: translateX(0);
}
.kc-history-header {
    display: flex;
    align-items: center;
    padding: 0 10px;
    height: 36px;
    background: #F5F3EC;
    border-bottom: 1px solid #ECE9DF;
    flex-shrink: 0;
    gap: 8px;
}
.kc-history-header-label {
    flex: 1;
    font-family: 'JetBrains Mono', monospace;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #6b7280;
}
.kc-history-close {
    background: none;
    border: none;
    cursor: pointer;
    color: #9ca3af;
    padding: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 3px;
    transition: color 0.15s, background 0.15s;
}
.kc-history-close:hover { color: #374151; background: #ECE9DF; }
.kc-history-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.kc-history-empty {
    padding: 28px 16px;
    text-align: center;
    font-size: 11px;
    font-family: 'JetBrains Mono', monospace;
    color: #9ca3af;
    letter-spacing: 0.04em;
}
.kc-history-item {
    padding: 9px 10px;
    background: #ffffff;
    border: 1px solid #ECE9DF;
    border-radius: 3px;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
    position: relative;
}
.kc-history-item:hover {
    border-color: #F5C0C5;
    background: #FFF0F2;
}
.kc-history-item-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 3px;
}
.kc-history-item-date {
    font-size: 10px;
    font-family: 'JetBrains Mono', monospace;
    color: #9ca3af;
    letter-spacing: 0.04em;
}
.kc-history-item-del {
    background: none;
    border: none;
    color: #d1d5db;
    cursor: pointer;
    font-size: 13px;
    padding: 0;
    line-height: 1;
    transition: color 0.15s;
}
.kc-history-item-del:hover { color: #D6263A; }
.kc-history-item-preview {
    font-size: 12px;
    color: #374151;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ── Scrollbar ───────────────────────────────────────────────────────── */
.claude-chat-messages::-webkit-scrollbar,
.kc-history-list::-webkit-scrollbar { width: 4px; }
.claude-chat-messages::-webkit-scrollbar-track,
.kc-history-list::-webkit-scrollbar-track { background: transparent; }
.claude-chat-messages::-webkit-scrollbar-thumb,
.kc-history-list::-webkit-scrollbar-thumb { background: #ECE9DF; border-radius: 2px; }
.claude-chat-messages::-webkit-scrollbar-thumb:hover,
.kc-history-list::-webkit-scrollbar-thumb:hover { background: #D6263A; }

/* ── Mobile ──────────────────────────────────────────────────────────── */
@media (max-width: 782px) {
    #claude-chat-panel {
        width: calc(100vw - 20px);
        height: calc(100vh - 60px);
        top: auto;
        right: 10px;
        bottom: 10px;
        transform: none !important;
    }
    #claude-chat-btn,
    .claude-fab {
        top: auto;
        right: 10px;
        bottom: 10px;
        transform: none !important;
    }
    #claude-chat-btn:hover,
    .claude-fab:hover { transform: scale(1.04) !important; }
    #kc-history-panel { top: 44px; }
}
