:root {
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --bg-dark: #111827;
    --bg-card: rgba(31, 41, 55, 0.7);
    --bg-glass: rgba(255, 255, 255, 0.03);
    --border-glass: rgba(255, 255, 255, 0.08);
    --text-main: #f9fafb;
    --text-muted: #d1d5db;
    --link-color: #93c5fd;
    --radius-lg: 16px;
    --radius-md: 10px;
}

body.light-theme {
    --bg-dark: #f3f4f6;
    --bg-card: rgba(255, 255, 255, 0.8);
    --bg-glass: rgba(0, 0, 0, 0.03);
    --border-glass: rgba(0, 0, 0, 0.1);
    --text-main: #111827;
    --text-muted: #4b5563;
    --link-color: #2563eb;
}

body.light-theme #chat-container {
    background: radial-gradient(circle at center, #ffffff 0%, #f3f4f6 100%);
}

body.light-theme .message.ai .content {
    background: rgba(255, 255, 255, 0.9);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
}

body.light-theme .input-container {
    background: white;
}

body.light-theme input,
body.light-theme select,
body.light-theme textarea {
    background: white;
    color: #111827;
    border: 1px solid rgba(0, 0, 0, 0.1);
}

body.light-theme .history-item:hover,
body.light-theme .history-item.active {
    background: white;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Inter', sans-serif;
}

body {
    background-color: var(--bg-dark);
    color: var(--text-main);
    overflow: hidden;
    height: 100vh;
}

.brand {
    font-family: 'Outfit', sans-serif;
    font-weight: 800;
    letter-spacing: -1px;
}

.brand span {
    color: var(--primary);
}

.glass {
    background: var(--bg-glass);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-glass);
}

.hidden {
    display: none !important;
}

/* Auth Views */
#auth-view {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
}

.auth-card {
    padding: 40px;
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 400px;
    text-align: center;
    animation: fadeIn 0.5s ease-out;
}

.auth-card h1 {
    font-size: 2.5rem;
    margin-bottom: 30px;
}

.auth-card h2 {
    font-size: 1.2rem;
    margin-bottom: 20px;
    color: var(--text-muted);
}

input,
select,
textarea {
    width: 100%;
    padding: 12px 16px;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-md);
    color: white;
    margin-bottom: 15px;
    outline: none;
    transition: 0.2s;
}

input:focus {
    border-color: var(--primary);
}

.primary-btn {
    width: 100%;
    padding: 12px;
    background: var(--primary);
    border: none;
    border-radius: var(--radius-md);
    color: white;
    font-weight: 600;
    cursor: pointer;
    transition: 0.3s;
}

.primary-btn:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
}

.secondary-btn {
    width: 100%;
    padding: 12px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-md);
    color: var(--text-main);
    font-weight: 500;
    cursor: pointer;
    transition: 0.3s;
    margin-top: 10px;
}

body.light-theme .secondary-btn {
    background: rgba(0, 0, 0, 0.03);
    border-color: rgba(0, 0, 0, 0.1);
}

.secondary-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: var(--primary);
    transform: translateY(-1px);
}

body.light-theme .secondary-btn:hover {
    background: rgba(0, 0, 0, 0.1);
    border-color: var(--primary);
}

.reset-link {
    margin-top: 15px;
    font-size: 0.9rem;
    color: var(--text-muted);
    cursor: pointer;
}

/* Main Layout */
#main-view {
    display: flex;
    height: 100vh;
}

#sidebar {
    width: 280px;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border-glass);
}

.sidebar-header {
    padding: 25px;
}

.sidebar-content {
    flex: 1;
    padding: 0 15px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.new-chat-btn,
.model-lab-btn {
    width: 100%;
    padding: 12px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-md);
    color: var(--text-main);
    cursor: pointer;
    margin-bottom: 10px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-weight: 500;
    transition: 0.2s;
}

.new-chat-btn:hover,
.model-lab-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--primary);
    color: var(--primary);
}

body.light-theme .new-chat-btn,
body.light-theme .model-lab-btn {
    background: rgba(0, 0, 0, 0.03);
    border-color: rgba(0, 0, 0, 0.1);
}

