/* ============= AI Chat CSS ============= */

/* --- Chat Page Layout --- */
.ai-chat-body {
    margin: 0;
    padding: 0;
    height: 100vh;
    overflow: hidden;
    background: #111118;
    color: #e4e4e7;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

.ai-chat-layout {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* --- Sidebar --- */
.ai-sidebar {
    width: 280px;
    min-width: 280px;
    background: #16161e;
    border-right: 1px solid rgba(255,255,255,0.06);
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease;
    z-index: 100;
}

.ai-sidebar-header {
    padding: 16px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
}

.ai-btn-new-chat {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    height: 40px;
    background: rgba(99,102,241,0.12);
    border: 1px solid rgba(99,102,241,0.2);
    border-radius: 10px;
    color: #a5b4fc;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.ai-btn-new-chat:hover {
    background: rgba(99,102,241,0.2);
    border-color: rgba(99,102,241,0.35);
}

.ai-sidebar-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.ai-sidebar-list::-webkit-scrollbar {
    width: 4px;
}

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

.ai-sidebar-empty {
    text-align: center;
    color: rgba(255,255,255,0.25);
    font-size: 13px;
    padding: 40px 16px;
}

.ai-conv-item {
    display: flex;
    align-items: center;
    padding: 10px 12px;
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.15s;
    margin-bottom: 2px;
    position: relative;
}

.ai-conv-item:hover {
    background: rgba(255,255,255,0.04);
}

.ai-conv-item.active {
    background: rgba(99,102,241,0.12);
}

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

.ai-conv-item-title {
    font-size: 13px;
    color: #d4d4d8;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 3px;
}

.ai-conv-item.active .ai-conv-item-title {
    color: #a5b4fc;
}

.ai-conv-item-meta {
    font-size: 11px;
    color: rgba(255,255,255,0.25);
    white-space: nowrap;
}

/* --- Main Area --- */
.ai-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    height: 100vh;
}

/* --- Header --- */
.ai-header {
    display: flex;
    align-items: center;
    padding: 10px 16px;
    background: #16161e;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    gap: 12px;
    flex-shrink: 0;
}

.ai-btn-sidebar-toggle {
    display: none;
    background: none;
    border: none;
    color: rgba(255,255,255,0.5);
    cursor: pointer;
    padding: 6px;
    border-radius: 8px;
    transition: all 0.2s;
}

.ai-btn-sidebar-toggle:hover {
    background: rgba(255,255,255,0.06);
    color: #fff;
}

.ai-header-center {
    flex: 1;
    min-width: 0;
}

.ai-header-title {
    font-size: 15px;
    font-weight: 600;
    color: #e4e4e7;
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ai-header-tools {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.ai-model-select {
    height: 32px;
    padding: 0 8px;
    background: #1e1e2a;
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 8px;
    color: #d4d4d8;
    font-size: 12px;
    outline: none;
    cursor: pointer;
    max-width: 150px;
}

.ai-model-select option {
    background: #1e1e2a;
    color: #d4d4d8;
}

.ai-quota-bars {
    display: flex;
    gap: 12px;
    align-items: center;
}

.ai-quota-item {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 11px;
}

.ai-quota-label {
    color: rgba(255,255,255,0.35);
}

.ai-progress {
    width: 50px;
    height: 4px;
    background: rgba(255,255,255,0.06);
    border-radius: 2px;
    overflow: hidden;
}

.ai-progress-fill {
    height: 100%;
    border-radius: 2px;
    transition: width 0.4s ease;
}

.ai-progress-today {
    background: linear-gradient(90deg, #6366f1, #818cf8);
}

.ai-progress-week {
    background: linear-gradient(90deg, #f59e0b, #fbbf24);
}

.ai-progress-fill.warning {
    background: linear-gradient(90deg, #f59e0b, #f97316);
}

.ai-progress-fill.danger {
    background: linear-gradient(90deg, #ef4444, #dc2626);
}

.ai-quota-percent {
    color: rgba(255,255,255,0.35);
    min-width: 28px;
    font-size: 11px;
}

.ai-btn-tool {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: none;
    background: none;
    color: rgba(255,255,255,0.4);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.ai-btn-tool:hover {
    background: rgba(255,255,255,0.06);
    color: #fff;
}

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

.ai-btn-logout:hover {
    color: #fca5a5;
    background: rgba(239,68,68,0.1);
}

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

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

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

.ai-messages-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: rgba(255,255,255,0.2);
    text-align: center;
}

.ai-empty-icon {
    margin-bottom: 16px;
    opacity: 0.4;
}

.ai-messages-empty h3 {
    font-size: 18px;
    font-weight: 600;
    color: rgba(255,255,255,0.25);
    margin: 0 0 8px;
}

.ai-messages-empty p {
    font-size: 13px;
    color: rgba(255,255,255,0.15);
    margin: 0;
}

.ai-msg {
    display: flex;
    gap: 10px;
    max-width: 85%;
    animation: msgIn 0.3s ease;
}

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

.ai-msg-user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.ai-msg-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
}

.ai-msg-assistant .ai-msg-avatar {
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: #fff;
}

.ai-msg-user .ai-msg-avatar {
    background: rgba(255,255,255,0.08);
    color: rgba(255,255,255,0.6);
}

.ai-msg-content {
    padding: 12px 16px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.6;
    word-break: break-word;
}

.ai-msg-assistant .ai-msg-content {
    background: #1e1e2a;
    border: 1px solid rgba(255,255,255,0.04);
    color: #e4e4e7;
}

.ai-msg-user .ai-msg-content {
    background: rgba(99,102,241,0.12);
    color: #e4e4e7;
    border: 1px solid rgba(99,102,241,0.15);
}

.ai-msg-content pre {
    background: #0d0d14;
    border-radius: 8px;
    padding: 12px;
    overflow-x: auto;
    font-size: 13px;
    line-height: 1.5;
    margin: 8px 0;
    border: 1px solid rgba(255,255,255,0.04);
}

.ai-msg-content code {
    font-family: "SF Mono", "Monaco", "Menlo", "Consolas", monospace;
    font-size: 13px;
}

.ai-msg-content p {
    margin: 0 0 8px;
}

.ai-msg-content p:last-child {
    margin-bottom: 0;
}

.ai-msg-failed {
    opacity: 0.6;
}

.ai-msg-failed .ai-msg-content {
    border-color: rgba(239,68,68,0.2);
}

.ai-msg-error {
    font-size: 11px;
    color: #fca5a5;
    margin-top: 4px;
}

.ai-msg-thinking {
    align-self: flex-start;
}

.ai-msg-thinking .ai-msg-content {
    background: #1e1e2a;
    color: rgba(255,255,255,0.4);
    font-style: italic;
    padding: 10px 20px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.ai-thinking-dot {
    width: 5px;
    height: 5px;
    background: rgba(255,255,255,0.3);
    border-radius: 50%;
    animation: dotPulse 1.4s infinite;
}

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

@keyframes dotPulse {
    0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
    40% { opacity: 1; transform: scale(1); }
}

/* --- Input Area --- */
.ai-input-area {
    padding: 12px 16px 16px;
    border-top: 1px solid rgba(255,255,255,0.06);
    background: #16161e;
    flex-shrink: 0;
}

.ai-input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: #1e1e2a;
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 14px;
    padding: 6px 6px 6px 14px;
    transition: border-color 0.2s;
}

.ai-input-wrapper:focus-within {
    border-color: rgba(99,102,241,0.4);
}

.ai-textarea {
    flex: 1;
    background: none;
    border: none;
    color: #e4e4e7;
    font-size: 14px;
    line-height: 1.5;
    resize: none;
    outline: none;
    max-height: 120px;
    padding: 6px 0;
    font-family: inherit;
}

.ai-textarea::placeholder {
    color: rgba(255,255,255,0.2);
}

.ai-btn-send {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    border: none;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.2s;
}

.ai-btn-send:hover {
    background: linear-gradient(135deg, #5558e6, #7c4fea);
    transform: scale(1.05);
}

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

.ai-input-hint {
    text-align: center;
    color: rgba(255,255,255,0.15);
    font-size: 11px;
    margin-top: 6px;
}

.ai-input-area.disabled .ai-input-wrapper {
    opacity: 0.4;
    pointer-events: none;
}

/* --- Sidebar Overlay (mobile) --- */
.ai-sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 99;
}

/* --- Responsive --- */
@media (max-width: 768px) {
    .ai-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        transform: translateX(-100%);
    }

    .ai-sidebar.active {
        transform: translateX(0);
    }

    .ai-sidebar-overlay.active {
        display: block;
    }

    .ai-btn-sidebar-toggle {
        display: flex;
    }

    .ai-header-tools {
        gap: 4px;
    }

    .ai-quota-bars {
        display: none;
    }

    .ai-model-select {
        max-width: 120px;
    }

    .ai-msg {
        max-width: 92%;
    }

    .ai-header {
        padding: 8px 10px;
    }
}
