/* ─── Variables ─────────────────────────────────────────────────────────────── */
:root {
    --bg-main: #0b0f19;
    --bg-sidebar: #0d1424;
    --bg-card: rgba(15, 23, 42, 0.8);
    --bg-input: rgba(15, 23, 42, 0.95);
    --border: rgba(255,255,255,0.07);
    --border-light: rgba(255,255,255,0.12);
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --accent: #06b6d4;
    --accent-blue: #3b82f6;
    --color-low: #10b981;
    --color-medium: #3b82f6;
    --color-high: #f59e0b;
    --color-critical: #ef4444;
    --sidebar-w: 280px;
    --header-h: 72px;
    --input-h: 80px;
    --radius: 16px;
    --ease: cubic-bezier(0.4, 0, 0.2, 1);
}

/* ─── Reset ──────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body {
    background: var(--bg-main);
    color: var(--text-primary);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
}
button { cursor: pointer; border: none; background: none; color: inherit; font: inherit; }

/* ─── App Grid ───────────────────────────────────────────────────────────────── */
#app {
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr;
    height: 100vh;
    overflow: hidden;
}

/* ─── Sidebar ────────────────────────────────────────────────────────────────── */
.sidebar {
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
    transition: left 0.3s var(--ease);
}

.sidebar-header {
    padding: 24px 20px 0;
    flex-shrink: 0;
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.logo-icon { width: 40px; height: 40px; border-radius: 10px; flex-shrink: 0; }

.logo h2 {
    font-family: 'Outfit', sans-serif;
    font-size: 20px;
    font-weight: 800;
    color: var(--text-primary);
    letter-spacing: -0.3px;
}

.logo span {
    font-size: 11px;
    color: var(--text-muted);
    display: block;
}

.badge {
    display: inline-block;
    font-size: 10px;
    font-weight: 600;
    color: var(--accent);
    background: rgba(6, 182, 212, 0.08);
    border: 1px solid rgba(6, 182, 212, 0.15);
    padding: 3px 10px;
    border-radius: 20px;
    letter-spacing: 0.3px;
}

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 24px 20px;
    display: flex;
    flex-direction: column;
    gap: 28px;
}

.sidebar-content::-webkit-scrollbar { width: 4px; }
.sidebar-content::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 2px; }

.nav-section { display: flex; flex-direction: column; gap: 8px; }

.nav-section h3 {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 1.2px;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.status-item {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 12px;
    color: var(--text-secondary);
    padding: 4px 0;
}

.status-dot {
    width: 7px; height: 7px;
    border-radius: 50%;
    flex-shrink: 0;
    background: var(--text-muted);
}

.status-dot.online {
    background: var(--color-low);
    box-shadow: 0 0 8px rgba(16, 185, 129, 0.5);
}

.nav-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    transition: all 0.15s var(--ease);
    width: 100%;
    text-align: left;
}

.nav-btn svg { width: 16px; height: 16px; flex-shrink: 0; }

.nav-btn:hover {
    color: var(--text-primary);
    background: rgba(255,255,255,0.04);
}

.nav-btn.active {
    color: var(--text-primary);
    background: rgba(6, 182, 212, 0.1);
    border: 1px solid rgba(6, 182, 212, 0.18);
}

.example-btn {
    display: block;
    width: 100%;
    text-align: left;
    padding: 8px 12px;
    background: rgba(255,255,255,0.025);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-secondary);
    font-size: 12px;
    transition: all 0.15s var(--ease);
}

.example-btn:hover {
    background: rgba(255,255,255,0.06);
    color: var(--text-primary);
    border-color: var(--border-light);
    transform: translateX(2px);
}

.sidebar-footer {
    flex-shrink: 0;
    padding: 16px 20px 24px;
    border-top: 1px solid var(--border);
}

.disclaimer-mini {
    background: rgba(239,68,68,0.04);
    border: 1px dashed rgba(239,68,68,0.2);
    border-radius: 10px;
    padding: 12px;
}

