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

:root {
    --bg-primary: #0a0000;
    --bg-secondary: #110505;
    --bg-tertiary: #1a0808;
    --bg-hover: #220a0a;
    --border: rgba(255, 40, 40, 0.12);
    --border-hover: rgba(255, 40, 40, 0.25);
    --red-primary: #ff2222;
    --red-light: #ff4444;
    --red-dark: #cc0000;
    --red-glow: rgba(255, 30, 30, 0.15);
    --red-subtle: rgba(255, 30, 30, 0.08);
    --text-primary: #f0e0e0;
    --text-secondary: #998888;
    --text-muted: #664444;
}

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

.app {
    display: flex;
    height: 100vh;
    position: relative;
}

/* ═══════ SIDEBAR ═══════ */
.sidebar {
    width: 280px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: transform 0.3s ease;
    z-index: 100;
}

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

.logo {
    font-size: 22px;
    font-weight: 800;
    background: linear-gradient(135deg, #ff4444, #ff6666);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.btn-new-chat {
    width: 36px;
    height: 36px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--red-light);
    border-radius: 10px;
    cursor: pointer;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.btn-new-chat:hover {
    background: var(--red-subtle);
    border-color: var(--border-hover);
    transform: scale(1.05);
}

/* ═══════ SIDEBAR TOGGLE (Mobile) ═══════ */
.sidebar-toggle {
    display: none;
    position: fixed;
    top: 14px;
    left: 14px;
    z-index: 200;
    width: 40px;
    height: 40px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    color: var(--red-light);
    border-radius: 10px;
    font-size: 20px;
    cursor: pointer;
    align-items: center;
    justify-content: center;
}

/* ═══════ CONVERSATIONS LIST ═══════ */
.conversations-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.conv-loading {
    text-align: center;
    color: var(--text-muted);
    padding: 20px;
    font-size: 13px;
}

.conv-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.15s;
    margin-bottom: 2px;
    border: 1px solid transparent;
}

.conv-item:hover {
    background: var(--bg-hover);
}

.conv-item.active {
    background: var(--red-subtle);
    border-color: var(--border-hover);
}

.conv-item-title {
    font-size: 13px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    margin-right: 8px;
}

.conv-item.active .conv-item-title {
    color: var(--text-primary);
}

.conv-item-delete {
    opacity: 0;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 14px;
    padding: 4px 6px;
    border-radius: 6px;
    transition: all 0.15s;
    flex-shrink: 0;
}

.conv-item:hover .conv-item-delete {
    opacity: 1;
}

.conv-item-delete:hover {
    color: var(--red-light);
    background: rgba(255, 0, 0, 0.1);
}

/* ═══════ PLUGIN SECTION ═══════ */
.plugin-section {
    padding: 16px;
    border-top: 1px solid var(--border);
    text-align: center;
}

