/* Веб-клиент AI Lapin: вход, выбор раздела, чат.
   Тёмная и светлая тема — автоматически по системной настройке. */

:root {
    --bg: #f4f5f7;
    --card: #ffffff;
    --text: #1f2430;
    --muted: #6b7280;
    --accent: #2563eb;
    --accent-text: #ffffff;
    --accent-soft: rgba(37, 99, 235, 0.12);
    --border: #e5e7eb;
    --error: #b91c1c;
    --error-bg: rgba(185, 28, 28, 0.08);
    --shadow: 0 8px 30px rgba(15, 23, 42, 0.08);
    --bubble-user: #2563eb;
    --bubble-user-text: #ffffff;
    --bubble-assistant: #ffffff;
    --sidebar-bg: #ffffff;
    --sheet-bg: #ffffff;
    --backdrop: rgba(15, 23, 42, 0.45);
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0f1218;
        --card: #1a1f28;
        --text: #e8eaf0;
        --muted: #9aa2b1;
        --accent: #3b82f6;
        --accent-text: #ffffff;
        --accent-soft: rgba(59, 130, 246, 0.18);
        --border: #2b313d;
        --error: #f87171;
        --error-bg: rgba(248, 113, 113, 0.12);
        --shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
        --bubble-user: #3b82f6;
        --bubble-user-text: #ffffff;
        --bubble-assistant: #1a1f28;
        --sidebar-bg: #151a22;
        --sheet-bg: #1a1f28;
        --backdrop: rgba(0, 0, 0, 0.55);
    }
}

* {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

html {
    height: 100%;
    overscroll-behavior-y: none;
}

body {
    min-height: 100%;
    margin: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    font-size: 16px;
    line-height: 1.45;
    -webkit-text-size-adjust: 100%;
}

/* --- Вход и выбор раздела --- */

.auth-card {
    width: 100%;
    max-width: 380px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 18px;
    box-shadow: var(--shadow);
    overflow: hidden;
}

/* Картинка-баннер на входе и на выборе раздела (web/images/family-hero.jpg) */
.auth-hero img {
    display: block;
    width: 100%;
    height: auto;
    background: var(--accent-soft);
}

.auth-body {
    padding: 20px 24px 24px;
}

/* На низких экранах (телефон в альбомной ориентации) баннер подрезаем */
@media (max-height: 620px) {
    .auth-hero img {
        height: 110px;
        object-fit: cover;
        object-position: center 30%;
    }
}

h1 {
    margin: 0 0 4px;
    font-size: 1.45rem;
    line-height: 1.25;
}

.muted {
    color: var(--muted);
    font-size: 0.95rem;
}

.auth-card form {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

label {
    font-size: 0.85rem;
    color: var(--muted);
}

input {
    width: 100%;
    padding: 12px 14px;
    margin-bottom: 10px;
    font: inherit;
    color: var(--text);
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 10px;
    outline: none;
}

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

button {
    font: inherit;
}

#login-button {
    width: 100%;
    padding: 12px 16px;
    margin-top: 8px;
    font-weight: 600;
    color: var(--accent-text);
    background: var(--accent);
    border: none;
    border-radius: 10px;
    cursor: pointer;
}

button.secondary {
    width: 100%;
    padding: 12px 16px;
    margin-top: 12px;
    color: var(--text);
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 10px;
    font-weight: 500;
    cursor: pointer;
}

button:disabled {
    opacity: 0.6;
    cursor: default;
}

.error {
    margin: 10px 0 0;
    color: var(--error);
    font-size: 0.9rem;
}

.build-info {
    margin: 14px 0 0;
    color: var(--muted);
    font-size: 0.75rem;
    text-align: center;
    opacity: 0.85;
}

.build-info-inline {
    display: block;
    margin-top: 4px;
    color: var(--muted);
    font-size: 0.72rem;
    opacity: 0.85;
}

.section-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin: 12px 0 4px;
}

