* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #0f0f0f;
    color: #e5e5e5;
    min-height: 100vh;
    overflow-x: hidden;
}

.container {
    display: flex;
    height: 100vh;
    width: 100%;
}

#invite-user {
    padding: 6px 10px;
    background: #2563eb;
    border: none;
    border-radius: 6px;
    color: #fff;
    cursor: pointer;
    font-size: 0.8rem;
}

#invite-user:hover {
    background: #1e40af;
}

.sidebar {
    width: 280px;
    max-width: 90%;
    background: #1c1c1c;
    padding: 16px;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    border-right: 1px solid #333;
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.3);
    transition: transform 0.3s ease;
    z-index: 20;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: #444 #252525;
}

.sidebar::-webkit-scrollbar {
    width: 8px;
}

.sidebar::-webkit-scrollbar-track {
    background: #252525;
}

.sidebar::-webkit-scrollbar-thumb {
    background: #444;
    border-radius: 4px;
}

.sidebar::-webkit-scrollbar-thumb:hover {
    background: #555;
}

.sidebar.collapsed {
    transform: translateX(-100%);
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.sidebar h2 {
    font-size: 1.3rem;
    font-weight: 600;
    color: #ffffff;
}

#sidebar-toggle, #menu-toggle {
    background: none;
    border: none;
    color: #e5e5e5;
    font-size: 1.4rem;
    cursor: pointer;
    padding: 4px;
}

.tabs {
    display: flex;
    background: #252525;
    border-radius: 8px;
    margin-bottom: 16px;
    overflow-x: auto;
    white-space: nowrap;
    z-index: 22;
    position: sticky;
    top: 0;
}

.tab-button {
    flex: 1;
    padding: 10px 8px;
    background: none;
    border: none;
    color: #d4d4d4;
    font-size: 0.85rem;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
    touch-action: manipulation;
    min-width: 80px;
    text-align: center;
}

.tab-button.active {
    background: #2563eb;
    color: #fff;
    border-radius: 8px;
}

.tab-button:hover {
    background: #333;
}

.tab-content {
    display: none;
    flex: 1;
    overflow-y: auto;
}

.tab-content.active {
    display: block;
}

.sidebar-footer {
    margin-top: auto;
    padding-top: 16px;
    position: sticky;
    bottom: 0;
    background: #1c1c1c;
    z-index: 21;
}

#new-chat, #clear-history, #save-persona, #save-settings, #logout {
    display: block;
    padding: 10px;
    background: #2563eb;
    color: #fff;
    text-align: center;
    border-radius: 6px;
    margin-top: 8px;
    font-weight: 500;
    border: none;
    cursor: pointer;
    width: 100%;
}

#new-chat:hover, #clear-history:hover, #save-persona:hover, #save-settings:hover, #logout:hover {
    background: #1e40af;
}

#clear-history, #logout {
    background: #a80019;
}

#clear-history:hover, #logout:hover {
    background: #fc0328;
}

#chat-list, #persona-list {
    overflow-y: auto;
}

.chat-item, .persona-item {
    padding: 10px;
    cursor: pointer;
    border-radius: 6px;
    margin-bottom: 8px;
    background: #252525;
    color: #e5e5e5;
    transition: background 0.2s;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-item:hover, .persona-item:hover {
    background: #333;
}

.delete-persona, .delete-chat {
    background: #a80019;
    border: none;
    color: #fff;
    padding: 4px 8px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.75rem;
}

.delete-persona:hover, .delete-chat:hover {
    background: #fc0328;
}

.persona-form {
    margin-top: 16px;
    padding: 12px;
    background: #252525;
    border-radius: 8px;
}

.persona-form h3 {
    font-size: 1.1rem;
    color: #ffffff;
    margin-bottom: 12px;
}

.persona-form .form-group {
    margin-bottom: 12px;
}

.persona-form label {
    display: block;
    font-size: 0.85rem;
    color: #d4d4d4;
    margin-bottom: 4px;
}

.persona-form input,
.persona-form textarea {
    width: 100%;
    padding: 8px;
    background: #1c1c1c;
    border: 1px solid #444;
    border-radius: 6px;
    color: #e5e5e5;
    font-size: 0.85rem;
}

.persona-form textarea {
    resize: vertical;
    min-height: 60px;
}

.persona-form button {
    width: 100%;
    padding: 8px;
    background: #2563eb;
    border: none;
    border-radius: 6px;
    color: #fff;
    cursor: pointer;
    font-weight: 500;
}

.persona-form button:hover {
    background: #1e40af;
}

#model-select {
    width: 100%;
    padding: 8px;
    background: #252525;
    border: 1px solid #444;
    border-radius: 6px;
    color: #e5e5e5;
    font-size: 0.85rem;
}

