/* ==========================================================================
   design-refine — presentation only (built on 93.0, Cobalt Paper tokens)
   Scope: Triage · Debtors Book · Debtors Approval queue · Provisional Tax ·
          Clients · My work · navigation at small widths.
   Rule: restyle, never rewire. No rule here hides a control that 93.0 shows,
   and nothing here changes a request, a calculation or a permission.
   Loaded last from index.html. Removing that one <link> returns the 93.0 look.
   Class prefixes: .rf-* (new presentational hooks), .shell-* (small-width bar).
   ========================================================================== */

/* ---------- 0. Utilities ---------- */
.rf-num { font-variant-numeric: tabular-nums; }
.rf-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.rf-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: var(--r); }
.rf-scroll:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.rf-gap { height: 10px; }
.rf-sec-h { margin: 2px 0 8px; font-size: 14px; font-weight: 600; color: var(--text); display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; }
.rf-sec-sub { font-weight: 400; font-size: 12px; }
.rf-chip-urgent { background: var(--red-soft) !important; color: var(--red) !important; }
.rf-chip-stage { background: var(--accent-soft); color: var(--accent-ink); }

/* ---------- 1. Focus visibility (keyboard only) ---------- */
[data-rf-key]:focus { outline: none; }
[data-rf-key]:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-color: var(--accent-line); }
tr[data-rf-key]:focus-visible { outline-offset: -2px; }
tr[data-rf-key]:focus-visible td { background: var(--accent-soft); }
#view-inbox input[type="checkbox"]:focus-visible, #view-later input[type="checkbox"]:focus-visible, #view-lowpri input[type="checkbox"]:focus-visible,
#view-cleared input[type="checkbox"]:focus-visible, #view-debtors input[type="checkbox"]:focus-visible, #view-orgs input[type="checkbox"]:focus-visible,
#view-work input[type="checkbox"]:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
#view-orgs .w3-clients a:focus-visible, #view-provtax a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.sidebar .nav-item:focus-visible, .sidebar .nav-group-h:focus-visible, .sidebar-user:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

/* ---------- 2. Shell: small-width bar + navigation drawer ---------- */
.shell-mbar, .shell-nav-close, .shell-backdrop { display: none; }

@media (max-width: 860px) {
  .shell-mbar {
    display: flex; align-items: center; gap: 10px; position: sticky; top: 0; z-index: 60;
    height: 48px; margin: 0 -16px; padding: 0 12px; background: var(--surface); border-bottom: 1px solid var(--border);
  }
  .shell-mbar .ef-wordmark { font-size: 19px; line-height: 1; }
  .shell-mbar-here { margin-left: auto; font-size: 13px; font-weight: 500; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
  .shell-menu-btn { width: 40px; height: 40px; padding: 0; display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto; }
  .shell-menu-btn .ti { font-size: 20px; }
  /* Work and Education keep their own 93.0 bars in the markup; the shared bar replaces them on screen */
  #w3bMbar, #eduMbar { display: none !important; }

  .layout > .sidebar {
    transform: translateX(-102%); transition: transform var(--t, 150ms) var(--ease, ease); z-index: 1300;
    width: min(288px, 86vw); box-shadow: none; overflow-y: auto; overscroll-behavior: contain; visibility: hidden;
  }
  body.shell-nav-open .layout > .sidebar, body.w3b-nav-open .layout > .sidebar { transform: none; box-shadow: var(--shadow-pop); visibility: visible; }
  .sidebar .nav { overflow: visible; flex: 0 0 auto; }
  .sidebar .nav-item { min-height: 40px; }
  .sidebar .nav-group-h { min-height: 36px; }
  .shell-nav-close {
    display: inline-flex; align-items: center; justify-content: center; position: absolute; top: 8px; right: 8px; z-index: 2;
    width: 40px; height: 40px; border: 1px solid var(--border-2); border-radius: var(--r); background: var(--surface); color: var(--text-2); cursor: pointer;
  }
  .shell-nav-close .ti { font-size: 18px; }
  .shell-backdrop { display: block; position: fixed; inset: 0; z-index: 1290; background: rgba(17, 24, 39, .38); }
  .shell-backdrop[hidden] { display: none; }
  body.shell-nav-open { overflow: hidden; }

  .main, body.w3b-m .main { margin-left: 0; padding: 0 16px 40px; }
  .main > section > .topbar, body.w3b-m #view-work .topbar {
    position: static; margin: 0 -16px 12px; padding: 10px 16px; min-height: 0; gap: 8px; flex-wrap: wrap; height: auto;
  }
  .main > section > .topbar h1 { font-size: 20px; white-space: normal; }
  .main > section > .topbar .topbar-right { flex: 1 1 100%; width: 100%; gap: 8px; flex-wrap: wrap; margin-left: 0; justify-content: flex-start; }
  .main > section > .topbar .counts { white-space: normal; }
  .main > section > .topbar .btn-ghost, .main > section > .topbar .btn-primary, .main > section > .topbar .sort-select { min-height: 36px; }

  /* tab rows scroll sideways instead of stacking */
  .rf-tabs, #w3OrgsSeg, #dvSeg, #view-inbox .channel-seg { display: flex; flex-wrap: nowrap; overflow-x: auto; max-width: 100%; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
  .rf-tabs::-webkit-scrollbar, #w3OrgsSeg::-webkit-scrollbar, #dvSeg::-webkit-scrollbar { display: none; }
  .rf-tabs > button, #w3OrgsSeg > button, #dvSeg > button { flex: 0 0 auto; white-space: nowrap; min-height: 36px; }

  .toolbar { gap: 8px; }
  .toolbar .toolbar-spacer { display: none; }
  .toolbar input[type="search"], .toolbar .search-input, #view-inbox .toolbar input[type="text"] { flex: 1 1 100%; width: 100%; max-width: none; min-height: 36px; }
  .toolbar select, .toolbar .sort-select { min-height: 36px; flex: 1 1 140px; max-width: none; }

  .stat-strip .rail-stats { grid-auto-flow: row; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); }
}

