/* Cyberpunk Theme - Chatbot */

:root {
    --cyber-primary: #34d399;    /* soft emerald   */
    --cyber-secondary: #f472b6; /* muted pink      */
    --cyber-accent: #38bdf8;    /* sky blue        */
    --cyber-yellow: #fbbf24;    /* warm amber      */
    --cyber-purple: #a78bfa;    /* lavender        */
    --cyber-dark: #0f172a;      /* dark slate      */
    --cyber-darker: #080e1c;    /* deepest slate   */
    --cyber-grid: #1e293b;      /* grid lines      */
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Rajdhani', sans-serif;
    background: linear-gradient(135deg, var(--cyber-darker) 0%, var(--cyber-dark) 100%);
    min-height: 100vh;
    position: relative;
    overflow: hidden;
}

/* Animated background grid */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: 
        linear-gradient(var(--cyber-grid) 1px, transparent 1px),
        linear-gradient(90deg, var(--cyber-grid) 1px, transparent 1px);
    background-size: 50px 50px;
    opacity: 0.3;
    animation: gridMove 20s linear infinite;
    pointer-events: none;
    z-index: 0;
}

@keyframes gridMove {
    0% { transform: translate(0, 0); }
    100% { transform: translate(50px, 50px); }
}

/* Chatbot Icon — hidden (always-open mode) */
#chatbot-icon { display: none; }

.icon-text {
    font-family: 'Orbitron', sans-serif;
    font-size: 28px;
    font-weight: 900;
    color: var(--cyber-darker);
    text-shadow: 0 0 10px rgba(255, 255, 255, 0.5);
}

@keyframes pulse {
    0%, 100% {
        box-shadow: 
            0 0 12px rgba(52, 211, 153, 0.3),
            0 0 24px rgba(56, 189, 248, 0.18);
    }
    50% {
        box-shadow: 
            0 0 20px rgba(52, 211, 153, 0.5),
            0 0 38px rgba(56, 189, 248, 0.28);
    }
}

/* Wrapper: true full-screen, sidebar left + chat right */
#chatbot-wrapper {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: row;
    width: 100vw;
    height: 100vh;
    z-index: 1000;
    animation: slideIn 0.4s ease-out;
}

#chatbot-container {
    flex: 1;
    height: 100vh;
    background: rgba(8, 14, 28, 0.97);
    border-radius: 0;
    border: none;
    box-shadow: none;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#chatbot-container::before {
    content: '';
    position: absolute;
    top: -2px;
    left: -2px;
    right: -2px;
    bottom: -2px;
    background: linear-gradient(45deg, var(--cyber-primary), var(--cyber-accent), var(--cyber-secondary), var(--cyber-purple));
    border-radius: 15px;
    z-index: -1;
    opacity: 0;
    transition: opacity 0.3s;
}

#chatbot-container:hover::before {
    opacity: 0.3;
    animation: borderGlow 2s linear infinite;
}

@keyframes borderGlow {
    0%, 100% { opacity: 0.3; }
    50% { opacity: 0.6; }
}

@keyframes slideIn {
    from {
        transform: translateY(20px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

#chatbot-wrapper.hidden {
    visibility: hidden;
    pointer-events: none;
    opacity: 0;
}

/* Chatbot Header */
#chatbot-header {
    background: linear-gradient(135deg, rgba(52, 211, 153, 0.06), rgba(56, 189, 248, 0.06));
    padding: 18px 28px;
    display: flex;
    justify-content: center;
    align-items: center;
    border-bottom: 1px solid rgba(52, 211, 153, 0.25);
    position: relative;
}

#chatbot-header::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    width: 100%;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--cyber-accent), transparent);
    animation: scanline 3s linear infinite;
}

@keyframes scanline {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

#chatbot-header h2 {
    font-family: 'Orbitron', sans-serif;
    font-size: 22px;
    font-weight: 700;
    color: var(--cyber-primary);
    text-transform: uppercase;
    letter-spacing: 3px;
    text-shadow: 
        0 0 6px rgba(52, 211, 153, 0.5),
        0 0 14px rgba(56, 189, 248, 0.3);
}

