/* The list pane and the conversation (S2c, #168; behaviour in panes.js).
   Desktop (64rem and wider): the list sits beside the conversation, wider on
   very wide screens. Tablet (48rem to 64rem): the list opens over the
   conversation from the header toggle. Phone (below 48rem): a stack, the list
   first, the conversation pushed over it. Lanterns (rooms) and pebbles
   (people) take their identity hue (identity-hue.js, CCM visual vocabulary).
   Uses only existing tokens. */

/* ---- The list pane ---- */

.list-pane {
  display: flex;
  min-width: 0;
  min-height: 0;
  flex-direction: column;
  gap: 0.25rem;
  padding-bottom: 0.5rem;
  overflow-y: auto;
}

.list-pane > * { flex-shrink: 0; }

.list-pane-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.6rem 0.35rem 0.75rem 1rem;
}

.list-pane-title { display: grid; gap: 0.2rem; min-width: 0; }

.list-title {
  margin: 0;
  font-family: var(--display-font);
  font-size: var(--type-display-m);
  font-weight: 700;
  letter-spacing: var(--title-tracking);
  line-height: var(--leading-display);
  overflow-wrap: anywhere;
}

/* The installation's name heads every list pane (Lantern Next L2, owner decision): on
   wide screens the rail beside it shows the icon, so here it is the name alone; phones
   have no rail, so the icon comes with it (below). A long name wraps, to as many lines
   as it needs, and never scrolls the page sideways. */
.list-pane-brand {
  display: flex;
  align-items: flex-start;
  gap: 0.45rem;
  min-width: 0;
  margin: 0 0 0.2rem;
  color: var(--text-muted);
  font-size: var(--type-label);
  font-weight: 600;
  line-height: var(--leading-tight);
}
.list-pane-brand img { display: none; flex: none; width: 1.5rem; height: 1.5rem; border-radius: 22%; object-fit: cover; }
.list-pane-brand span { min-width: 0; overflow-wrap: anywhere; }

.list-pane-actions { display: flex; flex: none; align-items: center; gap: 0.15rem; }
.list-pane-actions .header-button { color: var(--text-muted); }
.list-pane-actions .header-button:hover { color: var(--text); }

.list-pane .room-list { padding: 0 0.5rem; }
.list-pane .room-button { min-height: 3rem; gap: 0.6rem; padding: 0.4rem 0.6rem; }
.list-pane .guest-dm-card { margin: 0.75rem 0.75rem 0; }

/* ---- Lanterns and pebbles ---- */

.lantern,
.pebble {
  display: inline-grid;
  flex: none;
  place-items: center;
  width: 2.25rem;
  height: 2.25rem;
  background: var(--raised);
  color: var(--text-muted);
  font-weight: 700;
  line-height: 1;
  vertical-align: middle;
}

/* A squircle: the corner is about a third of the side. */
.lantern { border-radius: 0.75rem; font-size: 1rem; }
.pebble { border-radius: 50%; font-size: 0.8rem; letter-spacing: 0.02em; }

.list-pane .lantern { width: 2.25rem; height: 2.25rem; margin-right: 0.15rem; }
.room-heading .lantern { margin-right: 0.45rem; font-family: inherit; font-size: 1.05rem; letter-spacing: 0; vertical-align: 0.1em; }

/* A room's lantern shows its initial (Lantern Next L1). The element's text stays "#"
   (zero-size, like the nav's unread count in shell.css), so "# name" is unchanged for
   screen readers, copy and tests; the letter is generated content with empty
   alternative text (the plain declaration is the fallback for engines without it).
   Ink on the identity hue, 8.4:1 or more on every hue. */
/* Flex, not the base grid: the zero-size "#" would otherwise take a grid row of its own
   and push the letter off centre. */
.lantern.lantern[data-initial] { display: inline-flex; align-items: center; justify-content: center; font-size: 0; }
.room-heading .lantern.lantern[data-initial] { vertical-align: middle; }
.lantern[data-initial]::before {
  content: attr(data-initial);
  content: attr(data-initial) / "";
  font-family: var(--display-font);
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0;
  line-height: 1;
}

