/* ==========================================================================
 *  Chat Title Bar - Modern Design
 *  ========================================================================== */
.chat-title-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
    height: 44px;
    max-height: 44px;
    position: relative;
    flex-wrap: wrap;
}

.chat-title-text {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 600px;
    text-align: center;
    flex-shrink: 1;
    min-width: 0;
}

.chat-title-content {
    display: flex;
    align-items: center;
    gap: 8px;
    max-width: 100%;
    overflow: hidden;
}

.chat-title-rename {
    padding: 6px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    flex-shrink: 0;
    position: absolute;
    right: 16px;
}

.chat-title-bar:hover .chat-title-rename {
    opacity: 1;
}

.chat-title-rename:hover {
    background: var(--bg-secondary);
    border-color: var(--border-color);
    color: var(--text-primary);
}

.chat-title-rename:active {
    transform: scale(0.95);
}

/* Hide rename button when no chat */
.chat-title-bar.no-chat .chat-title-rename {
    display: none;
}

.chat-title-bar.no-chat .chat-title-text {
    color: var(--text-muted);
    font-style: italic;
}

/* Title bar actions */
.chat-title-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: 8px;
    flex-shrink: 0;
}

.chat-title-edit-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: var(--radius-md);
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.15s ease;
    opacity: 0;
}

.chat-title-bar:hover .chat-title-edit-btn {
    opacity: 1;
}

.chat-title-edit-btn:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

/* Sidebar edit button */
.chat-action-btn.edit {
    background: transparent;
    color: var(--text-muted);
}

.chat-action-btn.edit:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

/* Ensure title text can contain edit input */
#chat-title-text {
    min-width: 0;
    flex: 1;
    line-height: 24px;
    height: 24px; /* Fixed height to prevent layout shift during rename */
}

/* No-chat state for title bar */
.chat-title-bar.no-chat .chat-title-edit-btn {
    display: none;
}

@media (max-width: 600px) {
    .chat-title-bar {
        padding: 8px 12px;
        height: 40px;
    }

    .chat-title-text {
        font-size: 0.85rem;
        max-width: 200px;
    }

    .chat-title-rename {
        opacity: 1;
    }
}

/* ==========================================================================
 *  Search Bar - Modern Design
 *  ========================================================================== */
.search-container {
    display: none;
    padding: 14px 20px;
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
}

.search-container.active {
    display: block;
}

.search-input-wrapper {
    display: flex;
    align-items: center;
    gap: 10px;
    max-width: 600px;
    margin: 0 auto;
}

.search-input {
    flex: 1;
    padding: 12px 18px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-full);
    color: var(--text-primary);
    font-size: 0.9rem;
    outline: none;
    transition: all 0.2s ease;
}

.search-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 15%, transparent);
}

.search-input::placeholder {
    color: var(--text-muted);
}

.search-nav-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    padding: 0;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s ease;
}

.search-nav-btn:hover:not(:disabled) {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border-color: var(--accent);
}

.search-nav-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.search-index {
    min-width: 50px;
    font-size: 0.8rem;
    color: var(--text-muted);
    text-align: center;
}

.search-count {
    padding: 6px 12px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-full);
    font-size: 0.8rem;
    color: var(--text-secondary);
    white-space: nowrap;
}

.search-close-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    padding: 0;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.15s ease;
}

.search-close-btn:hover {
    background: var(--bg-tertiary);
    color: var(--error);
    border-color: var(--error);
}

/* Search highlighting */
.message.search-highlight {
    box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 30%, transparent);
}

/* Match highlighting */
.message .search-match {
    background: rgba(255, 200, 50, 0.4);
    color: var(--text-primary);
    padding: 1px 2px;
    border-radius: 2px;
    transition: background 0.15s;
}

/* Current match highlighting */
.message .search-match.current {
    background: var(--accent);
    color: var(--bg-primary);
    box-shadow: 0 0 8px var(--accent-glow);
    border-radius: 3px;
    padding: 1px 4px;
}

/* Dark theme adjustments */
@media (prefers-color-scheme: dark) {
    .message .search-match {
        background: rgba(255, 220, 100, 0.3);
    }

    .message .search-match.current {
        background: var(--accent);
        color: #000;
    }
}
