/* The Tickets tab of the operator's area (js/admin-tickets.js,
   js/admin-ticket-sheet.js, js/admin-ticket-thread.js,
   js/admin-ticket-reply.js, js/admin-ticket-moves.js,
   js/admin-ticket-context.js). Loaded by index.html after admin.css. The
   table is app.css's shared one (.list, .list-head, .list-row, .cell-num,
   .tag[data-tone]); this file adds the column widths, how a row folds into
   a card, the row's one click target, and the sheet's facts, what we know
   about the sender, conversation and reply box. Colours, spaces and type
   sizes are tokens from app.css's :root or from the block below.

   A ticket row, wide:
     [ #41 ][ category ][ urgency ][ subject ......... ][ since ][ state ]
   and folded into a card, when the table gets less than about 840px:
     [ subject, then the summary line                                    ]
     [ #41   Billing   High   Escalated   1 hr ago                       ]

   The whole row opens the ticket, but only the subject is a button: its
   ::after covers the row, so a keyboard has one stop per ticket and a
   pointer can press anywhere on it. */

:root {
  --ticket-column-ref: 64px;
  --ticket-column-category: 128px;   /* "Feature request" is the widest */
  --ticket-column-urgency: 96px;
  --ticket-column-since: 124px;      /* "Yesterday, 14:05" is the widest */
  --ticket-column-state: 108px;
}

/* --- the search ---------------------------------------------------- */

/* The box is the users tab's (admin.css `.users-toolbar .search`, one rule for
   both toolbars); the category select keeps its own width, and on a phone
   takes the full width like the box. The hint beside the box ("Type at least
   2 characters.") takes no room while it is empty. */
.tickets-toolbar .hint { margin-top: 0; }
.tickets-toolbar .hint:empty { display: none; }
@media (max-width: 640px) {
  .tickets-toolbar select { width: 100%; }
}

/* --- the list ----------------------------------------------------- */

/* The table asks how wide it is, not how wide the window is (same reason as
   the users table in admin.css). */
.ticket-body { container: tickets / inline-size; }

.ticket-list {
  margin: 0;
  padding: 0;
  list-style: none;
}
/* On the rows themselves, not on the list: app.css sets --cols on any row
   with three or more cells (.list-row:has(> :nth-child(3))), which beats
   a value inherited from the list. */
.ticket-list .list-head,
.ticket-list .list-row {
  --cols:
    var(--ticket-column-ref) var(--ticket-column-category) var(--ticket-column-urgency)
    minmax(0, 1fr)
    var(--ticket-column-since) var(--ticket-column-state);
}
.ticket-row { position: relative; }
.ticket-row:hover { background: var(--hover); }

.ticket-open {
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.ticket-open::after { content: ""; position: absolute; inset: 0; }
/* The ring is drawn inside the row: the list clips (overflow: hidden). */
.ticket-open:focus-visible { outline: none; }
.ticket-open:focus-visible::after { outline: 2px solid var(--focus); outline-offset: -2px; }
.ticket-row .who .t { max-width: 100%; }
/* A word the table does not know is drawn as the API spelled it
   (js/admin-ticket-words.js); a long one must not run over the subject
   beside it. */
.ticket-row .c-category,
.ticket-row .c-urgency { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ticket-row .c-urgency .tag { max-width: 100%; overflow: hidden; }

.ticket-foot {
  margin-top: var(--space-3);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-3);
}

/* A move's reason (the mover's own sentence) under its words in the sheet. */
.ticket-move-reason { display: block; overflow-wrap: anywhere; }

/* 840px: below it the six columns leave the subject under about 200px.
   (A container query cannot read a custom property, so it is a literal.) */
@container tickets (max-width: 840px) {
  .ticket-list .list-head { display: none; }
  .ticket-list .list-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2) var(--space-3);
  }
  .ticket-row .who { flex: 1 0 100%; order: -1; }
  .ticket-row .who .t { white-space: normal; overflow-wrap: anywhere; }
  .ticket-row .who .s { overflow-wrap: anywhere; white-space: normal; }
  .ticket-row .cell-num { text-align: left; }
}

/* --- the sheet ---------------------------------------------------- */

