:root {
    --bg-primary: #0b0f0e;
    --bg-secondary: #111816;
    --bg-elevated: #161f1c;
    --bg-hover: #1c2824;
    --bg-input: #1e2623;
    --bg-input-hover: #232d29;
    --text-input: #e8f0ed;
    --text-input-muted: #8a9a94;
    --icon-input: #7d8f88;
    --border-subtle: rgba(255, 255, 255, 0.08);
    --border-strong: rgba(16, 163, 127, 0.35);
    --accent: #10a37f;
    --accent-bright: #2fd6a8;
    --accent-glow: rgba(16, 163, 127, 0.35);
    --accent-soft: rgba(16, 163, 127, 0.12);
    --text-primary: #e8f0ed;
    --text-secondary: #9fb3ac;
    --text-muted: #6b7f78;
    --danger: #e74c3c;
    --radius-lg: 16px;
    --radius-md: 12px;
    --radius-sm: 8px;
    --shadow-card: 0 8px 30px rgba(0, 0, 0, 0.35);
    --shadow-glow: 0 0 0 1px rgba(16, 163, 127, 0.25), 0 8px 30px rgba(16, 163, 127, 0.12);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

body {
    background-color: var(--bg-primary);
    background-image:
        radial-gradient(ellipse 80% 50% at 50% -10%, rgba(16, 163, 127, 0.12), transparent),
        radial-gradient(ellipse 60% 40% at 90% 110%, rgba(16, 163, 127, 0.08), transparent);
    background-attachment: fixed;
    color: var(--text-primary);
    height: 100vh;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
}

body::before {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) rotate(-30deg);
    font-size: 400px;
    font-weight: bold;
    font-family: 'Helvetica Neue', Arial, sans-serif;
    color: rgba(16, 163, 127, 0.04);
    pointer-events: none;
    z-index: -1;
    letter-spacing: 0.1em;
}

/* Глобальные стили скроллбара в тёмной теме */
html {
    scrollbar-width: thin;
    scrollbar-color: var(--bg-hover) transparent;
}

html::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

html::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

html::-webkit-scrollbar-thumb {
    background-color: var(--bg-hover);
    border-radius: 5px;
    border: 2px solid transparent;
    background-clip: content-box;
}

html::-webkit-scrollbar-thumb:hover {
    background-color: var(--accent);
    border: 2px solid transparent;
    background-clip: content-box;
}

html::-webkit-scrollbar-corner {
    background: var(--bg-primary);
}

.chat-container {
    flex: 1;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 24px;
    padding-bottom: 150px;
    margin: auto;
    width: 90%;
}

.chat-container-wrapper {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

@media (min-width: 900px) {
    .chat-container {
        width: 800px;
    }
}

.message {
    display: flex;
    flex-wrap: wrap;
    gap: 24px;
    max-width: 800px;
    margin: 0 auto;
    padding: 24px 0;
    width: 100%;
    overflow: hidden;
}

.user-message {
    background: linear-gradient(135deg, rgba(16, 163, 127, 0.18), rgba(16, 163, 127, 0.08));
    border: 1px solid rgba(16, 163, 127, 0.25);
    padding: 13px 24px;
    border-radius: 16px 16px 4px 16px;
    margin-right: auto;
    margin-left: 0;
    box-shadow: 0 4px 20px rgba(16, 163, 127, 0.08);
    backdrop-filter: blur(8px);
}

.assistant-message {
    background-color: transparent;
    color: var(--text-primary);
    overflow: visible;
}

.message-content {
    flex: 1;
    min-width: 0;
    line-height: 1.5;
    max-width: 100%;
}

.message-content p,
.message-content ul,
.message-content ol,
.message-content blockquote,
.message-content pre {
    max-width: 100%;
}

.message-content h1,
.message-content h2,
.message-content h3 {
    margin: 16px 0 8px 0;
    font-weight: 600;
}

.message-content h1 {
    font-size: 24px;
}

.message-content h2 {
    font-size: 20px;
}

.message-content h3 {
    font-size: 18px;
}

.message-content p {
    margin: 8px 0;
}

.message-content ul,
.message-content ol {
    margin: 8px 0;
    padding-left: 24px;
}

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

.message-content code {
    background-color: rgba(16, 163, 127, 0.12);
    color: var(--accent-bright);
    padding: 2px 6px;
    border-radius: 6px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.9em;
}

.message-content pre {
    background-color: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    padding: 14px;
    border-radius: var(--radius-md);
    overflow-x: auto;
    margin: 12px 0;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
}

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

.message-content blockquote {
    border-left: 3px solid var(--accent);
    padding-left: 16px;
    margin: 8px 0;
    color: var(--text-secondary);
    background: rgba(16, 163, 127, 0.05);
    border-radius: 0 8px 8px 0;
    padding: 8px 16px;
}

.message-content table {
    border-collapse: collapse;
    width: 100%;
    margin: 12px 0;
    display: block;
    overflow-x: auto;
}

.message-content th,
.message-content td {
    border: 1px solid var(--border-subtle);
    padding: 8px;
    text-align: left;
    max-width: 350px;
    position: relative;
}

.message-content th {
    background-color: var(--bg-elevated);
    font-weight: bold;
    color: var(--accent-bright);
}

.message-content tr {
    position: relative;
}

.message-content tr:nth-child(even) {
    background-color: rgba(255, 255, 255, 0.02);
}

.message-content a {
    color: #10a37f;
    text-decoration: none;
}

.message-content a:hover {
    text-decoration: underline;
}

.message-content img {
    max-width: 100%;
    border-radius: 8px;
}

.input-container {
    padding-bottom: 24px;
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(to top, var(--bg-primary) 70%, transparent);
    padding-top: 40px;
}

.initial-input-container {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 80%;
    max-width: 800px;
    height: 115px;
    background: transparent;
    padding-top: 0;
}

.model-selector {
    width: 150px;
    background: var(--bg-elevated);
    color: var(--text-primary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 12px 20px;
    font-size: 16px;
    margin-bottom: 0;
    outline: none;
    transition: all 0.3s ease;
    flex-shrink: 1;
}

.model-selector:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.input-box {
    max-width: 800px;
    margin: 0 auto;
    position: relative;
    border: 1px solid var(--border-subtle);
    corner-shape: superellipse(1.5);
    border-radius: 36px;
    background: var(--bg-input);
    display: flex;
    flex-direction: row;
    align-items: flex-end;
    gap: 8px;
    padding: 10px 12px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4), 0 0 0 1px rgba(255, 255, 255, 0.02);
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

.input-box:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft), 0 12px 40px rgba(0, 0, 0, 0.4), 0 0 30px rgba(16, 163, 127, 0.15);
}

