/* ── AI Chat Widget ────────────────────────────────────────────────────────── */

.ai-chat-toggle {
    position: fixed;
    top: 20px;
    right: 20px;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: #1a1a2e;
    border: 2px solid #3a3a5c;
    color: #fff;
    font-size: 22px;
    cursor: pointer;
    z-index: 10000001;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(0,0,0,0.3);
    transition: background 0.2s, transform 0.2s;
}
.ai-chat-toggle:hover {
    background: #2a2a4e;
    transform: scale(1.08);
}
.ai-chat-toggle.active {
    background: #3a3a5c;
}

/* ── Panel ─────────────────────────────────────────────────────────────────── */

.ai-chat-panel {
    position: fixed;
    top: 82px;
    right: 20px;
    width: 420px;
    height: 540px;
    min-width: 320px;
    min-height: 300px;
    max-width: calc(100vw - 40px);
    max-height: calc(100vh - 100px);
    background: #13131f;
    border: 1px solid #2a2a44;
    border-radius: 14px;
    z-index: 10000001;
    display: none;
    flex-direction: column;
    box-shadow: 0 8px 32px rgba(0,0,0,0.45);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif;
    overflow: hidden;
}
.ai-chat-panel.open {
    display: flex;
}

/* ── Resize handle (top-left corner) ───────────────────────────────────────── */

.ai-chat-resize {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 18px;
    height: 18px;
    cursor: sw-resize;
    z-index: 2;
    border-bottom-left-radius: 14px;
}
.ai-chat-resize::after {
    content: "";
    position: absolute;
    bottom: 5px;
    left: 5px;
    width: 8px;
    height: 8px;
    border-bottom: 2px solid #4a4a6a;
    border-left: 2px solid #4a4a6a;
    border-bottom-left-radius: 3px;
    opacity: 0.5;
    transition: opacity 0.15s;
}
.ai-chat-resize:hover::after {
    opacity: 1;
}

/* ── Header ────────────────────────────────────────────────────────────────── */

.ai-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    background: #1a1a2e;
    border-bottom: 1px solid #2a2a44;
    flex-shrink: 0;
}
.ai-chat-header-title {
    font-size: 14px;
    font-weight: 600;
    color: #e0e0f0;
    display: flex;
    align-items: center;
    gap: 8px;
}
.ai-chat-header-title .ai-chat-icon {
    font-size: 16px;
}
.ai-chat-header-actions {
    display: flex;
    gap: 4px;
}
.ai-chat-header-btn {
    background: none;
    border: none;
    color: #888;
    font-size: 14px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    transition: background 0.15s, color 0.15s;
}
.ai-chat-header-btn:hover {
    background: #2a2a44;
    color: #e0e0f0;
}

/* ── Messages area ─────────────────────────────────────────────────────────── */

.ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.ai-chat-messages::-webkit-scrollbar {
    width: 6px;
}
.ai-chat-messages::-webkit-scrollbar-track {
    background: transparent;
}
.ai-chat-messages::-webkit-scrollbar-thumb {
    background: #2a2a44;
    border-radius: 3px;
}

/* ── Message bubbles ───────────────────────────────────────────────────────── */

.ai-chat-msg {
    max-width: 92%;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 13px;
    line-height: 1.55;
    color: #d8d8e8;
    word-wrap: break-word;
}
.ai-chat-msg.user {
    align-self: flex-end;
    background: #2b4a8a;
    border-bottom-right-radius: 4px;
    color: #f0f0ff;
}
.ai-chat-msg.assistant {
    align-self: flex-start;
    background: #1e1e34;
    border-bottom-left-radius: 4px;
    border: 1px solid #2a2a44;
}