:is(.lantern, .pebble)[data-hue="0"] { background: var(--hue-0); color: var(--hue-ink); }
:is(.lantern, .pebble)[data-hue="1"] { background: var(--hue-1); color: var(--hue-ink); }
:is(.lantern, .pebble)[data-hue="2"] { background: var(--hue-2); color: var(--hue-ink); }
:is(.lantern, .pebble)[data-hue="3"] { background: var(--hue-3); color: var(--hue-ink); }
:is(.lantern, .pebble)[data-hue="4"] { background: var(--hue-4); color: var(--hue-ink); }
:is(.lantern, .pebble)[data-hue="5"] { background: var(--hue-5); color: var(--hue-ink); }
:is(.lantern, .pebble)[data-hue="6"] { background: var(--hue-6); color: var(--hue-ink); }
:is(.lantern, .pebble)[data-hue="7"] { background: var(--hue-7); color: var(--hue-ink); }

/* People are here: a gap in the header's colour, a honey ring and a soft halo.
   Static, and always next to "N here now". */
.lantern.glow {
  box-shadow:
    0 0 0 2px var(--surface),
    0 0 0 4px var(--presence),
    0 0 14px 5px color-mix(in srgb, var(--presence) 40%, transparent);
}

/* ---- The conversation header ---- */

.room-heading .room-meta-line {
  display: flex;
  flex-wrap: wrap;
  gap: 0.1rem 0.65rem;
}

.room-here { color: var(--presence-text); font-weight: 600; }
.room-here[hidden] { display: none; }

.conversation-title:focus { outline: none; }
.conversation-title:focus-visible { outline: 2px solid var(--signature-text); outline-offset: 4px; border-radius: 0.4rem; }

.drawer-toggle .toggle-back { display: none; }

/* ---- The Direct page: the same frame as the Rooms page ---- */

.messages-shell.dm-shell {
  --sidebar-width: 21.25rem;
  position: relative;
  display: grid;
  width: auto;
  max-width: none;
  height: 100vh;
  height: 100dvh;
  margin: 0;
  padding: 1rem;
  gap: 1rem;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
}

.dm-shell:has(> .rules-banner:not(.hidden)) { grid-template-rows: auto minmax(0, 1fr); }
.dm-shell > .rules-banner { grid-column: 1 / -1; margin: 0; }
.dm-shell .drawer-close,
.dm-shell .drawer-toggle,
.dm-shell .drawer-backdrop { display: none; }

.list-pane-status { margin: 0; color: var(--text-muted); font-size: 0.82rem; overflow-wrap: anywhere; }

.dm-list-pane { gap: 0.6rem; }
.dm-list-pane > :not(.list-pane-header) { margin-inline: 0.75rem; }
.dm-start-row { display: flex; gap: 0.5rem; }
.dm-start-row input { flex: 1; min-width: 0; }
.list-section-heading {
  margin: 0.75rem 0.75rem 0.1rem;
  color: var(--text-muted);
  font-size: var(--type-label);
  font-weight: 600;
  line-height: var(--leading-tight);
}

.dm-shell .conversation-list { gap: 0.25rem; overflow: visible; }
.dm-shell .conversation-button {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-height: 3.5rem;
  border-color: transparent;
  border-radius: var(--radius-field);
  background: transparent;
  font-size: var(--type-body);
}
.dm-shell .conversation-button:hover { border-color: transparent; background: color-mix(in srgb, var(--text) 6%, transparent); }
/* The selected row, as in the Rooms list (L3). */
.dm-shell .conversation-button.active,
.dm-shell .conversation-button.active:hover {
  position: relative;
  border-color: transparent;
  background: var(--selected);
  box-shadow: var(--elev-1);
}

/* ---- The selected row's bar (Lantern Next L3) ----
   One short bar at the row's start, in Rooms, Direct and You: a shape beside the lit
   fill, so the selection isn't carried by a tint. Persimmon as text (3:1 or more on
   the fill in every scheme). */
:is(.room-button.active, .dm-shell .conversation-button.active, .you-section-link[aria-current="page"])::before {
  position: absolute;
  top: 50%;
  left: 0.2rem;
  width: 3px;
  height: 1.4rem;
  margin-top: -0.7rem;
  border-radius: 2px;
  background: var(--signature-text);
  content: "";
}
@media (forced-colors: active) {
  :is(.room-button.active, .dm-shell .conversation-button.active, .you-section-link[aria-current="page"])::before { background: Highlight; }
  .dm-shell .conversation-button.active { border: 2px solid Highlight; }
}
.conversation-text { display: grid; flex: 1; gap: 0.15rem; min-width: 0; }
.dm-shell .conversation-button .pebble { width: 2.5rem; height: 2.5rem; }