.section-button {
    display: flex;
    align-items: center;
    gap: 12px;
    text-align: left;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text);
    border-radius: 14px;
    padding: 14px;
    cursor: pointer;
}

.section-button:hover {
    border-color: var(--accent);
    background: var(--accent-soft);
}

.section-icon {
    font-size: 1.6rem;
}

.section-button b {
    display: block;
}

.section-button small {
    color: var(--muted);
}

/* --- Каркас приложения --- */

.app {
    position: fixed;
    left: 0;
    right: 0;
    top: var(--viewport-top, 0);
    height: var(--viewport-height, 100dvh);
    display: flex;
    background: var(--bg);
}

.backdrop {
    position: absolute;
    inset: 0;
    z-index: 25;
    background: var(--backdrop);
}

.sidebar {
    position: absolute;
    z-index: 30;
    top: 0;
    bottom: 0;
    left: 0;
    width: min(84vw, 340px);
    display: flex;
    flex-direction: column;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border);
    transform: translateX(-105%);
    transition: transform 0.2s ease;
}

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

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 12px 8px;
    padding-top: calc(12px + env(safe-area-inset-top));
    border-bottom: 1px solid var(--border);
}

.sidebar-actions {
    display: flex;
    gap: 4px;
}

.sidebar-actions button,
.icon-button {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    border: none;
    background: transparent;
    color: var(--text);
    font-size: 1.15rem;
    cursor: pointer;
}

.sidebar-actions button:hover,
.icon-button:hover {
    background: var(--accent-soft);
}

.chat-list {
    list-style: none;
    margin: 0;
    padding: 6px;
    overflow-y: auto;
    overscroll-behavior: contain;
    flex: 1;
}

.chat-list-item button {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 2px;
    text-align: left;
    border: none;
    background: transparent;
    color: var(--text);
    border-radius: 10px;
    padding: 10px 12px;
    cursor: pointer;
}

.chat-list-item.active button {
    background: var(--accent-soft);
}

.chat-item-title {
    font-weight: 500;
    max-width: 100%;
    /* Две строки: длинное название чата видно почти целиком (v1.47.1). */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    white-space: normal;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.3;
    max-height: 2.6em;
    overflow-wrap: anywhere;
}

.chat-item-time {
    color: var(--muted);
    font-size: 0.78rem;
}

.chat-list-empty {
    color: var(--muted);
    padding: 12px;
    text-align: center;
}

.sidebar-footer {
    padding: 10px 12px;
    border-top: 1px solid var(--border);
    font-size: 0.82rem;
}

/* --- Чат --- */

.chat {
    position: relative;
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    height: 100%;
}

.chat-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    padding-top: calc(10px + env(safe-area-inset-top));
    background: var(--card);
    border-bottom: 1px solid var(--border);
}