.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    width: 100%;
}

.header {
    background: #1c1c1c;
    padding: 8px 12px;
    display: flex;
    align-items: center;
    gap: 8px;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    border-bottom: 1px solid #333;
    z-index: 10;
}

.menu-toggle {
    background: none;
    border: none;
    color: #e5e5e5;
    font-size: 1.4rem;
    cursor: pointer;
}

.header h1 {
    font-size: 1.2rem;
    font-weight: 600;
    color: #ffffff;
    flex: 1;
}

.controls {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.controls select {
    padding: 6px 10px;
    background: #252525;
    border: 1px solid #444;
    border-radius: 6px;
    color: #e5e5e5;
    font-size: 0.8rem;
    min-width: 100px;
    max-width: 140px;
}

.toggle-switch {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.toggle-switch input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-switch label {
    position: relative;
    display: inline-block;
    width: 36px;
    height: 18px;
}

.slider {
    position: absolute;
    top: 0;
    left: 0;
    width: 36px;
    height: 18px;
    background: #444;
    border-radius: 18px;
    cursor: pointer;
    transition: background 0.2s ease;
}

.slider:before {
    content: '';
    position: absolute;
    width: 14px;
    height: 14px;
    background: #fff;
    border-radius: 50%;
    top: 2px;
    left: 2px;
    transition: transform 0.2s ease;
}

.toggle-switch input:checked + label .slider {
    background: #2563eb;
}

.toggle-switch input:checked + label .slider:before {
    transform: translateX(18px);
}

.ethics-label {
    font-size: 0.8rem;
    color: #e5e5e5;
}

#chat-container {
    flex: 1;
    padding: 12px;
    overflow-y: auto;
    margin-top: 50px;
    margin-bottom: 100px;
    width: 100%;
}

.message {
    padding: 12px;
    margin-bottom: 12px;
    border-radius: 8px;
    max-width: 85%;
    line-height: 1.4;
    position: relative;
}

.message.user {
    background: #2563eb;
    margin-left: auto;
    color: #fff;
}

.message.assistant {
    background: #2c2c2c;
    color: #e5e5e5;
}

.message .username {
    font-size: 0.8rem;
    font-weight: 600;
    margin-bottom: 4px;
    color: #d4d4d4;
}

.code-block {
    position: relative;
    margin: 8px 0;
    border-radius: 6px;
    overflow: hidden;
    background: #1c1c1c;
}

.code-block pre {
    background: #1c1c1c;
    padding: 12px;
    border-radius: 6px;
    overflow-x: auto;
    font-size: 0.8rem;
    color: #d4d4d4;
    margin: 0;
}

.code-block code {
    font-family: 'Fira Code', monospace;
}

.copy-button, .view-code-button {
    position: absolute;
    top: 6px;
    right: 6px;
    background: #2563eb;
    color: #fff;
    border: none;
    border-radius: 4px;
    padding: 4px 8px;
    cursor: pointer;
    font-size: 0.75rem;
}

.view-code-button {
    right: 50px;
}

.copy-button:hover, .view-code-button:hover {
    background: #1e40af;
}

.copy-button.copied {
    background: #4ade80;
}

.copy-button svg {
    width: 14px;
    height: 14px;
}

.download-code {
    display: inline-block;
    margin: 4px;
    padding: 4px 8px;
    background: #2563eb;
    color: #fff;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8rem;
    text-decoration: none;
}

.download-code:hover {
    background: #1e40af;
}

#code-editor-sidebar {
    position: fixed;
    top: 0;
    right: 0;
    width: 400px;
    max-width: 90%;
    height: 100%;
    background: #1c1c1c;
    border-left: 1px solid #333;
    box-shadow: -2px 0 10px rgba(0, 0, 0, 0.3);
    transform: translateX(100%);
    transition: transform 0.3s ease;
    z-index: 30;
    display: flex;
    flex-direction: column;
}