/* ---------- 3. Triage (and Later / Low Priority / Cleared rows) ---------- */
.conv-row { padding: 13px 16px; margin-bottom: 8px; gap: 12px; }
.conv-row .conv-main { min-width: 0; flex: 1 1 auto; }
.conv-line { gap: 8px; }
.conv-names { font-size: 14px; font-weight: 600; letter-spacing: -0.005em; overflow: hidden; text-overflow: ellipsis; max-width: 46%; flex: 0 1 auto; }
.conv-subject { font-size: 13.5px; color: var(--text-2); font-weight: 500; }
.conv-number { font-variant-numeric: tabular-nums; color: var(--ink-3); }
.conv-preview { color: var(--ink-3); line-height: 1.45; margin-top: 3px; }
.conv-meta { gap: 10px; }
.conv-time { font-size: 12px; color: var(--ink-3); font-variant-numeric: tabular-nums; min-width: 4.2em; text-align: right; }
.conv-row.handled { opacity: 1; }
.conv-row.handled .conv-names, .conv-row.handled .conv-subject { color: var(--ink-3); font-weight: 500; }
.conv-row.handled .conv-avatar { opacity: .6; }
.feed-day { margin-top: 14px; }

/* the leading tick: same control, a larger hit area */
.conv-row .conv-check { margin: -6px -4px -6px -8px; padding: 9px 8px; display: flex; align-items: flex-start; }
.conv-row .conv-check input { width: 18px; height: 18px; margin: 0; }

/* Later / Low priority / Back to Triage: reachable by keyboard and on touch, not only on hover */
.conv-row:focus-within .row-acts, .conv-row[data-rf-key]:focus-visible .row-acts { display: inline-flex; }
.row-acts { gap: 4px; }
.row-act { display: inline-flex; align-items: center; justify-content: center; gap: 5px; }
.row-act .rf-act-t { display: none; font-size: 12px; font-weight: 500; }
@media (hover: none), (max-width: 860px) {
  .conv-row .row-acts { display: inline-flex; }
  .conv-row .row-act { min-height: 36px; min-width: 36px; padding: 0 10px; }
  .conv-row .row-act .rf-act-t { display: inline; }
}
@media (max-width: 640px) {
  .conv-row { flex-wrap: wrap; padding: 12px; gap: 10px; }
  .conv-row .conv-avatar { display: none; }
  .conv-row .conv-main { flex: 1 1 0; }
  .conv-line { flex-wrap: wrap; row-gap: 2px; }
  .conv-names { max-width: 100%; white-space: normal; }
  .conv-subject { flex: 1 1 100%; white-space: normal; overflow: visible; }
  .conv-preview { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; white-space: normal; }
  .conv-row .conv-meta { flex: 1 1 100%; order: 3; margin: 0; padding-left: 36px; flex-wrap: wrap; justify-content: flex-start; gap: 8px; }
  .conv-row .conv-meta .conv-time { margin-left: auto; }
  .conv-row .conv-check { padding: 11px 10px; margin: -8px -6px -8px -10px; }
}

