/* ============================================================
   styles.css — AI chat UI
   All colors via CSS custom properties defined in sidebar.css.
   No hardcoded hex — fully theme-aware.
   ============================================================ */

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* ── Chat Window ───────────────────────────────────────────── */

.chat-window {
    flex: 1;
    overflow-y: auto;
    padding: 28px 32px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    scroll-behavior: smooth;
    width: 100%;
}

.chat-window::-webkit-scrollbar { width: 4px; }
.chat-window::-webkit-scrollbar-track { background: transparent; }
.chat-window::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 2px; }

/* ── Empty State ───────────────────────────────────────────── */

.empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    color: var(--text-tertiary);
    text-align: center;
    user-select: none;
}

.empty-icon { margin-bottom: 4px; }

.empty-state p {
    font-size: 14px;
    color: var(--text-secondary);
    font-weight: 500;
}

.empty-sub {
    font-size: 11px !important;
    color: var(--text-tertiary) !important;
    font-weight: 400 !important;
    letter-spacing: 0.02em;
}

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

.message {
    display: flex;
    flex-direction: column;
    gap: 5px;
    max-width: 100%;
    animation: fadeUp 0.18s ease-out forwards;
    opacity: 0;
}

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

.message.user {
    align-self: flex-end;
    max-width: 78%;
}

.message.ai {
    align-self: flex-start;
    max-width: 90%;
}

.message.error-msg {
    align-self: flex-start;
}

.message-label {
    font-size: 10px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-tertiary);
    font-weight: 600;
    padding: 0 2px;
}

.message.user .message-label { color: var(--accent-color); opacity: 0.8; }
.message.error-msg .message-label { color: #FF453A; opacity: 0.9; }

.message-text {
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.65;
    color: var(--text-primary);
    word-break: break-word;
}

.message.user .message-text {
    background: var(--surface-secondary);
    border: 1px solid var(--border-color);
    border-bottom-right-radius: 4px;
}

.message.ai .message-text {
    background: var(--surface-primary);
    border: 1px solid var(--border-color);
    border-bottom-left-radius: 4px;
    white-space: pre-wrap;
}

.message.error-msg .message-text {
    background: rgba(255,69,58,0.06);
    border: 1px solid rgba(255,69,58,0.2);
    color: #FF453A;
    font-size: 13px;
}

/* ── Thinking ──────────────────────────────────────────────── */

.thinking {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    border-radius: 12px;
    border-bottom-left-radius: 4px;
    background: var(--surface-primary);
    border: 1px solid var(--border-color);
    align-self: flex-start;
    animation: fadeUp 0.18s ease-out forwards;
}

.thinking-dots {
    display: flex;
    gap: 4px;
}

.thinking-dots span {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--accent-color);
    animation: dot-bounce 1.2s ease-in-out infinite;
    opacity: 0.6;
}

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

@keyframes dot-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-4px); opacity: 1; }
}

.thinking-label {
    font-size: 11px;
    color: var(--text-secondary);
    font-weight: 500;
}

/* ── Retry / upgrade ───────────────────────────────────────── */

.retry-btn {
    align-self: flex-start;
    margin-top: 4px;
    font-size: 11px;
    padding: 5px 12px;
    border-radius: 7px;
    border: 1px solid var(--border-color);
    background: var(--surface-secondary);
    color: var(--text-secondary);
    cursor: pointer;
    font-family: inherit;
    transition: border-color 0.15s, color 0.15s;
}

.retry-btn:hover {
    border-color: var(--accent-color);
    color: var(--accent-color);
}

.upgrade-prompt {
    align-self: flex-start;
    margin-top: 6px;
}

.upgrade-prompt a {
    font-size: 12px;
    color: #f59e0b;
    text-decoration: none;
    border: 1px solid rgba(245,158,11,0.3);
    padding: 5px 12px;
    border-radius: 7px;
    background: rgba(245,158,11,0.06);
}

/* ── Input Area ────────────────────────────────────────────── */

