/* =========================================================
   Sidebar component styles.
   Source: design/components/sidebar/sidebar.css
   ========================================================= */

.sidebar {
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  width: 292px;
  min-height: 690px;
  padding: 20px;
  border: 1px solid var(--color-border-soft);
  border-radius: var(--radius-6xl);
  background: var(--color-overlay);
  box-shadow: var(--shadow-glass);
  backdrop-filter: var(--blur-glass);
  -webkit-backdrop-filter: var(--blur-glass);
  font-family: var(--font-heading);
  color: var(--color-slate-900);
}

.sidebar * { box-sizing: inherit; }

.sidebar__header,
.sidebar__content {
  width: 100%;
}

.sidebar__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.sidebar__brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.sidebar__brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(3, 151, 250, 0.18);
}
.sidebar__brand-mark svg { display: block; width: 40px; height: 40px; }

.sidebar__brand-copy {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.sidebar__title {
  margin: 0;
  color: var(--color-slate-900);
  font-size: 16px;
  line-height: 20px;
  font-weight: 800;
}

.sidebar__subtitle {
  color: var(--color-primary);
  font-family: Inter, sans-serif;
  font-weight: 400;
  font-size: 9px;
  line-height: 13.5px;
  letter-spacing: 0.9px;
  text-transform: uppercase;
}

.sidebar__content {
  display: flex;
  flex-direction: column;
  gap: 24px;
  flex: 1 1 auto;
}

.sidebar__panel,
.sidebar__chats { width: 100%; }

.sidebar__panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 16px;
  border: 1px solid var(--color-border-strong);
  border-radius: 32px;
  background: var(--color-surface-soft);
}

.sidebar__section-heading {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.sidebar__section-heading--chat { margin-bottom: 16px; }

.sidebar__section-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 20px;
  height: 20px;
}
.sidebar__section-icon svg { display: block; width: 20px; height: 20px; }

.sidebar__section-title {
  margin: 0;
  min-width: 0;
  color: var(--color-slate-900);
  font-size: 16px;
  line-height: 20px;
  font-weight: 800;
}

.sidebar__panel-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sidebar__panel-item {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 20px;
  color: var(--color-slate-600);
  font-family: var(--font-heading);
  font-size: 12px;
  line-height: 16px;
  font-weight: 600;
  white-space: nowrap;
  text-decoration: none;
  cursor: pointer;
}
.sidebar__panel-item--active,
.sidebar__panel-item.active {
  color: var(--color-slate-900);
  font-weight: 800;
}

.panel-item__icon {
  flex: none;
  width: 20px;
  height: 20px;
  color: currentColor;
}

.sidebar__section-heading .sidebar__section-icon { color: var(--color-slate-800); }
.sidebar__panel-item--active .panel-item__icon { color: var(--color-slate-600); }

.sidebar__chats {
  display: flex;
  flex-direction: column;
  padding: 0 8px;
}

.sidebar__chats-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.sidebar__chat-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  cursor: pointer;
  text-decoration: none;
}

.sidebar__chats-empty {
  list-style: none;
  margin: 0;
  padding: 8px 4px;
  color: var(--color-slate-600);
  font-size: 12px;
  line-height: 18px;
  font-style: italic;
}

.chat-item__title {
  color: var(--color-slate-600);
  font-family: var(--font-heading);
  font-size: 12px;
  line-height: 16px;
  font-weight: 600;
}
.sidebar__chat-item--active .chat-item__title,
.sidebar__chat-item.active .chat-item__title {
  color: var(--color-slate-900);
  font-weight: 800;
}

.chat-item__preview {
  max-width: 220px;
  overflow: hidden;
  color: var(--color-slate-400);
  font-family: var(--font-body);
  font-size: 12px;
  line-height: 16px;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.sidebar__footer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: 100%;
  margin-top: auto;
  padding-top: 14px;
}

.sidebar__new-chat {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 100%;
  max-width: 238px;
  min-height: 46px;
  padding: 12px 18px;
  border: none;
  border-radius: 24px;
  background: var(--color-primary);
  color: #ffffff;
  font-family: var(--font-heading);
  font-size: 16px;
  line-height: 20px;
  font-weight: 700;
  cursor: pointer;
  transition:
    background-color var(--transition-fast),
    transform var(--transition-fast),
    box-shadow var(--transition-fast);
}
.sidebar__new-chat:hover { background: var(--color-primary-hover); }
.sidebar__new-chat:focus-visible {
  outline: 2px solid var(--color-primary-soft);
  outline-offset: 2px;
}

/* Secondary variant — used for "Войти" when unauthenticated. */
.sidebar__new-chat--secondary,
.sidebar__new-chat--secondary:link,
.sidebar__new-chat--secondary:visited {
  background: transparent;
  color: var(--color-primary);
  border: 1px solid var(--color-primary);
  text-decoration: none;
}
.sidebar__new-chat--secondary:hover {
  background: var(--color-primary-soft, rgba(14, 165, 233, 0.12));
  color: var(--color-primary);
}

