:root {
    --bg: #1e1e2e;
    --surface: #282840;
    --surface2: #313150;
    --border: #3e3e5e;
    --text: #e0e0e8;
    --text2: #a0a0b8;
    --accent: #7c6ef0;
    --accent2: #5a4fd4;
    --green: #50c878;
    --orange: #f0a050;
    --red: #f06060;
    --chat-user: #3a3a5a;
    --chat-ai: #2a2a48;
}

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

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ═══ TOP BAR ═══ */
.topbar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    min-height: 48px;
    flex-shrink: 0;
}
.topbar .logo {
    font-weight: 700;
    font-size: 18px;
    color: var(--accent);
    margin-right: 8px;
}

.mode-switch {
    display: flex;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--border);
}
.mode-btn {
    padding: 6px 16px;
    border: none;
    background: transparent;
    color: var(--text2);
    cursor: pointer;
    font-size: 13px;
    transition: all 0.2s;
}
.mode-btn.active {
    background: var(--accent);
    color: white;
}
.mode-btn:hover:not(.active) {
    background: var(--surface2);
}

.provider-badge {
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    border: 1px solid var(--border);
}
.provider-badge.anthropic { background: #3a2a1a; color: #f0b060; border-color: #5a4a3a; }
.provider-badge.gemini { background: #1a2a3a; color: #60b0f0; border-color: #3a4a5a; }
.provider-badge.openrouter { background: #1a3a2a; color: #60f0b0; border-color: #3a5a4a; }

.model-select {
    padding: 5px 10px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--surface2);
    color: var(--text);
    font-size: 13px;
    cursor: pointer;
    max-width: 280px;
}

.topbar-actions {
    margin-left: auto;
    display: flex;
    gap: 8px;
    align-items: center;
}
.topbar-btn {
    padding: 6px 12px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text2);
    cursor: pointer;
    font-size: 13px;
    transition: all 0.2s;
}
.topbar-btn:hover { background: var(--surface2); color: var(--text); }

.project-path {
    font-size: 12px;
    color: var(--text2);
    /* max-width: 300px; */
    flex-grow: 1;
    min-width: 100px;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    /* word-break: break-all;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden; */
}

/* ═══ MAIN AREA ═══ */
.main {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* ═══ SIDEBAR (FILES) ═══ */
.sidebar {
    width: 260px;
    min-width: 40px;
    max-width: 500px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    position: relative;
    z-index: 50; /* Понижаем z-index сайдбара, чтобы он не перекрывал модалки */
    transition: width 0.2s;
}
.sidebar.collapsed { width: 40px !important; min-width: 40px; overflow: hidden; }
.sidebar.collapsed .file-tree { display: none; }
.sidebar.collapsed .sidebar-header span { display: none; }
.sidebar.collapsed .sidebar-header .refresh-btn { display: none; }
.sidebar.collapsed .sidebar-header { justify-content: center; padding: 10px 0; }
.sidebar.collapsed .resize-handle { display: none; }
.sidebar.collapsed .sidebar-separator { display: none; }
.sidebar.collapsed .external-header { display: none; }
.sidebar.collapsed .external-tree { display: none; }
.sidebar-header {
    padding: 10px 7px;
    font-weight: 600;
    font-size: 13px;
    color: var(--text2);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 6px;
}
.sidebar-header button {
    background: none;
    border: none;
    color: var(--text2);
    cursor: pointer;
    font-size: 14px;
}
.sidebar-header button:hover { color: var(--text); }

.file-tree {
    flex: 1;
    overflow-y: auto;
    padding: 4px 0;
}
.file-item {
    padding: 3px 7px;
    font-size: 13px;
    cursor: pointer;
    display: flex;
    align-items: flex-start;
    gap: 3px;
    color: var(--text2);
    flex-wrap: wrap;
}
.file-item:hover { background: var(--surface2); color: var(--text); }
.file-item.active { background: var(--accent); color: white; }
.file-item.dir { color: var(--orange); font-weight: 500; }
.file-item .icon { font-size: 12px; flex-shrink: 0; margin-top: 2px; }
.file-item .fsize { color: var(--text2); font-size: 10px; margin-left: auto; flex-shrink: 0; }
.file-item.active .fsize { color: rgba(255,255,255,0.7); }
.file-item .arrow { font-size: 10px; width: 12px; text-align: center; flex-shrink: 0; color: var(--text2); margin-top: 2px; }
.file-item .fname { word-break: break-word; white-space: normal; min-width: 0; }

/* ═══ RESIZE HANDLES ═══ */
.resize-handle {
    width: 4px;
    cursor: col-resize;
    background: transparent;
    position: absolute;
    top: 0;
    bottom: 0;
    right: -2px;
    z-index: 20;
    transition: background 0.2s;
}
.resize-handle:hover, .resize-handle.active { background: var(--accent); }

/* ═══ FILE PREVIEW PANEL ═══ */
.preview-panel {
    width: 0;
    min-width: 0;
    background: var(--bg);
    border-right: 1px solid var(--border);
    display: none;
    flex-direction: column;
    flex-shrink: 0;
    position: relative;
    overflow: hidden;
}
.preview-panel.open {
    display: flex;
    min-width: 200px;
    max-width: 800px;
}
.preview-header {
    padding: 8px 12px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text2);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.preview-header .close-btn {
    background: none;
    border: none;
    color: var(--text2);
    cursor: pointer;
    font-size: 16px;
    padding: 0 4px;
}
.preview-header .close-btn:hover { color: var(--red); }
.preview-content {
    flex: 1;
    overflow: auto;
    padding: 12px;
    font-family: 'Cascadia Code', 'Consolas', monospace;
    font-size: 13px;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
    color: var(--text);
}
.preview-binary {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 100%;
    color: var(--text2);
    font-size: 14px;
}
.preview-binary .bigicon { font-size: 48px; }

/* ═══ CHAT AREA ═══ */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    min-width: 300px;
}

.messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.msg {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-word;
    min-width: 200px;
    position: relative;
}
.msg.user {
    align-self: flex-end;
    background: var(--chat-user);
    border-bottom-right-radius: 4px;
    padding-bottom: 28px;
    min-width: 140px; /* Чтобы кнопки не уплывали при коротком тексте */
}
.msg.ai {
    align-self: flex-start;
    background: var(--chat-ai);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
    padding-bottom: 12px;
    min-width: 140px; /* Чтобы кнопки не уплывали при коротком тексте */
}
.msg.system {
    align-self: center;
    color: var(--text2);
    font-size: 12px;
    font-style: italic;
    margin: 4px 0;
}

/* ═══ COST INFO ═══ */
.cost-info {
    margin-top: 8px;
    padding-top: 6px;
    border-top: 1px solid var(--border);
    text-align: left;
    font-size: 11px;
    color: var(--orange);
    opacity: 0.85;
    font-family: 'Segoe UI', monospace;
    padding-right: 70px;
    position: relative;
    cursor: pointer;
}
.cost-info:hover { opacity: 1; }
.cost-tooltip {
    display: none;
    position: absolute;
    bottom: calc(100% + 6px);
    left: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px 16px;
    font-size: 11px;
    color: var(--text);
    white-space: pre;
    z-index: 100;
    min-width: 320px;
    max-width: 420px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.5);
    line-height: 1.6;
    font-family: 'Segoe UI', monospace;
    pointer-events: auto;
}
.cost-info:hover .cost-tooltip { display: block; }
.cost-tooltip .tt-header { color: var(--accent); font-weight: 600; margin-bottom: 4px; }
.cost-tooltip .tt-row { display: flex; justify-content: space-between; gap: 16px; }
.cost-tooltip .tt-label { color: var(--text2); }
.cost-tooltip .tt-value { color: var(--text); text-align: right; }
.cost-tooltip .tt-sep { border-top: 1px solid var(--border); margin: 4px 0; }
.cost-tooltip .tt-total { color: var(--orange); font-weight: 600; }

