:root {
    color-scheme: dark;
    --bg: #07101e;
    --panel: #0b1423;
    --surface: #101b2d;
    --surface-2: #17243a;
    --line: rgba(148, 163, 184, .16);
    --text: #f8fafc;
    --soft: #dbe7f7;
    --muted: #8a98ad;
    --accent: #6d35ff;
    --accent-2: #2857ff;
    --success: #10b981;
    --danger: #ef4444;
    --shadow: 0 22px 60px rgba(2, 6, 23, .32);
}

:root[data-theme="light"] {
    color-scheme: light;
    --bg: #f7f8fc;
    --panel: #ffffff;
    --surface: #ffffff;
    --surface-2: #f2f5fb;
    --line: rgba(15, 23, 42, .1);
    --text: #111827;
    --soft: #1f2937;
    --muted: #64748b;
    --shadow: 0 20px 45px rgba(15, 23, 42, .08);
}

@media (prefers-color-scheme: light) {
    :root[data-theme="auto"] {
        color-scheme: light;
        --bg: #f7f8fc;
        --panel: #ffffff;
        --surface: #ffffff;
        --surface-2: #f2f5fb;
        --line: rgba(15, 23, 42, .1);
        --text: #111827;
        --soft: #1f2937;
        --muted: #64748b;
        --shadow: 0 20px 45px rgba(15, 23, 42, .08);
    }
}

* {
    box-sizing: border-box;
    scrollbar-width: thin;
    scrollbar-color: color-mix(in srgb, var(--muted) 45%, transparent) transparent;
}

[hidden] {
    display: none !important;
}

html,
body {
    height: 100%;
    margin: 0;
    overflow: hidden;
}

body {
    font-family: Tahoma, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
}

button,
input,
textarea,
select {
    font: inherit;
}

button {
    cursor: pointer;
}

.app-shell {
    height: 100dvh;
    display: grid;
    grid-template-columns: 300px minmax(0, 1fr);
    direction: ltr;
    background: var(--bg);
}

.sidebar,
.chat-main {
    direction: rtl;
}

.sidebar {
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    background: color-mix(in srgb, var(--panel) 96%, transparent);
    border-right: 1px solid var(--line);
}

.sidebar-head,
.topbar,
.dialog-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.sidebar-head {
    padding: 16px 18px 12px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 800;
    color: var(--text);
}

.brand-mark,
.avatar,
.conversation-icon {
    display: grid;
    place-items: center;
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    color: #fff;
}

.brand-mark {
    width: 30px;
    height: 30px;
    border-radius: 8px;
}

.new-chat,
.deleted-toggle {
    margin: 6px 16px 12px;
    min-height: 38px;
    border: 0;
    border-radius: 9px;
    color: #fff;
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    font-weight: 800;
    box-shadow: 0 12px 26px rgba(91, 70, 255, .24);
}

.deleted-toggle {
    background: var(--surface);
    color: var(--muted);
    border: 1px solid var(--line);
    box-shadow: none;
}

.deleted-toggle.active {
    color: #fff;
    border-color: transparent;
    background: linear-gradient(135deg, #ef4444, #9f1239);
}

.sidebar-search {
    height: 36px;
    margin: 0 14px 10px;
    display: grid;
    grid-template-columns: 24px 1fr;
    align-items: center;
    gap: 4px;
    padding: 0 10px;
    color: var(--muted);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 9px;
}

.sidebar-search input {
    min-width: 0;
    border: 0;
    outline: none;
    color: var(--text);
    background: transparent;
    font-size: 12px;
}

.conversation-list {
    flex: 1;
    min-height: 0;
    overflow: auto;
    padding: 0 10px 12px;
}

.sidebar-label {
    padding: 8px 8px 9px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 800;
}

.conversation-item {
    width: 100%;
    min-height: 54px;
    display: grid;
    grid-template-columns: 30px minmax(0, 1fr) repeat(2, 28px);
    align-items: center;
    gap: 9px;
    margin-bottom: 4px;
    padding: 8px;
    border: 1px solid transparent;
    border-radius: 10px;
    color: var(--soft);
    background: transparent;
    text-align: right;
}

.conversation-item:hover,
.conversation-item.active {
    background: color-mix(in srgb, var(--accent) 14%, var(--surface));
    border-color: color-mix(in srgb, var(--accent) 28%, transparent);
}

.conversation-item.deleted {
    opacity: .8;
}

.conversation-item.archived .conversation-icon {
    background: linear-gradient(135deg, #64748b, #334155);
}

.conversation-icon {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 900;
    line-height: 1;
}

.conversation-body {
    min-width: 0;
    display: grid;
    gap: 3px;
}

.conversation-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 800;
    font-size: 12px;
}

.conversation-body small {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--muted);
    font-size: 11px;
}

