/* AI Chat View */

#view-ai-chat.route-view.active {
    position: fixed;
    top: 48px;    /* below app header */
    bottom: 72px; /* above bottom nav */
    left: 0;
    right: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 10;
    background: var(--bg);
}

.ai-chat-view {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

/* Header */
.ai-chat-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.ai-chat-header h3 {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    flex: 1;
}

.ai-chat-header-btn {
    background: none;
    border: 1px solid var(--border-strong);
    border-radius: 6px;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 16px;
}

.ai-chat-header-btn:hover {
    background: var(--bg-input);
    color: var(--text);
}

/* Messages Area */
.ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    -webkit-overflow-scrolling: touch;
}

/* Empty State */
.ai-chat-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    color: var(--text-dim);
    text-align: center;
    padding: 32px 16px;
}

.ai-chat-empty-icon {
    font-size: 40px;
    margin-bottom: 12px;
    opacity: 0.5;
}

.ai-chat-empty p {
    font-size: 14px;
    margin: 0 0 4px;
    color: var(--text-muted);
}

.ai-chat-empty small {
    font-size: 12px;
    color: var(--text-dim);
}

/* Suggested Prompts */
.ai-chat-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    margin-top: 16px;
    max-width: 340px;
}

.ai-chat-suggestion {
    background: var(--bg-input);
    border: 1px solid var(--border-strong);
    border-radius: 16px;
    padding: 6px 14px;
    font-size: 13px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s;
}

.ai-chat-suggestion:hover {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

/* Message Bubbles */
.ai-chat-msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
}

.ai-chat-msg.user {
    align-self: flex-end;
    background: var(--accent);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.ai-chat-msg.assistant {
    align-self: flex-start;
    background: var(--bg-card);
    color: var(--text);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
}

/* Markdown in assistant messages */
.ai-chat-msg.assistant p { margin: 0 0 8px; }
.ai-chat-msg.assistant p:last-child { margin-bottom: 0; }
.ai-chat-msg.assistant strong { font-weight: 600; }

.ai-chat-msg.assistant ul,
.ai-chat-msg.assistant ol {
    margin: 4px 0 8px 18px;
    padding: 0;
}

.ai-chat-msg.assistant li { margin-bottom: 2px; }

.ai-chat-msg.assistant code {
    background: var(--bg-input);
    padding: 1px 4px;
    border-radius: 3px;
    font-size: 12px;
}

/* Streaming cursor */
.ai-chat-msg.assistant.streaming::after {
    content: '';
    display: inline-block;
    width: 5px;
    height: 14px;
    background: var(--accent);
    margin-left: 2px;
    vertical-align: text-bottom;
    animation: ai-chat-blink 0.7s infinite;
}

@keyframes ai-chat-blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

/* Error */
.ai-chat-error {
    padding: 8px 12px;
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.3);
    border-radius: 8px;
    color: #ef4444;
    font-size: 13px;
    align-self: center;
}

/* Input Area */
.ai-chat-input-area {
    display: flex;
    gap: 8px;
    padding: 10px 16px;
    border-top: 1px solid var(--border);
    background: var(--bg);
    flex-shrink: 0;
    align-items: flex-end;
}

.ai-chat-input-area textarea {
    flex: 1;
    resize: none;
    border: 1px solid var(--border-strong);
    border-radius: 10px;
    padding: 8px 12px;
    font-size: 14px;
    font-family: inherit;
    line-height: 1.4;
    max-height: 100px;
    background: var(--bg-input);
    color: var(--text);
    outline: none;
}

.ai-chat-input-area textarea:focus {
    border-color: var(--accent);
}

.ai-chat-input-area textarea::placeholder {
    color: var(--text-dim);
}

.ai-chat-send-btn {
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 10px;
    padding: 8px 16px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
}

.ai-chat-send-btn:hover {
    background: var(--accent-hover);
}

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

/* History Panel */
.ai-chat-history {
    border-bottom: 1px solid var(--border);
    background: var(--bg-elevated);
    flex-shrink: 0;
    max-height: 40vh;
    overflow-y: auto;
}

.ai-chat-history-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
}

.ai-chat-history-item:hover {
    background: var(--bg-input);
}

.ai-chat-history-item.active {
    background: var(--bg-input);
    border-left: 3px solid var(--accent);
}

.ai-chat-history-title {
    font-size: 13px;
    color: var(--text);
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ai-chat-history-delete {
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 16px;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
    flex-shrink: 0;
    opacity: 0;
}

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

.ai-chat-history-delete:hover {
    color: #ef4444;
}

.ai-chat-history-empty {
    padding: 16px;
    text-align: center;
    color: var(--text-dim);
    font-size: 13px;
}