.glitch {
    position: relative;
}

.glitch::before,
.glitch::after {
    content: attr(data-text);
    position: absolute;
    top: 0;
    left: 0;
    opacity: 0.8;
}

.glitch::before {
    animation: glitch-1 0.3s infinite;
    color: var(--cyber-accent);
    z-index: -1;
}

.glitch::after {
    animation: glitch-2 0.3s infinite;
    color: var(--cyber-secondary);
    z-index: -2;
}

@keyframes glitch-1 {
    0%, 100% {
        transform: translate(0);
    }
    33% {
        transform: translate(-2px, 2px);
    }
    66% {
        transform: translate(2px, -2px);
    }
}

@keyframes glitch-2 {
    0%, 100% {
        transform: translate(0);
    }
    33% {
        transform: translate(2px, -2px);
    }
    66% {
        transform: translate(-2px, 2px);
    }
}

#close-chatbot { display: none; }

/* Chatbot Body */
#chatbot-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: rgba(5, 7, 20, 0.5);
}

#chatbot-body::-webkit-scrollbar {
    width: 8px;
}

#chatbot-body::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 4px;
}

#chatbot-body::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, var(--cyber-primary), var(--cyber-accent));
    border-radius: 4px;
    box-shadow: 0 0 10px var(--cyber-primary);
}

#chatbot-body::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(180deg, var(--cyber-accent), var(--cyber-primary));
}

#chatbot-messages {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

/* Message Styles */
.message {
    padding: 12px 16px;
    border-radius: 10px;
    max-width: 80%;
    animation: messageSlide 0.3s ease-out;
    position: relative;
    font-size: 15px;
    line-height: 1.5;
}