.input-container:not(.initial-input-container) .input-box {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 10px;
}

/* На главной странице кнопки ввода выравниваем по центру */
.initial-input-container .input-box {
    align-items: center;
}

.initial-input-container .input-box textarea {
    flex: 1;
    min-width: 0;
}

.initial-input-container .model-selector-btn {
    flex-shrink: 0;
}

.input-container:not(.initial-input-container) .model-selector {
    margin-bottom: 0;
    width: auto;
    min-width: 100px;
    max-width: 150px;
}

.input-container:not(.initial-input-container) .input-box textarea {
    flex: 1;
    margin-bottom: 0;
    min-width: 100px;
}







.input-box textarea {
    width: 100%;
    background: transparent;
    color: var(--text-input);
    border: none;
    border-radius: 0;
    padding: 12px 8px;
    resize: none;
    min-height: 40px;
    max-height: 200px;
    outline: none;
    font-size: 16px;
    transition: none;
    box-shadow: none;
    position: relative;
    z-index: 1;
    line-height: 1.5;
}

.input-box textarea::placeholder {
    color: var(--text-input-muted);
    font-style: normal;
}

.attach-button {
    background: transparent;
    border: none;
    color: var(--icon-input);
    border-radius: 12px;
    width: 38px;
    height: 38px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
    transition: background 0.2s, color 0.2s;
}

.attach-button:hover {
    background: rgba(16, 163, 127, 0.15);
    color: var(--accent-bright);
}

/* Группа кнопок ввода (скрепка + микрофон) */
.input-actions {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

/* Кнопка "Ввод вручную" */
.manual-input-btn {
    background: transparent;
    border: none;
    color: var(--icon-input);
    border-radius: 12px;
    width: 38px;
    height: 38px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
    transition: background 0.2s, color 0.2s;
}

.manual-input-btn:hover {
    background: rgba(16, 163, 127, 0.15);
    color: var(--accent-bright);
}

/* Состояние записи: красная пульсация */
.manual-input-btn.recording {
    color: #e74c3c;
    background: rgba(231, 76, 60, 0.15);
    animation: mic-recording-pulse 1s ease-in-out infinite;
}

@keyframes mic-recording-pulse {
    0%, 100% {
        transform: scale(1);
        opacity: 1;
    }
    50% {
        transform: scale(1.12);
        opacity: 0.7;
    }
}

/* Состояние обработки: спиннер */
.manual-input-btn.loading {
    color: var(--accent-bright);
    animation: mic-loading-spin 0.8s linear infinite;
}

@keyframes mic-loading-spin {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

/* Кнопка-бутерброд и меню параметров разговора */
.conversation-menu-wrap {
    position: relative;
    flex-shrink: 0;
}

.conversation-menu-btn {
    background: transparent;
    border: none;
    color: var(--icon-input);
    border-radius: 12px;
    width: 38px;
    height: 38px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
    transition: background 0.2s, color 0.2s;
}

.conversation-menu-btn:hover {
    background: rgba(16, 163, 127, 0.15);
    color: var(--accent-bright);
}

.conversation-menu {
    position: absolute;
    bottom: calc(100% + 8px);
    right: 0;
    min-width: 260px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-card);
    padding: 8px;
    z-index: 100;
    backdrop-filter: blur(12px);
}

.conversation-menu-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 6px 10px 8px;
}