/* ═══ EXTERNAL FILES ═══ */
.sidebar-separator {
    height: 5px;
    border: none;
    border-top: 1px solid var(--border);
    margin: 0;
    cursor: row-resize;
    background: transparent;
    flex-shrink: 0;
    transition: background 0.2s;
}
.sidebar-separator:hover, .sidebar-separator.active {
    background: var(--accent);
}
.external-header {
    padding: 6px 7px;
    font-weight: 600;
    font-size: 12px;
    color: var(--text2);
    display: flex;
    align-items: center;
    gap: 6px;
}
.external-header button {
    background: none;
    border: none;
    color: var(--text2);
    cursor: pointer;
    font-size: 12px;
}
.external-header button:hover { color: var(--text); }
.import-btn {
    padding: 4px 8px;
    font-size: 11px;
    color: var(--accent);
    background: none;
    border: 1px solid var(--accent);
    border-radius: 4px;
    cursor: pointer;
    margin-left: auto;
}
.import-btn:hover { background: var(--accent); color: white; }
.external-tree {
    flex: 1;
    overflow-y: auto;
    padding: 2px 0;
    min-height: 40px;
}

/* ═══ TYPING INDICATOR ═══ */
.typing-indicator {
    align-self: flex-start;
    color: var(--text2);
    font-size: 13px;
    padding: 10px 16px;
    display: none;
    align-items: center;
    gap: 5px;
    position: relative;
}
.typing-indicator.visible { display: flex; }
.typing-timer {
    font-size: 11px;
    color: var(--orange);
    margin-left: 5px;
    font-family: monospace;
    font-variant-numeric: tabular-nums;
}
.stop-btn {
    margin-left: 10px;
    background: rgba(255, 60, 60, 0.15);
    border: 1px solid rgba(255, 60, 60, 0.3);
    color: #ff5f5f;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 10px;
    transition: all 0.2s;
    font-weight: bold;
}
.stop-btn:hover {
    background: #ff3c3c;
    color: white;
    border-color: #ff3c3c;
    box-shadow: 0 0 10px rgba(255, 60, 60, 0.4);
}
.typing-dot {
    width: 6px; height: 6px;
    border-radius: 50%;
    background: var(--accent);
    animation: typingBounce 1.4s infinite ease-in-out both;
}
.typing-dot:nth-child(1) { animation-delay: 0s; }
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes typingBounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