/* ---------- 4. Debtors · Approval queue ---------- */
.rf-q-top { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin: 0 0 14px; }
.rf-q-intro { margin: 0; max-width: 78ch; line-height: 1.5; }
.rf-q-bulk { margin: 0; gap: 12px; align-items: center; flex: 0 0 auto; }
.rf-q-count { font-size: 13px; color: var(--ink-3); }
.rf-q-count b { color: var(--text); font-weight: 600; }
.contact-row.rf-q { align-items: flex-start; cursor: default; padding: 16px 18px; margin-bottom: 10px; gap: 14px; }
.contact-row.rf-q:hover { border-color: var(--border); }
.contact-row.rf-q .contact-avatar { border-radius: var(--r); background: var(--accent-soft); color: var(--accent-ink); }
.rf-q-head { flex-wrap: wrap; row-gap: 6px; }
.rf-q-client { font-size: 15px; font-weight: 600; letter-spacing: -0.01em; margin-right: 2px; }
.rf-q-facts { display: grid; grid-template-columns: max-content minmax(0, 1fr); column-gap: 12px; row-gap: 2px; margin-top: 8px; font-size: 13px; white-space: normal; overflow: visible; }
.rf-q-k { color: var(--ink-4); font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; padding-top: 1px; }
.rf-q-v { color: var(--text-2); min-width: 0; overflow-wrap: anywhere; }
.rf-q-v strong { color: var(--text); font-weight: 600; }
.rf-q-fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 320px)); gap: 12px; margin-top: 12px; }
.rf-field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.rf-field-l { font-size: 12px; font-weight: 600; color: var(--ink-3); display: inline-flex; align-items: center; gap: 5px; }
.rf-field-wide { margin-top: 12px; }
.rf-q .auth-input.rf-q-in { margin: 0; width: 100%; height: 34px; font-size: 13px; }
.rf-q .auth-input.rf-q-in.is-missing { border-color: var(--red); background: var(--red-soft); }
.rf-q .auth-input.rf-q-in.is-missing::placeholder { color: var(--red); opacity: .9; }
.rf-q textarea.auth-input.rf-q-body { margin: 0; width: 100%; min-height: 118px; height: auto; font-size: 13px; line-height: 1.5; padding: 10px 12px; resize: vertical; }
.rf-q-acts { display: flex; flex-direction: column; gap: 8px; flex: 0 0 148px; }
.rf-q-acts .btn-small { width: 100%; justify-content: center; min-height: 32px; margin: 0; }
@media (max-width: 860px) {
  .contact-row.rf-q { flex-wrap: wrap; padding: 14px; }
  .contact-row.rf-q .contact-avatar { display: none; }
  .rf-q-main { flex: 1 1 100%; }
  .rf-q-fields { grid-template-columns: 1fr; }
  .rf-q-acts { flex: 1 1 100%; flex-direction: row; flex-wrap: wrap; }
  .rf-q-acts .btn-small { flex: 1 1 120px; min-height: 40px; width: auto; }
  .rf-q-acts .btn-primary { flex: 1 1 100%; }
  .rf-q .auth-input.rf-q-in { height: 40px; font-size: 16px; }
  .rf-q textarea.auth-input.rf-q-body { font-size: 16px; }
  .rf-q-bulk { flex: 1 1 100%; justify-content: space-between; }
  .rf-q-bulk .btn-small { min-height: 40px; }
}