/* Markdown inside assistant messages */
.ai-chat-msg.assistant p {
    margin: 0 0 8px 0;
}
.ai-chat-msg.assistant p:last-child {
    margin-bottom: 0;
}
.ai-chat-msg.assistant strong {
    color: #c0c8ff;
}
.ai-chat-msg.assistant table {
    border-collapse: collapse;
    margin: 8px 0;
    font-size: 12px;
    width: 100%;
}
.ai-chat-msg.assistant th,
.ai-chat-msg.assistant td {
    border: 1px solid #2a2a44;
    padding: 5px 8px;
    text-align: left;
}
.ai-chat-msg.assistant th {
    background: #252540;
    color: #c0c8ff;
    font-weight: 600;
}
.ai-chat-msg.assistant code {
    background: #252540;
    padding: 1px 5px;
    border-radius: 4px;
    font-size: 12px;
}
.ai-chat-msg.assistant ul,
.ai-chat-msg.assistant ol {
    margin: 4px 0;
    padding-left: 20px;
}
.ai-chat-msg.assistant li {
    margin-bottom: 2px;
}

/* ── Typing indicator ──────────────────────────────────────────────────────── */

.ai-chat-typing {
    display: flex;
    gap: 4px;
    padding: 4px 0;
}
.ai-chat-typing span {
    width: 7px;
    height: 7px;
    background: #4a4a6a;
    border-radius: 50%;
    animation: ai-chat-bounce 1.2s infinite;
}
.ai-chat-typing span:nth-child(2) { animation-delay: 0.2s; }
.ai-chat-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes ai-chat-bounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-6px); }
}

/* ── Input area ────────────────────────────────────────────────────────────── */

.ai-chat-input-area {
    display: flex;
    align-items: flex-end;
    padding: 12px;
    border-top: 1px solid #2a2a44;
    background: #1a1a2e;
    gap: 8px;
    flex-shrink: 0;
}
.ai-chat-input {
    flex: 1;
    background: #13131f;
    border: 1px solid #2a2a44;
    border-radius: 10px;
    padding: 10px 14px;
    color: #e0e0f0;
    font-size: 13px;
    font-family: inherit;
    resize: none;
    min-height: 40px;
    max-height: 100px;
    outline: none;
    transition: border-color 0.2s;
    line-height: 1.4;
}
.ai-chat-input::placeholder {
    color: #555;
}
.ai-chat-input:focus {
    border-color: #4a4a8a;
}
.ai-chat-send {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: #3b5cc6;
    border: none;
    color: #fff;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    flex-shrink: 0;
}
.ai-chat-send:hover {
    background: #4b6cd6;
}
.ai-chat-send:disabled {
    background: #2a2a44;
    color: #555;
    cursor: not-allowed;
}

/* ── Welcome state ─────────────────────────────────────────────────────────── */

.ai-chat-welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    padding: 32px 24px;
    text-align: center;
    color: #888;
}
.ai-chat-welcome-icon {
    font-size: 36px;
    margin-bottom: 16px;
    opacity: 0.6;
}
.ai-chat-welcome h3 {
    color: #c0c8ff;
    font-size: 16px;
    margin: 0 0 8px 0;
    font-weight: 600;
}
.ai-chat-welcome p {
    font-size: 13px;
    line-height: 1.5;
    margin: 0 0 16px 0;
}
.ai-chat-suggestions {
    display: flex;
    flex-direction: column;
    gap: 6px;
    width: 100%;
}
.ai-chat-suggestion {
    background: #1e1e34;
    border: 1px solid #2a2a44;
    border-radius: 8px;
    padding: 8px 12px;
    color: #b0b0d0;
    font-size: 12px;
    cursor: pointer;
    text-align: left;
    transition: background 0.15s, border-color 0.15s;
}
.ai-chat-suggestion:hover {
    background: #252540;
    border-color: #3a3a6c;
    color: #d0d0f0;
}

/* ── Error ─────────────────────────────────────────────────────────────────── */

.ai-chat-msg.error {
    align-self: center;
    background: #3a1a1a;
    border: 1px solid #5a2a2a;
    color: #ff8888;
    font-size: 12px;
    text-align: center;
}

/* ── Responsive ────────────────────────────────────────────────────────────── */

@media (max-width: 500px) {
    .ai-chat-panel {
        width: calc(100vw - 16px);
        right: 8px;
        top: 74px;
        height: calc(100vh - 90px);
        border-radius: 12px;
    }
    .ai-chat-toggle {
        top: 12px;
        right: 12px;
    }
}