/* ═══ INPUT ═══ */
.bottom-input-wrapper {
    display: flex;
    flex-direction: column;
    border-top: 1px solid var(--border);
    background: var(--surface);
    transition: all 0.2s;
}
.bottom-input-wrapper.drop-zone-active {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
    background: var(--surface2);
}

.input-area {
    padding: 12px 16px;
    display: flex;
    gap: 10px;
    align-items: flex-end;
}
.input-area textarea {
    flex: 1;
    padding: 10px 14px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    font-family: inherit;
    font-size: 14px;
    resize: none;
    min-height: 44px;
    max-height: 200px;
    line-height: 1.5;
}
.input-area textarea:focus {
    outline: none;
    border-color: var(--accent);
}
.input-area textarea::placeholder { color: var(--text2); }

.send-btn {
    padding: 10px 20px;
    border-radius: 10px;
    border: none;
    background: var(--accent);
    color: white;
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.2s;
    flex-shrink: 0;
}
.send-btn:hover { background: var(--accent2); }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.estimate-btn {
    background: var(--surface2);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 10px 14px;
    border-radius: 10px;
    cursor: pointer;
    font-size: 16px;
    transition: all 0.2s;
    flex-shrink: 0;
}
.estimate-btn:hover { background: var(--accent); color: white; border-color: var(--accent); }

/* ═══ ESTIMATE MODAL ═══ */
.estimate-modal {
    width: 500px;
}
.estimate-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 10px;
}
.estimate-table th {
    text-align: left;
    font-size: 12px;
    color: var(--text2);
    padding: 8px;
    border-bottom: 1px solid var(--border);
}
.estimate-table td {
    padding: 5px 8px;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
}
.est-model { font-weight: 600; color: var(--text); }
.est-prov { font-size: 11px; color: var(--text2); }
.est-price-cheap { color: var(--green); font-weight: 600; }
.est-price-expensive { color: var(--orange); font-weight: 600; }

.estimate-time-header {
    font-size: 12px;
    color: var(--red);
    font-weight: 600;
    text-align: right;
}

.ai-recommendation {
    background: rgba(var(--accent-rgb), 0.1);
    border: 1px solid var(--accent);
    border-radius: 8px;
    padding: 6px 12px;
    margin-bottom: 8px;
    font-size: 13px;
    line-height: 1.5;
    color: var(--text);
}
.btn-ai-advice {
    background: transparent;
    border: 1px solid var(--accent);
    color: var(--accent);
    padding: 8px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    margin-right: auto;
    transition: all 0.2s;
}
.btn-ai-advice:hover {
    background: var(--accent);
    color: white;
}
.btn-ai-advice:disabled {
    opacity: 0.5;
    cursor: wait;
}
.estimate-disclaimer {
    margin-top: 16px;
    font-size: 11px;
    color: var(--text2);
    font-style: italic;
    line-height: 1.4;
}

/* ═══ BOTTOM MODE SWITCH ═══ */
.mode-switch-bottom {
    display: flex;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--border);
    flex-shrink: 0;
}
.mode-btn-bottom {
    width: 38px;
    height: 38px;
    border: none;
    background: transparent;
    color: var(--text2);
    cursor: pointer;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    line-height: 1;
}
.mode-btn-bottom.active {
    background: var(--accent);
    color: white;
}
.mode-btn-bottom:hover:not(.active) {
    background: var(--surface2);
}

