/* ==========================================================================
   Area: customer support tickets (views/account/support*.ejs, views/pages/ticket.ejs).
   Loaded after site.css (and area-account.css on account pages) via head({ styles }).
   Object UI: the customer's own messages sit right on lichen, customer care replies sit left on paper,
   Point2Point's own messages are a compact oat-deep slip. The newest reply waiting on the customer carries the
   sprout tape. No borders, no rules, no new colours. Martian Mono only for refs and times.
   ========================================================================== */

/* ---------- Guest page frame ---------- */
.tk-page { padding: var(--s-5) 0 var(--s-9); }
.tk-page .flashes { margin-bottom: var(--s-5); }

/* ---------- Page head ---------- */
.tk-head { margin-bottom: var(--s-6); max-width: 52rem; }
.tk-head__ref { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 18px; margin: 0 0 var(--s-3); }
.tk-head__ref .mono { font-size: var(--data-m); font-weight: 500; padding: 3px 10px 4px; border-radius: var(--r-s); background: var(--oat-deep); }
.tk-head__title { margin: 0; font-size: clamp(2rem, 3.6vw, 3rem); line-height: 1.02; font-weight: 600; letter-spacing: -.035em; overflow-wrap: anywhere; }
.tk-head__lede { margin: var(--s-3) 0 0; color: var(--fg-2); font-size: 1.125rem; line-height: 1.45; }

/* ---------- Layout: thread + details ---------- */
.tk-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 40px; align-items: start; }
.tk-main { display: grid; gap: var(--s-6); min-width: 0; }
.tk-side { display: grid; gap: var(--s-4); min-width: 0; position: sticky; top: var(--s-5); }
@media (max-width: 1180px) { .tk-layout { grid-template-columns: minmax(0, 1fr) 300px; gap: 28px; } }
@media (max-width: 960px) {
  .tk-layout { grid-template-columns: minmax(0, 1fr); }
  .tk-side { position: static; }
}
/* Under the thread on a tablet: the details and the urgent note two up */
@media (min-width: 641px) and (max-width: 960px) {
  .tk-side:has(> :nth-child(2)) { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: stretch; }
  .tk-side > .tk-help { display: grid; align-content: center; }
  /* Three cards or more read top down, and an odd last card takes the row */
  .tk-side:has(> :nth-child(3)) > .tk-help { align-content: start; }
  .tk-side > :last-child:nth-child(odd):not(:first-child) { grid-column: 1 / -1; }
  /* Two help cards side by side start level; one docket alone keeps its pairs across the row */
  .tk-side:has(> .tk-help + .tk-help) > .tk-help { align-content: start; }
  .tk-side > .docket:only-child .kv { grid-template-columns: repeat(2, minmax(96px, max-content) minmax(0, 1fr)); }
}

/* ---------- The conversation ---------- */
.tk-msgs { display: grid; gap: 14px; margin: 0; padding: 0; list-style: none; }
.tk-msg { display: flex; min-width: 0; scroll-margin-top: var(--s-6); }
.tk-msg--customer { justify-content: flex-end; }
.tk-msg--staff { justify-content: flex-start; }

.tk-card { position: relative; width: min(100%, 38rem); padding: 16px 20px 18px; border-radius: var(--r-xl); background: var(--slip); color: var(--ink); }
.tk-msg--staff .tk-card { border-top-left-radius: 6px; }
.tk-msg--customer .tk-card { background: var(--lichen); border-top-right-radius: 6px; }
.tk-card__head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 2px 14px; margin-bottom: 8px; }
.tk-card__who { margin: 0; display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 8px; }
.tk-card__who strong { font-weight: 600; }
.tk-card__who span { color: var(--ink-2); font-size: var(--small-size); }
.tk-card__time { color: var(--ink-2); font-size: var(--small-size); font-variant-numeric: tabular-nums; white-space: nowrap; }
.tk-card__body { white-space: pre-line; overflow-wrap: anywhere; line-height: 1.55; }

/* The newest reply the customer still has to answer: a small sprout label beside the name (round 3: no tape). */
.tk-card__who .tk-latest { align-self: center; padding: 1px 8px; border-radius: 6px; background: var(--sprout); color: var(--ink); font-size: var(--xs-size); font-weight: 600; }