body.light-theme .new-chat-btn:hover,
body.light-theme .model-lab-btn:hover {
    background: white;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.history-list {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
    overflow-y: auto;
    padding-bottom: 20px;
}

.history-item {
    padding: 12px;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 0.95rem;
    color: var(--text-muted);
    transition: 0.2s;
    background: rgba(255, 255, 255, 0.02);
    display: flex;
    align-items: flex-start;
    gap: 10px;
    justify-content: space-between;
    position: relative;
    overflow: hidden;
}

.chat-title {
    flex: 1;
    display: flex;
    align-items: flex-start;
    gap: 10px;
    min-width: 0;
    line-height: 1.4;
}

.chat-title i {
    margin-top: 3px;
}

.title-text {
    flex: 1;
    overflow-wrap: break-word;
    word-break: break-word;
}

.chat-actions {
    display: flex;
    gap: 4px;
    opacity: 0;
    transition: 0.2s;
    background: transparent;
    padding-left: 5px;
}

.history-item:hover .chat-actions {
    opacity: 1;
}

.action-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    transition: 0.2s;
}

.edit-btn:hover {
    color: var(--primary);
    background: rgba(19, 16, 237, 0.1);
}

.delete-btn:hover {
    color: #ff4d4d;
    background: rgba(255, 77, 77, 0.1);
}

.rename-input {
    background: rgba(0, 0, 0, 0.3) !important;
    border: 1px solid var(--primary) !important;
    border-radius: 4px;
    color: white;
    font-size: 0.85rem;
    padding: 2px 6px !important;
    width: 100%;
    margin: 0 !important;
}

.history-item:hover,
.history-item.active {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-main);
}

#chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: radial-gradient(circle at center, #1a1c22 0%, #0f1115 100%);
}

.chat-header {
    height: 60px;
    padding: 0 25px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

#messages {
    flex: 1;
    overflow-y: auto;
    padding: 40px 20%;
}

.message {
    margin-bottom: 30px;
    line-height: 1.6;
    animation: slideUp 0.3s ease-out;
}

.message.user {
    text-align: right;
}

.message.user .content {
    background: var(--primary);
    display: inline-block;
    padding: 12px 20px;
    border-radius: 20px 20px 4px 20px;
}

.message.ai .content {
    background: rgba(255, 255, 255, 0.05);
    padding: 15px;
    border-radius: 4px 20px 20px 20px;
}

.input-area {
    padding: 20px 20%;
}

.input-container {
    position: relative;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-glass);
    border-radius: 24px;
    padding: 10px 15px;
    display: flex;
    align-items: flex-end;
}

#chat-input {
    background: transparent;
    border: none;
    margin-bottom: 0;
    resize: none;
    max-height: 200px;
    resize: none;
    max-height: 200px;
    padding: 8px;
}

#chat-input:disabled {
    cursor: wait;
    background: rgba(255, 255, 255, 0.03);
}

#chat-input:disabled::placeholder {
    color: var(--text-main);
    opacity: 1;
    font-style: italic;
    animation: textPulse 1.5s infinite ease-in-out;
}

@keyframes textPulse {
    0% {
        opacity: 0.4;
    }

    50% {
        opacity: 1;
    }

    100% {
        opacity: 0.4;
    }
}

#send-btn {
    background: var(--primary);
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    color: white;
    cursor: pointer;
    flex-shrink: 0;
}

/* User Pill */
.user-pill {
    margin: 15px;
    padding: 10px;
    border-radius: 30px;
    background: rgba(255, 255, 255, 0.05);
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    position: relative;
}

.user-menu {
    position: absolute;
    bottom: 60px;
    left: 0;
    width: 100%;
    border-radius: var(--radius-md);
    overflow: hidden;
    background: var(--bg-dark);
    border: 1px solid var(--border-glass);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
}

body.light-theme .user-menu {
    background: white;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
}

.user-menu button {
    width: 100%;
    padding: 12px 16px;
    background: transparent;
    border: none;
    color: var(--text-main);
    text-align: left;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: 0.2s;
}

.user-menu button:hover {
    background: var(--bg-glass);
    color: var(--primary);
}

body.light-theme .user-menu button:hover {
    background: rgba(0, 0, 0, 0.05);
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.scrollable::-webkit-scrollbar {
    width: 6px;
}

.scrollable::-webkit-scrollbar-thumb {
    background: var(--border-glass);
    border-radius: 3px;
}

/* Modals */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal {
    width: 90%;
    max-width: 600px;
    padding: 30px;
    border-radius: var(--radius-lg);
    background: var(--bg-dark);
    border: 1px solid var(--border-glass);
    color: var(--text-main);
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.4);
}

body.light-theme .modal {
    background: white;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.1);
}

.user-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 20px;
}

