/* ─────────────────────────────────────────────────────────────────────────
   Quest outline — a quest's or mission's actions as one outline, its stage
   chip, the side panel drawer, and the quest rows on a holon page
   (METIS-pub#744).

   Loaded by the two section templates (audax/holon_sections/actions.html and
   quests.html) and the page header's summary (audax/partials/header_summary.html),
   not on every Audax route. Not scoped to [data-app="audax"]:
   the quest rows land on an organisation's or event's page, whose theme is
   the platform's, and a quest page is a holon page. Everything here reads
   platform tokens; the step colours come from the step itself through
   --au-step-bg / --au-step-fg, as the holon's own stage chip does.

   Audax's own, until a second app wants the progress bar or the drawer; then
   they graduate to crm/css/components/ (CLAUDE.md § UI).
   ───────────────────────────────────────────────────────────────────────── */

@layer components {
  .au-outline { display: grid; gap: var(--space-4); }
  .au-outline__list { display: grid; gap: var(--space-4); min-width: 0; }

  .au-outline__controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-3);
  }
  .au-outline__journey label { display: flex; align-items: center; gap: var(--space-2); font-size: var(--text-md); }
  .au-outline__who { display: inline-flex; }
  .au-outline__add-mission { margin-left: auto; }
  /* The outline's and the side panel's buttons (+ Mission, Open full page):
     the platform .btn's --text-base is under #786's floor. */
  :is(.au-outline__controls, .au-panel__head) .btn { font-size: var(--text-md); }

  /* ── The page header's summary: progress, overdue, team ─────────── */
  .au-summary {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2) var(--space-4);
    margin-top: var(--space-2);
  }
  .au-summary__progress { flex: 0 1 24rem; display: flex; align-items: center; gap: var(--space-2); min-width: 0; }
  .au-summary__overdue { color: var(--color-danger); font-size: var(--text-md); font-weight: 700; }

  /* ── Progress: a done-of-total bar and its words ─────────────────── */
  .au-progress {
    display: inline-block;
    flex: 1 1 4rem;
    min-width: 4rem;
    max-width: 16rem;
    height: var(--space-2);
    border-radius: var(--radius-full);
    background: var(--color-border-light);
    overflow: hidden;
    vertical-align: middle;
  }
  .au-progress__fill {
    display: block;
    width: var(--au-progress, 0%);
    height: 100%;
    background: var(--color-accent);
  }
  .au-progress__words { font-size: var(--text-md); color: var(--color-text-muted); white-space: nowrap; }

  /* ── Team faces ──────────────────────────────────────────────────── */
  .au-team { display: inline-flex; align-items: center; gap: var(--space-2); color: var(--color-text-muted); font-size: var(--text-md); text-decoration: none; }
  .au-team__faces { display: inline-flex; }
  .au-team__face { display: inline-flex; margin-left: calc(var(--space-2) * -1); }
  .au-team__face:first-child { margin-left: 0; }
  .au-team__face .chat-avatar-img,
  .au-team__face .chat-avatar-initials { outline: 2px solid var(--color-surface); }

  /* ── Groups: the quest itself, then one box per mission ──────────── */
  .au-group { display: grid; gap: var(--space-2); }
  .au-group--mission {
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: var(--space-3) var(--space-4);
    background: var(--color-surface);
  }
  .au-group__head { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-3); }
  .au-group__title { margin: 0; font-size: var(--text-lg); }
  /* The journey, said once for the group (#826 review, m4). */
  .au-group__journey { color: var(--color-text-muted); font-size: var(--text-md); }
  /* "Show N done": the group's finished actions, folded (#826 review, m4). */
  .au-done > .au-done__toggle {
    display: inline-flex;
    align-items: center;
    min-height: 32px;
    padding: 0 var(--space-2);
    color: var(--color-text-muted);
    font-size: var(--text-md);
    cursor: pointer;
    list-style: none;
  }
  .au-done > .au-done__toggle::-webkit-details-marker { display: none; }
  .au-done > .au-done__toggle:hover { color: var(--color-accent); }
  .au-done__hide,
  .au-done[open] .au-done__show { display: none; }
  .au-done[open] .au-done__hide { display: inline; }
  .au-group__progress { display: inline-flex; align-items: center; gap: var(--space-2); flex: 1 1 10rem; }
  .au-group__goal .field-label { display: none; }

  /* ── One line per action (and per quest on a holon page) ─────────── */
  .au-lines { list-style: none; margin: 0; padding: 0; display: grid; }
  .au-lines__empty { color: var(--color-text-muted); font-size: var(--text-md); }
  .au-line {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-1) var(--space-3);
    padding: var(--space-2) 0;
    border-bottom: 1px solid var(--color-border-light);
    min-width: 0;
  }
  .au-line:last-child { border-bottom: 0; }
  .au-line__name {
    flex: 1 1 10rem;
    min-width: 0;
    padding: 0;
    border: 0;
    background: none;
    color: var(--color-text-strong);
    font: inherit;
    text-align: left;
    cursor: pointer;
    overflow-wrap: anywhere;
  }
  .au-line__name:hover { text-decoration: underline; }
  .au-line__where,
  .au-line__who,
  .au-line__due { font-size: var(--text-md); color: var(--color-text-muted); }
  .au-line__due.is-overdue { color: var(--color-danger); font-weight: 700; }
  .au-line.is-finished .au-line__name { text-decoration: line-through; color: var(--color-text-muted); }

  /* An editor's line (METIS-pub#787): a click on the line opens the panel, so
     the whole line reads as clickable; the name renames in place and the due
     chip opens the quick date. Below 768px (the list-card switch, #672) the
     box and the menu give way to plain text (.au-line__open, .au-line__due-text)
     and a tap anywhere opens the panel. */
  .au-line--editable { cursor: pointer; }
  .au-line--editable:hover { background: var(--color-surface-2); }
  .au-line__name-box {
    width: 100%;
    margin: 0;
    padding: var(--space-1);
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: none;
    color: inherit;
    font: inherit;
    cursor: text;
  }
  .au-line__name-box:hover { border-color: var(--color-border-light); }
  .au-line__name-box:focus {
    border-color: var(--color-accent);
    background: var(--color-surface);
    outline: none;
  }
  .au-line.is-finished .au-line__name-box { text-decoration: line-through; color: var(--color-text-muted); }
  .au-line__open {
    flex: 1 1 10rem;
    min-width: 0;
    padding: 0;
    border: 0;
    background: none;
    color: var(--color-text-strong);
    font: inherit;
    text-align: left;
    overflow-wrap: anywhere;
  }
  .au-line.is-finished .au-line__open { text-decoration: line-through; color: var(--color-text-muted); }
  form.au-line__name,
  details.au-line__due { display: none; }
  details.au-line__due { position: relative; }
  .au-line__due-text { font-size: var(--text-md); color: var(--color-text-muted); }
  .au-line__due-text.is-overdue { color: var(--color-danger); font-weight: 700; }
  .au-line__due-chip {
    display: inline-flex;
    align-items: center;
    padding: var(--space-1) var(--space-2);
    border-radius: var(--radius-full);
    list-style: none;
    cursor: pointer;
    white-space: nowrap;
  }
  .au-line__due-chip::-webkit-details-marker { display: none; }
  .au-line__due-chip:hover,
  .au-line__due[open] > .au-line__due-chip { background: var(--color-surface-2); }
  .au-line__due-chip.is-empty { color: var(--color-text-faint); }
  /* The menu: the quick date's row stood on end (its children become the
     menu's items), with "Pick a date" above the date box. */
  .au-line__due-menu {
    position: absolute;
    z-index: 300;
    top: calc(100% + var(--space-1));
    right: 0;
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    min-width: 12rem;
    padding: var(--space-2);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--elev-2);
    cursor: default;
  }
  .au-line__due-menu .date-quick { display: contents; }
  .au-line__due-menu .date-quick__preset { order: 1; justify-content: flex-start; }
  .au-line__pick { order: 2; font-size: var(--text-md); color: var(--color-text-muted); }
  .au-line__due-menu input[type="date"] { order: 3; }
  .au-line__due-menu .date-quick__clear { order: 4; justify-content: flex-start; }

  /* 768px, as the line's click filter asks matchMedia: in px, so the two
     agree whatever the browser's default font size. */
  @media (min-width: 768px) {
    form.au-line__name,
    details.au-line__due { display: block; }
    .au-line__due-text { display: none; }
    /* Still reached by Tab: the line's keyboard way into the panel. */
    .au-line__open {
      position: absolute;
      width: 1px;
      height: 1px;
      overflow: hidden;
      clip-path: inset(50%);
      white-space: nowrap;
    }
  }

  .au-quest__progress { display: inline-flex; align-items: center; gap: var(--space-2); }
  .au-quest__overdue { color: var(--color-danger); font-size: var(--text-md); font-weight: 700; }

  /* ── Actions in columns (METIS-pub#823) ──────────────────────────
     One grid row per action, the column names once above them all
     (audax/partials/_outline_head.html), so every row of a list lines up and
     an empty cell keeps its place. The name takes what is left. The quest
     page: Action · Stage · Responsible · Due, with Quest › mission after the
     name in the due view (--where). My actions (--mine): its quest's logo
     first and no Responsible (they are all the reader's). Each cell names
     its area, so the phone's stacked rows below only redraw the areas. */
  .au-lines--grid {
    --au-cols: minmax(0, 1fr) 16rem 11rem 6.5rem;
    --au-areas: "name stage who due";
  }
  .au-lines--grid.au-lines--where {
    --au-cols: minmax(0, 1fr) minmax(0, 14rem) 16rem 11rem 6.5rem;
    --au-areas: "name where stage who due";
  }
  .au-lines--grid.au-lines--mine {
    --au-cols: 2rem minmax(0, 1fr) 13rem 6.5rem;
    --au-areas: "pic name stage due";
  }
  .au-lines--grid.au-lines--mine.au-lines--where {
    --au-cols: 2rem minmax(0, 1fr) minmax(0, 18rem) 13rem 6.5rem;
    --au-areas: "pic name where stage due";
  }
  .au-lines--grid > .au-line,
  .au-lines--grid > .au-lines__head {
    position: relative;
    display: grid;
    grid-template-columns: var(--au-cols);
    grid-template-areas: var(--au-areas);
    align-items: center;
    column-gap: var(--space-3);
    min-height: 44px;
    padding: 0 var(--space-2);
  }
  .au-lines--grid > .au-lines__head {
    min-height: 32px;
    border-bottom: 1px solid var(--color-border);
    color: var(--color-text-muted);
    font-size: var(--text-md);
    font-weight: 600;
  }
  .au-lines--grid > .au-lines__head > :last-child { justify-self: end; }
  /* The column names, once for the whole list (METIS-pub#826: not over every
     group), held at the top of the scroll while the rows pass under them.
     When missions are boxed, the names step in by the box's border and
     padding, and so do the quest's own rows, so every column lines up. */
  .au-outline__head {
    position: sticky;
    /* The page column that scrolls (.detail-main, detail.css) has
       --space-md of padding, and a sticky box stops inside it: at 0 the rows
       would show through that strip above the names. */
    top: calc(var(--space-md) * -1);
    z-index: 2;
    background: var(--color-bg);
  }
  .au-outline__list:has(> .au-group--mission) > .au-outline__head,
  .au-outline__list:has(> .au-group--mission) > .au-group:not(.au-group--mission) {
    padding-inline: calc(var(--space-4) + 1px);
  }
  .au-lines--grid .au-line__pic { grid-area: pic; display: inline-flex; }
  .au-lines--grid .au-line__name {
    grid-area: name;
    justify-self: start;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: var(--text-md);
  }
  a.au-line__name { color: var(--color-text-strong); text-decoration: none; }
  .au-lines--grid .au-line__where {
    grid-area: where;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .au-lines--grid .au-line__stage { grid-area: stage; display: flex; align-items: center; gap: var(--space-1); min-width: 0; }
  .au-lines--grid .au-line__stage .au-stage-wrap { display: flex; align-items: center; gap: var(--space-1); min-width: 0; }
  .au-lines--grid .au-line__who { grid-area: who; justify-self: start; min-width: 0; max-width: 100%; }
  .au-lines--grid .au-line__due { grid-area: due; justify-self: end; text-align: right; font-variant-numeric: tabular-nums; }
  /* An editor's row on the quest page (METIS-pub#787): the rename box fills
     the name column; the plain name and date that stand in for the box and
     the due menu below 768px take the same columns. */
  .au-lines--grid form.au-line__name { justify-self: stretch; }
  .au-lines--grid .au-line__open {
    grid-area: name;
    justify-self: start;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: var(--text-md);
  }
  .au-lines--grid .au-line__due-text { grid-area: due; justify-self: end; text-align: right; font-variant-numeric: tabular-nums; }
  /* The editors a row opens (the stage chip's pencil, a cell's autosave
     field) sit under the row, as wide as it, over the rows below. */
  .au-lines--grid .au-stage-editor,
  .au-lines--grid .au-line__editor {
    position: absolute;
    z-index: 300;
    top: 100%;
    left: 0;
    right: 0;
  }
  .au-line__editor:empty { display: none; }
  .au-line__editor {
    padding: var(--space-3);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--elev-2);
  }
  /* The quest's logo on My actions, whole in a white tile (a logo is never
     cropped to a shape), or its initials. */
  .au-line__pic-img,
  .au-line__pic-initials {
    width: 1.75rem;
    height: 1.75rem;
    padding: 2px;
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-sm);
    background: var(--color-surface);
    object-fit: contain;
  }
  .au-line__pic-initials {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--color-text-muted);
    font-size: var(--text-md);
    font-weight: 700;
  }

  /* A cell that changes the action in place (METIS-pub#824) says so on
     hover; an empty one invites a value. */
  .au-cell {
    margin: 0 calc(var(--space-2) * -1);
    padding: var(--space-1) var(--space-2);
    border: 0;
    border-radius: var(--radius-sm);
    background: none;
    color: inherit;
    font: inherit;
    cursor: pointer;
  }
  .au-cell:hover { background: var(--color-surface-2); outline: 1px solid var(--color-border); outline-offset: -1px; }
  .au-cell:focus-visible { background: var(--color-surface-2); }
  .au-line__due.au-cell { font-size: var(--text-md); }
  .au-cell__empty { color: var(--color-text-muted); font-size: var(--text-md); font-weight: 400; }
  .au-cell:hover .au-cell__empty,
  .au-cell:focus-visible .au-cell__empty { color: var(--color-accent); }

  /* A phone: the name on its own line, then the stage, then the person and
     the date on one line. No column names. */
  @media (max-width: 40rem) {
    .au-lines--grid {
      --au-cols: minmax(0, 1fr) auto;
      --au-areas: "name name" "stage stage" "who due";
    }
    .au-lines--grid.au-lines--where {
      --au-cols: minmax(0, 1fr) auto;
      --au-areas: "name name" "where where" "stage stage" "who due";
    }
    .au-lines--grid.au-lines--mine {
      --au-cols: 1.75rem minmax(0, 1fr) auto;
      --au-areas: "pic name name" "pic stage due";
    }
    .au-lines--grid.au-lines--mine.au-lines--where {
      --au-cols: 1.75rem minmax(0, 1fr) auto;
      --au-areas: "pic name name" "pic where due" "pic stage stage";
    }
    .au-lines--grid > .au-line { row-gap: var(--space-1); padding-block: var(--space-2); }
    .au-lines--grid > .au-lines__head,
    .au-outline__head { display: none; }
    .au-lines--grid .au-line__name { white-space: normal; }
    .au-lines--grid .au-line__pic { align-self: start; }
  }

  /* ── My actions (METIS-pub#811): the Group by control, then the groups,
     each a heading over the quest page's own rows ──────────────────── */
  .au-mine { display: grid; gap: var(--space-6); }
  .au-mine__group { display: grid; gap: var(--space-2); }
  /* A group's other work (METIS-pub#725): Home › Today's rows, under the
     group's heading, whose rule already draws the line above them. */
  .au-mine .au-mine__others { margin-top: 0; border-top: 0; }
  /* ── The add line ────────────────────────────────────────────────── */
  .au-add { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
  .au-add__name { flex: 1 1 12rem; min-width: 0; }
  .au-add__more { font-size: var(--text-md); }

  /* ── The stage chip and its menu ─────────────────────────────────── */
  .au-stage { position: relative; display: inline-block; }
  .au-stage__chip {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    padding: var(--space-1) var(--space-2);
    border-radius: var(--radius-full);
    background: var(--au-step-bg, var(--color-surface-2));
    color: var(--au-step-fg, var(--color-text));
    font-size: var(--text-md);
    white-space: nowrap;
    list-style: none;
    cursor: default;
  }
  summary.au-stage__chip { cursor: pointer; }
  summary.au-stage__chip::-webkit-details-marker { display: none; }
  .au-stage__journey { opacity: 0.8; }
  .au-stage__dots { display: inline-flex; gap: var(--space-1); margin-left: var(--space-1); }
  .au-stage__dot {
    width: 5px;
    height: 5px;
    border-radius: var(--radius-full);
    border: 1px solid currentColor;
    opacity: 0.6;
  }
  .au-stage__dot.is-reached { background: currentColor; opacity: 1; }
  .au-stage__menu {
    position: absolute;
    z-index: 300;
    top: calc(100% + var(--space-1));
    left: 0;
    min-width: 16rem;
    max-width: min(22rem, 90vw);
    margin: 0;
    padding: var(--space-1);
    list-style: none;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--elev-2);
  }
  .au-stage__option {
    display: grid;
    width: 100%;
    gap: var(--space-1);
    padding: var(--space-2);
    border: 0;
    border-radius: var(--radius-sm);
    background: none;
    color: var(--color-text);
    font: inherit;
    text-align: left;
    cursor: pointer;
  }
  .au-stage__option:hover,
  .au-stage__option:focus-visible { background: var(--color-surface-2); }
  .au-stage__option.is-current .au-stage__option-title { font-weight: 700; }
  .au-stage__option.is-current .au-stage__option-title::before { content: "✓ "; }
  .au-stage__option-title { font-size: var(--text-md); }
  .au-stage__option-meaning { font-size: var(--text-md); color: var(--color-text-muted); white-space: normal; }
  /* "Add a journey": a link to the journey's Configuration (METIS-pub#747). */
  .au-stage__add {
    border-top: 1px solid var(--color-border-light);
    color: var(--color-accent);
    font-size: var(--text-md);
    text-decoration: none;
  }

  /* The pencil after the chip, and the Journey + Step editor it opens
     (METIS-pub#750). Empty until opened; Cancel empties it. The wrapper is
     `display: contents`, so the chip, the pencil and the editor are items of
     the row the chip sits in (an outline line, the panel's Stage row), and
     the editor wraps onto a row of its own as wide as that container: never
     wider than the drawer or the screen. */
  .au-stage-wrap { display: contents; }
  .au-panel__stage { flex-wrap: wrap; }
  .au-stage-editor:empty { display: none; }
  /* On an outline line, after the whole line rather than between the chip and the name. */
  .au-line > .au-stage-editor { order: 99; }
  .au-stage-editor {
    display: block;
    flex: 1 1 100%;
    min-width: 0;
    max-width: 100%;
    padding: var(--space-3);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--elev-2);
    white-space: normal;
  }
  /* Two columns only where both fit; one in the drawer and on a phone. */
  .au-stage-editor .flow-edit-layout { grid-template-columns: repeat(auto-fit, minmax(min(16rem, 100%), 1fr)); }
  .au-stage-editor .journey-chip select { min-width: 0; }

  /* ── The side panel: the one shared side panel (crm/css/components/
     side-panel.css, METIS-pub#825 version B), from under the strip to the
     bottom of the window, beside the band and the page; a sheet on a phone.
     #au-drawer sits in the shell's panel (shell/base.html), which opens
     once it holds a panel (whose head is .side-panel__head); the Quests
     page's mission drawer is a .side-panel[data-sheet] of its own. ── */
  .au-drawer:not(:has(.side-panel__head)) { display: none; }
  .au-panel { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--space-3); padding: 0 var(--space-4) var(--space-4); }
  /* The shared head, across the panel's width: the name and ✕ on the first
     line; the empty ::before (its own line) puts where-it-is, Open full page
     and "…" on the next. */
  .au-panel__head { margin-inline: calc(var(--space-4) * -1); }
  .au-panel__head::before { content: ""; order: -1; flex-basis: 100%; height: 0; }
  .au-panel__title { order: -3; }
  .au-panel__close { order: -2; }
  .au-panel__where { flex: 1 1 auto; font-size: var(--text-md); color: var(--color-text-muted); position: relative; }
  .au-panel__where > summary,
  .au-panel__more > summary { cursor: pointer; list-style: none; }
  /* The "…" menu (METIS-pub#791): the "In <place> ▾" menu's list, opening
     leftwards because it sits at the row's right end. */
  .au-panel__more { position: relative; font-size: var(--text-md); }
  .au-panel__more > summary { padding: 0 var(--space-2); color: var(--color-text-muted); }
  .au-panel__more .au-panel__places { right: 0; white-space: nowrap; }
  /* "In … ▾" can list every quest a global editor may add to (METIS-pub#851):
     it scrolls rather than running off the page. */
  .au-panel__where .au-panel__places { max-height: calc(var(--space-16) * 6); overflow-y: auto; }
  .au-panel__places {
    position: absolute;
    z-index: 1;
    margin: var(--space-1) 0 0;
    padding: var(--space-1);
    list-style: none;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--elev-2);
  }
  .au-panel__place { display: block; width: 100%; padding: var(--space-2); border: 0; background: none; color: var(--color-text); font: inherit; text-align: left; cursor: pointer; }
  .au-panel__place:hover { background: var(--color-surface-2); }
  .au-panel__place.is-current { font-weight: 700; }
  .au-panel__place--danger { color: var(--color-danger); }
  .au-panel__stage { display: flex; align-items: center; gap: var(--space-3); }
  .au-panel__feed { min-height: 12rem; }
}
