/* --- the composer: one card, or several from lines of text --------------- */

.row.composer > .fold-body {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  /* No gap from `.row`: the head and the forms are spaced by the forms' own
     margin, which folds away with them. */
  row-gap: 0;
}

.composer-head {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 16px;
  /* The select bar's height, less its padding: put away, the composer is a
     bar of the same size as the one under it. */
  min-height: 44px;
}

/* Put away, the composer takes the select bar's padding too. Not while the
   whole thing is folded out of edit mode, which needs no padding at all. */
.row.composer.closed:not(.folded) {
  padding-block: 10px;
}

/* The title doubles as the fold switch: a button with no button box, and a
   chevron that points down when open, right when put away. */
button.composer-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-size: 15px;
  font-weight: 600;
}

button.composer-toggle:hover:not(:disabled) {
  background: transparent;
  color: var(--accent-text);
}

button.composer-toggle .chevron {
  transform: rotate(-90deg);
  transition: transform 180ms ease;
}

button.composer-toggle.open .chevron {
  transform: none;
}

.composer-modes.off {
  visibility: hidden;
}

.composer-title {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  font-size: 15px;
  font-weight: 600;
}

/* The bulk editor has no fold of its own inside: its form follows the head
   at the distance the composer's forms do. */
.bulk-editor .composer-many {
  margin-top: 14px;
}

/* The select bar's edit button, lit while the editor it opens is open. */
.select-actions button.icon-btn.active {
  color: var(--accent-text);
}

/* The forms fold like the whole composer does (`.fold`), only smaller;
   put away, they give back their margin too. */
.composer-body.open {
  margin-top: 14px;
}

@media (prefers-reduced-motion: reduce) {
  .composer-body,
  button.composer-toggle .chevron {
    transition: none;
  }
}

.composer-one {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
  align-items: center;
  gap: 16px;
}

.composer-many {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 10px 16px;
}

.composer-many textarea.composer-text {
  min-height: 104px;
  font-family: inherit;
}

.composer-side {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
}

.composer-sep {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--muted);
}

.composer-sep input.sep-input {
  width: 4.5em;
  min-height: 36px;
  padding: 4px 10px;
  text-align: center;
  font-family: var(--font-mono, monospace);
}

.composer-hint {
  grid-column: 1 / -1;
  margin: 0;
  font-size: 13px;
}

/* --- choosing cards --------------------------------------------------- */

.select-bar {
  padding: 10px 20px;
  border-bottom: var(--border-w) solid var(--line);
}

.select-bar > .fold-body {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 16px;
}

.select-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* "Select all" at the far end, its checkbox cell right above the cards'. */
.select-all {
  display: inline-flex;
  align-items: center;
  margin-left: auto;
  font-size: 14px;
  color: var(--muted);
  cursor: pointer;
}

.card-select input {
  width: 18px;
  height: 18px;
  min-height: 0;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

/* A row's checkbox, in a tap-target-sized cell beside its buttons. */
.card-select {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  cursor: pointer;
}

.row.card-cols.selected {
  background: color-mix(in srgb, var(--accent) 7%, var(--surface));
}

/* Outside edit mode the cards are read-only. Their buttons, checkboxes and
   grips are hidden but keep their room, so entering edit mode moves nothing;
   hidden, they can be neither clicked nor tabbed to. */
.cards-panel:not(.deck-editing) .card-cols .row-actions,
.cards-panel:not(.deck-editing) .row-grip {
  visibility: hidden;
}

/* Column tracks, shared by a panel's head and its rows. */
.deck-cols {
  grid-template-columns: minmax(0, 1fr) 190px 110px 120px 100px;
}

.card-cols {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 140px;
}

/* A card row is its two sides beside a 44px column of buttons: everything
   centres on the row, not on its top edge — the text included, which would
   otherwise sit above the icons. */
.row.card-cols {
  align-items: center;
}

/* The buttons already give the row its height; a minimum here would only
   leave short text at the top of a taller box. */
.row.card-cols .card-side {
  min-height: 0;
  padding-top: 0;
}

.row.card-cols > .row-grip {
  top: 0;
  bottom: 0;
  height: auto;
}

/* An in-place row form has to hand its fields straight to the row's grid, or
   the whole form would sit in the first column. */
.row-grid {
  display: contents;
}

.row-main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.row-title {
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: 600;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

a.row-title:hover {
  color: var(--accent-text);
  text-decoration: none;
}

.row-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.row-when {
  font-size: 14px;
  color: var(--muted);
  line-height: 34px;
}

/* A card's two sides: display face in front, body face behind. */
.card-side {
  min-width: 0;
  min-height: 34px;
  padding-top: 4px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

.card-side.front {
  font-family: var(--font-display);
  font-size: 17px;
  color: var(--ink);
}

.card-side.back {
  font-size: 16px;
  color: var(--ink-soft);
}

.access {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  line-height: 34px;
  color: var(--muted);
}

/* Link-only: grey while the link has reached nobody, bright once it has. */
.access.unlisted {
  color: var(--muted);
}

.access.unlisted.opened {
  color: var(--accent-text);
  font-weight: 500;
}

.share-pop-note.share-warning {
  color: var(--danger);
}

.access.public {
  color: var(--accent-text);
}

/* --- drag & drop reordering -------------------------------------------- */

.dragging {
  opacity: 0.4;
}

/* Where the dragged item will land: a line on the side of the target it
   goes to — above when moving up, below when moving down. */
.drop-after::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 2px;
  background: var(--accent);
}

.drop-before::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: -1px;
  height: 2px;
  background: var(--accent);
}

.grip {
  display: inline-flex;
  align-items: center;
  color: var(--muted);
}

/* Every drag starts on a grip, which takes the whole gesture: no page scroll
   (touch), no text selection (mouse). */
.grip,
.row-grip {
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: grab;
}

.grip:active,
.row-grip:active {
  cursor: grabbing;
}

.topic-card .grip {
  padding: 0 6px;
}

/* A row's drag handle, in the left padding and out of the flow, so rows lay
   out the same with or without it. Faint until the row is hovered; on touch
   screens, with no hover, it simply stays faint. Top and height match the
   row's padding and first line, centring it on the title. */
.row > .row-grip {
  position: absolute;
  top: 16px;
  left: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 34px;
  color: var(--muted);
  opacity: 0.45;
  transition: opacity 120ms ease-out;
}

.row:hover > .row-grip,
.row.dragging > .row-grip {
  opacity: 1;
}

/* A finger needs more than the icon to hit: the whole left gutter, as tall
   as a tap target, centred on the same first line. It stays visible, since
   there is no hover to reveal it. */
@media (pointer: coarse) {
  .row > .row-grip {
    top: 11px;
    height: 44px;
    opacity: 0.7;
  }
}