.delete-conversation {
    width: 27px;
    height: 27px;
    border: 0;
    border-radius: 8px;
    color: var(--muted);
    background: transparent;
    opacity: 0;
}

.delete-conversation.purge {
    color: #fecaca;
    background: color-mix(in srgb, var(--danger) 18%, transparent);
}

.conversation-item:hover .delete-conversation {
    opacity: 1;
}

.sidebar-foot {
    padding: 12px 16px 16px;
    border-top: 1px solid var(--line);
}

.memory-btn,
.top-link,
.icon-btn {
    border: 1px solid var(--line);
    border-radius: 9px;
    background: var(--surface);
    color: var(--text);
}

.memory-btn {
    width: 100%;
    min-height: 38px;
}

.theme-switch {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
    margin: 10px 0;
    padding: 4px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--surface);
}

.theme-switch button {
    height: 28px;
    border: 0;
    border-radius: 8px;
    color: var(--muted);
    background: transparent;
    font-size: 11px;
}

.theme-switch button.active,
.icon-btn.active {
    color: #fff;
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
}

.logout,
.top-link,
.impersonation-banner a {
    color: var(--soft);
    text-decoration: none;
}

.logout {
    display: block;
    margin-top: 10px;
}

.impersonation-banner {
    display: grid;
    gap: 6px;
    margin-bottom: 10px;
    padding: 10px;
    border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
    border-radius: 10px;
    background: color-mix(in srgb, var(--accent) 12%, var(--surface));
    color: var(--soft);
    font-size: 12px;
}

.chat-main {
    min-width: 0;
    min-height: 0;
    display: grid;
    grid-template-rows: auto 1fr auto;
}

.topbar {
    min-height: 58px;
    padding: 10px 18px;
    border-bottom: 1px solid var(--line);
    background: color-mix(in srgb, var(--bg) 92%, transparent);
}

.chat-title {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 800;
}

.top-actions,
.model-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
}

.hidden-settings {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    pointer-events: none;
    opacity: 0;
}

.icon-btn {
    width: 36px;
    height: 36px;
}

.menu-btn,
.mobile-close {
    display: none;
}

.user-chip {
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--soft);
}

.top-link {
    padding: 8px 10px;
}

.messages {
    min-height: 0;
    overflow-y: auto;
    padding: 22px max(18px, calc((100vw - 1060px) / 2)) 118px;
}

.empty-state {
    min-height: 64vh;
    display: grid;
    align-content: center;
    justify-items: center;
    gap: 24px;
    max-width: 780px;
    margin: 0 auto;
}

.empty-state h1 {
    margin: 0;
    color: var(--text);
    text-align: center;
    font-size: clamp(24px, 3vw, 34px);
}

.welcome-loader {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-width: 86px;
    min-height: 38px;
}

.welcome-loader i {
    width: 10px;
    height: 10px;
    border-radius: 999px;
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    animation: welcome-dot 0.9s ease-in-out infinite;
}

.welcome-loader i:nth-child(2) {
    animation-delay: .15s;
}

.welcome-loader i:nth-child(3) {
    animation-delay: .3s;
}

@keyframes welcome-dot {
    0%, 100% { transform: translateY(0); opacity: .45; }
    50% { transform: translateY(-9px); opacity: 1; }
}

.quick-grid {
    width: min(720px, 100%);
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.quick-grid button {
    min-height: 56px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--surface);
    color: var(--soft);
    text-align: right;
    padding: 12px 14px;
}

.message {
    max-width: 860px;
    margin: 0 auto 18px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 34px;
    gap: 10px;
    direction: ltr;
}

.avatar {
    grid-column: 2;
    width: 32px;
    height: 32px;
    border-radius: 9px;
    font-size: 11px;
    font-weight: 900;
}

.bubble {
    grid-column: 1;
    min-width: 0;
    direction: rtl;
    color: var(--soft);
    line-height: 1.95;
    overflow-wrap: break-word;
    white-space: pre-wrap;
}

