:root {
    --background: #f5f6f8;
    --surface: #ffffff;
    --surface-secondary: #f0f2f5;
    --text: #17191c;
    --muted: #6d727b;
    --border: #dde1e7;
    --primary: #7357e8;
    --primary-hover: #6245d5;
    --danger: #d64545;
    --danger-hover: #bd3434;
    --success: #1f8b55;
    --radius: 12px;
    --shadow: 0 8px 30px rgba(20, 24, 35, 0.06);
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    min-height: 100%;
}

body {
    background: var(--background);
    color: var(--text);
    font-family:
        Inter,
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        sans-serif;
    font-size: 15px;
    line-height: 1.5;
}

a {
    color: var(--primary);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

h1,
h2,
h3,
p {
    margin-top: 0;
}

h1 {
    margin-bottom: 8px;
    font-size: 30px;
}

h2 {
    font-size: 20px;
}

button,
input,
textarea,
select {
    font: inherit;
}

.header {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 64px;
    padding: 0 32px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.logo {
    color: var(--text);
    font-size: 18px;
    font-weight: 800;
    letter-spacing: 0.04em;
}

.logo:hover {
    text-decoration: none;
}

.navigation {
    display: flex;
    align-items: center;
    gap: 20px;
}

.navigation a {
    color: var(--text);
}

.username {
    color: var(--muted);
}

.container {
    width: min(1180px, calc(100% - 40px));
    margin: 40px auto;
}

.inline-form {
    display: inline;
}

.page-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    margin-bottom: 28px;
}

.muted {
    color: var(--muted);
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    padding: 9px 18px;
    color: #ffffff;
    background: var(--primary);
    border: 0;
    border-radius: 9px;
    cursor: pointer;
    font-weight: 600;
    text-decoration: none;
    transition:
        background 0.15s,
        opacity 0.15s;
}

.button:hover {
    color: #ffffff;
    background: var(--primary-hover);
    text-decoration: none;
}

.button:disabled {
    cursor: not-allowed;
    opacity: 0.65;
}

.button-small {
    min-height: 34px;
    padding: 6px 12px;
    font-size: 14px;
}

.button-full {
    width: 100%;
}

.button-secondary {
    color: var(--text);
    background: var(--surface-secondary);
    border: 1px solid var(--border);
}

.button-secondary:hover {
    color: var(--text);
    background: #e5e8ed;
}

.button-danger {
    background: var(--danger);
}

.button-danger:hover {
    background: var(--danger-hover);
}

.form {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.form label,
.filter-form label {
    color: var(--muted);
    font-size: 14px;
    font-weight: 600;
}

input,
textarea,
select {
    width: 100%;
    padding: 11px 13px;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 9px;
    outline: none;
}

input:focus,
textarea:focus,
select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(115, 87, 232, 0.12);
}

.login-page {
    display: grid;
    min-height: 100vh;
    padding: 24px;
    place-items: center;
}

.login-card {
    width: min(420px, 100%);
    padding: 38px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 18px;
    box-shadow: var(--shadow);
}

.login-logo {
    margin-bottom: 30px;
    color: var(--primary);
    font-size: 20px;
    font-weight: 800;
    letter-spacing: 0.05em;
}

.login-card .button {
    margin-top: 12px;
}

.alert {
    margin-bottom: 20px;
    padding: 13px 16px;
    border-radius: 9px;
}

.alert-danger {
    color: #8d2828;
    background: #fbe4e4;
}

.alert-success {
    color: #17683f;
    background: #dff4e9;
}

.alert-warning {
    color: #795b13;
    background: #fff2c8;
}

.panel {
    margin-bottom: 24px;
    padding: 24px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.card-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chat-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    padding: 20px;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    transition:
        border-color 0.15s,
        transform 0.15s;
}

.chat-card:hover {
    border-color: var(--primary);
    text-decoration: none;
    transform: translateY(-1px);
}

.chat-card h2,
.chat-card h3 {
    margin-bottom: 5px;
}

.chat-card p,
.chat-card time {
    margin: 0;
    color: var(--muted);
    font-size: 14px;
}

.empty-state,
.error-page {
    padding: 70px 30px;
    text-align: center;
    background: var(--surface);
    border: 1px dashed var(--border);
    border-radius: var(--radius);
}

.chat-page {
    height: calc(100vh - 64px);
}

.chat-layout {
    display: grid;
    grid-template-rows: auto 1fr auto auto;
    height: 100%;
    background: var(--surface);
}

.chat-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 18px 28px;
    border-bottom: 1px solid var(--border);
}

