/* Messages, notifications and team (feat/chat). Tokens only (tokens.css). Desktop: conversations | thread | about;
   phone: the list or the thread, full width, with the thread header and the reply box kept in view. */
.chat-layout { display: grid; grid-template-columns: 19rem minmax(0, 1fr) 14rem; gap: var(--card-gap); align-items: start; }
.chat-layout-list { grid-template-columns: 19rem minmax(0, 1fr); align-items: stretch; }
.chat-layout-list > .inbox-pane, .chat-layout-list > .thread-pane { height: calc(100vh - 11rem); max-height: none; }
/* the thread page has no page title: the conversation uses the whole height */
.chat-layout:not(.chat-layout-list) > .inbox-pane, .chat-layout:not(.chat-layout-list) > .thread-pane { height: calc(100vh - 4rem); max-height: none; }
/* whole rows and chips are links: no link underline or link colour inside them */
a.inbox-row, a.inbox-row *, a.chip, a.notify-row, a.notify-row *, a.menu-item, a.msg-att-file { text-decoration: none !important; }
a.inbox-row, a.inbox-row .inbox-name, a.chip, a.notify-row, a.notify-row strong, a.menu-item, a.msg-att-file { color: var(--color-text) !important; }
a.chip.is-on { color: var(--color-surface) !important; }
a.inbox-row .inbox-job, a.inbox-row .inbox-last, a.inbox-row .inbox-time, a.notify-row .meta { color: var(--color-text-muted) !important; }
a.inbox-row.is-unread .inbox-last { color: var(--color-text) !important; }
.inbox-side { display: grid; justify-items: end; gap: var(--space-1); }
.mini-avatar { display: inline-flex; align-items: center; justify-content: center; width: 1.5rem; height: 1.5rem; border-radius: var(--radius-full); background: var(--color-surface-2); border: 1px solid var(--color-line-strong); color: var(--color-text); font-size: 0.65rem; font-weight: var(--weight-semibold); }
.mini-avatar.is-me { background: var(--pill-brand-bg); color: var(--pill-brand-text); border-color: transparent; }
.inbox-pane, .thread-pane, .thread-side { background: var(--color-surface); border: 1px solid var(--color-line); border-radius: var(--radius-lg); }
.inbox-pane { display: flex; flex-direction: column; max-height: calc(100vh - 11rem); min-height: 24rem; overflow: hidden; }
.inbox-filters { padding: var(--space-3); border-bottom: 1px solid var(--color-line); display: grid; gap: var(--space-2); }
.inbox-filters select { width: 100%; }
.inbox-filters .chips { flex-wrap: nowrap; }
.inbox-filters .chip { text-decoration: none; padding: var(--space-1) var(--space-3); min-height: 32px; display: inline-flex; align-items: center; max-width: none; }
.chip.is-on { background: var(--color-text); color: var(--color-surface); font-weight: var(--weight-semibold); }
.inbox-list { list-style: none; margin: 0; padding: 0 0 var(--space-2); overflow-y: auto; }
.inbox-row { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: var(--space-3); align-items: start; min-height: 4.75rem; padding: var(--space-3) var(--space-4); color: var(--color-text); text-decoration: none; border-bottom: 1px solid var(--color-line); }
.inbox-row:hover { background: var(--color-surface-2); text-decoration: none; }
.inbox-row[aria-current="page"] { background: var(--color-surface-2); box-shadow: inset 4px 0 0 var(--color-primary); }
.inbox-text { display: grid; gap: 1px; min-width: 0; }
.inbox-top { display: flex; justify-content: space-between; gap: var(--space-2); }
.inbox-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: var(--weight-semibold); }
.inbox-time { font-size: var(--text-xs); color: var(--color-text-muted); white-space: nowrap; }
.inbox-job, .inbox-last { font-size: var(--text-sm); color: var(--color-text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.inbox-row.is-unread .inbox-last { color: var(--color-text); font-weight: var(--weight-semibold); }
.inbox-assigned { color: var(--color-text); }
.inbox-empty { padding: var(--space-4); }
.badge-count, .nav-badge { display: inline-flex; align-items: center; justify-content: center; min-width: 1.35rem; height: 1.35rem; padding: 0 0.35rem; border-radius: var(--radius-full); background: var(--color-primary); color: var(--color-accent-text); font-size: var(--text-xs); font-weight: var(--weight-semibold); line-height: 1; }
.badge-count { margin-top: 0; }
.nav-badge[hidden] { display: none; }
.side-link .nav-badge { margin-left: auto; }
.tab .nav-badge { position: absolute; top: 4px; left: calc(50% + 6px); z-index: 2; }
.top-bell { position: relative; }
.top-bell[aria-current="page"] { background: var(--color-surface-2); }
.top-bell .nav-badge { position: absolute; top: 4px; right: 2px; min-width: 1.1rem; height: 1.1rem; font-size: 0.65rem; }

.thread-pane { display: flex; flex-direction: column; height: calc(100vh - 11rem); min-height: 28rem; overflow: hidden; }
.thread-pane-empty { justify-content: center; }
.thread-head { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--color-line); background: var(--color-surface); }
.thread-title { min-width: 0; flex: 1; }
.thread-title .meta > span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.thread-title h1 { font-size: var(--text-lg); line-height: var(--lh-lg); margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread-title .meta { display: flex; gap: var(--space-2); align-items: center; flex-wrap: nowrap; margin: 0; }
.assign-form { display: flex; align-items: center; gap: var(--space-2); font-size: var(--text-sm); }
.assign-form label { color: var(--color-text-muted); white-space: nowrap; font-size: var(--text-xs); }
.assign-form { flex: none; }
.assign-form select { max-width: 13rem; }
.assign-form select { max-width: 11rem; min-height: 36px; font-size: var(--text-sm); }
.thread-scroll { flex: 1; overflow-y: auto; padding: var(--space-5) var(--space-4) var(--space-4); background: var(--color-canvas); }
.thread-more { text-align: center; font-size: var(--text-sm); margin: 0 0 var(--space-3); }
.thread-none { text-align: center; }
.chat-thread { gap: var(--space-3); margin: 0; }
.chat-thread .msg { max-width: min(36rem, 82%); padding: var(--space-2) var(--space-3); border: 1px solid var(--color-line); background: var(--color-surface); border-radius: var(--radius-lg); border-bottom-left-radius: var(--radius-sm); }
.chat-thread .msg-out { background: color-mix(in srgb, var(--color-primary) 16%, var(--color-surface)); border-color: color-mix(in srgb, var(--color-primary) 35%, var(--color-surface)); border-radius: var(--radius-lg); border-bottom-right-radius: var(--radius-sm); }
.msg-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 var(--space-2); font-size: var(--text-xs); color: var(--color-text-muted); }
.msg-head strong { color: var(--color-text); font-weight: var(--weight-semibold); }
.chat-thread .msg-out .msg-head, .chat-thread .msg-out .msg-del { display: none; margin: 0; }
.msg-out:hover .msg-del, .msg-out:focus-within .msg-del { display: block; text-align: right; }
.link-btn { background: none; border: 0; padding: 0; font: inherit; font-size: var(--text-xs); color: var(--color-text-muted); text-decoration: underline; cursor: pointer; }
.msg-seen { color: color-mix(in srgb, var(--color-text) 78%, transparent); }
.msg-time { margin-left: auto; white-space: nowrap; }
.msg-tag { flex-basis: 100%; order: 3; font-weight: var(--weight-semibold); color: var(--color-text); }
.hidden-contact { display: inline; padding: 1px var(--space-2); vertical-align: baseline; border-radius: var(--radius-full); background: var(--color-surface-2); border: 1px dashed var(--color-line-strong); color: var(--color-text); font-size: var(--text-xs); font-style: italic; line-height: 1.3; white-space: nowrap; }
.chat-thread .day-sep { align-self: center; list-style: none; font-size: var(--text-xs); color: var(--color-text-muted); font-weight: var(--weight-semibold); padding: var(--space-1) var(--space-3); background: var(--color-surface); border: 1px solid var(--color-line); border-radius: var(--radius-full); }
.chat-thread .msg-body { margin: var(--space-1) 0 0; white-space: pre-line; overflow-wrap: anywhere; }
.msg-att { display: block; margin-top: var(--space-2); }
.msg-att-img img { display: block; max-width: 100%; max-height: 16rem; border-radius: var(--radius-md); border: 1px solid var(--color-line); }
.msg-att-file { display: inline-flex; align-items: center; gap: var(--space-2); padding: var(--space-2) var(--space-3); border: 1px solid var(--color-line-strong); border-radius: var(--radius-md); background: var(--color-surface); font-size: var(--text-sm); }
.msg-att-file .i { width: 18px; height: 18px; }
.msg-del { display: none; margin: 0; }
.msg-out:hover .msg-del, .msg-out:focus-within .msg-del { display: block; text-align: right; }
.link-btn { background: none; border: 0; padding: 0; font: inherit; font-size: var(--text-xs); color: var(--color-text-muted); text-decoration: underline; cursor: pointer; }
.msg-seen { display: block; text-align: right; font-size: var(--text-xs); color: var(--color-text-muted); margin-top: 2px; }
.mask-note { display: flex; gap: var(--space-2); align-items: flex-start; margin: var(--space-2) 0 0; padding: var(--space-2) var(--space-3); border-radius: var(--radius-md); background: var(--color-surface); border: 1px dashed var(--color-line-strong); font-size: var(--text-xs); line-height: var(--lh-xs); color: var(--color-text); }
.mask-note .i { width: 16px; height: 16px; flex: none; margin-top: 1px; color: var(--color-text-muted); }
.mask-note[hidden] { display: none; }
.composer .mask-note, form[data-mask-check] .mask-note { background: var(--pill-wait-bg); color: var(--pill-wait-text); border: 0; font-size: var(--text-sm); line-height: var(--lh-sm); order: -1; }
.composer .mask-note .i, form[data-mask-check] .mask-note .i { color: currentColor; margin-top: 4px; }
.msg-shift { margin-top: var(--space-2); padding: var(--space-3); border-radius: var(--radius-md); background: var(--color-surface); border: 1px solid var(--color-line); }
.msg-shift-title { display: flex; gap: var(--space-2); align-items: center; margin: 0; }
.msg-shift-title .i { width: 18px; height: 18px; }
.msg-shift .meta { margin: var(--space-1) 0 0; }
.msg-shift-ask { margin: var(--space-2) 0 0; font-size: var(--text-sm); }
.msg-shift-actions { margin-top: var(--space-2); gap: var(--space-2); }
.side-shifts .pill { justify-self: start; margin-top: 2px; }
.msg-shift-state { margin: var(--space-2) 0 0; }
.msg-shift-state:empty { display: none; }
.thread-alert { margin: 0; border-radius: 0; border-left-width: 4px; border-right: 0; }

.composer { border-top: 1px solid var(--color-line); padding: var(--space-3) var(--space-4); display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--space-2); background: var(--color-surface); position: relative; }
.composer textarea { width: 100%; box-sizing: border-box; resize: none; min-height: 3.25rem; max-height: 12rem; }
.composer-row { display: flex; align-items: center; gap: var(--space-2); }
.composer .spacer { flex: 1; }
.attach-btn { position: relative; overflow: hidden; cursor: pointer; }
.attach-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.attach-btn .i { width: 18px; height: 18px; }
.attach-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 12rem; }
.quick-replies { position: relative; justify-self: start; }
.quick-replies .menu { left: 0; right: auto; top: auto; bottom: calc(100% + 4px); min-width: 16rem; max-height: 18rem; overflow-y: auto; }
.quick-replies .menu-item { white-space: normal; text-decoration: none; color: var(--color-text); }

