/* ─────────────────────────────────────────────────────────────────────────
   SIDE PANEL — the one right-hand panel (METIS-pub#825 version B, #826).

   From the foot of the strip to the bottom of the window (the owner,
   2026-11-26): the strip keeps the whole width above it; while a panel is
   open the band and the page take the width left of it (their right margin),
   and the panel scrolls on its own under its head (title, ×). Its top is the
   strip's height token, --place-strip-h (the body is a column that never
   scrolls, base.css, so the strip never moves). On a phone a panel opened from a row is a sheet over the
   whole screen; a panel showing its page's default (Home's Updates) stays in
   the page's flow, under the list.

     .side-panel              the panel; open while it holds a .side-panel__head
                              (an empty one, or one holding only a page's
                              placeholder, is the page's to lay out)
     [data-sheet]             on the panel: on a phone, cover the screen. Set
                              by whatever opened it from a row (the server for
                              an address that names it, crm/js/side_panel.js
                              or the page's own script for a click)
     .side-panel__head        sticky at its top: what it shows, and its ×
     .side-panel__head--who   a person's or a holon's head (crm/partials/
                              _side_panel_head.html): __pic (face or logo,
                              its __logo), __who with __eyebrow (the parent),
                              __title, __sub (a headline), __line (place,
                              contacts, or the kind and stage chip)
     .side-panel__title       the name, wrapping, never cut
     .side-panel__close       the ×; [data-side-panel-close] closes it
                              (crm/js/side_panel.js)
     .side-panel__default     the shell's wrapper of a page's default
     .side-panel__body …      a pane's body: __meta (what it is part of,
                              its status), __fields (label, value),
                              __section with its __label, __people (faces,
                              names), __faces (faces in one line), __more,
                              __notes (a feed under it)
     .side-panel__flows …     where a person stands, a flow at a time
                              (crm/chat/partials/_flow_row.html, METIS-pub#825):
                              __due (red, only when a follow-up is overdue;
                              also a place's overdue people, __due-people),
                              __status (one quiet line, ending in ✎), __edit
                              (the editor behind ✎, with Done), __hint

   The panel is the shell's, one on every page (shell/base.html); a page
   gives it only its default (Home's Updates, a place's Coming up, a detail
   page's notes, the Profile's account), and any person or holon link opens
   in it ({% panel_link %}, core.side_panels). With no default and nothing
   open the page keeps the whole width. Width: --side-panel-w. Tokens only.

     [data-panel-key][aria-current]   a row that is not a link (a table's
                              <tr>, a Connections row), open in the panel;
                              a link row's own list marks its row
                              (todo-list.css)
   ───────────────────────────────────────────────────────────────────────── */