.message.assistant .bubble {
    padding: 18px 20px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.message.user .bubble {
    width: fit-content;
    max-width: min(760px, 100%);
    margin-right: auto;
    padding: 12px 14px;
    border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
    border-radius: 10px;
    color: #fff;
    background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 45%, var(--surface)), color-mix(in srgb, var(--accent-2) 35%, var(--surface)));
}

.deleted-message {
    opacity: .72;
}

.typing .bubble::after {
    content: '▌';
    color: var(--accent);
    animation: blink 1s steps(1) infinite;
}

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

.bubble p {
    margin: 0 0 12px;
}

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

.bubble h2,
.bubble h3,
.bubble h4 {
    margin: 0 0 10px;
    color: var(--text);
}

.bubble ul,
.bubble ol {
    margin: 8px 24px 14px 0;
}

.bubble pre {
    position: relative;
    direction: ltr;
    text-align: left;
    margin: 12px 0;
    padding: 42px 14px 14px;
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #0f172a;
    color: #e5e7eb;
}

.copy-code {
    position: absolute;
    top: 8px;
    left: 8px;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: #1e293b;
    color: #f8fafc;
    padding: 4px 9px;
    font-size: 11px;
}

.bubble code {
    direction: ltr;
    unicode-bidi: plaintext;
    border-radius: 6px;
    background: color-mix(in srgb, var(--surface-2) 70%, transparent);
    color: var(--text);
    padding: 2px 6px;
    font-family: Consolas, Monaco, monospace;
}

.bubble pre code {
    padding: 0;
    background: transparent;
    color: #e5e7eb;
}

.bubble a {
    color: #89a8ff;
}

.bubble blockquote {
    margin: 10px 0;
    padding: 8px 12px;
    border-right: 3px solid var(--accent);
    border-radius: 8px;
    background: color-mix(in srgb, var(--accent) 10%, transparent);
}

.md-table-wrap {
    max-width: 100%;
    overflow: auto;
    margin: 12px 0;
    border: 1px solid var(--line);
    border-radius: 10px;
}

table {
    width: 100%;
    border-collapse: collapse;
}

.bubble table {
    min-width: 620px;
    background: var(--surface);
}

th,
td {
    padding: 11px 10px;
    border-bottom: 1px solid var(--line);
    color: var(--soft);
    text-align: right;
}

th {
    color: var(--text);
    background: var(--surface-2);
}

.thinking-panel {
    grid-column: 1;
    direction: rtl;
    margin-bottom: 8px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: color-mix(in srgb, var(--surface) 86%, transparent);
    color: var(--muted);
}

.thinking-panel summary {
    padding: 8px 11px;
    cursor: pointer;
}

.thinking-body {
    max-height: 180px;
    margin: 0;
    overflow: auto;
    padding: 0 11px 11px;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    word-break: normal;
    unicode-bidi: plaintext;
    line-height: 1.8;
}

.message-actions {
    grid-column: 1;
    display: flex;
    align-items: center;
    gap: 7px;
    flex-wrap: wrap;
    margin-top: 8px;
}

.message-time {
    grid-column: 1;
    justify-self: start;
    margin-top: 4px;
    color: var(--muted);
    font-size: 11px;
    line-height: 1;
}

.memory-status {
    grid-column: 1;
    width: fit-content;
    max-width: 100%;
    margin-top: 8px;
    padding: 7px 10px;
    border: 1px solid color-mix(in srgb, var(--accent) 28%, var(--line));
    border-radius: 8px;
    background: color-mix(in srgb, var(--accent) 8%, var(--surface));
    color: var(--soft);
    font-size: 12px;
}

.memory-status.error {
    border-color: color-mix(in srgb, var(--danger) 35%, var(--line));
    background: color-mix(in srgb, var(--danger) 8%, var(--surface));
}

.timing-status {
    grid-column: 1;
    width: fit-content;
    max-width: 100%;
    margin-top: 6px;
    color: var(--muted);
    font-size: 12px;
}

.message-files {
    grid-column: 1;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 8px;
}

.message-file {
    width: min(260px, 100%);
    display: grid;
    grid-template-columns: 58px minmax(0, 1fr);
    gap: 9px;
    align-items: center;
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--surface);
    color: var(--soft);
    text-decoration: none;
}

.message-file img,
.file-format {
    width: 58px;
    height: 58px;
    grid-row: span 2;
    border-radius: 8px;
}

.message-file img {
    object-fit: cover;
}