.chat-heading {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.chat-heading strong,
.chat-title-button,
.chat-heading small {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-heading small {
    color: var(--muted);
    font-size: 0.8rem;
}

/* Название чата — кнопка: тап переименовывает чат (docs/ui_chat_plan.md, этап 2).
   Отрицательные поля компенсируют паддинг — область тапа больше, вид не меняется */
.chat-title-button {
    padding: 4px 8px;
    margin: -4px -8px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--text);
    font: inherit;
    font-weight: 600;
    text-align: left;
    cursor: pointer;
    /* В шапке тоже две строки: полное название выбранного чата. */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    white-space: normal;
    overflow: hidden;
    line-height: 1.25;
    max-height: 2.5em;
    overflow-wrap: anywhere;
}

@media (hover: hover) {
    .chat-title-button:hover {
        color: var(--accent);
    }

    /* Подсказка-карандаш на десктопе при наведении */
    .chat-title-button::after {
        content: " ✏️";
        font-size: 0.75em;
        opacity: 0;
        transition: opacity 0.15s ease;
    }

    .chat-title-button:hover::after {
        opacity: 0.75;
    }
}

.messages {
    flex: 1;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 14px 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.message {
    max-width: 86%;
    border-radius: 14px;
    padding: 10px 12px;
    word-break: break-word;
}

.message.user {
    align-self: flex-end;
    background: var(--bubble-user);
    color: var(--bubble-user-text);
    border-bottom-right-radius: 4px;
}

.message.assistant {
    align-self: flex-start;
    background: var(--bubble-assistant);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
}

.message.error {
    align-self: center;
    background: var(--error-bg);
    color: var(--error);
    border: 1px solid var(--error);
    font-size: 0.92rem;
}

.message.system {
    align-self: center;
    background: transparent;
    border: 1px dashed var(--border);
    color: var(--muted);
    font-size: 0.85rem;
}

.message.system .ask-option {
    margin-top: 8px;
    display: block;
    width: 100%;
}

.document-card {
    display: flex;
    align-items: center;
    gap: 10px;
}

.document-icon {
    font-size: 1.4rem;
}

.document-name {
    font-weight: 500;
    overflow-wrap: anywhere;
}

.document-meta {
    font-size: 0.78rem;
    opacity: 0.85;
}

.icon-button:disabled {
    opacity: 0.5;
}

.message-content {
    overflow-wrap: anywhere;
}

.message-content p {
    margin: 0 0 0.6em;
}

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

.message-content pre {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px;
    overflow-x: auto;
    font-size: 0.88rem;
}

.message-content code {
    font-family: ui-monospace, Consolas, monospace;
    font-size: 0.9em;
}

.message-content :not(pre) > code {
    background: var(--accent-soft);
    padding: 1px 5px;
    border-radius: 5px;
}

.message-content table {
    border-collapse: collapse;
    width: 100%;
    font-size: 0.9rem;
    margin-bottom: 0.6em;
}

.message-content th,
.message-content td {
    border: 1px solid var(--border);
    padding: 4px 8px;
    text-align: left;
}

.message-content a {
    color: var(--accent);
}

.message-content ul,
.message-content ol {
    margin: 0 0 0.6em;
    padding-left: 1.3em;
}

.message-footer {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
    margin-top: 6px;
}

.message-copy {
    border: none;
    background: transparent;
    color: var(--muted);
    font-size: 0.78rem;
    padding: 0;
    cursor: pointer;
}

.message-copy:hover {
    color: var(--accent);
}

.message-meta {
    color: var(--muted);
    font-size: 0.75rem;
}

.progress {
    align-self: flex-start;
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bubble-assistant);
    border: 1px dashed var(--border);
    color: var(--muted);
}

.spinner {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    animation: spin 0.9s linear infinite;
}

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

.welcome {
    margin: auto;
    text-align: center;
    color: var(--muted);
    max-width: 420px;
    padding: 20px;
}

.welcome .empty-illustration {
    margin-bottom: 6px;
}

/* Виджет вопросов ask_user */

.ask-widget {
    align-self: flex-start;
    max-width: 92%;
    background: var(--card);
    border: 1px solid var(--accent);
}

.ask-position {
    color: var(--muted);
    font-size: 0.8rem;
}

.ask-intro {
    font-weight: 600;
    margin-bottom: 4px;
}

.ask-question {
    margin-bottom: 10px;
}

.ask-options {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.ask-option {
    min-height: 40px;
    max-width: 100%;
    padding: 8px 14px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--bg);
    color: var(--text);
    font-size: 0.95rem;
    line-height: 1.35;
    text-align: left;
    /* Длинный вариант виден целиком и переносится на несколько строк,
       а не обрезается многоточием (v1.47.2). */
    white-space: normal;
    overflow-wrap: anywhere;
    cursor: pointer;
}

.ask-option:hover {
    border-color: var(--accent);
}

.ask-option.chosen {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-text);
}

.ask-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 10px;
}