.thread-side { padding: var(--space-4); }
.thread-side-sum { display: none; }
.thread-side-body { display: grid; gap: var(--space-3); }
.thread-side .mini-title { margin: 0; }
.side-shifts { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--space-2); }
.side-shifts li { display: grid; gap: 2px; padding-bottom: var(--space-2); border-bottom: 1px solid var(--color-line); }
.side-shifts li:last-child { border-bottom: 0; }
.side-safe { display: flex; gap: var(--space-2); align-items: flex-start; margin: 0; }
.side-safe .i { width: 16px; height: 16px; flex: none; margin-top: 3px; color: var(--color-success); }

/* team page */
.team-list li { gap: var(--space-3); }
.person-text { display: grid; min-width: 0; }
.person-text .meta { overflow: hidden; text-overflow: ellipsis; }
.team-actions { gap: var(--space-2); flex-wrap: nowrap; align-items: center; }
.team-actions .inline-setting { display: flex; gap: var(--space-2); align-items: center; }
.team-actions select, .team-actions .btn-sm { min-height: 36px; }
.team-list + .role-key { border-top: 0; padding-top: var(--space-1); margin-top: var(--space-3); }
.more-menu { position: relative; }
.more-menu summary { list-style: none; }
.more-menu summary::-webkit-details-marker { display: none; }
.more-menu .menu { min-width: 12rem; }
.more-menu form { margin: 0; display: grid; }
.menu-danger { color: var(--color-danger); }
.role-key { display: grid; gap: var(--space-2); margin: var(--space-4) 0 0; padding-top: var(--space-4); border-top: 1px solid var(--color-line); font-size: var(--text-sm); }
.role-key div { display: grid; grid-template-columns: 6rem 1fr; gap: var(--space-3); }
.role-key dt { font-weight: var(--weight-semibold); }
.role-key dd { margin: 0; color: var(--color-text-muted); }
.invite-row { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) auto; }
.activity-list li { font-size: var(--text-sm); }
.seg-wrap { flex-wrap: wrap; }
.broadcast-list li { display: block; }
.broadcast-list li > span { white-space: pre-line; }
.qr-list li > span { min-width: 0; }
.qr-list .meta.block { white-space: pre-line; }

