/* ═══════════════════════════════════════════
   LoreAI — style.css
   ═══════════════════════════════════════════ */

/* ── VARIABLES ──────────────────────────── */
:root {
    --bg:          #1e1e1e;
    --sidebar-bg:  #161616;
    --surface:     #2c2c2c;
    --surface2:    #383838;
    --surface3:    #444;
    --border:      rgba(255,255,255,0.09);
    --border2:     rgba(255,255,255,0.15);
    --accent:      #19c37d;
    --accent-dim:  rgba(25,195,125,0.14);
    --accent-glow: rgba(25,195,125,0.35);
    --red:         #f87171;
    --text:        #ededed;
    --text-dim:    rgba(236,236,236,0.36);
    --text-mid:    rgba(236,236,236,0.62);
    --user-bg:     #2c2c2c;
    --radius:      12px;
    --sw:          256px;
    --font:        'Inter', system-ui, sans-serif;
    --mono:        'JetBrains Mono', monospace;
}

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

html {
    height: 100%;
    height: 100dvh;
    overflow: hidden;
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    display: flex;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    font-size: 15px;
    position: relative;
}

/* ── SPACE BG (canvas-driven) ───────────── */
#star-canvas {
    display: none !important;
}

/* ── SIDEBAR ────────────────────────────── */
#sidebar {
    position: relative; z-index: 20; width: var(--sw); flex-shrink: 0;
    background: #161616; display: flex; flex-direction: column;
    overflow: hidden; transition: width .25s ease, transform .25s ease;
    border-right: 1px solid var(--border);
    isolation: isolate;
}
#sidebar.collapsed { width: 0; }

/* Sidebar tabs */
.sb-tabs {
    display: flex; border-bottom: 1px solid var(--border);
    padding: 8px 8px 0; gap: 2px; flex-shrink: 0;
}
.sb-tab {
    flex: 1; padding: 8px 6px; background: transparent; border: none;
    border-radius: 8px 8px 0 0; color: var(--text-mid); font-family: var(--font);
    font-size: 12.5px; cursor: pointer; transition: background .15s, color .15s;
    display: flex; align-items: center; justify-content: center; gap: 5px;
    border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.sb-tab:hover { color: var(--text); background: var(--surface); }
.sb-tab.active { color: var(--text); border-bottom-color: var(--accent); }

/* Tab panels */
.sb-panel { display: none; flex: 1; flex-direction: column; overflow: hidden; }
.sb-panel.active { display: flex; }

/* ─ Chats panel ─ */
.sb-head { padding: 10px; flex-shrink: 0; }
.new-btn {
    width: 100%; padding: 9px 12px; background: transparent;
    border: 1px solid var(--border); border-radius: var(--radius);
    color: var(--text); font-family: var(--font); font-size: 13.5px;
    cursor: pointer; display: flex; align-items: center; gap: 8px;
    transition: background .15s; text-align: start;
}
.new-btn:hover { background: var(--surface); }

.chat-list {
    flex: 1; overflow-y: auto; padding: 4px 8px 8px;
    scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.07) transparent;
}
.chat-list::-webkit-scrollbar { width: 3px; }

