/* ==========================================
   WriteMindly — Styles
   ========================================== */

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

:root {
    --primary: #6366f1;
    --primary-light: #818cf8;
    --primary-dark: #4f46e5;
    --primary-glow: rgba(99, 102, 241, 0.15);
    --gradient: linear-gradient(135deg, #6366f1, #8b5cf6);
    --user-gradient: linear-gradient(135deg, #6366f1, #4f46e5);
    --bg: #f8f9fb;
    --surface: #ffffff;
    --text: #1a1a2e;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --border: #e2e8f0;
    --border-light: #f1f5f9;
    --code-bg: #0f172a;
    --code-header: #1e293b;
    --success: #10b981;
    --warning: #f59e0b;
    --error: #ef4444;
    --info: #3b82f6;
    --radius: 16px;
    --radius-sm: 10px;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 20px rgba(0,0,0,0.08);
    --shadow-lg: 0 8px 40px rgba(0,0,0,0.12);
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
    height: 100vh;
    display: flex;
    flex-direction: column;
    -webkit-font-smoothing: antialiased;
}

/* ── Chat Container ── */
.chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem 1rem 160px;
    scroll-behavior: smooth;
}

.chat-container::-webkit-scrollbar { width: 5px; }
.chat-container::-webkit-scrollbar-track { background: transparent; }
.chat-container::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 10px; }

/* ── Empty State ── */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: 2rem;
    text-align: center;
}
.empty-state.hidden { display: none; }

.logo-icon {
    width: 72px;
    height: 72px;
    background: var(--gradient);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    color: white;
    font-weight: 700;
    margin-bottom: 1.5rem;
    box-shadow: 0 8px 32px var(--primary-glow);
    animation: logoPulse 3s ease-in-out infinite;
}
@keyframes logoPulse {
    0%, 100% { box-shadow: 0 8px 32px var(--primary-glow); transform: scale(1); }
    50% { box-shadow: 0 12px 48px rgba(99,102,241,0.3); transform: scale(1.03); }
}

.empty-title { font-size: 1.75rem; font-weight: 700; color: var(--text); margin-bottom: 0.5rem; }
.empty-subtitle { font-size: 1rem; color: var(--text-secondary); max-width: 420px; line-height: 1.6; }

.suggestions {
    display: flex; flex-wrap: wrap; gap: 0.75rem;
    justify-content: center; margin-top: 2rem; max-width: 750px;
}
.suggestion-chip {
    padding: 0.8rem 1.2rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    font-size: 0.8rem;
    color: var(--text);
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: var(--shadow-sm);
}
.suggestion-chip:hover {
    border-color: var(--primary);
    color: var(--primary);
    transform: translateY(-2px);
    box-shadow: 0 4px 16px var(--primary-glow);
}

