/* ============================================
   LLM Chat - Dark Theme
   Matches DAT Workspace design language
   ============================================ */

/* ---------- CSS Variables ---------- */
:root {
    --bg-primary: #0f1117;
    --bg-secondary: #1a1d27;
    --bg-card: #222636;
    --bg-input: #2a2e3f;
    --border: #2e3348;
    --text-primary: #f5f6fa;
    --text-secondary: #cdd1e0;
    --text-muted: #a0a4b8;
    --accent: #6c8cff;
    --accent-hover: #8ba4ff;
    --green: #4ade80;
    --yellow: #facc15;
    --red: #f87171;
    --orange: #fb923c;
    --radius: 8px;

    --header-height: 52px;
    --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

/* ---------- Reset & Base ---------- */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
}

html {
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
}

body {
    font-family: var(--font-family);
    background: var(--bg-primary);
    color: var(--text-primary);
    display: flex;
    flex-direction: column;
}

/* ---------- Header ---------- */
.header {
    background: rgba(15, 17, 23, 0.6);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid rgba(108, 140, 255, 0.1);
    padding: 0 20px;
    height: var(--header-height);
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.header__back {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 6px;
    color: var(--text-secondary);
    text-decoration: none;
    transition: background 0.2s, color 0.2s;
}

.header__back:hover {
    background: rgba(108, 140, 255, 0.15);
    color: var(--text-primary);
}

.header__back svg {
    width: 20px;
    height: 20px;
}

.header__title {
    font-size: 1.1rem;
    font-weight: 600;
    background: linear-gradient(135deg, var(--accent) 0%, hsla(270, 50%, 65%, 1) 50%, hsla(40, 80%, 60%, 1) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.header__spacer {
    flex: 1;
}

.header__actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ---------- Main Chat Container ---------- */
.chat-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    max-width: 900px;
    width: 100%;
    margin: 0 auto;
    padding: 16px 20px 20px;
    min-height: 0;
}

.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    min-height: 0;
}

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

.chat-messages:empty::before {
    content: 'Start a conversation...';
    color: var(--text-muted);
    text-align: center;
    padding: 40px 20px;
    font-size: 0.9rem;
}

.chat-msg {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.6;
    word-wrap: break-word;
    white-space: pre-wrap;
}

.chat-msg.user {
    align-self: flex-end;
    background: var(--accent);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.chat-msg.assistant {
    align-self: flex-start;
    background: var(--bg-input);
    color: var(--text-primary);
    border-bottom-left-radius: 4px;
}

.chat-msg .tokens {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.chat-msg.assistant .tokens {
    border-top-color: var(--border);
}

/* ---------- Input Area ---------- */
.chat-form {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    padding: 16px;
    border-top: 1px solid var(--border);
    background: var(--bg-secondary);
}

.chat-input {
    flex: 1;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    padding: 12px 14px;
    font-size: 14px;
    font-family: inherit;
    resize: none;
    outline: none;
    min-height: 48px;
    max-height: 150px;
    line-height: 1.5;
    transition: border-color 0.15s;
}

.chat-input:focus {
    border-color: var(--accent);
}

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

/* ---------- Buttons ---------- */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    font-family: inherit;
    transition: background 0.15s, opacity 0.15s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    white-space: nowrap;
    text-decoration: none;
}

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

.btn--accent {
    background: var(--accent);
    color: #fff;
    min-width: 80px;
}

.btn--accent:hover:not(:disabled) {
    background: var(--accent-hover);
}

.btn--secondary {
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-secondary);
    border: 1px solid var(--border);
    padding: 8px 14px;
    font-size: 13px;
}

.btn--secondary:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

.btn svg {
    width: 16px;
    height: 16px;
}

/* ---------- Access Denied ---------- */
.access-denied {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    flex: 1;
    color: var(--text-muted);
    text-align: center;
    padding: 20px;
}

.access-denied h2 {
    color: var(--red);
    font-size: 1.3rem;
}

.access-denied p {
    font-size: 0.9rem;
    max-width: 300px;
}

.access-denied svg {
    color: var(--red);
    opacity: 0.6;
}

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ---------- Image Attachment Button ---------- */
.btn--icon {
    padding: 10px;
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.btn--icon:hover {
    background: rgba(108, 140, 255, 0.15);
    color: var(--accent);
    border-color: var(--accent);
}

.btn--icon svg {
    width: 20px;
    height: 20px;
}

/* ---------- Image Preview Area ---------- */
.image-preview {
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    background: var(--bg-secondary);
}

.image-preview__list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.image-preview__item {
    position: relative;
    width: 80px;
    height: 80px;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--border);
}

.image-preview__item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.image-preview__remove {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.7);
    border: none;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    line-height: 1;
    transition: background 0.15s;
}

.image-preview__remove:hover {
    background: var(--red);
}

/* ---------- Images in Chat Messages ---------- */
.chat-msg__images {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 8px;
}

.chat-msg__image {
    max-width: 200px;
    max-height: 200px;
    border-radius: 8px;
    cursor: pointer;
    transition: transform 0.15s;
}

.chat-msg__image:hover {
    transform: scale(1.02);
}

/* Image modal for full-size view */
.image-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
    cursor: zoom-out;
}

.image-modal img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 8px;
}

/* ---------- Responsive ---------- */
@media (max-width: 600px) {
    .chat-wrapper {
        padding: 12px;
    }

    .chat-msg {
        max-width: 90%;
    }

    .chat-form {
        padding: 12px;
    }

    .image-preview__item {
        width: 60px;
        height: 60px;
    }

    .chat-msg__image {
        max-width: 150px;
        max-height: 150px;
    }
}
