/* GreenPower Knowledge Lab — Styles */
/* Merged: rx-080.2 QA fixes + rx-080.4 markdown/citations/PDF/copy */

:root {
    --accent: #4CAF50;
    --accent-glow: rgba(76, 175, 80, 0.15);
    --bg: #0F1923;
    --surface: #1A2332;
    --surface-2: #232D3A;
    --border: #2A3544;
    --text: #E8ECF1;
    --text-dim: #8B9BB0;
    --radius: 8px;
    --sidebar-width: 280px;
    --sidebar-collapsed: 64px;
    --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

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

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    height: 100vh;
    overflow: hidden;
}

/* === Layout === */
#app {
    display: flex;
    height: 100vh;
}

/* === Sidebar === */
.sidebar {
    width: var(--sidebar-width);
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    transition: width 0.2s ease;
    overflow: hidden;
    flex-shrink: 0;
}

.sidebar[data-collapsed="true"] {
    width: var(--sidebar-collapsed);
}

.sidebar[data-collapsed="true"] .sidebar-label {
    opacity: 0;
    pointer-events: none;
    width: 0;
}

.sidebar[data-collapsed="true"] .sidebar-brand {
    display: none;
}

.sidebar[data-collapsed="true"] .sidebar-header {
    justify-content: center;
}

.sidebar[data-collapsed="true"] .section-header {
    justify-content: center;
}

.sidebar[data-collapsed="true"] .session-icon {
    width: auto;
}

.sidebar[data-collapsed="true"] .session-item {
    justify-content: center;
    padding: 10px 8px;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 12px;
    border-bottom: 1px solid var(--border);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
}

.brand-icon {
    width: 36px;
    height: 36px;
    background: var(--accent);
    color: #fff;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 14px;
    flex-shrink: 0;
}

.brand-name {
    font-weight: 600;
    font-size: 16px;
    white-space: nowrap;
}

.btn-toggle {
    background: none;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    font-size: 18px;
    padding: 4px 8px;
    border-radius: var(--radius);
    flex-shrink: 0;
}

.btn-toggle:hover { background: var(--surface-2); }

.sidebar-section {
    padding: 8px;
    flex: 0 0 auto;
}

/* Scrollable user and session lists */
#user-list {
    max-height: 35vh;
    overflow-y: auto;
}
#session-list {
    max-height: 30vh;
    overflow-y: auto;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 8px;
    color: var(--text-dim);
    font-size: 12px;
    text-transform: none;
    letter-spacing: 0.5px;
}

.sidebar-divider {
    height: 1px;
    background: var(--border);
    margin: 4px 12px;
}

.session-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background 0.15s;
    white-space: nowrap;
    overflow: hidden;
}

.session-item:hover { background: var(--surface-2); }
.session-item.active { background: var(--accent-glow); border-left: 3px solid var(--accent); }

.session-icon {
    font-size: 18px;
    flex-shrink: 0;
    width: 32px;
    text-align: center;
}

.session-shared { font-weight: 600; }

/* User list items */
.user-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 12px;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 14px;
    position: relative;
}

.user-item:hover { background: var(--surface-2); }

.user-avatar-sm {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--surface-2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    flex-shrink: 0;
    color: var(--accent);
}

.dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}

.dot.green { background: var(--accent); }
.dot.gray { background: var(--text-dim); }

/* Sidebar footer */
.sidebar-footer {
    border-top: 1px solid var(--border);
    padding: 12px;
    margin-top: auto;
}

.current-user {
    display: flex;
    align-items: center;
    gap: 10px;
}

.btn-logout {
    background: none;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    margin-left: auto;
    font-size: 16px;
    flex-shrink: 0;
}

.btn-small {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-dim);
    cursor: pointer;
    padding: 2px 8px;
    border-radius: var(--radius);
    font-size: 14px;
}

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

/* === Main Content === */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 24px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
}

.chat-header h2 {
    font-size: 18px;
    font-weight: 600;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.online-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--text-dim);
}

/* === Messages === */
.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 16px 24px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.message {
    max-width: 80%;
    padding: 10px 14px;
    border-radius: var(--radius);
    font-size: 14px;
    line-height: 1.5;
}

.message.user {
    background: var(--surface-2);
    align-self: flex-end;
}

.message.other-user {
    background: var(--surface);
    border: 1px solid var(--border);
    align-self: flex-start;
}

.message.assistant {
    background: var(--surface);
    border-left: 3px solid var(--accent);
    align-self: flex-start;
    max-width: 90%;
}

.message.system {
    background: var(--surface-2);
    border: 1px solid var(--border);
    align-self: center;
    max-width: 70%;
    text-align: center;
    font-size: 13px;
    color: var(--text-dim);
}

.message-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
    font-size: 12px;
}

.message-author {
    font-weight: 600;
    color: var(--accent);
}

.message-time {
    color: var(--text-dim);
}

.message-content {
    word-wrap: break-word;
}