/* ═══ SETTINGS MODAL ═══ */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    z-index: 100;
    justify-content: center;
    align-items: center;
}
.modal-overlay.visible { display: flex; }
.modal {
    background: var(--surface);
    border-radius: 16px;
    border: 1px solid var(--border);
    padding: 0;
    width: 620px;
    max-width: 92vw;
    max-height: 88vh;
    display: flex;
    flex-direction: column;
}
.modal-header {
    padding: 18px 24px 0 24px;
    display: flex;
    align-items: center;
    gap: 10px;
}
.modal-header h2 {
    font-size: 18px;
    color: var(--accent);
}

.tabs {
    display: flex;
    gap: 0;
    padding: 14px 24px 0 24px;
    border-bottom: 1px solid var(--border);
}
.tab-btn {
    padding: 8px 18px;
    border: none;
    background: transparent;
    color: var(--text2);
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active {
    color: #fff;
    border-bottom: 2px solid var(--accent-color);
    background-color: rgba(255, 255, 255, 0.05);
}
.tab-content {
    display: none;
    padding: 20px 24px;
    overflow-y: auto;
    flex: 1;
}
.tab-content.active { display: block; }
.modal label {
    display: block;
    font-size: 13px;
    color: var(--text2);
    margin-bottom: 4px;
    margin-top: 14px;
}
.modal label:first-child { margin-top: 0; }
.modal input[type="text"],
.modal input[type="password"],
.modal input[type="number"] {
    width: 100%;
    padding: 8px 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    font-family: inherit;
}
.modal input:focus { outline: none; border-color: var(--accent); }
.modal select {
    width: 100%;
    padding: 8px 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    cursor: pointer;
}
.provider-select-row { display: flex; gap: 8px; margin-bottom: 16px; }
.provider-card {
    flex: 1; padding: 10px; border-radius: 10px;
    border: 2px solid var(--border); background: var(--bg);
    cursor: pointer; text-align: center; transition: all 0.2s;
}
.provider-card:hover { border-color: var(--accent); }
.provider-card.selected { border-color: var(--accent); background: var(--surface2); }
.provider-card .prov-name { font-weight: 600; font-size: 14px; }
.provider-card .prov-hint { font-size: 11px; color: var(--text2); margin-top: 2px; }
.test-row { display: flex; gap: 10px; align-items: center; margin-top: 16px; }
.test-btn {
    padding: 8px 20px; border-radius: 8px; border: 1px solid var(--border);
    background: var(--surface2); color: var(--text); cursor: pointer;
    font-size: 13px; white-space: nowrap; transition: all 0.2s;
}
.test-btn:hover { background: var(--accent); color: white; border-color: var(--accent); }
.test-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.test-result {
    font-size: 13px; padding: 6px 12px; border-radius: 6px; flex: 1;
    white-space: pre-wrap; word-break: break-word;
}
.test-result.ok { background: #1a3a1a; color: var(--green); }
.test-result.fail { background: #3a1a1a; color: var(--red); }
.test-result.loading { color: var(--text2); font-style: italic; }
.modal-footer {
    padding: 14px 24px; border-top: 1px solid var(--border);
    display: flex; justify-content: flex-end; gap: 10px;
}
.modal-footer button { padding: 8px 22px; border-radius: 8px; border: none; cursor: pointer; font-size: 14px; }
.btn-save { background: var(--accent); color: white; }
.btn-save:hover { background: var(--accent2); }
.btn-cancel { background: var(--surface2); color: var(--text); border: 1px solid var(--border) !important; }

/* ═══ SCROLLBAR ═══ */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ═══ MSG ACTION BUTTONS (INSIDE BUBBLE) ═══ */
.msg.ai {
    position: relative;
    padding-top: 14px;
    padding-bottom: 14px;
}
.msg.user {
    position: relative;
    padding-bottom: 14px;
}
.msg.error {
    align-self: center;
    background: var(--red);
    color: white;
    font-size: 13px;
    padding: 8px 16px;
    margin: 4px 0;
}
.msg-actions-inner {
    position: absolute;
    display: flex;
    gap: 4px;
    align-items: center;
    opacity: 0;
    transition: opacity 0.2s;
    z-index: 2;
    padding: 2px 0;
    background: transparent;
    border-radius: 6px;
}
.msg.ai:hover .msg-actions-inner { opacity: 1; }
.msg.user:hover .msg-actions-inner { opacity: 1; }
.msg-actions-inner.top-right { top: 4px; right: 8px; }
.msg-actions-inner.bottom-right { bottom: 4px; right: 8px; .msg.user .msg-actions-inner.bottom-right,
.msg.ai .msg-actions-inner.bottom-right {
    position: absolute;
    bottom: 4px;
    right: 8px;
    display: flex;
}

.setting-row {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-top: 15px;
}

.setting-row label {
    flex-basis: 200px;
}

.setting-row input[type="range"] {
    flex: 1;
}   align-items: center;
}
.action-btn {
    width: 24px; height: 24px; border-radius: 5px;
    border: 1px solid var(--border); background: var(--surface2);
    color: var(--text2); cursor: pointer; font-size: 12px;
    display: flex; align-items: center; justify-content: center;
    transition: all 0.2s; line-height: 1; flex-shrink: 0;
}
.action-btn:hover { background: var(--accent); color: white; border-color: var(--accent); }
.copied-label {
    font-size: 10px; color: var(--green); font-weight: 600;
    opacity: 0; transition: opacity 0.3s; white-space: nowrap;
}
.copied-label.visible { opacity: 1; }

/* ═══ SCROLL TO BOTTOM ═══ */
.scroll-bottom-btn {
    position: absolute; bottom: 80px; right: 24px;
    width: 36px; height: 36px; border-radius: 50%;
    border: 1px solid var(--border); background: var(--surface);
    color: var(--text); cursor: pointer; font-size: 18px;
    display: none; align-items: center; justify-content: center;
    z-index: 10; box-shadow: 0 2px 8px rgba(0,0,0,0.3); transition: all 0.2s;
}
.scroll-bottom-btn:hover { background: var(--accent); color: white; border-color: var(--accent); }
.scroll-bottom-btn.visible { display: flex; }

/* ═══ BALANCE BAR ═══ */
.balance-bar {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 4px 16px;
    background: var(--surface);
    border-top: 1px solid var(--border);
    font-size: 11px;
    color: var(--text2);
    flex-shrink: 0;
    min-height: 26px;
}
.balance-item {
    display: flex;
    align-items: center;
    gap: 4px;
}
.balance-item .bal-label { font-weight: 600; }
.balance-item .bal-value { font-variant-numeric: tabular-nums; font-weight: 600; }
.balance-item.anthropic .bal-label { color: #f0b060; }
.balance-item.openrouter .bal-label { color: #60f0b0; }
.balance-item.gemini .bal-label { color: #60b0f0; }
.balance-item.kieai .bal-label { color: #c890f0; }
.balance-session { margin-left: auto; color: var(--text2); position: relative; cursor: pointer; }
.balance-session .total { color: var(--red); font-weight: 600; }
.balance-session .session-tooltip {
    display: none;
    position: absolute;
    bottom: 100%;
    right: 0;
    margin-bottom: 6px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 0;
    min-width: 320px;
    max-height: 300px;
    overflow-y: auto;
    box-shadow: 0 4px 16px rgba(0,0,0,0.4);
    z-index: 100;
    font-size: 11px;
}
.balance-session .session-tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    height: 15px;
    background: transparent;
}
.session-tooltip .st-header {
    padding: 4px 12px 6px;
    font-weight: 600;
    color: var(--accent);
    border-bottom: 1px solid var(--border);
}
.session-tooltip .st-row {
    display: flex;
    padding: 3px 12px;
    gap: 8px;
    align-items: center;
}
.session-tooltip .st-row:hover { background: var(--bg); }
.session-tooltip .st-time { color: var(--text2); min-width: 110px; }
.session-tooltip .st-model { flex: 1; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.session-tooltip .st-tokens { color: var(--text2); min-width: 50px; text-align: right; }
.session-tooltip .st-cost { color: var(--red); font-weight: 600; min-width: 60px; text-align: right; }
.session-tooltip .st-empty { padding: 12px; color: var(--text2); text-align: center; font-style: italic; }
.session-tooltip .st-row { position: relative; }
.session-tooltip .st-detail {
    display: none;
    position: absolute;
    bottom: 0;
    right: 100%;
    margin-right: 6px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 12px;
    min-width: 300px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.4);
    z-index: 110;
    font-size: 11px;
    white-space: nowrap;
}
.session-tooltip .st-row:hover .st-detail { display: block; }

/* ═══ CODE BLOCKS ═══ */
.code-block-container {
    margin: 10px 0;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #1e1e2e;
    overflow: hidden;
    position: relative;
}
.code-block-header {
    padding: 6px 12px;
    background: var(--surface2);
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 11px;
    color: var(--text2);
}
.code-block-header .lang {
    font-family: monospace;
    font-weight: 600;
}
.code-block-body {
    padding: 12px;
    overflow-x: auto;
    font-family: 'Cascadia Code', 'Consolas', monospace;
    font-size: 13px;
    line-height: 1.5;
    white-space: pre;
    color: #d0d0d0;
}
.code-copy-btn {
    padding: 4px 8px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text2);
    cursor: pointer;
    font-size: 11px;
    transition: all 0.2s;
}
.code-copy-btn:hover {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

/* ═══ ATTACHMENTS ═══ */
.attachments-container {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: none;
}
.attachments-container.visible { display: flex; }
.attachment-item {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--surface2);
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 12px;
    color: var(--text);
    border: 1px solid var(--border);
    position: relative;
    cursor: pointer;
}
.attachment-size {
    font-size: 10px;
    color: var(--text2);
    opacity: 0.8;
}
.attachment-size.large {
    color: var(--red);
    font-weight: bold;
}
.opt-tag {
    color: var(--orange);
    font-size: 11px;
    margin: 0 2px;
    cursor: help;
    text-shadow: 0 0 5px rgba(240, 160, 80, 0.5);
}

/* ═══ FULLSCREEN IMAGE MODAL ═══ */
.image-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5); /* Затемнение 50% вместо 80% */
    z-index: 2147483647; /* Максимально возможный z-index */
    justify-content: center;
    align-items: center;
    cursor: pointer;
}
.image-modal-content {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 10px 40px rgba(0,0,0,0.6);
    cursor: default;
    max-width: 95vw;
    max-height: 95vh;
}
.image-modal-header {
    padding: 8px 16px;
    background: var(--surface2);
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
}
.image-modal-header .image-name {
    color: var(--orange);
    font-family: monospace;
}
.image-modal-header .close-btn {
    cursor: pointer;
    color: var(--text2);
    font-size: 18px;
}
.image-modal-header .close-btn:hover { color: var(--red); }
.image-modal-body {
    padding: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: auto;
    background: #000;
}
.image-modal-body img {
    display: block;
    object-fit: contain;
}

.attachment-item .remove-btn {
    cursor: pointer;
    color: var(--text2);
    font-weight: bold;
    margin-left: 4px;
}
.attachment-item .remove-btn:hover { color: var(--red); }
.attachments-summary {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 2px 4px;
    font-size: 11px;
    white-space: nowrap;
    align-self: center;
}
.attachments-count {
    color: var(--orange);
    opacity: 0.85;
}
.clear-all-btn {
    cursor: pointer;
    color: var(--orange);
    font-size: 16px;
    font-weight: bold;
    line-height: 1;
    padding: 0 2px;
    transition: color 0.15s;
}
.clear-all-btn:hover { color: var(--red); }
.est-price-credits {
    font-size: 11px;
    color: #c890f0;
    font-weight: 600;
    line-height: 1.3;
}
        .attachment-preview {
            display: none;
            position: fixed; /* Радикально: фиксированное позиционирование */
            bottom: auto;
            left: auto;
            transform: none;
            margin-bottom: 0;
            background: var(--surface);
            border: 1px solid var(--border);
            border-radius: 8px;
            padding: 12px;
            z-index: 2147483647; /* Максимальный приоритет */
            box-shadow: 0 12px 32px rgba(0,0,0,0.7);
            width: 600px; /* Увеличено значительно */
            pointer-events: none;
        }
        .attachment-preview img {
            max-width: 580px; 
            max-height: 500px; 
            display: block;
            border-radius: 4px;
        }
        .attachment-preview-text {
            font-size: 13px; 
            color: var(--text); 
            white-space: pre-wrap;
            word-break: break-all;
            max-height: 500px; /* Увеличено */
            overflow: hidden;
            font-family: 'Cascadia Code', monospace;
            line-height: 1.5;
        }

/* ═══ DROP ZONES ═══ */
#projectPathInput.drop-zone-active {
    border-color: var(--accent) !important;
    box-shadow: 0 0 0 2px var(--accent) !important;
}

.preview-editor {
    flex: 1;
    overflow: auto;
    display: flex;
    flex-direction: column;
}
.preview-editor textarea {
    flex: 1;
    width: 100%;
    padding: 12px;
    border: none;
    background: var(--bg);
    color: var(--text);
    font-family: 'Cascadia Code', 'Consolas', monospace;
    font-size: 13px;
    line-height: 1.5;
    resize: none;
    tab-size: 4;
}
.preview-editor textarea:focus { outline: none; }
.preview-header .editor-actions {
    display: flex;
    gap: 4px;
    align-items: center;
}
.editor-btn {
    padding: 2px 8px;
    border-radius: 4px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text2);
    cursor: pointer;
    font-size: 12px;
    display: none;
    align-items: center;
    gap: 3px;
    transition: all 0.2s;
}
.editor-btn:hover { background: var(--accent); color: white; border-color: var(--accent); }
.editor-btn.visible { display: flex; }
.editor-btn.save-btn { color: var(--red); border-color: var(--red); font-weight: 600; }
.editor-btn.save-btn:hover { background: var(--red); color: white; }
.main-tab-content {
    display: none;
    padding: 15px 20px; /* Добавляем отступы */
}

/* --- Settings Modal --- */
.modal-header {
    border-bottom: 1px solid var(--border);
    padding-bottom: 10px;
    margin-bottom: 15px;
    text-align: center;
}
.main-tabs {
    margin-bottom: 20px;
}
.main-tabs .tab-btn.active {
    background-color: var(--accent);
    color: white;
}
.main-tab-content {
    border: 1px solid transparent;
    padding: 15px;
    border-radius: 8px;
    transition: border-color 0.3s;
}
.main-tab-content.active-content {
    border-color: var(--accent);
}

.tabs .tab-btn.active {
    background-color: var(--accent);
    color: white;
    border-bottom-color: transparent;
}
.tab-content.active {
    display: block;
}
.provider-card.selected {
    outline: 2px solid var(--accent);
    background-color: var(--surface2);
    box-shadow: 0 0 10px rgba(var(--accent-rgb), 0.3);
}
.modal-footer {
    text-align: right;
    margin-top: 20px;
    border-top: 1px solid var(--border);
    padding-top: 15px;
}
.modal-footer button {
    margin-left: 10px;
}
.modal-footer .save-btn {
    background-color: var(--accent);
    color: white;
}
.modal-footer .save-btn:hover {
    background-color: #6a44ff;
}
.modal-header h2 {
    margin: 0;
    font-size: 1.4em;
    color: var(--text-light);
}
.main-tabs .tab-btn {
    padding: 10px 20px;
    font-size: 1.1em;
}
.main-tab-content.active {
    display: block;
}
.main-tab-content {
    display: none;
}
.tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
    margin-bottom: 15px;
}
.tab-btn {
    padding: 8px 15px;
    cursor: pointer;
    border: none;
    background: none;
    color: var(--text-dim);
    font-size: 1em;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
}
.tab-btn:hover {
    color: var(--text);
    border-bottom-color: var(--accent-light);
}
.tab-content {
    display: none;
    padding: 15px;
    border: 1px solid var(--border);
    border-top: none;
    border-radius: 0 0 8px 8px;
}
.setting-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
    padding: 8px;
    border-radius: 6px;
}
.setting-row label {
    flex-basis: 40%;
}
.setting-row input[type="text"],
.setting-row input[type="password"],
.setting-row select {
    flex: 1;
    padding: 8px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
}
.setting-row input[type="range"] {
    flex: 1;
}
.test-conn-btn {
    padding: 6px 10px;
    font-size: 0.9em;
    margin-left: 10px;
}
.test-result {
    font-size: 0.9em;
    margin-left: 10px;
}