.ask-action {
    border: none;
    background: transparent;
    color: var(--muted);
    font-size: 0.85rem;
    cursor: pointer;
}

.ask-action:hover {
    color: var(--accent);
}

.ask-custom {
    display: flex;
    gap: 8px;
    margin-top: 10px;
}

.ask-custom input {
    flex: 1;
    margin-bottom: 0;
    padding: 8px 10px;
}

.ask-note {
    margin-top: 8px;
    color: var(--muted);
    font-size: 0.85rem;
}

.ask-widget.ask-done {
    border-color: var(--border);
    opacity: 0.85;
}

/* Чипы активных режимов */

.chips {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    padding: 6px 12px 0;
}

.chip {
    flex: 0 0 auto;
    min-height: 36px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--card);
    color: var(--muted);
    padding: 6px 12px;
    font-size: 0.82rem;
    cursor: pointer;
    max-width: 220px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chip:hover {
    color: var(--accent);
    border-color: var(--accent);
}

/* Поле ввода */

.composer {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 8px;
    padding: 10px 12px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
    background: var(--card);
    border-top: 1px solid var(--border);
}

.composer textarea {
    flex: 1 1 auto;
    min-width: 0;
    resize: none;
    max-height: 150px;
    padding: 10px 12px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text);
    font: inherit;
}

.composer textarea:focus {
    outline: none;
    border-color: var(--accent);
}

.send-button {
    width: 44px;
    height: 44px;
    flex: 0 0 auto;
    border-radius: 12px;
    border: none;
    background: var(--accent);
    color: var(--accent-text);
    font-size: 1.1rem;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-touch-callout: none;
    user-select: none;
}

.send-button:disabled {
    opacity: 0.5;
}

/* Запись голосового: кнопка отправки становится «стоп» (v1.46.1) */
.send-button.recording {
    background: var(--error);
    color: #fff;
}

/* Плашка записи/распознавания над полем ввода (v1.46.0) */

.composer-voice {
    flex-basis: 100%;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 0.9rem;
}

.composer-voice[data-state="recording"] {
    border-color: var(--error);
}

.voice-dot {
    width: 10px;
    height: 10px;
    flex: 0 0 auto;
    border-radius: 50%;
    background: var(--error);
    animation: voice-pulse 1.1s ease-in-out infinite;
}

.voice-spinner {
    width: 14px;
    height: 14px;
    flex: 0 0 auto;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: voice-spin 0.8s linear infinite;
}

.voice-status {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.voice-timer {
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}

.voice-actions {
    margin-left: auto;
    display: flex;
    gap: 8px;
}

.voice-cancel,
.voice-finish {
    border: 1px solid var(--border);
    border-radius: 8px;
    background: transparent;
    color: var(--text);
    padding: 5px 10px;
    font: inherit;
    cursor: pointer;
}

.voice-cancel {
    color: var(--muted);
}

.voice-finish {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-text);
}

@keyframes voice-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.35; }
}

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

/* Картинки в чате: чипы над полем ввода и галерея в сообщении (этап 5) */

.composer-attachments {
    flex-basis: 100%;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

/* Очередь сообщений над полем ввода (docs/chat_queue_plan.md, v1.40.0) */

.composer-queue {
    flex-basis: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 6px 10px;
    border: 1px dashed var(--border);
    border-radius: 10px;
    font-size: 0.85rem;
}

.composer-queue-clear {
    border: none;
    background: none;
    color: inherit;
    text-decoration: underline;
    cursor: pointer;
    padding: 0;
    font: inherit;
}

.attachment-chip {
    position: relative;
    width: 56px;
    height: 56px;
    border-radius: 10px;
    overflow: hidden;
    border: 1px solid var(--border);
}

.attachment-preview {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.attachment-remove {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 20px;
    height: 20px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.6);
    color: #fff;
    font-size: 0.7rem;
    line-height: 1;
    cursor: pointer;
}

.bubble-images {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 6px;
}

.bubble-image {
    display: block;
    max-width: 220px;
    max-height: 220px;
    border-radius: 10px;
    cursor: pointer;
}

/* Пустые состояния */

.empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    text-align: center;
    padding: 24px;
    overflow-y: auto;
    overscroll-behavior: contain;
}

