:root {
    --bg: #0b0b0b;
    --panel: #ffffff;
    --muted: #bdbdbd;
    --accent: #000000;
    --danger: #d64545;
    --warning: #e67e22;
    --success: #10a37f;
    --glass: rgba(255, 255, 255, 0.04);
    --radius: 10px;
    --sidebar-width: 300px;
    --user-msg-bg: #10a37f;
    --bot-msg-bg: rgba(255, 255, 255, 0.08);
    font-family: 'Inter', ui-sans-serif, system-ui, -apple-system, sans-serif;
    color-scheme: dark;
}

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

html, body {
    height: 100%;
    width: 100%;
    background: var(--bg);
    overflow: hidden;
}

body {
    display: flex;
}

.app {
    flex: 1;
    height: 100%;
    width: 100%;
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr;
    background: linear-gradient(180deg, #0c0c0c, #080808);
}

        .popup-overlay {
            display: none;
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0, 0, 0, 0.5);
            z-index: 1000;
            justify-content: center;
            align-items: center;
            padding: 20px;
        }
        
        .popup-content {
            background: var(--bg);
            border: 1px solid var(--border);
            border-radius: 12px;
            padding: 20px;
            max-width: 450px;
            width: 100%;
            max-height: 85vh;
            overflow-y: auto;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
        }
        
        .popup-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 12px;
        }
        
        .popup-title {
            font-size: 16px;
            font-weight: 700;
            color: var(--text);
        }
        
        .close-popup {
            background: none;
            border: none;
            font-size: 20px;
            cursor: pointer;
            color: var(--muted);
            padding: 4px 8px;
            line-height: 1;
            border-radius: 4px;
        }
        
        .close-popup:hover {
            background: var(--hover);
        }
        
        .popup-body {
            color: var(--text);
            line-height: 1.4;
            font-size: 13px;
        }
        
        .popup-section {
            margin-bottom: 15px;
        }
        
        .popup-section h4 {
            margin: 0 0 6px 0;
            font-size: 13px;
            color: var(--text);
        }
        
        .popup-code {
            background: var(--code-bg);
            border: 1px solid var(--border);
            border-radius: 6px;
            padding: 8px;
            font-family: 'Courier New', monospace;
            font-size: 12px;
            margin: 8px 0;
            line-height: 1.3;
            overflow-x: auto;
            white-space: pre-wrap;
            word-break: break-all;
        }
        
        .popup-list {
            margin: 8px 0;
            padding-left: 20px;
        }
        
        .popup-list li {
            margin-bottom: 4px;
            font-size: 13px;
        }
        
        .popup-footer {
            display: flex;
            justify-content: flex-end;
            gap: 8px;
            margin-top: 15px;
            padding-top: 15px;
            border-top: 1px solid var(--border);
        }
        
        .popup-btn {
            padding: 6px 12px;
            border-radius: 6px;
            border: 1px solid var(--border);
            background: var(--bg);
            color: var(--text);
            cursor: pointer;
            font-size: 13px;
            min-width: 80px;
        }
        
        .popup-btn.primary {
            background: var(--accent);
            color: white;
            border-color: var(--accent);
        }
        
        .popup-btn:hover {
            opacity: 0.9;
        }
        
        .api-btn {
            background: white;
            border: 1px solid #ddd;
            color: #333;
            cursor: pointer;
            font-size: 13px;
            margin-left: 10px;
            padding: 4px 10px;
            border-radius: 6px;
            font-weight: 500;
            transition: all 0.2s ease;
            display: inline-flex;
            align-items: center;
            gap: 4px;
        }
        
        .api-btn:hover {
            background: #f5f5f5;
            border-color: #ccc;
            transform: translateY(-1px);
            box-shadow: 0 2px 5px rgba(0,0,0,0.1);
        }
        
        .api-btn:active {
            transform: translateY(0);
        }
        
        .model-container {
            display: flex;
            align-items: center;
            gap: 8px;
        }
        
        .api-icon {
            font-size: 14px;
        }
        
        .note {
            font-size: 12px;
            color: var(--muted);
            margin-top: 8px;
            font-style: italic;
        }
        
        .popup-content::-webkit-scrollbar {
            width: 6px;
        }
        
        .popup-content::-webkit-scrollbar-track {
            background: var(--code-bg);
            border-radius: 3px;
        }
        
        .popup-content::-webkit-scrollbar-thumb {
            background: var(--border);
            border-radius: 3px;
        }

.sidebar {
    padding: 22px;
    border-right: 1px solid rgba(255, 255, 255, 0.06);
    display: flex;
    flex-direction: column;
    gap: 22px;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.03), rgba(255, 255, 255, 0.01));
    overflow-y: auto;
    height: 100vh;
    position: sticky;
    top: 0;
}

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

.logo .mark {
    width: 48px;
    height: 48px;
    border-radius: var(--radius);
    background: var(--panel);
    color: var(--accent);
    font-weight: 800;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 22px rgba(0, 0, 0, 0.6);
}

.new-chat {
    padding: 12px;
    border-radius: var(--radius);
    background: var(--success);
    border: none;
    cursor: pointer;
    font-weight: 600;
    color: white;
    transition: background-color 0.2s;
    width: 100%;
}

.new-chat:hover {
    background-color: #0d8c6d;
}

.conversations {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}

.conversation-item {
    padding: 12px 14px;
    border-radius: var(--radius);
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.05);
    color: var(--muted);
    cursor: pointer;
    text-align: left;
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: all 0.2s;
    width: 100%;
}

