/* CMYK.OS — оболочка приложения: фиксированный sidebar + основная область */

:root {
  /* = .navbar-fintech: padding 8+safe + min-height 2.6rem + padding 8 */
  --cmykos-topbar-h: calc(2.6rem + 16px + env(safe-area-inset-top, 0px));
}

.cmykos-shell {
  display: flex;
  min-height: calc(100vh - var(--cmykos-topbar-h));
  margin-top: 0;
}

.cmykos-sidebar {
  position: fixed;
  top: var(--cmykos-topbar-h);
  left: 0;
  bottom: 0;
  width: 250px;
  z-index: 1020;
  background: var(--ds-surface, #ffffff);
  border-right: 1px solid var(--ds-separator, #e4e7eb);
  box-shadow: 1px 0 8px rgba(8, 35, 48, 0.04);
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding: 12px 0 24px;
  transition: transform 0.22s ease, background-color var(--ds-dur, 0.2s) ease,
              border-color var(--ds-dur, 0.2s) ease;
}

.cmykos-sidebar__inner {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 10px;
}

.cmykos-sidebar__group {
  margin-top: 8px;
}
.cmykos-sidebar__group:first-child {
  margin-top: 2px;
}

.cmykos-sidebar__accordion {
  border-top: 1px solid var(--ds-separator, #eef1f5);
  padding-top: 4px;
}
.cmykos-sidebar__accordion:first-child {
  border-top: none;
  padding-top: 0;
}

.cmykos-sidebar__label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ds-label-secondary, #94a3b8);
  padding: 8px 10px;
  margin: 0;
  list-style: none;
  cursor: pointer;
  user-select: none;
  border-radius: var(--ds-radius-sm, 8px);
  transition: background-color var(--ds-dur-fast, 0.12s) ease, color var(--ds-dur-fast, 0.12s) ease;
}
.cmykos-sidebar__label::-webkit-details-marker { display: none; }
.cmykos-sidebar__label::marker { content: ''; }
.cmykos-sidebar__label::after {
  content: '';
  flex: 0 0 auto;
  width: 0.45rem;
  height: 0.45rem;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(-45deg);
  opacity: 0.55;
  transition: transform var(--ds-dur, 0.2s) ease;
}
.cmykos-sidebar__accordion[open] > .cmykos-sidebar__label {
  color: var(--ds-label, #475569);
}
.cmykos-sidebar__accordion[open] > .cmykos-sidebar__label::after {
  transform: rotate(45deg);
  opacity: 0.75;
}
.cmykos-sidebar__label:hover {
  background: var(--ds-fill, #f0f2f5);
  color: var(--ds-label, #101828);
}

.cmykos-sidebar__panel {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 0 6px;
}

.cmykos-sidebar__sublabel {
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ds-label-tertiary, #94a3b8);
  padding: 6px 10px 4px 2.45rem;
  user-select: none;
}

.cmykos-sidebar__link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  color: var(--ds-label-secondary, #475569);
  font-weight: 600;
  font-size: 0.9rem;
  text-decoration: none;
  line-height: 1.25;
  transition: background-color 0.15s ease, color 0.15s ease;
}
.cmykos-sidebar__link:hover,
.cmykos-sidebar__link:focus-visible {
  background: var(--ds-fill, #f0f2f5);
  color: var(--ds-label, #101828);
  text-decoration: none;
}
.cmykos-sidebar__link.is-active {
  background: color-mix(in srgb, var(--ds-brand, #635bff) 12%, transparent);
  color: var(--ds-brand-strong, #4338ca);
}
.cmykos-sidebar__link .ico {
  flex-shrink: 0;
  width: 1.35rem;
  text-align: center;
  font-size: 1.05rem;
  line-height: 1;
}
.cmykos-sidebar__link .bi {
  flex-shrink: 0;
  font-size: 1.05rem;
  opacity: 0.85;
}

.cmykos-sidebar__sublink {
  padding-left: 2.45rem;
  font-size: 0.84rem;
  font-weight: 500;
}

.cmykos-sidebar__nested-group {
  margin: 6px 0 2px;
  padding: 6px 6px 4px;
  border-radius: var(--ds-radius-md, 10px);
  background: var(--ds-surface-2, #fafafa);
  border: 1px solid var(--ds-separator, rgba(0, 0, 0, 0.08));
}
.cmykos-sidebar__sublabel--nested {
  padding: 4px 8px 6px;
  margin: 0;
}
.cmykos-sidebar__nested {
  margin: 0;
  border-radius: var(--ds-radius-sm, 8px);
}
.cmykos-sidebar__nested + .cmykos-sidebar__nested {
  margin-top: 2px;
  border-top: 1px solid var(--ds-hairline, rgba(0, 0, 0, 0.06));
  padding-top: 2px;
}
.cmykos-sidebar__nested-head {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1 1 auto;
}
.cmykos-sidebar__nested-head .ico,
.cmykos-sidebar__nested-head .bi {
  flex-shrink: 0;
  width: 1.25rem;
  text-align: center;
  font-size: 1rem;
  line-height: 1;
  opacity: 0.88;
}
.cmykos-sidebar__nested-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  margin: 0;
  list-style: none;
  cursor: pointer;
  user-select: none;
  border-radius: var(--ds-radius-sm, 8px);
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--ds-label-secondary, #64748b);
  transition: background-color var(--ds-dur-fast, 0.12s) ease, color var(--ds-dur-fast, 0.12s) ease;
}
.cmykos-sidebar__nested-label::-webkit-details-marker { display: none; }
.cmykos-sidebar__nested-label::marker { content: ''; }
.cmykos-sidebar__nested-label::after {
  content: '';
  flex: 0 0 auto;
  width: 0.45rem;
  height: 0.45rem;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(-45deg);
  opacity: 0.55;
  transition: transform var(--ds-dur, 0.2s) ease;
}
.cmykos-sidebar__nested[open] > .cmykos-sidebar__nested-label {
  color: var(--ds-label, #475569);
  background: var(--ds-surface, #fff);
}
.cmykos-sidebar__nested[open] > .cmykos-sidebar__nested-label::after {
  transform: rotate(45deg);
  opacity: 0.75;
}
.cmykos-sidebar__nested-label:hover {
  background: var(--ds-fill, #f0f2f5);
  color: var(--ds-label, #101828);
}
.cmykos-sidebar__nested-panel {
  display: flex;
  flex-direction: column;
  gap: 1px;
  margin: 2px 0 4px 1.05rem;
  padding: 2px 0 4px 0.55rem;
  border-left: 2px solid var(--ds-separator-strong, rgba(0, 0, 0, 0.1));
}
.cmykos-sidebar__nested-panel .cmykos-sidebar__sublink {
  padding-left: 0.55rem;
  font-size: 0.82rem;
  font-weight: 500;
}
.cmykos-sidebar__nested-panel .cmykos-sidebar__sublink.is-active {
  background: var(--ds-info-bg, #eef2ff);
  color: var(--ds-brand-strong, #4338ca);
  box-shadow: inset 2px 0 0 var(--ds-brand, #635bff);
}

.cmykos-main {
  flex: 1 1 auto;
  min-width: 0;
  margin-left: 250px;
  padding-top: 8px;
  padding-bottom: 32px;
  transition: margin-left 0.22s ease;
}

/* Кнопка «свернуть меню» внутри сайдбара (десктоп) */
.cmykos-nav-collapse-btn {
  display: none;
  align-items: center;
  gap: 6px;
  margin: 0 10px 8px auto;
  padding: 5px 10px;
  border: 1px solid var(--ds-separator, #e4e7eb);
  border-radius: 8px;
  background: var(--ds-surface, #fff);
  color: var(--ds-label-secondary, #64748b);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}
.cmykos-nav-collapse-btn:hover {
  background: var(--ds-fill, #f0f2f5);
  color: var(--ds-label, #101828);
}

/* Плавающая кнопка «показать меню», когда оно свёрнуто (десктоп) */
.cmykos-nav-rail {
  display: none;
  position: fixed;
  top: calc(var(--cmykos-topbar-h) + 10px);
  left: 10px;
  z-index: 1021;
  width: 2.4rem;
  height: 2.4rem;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--ds-separator, #e4e7eb);
  border-radius: 10px;
  background: var(--ds-surface, #fff);
  color: var(--ds-label-secondary, #475569);
  box-shadow: var(--ds-shadow-2, 0 4px 14px rgba(8, 35, 48, 0.12));
  cursor: pointer;
}
.cmykos-nav-rail:hover {
  background: #f0f2f5;
}

/* Сворачивание главного меню на десктопе (кнопка-бургер в шапке) */
@media (min-width: 992px) {
  .cmykos-sidebar-toggle {
    display: inline-flex;
  }
  .cmykos-nav-collapse-btn {
    display: inline-flex;
  }
  body.cmyk-nav-collapsed .cmykos-sidebar {
    transform: translateX(-100%);
  }
  body.cmyk-nav-collapsed .cmykos-main {
    margin-left: 0;
  }
  body.cmyk-nav-collapsed .cmykos-nav-rail {
    display: inline-flex;
  }
  body.page-cabinet.cmyk-nav-collapsed .cmykos-nav-rail,
  body.page-chats--partner.cmyk-nav-collapsed .cmykos-nav-rail,
  body.page-calc-client--partner.cmyk-nav-collapsed .cmykos-nav-rail,
  body.page-embedded.cmyk-nav-collapsed .cmykos-nav-rail {
    display: none !important;
  }
}

/* Затемнение под мобильным меню */
.cmykos-sidebar-backdrop {
  display: none;
  position: fixed;
  inset: var(--cmykos-topbar-h) 0 0 0;
  z-index: 1015;
  background: rgba(15, 23, 42, 0.35);
  backdrop-filter: blur(2px);
}
.cmykos-sidebar-backdrop.is-visible {
  display: block;
}

/* Кнопка бургера в шапке */
.cmykos-sidebar-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  border: 1px solid var(--ds-separator, #e4e7eb);
  border-radius: 8px;
  background: var(--ds-surface, #fff);
  color: var(--ds-label-secondary, #475569);
  padding: 0;
}
.cmykos-sidebar-toggle:hover {
  background: var(--ds-fill, #f0f2f5);
  color: var(--ds-label, #101828);
}

@media (max-width: 991.98px) {
  .cmykos-sidebar-toggle {
    display: inline-flex;
  }
  .cmykos-sidebar {
    transform: translateX(-100%);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.12);
  }
  .cmykos-sidebar.is-open {
    transform: translateX(0);
  }
  .cmykos-main {
    margin-left: 0;
  }
}

/* Страницы без оболочки (кабинет, партнёрский чат, embedded) */
body.page-cabinet .cmykos-sidebar,
body.page-cabinet .cmykos-sidebar-backdrop,
body.page-cabinet .cmykos-sidebar-toggle,
body.page-cabinet .cmykos-nav-rail,
body.page-cabinet .cmykos-nav-collapse-btn,
body.page-chats--partner .cmykos-sidebar,
body.page-chats--partner .cmykos-sidebar-backdrop,
body.page-chats--partner .cmykos-sidebar-toggle,
body.page-chats--partner .cmykos-nav-rail,
body.page-calc-client--partner .cmykos-sidebar,
body.page-calc-client--partner .cmykos-sidebar-backdrop,
body.page-calc-client--partner .cmykos-sidebar-toggle,
body.page-calc-client--partner .cmykos-nav-rail,
body.page-calc-client--partner .cmykos-nav-collapse-btn,
body.page-embedded .cmykos-sidebar,
body.page-embedded .cmykos-sidebar-backdrop,
body.page-embedded .cmykos-sidebar-toggle,
body.page-directories .cmykos-sidebar,
body.page-directories .cmykos-sidebar-backdrop,
body.page-directories .cmykos-sidebar-toggle {
  display: none !important;
}
body.page-cabinet .cmykos-main,
body.page-chats--partner .cmykos-main,
body.page-calc-client--partner .cmykos-main,
body.page-embedded .cmykos-main,
body.page-directories .cmykos-main {
  margin-left: 0 !important;
}
body.page-cabinet .cmykos-shell,
body.page-chats--partner .cmykos-shell,
body.page-calc-client--partner .cmykos-shell,
body.page-embedded .cmykos-shell,
body.page-directories .cmykos-shell {
  min-height: auto;
}
body.page-directories .cmykos-main > .container-fluid {
  padding-left: 0 !important;
  padding-right: 0 !important;
  max-width: 100%;
}

/* Постоянная оболочка: шапка + меню снаружи, страница во фрейме */
html:has(body.page-app-shell),
body.page-app-shell {
  height: 100%;
  overflow: hidden;
}
body.page-app-shell .cmykos-shell {
  height: calc(100vh - var(--cmykos-topbar-h));
  min-height: 0;
}
body.page-app-shell .cmykos-main {
  padding: 0;
  overflow: hidden;
  height: 100%;
  display: flex;
  flex-direction: column;
}
body.page-app-shell .cmykos-main > .container-fluid {
  flex: 1 1 auto;
  min-height: 0;
  height: 100%;
  padding: 0 !important;
  max-width: none;
  display: flex;
  flex-direction: column;
}
.cmykos-app-frame {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
  background: var(--ds-bg, #f7f9fc);
}

html.cmykos-shell-frame,
html.cmykos-shell-frame body {
  height: 100%;
  padding-top: 0 !important;
}
html.cmykos-shell-frame body.page-chats .chat-layout .chat-pane-full,
html.cmykos-shell-frame body.page-chats .chat-layout .chat-sidebar-full {
  height: calc(100vh - 16px);
  height: calc(100dvh - 16px);
}