@keyframes messageSlide {
    from {
        transform: translateX(-20px);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.user-message {
    align-self: flex-end;
    background: linear-gradient(135deg, rgba(52, 211, 153, 0.85), rgba(56, 189, 248, 0.85));
    color: #0a1628;
    border: 1px solid rgba(56, 189, 248, 0.5);
    box-shadow: 0 0 10px rgba(52, 211, 153, 0.2);
    font-weight: 600;
}

.bot-message {
    align-self: flex-start;
    background: rgba(30, 41, 59, 0.75);
    color: #cbd5e1;
    border: 1px solid rgba(167, 139, 250, 0.3);
    box-shadow: 0 0 10px rgba(167, 139, 250, 0.1);
}

.bot-message::before {
    content: '◢';
    position: absolute;
    left: -8px;
    top: 10px;
    color: var(--cyber-purple);
    opacity: 0.7;
    font-size: 14px;
}

/* ── Markdown rendering inside bot messages ── */
.bot-message p {
    margin: 0 0 0.65em;
    line-height: 1.65;
}
.bot-message p:last-child { margin-bottom: 0; }

.bot-message h1, .bot-message h2, .bot-message h3,
.bot-message h4, .bot-message h5, .bot-message h6 {
    color: var(--cyber-primary);
    font-family: 'Orbitron', sans-serif;
    font-weight: 700;
    margin: 0.9em 0 0.4em;
    line-height: 1.3;
}
.bot-message h1 { font-size: 1.15em; }
.bot-message h2 { font-size: 1.05em; }
.bot-message h3, .bot-message h4,
.bot-message h5, .bot-message h6 { font-size: 0.95em; }

.bot-message ul, .bot-message ol {
    padding-left: 1.4em;
    margin: 0.4em 0 0.65em;
}
.bot-message li { margin-bottom: 0.3em; line-height: 1.55; }

.bot-message code {
    background: rgba(15, 23, 42, 0.9);
    color: var(--cyber-accent);
    padding: 0.15em 0.45em;
    border-radius: 4px;
    font-family: 'Consolas', 'Fira Code', monospace;
    font-size: 0.88em;
    border: 1px solid rgba(56, 189, 248, 0.25);
}

.bot-message pre {
    background: rgba(8, 14, 28, 0.95);
    border: 1px solid rgba(56, 189, 248, 0.2);
    border-radius: 8px;
    padding: 12px 14px;
    overflow-x: auto;
    margin: 0.6em 0;
}
.bot-message pre code {
    background: none;
    border: none;
    padding: 0;
    font-size: 0.87em;
    color: #93c5fd;
}

.bot-message blockquote {
    border-left: 3px solid var(--cyber-purple);
    margin: 0.5em 0;
    padding: 0.3em 0 0.3em 0.9em;
    color: #94a3b8;
    font-style: italic;
}

.bot-message hr {
    border: none;
    border-top: 1px solid rgba(167, 139, 250, 0.25);
    margin: 0.7em 0;
}

.bot-message strong { color: #e2e8f0; font-weight: 700; }
.bot-message em    { color: #a5b4fc; font-style: italic; }

.bot-message a {
    color: var(--cyber-accent);
    text-decoration: underline;
    text-underline-offset: 3px;
}
.bot-message a:hover { color: var(--cyber-primary); }

.bot-message table {
    border-collapse: collapse;
    width: 100%;
    margin: 0.6em 0;
    font-size: 0.9em;
}
.bot-message th {
    background: rgba(52, 211, 153, 0.12);
    color: var(--cyber-primary);
    font-weight: 700;
    padding: 6px 10px;
    border: 1px solid rgba(52, 211, 153, 0.2);
}
.bot-message td {
    padding: 5px 10px;
    border: 1px solid rgba(167, 139, 250, 0.15);
    color: #cbd5e1;
}

/* Input Container */
#chatbot-input-container {
    padding: 20px;
    background: rgba(10, 14, 39, 0.8);
    border-top: 2px solid var(--cyber-accent);
    display: flex;
    gap: 10px;
}

#chatbot-input {
    flex: 1;
    padding: 12px 16px;
    background: rgba(0, 0, 0, 0.5);
    border: 2px solid var(--cyber-accent);
    border-radius: 8px;
    color: var(--cyber-primary);
    font-family: 'Rajdhani', sans-serif;
    font-size: 16px;
    font-weight: 500;
    outline: none;
    transition: all 0.3s ease;
}

#chatbot-input::placeholder {
    color: rgba(0, 255, 159, 0.4);
    font-weight: 300;
    letter-spacing: 1px;
}

#chatbot-input:focus {
    border-color: var(--cyber-primary);
    box-shadow: 
        0 0 20px rgba(0, 255, 159, 0.3),
        inset 0 0 10px rgba(0, 255, 159, 0.1);
    background: rgba(0, 0, 0, 0.7);
}

#send-message {
    padding: 12px 24px;
    background: linear-gradient(135deg, var(--cyber-accent), var(--cyber-primary));
    border: 2px solid var(--cyber-accent);
    border-radius: 8px;
    color: var(--cyber-darker);
    font-family: 'Orbitron', sans-serif;
    font-size: 14px;
    font-weight: 700;
    letter-spacing: 2px;
    cursor: pointer;
    transition: all 0.3s ease;
    text-transform: uppercase;
    position: relative;
    overflow: hidden;
}

#send-message::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

#send-message:hover::before {
    width: 300px;
    height: 300px;
}

#send-message:hover {
    box-shadow: 
        0 0 25px var(--cyber-accent),
        0 0 50px rgba(0, 217, 255, 0.3);
    transform: translateY(-2px);
}

#send-message:active {
    transform: translateY(0);
}

/* Responsive Design */
@media (max-width: 768px) {
    #chatbot-sidebar {
        display: none;
    }
    #chatbot-container {
        width: 100vw;
    }
}

