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

/* ===== TOKENS ===== */
:root {
    --bg:          #212121;
    --sidebar-bg:  #171717;
    --surface:     #2f2f2f;
    --surface-2:   #3a3a3a;
    --surface-3:   #404040;
    --text:        #ececec;
    --text-2:      #b4b4b4;
    --text-3:      #8e8ea0;
    --border:      rgba(255,255,255,0.08);
    --hover:       rgba(255,255,255,0.06);
    --hover-2:     rgba(255,255,255,0.10);
    --ai-ava-bg:   #9b1c1c;
    --accent:      #10a37f;
    --send-off:    #4d4d4f;
    --send-on:     #ffffff;
    --sidebar-w:   260px;
    --topbar-h:    56px;
    --max-chat:    720px;
    --max-compose: 680px;
    --r-card:      12px;
    --r-bubble:    18px;
    --r-input:     16px;
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
}

/* ===== BASE ===== */
html, body {
    height: 100%;
    overflow: hidden;
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

button {
    font-family: var(--font);
    cursor: pointer;
    border: none;
    background: none;
    color: inherit;
}

/* ===== SHELL ===== */
.app-shell {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ─────────────────────────────────────────
   SIDEBAR
───────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-w);
    flex-shrink: 0;
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: width 0.25s ease;
    white-space: nowrap;
}

.app-shell.sidebar-collapsed .sidebar {
    width: 0;
}

/* Top row: logo left, collapse right */
.sb-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 10px;
    height: var(--topbar-h);
    flex-shrink: 0;
}

.sb-logo {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    flex-shrink: 0;
}

.sb-logo-img {
    width: 28px;
    height: 28px;
    object-fit: contain;
    border-radius: 6px;
}

/* Primary icon+text nav items */
.sb-nav {
    padding: 4px 8px 8px;
    flex-shrink: 0;
}

.sb-nav-item {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    border-radius: 8px;
    color: var(--text);
    font-size: 15px;
    font-weight: 300;
    text-align: left;
    transition: background 0.1s;
}

.sb-nav-item:hover {
    background: var(--hover);
}

.sb-nav-item svg {
    flex-shrink: 0;
    opacity: 1;
}

/* Chat history section */
.sb-history {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 4px 8px;
    display: flex;
    flex-direction: column;
}

.sb-section-label {
    display: block;
    font-size: 13px;
    font-weight: 300;
    color: var(--text-3);
    padding: 10px 10px 4px;
}

.sb-chat-row {
    position: relative;
    display: flex;
    align-items: center;
    border-radius: 8px;
    transition: background 0.1s;
}

.sb-chat-row:hover {
    background: var(--hover);
}

.sb-chat-row.is-active {
    background: var(--hover);
}

.sb-chat-item {
    flex: 1;
    min-width: 0;
    text-align: left;
    color: var(--text-2);
    font-size: 14px;
    padding: 8px 10px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    transition: color 0.1s;
}

.sb-chat-row:hover .sb-chat-item,
.sb-chat-row.is-active .sb-chat-item {
    color: var(--text);
}

.sb-chat-del {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    margin-right: 4px;
    border-radius: 4px;
    color: var(--text-3);
    opacity: 0;
    transition: opacity 0.1s, background 0.1s, color 0.1s;
}

.sb-chat-row:hover .sb-chat-del {
    opacity: 1;
}

.sb-chat-del:hover {
    background: rgba(255,255,255,0.1);
    color: var(--text);
}

.sb-empty {
    font-size: 13px;
    color: var(--text-3);
    padding: 8px 10px;
    font-style: italic;
}

/* Bottom user row */
.sb-foot {
    padding: 8px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.sb-user-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 8px;
    transition: background 0.1s;
    cursor: default;
}

.sb-user-row:hover {
    background: var(--hover);
}

.sb-ava {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: #7c3aed;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 700;
    color: white;
    flex-shrink: 0;
}

