:root {
    --bg-primary: #0f0f0f;
    --bg-secondary: #1a1a2e;
    --bg-card: #16213e;
    --bg-input: #1e1e3a;
    --text-primary: #e0e0e0;
    --text-secondary: #a0a0b0;
    --accent: #4f8cff;
    --accent-hover: #3a6fd8;
    --success: #4caf50;
    --danger: #f44336;
    --warning: #ff9800;
    --border: #2a2a4a;
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
    --radius: 8px;
    --radius-sm: 4px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.5;
}

a {
    color: var(--accent);
    text-decoration: none;
}

a:hover {
    color: var(--accent-hover);
}

/* Navbar */
.navbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1.5rem;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    height: 56px;
}

.nav-brand a {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--accent);
}

.nav-links {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.nav-links a {
    font-size: 0.875rem;
    color: var(--text-secondary);
    transition: color 0.2s;
}

.nav-links a:hover {
    color: var(--text-primary);
}

.nav-user {
    font-size: 0.875rem;
    color: var(--text-secondary);
    padding: 0.25rem 0.75rem;
    background: var(--bg-input);
    border-radius: var(--radius-sm);
}

/* Flash messages */
.flash-messages {
    position: fixed;
    top: 64px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 200;
    width: 90%;
    max-width: 600px;
}

.flash {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
    transition: opacity 0.3s;
    border: 1px solid;
}

.flash-success {
    background: rgba(76, 175, 80, 0.15);
    border-color: var(--success);
    color: var(--success);
}

.flash-error {
    background: rgba(244, 67, 54, 0.15);
    border-color: var(--danger);
    color: var(--danger);
}

/* Auth */
.auth-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 2rem;
}

.auth-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2.5rem;
    width: 100%;
    max-width: 400px;
    box-shadow: var(--shadow);
}

.auth-title {
    font-size: 1.75rem;
    font-weight: 700;
    text-align: center;
    color: var(--accent);
    margin-bottom: 0.25rem;
}

.auth-subtitle {
    text-align: center;
    color: var(--text-secondary);
    margin-bottom: 2rem;
    font-size: 0.9rem;
}

/* Forms */
.form-group {
    margin-bottom: 1.25rem;
}

.form-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 0.4rem;
}

.form-group input[type="text"],
.form-group input[type="password"],
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 0.65rem 0.85rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.9rem;
    transition: border-color 0.2s;
    outline: none;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    border-color: var(--accent);
}

.form-group input[readonly] {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Buttons */
.btn {
    display: inline-block;
    padding: 0.6rem 1.2rem;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s, opacity 0.2s;
    text-decoration: none;
    text-align: center;
}

.btn-primary {
    background: var(--accent);
    color: white;
}

.btn-primary:hover {
    background: var(--accent-hover);
    color: white;
}

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

.btn-outline {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-primary);
}

.btn-outline:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.btn-small {
    padding: 0.35rem 0.75rem;
    font-size: 0.8rem;
}

.btn-danger {
    background: var(--danger);
    color: white;
}

.btn-danger:hover {
    background: #d32f2f;
    color: white;
}

.btn-full {
    width: 100%;
}

.btn-send {
    height: 40px;
    min-width: 80px;
}

.api-key-row {
    display: flex;
    gap: 0.5rem;
}

.api-key-row input {
    flex: 1;
}

.api-key-row .btn {
    flex-shrink: 0;
}

/* Checkbox */
.checkbox-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    font-size: 0.9rem;
}

.checkbox-label input[type="checkbox"] {
    accent-color: var(--accent);
    width: 16px;
    height: 16px;
}

/* Chat Layout */
.chat-container {
    display: flex;
    height: calc(100vh - 56px);
    margin-top: 56px;
}

.chat-sidebar {
    width: 280px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    flex-shrink: 0;
}

.sidebar-header h3 {
    font-size: 1rem;
    margin-bottom: 0.5rem;
}

.model-hint {
    font-size: 0.7rem;
    color: var(--accent);
    margin-top: 0.3rem;
    font-style: italic;
}

.sidebar-header select {
    width: 100%;
    padding: 0.5rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.8rem;
    outline: none;
}

.sidebar-actions {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.sidebar-status {
    padding: 0.75rem 0;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    font-size: 0.8rem;
}

.status-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.3rem;
}

.status-label {
    color: var(--text-secondary);
}

.status-value {
    color: var(--text-primary);
    font-family: monospace;
    font-size: 0.75rem;
    max-width: 160px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.status-ok {
    color: var(--success);
}

.status-missing {
    color: var(--warning);
}

.status-warning {
    margin-top: 0.5rem;
    font-size: 0.75rem;
}

.status-warning a {
    color: var(--warning);
    text-decoration: underline;
}

.sidebar-info {
    padding: 1rem 0;
    border-top: 1px solid var(--border);
}

.sidebar-info p {
    font-size: 0.8rem;
    color: var(--text-secondary);
    line-height: 1.4;
}

.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem 2rem;
}

.message-welcome {
    text-align: center;
    padding: 4rem 2rem;
    color: var(--text-secondary);
}

.message-welcome h2 {
    font-size: 2rem;
    color: var(--accent);
    margin-bottom: 0.5rem;
}

.message {
    margin-bottom: 1.5rem;
    max-width: 800px;
    margin-left: auto;
    margin-right: auto;
    width: 100%;
}