.conversation-item:hover {
    background: rgba(255, 255, 255, 0.05);
}

.conversation-item.active {
    background: rgba(255, 255, 255, 0.08);
    color: white;
    border-color: rgba(255, 255, 255, 0.1);
}

.conversation-item .delete-btn {
    float: right;
    color: var(--danger);
    opacity: 0;
    transition: opacity 0.2s;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 16px;
    padding: 0 5px;
}

.conversation-item:hover .delete-btn {
    opacity: 1;
}

.delete-all-btn {
    padding: 12px;
    border-radius: var(--radius);
    background: var(--danger);
    border: none;
    cursor: pointer;
    font-weight: 600;
    color: white;
    transition: background-color 0.2s;
    width: 100%;
    margin-top: 10px;
}

.delete-all-btn:hover {
    background-color: #c03939;
}

.delete-all-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.rules {
    padding: 14px;
    border-radius: var(--radius);
    background: var(--glass);
    border: 1px dashed rgba(255, 255, 255, 0.05);
    color: var(--muted);
    font-size: 14px;
    line-height: 1.5;
    margin-top: auto;
}

/* Main Content Styles */
.main {
    display: flex;
    flex-direction: column;
    height: 100vh;
    width: 100%;
}

.header {
    padding: 20px 26px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    flex-shrink: 0;
}

.messages {
    flex: 1;
    padding: 26px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 24px;
    background-image: repeating-linear-gradient(180deg, rgba(255, 255, 255, 0.008) 0 1px, transparent 1px 42px);
    min-height: 0;
}

.messages::-webkit-scrollbar {
    width: 10px;
}

.messages::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 10px;
}

.messages::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 10px;
}

.messages::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.35);
}

.message {
    display: flex;
    gap: 16px;
    max-width: 100%;
}

.message.user {
    flex-direction: row-reverse;
}

.avatar {
    width: 36px;
    height: 36px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    flex-shrink: 0;
}

.user .avatar {
    background-color: var(--user-msg-bg);
    color: white;
}

.bot .avatar {
    background-color: rgba(255, 255, 255, 0.1);
    color: white;
}

.content {
    max-width: 80%;
    padding: 16px;
    border-radius: var(--radius);
    font-size: 15px;
    line-height: 1.5;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.user .content {
    background-color: var(--user-msg-bg);
    color: white;
    border-bottom-right-radius: 4px;
}

.bot .content {
    background-color: var(--bot-msg-bg);
    color: white;
    border-bottom-left-radius: 4px;
}

.thinking {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--muted);
    font-size: 14px;
}

.dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--muted);
    animation: pulse 1.5s infinite ease-in-out;
}

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

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

@keyframes pulse {
    0%, 100% {
        opacity: 0.4;
        transform: scale(0.8);
    }
    50% {
        opacity: 1;
        transform: scale(1);
    }
}

.composer {
    padding: 16px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    display: flex;
    gap: 12px;
    align-items: center;
    background: rgba(0, 0, 0, 0.2);
    flex-shrink: 0;
}

.composer-wrapper {
    flex: 1;
    position: relative;
}

textarea {
    width: 100%;
    padding: 14px 50px 14px 14px;
    font-size: 15px;
    border-radius: var(--radius);
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(255, 255, 255, 0.05);
    color: var(--panel);
    resize: none;
    min-height: 44px;
    max-height: 200px;
    font-family: inherit;
    transition: border-color 0.2s;
}

textarea:focus {
    outline: none;
    border-color: var(--success);
}

.send-btn {
    position: absolute;
    right: 8px;
    bottom: 8px;
    padding: 8px;
    border-radius: 6px;
    background: var(--success);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s;
}

.send-btn:hover {
    background-color: #0d8c6d;
}

.send-btn[disabled] {
    opacity: 0.5;
    cursor: not-allowed;
}

.send-btn svg {
    width: 20px;
    height: 20px;
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--muted);
    text-align: center;
    padding: 40px;
}

.empty-state h2 {
    margin-bottom: 12px;
    color: white;
}

@media (max-width: 900px) {
    .app {
        grid-template-columns: 1fr;
    }

    .sidebar {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        z-index: 100;
        background: var(--bg);
        padding: 20px;
    }

    .sidebar.active {
        display: flex;
    }

    .mobile-menu-btn {
        display: block;
        background: none;
        border: none;
        color: white;
        cursor: pointer;
        font-size: 20px;
        padding: 5px;
    }

    .header {
        padding: 16px;
    }

    .content {
        max-width: 90%;
    }

    .messages {
        padding: 16px;
    }
}

.mobile-menu-btn {
    display: none;
}

.typing {
    display: inline-block;
    overflow: hidden;
    white-space: nowrap;
    border-right: 2px solid white;
    animation: typing 1s steps(20, end), blink 0.75s step-end infinite;
}

@keyframes typing {
    from { width: 0 }
    to { width: 100% }
}

@keyframes blink {
    from, to { border-color: transparent }
    50% { border-color: white }
}

.error-message {
    color: var(--danger);
    font-size: 14px;
    margin-top: 5px;
    display: flex;
    align-items: center;
    gap: 5px;
}

.error-message::before {
    content: "⚠️";
}

.sidebar::-webkit-scrollbar {
    width: 6px;
}

.sidebar::-webkit-scrollbar-track {
    background: transparent;
}

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

.sidebar::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

.conversation-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 10px;
}