.disclaimer-mini strong {
    font-size: 10px;
    color: var(--color-critical);
    display: block;
    margin-bottom: 6px;
    letter-spacing: 0.5px;
}

.disclaimer-mini p {
    font-size: 11px;
    color: var(--text-muted);
    line-height: 1.5;
}

/* ─── Main Container ─────────────────────────────────────────────────────────── */
.main-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
    background: var(--bg-main);
    background-image: radial-gradient(ellipse at 80% 0%, rgba(6,182,212,0.04) 0%, transparent 60%);
}

/* ─── Header ─────────────────────────────────────────────────────────────────── */
.main-header {
    height: var(--header-h);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    border-bottom: 1px solid var(--border);
    background: rgba(11,15,25,0.9);
    backdrop-filter: blur(16px);
    flex-shrink: 0;
    z-index: 10;
}

.header-left { display: flex; align-items: center; gap: 14px; }

.menu-toggle {
    display: none;
    padding: 8px;
    border-radius: 8px;
    color: var(--text-secondary);
    transition: all 0.15s;
}
.menu-toggle:hover { background: rgba(255,255,255,0.05); color: var(--text-primary); }
.menu-toggle svg { width: 20px; height: 20px; display: block; }

.header-title h1 {
    font-family: 'Outfit', sans-serif;
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
}

.header-title p {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}

.header-actions { display: flex; align-items: center; gap: 10px; }

.safety-indicator {
    display: flex;
    align-items: center;
    gap: 7px;
    background: rgba(16,185,129,0.06);
    border: 1px solid rgba(16,185,129,0.15);
    padding: 5px 14px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    color: var(--color-low);
    transition: all 0.3s var(--ease);
}

.safety-dot {
    width: 6px; height: 6px;
    border-radius: 50%;
    background: var(--color-low);
    box-shadow: 0 0 8px rgba(16,185,129,0.6);
}

.safety-indicator.critical {
    background: rgba(239,68,68,0.08);
    border-color: rgba(239,68,68,0.25);
    color: var(--color-critical);
    animation: criticalPulse 2s infinite;
}

.safety-indicator.critical .safety-dot {
    background: var(--color-critical);
    box-shadow: 0 0 8px rgba(239,68,68,0.6);
}

.clear-btn {
    padding: 7px;
    border-radius: 8px;
    color: var(--text-muted);
    transition: all 0.15s;
}
.clear-btn:hover { background: rgba(255,255,255,0.05); color: var(--color-critical); }
.clear-btn svg { width: 16px; height: 16px; display: block; }

/* ─── Chat Canvas ────────────────────────────────────────────────────────────── */
.chat-canvas {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

/* ─── Messages Wrapper (the scrollable area) ─────────────────────────────────── */
#messages-wrapper {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 28px 28px 8px;
    scroll-behavior: smooth;
}

#messages-wrapper::-webkit-scrollbar { width: 5px; }
#messages-wrapper::-webkit-scrollbar-track { background: transparent; }
#messages-wrapper::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.08); border-radius: 3px; }
#messages-wrapper::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.15); }

#messages {
    display: flex;
    flex-direction: column;
    gap: 20px;
    max-width: 820px;
    margin: 0 auto;
    padding-bottom: 16px;
}

/* ─── Scroll To Bottom Button (ChatGPT-style) ────────────────────────────────── */
.scroll-to-bottom {
    position: absolute;
    bottom: calc(var(--input-h) + 60px);
    left: 50%;
    transform: translateX(-50%) translateY(12px);
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    box-shadow: 0 4px 20px rgba(0,0,0,0.4);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s var(--ease), transform 0.25s var(--ease);
    z-index: 20;
    backdrop-filter: blur(8px);
}

.scroll-to-bottom.visible {
    opacity: 1;
    pointer-events: auto;
    transform: translateX(-50%) translateY(0);
}