/* Point2Point's own messages (the live chat summary, "Marked as resolved"): a compact oat-deep slip on the
   left, line breaks kept. "Topic: …" lines sit on a paper docket inside it as label/value pairs. */
.tk-msg--system { justify-content: flex-start; }
.tk-sys { width: min(100%, 34rem); padding: 14px 18px 16px; border-radius: var(--r-l); border-top-left-radius: 6px; background: var(--oat-deep); color: var(--ink); font-size: var(--small-size); line-height: var(--small-lh); }
.tk-sys__head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 2px 14px; margin-bottom: 6px; }
.tk-sys__who { margin: 0; font-weight: 600; color: var(--moss); }
.tk-sys__time { color: var(--ink-2); font-size: var(--xs-size); font-variant-numeric: tabular-nums; white-space: nowrap; }
.tk-sys__text { margin: 0; white-space: pre-line; overflow-wrap: anywhere; }
.tk-sys__text + .tk-sys__text { margin-top: 8px; }
.tk-sys__facts { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 5px 16px; margin: 12px 0 0; padding: 10px 14px 12px; border-radius: var(--r); background: var(--slip); }
.tk-sys__facts + .tk-sys__text { margin-top: 10px; }
.tk-sys__facts dt { color: var(--ink-2); }
.tk-sys__facts dd { margin: 0; overflow-wrap: anywhere; }
.tk-sys__facts dd.mono { font-size: var(--data-s); padding-top: 2px; }

/* ---------- Reply box ---------- */
.tk-reply__lede { margin: 0 0 var(--s-4); color: var(--fg-2); }
.tk-reply__go { margin-top: var(--s-4); }
.tk-reply__note { color: var(--fg-2); font-size: var(--small-size); }

/* ---------- Details side column ---------- */
.tk-details .panel__body { padding-top: 24px; }
.tk-kv { grid-template-columns: 76px minmax(0, 1fr); gap: 8px 12px; font-size: var(--small-size); }
.tk-kv dd.mono, .tk-kv dd .mono { font-size: .75rem; white-space: nowrap; }
.tk-kv dd.data { font-family: var(--f-mono); font-size: var(--data-s); }
@media (max-width: 640px) { .tk-kv { grid-template-columns: 76px minmax(0, 1fr); gap: 8px 12px; } .tk-kv dd { margin-bottom: 0; } }
.tk-resolve { padding-top: 4px; }
.tk-resolve__q { margin: 0 0 8px; font-weight: 600; }

.tk-help { padding: 20px 22px 22px; border-radius: var(--r-l); background: var(--oat-deep); font-size: var(--small-size); color: var(--ink-2); }
.tk-help > p { margin: 0; }
.tk-help > p + p { margin-top: 10px; }
.tk-help a[href^="tel:"] { white-space: nowrap; }
.tk-help__title { color: var(--ink); font-weight: 600; font-size: 1.0625rem; letter-spacing: -.01em; }
.tk-help__phone { font-variant-numeric: tabular-nums; white-space: nowrap; }
.tk-help .mono { font-size: var(--data-s); color: var(--ink); white-space: nowrap; }

/* "What happens next" */