.conversation-menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 14px;
    color: var(--text-primary);
    user-select: none;
    transition: background 0.2s;
}

.conversation-menu-item[hidden] {
    display: none;
}

.conversation-menu-item:hover {
    background: var(--bg-hover);
}

.menu-item-icon {
    width: 18px;
    text-align: center;
    color: var(--accent);
    flex-shrink: 0;
    font-size: 14px;
}

.conversation-menu-checkbox {
    width: 16px;
    height: 16px;
    accent-color: var(--accent);
    cursor: pointer;
    flex-shrink: 0;
}

.conversation-menu-divider {
    height: 1px;
    background: var(--border-subtle);
    margin: 6px 4px;
}

.conversation-menu-attach {
    background: none;
    border: none;
    width: 100%;
    text-align: left;
    font-family: inherit;
}

.conversation-menu-attach:hover {
    background: var(--bg-hover);
}

.conversation-menu-call-llm {
    background: none;
    border: none;
    width: 100%;
    text-align: left;
    font-family: inherit;
    color: var(--accent-bright);
    font-weight: 600;
}

.conversation-menu-call-llm:hover {
    background: var(--bg-hover);
}

.marks-toggle {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    border-radius: 12px;
    width: 38px;
    height: 38px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
    transition: background 0.2s, color 0.2s;
}

.marks-toggle:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.marks-toggle.active {
    background: var(--accent);
    color: white;
    box-shadow: 0 0 12px var(--accent-glow);
}


.message-content li .line-checkbox-container {
    left: -83px;
}

.hidden-file-input {
    display: none;
}

.drop-placeholder {
    display: none;
    flex: 1;
    min-height: 56px;
    border: 2px dashed #10a37f;
    border-radius: 8px;
    color: #1a7f6e;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    background: rgba(16, 163, 127, 0.08);
}

.input-box.drag-active textarea {
    display: none;
}

.input-box.drag-active .drop-placeholder {
    display: flex;
}

