/* ----------------------------------------------------------------------------
Window (Container)
   ---------------------------------------------------------------------------- */
.ai-chat-window {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.95);
    width: 70vw;
    max-width: 650px;
    height: 50vh;
    max-height: 400px;
    background-color: rgba(30, 30, 30, 0.5);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    z-index: 10000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease-in-out, visibility 0.3s ease-in-out, transform 0.3s ease-in-out;
    overflow: hidden;
}

.ai-chat-window.active {
    opacity: 1 !important;
    visibility: visible !important;
    transform: translate(-50%, -50%) scale(1) !important;
}

/* ----------------------------------------------------------------------------
   Header
   ---------------------------------------------------------------------------- */
.ai-chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    background-color: rgba(20, 20, 20, 0.5);
}

.ai-chat-header-left {
    display: flex;
    align-items: center;
    gap: 16px;
    flex: 1;
    min-width: 0;
}

.ai-chat-header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.ai-chat-title {
    margin: 0;
    font-size: 1.2em;
    color: #fff;
    font-weight: 600;
}

/* Model Selector */
.ai-chat-model-selector {
    position: relative;
    display: flex;
    align-items: center;
    gap: 4px;
    flex: 1 1 auto;
    min-width: 0;
    max-width: 100%;
    z-index: 1;
}

/* Custom Dropdown */
.ai-chat-model-dropdown {
    position: relative;
    width: 100%;
    min-width: 125px;
}

.ai-chat-model-dropdown-toggle {
    width: 100%;
    background-color: rgba(40, 40, 40, 0.8);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    color: #fff;
    padding: 8px 32px 8px 12px;
    font-size: 0.85em;
    font-family: inherit;
    cursor: pointer;
    outline: none;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-sizing: border-box;
    text-align: left;
}

.ai-chat-model-dropdown-toggle:hover:not(:disabled) {
    background-color: rgba(50, 50, 50, 0.9);
    border-color: rgba(255, 255, 255, 0.2);
}

.ai-chat-model-dropdown-toggle:focus:not(:disabled) {
    border-color: rgba(100, 150, 255, 0.5);
    box-shadow: 0 0 0 2px rgba(100, 150, 255, 0.2);
}

.ai-chat-model-dropdown-toggle:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    background-color: rgba(30, 30, 30, 0.8);
}

.ai-chat-model-dropdown-selected {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ai-chat-model-dropdown-arrow {
    flex-shrink: 0;
    margin-left: 8px;
    font-size: 0.75em;
    transition: transform 0.2s ease;
    color: rgba(255, 255, 255, 0.7);
}

.ai-chat-model-dropdown.active .ai-chat-model-dropdown-arrow {
    transform: rotate(180deg);
}

.ai-chat-model-dropdown-menu {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background-color: rgba(40, 40, 40, 0.95);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
    z-index: 10001;
    max-height: 200px;
    overflow-y: auto;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
    transition: opacity 0.2s ease, visibility 0.2s ease, transform 0.2s ease;
}

.ai-chat-model-dropdown-menu.hidden {
    display: none;
}

.ai-chat-model-dropdown.active .ai-chat-model-dropdown-menu:not(.hidden) {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
    display: block;
}

.ai-chat-model-dropdown-options {
    padding: 4px 0;
}

.ai-chat-model-dropdown-option {
    padding: 10px 12px;
    color: #fff;
    cursor: pointer;
    transition: background-color 0.15s ease;
    font-size: 0.85em;
    display: block;
    width: 100%;
    text-align: left;
    border: none;
    background: none;
    font-family: inherit;
}

.ai-chat-model-dropdown-option:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

.ai-chat-model-dropdown-option.selected {
    background-color: rgba(100, 150, 255, 0.2);
    color: rgba(100, 150, 255, 1);
}

.ai-chat-model-dropdown-option:focus {
    outline: none;
    background-color: rgba(255, 255, 255, 0.15);
}

.ai-chat-model-loading {
    display: none;
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.85em;
    pointer-events: none;
    flex-shrink: 0;
}

.ai-chat-model-loading i {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

/* Header Buttons */
.ai-chat-close-btn {
    background: none;
    border: none;
    color: #fff;
    font-size: 1.5em;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 8px;
    transition: background-color 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
}

.ai-chat-close-btn:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

.ai-chat-clear-btn {
    background: none;
    border: none;
    color: #fff;
    font-size: 1.1em;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 8px;
    transition: background-color 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    opacity: 0.7;
}

.ai-chat-clear-btn:hover {
    background-color: rgba(255, 100, 100, 0.2);
    opacity: 1;
}

.ai-chat-model-info-btn {
    background: none;
    border: none;
    color: #fff;
    font-size: 1.1em;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 8px;
    transition: background-color 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    opacity: 0.7;
}

.ai-chat-model-info-btn:hover {
    background-color: rgba(100, 150, 255, 0.2);
    opacity: 1;
}

/* ----------------------------------------------------------------------------
   Messages Area
   ---------------------------------------------------------------------------- */
.ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    min-height: 0;
}

.ai-chat-messages::-webkit-scrollbar {
    width: 6px;
}

.ai-chat-messages::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 3px;
}