/* ---------- 5a. Debtors · Book (classic presentation) ---------- */
.rf-stats { display: grid; grid-template-columns: 1.4fr repeat(6, minmax(0, 1fr)); background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); margin-bottom: 16px; overflow: hidden; }
.rf-stat { display: flex; flex-direction: column; gap: 4px; padding: 12px 16px; border-right: 1px solid var(--border); min-width: 0; }
.rf-stat:last-child { border-right: 0; }
.rf-stat-l { font-size: 12px; font-weight: 500; color: var(--ink-3); white-space: nowrap; }
.rf-stat-v { font-family: var(--font-display); font-size: 18px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.15; color: var(--text); white-space: nowrap; }
.rf-stat.is-lead .rf-stat-v { font-size: 22px; }
.rf-book-note { margin: 0 0 8px; font-size: 12px; }
.contact-row.rf-book-row { margin-bottom: 8px; padding: 12px 16px; gap: 14px; align-items: center; }
.contact-row.rf-book-row .contact-avatar { border-radius: var(--r); background: var(--accent-soft); color: var(--accent-ink); }
.contact-row.rf-book-row.is-dim { opacity: .62; }
.contact-row.rf-book-row.is-focus { box-shadow: inset 3px 0 0 var(--amber); }
.contact-row.rf-book-row .contact-name { flex-wrap: wrap; row-gap: 4px; font-size: 14px; }
.contact-row.rf-book-row .contact-detail { white-space: normal; line-height: 1.5; }
.rf-age { display: grid; grid-template-columns: minmax(104px, auto) repeat(5, minmax(64px, auto)); column-gap: 14px; align-items: end; flex: 0 0 auto; }
.rf-age-b { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; min-width: 0; }
.rf-age-l { font-size: 11px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--ink-4); white-space: nowrap; }
.rf-age-v { font-size: 13px; color: var(--text); white-space: nowrap; }
.rf-age-b.is-zero .rf-age-v { color: var(--ink-4); }
.rf-age-b.is-total { padding-right: 14px; border-right: 1px solid var(--border); }
.rf-age-b.is-total .rf-age-v { font-size: 15px; font-weight: 700; }
@media (max-width: 1240px) {
  .contact-row.rf-book-row { flex-wrap: wrap; }
  .contact-row.rf-book-row .contact-main { flex: 1 1 60%; }
  .rf-age { flex: 1 1 100%; grid-template-columns: repeat(6, minmax(0, 1fr)); padding-top: 10px; border-top: 1px solid var(--border); column-gap: 8px; }
  .rf-age-b { align-items: flex-start; }
  .rf-age-b.is-total { border-right: 0; padding-right: 0; }
}
@media (max-width: 860px) {
  .rf-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .rf-stat { border-right: 0; border-bottom: 1px solid var(--border); padding: 10px 12px; }
  .rf-stat:nth-child(odd) { border-right: 1px solid var(--border); }
  .rf-stat.is-lead { grid-column: 1 / -1; border-right: 0; }
  .rf-stat:nth-child(even):not(.is-lead) { border-right: 1px solid var(--border); }
  .rf-stat:nth-child(odd):not(.is-lead) { border-right: 0; }
  .rf-stat:nth-last-child(-n+2) { border-bottom: 0; }
  .contact-row.rf-book-row { padding: 12px; }
  .contact-row.rf-book-row .contact-avatar { display: none; }
  .rf-age { grid-template-columns: repeat(3, minmax(0, 1fr)); row-gap: 10px; }
}