/* Иллюстрация пустых экранов — тот же баннер, что и на входе */
.empty-illustration {
    width: min(100%, 460px);
    height: auto;
    border-radius: 16px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
}

.empty-state h2 {
    margin: 0;
}

.empty-state p {
    max-width: 380px;
}

/* Кнопки пустого экрана «нет чатов»: Новый чат сверху, Заметка снизу (v1.12.3) */
.empty-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: min(100%, 380px);
    margin-top: 8px;
}

.empty-actions button {
    width: 100%;
    margin-top: 0;
    padding: 12px 16px;
    font-weight: 600;
    color: var(--accent-text);
    background: var(--accent);
    border: none;
    border-radius: 10px;
    cursor: pointer;
}

.empty-actions button.secondary {
    color: var(--text);
    background: transparent;
    border: 1px solid var(--border);
    font-weight: 500;
}

/* --- Управление базами знаний --- */

.kb {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    height: 100%;
}

.kb-content {
    flex: 1;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.kb-card {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    text-align: left;
    border: 1px solid var(--border);
    background: var(--card);
    color: var(--text);
    border-radius: 14px;
    padding: 12px;
    cursor: pointer;
}

.kb-card:hover {
    border-color: var(--accent);
}

.kb-card-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.kb-card-title {
    font-weight: 600;
    overflow-wrap: anywhere;
}

.kb-card-meta {
    color: var(--muted);
    font-size: 0.82rem;
}

.kb-card-arrow {
    color: var(--muted);
    font-size: 1.2rem;
}

.kb-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 2px;
}

.badge {
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 1px 8px;
    font-size: 0.72rem;
    color: var(--muted);
}

.badge-ok {
    border-color: var(--accent);
    color: var(--accent);
}

.badge-warn {
    border-color: #b45309;
    color: #b45309;
}

@media (prefers-color-scheme: dark) {
    .badge-warn {
        border-color: #fbbf24;
        color: #fbbf24;
    }
}

.kb-description {
    margin: 0;
    color: var(--text);
    font-size: 0.92rem;
}

.kb-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.kb-action {
    border: 1px solid var(--border);
    background: var(--card);
    color: var(--text);
    border-radius: 12px;
    padding: 12px 10px;
    cursor: pointer;
    font-size: 0.92rem;
    text-align: center;
}

.kb-action:hover {
    border-color: var(--accent);
    background: var(--accent-soft);
}

.kb-section-title {
    font-weight: 600;
    margin-top: 4px;
}

.sheet-form {
    display: flex;
    flex-direction: column;
    padding: 4px 6px;
}

.field-label {
    font-size: 0.85rem;
    color: var(--muted);
    margin-top: 6px;
}

.sheet-form input,
.sheet-form textarea,
.modal-panel textarea {
    width: 100%;
    margin-top: 4px;
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text);
    font: inherit;
}

.sheet-form textarea {
    min-height: 80px;
    resize: both;
    max-width: 100%;
}

.modal-panel textarea {
    min-height: 180px;
    resize: both;
    max-width: 100%;
}

.modal-field {
    margin-top: 10px;
}

.modal-field label {
    display: block;
    margin-bottom: 4px;
    color: var(--muted);
    font-size: 0.85rem;
}

/* --- Нижний лист --- */

.sheet {
    position: fixed;
    inset: 0;
    z-index: 60;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
}

.sheet-backdrop {
    position: absolute;
    inset: 0;
    background: var(--backdrop);
}

.sheet-panel {
    position: relative;
    background: var(--sheet-bg);
    border-radius: 18px 18px 0 0;
    max-height: 82vh;
    display: flex;
    flex-direction: column;
    padding-bottom: env(safe-area-inset-bottom);
    animation: slide-up 0.18s ease;
}

