/* The client page's controls (js/recipient-toolbar.js): search, sort, the
   grid or list switch, Select all / none / invert, and the type and
   folder chips. The sticky download bar is in recipient-bar.css. Loaded
   after recipient.css. Buttons, .search, .seg and .text are app.css's.

   Row one wraps to fit; every control in it is --rc-control tall:

     wide      (Search files)  Sort by [Folder v]  [Grid|List]  [Select..]
     narrower  (Search files)  Sort by [Folder v]  [Grid|List]
                                 [Select all|Select none|Invert]
     phone     (Search files)
               Sort by [Folder v]                  [Grid|List]
               [  Select all  |  Select none  |  Invert  ]

   Row two is the chips, a quiet label to the left of each group:

     Type     [v Photos 960] [  Videos 3] [  Documents 1]
     Folder   [v Erik 318]   [  No folder 646]

   A chip is two buttons in one rounded rectangle: the box chooses its
   files, the name shows only them. The box sits right against the name
   (a gap of 8px); the chip is as wide as its words, and a name too long
   for the line is cut with an ellipsis. */

:root {
  --rc-control: 40px;       /* search, sort, the switch, the choosing buttons */
  --rc-chip-border: 1px;
  --rc-chip-height: 34px;
  --rc-label-width: 3.5rem; /* the column "Type" and "Folder" sit in */
}

/* A finger needs the full touch size: 44px (the buttons inside a chip too,
   so the chip is 46 with its border). This follows the pointer, not the
   width: a narrow window with a mouse gets the small, calm size. */
@media (pointer: coarse) {
  :root {
    --rc-control: var(--control-l);
    --rc-chip-height: calc(var(--control-l) + 2 * var(--rc-chip-border));
  }
}

.rc-toolbar { margin-bottom: var(--space-5); }

/* --- row one: search, sort, view, choosing ---------------------------- */

.rc-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-3);
}

.rc-tools .search {
  flex: 1 1 12rem;
  min-width: 0;
  margin-left: 0;
  height: var(--rc-control);
  border-color: var(--field-line);   /* same edge as the sort field beside it */
}

/* Sort and view stay together: they wrap as one. */
.rc-arrange { display: flex; align-items: center; gap: var(--space-3); }
.rc-sort { display: flex; align-items: center; gap: var(--space-2); white-space: nowrap; }
.rc-sort .s { color: var(--mute); }
.rc-sort .text { width: 9.5rem; height: var(--rc-control); }

/* The choosing buttons wrap to a line of their own, at the right edge. */
.rc-selectors { margin-left: auto; }

/* The view switch and the choosing buttons are the same part: one outline,
   joined buttons, a hairline between. The outline is drawn on top (::after)
   so a chosen segment's tint cannot cover it, and the buttons keep the
   group's whole height. */
.rc-view,
.rc-selectors {
  position: relative;
  display: inline-flex;
  align-items: stretch;
  height: var(--rc-control);
  padding: 0;
  gap: 0;
  background: var(--surface);
  border-radius: var(--radius-control);
  overflow: hidden;
}
.rc-view::after,
.rc-selectors::after {
  content: "";
  position: absolute;
  inset: 0;
  border: 1px solid var(--line-strong);
  border-radius: inherit;
  pointer-events: none;
}

.rc-view button,
.rc-selectors .btn.quiet,
.rc-selectors .btn.quiet:hover {
  height: auto;
  padding: 0 var(--space-3);
  border: 0;
  border-radius: 0;
  background: none;
  font: 500 var(--text-m)/18px var(--font-sans);
}
.rc-view button + button,
.rc-selectors .btn + .btn { border-left: 1px solid var(--line2); }
.rc-view button { color: var(--ink2); }
.rc-view button:hover,
.rc-selectors .btn.quiet:hover { background: var(--hover); color: var(--ink); }
.rc-view button:active,
.rc-selectors .btn.quiet:active { background: var(--sunken); }
.rc-view button:focus-visible,
.rc-selectors .btn:focus-visible { outline-offset: -2px; }

/* The one showing: a tint and the accent's ink, not a raised box. */
/* app.css also rings it (box-shadow): that doubles the hairline beside it. */
.rc-view button[aria-pressed="true"] {
  background: var(--accent-tint);
  color: var(--accent-ink);
  box-shadow: none;
}

.rc-search-note { margin: var(--space-2) 0 0; color: var(--ink2); }
.rc-search-note .btn { vertical-align: baseline; }

/* Stands where the chips will be: "Finding..." or the way to load them. */
.rc-chip-note { margin: var(--space-3) 0 0; color: var(--ink2); }
.rc-chip-note .btn { vertical-align: baseline; }

/* --- row two: chips under a label per group ---------------------------- */