/* ---------- 5b. Debtors · Book (collections presentation, .dv-*) ---------- */
.dv-table td.dv-num, .dv-table th.dv-r { font-variant-numeric: tabular-nums; }
.dv-table th { color: var(--ink-3); }
.dv-table td.dv-strong { font-weight: 600; }
@media (max-width: 860px) {
  .dv-score { flex-wrap: wrap; }
  .dv-score .dv-k { flex: 1 1 44%; border-bottom: 1px solid var(--border); padding: 10px 12px; }
  .dv-score .dv-k.is-lead { flex: 1 1 100%; border-right: 0; }
  .dv-score .dv-k:last-child { border-bottom: 0; }
  .dv-toolbar select { flex: 1 1 140px; min-height: 36px; }
  .dv-toolbar input[type="search"] { flex: 1 1 100%; width: 100%; min-height: 36px; }
  .dv-toolbar .dv-spacer { display: none; }
  .dv-chips { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
  .dv-chips::-webkit-scrollbar { display: none; }
  .dv-chips .dv-chip { flex: 0 0 auto; min-height: 32px; }
  .dv-selbar { bottom: 8px; padding: 10px 12px; }
  .dv-selbar .btn-small { min-height: 36px; }
}
@media (max-width: 640px) {
  /* each client becomes a card: name, overdue first, then the ageing buckets with their own labels */
  .rf-dv-book { overflow: visible; border: 0; background: transparent; }
  .rf-dv-book .dv-table, .rf-dv-book .dv-table tbody { display: block; width: 100%; }
  .rf-dv-book .dv-table thead tr { display: flex; align-items: center; padding: 0 2px 8px; }
  .rf-dv-book .dv-table thead th { display: none; border: 0; background: transparent; }
  .rf-dv-book .dv-table thead th.dv-cb { display: flex; align-items: center; gap: 8px; width: auto; padding: 0; }
  .rf-dv-book .dv-table thead th.dv-cb::after { content: "Select all shown"; font-size: 12px; font-weight: 500; letter-spacing: 0; text-transform: none; color: var(--ink-3); }
  .rf-dv-book .dv-table tbody tr { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); column-gap: 10px; row-gap: 8px; position: relative; padding: 12px; margin-bottom: 8px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); }
  .rf-dv-book .dv-table tbody tr.is-sel { background: var(--accent-soft); border-color: var(--accent-line); }
  .rf-dv-book .dv-table tbody td { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; padding: 0; border: 0; background: transparent !important; text-align: left; min-width: 0; }
  .rf-dv-book .dv-table tbody td[data-label]::before { content: attr(data-label); font-size: 11px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--ink-4); }
  .rf-dv-book .dv-table tbody td.dv-c-client { grid-column: 1 / -1; min-width: 0; padding-right: 40px; }
  .rf-dv-book .dv-table tbody td.dv-cb { position: absolute; top: 4px; right: 4px; width: 40px; height: 40px; align-items: center; justify-content: center; }
  .rf-dv-book .dv-table tbody td.dv-strong { font-size: 16px; }
  .rf-dv-book .dv-table tbody td[data-label="Where it stands"], .rf-dv-book .dv-table tbody td[data-label="Contact details"] { grid-column: span 3; flex-direction: row; align-items: center; gap: 8px; flex-wrap: wrap; }
  .rf-dv-book .dv-table tbody td[data-label="Last contact"] { grid-column: span 3; flex-direction: row; gap: 8px; align-items: baseline; }
  .rf-dv-book .dv-table tbody td[colspan] { grid-column: 1 / -1; }
  .rf-dv-book .dv-card-f { padding: 8px 2px 0; border: 0; }
}