.grp-lbl {
    font-size: 11px; font-weight: 600; color: var(--text-dim);
    letter-spacing: .3px; padding: 12px 8px 4px;
}
.ci {
    display: flex; align-items: center; gap: 8px; padding: 8px 10px;
    border-radius: 8px; cursor: pointer; color: var(--text-mid); font-size: 13.5px;
    transition: background .12s, color .12s;
}
.ci:hover { background: var(--surface); color: var(--text); }
.ci.active { background: var(--surface2); color: var(--text); }
.ci-title { flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.ci-del {
    opacity: 0; padding: 2px 6px; border-radius: 5px; font-size: 11px;
    color: var(--text-dim); cursor: pointer; transition: opacity .12s, color .12s; flex-shrink: 0;
}
.ci:hover .ci-del { opacity: 1; }
.ci-del:hover { color: var(--red); }

/* ─ News panel ─ */
#news-panel { padding: 8px; gap: 8px; overflow-y: auto; }
.news-card {
    background: var(--surface); border-radius: 10px; padding: 11px 13px;
    border: 1px solid var(--border); cursor: pointer;
    transition: background .15s, border-color .15s; text-decoration: none;
    display: block; animation: fadeUp .3s ease;
}
.news-card:hover { background: var(--surface2); border-color: var(--border2); }
.news-tag {
    font-size: 10px; font-weight: 600; letter-spacing: .8px; text-transform: uppercase;
    color: var(--accent); margin-bottom: 5px;
}
.news-title { font-size: 13px; color: var(--text); line-height: 1.5; font-weight: 500; }
.news-date { font-size: 11px; color: var(--text-dim); margin-top: 5px; }
.news-loading { padding: 20px; text-align: center; color: var(--text-dim); font-size: 13px; }
.news-dot {
    display: inline-block; width: 6px; height: 6px; border-radius: 50%;
    background: var(--accent); margin-right: 6px;
    animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse { 0%,100%{opacity:1;transform:scale(1)} 50%{opacity:.4;transform:scale(.7)} }

/* Sidebar bottom */
.sb-bot { border-top: 1px solid var(--border); padding: 10px; flex-shrink: 0; }
.sb-btn {
    width: 100%; padding: 9px 12px; background: transparent; border: none;
    border-radius: 8px; color: var(--text-mid); font-family: var(--font);
    font-size: 13.5px; cursor: pointer; display: flex; align-items: center;
    gap: 9px; transition: background .15s, color .15s; text-align: start;
}
.sb-btn:hover { background: var(--surface); color: var(--text); }
.sb-btn.danger:hover { color: var(--red); }

/* ── MAIN ───────────────────────────────── */
#main {
    position: relative; z-index: 10; flex: 1;
    display: flex; flex-direction: column; overflow: hidden; min-width: 0;
    isolation: isolate;
}

/* ── TOP BAR ────────────────────────────── */
.top-bar {
    display: flex; align-items: center; gap: 6px; padding: 8px 14px;
    border-bottom: 1px solid var(--border);
    background: rgba(33,33,33,0.95);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    flex-shrink: 0; z-index: 30; height: 52px;
}
.icon-btn {
    background: transparent; border: none; border-radius: 8px;
    color: var(--text-mid); padding: 6px 8px; cursor: pointer;
    font-size: 16px; line-height: 1; display: flex; align-items: center;
    transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--surface); color: var(--text); }

/* Server status pill */
.status-pill {
    display: flex; align-items: center; gap: 6px; padding: 5px 11px;
    border-radius: 20px; border: 1px solid var(--border); font-size: 12px;
    color: var(--text-dim); transition: all .3s; cursor: default; user-select: none;
}
.status-dot {
    width: 7px; height: 7px; border-radius: 50%; background: #555;
    transition: background .3s; flex-shrink: 0;
}
.status-pill.online  { border-color: rgba(25,195,125,.3); color: var(--accent); }
.status-pill.online  .status-dot { background: var(--accent); box-shadow: 0 0 6px var(--accent-glow); animation: pulse 2s ease infinite; }
.status-pill.offline { border-color: rgba(248,113,113,.3); color: var(--red); }
.status-pill.offline .status-dot { background: var(--red); }
.status-pill.checking .status-dot { background: #f59e0b; animation: pulse 1s ease infinite; }

/* Wrapper + dropdown */
.wrapper { position: relative; }
.wrapper:hover .dropdown-menu { display: block; }

.ctrl-btn {
    display: flex; align-items: center; gap: 6px; padding: 6px 12px;
    background: transparent; border: 1px solid var(--border); border-radius: 8px;
    cursor: pointer; font-family: var(--font); font-size: 13.5px; color: var(--text-mid);
    white-space: nowrap; transition: background .15s, color .15s; user-select: none;
}
.ctrl-btn:hover { background: var(--surface); color: var(--text); }
.chevron { font-size: 9px; opacity: .4; }

.dropdown-menu {
    display: none; position: absolute; top: calc(100% + 5px);
    background: #2a2a2a; border: 1px solid var(--border);
    border-radius: 10px; min-width: 160px; overflow: hidden;
    box-shadow: 0 8px 28px rgba(0,0,0,.5); z-index: 200;
}
[dir="ltr"] .dropdown-menu { left: 0; }
[dir="rtl"] .dropdown-menu { right: 0; }
.option-item {
    display: block; padding: 9px 14px; font-size: 13.5px; color: var(--text-mid);
    cursor: pointer; transition: background .12s, color .12s;
    text-decoration: none; white-space: nowrap;
}
.option-item:hover { background: var(--surface2); color: var(--text); }
.option-item.danger { color: var(--red); }
.option-item.danger:hover { background: rgba(248,113,113,.1); }

.top-title {
    flex: 1; text-align: center; font-size: 14px; font-weight: 500;
    color: var(--text-mid); white-space: nowrap; overflow: hidden;
    text-overflow: ellipsis; padding: 0 8px;
}
.spacer { flex: 1; }

/* ── CHAT AREA ──────────────────────────── */
#chat {
    flex: 1; overflow-y: auto; padding: 20px 0 24px;
    display: flex; flex-direction: column;
    scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.07) transparent;
    scroll-behavior: smooth;
}
#chat::-webkit-scrollbar { width: 5px; }
#chat::-webkit-scrollbar-thumb { background: rgba(255,255,255,.08); border-radius: 4px; }

