/* Sidebar */
:root {
  --sidebar-inline-space: calc(var(--inline-space) * 1.25);
  --sidebar-tools-height: calc(var(--block-space) + var(--btn-size) + (var(--block-space) * 2));
}

.sidebar__container {
  block-size: 100dvh;
  max-block-size: 100dvh;
  display: flex;
  flex-direction: column;
  gap: var(--block-space-half);
  padding-block: var(--block-space) var(--sidebar-tools-height);
  padding-inline: var(--sidebar-inline-space);
}

/* Brand wordmark */
.sidebar__brand {
  --column-gap: 0.4em;

  min-block-size: var(--btn-size);
  padding-inline-start: 0.2em;
}

.sidebar__brand-mark {
  font-size: 1.3rem;
  line-height: 1;
}

.sidebar__brand-name {
  font-family: var(--font-display);
  font-size: 1.7rem;
  font-weight: 400;
  letter-spacing: 0.03em;
  line-height: 1;
}

/* Search / Saved / Mentions nav rows: plain rows like the channel rows — no
   boxed input look (no fill, no border), just icon + label with a hover tint. */
.sidebar__search {
  --btn-border-radius: 8px;
  --btn-background: transparent;
  --btn-border-color: transparent;
  --btn-color: var(--color-border-darker);

  justify-content: start;
  font-weight: 400;
  inline-size: 100%;
  padding: 0.18em 0.5em;

  @media (any-hover: hover) {
    &:where(:not(:active):hover) {
      --btn-background: var(--color-message-bg);
    }
  }
}

/* Inline (type-ahead) search: the Search row is now a real input. The form is
   the positioning context for the absolutely-positioned results panel. */
.sidebar__search-form {
  position: relative;
  display: block;
}

/* The row keeps the de-boxed nav look (transparent, hover tint via .sidebar__search
   above); the input itself is borderless and transparent so it reads as a row,
   not a boxed field. */
.inline-search__row {
  cursor: text;
}

.inline-search__icon {
  flex: 0 0 auto;
}

.inline-search__input {
  flex: 1 1 auto;
  min-inline-size: 0;
  appearance: none;
  border: none;
  background: transparent;
  color: var(--color-text);
  font: inherit;
  font-weight: 400;
  padding: 0;
  margin: 0;
  outline: none;
}

.inline-search__input::placeholder {
  color: var(--color-border-darker);
  opacity: 1;
}

/* Hide the native search clear/decoration for a clean row. */
.inline-search__input::-webkit-search-decoration,
.inline-search__input::-webkit-search-cancel-button {
  appearance: none;
}

/* Dropdown panel anchored under the input, floating above other sidebar content. */
.inline-search__panel {
  position: absolute;
  inset-block-start: calc(100% + 4px);
  inset-inline: 0;
  z-index: 30;
  max-block-size: 60vh;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--color-bg);
  border: 1px solid var(--color-border-dark);
  border-radius: 10px;
  box-shadow: 0 8px 24px oklch(var(--lch-always-black) / 0.18);
}

.inline-search__results-list {
  list-style: none;
  margin: 0;
  padding: 4px;
}

.inline-search__result {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 6px 8px;
  border-radius: 7px;
  color: var(--color-text);
  text-decoration: none;
}

@media (any-hover: hover) {
  .inline-search__result:where(:hover) {
    background: var(--color-message-bg);
  }
}

.inline-search__result--active {
  background: var(--color-selected);
  box-shadow: inset 0 0 0 1px var(--color-selected-dark);
}

.inline-search__result-top {
  display: flex;
  align-items: baseline;
  gap: 0.5em;
  min-inline-size: 0;
}

.inline-search__result-room {
  font-weight: 600;
  font-size: 0.78rem;
  color: var(--color-accent);
  flex: 0 1 auto;
}

/* Room (channel/DM) hit rows: a single-line row, slightly tighter than a
   message hit (which also has author + snippet lines). */
.inline-search__result--room {
  gap: 0;
}

/* The "#" channel glyph rendered before a channel name. */
.inline-search__result-glyph {
  margin-inline-end: 0.15em;
  color: var(--color-border-darker);
}

.inline-search__result-author {
  font-size: 0.7rem;
  color: var(--color-border-darker);
  flex: 1 1 auto;
}

.inline-search__result-snippet {
  font-size: 0.78rem;
  color: var(--color-text);
  display: block;
}

.inline-search__loading,
.inline-search__empty {
  padding: 10px 12px;
  font-size: 0.78rem;
  color: var(--color-border-darker);
}

/* Section labels */
.sidebar__section-label {
  color: var(--color-border-darker);
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  margin-block-end: 0.1em;
  padding-inline-start: 0.4em;
  text-transform: uppercase;
}

