/* ─── CSS Variables (dark theme) ──────────────────────────────────────────── */
:root {
    --bg:              #0d0d0f;
    --bg-surface:      #16161a;
    --bg-elevated:     #1e1e24;
    --bg-input:        #252530;
    --border:          #2a2a36;
    --accent:          #4a9eff;
    --accent-dim:      #1d3d6b;
    --text-primary:    #e8e8f0;
    --text-secondary:  #8888a8;
    --text-muted:      #555570;
    --user-bubble:     #1a3a5c;
    --user-text:       #d0e8ff;
    --assistant-bg:    #1e1e24;
    --error-bg:        #3a1a1a;
    --error-text:      #ff8080;
    --radius:          12px;
    --radius-sm:       8px;
    --font:            -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --font-mono:       "JetBrains Mono", "Fira Code", Consolas, monospace;
}

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

html, body {
    height: 100%;
    background: var(--bg);
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

/* ─── App Layout ──────────────────────────────────────────────────────────── */
.app-layout {
    height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ─── App Shell (sidebar + main panel) ───────────────────────────────────── */
.app-shell {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ─── Sidebar ─────────────────────────────────────────────────────────────── */
.sidebar {
    width: 260px;
    min-width: 260px;
    background: var(--bg-surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 12px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.sidebar-title {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
}

.sidebar-new-btn {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    padding: 4px 10px;
    font-size: 12px;
    cursor: pointer;
    transition: border-color 0.15s, color 0.15s;
}

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

.conv-list {
    flex: 1;
    overflow-y: auto;
    padding: 6px 0;
}

.conv-empty {
    padding: 20px 14px;
    font-size: 13px;
    color: var(--text-muted);
    line-height: 1.5;
}

.conv-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    cursor: pointer;
    border-radius: var(--radius-sm);
    margin: 1px 6px;
    transition: background 0.12s;
    gap: 6px;
}

.conv-item:hover { background: var(--bg-elevated); }
.conv-item.active { background: var(--accent-dim); }

.conv-meta {
    flex: 1;
    min-width: 0;
}

.conv-title {
    font-size: 13px;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conv-date {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}

.conv-actions {
    display: none;
    gap: 2px;
    flex-shrink: 0;
}

.conv-item:hover .conv-actions { display: flex; }

.conv-action-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 3px 5px;
    border-radius: 4px;
    font-size: 13px;
    line-height: 1;
    transition: color 0.12s, background 0.12s;
}

.conv-action-btn:hover {
    color: var(--text-primary);
    background: var(--bg-input);
}

.conv-del-btn:hover {
    color: var(--error-text);
    background: var(--error-bg);
}

.sidebar-footer {
    padding: 12px 14px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.sidebar-user {
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
}

/* ─── Main Panel ──────────────────────────────────────────────────────────── */
.main-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 0 24px;
    min-width: 0;
}

/* ─── Conversation title badge (header) ───────────────────────────────────── */
.conv-title-badge {
    font-size: 12px;
    color: var(--text-muted);
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 3px 10px;
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ─── Shared conversation banner ──────────────────────────────────────────── */
.shared-banner {
    background: var(--accent-dim);
    border: 1px solid var(--accent);
    border-radius: var(--radius-sm);
    padding: 8px 14px;
    font-size: 13px;
    color: var(--accent);
    display: flex;
    align-items: center;
    flex-shrink: 0;
    margin-bottom: 8px;
}

.shared-new-btn {
    background: none;
    border: 1px solid var(--accent);
    color: var(--accent);
    border-radius: var(--radius-sm);
    padding: 3px 10px;
    font-size: 12px;
    cursor: pointer;
    margin-left: auto;
    transition: background 0.15s;
}

.shared-new-btn:hover { background: rgba(74, 158, 255, 0.15); }

/* ─── Toast notification ──────────────────────────────────────────────────── */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 10px 20px;
    border-radius: var(--radius);
    font-size: 13px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
    z-index: 1000;
    white-space: nowrap;
    animation: fadeIn 0.2s ease;
}

/* ─── Chat Container (legacy — kept for compatibility) ────────────────────── */
.chat-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-width: 860px;
    margin: 0 auto;
    width: 100%;
    padding: 0 16px;
}

/* ─── Header ──────────────────────────────────────────────────────────────── */
.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 0;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo {
    height: 32px;
    width: auto;
}

.header-titles h1 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
}

.header-subtitle {
    font-size: 12px;
    color: var(--text-secondary);
}

.header-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.user-pill {
    font-size: 12px;
    color: var(--text-secondary);
    background: var(--bg-elevated);
    padding: 4px 10px;
    border-radius: 20px;
    border: 1px solid var(--border);
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.btn-icon {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    padding: 6px 8px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    transition: border-color 0.15s, color 0.15s;
}

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

/* ─── Quick Actions ───────────────────────────────────────────────────────── */
.quick-actions-panel {
    padding: 32px 0 16px;
    flex-shrink: 0;
}

.quick-actions-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.quick-actions-row {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

.quick-action-card {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 16px;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
    min-width: 0;
}

.quick-action-card:hover {
    border-color: var(--accent-dim);
    background: var(--bg-input);
}

.qa-icon {
    font-size: 18px;
    flex-shrink: 0;
}

.qa-text {
    color: var(--text-secondary);
    font-size: 13px;
}

.qa-input {
    flex: 1;
    min-width: 80px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    padding: 4px 8px;
    font-size: 13px;
    outline: none;
}

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

.qa-btn {
    background: var(--accent);
    border: none;
    border-radius: var(--radius-sm);
    color: white;
    padding: 4px 12px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: opacity 0.15s;
}

.qa-btn:hover { opacity: 0.85; }

/* ─── Messages Area ───────────────────────────────────────────────────────── */
.messages-area {
    flex: 1;
    overflow-y: auto;
    padding: 20px 0;
    display: flex;
    flex-direction: column;
    gap: 16px;
    scroll-behavior: smooth;
}

.messages-area::-webkit-scrollbar { width: 4px; }
.messages-area::-webkit-scrollbar-track { background: transparent; }
.messages-area::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* ─── Message Bubbles ─────────────────────────────────────────────────────── */
.message {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    animation: fadeIn 0.2s ease;
}

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

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

.avatar-assistant {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--accent-dim);
    border: 1px solid var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent);
    flex-shrink: 0;
    margin-top: 2px;
}

.message-bubble {
    max-width: 78%;
    padding: 12px 16px;
    border-radius: var(--radius);
    line-height: 1.65;
    word-break: break-word;
}

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

.message-assistant .message-bubble {
    background: var(--assistant-bg);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
}

/* ─── Markdown Rendering inside Assistant Bubbles ─────────────────────────── */
.message-bubble h1, .message-bubble h2, .message-bubble h3 {
    font-weight: 600;
    margin: 12px 0 6px;
    color: var(--text-primary);
}

.message-bubble h1 { font-size: 16px; }
.message-bubble h2 { font-size: 15px; }
.message-bubble h3 { font-size: 14px; }

.message-bubble p { margin-bottom: 8px; }
.message-bubble p:last-child { margin-bottom: 0; }

.message-bubble ul, .message-bubble ol {
    padding-left: 20px;
    margin-bottom: 8px;
}

.message-bubble li { margin-bottom: 4px; }

.message-bubble strong { color: var(--text-primary); font-weight: 600; }

.message-bubble em { color: var(--text-secondary); }

.message-bubble code {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 1px 6px;
    font-family: var(--font-mono);
    font-size: 12px;
    color: #7ec8e3;
}

.message-bubble pre {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px;
    overflow-x: auto;
    margin: 8px 0;
}

.message-bubble pre code {
    background: none;
    border: none;
    padding: 0;
    color: var(--text-primary);
}

.message-bubble blockquote {
    border-left: 3px solid var(--accent);
    padding-left: 12px;
    color: var(--text-secondary);
    margin: 8px 0;
}

.message-bubble hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 12px 0;
}

.message-bubble a {
    color: var(--accent);
    text-decoration: none;
}

.message-bubble a:hover { text-decoration: underline; }

.message-bubble table {
    width: 100%;
    border-collapse: collapse;
    margin: 8px 0;
    font-size: 13px;
}

.message-bubble th, .message-bubble td {
    text-align: left;
    padding: 6px 10px;
    border: 1px solid var(--border);
}

.message-bubble th {
    background: var(--bg-elevated);
    font-weight: 600;
    color: var(--text-secondary);
}

/* ─── Thinking State ──────────────────────────────────────────────────────── */
.thinking-avatar {
    background: var(--bg-elevated);
    border-color: var(--border);
    color: var(--text-muted);
}

.thinking-bubble {
    color: var(--text-secondary);
    font-style: italic;
    display: flex;
    align-items: center;
    gap: 10px;
}

.dot-pulse {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--accent);
    animation: dotPulse 1.4s infinite ease-in-out;
}

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

