/* ============================================================
   mobile.css — телефонная версия и PWA. Грузится ПОСЛЕ всех остальных стилей и
   переопределяет их только на узком экране (≤860px) / на сенсорных устройствах.
   Логика раскрывающейся панели и «Назад» — mobile.js.
   ============================================================ */

:root{--rail-h:52px;--safe-t:env(safe-area-inset-top,0px);--safe-b:env(safe-area-inset-bottom,0px);--safe-l:env(safe-area-inset-left,0px);--safe-r:env(safe-area-inset-right,0px)}

/* вне телефона эти элементы не существуют */
.rail-expand,.rail-backdrop,.net-bar,.m-chat-bar,.rail-support,.m-jump,.m-ptr,.m-update,.m-fs-head,.m-open-chat,.m-plus,.m-call,.m-ln-bar,.m-filter-toggle,.m-sheet-back{display:none}

html{-webkit-text-size-adjust:100%;text-size-adjust:100%}
@media (pointer:coarse){
    a,button,summary,select,label,[role=button],.chat-item{touch-action:manipulation;-webkit-tap-highlight-color:transparent}
}

@media (max-width:860px){
    html,body{overscroll-behavior:none;overflow:hidden}
    body{font-size:15px;-webkit-touch-callout:none}
    /* текст можно выделять и копировать там, где это нужно (переписка, поля) */
    input,textarea,.context-panel,.admin-panel-body{-webkit-touch-callout:default}
    /* долгое нажатие по сообщению открывает своё меню, поэтому системное выделение отключено (есть пункт «Выделить часть текста») */
    .messages-container .message{-webkit-user-select:none;user-select:none}
    .messages-container .message.m-selectable{-webkit-user-select:text;user-select:text;outline:2px solid var(--accent);outline-offset:2px}
    .messages-container .message.m-pressed{filter:brightness(.94);transition:filter .15s}
    .messages-container .message.m-selectable *{-webkit-user-select:text;user-select:text}
    ::-webkit-scrollbar{display:none}
    *{scrollbar-width:none}

    /* ---------- оболочка: ровно на видимую область (dvh / клавиатура через --app-h) ---------- */
    .container,body.impersonating .container{
        position:fixed;top:0;left:0;right:0;margin:0;
        height:var(--app-h,100dvh);
        padding-left:var(--safe-l);padding-right:var(--safe-r);
    }
    body.impersonating .container{top:44px;height:calc(var(--app-h,100dvh) - 44px)}

    /* ---------- верхняя панель разделов ---------- */
    .icon-rail{
        height:calc(var(--rail-h) + var(--safe-t))!important;padding:var(--safe-t) 6px 0 0;gap:2px;
        background:var(--surface);align-items:center;flex-basis:auto!important;
        border-bottom:1px solid var(--border);
        transition:none;
    }
    .icon-rail .rail-logo{order:1;margin:0 6px 0 4px;width:30px;height:20px}
    .rail-expand{order:0}
    .icon-rail .rail-btn{order:2}
    .icon-rail .rail-sep{order:2;flex:none;width:1px;height:22px;background:var(--border);margin:0 4px}
    .icon-rail .rail-btn[hidden]{display:none}
    .rail-btn{width:46px;min-width:46px;height:44px;padding:0;justify-content:center;border-radius:12px;gap:0}
    .rail-btn .icon{width:22px;height:22px}
    .rail-btn.active{background:var(--accent-soft);color:var(--accent-text);box-shadow:inset 0 -2px 0 var(--accent)}
    .rail-label{display:none}
    .rail-badge{top:3px;right:3px}

    /* кнопка «>>»: самая первая, всегда на виду (прилипает к левому краю при прокрутке ленты) */
    .rail-expand{
        display:flex;align-items:center;justify-content:center;flex:none;position:sticky;left:0;z-index:3;
        width:46px;height:44px;margin:0 2px 0 0;padding:0;border:none;border-radius:12px;cursor:pointer;
        background:var(--surface);color:var(--accent-text);
        box-shadow:6px 0 8px -4px var(--surface);
    }
    .rail-expand .icon{width:24px;height:24px;stroke-width:2.2;transition:transform .2s var(--ease)}
    .rail-expand:active{background:var(--accent-soft)}
    .rail-expand-label{display:none}

    /* рельсовая «засветка» по краям не нужна поверх липкой кнопки слева */
    .icon-rail.fade-l,.icon-rail.fade-l.fade-r{-webkit-mask-image:linear-gradient(to right,#000 calc(100% - 36px),transparent);mask-image:linear-gradient(to right,#000 calc(100% - 36px),transparent)}
    .icon-rail.fade-l:not(.fade-r){-webkit-mask-image:none;mask-image:none}

    /* ---------- панель раскрыта: сетка плиток с названиями ---------- */
    body.rail-open .rail-backdrop{display:block;position:fixed;inset:0;z-index:180;background:rgba(10,12,16,.46);animation:m-fade .18s var(--ease)}
    body.rail-open .icon-rail{
        position:fixed;top:0;left:0;right:0;z-index:190;width:100%!important;
        height:auto!important;max-height:calc(var(--app-h,100dvh) - 24px);
        display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:6px;align-content:start;
        padding:calc(var(--safe-t) + 8px) calc(10px + var(--safe-r)) 12px calc(10px + var(--safe-l));
        overflow-x:hidden;overflow-y:auto;-webkit-mask-image:none;mask-image:none;
        border-radius:0 0 22px 22px;border-bottom:none;box-shadow:0 18px 40px -12px rgba(10,12,16,.45);
        animation:m-drop .2s var(--ease);
    }
    body.rail-open .rail-logo{display:none}
    body.rail-open .rail-spacer{display:none}
    body.rail-open .icon-rail .rail-sep{display:none}
    body.rail-open .icon-rail .rail-btn,body.rail-open .rail-expand{
        order:0;width:auto;min-width:0;height:auto;min-height:76px;padding:10px 4px 8px;flex-direction:column;
        justify-content:center;gap:6px;border-radius:14px;background:var(--surface-2);color:var(--text-dim);box-shadow:none;position:relative;
    }
    body.rail-open .icon-rail .rail-btn.active{background:var(--accent-soft);color:var(--accent-text);box-shadow:inset 0 0 0 1.5px var(--accent)}
    body.rail-open .rail-label{display:block;opacity:1;font-size:12.5px;line-height:1.2;text-align:center;white-space:normal;overflow-wrap:anywhere;max-width:100%;color:inherit}
    body.rail-open .rail-btn .icon{width:24px;height:24px}
    body.rail-open .rail-expand{position:static;grid-column:1;box-shadow:none;color:var(--accent-text);background:var(--accent-soft)}
    body.rail-open .rail-expand .icon{transform:rotate(180deg)}
    body.rail-open .rail-expand-label{display:block}
    body.rail-open .rail-badge{top:6px;right:calc(50% - 22px)}
    body.rail-open #logoutRailBtn:not([hidden]){color:var(--danger-text)}
    @keyframes m-drop{from{transform:translateY(-14px);opacity:0}to{transform:none;opacity:1}}
    @keyframes m-fade{from{opacity:0}to{opacity:1}}

    /* ---------- основные колонки под новой высотой панели ---------- */
    .sidebar,.main-area,.context-panel,.admin-panel{inset:calc(var(--rail-h) + var(--safe-t)) var(--safe-r) 0 var(--safe-l)}
    .sidebar{padding-bottom:var(--safe-b)}
    .admin-panel{padding-bottom:0}
    .admin-panel-body{padding:14px 12px calc(24px + var(--safe-b))!important}

    /* ---------- поля ввода: 16px — Safari/Chrome не «зумят» страницу при фокусе ---------- */
    input:not([type=checkbox]):not([type=radio]):not([type=range]):not([type=file]):not([type=color]),select,textarea{font-size:16px!important}
    input:not([type=checkbox]):not([type=radio]):not([type=range]):not([type=file]):not([type=color]),select{min-height:42px}
    /* чекбоксы/радио рисует uikit.css (размер — через --ck, width/height там с !important): на телефоне крупнее, по всему приложению */
    input[type=checkbox],input[type=radio]{--ck:20px!important}

    /* ---------- шапка списка чатов ---------- */
    .sidebar-header{padding:8px 12px 6px;gap:8px}
    .sidebar-header .global-search input,#globalSearch{padding:10px 12px 10px 34px;min-height:42px;border-radius:12px}
    .global-search::before{left:12px;top:14px;width:15px;height:15px}
    .company-filter select{min-height:42px}
    .assign-filter{padding:4px 12px}
    .chat-tabs-row{padding:6px 12px;gap:8px}
    .af-btn{min-height:38px}

    /* ---------- список чатов ---------- */
    .chat-item{padding:12px 14px}
    .chat-item:active{background:var(--surface-2)}
    .chat-name{font-size:15.5px}
    .chat-time{font-size:12px}
    .chat-item-preview{font-size:14px;padding-right:0;margin-top:1px}
    .chat-item-phone{font-size:12px}
    .chat-date-sep{padding:10px 14px 4px;font-size:11.5px}
    .invite-bar{padding:8px 12px}
    .invite-btn{width:40px;height:40px}

    /* ---------- переписка ---------- */
    .m-chat-bar{display:flex;align-items:center;gap:8px;flex:none;padding:6px 8px;background:var(--surface);border-bottom:1px solid var(--border);min-height:54px}
    .m-chat-bar .chat-back-btn,.m-chat-bar .chat-info-btn,.context-back-btn{
        position:static!important;display:flex!important;flex:none;width:42px;height:42px;margin:0;padding:0;justify-content:center;align-items:center;
        border-radius:12px;border:none;background:var(--surface-2);color:var(--text)}
    .m-chat-bar .chat-info-btn[hidden]{display:none!important}
    .m-chat-title{flex:1;min-width:0;display:flex;flex-direction:column;line-height:1.25}
    .m-chat-title b{font-size:16px;font-weight:600;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
    .m-chat-title span{font-size:12.5px;color:var(--text-faint);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
    .context-back-btn{position:absolute!important;left:8px;top:8px}
    .chat-header{padding:0 14px}
    .chat-header-content{flex-wrap:wrap;gap:2px 8px}
    .messages-container{padding:12px 10px;gap:8px;-webkit-overflow-scrolling:touch;overscroll-behavior:contain}
    .message{max-width:88%;font-size:15px;padding:9px 12px;line-height:1.45}
    .message img,.message video{max-width:100%;height:auto}
    .message-header{font-size:11.5px}
    .date-label{font-size:12px}

    /* композер */
    .message-input-container{padding:8px 10px calc(8px + var(--safe-b));gap:8px}
    .composer-row{gap:6px;flex-wrap:nowrap}
    .composer-attach-chip{flex:0 0 100%}
    .composer-row:has(.composer-attach-chip:not([hidden])){flex-wrap:wrap}
    .composer-attach-btn{width:40px;height:40px;border-radius:50%;background:var(--surface-2)}
    .composer-input-wrap{min-width:0}
    #messageInput{min-height:42px;padding:10px 14px;border-radius:21px;max-height:132px;line-height:1.35}
    .composer-input-wrap #messageInput{padding-right:14px}
    .tpl-save{display:none!important}
    .send-button{width:42px;height:42px;padding:0;border-radius:50%;font-size:0;display:flex;align-items:center;justify-content:center;position:relative}
    .send-button span{display:none}
    .send-button::before{content:'';width:20px;height:20px;background:#fff;
        -webkit-mask:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 19V5M5 12l7-7 7 7'/%3E%3C/svg%3E") center/contain no-repeat;
        mask:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 19V5M5 12l7-7 7 7'/%3E%3C/svg%3E") center/contain no-repeat}
    .pause-chat-btn{height:46px}
    .message-input-container:has(.pause-chat-btn:not([hidden])){padding:10px 12px calc(10px + var(--safe-b))}
    .message-input-container:has(.pause-chat-btn:not([hidden])) .pause-chat-btn{height:46px}
    .tpl-pop{left:10px;right:10px}
    .typing-bar{padding:2px 14px}

    /* профиль клиента */
    .context-panel{padding-top:60px;padding-bottom:var(--safe-b)}

    /* ---------- заголовки разделов ---------- */
    .admin-panel-head{padding:10px 12px;gap:8px}
    .admin-panel-head h2{font-size:17px}
    .admin-panel-head select,.admin-panel-head input{flex:1 1 100%;min-width:0;min-height:42px}
    .admin-panel-head button{min-height:42px;padding:8px 14px;border-radius:10px}

    /* ---------- таблицы: горизонтальный свайп внутри блока, страница не уезжает ---------- */
    .admin-panel-body table,.admin-panel table:not(.m-keep){display:block;max-width:100%;overflow-x:auto;-webkit-overflow-scrolling:touch}
    .admin-panel-body pre{overflow-x:auto;max-width:100%}

    /* выбор компании в шапке раздела: на всю ширину, как обычное поле (десктопная оранжевая «пилюля» на телефоне выглядела как главная кнопка) */
    .admin-panel-head .company-switch{flex:1 1 100%;min-width:0}
    .admin-panel-head .cs-btn{min-height:42px;padding:8px 12px;background:var(--field-bg);color:var(--text);border:1px solid var(--field-border);border-radius:10px;font-size:15px}
    .admin-panel-head .cs-btn:hover{border-color:var(--field-border-hover)}
    .admin-panel-head .cs-btn.open,.admin-panel-head .cs-btn:focus-visible{border-color:var(--accent)}
    .admin-panel-head .cs-btn .icon{width:16px;height:16px}
    .cs-panel{max-height:min(60dvh,420px)}
    .cs-opt{min-height:44px}
    .admin-panel-head .cs-label,.cs-btn{font-size:15px}

    /* «Установить» — только в раскрытой панели */
    body:not(.rail-open) .rail-install{display:none!important}

    /* ---------- читаемые размеры: мелкий десктопный текст → 13.5px, бейджи → 12px ---------- */
    .ld-muted,.ld-chip,.ld-chipi,.ld-stage,.ct-name,.ct-sub,.ct-date,.ct-count,.wh-add-btn,.bots-tab,.bots-btn,.bots-muted,.asst-switch-btn,
    .ln-chip,.ln-btn,.ln-muted,.ln-crumbs,.ln-video-cap,.in-bubble-hint,.in-muted,.in-note,.st-k,.bar-label,.bar-val,.analytics-subhead,
    .audit-time,.audit-actor,.audit-project,.audit-target,.audit-more,.access-hint,.u-email,.u-edit-btn,.mrow-email,.ugroup-title,
    .settings-field,.ops-muted,.settings-tab,.bl-muted,.bl-status,.sp-muted,.sp-org-n,.mp-note,.up-chip,.up-sub,.admin-panel-body label,
    .admin-panel-body td,.admin-panel-body th,.sp-head span,.sp-msg b,.sp-msg time,.access-flow-num{font-size:13.5px}
    .in-badge,.bots-badge,.ln-badge,.ln-cat,.people-badge,.company-badge,.flag-pill,.u-role-badge,.u-projcount,.ugroup-count,.audit-action-badge,.up-badge,.ts-count,.cs-badge{font-size:12px}
    .ln-item{font-size:14.5px;padding:10px 10px}
    .modal-btn,.ln-btn,.ld-chip,.in-btn,.bots-btn,.settings-tab,.bots-tab,.af-btn,.wh-add-btn{min-height:40px}
    .ln-chip{min-height:34px;display:inline-flex;align-items:center}

    /* ---------- Обучение ---------- */
    .ln-nav{max-height:34dvh;padding:10px 12px}
    .ln-main{padding:16px 14px calc(40px + var(--safe-b))}
    .ln-head{flex-wrap:wrap}
    .ln-head h1{font-size:22px;line-height:1.25}
    .ln-lead{font-size:15px}
    .ln-video{margin:0 -14px 18px;border-radius:0}
    .ln-article img,.ln-article video,.ln-article iframe{max-width:100%;height:auto}
    .ln-article pre,.ln-article table{max-width:100%;overflow-x:auto;display:block}

    /* пузырь поддержки → плитка «Помощь» в панели; панель переписки — на весь экран */
    .sp-bubble{display:none!important}
    body.rail-open .icon-rail .rail-support{display:flex}
    .rail-expand.has-dot::after,.rail-support.has-dot::after{content:'';position:absolute;top:7px;right:9px;width:10px;height:10px;border-radius:50%;background:var(--danger);border:2px solid var(--surface)}
    body.rail-open .rail-support.has-dot::after{top:8px;right:calc(50% - 22px)}
    .sp-float{left:0;right:0;bottom:0;top:calc(var(--rail-h) + var(--safe-t));width:auto;max-width:none;height:auto;max-height:none;border-radius:0;z-index:150}
    .sp-form{padding:8px 10px calc(8px + var(--safe-b))}
    .sp-form textarea{font-size:16px}
    .sp-modal{align-items:flex-end;padding:0}
    .sp-modal-card{max-width:none;border-radius:20px 20px 0 0;padding-bottom:calc(20px + var(--safe-b))}

    /* ---------- жесты и прокрутка ---------- */
    html,body{touch-action:manipulation}          /* нет «двойного касания = зум»; щипок остаётся (доступность) */
    .chat-list,.messages-container,.admin-panel-body,.context-panel,.ln-main,.ln-nav,.modal-content,.cs-panel,.sp-list,.icon-rail{overscroll-behavior:contain}
    .messages-container{scroll-behavior:auto;overflow-anchor:auto}
    .chat-list{overflow-x:hidden}
    .chat-item{touch-action:pan-y}
    .m-chat-bar,.admin-panel-head{position:relative;z-index:2}

    /* вытянуть список вниз — обновить */
    .m-ptr{display:flex;align-items:center;justify-content:center;height:0;overflow:hidden;flex:none;color:var(--text-faint);transition:height .15s var(--ease);background:var(--surface)}
    .m-ptr .icon{width:22px;height:22px;transition:transform .15s}
    .m-ptr.ready{color:var(--accent-text)}.m-ptr.ready .icon{transform:rotate(180deg)}
    .m-ptr.spin .icon{animation:m-spin .8s linear infinite;transform:none}
    @keyframes m-spin{to{transform:rotate(360deg)}}

    /* «вниз, к последнему» */
    .m-jump{display:flex;align-items:center;justify-content:center;position:absolute;right:12px;bottom:calc(var(--m-comp-h,74px) + 10px + var(--safe-b));z-index:5;width:44px;height:44px;border-radius:50%;
        border:1px solid var(--border);background:var(--surface);color:var(--text-dim);box-shadow:var(--shadow-2);cursor:pointer}
    .m-jump[hidden]{display:none}
    .m-jump .icon{width:22px;height:22px;stroke-width:2.2}

    /* плашка «Вышла новая версия» */
    .m-update{display:flex;align-items:center;gap:12px;position:fixed;left:12px;right:12px;bottom:calc(14px + var(--safe-b));z-index:500;padding:10px 12px 10px 16px;border-radius:14px;background:var(--text);color:var(--bg);box-shadow:var(--shadow-3);font-size:14.5px}
    .m-update span{flex:1}
    .m-update button{border:none;border-radius:10px;background:var(--accent);color:#fff;font-weight:600;padding:9px 16px;min-height:40px;font-size:14.5px}

    /* ручка шторки */
    .modal-content::before{content:'';display:block;width:38px;height:4px;border-radius:4px;background:var(--border-strong);margin:8px auto 0}

    /* ---------- мелкие цели нажатия ---------- */
    .notif-btn{padding:10px;margin:-6px -4px -6px auto}
    .views-btn,.sidebar .views-btn{min-height:38px}
    .audit-toggle{min-width:40px;min-height:40px}
    .u-edit-btn{min-height:38px;padding:0 12px}
    summary{min-height:40px;display:flex;align-items:center}

    /* ---------- «липкий hover» после касания: на сенсорных экранах не оставляем подсветку ---------- */
    @media (hover:none){
        .chat-item:hover{background:transparent}
        .chat-item.chat-unseen:hover,.chat-item.chat-unseen{background:var(--warn-soft)}
        .chat-item.active:hover{background:transparent}
        .rail-btn:hover:not(.active){background:none;color:var(--text-faint)}
        body.rail-open .icon-rail .rail-btn:hover:not(.active){background:var(--surface-2);color:var(--text-dim)}
        .state-badge:hover,.pf-badge:not(.pf-open):hover{padding-right:0}.state-badge:hover .state-badge-word,.pf-badge:not(.pf-open):hover .pf-word{max-width:0;opacity:0}
    }

    /* загрузочный скелет — в форме телефонной раскладки (без десктопной колонки-рейла и сайдбара 340px) */
    .boot-skeleton{flex-direction:column}
    .boot-skeleton .boot-rail{width:100%;flex-direction:row;height:calc(var(--rail-h) + var(--safe-t));padding:var(--safe-t) 12px 0;gap:16px;border-right:none;border-bottom:1px solid var(--border);justify-content:flex-start}
    .boot-sidebar{width:100%;flex:1;border-right:none}
    .boot-main{display:none}

    .cu-row{flex-wrap:wrap;gap:8px}
    .cu-row>label{flex:1 1 150px;min-width:0}
    .cu-row input,.cu-row select{width:100%;min-width:0}

    /* ---------- Заявки ---------- */
    #leadsBody{padding:12px 12px calc(24px + var(--safe-b))}
    .ld-bar{gap:8px;margin-bottom:10px}
    .ld-bar .ld-select{flex:1 1 100%;min-height:42px;font-size:16px}
    .ld-chips{flex:1 1 100%;overflow-x:auto;flex-wrap:nowrap;padding-bottom:2px;-webkit-overflow-scrolling:touch}
    .ld-chip{flex:none;min-height:38px;padding:6px 15px;font-size:14px}
    .ld-search,#ldSearch{flex:1 1 100%;width:100%}
    .ld-bar>span[style]{display:none}
    .ld-bar .modal-btn{flex:1 1 auto;min-height:42px}
    .ld-card{padding:12px 14px}
    .ld-list.board{scroll-snap-type:x mandatory;-webkit-overflow-scrolling:touch}
    .ld-list.board .ld-col{scroll-snap-align:center}
    .ld-foot{display:flex;flex-wrap:wrap;gap:8px;align-items:center}
    .ld-acts .modal-btn,.ld-acts button{min-height:42px}

    /* ---------- Контакты: строка таблицы → карточка ---------- */
    .ct-table{border:none;border-radius:0;overflow:visible;background:none}
    .ct-table table{display:block;overflow:visible}
    .ct-table thead{display:none}
    .ct-table tbody{display:flex;flex-direction:column;gap:8px}
    .ct-table tbody tr{
        display:grid;grid-template-columns:auto minmax(0,1fr) auto;grid-template-areas:"chk name stat" "chk chan asg";gap:2px 10px;align-items:center;
        padding:12px;background:var(--surface);border:1px solid var(--border);border-radius:14px;
    }
    .ct-table tbody tr:active{background:var(--surface-2)}
    .ct-table td{padding:0!important;border:none!important;display:block;min-width:0}
    .ct-table td:nth-child(1){grid-area:chk;align-self:start;padding-top:2px!important}
    .ct-table td:nth-child(2){grid-area:name}
    .ct-table td:nth-child(3){grid-area:chan;color:var(--text-faint);font-size:13px}
    .ct-table td:nth-child(4){grid-area:stat;text-align:right}
    .ct-table td:nth-child(5){grid-area:asg;text-align:right;color:var(--text-faint);font-size:13px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
    .ct-name{font-size:15.5px;font-weight:600}
    .ct-sub{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
    .ct-bar{flex-wrap:wrap;gap:8px}
    .ct-bar>*{flex:1 1 140px;min-width:0}

    /* ---------- модалки — «шторки» снизу ---------- */
    .modal{padding:0;align-items:flex-end}
    .modal-content{width:100%!important;max-width:none!important;max-height:calc(var(--app-h,100dvh) - 36px);border-radius:20px 20px 0 0!important;overflow-y:auto;padding-bottom:var(--safe-b);animation:m-sheet .22s var(--ease)}
    .modal-footer{flex-wrap:wrap;padding:12px 16px calc(12px + var(--safe-b))}
    .modal-footer .modal-btn{flex:1 1 auto;min-height:44px}
    .modal-btn{min-height:44px}
    @keyframes m-sheet{from{transform:translateY(24px);opacity:.4}to{transform:none;opacity:1}}

    /* ---------- тосты над жестовой полосой ---------- */
    .toast-stack{left:12px;right:12px;bottom:calc(14px + var(--safe-b));top:auto;align-items:stretch}

    /* плашка «нет сети» под панелью */
    .net-bar{display:block;position:fixed;left:0;right:0;top:calc(var(--rail-h) + var(--safe-t));z-index:170;padding:6px 12px;text-align:center;font-size:12.5px;font-weight:600;background:var(--danger);color:#fff}
    .net-bar[hidden]{display:none}

    /* когда экранная клавиатура открыта — прячем второстепенное */
    html.kb-open .icon-rail{display:none}
    html.kb-open .sidebar,html.kb-open .main-area,html.kb-open .context-panel,html.kb-open .admin-panel{top:0}
}

/* установленное приложение: статус-бар окрашивает система, отступ сверху не нужен */
html.is-standalone .net-bar{top:calc(var(--rail-h) + var(--safe-t))}

/* пункт «Установить» виден только когда есть что ставить */
.rail-install[hidden]{display:none!important}

/* телефон в альбомной ориентации: панель ниже, чтобы не съедать высоту */
@media (max-width:860px) and (max-height:480px){
    :root{--rail-h:44px}
    .rail-btn,.rail-expand{height:38px}
    body.rail-open .icon-rail{grid-template-columns:repeat(6,minmax(0,1fr))}
    body.rail-open .icon-rail .rail-btn,body.rail-open .rail-expand{min-height:62px}
}

@media (max-width:360px){
    body.rail-open .icon-rail{grid-template-columns:repeat(2,minmax(0,1fr))}
}
@media (min-width:480px) and (max-width:860px){
    body.rail-open .icon-rail{grid-template-columns:repeat(4,minmax(0,1fr))}
}

/* ---------- узкие телефоны (≤374px) ---------- */
@media (max-width:374px){
    .composer-attach-btn{width:36px;height:36px}
    .composer-row{gap:4px}
    .message-input-container{padding-left:6px;padding-right:6px}
    .send-button{width:40px;height:40px}
    .admin-panel input[type=date]{min-width:0;width:100%}
    .chat-name{font-size:15px}
}
@media (max-width:860px){
    #messageInput::placeholder{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
    #messageInput:focus-visible,#globalSearch:focus-visible{box-shadow:none}
}

/* ---------- альбомная ориентация телефона: в открытом чате панель разделов прячем, чтобы переписке хватало высоты ---------- */
@media (max-width:860px) and (max-height:480px){
    .sidebar-header{padding:4px 10px;gap:4px}
    .sidebar-header .global-search input,#globalSearch{min-height:34px;padding-top:6px;padding-bottom:6px}
    .global-search::before{top:10px}
    .company-filter select,.chat-tabs-row .af-btn{min-height:34px}
    .chat-item{padding:8px 12px}
    .m-chat-bar{min-height:44px;padding-top:3px;padding-bottom:3px}
    .m-chat-bar .chat-back-btn,.m-chat-bar .chat-info-btn{width:38px;height:38px}
    .message-input-container{padding-top:5px;padding-bottom:calc(5px + var(--safe-b))}
    .messages-container{padding:8px 10px}
}

/* ---------- планшет (600–860px): список чатов и переписка рядом ---------- */
@media (min-width:600px) and (max-width:860px){
    .sidebar{right:auto;width:300px!important;flex:none;transform:none!important;border-right:1px solid var(--border)}
    .main-area{left:calc(300px + var(--safe-l));width:auto;transform:none!important}
    body.chat-open .sidebar{transform:none!important}
    .m-chat-bar .chat-back-btn{display:none!important}
    .message{max-width:78%}
    .admin-panel-body{padding-left:18px!important;padding-right:18px!important}
    body.rail-open .icon-rail{grid-template-columns:repeat(6,minmax(0,1fr))}
}

/* ============================================================
   Содержимое вкладок: Ассистент / Интеграции / Настройки / Тариф
   ============================================================ */
@media (max-width:860px){
    /* ---------- Ассистент: компактная шапка ---------- */
    .asst-switch{padding:6px 10px;gap:6px}
    .asst-switch-btn{flex:1 1 0;min-height:40px;padding:6px 8px;font-size:14px;line-height:1.15}
    .bots-head{padding:8px 12px;gap:6px 8px}
    .bots-head h2{display:none}
    .bots-head .company-switch{flex:1 1 100%!important;width:auto!important;order:-1}
    .bots-head>span[style]{display:none}
    .bots-head .bots-btn{flex:1 1 auto;min-height:40px}
    .bots-tabs{display:flex;overflow-x:auto;flex-wrap:nowrap;gap:2px;padding:0 6px;scroll-snap-type:x proximity;-webkit-overflow-scrolling:touch;border-bottom:1px solid var(--border);background:var(--surface);position:sticky;top:0;z-index:3}
    .bots-tab{flex:none;min-height:46px;padding:0 14px;font-size:14.5px;scroll-snap-align:center;white-space:nowrap}
    .bots-body{padding:12px 12px calc(24px + var(--safe-b))}
    .bots-card{padding:14px;border-radius:14px}
    .bots-card>.bots-actions:last-child{position:sticky;bottom:0;z-index:2;margin:12px -14px -14px;padding:10px 14px;background:linear-gradient(to top,var(--surface) 78%,transparent);border-radius:0 0 14px 14px}
    .bots-btn,.bots-btn.sm{min-height:42px}
    .bots-row{flex-direction:column;align-items:stretch;gap:4px}
    .bots-split{grid-template-columns:1fr!important}
    .bots-msg{max-width:88%;font-size:15px}
    .bots-trace{max-height:50dvh;overflow:auto;font-size:12.5px}
    textarea.bots-json,.bots-json{font-size:13px}

    /* «Попробуйте своего бота» / симулятор: кнопка → полноэкранный чат */
    .m-chatcard:not(.m-fs) .bots-chat,.m-chatcard:not(.m-fs) .bots-actions{display:none}
    .m-chatcard:not(.m-fs) .m-open-chat{display:flex;align-items:center;justify-content:center;gap:10px;width:100%;min-height:52px;margin-top:12px;border:none;border-radius:14px;background:var(--accent);color:#fff;font:600 16px var(--font-ui)}
    .m-chatcard:not(.m-fs) .m-open-chat .icon{width:22px;height:22px}
    body.m-fs-open .admin-panel{z-index:250}
    body.m-fs-open .icon-rail{visibility:hidden}
    .m-chatcard.m-fs{position:fixed;inset:0;z-index:300;margin:0;padding:var(--safe-t) 0 0;border:none;border-radius:0;background:var(--bg);display:flex;flex-direction:column;height:var(--app-h,100dvh)}
    .m-chatcard.m-fs>h3,.m-chatcard.m-fs>.bots-muted,.m-chatcard.m-fs>.bots-row,.m-chatcard.m-fs>.bots-actions{display:none}
    .m-chatcard.m-fs .m-fs-head{display:flex;align-items:center;gap:8px;flex:none;padding:8px 8px 8px 16px;background:var(--surface);border-bottom:1px solid var(--border);min-height:56px}
    .m-fs-head b{flex:1;font-size:17px;font-weight:600;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
    .m-fs-new{border:1px solid var(--border);background:var(--surface-2);color:var(--text-dim);border-radius:12px;min-height:40px;padding:0 14px;font:500 14px var(--font-ui)}
    .m-fs-x{display:flex;align-items:center;justify-content:center;width:44px;height:44px;border:none;border-radius:50%;background:var(--surface-2);color:var(--text)}
    .m-fs-x .icon{width:22px;height:22px;stroke-width:2.2}
    .m-chatcard.m-fs .bots-chat{flex:1;min-height:0;max-height:none;border:none;border-radius:0;background:var(--bg)}
    .m-chatcard.m-fs .bots-chat-log{padding:12px 12px 8px}
    .m-chatcard.m-fs .bots-chat-input{display:flex;gap:8px;padding:8px 10px calc(8px + var(--safe-b));background:var(--surface);border-top:1px solid var(--border)}
    .m-chatcard.m-fs .bots-chat-input input{flex:1;min-width:0;min-height:44px;border-radius:22px;padding:0 16px}
    .m-chatcard.m-fs .bots-chat-input .bots-btn{min-height:44px;border-radius:22px;padding:0 18px}

    /* ---------- таблицы-карточки ---------- */
    table.m-cards,table.m-cards tbody{display:block;overflow:visible;max-width:100%}
    table.m-cards thead{display:none}
    table.m-cards tr{display:block;padding:12px 14px;margin:0 0 10px;background:var(--surface);border:1px solid var(--border);border-radius:14px}
    table.m-cards td{display:block;padding:4px 0!important;border:none!important;font-size:14.5px;min-width:0;overflow-wrap:anywhere}
    table.m-cards td::before{content:attr(data-label);display:block;font-size:11.5px;font-weight:600;letter-spacing:.02em;text-transform:uppercase;color:var(--text-faint);margin-bottom:1px}
    table.m-cards td[data-label=""]::before{display:none}
    table.m-cards td:empty{display:none}
    table.m-cards td{width:auto!important;white-space:normal!important}
    table.m-cards .bots-rowact,table.m-cards .bots-act>div{display:flex;gap:8px;margin-top:6px}
    table.m-cards .bots-rowact .bots-btn{flex:1;min-height:42px}
    table.m-cards tr:active{background:var(--surface-2)}

    /* ---------- Интеграции: плитки → компактные строки ---------- */
    .in-grid{grid-template-columns:1fr;gap:8px}
    .in-bubble{display:grid;grid-template-columns:48px minmax(0,1fr);column-gap:14px;row-gap:2px;align-items:center;padding:12px 14px;border-radius:16px}
    .in-bubble>*{grid-column:2}
    .in-bubble>.in-logo{grid-column:1;grid-row:1/span 4;width:48px;height:48px}
    .in-bubble:active{background:var(--surface-2)}
    .in-bubble-title{font-size:16px}
    .in-group{margin:18px 0 8px}
    .in-conn{padding:12px}
    .in-conn-act{display:grid;grid-template-columns:1fr 1fr;gap:8px;width:100%}
    .in-card{padding:14px;border-radius:14px}

    /* ---------- Настройки: аккордеон карточек ---------- */
    .settings-card.m-acc>h3:first-child{display:flex;align-items:center;justify-content:space-between;gap:8px;min-height:44px;margin:-6px 0;cursor:pointer;font-size:15px}
    .settings-card.m-acc>h3:first-child::after{content:'';flex:none;width:10px;height:10px;border-right:2px solid var(--text-faint);border-bottom:2px solid var(--text-faint);transform:rotate(45deg);transition:transform .18s;margin-right:4px}
    .settings-card.m-acc.open>h3:first-child::after{transform:rotate(-135deg)}
    .settings-card.m-acc:not(.open)>*:not(h3:first-child){display:none}
    .settings-card.m-acc.open>h3:first-child{margin-bottom:8px}

    /* ---------- Тариф: тарифы — горизонтальная карусель ---------- */
    .bl-plans{display:flex!important;overflow-x:auto;scroll-snap-type:x mandatory;gap:12px;margin:0 -12px 14px;padding:4px 12px 10px;-webkit-overflow-scrolling:touch}
    .bl-plan{flex:0 0 82%;scroll-snap-align:center}
    .bl-channels{grid-template-columns:1fr}
}

/* ============================================================
   Телефонные паттерны: «+» в композере, шторка выбора компании, Обучение, Контакты
   ============================================================ */
@media (max-width:860px){
    /* композер: вместо трёх кружков — один «+», действия — в листе */
    #composerAttachBtn,#composerLibraryBtn,#composerNoteBtn,#tplSaveBtn,#tplMgrBtn{display:none!important}
    .m-plus{display:flex;align-items:center;justify-content:center;flex:none;width:42px;height:42px;border:none;border-radius:50%;background:var(--surface-2);color:var(--text-dim)}
    .m-plus .icon{width:22px;height:22px;stroke-width:2.2}
    .m-plus:active{background:var(--surface-3)}
    .m-sheet-back{display:flex;align-items:flex-end;position:fixed;inset:0;z-index:420;background:rgba(10,12,16,.45);animation:m-fade .15s}
    .m-sheet{width:100%;background:var(--surface);border-radius:20px 20px 0 0;padding:6px 8px calc(10px + var(--safe-b));animation:m-sheet .2s var(--ease)}
    .m-sheet-grip{width:38px;height:4px;border-radius:4px;background:var(--border-strong);margin:4px auto 8px}
    .m-sheet-item{display:flex;align-items:center;gap:14px;width:100%;min-height:54px;padding:0 14px;border:none;border-radius:12px;background:none;color:var(--text);font:500 16px var(--font-ui);text-align:left}
    .m-sheet-item:active{background:var(--surface-2)}
    .m-sheet-item .icon{width:22px;height:22px;color:var(--text-dim)}

    /* звонок из шапки чата */
    .m-call{display:flex;align-items:center;justify-content:center;flex:none;width:42px;height:42px;border-radius:12px;background:var(--accent-soft);color:var(--accent-text)}
    .m-call[hidden]{display:none}
    .m-call .icon{width:21px;height:21px}

    /* выбор компании / вкладки: выпадашка → нижняя шторка */
    .cs-panel{position:fixed!important;left:0!important;right:0!important;top:auto!important;bottom:0;max-height:72dvh;border-radius:20px 20px 0 0;border:none;z-index:360;box-shadow:0 0 0 100vmax rgba(10,12,16,.45);padding-bottom:var(--safe-b);animation:m-sheet .2s var(--ease)}
    .cs-panel[hidden]{display:none!important}
    .cs-opt{min-height:50px;padding:0 16px;font-size:16px}
    .cs-search{padding:10px 12px}
    /* выпадающие списки uikit (.ui-pop, из <body>) на телефоне — та же нижняя шторка; !important перебивает инлайн-позицию из uikit.js place() */
    .ui-pop.cs-panel{position:fixed!important;left:0!important;right:0!important;top:auto!important;bottom:0!important;width:auto!important;min-width:0!important;max-width:none!important;max-height:72dvh!important;
        border:none;border-radius:20px 20px 0 0;box-shadow:0 0 0 100vmax rgba(10,12,16,.45);padding:6px 6px calc(6px + var(--safe-b));animation:m-sheet .2s var(--ease)}
    .ui-pop.up{animation-name:m-sheet}
    .ui-pop .cs-search{margin:-6px -6px 4px;padding:12px 12px 8px;border-radius:20px 20px 0 0}

    /* Обучение: список или статья — по одному экрану */
    .ln-layout{display:flex!important;flex-direction:column;height:100%}
    .ln-layout .ln-nav{max-height:none;flex:1;border-right:none;overflow-y:auto}
    .ln-layout .ln-main{flex:1;min-height:0}
    body:not(.m-ln-detail) .ln-layout .ln-main{display:none}
    body.m-ln-detail .ln-layout .ln-nav{display:none}
    .m-ln-bar{display:none}
    body.m-ln-detail .m-ln-bar{display:flex;flex:none;padding:6px 8px;background:var(--surface);border-bottom:1px solid var(--border)}
    .m-ln-bar button{display:flex;align-items:center;gap:4px;min-height:42px;padding:0 12px 0 6px;border:none;background:none;color:var(--accent-text);font:600 16px var(--font-ui)}
    .m-ln-bar .icon{width:22px;height:22px;stroke-width:2.2}

    /* Контакты: фильтры за кнопкой */
    .m-filter-toggle{display:flex;align-items:center;gap:10px;width:calc(100% - 24px);margin:8px 12px;min-height:44px;padding:0 14px;border:1px solid var(--border);border-radius:12px;background:var(--surface);color:var(--text);font:500 15px var(--font-ui)}
    .m-filter-toggle .icon{width:20px;height:20px;color:var(--text-dim)}
    .m-filter-toggle span{flex:1;text-align:left}
    .m-filter-toggle i{font-style:normal;min-width:22px;height:22px;padding:0 6px;border-radius:11px;background:var(--accent);color:#fff;font-size:12.5px;font-weight:700;line-height:22px;text-align:center}
    .m-filter-toggle i[hidden]{display:none}
    .m-filter-toggle.on{border-color:var(--accent)}
    #contactsBar.m-collapsed{display:none}
}

/* кнопка, открывающаяся свайпом по строке чата */
@media (max-width:860px){
    .chat-item{position:relative}
    .m-swipe-act{position:absolute;left:100%;top:0;bottom:0;width:104px;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:4px;border:none;background:var(--accent);color:#fff;font:600 13px var(--font-ui);padding:0}
    .m-swipe-act.to-bot{background:#2f6fe4}
    .m-swipe-act .icon{width:24px;height:24px;stroke-width:1.9}
    .m-sheet-quote{margin:2px 14px 8px;padding:8px 12px;border-left:3px solid var(--accent);background:var(--surface-2);border-radius:8px;color:var(--text-dim);font-size:14px;line-height:1.35;max-height:5.4em;overflow:hidden;white-space:pre-wrap}
}

@media (max-width:860px){
    .m-sheet,.m-sheet *{-webkit-user-select:none;user-select:none;-webkit-touch-callout:none}
    .m-sheet-back.m-arming{pointer-events:none}
}