/* Mark-all-read: subtle, muted text button sitting between the search field and
   the first rooms section. Not a loud button; a quiet utility action. The
   button_to wraps it in a form; the form is full-width and left-aligned. */
.sidebar__mark-all-read {
  inline-size: 100%;
  margin-block-end: calc(var(--block-space) * -0.5);
}

.sidebar__mark-all-read-btn {
  --btn-background: transparent;
  --btn-border-color: transparent;
  --btn-color: var(--color-border-darker);

  color: var(--color-border-darker);
  font-weight: 500;
  inline-size: 100%;
  justify-content: start;
  padding-inline: 0.4em;

  @media (any-hover: hover) {
    &:where(:not(:active):hover) {
      --btn-background: var(--color-message-bg);
      --btn-color: var(--color-text);

      color: var(--color-text);
    }
  }
}

/* Drafts section: rows reuse the room--row chrome for visual consistency. Each
   row stacks the room name over a muted one-line snippet of the unsent text. */
.draft-row {
  flex-wrap: wrap;
  line-height: 1.2;

  .room__name {
    flex-basis: 100%;
    font-weight: 600;
  }
}

.draft-row__snippet {
  color: var(--color-border-darker);
  flex-basis: 100%;
  font-size: 0.78rem;
  font-weight: 400;
  min-inline-size: 0;
}

.sidebar__tools {
  background-color: var(--color-sidebar-bg);
  border-block-start: 1px solid var(--color-border-dark);
  inset: auto 0 0 0;
  padding-block: var(--block-space);
  padding-inline: var(--sidebar-inline-space);
  position: fixed;

  @media (min-width: 100ch) {
    inline-size: var(--sidebar-width);
    inset-inline-start: 0;
    inset-inline-end: auto;
  }

  @media (max-width: 100ch) {
    inline-size: min(82vw, 320px);
  }
}

.sidebar__toggle {
  margin-inline-start: auto;
  z-index: 6;

  @media (min-width: 100ch) {
    display: none;
  }

  /* On small screens the sidebar slides off-canvas, so keep the toggle pinned
     to the top-left of the viewport where it is always tappable. It remains a
     DOM child of #sidebar, so toggle-class#toggle still resolves. */
  @media (max-width: 100ch) {
    background-color: var(--color-sidebar-bg);
    inset: var(--block-space-half) auto auto var(--sidebar-inline-space);
    position: fixed;
    transition: inset-inline-start 300ms ease;

    .open & {
      inset-inline-start: calc(min(82vw, 320px) - var(--btn-size) - var(--sidebar-inline-space));
    }
  }
}

/* Unread indicator on the closed mobile toggle */
#sidebar:where(:not(.open):has(.unread)) .sidebar__toggle::after {
  --size: 0.85em;

  aspect-ratio: 1;
  background-color: var(--color-negative);
  block-size: var(--size);
  border: 2px solid var(--color-bg);
  border-radius: 50%;
  content: "";
  inline-size: var(--size);
  inset: -3px -3px auto auto;
  position: absolute;

  @media (min-width: 100ch) {
    display: none;
  }
}

/* Resize handle: thin hit area pinned to the sidebar's right edge. Desktop only
   (hidden where the sidebar goes off-canvas). Driven by sidebar_resize_controller. */
.sidebar__resize-handle {
  position: absolute;
  inset-block: 0;
  inset-inline-end: -2px;
  inline-size: 6px;
  cursor: col-resize;
  z-index: 5;
  touch-action: none;

  /* Subtle visible line that brightens on hover/drag. */
  &::after {
    content: "";
    position: absolute;
    inset-block: 0;
    inset-inline-end: 2px;
    inline-size: 1px;
    background-color: transparent;
    transition: background-color 120ms ease;
  }

  @media (any-hover: hover) {
    &:hover::after,
    &:active::after {
      background-color: var(--color-accent);
    }
  }

  @media (max-width: 100ch) {
    display: none;
  }
}

/* Direct messages */
.directs {
  --row-gap: 2px;
  --column-gap: 0;

  margin-block-end: var(--block-space-half);
}

.directs--edit  {
  display: grid;
  gap: var(--inline-space);
  grid-template-columns: repeat(auto-fit, minmax(33%, 1fr));
  grid-template-rows: min-content;
  place-items: center;

  .member {
    aspect-ratio: 1;
    block-size: auto;
    inline-size: 100%;
    margin-inline: auto;
    place-content: center;
  }
}

.direct {
  border-radius: 8px;
  box-shadow: none;
  color: var(--color-text);
  position: relative;
  text-decoration: none;
}