.file-format {
    display: grid;
    place-items: center;
    background: var(--surface-2);
    color: var(--text);
    font-size: 10px;
    font-weight: 900;
}

.message-file strong,
.message-file small {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.message-file small {
    color: var(--muted);
}

.message-actions button,
.version-chip {
    min-width: 32px;
    min-height: 30px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    color: var(--muted);
    padding: 5px 10px;
    font-size: 12px;
}

.message-actions button:hover {
    color: var(--text);
}

.message-actions button.selected-feedback {
    color: #fff;
    border-color: transparent;
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
}

.composer {
    width: min(850px, calc(100vw - 350px));
    margin: 0 auto 16px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 44px;
    gap: 8px;
    align-items: end;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.queue-bar {
    display: grid;
    gap: 6px;
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: color-mix(in srgb, var(--surface) 92%, var(--accent) 8%);
}

.queue-item {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--soft);
}

.queue-item span {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.queue-item button {
    height: 26px;
    padding: 0 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface-2);
    color: var(--muted);
    cursor: pointer;
}

.file-strip {
    width: min(850px, calc(100vw - 350px));
    margin: 0 auto 10px;
    display: flex;
    gap: 10px;
    overflow-x: auto;
    padding: 2px 2px 8px;
}

.file-card {
    min-width: 178px;
    max-width: 220px;
    display: grid;
    grid-template-columns: 44px minmax(0, 1fr);
    gap: 9px;
    align-items: center;
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--surface);
    color: var(--soft);
    text-decoration: none;
}

.file-card img {
    width: 44px;
    height: 44px;
    object-fit: cover;
    border-radius: 8px;
    grid-row: span 2;
}

.file-card strong,
.file-card span {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.file-card span {
    color: var(--muted);
    font-size: 11px;
}

.attachments-bar {
    grid-column: 1 / -1;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.attachment-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    max-width: 100%;
    padding: 6px 8px;
    border: 1px solid var(--line);
    border-radius: 9px;
    background: var(--surface-2);
    color: var(--soft);
    font-size: 12px;
}

.attachment-chip img {
    width: 30px;
    height: 30px;
    object-fit: cover;
    border-radius: 7px;
}

.attachment-chip button {
    width: 20px;
    height: 20px;
    border: 0;
    border-radius: 50%;
    color: #fff;
    background: var(--danger);
}

.composer textarea {
    grid-column: 1 / -1;
    min-height: 38px;
    max-height: 170px;
    resize: none;
    border: 0;
    outline: none;
    padding: 4px;
    color: var(--text);
    background: transparent;
    line-height: 1.8;
}

.composer-tools {
    display: flex;
    align-items: center;
    gap: 8px;
}

.think-toggle,
.attach-btn {
    height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--surface-2);
    color: var(--soft);
    padding: 0 11px;
}

.think-toggle input {
    accent-color: var(--accent);
}

.attach-btn {
    width: 34px;
    padding: 0;
    font-size: 20px;
}

.attach-btn input {
    display: none;
}

.composer button#sendBtn {
    grid-column: 2;
    width: 42px;
    height: 42px;
    border: 0;
    border-radius: 50%;
    color: #fff;
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    font-size: 16px;
}

.composer button#sendBtn.stop {
    background: linear-gradient(135deg, var(--danger), #9f1239);
}

.memory-dialog {
    width: min(680px, calc(100vw - 28px));
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow);
}

.memory-dialog::backdrop {
    background: rgba(2, 6, 23, .62);
}

.dialog-head {
    padding: 14px 16px;
    border-bottom: 1px solid var(--line);
}

.memory-dialog pre {
    max-height: 60vh;
    margin: 0;
    overflow: auto;
    padding: 16px;
    direction: ltr;
    text-align: left;
    white-space: pre-wrap;
}

.toast {
    position: fixed;
    inset: auto 50% 24px auto;
    z-index: 50;
    transform: translateX(50%) translateY(18px);
    opacity: 0;
    pointer-events: none;
    padding: 10px 14px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow);
    transition: opacity .18s ease, transform .18s ease;
}

.toast.show {
    opacity: 1;
    transform: translateX(50%) translateY(0);
}

.auth-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    background: var(--bg);
    overflow: auto;
}

.auth-shell {
    width: min(430px, calc(100vw - 32px));
}