/* Welcome */
.welcome-screen {
    margin: auto; text-align: center; display: flex; flex-direction: column;
    align-items: center; gap: 16px; padding: 40px 20px; animation: fadeUp .4s ease;
}
.logo-large {
    width: 72px; height: 72px; border-radius: 20px; object-fit: cover;
    box-shadow: 0 0 0 1px var(--border), 0 12px 40px rgba(0,0,0,.5), 0 0 40px rgba(25,195,125,.06);
}
.welcome-screen h2 { font-size: 26px; font-weight: 600; letter-spacing: -.5px; }
.welcome-screen p  { font-size: 13px; color: var(--text-dim); }

/* Quick commands hint */
.slash-hint {
    display: flex; gap: 8px; flex-wrap: wrap; justify-content: center;
    margin-top: 4px;
}
.slash-tag {
    padding: 5px 11px; background: var(--surface); border: 1px solid var(--border);
    border-radius: 20px; font-size: 12.5px; color: var(--text-mid); cursor: pointer;
    transition: background .15s, color .15s, border-color .15s;
}
.slash-tag:hover { background: var(--surface2); color: var(--text); border-color: var(--border2); }

.cp-badge {
    display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px;
    background: var(--accent-dim); border: 1px solid rgba(25,195,125,.25);
    border-radius: 20px; font-size: 12px; color: var(--accent);
}

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

/* Message rows */
.msg-row { width: 100%; padding: 5px 0; display: flex; justify-content: center; animation: fadeUp .2s ease; }
.msg-row:hover .msg-actions { opacity: 1; }
.msg-inner { width: 100%; max-width: 720px; padding: 0 22px; display: flex; gap: 12px; align-items: flex-start; }

.avatar {
    width: 30px; height: 30px; border-radius: 6px; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    font-size: 13px; font-weight: 600; margin-top: 2px; overflow: hidden;
}
.avatar-user { background: var(--surface2); color: var(--text); }
.avatar-ai img { width: 100%; height: 100%; object-fit: cover; border-radius: 6px; }

.bubble { flex: 1; min-width: 0; font-size: 15px; line-height: 1.75; color: var(--text); padding: 3px 0; }

.msg-row.user .msg-inner { flex-direction: row-reverse; }
[dir="rtl"] .msg-row.user .msg-inner { flex-direction: row; }
.msg-row.user .bubble {
    background: var(--user-bg); border-radius: 18px 18px 4px 18px;
    padding: 10px 16px; flex: 0 1 auto; max-width: 78%; align-self: flex-end;
}
[dir="rtl"] .msg-row.user .bubble { border-radius: 18px 18px 18px 4px; }

.msg-actions { display: flex; gap: 2px; margin-top: 6px; opacity: 0; transition: opacity .15s; }
.act-btn {
    background: transparent; border: none; color: var(--text-dim); cursor: pointer;
    padding: 4px 7px; border-radius: 6px; font-size: 12px; font-family: var(--font);
    transition: background .12s, color .12s; display: flex; align-items: center; gap: 4px;
}
.act-btn:hover { background: var(--surface); color: var(--text); }

