/*
 * Layer: телефонный слой панели (iPhone, PWA). Подключается после ui-v3.css
 * и меняет только узкие экраны. Базовые мобильные правила ui-v3 (≤860px)
 * остаются, здесь — то, чего им не хватало для работы оператора с телефона.
 */

html { -webkit-text-size-adjust:100%; text-size-adjust:100%; }
.more-nav { display:none; }

@media (max-width:860px) {
  /* Высота с учётом клавиатуры iOS: --app-h ставит скрипт по visualViewport. */
  .app,.app[data-context="on"],.app[data-context="off"] {
    height:var(--app-h,100dvh);
    grid-template-rows:minmax(0,1fr) calc(56px + env(safe-area-inset-bottom));
  }
  body { overscroll-behavior:none; -webkit-tap-highlight-color:transparent; }
  .main { padding-top:env(safe-area-inset-top); }

  /* iOS увеличивает страницу при фокусе на поле со шрифтом меньше 16px. */
  input,select,textarea,.ctl { font-size:16px!important; }

  /* Нижняя панель: светлая в светлой теме, пять равных кнопок без прокрутки. */
  .sidebar {
    padding:0 4px env(safe-area-inset-bottom);
    overflow:hidden;
    color:var(--text-secondary);
    background:color-mix(in srgb,var(--canvas) 92%,transparent);
    -webkit-backdrop-filter:blur(20px) saturate(160%);
    backdrop-filter:blur(20px) saturate(160%);
  }
  .primary-nav { display:contents; }
  .sidebar > .grow,.sidebar > .board { display:none!important; }
  .nav[data-view="lab"],.nav[data-view="nodes"],.nav[data-view="stats"] { display:none; }
  .nav,.more-nav {
    flex:1 1 0; width:auto; min-width:0; height:52px;
    display:flex; flex-direction:column; align-items:center; justify-content:center; gap:3px;
    color:var(--text-tertiary); font-size:10.5px; font-weight:500; border-radius:10px; background:none;
  }
  .more-nav .glyph { width:20px; height:20px; display:grid; place-items:center; }
  .more-nav .glyph svg { width:20px; height:20px; }
  .nav .glyph,.nav .glyph svg { width:20px; height:20px; }
  .nav:hover,.nav:active { background:none; color:var(--text-secondary); }
  .nav[aria-current="true"],.more-nav[aria-current="true"] { color:var(--accent); background:none; }
  .nav { position:relative; }
  .nav .count:not(:empty):not([data-zero]) {
    display:block; position:absolute; top:4px; left:calc(50% + 6px);
    min-width:17px; height:17px; padding:0 5px; border-radius:9px;
    color:#fff; background:var(--danger); font-size:10.5px; line-height:17px; text-align:center;
  }
  .nav .count:empty,.nav .count[data-zero] { display:none; }
  .search-nav { display:flex!important; order:4; margin:0; }
  .search-nav .count { display:none!important; }
  .more-nav { display:flex; order:5; }

  /* В открытом диалоге нижняя панель не нужна — больше места переписке. */
  .app:has(#view-inbox:not([hidden]) .inbox-workspace[data-pane="thread"]) { grid-template-rows:minmax(0,1fr) 0; }
  .app:has(#view-inbox:not([hidden]) .inbox-workspace[data-pane="thread"]) .sidebar { display:none; }

  /* Список обращений: строки под палец. */
  #list > * { min-height:64px; }
  .folder-tabs button,.folder-manage { min-height:36px; }

  /* Шапка диалога: имя сверху, действия второй строкой с прокруткой. */
  .conversation-head { min-height:0; padding:6px 10px 0; flex-wrap:wrap; gap:8px 10px; }
  .conversation-head .workspace-label { display:none; }
  .mobile-back { width:40px; height:40px; border:0; background:none; color:var(--accent); }
  .mobile-back svg { width:26px; height:26px; }
  .inbox-workspace { grid-template-columns:minmax(0,1fr); }
  .inbox-list-pane,.conversation-pane { min-width:0; grid-template-columns:minmax(0,1fr); }
  .title-stack { flex:1 1 0; width:auto; min-width:0; }
  #subtitle { display:block; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
  .queue-search kbd { display:none; }
  .title-avatar { width:36px; min-width:36px; max-width:36px; height:36px; min-height:36px; max-height:36px; flex-basis:36px; }
  .conversation-actions {
    order:9; flex:1 0 100%; width:100%; margin:0 -10px; padding:6px 10px 8px;
    display:flex; align-items:center; justify-content:flex-start; gap:8px; overflow-x:auto; scrollbar-width:none;
    border-top:1px solid var(--separator);
  }
  .conversation-actions::-webkit-scrollbar { display:none; }
  .conversation-actions .compact-field,
  .conversation-actions .compact-field.ai-field,
  .conversation-actions .toolbar-btn,
  #escBtn { display:flex!important; flex:0 0 auto; }
  .conversation-actions .compact-field > span { display:none; }
  .conversation-actions .ctl { height:34px; max-width:150px; }
  .conversation-actions .btn,.conversation-actions .icon-btn { min-height:34px; flex:0 0 auto; }
  .inspector-toggle { margin-left:auto; }
  /* Главное действие оператора — первым, без прокрутки. */
  #handoffBtn { order:-2; }
  .conversation-actions .compact-field:not(.ai-field) { order:-1; }

  .thread { padding:14px 10px; -webkit-overflow-scrolling:touch; }
  .msg { max-width:86%; }

  /* Поле ответа: над домашней полосой, кнопка отправки — 44px. */
  .composer { padding:6px 8px calc(8px + env(safe-area-inset-bottom)); }
  .tools { overflow-x:auto; scrollbar-width:none; gap:4px; flex-wrap:nowrap; }
  .tools::-webkit-scrollbar { display:none; }
  #captureBtn { display:none; }
  .tools .btn,.tools select { flex:0 0 auto; min-height:34px; }
  .tools select { width:auto; max-width:140px; }
  .tools .wleft { margin-left:auto; flex:0 0 auto; font-size:11px; }
  #input { max-height:32vh; }
  .send { width:40px; height:40px; }

  /* Детали обращения и листы — на весь экран, с безопасными зонами. */
  .context {
    top:0; right:0; bottom:0; left:0; width:100%;
    padding-top:env(safe-area-inset-top); padding-bottom:env(safe-area-inset-bottom);
    border:0; border-radius:0;
    background:var(--canvas)!important; -webkit-backdrop-filter:none!important; backdrop-filter:none!important;
  }
  .backdrop { padding:0; place-items:end stretch; }
  .sheet {
    width:100%; max-height:calc(var(--app-h,100dvh) - env(safe-area-inset-top) - 24px);
    border-radius:16px 16px 0 0; border-inline:0; border-bottom:0;
    padding-bottom:env(safe-area-inset-bottom);
  }
  .sheet.wide { max-height:var(--app-h,100dvh); padding-top:env(safe-area-inset-top); border-radius:0; }

  .toast,#toast { bottom:calc(72px + env(safe-area-inset-bottom)); }

  /* Вход: поле крупнее, карточка без рамки. */
  .gate-card { border:0; box-shadow:none; background:transparent; }
  .gate { padding-top:env(safe-area-inset-top); }
}

/* Лист «Ещё» в нижней панели. */
.more-list { display:grid; gap:2px; }
.more-list button {
  min-height:50px; padding:0 6px; display:flex; align-items:center; gap:14px;
  color:var(--text); font-size:16px; text-align:left; border-radius:10px;
}
.more-list button:active { background:var(--canvas-muted); }
.more-list .glyph { width:22px; height:22px; color:var(--accent); display:grid; place-items:center; }
.more-list .glyph svg { width:22px; height:22px; }
.more-list .danger { color:var(--danger); }
.more-list .danger .glyph { color:var(--danger); }
.more-list hr { margin:6px 0; border:0; border-top:1px solid var(--separator); }

/* Настройка пушей (Настройки → Уведомления). */
.push-modes { display:grid; gap:8px; }
.push-modes label {
  padding:10px 12px; display:flex; align-items:flex-start; gap:10px; cursor:pointer;
  border:1px solid var(--separator); border-radius:8px; background:var(--canvas);
}
.push-modes label:has(input:checked) { border-color:var(--accent); box-shadow:0 0 0 2px var(--focus); }
.push-modes input { margin-top:2px; accent-color:var(--accent); }
.push-modes span { display:grid; gap:2px; }
.push-modes b { font-size:13.5px; font-weight:550; }
.push-modes small { color:var(--text-tertiary); font-size:12px; }
.push-actions { margin-top:12px; display:flex; flex-wrap:wrap; gap:8px; }
.push-panel .hint { margin-top:10px; max-width:60ch; }
@media (max-width:860px) {
  .push-modes label { min-height:56px; }
  .push-modes b { font-size:15px; }
  .push-actions .btn { min-height:40px; }
}
