/* ============================================ */
/* SIMONA — main.css v7                        */
/* Upgraded: modern, refined, production-ready */
/* ============================================ */

/* ============================================ */
/* DESIGN TOKENS                               */
/* ============================================ */
:root {
    --red:        #C00000;
    --red-bright: #e63030;
    --red-hover:  #b01c1c;
    --red-glow:   rgba(230, 48, 48, 0.18);
    --red-tint:   rgba(192, 0, 0, 0.07);

    --bg:         #f7f7fa;
    --surface:    #ffffff;
    --border:     #e8e8ed;
    --border-mid: #d8d8e0;

    --text-primary:   #111114;
    --text-secondary: #555566;
    --text-muted:     #8a8a9a;
    --text-faint:     #b0b0bf;

    --sidebar-bg:  #111114;
    --sidebar-border: rgba(255,255,255,0.05);

    --radius-sm:  8px;
    --radius-md:  12px;
    --radius-lg:  18px;
    --radius-xl:  24px;

    --shadow-sm:  0 1px 4px rgba(0,0,0,0.06);
    --shadow-md:  0 4px 16px rgba(0,0,0,0.08), 0 1px 4px rgba(0,0,0,0.04);
    --shadow-lg:  0 8px 32px rgba(0,0,0,0.12), 0 2px 8px rgba(0,0,0,0.06);

    --ease-spring: cubic-bezier(0.34, 1.3, 0.64, 1);
    --ease-out:    cubic-bezier(0.4, 0, 0.2, 1);
}

/* ============================================ */
/* BASE                                        */
/* ============================================ */
*, *::before, *::after { box-sizing: border-box; }

body {
    font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ============================================ */
/* SIDEBAR                                     */
/* ============================================ */
.sidebar {
    transition: transform 0.25s var(--ease-out);
    will-change: transform;
    border-right: 1px solid var(--sidebar-border);
}
.sidebar.collapsed { transform: translateX(-272px); }
#main-content { transition: margin-left 0.25s var(--ease-out); }
#main-content.expanded { margin-left: 0 !important; }

.sidebar-resizer {
    position: absolute;
    right: 0; top: 0; bottom: 0;
    width: 4px;
    background: transparent;
    cursor: col-resize;
    z-index: 50;
    transition: background 0.2s;
}
.sidebar-resizer:hover { background: rgba(230, 48, 48, 0.4); }

/* ============================================ */
/* SCROLLBARS                                  */
/* ============================================ */
.conversation-list::-webkit-scrollbar,
#conversation-list::-webkit-scrollbar { width: 3px; }
.conversation-list::-webkit-scrollbar-track,
#conversation-list::-webkit-scrollbar-track { background: transparent; }
.conversation-list::-webkit-scrollbar-thumb,
#conversation-list::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.1);
    border-radius: 9999px;
}
.conversation-list::-webkit-scrollbar-thumb:hover,
#conversation-list::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.22); }

.messages-container::-webkit-scrollbar { width: 4px; }
.messages-container::-webkit-scrollbar-track { background: transparent; }
.messages-container::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 9999px;
}
.messages-container::-webkit-scrollbar-thumb:hover { background: var(--border-mid); }

/* ============================================ */
/* MODAL                                       */
/* ============================================ */
.modal-overlay.show { display: flex !important; }

/* ============================================ */
/* SCROLL BUTTON                               */
/* ============================================ */
.scroll-bottom.visible { opacity: 1 !important; pointer-events: all !important; }