.ai-chat-messages::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

.ai-chat-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* ----------------------------------------------------------------------------
   Messages
   ---------------------------------------------------------------------------- */
.ai-chat-message {
    display: flex;
    gap: 12px;
    animation: fadeInMessage 0.3s ease-in;
}

@keyframes fadeInMessage {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.ai-chat-message-user {
    flex-direction: row-reverse;
}

.ai-chat-message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 1.2em;
}

.ai-chat-message-user .ai-chat-message-avatar {
    background-color: rgba(100, 150, 255, 0.2);
    color: #6496ff;
}

.ai-chat-message-assistant .ai-chat-message-avatar {
    background-color: rgba(150, 100, 255, 0.2);
    color: #9664ff;
}

.ai-chat-message-content {
    flex: 1;
    max-width: calc(100% - 48px);
}

.ai-chat-message-user .ai-chat-message-content {
    display: flex;
    justify-content: flex-end;
}

.ai-chat-message-text {
    background-color: rgba(40, 40, 40, 0.8);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 12px 16px;
    color: #ddd;
    line-height: 1.5;
    word-wrap: break-word;
    white-space: pre-wrap;
}

.ai-chat-message-user .ai-chat-message-text {
    background-color: rgba(100, 150, 255, 0.15);
    border-color: rgba(100, 150, 255, 0.3);
    color: #fff;
}

.ai-chat-message-assistant .ai-chat-message-text {
    background-color: rgba(50, 50, 50, 0.8);
    border-color: rgba(255, 255, 255, 0.1);
}

.ai-chat-message-text.loading {
    position: relative;
}

.ai-chat-message-text.loading::after {
    content: '...';
    animation: loadingDots 1.5s infinite;
}

@keyframes loadingDots {
    0%, 20% { content: '.'; }
    40% { content: '..'; }
    60%, 100% { content: '...'; }
}

/* Typing Indicator */
.ai-chat-typing-indicator {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
}

.ai-chat-typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: rgba(255, 255, 255, 0.5);
    animation: typingDot 1.4s infinite;
}

.ai-chat-typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.ai-chat-typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typingDot {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.5;
    }
    30% {
        transform: translateY(-8px);
        opacity: 1;
    }
}

/* ----------------------------------------------------------------------------
   Markdown Styling (Message Content)
   ---------------------------------------------------------------------------- */
.ai-chat-message-text h1,
.ai-chat-message-text h2,
.ai-chat-message-text h3 {
    margin: 16px 0 8px 0;
    color: #fff;
    font-weight: 600;
}

.ai-chat-message-text h1 {
    font-size: 1.5em;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
    padding-bottom: 8px;
}

.ai-chat-message-text h2 {
    font-size: 1.3em;
}

.ai-chat-message-text h3 {
    font-size: 1.1em;
}

.ai-chat-message-text h1:first-child,
.ai-chat-message-text h2:first-child,
.ai-chat-message-text h3:first-child {
    margin-top: 0;
}

.ai-chat-message-text p {
    margin: 8px 0;
    line-height: 1.6;
}

.ai-chat-message-text p:first-child {
    margin-top: 0;
}

.ai-chat-message-text p:last-child {
    margin-bottom: 0;
}

.ai-chat-message-text code {
    background-color: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    padding: 2px 6px;
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.9em;
    color: #ffd700;
}

.ai-chat-message-text pre {
    background-color: rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 8px;
    padding: 12px;
    margin: 12px 0;
    overflow-x: auto;
    white-space: pre;
}

.ai-chat-message-text pre code {
    background: none;
    border: none;
    padding: 0;
    color: #e0e0e0;
    font-size: 0.85em;
    display: block;
}

.ai-chat-message-text ul,
.ai-chat-message-text ol {
    margin: 12px 0;
    padding-left: 24px;
}

.ai-chat-message-text li {
    margin: 6px 0;
    line-height: 1.5;
}

.ai-chat-message-text ul {
    list-style-type: disc;
}

.ai-chat-message-text ol {
    list-style-type: decimal;
}

.ai-chat-message-text a {
    color: #6496ff;
    text-decoration: underline;
    transition: color 0.2s ease;
}

.ai-chat-message-text a:hover {
    color: #7aa3ff;
}

.ai-chat-message-text blockquote {
    border-left: 3px solid rgba(100, 150, 255, 0.5);
    padding-left: 16px;
    margin: 12px 0;
    color: rgba(255, 255, 255, 0.8);
    font-style: italic;
}

.ai-chat-message-text hr {
    border: none;
    border-top: 1px solid rgba(255, 255, 255, 0.2);
    margin: 16px 0;
}

.ai-chat-message-text strong {
    font-weight: 600;
    color: #fff;
}

.ai-chat-message-text em {
    font-style: italic;
    color: rgba(255, 255, 255, 0.9);
}

.ai-chat-message-text del {
    text-decoration: line-through;
    opacity: 0.7;
}

/* ----------------------------------------------------------------------------
   Input Container (Bottom Section)
   ---------------------------------------------------------------------------- */