.send-button {
    background: linear-gradient(135deg, var(--accent), #0d8c6c);
    color: white;
    border: none;
    border-radius: 50%;
    width: 38px;
    height: 38px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(16, 163, 127, 0.3);
    flex-shrink: 0;
    position: relative;
    z-index: 2;
    font-size: 15px;
}

.send-button:hover {
    background: linear-gradient(135deg, var(--accent-bright), var(--accent));
    transform: scale(1.08);
    box-shadow: 0 4px 16px rgba(16, 163, 127, 0.45);
}

.send-button:disabled {
    background: var(--bg-hover);
    color: var(--text-muted);
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.image-message .message-content {
    max-width: 420px;
    border-radius: 10px;
    padding: 8px;
}

.image-message.user-message {
    background: transparent;
    padding: 0;
    border-radius: 0;
}

.image-message.user-message .message-content {
    background: transparent;
    border: none;
    padding: 0;
}

.image-message.assistant-message .message-content {
    background: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
}

.chat-image {
    display: block;
    width: 100%;
    height: auto;
    border-radius: 8px;
}

.chat-image-wrap {
    position: relative;
}

.image-actions {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

.image-action-button {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border: 1px solid #d6d6d6;
    border-radius: 8px;
    background: #f6f6f6;
    color: #333;
    font-size: 12px;
    padding: 6px 10px;
    cursor: pointer;
}

.image-action-button svg {
    width: 14px;
    height: 14px;
    fill: currentColor;
}

.crop-selection {
    display: none;
    position: absolute;
    border: 2px dashed #10a37f;
    background: rgba(16, 163, 127, 0.15);
    pointer-events: none;
    z-index: 3;
}

.inline-crop-controls {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 8px;
}

.inline-crop-controls button {
    border: 1px solid #d0d0d0;
    background: #f2f2f2;
    color: #222;
    padding: 8px 12px;
    border-radius: 8px;
    cursor: pointer;
}

.inline-crop-controls [data-action="crop-confirm"],
.inline-crop-controls [data-action="rotate-confirm"] {
    background: #10a37f;
    border-color: #0d8c6c;
    color: #fff;
}

.image-message.crop-active .chat-image {
    cursor: crosshair;
    user-select: none;
    -webkit-user-drag: none;
}

.image-message.rotate-active .chat-image-wrap {
    overflow: visible;
    min-height: 260px;
}

.chat-image-rotating {
    transition: transform 0.15s ease;
    transform-origin: center center;
}

.user-image-actions .image-action-button {
    background: #5a5f74;
    border-color: #717792;
    color: #f0f2f7;
}

.message.pending .chat-image {
    opacity: 0.65;
}

.upload-status {
    margin-top: 8px;
    font-size: 12px;
    color: #d0d0d0;
}

.image-loading::after {
    content: attr(data-loading-text);
    display: block;
    margin-top: 8px;
    font-size: 12px;
    color: #555;
}

/* Sidebar styles */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 280px;
    height: 100vh;
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    box-shadow: 2px 0 20px rgba(0, 0, 0, 0.4);
    transition: transform 0.3s ease;
    border-right: 1px solid var(--border-subtle);
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
}

.sidebar-header h2 {
    font-size: 1.5rem;
    margin: 0;
    flex-grow: 1;
    display: flex;
    align-items: center;
    gap: 8px;
}

.sidebar-header-first-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    gap: 10px;
}

.sidebar-toggle {
    background: none;
    border: none;
    color: #ececf1;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 5px;
    border-radius: 4px;
    display: none;
}

.sidebar-toggle:hover {
    background-color: #444;
}

/* Десктоп: скрываем кнопку переключения сайдбара */
@media (min-width: 769px) {
    .sidebar-toggle {
        display: none !important;
    }
}

.new-chat-btn {
    background: linear-gradient(135deg, var(--accent), #0d8c6c);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    padding: 8px 16px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.3s ease;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    box-shadow: 0 2px 8px rgba(16, 163, 127, 0.3);
}

.new-chat-btn:hover {
    background: linear-gradient(135deg, var(--accent-bright), var(--accent));
    transform: scale(1.05);
    box-shadow: 0 4px 16px rgba(16, 163, 127, 0.45);
}

/* Стили для кнопки режима отметок в сайдбаре */
.sidebar-header .marks-toggle {
    background: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    color: var(--text-secondary);
}

.sidebar-header .marks-toggle:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.sidebar-header .marks-toggle.active {
    background: var(--accent);
    color: white;
    box-shadow: 0 0 12px var(--accent-glow);
}

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    scrollbar-width: thin;
    scrollbar-color: var(--bg-hover) transparent;
}

.sidebar-content::-webkit-scrollbar {
    width: 8px;
}

.sidebar-content::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar-content::-webkit-scrollbar-thumb {
    background-color: var(--bg-hover);
    border-radius: 4px;
    border: 2px solid transparent;
    background-clip: content-box;
}

.sidebar-content::-webkit-scrollbar-thumb:hover {
    background-color: var(--accent);
    border: 2px solid transparent;
    background-clip: content-box;
}

.conversation-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.conversation-list li {
    padding: 12px 16px;
    margin-bottom: 8px;
    background-color: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background-color 0.2s, border-color 0.2s;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conversation-list li:hover {
    background-color: var(--bg-hover);
    border-color: var(--border-strong);
}

.conversation-list li.active {
    background-color: var(--accent);
    color: white;
    font-weight: bold;
    box-shadow: 0 0 12px var(--accent-glow);
}

.main-content {
    margin-left: 280px;
    transition: margin-left 0.3s ease;
    height: 100vh;
    display: flex;
    flex-direction: column;
    position: relative;
}

/* Mobile styles */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        width: 260px;
    }

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

    .sidebar-toggle {
        display: block;
        position: fixed;
        top: 20px;
        left: 20px;
        z-index: 1001;
        background-color: #2d2d2d;
        border: 1px solid #444;
        padding: 10px;
        border-radius: 6px;
        width: 53px;
        
    }

    .main-content {
        margin-left: 0;
    }

    .sidebar-header h2 {
        font-size: 1.3rem;
    }

    .new-chat-btn {
        padding: 6px 12px;
        font-size: 0.8rem;
    }
}

@media (max-width: 768px) {
    .initial-input-container {
        width: 95%;
        display: flex;
        flex-direction: column;
        align-items: center;
    }

    .initial-input-container .input-box {
        flex-direction: column;
        align-items: stretch;
    }

    .initial-input-container .input-box textarea {
        flex: 0 1 auto;
    }

    .input-box {
        gap: 6px;
        padding: 6px;
        width: 100%;
    }

    .initial-input-container .model-selector {
        width: 40%;
        min-width: auto;
        max-width: none;
        margin-bottom: 10px;
        order: -1;
        margin-left: auto;
    }

    .input-container:not(.initial-input-container) .model-selector {
        display: none;
    }

    .initial-input-container .send-button {
        display: none;
    }

    .model-selector {
        width: 100%;
        font-size: 14px;
        padding: 8px 12px;
        min-width: auto;
        max-width: none;
    }

    .input-box textarea {
        padding: 12px 8px;
        font-size: 14px;
        min-height: 46px;
        min-width: 100px;
        width: 100%;
    }

    .send-button,
    .attach-button,
    .manual-input-btn {
        width: 32px;
        height: 32px;
    }

    .drop-placeholder {
        min-height: 46px;
        font-size: 14px;
    }
}