.dm-shell .conversation-main {
  display: flex;
  min-width: 0;
  min-height: 0;
  flex-direction: column;
  /* The stage (L2), as the room conversation: see .chat-main in app.css. */
  border: 1px solid transparent;
  border-radius: var(--radius-sheet);
  background: var(--stage);
  box-shadow: var(--elev-1);
  overflow: hidden;
}

.dm-shell .conversation-main > * { flex: none; }
.dm-shell .dm-empty-state { flex: 1 1 auto; }
.dm-shell .dm-message-list { flex: 1 1 0; min-height: 0; }
.dm-shell .conversation-main > .error-text:empty { display: none; }

.dm-shell .conversation-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.9rem 1rem 0.9rem 1.5rem;
  background: var(--surface);
}
.dm-shell .dm-heading { display: grid; flex: 1; gap: 0.2rem; min-width: 0; }
.dm-shell .conversation-header h2 {
  font-family: var(--display-font);
  font-size: var(--type-title);
  font-weight: 700;
  letter-spacing: var(--title-tracking);
  line-height: var(--leading-tight);
}
/* One row at every width (Lantern Next L6): Report and Block open from "More actions" as
   a small menu under it. The button is a 44px target; the menu floats at the floating
   level and never leaves the window (it is anchored to the header's end and may be as
   narrow as the window allows, its items wrapping). */
.dm-shell .conversation-header { position: relative; }
.dm-shell .dm-more-toggle:not([hidden]) { display: grid; flex: none; min-width: var(--target-min); height: var(--target-min); place-items: center; padding: 0; }
.dm-shell .conversation-actions {
  position: absolute;
  z-index: 5;
  inset-block-start: calc(100% - 0.25rem);
  inset-inline-end: 0.5rem;
  display: none;
  flex-direction: column;
  flex-wrap: nowrap;
  align-items: stretch;
  gap: 0;
  min-width: min(13rem, calc(100vw - 1rem));
  max-width: calc(100vw - 1rem);
  padding: 0.35rem;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-field);
  background: var(--surface);
  box-shadow: var(--elev-2);
}
.dm-shell .conversation-actions.open { display: flex; }
.dm-shell .conversation-actions .message-menu-item { overflow-wrap: anywhere; cursor: pointer; }
.dm-shell .conversation-actions .message-menu-item:disabled { cursor: progress; }
@media (forced-colors: active) {
  .dm-shell .conversation-actions { border-color: CanvasText; }
}
.pebble[hidden] { display: none; }

/* The privacy notice: one line, the detail behind "Learn more". */
.privacy-line {
  padding: 0.45rem 1.5rem;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--unsure-line) 6%, var(--surface));
  color: var(--text-muted);
  font-size: 0.85rem;
}
.privacy-line summary { cursor: pointer; list-style: none; }
.privacy-line summary::-webkit-details-marker { display: none; }
.privacy-line .privacy-more { color: var(--signature-text); font-weight: 600; text-decoration: underline; text-underline-offset: 0.15em; }
.privacy-line[open] .privacy-more { display: none; }
.privacy-line p { margin: 0.4rem 0 0; line-height: 1.5; }
.privacy-line summary:focus-visible { outline: 2px solid var(--signature-text); outline-offset: 2px; border-radius: 0.3rem; }

/* ---- Desktop: the list beside the conversation ---- */

.chat-shell { --sidebar-width: 21.25rem; }

@media (min-width: 90rem) {
  .chat-shell, .messages-shell.dm-shell { --sidebar-width: 26.25rem; }
}

/* ---- Tablet: the list over the conversation ---- */

@media (min-width: 48rem) and (max-width: 63.99rem) {
  .chat-shell,
  .chat-shell.members-open,
  .messages-shell.dm-shell { grid-template-columns: minmax(0, 1fr); }

  :is(.chat-shell, .dm-shell) > .list-pane {
    position: fixed;
    z-index: 30;
    inset: 0 auto 0 var(--rail-width, 0px);
    width: min(22rem, 70vw);
    padding: 0.5rem 0.25rem 1rem;
    border-right: 1px solid var(--line);
    background: var(--ground);
    box-shadow: 0 0 60px var(--shadow-strong);
    transform: translateX(-110%);
    visibility: hidden;
    transition: transform 0.2s ease, visibility 0s linear 0.2s;
  }

  :is(.chat-shell, .dm-shell).list-open > .list-pane {
    transform: none;
    visibility: visible;
    transition: transform 0.2s ease;
  }

  :is(.chat-shell, .dm-shell).list-open .drawer-backdrop {
    position: fixed;
    z-index: 25;
    inset: 0;
    display: block;
    background: var(--scrim);
  }

  :is(.chat-shell, .dm-shell) :is(.drawer-toggle, .drawer-close) { display: inline-flex; }
}

