:root {
    color-scheme: light;
    font-family: "Avenir Next", "Inter", "SF Pro Text", "SF Pro Display", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: #f5f6f8;
    color: #111827;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
}

.layout {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 220px;
    background: #0f172a;
    color: #e2e8f0;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.brand {
    display: flex;
    align-items: center;
    justify-content: center;
}

.brand-logo {
    width: 86px;
    max-width: 100%;
    display: block;
    border-radius: 6px;
    opacity: 0.92;
}

.nav {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.nav a {
    color: #e2e8f0;
    text-decoration: none;
    padding: 8px 10px;
    border-radius: 8px;
}

.nav a:hover {
    background: rgba(148, 163, 184, 0.2);
}

.sidebar-footer {
    margin-top: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.sidebar-footer .user {
    font-size: 0.85rem;
    color: #cbd5f5;
}

.link {
    color: #3b82f6;
    text-decoration: none;
}

.content {
    flex: 1;
    padding: 32px 40px;
}

.card {
    background: #ffffff;
    border-radius: 16px;
    padding: 32px;
    box-shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
    min-height: calc(100vh - 64px);
}

h1 {
    margin-top: 0;
}

.muted {
    color: #6b7280;
}

.panel {
    background: #f8fafc;
    border-radius: 12px;
    padding: 20px;
    margin: 20px 0;
}

.panel.grid-2 {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 20px;
}

.panel-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

label {
    display: block;
    margin: 12px 0 6px;
    font-size: 0.9rem;
}

input,
select,
textarea {
    width: 100%;
    padding: 10px 12px;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
    font-size: 0.95rem;
}

button,
.button {
    display: inline-block;
    padding: 10px 16px;
    border-radius: 8px;
    border: none;
    background: #e2e8f0;
    color: #0f172a;
    text-decoration: none;
    cursor: pointer;
}

button.primary,
.button.primary {
    background: #2563eb;
    color: #fff;
}

button.danger,
.button.danger {
    background: #ef4444;
    color: #fff;
}

.actions {
    margin-top: 16px;
    display: flex;
    gap: 12px;
}

.table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 12px;
}

.table th,
.table td {
    text-align: left;
    padding: 12px 8px;
    border-bottom: 1px solid #e5e7eb;
}

.chat-log {
    background: #f8fafc;
    border-radius: 12px;
    padding: 16px;
    min-height: 300px;
    max-height: 420px;
    overflow-y: auto;
}

.chat-bubble {
    padding: 10px 12px;
    margin: 8px 0;
    border-radius: 12px;
    max-width: 80%;
}

.chat-bubble.user {
    background: #2563eb;
    color: #fff;
    margin-left: auto;
}

.chat-bubble.assistant {
    background: #e2e8f0;
    color: #0f172a;
}

.chat-bubble.system {
    background: #fef3c7;
    color: #92400e;
}

.chat-input {
    margin-top: 16px;
    display: grid;
    gap: 12px;
}

.controls {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 16px;
}

.image-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 12px;
    margin-top: 16px;
}

.image-grid img {
    width: 100%;
    border-radius: 10px;
    object-fit: cover;
}

.messages {
    margin-bottom: 16px;
}

.message {
    padding: 10px 12px;
    border-radius: 8px;
    margin-bottom: 8px;
    background: #f1f5f9;
}

.message.error {
    background: #fee2e2;
    color: #991b1b;
}

.message.success {
    background: #dcfce7;
    color: #166534;
}

.auth-layout {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f5f6f8;
    padding: 24px;
}

.auth-card {
    background: #ffffff;
    border-radius: 16px;
    padding: 32px;
    box-shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
    width: 100%;
    max-width: 420px;
    text-align: center;
}

.auth-logo {
    width: 110px;
    max-width: 100%;
    margin: 0 auto 8px;
    display: block;
    border-radius: 6px;
    opacity: 0.95;
}

.auth-card form {
    text-align: left;
}

.auth-card button.primary {
    width: 100%;
    margin-top: 14px;
}

.qr {
    max-width: 180px;
    border-radius: 12px;
    background: #fff;
    padding: 12px;
}

.chat-app {
    height: calc(100vh - 128px);
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 16px;
}

.chat-conversations {
    border: 1px solid #e5e7eb;
    border-radius: 14px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-conversations-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 10px;
}

.chat-conversations-header h2 {
    margin: 0;
    font-size: 1rem;
}

.conversation-list {
    overflow-y: auto;
    display: grid;
    gap: 8px;
}

.conversation-item {
    display: grid;
    grid-template-columns: 1fr auto auto;
    align-items: center;
    gap: 6px;
    border: 1px solid #eef2f7;
    border-radius: 10px;
    background: #f8fafc;
    padding: 6px;
}

.conversation-item.active {
    border-color: #bfdbfe;
    background: #eff6ff;
}

.conversation-open {
    border: none;
    background: transparent;
    text-align: left;
    padding: 6px;
    min-width: 0;
}

.conversation-title {
    font-size: 0.92rem;
    color: #111827;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conversation-time {
    font-size: 0.75rem;
    color: #6b7280;
}

.conversation-more,
.conversation-delete {
    border-radius: 8px;
    padding: 6px 8px;
    font-size: 0.75rem;
}

.chat-thread {
    border: 1px solid #e5e7eb;
    border-radius: 14px;
    background: #ffffff;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

.thread-empty {
    margin: auto;
    color: #6b7280;
}

.message-list {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.message-item {
    max-width: min(860px, 92%);
    border-radius: 12px;
    padding: 12px;
    line-height: 1.4;
    word-break: break-word;
}

.message-item.user {
    align-self: flex-end;
    background: #2563eb;
    color: #fff;
}

.message-item.assistant {
    align-self: flex-start;
    background: #f1f5f9;
    color: #0f172a;
}

.message-item.system {
    align-self: center;
    background: #fef3c7;
    color: #92400e;
}

.message-item.error {
    border: 1px solid #fca5a5;
}

.markdown-block {
    white-space: normal;
}

.markdown-block code {
    background: rgba(15, 23, 42, 0.08);
    padding: 0 4px;
    border-radius: 6px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.code-block {
    position: relative;
    margin: 10px 0;
    background: #0f172a;
    color: #e2e8f0;
    border-radius: 10px;
    padding: 28px 12px 12px;
    overflow-x: auto;
}

.code-block code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    background: transparent;
}

.copy-code-btn {
    position: absolute;
    top: 6px;
    right: 6px;
    padding: 4px 8px;
    font-size: 0.75rem;
}

.composer {
    border-top: 1px solid #e5e7eb;
    padding: 12px;
    display: grid;
    gap: 10px;
}

.composer textarea {
    resize: none;
    max-height: 200px;
    min-height: 44px;
}

.composer-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.jump-latest {
    position: absolute;
    bottom: 90px;
    right: 20px;
    z-index: 10;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.2);
}

.hidden {
    display: none !important;
}

.stream-cursor {
    display: inline-block;
    width: 9px;
    height: 1em;
    margin-left: 2px;
    background: currentColor;
    animation: blink 1s steps(1, end) infinite;
    vertical-align: text-bottom;
}

.retry-btn {
    margin-top: 8px;
    font-size: 0.8rem;
}

@keyframes blink {
    50% {
        opacity: 0;
    }
}

@media (max-width: 980px) {
    .content {
        padding: 12px;
    }

    .card {
        min-height: calc(100vh - 24px);
        padding: 12px;
    }

    .chat-app {
        height: calc(100vh - 60px);
        grid-template-columns: 1fr;
    }

    .chat-conversations {
        max-height: 220px;
    }
}
