/*
  Раскладка. Один и тот же разметочный каркас на всех экранах, меняется только CSS:
  на компьютере — боковая панель и колонки, на телефоне — нижнее меню и переходы
  «стопкой», как в iOS.
*/

.shell {
  height: 100%;
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  background: var(--bg-grouped);
}

/* ---------- Боковая панель (компьютер) ---------- */

.sidebar {
  display: flex;
  flex-direction: column;
  background: var(--bg-grouped);
  border-right: 1px solid var(--separator);
  min-width: 0;
}

.sidebar-head {
  padding: 20px 16px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-logo {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--blue);
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 4px 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 12px;
  border-radius: var(--r-md);
  color: var(--label);
  font-size: 15px;
  font-weight: 500;
  transition: background var(--dur-fast) var(--ease);
  width: 100%;
  text-align: left;
}

.nav-item:hover {
  background: var(--bg-hover);
}

.nav-item.is-active {
  background: var(--blue);
  color: var(--label-on-accent);
}

.nav-item.is-active .nav-icon {
  color: var(--label-on-accent);
}

.nav-icon {
  width: 22px;
  height: 22px;
  flex: 0 0 22px;
  color: var(--blue);
}

.nav-badge {
  margin-left: auto;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: var(--r-full);
  background: var(--red);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
}

.nav-item.is-active .nav-badge {
  background: #fff;
  color: var(--blue);
}

.sidebar-foot {
  border-top: 1px solid var(--separator);
  padding: 10px;
}

.me-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--r-md);
  width: 100%;
  text-align: left;
  transition: background var(--dur-fast) var(--ease);
}

.me-card:hover {
  background: var(--bg-hover);
}

.me-name {
  font-size: 14px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.me-role {
  font-size: 12px;
  color: var(--label-secondary);
}

/* ---------- Рабочая область ---------- */

.workspace {
  min-width: 0;
  min-height: 0;
  background: var(--bg);
  display: grid;
  grid-template-columns: var(--list-w) 1fr;
}

/* Разделы без второй колонки (Настройки, заглушки) занимают всю ширину */
.workspace.is-single {
  grid-template-columns: 1fr;
}

.pane {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.pane-list {
  border-right: 1px solid var(--separator);
  background: var(--bg);
}

.pane-detail {
  background: var(--bg-grouped);
}

/* Шапка панели: полупрозрачная с размытием, как в iOS */
.pane-head {
  flex: 0 0 auto;
  min-height: var(--header-h);
  padding: 8px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--separator);
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  position: sticky;
  top: 0;
  z-index: 5;
}

.pane-head-title {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pane-head-sub {
  font-size: 12px;
  color: var(--label-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pane-head-grow {
  flex: 1;
  min-width: 0;
}

.pane-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* Кнопка «назад» нужна только на телефоне */
.back-btn {
  display: none;
  align-items: center;
  gap: 2px;
  color: var(--blue);
  font-size: 17px;
  margin-left: -6px;
}

/* Нижнее меню — только на телефоне */
.tabbar {
  display: none;
}

/* ---------- Телефон ---------- */

@media (max-width: 899px) {
  .shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    display: none;
  }

  .workspace,
  .workspace.is-single {
    grid-template-columns: 1fr;
    /* Место под нижнее меню */
    padding-bottom: var(--tabbar-h);
  }

  /* Список и переписка занимают весь экран; какая из панелей видна,
     решает класс на .workspace — это и есть push-навигация. */
  .pane {
    grid-column: 1;
    grid-row: 1;
  }

  .pane-list {
    border-right: none;
  }

  .workspace.show-detail .pane-list {
    display: none;
  }

  .workspace:not(.show-detail) .pane-detail {
    display: none;
  }

  .back-btn {
    display: flex;
  }

  /* Экран переписки въезжает справа, как в iOS */
  .workspace.show-detail .pane-detail {
    animation: push-in var(--dur) var(--ease);
  }

  @keyframes push-in {
    from { transform: translateX(28px); opacity: 0.4; }
    to { transform: translateX(0); opacity: 1; }
  }

  .tabbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: var(--tabbar-h);
    padding-bottom: env(safe-area-inset-bottom);
    display: flex;
    align-items: stretch;
    background: rgba(249, 249, 249, 0.94);
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    border-top: 1px solid var(--separator);
    z-index: 20;
  }

  .tab {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    color: var(--gray);
    font-size: 10px;
    font-weight: 500;
    position: relative;
    transition: color var(--dur-fast) var(--ease);
  }

  .tab.is-active {
    color: var(--blue);
  }

  .tab-icon {
    width: 25px;
    height: 25px;
  }

  .tab-badge {
    position: absolute;
    top: 3px;
    left: 50%;
    margin-left: 4px;
    min-width: 17px;
    height: 17px;
    padding: 0 5px;
    border-radius: var(--r-full);
    background: var(--red);
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
  }
}

/* Промежуточная ширина: боковую панель сжимаем до иконок */
@media (min-width: 900px) and (max-width: 1100px) {
  .shell {
    grid-template-columns: 68px 1fr;
  }

  .sidebar-logo,
  .nav-item span,
  .me-text {
    display: none;
  }

  .nav-item {
    justify-content: center;
    padding: 11px 0;
  }

  .sidebar-head {
    justify-content: center;
    padding: 16px 0 10px;
  }

  .me-card {
    justify-content: center;
  }
}