@keyframes slide-up {
    from {
        transform: translateY(30px);
        opacity: 0.6;
    }
    to {
        transform: none;
        opacity: 1;
    }
}

.sheet-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
}

.sheet-body {
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 6px;
}

.sheet-row {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 10px;
    border: none;
    background: transparent;
    color: var(--text);
    text-align: left;
    padding: 12px 10px;
    border-radius: 12px;
    cursor: pointer;
    min-height: 48px;
}

.sheet-row:hover {
    background: var(--accent-soft);
}

.sheet-row:disabled {
    opacity: 0.55;
    cursor: default;
}

.sheet-row-icon {
    width: 24px;
    text-align: center;
    flex: 0 0 auto;
}

.sheet-row-text {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.sheet-row-title {
    font-weight: 500;
}

.sheet-row-subtitle {
    color: var(--muted);
    font-size: 0.8rem;
}

.sheet-row-value {
    color: var(--muted);
    font-size: 0.85rem;
    max-width: 42%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sheet-separator {
    height: 1px;
    background: var(--border);
    margin: 6px 10px;
}

.sheet-hint {
    color: var(--muted);
    font-size: 0.85rem;
    padding: 4px 12px 8px;
    margin: 0;
}

/* Строка поиска в листе выбора проекта (docs/ui_chat_plan.md, §9) */

.sheet-search {
    padding: 6px 8px 2px;
}

.sheet-search input {
    margin: 0;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: transparent;
    color: var(--text);
    font: inherit;
}

/* Секции каталога инструментов и строки-тумблеры (docs/capabilities_plan.md) */

.sheet-section {
    padding: 14px 16px 4px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
}

.sheet-row-inactive {
    opacity: 0.6;
}

.sheet-row-right {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
    flex: 0 0 auto;
}

.sheet-row-locked {
    color: var(--muted);
    font-size: 0.85rem;
}

.sheet-busy {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 18px 12px;
    color: var(--muted);
}

.profile-text {
    max-height: 45vh;
    overflow: auto;
    overscroll-behavior: contain;
    margin: 4px 12px 8px;
    padding: 10px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    font-family: inherit;
    font-size: 0.88rem;
    line-height: 1.4;
}

.context-details {
    display: grid;
    gap: 2px;
    padding: 2px 12px 8px;
}

.detail-row {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    font-size: 0.9rem;
}

.detail-row span:last-child {
    text-align: right;
}

.switch {
    position: relative;
    flex: 0 0 auto;
    width: 42px;
    height: 24px;
    border-radius: 999px;
    background: var(--border);
    transition: background 0.15s ease;
}

.switch::after {
    content: "";
    position: absolute;
    top: 3px;
    left: 3px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #fff;
    transition: transform 0.15s ease;
}

.switch.on {
    background: var(--accent);
}

.switch.on::after {
    transform: translateX(18px);
}

/* Снимки контекста */

.context-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: 12px;
}

.context-row:hover {
    background: var(--accent-soft);
}

.context-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    cursor: pointer;
}

.context-title {
    font-weight: 500;
}

.context-meta {
    color: var(--muted);
    font-size: 0.78rem;
}

.context-open {
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text);
    border-radius: 10px;
    padding: 6px 12px;
    cursor: pointer;
}

.context-delete {
    border: none;
    background: transparent;
    color: var(--muted);
    font-size: 1rem;
    cursor: pointer;
}

.context-delete:hover {
    color: var(--error);
}

/* --- Модальное окно --- */

.modal {
    position: fixed;
    inset: 0;
    z-index: 70;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: var(--backdrop);
}

.modal-panel {
    position: relative;
    width: 100%;
    max-width: 380px;
    background: var(--card);
    border-radius: 16px;
    padding: 18px;
    box-shadow: var(--shadow);
}

