/* ======== Мобильные панели: левый drawer, bottom sheet, контекстное меню (Agent B) ======== */

/* ---------- Левый drawer (история разговоров) ---------- */
.drawer-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s;
}
.drawer-overlay.open {
    opacity: 1;
    pointer-events: auto;
}

.drawer {
    position: fixed;
    top: 0;
    left: 0;
    width: 80vw;
    max-width: 320px;
    height: 100dvh;
    height: 100vh;
    background: var(--card-bg);
    z-index: 101;
    transform: translateX(-100%);
    transition: transform 0.25s;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    touch-action: pan-y;
    -webkit-overflow-scrolling: touch;
    box-shadow: var(--card-shadow);
}
.drawer.open {
    transform: translateX(0);
}

#drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 12px 8px 12px 16px;
    padding-top: max(12px, env(safe-area-inset-top));
    background: var(--drawer-head-bg);
    border-bottom: 1px solid var(--drawer-border);
    flex: 0 0 auto;
}
.drawer-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
#drawer-close {
    min-width: 44px;
    min-height: 44px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    color: var(--text);
    border: 0;
    border-radius: 10px;
    font-size: 18px;
    flex: 0 0 auto;
}
#drawer-close:active { background: var(--field-bg); }
@media (hover: hover) {
    #drawer-close:hover { background: var(--field-bg); }
}

#drawer-body {
    flex: 1 1 auto;
    padding: 12px;
}

/* Перенесённая карточка «История разговоров» внутри шторки */
#drawer .card {
    margin-bottom: 0;
    box-shadow: none;
}
#drawer .sessions-list {
    /* список не скроллится сам — скроллится вся шторка */
    max-height: none;
}

/* ---------- Полоса чипов-тегов над списком сессий ---------- */
.session-tag-bar {
    display: flex;
    gap: 6px;
    padding: 6px 0;
    overflow-x: auto;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-x;
    scrollbar-width: none;
}
.session-tag-bar::-webkit-scrollbar { display: none; }