.sb-user-meta {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.sb-user-name {
    font-size: 14px;
    font-weight: 500;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sb-user-plan {
    font-size: 12px;
    color: var(--text-3);
}

.sb-upgrade-btn {
    flex-shrink: 0;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-2);
    background: var(--surface);
    border-radius: 8px;
    padding: 5px 10px;
    transition: background 0.1s, color 0.1s;
}

.sb-upgrade-btn:hover {
    background: var(--surface-2);
    color: var(--text);
}

/* ─────────────────────────────────────────
   MOBILE OVERLAY
───────────────────────────────────────── */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 40;
}

/* ─────────────────────────────────────────
   MAIN
───────────────────────────────────────── */
.main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    background: var(--bg);
}

/* ─────────────────────────────────────────
   TOPBAR
───────────────────────────────────────── */
.topbar {
    height: var(--topbar-h);
    display: flex;
    align-items: center;
    padding: 0 12px;
    flex-shrink: 0;
    position: relative;
}

.topbar-l {
    display: flex;
    align-items: center;
    gap: 2px;
}

.topbar-c {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
}

.topbar-r {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-left: auto;
}

/* Shared icon button */
.icon-btn {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    color: var(--text-2);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.12s, color 0.12s;
}

.icon-btn:hover {
    background: var(--hover-2);
    color: var(--text);
}

/* Topbar toggle: only visible when sidebar collapsed */
.topbar-toggle {
    display: none;
}

.app-shell.sidebar-collapsed .topbar-toggle {
    display: flex;
}

/* Model selector */
.model-drop {
    display: flex;
    align-items: center;
    gap: 4px;
    color: var(--text);
    font-size: 16px;
    font-weight: 400;
    padding: 6px 8px;
    border-radius: 8px;
    transition: background 0.12s;
    font-family: var(--font);
}

.model-drop:hover {
    background: var(--hover-2);
}

.model-drop svg {
    color: var(--text-3);
    flex-shrink: 0;
}

/* Center "Get Plus"–style pill */
.topbar-plus-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    font-weight: 600;
    padding: 7px 14px;
    border-radius: 999px;
    background: #AB47BC;
    color: white;
    transition: opacity 0.12s;
    font-family: var(--font);
}

.topbar-plus-btn:hover {
    opacity: 0.88;
}

/* Share button */
.share-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    border: 1px solid var(--border);
    color: var(--text-2);
    font-size: 13px;
    font-weight: 500;
    padding: 7px 12px;
    border-radius: 999px;
    transition: background 0.12s, border-color 0.12s, color 0.12s;
    font-family: var(--font);
}

.share-btn:hover {
    background: var(--hover);
    border-color: rgba(255, 255, 255, 0.18);
    color: var(--text);
}

/* Topbar user avatar */
.topbar-user-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    overflow: hidden;
}

.topbar-user-ava {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #7c3aed;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 700;
    color: white;
}

/* ─────────────────────────────────────────
   CHAT AREA
───────────────────────────────────────── */
.chat-area {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    scroll-behavior: smooth;
}

/* ─────────────────────────────────────────
   WELCOME
───────────────────────────────────────── */
.welcome {
    min-height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 32px 16px 100px;
}

.welcome.hidden {
    display: none;
}

.welcome-inner {
    width: min(680px, 100%);
    text-align: center;
}

.welcome-h {
    font-size: clamp(22px, 2.8vw, 34px);
    font-weight: 400;
    color: var(--text);
    margin-bottom: 24px;
    letter-spacing: -0.01em;
}

/* Suggestion cards: 2×2 grid */
.cards-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    text-align: left;
}

.card {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 14px;
    background: var(--surface);
    border-radius: var(--r-card);
    color: var(--text-2);
    transition: background 0.15s;
    font-family: var(--font);
    text-align: left;
}

.card:hover {
    background: var(--surface-2);
    color: var(--text);
}

.card:hover .card-icon {
    color: var(--text-2);
}

.card-icon {
    color: var(--text-3);
    flex-shrink: 0;
    margin-top: 1px;
    transition: color 0.15s;
}

.card-body {
    flex: 1;
    min-width: 0;
}