/* ════════════════════════════════════════════════════
   AGENT MODE
   ════════════════════════════════════════════════════ */

/* Kнопка А в режиме переключателя */
.agent-mode-btn {
    font-weight: 700;
    font-size: 14px !important;
    letter-spacing: 0;
    color: var(--text2);
    border-left: 1px solid var(--border);
}
.agent-mode-btn.active {
    background: #a020f0 !important;
    color: white !important;
    box-shadow: 0 0 8px rgba(160, 32, 240, 0.5);
}
.agent-mode-btn:hover:not(.active) {
    background: rgba(160, 32, 240, 0.15) !important;
    color: #c060f0 !important;
}

/* Панель лога агента — средняя колонка между сайдбаром и чатом */
.agent-log-panel {
    width: 0;
    min-width: 0;
    background: var(--surface);
    border-right: 1px solid rgba(160, 32, 240, 0.3);
    display: none;
    flex-direction: column;
    flex-shrink: 0;
    position: relative;
    overflow: hidden;
}
.agent-log-panel.open {
    display: flex;
    width: 360px;
    min-width: 200px;
}
.agent-log-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 6px 14px;
    background: rgba(160, 32, 240, 0.12);
    border-bottom: 1px solid rgba(160, 32, 240, 0.3);
    flex-shrink: 0;
}
.agent-log-title {
    font-weight: 700;
    font-size: 13px;
    color: #c060f0;
    letter-spacing: 0.5px;
}
.agent-log-status {
    font-size: 12px;
    color: var(--text2);
    font-style: italic;
}