.message-header {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 0.25rem;
}

.message-content {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    line-height: 1.6;
    font-size: 0.9rem;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.message-user .message-content {
    background: var(--accent);
    color: white;
    border-bottom-right-radius: 2px;
    margin-left: 2rem;
}

.message-assistant .message-content {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-bottom-left-radius: 2px;
    margin-right: 2rem;
}

.chat-input-area {
    padding: 1rem 2rem 1.5rem;
    border-top: 1px solid var(--border);
    background: var(--bg-primary);
}

.chat-form {
    display: flex;
    gap: 0.75rem;
    max-width: 800px;
    margin: 0 auto;
    align-items: flex-end;
}

.chat-form textarea {
    flex: 1;
    padding: 0.65rem 0.85rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.9rem;
    resize: none;
    outline: none;
    max-height: 200px;
    min-height: 40px;
    line-height: 1.5;
}

.chat-form textarea:focus {
    border-color: var(--accent);
}

.input-hint {
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 0.5rem;
    opacity: 0.7;
}

/* Admin Layout */
.admin-container {
    max-width: 1000px;
    margin: 0 auto;
    padding: 76px 1.5rem 2rem;
}

.admin-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.admin-container h1 {
    font-size: 1.5rem;
    font-weight: 700;
}

.admin-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 2rem;
}

/* Stats */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    text-align: center;
}

.stat-number {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--accent);
}

.stat-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

/* Table */
.table-container {
    overflow-x: auto;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.table th {
    text-align: left;
    padding: 0.75rem 1rem;
    font-weight: 600;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border);
    background: var(--bg-secondary);
    white-space: nowrap;
}

.table td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

.table tr:last-child td {
    border-bottom: none;
}

.table tr:hover td {
    background: rgba(79, 140, 255, 0.03);
}

.actions-cell {
    white-space: nowrap;
    display: flex;
    gap: 0.4rem;
}

.models-cell {
    max-width: 250px;
}

/* Badges */
.badge {
    display: inline-block;
    padding: 0.2rem 0.5rem;
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    font-weight: 500;
}

.badge-admin {
    background: rgba(255, 152, 0, 0.15);
    color: var(--warning);
    border: 1px solid rgba(255, 152, 0, 0.3);
}

.badge-user {
    background: rgba(79, 140, 255, 0.15);
    color: var(--accent);
    border: 1px solid rgba(79, 140, 255, 0.3);
}

.badge-active {
    background: rgba(76, 175, 80, 0.15);
    color: var(--success);
    border: 1px solid rgba(76, 175, 80, 0.3);
}

.badge-inactive {
    background: rgba(244, 67, 54, 0.15);
    color: var(--danger);
    border: 1px solid rgba(244, 67, 54, 0.3);
}

/* Model tags */
.model-tag {
    display: inline-block;
    padding: 0.15rem 0.4rem;
    margin: 0.1rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 3px;
    font-size: 0.75rem;
    font-family: monospace;
}

.models-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 0.4rem;
    max-height: 300px;
    overflow-y: auto;
    padding: 0.5rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

.model-checkbox {
    font-size: 0.8rem;
    font-family: monospace;
}

.model-name {
    font-family: monospace;
}

.model-provider-tag {
    font-size: 0.65rem;
    padding: 1px 5px;
    border-radius: 3px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    color: var(--accent);
    font-family: sans-serif;
    margin-left: 0.25rem;
}

/* Form Card */
.form-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2rem;
    max-width: 700px;
    box-shadow: var(--shadow);
}

.form-card h1 {
    margin-bottom: 0.25rem;
}

.form-card .text-muted {
    margin-bottom: 1.5rem;
}

.form-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 1.5rem;
}

.text-muted {
    color: var(--text-secondary);
    font-size: 0.85rem;
}

/* Config cards */
.config-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.config-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    transition: border-color 0.2s;
}

.config-card.config-active {
    border-color: var(--accent);
}

.config-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    margin-bottom: 0.75rem;
}

.config-card-info {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
}

.config-card-info h3 {
    font-size: 1rem;
    font-weight: 600;
}

.config-card-actions {
    display: flex;
    gap: 0.35rem;
    flex-shrink: 0;
}

.config-provider-badge {
    font-size: 0.75rem;
    padding: 0.15rem 0.5rem;
    border-radius: var(--radius-sm);
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--accent);
}

.config-key-status {
    font-size: 0.75rem;
    padding: 0.15rem 0.5rem;
    border-radius: var(--radius-sm);
    border: 1px solid;
}

.config-model-count {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.config-card-models {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-secondary);
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.6);
}

.modal-content {
    position: relative;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    width: 90%;
    max-width: 650px;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.modal-header h2 {
    font-size: 1.2rem;
}

/* Sidebar spacing */
.sidebar-header-spacer {
    height: 0.75rem;
}

/* 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(--text-secondary);
}

/* Responsive */
@media (max-width: 768px) {
    .chat-sidebar {
        width: 200px;
    }

    .chat-messages {
        padding: 1rem;
    }

    .chat-input-area {
        padding: 0.75rem 1rem;
    }

    .message-user .message-content {
        margin-left: 0;
    }

    .message-assistant .message-content {
        margin-right: 0;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }

    .models-grid {
        grid-template-columns: 1fr;
    }

    .admin-header {
        flex-direction: column;
        gap: 0.75rem;
        align-items: flex-start;
    }
}