.card-title {
    font-size: 14px;
    font-weight: 500;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.card-sub {
    font-size: 13px;
    color: var(--text-3);
    margin-top: 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ─────────────────────────────────────────
   MESSAGES
───────────────────────────────────────── */
.msgs {
    display: none;
    flex-direction: column;
    max-width: var(--max-chat);
    margin: 0 auto;
    width: 100%;
    padding: 24px 16px 40px;
}

.msgs.active {
    display: flex;
}

.msg {
    display: flex;
    gap: 12px;
    padding: 8px 0;
}

/* User: right-aligned bubble */
.msg-user {
    justify-content: flex-end;
    padding-left: 56px;
}

/* AI: avatar + body */
.msg-ai {
    align-items: flex-start;
    padding-right: 56px;
}

.ai-ava {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--ai-ava-bg);
    overflow: hidden;
    flex-shrink: 0;
    margin-top: 2px;
}

.msg-bubble {
    background: var(--surface);
    border-radius: var(--r-bubble);
    padding: 12px 16px;
    max-width: 100%;
    word-break: break-word;
}

.msg-ai-body {
    flex: 1;
    min-width: 0;
    padding-top: 2px;
}

/* ─────────────────────────────────────────
   MESSAGE TEXT
───────────────────────────────────────── */
.msg-text {
    line-height: 1.68;
    color: var(--text);
    word-break: break-word;
}

.msg-text p              { margin-bottom: 12px; }
.msg-text p:last-child   { margin-bottom: 0; }
.msg-text ul,
.msg-text ol             { padding-left: 22px; margin-bottom: 12px; }
.msg-text li             { margin-bottom: 4px; }
.msg-text pre            { border-radius: 10px; overflow-x: auto; margin-bottom: 12px; }
.msg-text pre:last-child { margin-bottom: 0; }
.msg-text h1,
.msg-text h2,
.msg-text h3             { margin: 18px 0 8px; font-weight: 600; }
.msg-text h1:first-child,
.msg-text h2:first-child,
.msg-text h3:first-child { margin-top: 0; }

.msg-text code:not(pre code) {
    background: rgba(255, 255, 255, 0.09);
    padding: 2px 5px;
    border-radius: 4px;
    font-size: 0.9em;
}

.msg-text blockquote {
    border-left: 3px solid var(--border);
    padding-left: 14px;
    color: var(--text-2);
    margin-bottom: 12px;
}

.msg-text a            { color: var(--accent); text-decoration: none; }
.msg-text a:hover      { text-decoration: underline; }

.msg-text table        { border-collapse: collapse; width: 100%; margin-bottom: 12px; font-size: 14px; }
.msg-text th,
.msg-text td           { border: 1px solid var(--border); padding: 8px 12px; text-align: left; }
.msg-text th           { background: var(--surface); }

/* Message action buttons */
.msg-actions {
    display: flex;
    gap: 2px;
    margin-top: 6px;
    opacity: 0;
    transition: opacity 0.15s;
}

.msg:hover .msg-actions,
.msg-actions:focus-within {
    opacity: 1;
}

.action-btn {
    display: flex;
    align-items: center;
    gap: 5px;
    color: var(--text-3);
    font-size: 13px;
    padding: 6px 8px;
    border-radius: 6px;
    transition: background 0.1s, color 0.1s;
    font-family: var(--font);
}

.action-btn:hover {
    background: var(--hover);
    color: var(--text-2);
}

/* Sources */
.sources-wrap {
    margin-top: 14px;
    padding: 10px 12px;
    background: rgba(16, 163, 127, 0.06);
    border: 1px solid rgba(16, 163, 127, 0.18);
    border-radius: 10px;
}

.sources-hd {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--text-3);
    margin-bottom: 6px;
}

.source-item {
    font-size: 13px;
    color: var(--text-2);
    padding: 2px 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ─────────────────────────────────────────
   LOADING
───────────────────────────────────────── */
.loader {
    display: none;
    max-width: var(--max-chat);
    margin: 0 auto;
    width: 100%;
    padding: 0 16px 20px;
}

.loader.active {
    display: block;
}

.loader-inner {
    display: flex;
    align-items: center;
    gap: 12px;
    padding-right: 56px;
}

.ai-dot-ava {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--ai-ava-bg);
    overflow: hidden;
    flex-shrink: 0;
}

/* Icon image inside avatar circles */
.ava-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.dots {
    display: flex;
    gap: 5px;
    align-items: center;
}

.dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-3);
    animation: dotPop 1.3s infinite ease-in-out;
}

.dots span:nth-child(2) { animation-delay: 0.16s; }
.dots span:nth-child(3) { animation-delay: 0.32s; }

@keyframes dotPop {
    0%, 80%, 100% { transform: scale(0.8); opacity: 0.4; }
    40%           { transform: scale(1.1); opacity: 1; }
}

/* ─────────────────────────────────────────
   COMPOSER
───────────────────────────────────────── */
.composer-wrap {
    padding: 8px 16px 20px;
    max-width: calc(var(--max-compose) + 32px);
    margin: 0 auto;
    width: 100%;
    flex-shrink: 0;
}

.composer-card {
    background: var(--surface);
    border-radius: var(--r-input);
    padding: 12px 14px 10px;
}

.composer-card textarea {
    width: 100%;
    border: none;
    outline: none;
    resize: none;
    background: transparent;
    color: var(--text);
    font-family: var(--font);
    font-size: 16px;
    line-height: 1.5;
    min-height: 24px;
    max-height: 200px;
    display: block;
}

.composer-card textarea::placeholder {
    color: var(--text-3);
}

.composer-tools {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 10px;
}

.tools-l,
.tools-r {
    display: flex;
    align-items: center;
    gap: 2px;
}

.tool-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--text-3);
    font-size: 13px;
    font-weight: 500;
    padding: 6px 10px;
    border-radius: 8px;
    transition: background 0.1s, color 0.1s;
    font-family: var(--font);
}

.tool-btn:hover {
    background: var(--surface-2);
    color: var(--text-2);
}

.rag-toggle.rag-on {
    color: var(--accent);
}

.rag-toggle.rag-on:hover {
    background: rgba(16, 163, 127, 0.1);
    color: var(--accent);
}

/* Send button */
.send-btn {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--send-off);
    color: rgba(255, 255, 255, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: not-allowed;
    transition: background 0.15s;
    flex-shrink: 0;
}

.send-btn:not(:disabled) {
    background: var(--send-on);
    color: #0d0d0d;
    cursor: pointer;
}

.send-btn:not(:disabled):hover {
    background: #e4e4e4;
}

.disclaimer {
    text-align: center;
    font-size: 12px;
    color: var(--text-3);
    margin-top: 10px;
}

/* ─────────────────────────────────────────
   TOAST
───────────────────────────────────────── */
.toast {
    position: fixed;
    bottom: 88px;
    left: 50%;
    transform: translateX(-50%) translateY(10px);
    background: var(--surface-3);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 16px;
    font-size: 13px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
    z-index: 999;
    white-space: nowrap;
    max-width: 90vw;
    overflow: hidden;
    text-overflow: ellipsis;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ─────────────────────────────────────────
   SCROLLBAR
───────────────────────────────────────── */
::-webkit-scrollbar      { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.10); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.18); }

/* ─────────────────────────────────────────
   MOBILE (≤ 768px)
───────────────────────────────────────── */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        top: 0; left: 0; bottom: 0;
        width: var(--sidebar-w) !important;
        transform: translateX(calc(-1 * var(--sidebar-w)));
        transition: transform 0.25s ease;
        z-index: 50;
    }

    .app-shell.sidebar-collapsed .sidebar {
        transform: translateX(calc(-1 * var(--sidebar-w)));
    }

    .app-shell:not(.sidebar-collapsed) .sidebar {
        transform: translateX(0);
    }

    .app-shell:not(.sidebar-collapsed) .sidebar-overlay {
        display: block;
    }

    .cards-grid {
        grid-template-columns: 1fr;
    }

    .topbar-plus-btn {
        display: none;
    }

    .msg-ai  { padding-right: 16px; }
    .msg-user { padding-left: 16px; }
    .loader-inner { padding-right: 16px; }

    .composer-wrap {
        padding: 8px 12px 16px;
    }
}

@media (max-width: 480px) {
    .share-btn span {
        display: none;
    }
    .share-btn {
        padding: 7px;
        border-radius: 50%;
        width: 34px;
        height: 34px;
        justify-content: center;
    }
}