.input-area {
    border-top: 1px solid var(--border-color);
    padding: 16px 32px 20px;
    background: var(--surface-primary);
    flex-shrink: 0;
    width: 100%;
}

.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    background: var(--surface-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 10px 10px 10px 16px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.input-wrapper:focus-within {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent-color) 12%, transparent);
}

.input-field {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 14px;
    line-height: 1.5;
    resize: none;
    max-height: 120px;
    overflow-y: auto;
}

.input-field::placeholder { color: var(--text-tertiary); }
.input-field:disabled { opacity: 0.4; cursor: not-allowed; }
.input-field::-webkit-scrollbar { width: 3px; }
.input-field::-webkit-scrollbar-thumb { background: var(--border-color); }

.send-btn {
    width: 36px;
    height: 36px;
    border-radius: 9px;
    background: var(--accent-color);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: #fff;
    transition: opacity 0.15s, transform 0.1s;
}

.send-btn:hover:not(:disabled) { opacity: 0.85; transform: translateY(-1px); }
.send-btn:active:not(:disabled) { transform: translateY(0); }
.send-btn:disabled { background: var(--surface-tertiary); opacity: 0.5; cursor: not-allowed; }

.input-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 8px;
    padding: 0 2px;
}

.key-info {
    font-size: 11px;
    color: var(--text-tertiary);
    font-weight: 500;
}

.char-count {
    font-size: 11px;
    color: var(--text-tertiary);
}

/* ── Markdown in AI messages ───────────────────────────────── */

.message-text.md h1,
.message-text.md h2,
.message-text.md h3,
.message-text.md h4 {
    color: var(--text-primary);
    font-weight: 700;
    margin: 14px 0 6px;
    line-height: 1.3;
}

.message-text.md h1 { font-size: 18px; }
.message-text.md h2 { font-size: 16px; }
.message-text.md h3 { font-size: 14px; }
.message-text.md p { margin: 6px 0; }
.message-text.md ul,
.message-text.md ol { margin: 6px 0 6px 20px; display: flex; flex-direction: column; gap: 3px; }
.message-text.md li { line-height: 1.6; }
.message-text.md strong { color: var(--text-primary); font-weight: 600; }
.message-text.md em { font-style: italic; color: var(--text-secondary); }
.message-text.md a { color: var(--accent-color); text-decoration: underline; }
.message-text.md hr { border: none; border-top: 1px solid var(--border-color); margin: 12px 0; }
.message-text.md code {
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 12px;
    background: var(--surface-tertiary);
    border: 1px solid var(--border-color);
    padding: 1px 6px;
    border-radius: 5px;
    color: var(--accent-color);
}
.message-text.md pre {
    background: var(--surface-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 14px 16px;
    overflow-x: auto;
    margin: 10px 0;
}
.message-text.md pre code {
    background: none;
    border: none;
    padding: 0;
    color: var(--text-primary);
    font-size: 13px;
    line-height: 1.6;
}
.message-text.md blockquote {
    border-left: 3px solid var(--accent-color);
    padding: 4px 0 4px 14px;
    margin: 8px 0;
    color: var(--text-secondary);
    font-style: italic;
}
.message-text.md table {
    border-collapse: collapse;
    width: 100%;
    margin: 10px 0;
    font-size: 13px;
}
.message-text.md th,
.message-text.md td {
    border: 1px solid var(--border-color);
    padding: 7px 12px;
    text-align: left;
}
.message-text.md th {
    background: var(--surface-secondary);
    font-weight: 600;
    font-size: 11px;
}
.message-text.md tr:nth-child(even) {
    background: color-mix(in srgb, var(--accent-color) 3%, transparent);
}

/* ── Background container (ProgInsight standard) ───────────── */

#bg-container {
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    overflow: hidden;
}

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

@media (max-width: 768px) {
    .chat-window,
    .input-area {
        padding-left: 16px;
        padding-right: 16px;
    }

    .message.user { max-width: 95%; }
}