.scroll-to-bottom:hover {
    background: rgba(6, 182, 212, 0.15);
    border-color: rgba(6, 182, 212, 0.3);
    color: var(--accent);
}

.scroll-to-bottom svg { width: 18px; height: 18px; }

.scroll-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: var(--accent-blue);
    color: white;
    font-size: 9px;
    font-weight: 700;
    border-radius: 10px;
    padding: 1px 5px;
    min-width: 16px;
    text-align: center;
    display: none;
}

.scroll-badge.show { display: block; }

/* ─── Welcome Screen ─────────────────────────────────────────────────────────── */
.welcome-screen {
    max-width: 680px;
    margin: auto;
    text-align: center;
    padding: 48px 20px 32px;
    animation: fadeIn 0.5s var(--ease);
}

.welcome-logo {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 20px;
}

.welcome-screen h2 {
    font-family: 'Outfit', sans-serif;
    font-size: 26px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 10px;
    letter-spacing: -0.3px;
}

.welcome-screen > .welcome-header > p {
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.6;
    max-width: 480px;
    margin: 0 auto 36px;
}

.suggestion-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}

.suggestion-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 18px 16px;
    cursor: pointer;
    text-align: left;
    transition: all 0.2s var(--ease);
}

.suggestion-card:hover {
    border-color: rgba(6,182,212,0.3);
    background: rgba(6,182,212,0.05);
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0,0,0,0.2);
}

.card-tag {
    font-size: 9px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    padding: 2px 8px;
    border-radius: 20px;
    display: inline-block;
    margin-bottom: 10px;
}

.card-tag.low { background: rgba(16,185,129,0.12); color: var(--color-low); }
.card-tag.medium { background: rgba(59,130,246,0.12); color: var(--color-medium); }
.card-tag.critical { background: rgba(239,68,68,0.12); color: var(--color-critical); }

.suggestion-card h4 { font-size: 13px; font-weight: 600; color: var(--text-primary); margin-bottom: 6px; }
.suggestion-card p { font-size: 11px; color: var(--text-secondary); line-height: 1.4; }

