/* assets/css/style.css - GnexChat Dark Theme */

:root {
    --bg-primary: #0f0f1a;
    --bg-secondary: #1a1a2e;
    --bg-tertiary: #16213e;
    --bg-card: #1e1e36;
    --accent: #00c9a7;
    --accent-hover: #00e5c0;
    --accent-glow: rgba(0, 201, 167, 0.15);
    --text-primary: #eee;
    --text-secondary: #aab;
    --text-muted: #667;
    --border: #2a2a4a;
    --sender-user: #4fc3f7;
    --sender-ai: #ab47bc;
    --sender-me: #66bb6a;
    --bubble-me: #1b3a2a;
    --bubble-ai: #2a1a3e;
    --bubble-other: #1a2a3e;
    --shadow: 0 2px 12px rgba(0,0,0,0.4);
    --radius: 12px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
}

/* ── Landing Page ─────────────────────────── */
.landing-container { max-width: 800px; margin: 0 auto; padding: 60px 20px; }
.landing-header { text-align: center; margin-bottom: 48px; }
.logo { display: flex; align-items: center; justify-content: center; gap: 12px; }
.logo-icon { font-size: 48px; }
.logo h1 { font-size: 40px; background: linear-gradient(135deg, var(--accent), #a855f7);
            -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; }
.tagline { color: var(--text-secondary); margin-top: 12px; font-size: 18px; }

.landing-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.landing-cards #restore-card { grid-column: 1 / -1; max-width: 480px; justify-self: center; }
@media (max-width: 640px) { .landing-cards { grid-template-columns: 1fr; }
    .landing-cards #restore-card { max-width: none; } }

.card { background: var(--bg-card); border: 1px solid var(--border);
        border-radius: var(--radius); padding: 32px; box-shadow: var(--shadow); }
.card h2 { margin-bottom: 20px; font-size: 22px; }

/* ── Forms ────────────────────────────────── */
label { display: block; margin-bottom: 16px; font-size: 14px; color: var(--text-secondary); }
input, select, textarea {
    width: 100%; margin-top: 6px; padding: 10px 14px;
    background: var(--bg-primary); border: 1px solid var(--border);
    border-radius: 8px; color: var(--text-primary); font-size: 15px;
    outline: none; transition: border-color 0.2s;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; font-family: inherit; }
.input-group { display: flex; gap: 8px; margin-top: 6px; }
.input-group input, .input-group select { flex: 1; margin-top: 0; }

/* ── Buttons ──────────────────────────────── */
.btn { display: inline-flex; align-items: center; justify-content: center;
       padding: 10px 20px; border: none; border-radius: 8px;
       font-size: 15px; font-weight: 600; cursor: pointer; transition: all 0.2s;
       text-decoration: none; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); transform: translateY(-1px); }
.btn-secondary { background: var(--bg-tertiary); color: var(--text-primary); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-accent { background: var(--accent); color: #fff; font-size: 13px; padding: 6px 14px; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-remove { background: none; border: none; color: var(--text-muted); cursor: pointer;
              font-size: 14px; padding: 2px 6px; margin-left: auto; }
.btn-remove:hover { color: var(--accent); }
.btn-promote { background: none; border: none; cursor: pointer; color: var(--text-muted);
               font-size: 14px; padding: 2px 6px; margin-left: auto; }
.btn-promote:hover { color: var(--accent); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.error-msg { background: #3a1020; border: 1px solid var(--accent); border-radius: 8px;
             padding: 10px 16px; margin-top: 12px; color: var(--accent-hover); font-size: 14px; }

/* ── Chat Layout ──────────────────────────── */
.chat-app { display: flex; height: 100vh; overflow: hidden; }

.sidebar { width: 280px; min-width: 280px; background: var(--bg-secondary);
           border-right: 1px solid var(--border); display: flex; flex-direction: column;
           overflow-y: auto; padding: 20px; }
.sidebar-header h2 { font-size: 18px; margin-bottom: 4px; }
.room-code { font-size: 13px; color: var(--text-muted); font-family: monospace;
             user-select: all; cursor: pointer; }
.sidebar-section { margin-top: 24px; }
.sidebar-section h3 { font-size: 13px; color: var(--text-secondary); margin-bottom: 10px;
                      text-transform: uppercase; letter-spacing: 1px; }

.share-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.qr-container { background: #fff; padding: 12px; border-radius: 8px; display: inline-block; margin-top: 8px; }
.user-list { list-style: none; }
.user-list li { padding: 6px 0; font-size: 14px; display: flex; align-items: center; gap: 6px; }
.user-list li.inactive { opacity: 0.4; text-decoration: line-through; }
.bot-meta { font-size: 11px; color: var(--text-muted); }

@media (max-width: 768px) {
    .sidebar { position: fixed; left: -300px; top: 0; bottom: 0; z-index: 100;
               transition: left 0.3s; box-shadow: 4px 0 20px rgba(0,0,0,0.5); }
    .sidebar.sidebar-open { left: 0; }
    .sidebar-toggle { display: inline-flex !important; }
    .sidebar-close-btn { display: flex !important; }
}
@media (min-width: 769px) {
    .sidebar-toggle { display: none !important; }
    .sidebar-close-btn { display: none !important; }
}

/* Sidebar overlay (mobile backdrop) */
.sidebar-overlay {
    display: none; position: fixed; inset: 0; z-index: 99;
    background: rgba(0,0,0,0.5); backdrop-filter: blur(2px);
}
.sidebar-overlay.visible { display: block; }

/* Sidebar close button (inside sidebar, mobile only) */
.sidebar-close-btn {
    display: none; position: absolute; top: 14px; right: 14px;
    background: none; border: none; color: var(--text-secondary);
    font-size: 24px; cursor: pointer; line-height: 1; padding: 4px 8px;
    border-radius: 4px; z-index: 5;
}
.sidebar-close-btn:hover { background: var(--border); color: var(--text-primary); }

/* Make sidebar-header relative for absolute close button */
.sidebar-header { position: relative; padding-right: 36px; }

/* ── Chat Main ────────────────────────────── */
.chat-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.chat-topbar { display: flex; align-items: center; gap: 12px;
               padding: 12px 20px; border-bottom: 1px solid var(--border);
               background: var(--bg-secondary); }
.chat-topbar span { font-weight: 600; }
.mention-hint { font-size: 12px; color: var(--text-muted); white-space: nowrap; }
.mention-hint code { background: var(--bg-primary); padding: 2px 6px; border-radius: 4px; font-size: 11px; }

.messages-container { flex: 1; overflow-y: auto; padding: 20px; background: var(--bg-primary); }
.messages { display: flex; flex-direction: column; gap: 8px; }

.system-msg { text-align: center; font-size: 13px; color: var(--text-muted);
              padding: 8px; font-style: italic; }

/* ── Message Bubbles ──────────────────────── */
.msg-bubble { max-width: 75%; padding: 12px 16px; border-radius: 16px;
              word-wrap: break-word; line-height: 1.5; }
.bubble-me { background: var(--bubble-me); margin-left: auto; border-bottom-right-radius: 4px; }
.bubble-ai { background: var(--bubble-ai); border-bottom-left-radius: 4px; }
.bubble-other { background: var(--bubble-other); border-bottom-left-radius: 4px; }

.msg-header { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; flex-wrap: wrap; }
.msg-sender { font-weight: 700; font-size: 13px; }
.sender-me { color: var(--sender-me); }
.sender-ai { color: var(--sender-ai); }
.sender-other { color: var(--sender-user); }
.msg-provider { font-size: 10px; color: var(--text-muted); background: var(--bg-secondary);
                padding: 1px 6px; border-radius: 4px; }
.msg-provider.discussion { background: #2a3a1e; color: #8bc34a; }
.msg-time { font-size: 11px; color: var(--text-muted); margin-left: auto; }
.msg-content { font-size: 15px; }
.msg-content pre { background: var(--bg-secondary); border-radius: 8px; padding: 10px;
                   margin: 8px 0; overflow-x: auto; font-size: 13px; }
.msg-content code { background: var(--bg-secondary); padding: 1px 5px; border-radius: 4px; font-size: 13px; }

/* ── Chat Input ───────────────────────────── */
.chat-input-area { padding: 12px 20px; border-top: 1px solid var(--border);
                   background: var(--bg-secondary); position: relative; }
.chat-form { display: flex; gap: 10px; align-items: flex-end; }
.chat-form textarea { flex: 1; padding: 12px 16px; background: var(--bg-primary);
                      border: 1px solid var(--border); border-radius: 12px; color: var(--text-primary);
                      font-size: 15px; font-family: inherit; resize: none; outline: none;
                      max-height: 200px; min-height: 44px; line-height: 1.4; }
.chat-form textarea:focus { border-color: var(--accent); }
.send-btn { height: 44px; min-width: 70px; }

/* ── Mention Suggestions ──────────────────── */
.mention-suggestions { position: absolute; bottom: 100%; left: 20px; right: 90px;
                       background: var(--bg-card); border: 1px solid var(--border);
                       border-radius: 8px; max-height: 200px; overflow-y: auto; box-shadow: var(--shadow); }
.mention-item { padding: 10px 14px; cursor: pointer; font-size: 14px; }
.mention-item:hover { background: var(--bg-tertiary); }

/* ── Modal ────────────────────────────────── */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.7);
         display: flex; align-items: center; justify-content: center; z-index: 200; }
.modal-content { background: var(--bg-card); border: 1px solid var(--border);
                 border-radius: var(--radius); padding: 32px; max-width: 540px; width: 90%;
                 max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow); }
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; }
.modal-header h2 { font-size: 20px; }
.modal-close { background: none; border: none; color: var(--text-secondary);
               font-size: 28px; cursor: pointer; line-height: 1; }
.modal-close:hover { color: var(--text-primary); }
.form-row { margin-bottom: 16px; }
.provider-hint { font-size: 12px; color: #66bb6a; background: rgba(102,187,106,0.08);
                 border: 1px solid rgba(102,187,106,0.2); border-radius: 6px;
                 padding: 8px 12px; margin-top: 8px; display: none; }

/* ── Typing Indicator ──────────────────────── */
.typing-indicator { display: flex; align-items: center; gap: 8px; padding: 8px 16px;
                    color: var(--text-muted); font-size: 13px; font-style: italic; }
.typing-dots span { animation: typingBounce 1.4s infinite; display: inline-block;
                    font-size: 20px; line-height: 1; }
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-4px); opacity: 1; }
}