/* ---- Phone: the stack ---- */

@media (max-width: 47.99rem) {
  .chat-shell,
  .chat-shell.members-open {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr);
    gap: 0;
    padding: 0;
  }

  .chat-shell:has(> .lockdown-banner:not(.hidden)) { grid-template-rows: auto minmax(0, 1fr); }

  .messages-shell.dm-shell {
    grid-template-columns: minmax(0, 1fr);
    height: calc(100vh - var(--bar-space));
    height: calc(100dvh - var(--bar-space));
    padding: 0;
    gap: 0;
  }
  /* The full height (S7g): messages.css gives the inspection layout's .conversation-main
     85dvh on narrow screens, which left a blank strip under every phone's direct composer. */
  .dm-shell .conversation-main { height: auto; min-height: 0; border: 0; border-radius: 0; box-shadow: none; }
  .dm-shell .conversation-header { gap: 0.35rem; padding: 0.5rem 0.5rem 0.5rem 0.4rem; }
  .dm-shell .conversation-header h2 { overflow: hidden; font-size: 1.25rem; text-overflow: ellipsis; white-space: nowrap; }
  .dm-shell #dm-peer-status { font-size: 0.82rem; }
  .privacy-line { padding-inline: 0.85rem; }

  /* The list is the first screen; a chosen conversation covers it. */
  :is(.chat-shell, .dm-shell)[data-stack="list"] > :is(.chat-main, .conversation-main, .members-panel) { display: none; }
  :is(.chat-shell, .dm-shell)[data-stack="conversation"] > .list-pane { display: none; }
  :is(.chat-shell, .dm-shell) > .list-pane { padding: 0.25rem 0 1rem; background: var(--ground); }

  /* The list screen has no conversation to skip to. */
  body:has([data-panes][data-stack="list"]) .skip-link { display: none; }

  /* A pushed screen has no bottom bar. */
  .app-frame.has-nav:has(> [data-panes][data-stack="conversation"]) { --bar-space: 0px; }
  .app-frame.has-nav:has(> [data-panes][data-stack="conversation"]) > .app-nav { display: none; }

  :is(.chat-shell, .dm-shell) .drawer-toggle { display: inline-flex; }
  .drawer-toggle .toggle-list { display: none; }
  .drawer-toggle .toggle-back { display: block; }

  /* No rail here, so the icon comes with the name; the name is centred on the icon while
     it fits on one line and wraps beside it when it doesn't. */
  .list-pane-brand { margin-bottom: 0.35rem; }
  .list-pane-brand img { display: block; box-shadow: 0 0 0 1px var(--line); }
  .list-pane-brand span { align-self: center; }

  .list-pane .room-button { min-height: 3.25rem; font-size: 1rem; }
  .list-pane .lantern { width: 2.5rem; height: 2.5rem; }

  /* Room details give way on narrow headers; "N here now" stays. */
  .room-heading p.room-meta-line { display: flex; margin-top: 0.1rem; font-size: 0.82rem; }
  .room-meta-line #room-info { display: none; }
}

@media (any-pointer: coarse) {
  .list-pane-actions .header-button,
  .chat-shell .drawer-toggle { min-width: 3rem; min-height: 3rem; }
}

@media (prefers-reduced-motion: reduce) {
  :is(.chat-shell, .dm-shell) > .list-pane { transition: none; }
}

@media (forced-colors: active) {
  .lantern, .pebble { border: 1px solid CanvasText; }
  .lantern.glow { outline: 2px solid Highlight; outline-offset: 2px; }
}

/* R2 (S7h): on a narrow phone the encryption line is short words, which wrap rather than
   truncate, so "Learn more" is never cut off. The accessible name stays the full sentence. */
.privacy-short { display: none; }
@media (max-width: 24rem) {
  .privacy-line { padding-block: 0.35rem; font-size: 0.88rem; }
  .privacy-line:not([open]) .privacy-long { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .privacy-line:not([open]) .privacy-short { display: inline; }
}
