/* === CHAT AI (Google AI Studio Style) === */
.app-chat-ai {
    display: flex;
    height: 100%;
    background: var(--bg-surface);
}

.chat-sidebar {
    width: 260px;
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    background: rgba(0, 0, 0, 0.1);
    flex-shrink: 0;
}

.chat-sidebar-header {
    padding: 16px;
}

.chat-new-btn {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border);
    background: var(--bg-glass);
    color: var(--text-primary);
    border-radius: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background var(--transition);
}

.chat-new-btn:hover {
    background: var(--bg-hover);
}

.chat-history {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.chat-history-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-secondary);
    transition: background var(--transition);
    margin-bottom: 2px;
    position: relative;
    overflow: hidden;
}

.chat-history-item:hover {
    background: var(--bg-hover);
}

.chat-history-item.active {
    background: var(--accent-soft);
    color: var(--accent);
}

.chat-item-title {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-history-item .material-icons-round {
    font-size: 18px;
    flex-shrink: 0;
}

.chat-item-delete {
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 4px;
    border-radius: 4px;
    cursor: pointer;
    opacity: 0;
    transition: opacity var(--transition), background var(--transition), color var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-history-item:hover .chat-item-delete {
    opacity: 1;
}

.chat-item-delete:hover {
    background: rgba(255, 77, 77, 0.15);
    color: #ff6b6b;
}

.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.chat-header {
    height: 56px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 16px;
}

.chat-model-selector-container {
    display: flex;
    align-items: center;
}

.chat-model-select {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    color: var(--text-primary);
    padding: 8px 32px 8px 12px;
    font-size: 13px;
    font-weight: 500;
    font-family: inherit;
    outline: none;
    cursor: pointer;
    appearance: none;
    /* Remove default arrow */
    -webkit-appearance: none;
    -moz-appearance: none;
    background-image: url('data:image/svg+xml;utf8,<svg fill="white" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg"><path d="M7 10l5 5 5-5z"/><path d="M0 0h24v24H0z" fill="none"/></svg>');
    background-repeat: no-repeat;
    background-position: right 8px center;
    background-size: 16px;
    transition: all var(--transition);
    backdrop-filter: blur(10px);
}

.chat-model-select:hover {
    background-color: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
}

.chat-model-select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-soft);
}

.chat-model-select option {
    background: #1e1e2d;
    /* Solid dark background for dropdown list */
    color: var(--text-primary);
    padding: 10px;
    font-size: 13px;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.chat-msg {
    display: flex;
    gap: 16px;
    max-width: 85%;
}

.chat-msg.ai {
    align-self: flex-start;
}

.chat-msg.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.chat-msg-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #4285f4;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    flex-shrink: 0;
}

.chat-msg.user .chat-msg-avatar {
    background: var(--accent);
}

.chat-msg-avatar .material-icons-round {
    font-size: 18px;
}

.chat-msg-wrapper {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-width: 85%;
}

.chat-msg.user .chat-msg-wrapper {
    align-items: flex-end;
}

.chat-msg-content {
    background: var(--bg-glass);
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.5;
    color: var(--text-primary);
    border: 1px solid var(--border);
    width: fit-content;
}

.chat-msg.user .chat-msg-content {
    background: var(--accent-soft);
    border-color: var(--accent-glow);
}

.chat-msg-images {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 8px;
}

.chat-msg-img {
    max-width: 200px;
    max-height: 200px;
    border-radius: 8px;
    object-fit: cover;
    cursor: pointer;
    border: 1px solid var(--border);
    transition: transform var(--transition), box-shadow var(--transition);
}

.chat-msg-img:hover {
    transform: scale(1.02);
    box-shadow: var(--shadow-lg);
}

.chat-msg-utils {
    display: flex;
    gap: 8px;
    opacity: 0;
    transition: opacity var(--transition);
    padding: 0 4px;
}

.chat-msg:hover .chat-msg-utils {
    opacity: 1;
}

.chat-util-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
}

.chat-util-btn:hover {
    background: var(--bg-hover);
    color: var(--accent);
}

.chat-util-btn.success {
    color: #4cd137;
}

.chat-util-btn .material-icons-round {
    font-size: 16px;
}

/* Markdown Rendering */
.chat-text {
    word-break: break-word;
}

.chat-code-block {
    background: #1e1e1e;
    padding: 12px;
    border-radius: 8px;
    margin: 8px 0;
    overflow-x: auto;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.chat-code-block pre {
    margin: 0;
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 13px;
    color: #dcdcdc;
    line-height: 1.4;
}

.chat-inline-code {
    background: rgba(0, 0, 0, 0.2);
    padding: 2px 5px;
    border-radius: 4px;
    font-family: monospace;
    font-size: 0.9em;
    color: var(--accent);
}

.chat-list {
    margin: 8px 0;
    padding-left: 24px;
}

.chat-list-item {
    margin-bottom: 4px;
}

.chat-input-container {
    padding: 0 24px 24px;
}

.chat-input-box {
    background: var(--bg-glass-heavy);
    border: 1px solid var(--border-light);
    border-radius: 24px;
    padding: 8px 16px;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow);
}

.chat-image-preview {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 0;
}

.chat-preview-item {
    position: relative;
    width: 60px;
    height: 60px;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--border);
}

.chat-preview-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.chat-preview-remove {
    position: absolute;
    top: 2px;
    right: 2px;
    background: rgba(0, 0, 0, 0.5);
    color: white;
    border-radius: 50%;
    width: 18px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 14px;
    transition: background var(--transition);
}

.chat-preview-remove:hover {
    background: rgba(255, 0, 0, 0.7);
}

.chat-input-box textarea {
    width: 100%;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 14px;
    padding: 8px 0;
    resize: none;
    max-height: 200px;
    outline: none;
}

.chat-input-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-top: 4px;
}

.chat-input-actions {
    display: flex;
    gap: 12px;
    color: var(--text-muted);
}

.chat-input-actions span {
    cursor: pointer;
    font-size: 20px;
}

.chat-input-actions span:hover {
    color: var(--text-secondary);
}

#chat-send-btn {
    background: transparent;
    border: none;
    color: var(--accent);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px;
    border-radius: 50%;
    transition: background var(--transition);
}

#chat-send-btn:hover {
    background: var(--bg-hover);
}