/* Row layout: avatar + name (used in the left sidebar list) */
.direct--row {
  --column-gap: 0.6em;

  display: flex;
  inline-size: 100%;
  justify-content: flex-start;
  text-align: start;
  padding: 0.18em 0.5em;

  @media (any-hover: hover) {
    &:where(:not(:active):hover) {
      background-color: var(--color-message-bg);

      .avatar:not(.avatar--icon) {
        filter: none;
      }
    }
  }

  &:focus-within,
  &:where(:not(:active)):focus-visible {
    outline: 0;
  }
}

.direct__avatar {
  --avatar-size: 2.2ch;

  display: inline-flex;
  position: relative;

  .avatar {
    --avatar-size: 2.2ch;
  }

  .avatar__group {
    --avatar-size: 1.4ch;

    block-size: 2.4ch;
    inline-size: 2.4ch;
  }
}

.direct__new {
  .avatar--icon {
    --avatar-size: 2.2ch;
  }
}

.direct__author {
  --column-gap: 0.3ch;

  /* Read DM rows recede (lighter, normal weight); unread rows pop to full
     strength + heavy weight, matching the room rows above. */
  color: var(--color-border-darker);
  flex-grow: 1;
  font-weight: 400;
  min-inline-size: 0;

  /* Unread DM rows bold the name; the numeric count pill (shared with room
     rows, styled at the bottom of this file) carries the unread indication. */
  .unread & {
    color: var(--color-text);
    font-weight: 700;
  }
}

/* Rooms */
.rooms {
  --column-gap: 0.5em;
  --row-gap: 1px;
}

.rooms__new-btn {
  --btn-background: transparent;
  --btn-border-color: transparent;
  --btn-color: var(--color-border-darker);

  font-weight: 500;
  justify-content: start;
  margin-block-start: 0.2em;

  @media (any-hover: hover) {
    &:where(:not(:active):hover) {
      --btn-background: var(--color-message-bg);
    }
  }
}

.room {
  --btn-border-radius: 8px;
  --btn-border-color: transparent;
  --btn-background: transparent;

  color: var(--color-text);
  font-weight: normal;
  justify-content: flex-start;
  text-align: start;
  inline-size: 100%;
  max-inline-size: 100%;

  @media (any-hover: hover) {
    &:where(:not(:active):hover) {
      --btn-background: var(--color-message-bg);
    }
  }

  .searches-list & {
    border-radius: 8px;
  }
}

/* Room rows in the sidebar list: left-justified hash + name, badge pushed right */
.room--row {
  --column-gap: 0.5em;

  display: flex;
  justify-content: flex-start;
  text-align: start;
  padding: 0.18em 0.5em;
  font-size: 0.92rem;

  /* Read (default) rows recede: lighter color + normal weight so unread rows
     stand out at a glance, Slack-style. */
  --btn-color: var(--color-border-darker);
  color: var(--color-border-darker);
  font-weight: 400;

  .room__hash {
    color: var(--color-border-darker);
    flex-shrink: 0;
    font-weight: 600;
  }

  .room__name {
    flex-grow: 1;
    min-inline-size: 0;
    text-align: start;
  }

  /* Unread rows pop: full-strength text + heavy weight. */
  &.unread {
    --btn-color: var(--color-text);

    color: var(--color-text);
    font-weight: 700;

    .room__name {
      color: var(--color-text);
    }

    .room__hash {
      color: var(--color-accent);
    }
  }
}

/* Numeric unread-count pill. Shared by room rows and DM rows. Hidden unless the
   row carries .unread, so a read row never shows a stale pill. Right-aligned via
   margin-inline-start:auto; the star sits just after it (see .room__star rule).
   Replaces the former red dot on rooms and the accent dot on the DM author. */
.room__unread-badge {
  display: none;
}

.room--row.unread .room__unread-badge,
.direct--row.unread .room__unread-badge {
  align-items: center;
  background-color: var(--color-negative);
  border-radius: 1em;
  color: var(--color-text-reversed);
  display: inline-flex;
  flex-shrink: 0;
  font-size: 0.7rem;
  font-weight: 700;
  justify-content: center;
  line-height: 1;
  margin-inline-start: auto;
  min-inline-size: 1.5em;
  padding: 0.2em 0.5em;
}

/* Active room: filled cyan pill with dark text (used in sidebar list) */
.room--row[aria-current],
.room--row.room--active {
  --btn-background: var(--color-accent);
  --btn-color: #080808;
  --hover-filter: none;

  color: #080808;
  font-weight: 600;

  .room__name {
    color: #080808;
  }

  .room__hash {
    color: rgba(8, 8, 8, 0.55);
  }

  @media (any-hover: hover) {
    &:where(:not(:active):hover) {
      --btn-background: var(--color-accent);
    }
  }
}

/* Active DM: same filled cyan pill as active rooms. Direct rows aren't `.btn`,
   so set the background directly rather than via --btn-background. Keeps the
   open conversation clearly highlighted and legible against the muted read rows. */