/* ─── Chat Messages ──────────────────────────────────────────────────────────── */
.message {
    display: flex;
    flex-direction: column;
    width: 100%;
    animation: msgIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.message.user { align-items: flex-end; }
.message.assistant { align-items: flex-start; }

.message-meta {
    font-size: 11px;
    color: var(--text-muted);
    margin-bottom: 6px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.assistant-avatar {
    width: 24px; height: 24px;
    background: linear-gradient(135deg, #06b6d4, #3b82f6);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: 800;
    color: white;
    flex-shrink: 0;
}

.message-bubble {
    max-width: 75%;
    padding: 14px 18px;
    border-radius: 18px;
    line-height: 1.65;
    font-size: 14px;
    word-wrap: break-word;
}

.message.user .message-bubble {
    background: linear-gradient(135deg, #0284c7 0%, #2563eb 100%);
    color: white;
    border-bottom-right-radius: 4px;
    box-shadow: 0 2px 12px rgba(37,99,235,0.2);
}

.message.assistant .message-bubble {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
    color: var(--text-primary);
    max-width: 85%;
}

/* Markdown styling inside bubbles */
.message-bubble strong { font-weight: 600; }
.message-bubble em { font-style: italic; color: var(--text-secondary); }
.message-bubble code {
    background: rgba(255,255,255,0.08);
    padding: 1px 6px;
    border-radius: 4px;
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 12px;
}

.message-bubble .msg-h3 {
    font-family: 'Outfit', sans-serif;
    font-size: 15px;
    font-weight: 700;
    color: var(--text-primary);
    margin: 12px 0 6px;
    display: block;
}
.message-bubble .msg-h3:first-child { margin-top: 0; }

.message-bubble .msg-ul {
    list-style: none;
    padding: 0;
    margin: 8px 0;
}

.message-bubble .msg-ul li {
    position: relative;
    padding-left: 16px;
    margin-bottom: 4px;
    color: var(--text-primary);
    line-height: 1.55;
}

.message-bubble .msg-ul li::before {
    content: '–';
    position: absolute;
    left: 0;
    color: var(--accent);
}

.message-bubble .msg-ol {
    list-style: none;
    padding: 0;
    margin: 8px 0;
    counter-reset: ol-counter;
}

.message-bubble .msg-ol li {
    counter-increment: ol-counter;
    position: relative;
    padding-left: 22px;
    margin-bottom: 5px;
    line-height: 1.55;
}

.message-bubble .msg-ol li::before {
    content: counter(ol-counter) '.';
    position: absolute;
    left: 0;
    color: var(--accent);
    font-weight: 600;
    font-size: 12px;
}

/* ─── Severity Bar ───────────────────────────────────────────────────────────── */
.severity-bar {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    margin-top: 12px;
    padding: 5px 12px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.severity-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.severity-bar.low { background: rgba(16,185,129,0.1); color: var(--color-low); }
.severity-bar.low .severity-dot { background: var(--color-low); box-shadow: 0 0 6px rgba(16,185,129,0.5); }
.severity-bar.medium { background: rgba(59,130,246,0.1); color: var(--color-medium); }
.severity-bar.medium .severity-dot { background: var(--color-medium); }
.severity-bar.high { background: rgba(245,158,11,0.1); color: var(--color-high); }
.severity-bar.high .severity-dot { background: var(--color-high); }
.severity-bar.critical { background: rgba(239,68,68,0.12); color: var(--color-critical); animation: criticalPulse 2s infinite; }
.severity-bar.critical .severity-dot { background: var(--color-critical); box-shadow: 0 0 8px rgba(239,68,68,0.5); }

/* ─── Report Data Card ───────────────────────────────────────────────────────── */
.report-card {
    margin-top: 14px;
    padding: 14px 16px;
    background: rgba(255,255,255,0.025);
    border: 1px solid var(--border);
    border-radius: 12px;
}

.report-label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--accent);
    margin-bottom: 10px;
}

.report-card ul {
    list-style: none;
    padding: 0;
}

.report-card ul li {
    padding: 3px 0;
    padding-left: 14px;
    position: relative;
    font-size: 13px;
    color: var(--text-secondary);
}
.report-card ul li::before { content: '·'; position: absolute; left: 0; color: var(--accent); font-weight: 700; }

/* ─── Sources Row ────────────────────────────────────────────────────────────── */
.sources-row {
    margin-top: 12px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
    font-size: 11px;
    color: var(--text-muted);
}

.source-tag {
    background: rgba(6,182,212,0.08);
    border: 1px solid rgba(6,182,212,0.15);
    color: var(--accent);
    padding: 2px 8px;
    border-radius: 20px;
    font-size: 10px;
    font-weight: 500;
}

/* ─── Disclaimer ─────────────────────────────────────────────────────────────── */
.disclaimer-card {
    margin-top: 12px;
    padding: 10px 14px;
    background: rgba(255,255,255,0.02);
    border-left: 2px solid var(--text-muted);
    border-radius: 0 8px 8px 0;
    font-size: 11.5px;
    color: var(--text-muted);
    line-height: 1.5;
}

.disclaimer-card.critical { border-left-color: var(--color-critical); background: rgba(239,68,68,0.03); color: var(--color-critical); }
.disclaimer-card.high { border-left-color: var(--color-high); }

/* ─── Message Image ──────────────────────────────────────────────────────────── */
.message-image {
    max-width: 240px;
    border-radius: 12px;
    margin-bottom: 8px;
    border: 1px solid var(--border);
}

/* ─── Input Panel ────────────────────────────────────────────────────────────── */
.input-panel {
    flex-shrink: 0;
    padding: 12px 24px 20px;
    background: rgba(11,15,25,0.95);
    backdrop-filter: blur(20px);
    border-top: 1px solid var(--border);
}

.image-preview-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(6,182,212,0.06);
    border: 1px solid rgba(6,182,212,0.15);
    border-radius: 10px;
    padding: 8px 12px;
    margin-bottom: 8px;
}

.preview-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.preview-info img {
    width: 36px; height: 36px;
    object-fit: cover;
    border-radius: 6px;
}

.preview-info .filename {
    display: block;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-primary);
}

.preview-info .filesize {
    font-size: 11px;
    color: var(--text-muted);
}

.remove-preview-btn {
    padding: 4px;
    color: var(--text-muted);
    border-radius: 4px;
}
.remove-preview-btn:hover { color: var(--color-critical); }
.remove-preview-btn svg { width: 16px; height: 16px; display: block; }

.input-box-container {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--bg-input);
    border: 1px solid var(--border-light);
    border-radius: 14px;
    padding: 8px 8px 8px 12px;
    transition: border-color 0.2s;
}

