:root { --vh: 1vh; }

/* iOS PWA safe area — handled per-element inside @media blocks below */

/* ── MOBILE ── */
@media (max-width: 768px) {
  html, body {
    height: 100%;
    overflow: hidden;
    position: fixed;
    width: 100%;
  }

  header {
    height: calc(52px + env(safe-area-inset-top, 0px)) !important;
    padding-top: env(safe-area-inset-top, 0px) !important;
    align-items: flex-end !important;
    padding-bottom: 4px !important;
  }

  .layout {
    display: block;
    height: calc(var(--vh, 1vh) * 100 - 52px - env(safe-area-inset-top, 0px));
  }

  .sidebar {
    position: fixed;
    top: calc(52px + env(safe-area-inset-top, 0px));
    left: 0;
    right: 0;
    bottom: 0;
    height: auto;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    border-right: none;
  }
  .sidebar .sidebar-top { flex-shrink: 0; }
  .sidebar .filter-bar { flex-shrink: 0; }

  .chat-list {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 8px);
  }

  .content { display: none; width: 100%; height: 100%; }
  .layout.show-content .sidebar { display: none; }
  .layout.show-content .content { display: flex; }

  .back-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: #37352f;
    font-size: 20px;
    cursor: pointer;
    flex-shrink: 0;
    font-family: inherit;
  }
  .back-btn:hover { background: #f1f1ef; }

  .chat-title-main { font-size: 13px; }
  .composer-status { display: none; }
  #accountSelect { max-width: 110px; font-size: 12px; }
  .header-title { font-size: 14px; }

  .item-card {
    padding: 4px 14px !important;
  }
  .item-card-img,
  .item-card-avatar {
    width: 40px !important;
    height: 40px !important;
  }
  .item-card-title {
    font-size: 12px !important;
  }
  .item-card-price {
    font-size: 13px !important;
  }
}

/* Шапка скрыта в диалоге на мобильном */
@media (max-width: 768px) {
  body.in-chat header { display: none !important; }
  body.in-chat .content-top {
    min-height: calc(44px + env(safe-area-inset-top, 0px)) !important;
    padding-top: env(safe-area-inset-top, 0px) !important;
    align-items: flex-end !important;
    padding-bottom: 4px !important;
    height: auto !important;
  }
  body.in-chat .layout { height: calc(var(--vh, 1vh) * 100 - env(safe-area-inset-top, 0px)) !important; }
  body.keyboard-visible #itemCard { display: none !important; }
  body.keyboard-visible #chatPanel { display: none !important; }
  body.keyboard-visible .layout { height: calc(100dvh - env(safe-area-inset-top, 0px)) !important; }
  body.keyboard-visible #messages { padding-bottom: 60px !important; }
  body.in-chat .composer {
    position: fixed !important;
    bottom: 0px !important;
    left: 0 !important;
    right: 0 !important;
    z-index: 100;
    padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 8px) !important;
  }
  body.in-chat .composer-status {
    display: none !important;
    height: 0 !important;
    min-height: 0 !important;
  }
  body.in-chat #messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding-bottom: 60px;
  }
}