/* Широкое окно для больших форм: промпты, задания агентам (v1.13.5) */
.modal-panel.modal-panel-wide {
    max-width: min(94vw, 820px);
}

.modal-panel h3 {
    margin: 0 0 10px;
}

.modal-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 16px;
}

.modal-actions button {
    width: auto;
    margin: 0;
    padding: 9px 14px;
    border: none;
    border-radius: 10px;
    background: var(--accent);
    color: var(--accent-text);
    cursor: pointer;
}

.modal-actions button.secondary {
    width: auto;
    margin: 0;
    background: transparent;
    color: var(--text);
    border: 1px solid var(--border);
}

.modal-actions button.danger {
    background: var(--error);
}

/* --- Уведомления --- */

.toast {
    position: fixed;
    top: calc(12px + env(safe-area-inset-top));
    left: 50%;
    transform: translateX(-50%);
    z-index: 90;
    max-width: 90vw;
    padding: 10px 14px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow);
}

.toast-error {
    border-color: var(--error);
    color: var(--error);
}

/* --- Планшет и десктоп --- */

@media (min-width: 900px) {
    .sidebar {
        position: relative;
        transform: none;
        width: 320px;
    }

    .backdrop {
        display: none !important;
    }

    .message {
        max-width: 74%;
    }
}

/* --- R4: офлайн, обновления, установка, прокрутка, копирование кода --- */

.offline-banner {
    position: fixed;
    top: calc(8px + env(safe-area-inset-top));
    left: 50%;
    transform: translateX(-50%);
    z-index: 95;
    padding: 8px 14px;
    border-radius: 999px;
    border: 1px solid var(--error);
    background: var(--error-bg);
    color: var(--error);
    font-size: 0.85rem;
}

.update-banner {
    position: fixed;
    left: 50%;
    bottom: calc(16px + env(safe-area-inset-bottom));
    transform: translateX(-50%);
    z-index: 95;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px 10px 16px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--card);
    box-shadow: var(--shadow);
    font-size: 0.9rem;
}

.update-banner button {
    border: none;
    border-radius: 999px;
    background: var(--accent);
    color: var(--accent-text);
    padding: 6px 12px;
    font: inherit;
    font-size: 0.85rem;
    cursor: pointer;
}

.install-button {
    position: fixed;
    right: 12px;
    bottom: calc(70px + env(safe-area-inset-bottom));
    z-index: 80;
    padding: 10px 14px;
    border: 1px solid var(--accent);
    border-radius: 999px;
    background: var(--card);
    color: var(--accent);
    font: inherit;
    font-size: 0.9rem;
    cursor: pointer;
    box-shadow: var(--shadow);
}

.ios-hint {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: calc(16px + env(safe-area-inset-bottom));
    z-index: 85;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 12px 14px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--card);
    box-shadow: var(--shadow);
    font-size: 0.9rem;
}

.ios-hint button {
    border: none;
    background: transparent;
    color: var(--muted);
    font-size: 1.1rem;
    cursor: pointer;
}

.scroll-bottom {
    position: absolute;
    right: 14px;
    bottom: calc(110px + env(safe-area-inset-bottom));
    z-index: 20;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--card);
    color: var(--text);
    box-shadow: var(--shadow);
    font-size: 1rem;
    cursor: pointer;
}

.code-block {
    position: relative;
}

.code-block pre {
    padding-top: 34px;
}

.code-copy {
    position: absolute;
    top: 6px;
    right: 6px;
    z-index: 2;
    padding: 3px 8px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--card);
    color: var(--muted);
    font: inherit;
    font-size: 0.72rem;
    cursor: pointer;
}

.code-copy:hover {
    color: var(--accent);
    border-color: var(--accent);
}

/* --- Карточка сгенерированной картинки в ленте чата --- */

.message.image-message {
    max-width: min(520px, 92%);
    padding: 0;
    background: transparent;
    border: none;
    border-radius: 0;
}