.auth-panel,
.admin-card {
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.auth-panel {
    padding: 28px;
}

.auth-panel h1 {
    margin: 18px 0 8px;
}

.auth-panel p,
.admin-head p,
.admin-card small {
    color: var(--muted);
    line-height: 1.8;
}

.auth-form,
.mini-form {
    display: grid;
    gap: 12px;
}

.auth-form label,
.admin-card label {
    display: grid;
    gap: 8px;
    color: var(--soft);
}

.auth-form input,
.admin-card input,
.admin-card textarea,
.admin-card select {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 9px;
    outline: none;
    padding: 11px 12px;
    background: var(--panel);
    color: var(--text);
}

.auth-form button,
.admin-card button {
    border: 0;
    border-radius: 9px;
    padding: 11px 14px;
    color: #fff;
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    font-weight: 800;
}

.alert {
    margin-bottom: 16px;
    padding: 11px 12px;
    border: 1px solid color-mix(in srgb, var(--danger) 42%, transparent);
    border-radius: 9px;
    background: color-mix(in srgb, var(--danger) 12%, transparent);
    color: #fecaca;
}

.alert.success {
    border-color: color-mix(in srgb, var(--success) 45%, transparent);
    background: color-mix(in srgb, var(--success) 14%, transparent);
    color: #bbf7d0;
}

body.admin-page {
    min-height: 100%;
    overflow: auto;
    background: var(--bg);
}

html.admin-doc,
html.admin-doc body {
    height: auto;
    min-height: 100%;
    overflow: auto;
}

.admin-shell {
    width: min(1180px, calc(100vw - 28px));
    margin: 0 auto;
    padding: 26px 0 46px;
}

.admin-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
}

.admin-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.admin-actions a {
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 9px;
    background: var(--surface);
    color: var(--soft);
    text-decoration: none;
}

.admin-grid {
    display: grid;
    grid-template-columns: 1fr 330px;
    gap: 16px;
    align-items: start;
}

.admin-stats {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 16px;
}

.admin-stats div {
    min-height: 82px;
    display: grid;
    align-content: center;
    gap: 6px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.admin-stats strong {
    color: var(--text);
    font-size: 24px;
}

.admin-stats span {
    color: var(--muted);
    font-size: 12px;
}

.admin-card {
    padding: 18px;
}

.admin-card h2 {
    margin: 0 0 16px;
    font-size: 18px;
}

.admin-card textarea {
    resize: vertical;
    line-height: 1.8;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
}

.check-line {
    grid-template-columns: 22px 1fr;
    align-items: center;
}

.check-line input {
    width: auto;
}

.users-card {
    margin-top: 16px;
}

.table-wrap {
    overflow-x: auto;
}

.users-card table {
    min-width: 860px;
}

.reset-form {
    display: grid;
    grid-template-columns: minmax(130px, 1fr) auto;
    gap: 8px;
}

.inline-form {
    margin: 0;
}

.probe-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 14px;
}

.probe-box,
.probe-summary,
.model-card,
.probe-runtime,
.probe-errors {
    display: grid;
    gap: 10px;
}

.probe-summary,
.model-card,
.probe-runtime,
.probe-errors {
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--panel);
}

.model-card-head,
.model-meta {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
}

.model-meta span {
    padding: 5px 7px;
    border-radius: 8px;
    background: var(--surface-2);
    color: var(--muted);
    font-size: 12px;
}

.probe-box pre {
    max-height: 230px;
    margin: 0;
    overflow: auto;
    direction: ltr;
    text-align: left;
    color: var(--muted);
    white-space: pre-wrap;
}

@media (max-width: 860px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        z-index: 20;
        width: min(320px, 86vw);
        transform: translateX(-105%);
        transition: transform .18s ease;
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .menu-btn,
    .mobile-close {
        display: inline-grid;
        place-items: center;
    }

    .topbar {
        padding: 10px 12px;
    }

    .top-actions .top-link,
    .top-actions .user-chip {
        display: none;
    }

    .chat-title {
        text-align: center;
    }

    .messages {
        padding: 16px 12px 92px;
    }

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

    .message {
        grid-template-columns: minmax(0, 1fr) 30px;
        gap: 8px;
        margin-bottom: 14px;
    }

    .message.assistant .bubble {
        padding: 14px;
    }

    .composer {
        width: calc(100vw - 24px);
        margin-bottom: 10px;
    }

    .think-toggle span {
        display: none;
    }

    .admin-head,
    .admin-stats,
    .admin-grid {
        display: grid;
        grid-template-columns: 1fr;
    }

    .form-row {
        grid-template-columns: 1fr;
    }
}