/* Agent section styles */
.agent-section {
    margin-bottom: 20px;
    border-bottom: 1px solid var(--border-subtle);
    padding-bottom: 15px;
}

/* Conversation heading */
.conversation-heading {
    font-size: 1.1rem;
    color: var(--text-primary);
    margin: 20px 0 10px 0;
    padding-bottom: 8px;
}

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

.agent-header h3 {
    font-size: 1.1rem;
    color: var(--text-primary);
    margin: 0;
}

.create-agent-btn {
    background: linear-gradient(135deg, var(--accent), #0d8c6c);
    color: white;
    border: none;
    border-radius: 50%;
    width: 30px;
    height: 30px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(16, 163, 127, 0.3);
}

.create-agent-btn:hover {
    background: linear-gradient(135deg, var(--accent-bright), var(--accent));
    transform: scale(1.1);
    box-shadow: 0 4px 16px rgba(16, 163, 127, 0.45);
}

.agent-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.agent-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    margin-bottom: 6px;
    background-color: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background-color 0.2s, border-color 0.2s;
}

.agent-item:hover {
    background-color: var(--bg-hover);
    border-color: var(--border-strong);
}

.agent-item.active {
    background-color: var(--accent);
    color: white;
    font-weight: bold;
    box-shadow: 0 0 12px var(--accent-glow);
}

.agent-item.active .agent-name {
    color: white;
}

.agent-name {
    flex: 1;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 0.9rem;
}

.agent-actions {
    display: flex;
    gap: 5px;
}

.agent-edit-btn,
.agent-delete-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.9rem;
    padding: 2px;
    border-radius: 3px;
    transition: color 0.2s, opacity 0.2s;
}

.agent-edit-btn {
    opacity: 0;
}

.agent-item:hover .agent-edit-btn,
.agent-item.active .agent-edit-btn {
    opacity: 1;
}

.agent-edit-btn:hover {
    color: var(--accent-bright);
}

.agent-delete-btn:hover {
    color: var(--danger);
}

.agent-empty {
    color: var(--text-muted);
    font-style: italic;
    font-size: 0.9rem;
    text-align: center;
    padding: 10px;
}

.agent-hidden {
    display: none;
}

.show-more-agents-btn {
    display: block;
    width: 100%;
    padding: 8px 12px;
    margin-top: 4px;
    background: transparent;
    border: 1px dashed var(--border-subtle);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
}

.show-more-agents-btn:hover {
    border-color: var(--accent);
    color: var(--accent-bright);
    background: var(--accent-soft);
}

/* Chat agent header (in open conversation) */
.chat-agent-header {
    text-align: center;
    padding: 20px 24px 8px;
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
    flex-shrink: 0;
}

.chat-agent-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.chat-agent-title {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--accent-bright);
    margin: 0;
    line-height: 1.3;
    text-shadow: 0 0 20px var(--accent-glow);
}

/* Selected agent header (on home page) */
.selected-agent-header {
    position: absolute;
    bottom: calc(100% + 20px);
    left: 50%;
    transform: translateX(-50%);
    text-align: center;
    max-width: 800px;
    width: 100%;
}

.selected-agent-label {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    margin-bottom: 5px;
}

.selected-agent-title {
    font-size: 3rem;
    font-weight: 900;
    color: var(--accent-bright);
    margin: 0;
    line-height: 1.2;
    text-shadow: 0 0 30px var(--accent-glow);
}

/* Modal styles */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.7);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s;
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal {
    background-color: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 500px;
    padding: 25px;
    box-shadow: var(--shadow-card);
    color: var(--text-primary);
}

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

.modal-header h3 {
    margin: 0;
    font-size: 1.3rem;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    transition: color 0.2s;
}

.modal-close:hover {
    color: var(--text-primary);
}

.modal-body {
    margin-bottom: 20px;
}

.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.form-control {
    width: 100%;
    padding: 10px 12px;
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 1rem;
    transition: border-color 0.3s, box-shadow 0.3s;
}

.form-control:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

textarea.form-control {
    min-height: 100px;
    resize: vertical;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.btn {
    padding: 10px 20px;
    border-radius: var(--radius-sm);
    border: none;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.3s ease;
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent), #0d8c6c);
    color: white;
    box-shadow: 0 2px 8px rgba(16, 163, 127, 0.3);
}

.btn-primary:hover {
    background: linear-gradient(135deg, var(--accent-bright), var(--accent));
    box-shadow: 0 4px 16px rgba(16, 163, 127, 0.45);
}