/* ─ Think block ─ */
.think-block {
    background: rgba(25,195,125,.05); border: 1px solid rgba(25,195,125,.15);
    border-radius: 8px; padding: 8px 28px 8px 12px; margin-bottom: 10px;
    font-size: 13px; color: rgba(25,195,125,.68); font-style: italic;
    line-height: 1.6; cursor: pointer; position: relative; user-select: none;
}
.think-block::before {
    content: '⟡ thinking'; display: block; font-style: normal; font-size: 10px;
    letter-spacing: 1.3px; text-transform: uppercase;
    color: rgba(25,195,125,.38); margin-bottom: 4px; font-weight: 600;
}
.think-block .think-text { display: none; }
.think-block.open .think-text { display: block; }
.think-block::after {
    content: '▾'; position: absolute; top: 8px; right: 10px; font-size: 10px;
    color: rgba(25,195,125,.35); transition: transform .22s; font-style: normal;
}
[dir="rtl"] .think-block { padding: 8px 12px 8px 28px; }
[dir="rtl"] .think-block::after { right: auto; left: 10px; }
.think-block.open::after { transform: rotate(180deg); }

/* ─ Code ─ */
.bubble pre { margin: 10px 0; border-radius: 10px; overflow: hidden; border: 1px solid rgba(255,255,255,.08); }
.code-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 7px 14px; background: rgba(0,0,0,.35); font-family: var(--mono);
    font-size: 11.5px; color: rgba(255,255,255,.28);
    border-bottom: 1px solid rgba(255,255,255,.06);
}
.copy-btn {
    cursor: pointer; padding: 2px 8px; border-radius: 5px;
    border: 1px solid rgba(255,255,255,.1); background: transparent;
    color: rgba(255,255,255,.3); font-size: 11px; font-family: var(--font); transition: all .15s;
}
.copy-btn:hover { background: rgba(255,255,255,.08); color: rgba(255,255,255,.7); }
.bubble pre code.hljs { padding: 14px 16px; font-size: 13px; font-family: var(--mono); background: #1a1a1a; }
.bubble code:not(.hljs) {
    background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.1);
    padding: 1px 6px; border-radius: 5px; font-family: var(--mono); font-size: 13.5px;
}
.bubble strong { font-weight: 600; }
.bubble em { color: var(--text-mid); }
.bubble p { margin: 0 0 8px; }
.bubble p:last-child { margin-bottom: 0; }

/* Typing */
.typing-dots { display: flex; gap: 4px; align-items: center; padding: 6px 0; }
.typing-dots span { width: 5px; height: 5px; border-radius: 50%; background: var(--text-mid); animation: bounce .9s ease-in-out infinite; }
.typing-dots span:nth-child(2) { animation-delay: .15s; }
.typing-dots span:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%,80%,100%{transform:translateY(0);opacity:.3} 40%{transform:translateY(-4px);opacity:1} }

/* ── INPUT ──────────────────────────────── */
.input-wrap { flex-shrink: 0; padding: 10px 14px 14px; display: flex; justify-content: center; background: rgba(33,33,33,0.95); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); }
.input-box {
    width: 100%; max-width: 720px; background: var(--surface);
    border: 1px solid var(--border); border-radius: 16px; overflow: visible;
    transition: border-color .2s, box-shadow .2s; position: relative;
    box-shadow: 0 2px 14px rgba(0,0,0,.25);
}
.input-box:focus-within { border-color: rgba(255,255,255,.22); box-shadow: 0 4px 20px rgba(0,0,0,.35); }
.input-row { display: flex; align-items: flex-end; padding: 10px 10px 10px 16px; gap: 8px; }
[dir="rtl"] .input-row { padding: 10px 16px 10px 10px; }
textarea {
    flex: 1; background: transparent; border: none; color: var(--text);
    resize: none; font-family: var(--font); font-size: 15px;
    line-height: 1.55; outline: none; max-height: 200px; overflow-y: auto;
    scrollbar-width: none; padding: 0;
}
textarea::placeholder { color: var(--text-dim); }

