/* ============================================================
   Avante AI — Unified Chat Interface
   Combines ARIA (origination) + DELIA (underwriting) into one view.
   ============================================================ */

/* --- Layout: single column flex --- */
.avante-ai-view {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

/* --- Sidebar: Conversation History (inside left nav) --- */
.ai-sidebar-history {
    padding: 0 8px 4px;
    max-height: 240px;
    overflow-y: auto;
}

.ai-sidebar-history::-webkit-scrollbar {
    width: 3px;
}

.ai-sidebar-history::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
}

.ai-sidebar-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px 6px 20px;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s;
    margin-bottom: 1px;
}

.ai-sidebar-item:hover {
    background: rgba(255, 255, 255, 0.05);
}

.ai-sidebar-item.active {
    background: rgba(0, 229, 255, 0.08);
}

.ai-sidebar-item-avatar {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    flex-shrink: 0;
}

.ai-sidebar-item-title {
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    min-width: 0;
}

.ai-sidebar-item:hover .ai-sidebar-item-title {
    color: var(--text-primary);
}

/* "New Chat" sub-item in nav */
.nav-sub-item {
    padding-left: 20px;
    font-size: 13px;
    opacity: 0.7;
}

.nav-sub-item:hover {
    opacity: 1;
}

.nav-chevron {
    transition: transform 0.2s ease;
}

#nav-history-toggle.open .nav-chevron {
    transform: rotate(180deg);
}

/* --- Main chat area (now the full view) --- */

/* --- Greeting / intro state --- */
.ai-intro {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    text-align: center;
}

.ai-intro-avatars {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 24px;
}

.ai-intro-avatar {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    border: 2px solid var(--glass-border);
    transition: transform 0.3s, border-color 0.3s;
}

.ai-intro-avatar.aria-avatar {
    border-color: rgba(0, 229, 255, 0.3);
}

.ai-intro-avatar.delia-avatar {
    border-color: rgba(255, 249, 196, 0.3);
}

.ai-intro-avatar:hover {
    transform: scale(1.08);
}

.ai-intro-divider {
    width: 2px;
    height: 40px;
    background: linear-gradient(180deg, transparent, var(--glass-border), transparent);
}

.ai-intro-title {
    font-size: 26px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0 0 8px;
}

.ai-intro-subtitle {
    font-size: 14px;
    color: var(--text-secondary);
    margin: 0 0 32px;
    max-width: 500px;
    line-height: 1.5;
}

/* --- Input area (shared between intro + convo) --- */
.ai-input-area {
    padding: 16px 24px 20px;
    max-width: 800px;
    width: 100%;
    margin: 0 auto;
}

.ai-intro .ai-input-area {
    padding-top: 0;
}

.ai-input-container {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 8px 12px;
    transition: border-color 0.2s;
}

.ai-input-container:focus-within {
    border-color: var(--accent-cyan);
    box-shadow: 0 0 0 2px rgba(0, 229, 255, 0.1);
}

.ai-input {
    flex: 1;
    background: none;
    border: none;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 14px;
    outline: none;
    padding: 6px 4px;
}

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

.ai-send-btn {
    background: none;
    border: none;
    color: var(--accent-cyan);
    cursor: pointer;
    padding: 4px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    transition: background 0.15s;
}

.ai-send-btn:hover {
    background: rgba(0, 229, 255, 0.1);
}

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

/* --- Recent chats (intro screen) --- */
.ai-recent-chats {
    margin-top: 24px;
    width: 100%;
    max-width: 520px;
}

.ai-recent-chats-header {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 4px;
    padding-left: 4px;
}

.ai-recent-chats-list {
    display: flex;
    flex-direction: column;
}

.ai-recent-chat-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 4px;
    cursor: pointer;
    transition: background 0.15s;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.ai-recent-chat-item:hover {
    background: var(--glass-bg);
}

.ai-recent-chat-title {
    flex: 1;
    font-size: 13px;
    font-weight: 400;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: left;
}

.ai-recent-chat-time {
    font-size: 11px;
    color: var(--text-muted);
    flex-shrink: 0;
}

/* --- Conversation state --- */
.ai-convo {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.ai-convo-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px 24px;
    scroll-behavior: smooth;
}

/* --- Context banner --- */
.ai-context-banner {
    display: none;
    align-items: center;
    gap: 8px;
    padding: 8px 24px;
    font-size: 12px;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--glass-border);
    background: rgba(10, 15, 30, 0.3);
}

.ai-context-banner.visible {
    display: flex;
}

.ai-context-banner .context-avatar {
    width: 20px;
    height: 20px;
    border-radius: 50%;
}

.ai-context-banner .context-label {
    font-weight: 500;
}

.ai-context-banner.delia-context .context-label {
    color: #FFF9C4;
}

.ai-context-banner.aria-context .context-label {
    color: var(--accent-cyan);
}

/* --- Message bubbles --- */
.ai-msg-user {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 16px;
    animation: fadeUp 0.2s ease-out;
}