.input-box-container:focus-within {
    border-color: rgba(6,182,212,0.35);
}

.upload-btn {
    color: var(--text-muted);
    padding: 6px;
    border-radius: 8px;
    flex-shrink: 0;
    transition: all 0.15s;
    margin-bottom: 2px;
}
.upload-btn:hover { color: var(--accent); background: rgba(6,182,212,0.1); }
.upload-btn svg { width: 18px; height: 18px; display: block; }

textarea#user-input {
    flex: 1;
    background: none;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-family: 'Inter', sans-serif;
    font-size: 14px;
    line-height: 1.5;
    resize: none;
    max-height: 140px;
    padding: 5px 0;
}

textarea#user-input::placeholder { color: var(--text-muted); }

.send-btn {
    width: 36px; height: 36px;
    border-radius: 10px;
    background: linear-gradient(135deg, #06b6d4, #3b82f6);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.2s var(--ease);
}

.send-btn:not(:disabled):hover { transform: scale(1.06); box-shadow: 0 4px 16px rgba(6,182,212,0.3); }
.send-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.send-btn svg { width: 17px; height: 17px; }

/* ─── Typing Indicator ───────────────────────────────────────────────────────── */
.typing-indicator-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 4px 0;
}

.typing-avatar {
    width: 24px; height: 24px;
    background: linear-gradient(135deg, #06b6d4, #3b82f6);
    border-radius: 8px;
    font-size: 10px;
    font-weight: 800;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.typing-dots-wrap { display: flex; flex-direction: column; gap: 2px; }

.typing-dots-wrap span {
    font-size: 11px;
    color: var(--text-muted);
}

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

.typing-dot {
    width: 5px; height: 5px;
    background: var(--text-muted);
    border-radius: 50%;
    animation: bounce 1.4s infinite;
}

.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

/* ─── Mobile Overlay ─────────────────────────────────────────────────────────── */
.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(4px);
    z-index: 99;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}

.sidebar-overlay.show { opacity: 1; pointer-events: auto; }

/* ─── Animations ─────────────────────────────────────────────────────────────── */
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes msgIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes bounce { 0%, 60%, 100% { transform: translateY(0); } 30% { transform: translateY(-5px); } }
@keyframes criticalPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(239,68,68,0.15); }
    50% { box-shadow: 0 0 0 4px rgba(239,68,68,0.08); }
}

/* ─── Responsive ─────────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
    #app { grid-template-columns: 1fr; }
    .menu-toggle { display: flex; }

    .sidebar {
        position: fixed;
        top: 0; left: -300px;
        width: 280px;
        height: 100vh;
        z-index: 100;
    }

    .sidebar.open { left: 0; }

    #messages-wrapper { padding: 20px 16px 8px; }
    .input-panel { padding: 10px 16px 16px; }
    .suggestion-grid { grid-template-columns: 1fr; }
    .message-bubble { max-width: 95%; }
    .message.assistant .message-bubble { max-width: 95%; }
}
