/* Дополнения к legacy style.css: вход, вложения, проект, пользователь в шапке */
[hidden] { display: none !important; }

.old-thread-hint {
    margin-bottom: 10px;
    padding: 10px 14px;
    border: 1px solid rgba(255, 193, 7, .3);
    border-radius: 8px;
    background: rgba(255, 193, 7, .1);
    color: var(--text-muted);
    font-size: 13px;
    line-height: 1.5;
}

.message-row.system-schedule {
    line-height: 1.6;
    overflow-wrap: anywhere;
}
.schedule-heading { font-weight: 600; margin-bottom: 5px; }
.schedule-prompt { margin-top: 5px; color: var(--text-muted); white-space: pre-wrap; }

#login-screen {
    position: fixed; inset: 0; z-index: 2000;
    display: flex; align-items: center; justify-content: center;
    background: var(--bg);
}
.login-card {
    width: min(380px, calc(100vw - 32px));
    background: #fff; border: 1px solid var(--border); border-radius: 12px;
    padding: 28px; display: flex; flex-direction: column; gap: 12px;
    box-shadow: 0 4px 24px rgba(0,0,0,.06);
}
.login-card h2 { font-size: 20px; }
.login-hint { color: var(--text-muted); font-size: 14px; }
.login-card input {
    border: 1px solid var(--border-input); border-radius: 8px; padding: 10px 12px; font-size: 15px; outline: none;
}
.login-card input:focus { border-color: var(--accent); }
.login-card button[type=submit] {
    background: var(--accent); color: #fff; border: none; border-radius: 8px;
    padding: 10px 12px; font-size: 15px; cursor: pointer;
}
.login-card button[type=submit]:hover { background: var(--accent-hover); }
.login-card button[disabled] { opacity: .6; cursor: default; }
.login-error { color: #b91c1c; font-size: 13px; min-height: 18px; }
button.link { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 13px; text-decoration: underline; }

.header-user { position: relative; display: flex; align-items: center; font-size: 14px; }
.profile-img { width: 40px; height: 40px; border-radius: 50%; overflow: hidden; cursor: pointer; background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 600; user-select: none; }
.profile-img img { width: 100%; height: 100%; object-fit: cover; }
.avatar-dropdown-menu { display: none; position: absolute; top: 100%; right: 0; margin: 6px 0 0; padding: 4px 0; list-style: none; min-width: 140px; background: #fff; border: 1px solid var(--border-input); border-radius: 8px; box-shadow: 0 4px 16px rgba(0,0,0,.12); z-index: 50; }
.header-user.active .avatar-dropdown-menu { display: block; }
.avatar-dropdown-menu a, .avatar-dropdown-menu button { display: block; width: 100%; box-sizing: border-box; padding: 8px 14px; text-align: left; background: none; border: none; font: inherit; color: var(--text); text-decoration: none; cursor: pointer; }
.avatar-dropdown-menu a:hover, .avatar-dropdown-menu button:hover { background: rgba(0,0,0,.05); }

.project-row { display: flex; align-items: center; gap: 10px; margin: 8px 0 16px; justify-content: center; }
.project-picker { position: relative; flex-shrink: 0; }
.project-filter { display: inline-flex; min-width: 32px; margin-right: 0; max-width: 220px; }
#project-filter-name { overflow: hidden; text-overflow: ellipsis; }
.project-menu { position: absolute; top: calc(100% + 8px); right: 0; width: 290px; max-width: calc(100vw - 32px); background: #fff; border: 1px solid var(--border-input); border-radius: 12px; padding: 6px; box-shadow: 0 8px 28px rgba(0,0,0,.12); z-index: 60; }
.project-options { max-height: min(360px, 50vh); overflow-y: auto; }
.project-option { display: flex; align-items: center; gap: 8px; width: 100%; padding: 10px 12px; border: 0; border-radius: 7px; background: transparent; text-align: left; font: inherit; font-size: 14px; color: var(--text); cursor: pointer; overflow-wrap: anywhere; }
.project-option-icon { width: 1em; height: 1em; flex: 0 0 1em; }
.project-option:hover { background: #f3f4f6; }
.project-option[aria-pressed="true"] { background: rgba(16,163,127,.1); color: var(--accent); font-weight: 600; }
.project-display-option { display: flex; align-items: center; gap: 8px; padding: 12px; margin-top: 6px; border-top: 1px solid var(--border-input); font-size: 13px; color: var(--text); cursor: pointer; }
.project-display-option input { accent-color: var(--accent); flex-shrink: 0; }
.file-drop-overlay { position: absolute; inset: 64px 16px 16px; z-index: 70; border: 2px dashed var(--accent); border-radius: 18px; background: rgba(240,253,249,.96); color: var(--accent); display: flex; align-items: center; justify-content: center; pointer-events: none; }
.file-drop-overlay > div { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 24px; text-align: center; }
.file-drop-overlay strong { font-size: 20px; }
.file-drop-overlay span { font-size: 14px; color: var(--text-muted); }
.thread-project { font-size: 11px; color: var(--text-muted); margin-left: 6px; white-space: nowrap; }
.threads-status { display: flex; flex: 0 0 auto; justify-content: center; align-items: center; gap: 8px; padding: 14px 8px; font-size: 12px; color: var(--text-muted); }
.threads-status .thread-spinner { margin: 0; }
.threads-status button { border: 0; background: none; color: var(--accent); cursor: pointer; font: inherit; }
.thread-item { flex-shrink: 0; }
.rename-modal { display: flex; align-items: center; justify-content: center; }
.rename-form { margin: 0; width: min(420px, calc(100vw - 32px)); box-sizing: border-box; display: flex; flex-direction: column; gap: 12px; }
.rename-form h2 { margin: 0 0 4px; font-size: 20px; }
.rename-form label { font-size: 14px; }
.rename-form input { width: 100%; box-sizing: border-box; padding: 10px 12px; border: 1px solid var(--border-input); border-radius: 8px; font: inherit; }
.rename-form input:focus { outline: 2px solid var(--accent); outline-offset: 2px; }
.rename-actions { display: flex; justify-content: flex-end; gap: 8px; }
.rename-actions button { padding: 8px 14px; border: 1px solid var(--border-input); border-radius: 8px; background: #fff; color: var(--text); font: inherit; cursor: pointer; }
.rename-actions button[type=submit] { background: var(--accent); color: #fff; border-color: var(--accent); }
.rename-actions button:disabled { opacity: .6; cursor: wait; }
.project-row select { border: 1px solid var(--border-input); border-radius: 8px; padding: 6px 12px; font-size: 14px; background: #fff; }

.icon-btn { background: none; border: none; color: var(--text-muted); cursor: pointer; padding: 4px; display: flex; align-items: center; }
.icon-btn:hover { color: var(--text); }
.attachments { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.attachment-chip {
    display: inline-flex; align-items: center; gap: 6px; font-size: 12px;
    background: #fff; border: 1px solid var(--border); border-radius: 999px; padding: 4px 10px;
}
.attachment-chip button { border: none; background: none; cursor: pointer; color: var(--text-muted); font-size: 14px; line-height: 1; }
.text-attachment-chip { max-width: 100%; border-radius: 10px; align-items: flex-start; padding: 8px 10px; box-sizing: border-box; }
.text-attachment-chip details { min-width: 0; }
.text-attachment-chip summary { cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 360px; }
.text-attachment-chip pre { margin: 10px 0 0; max-height: 240px; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; font: 12px/1.6 monospace; }
.text-attachment-chip button { flex-shrink: 0; padding: 1px 2px; }
.message-row.user .user-message-collapsed { max-height: 240px; overflow: hidden; mask-image: linear-gradient(to bottom, #000 200px, transparent); }
.user-message-toggle { display: block; margin-top: 8px; padding: 4px 0; border: 0; background: none; color: var(--accent); font: inherit; font-size: 13px; cursor: pointer; }
.user-message-toggle:hover { text-decoration: underline; }
.message-attachments { margin-top: 6px; font-size: 12px; color: var(--text-muted); }
.message-inner a[download]::before { content: "📎 "; }
.thread-item.archived .thread-title { opacity: .6; }

.agent-banner { background: #fff4e5; border-bottom: 1px solid #f5c26b; color: #7a4b00; padding: 10px 16px; font-size: 14px; text-align: center; }
.agent-banner a { color: inherit; font-weight: 600; }

/* ── Карточки запросов агента (подтверждения, вопросы, MCP) ─────────────────── */
.interaction-card {
    background: #fff; border: 1px solid var(--accent); border-radius: 12px; padding: 16px; margin: 12px 0;
    box-shadow: 0 4px 12px rgba(16, 163, 127, 0.1); animation: interactionIn 0.3s ease;
}
@keyframes interactionIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
.interaction-title { font-weight: 600; font-size: 15px; margin-bottom: 12px; color: var(--accent); }
.interaction-sub { margin-top: 6px; color: var(--text-muted); font-size: 12px; }
.interaction-message, .interaction-description { white-space: pre-wrap; overflow-wrap: anywhere; }
.interaction-warning, .interaction-error {
    color: #991b1b; background: #fef2f2; border-left: 3px solid #dc2626; padding: 10px; margin: 10px 0;
    white-space: pre-wrap; overflow-wrap: anywhere;
}
.interaction-inspect { margin: 10px 0; }
.interaction-inspect summary { cursor: pointer; font-weight: 500; }
.interaction-inspect pre, .interaction-command {
    white-space: pre-wrap; overflow-wrap: anywhere; max-height: 320px; overflow-y: auto; font-size: 12px;
    background: #f9f9f9; padding: 10px;
}
.interaction-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.interaction-actions button {
    padding: 8px 14px; border-radius: 6px; font-size: 13px; cursor: pointer; border: 1px solid var(--border);
    transition: all 0.2s; font-weight: 500;
}
.interaction-actions button:disabled { opacity: 0.5; cursor: wait; }
.btn-accept { background: var(--accent); color: #fff; border: none; }
.btn-accept:hover { background: var(--accent-hover); }
.btn-accept-session { background: #f0fdf4; color: #166534; border-color: #bbf7d0; }
.btn-accept-session:hover { background: #dcfce7; }
.btn-decline { background: #fef2f2; color: #991b1b; border-color: #fecaca; }
.btn-decline:hover { background: #fee2e2; }
.interaction-question { display: block; margin-bottom: 12px; }
.interaction-field-label { display: block; font-weight: 500; font-size: 13px; margin-bottom: 4px; }
.interaction-question .interaction-sub { display: block; margin-bottom: 6px; }
.interaction-question input, .interaction-question select {
    box-sizing: border-box; width: 100%; padding: 8px; border: 1px solid var(--border); border-radius: 6px; font-size: 14px;
}
.interaction-form textarea { box-sizing: border-box; width: 100%; border: 1px solid var(--border); border-radius: 6px; padding: 8px; font: inherit; }
.interaction-link { display: inline-block; margin: 10px 0; color: var(--accent); text-decoration: underline; font-weight: 500; }

/* Telegram */
.tg-menu-dot { display: inline-block; width: 8px; height: 8px; margin-left: 8px; border-radius: 50%; background: #10a37f; box-shadow: 0 0 5px rgba(16,163,127,.6); vertical-align: middle; }
.tg-menu-dot[hidden] { display: none; }
#tg-menu-btn[hidden] { display: none; }
.tg-steps { padding-left: 20px; line-height: 1.9; }
.tg-btn { display: inline-block; padding: 6px 14px; border-radius: 8px; background: #10a37f; color: #fff !important; text-decoration: none; border: none; font: inherit; cursor: pointer; }
.tg-btn-secondary { background: #e5e5e5; color: var(--text) !important; }
.tg-ok { color: #10a37f; font-weight: 600; }
.tg-fallback { font-size: 13px; color: var(--text-muted); }
/* Тихие отметки агента */
.message-row.muted .message-content { opacity: .65; }
.message-row.muted .message-inner { font-size: 13px; }
.message-row.muted .mute-icon { display: inline-flex; align-items: center; margin-right: 6px; color: var(--text-muted); }

/* @-упоминания */
.input-wrapper { position: relative; }
.mention-list { position: absolute; left: 48px; right: 56px; bottom: 100%; margin: 0 0 6px; padding: 4px 0; list-style: none; max-height: 240px; overflow-y: auto; background: #fff; border: 1px solid var(--border-input); border-radius: 8px; box-shadow: 0 4px 16px rgba(0,0,0,.12); z-index: 60; }
.mention-list[hidden] { display: none; }
.mention-item { display: flex; justify-content: space-between; gap: 12px; padding: 7px 14px; cursor: pointer; }
.mention-item small { color: var(--text-muted); }
.mention-item.active, .mention-item:hover { background: rgba(16,163,127,.12); }

.tg-steps li { margin-bottom: 10px; }
.tg-steps li .tg-btn { margin-top: 6px; }
.tg-code-row { display: flex; align-items: center; gap: 10px; margin-top: 6px; flex-wrap: wrap; }
.tg-code { font-size: 18px; letter-spacing: 1px; padding: 6px 12px; background: rgba(16,163,127,.1); border: 1px dashed #10a37f; border-radius: 8px; user-select: all; }
.tg-wait { color: var(--text-muted); font-size: 13px; }
.tg-spinner { display: inline-block; width: 10px; height: 10px; border: 2px solid #10a37f; border-right-color: transparent; border-radius: 50%; animation: tg-spin 1s linear infinite; vertical-align: -1px; margin-right: 4px; }
@keyframes tg-spin { to { transform: rotate(360deg); } }

.login-method { display: flex; gap: 8px; margin-bottom: 12px; }
.login-card .login-method button { flex: 1; padding: 8px 12px; border-radius: 8px; background: transparent; color: inherit; border: 1px solid var(--border); cursor: pointer; }
.login-card .login-method button[aria-pressed="true"] { background: var(--accent); color: white; }

/* ===== MOBILE / PWA ===== */

/* Безопасные зоны (вырез, строка статуса, индикатор «домой»); вне standalone env() = 0 */
#header {
    padding-top: calc(9px + env(safe-area-inset-top));
    padding-left: calc(20px + env(safe-area-inset-left));
    padding-right: calc(20px + env(safe-area-inset-right));
}
#input-area {
    padding-bottom: calc(24px + env(safe-area-inset-bottom));
    padding-left: calc(20px + env(safe-area-inset-left));
    padding-right: calc(20px + env(safe-area-inset-right));
}

/* Прокрутка внутри блоков не должна тянуть за собой страницу (pull-to-refresh, резинка) */
html, body { overscroll-behavior: none; }
#messages, #welcome, #threads-history { overscroll-behavior: contain; }

#sidebar-backdrop { display: none; }

/* Узкий экран: сайдбар - выезжающая панель поверх чата */
@media (max-width: 768px) {
    #sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: min(85vw, 320px);
        z-index: 200;
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
        padding-left: env(safe-area-inset-left);
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.18);
    }
    #sidebar.hidden {
        transform: translateX(-105%);
        position: fixed;
        box-shadow: none;
    }
    #sidebar:not(.hidden) + #sidebar-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 150;
        background: rgba(0, 0, 0, 0.4);
    }

    #header {
        gap: 6px;
        padding-left: calc(8px + env(safe-area-inset-left));
        padding-right: calc(8px + env(safe-area-inset-right));
    }
    #header h1 { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    #share-btn .share-text { display: none; }
    #share-btn, #project-filter { min-width: 40px; margin-right: 0; }

    /* Лимит: вместо «Остаток лимита: NN%» и строки сброса - «Лимит NN%» */
    .header-usage > div:first-child { font-size: 0; }
    .header-usage .usage-percent { font-size: 12px; }
    .header-usage .usage-percent::before { content: 'Лимит '; }
    #usage-reset { display: none; }

    #input-area {
        padding-top: 8px;
        padding-bottom: calc(12px + env(safe-area-inset-bottom));
        padding-left: calc(10px + env(safe-area-inset-left));
        padding-right: calc(10px + env(safe-area-inset-right));
    }
    .textarea-row { padding: 8px 10px; }

    .modal-content { margin: 8vh auto; width: 92%; }
    .modal { height: 100dvh; }
}

/* Экран-палец: крупные цели нажатия, без hover-зависимых элементов, без зума iOS при фокусе */
@media (pointer: coarse) {
    #send-btn, #stop-btn { width: 44px; height: 44px; }
    .icon-btn, .btn-toggle-sidebar { min-width: 44px; min-height: 44px; justify-content: center; }
    .share-btn { height: 44px; min-width: 44px; }
    .close { padding: 8px 12px; margin: -8px -12px 0 0; }
    .context-menu { width: 220px; }
    .context-menu-item { padding: 12px 14px; }

    .thread-item .btn-favorite { opacity: 1; font-size: 18px; padding: 10px; right: 0; }
    .thread-item .thread-title { padding-right: 40px; }

    .input-hint { display: none; }

    input:not([type="checkbox"]):not([type="radio"]):not([type="file"]),
    select,
    textarea,
    #message-input { font-size: 16px; }
}
.owner-load-steps { margin-left: 12px; padding: 4px 10px; border: 1px solid var(--border-input); border-radius: 8px; background: #fff; color: var(--text); font: inherit; cursor: pointer; }
.owner-load-steps:hover { background: var(--bg-hover, #f5f5f5); }
.owner-load-steps:disabled { opacity: .6; cursor: wait; }


.mcp-menu-dot { display: inline-block; width: 8px; height: 8px; margin-left: 8px; border-radius: 50%; background: #e08a00; box-shadow: 0 0 5px rgba(224,138,0,.6); vertical-align: middle; }
.mcp-menu-dot[hidden], #mcp-menu-btn[hidden] { display: none; }
.mcp-list { list-style: none; padding: 0; margin: 12px 0; }
.mcp-list li { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid rgba(128,128,128,.2); }
.mcp-name { font-weight: 600; }
.mcp-desc { font-size: 13px; color: var(--text-muted); }
.mcp-state { font-size: 13px; color: var(--text-muted); }
.mcp-err { color: #d33; font-size: 13px; margin-top: 8px; }

/* ── Передача управления браузером агента ─────────────────────────────────── */
.handoff-overlay { position: fixed; inset: 0; z-index: 1000; background: #111; display: flex; flex-direction: column; }
.handoff-bar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: #222; color: #eee; font-size: 14px; }
.handoff-status { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.handoff-btn { padding: 6px 12px; border-radius: 6px; border: 1px solid #555; background: #333; color: #eee; cursor: pointer; font-size: 13px; }
.handoff-btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.handoff-canvas { flex: 1; width: 100%; min-height: 0; background: #000; outline: none; touch-action: none; cursor: default; }
.handoff-hidden-input { position: absolute; left: -9999px; opacity: 0; }