/* Artifact card */
.artifact-card {
    background: var(--surface);
    border-left: 3px solid var(--accent);
    border-radius: var(--radius);
    padding: 16px;
    margin: 8px 0;
    max-width: 90%;
}

.artifact-badge {
    background: var(--accent-glow);
    color: var(--accent);
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 12px;
    text-transform: none;
    font-weight: 600;
}

.artifact-question {
    color: var(--text-dim);
    font-style: italic;
    margin: 8px 0 4px;
    font-size: 13px;
}

.artifact-answer {
    max-height: 200px;
    overflow: hidden;
    position: relative;
    margin: 4px 0;
}

/* Typing indicator */
.typing-indicator {
    padding: 4px 24px;
    font-size: 13px;
    color: var(--text-dim);
    font-style: italic;
}

/* === Input Bar === */
.input-bar {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px 24px;
    border-top: 1px solid var(--border);
    background: var(--surface);
}

.chat-input {
    flex: 1;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    padding: 10px 14px;
    font-family: var(--font);
    font-size: 14px;
    resize: none;
    max-height: 120px;
    outline: none;
}

.chat-input:focus { border-color: var(--accent); }

.btn-send {
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    width: 40px;
    height: 40px;
    cursor: pointer;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.btn-send:hover { opacity: 0.9; }

/* === Login === */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
    background: var(--bg);
}

.login-container {
    width: 100%;
    max-width: 400px;
    padding: 20px;
}

.login-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 40px 32px;
}

.login-brand {
    text-align: center;
    margin-bottom: 32px;
}

.brand-icon-lg {
    display: inline-flex;
    width: 56px;
    height: 56px;
    background: var(--accent);
    color: #fff;
    border-radius: 12px;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 20px;
    margin-bottom: 12px;
}

.login-brand h1 {
    font-size: 24px;
    font-weight: 600;
    margin-bottom: 4px;
}

.login-subtitle {
    color: var(--text-dim);
    font-size: 14px;
}

.login-step {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.login-step label {
    font-size: 13px;
    color: var(--text-dim);
    text-transform: none;
    letter-spacing: 0.5px;
}

.login-input {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    padding: 12px 14px;
    font-size: 16px;
    font-family: var(--font);
    outline: none;
}

.login-input:focus { border-color: var(--accent); }

.btn-primary {
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    padding: 12px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    font-family: var(--font);
}

.btn-primary:hover { opacity: 0.9; }

.btn-link {
    background: none;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    font-size: 14px;
    text-align: center;
}

.error-text {
    color: #ef5350;
    font-size: 13px;
    min-height: 18px;
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 20px auto;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* === Responsive === */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0; top: 0; bottom: 0;
        z-index: 100;
        transform: translateX(-100%);
        width: var(--sidebar-width);
    }
    .sidebar[data-open="true"] {
        transform: translateX(0);
    }
    .main-content { margin-left: 0; }
}

/* 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-dim); }

/* === QA-003: Chat subtitle === */
.chat-subtitle {
    font-size: 12px;
    color: var(--text-dim);
    font-weight: 400;
    margin-top: 2px;
}

/* === QA-004: Online indicator dots === */
.online-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent);
    position: absolute;
    bottom: 8px;
    left: 30px;
    border: 2px solid var(--surface);
}
.online-dot.offline { background: var(--text-dim); opacity: 0.4; }

/* === QA-005: Header buttons === */
.btn-header {
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 6px 12px;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 14px;
    transition: background 0.15s;
}
.btn-header:hover { background: var(--border); }

.header-user {
    display: flex;
    align-items: center;
    cursor: pointer;
}
.header-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
}

/* === Logo styles === */
.login-logo-img {
    height: 48px;
    width: auto;
    margin-bottom: 16px;
    border-radius: 8px;
}

.sidebar-logo {
    height: 28px;
    width: auto;
    flex-shrink: 0;
    border-radius: 4px;
}

/* === QA-008: Microphone button === */
.btn-mic {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-dim);
    border-radius: var(--radius);
    width: 40px;
    height: 40px;
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.15s;
}
.btn-mic:hover { background: var(--surface-2); color: var(--text); }
.btn-mic.recording {
    background: rgba(239,68,68,0.15);
    border-color: #ef5350;
    color: #ef5350;
    animation: mic-pulse 1.5s ease-in-out infinite;
}
@keyframes mic-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

/* === QA-013: Welcome block + suggestion chips === */
.welcome-block {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 60px 20px;
    flex: 1;
}
.welcome-title {
    font-size: 24px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text);
}
.welcome-subtitle {
    font-size: 14px;
    color: var(--text-dim);
    margin-bottom: 24px;
}
.suggestion-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    max-width: 600px;
}
.suggestion-chip {
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.15s;
    font-family: var(--font);
}
.suggestion-chip:hover {
    background: var(--accent-glow);
    border-color: var(--accent);
    color: var(--accent);
}
.suggestion-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    padding: 16px 0;
    margin-top: auto;
}