.image-card {
    margin: 0;
    padding: 10px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 14px;
    border-bottom-left-radius: 4px;
    box-shadow: var(--shadow);
}

.image-card-img {
    display: block;
    width: 100%;
    max-height: 420px;
    object-fit: contain;
    border-radius: 10px;
    background: var(--bg);
}

.image-card-caption {
    margin-top: 8px;
    color: var(--muted);
    font-size: 0.82rem;
    line-height: 1.35;
}

.image-card-actions {
    margin-top: 8px;
    display: flex;
    justify-content: flex-end;
}

.image-card-download {
    color: var(--accent);
    font-size: 0.88rem;
    text-decoration: none;
}

.image-card-download:hover {
    text-decoration: underline;
}

/* --- Карточка собранной презентации в ленте чата --- */

.message.presentation-message {
    max-width: min(480px, 92%);
    padding: 0;
    background: transparent;
    border: none;
    border-radius: 0;
}

.presentation-card {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 14px;
    border-bottom-left-radius: 4px;
    box-shadow: var(--shadow);
}

.presentation-icon {
    font-size: 1.6rem;
    line-height: 1;
}

.presentation-text {
    flex: 1;
    min-width: 0;
}

.presentation-title {
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.presentation-meta {
    margin-top: 2px;
    color: var(--muted);
    font-size: 0.82rem;
}

.presentation-download {
    color: var(--accent);
    font-size: 0.9rem;
    text-decoration: none;
    white-space: nowrap;
}

.presentation-download:hover {
    text-decoration: underline;
}

/* --- Иерархия проектов в списках (docs/project_codes.md) --- */

.sheet-row.nested {
    padding-left: 34px;
}

.sheet-row.static {
    cursor: default;
    opacity: 0.85;
}

.sheet-row.static:hover {
    background: transparent;
}

.kb-card.nested {
    margin-left: 28px;
    width: calc(100% - 28px);
    border-left: 3px solid var(--border);
}

/* --- AI-агенты (docs/agents_plan.md, v1.13.0) --- */

.sheet-body textarea,
.sheet-body select {
    width: 100%;
    margin-top: 4px;
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text);
    font: inherit;
}

.sheet-body textarea {
    min-height: 120px;
    resize: both;
    max-width: 100%;
}

.agent-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 12px 0 4px;
}

.agent-actions button {
    width: auto;
    margin: 0;
    padding: 10px 14px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text);
    font: inherit;
    cursor: pointer;
}

.agent-actions button.primary {
    background: var(--accent);
    color: var(--accent-text);
    border-color: transparent;
    font-weight: 600;
}

.agent-actions button:disabled {
    opacity: 0.5;
    cursor: default;
}

.agent-run {
    cursor: pointer;
}

.sheet-actions {
    position: sticky;
    bottom: -6px;
    z-index: 2;
    margin: 14px -6px 0;
    padding: 10px 6px 6px;
    background: var(--sheet-bg);
    border-top: 1px solid var(--border);
}

.sheet-actions button.primary {
    width: 100%;
    padding: 12px 16px;
    border: none;
    border-radius: 10px;
    background: var(--accent);
    color: var(--accent-text);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}

.sheet-actions button.primary:disabled {
    opacity: 0.6;
}

/* --- Отладка агентов и скиллов (v1.16.0) --- */

.debug-card {
    margin: 2px 12px;
    padding: 5px 10px;
    border-left: 3px solid var(--border);
    color: var(--muted);
    font-size: 0.82rem;
    line-height: 1.35;
    white-space: pre-wrap;
    word-break: break-word;
}

.debug-card[data-kind="agent_start"],
.debug-card[data-kind="agent_call"] {
    border-left-color: var(--accent);
}

.debug-card[data-kind="agent_finish"],
.debug-card[data-kind="agent_result"] {
    border-left-color: #2e7d32;
}