.btn-secondary {
    background: var(--bg-hover);
    color: var(--text-primary);
    border: 1px solid var(--border-subtle);
}

.btn-secondary:hover {
    background: var(--bg-elevated);
}

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

.btn-danger:hover {
    background: #c0392b;
}

/* Стили для чекбоксов отметок */
.line-checkbox {
    width: 16px;
    height: 16px;
    margin-right: 8px;
    margin-top: 4px;
    flex-shrink: 0;
}

.line-checkbox-container {
    position: absolute;
    left: -60px;
    top: 0;
    width: 16px;
    height: 16px;
}

.line-checkbox-container.hidden-checkbox {
    display: none;
}

.line-checkbox-container .line-checkbox:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

.message-content p,
.message-content li,
.message-content pre,
.message-content blockquote,
.message-content h1,
.message-content h2,
.message-content h3,
.message-content h4,
.message-content h5,
.message-content h6 {
    position: relative;
    min-height: 24px; /* чтобы чекбокс не вылезал */
    overflow: visible !important;
}

.line-wrapper {
    position: relative;
    overflow: visible !important;
}

/* Кнопка "Остановить стрим" */
.stop-stream-btn {
    display: none;
    align-items: center;
    justify-content: center;
    gap: 4px;
    background: var(--danger);
    color: white;
    border: none;
    border-radius: 12px;
    padding: 8px 14px;
    font-size: 14px;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.2s, box-shadow 0.2s;
    white-space: nowrap;
    box-shadow: 0 2px 8px rgba(231, 76, 60, 0.3);
}

.stop-stream-btn:hover {
    background: #c0392b;
    box-shadow: 0 4px 16px rgba(231, 76, 60, 0.45);
}

.stop-stream-btn:active {
    background: #a93226;
}

/* Model selector button */
.model-selector-btn {
    background: var(--bg-input-hover);
    color: var(--text-input);
    border: 1px solid var(--border-subtle);
    border-radius: 12px;
    padding: 8px 14px;
    font-size: 14px;
    cursor: pointer;
    outline: none;
    transition: all 0.3s ease;
    flex-shrink: 1;
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
    max-width: 280px;
}

.model-selector-btn:hover {
    border-color: var(--accent);
    background: var(--bg-hover);
}

.model-selector-btn:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.model-btn-icon {
    color: var(--accent-bright);
    font-size: 13px;
    flex-shrink: 0;
}

.model-selector-btn .model-btn-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

.model-selector-btn .model-btn-arrow {
    font-size: 10px;
    color: var(--text-input-muted);
    flex-shrink: 0;
}

/* Model dropdown (replaces modal overlay) */
.model-dropdown {
    position: fixed;
    z-index: 3000;
    background: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-card);
    width: 380px;
    display: none;
    flex-direction: column;
    overflow: hidden;
}

.model-dropdown.active {
    display: flex;
}

.model-dropdown-header {
    display: flex;
    align-items: center;
    padding: 8px 12px 0 12px;
    gap: 8px;
    border-bottom: 1px solid var(--border-subtle);
}

.model-dropdown-header .model-tabs {
    display: flex;
    flex: 1;
    gap: 0;
}

.model-dropdown-header .model-tab {
    padding: 8px 16px;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 13px;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: color 0.2s, border-color 0.2s;
    font-family: inherit;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.model-dropdown-header .model-tab:hover {
    color: var(--text-primary);
}

.model-dropdown-header .model-tab.active {
    color: var(--accent-bright);
    border-bottom-color: var(--accent);
}

.model-dropdown-header .modal-close {
    flex-shrink: 0;
    font-size: 20px;
}

.model-search-input {
    padding: 10px 40px 10px 36px !important;
    font-size: 14px !important;
    border-radius: var(--radius-sm) !important;
    background-color: var(--bg-secondary) !important;
    border: 1px solid var(--border-subtle) !important;
}

.model-search-input:focus {
    border-color: var(--accent) !important;
}

/* Кнопка сортировки внутри поиска модели */
.model-sort-btn {
    position: absolute;
    right: 24px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 2;
    width: 28px;
    height: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: var(--radius-sm);
    background: none;
    color: var(--text-muted);
    font-size: 13px;
    cursor: pointer;
    transition: color 0.15s, background-color 0.15s;
}

.model-sort-btn:hover {
    color: var(--accent-bright);
    background-color: var(--bg-hover);
}

.model-sort-btn[data-mode="price"] {
    color: var(--accent-bright);
}

.model-search-wrap::before {
    content: '\f002';
    font-family: 'Font Awesome 6 Free';
    font-weight: 900;
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 13px;
    color: var(--text-muted);
    z-index: 1;
    pointer-events: none;
}

.model-list-wrap {
    overflow-y: auto;
    max-height: 320px;
    padding: 4px 8px 8px 8px;
}

.model-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.model-list-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    cursor: pointer;
    transition: background-color 0.15s;
    border-radius: var(--radius-sm);
}