#code-editor-sidebar.open {
    transform: translateX(0);
}

.code-editor-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px;
    background: #252525;
    border-bottom: 1px solid #333;
}

.code-editor-header h2 {
    font-size: 1.2rem;
    color: #ffffff;
}

#close-code-editor {
    background: none;
    border: none;
    color: #e5e5e5;
    font-size: 1.2rem;
    cursor: pointer;
}

.CodeMirror {
    flex: 1;
    font-size: 0.85rem;
    background: #1c1c1c;
    color: #d4d4d4;
    border: none;
}

.input-area {
    padding: 12px;
    background: #1c1c1c;
    display: flex;
    gap: 8px;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    border-top: 1px solid #333;
    z-index: 15;
    flex-wrap: wrap;
}

#message-input {
    flex: 1;
    padding: 10px;
    background: #252525;
    border: 1px solid #444;
    border-radius: 6px;
    resize: none;
    color: #e5e5e5;
    font-size: 0.85rem;
}

#message-input:focus {
    border-color: #2563eb;
}

#send-message {
    padding: 10px 20px;
    background: #2563eb;
    border: none;
    border-radius: 6px;
    color: #fff;
    cursor: pointer;
    font-weight: 500;
}

#send-message:hover {
    background: #1e40af;
}

/* Login and Register Page Styles */
.auth-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background: #0f0f0f;
    padding: 16px;
}

.auth-box {
    background: #1c1c1c;
    padding: 24px;
    border-radius: 8px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
}

.auth-box h1 {
    font-size: 1.5rem;
    color: #ffffff;
    margin-bottom: 12px;
    text-align: center;
    font-weight: 600;
}

.auth-box h2 {
    font-size: 1.1rem;
    color: #d4d4d4;
    margin-bottom: 12px;
    text-align: center;
    font-weight: 400;
}

.auth-box h3 {
    font-size: 0.9rem;
    color: #d4d4d4;
    margin-bottom: 16px;
    text-align: center;
    font-weight: 400;
}

.auth-box .form-group {
    margin-bottom: 16px;
}

.auth-box label {
    display: block;
    font-size: 0.85rem;
    color: #d4d4d4;
    margin-bottom: 4px;
}

.auth-box input {
    width: 100%;
    padding: 8px;
    background: #252525;
    border: 1px solid #444;
    border-radius: 6px;
    color: #e5e5e5;
    font-size: 0.85rem;
}

.auth-box input:focus {
    border-color: #2563eb;
    outline: none;
}

.auth-box button {
    width: 100%;
    padding: 10px;
    background: #2563eb;
    border: none;
    border-radius: 6px;
    color: #fff;
    cursor: pointer;
    font-weight: 500;
    font-size: 0.9rem;
}

.auth-box button:hover {
    background: #1e40af;
}

.auth-box .error {
    color: #f87171;
    font-size: 0.8rem;
    margin: 8px 0;
    text-align: center;
}

.auth-box .success {
    color: #4ade80;
    font-size: 0.8rem;
    margin: 8px 0;
    text-align: center;
}

.auth-box .success a {
    color: #2563eb;
    text-decoration: none;
}

.auth-box .success a:hover {
    text-decoration: underline;
}

.auth-box p {
    text-align: center;
    margin-top: 16px;
    font-size: 0.85rem;
    color: #d4d4d4;
}

.auth-box p a {
    color: #2563eb;
    text-decoration: none;
}

.auth-box p a:hover {
    text-decoration: underline;
}