/* ─── Input Area ──────────────────────────────────────────────────────────── */
.input-area {
    padding: 12px 0 16px;
    flex-shrink: 0;
    border-top: 1px solid var(--border);
}

.error-banner {
    background: var(--error-bg);
    color: var(--error-text);
    border: 1px solid #6a2020;
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    margin-bottom: 10px;
    font-size: 13px;
    display: flex;
    align-items: flex-start;
    gap: 8px;
}

.error-dismiss {
    background: none;
    border: none;
    color: var(--error-text);
    cursor: pointer;
    margin-left: auto;
    flex-shrink: 0;
    font-size: 14px;
    line-height: 1;
}

.input-row {
    display: flex;
    gap: 8px;
    align-items: flex-end;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px;
    transition: border-color 0.15s;
}

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

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

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

.send-btn {
    background: var(--accent);
    border: none;
    border-radius: var(--radius-sm);
    color: white;
    padding: 8px 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.15s;
    flex-shrink: 0;
    min-width: 40px;
    min-height: 38px;
}

.send-btn:hover:not(:disabled) { opacity: 0.85; }

.send-btn:disabled {
    background: var(--bg-elevated);
    color: var(--text-muted);
    cursor: not-allowed;
}

.input-hint {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 6px;
    text-align: center;
}

/* ─── Spinners ────────────────────────────────────────────────────────────── */
.spinner {
    width: 28px;
    height: 28px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.spinner-sm {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* ─── Loading Screen ──────────────────────────────────────────────────────── */
.loading-screen {
    height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    color: var(--text-secondary);
}

/* ─── Auth Message ────────────────────────────────────────────────────────── */
.auth-message {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
    color: var(--text-secondary);
}

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

/* ─── Sidebar User Avatar ─────────────────────────────────────────────────── */
.sidebar-user-row {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;   /* allow inner text to truncate */
}

.sidebar-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    flex-shrink: 0;
    overflow: hidden;
    background: var(--accent-dim);
    border: 1px solid var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
}

.sidebar-avatar-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.sidebar-avatar-initials {
    font-size: 10px;
    font-weight: 700;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.02em;
    line-height: 1;
}

/* ─── Freddy Chat Avatar ──────────────────────────────────────────────────── */
/* The .avatar-assistant circle (32×32, border-radius 50%) is already defined.  */
/* This rule makes the Freddy image fill it cleanly.                            */
.freddy-avatar-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
    display: block;
}