.model-list-item:hover {
    background-color: var(--bg-hover);
}

.model-list-item.selected {
    background-color: var(--accent-soft);
}

.model-list-item .model-item-name {
    font-size: 13px;
    color: var(--text-primary);
    font-weight: 500;
}

.model-list-item .model-item-provider {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 1px;
}

.model-list-item .model-item-right {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
    margin-left: 8px;
}

.model-list-item .model-item-check {
    color: var(--accent-bright);
    font-size: 14px;
    flex-shrink: 0;
}

.model-list-item .model-item-price {
    position: relative;
    font-size: 10px;
    line-height: 1;
    color: var(--text-muted);
    white-space: nowrap;
    cursor: default;
    padding: 1px 0;
}

/* Всплывашка с полной стоимостью: вход$->выход$ */
.model-list-item .model-item-price::after {
    content: attr(data-tooltip);
    position: absolute;
    left: 50%;
    bottom: calc(100% + 6px);
    transform: translateX(-50%);
    background: var(--bg-elevated, #1e293b);
    color: var(--text-primary, #e2e8f0);
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 11px;
    white-space: nowrap;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.15s ease, visibility 0.15s ease;
    z-index: 20;
    pointer-events: none;
}

.model-list-item .model-item-price:hover::after,
.model-list-item .model-item-price:focus::after {
    opacity: 1;
    visibility: visible;
}

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

.model-list-custom {
    padding: 8px 12px;
    cursor: pointer;
    transition: background-color 0.15s;
    border-radius: var(--radius-sm);
    background: var(--accent-soft);
}

.model-list-custom:hover {
    background-color: rgba(16, 163, 127, 0.2);
}

.model-list-custom .model-item-name {
    font-size: 13px;
    color: var(--accent-bright);
    font-weight: 600;
}

.model-list-custom .model-item-provider {
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 1px;
}

/* Responsive for model selector button */
@media (max-width: 768px) {
    .model-selector-btn {
        width: 100%;
        max-width: none;
        font-size: 14px;
        padding: 8px 12px;
    }

    .input-container:not(.initial-input-container) .model-selector-btn {
        display: none;
    }

    .initial-input-container .model-selector-btn {
        width: fit-content;
        min-width: auto;
        max-width: 100%;
        margin-bottom: 10px;
        order: -1;
        margin-left: auto;
        flex-shrink: 0;
    }

    .model-dropdown {
        width: calc(100vw - 32px) !important;
        left: 16px !important;
    }
}

/* === Кнопка редактирования сообщения ассистента === */

.message-actions-bar {
    display: flex;
    gap: 4px;
    margin-top: 12px;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.assistant-message:hover .message-actions-bar {
    opacity: 1;
}

.message-action-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    background: var(--bg-elevated);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 14px;
}

.message-action-btn:hover {
    background: var(--bg-hover);
    color: var(--accent-bright);
    border-color: var(--accent);
}

.message-action-btn svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
}

/* Режим редактирования */

.edit-message-editor {
    width: 100%;
    min-height: 100px;
    padding: 12px;
    border: 1px solid var(--accent);
    border-radius: var(--radius-md);
    font-size: 14px;
    line-height: 1.6;
    font-family: 'Inter', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    outline: none;
    background: var(--bg-elevated);
    color: var(--text-primary);
    box-shadow: 0 0 0 3px var(--accent-soft);
    transition: border-color 0.2s;
    overflow-y: auto;
}

.edit-message-editor:focus {
    border-color: var(--accent-bright);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.edit-message-editor p {
    margin: 4px 0;
}

.edit-message-editor ul,
.edit-message-editor ol {
    padding-left: 24px;
    margin: 4px 0;
}

.edit-message-editor pre {
    background: var(--bg-secondary);
    padding: 8px;
    border-radius: var(--radius-sm);
    margin: 8px 0;
    overflow-x: auto;
}

.edit-message-editor code {
    background: var(--bg-secondary);
    padding: 1px 4px;
    border-radius: 3px;
    font-family: monospace;
    font-size: 13px;
}

.edit-message-editor blockquote {
    border-left: 3px solid var(--accent);
    padding-left: 12px;
    margin: 8px 0;
    color: var(--text-secondary);
}

.edit-message-editor table {
    border-collapse: collapse;
    width: 100%;
    margin: 8px 0;
}

.edit-message-editor th,
.edit-message-editor td {
    border: 1px solid var(--border-subtle);
    padding: 6px 8px;
    text-align: left;
}

.edit-message-editor th {
    background: var(--bg-secondary);
    font-weight: 600;
}

.edit-message-actions {
    display: flex;
    gap: 8px;
    margin-top: 10px;
}

.save-edit-btn,
.cancel-edit-btn {
    all: unset;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    border-radius: 6px;
    padding: 4px 14px;
    font-size: 13px;
    line-height: 1;
    height: 28px;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.save-edit-btn {
    background: linear-gradient(135deg, var(--accent), #0d8c6c);
    color: white;
    border: none;
}

.save-edit-btn:hover {
    background: linear-gradient(135deg, var(--accent-bright), var(--accent));
}

.save-edit-btn:disabled {
    background: linear-gradient(135deg, #cccccc, #aaaaaa);
    cursor: not-allowed;
}

.cancel-edit-btn {
    background: var(--bg-hover);
    color: var(--text-primary);
    border: 1px solid var(--border-subtle);
}

.cancel-edit-btn:hover {
    background: var(--bg-elevated);
}

/* Скрываем панель действий во время редактирования */
.message.editing .message-actions-bar {
    display: none;
}

/* === Настройки агента (toggle switches) === */

.agent-settings {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 8px;
}

label.setting-toggle {
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    padding: 8px 0;
    user-select: none;
    width: 100%;
}

.setting-toggle input[type="checkbox"] {
    display: none;
}

.toggle-slider {
    position: relative;
    width: 36px;
    height: 20px;
    background: var(--bg-hover);
    border: 1px solid var(--border-subtle);
    border-radius: 10px;
    transition: background 0.2s;
    flex-shrink: 0;
}

.toggle-slider::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    background: var(--text-primary);
    border-radius: 50%;
    transition: transform 0.2s;
}

.setting-toggle input:checked + .toggle-slider {
    background: var(--accent);
    box-shadow: 0 0 8px var(--accent-glow);
}

.setting-toggle input:checked + .toggle-slider::after {
    transform: translateX(16px);
}

.setting-text {
    font-size: 0.9rem;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.settings-label {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-top: 8px;
    display: block;
}

/* === Settings bar (отображение настроек под input) === */

.agent-settings-bar {
    max-width: 800px;
    margin: 8px auto 0;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    justify-content: center;
}

.settings-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    background: var(--accent-soft);
    border: 1px solid var(--border-strong);
    border-radius: 20px;
    font-size: 0.8rem;
    color: var(--accent-bright);
    white-space: nowrap;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s, opacity 0.2s;
    font-family: inherit;
    line-height: inherit;
}

/* === Табы внутри дропдауна моделей === */

.model-tab-content {
    display: none;
    flex-direction: column;
}

.model-tab-content.active {
    display: flex;
}

.model-search-wrap {
    padding: 8px 12px;
    position: relative;
}

.model-search-wrap::before {
    content: '\f002';
    font-family: 'Font Awesome 6 Free';
    font-weight: 900;
    position: absolute;
    left: 24px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 14px;
    color: var(--text-muted);
    pointer-events: none;
    z-index: 1;
}

.model-list-wrap {
    overflow-y: auto;
    max-height: 300px;
}

.settings-badge:hover {
    background: rgba(16, 163, 127, 0.25);
    border-color: rgba(16, 163, 127, 0.5);
}

.settings-badge[data-enabled="false"] {
    background: rgba(85, 85, 85, 0.15);
    border-color: rgba(85, 85, 85, 0.25);
    color: var(--text-muted);
    opacity: 0.7;
}

.settings-badge[data-enabled="false"]:hover {
    background: rgba(85, 85, 85, 0.3);
    border-color: rgba(85, 85, 85, 0.45);
    opacity: 1;
}

/* === Источники (citations) === */
.message-citations {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    flex-basis: 100%;
    width: 100%;
}

.citation-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: var(--radius-sm);
    background: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    overflow: hidden;
    text-decoration: none;
    transition: background 0.2s, border-color 0.2s, transform 0.2s;
}

.citation-link:hover {
    background: var(--accent-soft);
    border-color: var(--accent);
    transform: translateY(-1px);
}

.citation-favicon {
    width: 18px;
    height: 18px;
    object-fit: contain;
    border-radius: 3px;
}

.citation-fallback {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    font-size: 12px;
    font-weight: 600;
    color: var(--accent-bright);
    background: var(--accent-soft);
    border-radius: 3px;
}

/* Инлайн-иконки источников, встроенные прямо в текст на месте цитаты */
.citation-sup {
    display: inline-block;
    margin: 0 2px;
    vertical-align: super;
    line-height: 0;
    font-size: 0;
}

.citation-sup a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    border-radius: var(--radius-sm);
    background: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    color: var(--accent-bright);
    font-size: 11px;
    font-weight: 600;
    line-height: 1;
    text-decoration: none;
    vertical-align: middle;
    transition: background 0.2s, border-color 0.2s;
}

.citation-sup a:hover {
    background: var(--accent-soft);
    border-color: var(--accent);
}