.chat-topbar h1 {
    margin: 3px 0 0;
    font-size: 22px;
}

.back-link {
    color: var(--muted);
    font-size: 14px;
}

.chat-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.rename-form {
    display: flex;
    gap: 8px;
}

.rename-form input {
    width: 230px;
}

.messages {
    overflow-y: auto;
    padding: 28px max(24px, calc((100% - 900px) / 2));
}

.message {
    max-width: 760px;
    margin-bottom: 22px;
}

.message-user {
    margin-left: auto;
    padding: 15px 17px;
    background: #ede9ff;
    border-radius: 14px 14px 3px 14px;
}

.message-assistant {
    margin-right: auto;
}

.message-role {
    margin-bottom: 6px;
    font-size: 13px;
    font-weight: 700;
}

.message-content {
    overflow-wrap: anywhere;
    white-space: pre-wrap;
}

.message-links {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 12px;
}

.message-links a {
    padding: 6px 10px;
    background: var(--surface-secondary);
    border-radius: 7px;
    font-size: 14px;
}

.message-time {
    display: block;
    margin-top: 8px;
    color: var(--muted);
    font-size: 12px;
}

.empty-chat {
    margin: 80px auto;
    color: var(--muted);
    text-align: center;
}

.message-form {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    width: min(900px, calc(100% - 40px));
    margin: 0 auto;
    padding: 18px 0;
    border-top: 1px solid var(--border);
}

.message-form textarea {
    min-height: 48px;
    max-height: 180px;
    resize: none;
}

.send-button {
    min-height: 48px;
}

.send-error {
    min-height: 24px;
    color: var(--danger);
    text-align: center;
    font-size: 14px;
}

.typing::after {
    content: "...";
    animation: typing 1.2s infinite;
}

@keyframes typing {
    0% {
        opacity: 0.25;
    }

    50% {
        opacity: 1;
    }

    100% {
        opacity: 0.25;
    }
}

.admin-view-note {
    padding: 15px;
    color: var(--muted);
    background: var(--surface-secondary);
    text-align: center;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr 190px auto;
    align-items: end;
    gap: 14px;
}

.form-row > div {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.admin-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
}