/* ── Bot Checkboxes (Discussion) ──────────── */
.bot-checkboxes { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.bot-checkboxes label { display: flex; align-items: center; gap: 8px; font-size: 14px;
                        color: var(--text-primary); cursor: pointer; margin-bottom: 0; }
.bot-checkboxes input[type="checkbox"] { width: auto; margin: 0; accent-color: var(--accent); }

/* ── Connection Status ────────────────────── */
.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%;
              margin-right: 6px; }
.status-dot.online { background: #66bb6a; }
.status-dot.offline { background: #e94560; }

/* ── Empty State ──────────────────────────── */
.empty-state { text-align: center; padding: 60px 20px; color: var(--text-muted); }
.empty-state h3 { font-size: 20px; margin-bottom: 8px; color: var(--text-secondary); }
.empty-state p { font-size: 14px; line-height: 1.6; }

/* ── Chat Links ───────────────────────────── */
.chat-link { color: var(--accent); text-decoration: underline; text-underline-offset: 2px;
             word-break: break-all; transition: opacity 0.2s; }
.chat-link:hover { opacity: 0.8; }

/* ── Room Memory ──────────────────────────── */
.memory-facts-list { max-height: 200px; overflow-y: auto; }
.memory-fact { display: flex; align-items: flex-start; gap: 6px; padding: 4px 0;
               font-size: 12px; border-bottom: 1px solid var(--border); }
.memory-fact:last-child { border-bottom: none; }
.memory-fact-text { flex: 1; color: var(--text-secondary); line-height: 1.4; }
.memory-fact-source { font-size: 10px; color: var(--text-muted); white-space: nowrap; }
.memory-fact-del { background: none; border: none; color: var(--text-muted);
                   cursor: pointer; font-size: 12px; padding: 0 2px; opacity: 0.5; }
.memory-fact-del:hover { opacity: 1; color: #ef4444; }

/* ── File Upload / Key Restore ────────────── */
.file-upload-area { display: flex; align-items: center; justify-content: center;
                    border: 2px dashed var(--border); border-radius: 10px; padding: 24px 16px;
                    cursor: pointer; transition: all 0.2s; text-align: center; }
.file-upload-area:hover, .file-upload-area.drag-over {
    border-color: var(--accent); background: rgba(255,152,0,0.05); }
.file-upload-label { color: var(--text-muted); font-size: 14px; pointer-events: none; }
.file-upload-label small { font-size: 12px; opacity: 0.7; }

/* ── Toast Notification ───────────────────── */
.toast { position: fixed; bottom: 20px; right: 20px; background: var(--bg-card);
         border: 1px solid var(--accent); border-radius: 8px; padding: 12px 20px;
         color: var(--text-primary); font-size: 14px; z-index: 300;
         animation: toastIn 0.3s ease-out; box-shadow: var(--shadow); }
.toast.fade-out { animation: toastOut 0.3s ease-in forwards; }
@keyframes toastIn { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toastOut { from { opacity: 1; } to { opacity: 0; transform: translateY(20px); } }

/* ── TTS Controls ─────────────────────────── */
.topbar-actions { display: flex; gap: 6px; margin-left: auto; margin-right: 8px; }
.tts-toggle { transition: all 0.2s; }
.tts-toggle.tts-active { background: var(--accent); color: #fff; }
.tts-speak-btn { background: none; border: none; cursor: pointer; font-size: 14px;
                 opacity: 0; transition: opacity 0.2s; padding: 2px 4px; margin-left: 4px;
                 vertical-align: middle; }
.msg-bubble:hover .tts-speak-btn { opacity: 0.6; }
.tts-speak-btn:hover { opacity: 1 !important; }
.tts-speak-btn.speaking { opacity: 1; animation: ttsPulse 1s infinite; }
@keyframes ttsPulse { 0%,100% { opacity: 1; } 50% { opacity: 0.4; } }

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

/* ── Shared Canvas Panel ─────────────── */
.canvas-panel {
    position: fixed; top: 0; right: 0; bottom: 0;
    width: 480px; max-width: 90vw;
    background: var(--bg-card);
    border-left: 1px solid var(--border);
    box-shadow: -4px 0 24px rgba(0,0,0,0.4);
    display: flex; flex-direction: column;
    z-index: 200;
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.canvas-panel.open { transform: translateX(0); }

.canvas-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 16px; border-bottom: 1px solid var(--border);
    background: var(--bg-sidebar);
}
.canvas-header h3 { margin: 0; font-size: 16px; }
.canvas-header-actions { display: flex; gap: 6px; align-items: center; }
.canvas-status { font-size: 11px; color: var(--text-muted); }

.canvas-toolbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 6px 16px; border-bottom: 1px solid var(--border);
    background: var(--bg-main);
}
.canvas-meta { font-size: 11px; color: var(--text-muted); }
.canvas-toolbar-actions { display: flex; gap: 4px; }

.btn-xs { padding: 2px 8px; font-size: 11px; border-radius: 4px;
    background: var(--bg-main); border: 1px solid var(--border); color: var(--text-secondary);
    cursor: pointer; }
.btn-xs:hover { background: var(--border); color: var(--text-primary); }

.canvas-editor {
    flex: 1; resize: none; border: none; outline: none;
    padding: 16px; font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 14px; line-height: 1.6;
    background: var(--bg-main); color: var(--text-primary);
    overflow-y: auto; tab-size: 4;
}
.canvas-editor::placeholder { color: var(--text-muted); opacity: 0.6; }

.canvas-footer {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 16px; border-top: 1px solid var(--border);
    background: var(--bg-sidebar);
}
.canvas-save-indicator { font-size: 11px; color: var(--text-muted); }

.canvas-history-panel {
    position: absolute; bottom: 50px; left: 0; right: 0;
    max-height: 300px; overflow-y: auto;
    background: var(--bg-card); border-top: 1px solid var(--border);
    box-shadow: 0 -4px 12px rgba(0,0,0,0.3);
}
.canvas-history-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 8px 16px; border-bottom: 1px solid var(--border);
    position: sticky; top: 0; background: var(--bg-sidebar);
}
.canvas-history-header h4 { margin: 0; font-size: 14px; }
.canvas-history-list { padding: 0; }

.canvas-history-item {
    display: flex; justify-content: space-between; align-items: center;
    padding: 8px 16px; border-bottom: 1px solid var(--border);
    cursor: pointer; font-size: 12px; transition: background 0.15s;
}
.canvas-history-item:hover { background: var(--bg-main); }
.canvas-history-item .ch-meta { color: var(--text-muted); }
.canvas-history-item .ch-who { color: var(--accent); font-weight: 600; }
.canvas-history-item .ch-ver { color: var(--text-secondary); }
.canvas-history-item .ch-type {
    display: inline-block; padding: 1px 6px; border-radius: 3px;
    font-size: 10px; font-weight: 600; text-transform: uppercase;
}
.canvas-history-item .ch-type.ai { background: #7c3aed33; color: #a78bfa; }
.canvas-history-item .ch-type.user { background: #05966933; color: #6ee7b7; }

/* Canvas open: shift chat when wide enough */
@media (min-width: 960px) {
    .chat-app.canvas-open .chat-main { margin-right: 480px; transition: margin 0.3s; }
}
@media (max-width: 959px) {
    .canvas-panel { width: 100vw; max-width: 100vw; }
}

/* Canvas update badge in chat */
.canvas-update-badge {
    display: inline-flex; align-items: center; gap: 4px;
    background: #7c3aed22; border: 1px solid #7c3aed44; border-radius: 6px;
    padding: 4px 10px; font-size: 12px; color: #a78bfa;
    cursor: pointer; transition: background 0.15s;
}
.canvas-update-badge:hover { background: #7c3aed33; }

/* Canvas toggle active state */
#canvas-toggle-btn.active {
    background: var(--accent); color: #fff;
}