.session-tag-chip {
    display: inline-flex;
    align-items: center;
    flex: 0 0 auto;
    min-height: 32px;
    padding: 4px 10px;
    border-radius: 16px;
    border: 1px solid var(--field-border);
    background: var(--card-bg);
    color: var(--text);
    font-size: 12px;
    font-family: var(--font);
    line-height: 1.2;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.session-tag-chip.active {
    background: var(--btn-action-bg);
    color: var(--btn-action-fg);
    border-color: var(--btn-action-bg);
    font-weight: 600;
}
.session-tag-chip:active { filter: brightness(0.94); }
@media (hover: hover) {
    .session-tag-chip:not(.active):hover { border-color: var(--muted); }
}

/* Маленькие бейджи тегов на карточке разговора */
.session-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin: 2px 0 3px;
}
.session-tag-badge {
    display: inline-flex;
    align-items: center;
    font-size: 10px;
    line-height: 1.4;
    opacity: 0.75;
    padding: 1px 6px;
    border-radius: 8px;
    background: rgba(128, 128, 128, 0.15);
    color: var(--text);
    white-space: nowrap;
}
/* Цветная метка темы: точка слева, фон бейджа остаётся нейтральным */
.session-tag-badge::before {
    content: '';
    flex: 0 0 auto;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    margin-right: 4px;
    background: var(--tag-color, #868e96);
}
.session-tag-badge[data-tag="#авто"] { --tag-color: #f76707; }
.session-tag-badge[data-tag="#ноутбуки"] { --tag-color: #339af0; }
.session-tag-badge[data-tag="#документы"] { --tag-color: #40c057; }
.session-tag-badge[data-tag="#медицина"] { --tag-color: #fa5252; }
.session-tag-badge[data-tag="#поездки"] { --tag-color: #cc5de8; }

@media (prefers-reduced-motion: reduce) {
    .drawer,
    .drawer-overlay { transition: none; }
}

/* ---------- Тап-таргеты ≥ 44px на тач-устройствах (контракт §6) ---------- */
@media (hover: none) {
    .copy-btn {
        width: 44px;
        height: 44px;
        min-height: 44px;
    }
    .session-hide-btn {
        min-width: 44px;
        min-height: 44px;
        font-size: 16px;
    }
}

/* ---------- Контекстное меню сообщения (long-press) ---------- */
.msg-menu {
    position: fixed;
    z-index: 300;
    min-width: 170px;
    background: var(--menu-bg);
    border: 1px solid var(--drawer-border);
    border-radius: 14px;
    box-shadow: 0 10px 32px rgba(0, 0, 0, 0.22);
    padding: 4px;
}
.msg-menu button {
    display: block;
    width: 100%;
    min-height: 44px;
    padding: 0 16px;
    background: transparent;
    border: 0;
    border-radius: 10px;
    color: var(--text);
    font-size: 15px;
    text-align: left;
}
.msg-menu button:active { background: var(--drawer-head-bg); }
@media (hover: hover) {
    .msg-menu button:hover { background: var(--drawer-head-bg); }
}
.msg-menu button.msg-danger { color: var(--error-fg); }
.msg-menu button.msg-danger:active { background: var(--error-bg); }

/* ---------- Bottom sheet ---------- */
.bottom-sheet {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    max-height: 90vh;
    background: var(--card-bg);
    border-radius: 16px 16px 0 0;
    z-index: 102;
    transform: translateY(100%);
    transition: transform 0.3s, max-height 0.25s;
    display: flex;
    flex-direction: column;
    border-top: 1px solid var(--drawer-border);
    box-shadow: var(--card-shadow);
}
.bottom-sheet.open {
    transform: translateY(0);
}
.bottom-sheet.dragging { transition: none; }
.bottom-sheet.snap-half { max-height: 50vh; }
.bottom-sheet.snap-full { max-height: 90vh; }

.sheet-header {
    flex: 0 0 auto;
    background: var(--card-bg);
    border-radius: 16px 16px 0 0;
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
}
.sheet-handle {
    width: 36px;
    height: 4px;
    background: var(--muted);
    border-radius: 2px;
    margin: 8px auto;
}
.sheet-title-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 8px 10px 16px;
}
.sheet-title {
    flex: 1;
    font-size: 16px;
    font-weight: 700;
    color: var(--text);
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sheet-back,
.sheet-close {
    min-width: 44px;
    min-height: 44px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    color: var(--text);
    border: 0;
    border-radius: 10px;
    font-size: 20px;
    flex: 0 0 auto;
}
.sheet-back[hidden],
.sheet-close[hidden] { display: none; }
.sheet-back:active,
.sheet-close:active { background: var(--field-bg); }
@media (hover: hover) {
    .sheet-back:hover,
    .sheet-close:hover { background: var(--field-bg); }
}

.sheet-body {
    flex: 1;
    overflow-y: auto;
    padding: 0 16px;
    padding-bottom: max(16px, env(safe-area-inset-bottom));
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
}
/* Перенесённые в шторку карточки-панели */
.sheet-body .card {
    margin: 0 0 12px;
    box-shadow: none;
}

/* Пункты меню увеличенной высоты (тап-таргет ≥ 44px) */
.sheet-item {
    display: flex;
    align-items: center;
    gap: 14px;
    width: 100%;
    min-height: 52px;
    padding: 10px 8px;
    background: transparent;
    border: 0;
    border-bottom: 1px solid var(--drawer-border);
    border-radius: 0;
    color: var(--text);
    font-size: 16px;
    font-weight: 400;
    text-align: left;
}
.sheet-item:last-child { border-bottom: 0; }
.sheet-item:active { background: var(--drawer-head-bg); }
@media (hover: hover) {
    .sheet-item:hover { background: var(--drawer-head-bg); }
}
.sheet-item-icon { font-size: 20px; flex: 0 0 auto; line-height: 1; }
.sheet-item-label { flex: 1; font-weight: 600; }
.sheet-item-sub {
    font-size: 12px;
    color: var(--muted);
    text-align: right;
    max-width: 42%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.sheet-item .sheet-check {
    flex: 0 0 22px;
    font-size: 16px;
    color: var(--strong-fg);
    text-align: right;
}
.sheet-note {
    padding: 18px 6px;
    color: var(--muted);
    font-size: 14px;
    line-height: 1.5;
    text-align: center;
}

/* ---------- Sub-sheet «О себе (память)» ---------- */
.user-context-hint {
    padding: 12px 2px 10px;
    text-align: left;
}
.user-context-input {
    display: block;
    width: 100%;
    min-height: 120px;
    max-height: 45vh;
    line-height: 1.5;
    resize: vertical;
}
.user-context-save {
    display: block;
    width: 100%;
    margin-top: 12px;
}

@media (min-width: 540px) {
    .bottom-sheet {
        left: 50%;
        right: auto;
        width: 520px;
        margin-left: -260px;
    }
}
/* На десктопе (с sidebar 280px) центрируем шторку в правой колонке */
@media (min-width: 768px) {
    .bottom-sheet {
        left: calc(50% + 140px);
        margin-left: -260px;
    }
}
@media (prefers-reduced-motion: reduce) {
    .bottom-sheet { transition: none; }
}

/* ===== FTS5 Search Results in Drawer ===== */
.fts-search-results {
    max-height: 50vh;
    overflow-y: auto;
    background: var(--card-bg);
    border-top: 1px solid var(--drawer-border);
    border-bottom: 1px solid var(--drawer-border);
    margin-top: 4px;
    z-index: 2;
}

.history-search-input {
    /* уже задано inline в HTML, но можно переопределить */
    box-sizing: border-box;
}

/* Сниппеты в результатах поиска */
.fts-result-item mark {
    background: transparent;
    color: var(--link);
    font-weight: 700;
    padding: 0 2px;
    border-radius: 2px;
}

.fts-result-item:last-child {
    border-bottom: none;
}

@media (hover: hover) {
    .fts-result-item:hover {
        background: var(--hover-bg) !important;
    }
}

/* ======== Десктоп: drawer → постоянный sidebar ======== */
@media (min-width: 768px) {
    .drawer-overlay { display: none !important; }
    .drawer {
        position: relative;
        top: auto;
        left: auto;
        width: 100%;
        max-width: none;
        height: auto;
        transform: none !important;
        z-index: 1;
        grid-row: 2;
        grid-column: 1;
        border-right: 1px solid var(--drawer-border);
    }
    .drawer:not(.open) {
        /* на десктопе шторка видна всегда — даже без класса open */
        transform: none !important;
    }
    #drawer-header { border-bottom-style: solid; }
    #drawer-close { display: none; }
}