.ai-chat-input-container {
    padding: 16px 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    background-color: rgba(20, 20, 20, 0.5);
}

.ai-chat-form {
    display: flex;
    gap: 12px;
    align-items: flex-end;
}

.ai-chat-input {
    flex: 1;
    background-color: rgba(40, 40, 40, 0.8);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    color: #fff;
    padding: 12px 16px;
    font-size: 1em;
    font-family: inherit;
    resize: none;
    outline: none;
    transition: all 0.2s ease;
    max-height: 120px;
    overflow-y: auto;
    line-height: 1.5;
}

.ai-chat-input:focus {
    border-color: rgba(100, 150, 255, 0.5);
    background-color: rgba(50, 50, 50, 0.9);
}

.ai-chat-input::placeholder {
    color: rgba(255, 255, 255, 0.4);
}

.ai-chat-send-btn {
    background-color: rgba(100, 150, 255, 0.8);
    border: none;
    border-radius: 12px;
    color: #fff;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
    font-size: 1.1em;
}

.ai-chat-send-btn:hover:not(:disabled) {
    background-color: rgba(100, 150, 255, 1);
    transform: scale(1.05);
}

.ai-chat-send-btn:active:not(:disabled) {
    transform: scale(0.95);
}

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

.ai-chat-status {
    margin-top: 8px;
    font-size: 0.85em;
    color: rgba(255, 255, 255, 0.5);
    text-align: center;
    min-height: 20px;
}

.ai-chat-status.error {
    color: #ff6b6b;
}

.ai-chat-status.success {
    color: #51cf66;
}

.ai-chat-status.warning {
    color: #ffd43b;
}

@keyframes pulse {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(255, 80, 80, 0.7);
    }
    50% {
        box-shadow: 0 0 0 8px rgba(255, 80, 80, 0);
    }
}

/* ----------------------------------------------------------------------------
   Model Info Modal
   ---------------------------------------------------------------------------- */
.ai-chat-model-info-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10001;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease-in-out, visibility 0.3s ease-in-out;
}

.ai-chat-model-info-modal.active {
    opacity: 1;
    visibility: visible;
}

.ai-chat-model-info-modal.hidden {
    display: none;
}

.ai-chat-model-info-modal-content {
    background-color: rgba(30, 30, 30, 0.95);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    padding: 24px;
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    position: relative;
    transform: scale(0.95);
    transition: transform 0.3s ease-in-out;
}

.ai-chat-model-info-modal.active .ai-chat-model-info-modal-content {
    transform: scale(1);
}

.ai-chat-model-info-modal-close-btn {
    position: absolute;
    top: 16px;
    right: 16px;
    background: none;
    border: none;
    color: #fff;
    font-size: 1.5em;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 8px;
    transition: background-color 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
}

.ai-chat-model-info-modal-close-btn:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

.ai-chat-model-info-title {
    margin: 0 0 20px 0;
    font-size: 1.5em;
    color: #fff;
    font-weight: 600;
    padding-right: 40px;
}

.ai-chat-model-info-content {
    color: #ddd;
    line-height: 1.6;
}

.ai-chat-model-info-item {
    margin-bottom: 16px;
    padding-bottom: 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.ai-chat-model-info-item:last-child {
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: none;
}

.ai-chat-model-info-item strong {
    color: #fff;
    display: block;
    margin-bottom: 4px;
    font-weight: 600;
}

.ai-chat-model-info-modal-content::-webkit-scrollbar {
    width: 6px;
}

.ai-chat-model-info-modal-content::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 3px;
}

.ai-chat-model-info-modal-content::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

.ai-chat-model-info-modal-content::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* ----------------------------------------------------------------------------
   Responsive Design
   ---------------------------------------------------------------------------- */
@media (max-width: 768px) {
    .ai-chat-window {
        width: 85vw;
        max-height: 90vh;
        border-radius: 12px;
    }
    
    .ai-chat-header {
        padding: 12px 16px;
    }
    
    .ai-chat-title {
        font-size: 1em;
    }
    
    .ai-chat-model-selector {
        flex: 1 1 auto;
        max-width: 100%;
    }
    
    .ai-chat-model-dropdown-toggle {
        font-size: 0.75em;
        padding: 6px 28px 6px 8px;
        min-width: 100px;
    }
    
    .ai-chat-model-dropdown-menu {
        max-height: 150px;
    }
    
    .ai-chat-model-dropdown-option {
        padding: 8px 10px;
        font-size: 0.8em;
    }
    
    .ai-chat-messages {
        padding: 16px;
        gap: 12px;
    }
    
    .ai-chat-input-container {
        padding: 12px 16px;
    }
    
    .ai-chat-message-avatar {
        width: 32px;
        height: 32px;
        font-size: 1em;
    }
    
    .ai-chat-message-text {
        padding: 10px 14px;
        font-size: 0.95em;
    }

    .ai-chat-model-info-modal-content {
        padding: 20px;
        max-width: 95%;
    }
    
    .ai-chat-model-info-title {
        font-size: 1.3em;
    }
}