#send, #send-btn {
    flex-shrink: 0; width: 34px; height: 34px; background: var(--accent);
    color: #000; border: none; border-radius: 8px; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: background .15s, transform .1s;
}
#send:hover, #send-btn:hover { background: #22d68a; }
#send:active, #send-btn:active { transform: scale(.92); }
#send:disabled, #send-btn:disabled { background: var(--surface2); color: var(--text-dim); cursor: not-allowed; opacity: .5; }

.input-hint { font-size: 11px; color: var(--text-dim); text-align: center; padding: 5px 0 0; }

/* ── INPUT FOOTER ───────────────────────── */
.input-footer {
    display: flex; align-items: center; justify-content: center;
    gap: 8px; padding: 6px 0 0; flex-wrap: wrap;
}
.disclaimer { font-size: 11px; color: var(--text-dim); }
.footer-sep { width: 1px; height: 11px; background: var(--border); flex-shrink: 0; }
.socials { display: flex; align-items: center; gap: 2px; }
.social-link {
    display: flex; align-items: center; justify-content: center;
    width: 24px; height: 24px; border-radius: 6px;
    color: var(--text-dim); transition: background .15s, color .15s; text-decoration: none;
}
.social-link:hover { background: var(--surface); color: var(--text); }

/* ─ Slash command popup ─ */
#slash-popup {
    display: none;
    position: absolute;
    bottom: calc(100% + 6px);   /* above the input-box */
    left: 0; right: 0;
    background: #2a2a2a;
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 8px 28px rgba(0,0,0,.5);
    z-index: 300;
}
#slash-popup.open { display: block; }
.slash-cmd {
    display: flex; align-items: center; gap: 10px; padding: 10px 14px;
    cursor: pointer; transition: background .12s; border-bottom: 1px solid var(--border);
}
.slash-cmd:last-child { border-bottom: none; }
.slash-cmd:hover, .slash-cmd.selected { background: var(--surface2); }
.slash-cmd-name { font-size: 13.5px; font-weight: 500; color: var(--accent); font-family: var(--mono); }
.slash-cmd-desc { font-size: 12.5px; color: var(--text-dim); }

/* ── MODAL ──────────────────────────────── */
.modal-overlay {
    display: none; position: fixed; inset: 0; z-index: 1000;
    background: rgba(0,0,0,.65); backdrop-filter: blur(6px);
    align-items: center; justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal {
    background: #2a2a2a; border: 1px solid var(--border); border-radius: 14px;
    padding: 24px; width: 90%; max-width: 460px;
    animation: fadeUp .2s ease; box-shadow: 0 20px 50px rgba(0,0,0,.6);
}
.modal h3 { font-size: 15px; font-weight: 600; margin-bottom: 6px; }
.modal p  { font-size: 13px; color: var(--text-dim); margin-bottom: 14px; line-height: 1.6; }
.modal textarea {
    width: 100%; min-height: 100px; background: var(--surface);
    border: 1px solid var(--border); border-radius: 10px; color: var(--text);
    padding: 11px 13px; font-size: 13.5px; resize: vertical;
    margin-bottom: 14px; max-height: 220px; outline: none; font-family: var(--font);
}
.modal textarea:focus { border-color: rgba(255,255,255,.2); }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; }
.btn { padding: 8px 18px; border-radius: 8px; font-family: var(--font); font-size: 13.5px; cursor: pointer; border: none; transition: all .15s; }
.btn-ghost { background: var(--surface2); color: var(--text-mid); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--surface); color: var(--text); }
.btn-primary { background: var(--accent); color: #000; font-weight: 500; }
.btn-primary:hover { background: #22d68a; }

/* ── MOBILE ─────────────────────────────── */
@media (max-width: 700px) {
    #sidebar { position: fixed; top: 0; bottom: 0; left: 0; z-index: 100; width: var(--sw) !important; transform: translateX(-100%); }
    [dir="rtl"] #sidebar { left: auto; right: 0; transform: translateX(100%); }
    #sidebar.open { transform: translateX(0); }
    #sidebar.collapsed { transform: translateX(-100%); }
    [dir="rtl"] #sidebar.collapsed { transform: translateX(100%); }
    #sb-toggle { display: flex !important; }
    .sb-overlay { display: none; position: fixed; inset: 0; z-index: 99; background: rgba(0,0,0,.5); }
    .sb-overlay.open { display: block; }
    .top-title { display: none; }
    .status-label { display: none; }
}