/* ============================================ */
/* CONVERSATION LIST                           */
/* ============================================ */
.conversation-item {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 8px 10px;
    margin: 1px 0;
    border-radius: 7px;
    font-size: 13px;
    color: rgba(255,255,255,0.7);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.conversation-item:hover { background: rgba(255,255,255,0.07); color: rgba(255,255,255,0.92); }
.conversation-item.active {
    background: rgba(192,0,0,0.14);
    color: #fff;
    font-weight: 500;
}
.conversation-item .conv-title {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: inherit;
}
.conversation-item .conv-menu-btn {
    background: transparent;
    border: none;
    padding: 3px 5px;
    border-radius: 4px;
    cursor: pointer;
    color: rgba(255,255,255,0.35);
    display: none;
    transition: all 0.15s;
    flex-shrink: 0;
}
.conversation-item:hover .conv-menu-btn { display: block; }
.conversation-item .conv-menu-btn:hover {
    background: rgba(255,255,255,0.1);
    color: rgba(255,255,255,0.85);
}
.conversation-item::before {
    content: '';
    position: absolute;
    left: 0; top: 22%; bottom: 22%;
    width: 2.5px;
    background: transparent;
    border-radius: 9999px;
    transition: background 0.15s;
}
.conversation-item.active::before { background: var(--red-bright); }

.conversation-group-title {
    padding: 10px 10px 5px;
    font-size: 10px;
    font-weight: 700;
    color: rgba(255,255,255,0.28);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

/* ============================================ */
/* SKELETON LOADING                            */
/* ============================================ */
.skeleton-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    margin: 3px 0;
    border-radius: 6px;
}
.skeleton-line {
    background: linear-gradient(
        90deg,
        rgba(255,255,255,0.05) 25%,
        rgba(255,255,255,0.1) 50%,
        rgba(255,255,255,0.05) 75%
    );
    background-size: 200% 100%;
    animation: shimmer 1.6s infinite;
    border-radius: 4px;
    height: 11px;
}
@keyframes shimmer {
    0%   { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ============================================ */
/* WELCOME SCREEN                              */
/* ============================================ */
.welcome-screen {
    animation: fadeUp 0.5s var(--ease-out) both;
}
@keyframes fadeUp {
    from { opacity: 0; transform: translateY(20px); }
    to   { opacity: 1; transform: translateY(0); }
}
.welcome-card {
    transition: border-color 0.15s, transform 0.15s, box-shadow 0.15s;
}

/* ============================================ */
/* CHAT LAYOUT                                 */
/* ============================================ */
#chat-messages {
    display: flex;
    flex-direction: column;
    gap: 0;
    padding: 20px 0 40px;
}

/* ── message-wrapper: padding-bottom buat ruang action bar ── */
.message-wrapper {
    display: flex;
    width: 100%;
    align-items: flex-start;
    gap: 8px;
    padding: 4px 0 32px;
    position: relative;
}
.message-wrapper.user      { flex-direction: row-reverse; }
.message-wrapper.assistant { flex-direction: row; }

/* ── Timestamp: inline di dalam bubble ─────────────────────── */
.msg-timestamp {
    display: block;
    font-size: 10px;
    color: var(--text-faint);
    margin-top: 4px;
    opacity: 0;
    transition: opacity 0.2s ease;
    pointer-events: none;
    letter-spacing: 0.01em;
}
.message-wrapper.user      .msg-timestamp { text-align: right; }
.message-wrapper.assistant .msg-timestamp { text-align: left; }
.message-wrapper:hover .msg-timestamp { opacity: 1; }

/* ── User bubble ─────────────────────────────────────────────── */
.message-user {
    background: #ececf1;
    color: var(--text-primary);
    border-radius: 18px 18px 4px 18px;
    padding: 10px 16px 8px;
    max-width: 72%;
    font-size: 14px;
    line-height: 1.6;
    word-wrap: break-word;
    overflow-wrap: break-word;
    animation: msgSlideRight 0.22s var(--ease-spring);
    box-shadow: var(--shadow-sm);
}

/* ── Assistant bubble ───────────────────────────────────────── */
.message-assistant {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 4px 18px 18px 18px;
    padding: 18px 22px 14px;
    max-width: min(92%, 820px);
    box-shadow: var(--shadow-sm);
    word-wrap: break-word;
    overflow-wrap: break-word;
    line-height: 1.75;
    color: var(--text-primary);
    font-size: 14.5px;
    animation: msgSlideLeft 0.22s var(--ease-spring);
    min-height: 1.5rem;
    overflow: hidden;
    transition: box-shadow 0.2s;
}
.message-assistant:hover {
    box-shadow: 0 2px 10px rgba(0,0,0,0.07);
}

.message-wrapper.assistant:has(pre) .message-assistant {
    max-width: 100%;
    width: 100%;
    padding: 18px 0 14px;
}
.message-wrapper.assistant:has(pre) .message-assistant > *:not(pre) {
    padding-left: 22px;
    padding-right: 22px;
}

@keyframes msgSlideRight {
    from { transform: translateX(12px) scale(0.97); opacity: 0; }
    to   { transform: translateX(0) scale(1); opacity: 1; }
}
@keyframes msgSlideLeft {
    from { transform: translateX(-12px) scale(0.97); opacity: 0; }
    to   { transform: translateX(0) scale(1); opacity: 1; }
}

/* ============================================ */
/* MESSAGE ACTION BAR (Copy + Edit)            */
/* ============================================ */

/* Action bar sits inside wrapper padding — no gap to cross */
.msg-actions {
    position: absolute;
    bottom: 6px;
    display: flex;
    align-items: center;
    gap: 3px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.18s ease 0.06s;
    z-index: 10;
}
.message-wrapper.user      .msg-actions { right: 0; }
.message-wrapper.assistant .msg-actions { left: 0; }
.message-wrapper:hover .msg-actions {
    opacity: 1;
    pointer-events: auto;
    transition: opacity 0.14s ease 0s;
}

.msg-action-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    height: 26px;
    padding: 0 10px;
    border-radius: 7px;
    border: 1px solid rgba(0,0,0,0.09);
    cursor: pointer;
    font-size: 11.5px;
    font-weight: 500;
    font-family: inherit;
    background: rgba(255,255,255,0.95);
    color: #555;
    box-shadow: 0 1px 5px rgba(0,0,0,0.1);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    transition: background 0.12s, color 0.12s, transform 0.1s, box-shadow 0.12s;
    white-space: nowrap;
    line-height: 1;
}
.msg-action-btn:hover {
    background: #fff;
    color: #111;
    box-shadow: 0 2px 10px rgba(0,0,0,0.13);
    transform: translateY(-1px);
}
.msg-action-btn:active { transform: translateY(0); box-shadow: 0 1px 4px rgba(0,0,0,0.1); }
.msg-action-btn svg { flex-shrink: 0; }
.msg-action-btn.copied { color: #16a34a; border-color: rgba(22,163,74,0.22); background: #f0fdf4; }

/* ============================================ */
/* EDIT OVERLAY                                */
/* ============================================ */

/* Full-width, at messageDiv level — not trapped in bubble */
.msg-edit-overlay {
    width: 100%;
    max-width: 700px;
    margin-top: 6px;
    background: var(--surface);
    border: 1.5px solid var(--border-mid);
    border-radius: 14px;
    box-shadow: var(--shadow-md);
    overflow: hidden;
    animation: edit-slide-in 0.2s var(--ease-spring) forwards;
}
.msg-edit-overlay:focus-within {
    border-color: var(--red-bright);
    box-shadow: 0 0 0 3px var(--red-glow), var(--shadow-md);
    transition: border-color 0.15s, box-shadow 0.15s;
}

@keyframes edit-slide-in {
    from { opacity: 0; transform: translateY(-6px) scale(0.98); }
    to   { opacity: 1; transform: translateY(0)   scale(1);    }
}

.msg-edit-area {
    width: 100%;
    min-height: 88px;
    max-height: 300px;
    border: none;
    outline: none;
    padding: 14px 16px 10px;
    font-size: 14px;
    font-family: inherit;
    color: var(--text-primary);
    background: transparent;
    resize: none;
    line-height: 1.65;
    box-sizing: border-box;
    display: block;
    box-shadow: none;
}

.msg-edit-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 7px 12px 9px;
    border-top: 1px solid var(--border);
    background: #fafafa;
    gap: 8px;
}

.msg-edit-hint {
    display: flex;
    flex-direction: column;
    gap: 2px;
    font-size: 11px;
    color: #aaa;
    flex-shrink: 1;
    min-width: 0;
}
.msg-edit-hint span:first-child {
    color: #888;
    font-size: 11px;
}
.msg-edit-hint-keys {
    color: #bbb;
    font-size: 10.5px;
    letter-spacing: 0.01em;
}

.msg-edit-btns {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}
.msg-edit-cancel {
    height: 30px;
    padding: 0 14px;
    border-radius: 8px;
    border: 1px solid var(--border-mid);
    background: var(--surface);
    color: var(--text-secondary);
    font-size: 12.5px;
    font-family: inherit;
    cursor: pointer;
    font-weight: 500;
    transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.msg-edit-cancel:hover {
    background: #f5f5f7;
    color: var(--text-primary);
    border-color: var(--border-mid);
}
.msg-edit-send {
    height: 30px;
    padding: 0 16px;
    border-radius: 8px;
    border: none;
    background: var(--red-bright);
    color: #fff;
    font-size: 12.5px;
    font-family: inherit;
    cursor: pointer;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    box-shadow: 0 1px 6px rgba(230,48,48,0.28);
    transition: background 0.12s, box-shadow 0.12s, transform 0.1s;
}
.msg-edit-send:hover {
    background: var(--red-hover);
    box-shadow: 0 3px 12px rgba(230,48,48,0.35);
}
.msg-edit-send:active { transform: scale(0.97); }

/* ============================================ */
/* STREAMING CURSOR                            */
/* ============================================ */
.message-assistant.streaming::after {
    content: '▋';
    display: inline-block;
    color: var(--red-bright);
    animation: blink-cursor 0.75s step-end infinite;
    margin-left: 2px;
    font-size: 0.88em;
    vertical-align: baseline;
    line-height: 1;
}
@keyframes blink-cursor {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0; }
}

/* ---- Typing dots ---- */
.typing-indicator {
    display: inline-flex;
    gap: 5px;
    padding: 6px 0;
    align-items: center;
}
.typing-indicator span {
    width: 7px; height: 7px;
    background: var(--text-muted);
    border-radius: 9999px;
    animation: bounce 1.3s infinite ease-in-out both;
}
.typing-indicator span:nth-child(1) { animation-delay: -0.32s; }
.typing-indicator span:nth-child(2) { animation-delay: -0.16s; }
@keyframes bounce {
    0%, 80%, 100% { transform: scale(0); opacity: 0.3; }
    40%           { transform: scale(1); opacity: 1; }
}

/* ============================================ */
/* CHAT IMAGES                                 */
/* ============================================ */
.chat-image {
    max-width: 100%;
    max-height: 320px;
    border-radius: 12px;
    margin: 8px 0 0;
    cursor: pointer;
    display: block;
    transition: transform 0.18s ease, box-shadow 0.18s ease;
}
.chat-image:hover { transform: scale(1.015); box-shadow: var(--shadow-lg); }

.chat-image-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 6px;
    margin: 8px 0 0;
    max-width: 400px;
}
.chat-image-thumb {
    width: 100%;
    aspect-ratio: 1/1;
    object-fit: cover;
    border-radius: 10px;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    display: block;
}
.chat-image-thumb:hover { transform: scale(1.04); box-shadow: var(--shadow-md); }

