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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, sans-serif;
    background: #0d1117;
    color: #c9d1d9;
    height: 100vh;
    overflow: hidden;
}

.hidden {
    display: none !important;
}

/* Login Screen */
#login-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
    background: #0d1117;
}

.login-box {
    background: #161b22;
    border: 1px solid #30363d;
    border-radius: 12px;
    padding: 40px;
    width: 360px;
    text-align: center;
}

.login-box h1 {
    margin-bottom: 24px;
    color: #58a6ff;
    font-size: 28px;
}

.login-box input {
    width: 100%;
    padding: 12px 16px;
    margin-bottom: 12px;
    background: #0d1117;
    border: 1px solid #30363d;
    border-radius: 8px;
    color: #c9d1d9;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}

.login-box input:focus {
    border-color: #58a6ff;
}

.login-box button {
    width: 100%;
    padding: 12px;
    background: #238636;
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.2s;
}

.login-box button:hover {
    background: #2ea043;
}

.error-msg {
    color: #f85149;
    margin-top: 12px;
    font-size: 13px;
    min-height: 18px;
}

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

/* Sidebar */
#sidebar {
    width: 260px;
    background: #161b22;
    border-right: 1px solid #30363d;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px;
    border-bottom: 1px solid #30363d;
}

.sidebar-header button {
    background: #21262d;
    color: #c9d1d9;
    border: 1px solid #30363d;
    border-radius: 6px;
    padding: 8px 12px;
    cursor: pointer;
    font-size: 13px;
    transition: background 0.2s;
}

.sidebar-header button:hover {
    background: #30363d;
}

#new-chat-btn {
    font-size: 18px !important;
    font-weight: bold;
}

#conversation-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.conv-item {
    padding: 10px 12px;
    margin-bottom: 4px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: background 0.15s;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.conv-item:hover {
    background: #21262d;
}

.conv-item.active {
    background: #30363d;
}

.conv-item .conv-title {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conv-item .delete-btn {
    display: none;
    background: none;
    border: none;
    color: #f85149;
    cursor: pointer;
    font-size: 14px;
    padding: 2px 6px;
    border-radius: 4px;
}

.conv-item:hover .delete-btn {
    display: inline;
}

.conv-item .delete-btn:hover {
    background: rgba(248, 81, 73, 0.15);
}

/* Main Area */
#main-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

#messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px 20px 10px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.message {
    max-width: 75%;
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.6;
    word-wrap: break-word;
}

.message.user {
    align-self: flex-end;
    background: #1f6feb;
    color: #fff;
    border-bottom-right-radius: 4px;
}

.message.assistant {
    align-self: flex-start;
    background: #21262d;
    border: 1px solid #30363d;
    border-bottom-left-radius: 4px;
}

.message.assistant p {
    margin-bottom: 8px;
}

.message.assistant p:last-child {
    margin-bottom: 0;
}

.message.assistant pre {
    background: #0d1117;
    border: 1px solid #30363d;
    border-radius: 8px;
    padding: 12px;
    overflow-x: auto;
    margin: 8px 0;
}

.message.assistant code {
    font-family: 'SF Mono', 'Fira Code', 'Fira Mono', Menlo, Consolas, monospace;
    font-size: 13px;
}

.message.assistant :not(pre) > code {
    background: #0d1117;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 12px;
}

.message.assistant ul,
.message.assistant ol {
    padding-left: 20px;
    margin: 8px 0;
}

.message.assistant blockquote {
    border-left: 3px solid #30363d;
    padding-left: 12px;
    margin: 8px 0;
    color: #8b949e;
}

.message.assistant h1, .message.assistant h2, .message.assistant h3 {
    margin: 12px 0 6px;
    color: #58a6ff;
}

.message.assistant table {
    border-collapse: collapse;
    margin: 8px 0;
    width: 100%;
}

.message.assistant th, .message.assistant td {
    border: 1px solid #30363d;
    padding: 6px 10px;
    text-align: left;
}

.message.assistant th {
    background: #161b22;
}

/* Input Area */
#input-area {
    padding: 16px 20px;
    border-top: 1px solid #30363d;
    background: #161b22;
}

#message-form {
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

#message-input {
    flex: 1;
    padding: 12px 16px;
    background: #0d1117;
    border: 1px solid #30363d;
    border-radius: 10px;
    color: #c9d1d9;
    font-size: 14px;
    font-family: inherit;
    resize: none;
    outline: none;
    max-height: 150px;
    min-height: 44px;
    line-height: 1.4;
    transition: border-color 0.2s;
}

#message-input:focus {
    border-color: #58a6ff;
}

#send-btn {
    padding: 10px 20px;
    background: #238636;
    color: #fff;
    border: none;
    border-radius: 10px;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.2s;
    height: 44px;
}

#send-btn:hover {
    background: #2ea043;
}

#send-btn:disabled {
    background: #30363d;
    cursor: not-allowed;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
}

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

::-webkit-scrollbar-thumb {
    background: #30363d;
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: #484f58;
}

/* Typing cursor */
.typing-cursor::after {
    content: '▊';
    animation: blink 1s infinite;
}

@keyframes blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

/* Empty state */
#messages-container:empty::after {
    content: 'Start a new conversation';
    color: #484f58;
    text-align: center;
    align-self: center;
    margin-top: 40px;
    font-size: 16px;
}

/* Mobile */
@media (max-width: 768px) {
    #sidebar {
        position: fixed;
        left: -260px;
        top: 0;
        bottom: 0;
        z-index: 100;
        transition: left 0.3s;
    }

    #sidebar.open {
        left: 0;
    }

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