.rc-chip-rows { display: flex; flex-direction: column; gap: var(--space-2); margin-top: var(--space-4); }
.rc-chip-rows:not(:has(.rc-chip)) { display: none; }
.rc-chip-group { display: grid; grid-template-columns: var(--rc-label-width) minmax(0, 1fr); align-items: start; }
.rc-chip-group:has(.rc-chips:empty) { display: none; }

/* The label's line is as tall as a chip, so it centres on the first row. */
.rc-chip-label { font: 500 var(--text-m)/var(--rc-chip-height) var(--font-sans); color: var(--mute); }

/* Wraps under its label. A delivery of many folders stops at three rows
   and a half and scrolls, instead of pushing the photos off the screen.
   The half row is the sign that there are more: exactly three rows would
   hide the rest without a trace, and overlay scrollbars (macOS, every
   phone) show nothing. */
.rc-chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  max-height: calc(3.5 * var(--rc-chip-height) + 3 * var(--space-2));
  overflow-y: auto;
}
.rc-chips:empty { display: none; }

.rc-chip {
  display: inline-flex;
  align-items: stretch;
  max-width: 100%;
  height: var(--rc-chip-height);
  border: var(--rc-chip-border) solid var(--line-strong);
  border-radius: var(--radius-control);
  background: var(--surface);
  overflow: hidden;
  transition: border-color var(--dur-fast), background-color var(--dur-fast);
}
.rc-chip button {
  display: inline-flex;
  align-items: center;
  border: 0;
  background: none;
  color: var(--ink2);
  font: 500 var(--text-m)/18px var(--font-sans);
  cursor: pointer;
  transition: background-color var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
}
.rc-chip button:hover { background: var(--hover); color: var(--ink); }
.rc-chip button:active { background: var(--sunken); }
.rc-chip button:focus-visible { outline-offset: -2px; }

/* 4px after the box and 4px before the name: an 8px gap, a hit area each. */
.rc-chip-pick { padding: 0 var(--space-1) 0 var(--space-2h); }
.rc-chip-show { gap: var(--space-1h); padding: 0 var(--space-3) 0 var(--space-1); min-width: 0; }
.rc-chip-show .n { flex: none; color: var(--mute); font-weight: 400; font-variant-numeric: tabular-nums; }

/* A producer's folder name can be as long as a sentence. It is cut with an
   ellipsis on one line (the count stays whole, the button's title has the
   whole name); wrapped, it would grow taller than the chip and lose its
   first and last lines. */
.rc-chip-pick { flex: none; }
.rc-chip-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; unicode-bidi: isolate; } /* the producer's tag: see .tag in app.css */

/* The box: empty, a tick when all are chosen, a dash for some. */
.rc-chip-box {
  display: grid;
  place-items: center;
  width: 16px;
  height: 16px;
  border: 1.5px solid var(--field-line);
  border-radius: 4px; /* a literal: the box is 16px, where --radius-s would read round */
  color: var(--on-accent);
  transition: background-color var(--dur-fast), border-color var(--dur-fast);
}
.rc-chip-box svg { display: none; width: 12px; height: 12px; stroke-width: 2.8; }
.rc-chip-pick[aria-pressed="true"] .rc-chip-box,
.rc-chip-pick[aria-pressed="mixed"] .rc-chip-box { border-color: var(--accent); background: var(--accent); }
.rc-chip-pick[aria-pressed="true"] .rc-chip-box svg:first-child { display: block; animation: pop var(--dur) var(--ease-out); }
.rc-chip-pick[aria-pressed="mixed"] .rc-chip-box svg:last-child { display: block; }

/* The one showing now. */
.rc-chip:has(.rc-chip-show[aria-pressed="true"]) {
  border-color: var(--accent);
  background: var(--accent-tint);
}
.rc-chip-show[aria-pressed="true"],
.rc-chip-show[aria-pressed="true"] .n { color: var(--accent-ink); }

/* --- touch and phone --------------------------------------------------- */

@media (pointer: coarse) {
  /* The hit area is 44px wide; the box sits in it 4px right of centre, so
     the name starts 10px after the box, not 14. */
  .rc-chip-pick { min-width: var(--control-l); justify-content: center; padding: 0 0 0 var(--space-2); }
  .rc-chip-show { min-width: var(--control-l); padding-left: 0; }
  .rc-view button { min-width: var(--control-l); }
}

@media (max-width: 520px) {
  /* Search on a line of its own; the sort field takes what the switch
     leaves; the choosing buttons share the last line. */
  .rc-tools .search { flex-basis: 100%; }
  .rc-arrange { flex: 1 1 100%; }
  .rc-sort { flex: 1; min-width: 0; }
  .rc-sort .text { flex: 1; width: auto; min-width: 0; }
  .rc-selectors { flex: 1 1 100%; }
  .rc-selectors .btn { flex: 1; padding-inline: var(--space-2); }
}