.chat-image-placeholder {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: #f5f5f7;
    border: 1px dashed var(--border-mid);
    border-radius: 8px;
    padding: 8px 14px;
    margin: 8px 0 0;
    color: var(--text-muted);
    font-size: 12px;
}
#image-modal-img { transition: opacity 0.2s ease; }

/* ============================================ */
/* IMAGE PREVIEW                               */
/* ============================================ */
.image-preview-container {
    animation: slideUp 0.2s var(--ease-spring);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 10px 12px;
    box-shadow: var(--shadow-sm);
}
@keyframes slideUp {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}
.img-preview-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}
.image-preview-title {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    display: flex;
    align-items: center;
    gap: 6px;
}
.img-count-badge {
    background: var(--red-bright);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    padding: 1px 6px;
    border-radius: 9999px;
    letter-spacing: 0.02em;
}
.image-preview-remove {
    background: transparent;
    border: none;
    padding: 4px;
    border-radius: 6px;
    cursor: pointer;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
}
.image-preview-remove:hover { background: #fff0f0; color: var(--red-bright); }

.img-preview-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.img-preview-item { position: relative; width: 72px; flex-shrink: 0; }
.img-preview-item img {
    width: 72px; height: 72px;
    object-fit: cover;
    border-radius: 9px;
    border: 1.5px solid var(--border);
    cursor: pointer;
    display: block;
    transition: transform 0.15s ease;
}
.img-preview-item img:hover { transform: scale(1.04); }
.img-preview-remove-single {
    position: absolute;
    top: -5px; right: -5px;
    width: 18px; height: 18px;
    background: #1c1c1e;
    border: 1.5px solid #fff;
    border-radius: 9999px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    transition: all 0.15s;
    padding: 0;
}
.img-preview-remove-single:hover { background: var(--red-bright); transform: scale(1.1); }
.img-preview-name {
    display: block;
    font-size: 10px;
    color: var(--text-muted);
    text-align: center;
    margin-top: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 72px;
}

/* ============================================ */
/* IMAGE MODAL                                 */
/* ============================================ */
.image-modal-content {
    animation: zoomIn 0.22s var(--ease-spring);
}
@keyframes zoomIn {
    from { opacity: 0; transform: scale(0.88); }
    to   { opacity: 1; transform: scale(1); }
}

/* ============================================ */
/* FILE BADGE                                  */
/* ============================================ */
.file-badge {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 5px 10px 5px 7px;
    border-radius: 9px;
    font-size: 12.5px;
    font-weight: 500;
    background: linear-gradient(135deg, #1c1c20 0%, #26262e 100%);
    color: rgba(255,255,255,0.88);
    border: 1px solid rgba(255,255,255,0.08);
    box-shadow: 0 1px 4px rgba(0,0,0,0.18), inset 0 1px 0 rgba(255,255,255,0.04);
    margin-right: 6px;
    margin-bottom: 6px;
    transition: box-shadow 0.15s ease, border-color 0.15s ease;
    max-width: 260px;
}
.file-badge:hover {
    border-color: rgba(255,255,255,0.14);
    box-shadow: 0 2px 8px rgba(0,0,0,0.22), inset 0 1px 0 rgba(255,255,255,0.06);
}

/* ============================================ */
/* CODE COPY BUTTON (in markdown blocks)       */
/* ============================================ */
.copy-code-btn {
    position: absolute;
    top: 6px; right: 12px;
    background: transparent;
    border: 1px solid transparent;
    color: rgba(255,255,255,0.5);
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 11.5px;
    cursor: pointer;
    transition: all 0.18s ease;
    opacity: 0;
    font-family: system-ui, -apple-system, sans-serif;
    z-index: 10;
}
.message-assistant pre:hover .copy-code-btn { opacity: 1; }
.copy-code-btn:hover {
    background: rgba(255,255,255,0.12);
    color: #fff;
    border-color: rgba(255,255,255,0.18);
}

/* ============================================ */
/* DROPDOWN / CONTEXT MENU                     */
/* ============================================ */
.dropdown-menu { display: none; }
.dropdown-menu.show { display: block; }
.context-menu { display: none; }

/* ============================================ */
/* TOAST NOTIFICATION                          */
/* ============================================ */
#toast-container {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 99999;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    pointer-events: none;
}
.toast {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #18181b;
    color: #fff;
    padding: 10px 18px;
    border-radius: var(--radius-md);
    font-size: 13.5px;
    font-weight: 500;
    box-shadow: 0 8px 32px rgba(0,0,0,0.22), 0 2px 8px rgba(0,0,0,0.12);
    border: 1px solid rgba(255,255,255,0.08);
    animation: toast-in 0.3s var(--ease-spring) forwards;
    pointer-events: auto;
    white-space: nowrap;
    max-width: 360px;
}
.toast.toast-out { animation: toast-out 0.25s ease forwards; }
.toast.toast-success { border-left: 3px solid #22c55e; }
.toast.toast-error   { border-left: 3px solid var(--red-bright); }
.toast.toast-info    { border-left: 3px solid #3b82f6; }
@keyframes toast-in {
    from { opacity: 0; transform: translateY(12px) scale(0.95); }
    to   { opacity: 1; transform: translateY(0)    scale(1);    }
}
@keyframes toast-out {
    from { opacity: 1; transform: translateY(0)   scale(1);    }
    to   { opacity: 0; transform: translateY(8px) scale(0.95); }
}

/* ============================================ */
/* MARKDOWN RENDERING                          */
/* ============================================ */
.message-assistant h1 {
    font-size: 1.18rem; font-weight: 700; color: var(--text-primary);
    letter-spacing: -0.02em; margin: 1.4rem 0 0.5rem; line-height: 1.35;
}
.message-assistant h2 {
    font-size: 1.02rem; font-weight: 650; color: var(--text-primary);
    margin: 1.2rem 0 0.45rem; padding-bottom: 0.35rem;
    border-bottom: 1.5px solid #f0f0f5; line-height: 1.35;
}
.message-assistant h3 {
    font-size: 0.93rem; font-weight: 650; color: var(--text-primary);
    margin: 1.1rem 0 0.35rem; line-height: 1.35;
}
.message-assistant h4 {
    font-size: 0.88rem; font-weight: 600; color: var(--text-secondary);
    margin: 0.9rem 0 0.3rem; line-height: 1.35;
}
.message-assistant h1:first-child,
.message-assistant h2:first-child,
.message-assistant h3:first-child,
.message-assistant h4:first-child { margin-top: 0; }

.message-assistant p { margin: 0 0 0.85rem; line-height: 1.75; color: var(--text-primary); }
.message-assistant p:last-child { margin-bottom: 0; }

/* Lists */
.message-assistant ul { margin: 0.2rem 0 0.9rem; padding-left: 0; list-style: none; }
.message-assistant ul li {
    position: relative; padding-left: 1.3rem;
    margin-bottom: 0.45rem; line-height: 1.68; color: var(--text-primary);
}
.message-assistant ul li::before {
    content: ''; position: absolute; left: 0.18rem; top: 0.62em;
    width: 5px; height: 5px;
    background: var(--red);
    border-radius: 50%;
}
.message-assistant ul ul { margin: 0.3rem 0 0.2rem; padding-left: 1rem; }
.message-assistant ul ul li::before { width: 4px; height: 4px; background: var(--text-faint); top: 0.64em; }

.message-assistant ol {
    margin: 0.2rem 0 0.9rem;
    padding-left: 0;
    counter-reset: ol-counter;
    list-style: none;
}
.message-assistant ol li {
    position: relative;
    padding-left: 2rem;
    margin-bottom: 0.45rem;
    line-height: 1.68;
    color: var(--text-primary);
    counter-increment: ol-counter;
}
.message-assistant ol li::before {
    content: counter(ol-counter) ".";
    position: absolute;
    left: 0;
    top: 0;
    width: 1.6rem;
    font-size: 0.88em;
    font-weight: 600;
    color: var(--red);
    text-align: left;
    line-height: 1.68;
}

.message-assistant strong { font-weight: 650; color: var(--text-primary); }
.message-assistant em     { font-style: italic; color: var(--text-secondary); }

/* Inline code */
.message-assistant code:not(pre code) {
    background: #f5f5f7;
    color: #c0392b;
    padding: 2px 6px;
    border-radius: 5px;
    font-family: 'DM Mono', 'Consolas', 'SF Mono', monospace;
    font-size: 0.84em;
    font-weight: 500;
    border: 1px solid #e8e8ed;
    white-space: nowrap;
}

/* Code blocks */
.message-assistant pre {
    background: #1a1a1e;
    border-radius: 12px;
    overflow: hidden;
    margin: 1.2rem 0;
    position: relative;
    border: 1px solid #2d2d32;
    box-shadow: 0 4px 18px rgba(0,0,0,0.14);
    width: 100%;
}
.message-assistant pre::before {
    content: attr(data-lang);
    display: flex; align-items: center;
    background: #25252a; color: #aaa;
    font-size: 12.5px;
    font-family: system-ui, -apple-system, sans-serif;
    padding: 7px 16px;
    border-bottom: 1px solid #2d2d32;
    text-transform: uppercase;
    font-weight: 600;
    letter-spacing: 0.04em;
    min-height: 34px; box-sizing: border-box;
}
.message-assistant pre code {
    display: block; padding: 16px;
    background: transparent; color: #e4eaf0;
    border: none;
    font-family: 'DM Mono', 'Consolas', 'Fira Code', monospace;
    font-size: 0.845rem; line-height: 1.65;
    white-space: pre; overflow-x: auto;
    tab-size: 4;
    scrollbar-width: thin;
    scrollbar-color: #3a3a3e transparent;
}
.message-assistant pre code::-webkit-scrollbar { height: 4px; }
.message-assistant pre code::-webkit-scrollbar-track { background: transparent; }
.message-assistant pre code::-webkit-scrollbar-thumb { background: #3a3a3e; border-radius: 9999px; }

/* Blockquote */
.message-assistant blockquote {
    border-left: 3px solid var(--red);
    background: #fdf8f8;
    border-radius: 0 10px 10px 0;
    padding: 10px 16px;
    margin: 0.9rem 0;
    color: var(--text-secondary);
    font-style: normal;
    font-size: 0.93em;
    line-height: 1.65;
}
.message-assistant blockquote p { margin: 0; color: var(--text-secondary); }

.message-assistant hr { border: none; border-top: 1.5px solid #f0f0f5; margin: 1.3rem 0; }

.message-assistant a {
    color: var(--red);
    text-decoration: underline;
    text-underline-offset: 2px;
    transition: opacity 0.15s;
}
.message-assistant a:hover { opacity: 0.7; }

/* Tables */
.message-assistant .table-wrapper {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 10px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    margin: 1rem 0;
}
.message-assistant table {
    width: max-content;
    min-width: 100%;
    border-collapse: collapse;
    font-size: 13.5px;
}
.message-assistant table {
    border-radius: 0;
    border: none;
    box-shadow: none;
    margin: 0;
}
.message-assistant th {
    background: #f7f7fa;
    font-weight: 650; color: var(--text-primary);
    padding: 9px 14px; text-align: left; font-size: 12.5px;
    letter-spacing: 0.01em; border-bottom: 1.5px solid var(--border-mid);
}
.message-assistant td {
    padding: 8px 14px; color: #2c2c3a;
    border-bottom: 1px solid #f0f0f5;
    vertical-align: top; line-height: 1.55;
}
.message-assistant tr:last-child td { border-bottom: none; }
.message-assistant tr:hover td { background: #fafafa; }
.message-assistant li > p { margin: 0 0 0.2rem; line-height: 1.68; }

/* ============================================ */
/* SMART LOADING CARD                          */
/* ============================================ */
.loading-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 4px 18px 18px 18px;
    padding: 14px 18px;
    min-width: 200px; max-width: 380px;
    box-shadow: var(--shadow-sm);
    animation: msgSlideLeft 0.22s var(--ease-spring);
}
.loading-card-inner { display: flex; align-items: center; gap: 12px; }
.loading-spinner-wrap { flex-shrink: 0; }
.loading-spinner {
    width: 20px; height: 20px;
    border: 2.5px solid var(--border);
    border-top-color: var(--red-bright);
    border-radius: 50%;
    animation: spin 0.72s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-card-text { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.loading-phrase {
    font-size: 13.5px; font-weight: 500; color: var(--text-primary); white-space: nowrap;
}
.loading-preview {
    font-size: 12px; color: var(--text-muted);
    overflow: hidden; text-overflow: ellipsis;
    white-space: nowrap; max-width: 260px; font-style: italic;
}

/* ============================================ */
/* INPUT AREA                                  */
/* ============================================ */
#message-input {
    transition: height 0.1s ease;
    overflow-y: hidden;
}

/* ============================================ */
/* DRAG & DROP                                 */
/* ============================================ */
#drag-overlay.drag-active {
    display: block !important;
}

body.drag-over #drag-overlay {
    display: block !important;
}

/* ============================================ */
/* MOBILE                                      */
/* ============================================ */
@media (max-width: 768px) {
    .sidebar { transform: translateX(-272px); }
    .sidebar.mobile-open { transform: translateX(0) !important; }
    #main-content { margin-left: 0 !important; }

    .message-user { max-width: 86%; font-size: 13.5px; }
    .message-assistant { max-width: 96%; padding: 14px 16px 12px; font-size: 14px; }
    .message-wrapper.assistant:has(pre) .message-assistant { padding: 14px 0 12px; }
    .message-wrapper.assistant:has(pre) .message-assistant > *:not(pre) {
        padding-left: 16px; padding-right: 16px;
    }

    .message-assistant table { font-size: 12px; }
    .message-assistant th, .message-assistant td { padding: 6px 10px; }
    .message-assistant pre code { font-size: 0.78rem; padding: 12px 14px; }

    /* Edit overlay: full width on mobile */
    .msg-edit-overlay { max-width: 100%; }
    .msg-edit-hint { display: none; }

    #toast-container { bottom: 80px; }
}