.direct--row[aria-current],
.direct--row.room--active {
  background-color: var(--color-accent);
  border-radius: 8px;

  .direct__author {
    color: #080808;
  }
}

/* Current room title in the top bar */
.room--current {
  --btn-border-radius: 8px;
  --btn-background: transparent;
  --btn-color: var(--color-text);
  --btn-border-color: transparent;
  --hover-filter: none;
  --num-buttons: 1;

  min-block-size: var(--btn-size);

  .room__contents {
    font-family: var(--font-display);
    font-weight: 400;
    font-size: 1.5rem;
    letter-spacing: 0.02em;

    .room--current:not(.room--current-direct) &::before {
      color: var(--color-border-darker);
      content: "#";
      margin-inline-end: 0.15em;
    }

    .account-has-logo & {
      --num-buttons: 2;
    }

    max-inline-size: calc(100dvw - var(--sidebar-width) - (var(--btn-size) * 2) - var(--inline-space) * 6);

    @media (max-width: 100ch) {
      --num-buttons: 2;

      max-inline-size: calc(100dvw - (var(--btn-size) * 3) - var(--inline-space) * 4);
    }
  }
}

/* Searches */
.searches {
  #nav {
    align-items: start;
    column-gap: 0;
    padding-inline-end: 0;
  }

  .rooms {
    padding-block-start: var(--block-space);
  }

  .message--formatted .message__room {
    display: block;
    font-size: 0.8rem;
    font-weight: 400;
    overflow: hidden;
    text-overflow: ellipsis;
    visibility: visible;
    white-space: nowrap;

    &::before {
      content: "→";
    }

    .message--me & {
      &::after {
        content: "←";
      }

      &::before {
        content: "";
      }
    }
  }

  .message__actions {
    display: none !important;
    visibility: hidden !important;
  }
}

.searches__recents {
  --mask: linear-gradient(to left, oklch(0% 0 0 / 1) 97%, oklch(0% 0 0 / 0) 99%);

  -webkit-mask-image: var(--mask);
  display: none;
  mask-image: var(--mask);
  position: relative;

  @media (max-width: 100ch) {
    display: flex;
  }

  .room {
    max-inline-size: 20ch;

    &:first-child {
      margin-inline-start: var(--inline-space);
    }
  }

  .searches__btn {
    margin-inline-end: var(--inline-space-double);
  }
}

.searches__query {
  --btn-border-radius: 0.5em;

  min-block-size: var(--btn-size);
}

.searches__results {
  padding-block-start: var(--navbar-height);
}

.searches__input:required:invalid {
  ~ .searches__reset {
    display: none;
    visibility: hidden;
  }
}

/* Star toggle on sidebar room + direct rows. Hidden until row hover; always
   visible when the row is starred. Pushed to the far end of the row. */
.room__star {
  --btn-size: auto;
  --btn-padding: 0;
  --btn-background: transparent;
  --btn-border-color: transparent;

  align-items: center;
  display: inline-flex;
  flex-shrink: 0;
  justify-content: center;
  margin-inline-start: auto;
  opacity: 0;
  padding: 0.15em;

  /* No button chrome: bare icon, no hover ring or focus box. */
  background: transparent;
  border: 0;
  box-shadow: none;

  &:focus-visible {
    opacity: 1;
    outline: none;
  }

  img {
    block-size: 16px;
    inline-size: 16px;
  }

  @media (any-hover: hover) {
    &:where(:hover) {
      --icon-filter: none;
    }
  }
}

/* When the row has no unread badge taking the auto margin, the star claims it;
   when there IS an unread badge, the badge already pushes right, so the star
   sits just after it without its own auto margin. */
.room--row.unread .room__star,
.direct--row.unread .room__star {
  margin-inline-start: 0.4em;
}

/* Reveal the star on row hover (pointer devices). */
@media (any-hover: hover) {
  .room--row:hover .room__star,
  .direct--row:hover .room__star {
    opacity: 0.55;
  }

  .room--row .room__star:hover,
  .direct--row .room__star:hover {
    opacity: 1;
  }
}

/* Starred: filled accent star, always shown. */
.room__star--on {
  opacity: 1;

  img {
    filter: none;
  }

  /* Tint the star with the brand accent via a color overlay. */
  color: var(--color-accent);
}

.room__star--on img {
  /* Recolor the black source SVG to the cyan accent. */
  filter: invert(63%) sepia(89%) saturate(1352%) hue-rotate(146deg) brightness(94%) contrast(91%);
}

/* On touch / no-hover devices, always show the star so it stays reachable. */
@media (any-hover: none) {
  .room__star {
    opacity: 0.55;
  }

  .room__star--on {
    opacity: 1;
  }
}