.user-table th,
.user-table td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid var(--border-glass);
}

/* User Table Action Buttons */
.user-table .action-btn {
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: 0.2s;
    border: 1px solid var(--border-glass);
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-main);
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.user-table .action-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--primary);
    transform: translateY(-1px);
}

.user-table .delete-btn:hover {
    background: rgba(255, 77, 77, 0.15);
    border-color: #ff4d4d;
    color: #ff4d4d;
}

.user-table .reset-btn:hover {
    background: rgba(147, 197, 253, 0.15);
    border-color: var(--link-color);
    color: var(--link-color);
}

/* Badges */
.badge {
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}

.badge-admin {
    background: rgba(99, 102, 241, 0.2);
    color: #818cf8;
}

.badge-user {
    background: rgba(156, 163, 175, 0.2);
    color: #9ca3af;
}

.badge-active {
    background: rgba(34, 197, 94, 0.2);
    color: #4ade80;
}

.badge-pending {
    background: rgba(245, 158, 11, 0.2);
    color: #fbbf24;
}


/* Loading Spinner */
.loading-indicator {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-muted);
    font-size: 0.9rem;
    padding: 10px 0;
}

.loading-indicator span {
    animation: textPulse 1.5s infinite ease-in-out;
}

.spinner {
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255, 255, 255, 0.1);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Markdown Styles */
.markdown-body {
    line-height: 1.6;
}

.markdown-body p {
    margin-bottom: 10px;
}

.markdown-body a {
    color: var(--link-color);
    text-decoration: underline;
    text-underline-offset: 4px;
    transition: 0.2s;
}

.markdown-body a:hover {
    color: white;
    text-decoration-color: var(--primary);
}

/* Model Lab Enhanced UI */
.lab-mode-toggle {
    display: flex;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-md);
    padding: 4px;
    margin-bottom: 20px;
    width: fit-content;
}

.lab-mode-toggle button {
    background: transparent;
    border: none;
    padding: 8px 20px;
    color: var(--text-muted);
    border-radius: 6px;
    cursor: pointer;
    transition: 0.2s;
    font-size: 0.9rem;
}

.lab-mode-toggle button.active {
    background: var(--primary);
    color: white;
}

.lab-mode-toggle button:hover:not(.active) {
    color: white;
}

.form-cols {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

#lab-system-prompt {
    font-family: inherit;
    line-height: 1.5;
    resize: vertical;
}

#lab-temp,
#lab-ctx {
    width: 100%;
}

/* Range Input Styling */
input[type=range] {
    -webkit-appearance: none;
    background: transparent;
    appearance: none;
}

input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    height: 16px;
    width: 16px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    margin-top: -6px;
}

input[type=range]::-webkit-slider-runnable-track {
    width: 100%;
    height: 4px;
    cursor: pointer;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
}

/* Model Details */
.model-details {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-left: 1rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: inline-block;
    vertical-align: middle;
    max-width: 400px;
    opacity: 0.7;
}

/* Premium Model Select Styling */
#model-select {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-glass);
    padding: 8px 36px 8px 16px;
    border-radius: 12px;
    color: var(--text-main);
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    min-width: 200px;
    margin-bottom: 0;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 256 256'%3E%3Cpath fill='%239ca3af' d='m213.66 101.66l-80 80a8 8 0 0 1-11.32 0l-80-80a8 8 0 0 1 11.32-11.32L128 164.69l74.34-74.35a8 8 0 0 1 11.32 11.32Z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 18px;
}

#model-select:hover {
    background-color: rgba(255, 255, 255, 0.08);
    border-color: var(--primary);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

#model-select:focus {
    outline: none;
    border-color: var(--primary);
    background-color: rgba(255, 255, 255, 0.1);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

#model-select option {
    background-color: #1f2937;
    color: white;
    padding: 10px;
}

body.light-theme #model-select {
    background-color: white;
    border-color: rgba(0, 0, 0, 0.1);
    color: #111827;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 256 256'%3E%3Cpath fill='%234b5563' d='m213.66 101.66l-80 80a8 8 0 0 1-11.32 0l-80-80a8 8 0 0 1 11.32-11.32L128 164.69l74.34-74.35a8 8 0 0 1 11.32 11.32Z'/%3E%3C/svg%3E");
}

body.light-theme #model-select:hover {
    background-color: #f9fafb;
    border-color: var(--primary);
}

body.light-theme #model-select option {
    background-color: white;
    color: #111827;
}