@media (max-width: 768px) {
    .sidebar {
        max-width: 100%;
        padding: 12px;
    }

    .sidebar:not(.collapsed) {
        transform: translateX(0);
    }
    
    .message .username {
        font-size: 0.75rem;
    }

    .chat-area {
        width: 100%;
    }

    .header {
        padding: 6px 10px;
    }

    .header h1 {
        font-size: 1.1rem;
    }

    .controls {
        flex-direction: column;
        align-items: stretch;
        gap: 6px;
    }

    .controls select {
        width: 100%;
        max-width: none;
        font-size: 0.8rem;
    }

    .toggle-switch {
        width: 100%;
        justify-content: space-between;
    }

    .tabs {
        flex-wrap: nowrap;
        overflow-x: auto;
    }

    .tab-button {
        font-size: 0.8rem;
        padding: 8px 6px;
        min-width: 70px;
    }

    .chat-item, .persona-item {
        padding: 8px;
        font-size: 0.8rem;
    }

    .delete-persona, .delete-chat {
        padding: 3px 6px;
        font-size: 0.7rem;
    }

    .auth-box {
        padding: 16px;
        max-width: 90%;
    }

    .auth-box h1 {
        font-size: 1.3rem;
    }

    .auth-box h2 {
        font-size: 1rem;
    }

    .auth-box h3 {
        font-size: 0.85rem;
    }

    .auth-box input {
        font-size: 0.8rem;
    }

    .auth-box button {
        padding: 8px;
        font-size: 0.8rem;
    }

    .auth-box .error, .auth-box .success {
        font-size: 0.75rem;
    }

    .auth-box p {
        font-size: 0.8rem;
    }

    #new-chat, #clear-history, #save-persona, #save-settings, #logout {
        padding: 8px;
        font-size: 0.8rem;
    }

    .persona-form {
        padding: 10px;
    }

    .persona-form h3 {
        font-size: 1rem;
    }

    .persona-form input,
    .persona-form textarea {
        font-size: 0.8rem;
        padding: 6px;
    }

    #chat-container {
        margin-top: 60px;
        margin-bottom: 120px;
        padding: 10px;
        padding-bottom: 150px;
    }

    .message {
        max-width: 90%;
        padding: 10px;
        font-size: 0.85rem;
    }

    .input-area {
        padding: 10px;
        flex-direction: column;
    }

    .view-code-button, .download-code {
        font-size: 0.75rem;
        padding: 3px 6px;
    }

    #message-input {
        width: 100%;
        font-size: 0.8rem;
    }

    #send-message {
        width: 100%;
        padding: 10px;
    }

    #code-editor-sidebar {
        width: 100%;
    }
}

@media (max-width: 480px) {
    .sidebar {
        padding: 10px;
    }

    .sidebar h2 {
        font-size: 1.2rem;
    }

    .tabs {
        gap: 4px;
    }

    .tab-button {
        font-size: 0.75rem;
        padding: 6px 4px;
        min-width: 60px;
    }
    
    .message .username {
        font-size: 0.7rem;
    }

    .chat-item, .persona-item {
        padding: 6px;
        font-size: 0.75rem;
    }

    .delete-persona, .delete-chat {
        padding: 2px 4px;
        font-size: 0.65rem;
    }

    .header {
        padding: 4px 8px;
    }

    .header h1 {
        font-size: 1rem;
    }

    .controls select {
        font-size: 0.75rem;
        padding: 4px 8px;
    }

    .toggle-switch label {
        width: 32px;
        height: 16px;
    }

    .slider {
        width: 32px;
        height: 16px;
    }

    .slider:before {
        width: 12px;
        height: 12px;
        top: 2px;
        left: 2px;
    }

    .toggle-switch input:checked + label .slider:before {
        transform: translateX(16px);
    }

    .ethics-label {
        font-size: 0.75rem;
    }

    .auth-box {
        padding: 12px;
    }

    .auth-box h1 {
        font-size: 1.2rem;
    }

    .auth-box h2 {
        font-size: 0.9rem;
    }

    .auth-box h3 {
        font-size: 0.8rem;
    }

    .auth-box input {
        font-size: 0.75rem;
        padding: 6px;
    }

    .auth-box button {
        padding: 6px;
        font-size: 0.75rem;
    }

    .auth-box .error, .auth-box .success {
        font-size: 0.7rem;
    }

    .auth-box p {
        font-size: 0.75rem;
    }

    .auth-box p a {
        font-size: 0.75rem;
    }

    #chat-container {
        margin-top: 50px;
        margin-bottom: 100px;
        padding: 8px;
        padding-bottom: 150px;
    }

    .message {
        padding: 8px;
        font-size: 0.8rem;
    }

    .input-area {
        padding: 8px;
    }

    .view-code-button, .download-code {
        font-size: 0.7rem;
        padding: 3px 6px;
    }

    #message-input {
        padding: 8px;
    }

    #send-message {
        padding: 8px;
    }
}