.ai-msg-user-bubble {
    max-width: 600px;
    background: linear-gradient(135deg, rgba(0, 229, 255, 0.15), rgba(41, 121, 255, 0.15));
    border: 1px solid rgba(0, 229, 255, 0.2);
    border-radius: 16px 16px 4px 16px;
    padding: 10px 16px;
    font-size: 14px;
    color: var(--text-primary);
    line-height: 1.5;
}

.ai-msg-assistant {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
    animation: fadeUp 0.2s ease-out;
}

.ai-msg-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    flex-shrink: 0;
    margin-top: 4px;
}

.ai-msg-content {
    flex: 1;
    min-width: 0;
}

.ai-msg-name {
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 4px;
}

.ai-msg-name.aria-name {
    color: var(--accent-cyan);
}

.ai-msg-name.delia-name {
    color: #FFF9C4;
}

.ai-msg-body {
    font-size: 14px;
    color: var(--text-primary);
    line-height: 1.65;
}

.ai-msg-body strong {
    color: #80E8FF;
    font-weight: 600;
}

.ai-msg-body h3, .ai-msg-body .md-heading {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 16px 0 8px;
}

.ai-msg-body hr {
    border: none;
    border-top: 1px solid var(--glass-border);
    margin: 12px 0;
}

.ai-msg-body ul, .ai-msg-body ol {
    padding-left: 20px;
    margin: 8px 0;
}

.ai-msg-body li {
    margin-bottom: 4px;
}

.ai-msg-body table {
    width: 100%;
    border-collapse: collapse;
    margin: 12px 0;
    font-size: 13px;
}

.ai-msg-body table th {
    text-align: left;
    padding: 8px 10px;
    border-bottom: 2px solid rgba(0, 229, 255, 0.3);
    color: var(--accent-cyan);
    font-weight: 600;
}

.ai-msg-body table td {
    padding: 6px 10px;
    border-bottom: 1px solid var(--glass-border);
}

/* --- Thinking dots --- */
.ai-thinking {
    display: flex;
    gap: 4px;
    padding: 8px 0;
}

.ai-thinking span {
    width: 6px;
    height: 6px;
    background: var(--accent-cyan);
    border-radius: 50%;
    animation: pulse 1.4s infinite ease-in-out;
}

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

.ai-thinking-label {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
}

/* DELIA thinking dots are yellow */
.delia-mode .ai-thinking span {
    background: #FFF9C4;
}

/* --- Uncertainty flag --- */
.ai-flag-banner {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    margin-top: 8px;
    background: rgba(255, 152, 0, 0.1);
    border: 1px solid rgba(255, 152, 0, 0.25);
    border-radius: 8px;
    font-size: 12px;
    color: #FFB74D;
}

.ai-flag-banner .material-symbols-rounded {
    font-size: 16px;
}

/* --- Feedback thumbs --- */
.ai-feedback {
    display: flex;
    gap: 2px;
    margin-top: 6px;
    opacity: 0;
    transition: opacity 0.2s ease;
}
.ai-msg-assistant:hover .ai-feedback,
.ai-feedback.submitted {
    opacity: 1;
}
.ai-feedback-btn {
    background: none;
    border: 1px solid transparent;
    border-radius: 6px;
    padding: 3px 6px;
    cursor: pointer;
    color: rgba(255,255,255,0.35);
    transition: color 0.15s, background 0.15s, border-color 0.15s;
    line-height: 1;
}
.ai-feedback-btn:hover {
    color: rgba(255,255,255,0.7);
    background: rgba(255,255,255,0.06);
    border-color: rgba(255,255,255,0.1);
}
.ai-feedback-btn .material-symbols-rounded {
    font-size: 15px;
}
.ai-feedback-btn.selected {
    color: #80E8FF;
    background: rgba(128,232,255,0.1);
    border-color: rgba(128,232,255,0.25);
}
.ai-feedback-btn.selected[data-rating="-1"] {
    color: #FF8A80;
    background: rgba(255,138,128,0.1);
    border-color: rgba(255,138,128,0.25);
}
.ai-feedback.submitted .ai-feedback-btn:not(.selected) {
    display: none;
}

/* --- File download chips --- */
.ai-file-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: rgba(255, 249, 196, 0.1);
    border: 1px solid rgba(255, 249, 196, 0.25);
    color: #FFF9C4;
    border-radius: 16px;
    padding: 4px 12px;
    font-size: 12px;
    text-decoration: none;
    cursor: pointer;
    transition: background 0.15s;
}

.ai-file-chip:hover {
    background: rgba(255, 249, 196, 0.2);
}

/* --- Pipeline link chips --- */
.ai-pipeline-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: rgba(0, 229, 255, 0.08);
    border: 1px solid rgba(0, 229, 255, 0.2);
    color: var(--accent-cyan);
    border-radius: 16px;
    padding: 4px 12px;
    font-size: 12px;
    text-decoration: none;
    cursor: pointer;
    transition: background 0.15s;
}

.ai-pipeline-chip:hover {
    background: rgba(0, 229, 255, 0.15);
}

/* --- Responsive --- */
@media (max-width: 600px) {
    .ai-input-area {
        padding: 12px 16px 16px;
    }
    .ai-intro-title {
        font-size: 22px;
    }
    .ai-intro-avatar {
        width: 56px;
        height: 56px;
    }
}