/* Тело лога */
.agent-log-body {
    flex: 1;
    min-height: 60px;
    overflow-y: auto;
    padding: 8px 12px;
    display: flex;
    flex-direction: column;
    gap: 3px;
}
.agent-log-line {
    font-size: 12px;
    line-height: 1.5;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Cascadia Code', 'Consolas', monospace;
}
.agent-log-plan    { color: #c060f0; }
.agent-log-action  { color: var(--green); }
.agent-log-verify  { color: #60c0f0; }
.agent-log-issue   { color: var(--orange); }
.agent-log-info    { color: var(--text2); }
.agent-log-success { color: var(--green); font-weight: 700; }
.agent-log-warn    { color: var(--orange); }
.agent-log-error   { color: var(--red); font-weight: 600; }

/* Область предпросмотра файлов в режиме агента (TOP of agent panel) */
.agent-preview-area {
    flex: 1;
    min-height: 80px;
    overflow: auto;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
}
.agent-preview-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text2);
    font-size: 12px;
    font-style: italic;
    opacity: 0.5;
}
/* Горизонтальный разделитель внутри панели агента */
.agent-inner-handle {
    height: 4px;
    background: var(--border);
    cursor: ns-resize;
    flex-shrink: 0;
    transition: background 0.2s;
}
.agent-inner-handle:hover, .agent-inner-handle.active {
    background: var(--accent);
}
.agent-preview-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 10px;
    background: var(--surface2);
    font-size: 12px;
    color: var(--text2);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
}
.agent-preview-header button {
    background: none;
    border: none;
    color: var(--text2);
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
}
.agent-preview-header button:hover { color: var(--red); }
.agent-preview-img {
    max-width: 100%;
    max-height: 300px;
    display: block;
    padding: 8px;
    object-fit: contain;
}
.agent-preview-text {
    padding: 8px 12px;
    font-size: 12px;
    font-family: 'Cascadia Code', 'Consolas', monospace;
    color: var(--text);
    white-space: pre-wrap;
    word-break: break-word;
    line-height: 1.5;
}

