/* iOS / mobile PWA — layout. Без negative-bottom костылей (они давали плашку поверх compose). */

html {
  background: #eef4ff;
}

@media (max-width: 1100px) {
  html {
    height: 100%;
    height: -webkit-fill-available;
    overflow: hidden;
    overscroll-behavior: none;
    background: #eef4ff;
  }

  body {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 100%;
    height: -webkit-fill-available;
    min-height: 100%;
    min-height: -webkit-fill-available;
    margin: 0;
    overflow: hidden;
    overscroll-behavior: none;
    background: #eef4ff;
  }

  .app-shell {
    position: fixed !important;
    top: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    overflow: hidden;
    padding-top: env(safe-area-inset-top, 0px);
    padding-bottom: 0 !important;
    padding-left: env(safe-area-inset-left, 0px);
    padding-right: env(safe-area-inset-right, 0px);
    margin: 0 !important;
    box-sizing: border-box;
    background:
      radial-gradient(circle at top left, rgba(72, 128, 255, 0.18), transparent 24%),
      linear-gradient(180deg, #f8fbff 0%, #eef4ff 100%);
  }

  .content-shell {
    min-height: 0;
    height: 100%;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
    padding: 8px 10px 0 !important;
    margin-bottom: 0 !important;
  }

  body.mobile-chats-active .content-shell {
    overflow: hidden;
    padding: 0 !important;
    margin: 0 !important;
    display: flex;
    flex-direction: column;
  }

  body.mobile-chats-active .content-shell > header.topbar {
    flex-shrink: 0;
    margin: 8px 8px 0;
    border-radius: 18px;
  }

  body.mobile-chats-active .content-shell > main {
    flex: 1;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    padding: 8px 8px 0 !important;
    margin: 0 !important;
    box-sizing: border-box;
  }

  body.mobile-chats-active:has(#icLayout.show-chat) .content-shell > main {
    padding: 0 !important;
  }

  body.mobile-chats-active:has(#icLayout.show-chat) .content-shell > header.topbar {
    display: none !important;
  }

  body.mobile-chats-active #pageChats.active {
    flex: 1;
    min-height: 0;
    display: flex !important;
    flex-direction: column;
    margin: 0 !important;
    padding-bottom: 0 !important;
  }

  body.mobile-chats-active #pageChats .ic-page {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    margin: 0;
    border-radius: 16px;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
    padding-bottom: 0 !important;
  }

  body.mobile-chats-active #icLayout {
    flex: 1;
    min-height: 0;
  }

  body.mobile-chats-active #icLayout .internal-chat-sidebar {
    flex: 1;
    min-height: 0;
    height: 100%;
  }

  /* Общение с клиентами — mobile/PWA */
  body.mobile-cc-active .content-shell {
    overflow: hidden;
    padding: 0 !important;
    margin: 0 !important;
    display: flex;
    flex-direction: column;
  }

  body.mobile-cc-active .content-shell > header.topbar {
    flex-shrink: 0;
    margin: 8px 8px 0;
    border-radius: 18px;
  }

  body.mobile-cc-active:has(.cc-layout.show-chat) .content-shell > header.topbar {
    display: none !important;
  }

  body.mobile-cc-active #pageObshchenie.active {
    flex: 1;
    min-height: 0;
    display: flex !important;
    flex-direction: column;
    margin: 0 !important;
    padding: 8px 8px 0 !important;
    overflow: hidden;
  }

  body.mobile-cc-active:has(.cc-layout.show-chat) #pageObshchenie.active {
    padding: 0 !important;
  }

  body.mobile-cc-active #pageObshchenie .cc-page {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    margin: 0;
    border-radius: 16px;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
    padding: 0 !important;
    overflow: hidden;
  }

  .app-shell:not(.sidebar-open) .sidebar-backdrop {
    visibility: hidden !important;
    opacity: 0 !important;
    pointer-events: none !important;
  }

  .sidebar {
    height: auto !important;
    max-height: none !important;
    top: 0 !important;
    bottom: 0 !important;
    overflow: hidden !important;
    overscroll-behavior: none;
    touch-action: pan-y;
    padding-top: calc(16px + env(safe-area-inset-top));
    padding-bottom: 8px !important;
  }

  .sidebar .sidebar-top,
  .sidebar .sidebar-user,
  .sidebar .sidebar-logout,
  .sidebar .sidebar-group-label {
    flex-shrink: 0;
    touch-action: none;
  }

  .sidebar nav.top-menu {
    flex: 1 1 auto;
    min-height: 0;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
    overscroll-behavior-x: none;
    touch-action: pan-y;
  }

  .sidebar a,
  .sidebar img,
  .sidebar button {
    -webkit-user-drag: none;
    -webkit-touch-callout: none;
    user-select: none;
    -webkit-user-select: none;
  }

  header.topbar {
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    justify-content: flex-start !important;
    flex-wrap: nowrap !important;
    gap: 10px !important;
    padding: 8px 10px !important;
    min-height: 56px;
    max-width: 100%;
    min-width: 0;
  }

  .menu-toggle {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    padding: 0 !important;
    margin: 0;
    border-radius: 14px;
    border: 1px solid var(--border);
    background: #fff;
    color: var(--text-secondary);
    font-size: 20px;
    line-height: 1;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 8px 18px rgba(15, 23, 42, 0.06);
    flex-shrink: 0;
    align-self: center;
  }

  .topbar-main {
    min-width: 0;
    flex: 1 1 auto;
    display: flex !important;
    flex-direction: column !important;
    flex-wrap: nowrap !important;
    align-items: stretch !important;
    justify-content: center !important;
    gap: 0 !important;
  }

  .header-left {
    flex: 0 1 auto !important;
    min-width: 0;
    max-width: 100%;
    display: flex !important;
    flex-direction: column;
    justify-content: center;
    gap: 0 !important;
  }

  .topbar-breadcrumb,
  #pageSubtitle,
  .topbar-actions {
    display: none !important;
  }

  body.ic-chats-page header.topbar .ic-topbar-notify {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    min-height: 44px;
    height: 44px;
    padding: 0 12px !important;
    margin: 0;
    border-radius: 14px;
    flex-shrink: 0;
    align-self: center;
  }

  /* Раньше кнопка пропадала внутри чата — из‑за этого на Android «не включались» уведомления */
  body.ic-chats-page:has(#icLayout.show-chat) header.topbar .ic-topbar-notify {
    display: inline-flex !important;
  }

  header.topbar h1,
  #pageTitle {
    font-size: 18px !important;
    line-height: 1.25 !important;
    margin: 0 !important;
    max-width: 100%;
    overflow: visible;
    text-overflow: unset;
    white-space: normal;
    word-break: break-word;
  }

  .sidebar-user {
    display: flex !important;
  }

  .sidebar-logout {
    display: flex !important;
  }

  .sidebar .brand-block,
  .sidebar .sidebar-footer {
    display: none !important;
  }

  .input,
  select.input,
  textarea.input,
  input.input,
  input[type="text"],
  input[type="search"],
  input[type="email"],
  input[type="password"],
  input[type="number"],
  input[type="date"],
  input[type="tel"],
  select,
  textarea,
  .bk-search-input,
  .bk-filter-select,
  .bk-contact-form .input,
  .bk-contact-form select,
  .da-search-input,
  .da-filter-select,
  .da-password-row .input,
  .tel-result-select,
  .lead-status-select,
  .bonus-kpi-table td.input-cell input,
  #icSearchInput,
  #icDirectSearch,
  #icGroupTitle,
  #mailInboxSearch,
  #mailQuickFilter,
  #mailSendTo,
  #mailSendCc,
  #mailSendBcc,
  #mailSendSubject,
  #mailSendAccountId,
  #mailSendFolderId,
  #mailSendBodyHtml.input,
  #pageMessengers .tg-compose-input-wrap textarea {
    font-size: 16px !important;
  }

  .responsive-form {
    grid-template-columns: 1fr !important;
  }

  #employeesSearchInput,
  #employeesSortSelect,
  #attendanceDate,
  #telephonyDate,
  #bonusKpiAddManagerSelect {
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
  }

  #pageTelefonia .tel-multiselect {
    min-width: 0 !important;
    width: 100%;
    max-width: 100%;
  }

  #pageTelefonia .tel-multiselect-toggle {
    width: 100%;
  }

  .card,
  .modal-content,
  .da-modal,
  .bk-drawer,
  .da-drawer {
    max-width: 100%;
    box-sizing: border-box;
  }

  .modal-overlay,
  .da-modal-overlay,
  .bk-drawer-overlay {
    padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  }

  .modal-content,
  .da-modal {
    max-height: min(85vh, calc(var(--ios-vh, 100dvh) - 48px));
    overflow: auto;
    -webkit-overflow-scrolling: touch;
  }

  .table-wrap,
  .infographic-table-wrap,
  #absencesResults > div {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .da-kpi-grid {
    grid-template-columns: 1fr !important;
  }

  #equipmentModal .form-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
  }

  #equipmentModal .form-actions .btn {
    width: 100%;
  }

  .mail-layout.mail-show-detail .mail-pane-detail {
    min-height: calc(var(--ios-vh, 100dvh) - 180px);
    max-height: none;
  }
}