/* notifications */
.notify-chips { margin-bottom: var(--space-3); }
.notify-chips .chip { text-decoration: none; padding: var(--space-1) var(--space-3); min-height: 32px; display: inline-flex; align-items: center; }
.notify-list { display: grid; gap: var(--space-2); }
.notify-row { display: flex; gap: var(--space-3); align-items: flex-start; color: var(--color-text); text-decoration: none; padding: var(--space-3) var(--space-4); }
.notify-row:hover { text-decoration: none; border-color: var(--color-line-strong); }
.notify-row.is-unread { box-shadow: inset 4px 0 0 var(--color-primary); }
.notify-row.is-unread strong { font-weight: var(--weight-bold); }
.notify-text { display: grid; gap: 2px; min-width: 0; }
.notify-body { overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; white-space: pre-line; }
.notify-icon .i { width: 22px; height: 22px; color: var(--color-text-muted); }

@media (max-width: 1180px) {
  .chat-layout { grid-template-columns: 18rem minmax(0, 1fr); }
  .chat-layout .thread-side { grid-column: 2; }
}
@media (max-width: 760px) {
  .chat-layout, .chat-layout-list { grid-template-columns: minmax(0, 1fr); gap: var(--space-3); }
  .chat-layout:not(.chat-layout-list) .inbox-pane { display: none; }
  .chat-layout:not(.chat-layout-list) > .thread-pane { height: auto; }
  .chat-layout .thread-side { grid-column: auto; order: -1; }
  .inbox-filters .chip, .notify-chips .chip { min-height: 40px; padding: 0 var(--space-3); font-size: var(--text-sm); }
  .inbox-pane { max-height: none; min-height: 0; border-radius: var(--radius-lg); overflow: visible; }
  .inbox-list { overflow: visible; }
  .thread-pane { height: auto; min-height: 0; overflow: visible; border: 0; border-radius: 0; background: transparent; margin: calc(-1 * var(--space-4)) calc(-1 * var(--space-4)) 0; }
  .thread-head { position: sticky; top: 60px; z-index: 15; padding: var(--space-2) var(--space-3); flex-wrap: wrap; }
  .thread-back { width: 40px; min-height: 40px; font-size: var(--text-2xl); line-height: 1; margin-left: calc(-1 * var(--space-2)); }
  .thread-head .avatar { display: none; }
  .assign-form { width: 100%; }
  .assign-form select { max-width: none; flex: 1; }
  .thread-scroll { overflow: visible; padding: var(--space-3); }
  .chat-thread .msg { max-width: 88%; }
  .composer { position: sticky; bottom: calc(60px + env(safe-area-inset-bottom)); z-index: 15; padding: var(--space-2) var(--space-3); box-shadow: 0 -4px 16px rgb(19 35 58 / 0.06); }
  .composer textarea { min-height: 2.75rem; }
  .thread-side { margin: calc(-1 * var(--space-2)) 0 var(--space-1); padding: 0; }
  .thread-side-sum { display: flex; align-items: center; gap: var(--space-2); padding: var(--space-3) var(--space-4); min-height: 48px; cursor: pointer; font-weight: var(--weight-semibold); list-style: none; }
  .thread-side-sum::-webkit-details-marker { display: none; }
  .thread-side-sum .i { width: 18px; height: 18px; }
  .thread-side-sum::after { content: "+"; margin-left: auto; font-size: var(--text-lg); color: var(--color-text-muted); }
  .thread-side[open] .thread-side-sum::after { content: "\2212"; }
  .thread-side-body { padding: 0 var(--space-4) var(--space-4); }
  .thread-side-body > .mini-title { display: none; }
  body:has([data-thread]) .app-top-title { visibility: hidden; }
  body:has([data-thread]) .app-content { padding-bottom: calc(60px + var(--space-2) + env(safe-area-inset-bottom)); }
  .chat-layout-list > .inbox-pane { height: auto; }
  .invite-row { grid-template-columns: minmax(0, 1fr); }
  .team-list li { flex-wrap: wrap; }
  .seg-wrap label { flex: 1 1 100%; }
  .team-actions { width: 100%; }
  .team-actions .inline-setting { flex: 1; }
  .team-actions .inline-setting select { flex: 1; }
  .team-actions select, .team-actions .btn-sm { min-height: 44px; }
  .role-key div { grid-template-columns: minmax(0, 1fr); gap: 0; }
}