/* ---------- 6. Provisional Tax register ---------- */
.rf-pt-intro { margin: 0 0 12px; max-width: 96ch; line-height: 1.5; }
.cs-table.rf-pt { min-width: 760px; }
.cs-table.rf-pt th { text-align: left; vertical-align: bottom; }
.cs-table.rf-pt thead th.rf-pt-ph { min-width: 190px; }
.rf-pt-pn { display: inline-block; min-width: 22px; padding: 1px 6px; margin-right: 4px; border-radius: 4px; background: var(--accent-soft); color: var(--accent-ink); font-weight: 700; letter-spacing: .02em; text-align: center; }
.cs-table.rf-pt tbody th.rf-pt-client { text-align: left; font-weight: 400; padding: 12px; border-bottom: 1px solid var(--border); vertical-align: top; background: var(--card-bg); text-transform: none; letter-spacing: 0; font-size: 13.5px; color: var(--text); }
.cs-table.rf-pt tbody tr:last-child th { border-bottom: 0; }
.rf-pt-client strong { display: block; font-weight: 600; }
.rf-pt-sub { display: block; font-size: 12px; margin-top: 2px; }
.rf-pt-entity { font-size: 12.5px; color: var(--text-2); vertical-align: top; white-space: nowrap; }
.cs-table.rf-pt td.rf-pt-cell { vertical-align: top; padding: 12px; }
.rf-pt-amt { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.rf-pt-amt strong { font-size: 15px; font-weight: 700; letter-spacing: -0.01em; color: var(--text); }
.rf-pt-over { color: var(--amber); }
.rf-pt-status { font-size: 11px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; padding: 1px 7px; border-radius: var(--r-pill); background: var(--sunken); color: var(--ink-3); }
.rf-pt-status.is-final { background: var(--accent-soft); color: var(--accent-ink); }
.rf-pt-status.is-sent { background: var(--green-soft); color: var(--green); }
.rf-pt-due { font-size: 12px; color: var(--ink-3); margin-top: 3px; }
.rf-pt-paid { font-size: 12px; color: var(--green); margin-top: 3px; font-weight: 500; }
.rf-pt-acts { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.rf-pt-acts .btn-small { margin: 0; }
@media (max-width: 860px) {
  .rf-pt-acts .btn-small, .rf-pt-cell.is-empty .btn-small { min-height: 36px; }
}
@media (max-width: 640px) {
  /* one card per client; each period keeps its own heading */
  .rf-scroll:has(> .rf-pt) { overflow: visible; }
  .cs-table.rf-pt { min-width: 0; display: block; background: transparent; box-shadow: none; }
  .cs-table.rf-pt thead { display: none; }
  .cs-table.rf-pt tbody { display: block; }
  .cs-table.rf-pt tbody tr { display: block; background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--r); margin-bottom: 10px; overflow: hidden; }
  .cs-table.rf-pt tbody th.rf-pt-client { display: block; padding: 12px 12px 2px; border: 0; font-size: 15px; }
  .cs-table.rf-pt tbody td { display: block; border: 0; padding: 0 12px; }
  .cs-table.rf-pt td.rf-pt-entity { padding-bottom: 10px; color: var(--ink-3); white-space: normal; }
  .cs-table.rf-pt td.rf-pt-cell { padding: 10px 12px 12px; border-top: 1px solid var(--border); }
  .cs-table.rf-pt td.rf-pt-cell::before { content: attr(data-label); display: block; font-size: 11px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--ink-4); margin-bottom: 4px; }
  .cs-table.rf-pt td.rf-pt-cell.is-empty { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
  .cs-table.rf-pt td.rf-pt-cell.is-empty::before { margin: 0; }
  .rf-pt-acts .btn-small { flex: 1 1 auto; justify-content: center; }
}

/* ---------- 7. Clients register ---------- */
#view-orgs .topbar h1 .pill { font-weight: 500; }
.cs-table.rf-clients th { color: var(--ink-3); white-space: nowrap; }
.cs-table.rf-clients td { vertical-align: middle; }
.cs-table.rf-clients .w3-cell-main b a { color: var(--text); text-decoration: none; }
.cs-table.rf-clients .w3-cell-main b a:hover { color: var(--accent-ink); text-decoration: underline; }
.cs-table.rf-clients td.w3-r, .cs-table.rf-clients th.w3-r { text-align: right; }
@media (max-width: 1100px) and (min-width: 641px) { .cs-table.rf-clients { min-width: 860px; } }
@media (max-width: 860px) {
  #view-orgs .topbar .btn-ghost, #view-orgs .topbar .btn-primary { flex: 1 1 auto; justify-content: center; }
  #view-orgs .topbar .sf-check { min-height: 36px; display: inline-flex; align-items: center; }
  .w3-healthbar { grid-template-columns: 1fr; gap: 10px; padding: 12px; }
  .w3-gaplinks { display: flex; flex-wrap: nowrap; overflow-x: auto; gap: 6px; padding-bottom: 2px; scrollbar-width: none; }
  .w3-gaplinks .pill { flex: 0 0 auto; }
  #view-orgs .bulk-bar { flex-wrap: wrap; gap: 8px; }
  #view-orgs .bulk-bar .btn-small, #view-orgs .bulk-bar .sort-select { min-height: 36px; }
}
@media (max-width: 640px) {
  .rf-scroll:has(> .rf-clients) { overflow: visible; }
  .cs-table.rf-clients { display: block; background: transparent; box-shadow: none; overflow: visible; }
  .cs-table.rf-clients tbody { display: block; }
  .cs-table.rf-clients thead { display: block; }
  .cs-table.rf-clients thead tr { display: flex; align-items: center; padding: 0 2px 8px; }
  .cs-table.rf-clients thead th { display: none; background: transparent; border: 0; padding: 0; }
  .cs-table.rf-clients thead th.w3-chk { display: flex; align-items: center; gap: 8px; width: auto; }
  .cs-table.rf-clients thead th.w3-chk::after { content: "Select all"; font-size: 12px; font-weight: 500; letter-spacing: 0; text-transform: none; color: var(--ink-3); }
  .cs-table.rf-clients tbody tr { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 12px; row-gap: 8px; position: relative; padding: 12px; margin-bottom: 8px; background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--r); }
  .cs-table.rf-clients tbody tr.is-selected { background: var(--accent-soft); border-color: var(--accent-line); }
  .cs-table.rf-clients tbody td { display: flex; flex-direction: column; align-items: flex-start; gap: 3px; padding: 0; border: 0; background: transparent !important; min-width: 0; text-align: left; }
  .cs-table.rf-clients tbody td[data-label]::before { content: attr(data-label); font-size: 11px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--ink-4); }
  .cs-table.rf-clients tbody td:empty { display: none; }
  .cs-table.rf-clients tbody td.rf-cl-name { grid-column: 1 / -1; padding-right: 40px; }
  .cs-table.rf-clients tbody td.rf-cl-name b { white-space: normal; font-size: 15px; }
  .cs-table.rf-clients tbody td.rf-cl-name .w3-cell-sub { white-space: normal; }
  .cs-table.rf-clients tbody td.w3-chk { position: absolute; top: 4px; right: 4px; width: 40px; height: 40px; align-items: center; justify-content: center; }
  .cs-table.rf-clients tbody td[data-label="Services"] { grid-column: 1 / -1; }
  .cs-table.rf-clients tbody td[colspan] { grid-column: 1 / -1; }
  .w3-sum { flex-wrap: wrap; }
}