/* ── Messages ── */
.messages-wrapper {
    display: none;
    max-width: 820px;
    margin: 0 auto;
    width: 100%;
}
.messages-wrapper.active {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

/* ── Message Row ── */
.msg-row {
    animation: msgIn 0.35s ease-out;
    padding: 0.25rem 0;
}
@keyframes msgIn {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

.msg-group {
    display: flex;
    align-items: flex-start;
    gap: 0.875rem;
}

.msg-row.user .msg-group {
    flex-direction: row-reverse;
}

/* ── Avatar ── */
.msg-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 0.8rem;
    font-weight: 700;
    margin-top: 0.25rem;
}
.msg-avatar.user {
    background: var(--user-gradient);
    color: white;
}
.msg-avatar.assistant {
    background: var(--gradient);
    color: white;
}

/* ── Message Body ── */
.msg-body {
    flex: 1;
    min-width: 0;
    max-width: fit-content;
    /* max-width: 85%; */
}

.msg-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 0.35rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.msg-row.user .msg-label { justify-content: flex-end; }
.msg-time { font-weight: 400; color: var(--text-muted); font-size: 0.72rem; }

/* ── Bubble ── */
.msg-bubble {
    padding: 1rem 1.25rem;
    font-size: 0.938rem;
    line-height: 1.75;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.msg-row.user .msg-bubble {
    background: var(--user-gradient);
    color: white;
    border-radius: 18px 18px 4px 18px;
    box-shadow: 0 2px 12px rgba(99,102,241,0.2);
}
.msg-row.user .msg-bubble strong { color: #fff; }
.msg-row.user .msg-bubble em { color: rgba(255,255,255,0.9); }

.msg-row.assistant .msg-bubble {
    background: var(--surface);
    color: var(--text);
    border-radius: 18px 18px 18px 4px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}

/* ── Error / Stopped ── */
.msg-error {
    padding: 0.75rem 1rem;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: var(--radius-sm);
    color: var(--error);
    font-size: 0.9rem;
}
.msg-stopped { color: var(--text-muted); }

/* ============================================
   RICH MARKDOWN INSIDE .msg-bubble
   ============================================ */

/* ── Headings ── */
.msg-bubble h1,
.msg-bubble h2,
.msg-bubble h3,
.msg-bubble h4 {
    font-weight: 700;
    line-height: 1.35;
    margin: 1.25rem 0 0.5rem;
    letter-spacing: -0.01em;
}
.msg-bubble h1:first-child,
.msg-bubble h2:first-child,
.msg-bubble h3:first-child,
.msg-bubble h4:first-child {
    margin-top: 0;
}

.msg-bubble h1 {
    font-size: 1.35rem;
    color: var(--text);
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--border-light);
}
.msg-bubble h2 {
    font-size: 1.2rem;
    color: var(--primary-dark);
    display: flex;
    align-items: center;
    gap: 0.4rem;
}
.msg-bubble h3 {
    font-size: 1.05rem;
    color: var(--text-secondary);
}
.msg-bubble h4 {
    font-size: 0.95rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

/* ── Paragraphs ── */
.msg-bubble p {
    margin-bottom: 0.65rem;
}
.msg-bubble p:last-child { margin-bottom: 0; }

/* ── Bold / Italic ── */
.msg-bubble strong {
    font-weight: 650;
    color: var(--text);
}
.msg-bubble em {
    font-style: italic;
    color: #475569;
}

/* ── Highlight ── */
.msg-bubble mark {
    background: linear-gradient(120deg, #fef3c7 0%, #fde68a 100%);
    color: #92400e;
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
    font-weight: 500;
}

/* ── Blockquotes (Callout Card) ── */
.msg-bubble blockquote {
    /* margin: 1rem 0; */
    /* padding: 1rem 1.25rem; */
    /* background: linear-gradient(135deg, #f0f4ff 0%, #e8ecff 100%); */
    /* border-left: 4px solid var(--primary); */
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    color: #312e81;
    position: relative;
    font-size: 0.938rem;
}
.msg-bubble blockquote::before {
    content: '"';
    position: absolute;
    top: -0.15rem;
    left: 0.65rem;
    font-size: 2.5rem;
    color: var(--primary-light);
    opacity: 0.3;
    font-family: Georgia, serif;
    line-height: 1;
}
.msg-bubble blockquote p { margin-bottom: 0.5rem; }
.msg-bubble blockquote p:last-child { margin-bottom: 0; }
.msg-bubble blockquote h1,
.msg-bubble blockquote h2,
.msg-bubble blockquote h3 {
    color: var(--primary-dark);
}
.msg-bubble blockquote strong { color: #312e81; }
.msg-bubble blockquote em { color: #4338ca; }

/* ── Unordered Lists ── */
.msg-bubble ul {
    margin: 0.75rem 0;
    padding: 0;
    list-style: none;
}
.msg-bubble ul li {
    position: relative;
    padding-left: 1.6rem;
    margin-bottom: 0.45rem;
    line-height: 1.65;
}
.msg-bubble ul li::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0.55rem;
    width: 7px;
    height: 7px;
    background: var(--gradient);
    border-radius: 50%;
    box-shadow: 0 0 0 3px var(--primary-glow);
}

/* ── Ordered Lists ── */
.msg-bubble ol {
    margin: 0.75rem 0;
    padding: 0;
    list-style: none;
    counter-reset: ol-counter;
}
.msg-bubble ol li {
    position: relative;
    padding-left: 2.25rem;
    margin-bottom: 0.5rem;
    line-height: 1.65;
    counter-increment: ol-counter;
}
.msg-bubble ol li::before {
    content: counter(ol-counter);
    position: absolute;
    left: 0;
    top: 0.05rem;
    width: 1.5rem;
    height: 1.5rem;
    background: var(--gradient);
    color: white;
    font-size: 0.72rem;
    font-weight: 700;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 6px var(--primary-glow);
}

/* ── Inline Code ── */
.msg-bubble .inline-code,
.msg-bubble code:not(pre code) {
    background: #f1f5f9;
    color: #be185d;
    padding: 0.15rem 0.45rem;
    border-radius: 5px;
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 0.84em;
    font-weight: 500;
    border: 1px solid #e2e8f0;
}

/* ── Code Blocks ── */
.code-block-wrapper {
    margin: 1rem 0;
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: var(--code-bg);
    box-shadow: var(--shadow-md);
    border: 1px solid #1e293b;
}
.code-block-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.6rem 1rem;
    background: var(--code-header);
    border-bottom: 1px solid #334155;
}
.code-language {
    font-size: 0.75rem;
    color: #94a3b8;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.copy-btn {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.3rem 0.65rem;
    background: transparent;
    border: 1px solid #334155;
    border-radius: 6px;
    color: #94a3b8;
    font-size: 0.72rem;
    cursor: pointer;
    transition: all 0.15s;
    font-family: inherit;
}
.copy-btn:hover { background: #334155; color: #e2e8f0; }
.copy-btn.copied { background: var(--success); border-color: var(--success); color: white; }

.code-block-body {
    padding: 1rem;
    overflow-x: auto;
}
.code-block-body pre {
    margin: 0;
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 0.84rem;
    line-height: 1.65;
    color: #e2e8f0;
}
.code-block-body code { font-family: inherit; }

.syn-kw { color: #c084fc; }
.syn-str { color: #86efac; }
.syn-num { color: #fdba74; }
.syn-cmt { color: #64748b; font-style: italic; }

/* ── Horizontal Rule ── */
.msg-bubble hr {
    margin: 1.25rem 0;
    border: none;
    height: 1px;
    background: linear-gradient(90deg, transparent 0%, var(--border) 20%, var(--border) 80%, transparent 100%);
}

/* ── Links ── */
.msg-bubble a {
    color: var(--primary);
    text-decoration: none;
    border-bottom: 1px dashed var(--primary-light);
    transition: all 0.15s;
    font-weight: 500;
}
.msg-bubble a:hover {
    color: var(--primary-dark);
    border-bottom-style: solid;
}

/* ── Images ── */
.msg-bubble img {
    max-width: 100%;
    border-radius: var(--radius-sm);
    margin: 0.5rem 0;
    box-shadow: var(--shadow-sm);
}

/* ── Tables ── */
.table-wrapper { margin: 1rem 0; overflow-x: auto; border-radius: var(--radius-sm); }
.msg-bubble table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}
.msg-bubble th {
    background: var(--border-light);
    font-weight: 600;
    text-align: left;
    padding: 0.65rem 0.85rem;
    border-bottom: 2px solid var(--border);
}
.msg-bubble td {
    padding: 0.6rem 0.85rem;
    border-bottom: 1px solid var(--border-light);
}
.msg-bubble tr:last-child td { border-bottom: none; }
.msg-bubble tr:hover td { background: #f8fafc; }

/* ── Streaming Cursor ── */
.cursor {
    display: inline-block;
    width: 3px;
    height: 1.1em;
    background: var(--gradient);
    margin-left: 2px;
    border-radius: 2px;
    vertical-align: text-bottom;
    animation: cursorBlink 0.75s step-end infinite;
}
@keyframes cursorBlink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

/* ── Message Actions ── */
.msg-actions {
    display: flex;
    gap: 0.4rem;
    margin-top: 0.5rem;
    opacity: 0;
    transition: opacity 0.2s;
}
.msg-row:hover .msg-actions { opacity: 1; }

.act-btn {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.3rem 0.65rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-muted);
    font-size: 0.72rem;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.15s;
}
.act-btn:hover {
    background: var(--surface);
    color: var(--text);
    border-color: var(--primary-light);
}
.act-btn.copied {
    background: #ecfdf5;
    border-color: var(--success);
    color: var(--success);
}

/* ── Input Area ── */
.input-area {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(to top, var(--bg) 80%, transparent);
    padding: 1rem 1.5rem 1.25rem;
    z-index: 50;
}
.input-wrapper {
    max-width: 820px;
    margin: 0 auto;
}
.input-box {
    display: flex;
    align-items: flex-end;
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: 24px;
    padding: 0.5rem 0.5rem 0.5rem 1.25rem;
    box-shadow: var(--shadow-lg);
    transition: border-color 0.2s, box-shadow 0.2s;
}
.input-box:focus-within {
    border-color: var(--primary-light);
    box-shadow: 0 4px 32px var(--primary-glow), var(--shadow-lg);
}
.input-box textarea {
    flex: 1;
    border: none;
    outline: none;
    resize: none;
    font-family: inherit;
    font-size: 0.95rem;
    line-height: 1.5;
    color: var(--text);
    background: transparent;
    max-height: 150px;
    padding: 0.5rem 0;
}
.input-box textarea::placeholder { color: var(--text-muted); }

.send-button {
    width: 42px; height: 42px;
    border: none;
    background: var(--gradient);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s, box-shadow 0.15s;
    margin-left: 0.5rem;
    flex-shrink: 0;
}
.send-button:hover { transform: scale(1.06); box-shadow: 0 4px 16px var(--primary-glow); }
.send-button:active { transform: scale(0.94); }
.send-button:disabled { background: var(--border); cursor: not-allowed; box-shadow: none; }
.send-button:disabled:hover { transform: none; }
.send-button svg { width: 18px; height: 18px; color: white; margin-left: 1px; }
.send-button:disabled svg { color: var(--text-muted); }

.stop-button {
    width: 42px; height: 42px;
    border: none;
    background: linear-gradient(135deg, #ef4444, #dc2626);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s;
    margin-left: 0.5rem;
    flex-shrink: 0;
}
.stop-button:hover { transform: scale(1.06); box-shadow: 0 4px 16px rgba(239,68,68,0.3); }
.stop-button svg { width: 16px; height: 16px; color: white; }

.hidden { display: none !important; }

.footer-text {
    text-align: center;
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-top: 0.65rem;
    letter-spacing: 0.02em;
}

/* ── New Chat Button ── */
.new-chat-btn {
    position: fixed;
    top: 1rem;
    right: 1rem;
    padding: 0.55rem 1.15rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.84rem;
    font-family: inherit;
    color: var(--text);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: all 0.2s;
    box-shadow: var(--shadow-sm);
    z-index: 100;
}
.new-chat-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
    transform: translateY(-1px);
    box-shadow: 0 4px 16px var(--primary-glow);
}

/* ── Responsive ── */
@media (max-width: 768px) {
    .chat-container { padding: 1rem 0.75rem 140px; }
    .msg-body { max-width: 92%; }
    .input-area { padding: 0.75rem 0.85rem 1rem; }
    .empty-title { font-size: 1.4rem; }
    .suggestions { flex-direction: column; padding: 0 0.5rem; }
    .msg-avatar { width: 30px; height: 30px; }
    .msg-group { gap: 0.65rem; }
    .msg-bubble { padding: 0.85rem 1rem; font-size: 0.9rem; }
    .code-block-header { flex-wrap: wrap; gap: 0.5rem; }
}

@media (max-width: 480px) {
    .logo-icon { width: 56px; height: 56px; font-size: 1.5rem; }
    .empty-title { font-size: 1.2rem; }
    .empty-subtitle { font-size: 0.88rem; }
    .suggestion-chip { font-size: 0.84rem; padding: 0.7rem 1rem; }
}

.msg-row .user .msg-bubble{
    text-align-last: end;
}

.bot-avatar {
    /* width: 38px;
    height: 38px; */
    border-radius: 50%;
    /* padding: 2px;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1); */
}

.bot-avatar img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: contain;
    background: #fff;
}