/* ─── Выпадающие списки моделей агента в настройках ─── */
.agent-model-row {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 14px;
    padding: 12px 14px;
    background: rgba(160, 32, 240, 0.06);
    border: 1px solid rgba(160, 32, 240, 0.25);
    border-radius: 8px;
}
.agent-model-field {
    display: flex;
    flex-direction: column;
    gap: 5px;
}
.agent-model-label {
    font-size: 12px;
    font-weight: 600;
    color: #c060f0;
    letter-spacing: 0.3px;
}
.agent-model-select {
    width: 100%;
    padding: 7px 10px;
    border-radius: 7px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    font-size: 13px;
    cursor: pointer;
}
.agent-model-select:focus {
    outline: none;
    border-color: #a020f0;
}

/* ─── Маркировка А в тултипе расходов ─── */
.st-agent-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    border-radius: 3px;
    background: #a020f0;
    color: white;
    font-size: 10px;
    font-weight: 700;
    flex-shrink: 0;
    margin-right: 2px;
}
.session-tooltip .st-row-agent {
    background: rgba(160, 32, 240, 0.08);
}
.session-tooltip .st-row-agent:hover {
    background: rgba(160, 32, 240, 0.15);
}
    min-width: 120px;
    text-align: left;
}
.provider-select-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
    margin-top: 10px;
}
.provider-card {
    padding: 15px;
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    background: var(--surface);
}
.provider-card:hover {
    border-color: var(--accent-light);
    background: var(--surface2);
}
.prov-name {
    font-weight: bold;
    font-size: 1.1em;
    margin-bottom: 5px;
}
.prov-hint {
    font-size: 0.9em;
    color: var(--text-dim);
}
#main-tab-providers .tabs .tab-btn.active {
    color: white;
    background-color: var(--accent);
    border-bottom-color: transparent;
}
#main-tab-providers .tab-content {
    border: none;
    padding: 0;
}
#main-tab-providers .tab-content.active {
    border-top: 1px solid var(--border);
    margin-top: -1px;
    padding-top: 15px;
}