/* ---------- List (/account/support) ---------- */
.tk-tabs { margin-bottom: var(--s-4); }
.tk-list { margin-bottom: var(--s-5); }
.tk-row { display: grid; grid-template-columns: 88px minmax(0, 1fr) 150px 150px; gap: 6px 20px; align-items: center; padding: 16px 20px 17px; }
.tk-row__ref { font-size: var(--data-s); color: var(--ink-2); }
.tk-row__main { display: grid; gap: 3px; min-width: 0; }
.tk-row__subject { font-weight: 600; overflow-wrap: anywhere; }
.tk-row__preview { color: var(--ink-2); font-size: var(--small-size); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tk-row__when { color: var(--ink-2); font-size: var(--small-size); font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
a.tk-row.is-current { background: var(--lichen); }
/* Narrower: the last update moves under the status, so the slip stays two lines tall */
@media (max-width: 1180px) {
  .tk-row { grid-template-columns: 88px minmax(0, 1fr) 150px; row-gap: 2px; }
  .tk-row__ref, .tk-row__main { grid-row: 1 / span 2; }
  .tk-row__status { grid-column: 3; grid-row: 1; align-self: end; }
  .tk-row__when { grid-column: 3; grid-row: 2; align-self: start; text-align: left; }
}
@media (max-width: 640px) {
  .tk-row { grid-template-columns: minmax(0, 1fr) auto; gap: 6px 12px; padding: 14px 16px 15px; }
  .tk-row__ref { grid-column: 1; grid-row: 1; }
  .tk-row__status { grid-column: 2; grid-row: 1; }
  .tk-row__main { grid-column: 1 / -1; grid-row: 2; }
  .tk-row__preview { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
  .tk-row__when { grid-column: 1 / -1; grid-row: 3; }
}
.tk-aside-note { max-width: 40rem; margin: var(--s-6) 0 0; color: var(--fg-2); font-size: var(--small-size); }

/* ---------- New ticket form ---------- */
.tk-form .btnrow { margin-top: 16px; }
.tk-form__hint { margin: 4px 0 0; }
.tk-form__hint + .field { margin-top: 12px; }
/* Claims: the file boxes run the width of the fields around them */
.tk-page .form-compact .upload__box { max-width: none; }
/* The details beside a claim line up with the help cards; short pairs stay on one line on a phone */
.tk-side > .docket { padding-inline: 22px; }
@media (max-width: 640px) {
  .tk-side > .docket .kv { grid-template-columns: minmax(96px, max-content) minmax(0, 1fr); gap: 8px var(--s-4); }
  .tk-side > .docket .kv dd { margin-bottom: 0; }
}
.tk-side__acts { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 4px var(--s-4); }
.tk-refuse { max-width: 40rem; }
/* A parcel number in a page head stays in one piece */
.tk-page :is(.lede, .tk-head__lede) .mono { white-space: nowrap; }
@media (max-width: 360px) { .tk-page :is(.lede, .tk-head__lede) .mono { font-size: 1rem; } }
/* Three buttons on a phone: the primary takes the row and the other two share the next */
@media (max-width: 640px) {
  .tk-btns { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-2); }
  .tk-btns > .btn--primary:first-child:not(:nth-last-child(2)) { grid-column: 1 / -1; }
  .tk-btns > .btn { padding-inline: 12px; }
}

@media (max-width: 640px) {
  .tk-head { margin-bottom: var(--s-5); }
  .tk-card { padding: 14px 16px 16px; }
  .tk-sys { padding: 12px 14px 14px; }
  .tk-sys__facts { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .tk-sys__facts dd + dt { margin-top: 8px; }
  .tk-msg--customer .tk-card, .tk-msg--staff .tk-card { width: min(100%, 92%); }
}

/* Live ticket page (area-account.js): a reply that arrived while the page was open, or a status change by customer care */
/* It sits at the end of the conversation and sticks to the bottom of the screen while the thread is in view, clear
   of the help bubble in the corner. */
.tk-livenote { position: sticky; bottom: 12px; z-index: 5; margin: 10px 0 0; max-width: calc(100% - 72px); width: fit-content; }
.tk-livenote[hidden] { display: none; }
.tk-livenote__go { display: inline-flex; align-items: center; gap: 8px; min-height: 40px; padding: 8px 14px; border: 0; border-radius: var(--r);
  background: var(--moss-deep); color: var(--on-dark); font: inherit; font-size: var(--small-size); font-weight: 600; text-align: left; cursor: pointer;
  box-shadow: 0 12px 22px -14px rgba(28, 35, 30, .6); }
.tk-livenote__go::after { content: ""; flex: none; width: 14px; height: 14px; background: currentColor;
  -webkit-mask: var(--chev) center / contain no-repeat; mask: var(--chev) center / contain no-repeat; }
.tk-livenote__go:hover { background: var(--moss); }
.tk-livenote__go:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
@media (max-width: 960px), (pointer: coarse) { .tk-livenote__go { min-height: 44px; } }
.tk-msg.is-new .tk-card, .tk-msg.is-new .tk-sys { animation: tk-in .6s ease-out; }
@keyframes tk-in { from { box-shadow: 0 0 0 3px var(--sprout); } }
@media (prefers-reduced-motion: reduce) { .tk-msg.is-new .tk-card, .tk-msg.is-new .tk-sys { animation: none; } }