/* ---------- 8. My work ---------- */
#view-work .w3-cols { grid-template-columns: 20px minmax(180px, 1.2fr) 148px 116px 150px minmax(180px, 1.7fr) 72px; }
#view-work .w3-cols.is-review { grid-template-columns: 20px minmax(180px, 1.25fr) 132px 118px minmax(150px, 1fr) minmax(170px, 1.3fr) 108px; }
#view-work .w3-row .w3-c-due { min-width: 0; font-variant-numeric: tabular-nums; }
#view-work .w3-row .w3-c-due > * { overflow: hidden; text-overflow: ellipsis; }
#view-work .w3-cell-main b { font-size: 13.5px; }
#view-work .w3-next { color: var(--text); }
#view-work .w3-colhead { color: var(--ink-3); }
#view-work .wk-group-head { margin-top: 4px; }
/* Advance / Waiting: visible to keyboard and touch users as well as on hover */
#view-work .w3-row:focus-within .w3-acts { opacity: 1; }
@media (hover: none) { #view-work .w3-row .w3-acts { opacity: 1; } }
@media (max-width: 640px) {
  #view-work .w3-cols, #view-work .w3-cols.is-review { grid-template-columns: 24px minmax(0, 1fr) auto; row-gap: 6px; }
  #view-work .w3-row { padding: 12px; }
  #view-work .w3-row > input[type="checkbox"] { width: 18px; height: 18px; }
  #view-work .w3-cell-main b { white-space: normal; font-size: 14.5px; }
  #view-work .w3-cell-sub { white-space: normal; }
  #view-work .w3-row > .w3-c-next { font-size: 13.5px; }
  #view-work .w3-row > .w3-c-next::before { content: "Next step"; display: block; font-size: 11px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--ink-4); margin-bottom: 1px; }
  #view-work .w3-row > .w3-c-next:empty { display: none; }
  /* 93.0 hides Advance / Waiting on a phone; they are shown here as full-size buttons (same buttons, same handlers) */
  #view-work .w3-row > .w3-acts { display: flex; grid-column: 2 / -1; justify-content: flex-start; opacity: 1; gap: 8px; }
  #view-work .w3-row > .w3-acts .row-act, #view-work .w3-row > .w3-acts .btn-small { min-height: 40px; min-width: 44px; }
  #view-work .w3-toolbar .sort-select { flex: 1 1 140px; max-width: none; }
  #view-work .wk-group-head { flex-wrap: wrap; }
  #view-work .wk-group-head .w3-hint { flex: 1 1 100%; }
}

/* ---------- 9. Narrow phones (320 CSS px) ---------- */
@media (max-width: 360px) {
  .main, body.w3b-m .main { padding: 0 12px 32px; }
  .shell-mbar { margin: 0 -12px; }
  .main > section > .topbar, body.w3b-m #view-work .topbar { margin: 0 -12px 10px; padding: 8px 12px; }
  .rf-age { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .rf-dv-book .dv-table tbody tr { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .rf-dv-book .dv-table tbody td[data-label="Where it stands"], .rf-dv-book .dv-table tbody td[data-label="Contact details"], .rf-dv-book .dv-table tbody td[data-label="Last contact"] { grid-column: 1 / -1; }
  .cs-table.rf-clients tbody tr { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) { .layout > .sidebar { transition: none; } }

/* ---------- 10. Small fixes found while checking ---------- */
.topbar h1[tabindex="-1"]:focus, .topbar h1[tabindex="-1"]:focus-visible { outline: none; } /* focus target after choosing a destination in the drawer */
@media (max-width: 640px) {
  #view-work .w3-testbar, #view-work [id^="w3Test"] { flex-wrap: wrap; }
  #view-work [id^="w3Test"] > div { flex: 1 1 100%; min-width: 0; }
  #view-work [id^="w3Test"] .w3-spacer { display: none; }
}
.conv-row label.conv-check { cursor: pointer; } /* the tick's padding now ticks it (label), instead of being dead space */
@media (max-width: 640px) {
  /* the existing snooze choices, presented as a bottom sheet on a phone */
  #snoozePopup:not(.hidden) { left: 8px !important; right: 8px; top: auto !important; bottom: 8px; width: auto; max-width: none; }
  #snoozePopup button { min-height: 44px; }
  #snoozePopup #snzCustom { min-height: 40px; flex: 1 1 auto; min-width: 0; }
}
@media (max-width: 640px) { .conv-row .conv-subject { max-width: none; } .conv-row .conv-names { flex: 0 1 auto; } }
#view-work .w3-cols:not(.is-review) { grid-template-columns: 20px minmax(180px, 1.2fr) 164px 104px 150px minmax(180px, 1.7fr) 72px; }
@media (max-width: 640px) { #view-work .w3-cols:not(.is-review) { grid-template-columns: 24px minmax(0, 1fr) auto; } }

/* ---------- 11. My work below 1180 px (small laptops, 200% zoom): the seven-column row no longer fits beside the
   sidebar (93.0 scrolls sideways here), so each job stacks like the phone layout. Same cells, same order. ---------- */
@media (max-width: 1240px) {
  #view-work .w3-colhead { display: none; }
  #view-work .w3-keys { flex-wrap: wrap; row-gap: 6px; }
  #view-work .w3-cols, #view-work .w3-cols.is-review, #view-work .w3-cols:not(.is-review) { grid-template-columns: 24px minmax(0, 1fr) auto; row-gap: 6px; }
  #view-work .w3-row { padding: 12px; }
  #view-work .w3-row > .w3-c-due { grid-column: 3; grid-row: 1; text-align: right; }
  #view-work .w3-row.is-review > .w3-c-due { grid-column: 2 / -1; grid-row: auto; text-align: left; }
  #view-work .w3-cols:not(.is-review) > .w3-c-docs { display: flex; gap: 8px; align-items: center; }
  #view-work .w3-row > .w3-c-docs, #view-work .w3-row > .w3-c-st, #view-work .w3-row > .w3-c-next { grid-column: 2 / -1; }
  #view-work .w3-row > .w3-c-next::before { content: "Next step"; display: block; font-size: 11px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--ink-4); margin-bottom: 1px; }
  #view-work .w3-row > .w3-c-next:empty { display: none; }
  #view-work .w3-row > .w3-acts { display: flex; grid-column: 2 / -1; justify-content: flex-start; opacity: 1; gap: 8px; }
  #view-work .w3-row > .w3-acts .row-act, #view-work .w3-row > .w3-acts .btn-small { min-height: 40px; min-width: 44px; }
  #view-work .w3-cell-main b, #view-work .w3-cell-sub { white-space: normal; }
  #view-work .w3-tabs { overflow-x: auto; }
  #view-work .w3-toolbar { flex-wrap: wrap; }
  #view-work .w3-toolbar .sort-select { min-width: 0; }
}
@media (max-width: 360px) { #view-work .w3-toolbar .sort-select { flex: 1 1 100%; max-width: 100%; } }
.w3-healthbar > * { min-width: 0; }
.w3-gaplinks .pill { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.w3-gaplinks button.pill { min-height: 28px; padding-top: 2px; padding-bottom: 2px; }
@media (max-width: 860px) { .w3-gaplinks button.pill { min-height: 36px; } }
@media (min-width: 641px) { .cs-table.rf-pt tbody th.rf-pt-client { min-width: 168px; } }