/* Logout variant — sits below "Новый чат". */
.sidebar__new-chat--logout,
.sidebar__new-chat--logout:link,
.sidebar__new-chat--logout:visited {
  background: transparent;
  color: var(--color-slate-600);
  border: 1px solid var(--color-slate-400);
}
.sidebar__new-chat--logout:hover {
  background: rgba(15, 23, 42, 0.04);
  color: var(--color-danger);
  border-color: var(--color-danger);
}
.sidebar__new-chat-icon {
  display: inline-flex;
  flex: none;
  width: 18px;
  height: 18px;
}
.sidebar__new-chat-icon svg { display: block; width: 18px; height: 18px; }
.sidebar__new-chat-label { display: inline-flex; align-items: center; }

/* =========================================================
   Mobile off-canvas sidebar
   The MainLayout includes a hidden checkbox (#sidebar-toggle),
   a burger label, and a backdrop label. On desktop they are
   hidden; on viewports <= 768px the sidebar becomes a drawer.
   ========================================================= */

/* Hidden checkbox — only used as a CSS state holder. */
.sidebar-toggle {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  clip: rect(0 0 0 0);
  overflow: hidden;
  white-space: nowrap;
}

/* Burger button — visible only on small screens. */
.sidebar-burger {
  display: none;
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 90;
  box-sizing: border-box;
  width: 44px;
  height: 44px;
  align-items: center;
  justify-content: center;
  padding: 10px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.85);
  border: 1px solid var(--color-border-soft);
  box-shadow: 0 6px 18px rgba(15, 23, 42, 0.1);
  backdrop-filter: var(--blur-glass);
  -webkit-backdrop-filter: var(--blur-glass);
  cursor: pointer;
  color: var(--color-slate-800);
  transition: background-color var(--transition-fast), transform var(--transition-fast);
}

.sidebar-burger:hover { background: var(--color-surface); }
.sidebar-burger:active { transform: scale(0.96); }

.sidebar-burger__icon {
  position: relative;
  display: inline-flex;
  flex-direction: column;
  justify-content: space-between;
  width: 22px;
  height: 16px;
}

.sidebar-burger__icon span {
  display: block;
  width: 100%;
  height: 2px;
  border-radius: 2px;
  background: currentColor;
  transition: transform var(--transition-fast), opacity var(--transition-fast);
}

/* Burger morphs into × when the menu is open. */
.sidebar-toggle:checked ~ .sidebar-burger .sidebar-burger__icon span:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}
.sidebar-toggle:checked ~ .sidebar-burger .sidebar-burger__icon span:nth-child(2) {
  opacity: 0;
}
.sidebar-toggle:checked ~ .sidebar-burger .sidebar-burger__icon span:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

/* Backdrop — dim overlay behind the drawer. */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 85;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-fast);
  cursor: pointer;
}

/* ─── Small-screen drawer behaviour ─── */
@media (max-width: 768px) {
  .sidebar-burger {
    display: inline-flex;
  }

  .sidebar-backdrop {
    display: block;
  }

  /* Sidebar becomes a fixed drawer offscreen by default. */
  .app-shell > .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 95;
    width: min(86vw, 320px);
    max-width: 86vw;
    /* Reset the desktop min-height so the drawer can shrink to the viewport
       without forcing internal vertical scrolling on short phones. */
    min-height: 0;
    height: 100vh;
    margin: 0;
    border-radius: 0 24px 24px 0;
    transform: translateX(-105%);
    transition: transform 260ms cubic-bezier(0.2, 0.8, 0.2, 1);
    overflow-y: auto;
    padding: 70px 16px 20px;
    box-shadow: 0 24px 60px rgba(15, 23, 42, 0.25);
  }

  /* Slide-in when toggle is checked. */
  .sidebar-toggle:checked ~ .sidebar {
    transform: translateX(0);
  }

  /* Show backdrop only when drawer is open. */
  .sidebar-toggle:checked ~ .sidebar-backdrop {
    opacity: 1;
    pointer-events: auto;
  }

  /* Prevent body scroll when drawer is open. */
  .sidebar-toggle:checked ~ .app-root {
    overflow: hidden;
  }

  /* Tighten internal sidebar typography for narrow drawers. */
  .sidebar__panel-item,
  .chat-item__title {
    font-size: 13px;
  }

  .sidebar__new-chat {
    font-size: 15px;
  }

  .chat-item__preview {
    max-width: 100%;
  }
}

@media (max-width: 480px) {
  .app-shell > .sidebar {
    width: 88vw;
    border-radius: 0 20px 20px 0;
    padding: 64px 14px 16px;
  }

  .sidebar-burger {
    width: 40px;
    height: 40px;
    top: 12px;
    left: 12px;
    padding: 9px;
  }
}