/* Loading Animation */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 12px;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: var(--cyber-primary);
    border-radius: 50%;
    animation: typing 1.4s infinite;
    box-shadow: 0 0 10px var(--cyber-primary);
}

.typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.7;
    }
    30% {
        transform: translateY(-10px);
        opacity: 1;
    }
}

/* ── Conversation Sidebar ──────────────────────────────────────────────── */
#chatbot-sidebar {
    width: 280px;
    min-width: 220px;
    height: 100vh;
    background: rgba(4, 9, 20, 0.98);
    border-radius: 0;
    border: none;
    border-right: 1px solid rgba(52, 211, 153, 0.2);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    flex-shrink: 0;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 14px 13px;
    border-bottom: 1px solid rgba(52, 211, 153, 0.18);
    background: rgba(52, 211, 153, 0.04);
    flex-shrink: 0;
}

.sidebar-title {
    font-family: 'Orbitron', sans-serif;
    font-size: 11px;
    font-weight: 700;
    color: var(--cyber-primary);
    letter-spacing: 2px;
    text-transform: uppercase;
    opacity: 0.85;
}

#new-chat-btn {
    background: rgba(52, 211, 153, 0.1);
    border: 1px solid rgba(52, 211, 153, 0.3);
    color: var(--cyber-primary);
    width: 28px;
    height: 28px;
    border-radius: 7px;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 0 1px;
}

#new-chat-btn:hover {
    background: rgba(52, 211, 153, 0.22);
    box-shadow: 0 0 10px rgba(52, 211, 153, 0.25);
    transform: scale(1.08);
}

#sidebar-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px 6px;
}

#sidebar-list::-webkit-scrollbar { width: 3px; }
#sidebar-list::-webkit-scrollbar-track { background: transparent; }
#sidebar-list::-webkit-scrollbar-thumb {
    background: rgba(52, 211, 153, 0.2);
    border-radius: 2px;
}

.sidebar-empty {
    padding: 24px 12px;
    color: rgba(148, 163, 184, 0.4);
    font-size: 12px;
    font-family: 'Rajdhani', sans-serif;
    text-align: center;
    line-height: 1.6;
}

.sidebar-item {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 8px 9px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.18s ease, border-color 0.18s ease;
    margin-bottom: 3px;
    border: 1px solid transparent;
}

.sidebar-item:hover {
    background: rgba(52, 211, 153, 0.07);
    border-color: rgba(52, 211, 153, 0.15);
}

.sidebar-item.active {
    background: rgba(52, 211, 153, 0.11);
    border-color: rgba(52, 211, 153, 0.28);
}

.sidebar-item-title {
    flex: 1;
    font-family: 'Rajdhani', sans-serif;
    font-size: 13px;
    color: #7a8fa6;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.3;
    cursor: pointer;
    transition: color 0.15s;
}

.sidebar-item:hover .sidebar-item-title {
    color: #94a3b8;
}

.sidebar-item.active .sidebar-item-title {
    color: var(--cyber-primary);
}

.sidebar-item-delete {
    background: transparent;
    border: none;
    color: rgba(148, 163, 184, 0.35);
    font-size: 17px;
    line-height: 1;
    cursor: pointer;
    padding: 2px 5px;
    border-radius: 5px;
    flex-shrink: 0;
    transition: all 0.18s;
    opacity: 0;
}

.sidebar-item:hover .sidebar-item-delete {
    opacity: 1;
}

.sidebar-item-delete:hover {
    color: var(--cyber-secondary);
    background: rgba(244, 114, 182, 0.12);
}

.sidebar-rename-input {
    flex: 1;
    font-family: 'Rajdhani', sans-serif;
    font-size: 13px;
    color: var(--cyber-primary);
    background: rgba(52, 211, 153, 0.07);
    border: 1px solid rgba(52, 211, 153, 0.4);
    border-radius: 4px;
    padding: 1px 5px;
    outline: none;
    min-width: 0;
    caret-color: var(--cyber-primary);
}