/* ═══════════════════════════════════════════════════════════════
   rx-080.4 ADDITIONS: PDF panel, citations, copy button, markdown
   ═══════════════════════════════════════════════════════════════ */

/* === PDF Viewer Panel (ported from cabinet) === */
.gp-pdf-panel {
    position: fixed;
    right: 0; top: 0; bottom: 0;
    max-height: 100vh;
    overflow: hidden;
    width: 480px;
    background: var(--surface);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1000;
    box-shadow: -8px 0 32px rgba(0,0,0,0.5);
}
.gp-pdf-panel.gp-panel-visible { transform: translateX(0); }

.gp-pdf-header {
    height: 48px;
    display: flex;
    align-items: center;
    padding: 0 12px;
    gap: 8px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    background: var(--surface-2);
}
.gp-pdf-title {
    flex: 1;
    font-size: 12px;
    font-weight: 500;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.gp-pdf-page {
    font-size: 11px;
    color: var(--text-dim);
    background: rgba(255,255,255,0.05);
    padding: 2px 8px;
    border-radius: 4px;
    border: 1px solid var(--border);
    white-space: nowrap;
}
.gp-icon-btn {
    width: 28px; height: 28px;
    border-radius: 6px;
    background: transparent;
    border: none; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    color: var(--text-dim);
    transition: all 0.15s;
    text-decoration: none;
    flex-shrink: 0;
}
.gp-icon-btn:hover { background: var(--surface-2); color: var(--text); }
.gp-icon-btn.gp-close:hover { background: rgba(239,68,68,0.15); color: #f87171; }

.gp-pdf-iframe-wrap { flex: 1; overflow: hidden; position: relative; }
.gp-pdf-iframe-wrap iframe { width: 100%; height: 100%; border: none; display: block; }
.gp-pdf-loading {
    position: absolute; inset: 0;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    gap: 12px;
    background: var(--surface);
    color: var(--text-dim); font-size: 13px;
}
.gp-spinner {
    width: 24px; height: 24px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: gp-spin 0.8s linear infinite;
}
@keyframes gp-spin { to { transform: rotate(360deg); } }

.gp-pdf-footer {
    padding: 10px 12px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}
.gp-external-btn {
    display: flex; align-items: center; justify-content: center; gap: 6px;
    background: rgba(255,255,255,0.04);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px;
    font-size: 12px;
    color: var(--text-dim);
    text-decoration: none;
    transition: all 0.15s;
}
.gp-external-btn:hover { border-color: var(--accent); color: var(--accent); }

.gp-resize-handle {
    position: absolute;
    left: -4px; top: 0; bottom: 0;
    width: 8px;
    cursor: ew-resize;
    z-index: 10;
}
.gp-resize-handle::after {
    content: '';
    position: absolute;
    left: 3px; top: 50%; transform: translateY(-50%);
    width: 2px; height: 40px;
    background: var(--border);
    border-radius: 1px;
    transition: background 0.15s;
}
.gp-resize-handle:hover::after { background: var(--accent); }

/* === Citation chips (ported from cabinet) === */
.gp-citation {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: rgba(76, 175, 80, 0.08);
    border: 1px solid rgba(76, 175, 80, 0.25);
    border-radius: 6px;
    padding: 1px 8px 1px 5px;
    font-size: 11.5px;
    color: #4ade80;
    cursor: pointer;
    transition: all 0.18s;
    text-decoration: none !important;
    font-family: 'Inter', monospace;
    vertical-align: middle;
    margin: 1px 3px;
    line-height: 1.6;
}
.gp-citation:hover {
    background: rgba(76, 175, 80, 0.15);
    border-color: rgba(76, 175, 80, 0.5);
    transform: translateY(-1px);
}
.gp-citation.gp-active {
    background: rgba(76, 175, 80, 0.20);
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(76, 175, 80, 0.15);
}
.gp-cite-page {
    opacity: 0.65;
    font-size: 10px;
    margin-left: 2px;
}

/* === Copy button (ported from cabinet rx-079) === */
.gp-msg-wrapper { position: relative; }
.btn-copy-msg {
    position: absolute;
    top: 4px; right: 4px;
    width: 28px; height: 28px;
    display: flex; align-items: center; justify-content: center;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-dim);
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s ease, color 0.2s ease, border-color 0.2s ease;
    z-index: 2;
    padding: 0;
}
.message.assistant:hover .btn-copy-msg { opacity: 1; }
.btn-copy-msg:hover { color: var(--text); border-color: var(--text-dim); }
.btn-copy-msg.copied { color: var(--accent); border-color: var(--accent); opacity: 1; }

/* === Fade-in animation for rendered messages === */
.gp-fade-in {
    animation: gp-fade-in 0.4s ease forwards;
}
@keyframes gp-fade-in {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* === Markdown content in messages === */
.message-content table { margin: 8px 0; }
.message-content table th { background: var(--surface-2); font-weight: 600; }
.message-content pre { white-space: pre-wrap; word-break: break-word; }
.message-content hr { opacity: 0.5; }
.message-content strong { color: var(--text); }