.plugin-section h4 {
    color: var(--text-secondary);
    font-size: 11px;
    font-weight: 600;
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.plugin-code {
    font-size: 26px;
    font-weight: 800;
    color: var(--red-light);
    letter-spacing: 4px;
    font-family: 'Courier New', monospace;
    padding: 10px;
    background: var(--bg-primary);
    border-radius: 10px;
    border: 1px dashed var(--border);
    margin-bottom: 10px;
    user-select: all;
}

.btn-plugin {
    width: 100%;
    padding: 10px;
    background: linear-gradient(135deg, var(--red-dark), var(--red-primary));
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-plugin:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 15px rgba(255, 0, 0, 0.3);
}

.btn-plugin:active {
    transform: translateY(0);
}

.plugin-status {
    margin-top: 8px;
    font-size: 12px;
    font-weight: 600;
}

.plugin-status.disconnected { color: #ff4444; }
.plugin-status.connected { color: #44ff44; }

/* ═══════ USER PROFILE ═══════ */
.user-profile {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    border-top: 1px solid var(--border);
    background: var(--bg-tertiary);
}

.user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 2px solid var(--border-hover);
    object-fit: cover;
}

.user-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.user-display-name {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-username {
    font-size: 11px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.btn-logout {
    width: 32px;
    height: 32px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-muted);
    border-radius: 8px;
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.btn-logout:hover {
    color: var(--red-light);
    border-color: var(--red-light);
    background: rgba(255, 0, 0, 0.1);
}

/* ═══════ CHAT AREA ═══════ */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-primary);
    min-width: 0;
}

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

.chat-header h2 {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-header-status {
    font-size: 12px;
    color: var(--text-muted);
    flex-shrink: 0;
}

/* ═══════ WELCOME SCREEN ═══════ */
.welcome-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    padding: 40px 20px;
}

.welcome-icon {
    font-size: 80px;
    margin-bottom: 16px;
    animation: float 3s ease-in-out infinite;
}

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

.welcome-screen h1 {
    font-size: 32px;
    font-weight: 800;
    background: linear-gradient(135deg, #ff4444, #ff8888);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 8px;
}

.welcome-screen p {
    color: var(--text-secondary);
    margin-bottom: 30px;
    font-size: 15px;
}

.welcome-examples {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    max-width: 500px;
    width: 100%;
}

.example-card {
    padding: 16px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 14px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-secondary);
    text-align: left;
    transition: all 0.2s;
    line-height: 1.5;
}

.example-card:hover {
    border-color: var(--border-hover);
    background: var(--bg-hover);
    color: var(--text-primary);
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(255, 0, 0, 0.1);
}

/* ═══════ MESSAGES ═══════ */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.message {
    max-width: 80%;
    padding: 16px 20px;
    border-radius: 18px;
    line-height: 1.6;
    font-size: 14px;
    animation: msgIn 0.3s ease;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

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

.message.user {
    align-self: flex-end;
    background: linear-gradient(135deg, var(--red-dark), var(--red-primary));
    color: white;
    border-bottom-right-radius: 6px;
    box-shadow: 0 2px 15px rgba(255, 0, 0, 0.2);
}

.message.bot {
    align-self: flex-start;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-bottom-left-radius: 6px;
}

.message .action-badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 800;
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.badge-create {
    background: rgba(0, 200, 0, 0.15);
    color: #44ff44;
    border: 1px solid rgba(0, 200, 0, 0.3);
}

.badge-edit {
    background: rgba(255, 170, 0, 0.15);
    color: #ffaa00;
    border: 1px solid rgba(255, 170, 0, 0.3);
}

.badge-delete {
    background: rgba(255, 50, 50, 0.15);
    color: #ff4444;
    border: 1px solid rgba(255, 50, 50, 0.3);
}

.message pre {
    background: #050000;
    padding: 14px;
    border-radius: 10px;
    margin-top: 12px;
    overflow-x: auto;
    font-size: 12px;
    color: #ff8888;
    border: 1px solid var(--border);
    font-family: 'Cascadia Code', 'Fira Code', 'Courier New', monospace;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-all;
}

.message .script-info {
    font-size: 13px;
    margin-top: 6px;
    color: var(--text-secondary);
    line-height: 1.8;
}

.message .script-info b {
    color: var(--text-primary);
}

.message .plugin-badge {
    display: inline-block;
    margin-top: 10px;
    padding: 5px 12px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 600;
}

.plugin-badge.sent {
    background: rgba(0, 255, 0, 0.1);
    color: #44ff44;
    border: 1px solid rgba(0, 255, 0, 0.2);
}

.plugin-badge.not-sent {
    background: rgba(255, 0, 0, 0.1);
    color: #ff4444;
    border: 1px solid rgba(255, 0, 0, 0.2);
}

/* ═══════ INPUT AREA ═══════ */
.chat-input-area {
    padding: 16px 24px 20px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.input-wrapper {
    display: flex;
    gap: 10px;
    align-items: center;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 4px 4px 4px 18px;
    transition: all 0.2s;
}

.input-wrapper:focus-within {
    border-color: var(--red-primary);
    box-shadow: 0 0 20px rgba(255, 0, 0, 0.1);
}

#chat-input {
    flex: 1;
    padding: 12px 0;
    border: none;
    background: transparent;
    color: var(--text-primary);
    font-size: 14px;
    outline: none;
    font-family: inherit;
    min-width: 0;
}

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

.btn-send {
    width: 42px;
    height: 42px;
    background: linear-gradient(135deg, var(--red-dark), var(--red-primary));
    color: white;
    border: none;
    border-radius: 11px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.btn-send:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 15px rgba(255, 0, 0, 0.3);
}

.btn-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* ═══════ THINKING ANIMATION ═══════ */
.thinking-dots {
    display: flex;
    gap: 4px;
    padding: 8px 0;
}

.thinking-dots span {
    width: 8px;
    height: 8px;
    background: var(--red-light);
    border-radius: 50%;
    animation: bounce 1.4s ease-in-out infinite;
}

.thinking-dots span:nth-child(2) { animation-delay: 0.2s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
    0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
    40% { transform: translateY(-8px); opacity: 1; }
}

/* ═══════ 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(--border-hover); }

/* ═══════ RESPONSIVE ═══════ */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
        box-shadow: 10px 0 40px rgba(0, 0, 0, 0.8);
    }

    .sidebar-toggle {
        display: flex;
    }

    .chat-header {
        padding-left: 60px;
    }

    .welcome-examples {
        grid-template-columns: 1fr;
    }

    .welcome-screen h1 {
        font-size: 24px;
    }

    .welcome-icon {
        font-size: 56px;
    }

    .message {
        max-width: 90%;
    }
}