.action-list {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.filter-form {
    display: flex;
    align-items: flex-end;
    gap: 12px;
}

.filter-form > div {
    display: flex;
    min-width: 220px;
    flex-direction: column;
    gap: 6px;
}

.table-wrapper {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    padding: 13px 12px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: top;
}

th {
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

.status {
    display: inline-block;
    padding: 4px 9px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
}

.status-active {
    color: var(--success);
    background: #dff4e9;
}

.status-blocked {
    color: var(--danger);
    background: #fbe4e4;
}

.log-details {
    min-width: 280px;
    max-width: 480px;
    overflow-wrap: anywhere;
}

code {
    padding: 3px 6px;
    background: var(--surface-secondary);
    border-radius: 5px;
}

@media (max-width: 850px) {
    .header {
        padding: 0 18px;
    }

    .navigation {
        gap: 10px;
    }

    .username {
        display: none;
    }

    .container {
        width: min(100% - 24px, 1180px);
        margin: 24px auto;
    }

    .page-heading,
    .chat-topbar {
        align-items: flex-start;
        flex-direction: column;
    }

    .chat-actions,
    .rename-form {
        width: 100%;
    }

    .rename-form {
        flex-wrap: wrap;
    }

    .rename-form input {
        width: 100%;
    }

    .form-row,
    .admin-grid {
        grid-template-columns: 1fr;
    }

    .filter-form {
        align-items: stretch;
        flex-direction: column;
    }

    .filter-form > div {
        width: 100%;
    }

    .messages {
        padding: 20px 14px;
    }

    .message-form {
        width: calc(100% - 24px);
    }

    .chat-card {
        align-items: flex-start;
        flex-direction: column;
        gap: 8px;
    }
}

/* ===== Тёмный пользовательский интерфейс ===== */
:root {
    color-scheme: dark;
    --background: #0d0f12;
    --surface: #12151a;
    --surface-secondary: #191d24;
    --surface-hover: #20252e;
    --text: #f2f4f7;
    --muted: #9299a6;
    --border: #292e37;
    --primary: #7c5cff;
    --primary-hover: #8b70ff;
    --danger: #e55757;
    --danger-hover: #ef6868;
    --success: #45b979;
    --radius: 13px;
    --header-height: 58px;
    --sidebar-width: 258px;
    --shadow: 0 18px 50px rgba(0, 0, 0, 0.25);
}

html,
body {
    height: 100%;
    background: var(--background);
}

body {
    overflow-x: hidden;
}

.header {
    position: fixed;
    inset: 0 0 auto 0;
    z-index: 100;
    min-height: var(--header-height);
    height: var(--header-height);
    padding: 0 22px;
    background: rgba(13, 15, 18, 0.94);
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(18px);
}

.logo {
    color: var(--text);
    font-size: 16px;
    letter-spacing: 0.12em;
}

.navigation a,
.username {
    color: var(--muted);
}

.container {
    margin-top: calc(var(--header-height) + 40px);
}

.user-page {
    width: 100%;
    height: 100vh;
    margin: 0;
    padding-top: var(--header-height);
}

.user-workspace {
    display: grid;
    grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
    height: 100%;
    min-width: 720px;
    background: var(--background);
}

.chat-sidebar {
    display: grid;
    grid-template-rows: auto auto auto minmax(0, 1fr) auto;
    min-width: var(--sidebar-width);
    background: #111419;
    border-right: 1px solid var(--border);
    height: 100%;
    overflow: hidden;
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 11px;
    min-width: 0;
    padding: 18px 16px 14px;
}

.user-avatar {
    display: grid;
    flex: 0 0 38px;
    width: 38px;
    height: 38px;
    color: #fff;
    background: linear-gradient(145deg, #8b70ff, #5b3ee5);
    border-radius: 12px;
    font-size: 16px;
    font-weight: 800;
    place-items: center;
}

.user-details {
    display: flex;
    min-width: 0;
    flex-direction: column;
}

.user-details strong {
    overflow: hidden;
    color: var(--text);
    text-overflow: ellipsis;
    white-space: nowrap;
}

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

.sidebar-close {
    display: none;
    margin-left: auto;
    padding: 3px 8px;
    color: var(--muted);
    background: transparent;
    border: 0;
    cursor: pointer;
    font-size: 27px;
}

.new-chat-form {
    padding: 4px 14px 16px;
}

.new-chat-button {
    display: flex;
    align-items: center;
    width: 100%;
    min-height: 46px;
    padding: 0 15px;
    color: var(--text);
    background: var(--surface-secondary);
    border: 1px solid #303642;
    border-radius: 12px;
    cursor: pointer;
    font-weight: 650;
    transition: 0.16s ease;
}

.new-chat-button:hover {
    background: var(--surface-hover);
    border-color: #454d5b;
}

.new-chat-icon {
    margin-right: 10px;
    color: #a896ff;
    font-size: 21px;
}

.sidebar-section-title {
    padding: 0 18px 8px;
    color: #747b88;
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.sidebar-chat-list {
    min-height: 0;
    overflow-y: auto;
    padding: 0 9px 14px;
    scrollbar-color: #363c47 transparent;
    scrollbar-width: thin;
}

.sidebar-chat-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 32px;
    align-items: center;
    width: 100%;
    min-height: 36px;
    margin-bottom: 2px;
    border: 1px solid transparent;
    border-radius: 8px;
    overflow: hidden;
    transition: 0.14s ease;
}

.sidebar-chat-row:hover {
    background: #1a1e25;
}

.sidebar-chat-row.active {
    background: #242033;
    border-color: #40365f;
}

.sidebar-chat-item {
    display: flex;
    width: 100%;
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
    align-items: flex-start;
    flex-direction: column;
    padding: 7px 4px 7px 10px;
    color: #c9ced7;
}

.sidebar-chat-item:hover {
    color: var(--text);
    text-decoration: none;
}

.sidebar-chat-name {
    display: block;
    width: 100%;
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 13px;
}

.sidebar-chat-model {
    display: block;
    margin-top: 2px;
    color: #9c8fe0;
    font-size: 10px;
    font-weight: 700;
}

.sidebar-chat-usage {
    display: block;
    margin-top: 3px;
    color: #8e8a9d;
    font-size: 10px;
    line-height: 1.15;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-chat-row.active .sidebar-chat-usage {
    color: #bcb4d7;
}

.sidebar-delete-form {
    display: flex;
    width: 32px;
    min-width: 32px;
    align-items: center;
    justify-content: center;
}

.sidebar-delete {
    display: grid;
    width: 28px;
    height: 28px;
    padding: 6px;
    color: #747b88;
    background: transparent;
    border: 0;
    border-radius: 6px;
    cursor: pointer;
    place-items: center;
}

.sidebar-delete:hover {
    color: #ff7777;
    background: rgba(229, 87, 87, 0.12);
}

.sidebar-delete svg {
    width: 16px;
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 1.8;
}

.sidebar-empty {
    padding: 18px 12px;
    color: var(--muted);
    text-align: center;
    font-size: 13px;
}

.sidebar-footer {
    padding: 12px 14px;
    border-top: 1px solid var(--border);
}

.sidebar-footer form {
    margin: 0;
}

/* Компактные сообщения и оформление ответов GPT */
.message-user {
    margin-left: auto;
    padding: 8px 12px;
    background: #4f35b5;
    border-radius: 13px 13px 3px 13px;
    line-height: 1.38;
}

.message-user .message-content {
    white-space: pre-wrap;
}

.message-user .message-role,
.message-user .message-time {
    display: none;
}

.message-assistant .message-content {
    white-space: normal;
}

.message-assistant .message-content > :first-child {
    margin-top: 0;
}

.message-assistant .message-content > :last-child {
    margin-bottom: 0;
}

.message-assistant .message-content p,
.message-assistant .message-content ul,
.message-assistant .message-content ol,
.message-assistant .message-content pre,
.message-assistant .message-content blockquote,
.message-assistant .message-content table {
    margin: 0 0 14px;
}

.message-assistant .message-content h1,
.message-assistant .message-content h2,
.message-assistant .message-content h3 {
    margin: 22px 0 9px;
    line-height: 1.25;
}

.message-assistant .message-content h1 { font-size: 1.45em; }
.message-assistant .message-content h2 { font-size: 1.25em; }
.message-assistant .message-content h3 { font-size: 1.1em; }

.message-assistant .message-content li {
    margin: 5px 0;
}

.message-assistant .message-content strong {
    color: #fff;
}

.message-assistant .message-content a {
    color: #a996ff;
    text-decoration: underline;
    text-underline-offset: 3px;
}

.message-assistant .message-content pre {
    overflow-x: auto;
    padding: 14px 16px;
    background: #090b0e;
    border: 1px solid var(--border);
    border-radius: 10px;
}

.message-assistant .message-content pre code {
    padding: 0;
    background: transparent;
}

.message-assistant .message-content blockquote {
    padding: 2px 0 2px 14px;
    color: #bec3cc;
    border-left: 3px solid var(--primary);
}

.message-assistant .message-content table {
    display: block;
    overflow-x: auto;
}

.math-display {
    width: 100%;
    margin: 15px 0;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 6px 2px;
    text-align: center;
}

.math-display .katex-display {
    margin: 0;
}

.math-inline {
    display: inline;
}

.math-error {
    color: #ff9d9d;
    font-family: monospace;
    white-space: pre-wrap;
}

.message-image {
    position: relative;
    width: min(100%, 760px);
    min-height: 160px;
    margin: 14px 0;
    overflow: hidden;
    background: #151920;
    border: 1px solid var(--border);
    border-radius: 14px;
}

.message-image img {
    display: block;
    width: 100%;
    max-height: 72vh;
    object-fit: contain;
}

.message-image-link {
    display: block;
    cursor: zoom-in;
}

.message-image.loading img {
    visibility: hidden;
}

.image-loader {
    display: none;
}

.message-image.loading .image-loader,
.message-image.failed .image-loader {
    position: absolute;
    inset: 0;
    display: grid;
    align-content: center;
    justify-items: center;
    gap: 10px;
    color: var(--muted);
    padding: 24px;
    text-align: center;
}

.image-loader strong {
    color: var(--text);
    font-size: 15px;
}

.image-loader-hint {
    color: color-mix(in srgb, var(--muted) 72%, transparent);
    font-size: 12px;
}

.image-loader span {
    width: 28px;
    height: 28px;
    border: 3px solid #3a3f49;
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: image-spin 0.8s linear infinite;
}

.message-image.failed {
    min-height: 190px;
    border-color: color-mix(in srgb, #ff6b7a 42%, var(--border));
    background:
        linear-gradient(
            145deg,
            color-mix(in srgb, #ff6b7a 7%, #151920),
            #151920
        );
}

.message-image.failed .message-image-link {
    display: none;
}

@keyframes image-spin {
    to { transform: rotate(360deg); }
}

.sidebar-logout {
    width: 100%;
    padding: 9px;
    color: var(--muted);
    background: transparent;
    border: 0;
    border-radius: 8px;
    cursor: pointer;
    text-align: left;
}

.sidebar-logout:hover {
    color: var(--text);
    background: var(--surface-secondary);
}

.chat-main {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    min-width: 0;
    height: 100%;
    background:
        radial-gradient(circle at 50% 0%, rgba(124, 92, 255, 0.06), transparent 34%),
        var(--background);
}

.chat-main-empty {
    display: grid;
    place-items: center;
}

.welcome-card {
    max-width: 460px;
    padding: 30px;
    text-align: center;
}

.welcome-card h1 {
    margin: 20px 0 8px;
    font-size: 28px;
}

.welcome-card p {
    margin-bottom: 24px;
    color: var(--muted);
}

.welcome-logo {
    display: grid;
    width: 68px;
    height: 68px;
    margin: 0 auto;
    color: #fff;
    background: linear-gradient(145deg, #947aff, #5737dc);
    border-radius: 20px;
    box-shadow: 0 15px 38px rgba(87, 55, 220, 0.3);
    font-size: 28px;
    font-weight: 900;
    place-items: center;
}

.welcome-logo.small {
    width: 48px;
    height: 48px;
    margin-bottom: 16px;
    border-radius: 15px;
    font-size: 20px;
}

.welcome-button {
    min-height: 48px;
    margin: 22px auto 0;
    padding-inline: 22px;
}

.model-dialog[hidden] {
    display: none;
}

.model-dialog {
    position: fixed;
    z-index: 1000;
    display: grid;
    inset: 0;
    padding: 20px;
    place-items: center;
}

.model-dialog-backdrop {
    position: absolute;
    inset: 0;
    padding: 0;
    background: rgba(4, 6, 10, 0.72);
    border: 0;
    backdrop-filter: blur(7px);
    cursor: default;
}

.model-dialog-card {
    position: relative;
    z-index: 1;
    width: min(100%, 470px);
    padding: 28px;
    color: var(--text);
    background: #171a20;
    border: 1px solid #343a46;
    border-radius: 20px;
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.48);
}

.model-dialog-card h2 {
    margin: 0 40px 6px 0;
    font-size: 22px;
}

.model-dialog-card > p {
    margin: 0 0 20px;
    color: var(--muted);
    font-size: 14px;
}

.model-dialog-close {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 34px;
    height: 34px;
    padding: 0;
    color: var(--muted);
    background: transparent;
    border: 0;
    border-radius: 9px;
    cursor: pointer;
    font-size: 26px;
    line-height: 1;
}

.model-dialog-close:hover {
    color: var(--text);
    background: var(--surface-hover);
}

.model-options {
    display: grid;
    gap: 10px;
}

.model-option {
    display: block;
    cursor: pointer;
}

.model-option input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.model-option-content {
    display: flex;
    min-height: 72px;
    padding: 14px 16px;
    background: #1d2128;
    border: 1px solid #343a46;
    border-radius: 13px;
    flex-direction: column;
    justify-content: center;
    transition: 0.16s ease;
}

.model-option-content strong {
    font-size: 15px;
}

.model-option-content small {
    margin-top: 4px;
    color: var(--muted);
    font-size: 12px;
}

.model-option:hover .model-option-content {
    border-color: #555e6d;
}

.model-option input:checked + .model-option-content {
    background: rgba(115, 92, 232, 0.15);
    border-color: #806ae9;
    box-shadow: 0 0 0 3px rgba(115, 92, 232, 0.12);
}

.model-option input:focus-visible + .model-option-content {
    outline: 2px solid #a896ff;
    outline-offset: 2px;
}

.model-dialog-create {
    width: 100%;
    min-height: 48px;
    margin-top: 18px;
}

.model-dialog-is-open {
    overflow: hidden;
}

.chat-topbar {
    min-height: 62px;
    padding: 10px 22px;
    background: rgba(13, 15, 18, 0.72);
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(12px);
}

.chat-title-wrap {
    min-width: 0;
}

.chat-model-badge {
    display: inline-block;
    margin-top: 4px;
    color: #a99bec;
    font-size: 11px;
    font-weight: 700;
}

.chat-topbar h1 {
    overflow: hidden;
    margin: 0;
    font-size: 17px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-actions {
    flex: 0 0 auto;
}

.rename-form {
    display: flex;
    gap: 7px;
}

.rename-form input {
    width: 190px;
    height: 36px;
    padding: 7px 10px;
    background: var(--surface);
}

.icon-action {
    display: grid;
    width: 36px;
    height: 36px;
    padding: 0;
    color: var(--muted);
    background: var(--surface-secondary);
    border: 1px solid var(--border);
    border-radius: 9px;
    cursor: pointer;
    place-items: center;
}

.icon-action:hover {
    color: var(--text);
    background: var(--surface-hover);
}

.icon-action-danger:hover {
    color: #ff8d8d;
    border-color: #663b3b;
}

.messages {
    min-height: 0;
    overflow-y: auto;
    padding: 32px max(24px, calc((100% - 860px) / 2));
    scrollbar-color: #363c47 transparent;
    scrollbar-width: thin;
}

.message {
    max-width: 760px;
    margin-bottom: 25px;
}

.message-user {
    margin-left: auto;
    padding: 13px 16px;
    color: #fff;
    background: linear-gradient(145deg, #6d51dd, #5940be);
    border: 1px solid #7b61e3;
    border-radius: 16px 16px 4px 16px;
}

.message-assistant {
    margin-right: auto;
    padding: 3px 2px;
}

.message-role {
    color: #a996ff;
}

.message-user .message-role {
    color: #ded7ff;
}

.message-content {
    color: var(--text);
    line-height: 1.65;
}

.message-links a {
    color: #baaaff;
    background: var(--surface-secondary);
}

.message-time {
    color: #7c8390;
}

.empty-chat {
    align-self: center;
    margin: 0 auto;
}

.composer-area {
    padding: 12px max(20px, calc((100% - 900px) / 2)) 18px;
    background: linear-gradient(transparent, var(--background) 24%);
}

.message-form {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 42px;
    align-items: end;
    gap: 9px;
    width: 100%;
    margin: 0;
    padding: 7px;
    background: #171a20;
    border: 1px solid #303641;
    border-radius: 17px;
    box-shadow: 0 12px 36px rgba(0, 0, 0, 0.22);
}

.message-form textarea {
    min-height: 42px;
    max-height: 180px;
    padding: 10px 11px;
    background: transparent;
    border: 0;
    box-shadow: none;
    resize: none;
}

.message-form textarea:focus {
    border: 0;
    box-shadow: none;
}

.send-button {
    display: grid;
    width: 42px;
    min-height: 42px;
    padding: 0;
    color: #fff;
    background: var(--primary);
    border: 0;
    border-radius: 12px;
    cursor: pointer;
    font-size: 22px;
    font-weight: 700;
    place-items: center;
}

.send-button:hover {
    background: var(--primary-hover);
}

.send-button:disabled {
    cursor: not-allowed;
    opacity: 0.55;
}

.send-error {
    min-height: 20px;
    padding-top: 3px;
}

.menu-toggle {
    display: none;
    width: 38px;
    height: 38px;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    margin-right: 10px;
    padding: 0;
    background: transparent;
    border: 0;
    border-radius: 9px;
}

.menu-toggle span {
    width: 18px;
    height: 2px;
    background: var(--text);
    border-radius: 2px;
}

.sidebar-overlay {
    display: none;
}

.admin-chat-layout {
    height: calc(100vh - var(--header-height));
    margin-top: var(--header-height);
}

@media (max-width: 850px) {
    .header {
        justify-content: flex-start;
        padding: 0 12px;
    }

    .menu-toggle {
        display: flex;
    }

    .navigation {
        margin-left: auto;
    }

    .user-workspace {
        display: block;
        min-width: 0;
    }

    .chat-sidebar {
        position: fixed;
        inset: var(--header-height) auto 0 0;
        z-index: 120;
        width: min(86vw, 310px);
        min-width: 0;
        transform: translateX(-105%);
        transition: transform 0.22s ease;
        box-shadow: 18px 0 50px rgba(0, 0, 0, 0.4);
    }

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

    .sidebar-close {
        display: block;
    }

    .sidebar-overlay {
        position: fixed;
        inset: var(--header-height) 0 0;
        z-index: 110;
        display: block;
        visibility: hidden;
        background: rgba(0, 0, 0, 0.62);
        opacity: 0;
        transition: 0.2s ease;
    }

    .sidebar-overlay.open {
        visibility: visible;
        opacity: 1;
    }

    body.sidebar-is-open {
        overflow: hidden;
    }

    .chat-main {
        width: 100%;
    }

    .chat-topbar {
        align-items: stretch;
        flex-direction: column;
        gap: 8px;
        padding: 10px 12px 11px;
    }

    .chat-title-wrap {
        width: 100%;
        flex: 1;
    }

    .chat-actions {
        width: 100%;
    }

    .rename-form {
        width: 100%;
        gap: 8px;
    }

    .rename-form input {
        display: block;
        width: auto;
        min-width: 0;
        flex: 1 1 auto;
    }

    .rename-form .icon-action {
        flex: 0 0 36px;
    }

    .messages {
        padding: 22px 13px;
    }

    .message {
        max-width: 92%;
    }

    .composer-area {
        padding: 8px 10px 11px;
    }

    .welcome-card {
        padding: 20px;
    }
}

@media (max-width: 480px) {
    .chat-actions {
        gap: 6px;
    }

    .icon-action {
        width: 34px;
        height: 34px;
    }

    .rename-form .icon-action {
        flex-basis: 34px;
    }

    .chat-topbar h1 {
        font-size: 15px;
    }

    .chat-model-badge {
        margin-top: 2px;
        font-size: 10px;
    }
}

/* Финальные компактные размеры сообщений (ПК и телефон) */
.message-user {
    margin-left: auto;
    padding: 8px 12px;
    color: #fff;
    background: #4f35b5;
    border: 1px solid #6045c7;
    border-radius: 13px 13px 3px 13px;
    line-height: 1.38;
}

.message-user .message-content {
    color: #fff;
    line-height: 1.38;
    white-space: pre-wrap;
}

.message-user .message-role,
.message-user .message-time {
    display: none;
}

.message-assistant .message-content {
    white-space: normal;
}

@media (max-width: 850px) {
    .message-user {
        max-width: 88%;
        padding: 7px 10px;
    }

    .message-image {
        min-height: 130px;
        border-radius: 11px;
    }
}

/* Панель чатов: прокручивается только список, не вся панель */
body:has(> .user-page) {
    height: 100dvh;
    overflow: hidden;
}

.user-page {
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
}

.user-workspace {
    height: calc(100dvh - var(--header-height));
    min-height: 0;
    overflow: hidden;
}

.chat-sidebar {
    align-self: stretch;
    height: calc(100dvh - var(--header-height));
    min-height: 0;
    overflow: hidden;
    overscroll-behavior: none;
}

.sidebar-user,
.new-chat-form,
.sidebar-section-title,
.sidebar-footer {
    min-height: max-content;
}

.sidebar-chat-list {
    height: 100%;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.chat-main {
    height: calc(100dvh - var(--header-height));
    min-height: 0;
    overflow: hidden;
}

@media (max-width: 850px) {
    .chat-sidebar {
        height: auto;
    }
}