@media (max-width: 640px) {
  .da-drawer-footer {
    flex-wrap: wrap;
  }

  .da-drawer-footer .btn {
    flex: 1 1 100%;
  }

  #pageUchettekhniki .infographic-toolbar-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
  }

  #pageUchettekhniki .infographic-toolbar-group .btn {
    width: 100%;
  }
}

@media (max-width: 480px) {
  #infoReport6Block .bonus-kpi-rt-header,
  #infoReport6Block .bonus-kpi-rt-row {
    grid-template-columns: 24px minmax(0, 1fr) 72px !important;
  }

  .bk-btn-primary {
    white-space: normal;
    width: 100%;
  }

  header.topbar h1,
  #pageTitle {
    font-size: 17px !important;
  }
}

/* ——— PWA shell 360/390: drawer, header, safe-area, no page overflow-x ——— */
.sidebar-close-mobile {
  display: none;
}

@media (max-width: 1100px) {
  .sidebar-backdrop {
    z-index: 1000;
    touch-action: none;
    -webkit-tap-highlight-color: transparent;
  }

  .app-shell.sidebar-open .sidebar-backdrop {
    visibility: visible;
    opacity: 1;
    pointer-events: auto;
  }

  .app-shell.sidebar-open .content-shell {
    overflow: hidden !important;
  }

  .sidebar {
    width: min(320px, calc(100vw - 48px)) !important;
    max-width: calc(100vw - 40px) !important;
    box-sizing: border-box !important;
    padding-left: max(12px, env(safe-area-inset-left, 0px)) !important;
    padding-right: 12px !important;
    padding-top: calc(12px + env(safe-area-inset-top, 0px)) !important;
    padding-bottom: max(12px, env(safe-area-inset-bottom, 0px), var(--ios-safe-bottom, 0px)) !important;
    overflow: hidden !important;
  }

  .sidebar-close-mobile {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    margin: 4px 0 0;
    padding: 0;
    border-radius: 12px;
    border: 1px solid rgba(148, 163, 184, 0.28);
    background: rgba(255, 255, 255, 0.08);
    color: #e2e8f0;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
  }

  .sidebar .nav-label {
    white-space: normal !important;
    overflow: visible !important;
    width: auto !important;
    transform: none !important;
    opacity: 1 !important;
    line-height: 1.3;
    word-break: break-word;
  }

  nav.top-menu {
    gap: 4px !important;
    padding-bottom: 8px;
  }

  nav.top-menu a {
    min-height: 44px !important;
    padding: 10px 12px !important;
    font-size: 15px !important;
    transform: none !important;
  }

  nav.top-menu a:hover {
    transform: none !important;
  }

  .top-submenu {
    margin-left: 8px !important;
    margin-right: 0 !important;
  }

  .top-submenu.open {
    max-height: none !important;
    overflow: visible !important;
  }

  .top-submenu a {
    min-height: 44px !important;
    padding: 10px 12px !important;
    font-size: 14px !important;
    line-height: 1.35 !important;
    white-space: normal;
    align-items: center;
  }

  .top-submenu a.nav-mail-account {
    min-height: 44px !important;
  }

  .top-submenu a.nav-mail-account .nav-mail-label,
  .top-submenu a.nav-mail-account .nav-mail-email {
    font-size: 13px !important;
  }

  .sidebar-logout {
    min-height: 44px !important;
  }

  .content-shell {
    max-width: 100%;
    overscroll-behavior-x: none;
    padding-bottom: max(8px, env(safe-area-inset-bottom, 0px)) !important;
  }

  html.pwa-standalone .content-shell,
  html.standalone-app .content-shell {
    padding-bottom: max(12px, env(safe-area-inset-bottom, 0px), var(--ios-safe-bottom, 0px)) !important;
  }

  body.mobile-chats-active .content-shell,
  body.mobile-cc-active .content-shell {
    padding-bottom: 0 !important;
  }
}

@media (max-width: 360px) {
  .sidebar {
    width: min(300px, calc(100vw - 40px)) !important;
  }
}