@layer components {
  .side-panel__head {
    position: sticky;
    top: 0;
    z-index: 2;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2) var(--space-3);
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--color-border);
    background: var(--color-surface);
  }

  .side-panel__title {
    flex: 1 1 0;
    min-width: 0;
    margin: 0;
    color: var(--color-text-strong);
    font-size: var(--text-lg);
    font-weight: 600;
    overflow-wrap: anywhere;
  }

  /* A person's or a holon's head: the picture, then who it is. */
  .side-panel__head--who {
    flex-wrap: nowrap;
    align-items: flex-start;
  }

  .side-panel__pic {
    flex: none;
  }

  .side-panel__pic .person-face {
    --person-face-size: var(--space-12);
  }

  .side-panel__logo {
    display: block;
    width: var(--space-12);
    height: var(--space-12);
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-md);
    background: var(--color-surface);
    object-fit: contain;
  }

  .side-panel__logo--initial {
    display: grid;
    place-items: center;
    color: var(--color-text-muted);
    font-size: var(--text-lg);
    font-weight: 600;
  }

  .side-panel__who {
    display: flex;
    flex: 1 1 0;
    flex-direction: column;
    gap: var(--space-1);
    min-width: 0;
  }

  .side-panel__who .side-panel__title {
    flex: none;
    color: var(--color-text-strong);
    text-decoration: none;
  }

  .side-panel__who a.side-panel__title:hover {
    text-decoration: underline;
  }

  /* A panel whose head is its own (Audax's action and mission panels): the
     title is the link to the full page, drawn as the title until hovered,
     like the person and holon head's name above. */
  .side-panel__title-link {
    color: inherit;
    text-decoration: none;
  }
  .side-panel__title-link:hover { text-decoration: underline; }

  .side-panel__eyebrow {
    color: var(--color-text-muted);
    font-size: var(--text-xs);
    text-decoration: none;
  }

  .side-panel__sub {
    display: -webkit-box;
    margin: 0;
    overflow: hidden;
    color: var(--color-text-muted);
    font-size: var(--text-sm);
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
  }

  .side-panel__line {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-1) var(--space-2);
    margin: 0;
    color: var(--color-text-muted);
    font-size: var(--text-sm);
  }

  .side-panel__line a {
    display: inline-flex;
    color: var(--color-text-muted);
  }

  .side-panel__close {
    flex: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: var(--space-8);
    height: var(--space-8);
    padding: 0;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-full);
    background: var(--color-surface);
    color: var(--color-text-muted);
    cursor: pointer;
  }

  .side-panel__close:hover {
    color: var(--color-text);
  }

  .side-panel__close svg {
    width: var(--space-4);
    height: var(--space-4);
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
  }

  /* A pane's body under its head (a holon's summary, the Profile's account
     sections): padded like the head, its parts one under the other. */
  .side-panel__body {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: var(--space-4);
    padding: var(--space-3) var(--space-4) var(--space-4);
  }

  .side-panel__meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2) var(--space-3);
    margin: 0;
    color: var(--color-text-muted);
    font-size: var(--text-sm);
  }

  .side-panel__fields {
    display: grid;
    grid-template-columns: max-content minmax(0, 1fr);
    gap: var(--space-1) var(--space-3);
    margin: 0;
  }

  .side-panel__fields dt {
    color: var(--color-text-muted);
    font-size: var(--text-sm);
  }

  .side-panel__fields dd {
    margin: 0;
    min-width: 0;
  }

  .side-panel__section {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: var(--space-2);
  }

  .side-panel__notes {
    padding: 0 var(--space-4) var(--space-4);
  }

  .side-panel__label {
    margin: 0;
    color: var(--color-text-muted);
    font-size: var(--text-sm);
    font-weight: 600;
  }

  .side-panel__people {
    display: grid;
    gap: var(--space-2);
    margin: 0;
    padding: 0;
    list-style: none;
  }

  .side-panel__people a {
    color: inherit;
    text-decoration: none;
  }

  .side-panel__people a:hover .person-face__name,
  .side-panel__more:hover {
    text-decoration: underline;
  }

  .side-panel__more {
    justify-self: start;
    padding: 0;
    border: 0;
    background: none;
    color: var(--color-accent);
    font: inherit;
    font-size: var(--text-sm);
    text-decoration: none;
    cursor: pointer;
  }

  .side-panel__hint {
    color: var(--color-text-muted);
    font-size: var(--text-sm);
  }

  /* The team as faces in one line, wrapping. */
  .side-panel__faces {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2) var(--space-3);
    margin: 0;
    padding: 0;
    list-style: none;
  }

  .side-panel__faces a {
    color: inherit;
    text-decoration: none;
  }

  /* Where a person stands, a flow at a time (METIS-pub#825): loud only
     when something is due. */
  .side-panel__flows {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4) 0;
  }

  .side-panel__flow form {
    display: grid;
    gap: var(--space-2);
    margin: 0;
  }

  /* The row's icon buttons (✎, the calendar): sized and stroked here, as
     .btn--icon leaves an icon's size to its host. */
  .side-panel__flow .btn svg {
    width: var(--space-4);
    height: var(--space-4);
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
  }

  .side-panel__due {
    display: grid;
    gap: var(--space-2);
    padding: var(--space-3);
    border: 1px solid var(--color-danger-border);
    border-radius: var(--radius-lg);
    background: var(--color-danger-bg);
  }

  .side-panel__due-what {
    display: flex;
    align-items: flex-start;
    gap: var(--space-2);
    margin: 0;
    color: var(--color-danger-strong);
  }

  .side-panel__due-what svg {
    flex: none;
    margin-top: var(--space-1);
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
  }

  .side-panel__due-what b {
    color: var(--color-text-strong);
    font-weight: 600;
  }

  .side-panel__due-what small {
    display: block;
    font-size: var(--text-sm);
  }

  .side-panel__due-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
  }

  .side-panel__due-people {
    display: grid;
    gap: var(--space-2);
    margin: 0;
    padding: 0;
    list-style: none;
  }

  .side-panel__due-people li {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    min-width: 0;
  }

  .side-panel__due-people a {
    min-width: 0;
    color: var(--color-text-strong);
    text-decoration: none;
  }

  .side-panel__due-people .chat-follow-up-badge {
    margin-left: auto;
  }

  .side-panel__status {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-md);
    background: var(--color-surface);
    font-size: var(--text-sm);
  }

  .side-panel__status-place {
    flex-basis: 100%;
    color: var(--color-text-muted);
  }

  .side-panel__status-place a {
    color: inherit;
  }

  .side-panel__status-end {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    margin-left: auto;
  }

  .side-panel__add {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
  }

  .side-panel__edit {
    padding: var(--space-2) var(--space-3) var(--space-3);
    border: 1px solid var(--color-accent);
    border-radius: var(--radius-md);
    background: color-mix(in oklab, var(--color-accent) 4%, var(--color-surface));
  }

  .side-panel__edit-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: var(--color-text-muted);
    font-size: var(--text-sm);
  }

  /* The editor is open: the quiet line it edits steps back. */
  .side-panel__flow:has(.side-panel__edit:not([hidden])) .side-panel__status {
    display: none;
  }

  /* The row open in the panel, when the row is not a link itself: tinted,
     with an accent bar at its left edge. A table row's bar is its first
     cell's (a <tr>'s own border does not draw beside collapsed cells). */
  [data-panel-key][aria-current]:not(a) {
    background: color-mix(in oklab, var(--color-accent) 8%, transparent);
  }

  [data-panel-key][aria-current]:not(a, tr),
  tr[data-panel-key][aria-current] > :first-child {
    border-left: var(--space-1) solid var(--color-accent);
  }

  /* A wide window: the panel is a column from under the strip to the
     bottom of the window, and the band and the page move left of it. */
  @media (min-width: 769px) {
    body:has(.side-panel .side-panel__head) > .place-band,
    body:has(.side-panel .side-panel__head) > .main {
      margin-right: var(--side-panel-w);
    }

    /* A page that sizes its main itself (a list page's width: 100%,
       table.css) still ends at the panel's edge. */
    body:has(.side-panel .side-panel__head) > .main {
      max-width: calc(100% - var(--side-panel-w));
    }

    .side-panel:has(.side-panel__head) {
      position: fixed;
      z-index: 400;
      top: var(--place-strip-h);
      right: 0;
      bottom: 0;
      width: var(--side-panel-w);
      display: flex;
      flex-direction: column;
      overflow-y: auto;
      /* The panel never scrolls sideways: a wide line or picture inside
         is held to its width instead (METIS-pub#847). */
      overflow-x: hidden;
      overscroll-behavior: contain;
      background: var(--color-surface);
      border-left: 1px solid var(--color-border);
      box-shadow: var(--elev-2);
    }

    .side-panel:has(.side-panel__head) > * {
      flex-shrink: 0;
    }

    .side-panel:has(.side-panel__head) :is(img, video, iframe, pre, table) {
      max-width: 100%;
    }
  }

  /* A phone: a panel opened from a row covers the screen (the strip's
     menus included, hence above their 600), and the page behind it does
     not scroll. */
  @media (max-width: 768px) {
    .side-panel[data-sheet]:has(.side-panel__head) {
      position: fixed;
      z-index: 700;
      inset: 0;
      display: flex;
      flex-direction: column;
      overflow-y: auto;
      overscroll-behavior: contain;
      background: var(--color-surface);
    }

    .side-panel[data-sheet]:has(.side-panel__head) > * {
      flex-shrink: 0;
    }

    body:has(.side-panel[data-sheet] .side-panel__head) .main {
      overflow: hidden;
    }

    /* A default with nothing opened (Home's Updates, a page's notes)
       follows the page, as a section of it, not a column. */
    .side-panel:not([data-sheet]):has(.side-panel__default .side-panel__head) {
      margin-top: var(--space-8);
      border-top: 1px solid var(--color-border-light);
    }

    .side-panel:not([data-sheet]) .side-panel__default .side-panel__head {
      position: static;
      padding-inline: 0;
      border-bottom: 0;
      background: none;
    }

    .side-panel__close {
      width: 44px;
      height: 44px;
      color: var(--color-text-strong);
    }
  }
}