#ticket-sheet .body > * + *,
#ticket-sheet [data-part=ticket-moves-section] > * + * { margin-top: var(--space-4); }
#ticket-sheet [data-part=ticket-moves-section]:empty { display: none; }
#ticket-sheet h3 {
  margin-bottom: calc(-1 * var(--space-2));
  font: 500 var(--text-m)/18px var(--font-sans);
  color: var(--ink2);
}
#ticket-sheet .sheet-sub { margin-top: var(--space-1); }

.ticket-facts {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: var(--space-2) var(--space-4);
  margin: 0;
}
.ticket-facts dt { color: var(--mute); font-size: var(--text-m); line-height: 20px; }
.ticket-facts dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

/* What we know about the sender: three short parts, each a heading over a
   line or a list. A title or a name is the customer's or a producer's own
   words, so it wraps rather than widen the sheet. */
.ticket-context { justify-self: stretch; display: grid; gap: var(--space-4); }
.ticket-context-part { display: grid; gap: var(--space-2); min-width: 0; }
.ticket-context-part h4 { font-size: var(--text-m); margin: 0; }
.ticket-context-part p { margin: 0; }
.ticket-context-list { margin: 0; padding: 0; list-style: none; display: grid; gap: var(--space-2); }
.ticket-context-list li { overflow-wrap: anywhere; }

.ticket-thread-area { display: grid; grid-template-columns: minmax(0, 1fr); justify-items: start; gap: var(--space-3); }
.ticket-thread-problem,
.ticket-thread-area > [data-part=ticket-reply] { justify-self: stretch; }

/* The conversation: one entry per message and per reply of ours, oldest
   first. Our replies are set in from the left edge so the two voices read
   apart without a colour for either. */
.ticket-thread {
  justify-self: stretch;
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: var(--space-4);
}
.ticket-entry { display: grid; gap: var(--space-2); min-width: 0; }
.ticket-entry-head { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-3); }
.ticket-entry-reply { padding-left: var(--space-3); border-left: 2px solid var(--line); }
.ticket-reply-subject,
.ticket-reply-state { margin: 0; overflow-wrap: anywhere; }
.ticket-reply-again { display: grid; justify-items: start; gap: var(--space-2); }
.ticket-reply-again:empty { display: none; }
.ticket-reply-again .err { margin: 0; }

/* The reply box. The close labels sit in a native <details>: closed until
   the operator opens it to "Send and close". */
#ticket-sheet [data-part=ticket-reply] h3 { margin: var(--space-4) 0 var(--space-3); }
#ticket-reply-form .ticket-facts { margin-bottom: var(--space-3); }
#ticket-reply-form .callout { margin-bottom: var(--space-3); }
/* The suggested reply sits above the box. Its text is the box's own look
   (.ticket-mail); its button may be as wide as a phone and wrap like Send. */
.ticket-draft { display: grid; justify-items: start; gap: var(--space-2); margin-bottom: var(--space-3); }
.ticket-draft > * { justify-self: stretch; margin: 0; }
.ticket-draft h4 { font-size: var(--text-m); }
.ticket-draft .btn {
  justify-self: start;
  max-width: 100%;
  height: auto;
  min-height: var(--btn-h);
  padding-block: var(--space-2);
  white-space: normal;
  overflow-wrap: anywhere;
  text-align: center;
}
.ticket-reply-close { margin-top: var(--space-3); }
.ticket-reply-close summary { cursor: pointer; color: var(--ink2); font-size: var(--text-m); }
/* A long address wraps on the button's face rather than being cut short. */
.ticket-reply-actions .btn {
  max-width: 100%;
  height: auto;
  min-height: var(--btn-h);
  padding-block: var(--space-2);
  white-space: normal;
  overflow-wrap: anywhere;
  text-align: center;
}
.ticket-reply-actions {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-top: var(--space-4);
}

/* A stranger's words, or a suggested reply's, exactly as written: plain text,
   wrapped, never markup. */
.ticket-mail {
  justify-self: stretch;
  margin: 0;
  padding: var(--space-3);
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  background: var(--sunken);
  color: var(--ink);
  font: 400 var(--text-m)/18px var(--font-mono);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.ticket-moves { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.ticket-moves form,
.ticket-moves > .err { flex: 1 0 100%; }
.ticket-moves > .err { margin: 0; }
.ticket-move-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  margin-top: var(--space-4);
}

@media (max-width: 820px) {
  .ticket-moves .btn { flex: 1 0 100%; }
  .ticket-move-actions .btn { flex: 1; }
  .ticket-reply-actions .btn { flex: 1 0 100%; }
}
